Search in sources :

Example 1 with UDFMetaData

use of org.teiid.deployers.UDFMetaData 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 UDFMetaData

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

the class VDBParserDeployer method mergeMetaData.

protected VDBMetaData mergeMetaData(DeploymentUnit deploymentUnit) throws DeploymentUnitProcessingException {
    VDBMetaData vdb = deploymentUnit.getAttachment(TeiidAttachments.VDB_METADATA);
    UDFMetaData udf = deploymentUnit.getAttachment(TeiidAttachments.UDF_METADATA);
    VirtualFile file = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_ROOT).getRoot();
    if (vdb == null) {
        LogManager.logError(LogConstants.CTX_RUNTIME, IntegrationPlugin.Util.gs(IntegrationPlugin.Event.TEIID50016, file.getName()));
        return null;
    }
    try {
        if (udf != null) {
            // load the UDF
            for (Model model : vdb.getModels()) {
                if (model.getModelType().equals(Model.Type.FUNCTION)) {
                    String path = ((ModelMetaData) model).getPath();
                    if (path == null) {
                        throw new DeploymentUnitProcessingException(IntegrationPlugin.Util.gs(IntegrationPlugin.Event.TEIID50075, model.getName()));
                    }
                    ((FileUDFMetaData) udf).buildFunctionModelFile(model.getName(), path);
                }
            }
        }
    } catch (IOException e) {
        throw new DeploymentUnitProcessingException(IntegrationPlugin.Event.TEIID50017.name(), e);
    } catch (XMLStreamException e) {
        throw new DeploymentUnitProcessingException(IntegrationPlugin.Event.TEIID50017.name(), e);
    }
    // $NON-NLS-1$ //$NON-NLS-2$
    LogManager.logTrace(LogConstants.CTX_RUNTIME, "VDB", file.getName(), "has been parsed.");
    return vdb;
}
Also used : VirtualFile(org.jboss.vfs.VirtualFile) DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) XMLStreamException(javax.xml.stream.XMLStreamException) VDBMetaData(org.teiid.adminapi.impl.VDBMetaData) UDFMetaData(org.teiid.deployers.UDFMetaData) Model(org.teiid.adminapi.Model) IOException(java.io.IOException) ModelMetaData(org.teiid.adminapi.impl.ModelMetaData)

Example 3 with UDFMetaData

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

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

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

the class VDBParserDeployer method deploy.

public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    if (!TeiidAttachments.isVDBDeployment(deploymentUnit)) {
        return;
    }
    VirtualFile file = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_ROOT).getRoot();
    if (TeiidAttachments.isVDBXMLDeployment(deploymentUnit)) {
        parseVDBXML(file, deploymentUnit, phaseContext, true);
    } else if (TeiidAttachments.isVDBDDLDeployment(deploymentUnit)) {
        parseVDBDDL(file, deploymentUnit, phaseContext, true);
    } else {
        // scan for different files
        try {
            file.getChildrenRecursively(new VirtualFileFilter() {

                @Override
                public boolean accepts(VirtualFile file) {
                    if (file.isDirectory()) {
                        return false;
                    }
                    if (file.getName().toLowerCase().endsWith(VDBResources.MODEL_EXT)) {
                        UDFMetaData udf = deploymentUnit.getAttachment(TeiidAttachments.UDF_METADATA);
                        if (udf == null) {
                            udf = new FileUDFMetaData();
                            deploymentUnit.putAttachment(TeiidAttachments.UDF_METADATA, udf);
                        }
                        ((FileUDFMetaData) udf).addModelFile(file);
                    }
                    return false;
                }
            });
            // $NON-NLS-1$
            VirtualFile vdbXml = file.getChild("/META-INF/vdb.xml");
            // $NON-NLS-1$
            VirtualFile vdbDDL = file.getChild("/META-INF/vdb.ddl");
            if (!vdbXml.exists() && !vdbDDL.exists()) {
                throw new DeploymentUnitProcessingException(IntegrationPlugin.Util.gs(IntegrationPlugin.Event.TEIID50101, deploymentUnit));
            }
            if (vdbXml.exists()) {
                parseVDBXML(vdbXml, deploymentUnit, phaseContext, false);
            } else {
                parseVDBDDL(vdbDDL, deploymentUnit, phaseContext, false);
            }
            mergeMetaData(deploymentUnit);
        } catch (IOException e) {
            throw new DeploymentUnitProcessingException(IntegrationPlugin.Event.TEIID50017.name(), e);
        }
    }
}
Also used : VirtualFile(org.jboss.vfs.VirtualFile) DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) VirtualFileFilter(org.jboss.vfs.VirtualFileFilter) UDFMetaData(org.teiid.deployers.UDFMetaData) IOException(java.io.IOException) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit)

Aggregations

UDFMetaData (org.teiid.deployers.UDFMetaData)7 VDBMetaData (org.teiid.adminapi.impl.VDBMetaData)5 IOException (java.io.IOException)4 DeploymentUnitProcessingException (org.jboss.as.server.deployment.DeploymentUnitProcessingException)3 VirtualFile (org.jboss.vfs.VirtualFile)3 ModelMetaData (org.teiid.adminapi.impl.ModelMetaData)3 VirtualDatabaseException (org.teiid.deployers.VirtualDatabaseException)3 MetadataStore (org.teiid.metadata.MetadataStore)3 IndexMetadataRepository (org.teiid.metadata.index.IndexMetadataRepository)3 XMLStreamException (javax.xml.stream.XMLStreamException)2 DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)2 Model (org.teiid.adminapi.Model)2 Translator (org.teiid.adminapi.Translator)2 VDBTranslatorMetaData (org.teiid.adminapi.impl.VDBTranslatorMetaData)2 TeiidException (org.teiid.core.TeiidException)2 ConnectorManagerRepository (org.teiid.dqp.internal.datamgr.ConnectorManagerRepository)2 VDBResources (org.teiid.query.metadata.VDBResources)2 TranslatorException (org.teiid.translator.TranslatorException)2 Collection (java.util.Collection)1 LinkedHashMap (java.util.LinkedHashMap)1