Search in sources :

Example 41 with ServiceName

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

the class UndertowService method getFilterRefServiceName.

public static ServiceName getFilterRefServiceName(final PathAddress address, String name) {
    final PathAddress oneUp = address.subAddress(0, address.size() - 1);
    final PathAddress twoUp = oneUp.subAddress(0, oneUp.size() - 1);
    final PathAddress threeUp = twoUp.subAddress(0, twoUp.size() - 1);
    ServiceName serviceName;
    if (address.getLastElement().getKey().equals(Constants.FILTER_REF)) {
        if (oneUp.getLastElement().getKey().equals(Constants.HOST)) {
            //adding reference
            String host = oneUp.getLastElement().getValue();
            String server = twoUp.getLastElement().getValue();
            serviceName = UndertowService.filterRefName(server, host, name);
        } else {
            String location = oneUp.getLastElement().getValue();
            String host = twoUp.getLastElement().getValue();
            String server = threeUp.getLastElement().getValue();
            serviceName = UndertowService.filterRefName(server, host, location, name);
        }
    } else if (address.getLastElement().getKey().equals(Constants.HOST)) {
        String host = address.getLastElement().getValue();
        String server = oneUp.getLastElement().getValue();
        serviceName = UndertowService.filterRefName(server, host, name);
    } else {
        String location = address.getLastElement().getValue();
        String host = oneUp.getLastElement().getValue();
        String server = twoUp.getLastElement().getValue();
        serviceName = UndertowService.filterRefName(server, host, location, name);
    }
    return serviceName;
}
Also used : ServiceName(org.jboss.msc.service.ServiceName) PathAddress(org.jboss.as.controller.PathAddress)

Example 42 with ServiceName

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

the class LocationAdd method performRuntime.

@Override
protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException {
    final PathAddress address = PathAddress.pathAddress(operation.get(OP_ADDR));
    final PathAddress hostAddress = address.subAddress(0, address.size() - 1);
    final PathAddress serverAddress = hostAddress.subAddress(0, hostAddress.size() - 1);
    final String name = address.getLastElement().getValue();
    final String handler = LocationDefinition.HANDLER.resolveModelAttribute(context, model).asString();
    final LocationService service = new LocationService(name);
    final String serverName = serverAddress.getLastElement().getValue();
    final String hostName = hostAddress.getLastElement().getValue();
    final ServiceName hostServiceName = UndertowService.virtualHostName(serverName, hostName);
    final ServiceName serviceName = UndertowService.locationServiceName(serverName, hostName, name);
    final ServiceBuilder<LocationService> builder = context.getServiceTarget().addService(serviceName, service).addDependency(hostServiceName, Host.class, service.getHost()).addDependency(UndertowService.HANDLER.append(handler), HttpHandler.class, service.getHttpHandler());
    builder.setInitialMode(ServiceController.Mode.ACTIVE).install();
}
Also used : ServiceName(org.jboss.msc.service.ServiceName) PathAddress(org.jboss.as.controller.PathAddress)

Example 43 with ServiceName

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

the class HostAdd method performRuntime.

