Author: shawkins
Date: 2012-07-31 13:19:19 -0400 (Tue, 31 Jul 2012)
New Revision: 4281
Added:
trunk/runtime/src/test/java/org/teiid/deployers/TestVDBStatusChecker.java
Modified:
trunk/jboss-integration/src/main/java/org/teiid/jboss/TeiidAttachments.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/TranslatorAdd.java
trunk/jboss-integration/src/main/java/org/teiid/jboss/TranslatorDeployer.java
trunk/jboss-integration/src/main/java/org/teiid/jboss/VDBDeployer.java
trunk/runtime/src/main/java/org/teiid/deployers/CompositeVDB.java
trunk/runtime/src/main/java/org/teiid/deployers/RuntimeVDB.java
trunk/runtime/src/main/java/org/teiid/deployers/VDBRepository.java
trunk/runtime/src/main/java/org/teiid/deployers/VDBStatusChecker.java
trunk/runtime/src/test/java/org/teiid/deployers/TestCompositeVDB.java
trunk/test-integration/common/src/test/resources/service-vdb.xml
Log:
TEIID-2121 expanding the fix and adding service cleanups
Modified: trunk/jboss-integration/src/main/java/org/teiid/jboss/TeiidAttachments.java
===================================================================
--- trunk/jboss-integration/src/main/java/org/teiid/jboss/TeiidAttachments.java 2012-07-31
16:35:27 UTC (rev 4280)
+++ trunk/jboss-integration/src/main/java/org/teiid/jboss/TeiidAttachments.java 2012-07-31
17:19:19 UTC (rev 4281)
@@ -25,6 +25,7 @@
import org.jboss.as.server.deployment.AttachmentKey;
import org.jboss.as.server.deployment.DeploymentUnit;
import org.teiid.adminapi.impl.VDBMetaData;
+import org.teiid.adminapi.impl.VDBTranslatorMetaData;
import org.teiid.deployers.UDFMetaData;
import org.teiid.metadata.index.IndexMetadataStore;
@@ -32,6 +33,7 @@
enum DeploymentType{VDB, DYNAMIC_VDB, TRANSLATOR};
+ public static final AttachmentKey<VDBTranslatorMetaData> TRANSLATOR_METADATA =
AttachmentKey.create(VDBTranslatorMetaData.class);
public static final AttachmentKey<VDBMetaData> VDB_METADATA =
AttachmentKey.create(VDBMetaData.class);
public static final AttachmentKey<UDFMetaData> UDF_METADATA =
AttachmentKey.create(UDFMetaData.class);
public static final AttachmentKey<IndexMetadataStore> INDEX_METADATA =
AttachmentKey.create(IndexMetadataStore.class);
Modified:
trunk/jboss-integration/src/main/java/org/teiid/jboss/TeiidOperationHandler.java
===================================================================
---
trunk/jboss-integration/src/main/java/org/teiid/jboss/TeiidOperationHandler.java 2012-07-31
16:35:27 UTC (rev 4280)
+++
trunk/jboss-integration/src/main/java/org/teiid/jboss/TeiidOperationHandler.java 2012-07-31
17:19:19 UTC (rev 4281)
@@ -53,6 +53,7 @@
import org.jboss.jca.common.api.metadata.ra.ResourceAdapter1516;
import org.jboss.msc.service.ServiceController;
import org.jboss.msc.service.ServiceName;
+import org.jboss.msc.service.ServiceRegistry;
import org.teiid.adminapi.Admin;
import org.teiid.adminapi.AdminException;
import org.teiid.adminapi.AdminProcessingException;
@@ -78,6 +79,7 @@
import org.teiid.deployers.RuntimeVDB;
import org.teiid.deployers.VDBRepository;
import org.teiid.deployers.VDBStatusChecker;
+import org.teiid.deployers.RuntimeVDB.ReplaceResult;
import org.teiid.dqp.internal.datamgr.TranslatorRepository;
import org.teiid.dqp.internal.process.DQPCore;
import org.teiid.dqp.internal.process.DQPWorkContext;
@@ -89,6 +91,7 @@
import org.teiid.query.metadata.DDLStringVisitor;
import org.teiid.query.metadata.TransformationMetadata;
import org.teiid.query.tempdata.TempTableDataManager;
+import org.teiid.vdb.runtime.VDBKey;
abstract class TeiidOperationHandler extends BaseOperationHandler<DQPCore> {
List<TransportService> transports = new ArrayList<TransportService>();
@@ -639,7 +642,7 @@
String dsName = operation.get(OperationsConstants.DS_NAME).asString();
ServiceController<?> sc =
context.getServiceRegistry(false).getRequiredService(TeiidServiceNames.VDB_STATUS_CHECKER);
VDBStatusChecker vsc = VDBStatusChecker.class.cast(sc.getValue());
- vsc.dataSourceAdded(dsName);
+ vsc.dataSourceAdded(dsName, null);
}
protected void describeParameters(ModelNode operationNode, ResourceBundle bundle) {
@@ -1383,7 +1386,22 @@
String dsName = operation.get(OperationsConstants.DS_NAME).asString();
try {
- vdb.assignDatasource(modelName, sourceName, translatorName, dsName);
+ synchronized (vdb.getVdb()) {
+ ReplaceResult rr = vdb.assignDatasource(modelName, sourceName, translatorName,
dsName);
+ if (rr.isNew) {
+ ServiceController<?> sc =
context.getServiceRegistry(false).getRequiredService(TeiidServiceNames.VDB_STATUS_CHECKER);
+ VDBStatusChecker vsc = VDBStatusChecker.class.cast(sc.getValue());
+ VDBDeployer.addDataSourceListener(context.getServiceTarget(), new
VDBKey(vdb.getVdb().getName(), vdb.getVdb().getVersion()), dsName, vsc);
+ }
+ if (rr.removedDs != null) {
+ final ServiceRegistry registry = context.getServiceRegistry(true);
+ final ServiceName serviceName =
TeiidServiceNames.dsListenerServiceName(vdb.getVdb().getName(), vdb.getVdb().getVersion(),
rr.removedDs);
+ final ServiceController<?> controller =
registry.getService(serviceName);
+ if (controller != null) {
+ context.removeService(serviceName);
+ }
+ }
+ }
} catch (AdminProcessingException e) {
throw new OperationFailedException(new ModelNode().set(e.getMessage()));
}
Modified: trunk/jboss-integration/src/main/java/org/teiid/jboss/TeiidServiceNames.java
===================================================================
---
trunk/jboss-integration/src/main/java/org/teiid/jboss/TeiidServiceNames.java 2012-07-31
16:35:27 UTC (rev 4280)
+++
trunk/jboss-integration/src/main/java/org/teiid/jboss/TeiidServiceNames.java 2012-07-31
17:19:19 UTC (rev 4281)
@@ -22,6 +22,7 @@
package org.teiid.jboss;
import org.jboss.msc.service.ServiceName;
+import org.teiid.deployers.VDBStatusChecker;
public class TeiidServiceNames {
public static ServiceName ENGINE = ServiceName.JBOSS.append("teiid",
"query-engine"); //$NON-NLS-1$ //$NON-NLS-2$
@@ -75,6 +76,6 @@
}
public static ServiceName dsListenerServiceName(String vdbName, int version, String
name) {
- return ServiceName.of(DS_LISTENER_BASE, vdbName, String.valueOf(version), name);
+ return ServiceName.of(DS_LISTENER_BASE, vdbName, String.valueOf(version),
VDBStatusChecker.stripContext(name));
}
}
Modified: trunk/jboss-integration/src/main/java/org/teiid/jboss/TranslatorAdd.java
===================================================================
--- trunk/jboss-integration/src/main/java/org/teiid/jboss/TranslatorAdd.java 2012-07-31
16:35:27 UTC (rev 4280)
+++ trunk/jboss-integration/src/main/java/org/teiid/jboss/TranslatorAdd.java 2012-07-31
17:19:19 UTC (rev 4281)
@@ -21,11 +21,7 @@
*/
package org.teiid.jboss;
-import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.ADD;
-import static
org.jboss.as.controller.descriptions.ModelDescriptionConstants.DESCRIPTION;
-import static
org.jboss.as.controller.descriptions.ModelDescriptionConstants.OPERATION_NAME;
-import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP_ADDR;
-import static
org.jboss.as.controller.descriptions.ModelDescriptionConstants.REQUEST_PROPERTIES;
+import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.*;
import java.util.List;
import java.util.Locale;
@@ -43,13 +39,10 @@
import org.jboss.modules.ModuleIdentifier;
import org.jboss.modules.ModuleLoadException;
import org.jboss.modules.ModuleLoader;
-import org.jboss.msc.service.ServiceBuilder;
import org.jboss.msc.service.ServiceController;
import org.jboss.msc.service.ServiceTarget;
import org.teiid.adminapi.impl.VDBTranslatorMetaData;
import org.teiid.deployers.TranslatorUtil;
-import org.teiid.deployers.VDBStatusChecker;
-import org.teiid.dqp.internal.datamgr.TranslatorRepository;
import org.teiid.logging.LogConstants;
import org.teiid.logging.LogManager;
import org.teiid.translator.ExecutionFactory;
@@ -117,11 +110,7 @@
if (translatorName.equalsIgnoreCase(metadata.getName())) {
LogManager.logInfo(LogConstants.CTX_RUNTIME,
IntegrationPlugin.Util.gs(IntegrationPlugin.Event.TEIID50006, metadata.getName()));
- TranslatorService translatorService = new TranslatorService(metadata);
- ServiceBuilder<VDBTranslatorMetaData> builder =
target.addService(TeiidServiceNames.translatorServiceName(metadata.getName()),
translatorService);
- builder.addDependency(TeiidServiceNames.TRANSLATOR_REPO,
TranslatorRepository.class, translatorService.repositoryInjector);
- builder.addDependency(TeiidServiceNames.VDB_STATUS_CHECKER,
VDBStatusChecker.class, translatorService.statusCheckerInjector);
-
newControllers.add(builder.setInitialMode(ServiceController.Mode.ACTIVE).install());
+ TranslatorDeployer.buildService(target, metadata);
added = true;
break;
}
Modified: trunk/jboss-integration/src/main/java/org/teiid/jboss/TranslatorDeployer.java
===================================================================
---
trunk/jboss-integration/src/main/java/org/teiid/jboss/TranslatorDeployer.java 2012-07-31
16:35:27 UTC (rev 4280)
+++
trunk/jboss-integration/src/main/java/org/teiid/jboss/TranslatorDeployer.java 2012-07-31
17:19:19 UTC (rev 4281)
@@ -32,7 +32,10 @@
import org.jboss.modules.Module;
import org.jboss.msc.service.ServiceBuilder;
import org.jboss.msc.service.ServiceController;
+import org.jboss.msc.service.ServiceName;
+import org.jboss.msc.service.ServiceRegistry;
import org.jboss.msc.service.ServiceTarget;
+import org.jboss.msc.service.ServiceController.Mode;
import org.teiid.adminapi.impl.VDBTranslatorMetaData;
import org.teiid.deployers.TranslatorUtil;
import org.teiid.deployers.VDBStatusChecker;
@@ -66,21 +69,40 @@
if (metadata == null) {
throw new
DeploymentUnitProcessingException(IntegrationPlugin.Util.gs(IntegrationPlugin.Event.TEIID50070,
moduleName));
}
- metadata.addProperty(TranslatorUtil.DEPLOYMENT_NAME,
deploymentUnit.getName());
+ deploymentUnit.putAttachment(TeiidAttachments.TRANSLATOR_METADATA, metadata);
+ metadata.addProperty(TranslatorUtil.DEPLOYMENT_NAME, moduleName);
metadata.addAttchment(ClassLoader.class, translatorLoader);
LogManager.logInfo(LogConstants.CTX_RUNTIME,
IntegrationPlugin.Util.gs(IntegrationPlugin.Event.TEIID50006, metadata.getName()));
- TranslatorService translatorService = new TranslatorService(metadata);
- ServiceBuilder<VDBTranslatorMetaData> builder =
target.addService(TeiidServiceNames.translatorServiceName(metadata.getName()),
translatorService);
- builder.addDependency(TeiidServiceNames.TRANSLATOR_REPO,
TranslatorRepository.class, translatorService.repositoryInjector);
- builder.addDependency(TeiidServiceNames.VDB_STATUS_CHECKER,
VDBStatusChecker.class, translatorService.statusCheckerInjector);
- builder.setInitialMode(ServiceController.Mode.ACTIVE).install();
+ buildService(target, metadata);
}
}
}
+ static void buildService(final ServiceTarget target,
+ VDBTranslatorMetaData metadata) {
+ TranslatorService translatorService = new TranslatorService(metadata);
+ ServiceBuilder<VDBTranslatorMetaData> builder =
target.addService(TeiidServiceNames.translatorServiceName(metadata.getName()),
translatorService);
+ builder.addDependency(TeiidServiceNames.TRANSLATOR_REPO, TranslatorRepository.class,
translatorService.repositoryInjector);
+ builder.addDependency(TeiidServiceNames.VDB_STATUS_CHECKER, VDBStatusChecker.class,
translatorService.statusCheckerInjector);
+ builder.setInitialMode(ServiceController.Mode.ACTIVE).install();
+ }
+
@Override
public void undeploy(final DeploymentUnit context) {
+ if (!TeiidAttachments.isTranslator(context)) {
+ return;
+ }
+ VDBTranslatorMetaData metadata =
context.getAttachment(TeiidAttachments.TRANSLATOR_METADATA);
+ if (metadata == null) {
+ return;
+ }
+ final ServiceRegistry registry = context.getServiceRegistry();
+ final ServiceName serviceName =
TeiidServiceNames.translatorServiceName(metadata.getName());
+ final ServiceController<?> controller = registry.getService(serviceName);
+ if (controller != null) {
+ controller.setMode(Mode.REMOVE);
+ }
}
}
Modified: trunk/jboss-integration/src/main/java/org/teiid/jboss/VDBDeployer.java
===================================================================
--- trunk/jboss-integration/src/main/java/org/teiid/jboss/VDBDeployer.java 2012-07-31
16:35:27 UTC (rev 4280)
+++ trunk/jboss-integration/src/main/java/org/teiid/jboss/VDBDeployer.java 2012-07-31
17:19:19 UTC (rev 4281)
@@ -21,8 +21,10 @@
*/
package org.teiid.jboss;
+import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
+import java.util.Set;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Executor;
import java.util.concurrent.TimeUnit;
@@ -51,6 +53,7 @@
import org.teiid.adminapi.Translator;
import org.teiid.adminapi.VDBImport;
import org.teiid.adminapi.impl.ModelMetaData;
+import org.teiid.adminapi.impl.SourceMappingMetadata;
import org.teiid.adminapi.impl.VDBMetaData;
import org.teiid.adminapi.impl.VDBTranslatorMetaData;
import org.teiid.common.buffer.BufferManager;
@@ -66,6 +69,7 @@
import org.teiid.metadata.index.IndexMetadataStore;
import org.teiid.query.ObjectReplicator;
import org.teiid.query.metadata.TransformationMetadata.Resource;
+import org.teiid.vdb.runtime.VDBKey;
class VDBDeployer implements DeploymentUnitProcessor {
@@ -154,15 +158,7 @@
final ServiceBuilder<RuntimeVDB> vdbService =
context.getServiceTarget().addService(TeiidServiceNames.vdbServiceName(deployment.getName(),
deployment.getVersion()), vdb);
// add dependencies to data-sources
- dataSourceDependencies(deployment, new DependentServices() {
- @Override
- public void dependentService(final String dsName, final ServiceName svcName) {
- DataSourceListener dsl = new DataSourceListener(dsName, svcName,
vdbStatusChecker);
- ServiceBuilder<DataSourceListener> sb =
context.getServiceTarget().addService(TeiidServiceNames.dsListenerServiceName(deployment.getName(),
deployment.getVersion(), dsName), dsl);
- sb.addDependency(svcName);
- sb.setInitialMode(Mode.PASSIVE).install();
- }
- });
+ dataSourceDependencies(deployment, context.getServiceTarget());
for (VDBImport vdbImport : deployment.getVDBImports()) {
vdbService.addDependency(TeiidServiceNames.vdbFinishedServiceName(vdbImport.getName(),
vdbImport.getVersion()));
@@ -246,8 +242,22 @@
svc.install();
}
- private void dataSourceDependencies(VDBMetaData deployment, DependentServices
svcListener) {
-
+ static void addDataSourceListener(
+ final ServiceTarget serviceTarget,
+ final VDBKey vdbKey,
+ final String dsName, VDBStatusChecker vdbStatusChecker) {
+ final String jndiName = getJndiName(dsName);
+ final ContextNames.BindInfo bindInfo = ContextNames.bindInfoFor(jndiName);
+ final ServiceName svcName = bindInfo.getBinderServiceName();
+ DataSourceListener dsl = new DataSourceListener(dsName, svcName, vdbStatusChecker,
vdbKey);
+ ServiceBuilder<DataSourceListener> sb =
serviceTarget.addService(TeiidServiceNames.dsListenerServiceName(vdbKey.getName(),
vdbKey.getVersion(), dsName), dsl);
+ sb.addDependency(svcName);
+ sb.setInitialMode(Mode.PASSIVE).install();
+ }
+
+ private void dataSourceDependencies(VDBMetaData deployment, ServiceTarget serviceTarget)
{
+ final VDBKey vdbKey = new VDBKey(deployment.getName(), deployment.getVersion());
+ Set<String> dataSources = new HashSet<String>();
for (ModelMetaData model:deployment.getModelMetaDatas().values()) {
for (String sourceName:model.getSourceNames()) {
String translatorName = model.getSourceTranslatorName(sourceName);
@@ -261,25 +271,25 @@
if (dsName == null) {
continue;
}
- final ContextNames.BindInfo bindInfo =
ContextNames.bindInfoFor(getJndiName(dsName));
- svcListener.dependentService(dsName, bindInfo.getBinderServiceName());
+ if (!dataSources.add(VDBStatusChecker.stripContext(dsName))) {
+ continue; //already listening
+ }
+ addDataSourceListener(serviceTarget, vdbKey, dsName, vdbStatusChecker);
}
}
}
- interface DependentServices {
- void dependentService(String dsName, ServiceName svc);
- }
-
static class DataSourceListener implements Service<DataSourceListener>{
private VDBStatusChecker vdbStatusChecker;
private String dsName;
private ServiceName svcName;
+ private VDBKey vdb;
- public DataSourceListener(String dsName, ServiceName svcName, VDBStatusChecker checker)
{
+ public DataSourceListener(String dsName, ServiceName svcName, VDBStatusChecker checker,
VDBKey vdb) {
this.dsName = dsName;
this.svcName = svcName;
this.vdbStatusChecker = checker;
+ this.vdb = vdb;
}
public DataSourceListener getValue() throws
IllegalStateException,IllegalArgumentException {
@@ -290,7 +300,7 @@
public void start(StartContext context) throws StartException {
ServiceController<?> s =
context.getController().getServiceContainer().getService(this.svcName);
if (s != null) {
- this.vdbStatusChecker.dataSourceAdded(this.dsName);
+ this.vdbStatusChecker.dataSourceAdded(this.dsName, vdb);
}
}
@@ -298,12 +308,12 @@
public void stop(StopContext context) {
ServiceController<?> s =
context.getController().getServiceContainer().getService(this.svcName);
if (s.getMode().equals(Mode.REMOVE) || s.getState().equals(State.STOPPING)) {
- this.vdbStatusChecker.dataSourceRemoved(this.dsName);
+ this.vdbStatusChecker.dataSourceRemoved(this.dsName, vdb);
}
}
}
- private String getJndiName(String name) {
+ public static String getJndiName(String name) {
String jndiName = name;
if (!name.startsWith(JAVA_CONTEXT)) {
jndiName = JAVA_CONTEXT + jndiName;
@@ -330,10 +340,9 @@
}
this.vdbStatusChecker.getVDBRepository().removeVDB(deployment.getName(),
deployment.getVersion());
- for (Model model:deployment.getModels()) {
- List<String> sourceNames = model.getSourceNames();
- for (String sourceName:sourceNames) {
- String dsName = model.getSourceConnectionJndiName(sourceName);
+ for (ModelMetaData model:deployment.getModelMetaDatas().values()) {
+ for (SourceMappingMetadata smm:model.getSources().values()) {
+ String dsName = smm.getConnectionJndiName();
if (dsName == null) {
continue;
}
@@ -344,5 +353,10 @@
}
}
}
+
+ final ServiceController<?> controller =
deploymentUnit.getServiceRegistry().getService(TeiidServiceNames.vdbServiceName(deployment.getName(),
deployment.getVersion()));
+ if (controller != null) {
+ controller.setMode(ServiceController.Mode.REMOVE);
+ }
}
}
Modified: trunk/runtime/src/main/java/org/teiid/deployers/CompositeVDB.java
===================================================================
--- trunk/runtime/src/main/java/org/teiid/deployers/CompositeVDB.java 2012-07-31 16:35:27
UTC (rev 4280)
+++ trunk/runtime/src/main/java/org/teiid/deployers/CompositeVDB.java 2012-07-31 17:19:19
UTC (rev 4281)
@@ -125,7 +125,7 @@
this.children = new LinkedHashMap<VDBKey, CompositeVDB>();
newMergedVDB.setImportedModels(new
TreeSet<String>(String.CASE_INSENSITIVE_ORDER));
for (VDBImport vdbImport : vdb.getVDBImports()) {
- CompositeVDB importedVDB = vdbRepository.getCompositeVDB(vdbImport.getName(),
vdbImport.getVersion());
+ CompositeVDB importedVDB = vdbRepository.getCompositeVDB(new
VDBKey(vdbImport.getName(), vdbImport.getVersion()));
if (importedVDB == null) {
throw new VirtualDatabaseException(RuntimePlugin.Event.TEIID40083,
RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40083, vdb.getName(), vdb.getVersion(),
vdbImport.getName(), vdbImport.getVersion()));
}
Modified: trunk/runtime/src/main/java/org/teiid/deployers/RuntimeVDB.java
===================================================================
--- trunk/runtime/src/main/java/org/teiid/deployers/RuntimeVDB.java 2012-07-31 16:35:27
UTC (rev 4280)
+++ trunk/runtime/src/main/java/org/teiid/deployers/RuntimeVDB.java 2012-07-31 17:19:19
UTC (rev 4281)
@@ -29,6 +29,8 @@
import org.teiid.adminapi.impl.ModelMetaData;
import org.teiid.adminapi.impl.SourceMappingMetadata;
import org.teiid.adminapi.impl.VDBMetaData;
+import org.teiid.dqp.internal.datamgr.ConnectorManager;
+import org.teiid.dqp.internal.datamgr.ConnectorManagerRepository;
import org.teiid.runtime.RuntimePlugin;
public abstract class RuntimeVDB {
@@ -36,6 +38,11 @@
private VDBModificationListener listener;
private boolean restartInProgress = false;
+ public static class ReplaceResult {
+ public boolean isNew;
+ public String removedDs;
+ }
+
public interface VDBModificationListener {
void dataRoleChanged(String policyName) throws AdminProcessingException;
void connectionTypeChanged() throws AdminProcessingException;
@@ -117,7 +124,7 @@
}
}
- public void assignDatasource(String modelName, String sourceName, String translatorName,
String dsName) throws AdminProcessingException{
+ public ReplaceResult assignDatasource(String modelName, String sourceName, String
translatorName, String dsName) throws AdminProcessingException{
synchronized (this.vdb) {
ModelMetaData model = this.vdb.getModel(modelName);
@@ -138,7 +145,16 @@
try {
this.listener.dataSourceChanged(modelName, sourceName, translatorName, dsName);
- getVDBStatusChecker().dataSourceReplaced(vdb.getName(), vdb.getVersion(), modelName,
sourceName, translatorName, dsName);
+ ConnectorManagerRepository cmr =
vdb.getAttachment(ConnectorManagerRepository.class);
+ ReplaceResult rr = new ReplaceResult();
+ if (dsName != null) {
+ rr.isNew = !dsExists(dsName, cmr);
+ }
+ boolean replaced = getVDBStatusChecker().dataSourceReplaced(vdb.getName(),
vdb.getVersion(), modelName, sourceName, translatorName, dsName);
+ if (replaced && previousDsName != null && !dsExists(previousDsName,
cmr)) {
+ rr.removedDs = previousDsName;
+ }
+ return rr;
} catch(AdminProcessingException e) {
source.setTranslatorName(previousTranslatorName);
source.setConnectionJndiName(previousDsName);
@@ -146,6 +162,16 @@
}
}
}
+
+ private boolean dsExists(String dsName, ConnectorManagerRepository cmr) {
+ String baseDsName = VDBStatusChecker.stripContext(dsName);
+ for (ConnectorManager cm : cmr.getConnectorManagers().values()) {
+ if (baseDsName.equals(VDBStatusChecker.stripContext(cm.getConnectionName()))) {
+ return true;
+ }
+ }
+ return false;
+ }
public void restart(List<String> modelNames) throws AdminProcessingException {
synchronized(this.vdb) {
@@ -168,5 +194,9 @@
return this.restartInProgress;
}
+ public VDBMetaData getVdb() {
+ return vdb;
+ }
+
protected abstract VDBStatusChecker getVDBStatusChecker();
}
Modified: trunk/runtime/src/main/java/org/teiid/deployers/VDBRepository.java
===================================================================
--- trunk/runtime/src/main/java/org/teiid/deployers/VDBRepository.java 2012-07-31 16:35:27
UTC (rev 4280)
+++ trunk/runtime/src/main/java/org/teiid/deployers/VDBRepository.java 2012-07-31 17:19:19
UTC (rev 4281)
@@ -150,8 +150,8 @@
}
}
- CompositeVDB getCompositeVDB(String name, int version) {
- return this.vdbRepo.get(new VDBKey(name, version));
+ CompositeVDB getCompositeVDB(VDBKey key) {
+ return this.vdbRepo.get(key);
}
/**
@@ -161,7 +161,7 @@
* @return
*/
public VDBMetaData getLiveVDB(String name, int version) {
- CompositeVDB v = getCompositeVDB(name, version);
+ CompositeVDB v = this.vdbRepo.get(new VDBKey(name, version));
if (v != null) {
return v.getVDB();
}
Modified: trunk/runtime/src/main/java/org/teiid/deployers/VDBStatusChecker.java
===================================================================
--- trunk/runtime/src/main/java/org/teiid/deployers/VDBStatusChecker.java 2012-07-31
16:35:27 UTC (rev 4280)
+++ trunk/runtime/src/main/java/org/teiid/deployers/VDBStatusChecker.java 2012-07-31
17:19:19 UTC (rev 4281)
@@ -22,6 +22,7 @@
package org.teiid.deployers;
import java.util.ArrayList;
+import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.Executor;
@@ -40,6 +41,7 @@
import org.teiid.logging.LogManager;
import org.teiid.runtime.RuntimePlugin;
import org.teiid.translator.ExecutionFactory;
+import org.teiid.vdb.runtime.VDBKey;
public abstract class VDBStatusChecker {
@@ -58,30 +60,84 @@
public void translatorRemoved(String translatorName) {
}
- public void dataSourceAdded(String dataSourceName) {
+ public void dataSourceAdded(String dataSourceName, VDBKey vdbKey) {
+ dataSourceName = stripContext(dataSourceName);
+ if (vdbKey == null) {
+ //scan all
+ resourceAdded(dataSourceName);
+ } else {
+ CompositeVDB cvdb = getVDBRepository().getCompositeVDB(vdbKey);
+ if (cvdb == null) {
+ return;
+ }
+ VDBMetaData vdb = cvdb.getVDB();
+ resourceAdded(dataSourceName, new LinkedList<Runnable>(), vdb);
+ }
+ }
+
+ public static String stripContext(String dataSourceName) {
+ if (dataSourceName == null) {
+ return null;
+ }
if (dataSourceName.startsWith(JAVA_CONTEXT)) {
dataSourceName = dataSourceName.substring(5);
}
- resourceAdded(dataSourceName);
+ return dataSourceName;
}
- public void dataSourceRemoved(String dataSourceName) {
- if (dataSourceName.startsWith(JAVA_CONTEXT)) {
- dataSourceName = dataSourceName.substring(5);
+ /**
+ *
+ * @param dataSourceName
+ * @param vdbKey which cannot be null
+ */
+ public void dataSourceRemoved(String dataSourceName, VDBKey vdbKey) {
+ dataSourceName = stripContext(dataSourceName);
+ CompositeVDB cvdb = getVDBRepository().getCompositeVDB(vdbKey);
+ if (cvdb == null) {
+ return;
}
- resourceRemoved(dataSourceName);
+ VDBMetaData vdb = cvdb.getVDB();
+ if (vdb.getStatus() == Status.FAILED) {
+ return;
+ }
+ synchronized (vdb) {
+ ConnectorManagerRepository cmr = vdb.getAttachment(ConnectorManagerRepository.class);
+ for (ModelMetaData model:vdb.getModelMetaDatas().values()) {
+ String sourceName = getSourceName(dataSourceName, model);
+ if (sourceName == null) {
+ continue;
+ }
+ Severity severity = Severity.WARNING;
+ ConnectorManager cm = cmr.getConnectorManager(sourceName);
+ if (cm.getExecutionFactory().isSourceRequired() && vdb.getStatus() ==
Status.ACTIVE) {
+ severity = Severity.ERROR;
+ }
+ String msg = RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40012, vdb.getName(),
vdb.getVersion(), dataSourceName);
+ model.addRuntimeMessage(severity, msg);
+ LogManager.logInfo(LogConstants.CTX_RUNTIME, msg);
+ }
+ }
}
- public void dataSourceReplaced(String vdbName, int vdbVersion,
+ /**
+ *
+ * @param vdbName
+ * @param vdbVersion
+ * @param modelName
+ * @param sourceName
+ * @param translatorName
+ * @param dsName
+ * @return true if the datasource is new to the vdb
+ * @throws AdminProcessingException
+ */
+ public boolean dataSourceReplaced(String vdbName, int vdbVersion,
String modelName, String sourceName, String translatorName,
String dsName) throws AdminProcessingException {
- if (dsName.startsWith(JAVA_CONTEXT)) {
- dsName = dsName.substring(5);
- }
+ dsName = stripContext(dsName);
VDBMetaData vdb = getVDBRepository().getLiveVDB(vdbName, vdbVersion);
- if (vdb.getStatus() == Status.FAILED) {
- return;
+ if (vdb == null || vdb.getStatus() == Status.FAILED) {
+ return false;
}
ModelMetaData model = vdb.getModel(modelName);
@@ -91,9 +147,11 @@
ExecutionFactory<Object, Object> ef = cm.getExecutionFactory();
boolean dsReplaced = false;
- if ((dsName != null && !dsName.equals(cm.getConnectionName())) || (dsName ==
null && cm.getConnectionName() != null)) {
+ String oldDsName = stripContext(cm.getConnectionName());
+ if ((dsName != null && !dsName.equals(oldDsName)) || (dsName == null
&& oldDsName != null)) {
LogManager.logInfo(LogConstants.CTX_RUNTIME,
RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40076, vdb.getName(), vdb.getVersion(),
model.getSourceTranslatorName(sourceName), dsName));
- cm = new ConnectorManager(translatorName, dsName);
+ cm = new ConnectorManager(translatorName, dsName);
+
cm.setExecutionFactory(ef);
cmr.addConnectorManager(sourceName, cm);
dsReplaced = true;
@@ -118,44 +176,49 @@
throw new AdminProcessingException(RuntimePlugin.Event.TEIID40033, e.getCause());
}
}
-
if (dsReplaced) {
ArrayList<Runnable> runnables = new ArrayList<Runnable>(1);
checkStatus(runnables, vdb, model, cm);
updateVDB(runnables, vdb);
}
+ return dsReplaced;
}
}
- public void resourceAdded(String resourceName) {
+ void resourceAdded(String resourceName) {
List<Runnable> runnables = new ArrayList<Runnable>();
for (CompositeVDB cvdb:getVDBRepository().getCompositeVDBs()) {
VDBMetaData vdb = cvdb.getVDB();
if (vdb.getStatus() == Status.FAILED) {
continue;
}
- synchronized (vdb) {
- ConnectorManagerRepository cmr =
vdb.getAttachment(ConnectorManagerRepository.class);
- boolean usesResourse = false;
- for (ModelMetaData model:vdb.getModelMetaDatas().values()) {
- if (!model.hasRuntimeMessages()) {
- continue;
- }
-
- String sourceName = getSourceName(resourceName, model);
- if (sourceName == null) {
- continue;
- }
+ resourceAdded(resourceName, runnables, vdb);
+ }
+ }
- usesResourse = true;
- ConnectorManager cm = cmr.getConnectorManager(sourceName);
- checkStatus(runnables, vdb, model, cm);
+ private void resourceAdded(String resourceName, List<Runnable> runnables,
+ VDBMetaData vdb) {
+ synchronized (vdb) {
+ ConnectorManagerRepository cmr = vdb.getAttachment(ConnectorManagerRepository.class);
+ boolean usesResourse = false;
+ for (ModelMetaData model:vdb.getModelMetaDatas().values()) {
+ if (!model.hasRuntimeMessages()) {
+ return;
}
-
- if (usesResourse) {
- updateVDB(runnables, vdb);
+
+ String sourceName = getSourceName(resourceName, model);
+ if (sourceName == null) {
+ return;
}
+
+ usesResourse = true;
+ ConnectorManager cm = cmr.getConnectorManager(sourceName);
+ checkStatus(runnables, vdb, model, cm);
}
+
+ if (usesResourse) {
+ updateVDB(runnables, vdb);
+ }
}
}
@@ -189,41 +252,13 @@
}
}
- public void resourceRemoved(String resourceName) {
- for (CompositeVDB cvdb:getVDBRepository().getCompositeVDBs()) {
- VDBMetaData vdb = cvdb.getVDB();
- if (vdb.getStatus() == Status.FAILED) {
- continue;
- }
- synchronized (vdb) {
- ConnectorManagerRepository cmr =
vdb.getAttachment(ConnectorManagerRepository.class);
- for (ModelMetaData model:vdb.getModelMetaDatas().values()) {
- String sourceName = getSourceName(resourceName, model);
- if (sourceName == null) {
- continue;
- }
- Severity severity = Severity.WARNING;
- ConnectorManager cm = cmr.getConnectorManager(sourceName);
- if (cm.getExecutionFactory().isSourceRequired() && vdb.getStatus() ==
Status.ACTIVE) {
- severity = Severity.ERROR;
- }
- String msg = RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40012, vdb.getName(),
vdb.getVersion(), resourceName);
- model.addRuntimeMessage(severity, msg);
- LogManager.logInfo(LogConstants.CTX_RUNTIME, msg);
- }
- }
- }
- }
-
private String getSourceName(String factoryName, ModelMetaData model) {
for (SourceMappingMetadata source:model.getSources().values()) {
String jndiName = source.getConnectionJndiName();
if (jndiName == null) {
continue;
}
- if (jndiName.startsWith(JAVA_CONTEXT)) {
- jndiName = jndiName.substring(5);
- }
+ jndiName = stripContext(jndiName);
if (factoryName.equals(jndiName)) {
return source.getName();
}
Modified: trunk/runtime/src/test/java/org/teiid/deployers/TestCompositeVDB.java
===================================================================
--- trunk/runtime/src/test/java/org/teiid/deployers/TestCompositeVDB.java 2012-07-31
16:35:27 UTC (rev 4280)
+++ trunk/runtime/src/test/java/org/teiid/deployers/TestCompositeVDB.java 2012-07-31
17:19:19 UTC (rev 4281)
@@ -65,7 +65,7 @@
return cvdb;
}
- private static VDBMetaData createVDBMetadata(MetadataStore metadataStore,
+ static VDBMetaData createVDBMetadata(MetadataStore metadataStore,
String vdbName) {
VDBMetaData vdbMetaData = new VDBMetaData();
vdbMetaData.setName(vdbName); //$NON-NLS-1$
Added: trunk/runtime/src/test/java/org/teiid/deployers/TestVDBStatusChecker.java
===================================================================
--- trunk/runtime/src/test/java/org/teiid/deployers/TestVDBStatusChecker.java
(rev 0)
+++ trunk/runtime/src/test/java/org/teiid/deployers/TestVDBStatusChecker.java 2012-07-31
17:19:19 UTC (rev 4281)
@@ -0,0 +1,70 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package org.teiid.deployers;
+
+import static org.junit.Assert.*;
+
+import java.util.concurrent.Executor;
+
+import org.junit.Test;
+import org.teiid.adminapi.impl.VDBMetaData;
+import org.teiid.dqp.internal.datamgr.ConnectorManager;
+import org.teiid.dqp.internal.datamgr.ConnectorManagerRepository;
+import org.teiid.metadata.MetadataStore;
+import org.teiid.query.unittest.RealMetadataFactory;
+
+@SuppressWarnings("nls")
+public class TestVDBStatusChecker {
+
+ @Test public void testDataSourceReplaced() throws Exception {
+ final VDBRepository repo = new VDBRepository();
+ repo.setSystemFunctionManager(RealMetadataFactory.SFM);
+ repo.start();
+
+ VDBStatusChecker vsc = new VDBStatusChecker() {
+
+ @Override
+ public VDBRepository getVDBRepository() {
+ return repo;
+ }
+
+ @Override
+ public Executor getExecutor() {
+ return null;
+ }
+ };
+
+ assertFalse(vsc.dataSourceReplaced("x", 1, "y", "z",
"t", "dsName"));
+
+ MetadataStore metadataStore =
RealMetadataFactory.exampleBQTCached().getMetadataStore();
+ VDBMetaData vdb = TestCompositeVDB.createVDBMetadata(metadataStore, "bqt");
+
+ ConnectorManagerRepository cmr = new ConnectorManagerRepository();
+ cmr.addConnectorManager("BQT1", new ConnectorManager("oracle",
"dsName"));
+ repo.addVDB(vdb, metadataStore, null, null, cmr);
+
+ assertTrue(vsc.dataSourceReplaced("bqt", 1, "BQT1",
"BQT1", "oracle", "dsName1"));
+ assertFalse(vsc.dataSourceReplaced("bqt", 1, "BQT1",
"BQT1", "oracle", "dsName1"));
+ }
+
+}
Property changes on:
trunk/runtime/src/test/java/org/teiid/deployers/TestVDBStatusChecker.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified: trunk/test-integration/common/src/test/resources/service-vdb.xml
===================================================================
--- trunk/test-integration/common/src/test/resources/service-vdb.xml 2012-07-31 16:35:27
UTC (rev 4280)
+++ trunk/test-integration/common/src/test/resources/service-vdb.xml 2012-07-31 17:19:19
UTC (rev 4281)
@@ -2,4 +2,7 @@
<model name="example">
<source name="jdbc-connector" translator-name="h2"
connection-jndi-name="java:/ServiceDS"/>
</model>
+ <model name="example1">
+ <source name="jdbc-connector" translator-name="h2"
connection-jndi-name="java:/ServiceDS"/>
+ </model>
</vdb>
\ No newline at end of file