use of org.jboss.as.controller.AttributeDefinition in project wildfly by wildfly.
the class InfinispanSubsystemXMLReader method readElement.
private static void readElement(XMLExtendedStreamReader reader, ModelNode operation, Attribute attribute) throws XMLStreamException {
AttributeDefinition definition = attribute.getDefinition();
AttributeParser parser = definition.getParser();
if (parser.isParseAsElement()) {
parser.parseElement(definition, reader, operation);
} else {
parser.parseAndSetParameter(definition, reader.getElementText(), operation, reader);
}
}
use of org.jboss.as.controller.AttributeDefinition in project wildfly by wildfly.
the class LegacyMetricOperationsRegistration method register.
public void register(ManagementResourceRegistration registration) {
// Transform legacy /subsystem=modcluster/mod-cluster-config=CONFIGURATION:add-metric(type=...) operation
// -> /subsystem=modcluster/proxy=*/dynamic-load-provider=configuration/load-metric=...:add(...)
OperationDefinition legacyAddMetricOperation = new SimpleOperationDefinitionBuilder("add-metric", ModClusterExtension.SUBSYSTEM_RESOLVER).addParameter(LoadMetricResourceDefinition.Attribute.TYPE.getDefinition()).addParameter(LoadMetricResourceDefinition.SharedAttribute.WEIGHT.getDefinition()).addParameter(LoadMetricResourceDefinition.SharedAttribute.CAPACITY.getDefinition()).addParameter(LoadMetricResourceDefinition.SharedAttribute.PROPERTY.getDefinition()).setDeprecated(ModClusterModel.VERSION_6_0_0.getVersion()).build();
OperationStepHandler legacyAddMetricHandler = new OperationStepHandler() {
@Override
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
operationDeprecated(context, operation);
PathAddress address = translateProxyPath(context);
String type = operation.require(LoadMetricResourceDefinition.Attribute.TYPE.getName()).asString();
PathAddress metricPath = PathAddress.pathAddress(DynamicLoadProviderResourceDefinition.LEGACY_PATH, LoadMetricResourceDefinition.pathElement(type));
PathAddress metricPathAddress = address.append(metricPath);
ModelNode metricOperation = Util.createAddOperation(metricPathAddress);
OperationEntry addOperationEntry = context.getResourceRegistration().getOperationEntry(PathAddress.pathAddress(metricPath), ModelDescriptionConstants.ADD);
for (AttributeDefinition attribute : addOperationEntry.getOperationDefinition().getParameters()) {
String name = attribute.getName();
if (operation.hasDefined(name)) {
metricOperation.get(name).set(operation.get(name));
}
}
context.addStep(metricOperation, addOperationEntry.getOperationHandler(), OperationContext.Stage.MODEL, true);
}
};
registration.registerOperationHandler(legacyAddMetricOperation, legacyAddMetricHandler);
// Transform legacy /subsystem=modcluster/mod-cluster-config=CONFIGURATION:remove-metric(type=...) operation
// -> /subsystem=modcluster/proxy=*/dynamic-load-provider=configuration/load-metric=...:remove()
OperationDefinition legacyRemoveMetricOperation = new SimpleOperationDefinitionBuilder("remove-metric", ModClusterExtension.SUBSYSTEM_RESOLVER).addParameter(LoadMetricResourceDefinition.Attribute.TYPE.getDefinition()).setDeprecated(ModClusterModel.VERSION_6_0_0.getVersion()).build();
OperationStepHandler legacyRemoveMetricHandler = new OperationStepHandler() {
@Override
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
operationDeprecated(context, operation);
PathAddress address = translateProxyPath(context);
String type = operation.require(LoadMetricResourceDefinition.Attribute.TYPE.getName()).asString();
PathAddress metricPath = PathAddress.pathAddress(DynamicLoadProviderResourceDefinition.LEGACY_PATH, LoadMetricResourceDefinition.pathElement(type));
PathAddress metricPathAddress = address.append(metricPath);
ModelNode metricOperation = Util.createRemoveOperation(metricPathAddress);
OperationEntry removeOperationEntry = context.getResourceRegistration().getOperationEntry(PathAddress.pathAddress(metricPath), ModelDescriptionConstants.REMOVE);
context.addStep(metricOperation, removeOperationEntry.getOperationHandler(), OperationContext.Stage.MODEL, true);
}
};
registration.registerOperationHandler(legacyRemoveMetricOperation, legacyRemoveMetricHandler);
// Transform legacy /subsystem=modcluster/mod-cluster-config=CONFIGURATION:add-custom-metric(class=...) operation
// -> /subsystem=modcluster/proxy=*/dynamic-load-provider=configuration/custom-load-metric=...:add(...)
OperationDefinition legacyAddCustomMetricOperation = new SimpleOperationDefinitionBuilder("add-custom-metric", ModClusterExtension.SUBSYSTEM_RESOLVER).addParameter(CustomLoadMetricResourceDefinition.Attribute.CLASS.getDefinition()).addParameter(LoadMetricResourceDefinition.SharedAttribute.WEIGHT.getDefinition()).addParameter(LoadMetricResourceDefinition.SharedAttribute.CAPACITY.getDefinition()).addParameter(LoadMetricResourceDefinition.SharedAttribute.PROPERTY.getDefinition()).setDeprecated(ModClusterModel.VERSION_6_0_0.getVersion()).build();
OperationStepHandler legacyAddCustomMetricHandler = new OperationStepHandler() {
@Override
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
operationDeprecated(context, operation);
PathAddress address = translateProxyPath(context);
String type = operation.require(CustomLoadMetricResourceDefinition.Attribute.CLASS.getName()).asString();
PathAddress metricPath = PathAddress.pathAddress(DynamicLoadProviderResourceDefinition.LEGACY_PATH, LoadMetricResourceDefinition.pathElement(type));
PathAddress metricPathAddress = address.append(metricPath);
ModelNode metricOperation = Util.createAddOperation(metricPathAddress);
OperationEntry addOperationEntry = context.getResourceRegistration().getOperationEntry(PathAddress.pathAddress(metricPath), ModelDescriptionConstants.ADD);
for (AttributeDefinition attribute : addOperationEntry.getOperationDefinition().getParameters()) {
String name = attribute.getName();
if (operation.hasDefined(name)) {
metricOperation.get(name).set(operation.get(name));
}
}
context.addStep(metricOperation, addOperationEntry.getOperationHandler(), OperationContext.Stage.MODEL, true);
}
};
registration.registerOperationHandler(legacyAddCustomMetricOperation, legacyAddCustomMetricHandler);
// Transform legacy /subsystem=modcluster/mod-cluster-config=CONFIGURATION:remove-custom-metric(class=...) operation
// -> /subsystem=modcluster/proxy=*/dynamic-load-provider=configuration/custom-load-metric=...:remove()
OperationDefinition legacyRemoveCustomMetricOperation = new SimpleOperationDefinitionBuilder("remove-custom-metric", ModClusterExtension.SUBSYSTEM_RESOLVER).addParameter(CustomLoadMetricResourceDefinition.Attribute.CLASS.getDefinition()).setDeprecated(ModClusterModel.VERSION_6_0_0.getVersion()).build();
OperationStepHandler legacyRemoveCustomMetricHandler = new OperationStepHandler() {
@Override
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
operationDeprecated(context, operation);
PathAddress address = translateProxyPath(context);
String type = operation.require(CustomLoadMetricResourceDefinition.Attribute.CLASS.getName()).asString();
PathAddress metricPath = PathAddress.pathAddress(DynamicLoadProviderResourceDefinition.LEGACY_PATH, LoadMetricResourceDefinition.pathElement(type));
PathAddress metricPathAddress = address.append(metricPath);
ModelNode metricOperation = Util.createRemoveOperation(metricPathAddress);
OperationEntry removeOperationEntry = context.getResourceRegistration().getOperationEntry(PathAddress.pathAddress(metricPath), ModelDescriptionConstants.REMOVE);
context.addStep(metricOperation, removeOperationEntry.getOperationHandler(), OperationContext.Stage.MODEL, true);
}
};
registration.registerOperationHandler(legacyRemoveCustomMetricOperation, legacyRemoveCustomMetricHandler);
}
use of org.jboss.as.controller.AttributeDefinition in project wildfly by wildfly.
the class NamingBindingResourceDefinition method registerOperations.
@Override
public void registerOperations(ManagementResourceRegistration resourceRegistration) {
super.registerOperations(resourceRegistration);
SimpleOperationDefinitionBuilder builder = new SimpleOperationDefinitionBuilder(NamingSubsystemModel.REBIND, getResourceDescriptionResolver()).addParameter(SimpleAttributeDefinitionBuilder.create(BINDING_TYPE).setValidator(new EnumValidator<>(BindingType.class, EnumSet.complementOf(EnumSet.of(BindingType.EXTERNAL_CONTEXT)))).build()).addParameter(TYPE).addParameter(VALUE).addParameter(CLASS).addParameter(MODULE).addParameter(LOOKUP).addParameter(ENVIRONMENT);
resourceRegistration.registerOperationHandler(builder.build(), new OperationStepHandler() {
@Override
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
context.addStep(new OperationStepHandler() {
@Override
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
Resource resource = context.readResourceForUpdate(PathAddress.EMPTY_ADDRESS);
ModelNode model = resource.getModel();
for (AttributeDefinition attr : ATTRIBUTES) {
attr.validateAndSet(operation, model);
}
context.addStep(NamingBindingResourceDefinition.VALIDATE_RESOURCE_MODEL_OPERATION_STEP_HANDLER, OperationContext.Stage.MODEL);
context.addStep(new OperationStepHandler() {
@Override
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
final String name = context.getCurrentAddressValue();
final ContextNames.BindInfo bindInfo = ContextNames.bindInfoFor(name);
ServiceController<ManagedReferenceFactory> service = (ServiceController<ManagedReferenceFactory>) context.getServiceRegistry(false).getService(bindInfo.getBinderServiceName());
if (service == null) {
context.reloadRequired();
return;
}
NamingBindingAdd.INSTANCE.doRebind(context, operation, (BinderService) service.getService());
}
}, OperationContext.Stage.RUNTIME);
}
}, OperationContext.Stage.MODEL);
}
});
}
use of org.jboss.as.controller.AttributeDefinition in project wildfly by wildfly.
the class HandlerResourceDefinition method createAttributeWriterHandler.
@Override
protected OperationStepHandler createAttributeWriterHandler() {
return new ModelOnlyWriteAttributeHandler(getAttributes().toArray(new AttributeDefinition[0])) {
@Override
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
context.addStep(new UniqueTypeValidationStepHandler(ModelElement.COMMON_HANDLER) {
@Override
protected String getType(OperationContext context, ModelNode model) throws OperationFailedException {
return getHandlerType(context, model);
}
}, OperationContext.Stage.MODEL);
super.execute(context, operation);
}
};
}
use of org.jboss.as.controller.AttributeDefinition in project wildfly by wildfly.
the class ElytronIntegrationResourceDefinitions method getElytronRealmResourceDefinition.
/**
* Defines a resource that represents an Elytron-compatible realm that can be exported by the legacy security subsystem.
* The constructed {@code SecurityRealm} wraps a legacy {@code SecurityDomainContext} and delegates authentication
* decisions to that context.
*
* To export the realm the resource uses a {@code BasicAddHandler} implementation that registers the security-realm
* capability and implements a {@code org.jboss.as.security.elytron.BasicService.ValueSupplier} that uses the injected
* {@code SecurityDomainContext} to create and return an instance of {@code SecurityDomainContextRealm}.
*/
public static ResourceDefinition getElytronRealmResourceDefinition() {
final AttributeDefinition[] attributes = new AttributeDefinition[] { LEGACY_JAAS_CONFIG, APPLY_ROLE_MAPPERS };
final AbstractAddStepHandler addHandler = createAddHandler(attributes, SECURITY_REALM_RUNTIME_CAPABILITY);
return new BasicResourceDefinition(Constants.ELYTRON_REALM, addHandler, attributes, SECURITY_REALM_RUNTIME_CAPABILITY);
}
Aggregations