@Override
protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException {
    final PathAddress address = context.getCurrentAddress();
    final PathAddress serverAddress = address.getParent();
    final PathAddress subsystemAddress = serverAddress.getParent();
    final ModelNode subsystemModel = Resource.Tools.readModel(context.readResourceFromRoot(subsystemAddress, false), 0);
    final ModelNode serverModel = Resource.Tools.readModel(context.readResourceFromRoot(serverAddress, false), 0);
    final String name = address.getLastElement().getValue();
    final List<String> aliases = HostDefinition.ALIAS.unwrap(context, model);
    final String defaultWebModule = HostDefinition.DEFAULT_WEB_MODULE.resolveModelAttribute(context, model).asString();
    final String defaultServerName = UndertowRootDefinition.DEFAULT_SERVER.resolveModelAttribute(context, subsystemModel).asString();
    final String defaultHostName = ServerDefinition.DEFAULT_HOST.resolveModelAttribute(context, serverModel).asString();
    final String serverName = serverAddress.getLastElement().getValue();
    final boolean isDefaultHost = defaultServerName.equals(serverName) && name.equals(defaultHostName);
    final int defaultResponseCode = HostDefinition.DEFAULT_RESPONSE_CODE.resolveModelAttribute(context, model).asInt();
    final boolean enableConsoleRedirect = !HostDefinition.DISABLE_CONSOLE_REDIRECT.resolveModelAttribute(context, model).asBoolean();
    DefaultDeploymentMappingProvider.instance().addMapping(defaultWebModule, serverName, name);
    final ServiceName virtualHostServiceName = UndertowService.virtualHostName(serverName, name);
    final Host service = new Host(name, aliases == null ? new LinkedList<>() : aliases, defaultWebModule, defaultResponseCode);
    final ServiceBuilder<Host> builder = context.getServiceTarget().addService(virtualHostServiceName, service).addDependency(UndertowService.SERVER.append(serverName), Server.class, service.getServerInjection()).addDependency(UndertowService.UNDERTOW, UndertowService.class, service.getUndertowService()).addDependency(ControlledProcessStateService.SERVICE_NAME, ControlledProcessStateService.class, service.getControlledProcessStateServiceInjectedValue());
    builder.setInitialMode(Mode.ON_DEMAND);
    if (isDefaultHost) {
        addCommonHost(context, name, aliases, serverName, virtualHostServiceName);
        //add alias for default host of default server service
        builder.addAliases(UndertowService.DEFAULT_HOST);
    }
    builder.install();
    if (enableConsoleRedirect) {
        // Setup the web console redirect
        final ServiceName consoleRedirectName = UndertowService.consoleRedirectServiceName(serverName, name);
        // A standalone server is the only process type with a console redirect
        if (context.getProcessType() == ProcessType.STANDALONE_SERVER) {
            final ConsoleRedirectService redirectService = new ConsoleRedirectService();
            final ServiceBuilder<ConsoleRedirectService> redirectBuilder = context.getServiceTarget().addService(consoleRedirectName, redirectService).addDependency(UndertowHttpManagementService.SERVICE_NAME, HttpManagement.class, redirectService.getHttpManagementInjector()).addDependency(virtualHostServiceName, Host.class, redirectService.getHostInjector()).setInitialMode(Mode.PASSIVE);
            redirectBuilder.install();
        } else {
            // Other process types don't have a console, not depending on the UndertowHttpManagementService should
            // result in a null dependency in the service and redirect accordingly
            final ConsoleRedirectService redirectService = new ConsoleRedirectService();
            final ServiceBuilder<ConsoleRedirectService> redirectBuilder = context.getServiceTarget().addService(consoleRedirectName, redirectService).addDependency(virtualHostServiceName, Host.class, redirectService.getHostInjector()).setInitialMode(Mode.PASSIVE);
            redirectBuilder.install();
        }
    }
}
Also used : WebHost(org.jboss.as.web.host.WebHost) LinkedList(java.util.LinkedList) ServiceName(org.jboss.msc.service.ServiceName) PathAddress(org.jboss.as.controller.PathAddress) ModelNode(org.jboss.dmr.ModelNode)

Example 44 with ServiceName

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

the class HostRemove method performRuntime.

@Override
protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException {
    final PathAddress address = context.getCurrentAddress();
    final PathAddress parent = address.getParent();
    final String name = address.getLastElement().getValue();
    final String serverName = parent.getLastElement().getValue();
    final ServiceName virtualHostServiceName = UndertowService.virtualHostName(serverName, name);
    context.removeService(virtualHostServiceName);
    final ServiceName consoleRedirectName = UndertowService.consoleRedirectServiceName(serverName, name);
    context.removeService(consoleRedirectName);
    final ServiceName commonHostName = WebHost.SERVICE_NAME.append(name);
    context.removeService(commonHostName);
    final String defaultWebModule = HostDefinition.DEFAULT_WEB_MODULE.resolveModelAttribute(context, model).asString();
    DefaultDeploymentMappingProvider.instance().removeMapping(defaultWebModule);
}
Also used : ServiceName(org.jboss.msc.service.ServiceName) PathAddress(org.jboss.as.controller.PathAddress)

Example 45 with ServiceName

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

