Search in sources :

Example 41 with OperationContext

use of org.jboss.as.controller.OperationContext in project wildfly-camel by wildfly-extras.

the class CamelContextRemove method performRuntime.

@Override
protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException {
    final String propName = operation.get(ModelDescriptionConstants.OP_ADDR).asObject().get(ModelConstants.CONTEXT).asString();
    final String oldContextDefinition = subsystemState.removeContextDefinition(propName);
    context.completeStep(new OperationContext.RollbackHandler() {

        @Override
        public void handleRollback(OperationContext context, ModelNode operation) {
            subsystemState.putContextDefinition(propName, oldContextDefinition);
        }
    });
    ServiceController<?> container = context.getServiceRegistry(false).getService(CamelConstants.CAMEL_CONTEXT_REGISTRY_SERVICE_NAME);
    if (container != null) {
        CamelContextRegistryService serviceRegistry = CamelContextRegistryService.class.cast(container.getService());
        CamelContextRegistry camelContextRegistry = serviceRegistry.getValue();
        if (camelContextRegistry != null) {
            CamelContext camelctx = camelContextRegistry.getCamelContext(propName);
            try {
                if (camelctx != null) {
                    camelctx.stop();
                }
            } catch (Exception e) {
                LOGGER.warn("Cannot stop camel context: " + camelctx.getName(), e);
                throw new OperationFailedException(e);
            }
        }
    }
}
Also used : OperationContext(org.jboss.as.controller.OperationContext) CamelContext(org.apache.camel.CamelContext) OperationFailedException(org.jboss.as.controller.OperationFailedException) CamelContextRegistryService(org.wildfly.extension.camel.service.CamelContextRegistryService) ModelNode(org.jboss.dmr.ModelNode) CamelContextRegistry(org.wildfly.extension.camel.CamelContextRegistry) OperationFailedException(org.jboss.as.controller.OperationFailedException)

Example 42 with OperationContext

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

the class EJB3SubsystemRootResourceDefinition method registerAttributes.

