Search in sources :

Example 1 with NamedThreadFactory

use of org.teiid.core.util.NamedThreadFactory in project teiid by teiid.

the class EmbeddedServer method start.

public synchronized void start(@SuppressWarnings("hiding") EmbeddedConfiguration config) {
    if (running != null) {
        throw new IllegalStateException();
    }
    this.dqp.setLocalProfile(this.embeddedProfile);
    this.shutdownListener.setBootInProgress(true);
    this.config = config;
    System.setProperty("jboss.node.name", config.getNodeName() == null ? "localhost" : config.getNodeName());
    this.cmr.setProvider(this);
    this.eventDistributorFactoryService = new EmbeddedEventDistributorFactoryService();
    this.eventDistributorFactoryService.start();
    this.dqp.setEventDistributor(this.eventDistributorFactoryService.getReplicatedEventDistributor());
    // $NON-NLS-1$
    this.scheduler = Executors.newScheduledThreadPool(config.getMaxAsyncThreads(), new NamedThreadFactory("Asynch Worker"));
    this.replicator = config.getObjectReplicator();
    if (this.replicator == null && config.getJgroupsConfigFile() != null) {
        channelFactory = new SimpleChannelFactory(config);
        this.replicator = new JGroupsObjectReplicator(channelFactory, this.scheduler);
        try {
            this.nodeTracker = new NodeTracker(channelFactory.createChannel("teiid-node-tracker"), config.getNodeName()) {

                @Override
                public ScheduledExecutorService getScheduledExecutorService() {
                    return scheduler;
                }
            };
        } catch (Exception e) {
            LogManager.logError(LogConstants.CTX_RUNTIME, e, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40089));
        }
    }
    this.eventDistributorFactoryService = new EmbeddedEventDistributorFactoryService();
    // must be called after the replicator is set
    this.eventDistributorFactoryService.start();
    this.dqp.setEventDistributor(this.eventDistributorFactoryService.getReplicatedEventDistributor());
    if (config.getTransactionManager() == null) {
        LogManager.logInfo(LogConstants.CTX_RUNTIME, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40089));
        this.transactionService.setTransactionManager((TransactionManager) Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), new Class<?>[] { TransactionManager.class }, new InvocationHandler() {

            @Override
            public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                throw new UnsupportedOperationException(RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40089));
            }
        }));
    } else {
        this.transactionService.setDetectTransactions(true);
        this.transactionService.setTransactionManager(config.getTransactionManager());
    }
    if (config.getSecurityHelper() != null) {
        this.sessionService.setSecurityHelper(config.getSecurityHelper());
    } else {
        this.sessionService.setSecurityHelper(new DoNothingSecurityHelper());
    }
    if (config.getSecurityDomain() != null) {
        this.sessionService.setSecurityDomain(config.getSecurityDomain());
    } else {
        // $NON-NLS-1$
        this.sessionService.setSecurityDomain("teiid-security");
    }
    this.sessionService.setVDBRepository(repo);
    setBufferManagerProperties(config);
    BufferService bs = getBufferService();
    this.dqp.setBufferManager(bs.getBufferManager());
    startVDBRepository();
    // $NON-NLS-1$
    rs = new SessionAwareCache<CachedResults>("resultset", config.getCacheFactory(), SessionAwareCache.Type.RESULTSET, config.getMaxResultSetCacheStaleness());
    // $NON-NLS-1$
    ppc = new SessionAwareCache<PreparedPlan>("preparedplan", config.getCacheFactory(), SessionAwareCache.Type.PREPAREDPLAN, 0);
    rs.setTupleBufferCache(bs.getTupleBufferCache());
    this.dqp.setResultsetCache(rs);
    ppc.setTupleBufferCache(bs.getTupleBufferCache());
    this.dqp.setPreparedPlanCache(ppc);
    this.dqp.setTransactionService((TransactionService) LogManager.createLoggingProxy(LogConstants.CTX_TXN_LOG, this.transactionService, new Class[] { TransactionService.class }, MessageLevel.DETAIL, Thread.currentThread().getContextClassLoader()));
    this.dqp.start(config);
    this.sessionService.setDqp(this.dqp);
    this.services.setSecurityHelper(this.sessionService.getSecurityHelper());
    if (this.config.getAuthenticationType() != null) {
        this.services.setAuthenticationType(this.config.getAuthenticationType());
        this.sessionService.setAuthenticationType(this.config.getAuthenticationType());
    }
    this.sessionService.start();
    this.services.setVDBRepository(this.repo);
    this.materializationMgr = getMaterializationManager();
    this.repo.addListener(this.materializationMgr);
    this.repo.setAllowEnvFunction(this.config.isAllowEnvFunction());
    if (this.nodeTracker != null) {
        this.nodeTracker.addNodeListener(this.materializationMgr);
    }
    this.logon = new LogonImpl(sessionService, null);
    services.registerClientService(ILogon.class, logon, LogConstants.CTX_SECURITY);
    DQP dqpProxy = DQP.class.cast(Proxy.newProxyInstance(this.getClass().getClassLoader(), new Class[] { DQP.class }, new SessionCheckingProxy(dqp, LogConstants.CTX_DQP, MessageLevel.TRACE)));
    services.registerClientService(DQP.class, dqpProxy, LogConstants.CTX_DQP);
    initDriver();
    List<SocketConfiguration> transports = config.getTransports();
    if (transports != null && !transports.isEmpty()) {
        for (SocketConfiguration socketConfig : transports) {
            SocketListener socketConnection = startTransport(socketConfig, bs.getBufferManager(), config.getMaxODBCLobSizeAllowed());
            if (socketConfig.getSSLConfiguration() != null) {
                try {
                    socketConfig.getSSLConfiguration().getServerSSLEngine();
                } catch (Exception e) {
                    throw new TeiidRuntimeException(e);
                }
            }
            this.transports.add(socketConnection);
        }
    }
    this.shutdownListener.setBootInProgress(false);
    this.shutdownListener.started();
    running = true;
}
Also used : TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) JGroupsObjectReplicator(org.teiid.replication.jgroups.JGroupsObjectReplicator) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) DQP(org.teiid.client.DQP) NamedThreadFactory(org.teiid.core.util.NamedThreadFactory) BufferService(org.teiid.dqp.service.BufferService) Method(java.lang.reflect.Method) InvocationHandler(java.lang.reflect.InvocationHandler) ConnectorManagerException(org.teiid.dqp.internal.datamgr.ConnectorManagerRepository.ConnectorManagerException) InvalidSessionException(org.teiid.client.security.InvalidSessionException) XMLStreamException(javax.xml.stream.XMLStreamException) TeiidSQLException(org.teiid.jdbc.TeiidSQLException) ConnectionException(org.teiid.net.ConnectionException) SQLException(java.sql.SQLException) TranslatorException(org.teiid.translator.TranslatorException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) URISyntaxException(java.net.URISyntaxException) TeiidException(org.teiid.core.TeiidException) SAXException(org.xml.sax.SAXException) VirtualDatabaseException(org.teiid.deployers.VirtualDatabaseException) TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) CachedResults(org.teiid.dqp.internal.process.CachedResults) PreparedPlan(org.teiid.dqp.internal.process.PreparedPlan)

