Search in sources :

Example 1 with ImmutableManagementResourceRegistration

use of org.jboss.as.controller.registry.ImmutableManagementResourceRegistration 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 ImmutableManagementResourceRegistration

use of org.jboss.as.controller.registry.ImmutableManagementResourceRegistration 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 ImmutableManagementResourceRegistration

use of org.jboss.as.controller.registry.ImmutableManagementResourceRegistration in project wildfly by wildfly.

the class DefaultSubsystemDescribeHandler method describe.

@Override
protected void describe(OrderedChildTypesAttachment orderedChildTypesAttachment, Resource resource, ModelNode addressModel, ModelNode result, ImmutableManagementResourceRegistration registration) {
    if (resource == null || registration.isRemote() || registration.isRuntimeOnly() || resource.isProxy() || resource.isRuntime() || registration.isAlias())
        return;
    result.add(createAddOperation(orderedChildTypesAttachment, addressModel, resource, registration.getChildAddresses(PathAddress.EMPTY_ADDRESS)));
    PathAddress address = PathAddress.pathAddress(addressModel);
    for (String type : resource.getChildTypes()) {
        for (Resource.ResourceEntry entry : resource.getChildren(type)) {
            PathElement path = entry.getPathElement();
            ImmutableManagementResourceRegistration childRegistration = Optional.ofNullable(registration.getSubModel(PathAddress.pathAddress(path))).orElse(registration.getSubModel(PathAddress.pathAddress(PathElement.pathElement(path.getKey()))));
            PathAddress childAddress = address.append(path);
            this.describe(orderedChildTypesAttachment, entry, childAddress.toModelNode(), result, childRegistration);
        }
    }
}
Also used : PathElement(org.jboss.as.controller.PathElement) PathAddress(org.jboss.as.controller.PathAddress) Resource(org.jboss.as.controller.registry.Resource) ImmutableManagementResourceRegistration(org.jboss.as.controller.registry.ImmutableManagementResourceRegistration)

Example 4 with ImmutableManagementResourceRegistration

use of org.jboss.as.controller.registry.ImmutableManagementResourceRegistration 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)

Example 5 with ImmutableManagementResourceRegistration

use of org.jboss.as.controller.registry.ImmutableManagementResourceRegistration in project teiid by teiid.

the class TeiidAdd method deployResources.

private void deployResources(OperationContext context) throws OperationFailedException {
    if (requiresRuntime(context)) {
        try {
            Module module = Module.forClass(getClass());
            if (module == null) {
                // during testing
                return;
            }
            // $NON-NLS-1$
            URL deployments = module.getExportedResource("deployments.properties");
            if (deployments == null) {
                // no deployments
                return;
            }
            BufferedReader in = new BufferedReader(new InputStreamReader(deployments.openStream()));
            String deployment;
            while ((deployment = in.readLine()) != null) {
                PathAddress deploymentAddress = PathAddress.pathAddress(PathElement.pathElement(DEPLOYMENT, deployment));
                ModelNode op = new ModelNode();
                op.get(OP).set(ADD);
                op.get(OP_ADDR).set(deploymentAddress.toModelNode());
                op.get(ENABLED).set(true);
                // prevents writing this deployment out to standalone.xml
                op.get(PERSISTENT).set(false);
                URL url = module.getExportedResource(deployment);
                String urlString = url.toExternalForm();
                ModelNode contentItem = new ModelNode();
                contentItem.get(URL).set(urlString);
                op.get(CONTENT).add(contentItem);
                ImmutableManagementResourceRegistration rootResourceRegistration = context.getRootResourceRegistration();
                OperationStepHandler handler = rootResourceRegistration.getOperationHandler(deploymentAddress, ADD);
                context.addStep(op, handler, OperationContext.Stage.MODEL);
            }
            in.close();
        } catch (IOException e) {
            throw new OperationFailedException(e.getMessage(), e);
        }
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) OperationStepHandler(org.jboss.as.controller.OperationStepHandler) PathAddress(org.jboss.as.controller.PathAddress) BufferedReader(java.io.BufferedReader) OperationFailedException(org.jboss.as.controller.OperationFailedException) ImmutableManagementResourceRegistration(org.jboss.as.controller.registry.ImmutableManagementResourceRegistration) TeiidConstants.asString(org.teiid.jboss.TeiidConstants.asString) IOException(java.io.IOException) Module(org.jboss.modules.Module) ModelNode(org.jboss.dmr.ModelNode) URL(org.jboss.as.controller.descriptions.ModelDescriptionConstants.URL) URL(java.net.URL)

Aggregations

ImmutableManagementResourceRegistration (org.jboss.as.controller.registry.ImmutableManagementResourceRegistration)5 PathAddress (org.jboss.as.controller.PathAddress)4 PathElement (org.jboss.as.controller.PathElement)4 Resource (org.jboss.as.controller.registry.Resource)4 ModelNode (org.jboss.dmr.ModelNode)4 Map (java.util.Map)3 AttributeDefinition (org.jboss.as.controller.AttributeDefinition)3 OperationFailedException (org.jboss.as.controller.OperationFailedException)3 OperationStepHandler (org.jboss.as.controller.OperationStepHandler)3 AttributeAccess (org.jboss.as.controller.registry.AttributeAccess)3 Objects (java.util.Objects)2 OperationContext (org.jboss.as.controller.OperationContext)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 BufferedReader (java.io.BufferedReader)1 IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1 URL (java.net.URL)1