Java Code Examples for org.jboss.as.controller.OperationContext#getCapabilityServiceTarget()

The following examples show how to use org.jboss.as.controller.OperationContext#getCapabilityServiceTarget() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LocalDestinationOutboundSocketBindingAddHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
static void installOutboundSocketBindingService(final OperationContext context, final ModelNode model) throws OperationFailedException {
    final CapabilityServiceTarget serviceTarget = context.getCapabilityServiceTarget();

    // socket name
    final String outboundSocketName = context.getCurrentAddressValue();
    final String socketBindingRef = LocalDestinationOutboundSocketBindingResourceDefinition.SOCKET_BINDING_REF.resolveModelAttribute(context, model).asString();
    // (optional) source interface
    final String sourceInterfaceName = OutboundSocketBindingResourceDefinition.SOURCE_INTERFACE.resolveModelAttribute(context, model).asStringOrNull();
    // (optional) source port
    final Integer sourcePort = OutboundSocketBindingResourceDefinition.SOURCE_PORT.resolveModelAttribute(context, model).asIntOrNull();
    // (optional but defaulted) fixedSourcePort
    final boolean fixedSourcePort = OutboundSocketBindingResourceDefinition.FIXED_SOURCE_PORT.resolveModelAttribute(context, model).asBoolean();

    // create the service
    final CapabilityServiceBuilder<?> builder = serviceTarget.addCapability(OUTBOUND_SOCKET_BINDING_CAPABILITY);
    final Consumer<OutboundSocketBinding> osbConsumer = builder.provides(OUTBOUND_SOCKET_BINDING_CAPABILITY);
    final Supplier<SocketBindingManager> sbmSupplier = builder.requiresCapability("org.wildfly.management.socket-binding-manager", SocketBindingManager.class);
    final Supplier<NetworkInterfaceBinding> nibSupplier = sourceInterfaceName != null ? builder.requiresCapability("org.wildfly.network.interface", NetworkInterfaceBinding.class, sourceInterfaceName) : null;
    final Supplier<SocketBinding> sbSupplier = builder.requiresCapability(SOCKET_BINDING_CAPABILITY_NAME, SocketBinding.class, socketBindingRef);
    builder.setInstance(new LocalDestinationOutboundSocketBindingService(osbConsumer, sbmSupplier, nibSupplier, sbSupplier, outboundSocketName, sourcePort, fixedSourcePort));
    builder.setInitialMode(ServiceController.Mode.ON_DEMAND);
    builder.addAliases(OutboundSocketBinding.OUTBOUND_SOCKET_BINDING_BASE_SERVICE_NAME.append(outboundSocketName));
    builder.install();
}
 
Example 2
Source File: RemoteDestinationOutboundSocketBindingAddHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
static void installOutboundSocketBindingService(final OperationContext context, final ModelNode model) throws OperationFailedException {
    final CapabilityServiceTarget serviceTarget = context.getCapabilityServiceTarget();

    // socket name
    final String outboundSocketName = context.getCurrentAddressValue();
    // destination host
    final String destinationHost = RemoteDestinationOutboundSocketBindingResourceDefinition.HOST.resolveModelAttribute(context, model).asString();
    // port
    final int destinationPort = RemoteDestinationOutboundSocketBindingResourceDefinition.PORT.resolveModelAttribute(context, model).asInt();
    // (optional) source interface
    final String sourceInterfaceName = OutboundSocketBindingResourceDefinition.SOURCE_INTERFACE.resolveModelAttribute(context, model).asStringOrNull();
    // (optional) source port
    final Integer sourcePort = OutboundSocketBindingResourceDefinition.SOURCE_PORT.resolveModelAttribute(context, model).asIntOrNull();
    // (optional but defaulted) fixedSourcePort
    final boolean fixedSourcePort = OutboundSocketBindingResourceDefinition.FIXED_SOURCE_PORT.resolveModelAttribute(context, model).asBoolean();

    // create the service
    final CapabilityServiceBuilder<?> builder = serviceTarget.addCapability(OUTBOUND_SOCKET_BINDING_CAPABILITY);
    final Consumer<OutboundSocketBinding> osbConsumer = builder.provides(OUTBOUND_SOCKET_BINDING_CAPABILITY);
    final Supplier<SocketBindingManager> sbmSupplier = builder.requiresCapability("org.wildfly.management.socket-binding-manager", SocketBindingManager.class);
    final Supplier<NetworkInterfaceBinding> nibSupplier = sourceInterfaceName != null ? builder.requiresCapability("org.wildfly.network.interface", NetworkInterfaceBinding.class, sourceInterfaceName) : null;
    builder.setInstance(new RemoteDestinationOutboundSocketBindingService(osbConsumer, sbmSupplier, nibSupplier, outboundSocketName, destinationHost, destinationPort, sourcePort, fixedSourcePort));
    builder.setInitialMode(ServiceController.Mode.ON_DEMAND);
    builder.addAliases(OutboundSocketBinding.OUTBOUND_SOCKET_BINDING_BASE_SERVICE_NAME.append(outboundSocketName));
    builder.install();
}
 
