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

The following examples show how to use org.jboss.as.controller.OperationContext#getRunningMode() . 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: DeploymentOverlayContentAdd.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
byte[] addFromHash(byte[] hash, String deploymentOverlayName, final String contentName, final PathAddress address, final OperationContext context) throws OperationFailedException {
    ContentReference reference = ModelContentReference.fromModelAddress(address, hash);
    if(remoteRepository != null) {
        remoteRepository.getDeploymentFiles(reference);
    }
    if (!contentRepository.syncContent(reference)) {
        if (context.isBooting()) {
            if (context.getRunningMode() == RunningMode.ADMIN_ONLY) {
                // The deployment content is missing, which would be a fatal boot error if we were going to actually
                // install services. In ADMIN-ONLY mode we allow it to give the admin a chance to correct the problem
                ServerLogger.ROOT_LOGGER.reportAdminOnlyMissingDeploymentOverlayContent(HashUtil.bytesToHexString(hash), deploymentOverlayName, contentName);

            } else {
                throw ServerLogger.ROOT_LOGGER.noSuchDeploymentOverlayContentAtBoot(HashUtil.bytesToHexString(hash), deploymentOverlayName, contentName);
            }
        } else {
            throw ServerLogger.ROOT_LOGGER.noSuchDeploymentOverlayContent(HashUtil.bytesToHexString(hash));
        }
    }
    return hash;
}
 
Example 2
Source File: DeploymentHandlerUtil.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
public static byte[] addFromHash(ContentRepository contentRepository, ModelNode contentItemNode, String deploymentName, PathAddress address, OperationContext context) throws OperationFailedException {
    byte[] hash = contentItemNode.require(CONTENT_HASH.getName()).asBytes();
    ContentReference reference = ModelContentReference.fromModelAddress(address, hash);
    if (!contentRepository.syncContent(reference)) {
        if (context.isBooting()) {
            if (context.getRunningMode() == RunningMode.ADMIN_ONLY) {
                // The deployment content is missing, which would be a fatal boot error if we were going to actually
                // install services. In ADMIN-ONLY mode we allow it to give the admin a chance to correct the problem
                ServerLogger.ROOT_LOGGER.reportAdminOnlyMissingDeploymentContent(reference.getHexHash(), deploymentName);
            } else {
                throw ServerLogger.ROOT_LOGGER.noSuchDeploymentContentAtBoot(reference.getHexHash(), deploymentName);
            }
        } else {
            throw ServerLogger.ROOT_LOGGER.noSuchDeploymentContent(reference.getHexHash());
        }
    }
    return hash;
}
 
Example 3
Source File: ThreadPoolMetricsHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
protected void executeRuntimeStep(OperationContext context, ModelNode operation) throws OperationFailedException {
    final String attributeName = operation.require(ModelDescriptionConstants.NAME).asString();
    if (context.getRunningMode() == RunningMode.NORMAL) {
        ServiceController<?> serviceController = getService(context, operation);
        final Service<?> service = serviceController.getService();
        setResult(context, attributeName, service);
    }

    context.completeStep(OperationContext.RollbackHandler.NOOP_ROLLBACK_HANDLER);
}
 
Example 4
Source File: Transformers.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Creates a new {@code TransformationInputs} from the given operation context.
 * @param context  the operation context. Cannot be {@code null}
 */
public TransformationInputs(OperationContext context) {
    this.originalModel = context.readResourceFromRoot(PathAddress.EMPTY_ADDRESS, true);
    this.registration = context.getRootResourceRegistration();
    this.processType = context.getProcessType();
    this.runningMode = context.getRunningMode();
    this.transformerOperationAttachment = context.getAttachment(TransformerOperationAttachment.KEY);
}
 
