Search in sources :

Example 16 with ConnectorManager

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

the class AbstractVDBDeployer method processVDBDDL.

private void processVDBDDL(final VDBMetaData vdb, final MetadataStore vdbMetadataStore, final ConnectorManagerRepository cmr, final VDBResources vdbResources) {
    if (vdb.getStatus() == Status.FAILED) {
        return;
    }
    String ddl = vdb.getPropertyValue(VDBMetaData.TEIID_DDL);
    if (ddl != null) {
        final Database database = DatabaseUtil.convert(vdb, vdbMetadataStore);
        CompositeMetadataStore compositeStore = new CompositeMetadataStore(vdbMetadataStore);
        final TransformationMetadata metadata = new TransformationMetadata(vdb, compositeStore, null, getVDBRepository().getSystemFunctionManager().getSystemFunctions(), null);
        DeploymentBasedDatabaseStore deploymentStore = new DeploymentBasedDatabaseStore(getVDBRepository()) {

            @Override
            protected TransformationMetadata getTransformationMetadata() {
                return metadata;
            }

            @Override
            public void importSchema(String schemaName, String serverType, String serverName, String foreignSchemaName, List<String> includeTables, List<String> excludeTables, Map<String, String> properties) {
                ModelMetaData model = vdb.getModel(schemaName);
                MetadataFactory factory = DatabaseStore.createMF(this, getSchema(schemaName), true);
                factory.getModelProperties().putAll(model.getPropertiesMap());
                factory.getModelProperties().putAll(properties);
                if (!includeTables.isEmpty()) {
                    // $NON-NLS-1$
                    factory.getModelProperties().put("importer.includeTables", StringUtil.join(includeTables, ","));
                }
                if (!excludeTables.isEmpty()) {
                    // $NON-NLS-1$
                    factory.getModelProperties().put("importer.excludeTables", StringUtil.join(excludeTables, ","));
                }
                factory.setParser(new QueryParser());
                if (vdbResources != null) {
                    factory.setVdbResources(vdbResources.getEntriesPlusVisibilities());
                }
                MetadataRepository baseRepo = model.getAttachment(MetadataRepository.class);
                MetadataRepository metadataRepository;
                try {
                    metadataRepository = getMetadataRepository(serverType);
                    if (metadataRepository == null) {
                        throw new VirtualDatabaseException(RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40094, model.getName(), vdb.getName(), vdb.getVersion(), serverType));
                    }
                } catch (VirtualDatabaseException e1) {
                    throw new MetadataException(e1);
                }
                metadataRepository = new ChainingMetadataRepository(Arrays.asList(new MetadataRepositoryWrapper(metadataRepository, null), baseRepo));
                ExecutionFactory ef = null;
                Object cf = null;
                Exception te = null;
                for (ConnectorManager cm : getConnectorManagers(model, cmr)) {
                    if (te != null) {
                        // $NON-NLS-1$
                        LogManager.logDetail(LogConstants.CTX_RUNTIME, te, "Failed to get metadata, trying next source.");
                        te = null;
                    }
                    try {
                        if (cm != null) {
                            ef = cm.getExecutionFactory();
                            cf = cm.getConnectionFactory();
                        }
                    } catch (TranslatorException e) {
                        // $NON-NLS-1$
                        LogManager.logDetail(LogConstants.CTX_RUNTIME, e, "Failed to get a connection factory for metadata load.");
                    }
                    if (LogManager.isMessageToBeRecorded(LogConstants.CTX_RUNTIME, MessageLevel.TRACE)) {
                        // $NON-NLS-1$ //$NON-NLS-2$
                        LogManager.logTrace(LogConstants.CTX_RUNTIME, "CREATE SCHEMA", factory.getSchema().getName(), ";\n", DDLStringVisitor.getDDLString(factory.getSchema(), null, null));
                    }
                    try {
                        metadataRepository.loadMetadata(factory, ef, cf);
                        break;
                    } catch (Exception e) {
                        te = e;
                        factory = DatabaseStore.createMF(this, getSchema(schemaName), true);
                        factory.getModelProperties().putAll(model.getPropertiesMap());
                        factory.getModelProperties().putAll(properties);
                        factory.setParser(new QueryParser());
                        if (vdbResources != null) {
                            factory.setVdbResources(vdbResources.getEntriesPlusVisibilities());
                        }
                    }
                }
                if (te != null) {
                    if (te instanceof RuntimeException) {
                        throw (RuntimeException) te;
                    }
                    throw new MetadataException(te);
                }
            }
        };
        deploymentStore.startEditing(false);
        deploymentStore.databaseCreated(database);
        deploymentStore.databaseSwitched(database.getName(), database.getVersion());
        deploymentStore.setMode(Mode.SCHEMA);
        try {
            QueryParser.getQueryParser().parseDDL(deploymentStore, new StringReader(ddl));
        } finally {
            deploymentStore.stopEditing();
        }
        DatabaseUtil.copyDatabaseGrantsAndRoles(database, vdb);
    }
}
Also used : ExecutionFactory(org.teiid.translator.ExecutionFactory) ConnectorManager(org.teiid.dqp.internal.datamgr.ConnectorManager) DeploymentBasedDatabaseStore(org.teiid.metadatastore.DeploymentBasedDatabaseStore) MetadataException(org.teiid.metadata.MetadataException) MetadataException(org.teiid.metadata.MetadataException) TranslatorException(org.teiid.translator.TranslatorException) VirtualDatabaseException(org.teiid.deployers.VirtualDatabaseException) ModelMetaData(org.teiid.adminapi.impl.ModelMetaData) MetadataRepository(org.teiid.metadata.MetadataRepository) QueryParser(org.teiid.query.parser.QueryParser) MetadataFactory(org.teiid.metadata.MetadataFactory) Database(org.teiid.metadata.Database) StringReader(java.io.StringReader) ArrayList(java.util.ArrayList) List(java.util.List) TranslatorException(org.teiid.translator.TranslatorException) VirtualDatabaseException(org.teiid.deployers.VirtualDatabaseException) Map(java.util.Map) ConcurrentSkipListMap(java.util.concurrent.ConcurrentSkipListMap)

