[teiid-commits] teiid SVN: r2924 - in trunk: client/src/main/java/org/teiid/adminapi and 2 other directories.

teiid-commits at lists.jboss.org teiid-commits at lists.jboss.org
Tue Feb 22 20:33:24 EST 2011


Author: shawkins
Date: 2011-02-22 20:33:24 -0500 (Tue, 22 Feb 2011)
New Revision: 2924

Modified:
   trunk/build/kits/jboss-container/deployers/teiid.deployer/teiid-deployer-jboss-beans.xml
   trunk/client/src/main/java/org/teiid/adminapi/Model.java
   trunk/runtime/src/main/java/org/teiid/deployers/VDBDeployer.java
   trunk/runtime/src/main/java/org/teiid/deployers/VDBStatusChecker.java
   trunk/runtime/src/main/resources/org/teiid/runtime/i18n.properties
Log:
TEIID-1470 updating dynamic vdb deployment logic

Modified: trunk/build/kits/jboss-container/deployers/teiid.deployer/teiid-deployer-jboss-beans.xml
===================================================================
--- trunk/build/kits/jboss-container/deployers/teiid.deployer/teiid-deployer-jboss-beans.xml	2011-02-22 20:58:00 UTC (rev 2923)
+++ trunk/build/kits/jboss-container/deployers/teiid.deployer/teiid-deployer-jboss-beans.xml	2011-02-23 01:33:24 UTC (rev 2924)
@@ -83,6 +83,7 @@
             
     <bean name="VDBStatusChecker" class="org.teiid.deployers.VDBStatusChecker">
         <property name="VDBRepository"><inject bean="VDBRepository"/></property>
+        <property name="threadPool"><inject bean="jboss.system:service=ThreadPool"/></property>
     </bean>
      
     <!-- Persistence class for the VDB deployment file -->

Modified: trunk/client/src/main/java/org/teiid/adminapi/Model.java
===================================================================
--- trunk/client/src/main/java/org/teiid/adminapi/Model.java	2011-02-22 20:58:00 UTC (rev 2923)
+++ trunk/client/src/main/java/org/teiid/adminapi/Model.java	2011-02-23 01:33:24 UTC (rev 2924)
@@ -62,14 +62,14 @@
     Type getModelType();
 
     /** 
-     * Determine whether this model can support more than one connector binding.
+     * Determine whether this model can support more than one source.
      * 
-     * @return <code>true</code> if this model supports multi-source bindings
+     * @return <code>true</code> if this model supports multiple sources
      */
     boolean isSupportsMultiSourceBindings();
     
     /**
-     * Associated Source Names for the Models (Connector Bindings)
+     * Associated Source Names for the Models
      * @return String
      */
     List<String> getSourceNames();

Modified: trunk/runtime/src/main/java/org/teiid/deployers/VDBDeployer.java
===================================================================
--- trunk/runtime/src/main/java/org/teiid/deployers/VDBDeployer.java	2011-02-22 20:58:00 UTC (rev 2923)
+++ trunk/runtime/src/main/java/org/teiid/deployers/VDBDeployer.java	2011-02-23 01:33:24 UTC (rev 2924)
@@ -301,28 +301,41 @@
 	    	}
 	    	
 	    	if (!loaded) {
-	    		String msg = RuntimePlugin.Util.getString("model_metadata_loading", vdb.getName()+"-"+vdb.getVersion(), model.getName(), SimpleDateFormat.getInstance().format(new Date())); //$NON-NLS-1$ //$NON-NLS-2$
-	    		final ValidationError addedError = model.addError(ModelMetaData.ValidationError.Severity.ERROR.toString(), msg); 
-	    		LogManager.logInfo(LogConstants.CTX_RUNTIME, msg);
 	    		threadPool.run(new Runnable() {
 					@Override
 					public void run() {
-						loadMetadata(vdb, model, cache, cacheFile, vdbStore, cmr, addedError);
+						Boolean loadStatus = loadMetadata(vdb, model, cache, cacheFile, vdbStore, cmr);
+						//if (loadStatus == null) {
+							//TODO: a source is up, but we failed.  should we retry or poll?
+						//} 
+						if (loadStatus == null || !loadStatus) {
+							//defer the load to the status checker if/when a source is available/redeployed
+							model.addAttchment(Runnable.class, this);
+						}	    				
 					}
 	    		});
 	    	}
 		}
 	}	
     
