[teiid-commits] teiid SVN: r4011 - in branches/8.0.x: runtime/src/main/java/org/teiid/deployers and 1 other directories.

teiid-commits at lists.jboss.org teiid-commits at lists.jboss.org
Tue Apr 17 14:54:39 EDT 2012


Author: shawkins
Date: 2012-04-17 14:54:37 -0400 (Tue, 17 Apr 2012)
New Revision: 4011

Modified:
   branches/8.0.x/jboss-integration/src/main/java/org/teiid/jboss/VDBService.java
   branches/8.0.x/runtime/src/main/java/org/teiid/deployers/CompositeVDB.java
   branches/8.0.x/runtime/src/main/java/org/teiid/deployers/VDBRepository.java
   branches/8.0.x/runtime/src/main/java/org/teiid/deployers/VDBStatusChecker.java
   branches/8.0.x/runtime/src/test/java/org/teiid/deployers/TestCompositeVDB.java
Log:
TEIID-1998 adding an initial build to avoid ever having a null merged vdb and ensuring that getVDB cannot block

Modified: branches/8.0.x/jboss-integration/src/main/java/org/teiid/jboss/VDBService.java
===================================================================
--- branches/8.0.x/jboss-integration/src/main/java/org/teiid/jboss/VDBService.java	2012-04-17 17:28:25 UTC (rev 4010)
+++ branches/8.0.x/jboss-integration/src/main/java/org/teiid/jboss/VDBService.java	2012-04-17 18:54:37 UTC (rev 4011)
@@ -135,12 +135,13 @@
 				if (!name.equals(VDBService.this.vdb.getName()) || version != VDBService.this.vdb.getVersion()) {
 					return;
 				}
+				VDBMetaData vdbInstance = vdb.getVDB();
 				// add object replication to temp/matview tables
