use of org.jboss.as.controller.OperationStepHandler in project wildfly by wildfly.
the class ReadAttributeTranslationHandler method execute.
@Override
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
PathAddress currentAddress = context.getCurrentAddress();
PathAddress targetAddress = this.translation.getPathAddressTransformation().apply(currentAddress);
Attribute targetAttribute = this.translation.getTargetAttribute();
ModelNode targetOperation = Operations.createReadAttributeOperation(targetAddress, targetAttribute);
if (operation.hasDefined(ModelDescriptionConstants.INCLUDE_DEFAULTS)) {
targetOperation.get(ModelDescriptionConstants.INCLUDE_DEFAULTS).set(operation.get(ModelDescriptionConstants.INCLUDE_DEFAULTS));
}
ImmutableManagementResourceRegistration registration = (currentAddress == targetAddress) ? context.getResourceRegistration() : context.getRootResourceRegistration().getSubModel(targetAddress);
if (registration == null) {
throw new OperationFailedException(ControllerLogger.MGMT_OP_LOGGER.noSuchResourceType(targetAddress));
}
OperationStepHandler readAttributeHandler = registration.getAttributeAccess(PathAddress.EMPTY_ADDRESS, targetAttribute.getName()).getReadHandler();
OperationStepHandler readTranslatedAttributeHandler = new ReadTranslatedAttributeStepHandler(readAttributeHandler, targetAttribute, this.translation.getReadTranslator());
// If targetOperation applies to the current resource, we can execute in the current step
if (targetAddress == currentAddress) {
readTranslatedAttributeHandler.execute(context, targetOperation);
} else {
if (registration.isRuntimeOnly()) {
try {
context.readResourceFromRoot(targetAddress, false);
} catch (Resource.NoSuchResourceException ignore) {
// If the target runtime resource does not exist return UNDEFINED
return;
}
}
context.addStep(targetOperation, readTranslatedAttributeHandler, context.getCurrentStage(), true);
}
}
use of org.jboss.as.controller.OperationStepHandler in project wildfly by wildfly.
the class AddStepHandler method execute.
@Override
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
PathAddress address = context.getCurrentAddress();
PathAddress parentAddress = address.getParent();
PathElement path = address.getLastElement();
OperationStepHandler parentHandler = context.getRootResourceRegistration().getOperationHandler(parentAddress, ModelDescriptionConstants.ADD);
if (parentHandler instanceof DescribedAddStepHandler) {
AddStepHandlerDescriptor parentDescriptor = ((DescribedAddStepHandler) parentHandler).getDescriptor();
if (parentDescriptor.getRequiredChildren().contains(path)) {
if (context.readResourceFromRoot(parentAddress, false).hasChild(path)) {
// If we are a required child resource of our parent, we need to remove the auto-created resource first
context.addStep(Util.createRemoveOperation(address), context.getRootResourceRegistration().getOperationHandler(address, ModelDescriptionConstants.REMOVE), OperationContext.Stage.MODEL);
context.addStep(operation, this, OperationContext.Stage.MODEL);
return;
}
}
for (PathElement requiredPath : parentDescriptor.getRequiredSingletonChildren()) {
String requiredPathKey = requiredPath.getKey();
if (requiredPath.getKey().equals(path.getKey())) {
Set<String> childrenNames = context.readResourceFromRoot(parentAddress, false).getChildrenNames(requiredPathKey);
if (!childrenNames.isEmpty()) {
// If there is a required singleton sibling resource, we need to remove it first
for (String childName : childrenNames) {
PathAddress singletonAddress = parentAddress.append(requiredPathKey, childName);
context.addStep(Util.createRemoveOperation(singletonAddress), context.getRootResourceRegistration().getOperationHandler(singletonAddress, ModelDescriptionConstants.REMOVE), OperationContext.Stage.MODEL);
}
context.addStep(operation, this, OperationContext.Stage.MODEL);
return;
}
}
}
}
super.execute(context, operation);
if (this.requiresRuntime(context)) {
for (RuntimeResourceRegistration registration : this.descriptor.getRuntimeResourceRegistrations()) {
context.addStep(new RuntimeResourceRegistrationStepHandler(registration), OperationContext.Stage.MODEL);
}
}
}
use of org.jboss.as.controller.OperationStepHandler in project wildfly by wildfly.
the class CacheContainerResourceDefinition method register.
@Override
public ManagementResourceRegistration register(ManagementResourceRegistration parent) {
ManagementResourceRegistration registration = parent.registerSubModel(this);
ResourceDescriptor descriptor = new ResourceDescriptor(this.getResourceDescriptionResolver()).addAttributes(Attribute.class).addAttributes(ListAttribute.class).addIgnoredAttributes(ExecutorAttribute.class).addIgnoredAttributes(EnumSet.complementOf(EnumSet.of(DeprecatedAttribute.MODULE))).addAttributeTranslation(DeprecatedAttribute.MODULE, new ListAttributeTranslation(ListAttribute.MODULES)).addCapabilities(Capability.class).addCapabilities(model -> model.hasDefined(Attribute.DEFAULT_CACHE.getName()), DEFAULT_CAPABILITIES.values()).addCapabilities(model -> model.hasDefined(Attribute.DEFAULT_CACHE.getName()), DEFAULT_CLUSTERING_CAPABILITIES.values()).addRequiredChildren(EnumSet.complementOf(EnumSet.of(ThreadPoolResourceDefinition.CLIENT))).addRequiredChildren(ScheduledThreadPoolResourceDefinition.class).addRequiredSingletonChildren(NoTransportResourceDefinition.PATH).setResourceTransformation(CacheContainerResource::new);
ServiceValueExecutorRegistry<EmbeddedCacheManager> managerExecutors = new ServiceValueExecutorRegistry<>();
ServiceValueExecutorRegistry<Cache<?, ?>> cacheExecutors = new ServiceValueExecutorRegistry<>();
ResourceServiceHandler handler = new CacheContainerServiceHandler(managerExecutors, cacheExecutors);
new SimpleResourceRegistration(descriptor, handler).register(registration);
// Translate legacy add-alias operation to list-add operation
OperationStepHandler addAliasHandler = new OperationStepHandler() {
@Override
public void execute(OperationContext context, ModelNode legacyOperation) {
String value = legacyOperation.get(ALIAS.getName()).asString();
ModelNode operation = Operations.createListAddOperation(context.getCurrentAddress(), ListAttribute.ALIASES, value);
context.addStep(operation, ListOperations.LIST_ADD_HANDLER, context.getCurrentStage());
}
};
registration.registerOperationHandler(ALIAS_ADD, addAliasHandler);
// Translate legacy remove-alias operation to list-remove operation
OperationStepHandler removeAliasHandler = new OperationStepHandler() {
@Override
public void execute(OperationContext context, ModelNode legacyOperation) throws OperationFailedException {
String value = legacyOperation.get(ALIAS.getName()).asString();
ModelNode operation = Operations.createListRemoveOperation(context.getCurrentAddress(), ListAttribute.ALIASES, value);
context.addStep(operation, ListOperations.LIST_REMOVE_HANDLER, context.getCurrentStage());
}
};
registration.registerOperationHandler(ALIAS_REMOVE, removeAliasHandler);
if (registration.isRuntimeOnlyRegistrationValid()) {
new MetricHandler<>(new CacheContainerMetricExecutor(managerExecutors), CacheContainerMetric.class).register(registration);
new CacheRuntimeResourceDefinition(cacheExecutors).register(registration);
}
new JGroupsTransportResourceDefinition().register(registration);
new NoTransportResourceDefinition().register(registration);
for (ThreadPoolResourceDefinition pool : EnumSet.complementOf(EnumSet.of(ThreadPoolResourceDefinition.CLIENT))) {
pool.register(registration);
}
for (ScheduledThreadPoolResourceDefinition pool : EnumSet.allOf(ScheduledThreadPoolResourceDefinition.class)) {
pool.register(registration);
}
new LocalCacheResourceDefinition(cacheExecutors).register(registration);
new InvalidationCacheResourceDefinition(cacheExecutors).register(registration);
new ReplicatedCacheResourceDefinition(cacheExecutors).register(registration);
new DistributedCacheResourceDefinition(cacheExecutors).register(registration);
new ScatteredCacheResourceDefinition(cacheExecutors).register(registration);
return registration;
}
use of org.jboss.as.controller.OperationStepHandler in project wildfly by wildfly.
the class StatisticsResourceDefinition method registerAttributes.
@Override
public void registerAttributes(ManagementResourceRegistration resourceRegistration) {
super.registerAttributes(resourceRegistration);
for (AttributeDefinition attribute : getAttributesFromPlugin(plugin)) {
resourceRegistration.registerMetric(attribute, new PoolMetrics.ParametrizedPoolMetricsHandler(plugin));
}
// adding enable/disable for pool stats
OperationStepHandler readHandler = new PoolStatisticsRuntimeAttributeReadHandler(plugin);
OperationStepHandler writeHandler = new PoolStatisticsRuntimeAttributeWriteHandler(plugin);
resourceRegistration.registerReadWriteAttribute(org.jboss.as.connector.subsystems.common.pool.Constants.POOL_STATISTICS_ENABLED, readHandler, writeHandler);
}
use of org.jboss.as.controller.OperationStepHandler in project wildfly by wildfly.
the class GetInstalledDriverOperationHandler method execute.
@Override
public void execute(final OperationContext context, final ModelNode operation) throws OperationFailedException {
validator.validate(operation);
final String name = operation.require(DRIVER_NAME.getName()).asString();
if (context.isNormalServer()) {
context.addStep(new OperationStepHandler() {
@Override
public void execute(final OperationContext context, final ModelNode operation) throws OperationFailedException {
ServiceRegistry registry = context.getServiceRegistry(false);
DriverRegistry driverRegistry = (DriverRegistry) registry.getRequiredService(ConnectorServices.JDBC_DRIVER_REGISTRY_SERVICE).getValue();
ServiceModuleLoader serviceModuleLoader = (ServiceModuleLoader) registry.getRequiredService(Services.JBOSS_SERVICE_MODULE_LOADER).getValue();
ModelNode result = new ModelNode();
InstalledDriver driver = driverRegistry.getInstalledDriver(name);
ModelNode driverNode = new ModelNode();
driverNode.get(DRIVER_NAME.getName()).set(driver.getDriverName());
if (driver.isFromDeployment()) {
driverNode.get(DEPLOYMENT_NAME.getName()).set(driver.getDriverName());
driverNode.get(DRIVER_MODULE_NAME.getName());
driverNode.get(MODULE_SLOT.getName());
driverNode.get(DRIVER_DATASOURCE_CLASS_NAME.getName());
driverNode.get(DRIVER_XA_DATASOURCE_CLASS_NAME.getName());
} else {
driverNode.get(DEPLOYMENT_NAME.getName());
driverNode.get(DRIVER_MODULE_NAME.getName()).set(driver.getModuleName().getName());
driverNode.get(MODULE_SLOT.getName()).set(driver.getModuleName() != null ? driver.getModuleName().getSlot() : "");
driverNode.get(DRIVER_DATASOURCE_CLASS_NAME.getName()).set(driver.getDataSourceClassName() != null ? driver.getDataSourceClassName() : "");
driverNode.get(DRIVER_XA_DATASOURCE_CLASS_NAME.getName()).set(driver.getXaDataSourceClassName() != null ? driver.getXaDataSourceClassName() : "");
}
driverNode.get(DATASOURCE_CLASS_INFO.getName()).set(dsClsInfoNode(serviceModuleLoader, driver.getModuleName(), driver.getDataSourceClassName(), driver.getXaDataSourceClassName()));
driverNode.get(DRIVER_CLASS_NAME.getName()).set(driver.getDriverClassName());
driverNode.get(DRIVER_MAJOR_VERSION.getName()).set(driver.getMajorVersion());
driverNode.get(DRIVER_MINOR_VERSION.getName()).set(driver.getMinorVersion());
driverNode.get(JDBC_COMPLIANT.getName()).set(driver.isJdbcCompliant());
result.add(driverNode);
context.getResult().set(result);
}
}, OperationContext.Stage.RUNTIME);
}
}
Aggregations