Search in sources :

Example 26 with OperationStepHandler

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

the class JSR77ManagementSubsystemAdd method performBoottime.

@Override
protected void performBoottime(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException {
    context.addStep(new AbstractDeploymentChainStep() {

        protected void execute(DeploymentProcessorTarget processorTarget) {
            processorTarget.addDeploymentProcessor(JSR77ManagementExtension.SUBSYSTEM_NAME, Phase.DEPENDENCIES, Phase.DEPENDENCIES_JSR77, new Jsr77DependenciesProcessor());
        }
    }, OperationContext.Stage.RUNTIME);
    final boolean appclient = context.getProcessType() == ProcessType.APPLICATION_CLIENT;
    if (!appclient) {
        context.addStep(new OperationStepHandler() {

            @Override
            public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
                ServiceTarget target = context.getServiceTarget();
                ServiceName mbeanServerServiceName = context.getCapabilityServiceName(JSR77ManagementRootResource.JMX_CAPABILITY, MBeanServer.class);
                RegisterMBeanServerDelegateService mbeanServerService = new RegisterMBeanServerDelegateService();
                target.addService(RegisterMBeanServerDelegateService.SERVICE_NAME, mbeanServerService).addDependency(mbeanServerServiceName, PluggableMBeanServer.class, mbeanServerService.injectedMbeanServer).addDependency(Services.JBOSS_SERVER_CONTROLLER, ModelController.class, mbeanServerService.injectedController).setInitialMode(Mode.ACTIVE).install();
                RegisterManagementEJBService managementEjbService = new RegisterManagementEJBService();
                target.addService(RegisterManagementEJBService.SERVICE_NAME, managementEjbService).addDependency(DeploymentRepository.SERVICE_NAME, DeploymentRepository.class, managementEjbService.deploymentRepositoryValue).addDependency(mbeanServerServiceName, MBeanServer.class, managementEjbService.mbeanServerValue).addDependency(EJBClientContextService.DEFAULT_SERVICE_NAME, EJBClientContextService.class, managementEjbService.ejbClientContextValue).addDependency(AssociationService.SERVICE_NAME, AssociationService.class, managementEjbService.associationServiceInjector).setInitialMode(Mode.ACTIVE).install();
                //TODO null for source ok?
                final ContextNames.BindInfo bindInfo = ContextNames.bindInfoFor(JNDI_NAME);
                final BinderService binderService = new BinderService(bindInfo.getBindName(), null);
                final InjectedValue<ClassLoader> viewClassLoader = new InjectedValue<ClassLoader>();
                viewClassLoader.setValue(Values.immediateValue(ManagementHome.class.getClassLoader()));
                target.addService(bindInfo.getBinderServiceName(), binderService).addInjection(binderService.getManagedObjectInjector(), new RemoteViewManagedReferenceFactory(APP_NAME, MODULE_NAME, DISTINCT_NAME, EJB_NAME, ManagementHome.class.getName(), false, viewClassLoader, appclient)).addDependency(bindInfo.getParentContextServiceName(), ServiceBasedNamingStore.class, binderService.getNamingStoreInjector()).setInitialMode(Mode.ACTIVE).install();
                // Rollback is handled by the parent step
                context.completeStep(OperationContext.RollbackHandler.NOOP_ROLLBACK_HANDLER);
            }
        }, Stage.RUNTIME);
    }
}
Also used : OperationContext(org.jboss.as.controller.OperationContext) InjectedValue(org.jboss.msc.value.InjectedValue) OperationStepHandler(org.jboss.as.controller.OperationStepHandler) ServiceTarget(org.jboss.msc.service.ServiceTarget) OperationFailedException(org.jboss.as.controller.OperationFailedException) RemoteViewManagedReferenceFactory(org.jboss.as.ejb3.remote.RemoteViewManagedReferenceFactory) AssociationService(org.jboss.as.ejb3.remote.AssociationService) BinderService(org.jboss.as.naming.service.BinderService) ManagementHome(javax.management.j2ee.ManagementHome) DeploymentProcessorTarget(org.jboss.as.server.DeploymentProcessorTarget) ServiceName(org.jboss.msc.service.ServiceName) ServiceBasedNamingStore(org.jboss.as.naming.ServiceBasedNamingStore) AbstractDeploymentChainStep(org.jboss.as.server.AbstractDeploymentChainStep) ModelNode(org.jboss.dmr.ModelNode) ModelController(org.jboss.as.controller.ModelController) PluggableMBeanServer(org.jboss.as.server.jmx.PluggableMBeanServer) MBeanServer(javax.management.MBeanServer)

