Search in sources :

Example 11 with ServiceController

use of org.jboss.msc.service.ServiceController in project wildfly by wildfly.

the class UndertowSubsystem31TestCase method testRuntime.

@Test
public void testRuntime() throws Exception {
    System.setProperty("server.data.dir", System.getProperty("java.io.tmpdir"));
    System.setProperty("jboss.home.dir", System.getProperty("java.io.tmpdir"));
    System.setProperty("jboss.home.dir", System.getProperty("java.io.tmpdir"));
    System.setProperty("jboss.server.server.dir", System.getProperty("java.io.tmpdir"));
    KernelServicesBuilder builder = createKernelServicesBuilder(RUNTIME).setSubsystemXml(getSubsystemXml());
    KernelServices mainServices = builder.build();
    if (!mainServices.isSuccessfulBoot()) {
        Assert.fail(mainServices.getBootError().toString());
    }
    ServiceController<FilterService> connectionLimiter = (ServiceController<FilterService>) mainServices.getContainer().getService(UndertowService.FILTER.append("limit-connections"));
    connectionLimiter.setMode(ServiceController.Mode.ACTIVE);
    FilterService connectionLimiterService = connectionLimiter.getService().getValue();
    HttpHandler result = connectionLimiterService.createHttpHandler(Predicates.truePredicate(), new PathHandler());
    Assert.assertNotNull("handler should have been created", result);
    ServiceController<FilterService> headersFilter = (ServiceController<FilterService>) mainServices.getContainer().getService(UndertowService.FILTER.append("headers"));
    headersFilter.setMode(ServiceController.Mode.ACTIVE);
    FilterService headersService = headersFilter.getService().getValue();
    HttpHandler headerHandler = headersService.createHttpHandler(Predicates.truePredicate(), new PathHandler());
    Assert.assertNotNull("handler should have been created", headerHandler);
    final ServiceName hostServiceName = UndertowService.virtualHostName("some-server", "other-host");
    ServiceController<Host> hostSC = (ServiceController<Host>) mainServices.getContainer().getService(hostServiceName);
    Assert.assertNotNull(hostSC);
    hostSC.setMode(ServiceController.Mode.ACTIVE);
    Host host = hostSC.getValue();
    Assert.assertEquals(1, host.getFilters().size());
    Assert.assertEquals(3, host.getAllAliases().size());
    Assert.assertEquals("default-alias", new ArrayList<>(host.getAllAliases()).get(1));
    final ServiceName locationServiceName = UndertowService.locationServiceName("some-server", "default-host", "/");
    ServiceController<LocationService> locationSC = (ServiceController<LocationService>) mainServices.getContainer().getService(locationServiceName);
    Assert.assertNotNull(locationSC);
    locationSC.setMode(ServiceController.Mode.ACTIVE);
    LocationService locationService = locationSC.getValue();
    Assert.assertNotNull(locationService);
    connectionLimiter.setMode(ServiceController.Mode.REMOVE);
    final ServiceName jspServiceName = UndertowService.SERVLET_CONTAINER.append("myContainer");
    ServiceController<ServletContainerService> jspServiceServiceController = (ServiceController<ServletContainerService>) mainServices.getContainer().getService(jspServiceName);
    Assert.assertNotNull(jspServiceServiceController);
    JSPConfig jspConfig = jspServiceServiceController.getService().getValue().getJspConfig();
    Assert.assertNotNull(jspConfig);
    Assert.assertNotNull(jspConfig.createJSPServletInfo());
    final ServiceName filterRefName = UndertowService.filterRefName("some-server", "other-host", "/", "static-gzip");
    ServiceController<FilterRef> gzipFilterController = (ServiceController<FilterRef>) mainServices.getContainer().getService(filterRefName);
    gzipFilterController.setMode(ServiceController.Mode.ACTIVE);
    FilterRef gzipFilterRef = gzipFilterController.getService().getValue();
    HttpHandler gzipHandler = gzipFilterRef.createHttpHandler(new PathHandler());
    Assert.assertNotNull("handler should have been created", gzipHandler);
    //testCustomFilters(mainServices);
    ServiceController<Host> defaultHostSC = (ServiceController<Host>) mainServices.getContainer().getService(UndertowService.DEFAULT_HOST);
    defaultHostSC.setMode(ServiceController.Mode.ACTIVE);
    Host defaultHost = defaultHostSC.getValue();
    Assert.assertNotNull("Default host should exist", defaultHost);
    ServiceController<Server> defaultServerSC = (ServiceController<Server>) mainServices.getContainer().getService(UndertowService.DEFAULT_SERVER);
    defaultServerSC.setMode(ServiceController.Mode.ACTIVE);
    Server defaultServer = defaultServerSC.getValue();
    Assert.assertNotNull("Default host should exist", defaultServer);
    final ServiceName accessLogServiceName = UndertowService.accessLogServiceName("some-server", "default-host");
    ServiceController<AccessLogService> accessLogSC = (ServiceController<AccessLogService>) mainServices.getContainer().getService(accessLogServiceName);
    Assert.assertNotNull(accessLogSC);
    accessLogSC.setMode(ServiceController.Mode.ACTIVE);
    AccessLogService accessLogService = accessLogSC.getValue();
    Assert.assertNotNull(accessLogService);
    Assert.assertFalse(accessLogService.isRotate());
}
Also used : HttpHandler(io.undertow.server.HttpHandler) KernelServices(org.jboss.as.subsystem.test.KernelServices) FilterService(org.wildfly.extension.undertow.filters.FilterService) ArrayList(java.util.ArrayList) PathHandler(io.undertow.server.handlers.PathHandler) FilterRef(org.wildfly.extension.undertow.filters.FilterRef) ServiceName(org.jboss.msc.service.ServiceName) ServiceController(org.jboss.msc.service.ServiceController) KernelServicesBuilder(org.jboss.as.subsystem.test.KernelServicesBuilder) AbstractSubsystemBaseTest(org.jboss.as.subsystem.test.AbstractSubsystemBaseTest) Test(org.junit.Test)

