Search in sources :

Example 11 with PathElement

use of org.jboss.as.controller.PathElement in project wildfly by wildfly.

the class TransportResourceDefinition method register.

@Override
public ManagementResourceRegistration register(ManagementResourceRegistration parent) {
    ManagementResourceRegistration registration = super.register(parent);
    new WriteAttributeStepHandler(new WriteThreadingAttributeStepHandlerDescriptor()) {

        @Override
        protected void validateUpdatedModel(OperationContext context, Resource model) throws OperationFailedException {
            // Add a new step to validate instead of doing it directly in this method.
            // This allows a composite op to change both attributes and then the
            // validation occurs after both have done their work.
            context.addStep(new OperationStepHandler() {

                @Override
                public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
                    ModelNode conf = context.readResource(PathAddress.EMPTY_ADDRESS).getModel();
                    // TODO doesn't cover the admin-only modes
                    if (context.getProcessType().isServer()) {
                        for (ThreadingAttribute attribute : EnumSet.allOf(ThreadingAttribute.class)) {
                            if (conf.hasDefined(attribute.getName())) {
                                // That is not supported.
                                throw new OperationFailedException(JGroupsLogger.ROOT_LOGGER.threadsAttributesUsedInRuntime());
                            }
                        }
                    }
                }
            }, OperationContext.Stage.MODEL);
        }
    }.register(registration);
    if (registration.getPathAddress().getLastElement().isWildcard()) {
        for (ThreadPoolResourceDefinition pool : EnumSet.allOf(ThreadPoolResourceDefinition.class)) {
            pool.register(registration);
        }
        parent.registerAlias(LEGACY_PATH, new AliasEntry(registration) {

            @Override
            public PathAddress convertToTargetAddress(PathAddress aliasAddress, AliasContext aliasContext) {
                PathAddress target = this.getTargetAddress();
                List<PathElement> result = new ArrayList<>(aliasAddress.size());
                for (int i = 0; i < aliasAddress.size(); ++i) {
                    PathElement element = aliasAddress.getElement(i);
                    if (i == target.size() - 1) {
                        final ModelNode operation = aliasContext.getOperation();
                        final String stackName;
                        if (ModelDescriptionConstants.ADD.equals(Operations.getName(operation)) && operation.hasDefined("type")) {
                            stackName = operation.get("type").asString();
                        } else {
                            Resource root = null;
                            try {
                                root = aliasContext.readResourceFromRoot(PathAddress.pathAddress(result));
                            } catch (Resource.NoSuchResourceException ignored) {
                            }
                            if (root == null) {
                                stackName = "*";
                            } else {
                                Set<String> names = root.getChildrenNames("transport");
                                if (names.size() > 1) {
                                    throw new AssertionError("There should be at most one child");
                                } else if (names.size() == 0) {
                                    stackName = "*";
                                } else {
                                    stackName = names.iterator().next();
                                }
                            }
                        }
                        result.add(PathElement.pathElement("transport", stackName));
                    } else if (i < target.size()) {
                        PathElement targetElement = target.getElement(i);
                        result.add(targetElement.isWildcard() ? PathElement.pathElement(targetElement.getKey(), element.getValue()) : targetElement);
                    } else {
                        result.add(element);
                    }
                }
                return PathAddress.pathAddress(result);
            }
        });
    }
    return registration;
}
Also used : OperationContext(org.jboss.as.controller.OperationContext) EnumSet(java.util.EnumSet) Set(java.util.Set) OperationStepHandler(org.jboss.as.controller.OperationStepHandler) WriteAttributeStepHandler(org.jboss.as.clustering.controller.WriteAttributeStepHandler) Resource(org.jboss.as.controller.registry.Resource) OperationFailedException(org.jboss.as.controller.OperationFailedException) ManagementResourceRegistration(org.jboss.as.controller.registry.ManagementResourceRegistration) PathElement(org.jboss.as.controller.PathElement) PathAddress(org.jboss.as.controller.PathAddress) ArrayList(java.util.ArrayList) List(java.util.List) AliasEntry(org.jboss.as.controller.registry.AliasEntry) ModelNode(org.jboss.dmr.ModelNode)

Example 12 with PathElement

use of org.jboss.as.controller.PathElement in project wildfly by wildfly.

the class AddStepHandler method populateModel.