-    private void loadMetadata(VDBMetaData vdb, ModelMetaData model, boolean cache, File cacheFile, MetadataStoreGroup vdbStore, ConnectorManagerRepository cmr, ValidationError addedError) {
-    	Exception exception = null;
-    	
-    	boolean loaded = false;
+    /**
+     * @return true if loaded, null if not loaded - but a cm is available, else false
+     */
+    private Boolean loadMetadata(VDBMetaData vdb, ModelMetaData model, boolean cache, File cacheFile, MetadataStoreGroup vdbStore, ConnectorManagerRepository cmr) {
+		String msg = RuntimePlugin.Util.getString("model_metadata_loading", vdb.getName()+"-"+vdb.getVersion(), model.getName(), SimpleDateFormat.getInstance().format(new Date())); //$NON-NLS-1$ //$NON-NLS-2$
+		final ValidationError addedError = model.addError(ModelMetaData.ValidationError.Severity.ERROR.toString(), msg); 
+		LogManager.logInfo(LogConstants.CTX_RUNTIME, msg);
+
+    	String exceptionMessage = null;
+    	Boolean loaded = false;
     	for (String sourceName: model.getSourceNames()) {
     		ConnectorManager cm = cmr.getConnectorManager(sourceName);
-    		if (cm == null) {
-    			continue;
-    		}
+    		String status = cm.getStausMessage();
+			if (status != null && status.length() > 0) {
+				exceptionMessage = status;
+				continue;
+			}
+			loaded = null;
     		try {
     			MetadataStore store = cm.getMetadata(model.getName(), this.vdbRepository.getBuiltinDatatypes(), model.getProperties());
     			if (cache) {
@@ -333,34 +346,34 @@
     			loaded = true;
     			break;
 			} catch (TranslatorException e) {
-				if (exception == null) {
-					exception = e;
+				//TODO: we aren't effectively differentiating the type of load error - connectivity vs. metadata
+				if (exceptionMessage == null) {
+					exceptionMessage = e.getMessage();
 				}
 			} catch (IOException e) {
-				if (exception == null) {
-					exception = e;
+				if (exceptionMessage == null) {
+					exceptionMessage = e.getMessage();
 				}				
 			}
     	}
     	
     	synchronized (vdb) {
-	    	if (!loaded) {
+	    	if (loaded == null || !loaded) {
 	    		vdb.setStatus(VDB.Status.INACTIVE);
-	    		String msg = RuntimePlugin.Util.getString("failed_to_retrive_metadata", vdb.getName()+"-"+vdb.getVersion(), model.getName()); //$NON-NLS-1$ //$NON-NLS-2$
-		    	model.addError(ModelMetaData.ValidationError.Severity.ERROR.toString(), msg); 
-		    	if (exception != null) {
-		    		model.addError(ModelMetaData.ValidationError.Severity.ERROR.toString(), exception.getMessage());     		
+	    		String failed_msg = RuntimePlugin.Util.getString(loaded==null?"failed_to_retrive_metadata":"nosources_to_retrive_metadata", vdb.getName()+"-"+vdb.getVersion(), model.getName()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+		    	model.addError(ModelMetaData.ValidationError.Severity.ERROR.toString(), failed_msg); 
+		    	if (exceptionMessage != null) {
+		    		model.addError(ModelMetaData.ValidationError.Severity.ERROR.toString(), exceptionMessage);     		
 		    	}
-		    	LogManager.logWarning(LogConstants.CTX_RUNTIME, msg);
+		    	LogManager.logWarning(LogConstants.CTX_RUNTIME, failed_msg);
+	    	} else if (vdb.isValid()) {
+    			this.vdbRepository.updateVDB(vdb.getName(), vdb.getVersion());
+				vdb.setStatus(VDB.Status.ACTIVE);
+				LogManager.logInfo(LogConstants.CTX_RUNTIME, RuntimePlugin.Util.getString("vdb_activated",vdb.getName(), vdb.getVersion())); //$NON-NLS-1$    			
 	    	}
-	    	else {
-	    		if (vdb.isValid()) {
-	    			this.vdbRepository.updateVDB(vdb.getName(), vdb.getVersion());
-					vdb.setStatus(VDB.Status.ACTIVE);
-					LogManager.logInfo(LogConstants.CTX_RUNTIME, RuntimePlugin.Util.getString("vdb_activated",vdb.getName(), vdb.getVersion())); //$NON-NLS-1$    			
-	    		}
-	    	}
     	}
+    	
+    	return loaded;
     }
     
 	private File buildCachedModelFileName(VFSDeploymentUnit unit, VDBMetaData vdb, String modelName) {

Modified: trunk/runtime/src/main/java/org/teiid/deployers/VDBStatusChecker.java
===================================================================
--- trunk/runtime/src/main/java/org/teiid/deployers/VDBStatusChecker.java	2011-02-22 20:58:00 UTC (rev 2923)
+++ trunk/runtime/src/main/java/org/teiid/deployers/VDBStatusChecker.java	2011-02-23 01:33:24 UTC (rev 2924)
@@ -21,6 +21,9 @@
  */
 package org.teiid.deployers;
 
+import java.util.LinkedList;
+
+import org.jboss.util.threadpool.ThreadPool;
 import org.teiid.adminapi.Model;
 import org.teiid.adminapi.VDB;
 import org.teiid.adminapi.impl.ModelMetaData;
@@ -35,6 +38,7 @@
 public class VDBStatusChecker {
 	private static final String JAVA_CONTEXT = "java:"; //$NON-NLS-1$
 	private VDBRepository vdbRepository;
+	private ThreadPool threadPool;
 	
 	public void translatorAdded(String translatorName) {
 		resourceAdded(translatorName, true);
@@ -67,6 +71,7 @@
 			if (vdb.getStatus() == VDB.Status.ACTIVE || vdb.isPreview()) {
 				continue;
 			}
+			LinkedList<Runnable> runnables = new LinkedList<Runnable>();
 			synchronized (vdb) {
 				ConnectorManagerRepository cmr = vdb.getAttachment(ConnectorManagerRepository.class);
 				
@@ -84,7 +89,13 @@
 						if (status != null && status.length() > 0) {
 							model.addError(ModelMetaData.ValidationError.Severity.ERROR.name(), status);
 							LogManager.logInfo(LogConstants.CTX_RUNTIME, status);					
-						}					
+						} else {
+							//get the pending metadata load
+							Runnable r = model.removeAttachment(Runnable.class);
+							if (r != null) {
+								runnables.add(r);
+							}
+						}
 					}
 				}
 	
@@ -97,7 +108,12 @@
 					}
 				}
 				
-				if (valid) {
+				if (!runnables.isEmpty()) {
+					//the task themselves will set the status on completion/failure
+					for (Runnable runnable : runnables) {
+						this.threadPool.run(runnable);
+					}
+				} else if (valid) {
 					vdb.setStatus(VDB.Status.ACTIVE);
 					LogManager.logInfo(LogConstants.CTX_RUNTIME, RuntimePlugin.Util.getString("vdb_activated",vdb.getName(), vdb.getVersion())); //$NON-NLS-1$
 				}
@@ -150,5 +166,9 @@
 			}
 		}
 		return null;
-	}		
+	}
+	
+	public void setThreadPool(ThreadPool threadPool) {
+		this.threadPool = threadPool;
+	}
 }

Modified: trunk/runtime/src/main/resources/org/teiid/runtime/i18n.properties
===================================================================
--- trunk/runtime/src/main/resources/org/teiid/runtime/i18n.properties	2011-02-22 20:58:00 UTC (rev 2923)
+++ trunk/runtime/src/main/resources/org/teiid/runtime/i18n.properties	2011-02-23 01:33:24 UTC (rev 2924)
@@ -58,7 +58,8 @@
 vdb_undeployed=VDB "{0}" undeployed.
 system_vdb_load_error=System.vdb needs to be loaded before any other VDBs.
 fail_to_deploy="{0}" Can not be active because model "{1}" is not fully configured.
-failed_to_retrive_metadata="{0}" is now "incomplete", because model "{1}" can not retrieve metadata. Fix errors and re-deploy the VDB.
+failed_to_retrive_metadata="{0}" is now "incomplete", because model "{1}" can not retrieve metadata. Please fix any errors and re-deploy relevant DataSources and/or the VDB.
+nosources_to_retrive_metadata="{0}" is now "incomplete", because model "{1}" can not retrieve metadata. Please deploy the necessary DataSources.
 invalid_metadata_file=Invalid metadata file found at {0}; delete this file and restart server.
 udf_model_not_found=User Defined Function (UDF) model "{0}" not found in the VDB
 duplicate_vdb=VDB with given name and version already exists! {0}.{1}



More information about the teiid-commits mailing list