Search in sources :

Example 21 with PathElement

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

the class AdminObjectAdd method performRuntime.

@Override
protected void performRuntime(OperationContext context, ModelNode operation, final Resource resource) throws OperationFailedException {
    final ModelNode address = operation.require(OP_ADDR);
    PathAddress path = PathAddress.pathAddress(address);
    final String raName = context.getCurrentAddress().getParent().getLastElement().getValue();
    final String archiveOrModuleName;
    ModelNode raModel = context.readResourceFromRoot(path.subAddress(0, path.size() - 1), false).getModel();
    final boolean statsEnabled = STATISTICS_ENABLED.resolveModelAttribute(context, raModel).asBoolean();
    if (!raModel.hasDefined(ARCHIVE.getName()) && !raModel.hasDefined(MODULE.getName())) {
        throw ConnectorLogger.ROOT_LOGGER.archiveOrModuleRequired();
    }
    if (raModel.get(ARCHIVE.getName()).isDefined()) {
        archiveOrModuleName = ARCHIVE.resolveModelAttribute(context, raModel).asString();
    } else {
        archiveOrModuleName = MODULE.resolveModelAttribute(context, raModel).asString();
    }
    final String poolName = PathAddress.pathAddress(address).getLastElement().getValue();
    final ModifiableAdminObject adminObjectValue;
    try {
        adminObjectValue = RaOperationUtil.buildAdminObjects(context, operation, poolName);
    } catch (ValidateException e) {
        throw new OperationFailedException(e, new ModelNode().set(ConnectorLogger.ROOT_LOGGER.failedToCreate("AdminObject", operation, e.getLocalizedMessage())));
    }
    ServiceName serviceName = ServiceName.of(ConnectorServices.RA_SERVICE, raName, poolName);
    ServiceName raServiceName = ServiceName.of(ConnectorServices.RA_SERVICE, raName);
    final ServiceTarget serviceTarget = context.getServiceTarget();
    final AdminObjectService service = new AdminObjectService(adminObjectValue);
    serviceTarget.addService(serviceName, service).setInitialMode(ServiceController.Mode.ACTIVE).addDependency(raServiceName, ModifiableResourceAdapter.class, service.getRaInjector()).install();
    ServiceRegistry registry = context.getServiceRegistry(true);
    final ServiceController<?> RaxmlController = registry.getService(ServiceName.of(ConnectorServices.RA_SERVICE, raName));
    Activation raxml = (Activation) RaxmlController.getValue();
    ServiceName deploymentServiceName = ConnectorServices.getDeploymentServiceName(archiveOrModuleName, raName);
    String bootStrapCtxName = DEFAULT_NAME;
    if (raxml.getBootstrapContext() != null && !raxml.getBootstrapContext().equals("undefined")) {
        bootStrapCtxName = raxml.getBootstrapContext();
    }
    AdminObjectStatisticsService adminObjectStatisticsService = new AdminObjectStatisticsService(context.getResourceRegistrationForUpdate(), poolName, statsEnabled);
    ServiceBuilder statsServiceBuilder = serviceTarget.addService(serviceName.append(ConnectorServices.STATISTICS_SUFFIX), adminObjectStatisticsService);
    statsServiceBuilder.addDependency(ConnectorServices.BOOTSTRAP_CONTEXT_SERVICE.append(bootStrapCtxName), Object.class, adminObjectStatisticsService.getBootstrapContextInjector()).addDependency(deploymentServiceName, Object.class, adminObjectStatisticsService.getResourceAdapterDeploymentInjector()).setInitialMode(ServiceController.Mode.PASSIVE).install();
    PathElement peAO = PathElement.pathElement(Constants.STATISTICS_NAME, "extended");
    final Resource aoResource = new IronJacamarResource.IronJacamarRuntimeResource();
    resource.registerChild(peAO, aoResource);
}
Also used : ValidateException(org.jboss.jca.common.api.validator.ValidateException) AdminObjectStatisticsService(org.jboss.as.connector.services.resourceadapters.statistics.AdminObjectStatisticsService) ServiceTarget(org.jboss.msc.service.ServiceTarget) 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) PathAddress(org.jboss.as.controller.PathAddress) ServiceRegistry(org.jboss.msc.service.ServiceRegistry) ModelNode(org.jboss.dmr.ModelNode)

Example 22 with PathElement

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

