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());
}
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();
}
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();
}
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;
}
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();
}
}
Aggregations