-				GlobalTableStore gts = new GlobalTableStoreImpl(getBuffermanager(), vdb.getVDB().getAttachment(TransformationMetadata.class));
+				GlobalTableStore gts = new GlobalTableStoreImpl(getBuffermanager(), vdbInstance.getAttachment(TransformationMetadata.class));
 				if (objectReplicatorInjector.getValue() != null) {
 					try {
 						gts = objectReplicatorInjector.getValue().replicate(name + version, GlobalTableStore.class, gts, 300000);
-						vdb.getVDB().addAttchment(GlobalTableStore.class, gts);
+						vdbInstance.addAttchment(GlobalTableStore.class, gts);
 					} catch (Exception e) {
 						LogManager.logError(LogConstants.CTX_RUNTIME, e, IntegrationPlugin.Util.gs(IntegrationPlugin.Event.TEIID50023, gts)); 
 					}

Modified: branches/8.0.x/runtime/src/main/java/org/teiid/deployers/CompositeVDB.java
===================================================================
--- branches/8.0.x/runtime/src/main/java/org/teiid/deployers/CompositeVDB.java	2012-04-17 17:28:25 UTC (rev 4010)
+++ branches/8.0.x/runtime/src/main/java/org/teiid/deployers/CompositeVDB.java	2012-04-17 18:54:37 UTC (rev 4011)
@@ -36,17 +36,7 @@
 import org.teiid.core.CoreConstants;
 import org.teiid.dqp.internal.datamgr.ConnectorManager;
 import org.teiid.dqp.internal.datamgr.ConnectorManagerRepository;
-import org.teiid.metadata.AbstractMetadataRecord;
-import org.teiid.metadata.Column;
-import org.teiid.metadata.ColumnStats;
-import org.teiid.metadata.DefaultMetadataRepository;
-import org.teiid.metadata.FunctionMethod;
-import org.teiid.metadata.MetadataRepository;
-import org.teiid.metadata.MetadataStore;
-import org.teiid.metadata.Procedure;
-import org.teiid.metadata.Schema;
-import org.teiid.metadata.Table;
-import org.teiid.metadata.TableStats;
+import org.teiid.metadata.*;
 import org.teiid.metadata.index.IndexMetadataStore;
 import org.teiid.query.function.FunctionTree;
 import org.teiid.query.function.UDFSource;
@@ -70,7 +60,7 @@
 	private boolean metadataloadFinished = false;
 	
 	// used as cached item to avoid rebuilding
-	private VDBMetaData mergedVDB;
+	private volatile VDBMetaData mergedVDB;
 	
 	public CompositeVDB(VDBMetaData vdb, MetadataStore metadataStore, UDFMetaData udf, FunctionTree systemFunctions, ConnectorManagerRepository cmr, MetadataStore... additionalStores) {
 		this.vdb = vdb;
@@ -81,7 +71,8 @@
 		this.udf = udf;
 		this.systemFunctions = systemFunctions;
 		this.cmr = cmr;
-		this.additionalStores = additionalStores;		
+		this.additionalStores = additionalStores;
+		this.mergedVDB = buildVDB();
 	}
 	
 	synchronized void addChild(CompositeVDB child) {
@@ -90,34 +81,35 @@
 		}
 		VDBMetaData childVDB = child.getVDB();
 		this.children.put(new VDBKey(childVDB.getName(), childVDB.getVersion()), child);
-		this.mergedVDB = null;
+		update();
 	}
 	
 	synchronized void removeChild(VDBKey child) {
 		if (this.children != null) {
 			this.children.remove(child);
 		}
-		this.mergedVDB = null;
+		update();
 	}	
 	
 	private synchronized void update() {
-		if (this.mergedVDB == null && this.metadataloadFinished) {
+		if (this.metadataloadFinished) {
 			
-			this.mergedVDB = buildVDB();
+			VDBMetaData newVDB = buildVDB();
 			
 			MetadataStore mergedStore = getMetadataStore();
 			
-			for (ModelMetaData model:this.mergedVDB.getModelMetaDatas().values()) {
+			for (ModelMetaData model:newVDB.getModelMetaDatas().values()) {
 				MetadataRepository repo = model.getAttachment(MetadataRepository.class);
 				if (repo instanceof DefaultMetadataRepository) {
-					updateFromMetadataRepository(this.mergedVDB, mergedStore.getSchema(model.getName()), (DefaultMetadataRepository)repo);
+					updateFromMetadataRepository(newVDB, mergedStore.getSchema(model.getName()), (DefaultMetadataRepository)repo);
 				}
 			}
 			
-			TransformationMetadata metadata = buildTransformationMetaData(this.mergedVDB, getVisibilityMap(), mergedStore, getUDF(), systemFunctions, this.additionalStores);
-			this.mergedVDB.addAttchment(QueryMetadataInterface.class, metadata);
-			this.mergedVDB.addAttchment(TransformationMetadata.class, metadata);
-			this.mergedVDB.addAttchment(MetadataStore.class, mergedStore);
+			TransformationMetadata metadata = buildTransformationMetaData(newVDB, getVisibilityMap(), mergedStore, getUDF(), systemFunctions, this.additionalStores);
+			newVDB.addAttchment(QueryMetadataInterface.class, metadata);
+			newVDB.addAttchment(TransformationMetadata.class, metadata);
+			newVDB.addAttchment(MetadataStore.class, mergedStore);
+			this.mergedVDB = newVDB;
 		}
 	}
 	
@@ -144,10 +136,7 @@
 		return metadata;
 	}
 	
-	public synchronized VDBMetaData getVDB() {
-		if (this.mergedVDB == null && this.metadataloadFinished) {			
-			update();
-		}
+	public VDBMetaData getVDB() {
 		return this.mergedVDB;
 	}
 	
@@ -340,11 +329,11 @@
 		metadataRepository.endLoadVdb(vdbName, vdbVersion);
 	}	
 	
-	public void setMetaloadFinished(boolean flag) {
-		this.metadataloadFinished = flag;
+	public synchronized void metadataLoadFinished() {
+		if (!this.metadataloadFinished) {
+			this.metadataloadFinished = true;
+			update();
+		}
 	}
 	
-	public boolean isMetadataloadFinished() {
-		return this.metadataloadFinished;
-	}
 }

Modified: branches/8.0.x/runtime/src/main/java/org/teiid/deployers/VDBRepository.java
===================================================================
--- branches/8.0.x/runtime/src/main/java/org/teiid/deployers/VDBRepository.java	2012-04-17 17:28:25 UTC (rev 4010)
+++ branches/8.0.x/runtime/src/main/java/org/teiid/deployers/VDBRepository.java	2012-04-17 18:54:37 UTC (rev 4011)
@@ -109,50 +109,34 @@
 		return vdbs;
 	}
 	
