Search in sources :

Example 6 with ConnectorManagerRepository

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

the class RuntimeVDB method removeSource.

public ReplaceResult removeSource(String modelName, String sourceName) throws AdminProcessingException {
    synchronized (this.vdb) {
        ModelMetaData model = this.vdb.getModel(modelName);
        if (model == null) {
            throw new AdminProcessingException(RuntimePlugin.Event.TEIID40090, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40090, modelName, this.vdb.getName(), this.vdb.getVersion()));
        }
        if (!model.isSupportsMultiSourceBindings()) {
            throw new AdminProcessingException(RuntimePlugin.Event.TEIID40108, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40108, modelName, this.vdb.getName(), this.vdb.getVersion()));
        }
        if (model.getSources().size() == 1) {
            throw new AdminProcessingException(RuntimePlugin.Event.TEIID40109, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40109, modelName, this.vdb.getName(), this.vdb.getVersion()));
        }
        SourceMappingMetadata source = model.getSources().remove(sourceName);
        if (source == null) {
            throw new AdminProcessingException(RuntimePlugin.Event.TEIID40091, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40091, sourceName, modelName, this.vdb.getName(), this.vdb.getVersion()));
        }
        if (model.getSources().size() == 1) {
            // we default to multi-source with multiple sources, so now we need to explicitly set to true
            model.setSupportsMultiSourceBindings(true);
        }
        String previousDsName = source.getConnectionJndiName();
        boolean success = false;
        try {
            this.listener.dataSourceChanged(modelName, sourceName, null, null);
            ConnectorManagerRepository cmr = vdb.getAttachment(ConnectorManagerRepository.class);
            // detect if the ConnectorManager is still used
            boolean exists = false;
            for (ModelMetaData m : this.vdb.getModelMetaDatas().values()) {
                if (m == model) {
                    continue;
                }
                if (m.getSourceMapping(sourceName) != null) {
                    exists = true;
                    break;
                }
            }
            if (!exists) {
                cmr.removeConnectorManager(sourceName);
            }
            ReplaceResult rr = new ReplaceResult();
            if (!dsExists(previousDsName, cmr)) {
                rr.removedDs = previousDsName;
            }
            success = true;
            return rr;
        } finally {
            if (!success) {
                // TODO: this means that the order has changed
                model.addSourceMapping(source);
            }
        }
    }
}
Also used : SourceMappingMetadata(org.teiid.adminapi.impl.SourceMappingMetadata) ConnectorManagerRepository(org.teiid.dqp.internal.datamgr.ConnectorManagerRepository) AdminProcessingException(org.teiid.adminapi.AdminProcessingException) ModelMetaData(org.teiid.adminapi.impl.ModelMetaData)

Example 7 with ConnectorManagerRepository

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

the class VDBRepository method validateDataSources.

void validateDataSources(VDBMetaData vdb) {
    ConnectorManagerRepository cmr = vdb.getAttachment(ConnectorManagerRepository.class);
    for (ModelMetaData model : vdb.getModelMetaDatas().values()) {
        if (model.isSource()) {
            Collection<SourceMappingMetadata> mappings = model.getSourceMappings();
            for (SourceMappingMetadata mapping : mappings) {
                ConnectorManager cm = cmr.getConnectorManager(mapping.getName());
                if (cm != null) {
                    String msg = cm.getStausMessage();
                    if (msg != null && msg.length() > 0) {
                        model.addRuntimeError(msg);
                        model.setMetadataStatus(Model.MetadataStatus.FAILED);
                        LogManager.logInfo(LogConstants.CTX_RUNTIME, msg);
                    }
                }
            }
        }
    }
}
Also used : SourceMappingMetadata(org.teiid.adminapi.impl.SourceMappingMetadata) ConnectorManagerRepository(org.teiid.dqp.internal.datamgr.ConnectorManagerRepository) ConnectorManager(org.teiid.dqp.internal.datamgr.ConnectorManager) ModelMetaData(org.teiid.adminapi.impl.ModelMetaData)

Example 8 with ConnectorManagerRepository

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

the class VDBStatusChecker method dataSourceRemoved.

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

Example 9 with ConnectorManagerRepository

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

the class TestCompositeVDB method testRoleInherit.