@Override
public void registerAttributes(ManagementResourceRegistration resourceRegistration) {
    resourceRegistration.registerReadOnlyAttribute(DEFAULT_CLUSTERED_SFSB_CACHE, new SimpleAliasReadAttributeHandler(DEFAULT_SFSB_CACHE));
    resourceRegistration.registerReadWriteAttribute(DEFAULT_SFSB_CACHE, null, EJB3SubsystemDefaultCacheWriteHandler.SFSB_CACHE);
    resourceRegistration.registerReadWriteAttribute(DEFAULT_SFSB_PASSIVATION_DISABLED_CACHE, null, EJB3SubsystemDefaultCacheWriteHandler.SFSB_PASSIVATION_DISABLED_CACHE);
    resourceRegistration.registerReadWriteAttribute(DEFAULT_SLSB_INSTANCE_POOL, null, EJB3SubsystemDefaultPoolWriteHandler.SLSB_POOL);
    resourceRegistration.registerReadWriteAttribute(DEFAULT_MDB_INSTANCE_POOL, null, EJB3SubsystemDefaultPoolWriteHandler.MDB_POOL);
    resourceRegistration.registerReadWriteAttribute(DEFAULT_ENTITY_BEAN_INSTANCE_POOL, null, EJB3SubsystemDefaultPoolWriteHandler.ENTITY_BEAN_POOL);
    resourceRegistration.registerReadWriteAttribute(DEFAULT_ENTITY_BEAN_OPTIMISTIC_LOCKING, null, EJB3SubsystemDefaultEntityBeanOptimisticLockingWriteHandler.INSTANCE);
    resourceRegistration.registerReadWriteAttribute(DEFAULT_RESOURCE_ADAPTER_NAME, null, DefaultResourceAdapterWriteHandler.INSTANCE);
    resourceRegistration.registerReadWriteAttribute(DEFAULT_SINGLETON_BEAN_ACCESS_TIMEOUT, null, DefaultSingletonBeanAccessTimeoutWriteHandler.INSTANCE);
    resourceRegistration.registerReadWriteAttribute(DEFAULT_STATEFUL_BEAN_ACCESS_TIMEOUT, null, DefaultStatefulBeanAccessTimeoutWriteHandler.INSTANCE);
    resourceRegistration.registerReadWriteAttribute(DEFAULT_STATEFUL_BEAN_SESSION_TIMEOUT, null, DefaultStatefulBeanSessionTimeoutWriteHandler.INSTANCE);
    resourceRegistration.registerReadWriteAttribute(ENABLE_STATISTICS, (context, operation) -> {
        ModelNode aliasOp = operation.clone();
        aliasOp.get("name").set(EJB3SubsystemModel.STATISTICS_ENABLED);
        context.addStep(aliasOp, ReadAttributeHandler.INSTANCE, OperationContext.Stage.MODEL, true);
    }, (context, operation) -> {
        ModelNode aliasOp = operation.clone();
        aliasOp.get("name").set(EJB3SubsystemModel.STATISTICS_ENABLED);
        context.addStep(aliasOp, WriteAttributeHandler.INSTANCE, OperationContext.Stage.MODEL, true);
    });
    resourceRegistration.registerReadWriteAttribute(STATISTICS_ENABLED, null, StatisticsEnabledWriteHandler.INSTANCE);
    resourceRegistration.registerReadWriteAttribute(PASS_BY_VALUE, null, EJBRemoteInvocationPassByValueWriteHandler.INSTANCE);
    resourceRegistration.registerReadWriteAttribute(DEFAULT_DISTINCT_NAME, null, EJBDefaultDistinctNameWriteHandler.INSTANCE);
    resourceRegistration.registerReadWriteAttribute(LOG_EJB_EXCEPTIONS, null, ExceptionLoggingWriteHandler.INSTANCE);
    resourceRegistration.registerReadWriteAttribute(ALLOW_EJB_NAME_REGEX, null, EJBNameRegexWriteHandler.INSTANCE);
    final EJBDefaultSecurityDomainWriteHandler defaultSecurityDomainWriteHandler = new EJBDefaultSecurityDomainWriteHandler(DEFAULT_SECURITY_DOMAIN, defaultSecurityDomainDeploymentProcessor);
    resourceRegistration.registerReadWriteAttribute(DEFAULT_SECURITY_DOMAIN, null, defaultSecurityDomainWriteHandler);
    final EJBDefaultMissingMethodPermissionsWriteHandler defaultMissingMethodPermissionsWriteHandler = new EJBDefaultMissingMethodPermissionsWriteHandler(DEFAULT_MISSING_METHOD_PERMISSIONS_DENY_ACCESS, missingMethodPermissionsDenyAccessMergingProcessor);
    resourceRegistration.registerReadWriteAttribute(DEFAULT_MISSING_METHOD_PERMISSIONS_DENY_ACCESS, null, defaultMissingMethodPermissionsWriteHandler);
    resourceRegistration.registerReadWriteAttribute(DISABLE_DEFAULT_EJB_PERMISSIONS, null, new AbstractWriteAttributeHandler<Void>(DISABLE_DEFAULT_EJB_PERMISSIONS) {

        protected boolean applyUpdateToRuntime(final OperationContext context, final ModelNode operation, final String attributeName, final ModelNode resolvedValue, final ModelNode currentValue, final HandbackHolder<Void> handbackHolder) throws OperationFailedException {
            if (resolvedValue.asBoolean()) {
                throw EjbLogger.ROOT_LOGGER.disableDefaultEjbPermissionsCannotBeTrue();
            }
            return false;
        }

        protected void revertUpdateToRuntime(final OperationContext context, final ModelNode operation, final String attributeName, final ModelNode valueToRestore, final ModelNode valueToRevert, final Void handback) throws OperationFailedException {
        }
    });
    resourceRegistration.registerReadWriteAttribute(ENABLE_GRACEFUL_TXN_SHUTDOWN, null, EnableGracefulTxnShutdownWriteHandler.INSTANCE);
    resourceRegistration.registerReadWriteAttribute(SERVER_INTERCEPTORS, null, new ReloadRequiredWriteAttributeHandler(SERVER_INTERCEPTORS));
    resourceRegistration.registerReadWriteAttribute(CLIENT_INTERCEPTORS, null, new ReloadRequiredWriteAttributeHandler(CLIENT_INTERCEPTORS));
}
Also used : OperationContext(org.jboss.as.controller.OperationContext) OperationFailedException(org.jboss.as.controller.OperationFailedException) ModelNode(org.jboss.dmr.ModelNode) ReloadRequiredWriteAttributeHandler(org.jboss.as.controller.ReloadRequiredWriteAttributeHandler)

