Search in sources :

Example 1 with VDBLifeCycleListener

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

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

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

Aggregations

CompositeVDB (org.teiid.deployers.CompositeVDB)3 VDBLifeCycleListener (org.teiid.deployers.VDBLifeCycleListener)3 SessionMetadata (org.teiid.adminapi.impl.SessionMetadata)2 Collection (java.util.Collection)1 Date (java.util.Date)1 StartException (org.jboss.msc.service.StartException)1 Translator (org.teiid.adminapi.Translator)1 VDBMetaData (org.teiid.adminapi.impl.VDBMetaData)1 VDBTranslatorMetaData (org.teiid.adminapi.impl.VDBTranslatorMetaData)1 InvalidSessionException (org.teiid.client.security.InvalidSessionException)1 CompositeGlobalTableStore (org.teiid.deployers.CompositeGlobalTableStore)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 SessionAwareCache (org.teiid.dqp.internal.process.SessionAwareCache)1 SessionService (org.teiid.dqp.service.SessionService)1 MetadataStore (org.teiid.metadata.MetadataStore)1 IndexMetadataRepository (org.teiid.metadata.index.IndexMetadataRepository)1 GlobalTableStore (org.teiid.query.tempdata.GlobalTableStore)1