@Override
protected void populateModel(OperationContext context, ModelNode operation, Resource resource) throws OperationFailedException {
    // Validate extra add operation parameters
    for (AttributeDefinition definition : this.descriptor.getExtraParameters()) {
        definition.validateOperation(operation);
    }
    PathAddress currentAddress = context.getCurrentAddress();
    // Validate and apply attribute translations
    Map<AttributeDefinition, AttributeTranslation> translations = this.descriptor.getAttributeTranslations();
    for (Map.Entry<AttributeDefinition, AttributeTranslation> entry : translations.entrySet()) {
        AttributeDefinition sourceParameter = entry.getKey();
        AttributeTranslation translation = entry.getValue();
        if (operation.hasDefined(sourceParameter.getName())) {
            ModelNode value = sourceParameter.validateOperation(operation);
            ModelNode targetValue = translation.getWriteTranslator().translate(context, value);
            Attribute targetAttribute = translation.getTargetAttribute();
            PathAddress targetAddress = translation.getPathAddressTransformation().apply(currentAddress);
            // Otherwise, we need a separate write-attribute operation
            if (targetAddress == currentAddress) {
                String targetName = targetAttribute.getName();
                if (!operation.hasDefined(targetName)) {
                    operation.get(targetName).set(targetValue);
                }
            } else {
                ModelNode writeAttributeOperation = Operations.createWriteAttributeOperation(targetAddress, targetAttribute, targetValue);
                ImmutableManagementResourceRegistration registration = (currentAddress == targetAddress) ? context.getResourceRegistration() : context.getRootResourceRegistration().getSubModel(targetAddress);
                if (registration == null) {
                    throw new OperationFailedException(ControllerLogger.MGMT_OP_LOGGER.noSuchResourceType(targetAddress));
                }
                OperationStepHandler writeAttributeHandler = registration.getAttributeAccess(PathAddress.EMPTY_ADDRESS, targetAttribute.getName()).getWriteHandler();
                context.addStep(writeAttributeOperation, writeAttributeHandler, OperationContext.Stage.MODEL);
            }
        }
    }
    // 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)) {
            OperationStepHandler writeHandler = this.descriptor.getCustomAttributes().get(definition);
            if (writeHandler != null) {
                // If attribute has custom handling, perform a separate write-attribute operation
                ModelNode writeAttributeOperation = Util.getWriteAttributeOperation(currentAddress, definition.getName(), definition.validateOperation(operation));
                context.addStep(writeAttributeOperation, writeHandler, OperationContext.Stage.MODEL);
            } else {
                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()));
    // Don't leave model undefined
    if (!model.isDefined()) {
        model.setEmptyObject();
    }
}
Also used : OperationStepHandler(org.jboss.as.controller.OperationStepHandler) OperationFailedException(org.jboss.as.controller.OperationFailedException) 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) PathAddress(org.jboss.as.controller.PathAddress) ImmutableManagementResourceRegistration(org.jboss.as.controller.registry.ImmutableManagementResourceRegistration) ModelNode(org.jboss.dmr.ModelNode) Map(java.util.Map)

Example 13 with PathElement

use of org.jboss.as.controller.PathElement 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 14 with PathElement

use of org.jboss.as.controller.PathElement in project wildfly by wildfly.

the class JobOperationStepHandler method getServiceName.

private static ServiceName getServiceName(final OperationContext context) {
    final PathAddress address = context.getCurrentAddress();
    String deploymentName = null;
    String subdeploymentName = null;
    for (PathElement element : address) {
        if (ModelDescriptionConstants.DEPLOYMENT.equals(element.getKey())) {
            deploymentName = getRuntimeName(context, element);
        } else if (ModelDescriptionConstants.SUBDEPLOYMENT.endsWith(element.getKey())) {
            subdeploymentName = element.getValue();
        }
    }
    if (deploymentName == null) {
        throw BatchLogger.LOGGER.couldNotFindDeploymentName(address.toString());
    }
    if (subdeploymentName == null) {
        return BatchServiceNames.jobOperatorServiceName(deploymentName);
    }
    return BatchServiceNames.jobOperatorServiceName(deploymentName, subdeploymentName);
}
Also used : PathElement(org.jboss.as.controller.PathElement) PathAddress(org.jboss.as.controller.PathAddress)

Example 15 with PathElement

use of org.jboss.as.controller.PathElement in project wildfly by wildfly.

the class RaAdd method performRuntime.

