Search in sources :

Example 1 with DeploymentBasedDatabaseStore

use of org.teiid.metadatastore.DeploymentBasedDatabaseStore in project teiid by teiid.

the class EmbeddedServer method deployVDBZip.

/**
 * Deploy a vdb zip file.  The name and version will be derived from the xml.
 * @param url
 * @throws TranslatorException
 * @throws ConnectorManagerException
 * @throws VirtualDatabaseException
 * @throws URISyntaxException
 * @throws IOException
 */
public void deployVDBZip(URL url) throws VirtualDatabaseException, ConnectorManagerException, TranslatorException, IOException, URISyntaxException {
    VirtualFile root = PureZipFileSystem.mount(url);
    VDBMetaData metadata;
    // $NON-NLS-1$
    VirtualFile vdbMetadata = root.getChild("/META-INF/vdb.xml");
    if (vdbMetadata.exists()) {
        try {
            VDBMetadataParser.validate(vdbMetadata.openStream());
        } catch (SAXException e) {
            throw new VirtualDatabaseException(e);
        }
        InputStream is = vdbMetadata.openStream();
        try {
            metadata = VDBMetadataParser.unmarshell(is);
        } catch (XMLStreamException e) {
            throw new VirtualDatabaseException(e);
        }
    } else {
        // $NON-NLS-1$
        vdbMetadata = root.getChild("/META-INF/vdb.ddl");
        DeploymentBasedDatabaseStore store = new DeploymentBasedDatabaseStore(getVDBRepository());
        metadata = store.getVDBMetadata(ObjectConverterUtil.convertToString(vdbMetadata.openStream()));
    }
    VDBResources resources = new VDBResources(root, metadata);
    deployVDB(metadata, resources);
}
Also used : VirtualFile(org.jboss.vfs.VirtualFile) XMLStreamException(javax.xml.stream.XMLStreamException) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) VDBMetaData(org.teiid.adminapi.impl.VDBMetaData) VDBResources(org.teiid.query.metadata.VDBResources) VirtualDatabaseException(org.teiid.deployers.VirtualDatabaseException) DeploymentBasedDatabaseStore(org.teiid.metadatastore.DeploymentBasedDatabaseStore) SAXException(org.xml.sax.SAXException)

Example 2 with DeploymentBasedDatabaseStore

use of org.teiid.metadatastore.DeploymentBasedDatabaseStore in project teiid by teiid.

the class EmbeddedServer method deployVDB.

/**
 * Deploy a vdb.xml file.  The name and version will be derived from the xml.
 * @param is, which will be closed by this deployment
 * @param ddl, true if the file contents are DDL
 * @throws TranslatorException
 * @throws ConnectorManagerException
 * @throws VirtualDatabaseException
 * @throws IOException
 */
public void deployVDB(InputStream is, boolean ddl) throws VirtualDatabaseException, ConnectorManagerException, TranslatorException, IOException {
    if (is == null) {
        return;
    }
    byte[] bytes = ObjectConverterUtil.convertToByteArray(is);
    VDBMetaData metadata = null;
    if (ddl) {
        DeploymentBasedDatabaseStore store = new DeploymentBasedDatabaseStore(getVDBRepository());
        metadata = store.getVDBMetadata(new String(bytes));
    } else {
        try {
            // TODO: find a way to do this off of the stream
            VDBMetadataParser.validate(new ByteArrayInputStream(bytes));
        } catch (SAXException e) {
            throw new VirtualDatabaseException(e);
        }
        try {
            metadata = VDBMetadataParser.unmarshell(new ByteArrayInputStream(bytes));
        } catch (XMLStreamException e) {
            throw new VirtualDatabaseException(e);
        }
    }
    metadata.setXmlDeployment(true);
    deployVDB(metadata, null);
}
Also used : XMLStreamException(javax.xml.stream.XMLStreamException) ByteArrayInputStream(java.io.ByteArrayInputStream) VDBMetaData(org.teiid.adminapi.impl.VDBMetaData) VirtualDatabaseException(org.teiid.deployers.VirtualDatabaseException) DeploymentBasedDatabaseStore(org.teiid.metadatastore.DeploymentBasedDatabaseStore) SAXException(org.xml.sax.SAXException)

