use of org.jboss.as.controller.OperationStepHandler in project wildfly by wildfly.
the class BatchSubsystemDefinition method registerAttributes.
@Override
public void registerAttributes(final ManagementResourceRegistration resourceRegistration) {
super.registerAttributes(resourceRegistration);
final OperationStepHandler writeHandler = new ReloadRequiredWriteAttributeHandler(DEFAULT_JOB_REPOSITORY, DEFAULT_THREAD_POOL, SECURITY_DOMAIN);
resourceRegistration.registerReadWriteAttribute(DEFAULT_JOB_REPOSITORY, null, writeHandler);
resourceRegistration.registerReadWriteAttribute(DEFAULT_THREAD_POOL, null, writeHandler);
resourceRegistration.registerReadWriteAttribute(SECURITY_DOMAIN, null, writeHandler);
resourceRegistration.registerReadWriteAttribute(RESTART_JOBS_ON_RESUME, null, new AbstractWriteAttributeHandler<Boolean>(RESTART_JOBS_ON_RESUME) {
@Override
protected boolean applyUpdateToRuntime(final OperationContext context, final ModelNode operation, final String attributeName, final ModelNode resolvedValue, final ModelNode currentValue, final HandbackHolder<Boolean> handbackHolder) throws OperationFailedException {
setValue(context, resolvedValue);
return false;
}
@Override
protected void revertUpdateToRuntime(final OperationContext context, final ModelNode operation, final String attributeName, final ModelNode valueToRestore, final ModelNode valueToRevert, final Boolean handback) throws OperationFailedException {
setValue(context, valueToRestore);
}
private void setValue(final OperationContext context, final ModelNode value) {
final BatchConfigurationService service = (BatchConfigurationService) context.getServiceRegistry(true).getService(context.getCapabilityServiceName(Capabilities.BATCH_CONFIGURATION_CAPABILITY.getName(), BatchConfiguration.class)).getService();
service.setRestartOnResume(value.asBoolean());
}
});
}
use of org.jboss.as.controller.OperationStepHandler in project wildfly by wildfly.
the class StorePropertyResourceDefinition method register.
@Override
public ManagementResourceRegistration register(ManagementResourceRegistration parent) {
ManagementResourceRegistration registration = parent.registerSubModel(this);
AbstractAddStepHandler addHandler = new AbstractAddStepHandler() {
@Override
public void execute(OperationContext context, ModelNode operation) {
operationDeprecated(context, operation);
context.createResource(PathAddress.EMPTY_ADDRESS);
String name = context.getCurrentAddressValue();
String value = operation.get(VALUE.getName()).asString();
PathAddress storeAddress = context.getCurrentAddress().getParent();
ModelNode putOperation = Operations.createMapPutOperation(storeAddress, StoreResourceDefinition.Attribute.PROPERTIES, name, value);
context.addStep(putOperation, MapOperations.MAP_PUT_HANDLER, context.getCurrentStage());
}
};
this.registerAddOperation(registration, addHandler);
AbstractRemoveStepHandler removeHandler = new AbstractRemoveStepHandler() {
@Override
public void execute(OperationContext context, ModelNode operation) {
operationDeprecated(context, operation);
context.removeResource(PathAddress.EMPTY_ADDRESS);
String name = context.getCurrentAddressValue();
PathAddress storeAddress = context.getCurrentAddress().getParent();
ModelNode putOperation = Operations.createMapRemoveOperation(storeAddress, StoreResourceDefinition.Attribute.PROPERTIES, name);
context.addStep(putOperation, MapOperations.MAP_REMOVE_HANDLER, context.getCurrentStage());
}
};
this.registerRemoveOperation(registration, removeHandler);
OperationStepHandler readHandler = new OperationStepHandler() {
@Override
public void execute(OperationContext context, ModelNode operation) {
operationDeprecated(context, operation);
PathAddress storeAddress = context.getCurrentAddress().getParent();
String key = context.getCurrentAddressValue();
ModelNode getOperation = Operations.createMapGetOperation(storeAddress, StoreResourceDefinition.Attribute.PROPERTIES, key);
context.addStep(getOperation, MapOperations.MAP_GET_HANDLER, context.getCurrentStage());
}
};
OperationStepHandler writeHandler = new OperationStepHandler() {
@Override
public void execute(OperationContext context, ModelNode operation) {
operationDeprecated(context, operation);
PathAddress storeAddress = context.getCurrentAddress().getParent();
String key = context.getCurrentAddressValue();
String value = Operations.getAttributeValue(operation).asString();
ModelNode putOperation = Operations.createMapPutOperation(storeAddress, StoreResourceDefinition.Attribute.PROPERTIES, key, value);
context.addStep(putOperation, MapOperations.MAP_PUT_HANDLER, context.getCurrentStage());
}
};
registration.registerReadWriteAttribute(VALUE, readHandler, writeHandler);
return registration;
}
use of org.jboss.as.controller.OperationStepHandler in project wildfly by wildfly.
the class DataSourceEnableDisable method execute.
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
// Log that this is deprecated
ConnectorLogger.ROOT_LOGGER.legacyDisableEnableOperation(operation.get(OP).asString());
// Just delegate to write-attribute.
ModelNode writeAttributeOp = getWriteAttributeOperation(context.getCurrentAddress(), Constants.ENABLED.getName(), enabled);
OperationStepHandler writeHandler = context.getResourceRegistration().getOperationHandler(PathAddress.EMPTY_ADDRESS, WRITE_ATTRIBUTE_OPERATION);
// set the addFirst param to 'true' so the write-attribute runs before any other steps already registered;
// i.e. in the logically equivalent spot in the sequence to this step
context.addStep(writeAttributeOp, writeHandler, OperationContext.Stage.MODEL, true);
}
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);
if (isDisabledDatasource(context, address, model)) {
throw ConnectorLogger.ROOT_LOGGER.datasourceIsDisabled(jndiName);
}
} 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);
}
}
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