@Override
public void performRuntime(final OperationContext context, ModelNode operation, final Resource resource) throws OperationFailedException {
    final ModelNode model = resource.getModel();
    // TODO WFLY-15231 -- this logic is using the wrong attributes, so it's currently doing nothing
    if (ELYTRON_ENABLED.resolveModelAttribute(context, model).asBoolean()) {
        if (model.hasDefined(SECURITY_DOMAIN.getName()))
            throw SUBSYSTEM_RA_LOGGER.attributeRequiresFalseOrUndefinedAttribute(SECURITY_DOMAIN.getName(), ELYTRON_ENABLED.getName());
        else if (model.hasDefined(SECURITY_DOMAIN_AND_APPLICATION.getName()))
            throw SUBSYSTEM_RA_LOGGER.attributeRequiresFalseOrUndefinedAttribute(SECURITY_DOMAIN_AND_APPLICATION.getName(), ELYTRON_ENABLED.getName());
        else if (model.hasDefined(APPLICATION.getName()))
            throw SUBSYSTEM_RA_LOGGER.attributeRequiresFalseOrUndefinedAttribute(APPLICATION.getName(), ELYTRON_ENABLED.getName());
    } else {
        if (model.hasDefined(AUTHENTICATION_CONTEXT.getName()))
            throw SUBSYSTEM_RA_LOGGER.attributeRequiresTrueAttribute(AUTHENTICATION_CONTEXT.getName(), ELYTRON_ENABLED.getName());
        else if (model.hasDefined(AUTHENTICATION_CONTEXT_AND_APPLICATION.getName()))
            throw SUBSYSTEM_RA_LOGGER.attributeRequiresTrueAttribute(AUTHENTICATION_CONTEXT_AND_APPLICATION.getName(), ELYTRON_ENABLED.getName());
    }
    // do the same for recovery security attributes
    if (RECOVERY_ELYTRON_ENABLED.resolveModelAttribute(context, model).asBoolean()) {
        if (model.hasDefined(RECOVERY_SECURITY_DOMAIN.getName()))
            throw SUBSYSTEM_RA_LOGGER.attributeRequiresFalseOrUndefinedAttribute(RECOVERY_SECURITY_DOMAIN.getName(), RECOVERY_ELYTRON_ENABLED.getName());
    } else {
        if (model.hasDefined(RECOVERY_AUTHENTICATION_CONTEXT.getName()))
            throw SUBSYSTEM_RA_LOGGER.attributeRequiresTrueAttribute(RECOVERY_AUTHENTICATION_CONTEXT.getName(), RECOVERY_ELYTRON_ENABLED.getName());
    }
    // Compensating is remove
    final String name = context.getCurrentAddressValue();
    final String archiveOrModuleName;
    final boolean statsEnabled = STATISTICS_ENABLED.resolveModelAttribute(context, model).asBoolean();
    if (!model.hasDefined(ARCHIVE.getName()) && !model.hasDefined(MODULE.getName())) {
        throw ConnectorLogger.ROOT_LOGGER.archiveOrModuleRequired();
    }
    if (model.get(ARCHIVE.getName()).isDefined()) {
        archiveOrModuleName = model.get(ARCHIVE.getName()).asString();
    } else {
        archiveOrModuleName = model.get(MODULE.getName()).asString();
    }
    ModifiableResourceAdapter resourceAdapter = RaOperationUtil.buildResourceAdaptersObject(name, context, operation, archiveOrModuleName);
    List<ServiceController<?>> newControllers = new ArrayList<ServiceController<?>>();
    if (model.get(ARCHIVE.getName()).isDefined()) {
        RaOperationUtil.installRaServices(context, name, resourceAdapter, newControllers);
    } else {
        RaOperationUtil.installRaServicesAndDeployFromModule(context, name, resourceAdapter, archiveOrModuleName, newControllers);
        if (context.isBooting()) {
            context.addStep(new OperationStepHandler() {

                public void execute(final OperationContext context, ModelNode operation) throws OperationFailedException {
                    // Next lines activate configuration on module deployed rar
                    // in case there is 2 different resource-adapter config using same module deployed rar
                    // a Deployment sercivice could be already present and need a restart to consider also this
                    // newly added configuration
                    ServiceName restartedServiceName = RaOperationUtil.restartIfPresent(context, archiveOrModuleName, name);
                    if (restartedServiceName == null) {
                        RaOperationUtil.activate(context, name, archiveOrModuleName);
                    }
                    context.completeStep(new OperationContext.RollbackHandler() {

                        @Override
                        public void handleRollback(OperationContext context, ModelNode operation) {
                            try {
                                RaOperationUtil.removeIfActive(context, archiveOrModuleName, name);
                            } catch (OperationFailedException e) {
                            }
                        }
                    });
                }
            }, OperationContext.Stage.RUNTIME);
        }
    }
    ServiceRegistry registry = context.getServiceRegistry(true);
    final ServiceController<?> RaxmlController = registry.getService(ServiceName.of(ConnectorServices.RA_SERVICE, name));
    Activation raxml = (Activation) RaxmlController.getValue();
    ServiceName serviceName = ConnectorServices.getDeploymentServiceName(archiveOrModuleName, name);
    String bootStrapCtxName = DEFAULT_NAME;
    if (raxml.getBootstrapContext() != null && !raxml.getBootstrapContext().equals("undefined")) {
        bootStrapCtxName = raxml.getBootstrapContext();
    }
    ResourceAdapterStatisticsService raStatsService = new ResourceAdapterStatisticsService(context.getResourceRegistrationForUpdate(), name, statsEnabled);
    ServiceBuilder statsServiceBuilder = context.getServiceTarget().addService(ServiceName.of(ConnectorServices.RA_SERVICE, name).append(ConnectorServices.STATISTICS_SUFFIX), raStatsService);
    statsServiceBuilder.addDependency(ConnectorServices.BOOTSTRAP_CONTEXT_SERVICE.append(bootStrapCtxName), Object.class, raStatsService.getBootstrapContextInjector()).addDependency(serviceName, Object.class, raStatsService.getResourceAdapterDeploymentInjector()).setInitialMode(ServiceController.Mode.PASSIVE).install();
    PathElement peStats = PathElement.pathElement(Constants.STATISTICS_NAME, "extended");
    final Resource statsResource = new IronJacamarResource.IronJacamarRuntimeResource();
    resource.registerChild(peStats, statsResource);
}
Also used : OperationContext(org.jboss.as.controller.OperationContext) ResourceAdapterStatisticsService(org.jboss.as.connector.services.resourceadapters.statistics.ResourceAdapterStatisticsService) OperationStepHandler(org.jboss.as.controller.OperationStepHandler) ArrayList(java.util.ArrayList) OperationFailedException(org.jboss.as.controller.OperationFailedException) Resource(org.jboss.as.controller.registry.Resource) Activation(org.jboss.jca.common.api.metadata.resourceadapter.Activation) ServiceBuilder(org.jboss.msc.service.ServiceBuilder) PathElement(org.jboss.as.controller.PathElement) ServiceName(org.jboss.msc.service.ServiceName) ServiceController(org.jboss.msc.service.ServiceController) ServiceRegistry(org.jboss.msc.service.ServiceRegistry) ModelNode(org.jboss.dmr.ModelNode)