@Test
public void testRoleInherit() throws Exception {
    VDBRepository repo = new VDBRepository();
    repo.setSystemStore(RealMetadataFactory.example1Cached().getMetadataStore());
    repo.setSystemFunctionManager(RealMetadataFactory.SFM);
    MetadataStore metadataStore = new MetadataStore();
    RealMetadataFactory.createPhysicalModel("x", metadataStore);
    VDBMetaData vdb = createVDBMetadata(metadataStore, "bqt");
    DataPolicyMetadata dpm = new DataPolicyMetadata();
    dpm.setName("x");
    dpm.setGrantAll(true);
    vdb.addDataPolicy(dpm);
    ConnectorManagerRepository cmr = new ConnectorManagerRepository();
    cmr.addConnectorManager("x", new ConnectorManager("y", "z"));
    repo.addVDB(vdb, metadataStore, null, null, cmr);
    metadataStore = new MetadataStore();
    RealMetadataFactory.createPhysicalModel("y", metadataStore);
    vdb = createVDBMetadata(metadataStore, "ex");
    VDBImportMetadata vdbImport = new VDBImportMetadata();
    vdbImport.setName("bqt");
    vdbImport.setVersion("1");
    vdbImport.setImportDataPolicies(true);
    vdb.getVDBImports().add(vdbImport);
    repo.addVDB(vdb, metadataStore, null, null, new ConnectorManagerRepository());
    vdb = repo.getLiveVDB("ex");
    assertEquals(1, vdb.getDataPolicyMap().get("x").getSchemas().size());
}
Also used : MetadataStore(org.teiid.metadata.MetadataStore) VDBImportMetadata(org.teiid.adminapi.impl.VDBImportMetadata) ConnectorManagerRepository(org.teiid.dqp.internal.datamgr.ConnectorManagerRepository) DataPolicyMetadata(org.teiid.adminapi.impl.DataPolicyMetadata) VDBMetaData(org.teiid.adminapi.impl.VDBMetaData) ConnectorManager(org.teiid.dqp.internal.datamgr.ConnectorManager) Test(org.junit.Test)

Example 10 with ConnectorManagerRepository

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

the class TestCompositeVDB method testDeepNesting.

@Test
public void testDeepNesting() throws Exception {
    VDBRepository repo = new VDBRepository();
    repo.setSystemStore(RealMetadataFactory.example1Cached().getMetadataStore());
    repo.setSystemFunctionManager(RealMetadataFactory.SFM);
    MetadataStore metadataStore = new MetadataStore();
    RealMetadataFactory.createPhysicalModel("x", metadataStore);
    VDBMetaData vdb = createVDBMetadata(metadataStore, "bqt");
    ConnectorManagerRepository cmr = new ConnectorManagerRepository();
    cmr.addConnectorManager("x", new ConnectorManager("y", "z"));
    repo.addVDB(vdb, metadataStore, null, null, cmr);
    metadataStore = new MetadataStore();
    RealMetadataFactory.createPhysicalModel("y", metadataStore);
    vdb = createVDBMetadata(metadataStore, "ex");
    VDBImportMetadata vdbImport = new VDBImportMetadata();
    vdbImport.setName("bqt");
    vdbImport.setVersion("1");
    vdb.getVDBImports().add(vdbImport);
    repo.addVDB(vdb, metadataStore, null, null, new ConnectorManagerRepository());
    VDBMetaData vdbInstance = repo.getVDB("ex", "1");
    assertTrue(!vdbInstance.getAttachment(ConnectorManagerRepository.class).getConnectorManagers().isEmpty());
    metadataStore = new MetadataStore();
    RealMetadataFactory.createPhysicalModel("z", metadataStore);
    vdb = createVDBMetadata(metadataStore, "ex1");
    vdbImport = new VDBImportMetadata();
    vdbImport.setName("ex");
    vdbImport.setVersion("1");
    vdb.getVDBImports().add(vdbImport);
    repo.addVDB(vdb, metadataStore, null, null, new ConnectorManagerRepository());
    vdbInstance = repo.getVDB("ex1", "1");
    assertTrue(!vdbInstance.getAttachment(ConnectorManagerRepository.class).getConnectorManagers().isEmpty());
}
Also used : MetadataStore(org.teiid.metadata.MetadataStore) VDBImportMetadata(org.teiid.adminapi.impl.VDBImportMetadata) ConnectorManagerRepository(org.teiid.dqp.internal.datamgr.ConnectorManagerRepository) VDBMetaData(org.teiid.adminapi.impl.VDBMetaData) 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