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);
}
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);
}
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);
}
}
}
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;
}
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());
}
Aggregations