Example 3 with DeploymentBasedDatabaseStore

use of org.teiid.metadatastore.DeploymentBasedDatabaseStore in project teiid by teiid.

the class VDBParserDeployer method parseVDBDDL.

private VDBMetaData parseVDBDDL(VirtualFile file, DeploymentUnit deploymentUnit, DeploymentPhaseContext phaseContext, boolean xmlDeployment) throws DeploymentUnitProcessingException {
    try {
        PropertyReplacer replacer = deploymentUnit.getAttachment(org.jboss.as.ee.metadata.property.Attachments.FINAL_PROPERTY_REPLACER);
        String vdbContents = replacer.replaceProperties(ObjectConverterUtil.convertToString(file.openStream()));
        ObjectSerializer serializer = ObjectSerializer.class.cast(phaseContext.getServiceRegistry().getService(TeiidServiceNames.OBJECT_SERIALIZER).getValue());
        DeploymentBasedDatabaseStore store = new DeploymentBasedDatabaseStore(vdbRepo);
        VDBMetaData vdb = store.getVDBMetadata(vdbContents);
        // if there is persisted one, let that be XML version for now.
        if (serializer.buildVdbXml(vdb).exists()) {
            vdb = VDBMetadataParser.unmarshell(new FileInputStream(serializer.buildVdbXml(vdb)));
        }
        vdb.setStatus(Status.LOADING);
        vdb.setXmlDeployment(xmlDeployment);
        deploymentUnit.putAttachment(TeiidAttachments.VDB_METADATA, vdb);
        // $NON-NLS-1$ //$NON-NLS-2$
        LogManager.logDetail(LogConstants.CTX_RUNTIME, "VDB " + file.getName() + " has been parsed.");
        return vdb;
    } catch (XMLStreamException e) {
        throw new DeploymentUnitProcessingException(IntegrationPlugin.Event.TEIID50017.name(), e);
    } catch (IOException e) {
        throw new DeploymentUnitProcessingException(IntegrationPlugin.Event.TEIID50017.name(), e);
    }
}
Also used : DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) XMLStreamException(javax.xml.stream.XMLStreamException) VDBMetaData(org.teiid.adminapi.impl.VDBMetaData) PropertyReplacer(org.jboss.metadata.property.PropertyReplacer) IOException(java.io.IOException) DeploymentBasedDatabaseStore(org.teiid.metadatastore.DeploymentBasedDatabaseStore) FileInputStream(java.io.FileInputStream)

Example 4 with DeploymentBasedDatabaseStore

use of org.teiid.metadatastore.DeploymentBasedDatabaseStore 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)

Aggregations

DeploymentBasedDatabaseStore (org.teiid.metadatastore.DeploymentBasedDatabaseStore)4 XMLStreamException (javax.xml.stream.XMLStreamException)3 VDBMetaData (org.teiid.adminapi.impl.VDBMetaData)3 VirtualDatabaseException (org.teiid.deployers.VirtualDatabaseException)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 SAXException (org.xml.sax.SAXException)2 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 StringReader (java.io.StringReader)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1 ConcurrentSkipListMap (java.util.concurrent.ConcurrentSkipListMap)1 DeploymentUnitProcessingException (org.jboss.as.server.deployment.DeploymentUnitProcessingException)1 PropertyReplacer (org.jboss.metadata.property.PropertyReplacer)1 VirtualFile (org.jboss.vfs.VirtualFile)1 ModelMetaData (org.teiid.adminapi.impl.ModelMetaData)1 ConnectorManager (org.teiid.dqp.internal.datamgr.ConnectorManager)1 Database (org.teiid.metadata.Database)1