Example 3
Source File: BindingAddHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
static void installBindingService(OperationContext context, ModelNode config, String name)
        throws UnknownHostException, OperationFailedException {
    final CapabilityServiceTarget serviceTarget = context.getCapabilityServiceTarget();

    final ModelNode intfNode = AbstractSocketBindingResourceDefinition.INTERFACE.resolveModelAttribute(context, config);
    final String intf = intfNode.isDefined() ? intfNode.asString() : null;
    final int port = AbstractSocketBindingResourceDefinition.PORT.resolveModelAttribute(context, config).asInt();
    final boolean fixedPort = AbstractSocketBindingResourceDefinition.FIXED_PORT.resolveModelAttribute(context, config).asBoolean();
    final ModelNode mcastNode = AbstractSocketBindingResourceDefinition.MULTICAST_ADDRESS.resolveModelAttribute(context, config);
    final String mcastAddr = mcastNode.isDefined() ? mcastNode.asString() : null;
    final int mcastPort = AbstractSocketBindingResourceDefinition.MULTICAST_PORT.resolveModelAttribute(context, config).asInt(0);
    final InetAddress mcastInet = mcastAddr == null ? null : InetAddress.getByName(mcastAddr);
    final ModelNode mappingsNode = config.get(CLIENT_MAPPINGS);
    final List<ClientMapping> clientMappings = mappingsNode.isDefined() ? parseClientMappings(context, mappingsNode) : null;

    final CapabilityServiceBuilder<?> builder = serviceTarget.addCapability(SOCKET_BINDING_CAPABILITY);
    final Consumer<SocketBinding> sbConsumer = builder.provides(SOCKET_BINDING_CAPABILITY);
    final Supplier<NetworkInterfaceBinding> ibSupplier = intf != null ? builder.requiresCapability("org.wildfly.network.interface", NetworkInterfaceBinding.class, intf) : null;
    final Supplier<SocketBindingManager> sbSupplier = builder.requiresCapability("org.wildfly.management.socket-binding-manager", SocketBindingManager.class);
    final SocketBindingService service = new SocketBindingService(sbConsumer, ibSupplier, sbSupplier, name, port, fixedPort, mcastInet, mcastPort, clientMappings);
    builder.setInstance(service);
    builder.addAliases(SocketBinding.JBOSS_BINDING_NAME.append(name));
    builder.setInitialMode(Mode.ON_DEMAND);
    builder.install();
}
 
