use of org.jboss.as.controller.OperationContext in project wildfly by wildfly.
the class ServerRemove method performRemove.
@Override
protected void performRemove(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException {
Resource resource = context.readResource(PathAddress.EMPTY_ADDRESS);
// add a runtime step to remove services related to broadcast-group/discovery-group that are started
// when the server is added.
context.addStep(new OperationStepHandler() {
@Override
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
final String serverName = context.getCurrentAddressValue();
final ServiceName serviceName = MessagingServices.getActiveMQServiceName(serverName);
for (final Resource.ResourceEntry broadcastGroup : resource.getChildren(CommonAttributes.BROADCAST_GROUP)) {
context.removeService(GroupBindingService.getBroadcastBaseServiceName(serviceName).append(broadcastGroup.getName()));
}
for (final Resource.ResourceEntry divertGroup : resource.getChildren(CommonAttributes.DISCOVERY_GROUP)) {
context.removeService(GroupBindingService.getDiscoveryBaseServiceName(serviceName).append(divertGroup.getName()));
}
}
}, OperationContext.Stage.RUNTIME);
super.performRemove(context, operation, model);
}
use of org.jboss.as.controller.OperationContext in project wildfly by wildfly.
the class SAMLResourceDefinition method createAttributeWriterHandler.
@Override
protected OperationStepHandler createAttributeWriterHandler() {
List<SimpleAttributeDefinition> attributes = getAttributes();
return new AbstractWriteAttributeHandler(attributes.toArray(new AttributeDefinition[attributes.size()])) {
@Override
protected boolean applyUpdateToRuntime(OperationContext context, ModelNode operation, String attributeName, ModelNode resolvedValue, ModelNode currentValue, HandbackHolder handbackHolder) throws OperationFailedException {
PathAddress pathAddress = PathAddress.pathAddress(operation.get(ModelDescriptionConstants.OP_ADDR));
updateConfiguration(context, pathAddress, false);
return false;
}
@Override
protected void revertUpdateToRuntime(OperationContext context, ModelNode operation, String attributeName, ModelNode valueToRestore, ModelNode valueToRevert, Object handback) throws OperationFailedException {
PathAddress pathAddress = PathAddress.pathAddress(operation.get(ModelDescriptionConstants.OP_ADDR));
updateConfiguration(context, pathAddress, true);
}
private void updateConfiguration(OperationContext context, PathAddress pathAddress, boolean rollback) throws OperationFailedException {
String federationAlias = pathAddress.subAddress(0, pathAddress.size() - 1).getLastElement().getValue();
ServiceRegistry serviceRegistry = context.getServiceRegistry(false);
ServiceController<SAMLService> serviceController = (ServiceController<SAMLService>) serviceRegistry.getService(SAMLService.createServiceName(federationAlias));
if (serviceController != null) {
SAMLService service = serviceController.getValue();
ModelNode samlNode;
if (!rollback) {
samlNode = context.readResource(PathAddress.EMPTY_ADDRESS, false).getModel();
} else {
Resource rc = context.getOriginalRootResource().navigate(pathAddress);
samlNode = rc.getModel();
}
service.setStsType(SAMLAddHandler.toSAMLConfig(context, samlNode));
}
}
};
}
use of org.jboss.as.controller.OperationContext in project wildfly by wildfly.
the class KeyStoreProviderResourceDefinition method createAttributeWriterHandler.
@Override
protected OperationStepHandler createAttributeWriterHandler() {
List<SimpleAttributeDefinition> attributes = getAttributes();
return new AbstractWriteAttributeHandler(attributes.toArray(new AttributeDefinition[attributes.size()])) {
@Override
protected boolean applyUpdateToRuntime(OperationContext context, ModelNode operation, String attributeName, ModelNode resolvedValue, ModelNode currentValue, HandbackHolder handbackHolder) throws OperationFailedException {
PathAddress pathAddress = PathAddress.pathAddress(operation.get(ModelDescriptionConstants.OP_ADDR));
updateConfiguration(context, pathAddress, false);
return false;
}
@Override
protected void revertUpdateToRuntime(OperationContext context, ModelNode operation, String attributeName, ModelNode valueToRestore, ModelNode valueToRevert, Object handback) throws OperationFailedException {
PathAddress pathAddress = PathAddress.pathAddress(operation.get(ModelDescriptionConstants.OP_ADDR));
updateConfiguration(context, pathAddress, true);
}
private void updateConfiguration(OperationContext context, PathAddress pathAddress, boolean rollback) throws OperationFailedException {
String federationAlias = pathAddress.subAddress(0, pathAddress.size() - 1).getLastElement().getValue();
ServiceRegistry serviceRegistry = context.getServiceRegistry(false);
ServiceController<KeyStoreProviderService> serviceController = (ServiceController<KeyStoreProviderService>) serviceRegistry.getService(KeyStoreProviderService.createServiceName(federationAlias));
if (serviceController != null) {
KeyStoreProviderService service = serviceController.getValue();
ModelNode keyStoreProviderNode;
if (!rollback) {
keyStoreProviderNode = context.readResource(PathAddress.EMPTY_ADDRESS, false).getModel();
} else {
Resource rc = context.getOriginalRootResource().navigate(pathAddress);
keyStoreProviderNode = rc.getModel();
}
ModelNode relativeToNode = KeyStoreProviderResourceDefinition.RELATIVE_TO.resolveModelAttribute(context, keyStoreProviderNode);
String relativeTo = null;
if (relativeToNode.isDefined()) {
relativeTo = relativeToNode.asString();
}
String file = KeyStoreProviderResourceDefinition.FILE.resolveModelAttribute(context, keyStoreProviderNode).asString();
service.setKeyProviderType(KeyStoreProviderAddHandler.toKeyProviderType(context, keyStoreProviderNode), file, relativeTo);
}
}
};
}
use of org.jboss.as.controller.OperationContext in project wildfly by wildfly.
the class IDMConfigAddStepHandler method configureModelValidators.
private void configureModelValidators(ModelValidationStepHandler[] modelValidators) {
List<AttributeDefinition> alternativeAttributes = new ArrayList<AttributeDefinition>();
for (AttributeDefinition attribute : this.attributes) {
if (attribute.getAlternatives() != null && attribute.getAlternatives().length > 0) {
alternativeAttributes.add(attribute);
}
}
if (!alternativeAttributes.isEmpty()) {
this.modelValidators.add(new AlternativeAttributeValidationStepHandler(alternativeAttributes.toArray(new AttributeDefinition[alternativeAttributes.size()]), isAlternativesRequired()));
}
if (modelValidators != null) {
this.modelValidators.addAll(Arrays.asList(modelValidators));
}
this.modelValidators.add(new ModelValidationStepHandler() {
@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();
}
});
}
use of org.jboss.as.controller.OperationContext in project wildfly by wildfly.
the class IdentityStoreRemoveStepHandler method updateModel.
@Override
protected void updateModel(OperationContext context, ModelNode operation) throws OperationFailedException {
checkIfLastIdentityStore(context);
super.updateModel(context, operation);
context.addStep(new OperationStepHandler() {
@Override
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
PathAddress address = context.getCurrentAddress();
String configurationName = address.getElement(address.size() - 2).getValue();
String partitionManagerName = address.getElement(address.size() - 3).getValue();
String identityStoreName = address.getLastElement().getValue();
context.removeService(PartitionManagerService.createIdentityStoreServiceName(partitionManagerName, configurationName, identityStoreName));
context.completeStep(OperationContext.ResultHandler.NOOP_RESULT_HANDLER);
}
}, OperationContext.Stage.RUNTIME);
}
Aggregations