Example 5
Source File: SecurityRealmAddHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
protected void performRuntime(OperationContext context, ModelNode operation, Resource resource) throws OperationFailedException {
    // Install another RUNTIME handler to actually install the services. This will run after the
    // RUNTIME handler for any child resources. Doing this will ensure that child resource handlers don't
    // see the installed services and can just ignore doing any RUNTIME stage work
    if(!context.isBooting() && context.getProcessType() == ProcessType.EMBEDDED_SERVER && context.getRunningMode() == RunningMode.ADMIN_ONLY) {
        context.reloadRequired();
    } else {
        context.addStep(ServiceInstallStepHandler.INSTANCE, OperationContext.Stage.RUNTIME);
    }
}
 
Example 6
Source File: LegacyConfigurationChangeResourceDefinition.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
protected boolean requiresRuntime(OperationContext context) {
    return context.getProcessType() != ProcessType.EMBEDDED_HOST_CONTROLLER
            && (context.getProcessType() != ProcessType.EMBEDDED_SERVER
            && context.getRunningMode() != RunningMode.ADMIN_ONLY);
}
 
Example 7
Source File: LegacyConfigurationChangeResourceDefinition.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
protected boolean requiresRuntime(OperationContext context) {
    return context.getProcessType() != ProcessType.EMBEDDED_HOST_CONTROLLER
            && (context.getProcessType() != ProcessType.EMBEDDED_SERVER
            && context.getRunningMode() != RunningMode.ADMIN_ONLY);
}
 
Example 8
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 9
Source File: AccessIdentityResourceDefinition.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
protected boolean requiresRuntime(OperationContext context) {
    return (context.getProcessType() != ProcessType.EMBEDDED_SERVER
            || context.getRunningMode() != RunningMode.ADMIN_ONLY)
            && (context.getProcessType() != ProcessType.EMBEDDED_HOST_CONTROLLER);
}
 
Example 10
Source File: SecurityRealmAddHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
protected void rollbackRuntime(OperationContext context, ModelNode operation, Resource resource) {
    if (!context.isBooting() && context.getProcessType() == ProcessType.EMBEDDED_SERVER && context.getRunningMode() == RunningMode.ADMIN_ONLY) {
        context.revertReloadRequired();
    }
}
 
Example 11
Source File: HttpManagementRemoveHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
protected boolean requiresRuntime(OperationContext context) {
    return context.getProcessType() != ProcessType.EMBEDDED_SERVER || context.getRunningMode() != RunningMode.ADMIN_ONLY;
}
 
Example 12
Source File: NativeManagementAddHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
protected boolean requiresRuntime(OperationContext context) {
    return super.requiresRuntime(context)
            && (context.getProcessType() != ProcessType.EMBEDDED_SERVER || context.getRunningMode() != RunningMode.ADMIN_ONLY);
}
 
Example 13
Source File: NativeRemotingManagementRemoveHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
protected boolean requiresRuntime(OperationContext context) {
    return context.getProcessType() != ProcessType.EMBEDDED_SERVER || context.getRunningMode() != RunningMode.ADMIN_ONLY;
}
 
Example 14
Source File: NativeManagementRemoveHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
protected boolean requiresRuntime(OperationContext context) {
    return context.getProcessType() != ProcessType.EMBEDDED_SERVER || context.getRunningMode() != RunningMode.ADMIN_ONLY;
}
 
Example 15
Source File: NativeRemotingManagementAddHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
protected boolean requiresRuntime(OperationContext context) {
    return context.getProcessType() != ProcessType.EMBEDDED_SERVER || context.getRunningMode() != RunningMode.ADMIN_ONLY;
}
 
Example 16
Source File: HttpManagementAddHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
protected boolean requiresRuntime(OperationContext context) {
    return super.requiresRuntime(context)
            && (context.getProcessType() != ProcessType.EMBEDDED_SERVER || context.getRunningMode() != RunningMode.ADMIN_ONLY);
}
 
Example 17
Source File: JmxAuditLogHandlerReferenceResourceDefinition.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
private static boolean isNotAdminOnlyServer(OperationContext context) {
    return !(!context.getProcessType().isHostController() && context.getRunningMode() == RunningMode.ADMIN_ONLY);
}