Example 27 with OperationStepHandler

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

the class MigrateOperation method execute.

@Override
public void execute(final OperationContext context, final ModelNode operation) throws OperationFailedException {
    if (context.getRunningMode() != RunningMode.ADMIN_ONLY) {
        throw new OperationFailedException("the iiop migration can be performed when the server is in admin-only mode");
    }
    final PathAddress subsystemsAddress = context.getCurrentAddress().getParent();
    if (context.readResourceFromRoot(subsystemsAddress).hasChild(OPENJDK_SUBSYSTEM_ELEMENT)) {
        throw new OperationFailedException("can not migrate: the new iiop-openjdk subsystem is already defined");
    }
    final Map<PathAddress, ModelNode> migrateOperations = new LinkedHashMap<>();
    if (!context.readResourceFromRoot(PathAddress.EMPTY_ADDRESS).hasChild(OPENJDK_EXTENSION_ELEMENT)) {
        addOpenjdkExtension(context, migrateOperations);
    }
    context.addStep(new OperationStepHandler() {

        @Override
        public void execute(OperationContext operationContext, ModelNode modelNode) throws OperationFailedException {
            final Resource jacorbResource = context.readResourceForUpdate(PathAddress.EMPTY_ADDRESS);
            final ModelNode jacorbModel = Resource.Tools.readModel(jacorbResource).clone();
            final List<String> warnings = new LinkedList<>();
            List<String> unsupportedProperties = TransformUtils.validateDeprecatedProperites(jacorbModel);
            if (!unsupportedProperties.isEmpty()) {
                warnings.add(JacORBLogger.ROOT_LOGGER.cannotEmulatePropertiesWarning(unsupportedProperties));
                for (String unsupportedProperty : unsupportedProperties) {
                    jacorbModel.get(unsupportedProperty).clear();
                }
            }
            checkPropertiesWithExpression(jacorbModel, warnings);
            final ModelNode openjdkModel = TransformUtils.transformModel(jacorbModel);
            ConfigValidator.validateConfig(context, openjdkModel);
            final PathAddress openjdkAddress = subsystemsAddress.append(OPENJDK_SUBSYSTEM_ELEMENT);
            addOpenjdkSubsystem(openjdkAddress, openjdkModel, migrateOperations);
            final PathAddress jacorbAddress = subsystemsAddress.append(JACORB_SUBSYSTEM_ELEMENT);
            removeJacorbSubsystem(jacorbAddress, migrateOperations, context.getProcessType() == ProcessType.STANDALONE_SERVER);
            if (describe) {
                // :describe-migration operation
                // for describe-migration operation, do nothing and return the list of operations that would
                // be executed in the composite operation
                final Collection<ModelNode> values = migrateOperations.values();
                ModelNode result = new ModelNode();
                result.get(MIGRATION_OPERATIONS).set(values);
                ModelNode rw = new ModelNode().setEmptyList();
                for (String warning : warnings) {
                    rw.add(warning);
                }
                result.get(MIGRATION_WARNINGS).set(rw);
                context.getResult().set(result);
            } else {
                // :migrate operation
                // invoke an OSH on a composite operation with all the migration operations
                final Map<PathAddress, ModelNode> migrateOpResponses = migrateSubsystems(context, migrateOperations);
                context.completeStep(new OperationContext.ResultHandler() {

                    @Override
                    public void handleResult(OperationContext.ResultAction resultAction, OperationContext context, ModelNode operation) {
                        final ModelNode result = new ModelNode();
                        ModelNode rw = new ModelNode().setEmptyList();
                        for (String warning : warnings) {
                            rw.add(warning);
                        }
                        result.get(MIGRATION_WARNINGS).set(rw);
                        if (resultAction == OperationContext.ResultAction.ROLLBACK) {
                            for (Map.Entry<PathAddress, ModelNode> entry : migrateOpResponses.entrySet()) {
                                if (entry.getValue().hasDefined(FAILURE_DESCRIPTION)) {
                                    //we check for failure description, as every node has 'failed', but one
                                    //the real error has a failure description
                                    //we break when we find the first one, as there will only ever be one failure
                                    //as the op stops after the first failure
                                    ModelNode desc = new ModelNode();
                                    desc.get(OP).set(migrateOperations.get(entry.getKey()));
                                    desc.get(RESULT).set(entry.getValue());
                                    result.get(MIGRATION_ERROR).set(desc);
                                    break;
                                }
                            }
                            context.getFailureDescription().set(new ModelNode(JacORBLogger.ROOT_LOGGER.migrationFailed()));
                        }
                        context.getResult().set(result);
                    }
                });
            }
        }
    }, MODEL);
}
Also used : OperationContext(org.jboss.as.controller.OperationContext) OperationStepHandler(org.jboss.as.controller.OperationStepHandler) OperationFailedException(org.jboss.as.controller.OperationFailedException) Resource(org.jboss.as.controller.registry.Resource) LinkedHashMap(java.util.LinkedHashMap) PathAddress(org.jboss.as.controller.PathAddress) Collection(java.util.Collection) LinkedList(java.util.LinkedList) List(java.util.List) ModelNode(org.jboss.dmr.ModelNode) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 28 with OperationStepHandler

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