Example 2 with NamedThreadFactory

use of org.teiid.core.util.NamedThreadFactory in project teiid by teiid.

the class TeiidAdd method initilaizeTeiidEngine.

private void initilaizeTeiidEngine(final OperationContext context, final ModelNode operation) throws OperationFailedException {
    ServiceTarget target = context.getServiceTarget();
    final String nodeName = getNodeName();
    Environment environment = context.getCallEnvironment();
    final JBossLifeCycleListener shutdownListener = new JBossLifeCycleListener(environment);
    // $NON-NLS-1$
    ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor(new NamedThreadFactory("Teiid Timer"));
    // async thread-pool
    int maxThreads = 10;
    if (asInt(THREAD_COUNT_ATTRIBUTE, operation, context) != null) {
        maxThreads = asInt(THREAD_COUNT_ATTRIBUTE, operation, context);
    }
    buildThreadService(maxThreads, target);
    // translator repository
    final TranslatorRepository translatorRepo = new TranslatorRepository();
    ValueService<TranslatorRepository> translatorService = new ValueService<TranslatorRepository>(new org.jboss.msc.value.Value<TranslatorRepository>() {

        @Override
        public TranslatorRepository getValue() throws IllegalStateException, IllegalArgumentException {
            return translatorRepo;
        }
    });
    ServiceController<TranslatorRepository> service = target.addService(TeiidServiceNames.TRANSLATOR_REPO, translatorService).install();
    final ConnectorManagerRepository connectorManagerRepo = buildConnectorManagerRepository(translatorRepo);
    // system function tree
    SystemFunctionManager systemFunctionManager = SystemMetadata.getInstance().getSystemFunctionManager();
    // VDB repository
    final VDBRepository vdbRepository = new VDBRepository();
    vdbRepository.setSystemFunctionManager(systemFunctionManager);
    if (isDefined(DATA_ROLES_REQUIRED_ELEMENT, operation, context) && asBoolean(DATA_ROLES_REQUIRED_ELEMENT, operation, context)) {
        vdbRepository.setDataRolesRequired(true);
    }
    if (isDefined(ALLOW_ENV_FUNCTION_ELEMENT, operation, context)) {
        vdbRepository.setAllowEnvFunction(asBoolean(ALLOW_ENV_FUNCTION_ELEMENT, operation, context));
    } else {
        vdbRepository.setAllowEnvFunction(false);
    }
    VDBRepositoryService vdbRepositoryService = new VDBRepositoryService(vdbRepository);
    ServiceBuilder<VDBRepository> vdbRepoService = target.addService(TeiidServiceNames.VDB_REPO, vdbRepositoryService);
    vdbRepoService.addDependency(TeiidServiceNames.BUFFER_MGR, BufferManager.class, vdbRepositoryService.bufferManagerInjector);
    vdbRepoService.addDependency(DependencyType.OPTIONAL, TeiidServiceNames.OBJECT_REPLICATOR, ObjectReplicator.class, vdbRepositoryService.objectReplicatorInjector);
    vdbRepoService.install();
    // VDB Status manager
    final VDBStatusCheckerExecutorService statusChecker = new VDBStatusCheckerExecutorService();
    ValueService<VDBStatusChecker> statusService = new ValueService<VDBStatusChecker>(new org.jboss.msc.value.Value<VDBStatusChecker>() {

        @Override
        public VDBStatusChecker getValue() throws IllegalStateException, IllegalArgumentException {
            return statusChecker;
        }
    });
    ServiceBuilder<VDBStatusChecker> statusBuilder = target.addService(TeiidServiceNames.VDB_STATUS_CHECKER, statusService);
    statusBuilder.addDependency(TeiidServiceNames.THREAD_POOL_SERVICE, Executor.class, statusChecker.executorInjector);
    statusBuilder.addDependency(TeiidServiceNames.VDB_REPO, VDBRepository.class, statusChecker.vdbRepoInjector);
    statusBuilder.install();
    // $NON-NLS-1$ //$NON-NLS-2$
    RelativePathService.addService(TeiidServiceNames.DATA_DIR, "teiid-data", "jboss.server.data.dir", target);
    final ObjectsSerializerService serializer = new ObjectsSerializerService();
    ServiceBuilder<ObjectSerializer> objectSerializerService = target.addService(TeiidServiceNames.OBJECT_SERIALIZER, serializer);
    objectSerializerService.addDependency(TeiidServiceNames.DATA_DIR, String.class, serializer.getPathInjector());
    objectSerializerService.install();
    // Object Replicator
    boolean replicatorAvailable = false;
    if (isDefined(DC_STACK_ATTRIBUTE, operation, context)) {
        String stack = asString(DC_STACK_ATTRIBUTE, operation, context);
        replicatorAvailable = true;
        JGroupsObjectReplicatorService replicatorService = new JGroupsObjectReplicatorService();
        ServiceBuilder<JGroupsObjectReplicator> serviceBuilder = target.addService(TeiidServiceNames.OBJECT_REPLICATOR, replicatorService);
        // $NON-NLS-1$ //$NON-NLS-2$
        serviceBuilder.addDependency(JGroupsRequirement.CHANNEL_FACTORY.getServiceName(context, stack), ChannelFactory.class, replicatorService.channelFactoryInjector);
        serviceBuilder.addDependency(TeiidServiceNames.THREAD_POOL_SERVICE, Executor.class, replicatorService.executorInjector);
        serviceBuilder.install();
        LogManager.logInfo(LogConstants.CTX_RUNTIME, IntegrationPlugin.Util.gs(IntegrationPlugin.Event.TEIID50003));
        NodeTrackerService trackerService = new NodeTrackerService(nodeName, scheduler);
        ServiceBuilder<NodeTracker> nodeTrackerBuilder = target.addService(TeiidServiceNames.NODE_TRACKER_SERVICE, trackerService);
        // $NON-NLS-1$ //$NON-NLS-2$
        nodeTrackerBuilder.addDependency(JGroupsRequirement.CHANNEL_FACTORY.getServiceName(context, stack), ChannelFactory.class, trackerService.channelFactoryInjector);
        nodeTrackerBuilder.install();
    } else {
        // $NON-NLS-1$
        LogManager.logDetail(LogConstants.CTX_RUNTIME, IntegrationPlugin.Util.getString("distributed_cache_not_enabled"));
    }
    // TODO: remove verbose service by moving the buffer service from runtime project
    // $NON-NLS-1$ //$NON-NLS-2$
    RelativePathService.addService(TeiidServiceNames.BUFFER_DIR, "teiid-buffer", "jboss.server.temp.dir", target);
    BufferManagerService bufferService = buildBufferManager(context, operation);
    ServiceBuilder<BufferManager> bufferServiceBuilder = target.addService(TeiidServiceNames.BUFFER_MGR, bufferService);
    bufferServiceBuilder.addDependency(TeiidServiceNames.BUFFER_DIR, String.class, bufferService.pathInjector);
    bufferServiceBuilder.install();
    TupleBufferCacheService tupleBufferService = new TupleBufferCacheService();
    ServiceBuilder<TupleBufferCache> tupleBufferBuilder = target.addService(TeiidServiceNames.TUPLE_BUFFER, tupleBufferService);
    tupleBufferBuilder.addDependency(TeiidServiceNames.BUFFER_MGR, BufferManager.class, tupleBufferService.bufferMgrInjector);
    tupleBufferBuilder.addDependency(replicatorAvailable ? DependencyType.REQUIRED : DependencyType.OPTIONAL, TeiidServiceNames.OBJECT_REPLICATOR, ObjectReplicator.class, tupleBufferService.replicatorInjector);
    tupleBufferBuilder.install();
    PolicyDecider policyDecider = null;
    if (isDefined(POLICY_DECIDER_MODULE_ELEMENT, operation, context)) {
        policyDecider = buildService(PolicyDecider.class, asString(POLICY_DECIDER_MODULE_ELEMENT, operation, context));
    }
    final AuthorizationValidator authValidator;
    if (isDefined(AUTHORIZATION_VALIDATOR_MODULE_ELEMENT, operation, context)) {
        authValidator = buildService(AuthorizationValidator.class, asString(AUTHORIZATION_VALIDATOR_MODULE_ELEMENT, operation, context));
    } else {
        DefaultAuthorizationValidator dap = new DefaultAuthorizationValidator();
        dap.setPolicyDecider(policyDecider);
        authValidator = dap;
    }
    ValueService<AuthorizationValidator> authValidatorService = new ValueService<AuthorizationValidator>(new org.jboss.msc.value.Value<AuthorizationValidator>() {

        @Override
        public AuthorizationValidator getValue() throws IllegalStateException, IllegalArgumentException {
            return authValidator;
        }
    });
    target.addService(TeiidServiceNames.AUTHORIZATION_VALIDATOR, authValidatorService).install();
    final PreParser preParser;
    if (isDefined(PREPARSER_MODULE_ELEMENT, operation, context)) {
        preParser = buildService(PreParser.class, asString(PREPARSER_MODULE_ELEMENT, operation, context));
    } else {
        preParser = new PreParser() {

            @Override
            public String preParse(String command, CommandContext context) {
                return command;
            }
        };
    }
    ValueService<PreParser> preParserService = new ValueService<PreParser>(new org.jboss.msc.value.Value<PreParser>() {

        @Override
        public PreParser getValue() throws IllegalStateException, IllegalArgumentException {
            return preParser;
        }
    });
    target.addService(TeiidServiceNames.PREPARSER, preParserService).install();
    // resultset cache
    boolean rsCache = true;
    if (isDefined(RSC_ENABLE_ATTRIBUTE, operation, context) && !asBoolean(RSC_ENABLE_ATTRIBUTE, operation, context)) {
        rsCache = false;
    }
    if (!isDefined(RSC_CONTAINER_NAME_ATTRIBUTE, operation, context)) {
        throw new OperationFailedException(IntegrationPlugin.Util.gs(IntegrationPlugin.Event.TEIID50094));
    }
    // $NON-NLS-1$
    String cacheName = "resultset";
    if (isDefined(RSC_NAME_ATTRIBUTE, operation, context)) {
        // if null; default cache will be used
        cacheName = asString(RSC_NAME_ATTRIBUTE, operation, context);
    }
    if (rsCache) {
        CacheFactoryService cfs = new CacheFactoryService();
        ServiceBuilder<CacheFactory> cacheFactoryBuilder = target.addService(TeiidServiceNames.RESULTSET_CACHE_FACTORY, cfs);
        String ispnName = asString(RSC_CONTAINER_NAME_ATTRIBUTE, operation, context);
        cacheFactoryBuilder.addDependency(InfinispanRequirement.CONTAINER.getServiceName(context, ispnName), EmbeddedCacheManager.class, // $NON-NLS-1$
        cfs.cacheContainerInjector);
        cacheFactoryBuilder.install();
        int maxStaleness = DQPConfiguration.DEFAULT_MAX_STALENESS_SECONDS;
        if (isDefined(RSC_MAX_STALENESS_ATTRIBUTE, operation, context)) {
            maxStaleness = asInt(RSC_MAX_STALENESS_ATTRIBUTE, operation, context);
        }
        CacheService<CachedResults> resultSetService = new CacheService<CachedResults>(cacheName, SessionAwareCache.Type.RESULTSET, maxStaleness);
        ServiceBuilder<SessionAwareCache<CachedResults>> resultsCacheBuilder = target.addService(TeiidServiceNames.CACHE_RESULTSET, resultSetService);
        resultsCacheBuilder.addDependency(TeiidServiceNames.TUPLE_BUFFER, TupleBufferCache.class, resultSetService.tupleBufferCacheInjector);
        resultsCacheBuilder.addDependency(TeiidServiceNames.RESULTSET_CACHE_FACTORY, CacheFactory.class, resultSetService.cacheFactoryInjector);
        // $NON-NLS-1$
        resultsCacheBuilder.addDependency(InfinispanCacheRequirement.CACHE.getServiceName(context, ispnName, cacheName));
        // $NON-NLS-1$
        resultsCacheBuilder.addDependency(InfinispanCacheRequirement.CACHE.getServiceName(context, ispnName, cacheName + SessionAwareCache.REPL));
        resultsCacheBuilder.install();
    }
    // prepared-plan cache
    boolean ppCache = true;
    if (isDefined(PPC_ENABLE_ATTRIBUTE, operation, context)) {
        ppCache = asBoolean(PPC_ENABLE_ATTRIBUTE, operation, context);
    }
    if (!isDefined(PPC_CONTAINER_NAME_ATTRIBUTE, operation, context)) {
        throw new OperationFailedException(IntegrationPlugin.Util.gs(IntegrationPlugin.Event.TEIID50095));
    }
    // $NON-NLS-1$
    cacheName = "preparedplan";
    if (isDefined(PPC_NAME_ATTRIBUTE, operation, context)) {
        cacheName = asString(PPC_NAME_ATTRIBUTE, operation, context);
    }
    if (ppCache) {
        CacheFactoryService cfs = new CacheFactoryService();
        ServiceBuilder<CacheFactory> cacheFactoryBuilder = target.addService(TeiidServiceNames.PREPAREDPLAN_CACHE_FACTORY, cfs);
        String ispnName = asString(PPC_CONTAINER_NAME_ATTRIBUTE, operation, context);
        cacheFactoryBuilder.addDependency(InfinispanRequirement.CONTAINER.getServiceName(context, ispnName), EmbeddedCacheManager.class, // $NON-NLS-1$
        cfs.cacheContainerInjector);
        cacheFactoryBuilder.install();
        CacheService<PreparedPlan> preparedPlanService = new CacheService<PreparedPlan>(cacheName, SessionAwareCache.Type.PREPAREDPLAN, 0);
        ServiceBuilder<SessionAwareCache<PreparedPlan>> preparedPlanCacheBuilder = target.addService(TeiidServiceNames.CACHE_PREPAREDPLAN, preparedPlanService);
        preparedPlanCacheBuilder.addDependency(TeiidServiceNames.PREPAREDPLAN_CACHE_FACTORY, CacheFactory.class, preparedPlanService.cacheFactoryInjector);
        // $NON-NLS-1$
        preparedPlanCacheBuilder.addDependency(InfinispanCacheRequirement.CACHE.getServiceName(context, ispnName, cacheName));
        preparedPlanCacheBuilder.install();
    }
    // Query Engine
    final DQPCoreService engine = buildQueryEngine(context, operation);
    EventDistributorFactoryService edfs = new EventDistributorFactoryService();
    ServiceBuilder<InternalEventDistributorFactory> edfsServiceBuilder = target.addService(TeiidServiceNames.EVENT_DISTRIBUTOR_FACTORY, edfs);
    edfsServiceBuilder.addDependency(TeiidServiceNames.VDB_REPO, VDBRepository.class, edfs.vdbRepositoryInjector);
    edfsServiceBuilder.addDependency(replicatorAvailable ? DependencyType.REQUIRED : DependencyType.OPTIONAL, TeiidServiceNames.OBJECT_REPLICATOR, ObjectReplicator.class, edfs.objectReplicatorInjector);
    edfs.dqpCore = engine.getValue();
    edfsServiceBuilder.install();
    // $NON-NLS-1$
    String workManager = "default";
    if (isDefined(WORKMANAGER, operation, context)) {
        workManager = asString(WORKMANAGER, operation, context);
    }
    ServiceBuilder<DQPCore> engineBuilder = target.addService(TeiidServiceNames.ENGINE, engine);
    // $NON-NLS-1$ //$NON-NLS-2$
    engineBuilder.addDependency(ServiceName.JBOSS.append("connector", "workmanager", workManager), WorkManager.class, engine.getWorkManagerInjector());
    // $NON-NLS-1$ //$NON-NLS-2$
    engineBuilder.addDependency(ServiceName.JBOSS.append("txn", "XATerminator"), XATerminator.class, engine.getXaTerminatorInjector());
    // $NON-NLS-1$ //$NON-NLS-2$
    engineBuilder.addDependency(ServiceName.JBOSS.append("txn", "TransactionManager"), TransactionManager.class, engine.getTxnManagerInjector());
    engineBuilder.addDependency(TeiidServiceNames.BUFFER_MGR, BufferManager.class, engine.getBufferManagerInjector());
    engineBuilder.addDependency(TeiidServiceNames.TRANSLATOR_REPO, TranslatorRepository.class, engine.getTranslatorRepositoryInjector());
    engineBuilder.addDependency(TeiidServiceNames.VDB_REPO, VDBRepository.class, engine.getVdbRepositoryInjector());
    engineBuilder.addDependency(TeiidServiceNames.AUTHORIZATION_VALIDATOR, AuthorizationValidator.class, engine.getAuthorizationValidatorInjector());
    engineBuilder.addDependency(TeiidServiceNames.PREPARSER, PreParser.class, engine.getPreParserInjector());
    engineBuilder.addDependency(rsCache ? DependencyType.REQUIRED : DependencyType.OPTIONAL, TeiidServiceNames.CACHE_RESULTSET, SessionAwareCache.class, engine.getResultSetCacheInjector());
    engineBuilder.addDependency(TeiidServiceNames.CACHE_PREPAREDPLAN, SessionAwareCache.class, engine.getPreparedPlanCacheInjector());
    engineBuilder.addDependency(TeiidServiceNames.EVENT_DISTRIBUTOR_FACTORY, InternalEventDistributorFactory.class, engine.getEventDistributorFactoryInjector());
    engineBuilder.setInitialMode(ServiceController.Mode.ACTIVE);
    engineBuilder.install();
    // add JNDI for event distributor
    final ReferenceFactoryService<EventDistributorFactory> referenceFactoryService = new ReferenceFactoryService<EventDistributorFactory>();
    // $NON-NLS-1$
    final ServiceName referenceFactoryServiceName = TeiidServiceNames.EVENT_DISTRIBUTOR_FACTORY.append("reference-factory");
    final ServiceBuilder<?> referenceBuilder = target.addService(referenceFactoryServiceName, referenceFactoryService);
    referenceBuilder.addDependency(TeiidServiceNames.EVENT_DISTRIBUTOR_FACTORY, EventDistributorFactory.class, referenceFactoryService.getInjector());
    referenceBuilder.setInitialMode(ServiceController.Mode.ACTIVE);
    // $NON-NLS-1$
    String jndiName = "teiid/event-distributor-factory";
    final ContextNames.BindInfo bindInfo = ContextNames.bindInfoFor(jndiName);
    final BinderService binderService = new BinderService(bindInfo.getBindName());
    final ServiceBuilder<?> binderBuilder = target.addService(bindInfo.getBinderServiceName(), binderService);
    binderBuilder.addDependency(referenceFactoryServiceName, ManagedReferenceFactory.class, binderService.getManagedObjectInjector());
    binderBuilder.addDependency(bindInfo.getParentContextServiceName(), ServiceBasedNamingStore.class, binderService.getNamingStoreInjector());
    binderBuilder.setInitialMode(ServiceController.Mode.ACTIVE);
    referenceBuilder.install();
    binderBuilder.install();
    // $NON-NLS-1$
    LogManager.logDetail(LogConstants.CTX_RUNTIME, IntegrationPlugin.Util.getString("event_distributor_bound", jndiName));
    // Materialization management service
    MaterializationManagementService matviewService = new MaterializationManagementService(shutdownListener, scheduler);
    ServiceBuilder<MaterializationManager> matviewBuilder = target.addService(TeiidServiceNames.MATVIEW_SERVICE, matviewService);
    matviewBuilder.addDependency(TeiidServiceNames.ENGINE, DQPCore.class, matviewService.dqpInjector);
    matviewBuilder.addDependency(TeiidServiceNames.VDB_REPO, VDBRepository.class, matviewService.vdbRepositoryInjector);
    matviewBuilder.addDependency(replicatorAvailable ? DependencyType.REQUIRED : DependencyType.OPTIONAL, TeiidServiceNames.NODE_TRACKER_SERVICE, NodeTracker.class, matviewService.nodeTrackerInjector);
    matviewBuilder.install();
    // Register VDB deployer
    context.addStep(new AbstractDeploymentChainStep() {

        @Override
        public void execute(DeploymentProcessorTarget processorTarget) {
            // vdb deployers
            processorTarget.addDeploymentProcessor(TeiidExtension.TEIID_SUBSYSTEM, Phase.STRUCTURE, 0, new FileRootMountProcessor(".ddl"));
            processorTarget.addDeploymentProcessor(TeiidExtension.TEIID_SUBSYSTEM, Phase.STRUCTURE, Phase.STRUCTURE_WAR_DEPLOYMENT_INIT | 0xFF75, new DynamicVDBRootMountDeployer());
            processorTarget.addDeploymentProcessor(TeiidExtension.TEIID_SUBSYSTEM, Phase.STRUCTURE, Phase.STRUCTURE_WAR_DEPLOYMENT_INIT | 0xFF76, new VDBStructureDeployer());
            processorTarget.addDeploymentProcessor(TeiidExtension.TEIID_SUBSYSTEM, Phase.PARSE, Phase.PARSE_WEB_DEPLOYMENT | 0x0001, new VDBParserDeployer(vdbRepository));
            processorTarget.addDeploymentProcessor(TeiidExtension.TEIID_SUBSYSTEM, Phase.DEPENDENCIES, Phase.DEPENDENCIES_WAR_MODULE | 0x0001, new VDBDependencyDeployer());
            processorTarget.addDeploymentProcessor(TeiidExtension.TEIID_SUBSYSTEM, Phase.INSTALL, Phase.INSTALL_WAR_DEPLOYMENT | 0x1000, new VDBDeployer(translatorRepo, vdbRepository, shutdownListener));
            // translator deployers
            processorTarget.addDeploymentProcessor(TeiidExtension.TEIID_SUBSYSTEM, Phase.STRUCTURE, Phase.STRUCTURE_JDBC_DRIVER | 0x0001, new TranslatorStructureDeployer());
            processorTarget.addDeploymentProcessor(TeiidExtension.TEIID_SUBSYSTEM, Phase.DEPENDENCIES, Phase.DEPENDENCIES_MODULE | 0x0001, new TranslatorDependencyDeployer());
            processorTarget.addDeploymentProcessor(TeiidExtension.TEIID_SUBSYSTEM, Phase.INSTALL, Phase.INSTALL_JDBC_DRIVER | 0x0001, new TranslatorDeployer());
        }
    }, OperationContext.Stage.RUNTIME);
    // install a session service
    // TODO: may eventually couple this with DQPCore
    final SessionServiceImpl sessionServiceImpl = new SessionServiceImpl();
    if (isDefined(AUTHENTICATION_SECURITY_DOMAIN_ATTRIBUTE, operation, context)) {
        String securityDomain = asString(AUTHENTICATION_SECURITY_DOMAIN_ATTRIBUTE, operation, context);
        sessionServiceImpl.setSecurityDomain(securityDomain);
    }
    if (isDefined(AUTHENTICATION_MAX_SESSIONS_ALLOWED_ATTRIBUTE, operation, context)) {
        sessionServiceImpl.setSessionMaxLimit(asLong(AUTHENTICATION_MAX_SESSIONS_ALLOWED_ATTRIBUTE, operation, context));
    }
    if (isDefined(AUTHENTICATION_SESSION_EXPIRATION_TIME_LIMIT_ATTRIBUTE, operation, context)) {
        sessionServiceImpl.setSessionExpirationTimeLimit(asLong(AUTHENTICATION_SESSION_EXPIRATION_TIME_LIMIT_ATTRIBUTE, operation, context));
    }
    if (isDefined(AUTHENTICATION_TYPE_ATTRIBUTE, operation, context)) {
        sessionServiceImpl.setAuthenticationType(AuthenticationType.valueOf(asString(AUTHENTICATION_TYPE_ATTRIBUTE, operation, context)));
    } else {
        sessionServiceImpl.setAuthenticationType(AuthenticationType.USERPASSWORD);
    }
    if (isDefined(AUTHENTICATION_TRUST_ALL_LOCAL_ATTRIBUTE, operation, context)) {
        boolean allowUnauthenticated = asBoolean(AUTHENTICATION_TRUST_ALL_LOCAL_ATTRIBUTE, operation, context);
        sessionServiceImpl.setTrustAllLocal(allowUnauthenticated);
    }
    if (isDefined(AUTHENTICATION_ALLOW_SECURITY_DOMAIN_QUALIFIER, operation, context)) {
        boolean allowSecurityDomainQualifier = asBoolean(AUTHENTICATION_ALLOW_SECURITY_DOMAIN_QUALIFIER, operation, context);
        sessionServiceImpl.setAllowSecurityDomainQualifier(allowSecurityDomainQualifier);
    }
    sessionServiceImpl.setDqp(engine.getValue());
    sessionServiceImpl.setVDBRepository(vdbRepository);
    sessionServiceImpl.setSecurityHelper(new JBossSecurityHelper());
    sessionServiceImpl.start();
    ContainerSessionService containerSessionService = new ContainerSessionService(sessionServiceImpl);
    ServiceBuilder<SessionService> sessionServiceBuilder = target.addService(TeiidServiceNames.SESSION, containerSessionService);
    sessionServiceBuilder.install();
    // rest war service
    RestWarGenerator warGenerator = TeiidAdd.buildService(RestWarGenerator.class, "org.jboss.teiid.rest-service");
    ResteasyEnabler restEnabler = new ResteasyEnabler(warGenerator);
    ServiceBuilder<Void> warGeneratorSvc = target.addService(TeiidServiceNames.REST_WAR_SERVICE, restEnabler);
    warGeneratorSvc.addDependency(Services.JBOSS_SERVER_CONTROLLER, ModelController.class, restEnabler.controllerValue);
    warGeneratorSvc.addDependency(TeiidServiceNames.THREAD_POOL_SERVICE, Executor.class, restEnabler.executorInjector);
    warGeneratorSvc.addDependency(TeiidServiceNames.VDB_REPO, VDBRepository.class, restEnabler.vdbRepoInjector);
    warGeneratorSvc.install();
}
Also used : SystemFunctionManager(org.teiid.query.function.SystemFunctionManager) NodeTracker(org.teiid.runtime.NodeTracker) DefaultAuthorizationValidator(org.teiid.dqp.internal.process.DefaultAuthorizationValidator) AuthorizationValidator(org.teiid.dqp.internal.process.AuthorizationValidator) CommandContext(org.teiid.CommandContext) TeiidConstants.asString(org.teiid.jboss.TeiidConstants.asString) PreParser(org.teiid.PreParser) TupleBufferCache(org.teiid.common.buffer.TupleBufferCache) CacheFactory(org.teiid.cache.CacheFactory) NamedThreadFactory(org.teiid.core.util.NamedThreadFactory) VDBStatusChecker(org.teiid.deployers.VDBStatusChecker) CachedResults(org.teiid.dqp.internal.process.CachedResults) PreparedPlan(org.teiid.dqp.internal.process.PreparedPlan) AbstractDeploymentChainStep(org.jboss.as.server.AbstractDeploymentChainStep) DQPCore(org.teiid.dqp.internal.process.DQPCore) InternalEventDistributorFactory(org.teiid.services.InternalEventDistributorFactory) RestWarGenerator(org.teiid.deployers.RestWarGenerator) ConnectorManagerRepository(org.teiid.dqp.internal.datamgr.ConnectorManagerRepository) OperationFailedException(org.jboss.as.controller.OperationFailedException) SessionService(org.teiid.dqp.service.SessionService) DeploymentProcessorTarget(org.jboss.as.server.DeploymentProcessorTarget) SessionAwareCache(org.teiid.dqp.internal.process.SessionAwareCache) BufferManager(org.teiid.common.buffer.BufferManager) TranslatorRepository(org.teiid.dqp.internal.datamgr.TranslatorRepository) JGroupsObjectReplicator(org.teiid.replication.jgroups.JGroupsObjectReplicator) ContextNames(org.jboss.as.naming.deployment.ContextNames) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) ServiceTarget(org.jboss.msc.service.ServiceTarget) MaterializationManager(org.teiid.runtime.MaterializationManager) ServiceName(org.jboss.msc.service.ServiceName) Environment(org.jboss.as.controller.access.Environment) PolicyDecider(org.teiid.PolicyDecider) ValueService(org.jboss.msc.service.ValueService) BinderService(org.jboss.as.naming.service.BinderService) DefaultAuthorizationValidator(org.teiid.dqp.internal.process.DefaultAuthorizationValidator) InternalEventDistributorFactory(org.teiid.services.InternalEventDistributorFactory) EventDistributorFactory(org.teiid.events.EventDistributorFactory) SessionServiceImpl(org.teiid.services.SessionServiceImpl) VDBRepository(org.teiid.deployers.VDBRepository)