Aggregations

PathElement (org.jboss.as.controller.PathElement)84 PathAddress (org.jboss.as.controller.PathAddress)47 ModelNode (org.jboss.dmr.ModelNode)46 Resource (org.jboss.as.controller.registry.Resource)24 OperationFailedException (org.jboss.as.controller.OperationFailedException)12 ServiceName (org.jboss.msc.service.ServiceName)12 Test (org.junit.Test)10 Map (java.util.Map)9 ArrayList (java.util.ArrayList)8 OperationStepHandler (org.jboss.as.controller.OperationStepHandler)8 ParseUtils.requireNoNamespaceAttribute (org.jboss.as.controller.parsing.ParseUtils.requireNoNamespaceAttribute)7 ParseUtils.unexpectedAttribute (org.jboss.as.controller.parsing.ParseUtils.unexpectedAttribute)7 ManagementResourceRegistration (org.jboss.as.controller.registry.ManagementResourceRegistration)7 DeploymentResourceSupport (org.jboss.as.server.deployment.DeploymentResourceSupport)7 AbstractSubsystemBaseTest (org.jboss.as.subsystem.test.AbstractSubsystemBaseTest)7 ServiceTarget (org.jboss.msc.service.ServiceTarget)6 StatisticsResourceDefinition (org.jboss.as.connector.dynamicresource.StatisticsResourceDefinition)4 AttributeDefinition (org.jboss.as.controller.AttributeDefinition)4 OperationContext (org.jboss.as.controller.OperationContext)4 StandardResourceDescriptionResolver (org.jboss.as.controller.descriptions.StandardResourceDescriptionResolver)4