Example 17 with ConnectorManager

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

the class AbstractVDBDeployer method getConnectorManagers.

protected List<ConnectorManager> getConnectorManagers(final ModelMetaData model, final ConnectorManagerRepository cmr) {
    if (model.isSource()) {
        Collection<SourceMappingMetadata> mappings = model.getSources().values();
        List<ConnectorManager> result = new ArrayList<ConnectorManager>(mappings.size());
        for (SourceMappingMetadata mapping : mappings) {
            result.add(cmr.getConnectorManager(mapping.getName()));
        }
        return result;
    }
    // return a single null to give us something to loop over
    return Collections.singletonList(null);
}
Also used : SourceMappingMetadata(org.teiid.adminapi.impl.SourceMappingMetadata) ArrayList(java.util.ArrayList) ConnectorManager(org.teiid.dqp.internal.datamgr.ConnectorManager)

Example 18 with ConnectorManager

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

the class EmbeddedServer method loadMetadata.

/**
 * TODO: consolidate this logic more into the abstract deployer
 */
@Override
protected void loadMetadata(VDBMetaData vdb, ModelMetaData model, ConnectorManagerRepository cmr, MetadataRepository metadataRepository, MetadataStore store, AtomicInteger loadCount, VDBResources vdbResources) throws TranslatorException {
    MetadataFactory factory = createMetadataFactory(vdb, store, model, vdbResources == null ? Collections.EMPTY_MAP : vdbResources.getEntriesPlusVisibilities());
    ExecutionFactory ef = null;
    Object cf = null;
    Exception te = null;
    for (ConnectorManager cm : getConnectorManagers(model, cmr)) {
        if (te != null) {
            // $NON-NLS-1$
            LogManager.logDetail(LogConstants.CTX_RUNTIME, te, "Failed to get metadata, trying next source.");
            te = null;
        }
        try {
            if (cm != null) {
                ef = cm.getExecutionFactory();
                cf = cm.getConnectionFactory();
            }
        } catch (TranslatorException e) {
            // $NON-NLS-1$
            LogManager.logDetail(LogConstants.CTX_RUNTIME, e, "Failed to get a connection factory for metadata load.");
        }
        if (LogManager.isMessageToBeRecorded(LogConstants.CTX_RUNTIME, MessageLevel.TRACE)) {
            // $NON-NLS-1$ //$NON-NLS-2$
            LogManager.logTrace(LogConstants.CTX_RUNTIME, "CREATE SCHEMA", factory.getSchema().getName(), ";\n", DDLStringVisitor.getDDLString(factory.getSchema(), null, null));
        }
        try {
            metadataRepository.loadMetadata(factory, ef, cf);
            break;
        } catch (Exception e) {
            te = e;
            factory = createMetadataFactory(vdb, store, model, vdbResources == null ? Collections.EMPTY_MAP : vdbResources.getEntriesPlusVisibilities());
        }
    }
    if (te != null) {
        if (te instanceof TranslatorException) {
            throw (TranslatorException) te;
        }
        if (te instanceof RuntimeException) {
            throw (RuntimeException) te;
        }
        throw new TranslatorException(te);
    }
    metadataLoaded(vdb, model, store, loadCount, factory, true, cmr, vdbResources);
}
Also used : TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) MetadataFactory(org.teiid.metadata.MetadataFactory) ExecutionFactory(org.teiid.translator.ExecutionFactory) TranslatorException(org.teiid.translator.TranslatorException) ConnectorManager(org.teiid.dqp.internal.datamgr.ConnectorManager) ConnectorManagerException(org.teiid.dqp.internal.datamgr.ConnectorManagerRepository.ConnectorManagerException) InvalidSessionException(org.teiid.client.security.InvalidSessionException) XMLStreamException(javax.xml.stream.XMLStreamException) TeiidSQLException(org.teiid.jdbc.TeiidSQLException) ConnectionException(org.teiid.net.ConnectionException) SQLException(java.sql.SQLException) TranslatorException(org.teiid.translator.TranslatorException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) URISyntaxException(java.net.URISyntaxException) TeiidException(org.teiid.core.TeiidException) SAXException(org.xml.sax.SAXException) VirtualDatabaseException(org.teiid.deployers.VirtualDatabaseException) TeiidRuntimeException(org.teiid.core.TeiidRuntimeException)

Example 19 with ConnectorManager

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

Example 20 with ConnectorManager

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

the class TestCompositeVDB method getConnectorManager.

private static ConnectorManager getConnectorManager(String translatorName, String connectionName, List<FunctionMethod> funcs) {
    final ExecutionFactory<Object, Object> ef = Mockito.mock(ExecutionFactory.class);
    Mockito.stub(ef.getPushDownFunctions()).toReturn(funcs);
    ConnectorManager cm = new ConnectorManager(translatorName, connectionName, ef);
    cm.start();
    return cm;
}
Also used : 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