Search in sources :

Example 61 with PathAddress

use of org.jboss.as.controller.PathAddress in project wildfly by wildfly.

the class LogStoreTransactionDeleteHandler method execute.

public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
    MBeanServer mbs = TransactionExtension.getMBeanServer(context);
    final Resource resource = context.readResourceForUpdate(PathAddress.EMPTY_ADDRESS);
    try {
        final ObjectName on = LogStoreResource.getObjectName(resource);
        //  Invoke operation
        Object res = mbs.invoke(on, "remove", null, null);
        try {
            // validate that the MBean was removed:
            mbs.getObjectInstance(on);
            String reason = res != null ? res.toString() : LOG_DELETE_FAILURE_MESSAGE;
            throw new OperationFailedException(reason);
        } catch (InstanceNotFoundException e) {
            // success, the MBean was deleted
            final PathAddress address = PathAddress.pathAddress(operation.require(ModelDescriptionConstants.OP_ADDR));
            final PathElement element = address.getLastElement();
            logStoreResource.removeChild(element);
        }
    } catch (OperationFailedException e) {
        throw e;
    } catch (Exception e) {
        throw new OperationFailedException(e.getMessage());
    }
    context.completeStep(OperationContext.RollbackHandler.NOOP_ROLLBACK_HANDLER);
}
Also used : PathElement(org.jboss.as.controller.PathElement) InstanceNotFoundException(javax.management.InstanceNotFoundException) PathAddress(org.jboss.as.controller.PathAddress) Resource(org.jboss.as.controller.registry.Resource) OperationFailedException(org.jboss.as.controller.OperationFailedException) OperationFailedException(org.jboss.as.controller.OperationFailedException) InstanceNotFoundException(javax.management.InstanceNotFoundException) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

Example 62 with PathAddress

use of org.jboss.as.controller.PathAddress 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 63 with PathAddress

use of org.jboss.as.controller.PathAddress 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 64 with PathAddress

use of org.jboss.as.controller.PathAddress 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 65 with PathAddress

use of org.jboss.as.controller.PathAddress 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)

Aggregations

PathAddress (org.jboss.as.controller.PathAddress)473 ModelNode (org.jboss.dmr.ModelNode)345 PathElement (org.jboss.as.controller.PathElement)54 Resource (org.jboss.as.controller.registry.Resource)53 ServiceName (org.jboss.msc.service.ServiceName)53 OperationFailedException (org.jboss.as.controller.OperationFailedException)48 Test (org.junit.Test)36 ServiceTarget (org.jboss.msc.service.ServiceTarget)32 ParseUtils.unexpectedElement (org.jboss.as.controller.parsing.ParseUtils.unexpectedElement)29 OperationContext (org.jboss.as.controller.OperationContext)28 ResourceTransformationDescriptionBuilder (org.jboss.as.controller.transform.description.ResourceTransformationDescriptionBuilder)25 KernelServices (org.jboss.as.subsystem.test.KernelServices)24 ParseUtils.requireNoNamespaceAttribute (org.jboss.as.controller.parsing.ParseUtils.requireNoNamespaceAttribute)23 ParseUtils.unexpectedAttribute (org.jboss.as.controller.parsing.ParseUtils.unexpectedAttribute)23 Map (java.util.Map)22 ActiveMQServer (org.apache.activemq.artemis.core.server.ActiveMQServer)19 OperationStepHandler (org.jboss.as.controller.OperationStepHandler)19 ArrayList (java.util.ArrayList)18 TransformationContext (org.jboss.as.controller.transform.TransformationContext)17 FailedOperationTransformationConfig (org.jboss.as.model.test.FailedOperationTransformationConfig)15