Search in sources :

Example 1 with CompositeVDB

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

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

the class DQPCoreService method start.

@Override
public void start(final StartContext context) {
    this.transactionServerImpl.setWorkManager(getWorkManagerInjector().getValue());
    this.transactionServerImpl.setXaTerminator(getXaTerminatorInjector().getValue());
    this.transactionServerImpl.setTransactionManager(getTxnManagerInjector().getValue());
    this.transactionServerImpl.setDetectTransactions(true);
    setPreParser(preParserInjector.getValue());
    setAuthorizationValidator(authorizationValidatorInjector.getValue());
    this.dqpCore.setBufferManager(bufferManagerInjector.getValue());
    this.dqpCore.setTransactionService((TransactionService) LogManager.createLoggingProxy(LogConstants.CTX_TXN_LOG, transactionServerImpl, new Class[] { TransactionService.class }, MessageLevel.DETAIL, Thread.currentThread().getContextClassLoader()));
    this.dqpCore.setEventDistributor(getEventDistributorFactoryInjector().getValue().getReplicatedEventDistributor());
    this.dqpCore.setResultsetCache(getResultSetCacheInjector().getValue());
    this.dqpCore.setPreparedPlanCache(getPreparedPlanCacheInjector().getValue());
    this.dqpCore.start(this);
    // add vdb life cycle listeners
    getVdbRepository().addListener(new VDBLifeCycleListener() {

        @Override
        public void removed(String name, CompositeVDB vdb) {
            // terminate all the previous sessions
            SessionService sessionService = (SessionService) context.getController().getServiceContainer().getService(TeiidServiceNames.SESSION).getValue();
            Collection<SessionMetadata> sessions = sessionService.getSessionsLoggedInToVDB(vdb.getVDBKey());
            for (SessionMetadata session : sessions) {
                sessionService.terminateSession(session.getSessionId(), null);
            }
            // dump the caches.
            try {
                SessionAwareCache<?> value = getResultSetCacheInjector().getValue();
                if (value != null) {
                    value.clearForVDB(vdb.getVDBKey());
                }
                value = getPreparedPlanCacheInjector().getValue();
                if (value != null) {
                    value.clearForVDB(vdb.getVDBKey());
                }
            } catch (IllegalStateException e) {
            // already shutdown
            }
        }

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

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

        @Override
        public void beforeRemove(String name, CompositeVDB cvdb) {
        }
    });
    LogManager.logInfo(LogConstants.CTX_RUNTIME, IntegrationPlugin.Util.gs(IntegrationPlugin.Event.TEIID50001, this.dqpCore.getRuntimeVersion(), new Date(System.currentTimeMillis()).toString()));
}
Also used : SessionService(org.teiid.dqp.service.SessionService) SessionAwareCache(org.teiid.dqp.internal.process.SessionAwareCache) CompositeVDB(org.teiid.deployers.CompositeVDB) SessionMetadata(org.teiid.adminapi.impl.SessionMetadata) Collection(java.util.Collection) VDBLifeCycleListener(org.teiid.deployers.VDBLifeCycleListener) Date(java.util.Date)

Example 3 with CompositeVDB

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

the class EmbeddedServer method startVDBRepository.

private void startVDBRepository() {
    this.repo.addListener(new VDBLifeCycleListener() {

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

        @Override
        public void removed(String name, CompositeVDB vdb) {
            if (replicator != null) {
                replicator.stop(vdb.getVDB().getAttachment(GlobalTableStore.class));
            }
            rs.clearForVDB(vdb.getVDBKey());
            ppc.clearForVDB(vdb.getVDBKey());
            for (SessionMetadata session : sessionService.getSessionsLoggedInToVDB(vdb.getVDBKey())) {
                try {
                    sessionService.closeSession(session.getSessionId());
                } catch (InvalidSessionException e) {
                }
            }
        }

        @Override
        public void finishedDeployment(String name, CompositeVDB vdb) {
            if (!vdb.getVDB().getStatus().equals(Status.ACTIVE)) {
                return;
            }
            GlobalTableStore gts = CompositeGlobalTableStore.createInstance(vdb, dqp.getBufferManager(), replicator);
            vdb.getVDB().addAttchment(GlobalTableStore.class, gts);
        }

        @Override
        public void beforeRemove(String name, CompositeVDB vdb) {
        }
    });
    this.repo.setSystemFunctionManager(SystemMetadata.getInstance().getSystemFunctionManager());
    this.repo.start();
}
Also used : InvalidSessionException(org.teiid.client.security.InvalidSessionException) CompositeVDB(org.teiid.deployers.CompositeVDB) GlobalTableStore(org.teiid.query.tempdata.GlobalTableStore) CompositeGlobalTableStore(org.teiid.deployers.CompositeGlobalTableStore) SessionMetadata(org.teiid.adminapi.impl.SessionMetadata) VDBLifeCycleListener(org.teiid.deployers.VDBLifeCycleListener)

