Search in sources :

Example 21 with ConnectorManagerRepository

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);
        }
    }
}
Also used : ConnectorManagerRepository(org.teiid.dqp.internal.datamgr.ConnectorManagerRepository) ConnectorManager(org.teiid.dqp.internal.datamgr.ConnectorManager) ModelMetaData(org.teiid.adminapi.impl.ModelMetaData)

Example 22 with ConnectorManagerRepository

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;
}
Also used : ConnectorManagerRepository(org.teiid.dqp.internal.datamgr.ConnectorManagerRepository) ConnectorManager(org.teiid.dqp.internal.datamgr.ConnectorManager) ModelMetaData(org.teiid.adminapi.impl.ModelMetaData) VDBKey(org.teiid.vdb.runtime.VDBKey) DataPolicyMetadata(org.teiid.adminapi.impl.DataPolicyMetadata) VDBMetaData(org.teiid.adminapi.impl.VDBMetaData) VDBImport(org.teiid.adminapi.VDBImport) DataPolicy(org.teiid.adminapi.DataPolicy) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 23 with ConnectorManagerRepository

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);
}
Also used : ConnectorManagerRepository(org.teiid.dqp.internal.datamgr.ConnectorManagerRepository) ExecutionFactory(org.teiid.translator.ExecutionFactory) ConnectorManager(org.teiid.dqp.internal.datamgr.ConnectorManager) MetadataStore(org.teiid.metadata.MetadataStore) ConnectorManagerException(org.teiid.dqp.internal.datamgr.ConnectorManagerRepository.ConnectorManagerException) ExecutionFactoryProvider(org.teiid.dqp.internal.datamgr.ConnectorManagerRepository.ExecutionFactoryProvider) VDBMetaData(org.teiid.adminapi.impl.VDBMetaData) VDBTranslatorMetaData(org.teiid.adminapi.impl.VDBTranslatorMetaData) Test(org.junit.Test)

Example 24 with ConnectorManagerRepository

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);
        }
    }
}
Also used : MetadataStore(org.teiid.metadata.MetadataStore) ConnectorManagerRepository(org.teiid.dqp.internal.datamgr.ConnectorManagerRepository) VDBMetaData(org.teiid.adminapi.impl.VDBMetaData) UDFMetaData(org.teiid.deployers.UDFMetaData) VDBResources(org.teiid.query.metadata.VDBResources) TransformerException(javax.xml.transform.TransformerException) TeiidComponentException(org.teiid.core.TeiidComponentException) SessionServiceException(org.teiid.dqp.service.SessionServiceException)

Example 25 with ConnectorManagerRepository

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);
}
Also used : MetadataStore(org.teiid.metadata.MetadataStore) ConnectorManagerRepository(org.teiid.dqp.internal.datamgr.ConnectorManagerRepository) VDBMetaData(org.teiid.adminapi.impl.VDBMetaData) FunctionMethod(org.teiid.metadata.FunctionMethod) ConnectorManager(org.teiid.dqp.internal.datamgr.ConnectorManager) Test(org.junit.Test)

Aggregations

ConnectorManagerRepository (org.teiid.dqp.internal.datamgr.ConnectorManagerRepository)30 ConnectorManager (org.teiid.dqp.internal.datamgr.ConnectorManager)15 VDBMetaData (org.teiid.adminapi.impl.VDBMetaData)14 Test (org.junit.Test)9 ModelMetaData (org.teiid.adminapi.impl.ModelMetaData)9 MetadataStore (org.teiid.metadata.MetadataStore)8 ArrayList (java.util.ArrayList)5 ExecutionFactory (org.teiid.translator.ExecutionFactory)5 TranslatorException (org.teiid.translator.TranslatorException)5 AdminProcessingException (org.teiid.adminapi.AdminProcessingException)4 SourceMappingMetadata (org.teiid.adminapi.impl.SourceMappingMetadata)4 FakeTransactionService (org.teiid.dqp.internal.datamgr.FakeTransactionService)4 AutoGenDataService (org.teiid.dqp.service.AutoGenDataService)4 HashMap (java.util.HashMap)3 DataPolicyMetadata (org.teiid.adminapi.impl.DataPolicyMetadata)3 VDBImportMetadata (org.teiid.adminapi.impl.VDBImportMetadata)3 ConnectorManagerException (org.teiid.dqp.internal.datamgr.ConnectorManagerRepository.ConnectorManagerException)3 List (java.util.List)2 BeforeClass (org.junit.BeforeClass)2 DataPolicy (org.teiid.adminapi.DataPolicy)2