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

The following examples show how to use org.jboss.as.controller.OperationContext#reloadRequired() . 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: LdapConnectionRemoveHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model) {
    PathAddress address = PathAddress.pathAddress(operation.require(OP_ADDR));
    String name = address.getLastElement().getValue();
    ServiceName svcName = LdapConnectionManagerService.ServiceUtil.createServiceName(name);
    ServiceRegistry registry = context.getServiceRegistry(true);
    ServiceController<?> controller = registry.getService(svcName);
    boolean removeIt;
    ServiceController.State state = controller == null ? null : controller.getState();
    if (state == ServiceController.State.UP) {
        removeIt = operation.hasDefined(OPERATION_HEADERS)
                && operation.get(OPERATION_HEADERS).hasDefined(ALLOW_RESOURCE_SERVICE_RESTART)
                && operation.get(OPERATION_HEADERS, ALLOW_RESOURCE_SERVICE_RESTART).asBoolean();
    } else {
        removeIt = true;
    }

    if (removeIt) {
        context.removeService(svcName);
    } else {
        context.reloadRequired();
    }
}
 
Example 2
Source File: InterfaceCriteriaWriteHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public void execute(final OperationContext context, final ModelNode operation) throws OperationFailedException {
    nameValidator.validate(operation);
    final String attributeName = operation.require(NAME).asString();
    final ModelNode newValue = operation.hasDefined(VALUE) ? operation.get(VALUE) : new ModelNode();
    final ModelNode submodel = context.readResourceForUpdate(PathAddress.EMPTY_ADDRESS).getModel();
    final AttributeDefinition attributeDefinition = ATTRIBUTES.get(attributeName);
    if (attributeDefinition != null) {
        final ModelNode syntheticOp = new ModelNode();
        syntheticOp.get(attributeName).set(newValue);
        attributeDefinition.validateAndSet(syntheticOp, submodel);
    } else {
        throw new OperationFailedException(ControllerLogger.ROOT_LOGGER.unknownAttribute(attributeName));
    }
    if (updateRuntime) {
        // Require a reload
        context.reloadRequired();
    }
    // Verify the model in a later step
    context.addStep(VERIFY_HANDLER, OperationContext.Stage.MODEL);
    OperationContext.RollbackHandler rollbackHandler = updateRuntime
            ? OperationContext.RollbackHandler.REVERT_RELOAD_REQUIRED_ROLLBACK_HANDLER
            : OperationContext.RollbackHandler.NOOP_ROLLBACK_HANDLER;
    context.completeStep(rollbackHandler);
}
 
Example 3
Source File: OutboundSocketBindingWriteHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
protected boolean applyUpdateToRuntime(OperationContext context, ModelNode operation, String attributeName,
                                       ModelNode resolvedValue, ModelNode currentValue,
                                       HandbackHolder<Boolean> handbackHolder) throws OperationFailedException {
    final String bindingName = context.getCurrentAddressValue();
    final ModelNode bindingModel = context.readResource(PathAddress.EMPTY_ADDRESS).getModel();
    final ServiceName serviceName = OUTBOUND_SOCKET_BINDING_CAPABILITY.getCapabilityServiceName(bindingName, OutboundSocketBinding.class);
    final ServiceController<?> controller = context.getServiceRegistry(true).getRequiredService(serviceName);
    final OutboundSocketBinding binding = controller.getState() == ServiceController.State.UP ? OutboundSocketBinding.class.cast(controller.getValue()) : null;
    final boolean bound = binding != null && binding.isConnected(); // FIXME see if this can be used, or remove
    if (binding == null) {
        // existing is not started, so can't "update" it. Instead reinstall the service
        handleBindingReinstall(context, bindingModel, serviceName);
        handbackHolder.setHandback(Boolean.TRUE);
    } else {
        // We don't allow runtime changes without a context reload for outbound socket bindings
        // since any services which might have already injected/depended on the outbound
        // socket binding service would have use the (now stale) attributes.
        context.reloadRequired();
    }

    return false; // we handle the reloadRequired stuff ourselves; it's clearer
}
 
