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