Author: rareddy
Date: 2012-06-21 15:07:57 -0400 (Thu, 21 Jun 2012)
New Revision: 4195
Modified:
trunk/admin/src/main/java/org/teiid/adminapi/Admin.java
trunk/admin/src/main/java/org/teiid/adminapi/AdminFactory.java
trunk/admin/src/main/java/org/teiid/adminapi/impl/VDBMetaData.java
trunk/adminshell/src/main/java/org/teiid/adminshell/AdminShell.java
trunk/common-core/src/main/java/org/teiid/core/util/FileUtils.java
trunk/engine/src/main/java/org/teiid/dqp/internal/datamgr/ConnectorWorkItem.java
trunk/engine/src/main/java/org/teiid/query/metadata/NativeMetadataRepository.java
trunk/jboss-integration/src/main/java/org/teiid/jboss/ObjectSerializer.java
trunk/jboss-integration/src/main/java/org/teiid/jboss/OperationsConstants.java
trunk/jboss-integration/src/main/java/org/teiid/jboss/TeiidExtension.java
trunk/jboss-integration/src/main/java/org/teiid/jboss/TeiidOperationHandler.java
trunk/jboss-integration/src/main/java/org/teiid/jboss/TeiidServiceNames.java
trunk/jboss-integration/src/main/java/org/teiid/jboss/VDBDeployer.java
trunk/jboss-integration/src/main/java/org/teiid/jboss/VDBService.java
trunk/jboss-integration/src/main/resources/org/teiid/jboss/i18n.properties
trunk/jboss-integration/src/test/java/org/teiid/jboss/TestTeiidConfiguration.java
trunk/metadata/src/main/java/org/teiid/metadata/index/IndexMetadataRepository.java
trunk/runtime/src/main/java/org/teiid/deployers/RuntimeVDB.java
trunk/runtime/src/main/java/org/teiid/runtime/EmbeddedServer.java
trunk/test-integration/common/src/test/java/org/teiid/arquillian/IntegrationTestDeployment.java
trunk/test-integration/common/src/test/java/org/teiid/arquillian/SampleExecutionFactory.java
Log:
TEIID-1328: adding "restart" option for the VDB, with ability to delete the
cached metadata from previous deployment.
Modified: trunk/admin/src/main/java/org/teiid/adminapi/Admin.java
===================================================================
--- trunk/admin/src/main/java/org/teiid/adminapi/Admin.java 2012-06-21 16:50:23 UTC (rev
4194)
+++ trunk/admin/src/main/java/org/teiid/adminapi/Admin.java 2012-06-21 19:07:57 UTC (rev
4195)
@@ -90,6 +90,16 @@
* @return
*/
VDB getVDB(String vdbName, int vdbVersion) throws AdminException;
+
+ /**
+ * Restart the VDB. This issues reload of the metadata.
+ * @param vdbName
+ * @param vbdVersion
+ * @param models names for which metadata needs to be reloaded, if null or not
supplied all models reloaded
+ * @throws AdminException
+ * @return
+ */
+ void restartVDB(String vdbName, int vdbVersion, String... models) throws
AdminException;
/**
* Get the translators that are available in the configuration
Modified: trunk/admin/src/main/java/org/teiid/adminapi/AdminFactory.java
===================================================================
--- trunk/admin/src/main/java/org/teiid/adminapi/AdminFactory.java 2012-06-21 16:50:23 UTC
(rev 4194)
+++ trunk/admin/src/main/java/org/teiid/adminapi/AdminFactory.java 2012-06-21 19:07:57 UTC
(rev 4195)
@@ -1301,6 +1301,42 @@
} catch (Exception e) {
throw new AdminProcessingException(AdminPlugin.Event.TEIID70050, e);
}
- }
+ }
+
+ @Override
+ public void restartVDB(String vdbName, int vdbVersion, String... models) throws
AdminException {
+ ModelNode request = null;
+ String modelNames = null;
+
+ if (models != null && models.length > 0) {
+ StringBuilder sb = new StringBuilder();
+ for (int i = 0; i < models.length-1; i++) {
+ sb.append(models[i]).append(",");
+ }
+ sb.append(models[models.length-1]);
+ modelNames = sb.toString();
+ }
+
+ if (modelNames != null) {
+ request = buildRequest("teiid", "restart-vdb",
+ "vdb-name", vdbName,
+ "vdb-version", String.valueOf(vdbVersion),
+ "model-names", modelNames);//$NON-NLS-1$ //$NON-NLS-2$
+ }
+ else {
+ request = buildRequest("teiid", "restart-vdb",
+ "vdb-name", vdbName,
+ "vdb-version", String.valueOf(vdbVersion));//$NON-NLS-1$
+ }
+
+ try {
+ ModelNode outcome = this.connection.execute(request);
+ if (!Util.isSuccess(outcome)) {
+ throw new AdminProcessingException(AdminPlugin.Event.TEIID70045,
Util.getFailureDescription(outcome));
+ }
+ } catch (Exception e) {
+ throw new AdminProcessingException(AdminPlugin.Event.TEIID70046, e);
+ }
+ }
}
}
Modified: trunk/admin/src/main/java/org/teiid/adminapi/impl/VDBMetaData.java
===================================================================
--- trunk/admin/src/main/java/org/teiid/adminapi/impl/VDBMetaData.java 2012-06-21 16:50:23
UTC (rev 4194)
+++ trunk/admin/src/main/java/org/teiid/adminapi/impl/VDBMetaData.java 2012-06-21 19:07:57
UTC (rev 4195)
@@ -83,9 +83,6 @@
public synchronized void setStatus(Status s) {
this.notifyAll();
- if (this.status == Status.REMOVED) {
- return;
- }
this.status = s;
}
Modified: trunk/adminshell/src/main/java/org/teiid/adminshell/AdminShell.java
===================================================================
--- trunk/adminshell/src/main/java/org/teiid/adminshell/AdminShell.java 2012-06-21
16:50:23 UTC (rev 4194)
+++ trunk/adminshell/src/main/java/org/teiid/adminshell/AdminShell.java 2012-06-21
19:07:57 UTC (rev 4195)
@@ -334,6 +334,15 @@
return getAdmin().getDataSourceTemplateNames();
}
+ @Doc(text = "Restart the VDB")
+ public static void restartVDB(
+ @Doc(text = "vdb name") String vdbName,
+ @Doc(text = "vdb version") int vdbVersion,
+ @Doc(text = "models") String... models)
+ throws AdminException {
+ getAdmin().restartVDB(vdbName, vdbVersion, models);
+ }
+
@Doc(text = "Get the current org.teiid.adminapi.Admin instance for direct use.
Note: Used for advanced usecases to bypass AdminShell methods")
public static Admin getAdmin() {
if (internalAdmin == null) {
Modified: trunk/common-core/src/main/java/org/teiid/core/util/FileUtils.java
===================================================================
--- trunk/common-core/src/main/java/org/teiid/core/util/FileUtils.java 2012-06-21 16:50:23
UTC (rev 4194)
+++ trunk/common-core/src/main/java/org/teiid/core/util/FileUtils.java 2012-06-21 19:07:57
UTC (rev 4195)
@@ -766,8 +766,11 @@
}
-
-
+ public static void remove(File file) {
+ if (file.exists()) {
+ file.delete();
+ }
+ }
public static void remove(String filePath) throws IOException {
File file = new File(filePath);
Modified:
trunk/engine/src/main/java/org/teiid/dqp/internal/datamgr/ConnectorWorkItem.java
===================================================================
---
trunk/engine/src/main/java/org/teiid/dqp/internal/datamgr/ConnectorWorkItem.java 2012-06-21
16:50:23 UTC (rev 4194)
+++
trunk/engine/src/main/java/org/teiid/dqp/internal/datamgr/ConnectorWorkItem.java 2012-06-21
19:07:57 UTC (rev 4195)
@@ -197,8 +197,10 @@
LogManager.logDetail(LogConstants.CTX_CONNECTOR, new Object[]
{this.requestMsg.getAtomicRequestID(), "Processing NEW request:",
this.requestMsg.getCommand()}); //$NON-NLS-1$
try {
- this.connectionFactory = this.manager.getConnectionFactory();
- this.connection = this.connector.getConnection(this.connectionFactory,
securityContext);
+ if (this.connector.isSourceRequired()) {
+ this.connectionFactory = this.manager.getConnectionFactory();
+ this.connection = this.connector.getConnection(this.connectionFactory,
securityContext);
+ }
Object unwrapped = null;
if (connection instanceof WrappedConnection) {
Modified:
trunk/engine/src/main/java/org/teiid/query/metadata/NativeMetadataRepository.java
===================================================================
---
trunk/engine/src/main/java/org/teiid/query/metadata/NativeMetadataRepository.java 2012-06-21
16:50:23 UTC (rev 4194)
+++
trunk/engine/src/main/java/org/teiid/query/metadata/NativeMetadataRepository.java 2012-06-21
19:07:57 UTC (rev 4195)
@@ -43,7 +43,7 @@
throw new TranslatorException(QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30591,
factory.getName()));
}
- if (connectionFactory == null) {
+ if (connectionFactory == null && executionFactory.isSourceRequired()) {
throw new TranslatorException(QueryPlugin.Event.TEIID31097,
QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31097));
}
Modified: trunk/jboss-integration/src/main/java/org/teiid/jboss/ObjectSerializer.java
===================================================================
--- trunk/jboss-integration/src/main/java/org/teiid/jboss/ObjectSerializer.java 2012-06-21
16:50:23 UTC (rev 4194)
+++ trunk/jboss-integration/src/main/java/org/teiid/jboss/ObjectSerializer.java 2012-06-21
19:07:57 UTC (rev 4195)
@@ -106,6 +106,10 @@
String dirName = baseDirectory(vdb.getName()+"_"+vdb.getVersion());
//$NON-NLS-1$
FileUtils.removeDirectoryAndChildren(new File(dirName));
}
+
+ public void removeAttachment(File file) {
+ FileUtils.remove(file);
+ }
private String baseDirectory(String fileName) {
String dirName = this.storagePath + File.separator + fileName + File.separator;
Modified: trunk/jboss-integration/src/main/java/org/teiid/jboss/OperationsConstants.java
===================================================================
---
trunk/jboss-integration/src/main/java/org/teiid/jboss/OperationsConstants.java 2012-06-21
16:50:23 UTC (rev 4194)
+++
trunk/jboss-integration/src/main/java/org/teiid/jboss/OperationsConstants.java 2012-06-21
19:07:57 UTC (rev 4195)
@@ -35,6 +35,7 @@
public static final String SOURCE_NAME = "source-name"; //$NON-NLS-1$
public static final String DS_NAME = "ds-name"; //$NON-NLS-1$
public static final String RAR_NAME = "rar-name"; //$NON-NLS-1$
+ public static final String MODEL_NAMES = "model-names"; //$NON-NLS-1$
public static final String SOURCE_VDBNAME = "source-vdb-name";//$NON-NLS-1$
public static final String SOURCE_VDBVERSION =
"source-vdb-version";//$NON-NLS-1$
Modified: trunk/jboss-integration/src/main/java/org/teiid/jboss/TeiidExtension.java
===================================================================
--- trunk/jboss-integration/src/main/java/org/teiid/jboss/TeiidExtension.java 2012-06-21
16:50:23 UTC (rev 4194)
+++ trunk/jboss-integration/src/main/java/org/teiid/jboss/TeiidExtension.java 2012-06-21
19:07:57 UTC (rev 4195)
@@ -130,6 +130,7 @@
new AddDataRole().register(teiidSubsystem);
new RemoveDataRole().register(teiidSubsystem);
new AddAnyAuthenticatedDataRole().register(teiidSubsystem);
+ new RestartVDB().register(teiidSubsystem);
new AssignDataSource().register(teiidSubsystem);
new ChangeVDBConnectionType().register(teiidSubsystem);
new RemoveAnyAuthenticatedDataRole().register(teiidSubsystem);
Modified:
trunk/jboss-integration/src/main/java/org/teiid/jboss/TeiidOperationHandler.java
===================================================================
---
trunk/jboss-integration/src/main/java/org/teiid/jboss/TeiidOperationHandler.java 2012-06-21
16:50:23 UTC (rev 4194)
+++
trunk/jboss-integration/src/main/java/org/teiid/jboss/TeiidOperationHandler.java 2012-06-21
19:07:57 UTC (rev 4195)
@@ -1158,6 +1158,40 @@
}
}
+class RestartVDB extends VDBOperations {
+
+ public RestartVDB() {
+ super("restart-vdb"); //$NON-NLS-1$
+ }
+
+ @Override
+ protected void executeOperation(OperationContext context, RuntimeVDB vdb, ModelNode
operation) throws OperationFailedException {
+ List<String> models = new ArrayList<String>();
+ if (operation.hasDefined(OperationsConstants.MODEL_NAMES)) {
+ String modelNames = operation.get(OperationsConstants.MODEL_NAMES).asString();
+ for (String model:modelNames.split(",")) { //$NON-NLS-1$
+ models.add(model.trim());
+ }
+ }
+
+ try {
+ vdb.restart(models);
+ } catch (AdminProcessingException e) {
+ throw new OperationFailedException(new ModelNode().set(e.getMessage()));
+ }
+ }
+
+ @Override
+ protected void describeParameters(ModelNode operationNode, ResourceBundle bundle) {
+ super.describeParameters(operationNode, bundle);
+
+ operationNode.get(REQUEST_PROPERTIES, OperationsConstants.MODEL_NAMES,
TYPE).set(ModelType.STRING);
+ operationNode.get(REQUEST_PROPERTIES, OperationsConstants.MODEL_NAMES,
REQUIRED).set(false);
+ operationNode.get(REQUEST_PROPERTIES, OperationsConstants.MODEL_NAMES,
DESCRIPTION).set(getParameterDescription(bundle, OperationsConstants.MODEL_NAMES));
+ operationNode.get(REPLY_PROPERTIES).setEmptyObject();
+ }
+}
+
class AssignDataSource extends VDBOperations {
public AssignDataSource() {
Modified: trunk/jboss-integration/src/main/java/org/teiid/jboss/TeiidServiceNames.java
===================================================================
---
trunk/jboss-integration/src/main/java/org/teiid/jboss/TeiidServiceNames.java 2012-06-21
16:50:23 UTC (rev 4194)
+++
trunk/jboss-integration/src/main/java/org/teiid/jboss/TeiidServiceNames.java 2012-06-21
19:07:57 UTC (rev 4195)
@@ -38,6 +38,7 @@
public static ServiceName AUTHORIZATION_VALIDATOR =
ServiceName.JBOSS.append("teiid",
"authorization-validator");//$NON-NLS-1$ //$NON-NLS-2$
private static ServiceName VDB_SVC_BASE = ServiceName.JBOSS.append("teiid",
"vdb"); //$NON-NLS-1$ //$NON-NLS-2$
private static ServiceName VDB_FINISHED_SVC_BASE =
ServiceName.JBOSS.append("teiid", "vdb-finished"); //$NON-NLS-1$
//$NON-NLS-2$
+ private static ServiceName VDB_SWITCH_SVC_BASE =
ServiceName.JBOSS.append("teiid", "switch"); //$NON-NLS-1$
//$NON-NLS-2$
public static ServiceName OBJECT_SERIALIZER =
ServiceName.JBOSS.append("teiid", "object-serializer"); //$NON-NLS-1$
//$NON-NLS-2$
public static ServiceName CACHE_RESULTSET = ServiceName.JBOSS.append("teiid",
"cache", "resultset"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
public static ServiceName CACHE_PREPAREDPLAN =
ServiceName.JBOSS.append("teiid", "cache", "prepared-plan");
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
@@ -58,6 +59,10 @@
return VDB_FINISHED_SVC_BASE.append(vdbName, String.valueOf(version));
}
+ public static ServiceName vdbSwitchServiceName(String vdbName, int version) {
+ return VDB_SWITCH_SVC_BASE.append(vdbName, String.valueOf(version));
+ }
+
public static ServiceName executorServiceName(String poolName) {
return ServiceName.JBOSS.append("thread", "executor", poolName);
//$NON-NLS-1$ //$NON-NLS-2$
}
Modified: trunk/jboss-integration/src/main/java/org/teiid/jboss/VDBDeployer.java
===================================================================
--- trunk/jboss-integration/src/main/java/org/teiid/jboss/VDBDeployer.java 2012-06-21
16:50:23 UTC (rev 4194)
+++ trunk/jboss-integration/src/main/java/org/teiid/jboss/VDBDeployer.java 2012-06-21
19:07:57 UTC (rev 4195)
@@ -23,25 +23,18 @@
import java.util.LinkedHashMap;
import java.util.List;
+import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Executor;
+import java.util.concurrent.TimeUnit;
import org.jboss.as.naming.deployment.ContextNames;
-import org.jboss.as.server.deployment.Attachments;
-import org.jboss.as.server.deployment.DeploymentPhaseContext;
-import org.jboss.as.server.deployment.DeploymentUnit;
-import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
-import org.jboss.as.server.deployment.DeploymentUnitProcessor;
+import org.jboss.as.server.deployment.*;
import org.jboss.modules.Module;
-import org.jboss.msc.service.Service;
-import org.jboss.msc.service.ServiceBuilder;
-import org.jboss.msc.service.ServiceController;
-import org.jboss.msc.service.ServiceName;
-import org.jboss.msc.service.StartContext;
-import org.jboss.msc.service.StartException;
-import org.jboss.msc.service.StopContext;
+import org.jboss.msc.service.*;
import org.jboss.msc.service.ServiceBuilder.DependencyType;
import org.jboss.msc.service.ServiceController.Mode;
import org.jboss.msc.service.ServiceController.State;
+import org.jboss.msc.value.InjectedValue;
import org.teiid.adminapi.Model;
import org.teiid.adminapi.Translator;
import org.teiid.adminapi.VDBImport;
@@ -139,10 +132,11 @@
visibilityMap = indexFactory.getEntriesPlusVisibilities();
}
// build a VDB service
- VDBService vdb = new VDBService(deployment, visibilityMap);
+ final VDBService vdb = new VDBService(deployment, visibilityMap);
if (indexRepo != null) {
vdb.addMetadataRepository("index", indexRepo); //$NON-NLS-1$
}
+
final ServiceBuilder<RuntimeVDB> vdbService =
context.getServiceTarget().addService(TeiidServiceNames.vdbServiceName(deployment.getName(),
deployment.getVersion()), vdb);
// add dependencies to data-sources
@@ -173,17 +167,71 @@
}
}
+ ServiceName vdbSwitchServiceName =
TeiidServiceNames.vdbSwitchServiceName(deployment.getName(), deployment.getVersion());
vdbService.addDependency(TeiidServiceNames.VDB_REPO, VDBRepository.class,
vdb.vdbRepositoryInjector);
vdbService.addDependency(TeiidServiceNames.TRANSLATOR_REPO, TranslatorRepository.class,
vdb.translatorRepositoryInjector);
vdbService.addDependency(TeiidServiceNames.executorServiceName(this.asyncThreadPoolName),
Executor.class, vdb.executorInjector);
vdbService.addDependency(TeiidServiceNames.OBJECT_SERIALIZER, ObjectSerializer.class,
vdb.serializerInjector);
vdbService.addDependency(TeiidServiceNames.BUFFER_MGR, BufferManager.class,
vdb.bufferManagerInjector);
vdbService.addDependency(TeiidServiceNames.VDB_STATUS_CHECKER, VDBStatusChecker.class,
vdb.vdbStatusCheckInjector);
+ vdbService.addDependency(vdbSwitchServiceName, CountDownLatch.class, new
InjectedValue<CountDownLatch>());
+ vdbService.addDependency(DependencyType.OPTIONAL, TeiidServiceNames.OBJECT_REPLICATOR,
ObjectReplicator.class, vdb.objectReplicatorInjector);
- vdbService.addDependency(DependencyType.OPTIONAL, TeiidServiceNames.OBJECT_REPLICATOR,
ObjectReplicator.class, vdb.objectReplicatorInjector);
+ // VDB restart switch, control the vdbservice by adding removing the switch service. If
you
+ // remove the service by setting status remove, there is no way start it back up if
vdbservice used alone
+ installVDBSwitchService(context.getServiceTarget(), vdbSwitchServiceName);
+
+ vdbService.addListener(new AbstractServiceListener<Object>() {
+ @Override
+ public void transition(final ServiceController controller, final
ServiceController.Transition transition) {
+ if (transition.equals(ServiceController.Transition.DOWN_to_WAITING)) {
+ RuntimeVDB runtimeVDB = RuntimeVDB.class.cast(controller.getValue());
+ if (runtimeVDB != null && runtimeVDB.isRestartInProgress()) {
+ ServiceName vdbSwitchServiceName =
TeiidServiceNames.vdbSwitchServiceName(deployment.getName(), deployment.getVersion());
+ ServiceController<?> switchSvc =
controller.getServiceContainer().getService(vdbSwitchServiceName);
+ if (switchSvc != null) {
+ CountDownLatch latch = CountDownLatch.class.cast(switchSvc.getValue());
+ try {
+ latch.await(5, TimeUnit.SECONDS);
+ } catch (InterruptedException e) {
+ // todo:log it?
+ }
+ }
+ installVDBSwitchService(controller.getServiceContainer(),
vdbSwitchServiceName);
+ }
+ }
+ }
+ });
vdbService.setInitialMode(Mode.PASSIVE).install();
}
+ private void installVDBSwitchService(final ServiceTarget serviceTarget, ServiceName
vdbSwitchServiceName) {
+ // install switch service now.
+ ServiceBuilder<CountDownLatch> svc =
serviceTarget.addService(vdbSwitchServiceName, new Service<CountDownLatch>() {
+ private CountDownLatch latch = new CountDownLatch(1);
+ @Override
+ public CountDownLatch getValue() throws IllegalStateException,IllegalArgumentException
{
+ return this.latch;
+ }
+ @Override
+ public void start(StartContext context) throws StartException {
+ }
+ @Override
+ public void stop(StopContext context) {
+ }
+ });
+ svc.addListener(new AbstractServiceListener<Object>() {
+ @Override
+ public void transition(final ServiceController controller, final
ServiceController.Transition transition) {
+ if (transition.equals(ServiceController.Transition.REMOVING_to_REMOVED)) {
+ CountDownLatch latch = CountDownLatch.class.cast(controller.getValue());
+ latch.countDown();
+ }
+ }
+ });
+ svc.install();
+ }
+
private void dataSourceDependencies(VDBMetaData deployment, DependentServices
svcListener) {
for (ModelMetaData model:deployment.getModelMetaDatas().values()) {
Modified: trunk/jboss-integration/src/main/java/org/teiid/jboss/VDBService.java
===================================================================
--- trunk/jboss-integration/src/main/java/org/teiid/jboss/VDBService.java 2012-06-21
16:50:23 UTC (rev 4194)
+++ trunk/jboss-integration/src/main/java/org/teiid/jboss/VDBService.java 2012-06-21
19:07:57 UTC (rev 4195)
@@ -24,15 +24,7 @@
import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.HashSet;
-import java.util.IdentityHashMap;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.ServiceLoader;
-import java.util.Set;
+import java.util.*;
import java.util.concurrent.Executor;
import java.util.concurrent.atomic.AtomicInteger;
@@ -42,13 +34,7 @@
import org.jboss.modules.ModuleIdentifier;
import org.jboss.modules.ModuleLoadException;
import org.jboss.modules.ModuleLoader;
-import org.jboss.msc.service.Service;
-import org.jboss.msc.service.ServiceBuilder;
-import org.jboss.msc.service.ServiceContainer;
-import org.jboss.msc.service.ServiceController;
-import org.jboss.msc.service.StartContext;
-import org.jboss.msc.service.StartException;
-import org.jboss.msc.service.StopContext;
+import org.jboss.msc.service.*;
import org.jboss.msc.value.InjectedValue;
import org.teiid.adminapi.AdminProcessingException;
import org.teiid.adminapi.Translator;
@@ -58,18 +44,11 @@
import org.teiid.adminapi.impl.VDBTranslatorMetaData;
import org.teiid.common.buffer.BufferManager;
import org.teiid.core.TeiidException;
-import org.teiid.deployers.CompositeVDB;
-import org.teiid.deployers.RuntimeVDB;
-import org.teiid.deployers.TranslatorUtil;
-import org.teiid.deployers.UDFMetaData;
-import org.teiid.deployers.VDBLifeCycleListener;
-import org.teiid.deployers.VDBRepository;
-import org.teiid.deployers.VDBStatusChecker;
-import org.teiid.deployers.VirtualDatabaseException;
+import org.teiid.deployers.*;
import org.teiid.dqp.internal.datamgr.ConnectorManager;
import org.teiid.dqp.internal.datamgr.ConnectorManagerRepository;
+import
org.teiid.dqp.internal.datamgr.ConnectorManagerRepository.ConnectorManagerException;
import org.teiid.dqp.internal.datamgr.TranslatorRepository;
-import
org.teiid.dqp.internal.datamgr.ConnectorManagerRepository.ConnectorManagerException;
import org.teiid.logging.LogConstants;
import org.teiid.logging.LogManager;
import org.teiid.metadata.Datatype;
@@ -185,10 +164,10 @@
throw new StartException(e);
}
- this.runtimeVDB = buildRuntimeVDB(this.vdb);
+ this.runtimeVDB = buildRuntimeVDB(this.vdb,
context.getController().getServiceContainer());
}
- private RuntimeVDB buildRuntimeVDB(VDBMetaData vdbMetadata) {
+ private RuntimeVDB buildRuntimeVDB(final VDBMetaData vdbMetadata, final ServiceContainer
serviceContainer) {
RuntimeVDB.VDBModificationListener modificationListener = new
RuntimeVDB.VDBModificationListener() {
@Override
public void dataRoleChanged(String policyName) throws AdminProcessingException {
@@ -202,6 +181,23 @@
public void dataSourceChanged(String modelName, String sourceName,String
translatorName, String dsName) throws AdminProcessingException {
save();
}
+ @Override
+ public void onRestart(List<String> modelNames) {
+ ServiceController<?> switchSvc =
serviceContainer.getService(TeiidServiceNames.vdbSwitchServiceName(vdbMetadata.getName(),
vdbMetadata.getVersion()));
+ if (switchSvc != null) {
+ if (!modelNames.isEmpty()) {
+ for (String model:modelNames) {
+ deleteModelCache(model);
+ }
+ }
+ else {
+ for (String model:vdbMetadata.getModelMetaDatas().keySet()) {
+ deleteModelCache(model);
+ }
+ }
+ switchSvc.setMode(ServiceController.Mode.REMOVE);
+ }
+ }
};
return new RuntimeVDB(vdbMetadata, modificationListener) {
protected VDBStatusChecker getVDBStatusChecker() {
@@ -209,6 +205,19 @@
}
};
}
+
+ Service<Void> createVoidService() {
+ return new Service<Void>() {
+ @Override
+ public Void getValue() throws IllegalStateException, IllegalArgumentException {
+ return null;
+ }
+ @Override
+ public void start(StartContext sc)throws StartException {}
+ @Override
+ public void stop(StopContext sc) {}
+ };
+ }
private ServiceBuilder<Void> addVDBFinishedService(StartContext context) {
ServiceContainer serviceContainer = context.getController().getServiceContainer();
@@ -216,28 +225,15 @@
if (controller != null) {
controller.setMode(ServiceController.Mode.REMOVE);
}
- return
serviceContainer.addService(TeiidServiceNames.vdbFinishedServiceName(vdb.getName(),
vdb.getVersion()), new Service<Void>() {
- @Override
- public Void getValue() throws IllegalStateException,
- IllegalArgumentException {
- return null;
- }
-
- @Override
- public void start(StartContext sc)
- throws StartException {
-
- }
-
- @Override
- public void stop(StopContext sc) {
-
- }
- });
+ return
serviceContainer.addService(TeiidServiceNames.vdbFinishedServiceName(vdb.getName(),
vdb.getVersion()), createVoidService());
}
@Override
public void stop(StopContext context) {
+ ServiceController<?> switchSvc =
context.getController().getServiceContainer().getService(TeiidServiceNames.vdbSwitchServiceName(vdb.getName(),
vdb.getVersion()));
+ if (switchSvc != null) {
+ switchSvc.setMode(ServiceController.Mode.REMOVE);
+ }
// stop object replication
if (this.objectReplicatorInjector.getValue() != null) {
GlobalTableStore gts = vdb.getAttachment(GlobalTableStore.class);
@@ -248,7 +244,7 @@
final ServiceController<?> controller =
context.getController().getServiceContainer().getService(TeiidServiceNames.vdbFinishedServiceName(vdb.getName(),
vdb.getVersion()));
if (controller != null) {
controller.setMode(ServiceController.Mode.REMOVE);
- }
+ }
LogManager.logInfo(LogConstants.CTX_RUNTIME,
IntegrationPlugin.Util.gs(IntegrationPlugin.Event.TEIID50026, this.vdb));
}
@@ -347,8 +343,12 @@
try {
ConnectorManager cm = getConnectorManager(model, cmr);
- ef = ((cm == null)?null:cm.getExecutionFactory());
- cf = ((cm == null)?null:cm.getConnectionFactory());
+ if (cm != null) {
+ ef = cm.getExecutionFactory();
+ if (ef.isSourceRequired()) {
+ cf = cm.getConnectionFactory();
+ }
+ }
} catch (TranslatorException e1) {
//ignore data source not availability, it may not be required.
}
@@ -413,6 +413,11 @@
}
}
}
+
+ private void deleteModelCache(String modelName) {
+ final File cachedFile = getSerializer().buildModelFile(vdb, modelName);
+ getSerializer().removeAttachment(cachedFile);
+ }
protected VDBRepository getVDBRepository() {
return vdbRepositoryInjector.getValue();
Modified: trunk/jboss-integration/src/main/resources/org/teiid/jboss/i18n.properties
===================================================================
--- trunk/jboss-integration/src/main/resources/org/teiid/jboss/i18n.properties 2012-06-21
16:50:23 UTC (rev 4194)
+++ trunk/jboss-integration/src/main/resources/org/teiid/jboss/i18n.properties 2012-06-21
19:07:57 UTC (rev 4195)
@@ -208,6 +208,8 @@
source-name.missing=Parameter "source-name" is required
ds-name.missing=Parameter "ds-name" is required
model-name.missing=Parameter "model-name" is required
+model-names.missing=Parameter "model-names" is required
+model-names.describe=Provide the names of models that need to be reloaded.
connection-type.missing = Parameter "connection-type" is required. Must be one
of [NONE, BY_VERSION, ANY]
rar-name.missing=Parameter "rar-name" is is required.
vdb-description.describe=vdb description
@@ -328,6 +330,12 @@
remove-data-role.mapped-role.describe=Security domain defined role name
remove-data-role.reply=void
+restart-vdb.describe=Restart the VDB, refresh any metadata
+restart-vdb.vdb-name.describe=VDB Name
+restart-vdb.vdb-version.describe=VDB Version
+restart-vdb.model-names.describe=comma separated names of the models for which the
metadata needs to be reloaded
+restart-vdb.reply=void
+
list-requests-per-session.describe=Current active requests in progress in the query
engine for a given session identifier
list-requests-per-session.session.describe=The session Identifier
list-requests-per-session.reply=requests for given session
Modified:
trunk/jboss-integration/src/test/java/org/teiid/jboss/TestTeiidConfiguration.java
===================================================================
---
trunk/jboss-integration/src/test/java/org/teiid/jboss/TestTeiidConfiguration.java 2012-06-21
16:50:23 UTC (rev 4194)
+++
trunk/jboss-integration/src/test/java/org/teiid/jboss/TestTeiidConfiguration.java 2012-06-21
19:07:57 UTC (rev 4195)
@@ -202,7 +202,7 @@
Assert.assertEquals(SUCCESS, result.get(OUTCOME).asString());
List<String> opNames = getList(result);
- assertEquals(38, opNames.size());
+ assertEquals(39, opNames.size());
String[] ops = {
"add","add-anyauthenticated-role","add-data-role","assign-datasource",
"cache-statistics","cache-types","cancel-request","change-vdb-connection-type",
"clear-cache","describe","execute-query","get-plan","get-translator","get-vdb",
@@ -212,7 +212,7 @@
"read-children-names","read-children-resources","read-children-types",
"read-operation-description","read-operation-names","read-rar-description",
"read-resource","read-resource-description","remove-anyauthenticated-role",
- "remove-data-role","terminate-session","terminate-transaction",
+ "remove-data-role","restart-vdb","terminate-session","terminate-transaction",
"workerpool-statistics","write-attribute", };
assertEquals(Arrays.asList(ops), opNames);
}
Modified:
trunk/metadata/src/main/java/org/teiid/metadata/index/IndexMetadataRepository.java
===================================================================
---
trunk/metadata/src/main/java/org/teiid/metadata/index/IndexMetadataRepository.java 2012-06-21
16:50:23 UTC (rev 4194)
+++
trunk/metadata/src/main/java/org/teiid/metadata/index/IndexMetadataRepository.java 2012-06-21
19:07:57 UTC (rev 4195)
@@ -40,8 +40,10 @@
public void loadMetadata(MetadataFactory factory, ExecutionFactory executionFactory,
Object connectionFactory)
throws TranslatorException {
try {
- this.idxStore.load(factory.getName(), factory.getDataTypes() ==
null?null:factory.getDataTypes().values());
if (this.idxStore.getSchema(factory.getName()) == null) {
+ this.idxStore.load(factory.getName(), factory.getDataTypes() ==
null?null:factory.getDataTypes().values());
+ }
+ if (this.idxStore.getSchema(factory.getName()) == null) {
throw new
TranslatorException(RuntimeMetadataPlugin.Util.gs(RuntimeMetadataPlugin.Event.TEIID80004,
factory.getName()));
}
factory.setSchema(this.idxStore.getSchema(factory.getName()));
Modified: trunk/runtime/src/main/java/org/teiid/deployers/RuntimeVDB.java
===================================================================
--- trunk/runtime/src/main/java/org/teiid/deployers/RuntimeVDB.java 2012-06-21 16:50:23
UTC (rev 4194)
+++ trunk/runtime/src/main/java/org/teiid/deployers/RuntimeVDB.java 2012-06-21 19:07:57
UTC (rev 4195)
@@ -34,11 +34,13 @@
public abstract class RuntimeVDB {
private VDBMetaData vdb;
private VDBModificationListener listener;
+ private boolean restartInProgress = false;
public interface VDBModificationListener {
void dataRoleChanged(String policyName) throws AdminProcessingException;
void connectionTypeChanged() throws AdminProcessingException;
void dataSourceChanged(String modelName, String sourceName, String translatorName,
String dsName) throws AdminProcessingException;
+ void onRestart(List<String> modelNames) throws AdminProcessingException;
}
public RuntimeVDB(VDBMetaData vdb, VDBModificationListener listener) {
@@ -145,6 +147,13 @@
}
}
+ public void restart(List<String> modelNames) throws AdminProcessingException {
+ synchronized(this.vdb) {
+ this.restartInProgress = true;
+ this.listener.onRestart(modelNames);
+ }
+ }
+
private DataPolicyMetadata getPolicy(String policyName)
throws AdminProcessingException {
DataPolicyMetadata policy = vdb.getDataPolicy(policyName);
@@ -155,5 +164,9 @@
return policy;
}
+ public boolean isRestartInProgress() {
+ return this.restartInProgress;
+ }
+
protected abstract VDBStatusChecker getVDBStatusChecker();
}
Modified: trunk/runtime/src/main/java/org/teiid/runtime/EmbeddedServer.java
===================================================================
--- trunk/runtime/src/main/java/org/teiid/runtime/EmbeddedServer.java 2012-06-21 16:50:23
UTC (rev 4194)
+++ trunk/runtime/src/main/java/org/teiid/runtime/EmbeddedServer.java 2012-06-21 19:07:57
UTC (rev 4195)
@@ -503,8 +503,12 @@
try {
ConnectorManager cm = getConnectorManager(model, cmr);
- ef = ((cm == null)?null:cm.getExecutionFactory());
- cf = ((cm == null)?null:cm.getConnectionFactory());
+ if (cm != null) {
+ ef = cm.getExecutionFactory();
+ if (ef.isSourceRequired()) {
+ cf = cm.getConnectionFactory();
+ }
+ }
} catch (TranslatorException e1) {
//ignore data source not availability, it may not be required.
}
Modified:
trunk/test-integration/common/src/test/java/org/teiid/arquillian/IntegrationTestDeployment.java
===================================================================
---
trunk/test-integration/common/src/test/java/org/teiid/arquillian/IntegrationTestDeployment.java 2012-06-21
16:50:23 UTC (rev 4194)
+++
trunk/test-integration/common/src/test/java/org/teiid/arquillian/IntegrationTestDeployment.java 2012-06-21
19:07:57 UTC (rev 4195)
@@ -24,15 +24,14 @@
import static org.junit.Assert.*;
+import java.io.ByteArrayInputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
import java.sql.Statement;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Properties;
-import java.util.Set;
+import java.util.*;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.shrinkwrap.api.ArchivePaths;
@@ -405,5 +404,54 @@
admin.deleteDataSource(deployedName);
}
-
+ @Test
+ public void testVDBRestart() throws Exception{
+ String vdbName = "test";
+ String testVDB = "<?xml version=\"1.0\" encoding=\"UTF-8\"
standalone=\"yes\"?>\n" +
+ "<vdb name=\"test\" version=\"1\">\n" +
+ " <property name=\"UseConnectorMetadata\"
value=\"cached\" />\n" +
+ " <model name=\"loopy\">\n" +
+ " <source name=\"loop\" translator-name=\"loopy\"
/>\n" +
+ " </model>\n" +
+ "</vdb>";
+
+ Collection<?> vdbs = admin.getVDBs();
+ assertTrue(vdbs.isEmpty());
+
+ JavaArchive jar = getLoopyArchive();
+ admin.deploy("loopy.jar", jar.as(ZipExporter.class).exportAsInputStream());
+
+ // normal load
+ admin.deploy("test-vdb.xml", new ByteArrayInputStream(testVDB.getBytes()));
+ AdminUtil.waitForVDBLoad(admin, vdbName, 1, 3);
+ int count = assertMetadataLoadCount(false, 1);
+
+ // 1st restart
+ admin.restartVDB(vdbName, 1);
+ AdminUtil.waitForVDBLoad(admin, vdbName, 1, 3);
+ count = assertMetadataLoadCount(true, count+1);
+
+ // 2nd restart
+ admin.restartVDB(vdbName, 1);
+ AdminUtil.waitForVDBLoad(admin, vdbName, 1, 3);
+ count = assertMetadataLoadCount(true, count+1);
+
+ admin.undeploy("loopy.jar");
+ }
+
+ private int assertMetadataLoadCount(boolean check, int expected) throws SQLException
{
+ Connection conn =
TeiidDriver.getInstance().connect("jdbc:teiid:test.1@mm://localhost:31000;user=user;password=user",
null);
+ Statement stmt = conn.createStatement();
+ stmt.execute("SELECT execCount FROM Matadata");
+ ResultSet rs = stmt.getResultSet();
+ rs.next();
+ int execCount = rs.getInt(1);
+ if (check) {
+ assertEquals(expected, execCount);
+ }
+ rs.close();
+ stmt.close();
+ conn.close();
+ return execCount;
+ }
}
Modified:
trunk/test-integration/common/src/test/java/org/teiid/arquillian/SampleExecutionFactory.java
===================================================================
---
trunk/test-integration/common/src/test/java/org/teiid/arquillian/SampleExecutionFactory.java 2012-06-21
16:50:23 UTC (rev 4194)
+++
trunk/test-integration/common/src/test/java/org/teiid/arquillian/SampleExecutionFactory.java 2012-06-21
19:07:57 UTC (rev 4195)
@@ -22,13 +22,73 @@
package org.teiid.arquillian;
+import java.util.Arrays;
+import java.util.List;
+
+import org.teiid.language.Command;
+import org.teiid.metadata.MetadataFactory;
+import org.teiid.metadata.RuntimeMetadata;
+import org.teiid.metadata.Table;
+import org.teiid.translator.*;
+import org.teiid.translator.loopback.LoopbackExecution;
import org.teiid.translator.loopback.LoopbackExecutionFactory;
@org.teiid.translator.Translator(name = "loopy")
+@SuppressWarnings("nls")
public class SampleExecutionFactory extends LoopbackExecutionFactory {
+ static int metadataloaded = 0; // use of static is bad, but we instantiate a separate
translator for each vdb load
+
public SampleExecutionFactory() {
setSupportsSelectDistinct(true);
setWaitTime(10);
setRowCount(200);
}
+
+ @Override
+ public void getMetadata(MetadataFactory metadataFactory, Object conn) throws
TranslatorException {
+ super.getMetadata(metadataFactory, conn);
+ metadataloaded++;
+
+ Table t = metadataFactory.addTable("Matadata");
+ metadataFactory.addColumn("execCount", "integer", t);
+ }
+
+ @Override
+ public boolean isSourceRequired() {
+ return false;
+ }
+
+ @Override
+ public Execution createExecution(Command command, ExecutionContext executionContext,
RuntimeMetadata metadata, Object connection)
+ throws TranslatorException {
+ if (command.toString().equals("SELECT g_0.execCount FROM Matadata AS
g_0")) { //$NON-NLS-1$
+ return new ResultSetExecution() {
+ boolean served = false;
+ @Override
+ public void execute() throws TranslatorException {
+
+ }
+
+ @Override
+ public void close() {
+
+ }
+
+ @Override
+ public void cancel() throws TranslatorException {
+ }
+
+ @Override
+ public List<?> next() throws TranslatorException, DataNotAvailableException {
+ if (!served) {
+ served = true;
+ return Arrays.asList(metadataloaded);
+ }
+ return null;
+ }
+ };
+ }
+ return new LoopbackExecution(command, this);
+ }
+
}
\ No newline at end of file