the class WorkManagerAdd method performRuntime.

@Override
protected void performRuntime(final OperationContext context, final ModelNode operation, final Resource resource) throws OperationFailedException {
    String name = JcaWorkManagerDefinition.WmParameters.NAME.getAttribute().resolveModelAttribute(context, resource.getModel()).asString();
    boolean elytronEnabled = JcaWorkManagerDefinition.WmParameters.ELYTRON_ENABLED.getAttribute().resolveModelAttribute(context, resource.getModel()).asBoolean();
    ServiceTarget serviceTarget = context.getServiceTarget();
    NamedWorkManager wm = new NamedWorkManager(name, elytronEnabled);
    WorkManagerService wmService = new WorkManagerService(wm);
    ServiceBuilder builder = serviceTarget.addService(ConnectorServices.WORKMANAGER_SERVICE.append(name), wmService);
    if (resource.hasChild(PathElement.pathElement(Element.LONG_RUNNING_THREADS.getLocalName()))) {
        builder.addDependency(ThreadsServices.EXECUTOR.append(WORKMANAGER_LONG_RUNNING).append(name), Executor.class, wmService.getExecutorLongInjector());
    }
    builder.addDependency(ThreadsServices.EXECUTOR.append(WORKMANAGER_SHORT_RUNNING).append(name), Executor.class, wmService.getExecutorShortInjector());
    builder.addDependency(TxnServices.JBOSS_TXN_CONTEXT_XA_TERMINATOR, JBossContextXATerminator.class, wmService.getXaTerminatorInjector()).setInitialMode(ServiceController.Mode.ON_DEMAND).install();
    WorkManagerStatisticsService wmStatsService = new WorkManagerStatisticsService(context.getResourceRegistrationForUpdate(), name, true);
    serviceTarget.addService(ConnectorServices.WORKMANAGER_STATS_SERVICE.append(name), wmStatsService).addDependency(ConnectorServices.WORKMANAGER_SERVICE.append(name), WorkManager.class, wmStatsService.getWorkManagerInjector()).setInitialMode(ServiceController.Mode.PASSIVE).install();
    PathElement peLocaldWm = PathElement.pathElement(org.jboss.as.connector.subsystems.resourceadapters.Constants.STATISTICS_NAME, "local");
    final Resource wmResource = new IronJacamarResource.IronJacamarRuntimeResource();
    if (!resource.hasChild(peLocaldWm))
        resource.registerChild(peLocaldWm, wmResource);
}
Also used : NamedWorkManager(org.jboss.as.connector.services.workmanager.NamedWorkManager) WorkManagerService(org.jboss.as.connector.services.workmanager.WorkManagerService) WorkManagerStatisticsService(org.jboss.as.connector.services.workmanager.statistics.WorkManagerStatisticsService) PathElement(org.jboss.as.controller.PathElement) ServiceTarget(org.jboss.msc.service.ServiceTarget) Resource(org.jboss.as.controller.registry.Resource) IronJacamarResource(org.jboss.as.connector.subsystems.resourceadapters.IronJacamarResource) ServiceBuilder(org.jboss.msc.service.ServiceBuilder)

Example 23 with PathElement

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

the class MetricCollector method collectResourceMetrics0.

