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);
}
}
}
}
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));
}
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);
}
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);
}
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);
}
}
Aggregations