the class HornetQServerResourceDefinition method registerAttributes.

@Override
public void registerAttributes(ManagementResourceRegistration resourceRegistration) {
    OperationStepHandler writeHandler = new ModelOnlyWriteAttributeHandler(CommonAttributes.SIMPLE_ROOT_RESOURCE_ATTRIBUTES);
    for (AttributeDefinition ad : CommonAttributes.SIMPLE_ROOT_RESOURCE_ATTRIBUTES) {
        if (ad.getName().equals(CLUSTERED.getName())) {
            resourceRegistration.registerReadWriteAttribute(CLUSTERED, ClusteredAttributeHandlers.READ_HANDLER, ClusteredAttributeHandlers.WRITE_HANDLER);
        } else if (ad.getName().equals(MESSAGE_COUNTER_ENABLED.getName())) {
            MessageCounterEnabledHandler handler = new MessageCounterEnabledHandler();
            resourceRegistration.registerReadWriteAttribute(MESSAGE_COUNTER_ENABLED, handler, handler);
        } else {
            resourceRegistration.registerReadWriteAttribute(ad, null, writeHandler);
        }
    }
    // handle deprecate attributes
    resourceRegistration.registerReadWriteAttribute(CommonAttributes.LIVE_CONNECTOR_REF, null, DeprecatedAttributeWriteHandler.INSTANCE);
}
Also used : ModelOnlyWriteAttributeHandler(org.jboss.as.controller.ModelOnlyWriteAttributeHandler) OperationStepHandler(org.jboss.as.controller.OperationStepHandler) AttributeDefinition(org.jboss.as.controller.AttributeDefinition)

Example 29 with OperationStepHandler

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

the class PoolOperations method execute.

public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
    final PathAddress address = PathAddress.pathAddress(operation.require(OP_ADDR));
    final String jndiName;
    ModelNode model;
    if (!address.getElement(0).getKey().equals(ModelDescriptionConstants.DEPLOYMENT) && (model = context.readResource(PathAddress.EMPTY_ADDRESS, false).getModel()).isDefined()) {
        jndiName = Util.getJndiName(context, model);
    } else {
        jndiName = address.getLastElement().getValue();
    }
    final Object[] parameters = getParameters(context, operation);
    if (context.isNormalServer()) {
        context.addStep(new OperationStepHandler() {

            public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
                final ServiceController<?> managementRepoService = context.getServiceRegistry(disallowMonitor).getService(ConnectorServices.MANAGEMENT_REPOSITORY_SERVICE);
                if (managementRepoService != null) {
                    ModelNode operationResult = null;
                    try {
                        final ManagementRepository repository = (ManagementRepository) managementRepoService.getValue();
                        final List<Pool> pools = matcher.match(jndiName, repository);
                        if (pools.isEmpty()) {
                            throw ConnectorLogger.ROOT_LOGGER.failedToMatchPool(jndiName);
                        }
                        for (Pool pool : pools) {
                            operationResult = invokeCommandOn(pool, parameters);
                        }
                    } catch (Exception e) {
                        throw new OperationFailedException(ConnectorLogger.ROOT_LOGGER.failedToInvokeOperation(e.getLocalizedMessage()));
                    }
                    if (operationResult != null) {
                        context.getResult().set(operationResult);
                    }
                }
                context.completeStep(OperationContext.RollbackHandler.NOOP_ROLLBACK_HANDLER);
            }
        }, OperationContext.Stage.RUNTIME);
    }
    context.stepCompleted();
}
Also used : OperationContext(org.jboss.as.controller.OperationContext) OperationStepHandler(org.jboss.as.controller.OperationStepHandler) OperationFailedException(org.jboss.as.controller.OperationFailedException) OperationFailedException(org.jboss.as.controller.OperationFailedException) ManagementRepository(org.jboss.jca.core.api.management.ManagementRepository) PathAddress(org.jboss.as.controller.PathAddress) ServiceController(org.jboss.msc.service.ServiceController) ArrayList(java.util.ArrayList) List(java.util.List) Pool(org.jboss.jca.core.api.connectionmanager.pool.Pool) ModelNode(org.jboss.dmr.ModelNode)

