use of org.jboss.as.controller.AttributeDefinition in project wildfly by wildfly.
the class ConnectionFactoryWriteAttributeHandler method applyUpdateToRuntime.
@Override
protected boolean applyUpdateToRuntime(final OperationContext context, final ModelNode operation, final String attributeName, final ModelNode newValue, final ModelNode currentValue, final HandbackHolder<Void> handbackHolder) throws OperationFailedException {
AttributeDefinition attr = getAttributeDefinition(attributeName);
if (attr.getFlags().contains(AttributeAccess.Flag.RESTART_ALL_SERVICES)) {
// Restart required
return true;
}
ServiceRegistry registry = context.getServiceRegistry(true);
final ServiceName serviceName = MessagingServices.getActiveMQServiceName(PathAddress.pathAddress(operation.get(ModelDescriptionConstants.OP_ADDR)));
ServiceController<?> service = registry.getService(serviceName);
if (service == null) {
// The service isn't installed, so the work done in the Stage.MODEL part is all there is to it
return false;
} else if (service.getState() != ServiceController.State.UP) {
// No, don't barf; just let the update apply to the model and put the server in a reload-required state
return true;
} else {
if (!ActiveMQActivationService.isActiveMQServerActive(context, operation)) {
return false;
}
// Actually apply the update
applyOperationToActiveMQService(context, getName(operation), attributeName, newValue, service);
return false;
}
}
use of org.jboss.as.controller.AttributeDefinition in project wildfly by wildfly.
the class ModClusterAddCustomMetric method execute.
@Override
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
PathAddress opAddress = PathAddress.pathAddress(operation.get(ModelDescriptionConstants.OP_ADDR));
PathAddress parent = opAddress.append(DynamicLoadProviderDefinition.PATH);
String name = CustomLoadMetricDefinition.CLASS.resolveModelAttribute(context, operation).asString();
ModelNode targetOperation = Util.createAddOperation(parent.append(PathElement.pathElement(CustomLoadMetricDefinition.PATH.getKey(), name)));
for (AttributeDefinition def : CustomLoadMetricDefinition.ATTRIBUTES) {
def.validateAndSet(operation, targetOperation);
}
context.addStep(targetOperation, CustomLoadMetricAdd.INSTANCE, OperationContext.Stage.MODEL, true);
context.completeStep(OperationContext.RollbackHandler.NOOP_ROLLBACK_HANDLER);
}
use of org.jboss.as.controller.AttributeDefinition in project wildfly by wildfly.
the class ModClusterAddMetric method execute.
@Override
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
PathAddress opAddress = PathAddress.pathAddress(operation.get(ModelDescriptionConstants.OP_ADDR));
PathAddress parent = opAddress.append(DynamicLoadProviderDefinition.PATH);
String name = LoadMetricDefinition.TYPE.resolveModelAttribute(context, operation).asString();
ModelNode targetOperation = Util.createAddOperation(parent.append(PathElement.pathElement(LoadMetricDefinition.PATH.getKey(), name)));
for (AttributeDefinition def : LoadMetricDefinition.ATTRIBUTES) {
def.validateAndSet(operation, targetOperation);
}
context.addStep(targetOperation, LoadMetricAdd.INSTANCE, OperationContext.Stage.MODEL, true);
context.completeStep(OperationContext.RollbackHandler.NOOP_ROLLBACK_HANDLER);
}
use of org.jboss.as.controller.AttributeDefinition 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.AttributeDefinition 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);
}
}
};
}
Aggregations