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));
}
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;
}
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);
}
}
}
}
}
}
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);
}
}
}
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;
}
Aggregations