Example 4
Source File: AbstractDeploymentChainStep.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
public final void execute(final OperationContext context, final ModelNode operation) {
    if (context.isBooting()) {
        execute(TARGET);
    } else {
        // WFCORE-1781 We should not be called post-boot as the DUP chain can only be modified in boot
        // Check and see if the OperationDefinition for this op declares reload/restart required and if so
        // trigger that; otherwise fail.
        ImmutableManagementResourceRegistration mrr = context.getResourceRegistration();
        OperationEntry oe = mrr.getOperationEntry(PathAddress.EMPTY_ADDRESS, operation.get(ModelDescriptionConstants.OP).asString());
        Set<OperationEntry.Flag> flags = oe == null ? Collections.emptySet() : oe.getOperationDefinition().getFlags();
        if (flags.contains(OperationEntry.Flag.RESTART_JVM)) {
            context.restartRequired();
            context.completeStep((ctx, op) -> ctx.revertRestartRequired());
        } else if (flags.contains(OperationEntry.Flag.RESTART_ALL_SERVICES)) {
            context.reloadRequired();
            context.completeStep(OperationContext.RollbackHandler.REVERT_RELOAD_REQUIRED_ROLLBACK_HANDLER);
        } else {
            // Coding error we cannot recover from
            throw new IllegalStateException();
        }
    }
}
 
Example 5
Source File: JaspiDefinition.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, ModelNode model)
        throws OperationFailedException {
    if (context.isResourceServiceRestartAllowed()) {
        removeRegistration(context);
    } else {
        context.reloadRequired();
    }
}
 
Example 6
Source File: ElytronDefinition.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, ModelNode model) throws OperationFailedException {
    if (context.isResourceServiceRestartAllowed()) {
        registerAuthConfigFactory(null);
        SecurityPropertyService securityPropertyService = uninstallSecurityPropertyService(context);
        if (securityPropertyService != null) {
            context.attach(SECURITY_PROPERTY_SERVICE_KEY, securityPropertyService);
        }
        context.removeService(ProviderRegistrationService.SERVICE_NAME);
    } else {
        context.reloadRequired();
    }
}
 
Example 7
Source File: JMXSubsystemRemove.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model) {
    if (isRemoveService(context)) {
        //Since so many things can depend on this, only remove if the user set the ALLOW_RESOURCE_SERVICE_RESTART operation header
        context.removeService(MBeanServerService.SERVICE_NAME);
    } else {
        context.reloadRequired();
    }
}
 
Example 8
Source File: SecurityRealmRemoveHandler.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, ModelNode model) throws OperationFailedException {
    super.performRuntime(context, operation, model);
    final boolean reloadRequired = ManagementUtil.isSecurityRealmReloadRequired(context, operation);
    if (reloadRequired) {
        context.reloadRequired();
    } else {
        removeServices(context, context.getCurrentAddressValue(), model);
    }
}
 
Example 9
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 10
Source File: HandlerOperations.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public final void performRuntime(final OperationContext context, final ModelNode operation, final ModelNode model, final LogContextConfiguration logContextConfiguration) throws OperationFailedException {
    final String name = context.getCurrentAddressValue();
    final HandlerConfiguration configuration = logContextConfiguration.getHandlerConfiguration(name);
    if (configuration == null) {
        throw createOperationFailure(LoggingLogger.ROOT_LOGGER.handlerConfigurationNotFound(name));
    }
    final AttributeDefinition[] attributes = getAttributes();
    if (attributes != null) {
        boolean restartRequired = false;
        boolean reloadRequired = false;
        for (AttributeDefinition attribute : attributes) {
            // Only update if the attribute is on the operation
            if (operation.has(attribute.getName())) {
                handleProperty(attribute, context, model, logContextConfiguration, configuration);
                restartRequired = restartRequired || Logging.requiresRestart(attribute.getFlags());
                reloadRequired = reloadRequired || Logging.requiresReload(attribute.getFlags());
            }
        }
        if (restartRequired) {
            context.restartRequired();
        } else if (reloadRequired) {
            context.reloadRequired();
        }
    }

    // It's important that properties are written in the correct order, reorder the properties if
    // needed before the commit.
    addOrderPropertiesStep(context, propertySorter, configuration);
}
 