Example 30 with OperationStepHandler

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

the class AbstractDataSourceAdd method performRuntime.

@Override
protected void performRuntime(final OperationContext context, final ModelNode operation, final ModelNode model) throws OperationFailedException {
    // domains should only be defined when Elytron enabled is undefined or false (default value)
    if (model.hasDefined(AUTHENTICATION_CONTEXT.getName()) && !ELYTRON_ENABLED.resolveModelAttribute(context, model).asBoolean()) {
        throw SUBSYSTEM_DATASOURCES_LOGGER.attributeRequiresTrueAttribute(AUTHENTICATION_CONTEXT.getName(), ELYTRON_ENABLED.getName());
    } else if (ELYTRON_ENABLED.resolveModelAttribute(context, model).asBoolean() && model.hasDefined(SECURITY_DOMAIN.getName())) {
        throw SUBSYSTEM_DATASOURCES_LOGGER.attributeRequiresFalseOrUndefinedAttribute(SECURITY_DOMAIN.getName(), ELYTRON_ENABLED.getName());
    }
    final boolean enabled = ENABLED.resolveModelAttribute(context, model).asBoolean();
    if (enabled) {
        firstRuntimeStep(context, operation, model);
        context.addStep(new OperationStepHandler() {

            @Override
            public void execute(OperationContext operationContext, ModelNode modelNode) throws OperationFailedException {
                secondRuntimeStep(context, operation, context.getResourceRegistrationForUpdate(), model, isXa());
            }
        }, OperationContext.Stage.RUNTIME);
    }
}
Also used : OperationContext(org.jboss.as.controller.OperationContext) OperationStepHandler(org.jboss.as.controller.OperationStepHandler) OperationFailedException(org.jboss.as.controller.OperationFailedException) ModelNode(org.jboss.dmr.ModelNode)

Aggregations

OperationStepHandler (org.jboss.as.controller.OperationStepHandler)48 ModelNode (org.jboss.dmr.ModelNode)39 OperationContext (org.jboss.as.controller.OperationContext)37 OperationFailedException (org.jboss.as.controller.OperationFailedException)31 PathAddress (org.jboss.as.controller.PathAddress)18 AttributeDefinition (org.jboss.as.controller.AttributeDefinition)12 Resource (org.jboss.as.controller.registry.Resource)11 PathElement (org.jboss.as.controller.PathElement)8 SimpleAttributeDefinition (org.jboss.as.controller.SimpleAttributeDefinition)8 ManagementResourceRegistration (org.jboss.as.controller.registry.ManagementResourceRegistration)7 ServiceController (org.jboss.msc.service.ServiceController)7 ServiceName (org.jboss.msc.service.ServiceName)7 Map (java.util.Map)5 ArrayList (java.util.ArrayList)4 ResourceServiceHandler (org.jboss.as.clustering.controller.ResourceServiceHandler)4 ReloadRequiredWriteAttributeHandler (org.jboss.as.controller.ReloadRequiredWriteAttributeHandler)4 Collection (java.util.Collection)3 LinkedHashMap (java.util.LinkedHashMap)3 List (java.util.List)3 ResourceDescriptor (org.jboss.as.clustering.controller.ResourceDescriptor)3