use of org.jboss.as.controller.OperationStepHandler in project wildfly by wildfly.
the class IDMConfigWriteAttributeHandler method execute.
@Override
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
context.addStep(new OperationStepHandler() {
@Override
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
final PathAddress address = getParentAddress(PathAddress.pathAddress(operation.require(OP_ADDR)));
Resource resource = context.readResourceFromRoot(address);
final ModelNode parentModel = Resource.Tools.readModel(resource);
PartitionManagerAddHandler.INSTANCE.validateModel(context, address.getLastElement().getValue(), parentModel);
context.stepCompleted();
}
}, OperationContext.Stage.MODEL);
super.execute(context, operation);
}
use of org.jboss.as.controller.OperationStepHandler in project wildfly by wildfly.
the class IdentityConfigurationRemoveStepHandler method updateModel.
@Override
protected void updateModel(OperationContext context, ModelNode operation) throws OperationFailedException {
PathAddress partitionManagerAddress = getParentAddress(context.getCurrentAddress());
Resource partitionManagerResource = context.readResourceFromRoot(partitionManagerAddress);
checkIfLastConfiguration(partitionManagerResource);
ModelNode originalParentModel = Resource.Tools.readModel(partitionManagerResource);
super.updateModel(context, operation);
context.addStep(new OperationStepHandler() {
@Override
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
PartitionManagerRemoveHandler.INSTANCE.removeIdentityStoreServices(context, originalParentModel, partitionManagerAddress.getLastElement().getValue(), context.getCurrentAddressValue());
context.completeStep(OperationContext.ResultHandler.NOOP_RESULT_HANDLER);
}
}, OperationContext.Stage.RUNTIME);
}
use of org.jboss.as.controller.OperationStepHandler in project wildfly by wildfly.
the class ManagementHelper method checkNoOtherSibling.
static OperationStepHandler checkNoOtherSibling(final String childType) {
return new OperationStepHandler() {
@Override
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
PathAddress parentAddress = context.getCurrentAddress().getParent();
Resource parent = context.readResourceFromRoot(parentAddress, false);
Set<String> children = parent.getChildrenNames(childType);
if (children.size() > 1) {
throw MessagingLogger.ROOT_LOGGER.onlyOneChildIsAllowed(childType, children);
}
}
};
}
use of org.jboss.as.controller.OperationStepHandler in project wildfly by wildfly.
the class AbstractUpdateJndiHandler method execute.
@Override
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
JNDI_BINDING.validateOperation(operation);
final String jndiName = JNDI_BINDING.resolveModelAttribute(context, operation).asString();
final ModelNode entries = context.readResourceForUpdate(PathAddress.EMPTY_ADDRESS).getModel().get(CommonAttributes.DESTINATION_ENTRIES.getName());
if (addOperation) {
for (ModelNode entry : entries.asList()) {
if (jndiName.equals(entry.asString())) {
throw new OperationFailedException(ROOT_LOGGER.jndiNameAlreadyRegistered(jndiName));
}
}
entries.add(jndiName);
} else {
ModelNode updatedEntries = new ModelNode();
boolean updated = false;
for (ModelNode entry : entries.asList()) {
if (jndiName.equals(entry.asString())) {
if (entries.asList().size() == 1) {
throw new OperationFailedException(ROOT_LOGGER.canNotRemoveLastJNDIName(jndiName));
}
updated = true;
} else {
updatedEntries.add(entry);
}
}
if (!updated) {
throw MessagingLogger.ROOT_LOGGER.canNotRemoveUnknownEntry(jndiName);
}
context.readResourceForUpdate(PathAddress.EMPTY_ADDRESS).getModel().get(CommonAttributes.DESTINATION_ENTRIES.getName()).set(updatedEntries);
}
if (context.isNormalServer()) {
if (rollbackOperationIfServerNotActive(context, operation)) {
return;
}
context.addStep(new OperationStepHandler() {
@Override
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
final String resourceName = PathAddress.pathAddress(operation.require(ModelDescriptionConstants.OP_ADDR)).getLastElement().getValue();
final ServiceName serviceName = MessagingServices.getActiveMQServiceName(PathAddress.pathAddress(operation.get(ModelDescriptionConstants.OP_ADDR)));
final ServiceName jmsManagerServiceName = JMSServices.getJmsManagerBaseServiceName(serviceName);
final ServiceController<?> jmsServerService = context.getServiceRegistry(false).getService(jmsManagerServiceName);
if (jmsServerService != null) {
JMSServerManager jmsServerManager = JMSServerManager.class.cast(jmsServerService.getValue());
if (jmsServerManager == null) {
PathAddress address = PathAddress.pathAddress(operation.require(OP_ADDR));
throw ControllerLogger.ROOT_LOGGER.managementResourceNotFound(address);
}
try {
if (addOperation) {
addJndiName(jmsServerManager, resourceName, jndiName);
} else {
removeJndiName(jmsServerManager, resourceName, jndiName);
}
} catch (Exception e) {
context.getFailureDescription().set(e.getLocalizedMessage());
}
}
if (!context.hasFailureDescription()) {
context.getResult();
}
context.completeStep(new OperationContext.RollbackHandler() {
@Override
public void handleRollback(OperationContext context, ModelNode operation) {
if (jmsServerService != null) {
JMSServerManager jmsServerManager = JMSServerManager.class.cast(jmsServerService.getValue());
try {
if (addOperation) {
removeJndiName(jmsServerManager, resourceName, jndiName);
} else {
addJndiName(jmsServerManager, resourceName, jndiName);
}
} catch (Exception e) {
context.getFailureDescription().set(e.getLocalizedMessage());
}
}
}
});
}
}, OperationContext.Stage.RUNTIME);
}
}
use of org.jboss.as.controller.OperationStepHandler in project wildfly by wildfly.
the class XTSSubsystemDefinition method registerAttributes.
@Override
public void registerAttributes(ManagementResourceRegistration resourceRegistration) {
resourceRegistration.registerReadWriteAttribute(HOST_NAME, null, new ReloadRequiredWriteAttributeHandler(HOST_NAME));
resourceRegistration.registerReadWriteAttribute(ENVIRONMENT_URL, null, new ReloadRequiredWriteAttributeHandler(ENVIRONMENT_URL));
resourceRegistration.registerReadWriteAttribute(DEFAULT_CONTEXT_PROPAGATION, null, new ReloadRequiredWriteAttributeHandler(DEFAULT_CONTEXT_PROPAGATION));
//this here just for legacy support!
resourceRegistration.registerReadOnlyAttribute(ENVIRONMENT, new OperationStepHandler() {
@Override
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
ModelNode url = context.readResource(PathAddress.EMPTY_ADDRESS).getModel().get(ModelDescriptionConstants.URL);
context.getResult().get(ModelDescriptionConstants.URL).set(url);
context.stepCompleted();
}
});
}
Aggregations