Search in sources :

Example 1 with ConnectorManager

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

the class TestConnectorCapabilitiesFinder method testFindRequiresSource.

@Test
public void testFindRequiresSource() throws Exception {
    // $NON-NLS-1$
    String modelName = "model";
    // $NON-NLS-1$
    String functionName = "fakeFunction";
    ArrayList<String> bindings = new ArrayList<String>();
    bindings.add(modelName);
    VDBMetaData vdb = Mockito.mock(VDBMetaData.class);
    ModelMetaData model = Mockito.mock(ModelMetaData.class);
    Mockito.stub(vdb.getModel(modelName)).toReturn(model);
    Mockito.stub(model.getSourceNames()).toReturn(bindings);
    BasicSourceCapabilities basicSourceCapabilities = new BasicSourceCapabilities();
    basicSourceCapabilities.setFunctionSupport(functionName, true);
    ConnectorManagerRepository repo = Mockito.mock(ConnectorManagerRepository.class);
    ConnectorManager cm = Mockito.mock(ConnectorManager.class);
    Mockito.stub(cm.getCapabilities()).toThrow(new TranslatorException());
    Mockito.stub(repo.getConnectorManager(Mockito.anyString())).toReturn(cm);
    CachedFinder finder = new CachedFinder(repo, vdb);
    // Test
    SourceCapabilities actual = finder.findCapabilities(modelName);
    // $NON-NLS-1$
    assertNotNull(actual);
    assertFalse(finder.isValid(modelName));
}
Also used : BasicSourceCapabilities(org.teiid.query.optimizer.capabilities.BasicSourceCapabilities) ConnectorManagerRepository(org.teiid.dqp.internal.datamgr.ConnectorManagerRepository) VDBMetaData(org.teiid.adminapi.impl.VDBMetaData) ArrayList(java.util.ArrayList) TranslatorException(org.teiid.translator.TranslatorException) ConnectorManager(org.teiid.dqp.internal.datamgr.ConnectorManager) SourceCapabilities(org.teiid.query.optimizer.capabilities.SourceCapabilities) BasicSourceCapabilities(org.teiid.query.optimizer.capabilities.BasicSourceCapabilities) ModelMetaData(org.teiid.adminapi.impl.ModelMetaData) Test(org.junit.Test)

Example 2 with ConnectorManager

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

the class CachedFinder method findCapabilities.

/**
 * Find capabilities used the cache if possible, otherwise do the lookup.
 */
public SourceCapabilities findCapabilities(String modelName) throws TeiidComponentException {
    SourceCapabilities caps = userCache.get(modelName);
    if (caps != null) {
        return caps;
    }
    ModelMetaData model = vdb.getModel(modelName);
    List<String> sourceNames = model.getSourceNames();
    if (sourceNames.isEmpty()) {
        throw new TeiidRuntimeException(QueryPlugin.Event.TEIID30499, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30499, modelName));
    }
    TeiidException cause = null;
    for (String sourceName : sourceNames) {
        // TOOD: in multi-source mode it may be necessary to compute minimal capabilities across the sources
        ConnectorManager mgr = this.connectorRepo.getConnectorManager(sourceName);
        if (mgr == null) {
            throw new TeiidComponentException(QueryPlugin.Event.TEIID30497, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30497, sourceName, modelName, sourceName));
        }
        try {
            caps = mgr.getCapabilities();
            break;
        } catch (TeiidException e) {
            cause = e;
            // $NON-NLS-1$
            LogManager.logDetail(LogConstants.CTX_DQP, e, "Could not obtain capabilities for" + sourceName);
        }
    }
    if (caps == null) {
        InvalidCaps ic = new InvalidCaps();
        ic.setSourceProperty(Capability.INVALID_EXCEPTION, cause);
        caps = ic;
    }
    userCache.put(modelName, caps);
    return caps;
}
Also used : TeiidComponentException(org.teiid.core.TeiidComponentException) SourceCapabilities(org.teiid.query.optimizer.capabilities.SourceCapabilities) BasicSourceCapabilities(org.teiid.query.optimizer.capabilities.BasicSourceCapabilities) TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) ConnectorManager(org.teiid.dqp.internal.datamgr.ConnectorManager) ModelMetaData(org.teiid.adminapi.impl.ModelMetaData) TeiidException(org.teiid.core.TeiidException)

Example 3 with ConnectorManager

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

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

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

the class CompositeVDB method getUDF.

private UDFMetaData getUDF() {
    UDFMetaData mergedUDF = new UDFMetaData();
    if (this.udf != null) {
        mergedUDF.addFunctions(this.udf);
    }
    for (Schema schema : store.getSchemas().values()) {
        Collection<FunctionMethod> funcs = schema.getFunctions().values();
        mergedUDF.addFunctions(schema.getName(), funcs);
    }
    if (this.cmr != null) {
        // system scoped common source functions
        for (ConnectorManager cm : this.cmr.getConnectorManagers().values()) {
            List<FunctionMethod> funcs = cm.getPushDownFunctions();
            mergedUDF.addFunctions(CoreConstants.SYSTEM_MODEL, funcs);
        }
    }
    if (this.children != null) {
        // udf model functions - also scoped to the model
        for (CompositeVDB child : this.children.values()) {
            UDFMetaData funcs = child.getUDF();
            if (funcs != null) {
                mergedUDF.addFunctions(funcs);
            }
        }
    }
    return mergedUDF;
}
Also used : Schema(org.teiid.metadata.Schema) FunctionMethod(org.teiid.metadata.FunctionMethod) ConnectorManager(org.teiid.dqp.internal.datamgr.ConnectorManager)

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