Aggregations

ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)2 NamedThreadFactory (org.teiid.core.util.NamedThreadFactory)2 CachedResults (org.teiid.dqp.internal.process.CachedResults)2 PreparedPlan (org.teiid.dqp.internal.process.PreparedPlan)2 JGroupsObjectReplicator (org.teiid.replication.jgroups.JGroupsObjectReplicator)2 IOException (java.io.IOException)1 InvocationHandler (java.lang.reflect.InvocationHandler)1 Method (java.lang.reflect.Method)1 URISyntaxException (java.net.URISyntaxException)1 UnknownHostException (java.net.UnknownHostException)1 SQLException (java.sql.SQLException)1 XMLStreamException (javax.xml.stream.XMLStreamException)1 OperationFailedException (org.jboss.as.controller.OperationFailedException)1 Environment (org.jboss.as.controller.access.Environment)1 ContextNames (org.jboss.as.naming.deployment.ContextNames)1 BinderService (org.jboss.as.naming.service.BinderService)1 AbstractDeploymentChainStep (org.jboss.as.server.AbstractDeploymentChainStep)1 DeploymentProcessorTarget (org.jboss.as.server.DeploymentProcessorTarget)1 ServiceName (org.jboss.msc.service.ServiceName)1 ServiceTarget (org.jboss.msc.service.ServiceTarget)1