Example 43 with OperationContext

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

the class JdrReportRequestHandler method execute.

@Override
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
    // In MODEL stage, just validate the request. Unnecessary if the request has no parameters
    validator.validate(operation);
    // Register a handler for the RUNTIME stage
    context.addStep(new OperationStepHandler() {

        @Override
        public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
            ServiceRegistry registry = context.getServiceRegistry(false);
            JdrReportCollector jdrCollector = JdrReportCollector.class.cast(registry.getRequiredService(JdrReportService.SERVICE_NAME).getValue());
            ModelNode response = context.getResult();
            JdrReport report = jdrCollector.collect();
            if (report.getStartTime() != null) {
                response.get("start-time").set(report.getStartTime());
            }
            if (report.getEndTime() != null) {
                response.get("end-time").set(report.getEndTime());
            }
            response.get("report-location").set(report.getLocation());
            context.completeStep(OperationContext.RollbackHandler.NOOP_ROLLBACK_HANDLER);
        }
    }, OperationContext.Stage.RUNTIME);
}
Also used : OperationContext(org.jboss.as.controller.OperationContext) OperationStepHandler(org.jboss.as.controller.OperationStepHandler) OperationFailedException(org.jboss.as.controller.OperationFailedException) ServiceRegistry(org.jboss.msc.service.ServiceRegistry) ModelNode(org.jboss.dmr.ModelNode)

Example 44 with OperationContext

use of org.jboss.as.controller.OperationContext 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, false).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, false).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);
            warnings.addAll(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 45 with OperationContext

use of org.jboss.as.controller.OperationContext 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(DeploymentRepositoryService.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.PASSIVE).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>();
                binderService.getManagedObjectInjector().inject(new RemoteViewManagedReferenceFactory(APP_NAME, MODULE_NAME, DISTINCT_NAME, EJB_NAME, ManagementHome.class.getName(), false, viewClassLoader, appclient));
                viewClassLoader.setValue(Values.immediateValue(ManagementHome.class.getClassLoader()));
                target.addService(bindInfo.getBinderServiceName(), binderService).addDependency(bindInfo.getParentContextServiceName(), ServiceBasedNamingStore.class, binderService.getNamingStoreInjector()).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) 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)

Aggregations

OperationContext (org.jboss.as.controller.OperationContext)67 ModelNode (org.jboss.dmr.ModelNode)66 OperationFailedException (org.jboss.as.controller.OperationFailedException)51 OperationStepHandler (org.jboss.as.controller.OperationStepHandler)45 PathAddress (org.jboss.as.controller.PathAddress)25 Resource (org.jboss.as.controller.registry.Resource)18 AttributeDefinition (org.jboss.as.controller.AttributeDefinition)15 ServiceController (org.jboss.msc.service.ServiceController)13 ServiceName (org.jboss.msc.service.ServiceName)12 ArrayList (java.util.ArrayList)8 ReloadRequiredWriteAttributeHandler (org.jboss.as.controller.ReloadRequiredWriteAttributeHandler)8 List (java.util.List)7 SimpleAttributeDefinition (org.jboss.as.controller.SimpleAttributeDefinition)7 Map (java.util.Map)6 Collection (java.util.Collection)5 SimpleOperationDefinitionBuilder (org.jboss.as.controller.SimpleOperationDefinitionBuilder)5 AbstractDeploymentChainStep (org.jboss.as.server.AbstractDeploymentChainStep)5 DeploymentProcessorTarget (org.jboss.as.server.DeploymentProcessorTarget)5 ServiceBuilder (org.jboss.msc.service.ServiceBuilder)5 ServiceRegistry (org.jboss.msc.service.ServiceRegistry)5