private void collectResourceMetrics0(final Resource current, ImmutableManagementResourceRegistration managementResourceRegistration, PathAddress address, Function<PathAddress, PathAddress> resourceAddressResolver, MetricRegistration registration, boolean exposeAnySubsystem, List<String> exposedSubsystems, String prefix) {
    if (!isExposingMetrics(address, exposeAnySubsystem, exposedSubsystems)) {
        return;
    }
    Map<String, AttributeAccess> attributes = managementResourceRegistration.getAttributes(address);
    if (attributes == null) {
        return;
    }
    ModelNode resourceDescription = null;
    for (Map.Entry<String, AttributeAccess> entry : attributes.entrySet()) {
        String attributeName = entry.getKey();
        AttributeAccess attributeAccess = entry.getValue();
        if (!isCollectibleMetric(attributeAccess)) {
            continue;
        }
        if (resourceDescription == null) {
            DescriptionProvider modelDescription = managementResourceRegistration.getModelDescription(address);
            resourceDescription = modelDescription.getModelDescription(Locale.getDefault());
        }
        PathAddress resourceAddress = resourceAddressResolver.apply(address);
        MeasurementUnit unit = attributeAccess.getAttributeDefinition().getMeasurementUnit();
        boolean isCounter = attributeAccess.getFlags().contains(AttributeAccess.Flag.COUNTER_METRIC);
        String attributeDescription = resourceDescription.get(ATTRIBUTES, attributeName, DESCRIPTION).asStringOrNull();
        WildFlyMetric metric = new WildFlyMetric(modelControllerClient, resourceAddress, attributeName);
        WildFlyMetricMetadata metadata = new WildFlyMetricMetadata(attributeName, resourceAddress, prefix, attributeDescription, unit, isCounter ? COUNTER : GAUGE);
        registration.addRegistrationTask(() -> registration.registerMetric(metric, metadata));
        registration.addUnregistrationTask(metadata.getMetricID());
    }
    for (String type : current.getChildTypes()) {
        for (Resource.ResourceEntry entry : current.getChildren(type)) {
            final PathElement pathElement = entry.getPathElement();
            final PathAddress childAddress = address.append(pathElement);
            collectResourceMetrics0(entry, managementResourceRegistration, childAddress, resourceAddressResolver, registration, exposeAnySubsystem, exposedSubsystems, prefix);
        }
    }
}
Also used : MeasurementUnit(org.jboss.as.controller.client.helpers.MeasurementUnit) Resource(org.jboss.as.controller.registry.Resource) AttributeAccess(org.jboss.as.controller.registry.AttributeAccess) PathElement(org.jboss.as.controller.PathElement) PathAddress(org.jboss.as.controller.PathAddress) ModelNode(org.jboss.dmr.ModelNode) DescriptionProvider(org.jboss.as.controller.descriptions.DescriptionProvider) Map(java.util.Map)

Example 24 with PathElement

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

the class JVMServerPropertiesTestCase method createDeploymentOperation.

private ModelNode createDeploymentOperation(Path deployment, PathElement... serverGroups) throws MalformedURLException {
    ModelNode content = new ModelNode();
    content.get("url").set(deployment.toUri().toURL().toString());
    ModelNode op = Util.createEmptyOperation(COMPOSITE, PathAddress.EMPTY_ADDRESS);
    ModelNode steps = op.get(STEPS);
    ModelNode step1 = steps.add();
    step1.set(Util.createEmptyOperation(ADD, PathAddress.pathAddress(PathElement.pathElement(DEPLOYMENT, deployment.getFileName().toString()))));
    step1.get(CONTENT).add(content);
    for (PathElement serverGroup : serverGroups) {
        ModelNode sg = steps.add();
        sg.set(Util.createEmptyOperation(ADD, PathAddress.pathAddress(serverGroup, PathElement.pathElement(DEPLOYMENT, deployment.getFileName().toString()))));
        sg.get(ENABLED).set(true);
    }
    return op;
}
Also used : PathElement(org.jboss.as.controller.PathElement) ModelNode(org.jboss.dmr.ModelNode)

Example 25 with PathElement

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

the class SubsystemParsingTestCase method testParseSubsystem.

/**
 * Tests that the xml is parsed into the correct operations
 */
@Test
public void testParseSubsystem() throws Exception {
    // Parse the subsystem xml into operations
    String subsystemXml = "<subsystem xmlns=\"" + AgroalNamespace.CURRENT.getUriString() + "\"/>";
    List<ModelNode> operations = super.parse(subsystemXml);
    // /Check that we have the expected number of operations
    Assert.assertEquals(1, operations.size());
    // Check that each operation has the correct content
    ModelNode addSubsystem = operations.get(0);
    Assert.assertEquals(ADD, addSubsystem.get(OP).asString());
    PathAddress address = PathAddress.pathAddress(addSubsystem.get(OP_ADDR));
    Assert.assertEquals(1, address.size());
    PathElement element = address.getElement(0);
    Assert.assertEquals(SUBSYSTEM, element.getKey());
    Assert.assertEquals(AgroalExtension.SUBSYSTEM_NAME, element.getValue());
}
Also used : PathElement(org.jboss.as.controller.PathElement) PathAddress(org.jboss.as.controller.PathAddress) ModelNode(org.jboss.dmr.ModelNode) AbstractSubsystemTest(org.jboss.as.subsystem.test.AbstractSubsystemTest) Test(org.junit.Test)

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