Search in sources :

Example 11 with ConnectorManager

use of org.teiid.dqp.internal.datamgr.ConnectorManager in project teiid by teiid.

the class RuntimeVDB method updateSource.

public ReplaceResult updateSource(String sourceName, String translatorName, String dsName) throws AdminProcessingException {
    synchronized (this.vdb) {
        ConnectorManagerRepository cmr = vdb.getAttachment(ConnectorManagerRepository.class);
        ConnectorManager cr = cmr.getConnectorManager(sourceName);
        if (cr == null) {
            throw new AdminProcessingException(RuntimePlugin.Event.TEIID40091, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40091, sourceName, this.vdb.getName(), this.vdb.getVersion()));
        }
        String previousTranslatorName = cr.getTranslatorName();
        String previousDsName = cr.getConnectionName();
        // modify all source elements in all models
        for (ModelMetaData m : this.vdb.getModelMetaDatas().values()) {
            SourceMappingMetadata mapping = m.getSourceMapping(sourceName);
            if (mapping != null) {
                mapping.setTranslatorName(translatorName);
                mapping.setConnectionJndiName(dsName);
            }
        }
        boolean success = false;
        try {
            this.listener.dataSourceChanged(null, sourceName, translatorName, dsName);
            ReplaceResult rr = new ReplaceResult();
            if (dsName != null) {
                rr.isNew = !dsExists(dsName, cmr);
            }
            boolean replaced = getVDBStatusChecker().dataSourceReplaced(vdb.getName(), vdb.getVersion(), null, sourceName, translatorName, dsName);
            if (replaced && previousDsName != null && !dsExists(previousDsName, cmr)) {
                rr.removedDs = previousDsName;
            }
            success = true;
            return rr;
        } finally {
            if (!success) {
                for (ModelMetaData m : this.vdb.getModelMetaDatas().values()) {
                    SourceMappingMetadata mapping = m.getSourceMapping(sourceName);
                    if (mapping != null) {
                        mapping.setTranslatorName(previousTranslatorName);
                        mapping.setConnectionJndiName(previousDsName);
                    }
                }
            }
        }
    }
}
Also used : SourceMappingMetadata(org.teiid.adminapi.impl.SourceMappingMetadata) ConnectorManagerRepository(org.teiid.dqp.internal.datamgr.ConnectorManagerRepository) ConnectorManager(org.teiid.dqp.internal.datamgr.ConnectorManager) AdminProcessingException(org.teiid.adminapi.AdminProcessingException) ModelMetaData(org.teiid.adminapi.impl.ModelMetaData)

Example 12 with ConnectorManager

use of org.teiid.dqp.internal.datamgr.ConnectorManager in project teiid by teiid.

the class VDBStatusChecker method updateSource.

/**
 * @return true if the datasource is new to the vdb
 * @throws AdminProcessingException
 */
public boolean updateSource(String vdbName, String vdbVersion, SourceMappingMetadata mapping, boolean replace) throws AdminProcessingException {
    String dsName = stripContext(mapping.getConnectionJndiName());
    VDBMetaData vdb = getVDBRepository().getLiveVDB(vdbName, vdbVersion);
    if (vdb == null || vdb.getStatus() == Status.FAILED) {
        return false;
    }
    synchronized (vdb) {
        ConnectorManagerRepository cmr = vdb.getAttachment(ConnectorManagerRepository.class);
        ConnectorManager existing = cmr.getConnectorManager(mapping.getName());
        try {
            cmr.createConnectorManager(vdb, cmr.getProvider(), mapping, replace);
        } catch (TeiidException e) {
            throw new AdminProcessingException(RuntimePlugin.Event.TEIID40033, e);
        }
        if (mapping.getConnectionJndiName() != null && (existing == null || !dsName.equals(existing.getConnectionName()))) {
            List<Runnable> runnables = new ArrayList<Runnable>();
            resourceAdded(dsName, runnables, vdb);
            return true;
        }
        return false;
    }
}
Also used : ConnectorManagerRepository(org.teiid.dqp.internal.datamgr.ConnectorManagerRepository) VDBMetaData(org.teiid.adminapi.impl.VDBMetaData) ArrayList(java.util.ArrayList) ConnectorManager(org.teiid.dqp.internal.datamgr.ConnectorManager) AdminProcessingException(org.teiid.adminapi.AdminProcessingException) TeiidException(org.teiid.core.TeiidException)

Example 13 with ConnectorManager

use of org.teiid.dqp.internal.datamgr.ConnectorManager 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 14 with ConnectorManager

use of org.teiid.dqp.internal.datamgr.ConnectorManager 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 15 with ConnectorManager

use of org.teiid.dqp.internal.datamgr.ConnectorManager 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)

Aggregations

ConnectorManager (org.teiid.dqp.internal.datamgr.ConnectorManager)22 ConnectorManagerRepository (org.teiid.dqp.internal.datamgr.ConnectorManagerRepository)15 ModelMetaData (org.teiid.adminapi.impl.ModelMetaData)9 VDBMetaData (org.teiid.adminapi.impl.VDBMetaData)9 TranslatorException (org.teiid.translator.TranslatorException)7 ArrayList (java.util.ArrayList)6 Test (org.junit.Test)6 ExecutionFactory (org.teiid.translator.ExecutionFactory)6 MetadataStore (org.teiid.metadata.MetadataStore)4 AdminProcessingException (org.teiid.adminapi.AdminProcessingException)3 SourceMappingMetadata (org.teiid.adminapi.impl.SourceMappingMetadata)3 TeiidException (org.teiid.core.TeiidException)3 VirtualDatabaseException (org.teiid.deployers.VirtualDatabaseException)3 ConnectorManagerException (org.teiid.dqp.internal.datamgr.ConnectorManagerRepository.ConnectorManagerException)3 FunctionMethod (org.teiid.metadata.FunctionMethod)3 MetadataFactory (org.teiid.metadata.MetadataFactory)3 IOException (java.io.IOException)2 List (java.util.List)2 Map (java.util.Map)2 XMLStreamException (javax.xml.stream.XMLStreamException)2