Search in sources :

Example 1 with AttributeAccess

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()));
}
Also used : OperationStepHandler(org.jboss.as.controller.OperationStepHandler) Resource(org.jboss.as.controller.registry.Resource) AttributeDefinition(org.jboss.as.controller.AttributeDefinition) AttributeAccess(org.jboss.as.controller.registry.AttributeAccess) PathElement(org.jboss.as.controller.PathElement) ImmutableManagementResourceRegistration(org.jboss.as.controller.registry.ImmutableManagementResourceRegistration) ModelNode(org.jboss.dmr.ModelNode) Map(java.util.Map)

Example 2 with AttributeAccess

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)));
}
Also used : OperationEntry(org.jboss.as.controller.registry.OperationEntry) OperationStepHandler(org.jboss.as.controller.OperationStepHandler) Resource(org.jboss.as.controller.registry.Resource) PathAddress(org.jboss.as.controller.PathAddress) Collection(java.util.Collection) SimpleAttributeDefinitionBuilder(org.jboss.as.controller.SimpleAttributeDefinitionBuilder) PathElement(org.jboss.as.controller.PathElement) ImmutableManagementResourceRegistration(org.jboss.as.controller.registry.ImmutableManagementResourceRegistration) AttributeAccess(org.jboss.as.controller.registry.AttributeAccess) Objects(java.util.Objects) BiPredicate(java.util.function.BiPredicate) ManagementResourceRegistration(org.jboss.as.controller.registry.ManagementResourceRegistration) OperationContext(org.jboss.as.controller.OperationContext) Stream(java.util.stream.Stream) AbstractAddStepHandler(org.jboss.as.controller.AbstractAddStepHandler) OperationFailedException(org.jboss.as.controller.OperationFailedException) Util(org.jboss.as.controller.operations.common.Util) Map(java.util.Map) Optional(java.util.Optional) ModelNode(org.jboss.dmr.ModelNode) SimpleOperationDefinitionBuilder(org.jboss.as.controller.SimpleOperationDefinitionBuilder) ModelDescriptionConstants(org.jboss.as.controller.descriptions.ModelDescriptionConstants) AttributeDefinition(org.jboss.as.controller.AttributeDefinition) ModelType(org.jboss.dmr.ModelType) PathAddress(org.jboss.as.controller.PathAddress) Objects(java.util.Objects) ImmutableManagementResourceRegistration(org.jboss.as.controller.registry.ImmutableManagementResourceRegistration) ModelNode(org.jboss.dmr.ModelNode) Map(java.util.Map)

Example 3 with AttributeAccess

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());
        }
    }
}
Also used : OperationEntry(org.jboss.as.controller.registry.OperationEntry) Resource(org.jboss.as.controller.registry.Resource) PathAddress(org.jboss.as.controller.PathAddress) PathElement(org.jboss.as.controller.PathElement) ImmutableManagementResourceRegistration(org.jboss.as.controller.registry.ImmutableManagementResourceRegistration) AttributeAccess(org.jboss.as.controller.registry.AttributeAccess) Objects(java.util.Objects) ManagementResourceRegistration(org.jboss.as.controller.registry.ManagementResourceRegistration) OperationContext(org.jboss.as.controller.OperationContext) OperationFailedException(org.jboss.as.controller.OperationFailedException) Map(java.util.Map) AbstractRemoveStepHandler(org.jboss.as.controller.AbstractRemoveStepHandler) ModelNode(org.jboss.dmr.ModelNode) SimpleOperationDefinitionBuilder(org.jboss.as.controller.SimpleOperationDefinitionBuilder) ModelDescriptionConstants(org.jboss.as.controller.descriptions.ModelDescriptionConstants) AttributeDefinition(org.jboss.as.controller.AttributeDefinition) PathElement(org.jboss.as.controller.PathElement) PathAddress(org.jboss.as.controller.PathAddress) Resource(org.jboss.as.controller.registry.Resource) Objects(java.util.Objects) ImmutableManagementResourceRegistration(org.jboss.as.controller.registry.ImmutableManagementResourceRegistration) Map(java.util.Map)

Aggregations

Map (java.util.Map)3 AttributeDefinition (org.jboss.as.controller.AttributeDefinition)3 PathElement (org.jboss.as.controller.PathElement)3 AttributeAccess (org.jboss.as.controller.registry.AttributeAccess)3 ImmutableManagementResourceRegistration (org.jboss.as.controller.registry.ImmutableManagementResourceRegistration)3 Resource (org.jboss.as.controller.registry.Resource)3 ModelNode (org.jboss.dmr.ModelNode)3 Objects (java.util.Objects)2 OperationContext (org.jboss.as.controller.OperationContext)2 OperationFailedException (org.jboss.as.controller.OperationFailedException)2 OperationStepHandler (org.jboss.as.controller.OperationStepHandler)2 PathAddress (org.jboss.as.controller.PathAddress)2 SimpleOperationDefinitionBuilder (org.jboss.as.controller.SimpleOperationDefinitionBuilder)2 ModelDescriptionConstants (org.jboss.as.controller.descriptions.ModelDescriptionConstants)2 ManagementResourceRegistration (org.jboss.as.controller.registry.ManagementResourceRegistration)2 OperationEntry (org.jboss.as.controller.registry.OperationEntry)2 Collection (java.util.Collection)1 Optional (java.util.Optional)1 BiPredicate (java.util.function.BiPredicate)1 Stream (java.util.stream.Stream)1