Example 4
Source File: HttpManagementAddHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
protected List<ServiceName> installServices(OperationContext context, HttpInterfaceCommonPolicy commonPolicy, ModelNode model) throws OperationFailedException {
    populateHostControllerInfo(hostControllerInfo, context, model);

    CapabilityServiceTarget serviceTarget = context.getCapabilityServiceTarget();
    boolean onDemand = context.isBooting();
    String interfaceName = hostControllerInfo.getHttpManagementInterface();
    int port = hostControllerInfo.getHttpManagementPort();
    String secureInterfaceName = hostControllerInfo.getHttpManagementSecureInterface();
    int securePort = hostControllerInfo.getHttpManagementSecurePort();

    ROOT_LOGGER.creatingHttpManagementService(interfaceName, port, securePort);

    boolean consoleEnabled = HttpManagementResourceDefinition.CONSOLE_ENABLED.resolveModelAttribute(context, model).asBoolean();
    ConsoleMode consoleMode = ConsoleMode.CONSOLE;

    if (consoleEnabled) {
        if (context.getRunningMode() == RunningMode.ADMIN_ONLY) {
            consoleMode = ConsoleMode.ADMIN_ONLY;
        } else if (!hostControllerInfo.isMasterDomainController()) {
            consoleMode = ConsoleMode.SLAVE_HC;
        }
    } else {
        consoleMode = ConsoleMode.NO_CONSOLE;
    }

    NativeManagementServices.installManagementWorkerService(serviceTarget, context.getServiceRegistry(false));

    // Track active requests
    final ServiceName requestProcessorName = UndertowHttpManagementService.SERVICE_NAME.append("requests");
    HttpManagementRequestsService.installService(requestProcessorName, serviceTarget);

    final String httpAuthenticationFactory = commonPolicy.getHttpAuthenticationFactory();
    final String securityRealm = commonPolicy.getSecurityRealm();
    final String sslContext = commonPolicy.getSSLContext();
    if (httpAuthenticationFactory == null && securityRealm == null) {
        ROOT_LOGGER.httpManagementInterfaceIsUnsecured();
    }

    final CapabilityServiceBuilder<?> builder = serviceTarget.addCapability(EXTENSIBLE_HTTP_MANAGEMENT_CAPABILITY);
    final Consumer<HttpManagement> hmConsumer = builder.provides(EXTENSIBLE_HTTP_MANAGEMENT_CAPABILITY);
    final Supplier<ListenerRegistry> lrSupplier = builder.requires(RemotingServices.HTTP_LISTENER_REGISTRY);
    final Supplier<ModelController> mcSupplier = builder.requires(DomainModelControllerService.SERVICE_NAME);
    final Supplier<NetworkInterfaceBinding> ibSupplier = builder.requiresCapability("org.wildfly.network.interface", NetworkInterfaceBinding.class, interfaceName);
    final Supplier<NetworkInterfaceBinding> sibSupplier = builder.requiresCapability("org.wildfly.network.interface", NetworkInterfaceBinding.class, secureInterfaceName);
    final Supplier<ProcessStateNotifier> cpsnSupplier = builder.requiresCapability("org.wildfly.management.process-state-notifier", ProcessStateNotifier.class);
    final Supplier<ConsoleAvailability> caSupplier = builder.requiresCapability("org.wildfly.management.console-availability", ConsoleAvailability.class);
    final Supplier<ManagementHttpRequestProcessor> rpSupplier = builder.requires(requestProcessorName);
    final Supplier<XnioWorker> xwSupplier = builder.requires(ManagementWorkerService.SERVICE_NAME);
    final Supplier<Executor> eSupplier = builder.requires(ExternalManagementRequestExecutor.SERVICE_NAME);
    final Supplier<HttpAuthenticationFactory> hafSupplier = httpAuthenticationFactory != null ? builder.requiresCapability(HTTP_AUTHENTICATION_FACTORY_CAPABILITY, HttpAuthenticationFactory.class, httpAuthenticationFactory) : null;
    final Supplier<SecurityRealm> srSupplier = securityRealm != null ? SecurityRealm.ServiceUtil.requires(builder, securityRealm) : null;
    final Supplier<SSLContext> scSupplier = sslContext != null ? builder.requiresCapability(SSL_CONTEXT_CAPABILITY, SSLContext.class, sslContext) : null;
    final UndertowHttpManagementService service = new UndertowHttpManagementService(hmConsumer, lrSupplier, mcSupplier, null, null, null, ibSupplier, sibSupplier,
            cpsnSupplier, rpSupplier, xwSupplier, eSupplier, hafSupplier, srSupplier, scSupplier, port, securePort, commonPolicy.getAllowedOrigins(), consoleMode,
            environment.getProductConfig().getConsoleSlot(), commonPolicy.getConstantHeaders(), caSupplier);
    builder.setInstance(service);
    builder.setInitialMode(onDemand ? ServiceController.Mode.ON_DEMAND : ServiceController.Mode.ACTIVE).install();

    // Add service preventing the server from shutting down
    final ServiceName shutdownName = UndertowHttpManagementService.SERVICE_NAME.append("shutdown");
    final ServiceBuilder<?> sb = serviceTarget.addService(shutdownName);
    final Supplier<Executor> executorSupplier = sb.requires(HostControllerService.HC_EXECUTOR_SERVICE_NAME);
    final Supplier<ManagementHttpRequestProcessor> processorSupplier = sb.requires(requestProcessorName);
    final Supplier<ManagementChannelRegistryService> registrySupplier = sb.requires(ManagementChannelRegistryService.SERVICE_NAME);
    sb.requires(UndertowHttpManagementService.SERVICE_NAME);
    sb.setInstance(new HttpShutdownService(executorSupplier, processorSupplier, registrySupplier));
    sb.install();

    if (commonPolicy.isHttpUpgradeEnabled()) {
        NativeManagementServices.installRemotingServicesIfNotInstalled(serviceTarget, hostControllerInfo.getLocalHostName(), context.getServiceRegistry(true), onDemand);
        final String httpConnectorName;
        if (port > -1 || securePort < 0) {
            httpConnectorName = ManagementRemotingServices.HTTP_CONNECTOR;
        } else {
            httpConnectorName = ManagementRemotingServices.HTTPS_CONNECTOR;
        }

        RemotingHttpUpgradeService.installServices(context, ManagementRemotingServices.HTTP_CONNECTOR, httpConnectorName,
                ManagementRemotingServices.MANAGEMENT_ENDPOINT, commonPolicy.getConnectorOptions(), securityRealm, commonPolicy.getSaslAuthenticationFactory());
        return Arrays.asList(UndertowHttpManagementService.SERVICE_NAME, HTTP_UPGRADE_REGISTRY.append(httpConnectorName));
    }
    return Collections.singletonList(UndertowHttpManagementService.SERVICE_NAME);
}
 