Example 12 with ServiceController

use of org.jboss.msc.service.ServiceController in project wildfly by wildfly.

the class XTSSubsystemAdd method performBoottime.

@Override
protected void performBoottime(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException {
    final String hostName = HOST_NAME.resolveModelAttribute(context, model).asString();
    final ModelNode coordinatorURLAttribute = ENVIRONMENT_URL.resolveModelAttribute(context, model);
    String coordinatorURL = coordinatorURLAttribute.isDefined() ? coordinatorURLAttribute.asString() : null;
    if (coordinatorURL != null) {
        String[] attrs = coordinatorURL.split("/");
        boolean isIPv6Address = false;
        for (int i = 0; i < attrs.length; i++) {
            if (attrs[i].startsWith("::1")) {
                attrs[i] = "[" + attrs[i].substring(0, 3) + "]" + attrs[i].substring(3);
                isIPv6Address = true;
                break;
            }
        }
        if (isIPv6Address) {
            StringBuffer sb = new StringBuffer(attrs[0]);
            for (int i = 1; i < attrs.length; i++) {
                sb.append('/').append(attrs[i]);
            }
            coordinatorURL = sb.toString();
        }
    }
    if (coordinatorURL != null) {
        XtsAsLogger.ROOT_LOGGER.debugf("nodeIdentifier=%s%n", coordinatorURL);
    }
    final boolean isDefaultContextPropagation = model.hasDefined(CommonAttributes.DEFAULT_CONTEXT_PROPAGATION) ? model.get(CommonAttributes.DEFAULT_CONTEXT_PROPAGATION).asBoolean() : false;
    context.addStep(new AbstractDeploymentChainStep() {

        protected void execute(DeploymentProcessorTarget processorTarget) {
            processorTarget.addDeploymentProcessor(XTSExtension.SUBSYSTEM_NAME, Phase.PARSE, Phase.PARSE_XTS_COMPONENT_INTERCEPTORS, new XTSInterceptorDeploymentProcessor());
            processorTarget.addDeploymentProcessor(XTSExtension.SUBSYSTEM_NAME, Phase.PARSE, Phase.PARSE_XTS_SOAP_HANDLERS, new XTSHandlerDeploymentProcessor());
            processorTarget.addDeploymentProcessor(XTSExtension.SUBSYSTEM_NAME, Phase.DEPENDENCIES, Phase.DEPENDENCIES_XTS, new XTSDependenciesDeploymentProcessor());
            processorTarget.addDeploymentProcessor(XTSExtension.SUBSYSTEM_NAME, Phase.POST_MODULE, Phase.POST_MODULE_XTS_PORTABLE_EXTENSIONS, new GracefulShutdownDeploymentProcessor());
        }
    }, OperationContext.Stage.RUNTIME);
    final ServiceTarget target = context.getServiceTarget();
    // TODO eventually we should add a config service which manages the XTS configuration
    // this will allow us to include a switch enabling or disabling deployment of
    // endpoints specific to client, coordinator or participant and then deploy
    // and redeploy the relevant endpoints as needed/ the same switches can be used
    // byte the XTS service to decide whether to perfomr client, coordinator or
    // participant initialisation. we should also provide config switches which
    // decide whether to initialise classes and deploy services for AT, BA or both.
    // for now we will just deploy all the endpoints and always do client, coordinator
    // and participant init for both AT and BA.
    // add an endpoint publisher service for each of the required endpoint contexts
    // specifying all the relevant URL patterns and SEI classes
    final ClassLoader loader = XTSService.class.getClassLoader();
    ServiceBuilder<Context> endpointBuilder;
    ArrayList<ServiceController<Context>> controllers = new ArrayList<ServiceController<Context>>();
    Map<Class<?>, Object> attachments = new HashMap<>();
    attachments.put(RejectionRule.class, new GracefulShutdownRejectionRule());
    for (ContextInfo contextInfo : contextDefinitions) {
        String contextName = contextInfo.contextPath;
        Map<String, String> map = new HashMap<String, String>();
        for (EndpointInfo endpointInfo : contextInfo.endpointInfo) {
            map.put(endpointInfo.URLPattern, endpointInfo.SEIClassname);
        }
        endpointBuilder = EndpointPublishService.createServiceBuilder(target, contextName, loader, hostName, map, null, null, null, attachments);
        controllers.add(endpointBuilder.setInitialMode(Mode.ACTIVE).install());
    }
    XTSHandlersService.install(target, isDefaultContextPropagation);
    // add an XTS service which depends on all the WS endpoints
    final XTSManagerService xtsService = new XTSManagerService(coordinatorURL);
    // this service needs to depend on the transaction recovery service
    // because it can only initialise XTS recovery once the transaction recovery
    // service has initialised the orb layer
    ServiceBuilder<?> xtsServiceBuilder = target.addService(XTSServices.JBOSS_XTS_MAIN, xtsService);
    xtsServiceBuilder.addDependency(TxnServices.JBOSS_TXN_ARJUNA_TRANSACTION_MANAGER);
    // this service needs to depend on JBossWS Config Service to be notified of the JBoss WS config (bind address, port etc)
    xtsServiceBuilder.addDependency(WSServices.CONFIG_SERVICE, ServerConfig.class, xtsService.getWSServerConfig());
    xtsServiceBuilder.addDependency(WSServices.XTS_CLIENT_INTEGRATION_SERVICE);
    // the service also needs to depend on the endpoint services
    for (ServiceController<Context> controller : controllers) {
        xtsServiceBuilder.addDependency(controller.getName());
    }
    xtsServiceBuilder.setInitialMode(Mode.ACTIVE).install();
    // WS-AT / JTA Transaction bridge services:
    final TxBridgeInboundRecoveryService txBridgeInboundRecoveryService = new TxBridgeInboundRecoveryService();
    ServiceBuilder<?> txBridgeInboundRecoveryServiceBuilder = target.addService(XTSServices.JBOSS_XTS_TXBRIDGE_INBOUND_RECOVERY, txBridgeInboundRecoveryService);
    txBridgeInboundRecoveryServiceBuilder.addDependency(XTSServices.JBOSS_XTS_MAIN);
    txBridgeInboundRecoveryServiceBuilder.setInitialMode(Mode.ACTIVE).install();
    final TxBridgeOutboundRecoveryService txBridgeOutboundRecoveryService = new TxBridgeOutboundRecoveryService();
    ServiceBuilder<?> txBridgeOutboundRecoveryServiceBuilder = target.addService(XTSServices.JBOSS_XTS_TXBRIDGE_OUTBOUND_RECOVERY, txBridgeOutboundRecoveryService);
    txBridgeOutboundRecoveryServiceBuilder.addDependency(XTSServices.JBOSS_XTS_MAIN);
    txBridgeOutboundRecoveryServiceBuilder.setInitialMode(Mode.ACTIVE).install();
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ServiceController(org.jboss.msc.service.ServiceController) Context(org.jboss.wsf.spi.publish.Context) OperationContext(org.jboss.as.controller.OperationContext) ServiceTarget(org.jboss.msc.service.ServiceTarget) DeploymentProcessorTarget(org.jboss.as.server.DeploymentProcessorTarget) AbstractDeploymentChainStep(org.jboss.as.server.AbstractDeploymentChainStep) ModelNode(org.jboss.dmr.ModelNode)

Example 13 with ServiceController

use of org.jboss.msc.service.ServiceController in project wildfly by wildfly.

the class AbstractDataSourceAdd method secondRuntimeStep.

static void secondRuntimeStep(OperationContext context, ModelNode operation, ManagementResourceRegistration datasourceRegistration, ModelNode model, boolean isXa) throws OperationFailedException {
    final ServiceTarget serviceTarget = context.getServiceTarget();
    final ModelNode address = operation.require(OP_ADDR);
    final String dsName = PathAddress.pathAddress(address).getLastElement().getValue();
    final String jndiName = JNDI_NAME.resolveModelAttribute(context, model).asString();
    final ServiceRegistry registry = context.getServiceRegistry(true);
    final List<ServiceName> serviceNames = registry.getServiceNames();
    final boolean elytronEnabled = ELYTRON_ENABLED.resolveModelAttribute(context, model).asBoolean();
    final ServiceName dataSourceServiceName = context.getCapabilityServiceName(Capabilities.DATA_SOURCE_CAPABILITY_NAME, dsName, DataSource.class);
    final ServiceController<?> dataSourceController = registry.getService(dataSourceServiceName);
    final ExceptionSupplier<CredentialSource, Exception> credentialSourceExceptionExceptionSupplier = dataSourceController.getService() instanceof AbstractDataSourceService ? ((AbstractDataSourceService) dataSourceController.getService()).getCredentialSourceSupplierInjector().getOptionalValue() : null;
    final ExceptionSupplier<CredentialSource, Exception> recoveryCredentialSourceExceptionExceptionSupplier = dataSourceController.getService() instanceof AbstractDataSourceService ? ((AbstractDataSourceService) dataSourceController.getService()).getRecoveryCredentialSourceSupplierInjector().getOptionalValue() : null;
    final boolean jta;
    if (isXa) {
        jta = true;
        final ModifiableXaDataSource dataSourceConfig;
        try {
            dataSourceConfig = xaFrom(context, model, dsName, credentialSourceExceptionExceptionSupplier, recoveryCredentialSourceExceptionExceptionSupplier);
        } catch (ValidateException e) {
            throw new OperationFailedException(ConnectorLogger.ROOT_LOGGER.failedToCreate("XaDataSource", operation, e.getLocalizedMessage()));
        }
        final ServiceName xaDataSourceConfigServiceName = XADataSourceConfigService.SERVICE_NAME_BASE.append(dsName);
        final XADataSourceConfigService xaDataSourceConfigService = new XADataSourceConfigService(dataSourceConfig);
        final ServiceBuilder<?> builder = serviceTarget.addService(xaDataSourceConfigServiceName, xaDataSourceConfigService);
        // add dependency on security domain service if applicable
        final DsSecurity dsSecurityConfig = dataSourceConfig.getSecurity();
        if (dsSecurityConfig != null) {
            final String securityDomainName = dsSecurityConfig.getSecurityDomain();
            if (!elytronEnabled && securityDomainName != null) {
                builder.addDependency(SecurityDomainService.SERVICE_NAME.append(securityDomainName));
            }
        }
        // add dependency on security domain service if applicable for recovery config
        if (dataSourceConfig.getRecovery() != null) {
            final Credential credential = dataSourceConfig.getRecovery().getCredential();
            if (credential != null) {
                final String securityDomainName = credential.getSecurityDomain();
                if (!RECOVERY_ELYTRON_ENABLED.resolveModelAttribute(context, model).asBoolean() && securityDomainName != null) {
                    builder.addDependency(SecurityDomainService.SERVICE_NAME.append(securityDomainName));
                }
            }
        }
        int propertiesCount = 0;
        for (ServiceName name : serviceNames) {
            if (xaDataSourceConfigServiceName.append("xa-datasource-properties").isParentOf(name)) {
                final ServiceController<?> xaConfigPropertyController = registry.getService(name);
                XaDataSourcePropertiesService xaPropService = (XaDataSourcePropertiesService) xaConfigPropertyController.getService();
                if (!ServiceController.State.UP.equals(xaConfigPropertyController.getState())) {
                    propertiesCount++;
                    xaConfigPropertyController.setMode(ServiceController.Mode.ACTIVE);
                    builder.addDependency(name, String.class, xaDataSourceConfigService.getXaDataSourcePropertyInjector(xaPropService.getName()));
                } else {
                    throw new OperationFailedException(ConnectorLogger.ROOT_LOGGER.serviceAlreadyStarted("Data-source.xa-config-property", name));
                }
            }
        }
        if (propertiesCount == 0) {
            throw ConnectorLogger.ROOT_LOGGER.xaDataSourcePropertiesNotPresent();
        }
        builder.install();
    } else {
        final ModifiableDataSource dataSourceConfig;
        try {
            dataSourceConfig = from(context, model, dsName, credentialSourceExceptionExceptionSupplier);
        } catch (ValidateException e) {
            throw new OperationFailedException(ConnectorLogger.ROOT_LOGGER.failedToCreate("DataSource", operation, e.getLocalizedMessage()));
        }
        jta = dataSourceConfig.isJTA();
        final ServiceName dataSourceCongServiceName = DataSourceConfigService.SERVICE_NAME_BASE.append(dsName);
        final DataSourceConfigService configService = new DataSourceConfigService(dataSourceConfig);
        final ServiceBuilder<?> builder = serviceTarget.addService(dataSourceCongServiceName, configService);
        // add dependency on security domain service if applicable
        final DsSecurity dsSecurityConfig = dataSourceConfig.getSecurity();
        if (dsSecurityConfig != null) {
            final String securityDomainName = dsSecurityConfig.getSecurityDomain();
            if (!elytronEnabled && securityDomainName != null) {
                builder.addDependency(SecurityDomainService.SERVICE_NAME.append(securityDomainName));
            }
        }
        for (ServiceName name : serviceNames) {
            if (dataSourceCongServiceName.append("connection-properties").isParentOf(name)) {
                final ServiceController<?> connPropServiceController = registry.getService(name);
                ConnectionPropertiesService connPropService = (ConnectionPropertiesService) connPropServiceController.getService();
                if (!ServiceController.State.UP.equals(connPropServiceController.getState())) {
                    connPropServiceController.setMode(ServiceController.Mode.ACTIVE);
                    builder.addDependency(name, String.class, configService.getConnectionPropertyInjector(connPropService.getName()));
                } else {
                    throw new OperationFailedException(ConnectorLogger.ROOT_LOGGER.serviceAlreadyStarted("Data-source.connectionProperty", name));
                }
            }
        }
        builder.install();
    }
    final ServiceName dataSourceServiceNameAlias = AbstractDataSourceService.SERVICE_NAME_BASE.append(jndiName).append(Constants.STATISTICS);
    if (dataSourceController != null) {
        if (!ServiceController.State.UP.equals(dataSourceController.getState())) {
            final boolean statsEnabled = STATISTICS_ENABLED.resolveModelAttribute(context, model).asBoolean();
            DataSourceStatisticsService statsService = new DataSourceStatisticsService(datasourceRegistration, statsEnabled);
            serviceTarget.addService(dataSourceServiceName.append(Constants.STATISTICS), statsService).addAliases(dataSourceServiceNameAlias).addDependency(dataSourceServiceName).addDependency(CommonDeploymentService.getServiceName(ContextNames.bindInfoFor(jndiName)), CommonDeployment.class, statsService.getCommonDeploymentInjector()).setInitialMode(ServiceController.Mode.PASSIVE).install();
            dataSourceController.setMode(ServiceController.Mode.ACTIVE);
        } else {
            throw new OperationFailedException(ConnectorLogger.ROOT_LOGGER.serviceAlreadyStarted("Data-source", dsName));
        }
    } else {
        throw new OperationFailedException(ConnectorLogger.ROOT_LOGGER.serviceNotAvailable("Data-source", dsName));
    }
    final DataSourceReferenceFactoryService referenceFactoryService = new DataSourceReferenceFactoryService();
    final ServiceName referenceFactoryServiceName = DataSourceReferenceFactoryService.SERVICE_NAME_BASE.append(dsName);
    final ServiceBuilder<?> referenceBuilder = serviceTarget.addService(referenceFactoryServiceName, referenceFactoryService).addDependency(dataSourceServiceName, DataSource.class, referenceFactoryService.getDataSourceInjector());
    referenceBuilder.install();
    final ContextNames.BindInfo bindInfo = ContextNames.bindInfoFor(jndiName);
    final BinderService binderService = new BinderService(bindInfo.getBindName());
    final ServiceBuilder<?> binderBuilder = serviceTarget.addService(bindInfo.getBinderServiceName(), binderService).addDependency(referenceFactoryServiceName, ManagedReferenceFactory.class, binderService.getManagedObjectInjector()).addDependency(bindInfo.getParentContextServiceName(), ServiceBasedNamingStore.class, binderService.getNamingStoreInjector()).addListener(new AbstractServiceListener<Object>() {

        public void transition(final ServiceController<? extends Object> controller, final ServiceController.Transition transition) {
            switch(transition) {
                case STARTING_to_UP:
                    {
                        if (jta) {
                            SUBSYSTEM_DATASOURCES_LOGGER.boundDataSource(jndiName);
                        } else {
                            SUBSYSTEM_DATASOURCES_LOGGER.boundNonJTADataSource(jndiName);
                        }
                        break;
                    }
                case STOPPING_to_DOWN:
                    {
                        if (jta) {
                            SUBSYSTEM_DATASOURCES_LOGGER.unboundDataSource(jndiName);
                        } else {
                            SUBSYSTEM_DATASOURCES_LOGGER.unBoundNonJTADataSource(jndiName);
                        }
                        break;
                    }
                case REMOVING_to_REMOVED:
                    {
                        SUBSYSTEM_DATASOURCES_LOGGER.debugf("Removed JDBC Data-source [%s]", jndiName);
                        break;
                    }
            }
        }
    });
    binderBuilder.setInitialMode(ServiceController.Mode.ACTIVE);
    binderBuilder.install();
}
Also used : ValidateException(org.jboss.jca.common.api.validator.ValidateException) DataSourceStatisticsService(org.jboss.as.connector.services.datasources.statistics.DataSourceStatisticsService) BinderService(org.jboss.as.naming.service.BinderService) ServiceController(org.jboss.msc.service.ServiceController) CredentialSource(org.wildfly.security.credential.source.CredentialSource) ContextNames(org.jboss.as.naming.deployment.ContextNames) Credential(org.jboss.jca.common.api.metadata.common.Credential) DsSecurity(org.jboss.jca.common.api.metadata.ds.DsSecurity) ServiceTarget(org.jboss.msc.service.ServiceTarget) OperationFailedException(org.jboss.as.controller.OperationFailedException) OperationFailedException(org.jboss.as.controller.OperationFailedException) ValidateException(org.jboss.jca.common.api.validator.ValidateException) ServiceName(org.jboss.msc.service.ServiceName) ServiceBasedNamingStore(org.jboss.as.naming.ServiceBasedNamingStore) ServiceRegistry(org.jboss.msc.service.ServiceRegistry) ModelNode(org.jboss.dmr.ModelNode)

Example 14 with ServiceController

use of org.jboss.msc.service.ServiceController in project wildfly by wildfly.

the class EnlistmentTraceAttributeWriteHandler method applyUpdateToRuntime.

@Override
protected boolean applyUpdateToRuntime(final OperationContext context, final ModelNode operation, final String parameterName, final ModelNode newValue, final ModelNode currentValue, final HandbackHolder<List<DataSource>> handbackHolder) throws OperationFailedException {
    final String jndiName = context.readResource(PathAddress.EMPTY_ADDRESS).getModel().get(Constants.JNDI_NAME.getName()).asString();
    final ServiceController<?> managementRepoService = context.getServiceRegistry(false).getService(ConnectorServices.MANAGEMENT_REPOSITORY_SERVICE);
    Boolean boolValue = Constants.ENLISTMENT_TRACE.resolveValue(context, newValue).asBoolean();
    try {
        final ManagementRepository repository = (ManagementRepository) managementRepoService.getValue();
        if (repository.getDataSources() != null) {
            repository.getDataSources().stream().filter(ds -> jndiName.equalsIgnoreCase(ds.getJndiName())).forEach(ds -> ds.setEnlistmentTrace(boolValue));
            handbackHolder.setHandback(repository.getDataSources().stream().filter(ds -> jndiName.equalsIgnoreCase(ds.getJndiName())).collect(Collectors.toList()));
        }
    } catch (Exception e) {
        throw new OperationFailedException(ConnectorLogger.ROOT_LOGGER.failedToSetAttribute(e.getLocalizedMessage()));
    }
    return false;
}
Also used : AbstractWriteAttributeHandler(org.jboss.as.controller.AbstractWriteAttributeHandler) ServiceController(org.jboss.msc.service.ServiceController) List(java.util.List) OperationContext(org.jboss.as.controller.OperationContext) ManagementRepository(org.jboss.jca.core.api.management.ManagementRepository) OperationFailedException(org.jboss.as.controller.OperationFailedException) PathAddress(org.jboss.as.controller.PathAddress) ConnectorLogger(org.jboss.as.connector.logging.ConnectorLogger) ConnectorServices(org.jboss.as.connector.util.ConnectorServices) ModelNode(org.jboss.dmr.ModelNode) Collectors(java.util.stream.Collectors) DataSource(org.jboss.jca.core.api.management.DataSource) ManagementRepository(org.jboss.jca.core.api.management.ManagementRepository) OperationFailedException(org.jboss.as.controller.OperationFailedException) OperationFailedException(org.jboss.as.controller.OperationFailedException)

Example 15 with ServiceController

use of org.jboss.msc.service.ServiceController in project wildfly by wildfly.

the class DefaultResourceAdapterWriteHandler method updateDefaultAdapterService.

void updateDefaultAdapterService(final OperationContext context, final ModelNode model) throws OperationFailedException {
    final ModelNode adapterNameNode = EJB3SubsystemRootResourceDefinition.DEFAULT_RESOURCE_ADAPTER_NAME.resolveModelAttribute(context, model);
    final String adapterName = adapterNameNode.isDefined() ? adapterNameNode.asString() : null;
    final ServiceRegistry serviceRegistry = context.getServiceRegistry(true);
    ServiceController<DefaultResourceAdapterService> existingDefaultRANameService = (ServiceController<DefaultResourceAdapterService>) serviceRegistry.getService(DefaultResourceAdapterService.DEFAULT_RA_NAME_SERVICE_NAME);
    // if a default RA name service is already installed then just update the resource adapter name
    if (existingDefaultRANameService != null) {
        existingDefaultRANameService.getValue().setResourceAdapterName(adapterName);
    } else if (adapterName != null) {
        // create a new one and install
        final DefaultResourceAdapterService defaultResourceAdapterService = new DefaultResourceAdapterService(adapterName);
        ServiceController<?> newController = context.getServiceTarget().addService(DefaultResourceAdapterService.DEFAULT_RA_NAME_SERVICE_NAME, defaultResourceAdapterService).install();
    }
}
Also used : DefaultResourceAdapterService(org.jboss.as.ejb3.component.messagedriven.DefaultResourceAdapterService) ServiceController(org.jboss.msc.service.ServiceController) ServiceRegistry(org.jboss.msc.service.ServiceRegistry) ModelNode(org.jboss.dmr.ModelNode)

Aggregations

ServiceController (org.jboss.msc.service.ServiceController)51 ServiceName (org.jboss.msc.service.ServiceName)20 ModelNode (org.jboss.dmr.ModelNode)17 OperationFailedException (org.jboss.as.controller.OperationFailedException)15 OperationContext (org.jboss.as.controller.OperationContext)12 ServiceRegistry (org.jboss.msc.service.ServiceRegistry)12 BinderService (org.jboss.as.naming.service.BinderService)9 PathAddress (org.jboss.as.controller.PathAddress)8 ContextNames (org.jboss.as.naming.deployment.ContextNames)8 HttpHandler (io.undertow.server.HttpHandler)7 PathHandler (io.undertow.server.handlers.PathHandler)7 OperationStepHandler (org.jboss.as.controller.OperationStepHandler)7 FilterService (org.wildfly.extension.undertow.filters.FilterService)7 ServiceBasedNamingStore (org.jboss.as.naming.ServiceBasedNamingStore)6 ArrayList (java.util.ArrayList)5 Resource (org.jboss.as.controller.registry.Resource)5 ManagedReferenceFactory (org.jboss.as.naming.ManagedReferenceFactory)5 AbstractServiceListener (org.jboss.msc.service.AbstractServiceListener)5 List (java.util.List)4 DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)4