Search in sources :

Example 1 with VirtualDatabaseException

use of org.teiid.deployers.VirtualDatabaseException in project teiid by teiid.

the class VDBService method start.

@Override
public void start(final StartContext context) throws StartException {
    ConnectorManagerRepository cmr = new ConnectorManagerRepository();
    TranslatorRepository repo = new TranslatorRepository();
    this.vdb.addAttchment(TranslatorRepository.class, repo);
    // check if this is a VDB with index files, if there are then build the TransformationMetadata
    UDFMetaData udf = this.vdb.getAttachment(UDFMetaData.class);
    // add required connector managers; if they are not already there
    for (Translator t : this.vdb.getOverrideTranslators()) {
        VDBTranslatorMetaData data = (VDBTranslatorMetaData) t;
        String type = data.getType();
        VDBTranslatorMetaData parent = getTranslatorRepository().getTranslatorMetaData(type);
        data.setModuleName(parent.getModuleName());
        data.addAttchment(ClassLoader.class, parent.getAttachment(ClassLoader.class));
        data.setParent(parent);
        repo.addTranslatorMetadata(data.getName(), data);
    }
    createConnectorManagers(cmr, repo, this.vdb);
    final ServiceBuilder<Void> vdbService = addVDBFinishedService(context);
    this.vdbListener = new VDBLifeCycleListener() {

        @Override
        public void added(String name, CompositeVDB cvdb) {
        }

        @Override
        public void beforeRemove(String name, CompositeVDB cvdb) {
        }

        @Override
        public void removed(String name, CompositeVDB cvdb) {
        }

        @Override
        public void finishedDeployment(String name, CompositeVDB cvdb) {
            if (!VDBService.this.vdbKey.equals(cvdb.getVDBKey())) {
                return;
            }
            // clear out the indexmetadatarepository as it holds state that is no longer necessary
            // $NON-NLS-1$
            repositories.put("index", new IndexMetadataRepository());
            VDBMetaData vdbInstance = cvdb.getVDB();
            if (vdbInstance.getStatus().equals(Status.ACTIVE)) {
                vdbService.install();
            }
        }
    };
    getVDBRepository().addListener(this.vdbListener);
    MetadataStore store = new MetadataStore();
    try {
        // check to see if there is an index file.  if there is then we assume
        // that index is the default metadata repo
        MetadataRepository<?, ?> defaultRepo = null;
        for (String s : this.vdbResources.getEntriesPlusVisibilities().keySet()) {
            if (s.endsWith(VDBResources.INDEX_EXT)) {
                // $NON-NLS-1$
                defaultRepo = super.getMetadataRepository("index");
                break;
            }
        }
        this.assignMetadataRepositories(vdb, defaultRepo);
        // add transformation metadata to the repository.
        getVDBRepository().addVDB(this.vdb, store, vdbResources.getEntriesPlusVisibilities(), udf, cmr);
    } catch (VirtualDatabaseException e) {
        cleanup(context);
        throw new StartException(e);
    }
    this.vdb.removeAttachment(UDFMetaData.class);
    try {
        loadMetadata(this.vdb, cmr, store, this.vdbResources);
    } catch (TranslatorException e) {
        cleanup(context);
        throw new StartException(e);
    }
    this.runtimeVDB = buildRuntimeVDB(this.vdb, context.getController().getServiceContainer());
}
Also used : ConnectorManagerRepository(org.teiid.dqp.internal.datamgr.ConnectorManagerRepository) CompositeVDB(org.teiid.deployers.CompositeVDB) UDFMetaData(org.teiid.deployers.UDFMetaData) TranslatorRepository(org.teiid.dqp.internal.datamgr.TranslatorRepository) IndexMetadataRepository(org.teiid.metadata.index.IndexMetadataRepository) MetadataStore(org.teiid.metadata.MetadataStore) Translator(org.teiid.adminapi.Translator) VDBMetaData(org.teiid.adminapi.impl.VDBMetaData) VDBLifeCycleListener(org.teiid.deployers.VDBLifeCycleListener) StartException(org.jboss.msc.service.StartException) TranslatorException(org.teiid.translator.TranslatorException) VirtualDatabaseException(org.teiid.deployers.VirtualDatabaseException) VDBTranslatorMetaData(org.teiid.adminapi.impl.VDBTranslatorMetaData)

Example 2 with VirtualDatabaseException

use of org.teiid.deployers.VirtualDatabaseException in project teiid by teiid.

the class EmbeddedServer method deployVDB.

