use of org.jboss.as.controller.registry.AttributeAccess in project wildfly by wildfly.
the class AddStepHandler method populateModel.
@Override
protected void populateModel(OperationContext context, ModelNode operation, Resource resource) throws OperationFailedException {
// Perform operation translation
for (OperationStepHandler translator : this.descriptor.getOperationTranslators()) {
translator.execute(context, operation);
}
// Validate extra add operation parameters
for (AttributeDefinition definition : this.descriptor.getExtraParameters()) {
definition.validateOperation(operation);
}
// Validate and apply attribute translations
Map<AttributeDefinition, AttributeTranslation> translations = this.descriptor.getAttributeTranslations();
for (Map.Entry<AttributeDefinition, AttributeTranslation> entry : translations.entrySet()) {
AttributeDefinition alias = entry.getKey();
AttributeTranslation translation = entry.getValue();
Attribute target = translation.getTargetAttribute();
String targetName = target.getName();
if (operation.hasDefined(alias.getName()) && !operation.hasDefined(targetName)) {
ModelNode value = alias.validateOperation(operation);
ModelNode translatedValue = translation.getWriteTranslator().translate(context, value);
// Target attribute will be validated by super implementation
operation.get(targetName).set(translatedValue);
}
}
// Validate proper attributes
ModelNode model = resource.getModel();
ImmutableManagementResourceRegistration registration = context.getResourceRegistration();
for (String attributeName : registration.getAttributeNames(PathAddress.EMPTY_ADDRESS)) {
AttributeAccess attribute = registration.getAttributeAccess(PathAddress.EMPTY_ADDRESS, attributeName);
AttributeDefinition definition = attribute.getAttributeDefinition();
if ((attribute.getStorageType() == AttributeAccess.Storage.CONFIGURATION) && !translations.containsKey(definition)) {
definition.validateAndSet(operation, model);
}
}
// Auto-create required child resources as necessary
addRequiredChildren(context, this.descriptor.getRequiredChildren(), (Resource parent, PathElement path) -> parent.hasChild(path));
addRequiredChildren(context, this.descriptor.getRequiredSingletonChildren(), (Resource parent, PathElement path) -> parent.hasChildren(path.getKey()));
}
use of org.jboss.as.controller.registry.AttributeAccess in project wildfly by wildfly.
the class AddStepHandler method recordCapabilitiesAndRequirements.
@Override
protected void recordCapabilitiesAndRequirements(OperationContext context, ModelNode operation, Resource resource) throws OperationFailedException {
PathAddress address = context.getCurrentAddress();
ModelNode model = resource.getModel();
// The super implementation assumes that the capability name is a simple extension of the base name - we do not.
// Only register capabilities when allowed by the associated predicate
this.descriptor.getCapabilities().entrySet().stream().filter(entry -> entry.getValue().test(model)).map(Map.Entry::getKey).forEach(capability -> context.registerCapability(capability.resolve(address)));
ImmutableManagementResourceRegistration registration = context.getResourceRegistration();
registration.getAttributeNames(PathAddress.EMPTY_ADDRESS).stream().map(name -> registration.getAttributeAccess(PathAddress.EMPTY_ADDRESS, name)).filter(Objects::nonNull).map(AttributeAccess::getAttributeDefinition).filter(Objects::nonNull).filter(AttributeDefinition::hasCapabilityRequirements).forEach(attribute -> attribute.addCapabilityRequirements(context, model.get(attribute.getName())));
this.descriptor.getResourceCapabilityReferences().forEach((reference, resolver) -> reference.addCapabilityRequirements(context, (String) null, resolver.apply(address)));
}
use of org.jboss.as.controller.registry.AttributeAccess in project wildfly by wildfly.
the class RemoveStepHandler method performRemove.
@Override
protected void performRemove(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException {
Resource resource = context.readResource(PathAddress.EMPTY_ADDRESS);
// Determine whether super impl will actually remove the resource
boolean remove = !resource.getChildTypes().stream().anyMatch(type -> resource.getChildren(type).stream().filter(entry -> !entry.isRuntime()).map(entry -> entry.getPathElement()).anyMatch(path -> resource.hasChild(path)));
if (remove) {
// We need to remove capabilities *before* removing the resource, since the capability reference resolution might involve reading the resource
PathAddress address = context.getCurrentAddress();
this.descriptor.getCapabilities().entrySet().stream().filter(entry -> entry.getValue().test(model)).map(Map.Entry::getKey).forEach(capability -> context.deregisterCapability(capability.resolve(address).getName()));
ImmutableManagementResourceRegistration registration = context.getResourceRegistration();
registration.getAttributeNames(PathAddress.EMPTY_ADDRESS).stream().map(name -> registration.getAttributeAccess(PathAddress.EMPTY_ADDRESS, name)).filter(Objects::nonNull).map(AttributeAccess::getAttributeDefinition).filter(Objects::nonNull).filter(AttributeDefinition::hasCapabilityRequirements).forEach(attribute -> attribute.removeCapabilityRequirements(context, model.get(attribute.getName())));
this.descriptor.getResourceCapabilityReferences().forEach((reference, resolver) -> reference.removeCapabilityRequirements(context, (String) null, resolver.apply(address)));
// Remove any runtime child resources
removeRuntimeChildren(context, PathAddress.EMPTY_ADDRESS);
}
super.performRemove(context, operation, model);
if (remove) {
PathAddress address = context.getResourceRegistration().getPathAddress();
PathElement path = address.getLastElement();
// If override model was registered, unregister it
if (!path.isWildcard() && (context.getResourceRegistration().getParent().getSubModel(PathAddress.pathAddress(path.getKey(), PathElement.WILDCARD_VALUE)) != null)) {
context.getResourceRegistrationForUpdate().unregisterOverrideModel(context.getCurrentAddressValue());
}
}
}
Aggregations