Example 11
Source File: StaticDiscoveryAddHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
protected void performRuntime(final OperationContext context, final ModelNode operation, final ModelNode model) throws OperationFailedException {
    if (context.isBooting()) {
        populateHostControllerInfo(hostControllerInfo, context, operation);
    } else {
        context.reloadRequired();
    }
}
 
Example 12
Source File: DiscoveryOptionAddHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
protected void performRuntime(final OperationContext context, final ModelNode operation, final ModelNode model) throws OperationFailedException {
    if (context.isBooting()) {
        populateHostControllerInfo(hostControllerInfo, context, operation);
    } else {
        context.reloadRequired();
    }
}
 
Example 13
Source File: BindingRemoveHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model) {
    String name = context.getCurrentAddressValue();
    ServiceName svcName = SOCKET_BINDING_CAPABILITY.getCapabilityServiceName(name);
    ServiceRegistry registry = context.getServiceRegistry(true);
    ServiceController<?> controller = registry.getService(svcName);
    ServiceController.State state = controller == null ? null : controller.getState();
    if (!context.isResourceServiceRestartAllowed() || (state == ServiceController.State.UP)) {
        context.reloadRequired();
    } else {
        context.removeService(svcName);
    }
}
 
Example 14
Source File: BoundedQueueThreadPoolWriteAttributeHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
protected void applyOperation(final OperationContext context, ModelNode model, String attributeName,
                              ServiceController<?> service, boolean forRollback) throws OperationFailedException {

    final BoundedQueueThreadPoolService pool =  (BoundedQueueThreadPoolService) service.getService();

    if (PoolAttributeDefinitions.KEEPALIVE_TIME.getName().equals(attributeName)) {
        TimeUnit defaultUnit = pool.getKeepAliveUnit();
        final TimeSpec spec = getTimeSpec(context, model, defaultUnit);
        pool.setKeepAlive(spec);
    } else if(PoolAttributeDefinitions.MAX_THREADS.getName().equals(attributeName)) {
        pool.setMaxThreads(PoolAttributeDefinitions.MAX_THREADS.resolveModelAttribute(context, model).asInt());
    } else if(PoolAttributeDefinitions.CORE_THREADS.getName().equals(attributeName)) {
        int coreCount;
        ModelNode coreNode = PoolAttributeDefinitions.CORE_THREADS.resolveModelAttribute(context, model);
        if (coreNode.isDefined()) {
            coreCount = coreNode.asInt();
        } else {
            // Core is same as max
            coreCount = PoolAttributeDefinitions.MAX_THREADS.resolveModelAttribute(context, model).asInt();
        }
        pool.setCoreThreads(coreCount);
    } else if(PoolAttributeDefinitions.QUEUE_LENGTH.getName().equals(attributeName)) {
        if (forRollback) {
            context.revertReloadRequired();
        } else {
            context.reloadRequired();
        }
    } else if (PoolAttributeDefinitions.ALLOW_CORE_TIMEOUT.getName().equals(attributeName)) {
        pool.setAllowCoreTimeout(PoolAttributeDefinitions.ALLOW_CORE_TIMEOUT.resolveModelAttribute(context, model).asBoolean());
    } else if (!forRollback) {
        // Programming bug. Throw a RuntimeException, not OFE, as this is not a client error
        throw ThreadsLogger.ROOT_LOGGER.unsupportedBoundedQueueThreadPoolAttribute(attributeName);
    }
}