use of org.teiid.dqp.internal.datamgr.ConnectorManagerRepository in project teiid by teiid.
the class VDBStatusChecker method resourceAdded.
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()) {
continue;
}
String sourceName = getSourceName(resourceName, model);
if (sourceName == null) {
continue;
}
usesResourse = true;
ConnectorManager cm = cmr.getConnectorManager(sourceName);
checkStatus(runnables, vdb, model, cm);
}
if (usesResourse) {
updateVDB(runnables, vdb);
}
}
}
use of org.teiid.dqp.internal.datamgr.ConnectorManagerRepository in project teiid by teiid.
the class CompositeVDB method buildCompositeState.
private void buildCompositeState(VDBRepository vdbRepository) throws VirtualDatabaseException {
if (vdb.getVDBImports().isEmpty()) {
this.vdb.addAttchment(ConnectorManagerRepository.class, this.cmr);
return;
}
VDBMetaData newMergedVDB = this.vdb.clone();
ConnectorManagerRepository mergedRepo = this.cmr;
if (!this.cmr.isShared()) {
mergedRepo = new ConnectorManagerRepository();
mergedRepo.getConnectorManagers().putAll(this.cmr.getConnectorManagers());
}
newMergedVDB.addAttchment(ConnectorManagerRepository.class, mergedRepo);
ClassLoader[] toSearch = new ClassLoader[vdb.getVDBImports().size() + 1];
toSearch[0] = this.vdb.getAttachment(ClassLoader.class);
this.children = new LinkedHashMap<VDBKey, CompositeVDB>();
newMergedVDB.setImportedModels(new TreeSet<String>(String.CASE_INSENSITIVE_ORDER));
int i = 1;
for (VDBImport vdbImport : vdb.getVDBImports()) {
VDBKey key = new VDBKey(vdbImport.getName(), vdbImport.getVersion());
if (key.isAtMost()) {
// TODO: could allow partial versions
throw new VirtualDatabaseException(RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40144, vdbKey, key));
}
CompositeVDB importedVDB = vdbRepository.getCompositeVDB(key);
if (importedVDB == null) {
throw new VirtualDatabaseException(RuntimePlugin.Event.TEIID40083, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40083, vdb.getName(), vdb.getVersion(), vdbImport.getName(), vdbImport.getVersion()));
}
VDBMetaData childVDB = importedVDB.getVDB();
newMergedVDB.getVisibilityOverrides().putAll(childVDB.getVisibilityOverrides());
toSearch[i++] = childVDB.getAttachment(ClassLoader.class);
this.children.put(importedVDB.getVDBKey(), importedVDB);
if (vdbImport.isImportDataPolicies()) {
for (DataPolicy dp : importedVDB.getVDB().getDataPolicies()) {
DataPolicyMetadata role = (DataPolicyMetadata) dp;
if (newMergedVDB.addDataPolicy(role) != null) {
throw new VirtualDatabaseException(RuntimePlugin.Event.TEIID40084, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40084, vdb.getName(), vdb.getVersion(), vdbImport.getName(), vdbImport.getVersion(), role.getName()));
}
if (role.isGrantAll()) {
role.setSchemas(childVDB.getModelMetaDatas().keySet());
}
}
}
// add models
for (ModelMetaData m : childVDB.getModelMetaDatas().values()) {
if (newMergedVDB.addModel(m) != null) {
throw new VirtualDatabaseException(RuntimePlugin.Event.TEIID40085, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40085, vdb.getName(), vdb.getVersion(), vdbImport.getName(), vdbImport.getVersion(), m.getName()));
}
newMergedVDB.getImportedModels().add(m.getName());
// $NON-NLS-1$
String visibilityOverride = newMergedVDB.getPropertyValue(m.getName() + ".visible");
if (visibilityOverride != null) {
boolean visible = Boolean.valueOf(visibilityOverride);
newMergedVDB.setVisibilityOverride(m.getName(), visible);
}
}
ConnectorManagerRepository childCmr = childVDB.getAttachment(ConnectorManagerRepository.class);
if (childCmr == null) {
// $NON-NLS-1$
throw new AssertionError("childVdb does not have a connector manager repository");
}
if (!this.cmr.isShared()) {
for (Map.Entry<String, ConnectorManager> entry : childCmr.getConnectorManagers().entrySet()) {
if (mergedRepo.getConnectorManagers().put(entry.getKey(), entry.getValue()) != null) {
throw new VirtualDatabaseException(RuntimePlugin.Event.TEIID40086, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40086, vdb.getName(), vdb.getVersion(), vdbImport.getName(), vdbImport.getVersion(), entry.getKey()));
}
}
}
}
if (toSearch[0] != null) {
CombinedClassLoader ccl = new CombinedClassLoader(toSearch[0].getParent(), toSearch);
this.mergedVDB.addAttchment(ClassLoader.class, ccl);
}
this.mergedVDB = newMergedVDB;
}
use of org.teiid.dqp.internal.datamgr.ConnectorManagerRepository in project teiid by teiid.
the class TestVDBStatusChecker method testDataSourceReplaced.
@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;
}
};
VDBTranslatorMetaData factory = new VDBTranslatorMetaData();
factory.setExecutionFactoryClass(ExecutionFactory.class);
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.setProvider(new ExecutionFactoryProvider() {
@Override
public ExecutionFactory<Object, Object> getExecutionFactory(String name) throws ConnectorManagerException {
return new ExecutionFactory<Object, Object>();
}
});
ExecutionFactory ef1 = new ExecutionFactory();
ConnectorManager mgr = new ConnectorManager("oracle", "dsName", ef1);
cmr.addConnectorManager("BQT1", mgr);
repo.addVDB(vdb, metadataStore, null, null, cmr);
assertTrue(vsc.dataSourceReplaced("bqt", "1", "BQT1", "BQT1", "oracle", "dsName1"));
ExecutionFactory ef = cmr.getConnectorManager("BQT1").getExecutionFactory();
assertSame(ef, ef1);
assertFalse(vsc.dataSourceReplaced("bqt", "1", "BQT1", "BQT1", "sqlserver", "dsName1"));
ExecutionFactory ef2 = cmr.getConnectorManager("BQT1").getExecutionFactory();
assertNotNull(ef2);
assertNotSame(ef, ef2);
assertTrue(vsc.dataSourceReplaced("bqt", "1", "BQT1", "BQT1", "oracle", "dsName2"));
ef = cmr.getConnectorManager("BQT1").getExecutionFactory();
assertNotNull(ef);
assertNotSame(ef, ef2);
}
use of org.teiid.dqp.internal.datamgr.ConnectorManagerRepository in project teiid by teiid.
the class EmbeddedAdminImpl method restartVDB.
@Override
public void restartVDB(String vdbName, String vdbVersion, String... models) throws AdminException {
VDBMetaData vdb = checkVDB(vdbName, vdbVersion);
synchronized (vdb) {
try {
// need remove model cache first
VDBMetaData currentVdb = this.embeddedServer.repo.removeVDB(vdbName, vdbVersion);
ConnectorManagerRepository cmr = this.embeddedServer.cmr;
UDFMetaData udf = currentVdb.getAttachment(UDFMetaData.class);
// need get the visibilityMap from runtime
LinkedHashMap<String, VDBResources.Resource> visibilityMap = new LinkedHashMap<String, VDBResources.Resource>();
MetadataStore store = new MetadataStore();
this.embeddedServer.repo.addVDB(currentVdb, store, visibilityMap, udf, cmr);
} catch (Exception e) {
throw new AdminProcessingException(RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40135, vdbName, vdbVersion, models), e);
}
}
}
use of org.teiid.dqp.internal.datamgr.ConnectorManagerRepository in project teiid by teiid.
the class TestCompositeVDB method testFunctionValidationError.
@Test
public void testFunctionValidationError() throws Exception {
VDBRepository repo = new VDBRepository();
repo.start();
repo.setSystemStore(RealMetadataFactory.example1Cached().getMetadataStore());
repo.setSystemFunctionManager(RealMetadataFactory.SFM);
MetadataStore metadataStore = new MetadataStore();
RealMetadataFactory.createPhysicalModel("x", metadataStore);
FunctionMethod method = MetadataFactory.createFunctionFromMethod("getProperty", System.class.getMethod("getProperty", String.class));
method.setInvocationClass("?");
method.setMethod(null);
metadataStore.getSchema("x").addFunction(method);
VDBMetaData vdb = createVDBMetadata(metadataStore, "bqt");
ConnectorManagerRepository cmr = new ConnectorManagerRepository();
cmr.addConnectorManager("x", new ConnectorManager("y", "z"));
repo.addVDB(vdb, metadataStore, null, null, cmr);
repo.finishDeployment(vdb.getName(), vdb.getVersion());
assertEquals(vdb.getStatus(), Status.FAILED);
}
Aggregations