the class AccessLogAdd method performRuntime.

@Override
protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException {
    final PathAddress address = context.getCurrentAddress();
    final PathAddress hostAddress = address.getParent();
    final PathAddress serverAddress = hostAddress.getParent();
    final String worker = AccessLogDefinition.WORKER.resolveModelAttribute(context, model).asString();
    final String pattern = AccessLogDefinition.PATTERN.resolveModelAttribute(context, model).asString();
    final String directory = AccessLogDefinition.DIRECTORY.resolveModelAttribute(context, model).asString();
    final String filePrefix = AccessLogDefinition.PREFIX.resolveModelAttribute(context, model).asString();
    final String fileSuffix = AccessLogDefinition.SUFFIX.resolveModelAttribute(context, model).asString();
    final boolean useServerLog = AccessLogDefinition.USE_SERVER_LOG.resolveModelAttribute(context, model).asBoolean();
    final boolean rotate = AccessLogDefinition.ROTATE.resolveModelAttribute(context, model).asBoolean();
    final boolean extended = AccessLogDefinition.EXTENDED.resolveModelAttribute(context, model).asBoolean();
    final ModelNode relativeToNode = AccessLogDefinition.RELATIVE_TO.resolveModelAttribute(context, model);
    final String relativeTo = relativeToNode.isDefined() ? relativeToNode.asString() : null;
    Predicate predicate = null;
    ModelNode predicateNode = AccessLogDefinition.PREDICATE.resolveModelAttribute(context, model);
    if (predicateNode.isDefined()) {
        predicate = Predicates.parse(predicateNode.asString(), getClass().getClassLoader());
    }
    final AccessLogService service;
    if (useServerLog) {
        service = new AccessLogService(pattern, extended, predicate);
    } else {
        service = new AccessLogService(pattern, directory, relativeTo, filePrefix, fileSuffix, rotate, extended, predicate);
    }
    final String serverName = serverAddress.getLastElement().getValue();
    final String hostName = hostAddress.getLastElement().getValue();
    final ServiceName serviceName = UndertowService.accessLogServiceName(serverName, hostName);
    final ServiceBuilder<AccessLogService> builder = context.getServiceTarget().addService(serviceName, service).addDependency(IOServices.WORKER.append(worker), XnioWorker.class, service.getWorker()).addDependency(PathManagerService.SERVICE_NAME, PathManager.class, service.getPathManager()).addDependency(UndertowService.virtualHostName(serverName, hostName), Host.class, service.getHost());
    builder.setInitialMode(ServiceController.Mode.ACTIVE).install();
}
Also used : PathManager(org.jboss.as.controller.services.path.PathManager) ServiceName(org.jboss.msc.service.ServiceName) PathAddress(org.jboss.as.controller.PathAddress) ModelNode(org.jboss.dmr.ModelNode) Predicate(io.undertow.predicate.Predicate)

Aggregations

ServiceName (org.jboss.msc.service.ServiceName)289 ServiceTarget (org.jboss.msc.service.ServiceTarget)56 PathAddress (org.jboss.as.controller.PathAddress)54 ModelNode (org.jboss.dmr.ModelNode)48 DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)44 ServiceRegistry (org.jboss.msc.service.ServiceRegistry)40 OperationFailedException (org.jboss.as.controller.OperationFailedException)33 Module (org.jboss.modules.Module)23 ServiceController (org.jboss.msc.service.ServiceController)23 ActiveMQServer (org.apache.activemq.artemis.core.server.ActiveMQServer)22 EEModuleDescription (org.jboss.as.ee.component.EEModuleDescription)22 ComponentDescription (org.jboss.as.ee.component.ComponentDescription)19 BinderService (org.jboss.as.naming.service.BinderService)18 HashSet (java.util.HashSet)17 ContextNames (org.jboss.as.naming.deployment.ContextNames)17 ServiceBuilder (org.jboss.msc.service.ServiceBuilder)15 HashMap (java.util.HashMap)14 DeploymentUnitProcessingException (org.jboss.as.server.deployment.DeploymentUnitProcessingException)14 ArrayList (java.util.ArrayList)13 OperationContext (org.jboss.as.controller.OperationContext)12