-	/**
-	 * This returns the all the VDBS that loaded and still loading or stalled due to data source unavailability.
-	 * @return
-	 */
-	public List<VDBMetaData> getAllDeployedVDBs(){
-		ArrayList<VDBMetaData> vdbs = new ArrayList<VDBMetaData>();
-		for(CompositeVDB cVDB:this.vdbRepo.values()) {
-			if (!cVDB.isMetadataloadFinished()) {
-				vdbs.add(cVDB.buildVDB());
-			}
-			else {
-				vdbs.add(cVDB.getVDB());
-			}
-		}
-		return vdbs;
-	}	
-
     protected VDBKey vdbId(VDBMetaData vdb) {
         return new VDBKey(vdb.getName(), vdb.getVersion());
     } 	
 		
 	public VDBMetaData getVDB(String vdbName) {
     	int latestVersion = 0;
-        for (VDBKey key:this.vdbRepo.tailMap(new VDBKey(vdbName, 0)).keySet()) {
-            if(!key.getName().equalsIgnoreCase(vdbName)) {
+    	VDBMetaData result = null;
+        for (Map.Entry<VDBKey, CompositeVDB> entry:this.vdbRepo.tailMap(new VDBKey(vdbName, 0)).entrySet()) {
+            if(!entry.getKey().getName().equalsIgnoreCase(vdbName)) {
             	break;
             }
-        	VDBMetaData vdb = this.vdbRepo.get(key).getVDB();
+        	VDBMetaData vdb = entry.getValue().getVDB();
         	switch (vdb.getConnectionType()) {
         	case ANY:
-        		latestVersion = Math.max(vdb.getVersion(), latestVersion);
+        		if (vdb.getVersion() > latestVersion) {
+        			latestVersion = vdb.getVersion();
+        			result = vdb;
+        		}
         		break;
         	case BY_VERSION:
                 if (latestVersion == 0) {
             		latestVersion = vdb.getVersion();
+            		result = vdb;
                 }            	
                 break;
         	}
         }
-        if(latestVersion == 0) {
-            return null; 
-        }
-
-        return getVDB(vdbName, latestVersion);
+        return result;
 	}
 	
 	public MetadataStore getSystemStore() {
@@ -228,12 +212,14 @@
 		if (removed != null) {
 			// if this VDB was part of another VDB; then remove them.
 			for (CompositeVDB other:this.vdbRepo.values()) {
-				if (other.hasChildVdb(key)) {
-					notifyRemove(other.getVDB().getName(), other.getVDB().getVersion(), other);
-	
-					other.removeChild(key);
-	
-					notifyAdd(other.getVDB().getName(), other.getVDB().getVersion(), other);
+				synchronized (other) {
+					if (other.hasChildVdb(key)) {
+						notifyRemove(other.getVDB().getName(), other.getVDB().getVersion(), other);
+		
+						other.removeChild(key);
+		
+						notifyAdd(other.getVDB().getName(), other.getVDB().getVersion(), other);
+					}
 				}
 			}
 			notifyRemove(key.getName(), key.getVersion(), removed);
@@ -276,7 +262,7 @@
 		CompositeVDB v = this.vdbRepo.get(new VDBKey(name, version));
 		if (v!= null) {
 			boolean valid = false;
-			v.setMetaloadFinished(true);
+			v.metadataLoadFinished();
 			VDBMetaData metdataAwareVDB = v.getVDB();			
 			ValidatorReport report = MetadataValidator.validate(metdataAwareVDB, metdataAwareVDB.removeAttachment(MetadataStore.class));
 			

Modified: branches/8.0.x/runtime/src/main/java/org/teiid/deployers/VDBStatusChecker.java
===================================================================
--- branches/8.0.x/runtime/src/main/java/org/teiid/deployers/VDBStatusChecker.java	2012-04-17 17:28:25 UTC (rev 4010)
+++ branches/8.0.x/runtime/src/main/java/org/teiid/deployers/VDBStatusChecker.java	2012-04-17 18:54:37 UTC (rev 4011)
@@ -119,10 +119,7 @@
 	}
 	
 	public void resourceAdded(String resourceName, boolean translator) {
-		for (VDBMetaData vdb:getVDBRepository().getAllDeployedVDBs()) {
-			if (vdb == null) {
-				continue;
-			}
+		for (VDBMetaData vdb:getVDBRepository().getVDBs()) {
 			if (vdb.getStatus() == VDB.Status.ACTIVE || vdb.isPreview()) {
 				continue;
 			}
@@ -178,10 +175,7 @@
 	}
 	
 	public void resourceRemoved(String resourceName, boolean translator) {
-		for (VDBMetaData vdb:getVDBRepository().getAllDeployedVDBs()) {
-			if (vdb == null) {
-				continue;
-			}			
+		for (VDBMetaData vdb:getVDBRepository().getVDBs()) {
 			if (vdb.isPreview()) {
 				continue;
 			}

Modified: branches/8.0.x/runtime/src/test/java/org/teiid/deployers/TestCompositeVDB.java
===================================================================
--- branches/8.0.x/runtime/src/test/java/org/teiid/deployers/TestCompositeVDB.java	2012-04-17 17:28:25 UTC (rev 4010)
+++ branches/8.0.x/runtime/src/test/java/org/teiid/deployers/TestCompositeVDB.java	2012-04-17 18:54:37 UTC (rev 4011)
@@ -66,7 +66,7 @@
     	cmr.addConnectorManager("source2", getConnectorManager("FakeTranslator2", "FakeConnection2", getFuncsTwo()));
     	
     	CompositeVDB cvdb = new CompositeVDB(vdbMetaData, metadataStore, null, RealMetadataFactory.SFM.getSystemFunctions(),cmr);
-    	cvdb.setMetaloadFinished(true);
+    	cvdb.metadataLoadFinished();
 		return cvdb;
 	}
 	



More information about the teiid-commits mailing list