Author: rareddy
Date: 2011-11-18 15:03:35 -0500 (Fri, 18 Nov 2011)
New Revision: 3673
Modified:
branches/7.6.x/build/kits/jboss-container/deployers/teiid.deployer/teiid-deployer-jboss-beans.xml
branches/7.6.x/engine/src/main/java/org/teiid/dqp/internal/datamgr/ConnectorManager.java
branches/7.6.x/engine/src/test/java/org/teiid/dqp/internal/datamgr/TestConnectorManager.java
branches/7.6.x/jboss-integration/src/main/java/org/teiid/adminapi/jboss/Admin.java
branches/7.6.x/runtime/src/main/java/org/teiid/deployers/VDBStatusChecker.java
branches/7.6.x/runtime/src/main/resources/org/teiid/runtime/i18n.properties
branches/7.6.x/runtime/src/test/java/org/teiid/deployers/TestCompositeVDB.java
branches/7.6.x/test-integration/common/src/test/java/org/teiid/jdbc/TestLocalConnections.java
Log:
TEIID-1832: adding code to switch datasource or translator that has been modified on the
VDB
Modified:
branches/7.6.x/build/kits/jboss-container/deployers/teiid.deployer/teiid-deployer-jboss-beans.xml
===================================================================
---
branches/7.6.x/build/kits/jboss-container/deployers/teiid.deployer/teiid-deployer-jboss-beans.xml 2011-11-18
18:01:18 UTC (rev 3672)
+++
branches/7.6.x/build/kits/jboss-container/deployers/teiid.deployer/teiid-deployer-jboss-beans.xml 2011-11-18
20:03:35 UTC (rev 3673)
@@ -88,6 +88,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>
+ <property name="translatorRepository"><inject
bean="translatorRepository"/></property>
</bean>
<!-- Persistence class for the VDB deployment file -->
Modified:
branches/7.6.x/engine/src/main/java/org/teiid/dqp/internal/datamgr/ConnectorManager.java
===================================================================
---
branches/7.6.x/engine/src/main/java/org/teiid/dqp/internal/datamgr/ConnectorManager.java 2011-11-18
18:01:18 UTC (rev 3672)
+++
branches/7.6.x/engine/src/main/java/org/teiid/dqp/internal/datamgr/ConnectorManager.java 2011-11-18
20:03:35 UTC (rev 3673)
@@ -233,7 +233,7 @@
* Get the <code>Translator</code> object managed by this manager.
* @return the <code>ExecutionFactory</code>.
*/
- protected ExecutionFactory<Object, Object> getExecutionFactory() {
+ public ExecutionFactory<Object, Object> getExecutionFactory() {
return this.executionFactory;
}
Modified:
branches/7.6.x/engine/src/test/java/org/teiid/dqp/internal/datamgr/TestConnectorManager.java
===================================================================
---
branches/7.6.x/engine/src/test/java/org/teiid/dqp/internal/datamgr/TestConnectorManager.java 2011-11-18
18:01:18 UTC (rev 3672)
+++
branches/7.6.x/engine/src/test/java/org/teiid/dqp/internal/datamgr/TestConnectorManager.java 2011-11-18
20:03:35 UTC (rev 3673)
@@ -46,7 +46,7 @@
static ConnectorManager getConnectorManager() throws Exception {
final FakeConnector c = new FakeConnector();
ConnectorManager cm = new
ConnectorManager("FakeConnector","FakeConnector") { //$NON-NLS-1$
//$NON-NLS-2$
- protected ExecutionFactory getExecutionFactory() {
+ public ExecutionFactory getExecutionFactory() {
return c;
}
protected Object getConnectionFactory(){
Modified:
branches/7.6.x/jboss-integration/src/main/java/org/teiid/adminapi/jboss/Admin.java
===================================================================
---
branches/7.6.x/jboss-integration/src/main/java/org/teiid/adminapi/jboss/Admin.java 2011-11-18
18:01:18 UTC (rev 3672)
+++
branches/7.6.x/jboss-integration/src/main/java/org/teiid/adminapi/jboss/Admin.java 2011-11-18
20:03:35 UTC (rev 3673)
@@ -533,7 +533,10 @@
getView().updateComponent(mc);
} catch (Exception e) {
throw new AdminComponentException(e.getMessage(), e);
- }
+ }
+
+ // enforce the changes in the engine.
+ this.statusChecker.dataSourceReplaced(vdbName, vdbVersion, modelName, sourceName,
translatorName, dsName);
}
private void manageRoleToDataPolicy(String vdbName, int vdbVersion, String policyName,
String role, boolean add) throws AdminException {
Modified: branches/7.6.x/runtime/src/main/java/org/teiid/deployers/VDBStatusChecker.java
===================================================================
---
branches/7.6.x/runtime/src/main/java/org/teiid/deployers/VDBStatusChecker.java 2011-11-18
18:01:18 UTC (rev 3672)
+++
branches/7.6.x/runtime/src/main/java/org/teiid/deployers/VDBStatusChecker.java 2011-11-18
20:03:35 UTC (rev 3673)
@@ -23,22 +23,29 @@
import java.util.LinkedList;
+import org.jboss.deployers.spi.DeploymentException;
import org.jboss.util.threadpool.ThreadPool;
+import org.teiid.adminapi.AdminException;
+import org.teiid.adminapi.AdminProcessingException;
import org.teiid.adminapi.Model;
+import org.teiid.adminapi.Translator;
import org.teiid.adminapi.VDB;
import org.teiid.adminapi.impl.ModelMetaData;
import org.teiid.adminapi.impl.VDBMetaData;
import org.teiid.dqp.internal.datamgr.ConnectorManager;
import org.teiid.dqp.internal.datamgr.ConnectorManagerRepository;
+import org.teiid.dqp.internal.datamgr.TranslatorRepository;
import org.teiid.logging.LogConstants;
import org.teiid.logging.LogManager;
import org.teiid.runtime.RuntimePlugin;
+import org.teiid.translator.ExecutionFactory;
public class VDBStatusChecker {
private static final String JAVA_CONTEXT = "java:"; //$NON-NLS-1$
private VDBRepository vdbRepository;
private ThreadPool threadPool;
+ private TranslatorRepository translatorRepository;
public void translatorAdded(String translatorName) {
resourceAdded(translatorName, true);
@@ -62,6 +69,49 @@
resourceremoved(dataSourceName, false);
}
+ public void dataSourceReplaced(String vdbName, int vdbVersion,
+ String modelName, String sourceName, String translatorName,
+ String dsName) throws AdminException {
+ if (dsName.startsWith(JAVA_CONTEXT)) {
+ dsName = dsName.substring(5);
+ }
+
+ VDBMetaData vdb = this.vdbRepository.getVDB(vdbName, vdbVersion);
+ ModelMetaData model = vdb.getModel(modelName);
+
+ synchronized (vdb) {
+ ConnectorManagerRepository cmr = vdb.getAttachment(ConnectorManagerRepository.class);
+ ConnectorManager cm = cmr.getConnectorManager(sourceName);
+ ExecutionFactory<Object, Object> ef = cm.getExecutionFactory();
+
+ boolean dsReplaced = false;
+ if (!cm.getConnectionName().equals(dsName)){
+ vdb.setStatus(VDB.Status.INACTIVE);
+ String msg = RuntimePlugin.Util.getString("datasource_replaced",
vdb.getName(), vdb.getVersion(), model.getSourceTranslatorName(sourceName), dsName);
//$NON-NLS-1$
+ model.addError(ModelMetaData.ValidationError.Severity.ERROR.name(), msg);
+ cm = new ConnectorManager(translatorName, dsName);
+ cm.setExecutionFactory(ef);
+ cm.setModelName(modelName);
+ cmr.addConnectorManager(sourceName, cm);
+ dsReplaced = true;
+ }
+
+ if (!cm.getTranslatorName().equals(translatorName)) {
+ try {
+ Translator t = this.translatorRepository.getTranslatorMetaData(translatorName);
+ ef = TranslatorUtil.buildExecutionFactory(t);
+ cm.setExecutionFactory(ef);
+ } catch (DeploymentException e) {
+ throw new AdminProcessingException(e.getCause());
+ }
+ }
+
+ if (dsReplaced) {
+ resourceAdded(dsName, false);
+ }
+ }
+ }
+
public void setVDBRepository(VDBRepository repo) {
this.vdbRepository = repo;
}
@@ -173,4 +223,8 @@
public void setThreadPool(ThreadPool threadPool) {
this.threadPool = threadPool;
}
+
+ public void setTranslatorRepository(TranslatorRepository repo) {
+ this.translatorRepository = repo;
+ }
}
Modified: branches/7.6.x/runtime/src/main/resources/org/teiid/runtime/i18n.properties
===================================================================
--- branches/7.6.x/runtime/src/main/resources/org/teiid/runtime/i18n.properties 2011-11-18
18:01:18 UTC (rev 3672)
+++ branches/7.6.x/runtime/src/main/resources/org/teiid/runtime/i18n.properties 2011-11-18
20:03:35 UTC (rev 3673)
@@ -70,6 +70,7 @@
translator_not_found=For {0}.{1} VDB, Translator "{2}" not found.
recursive_delegation=For {0}.{1} VDB, recursive delegation {2} found.
datasource_not_found=For {0}.{1} VDB, Data Source "{2}" not found.
+datasource_replaced=For {0}.{1} VDB, Data Source "{2}" replaced with
"{3}"
vdb_activated={0}.{1} status has been changed to active
vdb_inactivated={0}.{1} status has been changed to inactive. Check the required
translators and data sources!
translator_added=Teiid translator "{0}" has been added.
Modified: branches/7.6.x/runtime/src/test/java/org/teiid/deployers/TestCompositeVDB.java
===================================================================
---
branches/7.6.x/runtime/src/test/java/org/teiid/deployers/TestCompositeVDB.java 2011-11-18
18:01:18 UTC (rev 3672)
+++
branches/7.6.x/runtime/src/test/java/org/teiid/deployers/TestCompositeVDB.java 2011-11-18
20:03:35 UTC (rev 3673)
@@ -78,7 +78,7 @@
Mockito.stub(ef.getPushDownFunctions()).toReturn(funcs);
ConnectorManager cm = new ConnectorManager(translatorName,connectionName) {
- protected ExecutionFactory getExecutionFactory() {
+ public ExecutionFactory getExecutionFactory() {
return ef;
}
};
Modified:
branches/7.6.x/test-integration/common/src/test/java/org/teiid/jdbc/TestLocalConnections.java
===================================================================
---
branches/7.6.x/test-integration/common/src/test/java/org/teiid/jdbc/TestLocalConnections.java 2011-11-18
18:01:18 UTC (rev 3672)
+++
branches/7.6.x/test-integration/common/src/test/java/org/teiid/jdbc/TestLocalConnections.java 2011-11-18
20:03:35 UTC (rev 3673)
@@ -102,7 +102,7 @@
public ConnectorManager getConnectorManager(String connectorName) {
return new ConnectorManager(connectorName, connectorName) {
@Override
- protected ExecutionFactory<Object, Object> getExecutionFactory() {
+ public ExecutionFactory<Object, Object> getExecutionFactory() {
return new ExecutionFactory<Object, Object>() {
@Override
public Execution createExecution(Command command,