@Override
    public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
        final boolean restart = RESTART.validateOperation(operation).asBoolean(false);
        final Resource hostResource = context.readResource(PathAddress.EMPTY_ADDRESS);
        final int suspendTimeout = SUSPEND_TIMEOUT.resolveModelAttribute(context, operation).asInt();
        final BlockingTimeout blockingTimeout = BlockingTimeout.Factory.getProxyBlockingTimeout(context);

        context.addStep(new OperationStepHandler() {
            @Override
            public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
                // WFLY-2741 -- DO NOT call context.getServiceRegistry(true) as that will trigger blocking for
                // service container stability and one use case for this op is to recover from a
                // messed up service container from a previous op. Instead just ask for authorization.
                // Note that we already have the exclusive lock, so we are just skipping waiting for stability.
                // If another op that is a step in a composite step with this op needs to modify the container
                // it will have to wait for container stability, so skipping this only matters for the case
                // where this step is the only runtime change.
//                context.getServiceRegistry(true);
                AuthorizationResult authorizationResult = context.authorize(operation, EnumSet.of(Action.ActionEffect.WRITE_RUNTIME));
                if (authorizationResult.getDecision() == AuthorizationResult.Decision.DENY) {
                    throw ControllerLogger.ACCESS_LOGGER.unauthorized(operation.get(OP).asString(),
                            PathAddress.pathAddress(operation.get(OP_ADDR)), authorizationResult.getExplanation());
                }


                Set<String> servers = getServersForHost(hostResource);
                final List<ModelNode> errorResponses = serverInventory.suspendServers(servers, suspendTimeout, blockingTimeout);
                if (!errorResponses.isEmpty()) {
                    context.getFailureDescription().set(errorResponses);
                }

                context.completeStep(new OperationContext.ResultHandler() {
                    @Override
                    public void handleResult(OperationContext.ResultAction resultAction, OperationContext context, ModelNode operation) {
                        if(resultAction == OperationContext.ResultAction.KEEP) {
                            SystemExiter.logBeforeExit(new SystemExiter.ExitLogger() {
                                @Override
                                public void logExit() {
                                    HostControllerLogger.ROOT_LOGGER.shuttingDownInResponseToManagementRequest(getOperationName(operation));
                                }
                            });

                            if (restart) {
                                //Add the exit code so that we get respawned
                                domainController.stopLocalHost(ExitCodes.RESTART_PROCESS_FROM_STARTUP_SCRIPT);
                            } else {
                                domainController.stopLocalHost();
                            }
                        }
                    }
                });
            }
        }, OperationContext.Stage.RUNTIME);
    }
@ Override public void execute ( OperationContext context , ModelNode operation ) throws OperationFailedException { final boolean restart = RESTART . validateOperation ( operation ) . asBoolean ( false ) ; final Resource hostResource = context . readResource ( PathAddress . EMPTY_ADDRESS ) ; final int suspendTimeout = SUSPEND_TIMEOUT . resolveModelAttribute ( context , operation ) . asInt ( ) ; final BlockingTimeout blockingTimeout = BlockingTimeout . Factory . getProxyBlockingTimeout ( context ) ; context . addStep ( new OperationStepHandler ( ) { @ Override public void execute ( OperationContext context , ModelNode operation ) throws OperationFailedException { AuthorizationResult authorizationResult = context . authorize ( operation , EnumSet . of ( Action . ActionEffect . WRITE_RUNTIME ) ) ; if ( authorizationResult . getDecision ( ) == AuthorizationResult . Decision . DENY ) { throw ControllerLogger . ACCESS_LOGGER . unauthorized ( operation . get ( OP ) . asString ( ) , PathAddress . pathAddress ( operation . get ( OP_ADDR ) ) , authorizationResult . getExplanation ( ) ) ; } Set < String > servers = getServersForHost ( hostResource ) ; final List < ModelNode > errorResponses = serverInventory . suspendServers ( servers , suspendTimeout , blockingTimeout ) ; if ( ! errorResponses . isEmpty ( ) ) { context . getFailureDescription ( ) . set ( errorResponses ) ; } context . completeStep ( new OperationContext . ResultHandler ( ) { @ Override public void handleResult ( OperationContext . ResultAction resultAction , OperationContext context , ModelNode operation ) { if ( resultAction == OperationContext . ResultAction . KEEP ) { SystemExiter . logBeforeExit ( new SystemExiter . ExitLogger ( ) { @ Override public void logExit ( ) { HostControllerLogger . ROOT_LOGGER . shuttingDownInResponseToManagementRequest ( getOperationName ( operation ) ) ; } } ) ; if ( restart ) { domainController . stopLocalHost ( ExitCodes . RESTART_PROCESS_FROM_STARTUP_SCRIPT ) ; } else { domainController . stopLocalHost ( ) ; } } } } ) ; } } , OperationContext . Stage . RUNTIME ) ; }
{@inheritDoc}