Search in sources :

Example 1 with VDBResources

use of org.teiid.query.metadata.VDBResources in project teiid by teiid.

the class VDBDeployer method deploy.

public void deploy(final DeploymentPhaseContext context) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = context.getDeploymentUnit();
    if (!TeiidAttachments.isVDBDeployment(deploymentUnit)) {
        return;
    }
    final VDBMetaData deployment = deploymentUnit.getAttachment(TeiidAttachments.VDB_METADATA);
    VDBMetaData other = this.vdbRepository.getVDB(deployment.getName(), deployment.getVersion());
    if (other != null) {
        String deploymentName = other.getPropertyValue(TranslatorUtil.DEPLOYMENT_NAME);
        throw new DeploymentUnitProcessingException(IntegrationPlugin.Util.gs(IntegrationPlugin.Event.TEIID50106, deployment, deploymentName));
    }
    deployment.addProperty(TranslatorUtil.DEPLOYMENT_NAME, deploymentUnit.getName());
    // check to see if there is old vdb already deployed.
    final ServiceController<?> controller = context.getServiceRegistry().getService(TeiidServiceNames.vdbServiceName(deployment.getName(), deployment.getVersion()));
    if (controller != null) {
        LogManager.logInfo(LogConstants.CTX_RUNTIME, IntegrationPlugin.Util.gs(IntegrationPlugin.Event.TEIID50019, deployment));
        controller.setMode(ServiceController.Mode.REMOVE);
    }
    boolean preview = deployment.isPreview();
    if (!preview && deployment.hasErrors()) {
        throw new DeploymentUnitProcessingException(IntegrationPlugin.Util.gs(IntegrationPlugin.Event.TEIID50074, deployment));
    }
    // make sure the translator defined exists in configuration; otherwise add as error
    for (ModelMetaData model : deployment.getModelMetaDatas().values()) {
        if (!model.isSource() || model.getSourceNames().isEmpty()) {
            continue;
        }
        for (String source : model.getSourceNames()) {
            String translatorName = model.getSourceTranslatorName(source);
            if (deployment.isOverideTranslator(translatorName)) {
                VDBTranslatorMetaData parent = deployment.getTranslator(translatorName);
                translatorName = parent.getType();
            }
            Translator translator = this.translatorRepository.getTranslatorMetaData(translatorName);
            if (translator == null) {
                String msg = IntegrationPlugin.Util.gs(IntegrationPlugin.Event.TEIID50077, translatorName, deployment.getName(), deployment.getVersion());
                LogManager.logWarning(LogConstants.CTX_RUNTIME, msg);
            }
        }
    }
    // add VDB module's classloader as an attachment
    ModuleClassLoader classLoader = deploymentUnit.getAttachment(Attachments.MODULE).getClassLoader();
    deployment.addAttchment(ClassLoader.class, classLoader);
    deployment.addAttchment(ScriptEngineManager.class, new ScriptEngineManager(classLoader));
    try {
        EmbeddedServer.createPreParser(deployment);
    } catch (TeiidException e1) {
        throw new DeploymentUnitProcessingException(e1);
    }
    UDFMetaData udf = deploymentUnit.removeAttachment(TeiidAttachments.UDF_METADATA);
    if (udf == null) {
        udf = new UDFMetaData();
    }
    udf.setFunctionClassLoader(classLoader);
    deployment.addAttchment(UDFMetaData.class, udf);
    VirtualFile file = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_ROOT).getRoot();
    VDBResources resources;
    try {
        resources = new VDBResources(file, deployment);
    } catch (IOException e) {
        throw new DeploymentUnitProcessingException(IntegrationPlugin.Event.TEIID50017.name(), e);
    }
    this.vdbRepository.addPendingDeployment(deployment);
    // build a VDB service
    final VDBService vdb = new VDBService(deployment, resources, shutdownListener);
    // $NON-NLS-1$
    vdb.addMetadataRepository("index", new IndexMetadataRepository());
    final ServiceBuilder<RuntimeVDB> vdbService = context.getServiceTarget().addService(TeiidServiceNames.vdbServiceName(deployment.getName(), deployment.getVersion()), vdb);
    // add dependencies to data-sources
    dataSourceDependencies(deployment, context.getServiceTarget());
    for (VDBImport vdbImport : deployment.getVDBImports()) {
        VDBKey vdbKey = new VDBKey(vdbImport.getName(), vdbImport.getVersion());
        if (vdbKey.isAtMost()) {
            // TODO: could allow partial versions here if we canonicalize
            throw new DeploymentUnitProcessingException(RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40144, deployment, vdbKey));
        }
        LogManager.logInfo(LogConstants.CTX_RUNTIME, IntegrationPlugin.Util.gs(IntegrationPlugin.Event.TEIID50115, deployment, vdbKey));
        vdbService.addDependency(TeiidServiceNames.vdbFinishedServiceName(vdbImport.getName(), vdbKey.getVersion()));
    }
    // adding the translator services is redundant, however if one is removed then it is an issue.
    for (Model model : deployment.getModels()) {
        List<String> sourceNames = model.getSourceNames();
        for (String sourceName : sourceNames) {
            String translatorName = model.getSourceTranslatorName(sourceName);
            if (deployment.isOverideTranslator(translatorName)) {
                VDBTranslatorMetaData translator = deployment.getTranslator(translatorName);
                translatorName = translator.getType();
            }
            vdbService.addDependency(TeiidServiceNames.translatorServiceName(translatorName));
        }
    }
    ServiceName vdbSwitchServiceName = TeiidServiceNames.vdbSwitchServiceName(deployment.getName(), deployment.getVersion());
    vdbService.addDependency(TeiidServiceNames.VDB_REPO, VDBRepository.class, vdb.vdbRepositoryInjector);
    vdbService.addDependency(TeiidServiceNames.TRANSLATOR_REPO, TranslatorRepository.class, vdb.translatorRepositoryInjector);
    vdbService.addDependency(TeiidServiceNames.THREAD_POOL_SERVICE, Executor.class, vdb.executorInjector);
    vdbService.addDependency(TeiidServiceNames.OBJECT_SERIALIZER, ObjectSerializer.class, vdb.serializerInjector);
    vdbService.addDependency(TeiidServiceNames.VDB_STATUS_CHECKER, VDBStatusChecker.class, vdb.vdbStatusCheckInjector);
    vdbService.addDependency(vdbSwitchServiceName, CountDownLatch.class, new InjectedValue<CountDownLatch>());
    // VDB restart switch, control the vdbservice by adding removing the switch service. If you
    // remove the service by setting status remove, there is no way start it back up if vdbservice used alone
    installVDBSwitchService(context.getServiceTarget(), vdbSwitchServiceName);
    vdbService.addListener(new AbstractServiceListener<Object>() {

        @Override
        public void transition(final ServiceController controller, final ServiceController.Transition transition) {
            if (transition.equals(ServiceController.Transition.DOWN_to_WAITING)) {
                RuntimeVDB runtimeVDB = RuntimeVDB.class.cast(controller.getValue());
                if (runtimeVDB != null && runtimeVDB.isRestartInProgress()) {
                    ServiceName vdbSwitchServiceName = TeiidServiceNames.vdbSwitchServiceName(deployment.getName(), deployment.getVersion());
                    ServiceController<?> switchSvc = controller.getServiceContainer().getService(vdbSwitchServiceName);
                    if (switchSvc != null) {
                        CountDownLatch latch = CountDownLatch.class.cast(switchSvc.getValue());
                        try {
                            latch.await(5, TimeUnit.SECONDS);
                        } catch (InterruptedException e) {
                        // todo:log it?
                        }
                    }
                    installVDBSwitchService(controller.getServiceContainer(), vdbSwitchServiceName);
                }
            }
        }
    });
    vdbService.setInitialMode(Mode.PASSIVE).install();
}
Also used : DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) VirtualFile(org.jboss.vfs.VirtualFile) ScriptEngineManager(javax.script.ScriptEngineManager) IndexMetadataRepository(org.teiid.metadata.index.IndexMetadataRepository) Translator(org.teiid.adminapi.Translator) RuntimeVDB(org.teiid.deployers.RuntimeVDB) ModuleClassLoader(org.jboss.modules.ModuleClassLoader) UDFMetaData(org.teiid.deployers.UDFMetaData) VDBResources(org.teiid.query.metadata.VDBResources) IOException(java.io.IOException) CountDownLatch(java.util.concurrent.CountDownLatch) ModelMetaData(org.teiid.adminapi.impl.ModelMetaData) TeiidException(org.teiid.core.TeiidException) VDBKey(org.teiid.vdb.runtime.VDBKey) VDBMetaData(org.teiid.adminapi.impl.VDBMetaData) VDBImport(org.teiid.adminapi.VDBImport) Model(org.teiid.adminapi.Model) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) VDBTranslatorMetaData(org.teiid.adminapi.impl.VDBTranslatorMetaData)