Example 4 with CompositeVDB

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

the class MaterializationManager method nodeDropped.

@Override
public void nodeDropped(String nodeName) {
    for (VDBMetaData vdb : getVDBRepository().getVDBs()) {
        TransformationMetadata metadata = vdb.getAttachment(TransformationMetadata.class);
        if (metadata == null) {
            continue;
        }
        for (ModelMetaData model : vdb.getModelMetaDatas().values()) {
            if (vdb.getImportedModels().contains(model.getName())) {
                continue;
            }
            MetadataStore store = metadata.getMetadataStore();
            Schema schema = store.getSchema(model.getName());
            for (Table t : schema.getTables().values()) {
                if (t.isVirtual() && t.isMaterialized() && t.getMaterializedTable() != null) {
                    String allow = t.getProperty(MaterializationMetadataRepository.ALLOW_MATVIEW_MANAGEMENT, false);
                    if (allow == null || !Boolean.valueOf(allow)) {
                        continue;
                    }
                    // reset the pending job if there is one.
                    int update = resetPendingJob(vdb, t, nodeName);
                    if (update > 0) {
                        String ttlStr = t.getProperty(MaterializationMetadataRepository.MATVIEW_TTL, false);
                        if (ttlStr == null) {
                            ttlStr = String.valueOf(Long.MAX_VALUE);
                        }
                        if (ttlStr != null) {
                            long ttl = Long.parseLong(ttlStr);
                            if (ttl > 0) {
                                // run the job
                                CompositeVDB cvdb = getVDBRepository().getCompositeVDB(new VDBKey(vdb.getName(), vdb.getVersion()));
                                scheduleSnapshotJob(cvdb, t, ttl, 0L, true);
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : MetadataStore(org.teiid.metadata.MetadataStore) TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) Table(org.teiid.metadata.Table) VDBKey(org.teiid.vdb.runtime.VDBKey) CompositeVDB(org.teiid.deployers.CompositeVDB) VDBMetaData(org.teiid.adminapi.impl.VDBMetaData) Schema(org.teiid.metadata.Schema) ModelMetaData(org.teiid.adminapi.impl.ModelMetaData)

Example 5 with CompositeVDB

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

the class TestRestWebArchiveBuilder method testOtherModels.

@Test
public void testOtherModels() throws Exception {
    MetadataStore ms = new MetadataStore();
    CompositeVDB vdb = TestCompositeVDB.createCompositeVDB(ms, "x");
    vdb.getVDB().addProperty("{http://teiid.org/rest}auto-generate", "true");
    ModelMetaData model = new ModelMetaData();
    model.setName("other");
    model.setModelType(Type.OTHER);
    vdb.getVDB().addModel(model);
    RestASMBasedWebArchiveBuilder builder = new RestASMBasedWebArchiveBuilder();
    builder.getContent(vdb.getVDB());
}
Also used : MetadataStore(org.teiid.metadata.MetadataStore) CompositeVDB(org.teiid.deployers.CompositeVDB) TestCompositeVDB(org.teiid.deployers.TestCompositeVDB) ModelMetaData(org.teiid.adminapi.impl.ModelMetaData) Test(org.junit.Test)

Aggregations

CompositeVDB (org.teiid.deployers.CompositeVDB)6 MetadataStore (org.teiid.metadata.MetadataStore)4 ModelMetaData (org.teiid.adminapi.impl.ModelMetaData)3 VDBLifeCycleListener (org.teiid.deployers.VDBLifeCycleListener)3 Test (org.junit.Test)2 SessionMetadata (org.teiid.adminapi.impl.SessionMetadata)2 VDBMetaData (org.teiid.adminapi.impl.VDBMetaData)2 TestCompositeVDB (org.teiid.deployers.TestCompositeVDB)2 Collection (java.util.Collection)1 Date (java.util.Date)1 StartException (org.jboss.msc.service.StartException)1 Translator (org.teiid.adminapi.Translator)1 VDBTranslatorMetaData (org.teiid.adminapi.impl.VDBTranslatorMetaData)1 InvalidSessionException (org.teiid.client.security.InvalidSessionException)1 CompositeGlobalTableStore (org.teiid.deployers.CompositeGlobalTableStore)1 RestWarGenerator (org.teiid.deployers.RestWarGenerator)1 UDFMetaData (org.teiid.deployers.UDFMetaData)1 VirtualDatabaseException (org.teiid.deployers.VirtualDatabaseException)1 ConnectorManagerRepository (org.teiid.dqp.internal.datamgr.ConnectorManagerRepository)1 TranslatorRepository (org.teiid.dqp.internal.datamgr.TranslatorRepository)1