use of org.jboss.as.controller.OperationStepHandler in project wildfly by wildfly.
the class RaRemove method execute.
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
final ModelNode opAddr = operation.require(OP_ADDR);
final String idName = PathAddress.pathAddress(opAddr).getLastElement().getValue();
final boolean isModule;
// Compensating is add
final ModelNode model = context.readResource(PathAddress.EMPTY_ADDRESS, false).getModel();
final String archiveOrModuleName;
if (!model.hasDefined(ARCHIVE.getName()) && !model.hasDefined(MODULE.getName())) {
throw ConnectorLogger.ROOT_LOGGER.archiveOrModuleRequired();
}
if (model.get(ARCHIVE.getName()).isDefined()) {
isModule = false;
archiveOrModuleName = model.get(ARCHIVE.getName()).asString();
} else {
isModule = true;
archiveOrModuleName = model.get(MODULE.getName()).asString();
}
final ModelNode compensating = Util.getEmptyOperation(ADD, opAddr);
if (model.hasDefined(RESOURCEADAPTERS_NAME)) {
for (ModelNode raNode : model.get(RESOURCEADAPTERS_NAME).asList()) {
ModelNode raCompensatingNode = raNode.clone();
compensating.get(RESOURCEADAPTERS_NAME).add(raCompensatingNode);
}
}
context.removeResource(PathAddress.EMPTY_ADDRESS);
context.deregisterCapability(Capabilities.RESOURCE_ADAPTER_CAPABILITY.getDynamicName(context.getCurrentAddress()));
if (context.isDefaultRequiresRuntime()) {
context.addStep(new OperationStepHandler() {
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
final boolean wasActive;
wasActive = RaOperationUtil.removeIfActive(context, archiveOrModuleName, idName);
if (wasActive && !context.isResourceServiceRestartAllowed()) {
context.reloadRequired();
context.completeStep(new OperationContext.RollbackHandler() {
@Override
public void handleRollback(OperationContext context, ModelNode operation) {
context.revertReloadRequired();
}
});
return;
}
ServiceName raServiceName = ServiceName.of(ConnectorServices.RA_SERVICE, idName);
ServiceController<?> serviceController = context.getServiceRegistry(false).getService(raServiceName);
final ModifiableResourceAdapter resourceAdapter;
if (serviceController != null) {
resourceAdapter = (ModifiableResourceAdapter) serviceController.getValue();
} else {
resourceAdapter = null;
}
final List<ServiceName> serviceNameList = context.getServiceRegistry(false).getServiceNames();
for (ServiceName name : serviceNameList) {
if (raServiceName.isParentOf(name)) {
context.removeService(name);
}
}
if (model.get(MODULE.getName()).isDefined()) {
// ServiceName deploymentServiceName = ConnectorServices.getDeploymentServiceName(model.get(MODULE.getName()).asString(),raId);
// context.removeService(deploymentServiceName);
ServiceName deployerServiceName = ConnectorServices.RESOURCE_ADAPTER_DEPLOYER_SERVICE_PREFIX.append(idName);
context.removeService(deployerServiceName);
ServiceName inactiveServiceName = ConnectorServices.INACTIVE_RESOURCE_ADAPTER_SERVICE.append(idName);
context.removeService(inactiveServiceName);
}
context.removeService(raServiceName);
context.completeStep(new OperationContext.RollbackHandler() {
@Override
public void handleRollback(OperationContext context, ModelNode operation) {
if (resourceAdapter != null) {
List<ServiceController<?>> newControllers = new LinkedList<ServiceController<?>>();
if (model.get(ARCHIVE.getName()).isDefined()) {
RaOperationUtil.installRaServices(context, idName, resourceAdapter, newControllers);
} else {
try {
RaOperationUtil.installRaServicesAndDeployFromModule(context, idName, resourceAdapter, archiveOrModuleName, newControllers);
} catch (OperationFailedException e) {
}
}
try {
if (wasActive) {
RaOperationUtil.activate(context, idName, archiveOrModuleName);
}
} catch (OperationFailedException e) {
}
}
}
});
}
}, OperationContext.Stage.RUNTIME);
}
}
use of org.jboss.as.controller.OperationStepHandler in project wildfly by wildfly.
the class SSLResourceDefinition method register.
@Override
public ManagementResourceRegistration register(ManagementResourceRegistration parent) {
ManagementResourceRegistration registration = parent.registerSubModel(this);
ResourceDescriptor descriptor = new ResourceDescriptor(this.getResourceDescriptionResolver()).addExtraParameters(Attribute.class);
for (Attribute attribute : Attribute.values()) {
registration.registerReadWriteAttribute(attribute.getDefinition(), null, new ReloadRequiredWriteAttributeHandler() {
@Override
protected void validateUpdatedModel(OperationContext context, Resource model) {
context.addStep(new OperationStepHandler() {
@Override
public void execute(OperationContext ctx, ModelNode op) throws OperationFailedException {
final ModelNode conf = ctx.readResourceFromRoot(ctx.getCurrentAddress().getParent(), false).getModel();
if (conf.hasDefined(ProxyConfigurationResourceDefinition.Attribute.SSL_CONTEXT.getName())) {
throw new OperationFailedException(ROOT_LOGGER.bothElytronAndLegacySslContextDefined());
}
}
}, OperationContext.Stage.MODEL);
}
});
}
new ReloadRequiredResourceRegistration(descriptor).register(registration);
return registration;
}
use of org.jboss.as.controller.OperationStepHandler in project wildfly by wildfly.
the class LegacyMetricOperationsRegistration method register.
public void register(ManagementResourceRegistration registration) {
// Transform legacy /subsystem=modcluster/mod-cluster-config=CONFIGURATION:add-metric(type=...) operation
// -> /subsystem=modcluster/proxy=*/dynamic-load-provider=configuration/load-metric=...:add(...)
OperationDefinition legacyAddMetricOperation = new SimpleOperationDefinitionBuilder("add-metric", ModClusterExtension.SUBSYSTEM_RESOLVER).addParameter(LoadMetricResourceDefinition.Attribute.TYPE.getDefinition()).addParameter(LoadMetricResourceDefinition.SharedAttribute.WEIGHT.getDefinition()).addParameter(LoadMetricResourceDefinition.SharedAttribute.CAPACITY.getDefinition()).addParameter(LoadMetricResourceDefinition.SharedAttribute.PROPERTY.getDefinition()).setDeprecated(ModClusterModel.VERSION_6_0_0.getVersion()).build();
OperationStepHandler legacyAddMetricHandler = new OperationStepHandler() {
@Override
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
operationDeprecated(context, operation);
PathAddress address = translateProxyPath(context);
String type = operation.require(LoadMetricResourceDefinition.Attribute.TYPE.getName()).asString();
PathAddress metricPath = PathAddress.pathAddress(DynamicLoadProviderResourceDefinition.LEGACY_PATH, LoadMetricResourceDefinition.pathElement(type));
PathAddress metricPathAddress = address.append(metricPath);
ModelNode metricOperation = Util.createAddOperation(metricPathAddress);
OperationEntry addOperationEntry = context.getResourceRegistration().getOperationEntry(PathAddress.pathAddress(metricPath), ModelDescriptionConstants.ADD);
for (AttributeDefinition attribute : addOperationEntry.getOperationDefinition().getParameters()) {
String name = attribute.getName();
if (operation.hasDefined(name)) {
metricOperation.get(name).set(operation.get(name));
}
}
context.addStep(metricOperation, addOperationEntry.getOperationHandler(), OperationContext.Stage.MODEL, true);
}
};
registration.registerOperationHandler(legacyAddMetricOperation, legacyAddMetricHandler);
// Transform legacy /subsystem=modcluster/mod-cluster-config=CONFIGURATION:remove-metric(type=...) operation
// -> /subsystem=modcluster/proxy=*/dynamic-load-provider=configuration/load-metric=...:remove()
OperationDefinition legacyRemoveMetricOperation = new SimpleOperationDefinitionBuilder("remove-metric", ModClusterExtension.SUBSYSTEM_RESOLVER).addParameter(LoadMetricResourceDefinition.Attribute.TYPE.getDefinition()).setDeprecated(ModClusterModel.VERSION_6_0_0.getVersion()).build();
OperationStepHandler legacyRemoveMetricHandler = new OperationStepHandler() {
@Override
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
operationDeprecated(context, operation);
PathAddress address = translateProxyPath(context);
String type = operation.require(LoadMetricResourceDefinition.Attribute.TYPE.getName()).asString();
PathAddress metricPath = PathAddress.pathAddress(DynamicLoadProviderResourceDefinition.LEGACY_PATH, LoadMetricResourceDefinition.pathElement(type));
PathAddress metricPathAddress = address.append(metricPath);
ModelNode metricOperation = Util.createRemoveOperation(metricPathAddress);
OperationEntry removeOperationEntry = context.getResourceRegistration().getOperationEntry(PathAddress.pathAddress(metricPath), ModelDescriptionConstants.REMOVE);
context.addStep(metricOperation, removeOperationEntry.getOperationHandler(), OperationContext.Stage.MODEL, true);
}
};
registration.registerOperationHandler(legacyRemoveMetricOperation, legacyRemoveMetricHandler);
// Transform legacy /subsystem=modcluster/mod-cluster-config=CONFIGURATION:add-custom-metric(class=...) operation
// -> /subsystem=modcluster/proxy=*/dynamic-load-provider=configuration/custom-load-metric=...:add(...)
OperationDefinition legacyAddCustomMetricOperation = new SimpleOperationDefinitionBuilder("add-custom-metric", ModClusterExtension.SUBSYSTEM_RESOLVER).addParameter(CustomLoadMetricResourceDefinition.Attribute.CLASS.getDefinition()).addParameter(LoadMetricResourceDefinition.SharedAttribute.WEIGHT.getDefinition()).addParameter(LoadMetricResourceDefinition.SharedAttribute.CAPACITY.getDefinition()).addParameter(LoadMetricResourceDefinition.SharedAttribute.PROPERTY.getDefinition()).setDeprecated(ModClusterModel.VERSION_6_0_0.getVersion()).build();
OperationStepHandler legacyAddCustomMetricHandler = new OperationStepHandler() {
@Override
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
operationDeprecated(context, operation);
PathAddress address = translateProxyPath(context);
String type = operation.require(CustomLoadMetricResourceDefinition.Attribute.CLASS.getName()).asString();
PathAddress metricPath = PathAddress.pathAddress(DynamicLoadProviderResourceDefinition.LEGACY_PATH, LoadMetricResourceDefinition.pathElement(type));
PathAddress metricPathAddress = address.append(metricPath);
ModelNode metricOperation = Util.createAddOperation(metricPathAddress);
OperationEntry addOperationEntry = context.getResourceRegistration().getOperationEntry(PathAddress.pathAddress(metricPath), ModelDescriptionConstants.ADD);
for (AttributeDefinition attribute : addOperationEntry.getOperationDefinition().getParameters()) {
String name = attribute.getName();
if (operation.hasDefined(name)) {
metricOperation.get(name).set(operation.get(name));
}
}
context.addStep(metricOperation, addOperationEntry.getOperationHandler(), OperationContext.Stage.MODEL, true);
}
};
registration.registerOperationHandler(legacyAddCustomMetricOperation, legacyAddCustomMetricHandler);
// Transform legacy /subsystem=modcluster/mod-cluster-config=CONFIGURATION:remove-custom-metric(class=...) operation
// -> /subsystem=modcluster/proxy=*/dynamic-load-provider=configuration/custom-load-metric=...:remove()
OperationDefinition legacyRemoveCustomMetricOperation = new SimpleOperationDefinitionBuilder("remove-custom-metric", ModClusterExtension.SUBSYSTEM_RESOLVER).addParameter(CustomLoadMetricResourceDefinition.Attribute.CLASS.getDefinition()).setDeprecated(ModClusterModel.VERSION_6_0_0.getVersion()).build();
OperationStepHandler legacyRemoveCustomMetricHandler = new OperationStepHandler() {
@Override
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
operationDeprecated(context, operation);
PathAddress address = translateProxyPath(context);
String type = operation.require(CustomLoadMetricResourceDefinition.Attribute.CLASS.getName()).asString();
PathAddress metricPath = PathAddress.pathAddress(DynamicLoadProviderResourceDefinition.LEGACY_PATH, LoadMetricResourceDefinition.pathElement(type));
PathAddress metricPathAddress = address.append(metricPath);
ModelNode metricOperation = Util.createRemoveOperation(metricPathAddress);
OperationEntry removeOperationEntry = context.getResourceRegistration().getOperationEntry(PathAddress.pathAddress(metricPath), ModelDescriptionConstants.REMOVE);
context.addStep(metricOperation, removeOperationEntry.getOperationHandler(), OperationContext.Stage.MODEL, true);
}
};
registration.registerOperationHandler(legacyRemoveCustomMetricOperation, legacyRemoveCustomMetricHandler);
}
use of org.jboss.as.controller.OperationStepHandler in project wildfly by wildfly.
the class NamingBindingResourceDefinition method registerOperations.
@Override
public void registerOperations(ManagementResourceRegistration resourceRegistration) {
super.registerOperations(resourceRegistration);
SimpleOperationDefinitionBuilder builder = new SimpleOperationDefinitionBuilder(NamingSubsystemModel.REBIND, getResourceDescriptionResolver()).addParameter(SimpleAttributeDefinitionBuilder.create(BINDING_TYPE).setValidator(new EnumValidator<>(BindingType.class, EnumSet.complementOf(EnumSet.of(BindingType.EXTERNAL_CONTEXT)))).build()).addParameter(TYPE).addParameter(VALUE).addParameter(CLASS).addParameter(MODULE).addParameter(LOOKUP).addParameter(ENVIRONMENT);
resourceRegistration.registerOperationHandler(builder.build(), new OperationStepHandler() {
@Override
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
context.addStep(new OperationStepHandler() {
@Override
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
Resource resource = context.readResourceForUpdate(PathAddress.EMPTY_ADDRESS);
ModelNode model = resource.getModel();
for (AttributeDefinition attr : ATTRIBUTES) {
attr.validateAndSet(operation, model);
}
context.addStep(NamingBindingResourceDefinition.VALIDATE_RESOURCE_MODEL_OPERATION_STEP_HANDLER, OperationContext.Stage.MODEL);
context.addStep(new OperationStepHandler() {
@Override
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
final String name = context.getCurrentAddressValue();
final ContextNames.BindInfo bindInfo = ContextNames.bindInfoFor(name);
ServiceController<ManagedReferenceFactory> service = (ServiceController<ManagedReferenceFactory>) context.getServiceRegistry(false).getService(bindInfo.getBinderServiceName());
if (service == null) {
context.reloadRequired();
return;
}
NamingBindingAdd.INSTANCE.doRebind(context, operation, (BinderService) service.getService());
}
}, OperationContext.Stage.RUNTIME);
}
}, OperationContext.Stage.MODEL);
}
});
}
use of org.jboss.as.controller.OperationStepHandler in project wildfly by wildfly.
the class LoginModuleResourceDefinition method registerAttributes.
@Override
public void registerAttributes(ManagementResourceRegistration resourceRegistration) {
super.registerAttributes(resourceRegistration);
OperationStepHandler writeHandler = new ModelOnlyWriteAttributeHandler(ATTRIBUTES);
for (AttributeDefinition attribute : ATTRIBUTES) {
resourceRegistration.registerReadWriteAttribute(attribute, null, writeHandler);
}
}
Aggregations