Example 5
Source File: HttpManagementAddHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
protected List<ServiceName> installServices(OperationContext context, HttpInterfaceCommonPolicy commonPolicy, ModelNode model) throws OperationFailedException {
    final CapabilityServiceTarget serviceTarget = context.getCapabilityServiceTarget();

    // Socket-binding reference based config
    final String socketBindingName = SOCKET_BINDING.resolveModelAttribute(context, model).asStringOrNull();
    final String secureSocketBindingName = SECURE_SOCKET_BINDING.resolveModelAttribute(context, model).asStringOrNull();

    // Log the config
    if (socketBindingName != null) {
        if (secureSocketBindingName != null) {
            ServerLogger.ROOT_LOGGER.creatingHttpManagementServiceOnSocketAndSecureSocket(socketBindingName,
                    secureSocketBindingName);
        } else {
            ServerLogger.ROOT_LOGGER.creatingHttpManagementServiceOnSocket(socketBindingName);
        }
    } else if (secureSocketBindingName != null) {
        ServerLogger.ROOT_LOGGER.creatingHttpManagementServiceOnSecureSocket(secureSocketBindingName);
    }

    ConsoleMode consoleMode = consoleMode(commonPolicy.isConsoleEnabled(), context.getRunningMode() == RunningMode.ADMIN_ONLY);

    // Track active requests
    final ServiceName requestProcessorName = UndertowHttpManagementService.SERVICE_NAME.append("requests");
    HttpManagementRequestsService.installService(requestProcessorName, serviceTarget);

    NativeManagementServices.installManagementWorkerService(serviceTarget, context.getServiceRegistry(false));

    final String httpAuthenticationFactory = commonPolicy.getHttpAuthenticationFactory();
    final String securityRealm = commonPolicy.getSecurityRealm();
    final String sslContext = commonPolicy.getSSLContext();
    if (httpAuthenticationFactory == null && securityRealm == null) {
        ServerLogger.ROOT_LOGGER.httpManagementInterfaceIsUnsecured();
    }

    ServerEnvironment environment = (ServerEnvironment) context.getServiceRegistry(false).getRequiredService(ServerEnvironmentService.SERVICE_NAME).getValue();
    final CapabilityServiceBuilder<?> builder = serviceTarget.addCapability(EXTENSIBLE_HTTP_MANAGEMENT_CAPABILITY);
    final Consumer<HttpManagement> hmConsumer = builder.provides(EXTENSIBLE_HTTP_MANAGEMENT_CAPABILITY);
    final Supplier<ListenerRegistry> lrSupplier = builder.requires(RemotingServices.HTTP_LISTENER_REGISTRY);
    final Supplier<ModelController> mcSupplier = builder.requires(Services.JBOSS_SERVER_CONTROLLER);
    final Supplier<SocketBinding> sbSupplier = socketBindingName != null ? builder.requiresCapability(SOCKET_BINDING_CAPABILITY_NAME, SocketBinding.class, socketBindingName) : null;
    final Supplier<SocketBinding> ssbSupplier = secureSocketBindingName != null ? builder.requiresCapability(SOCKET_BINDING_CAPABILITY_NAME, SocketBinding.class, secureSocketBindingName) : null;
    final Supplier<SocketBindingManager> sbmSupplier = builder.requiresCapability("org.wildfly.management.socket-binding-manager", SocketBindingManager.class);
    final Supplier<ProcessStateNotifier> cpsnSupplier = builder.requiresCapability("org.wildfly.management.process-state-notifier", ProcessStateNotifier.class);
    final Supplier<ConsoleAvailability> caSupplier = builder.requiresCapability("org.wildfly.management.console-availability", ConsoleAvailability.class);
    final Supplier<ManagementHttpRequestProcessor> rpSupplier = builder.requires(requestProcessorName);
    final Supplier<XnioWorker> xwSupplier = builder.requires(ManagementWorkerService.SERVICE_NAME);
    final Supplier<Executor> eSupplier = builder.requires(ExternalManagementRequestExecutor.SERVICE_NAME);
    final Supplier<HttpAuthenticationFactory> hafSupplier = httpAuthenticationFactory != null ? builder.requiresCapability(HTTP_AUTHENTICATION_FACTORY_CAPABILITY, HttpAuthenticationFactory.class, httpAuthenticationFactory) : null;
    final Supplier<SecurityRealm> srSupplier = securityRealm != null ? SecurityRealm.ServiceUtil.requires(builder, securityRealm) : null;
    final Supplier<SSLContext> scSupplier = sslContext != null ? builder.requiresCapability(SSL_CONTEXT_CAPABILITY, SSLContext.class, sslContext) : null;
    final UndertowHttpManagementService undertowService = new UndertowHttpManagementService(hmConsumer, lrSupplier, mcSupplier, sbSupplier, ssbSupplier, sbmSupplier,
            null, null, cpsnSupplier, rpSupplier, xwSupplier, eSupplier, hafSupplier, srSupplier, scSupplier, null, null, commonPolicy.getAllowedOrigins(), consoleMode,
            environment.getProductConfig().getConsoleSlot(), commonPolicy.getConstantHeaders(), caSupplier);
    builder.setInstance(undertowService);
    builder.install();

    // Add service preventing the server from shutting down
    final ServiceName shutdownName = UndertowHttpManagementService.SERVICE_NAME.append("shutdown");
    final ServiceBuilder<?> sb = serviceTarget.addService(shutdownName);
    final Supplier<Executor> executorSupplier = sb.requires(Services.JBOSS_SERVER_EXECUTOR);
    final Supplier<ManagementHttpRequestProcessor> processorSupplier = sb.requires(requestProcessorName);
    final Supplier<ManagementChannelRegistryService> registrySupplier = sb.requires(ManagementChannelRegistryService.SERVICE_NAME);
    sb.requires(UndertowHttpManagementService.SERVICE_NAME);
    sb.setInstance(new HttpShutdownService(executorSupplier, processorSupplier, registrySupplier));
    sb.install();

    if(commonPolicy.isHttpUpgradeEnabled()) {
        final String hostName = WildFlySecurityManager.getPropertyPrivileged(ServerEnvironment.NODE_NAME, null);

        NativeManagementServices.installRemotingServicesIfNotInstalled(serviceTarget, hostName, context.getServiceRegistry(false));
        final String httpConnectorName;
        if (socketBindingName != null || (secureSocketBindingName == null)) {
            httpConnectorName = ManagementRemotingServices.HTTP_CONNECTOR;
        } else {
            httpConnectorName = ManagementRemotingServices.HTTPS_CONNECTOR;
        }

        RemotingHttpUpgradeService.installServices(context, ManagementRemotingServices.HTTP_CONNECTOR, httpConnectorName,
                ManagementRemotingServices.MANAGEMENT_ENDPOINT, commonPolicy.getConnectorOptions(), securityRealm, commonPolicy.getSaslAuthenticationFactory());

        return Arrays.asList(UndertowHttpManagementService.SERVICE_NAME, HTTP_UPGRADE_REGISTRY.append(httpConnectorName));
    }
    return Collections.singletonList(UndertowHttpManagementService.SERVICE_NAME);
}