protected void deployVDB(VDBMetaData vdb, VDBResources resources) throws ConnectorManagerException, VirtualDatabaseException, TranslatorException {
    checkStarted();
    if (!vdb.getOverrideTranslators().isEmpty() && !allowOverrideTranslators()) {
        throw new VirtualDatabaseException(RuntimePlugin.Event.TEIID40106, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40106, vdb.getName()));
    }
    vdb.addAttchment(ClassLoader.class, Thread.currentThread().getContextClassLoader());
    try {
        createPreParser(vdb);
    } catch (TeiidException e1) {
        throw new VirtualDatabaseException(e1);
    }
    cmr.createConnectorManagers(vdb, this);
    MetadataStore metadataStore = new MetadataStore();
    UDFMetaData udfMetaData = new UDFMetaData();
    udfMetaData.setFunctionClassLoader(Thread.currentThread().getContextClassLoader());
    MetadataRepository<?, ?> defaultRepo = null;
    LinkedHashMap<String, VDBResources.Resource> visibilityMap = null;
    if (resources != null) {
        // that index is the default metadata repo
        for (String s : resources.getEntriesPlusVisibilities().keySet()) {
            if (s.endsWith(VDBResources.INDEX_EXT)) {
                defaultRepo = new IndexMetadataRepository();
                break;
            }
        }
        visibilityMap = resources.getEntriesPlusVisibilities();
    } else {
        visibilityMap = new LinkedHashMap<String, VDBResources.Resource>();
    }
    this.assignMetadataRepositories(vdb, defaultRepo);
    repo.addVDB(vdb, metadataStore, visibilityMap, udfMetaData, cmr);
    try {
        this.loadMetadata(vdb, cmr, metadataStore, resources);
    } catch (VDBValidationError e) {
        throw new VirtualDatabaseException(RuntimePlugin.Event.valueOf(e.getCode()), e.getMessage());
    }
}
Also used : MetadataStore(org.teiid.metadata.MetadataStore) IndexMetadataRepository(org.teiid.metadata.index.IndexMetadataRepository) UDFMetaData(org.teiid.deployers.UDFMetaData) VirtualDatabaseException(org.teiid.deployers.VirtualDatabaseException) TeiidException(org.teiid.core.TeiidException)

Example 3 with VirtualDatabaseException

use of org.teiid.deployers.VirtualDatabaseException 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 4 with VirtualDatabaseException

use of org.teiid.deployers.VirtualDatabaseException 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 5 with VirtualDatabaseException

use of org.teiid.deployers.VirtualDatabaseException in project teiid by teiid.

the class VDBService method getMetadataRepository.

/**
 * Override for module based loading
 */
@SuppressWarnings("rawtypes")
@Override
protected MetadataRepository<?, ?> getMetadataRepository(String repoType) throws VirtualDatabaseException {
    MetadataRepository<?, ?> repo = super.getMetadataRepository(repoType);
    if (repo != null) {
        return repo;
    }
    try {
        repo = TeiidAdd.buildService(MetadataRepository.class, repoType);
    } catch (OperationFailedException e) {
        throw new VirtualDatabaseException(IntegrationPlugin.Event.TEIID50057, e, IntegrationPlugin.Util.gs(IntegrationPlugin.Event.TEIID50057, repoType));
    }
    MetadataRepository old = this.repositories.putIfAbsent(repoType, repo);
    return old != null ? old : repo;
}
Also used : MetadataRepository(org.teiid.metadata.MetadataRepository) IndexMetadataRepository(org.teiid.metadata.index.IndexMetadataRepository) OperationFailedException(org.jboss.as.controller.OperationFailedException) VirtualDatabaseException(org.teiid.deployers.VirtualDatabaseException)

Aggregations

VirtualDatabaseException (org.teiid.deployers.VirtualDatabaseException)10 ModelMetaData (org.teiid.adminapi.impl.ModelMetaData)4 VDBMetaData (org.teiid.adminapi.impl.VDBMetaData)4 MetadataRepository (org.teiid.metadata.MetadataRepository)4 ArrayList (java.util.ArrayList)3 XMLStreamException (javax.xml.stream.XMLStreamException)3 UDFMetaData (org.teiid.deployers.UDFMetaData)3 IndexMetadataRepository (org.teiid.metadata.index.IndexMetadataRepository)3 DeploymentBasedDatabaseStore (org.teiid.metadatastore.DeploymentBasedDatabaseStore)3 TranslatorException (org.teiid.translator.TranslatorException)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 Map (java.util.Map)2 MetadataFactory (org.teiid.metadata.MetadataFactory)2 MetadataStore (org.teiid.metadata.MetadataStore)2 SAXException (org.xml.sax.SAXException)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 StringReader (java.io.StringReader)1 Collection (java.util.Collection)1 LinkedHashMap (java.util.LinkedHashMap)1