Example 2 with VDBResources

use of org.teiid.query.metadata.VDBResources 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 3 with VDBResources

use of org.teiid.query.metadata.VDBResources in project teiid by teiid.

the class VDBMetadataFactory method loadMetadata.

public static IndexVDB loadMetadata(String vdbName, URL url) throws IOException, MalformedURLException {
    VirtualFile root;
    try {
        root = PureZipFileSystem.mount(url);
    } catch (URISyntaxException e) {
        throw new IOException(e);
    }
    IndexVDB result = new IndexVDB();
    result.resources = new VDBResources(root, null);
    IndexMetadataRepository store = new IndexMetadataRepository();
    result.store = store.load(SystemMetadata.getInstance().getDataTypes(), result.resources);
    return result;
}
Also used : VirtualFile(org.jboss.vfs.VirtualFile) VDBResources(org.teiid.query.metadata.VDBResources) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException)

Aggregations

VirtualFile (org.jboss.vfs.VirtualFile)3 VDBResources (org.teiid.query.metadata.VDBResources)3 IOException (java.io.IOException)2 VDBMetaData (org.teiid.adminapi.impl.VDBMetaData)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 URISyntaxException (java.net.URISyntaxException)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 ScriptEngineManager (javax.script.ScriptEngineManager)1 XMLStreamException (javax.xml.stream.XMLStreamException)1 DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)1 DeploymentUnitProcessingException (org.jboss.as.server.deployment.DeploymentUnitProcessingException)1 ModuleClassLoader (org.jboss.modules.ModuleClassLoader)1 Model (org.teiid.adminapi.Model)1 Translator (org.teiid.adminapi.Translator)1 VDBImport (org.teiid.adminapi.VDBImport)1 ModelMetaData (org.teiid.adminapi.impl.ModelMetaData)1 VDBTranslatorMetaData (org.teiid.adminapi.impl.VDBTranslatorMetaData)1 TeiidException (org.teiid.core.TeiidException)1 RuntimeVDB (org.teiid.deployers.RuntimeVDB)1