Author: rareddy
Date: 2010-08-02 15:12:20 -0400 (Mon, 02 Aug 2010)
New Revision: 2398
Modified:
trunk/runtime/src/main/java/org/teiid/deployers/VDBDeployer.java
trunk/runtime/src/main/resources/org/teiid/runtime/i18n.properties
Log:
TEIID-1006: Load the dynamic VDB's metadata asynchronously using a separate thread
than the deployer thread. The VDB will be marked inacive untill all the metadata loading
is complete.
Modified: trunk/runtime/src/main/java/org/teiid/deployers/VDBDeployer.java
===================================================================
--- trunk/runtime/src/main/java/org/teiid/deployers/VDBDeployer.java 2010-08-02 16:14:26
UTC (rev 2397)
+++ trunk/runtime/src/main/java/org/teiid/deployers/VDBDeployer.java 2010-08-02 19:12:20
UTC (rev 2398)
@@ -23,6 +23,8 @@
import java.io.File;
import java.io.IOException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
import java.util.IdentityHashMap;
import java.util.LinkedHashMap;
import java.util.List;
@@ -32,6 +34,7 @@
import org.jboss.deployers.spi.deployer.helpers.AbstractSimpleRealDeployer;
import org.jboss.deployers.structure.spi.DeploymentUnit;
import org.jboss.deployers.vfs.spi.structure.VFSDeploymentUnit;
+import org.jboss.util.threadpool.ThreadPool;
import org.teiid.adminapi.Model;
import org.teiid.adminapi.Translator;
import org.teiid.adminapi.VDB;
@@ -61,6 +64,7 @@
private TranslatorRepository translatorRepository;
private ObjectSerializer serializer;
private ContainerLifeCycleListener shutdownListener;
+ private ThreadPool threadPool;
public VDBDeployer() {
super(VDBMetaData.class);
@@ -110,14 +114,8 @@
// if store is null and vdb dynamic vdb then try to get the metadata
if (store == null && deployment.isDynamic()) {
- MetadataStoreGroup dynamicStore = new MetadataStoreGroup();
- for (Model model:deployment.getModels()) {
- if (model.getName().equals(CoreConstants.SYSTEM_MODEL) ||
model.getName().equals(CoreConstants.ODBC_MODEL)){
- continue;
- }
- dynamicStore.addStore(buildDynamicMetadataStore((VFSDeploymentUnit)unit, deployment,
(ModelMetaData)model));
- }
- store = dynamicStore;
+ store = new MetadataStoreGroup();
+ buildDynamicMetadataStore((VFSDeploymentUnit)unit, deployment, store);
}
// allow empty vdbs for enabling the preview functionality
@@ -217,6 +215,11 @@
LogManager.logInfo(LogConstants.CTX_RUNTIME, cm.getStausMessage());
}
}
+
+ // in the dynamic case the metadata may be still loading.
+ if (!model.getErrors().isEmpty()) {
+ valid = false;
+ }
}
return valid;
}
@@ -281,22 +284,55 @@
}
}
- private MetadataStore buildDynamicMetadataStore(VFSDeploymentUnit unit, VDBMetaData
vdb, ModelMetaData model) throws DeploymentException{
- if (model.getSourceNames().isEmpty()) {
- throw new
DeploymentException(RuntimePlugin.Util.getString("fail_to_deploy",
vdb.getName()+"-"+vdb.getVersion(), model.getName())); //$NON-NLS-1$
//$NON-NLS-2$
- }
+ private void buildDynamicMetadataStore(final VFSDeploymentUnit unit, final
VDBMetaData vdb, final MetadataStoreGroup vdbStore) throws DeploymentException {
- boolean cache =
"cached".equalsIgnoreCase(vdb.getPropertyValue("UseConnectorMetadata"));
//$NON-NLS-1$ //$NON-NLS-2$
- File cacheFile = null;
- if (cache) {
- cacheFile = buildCachedFileName(unit, vdb,model.getName());
- MetadataStore store = this.serializer.loadSafe(cacheFile, MetadataStore.class);
- if (store != null) {
- return store;
+ // make sure we are configured correctly first
+ for (Model model:vdb.getModels()) {
+ if (model.getName().equals(CoreConstants.SYSTEM_MODEL) ||
model.getName().equals(CoreConstants.ODBC_MODEL)){
+ continue;
}
- }
+
+ if (model.getSourceNames().isEmpty()) {
+ throw new
DeploymentException(RuntimePlugin.Util.getString("fail_to_deploy",
vdb.getName()+"-"+vdb.getVersion(), model.getName())); //$NON-NLS-1$
//$NON-NLS-2$
+ }
+ }
+
+ // check the cache files first; if not found load the metadata
+ for (Model m:vdb.getModels()) {
+ final ModelMetaData model = (ModelMetaData)m;
+ if (model.getName().equals(CoreConstants.SYSTEM_MODEL) ||
model.getName().equals(CoreConstants.ODBC_MODEL)){
+ continue;
+ }
+
+ final boolean cache =
"cached".equalsIgnoreCase(vdb.getPropertyValue("UseConnectorMetadata"));
//$NON-NLS-1$ //$NON-NLS-2$
+ final File cacheFile = buildCachedFileName(unit, vdb, model.getName());
+ boolean loaded = false;
+ if (cache) {
+ MetadataStore store = this.serializer.loadSafe(cacheFile, MetadataStore.class);
+ if (store != null) {
+ vdbStore.addStore(store);
+ loaded = true;
+ }
+ }
+
+ 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$
+ 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);
+ }
+ });
+ }
+ }
+ }
+
+ private void loadMetadata(VDBMetaData vdb, ModelMetaData model, boolean cache, File
cacheFile, MetadataStoreGroup vdbStore) {
+ Exception exception = null;
- Exception exception = null;
+ boolean loaded = false;;
for (String sourceName: model.getSourceNames()) {
ConnectorManager cm =
this.connectorManagerRepository.getConnectorManager(sourceName);
if (cm == null) {
@@ -307,7 +343,10 @@
if (cache) {
this.serializer.saveAttachment(cacheFile, store);
}
- return store;
+ vdbStore.addStore(store);
+ model.clearErrors();
+ loaded = true;
+ break;
} catch (TranslatorException e) {
if (exception == null) {
exception = e;
@@ -318,8 +357,25 @@
}
}
}
- throw new
DeploymentException(RuntimePlugin.Util.getString("failed_to_retrive_metadata",
vdb.getName()+"-"+vdb.getVersion(), model.getName()), exception); //$NON-NLS-1$
//$NON-NLS-2$
- }
+
+ synchronized (this) {
+ if (!loaded) {
+ vdb.setStatus(VDB.Status.INCOMPLETE);
+ 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());
+ }
+ LogManager.logWarning(LogConstants.CTX_RUNTIME, msg);
+ }
+ else {
+ if (vdb.isValid()) {
+ vdb.setStatus(VDB.Status.ACTIVE);
+ LogManager.logInfo(LogConstants.CTX_RUNTIME,
RuntimePlugin.Util.getString("vdb_activated",vdb.getName(), vdb.getVersion()));
//$NON-NLS-1$
+ }
+ }
+ }
+ }
private File buildCachedFileName(VFSDeploymentUnit unit, VDBMetaData vdb, String
modelName) {
return this.serializer.getAttachmentPath(unit,
vdb.getName()+"_"+vdb.getVersion()+"_"+modelName); //$NON-NLS-1$
//$NON-NLS-2$
@@ -332,4 +388,8 @@
public void setContainerLifeCycleListener(ContainerLifeCycleListener listener) {
shutdownListener = listener;
}
+
+ public void setThreadPool(ThreadPool pool) {
+ this.threadPool = pool;
+ }
}
Modified: trunk/runtime/src/main/resources/org/teiid/runtime/i18n.properties
===================================================================
--- trunk/runtime/src/main/resources/org/teiid/runtime/i18n.properties 2010-08-02 16:14:26
UTC (rev 2397)
+++ trunk/runtime/src/main/resources/org/teiid/runtime/i18n.properties 2010-08-02 19:12:20
UTC (rev 2398)
@@ -285,8 +285,8 @@
vdb_deployed=VDB "{0}" deployed in {1} state.
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 deployed because model "{1}" is not
fully configured.
-failed_to_retrive_metadata="{0}" Can not be deployed because model
"{1}" can not retrieve metadata.
+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.
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}
@@ -312,4 +312,5 @@
bad_binding=Binding on a statement, that has not been prepared:{0}
not_bound=No bound statement found with name {0}
no_stmt_found=No prepared statement found with name {0}
-error_closing_stmt=Error closing portal statement {0}
\ No newline at end of file
+error_closing_stmt=Error closing portal statement {0}
+model_metadata_loading=VDB "{0}" - "{1}" model metadata is currently
being loaded. Start Time: {2}
\ No newline at end of file