use of org.jboss.as.controller.SimpleOperationDefinitionBuilder in project wildfly by wildfly.
the class ModClusterConfigResourceDefinition method registerOperations.
@Override
public void registerOperations(ManagementResourceRegistration resourceRegistration) {
super.registerOperations(resourceRegistration);
final ResourceDescriptionResolver rootResolver = getResourceDescriptionResolver();
final OperationDefinition addMetricDef = new SimpleOperationDefinitionBuilder(CommonAttributes.ADD_METRIC, rootResolver).setParameters(LoadMetricDefinition.ATTRIBUTES).setRuntimeOnly().build();
final OperationDefinition addCustomDef = new SimpleOperationDefinitionBuilder(CommonAttributes.ADD_CUSTOM_METRIC, rootResolver).setParameters(CustomLoadMetricDefinition.ATTRIBUTES).setRuntimeOnly().build();
final OperationDefinition removeMetricDef = new SimpleOperationDefinitionBuilder(CommonAttributes.REMOVE_METRIC, rootResolver).setParameters(LoadMetricDefinition.TYPE).setRuntimeOnly().build();
final OperationDefinition removeCustomDef = new SimpleOperationDefinitionBuilder(CommonAttributes.REMOVE_CUSTOM_METRIC, rootResolver).setParameters(CustomLoadMetricDefinition.CLASS).setRuntimeOnly().build();
resourceRegistration.registerOperationHandler(addMetricDef, ModClusterAddMetric.INSTANCE);
resourceRegistration.registerOperationHandler(addCustomDef, ModClusterAddCustomMetric.INSTANCE);
resourceRegistration.registerOperationHandler(removeMetricDef, ModClusterRemoveMetric.INSTANCE);
resourceRegistration.registerOperationHandler(removeCustomDef, ModClusterRemoveCustomMetric.INSTANCE);
}
use of org.jboss.as.controller.SimpleOperationDefinitionBuilder in project wildfly by wildfly.
the class StackResourceDefinition method register.
@SuppressWarnings("deprecation")
@Override
public void register(ManagementResourceRegistration parentRegistration) {
ManagementResourceRegistration registration = parentRegistration.registerSubModel(this);
ResourceDescriptor descriptor = new ResourceDescriptor(this.getResourceDescriptionResolver()).addExtraParameters(TRANSPORT, PROTOCOLS).addCapabilities(Capability.class).addOperationTranslator(new OperationStepHandler() {
@Override
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
if (operation.hasDefined(TRANSPORT.getName())) {
PathAddress address = context.getCurrentAddress();
ModelNode transport = operation.get(TRANSPORT.getName());
String type = AbstractProtocolResourceDefinition.DeprecatedAttribute.TYPE.resolveModelAttribute(context, transport).asString();
PathElement transportPath = TransportResourceDefinition.pathElement(type);
PathAddress transportAddress = address.append(transportPath);
ModelNode transportOperation = Util.createAddOperation(transportAddress);
OperationEntry addOperationEntry = context.getResourceRegistration().getOperationEntry(PathAddress.pathAddress(TransportResourceDefinition.WILDCARD_PATH), ModelDescriptionConstants.ADD);
for (AttributeDefinition attribute : addOperationEntry.getOperationDefinition().getParameters()) {
String name = attribute.getName();
if (transport.hasDefined(name)) {
transportOperation.get(name).set(transport.get(name));
}
}
context.addStep(transportOperation, addOperationEntry.getOperationHandler(), OperationContext.Stage.MODEL);
}
}
}).addOperationTranslator(new OperationStepHandler() {
@Override
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
if (operation.hasDefined(PROTOCOLS.getName())) {
PathAddress address = context.getCurrentAddress();
for (ModelNode protocol : operation.get(PROTOCOLS.getName()).asList()) {
String type = AbstractProtocolResourceDefinition.DeprecatedAttribute.TYPE.resolveModelAttribute(context, protocol).asString();
PathElement protocolPath = ProtocolResourceDefinition.pathElement(type);
PathAddress protocolAddress = address.append(protocolPath);
ModelNode protocolOperation = Util.createAddOperation(protocolAddress);
OperationEntry addOperationEntry = context.getResourceRegistration().getOperationEntry(PathAddress.pathAddress(ProtocolResourceDefinition.WILDCARD_PATH), ModelDescriptionConstants.ADD);
for (AttributeDefinition attribute : addOperationEntry.getOperationDefinition().getParameters()) {
String name = attribute.getName();
if (protocol.hasDefined(name)) {
protocolOperation.get(name).set(protocol.get(name));
}
}
context.addStep(protocolOperation, addOperationEntry.getOperationHandler(), OperationContext.Stage.MODEL);
}
}
}
});
ResourceServiceHandler handler = new StackServiceHandler(this.builderFactory);
new SimpleResourceRegistration(descriptor, handler).register(registration);
OperationDefinition legacyAddProtocolOperation = new SimpleOperationDefinitionBuilder("add-protocol", this.getResourceDescriptionResolver()).setParameters(SocketBindingProtocolResourceDefinition.Attribute.SOCKET_BINDING.getDefinition()).addParameter(AbstractProtocolResourceDefinition.DeprecatedAttribute.TYPE.getDefinition()).addParameter(AbstractProtocolResourceDefinition.Attribute.PROPERTIES.getDefinition()).setDeprecated(JGroupsModel.VERSION_3_0_0.getVersion()).build();
// Transform legacy /subsystem=jgroups/stack=*:add-protocol() operation -> /subsystem=jgroups/stack=*/protocol=*:add()
OperationStepHandler legacyAddProtocolHandler = new OperationStepHandler() {
@Override
public void execute(OperationContext context, ModelNode operation) {
PathAddress address = context.getCurrentAddress();
String protocol = operation.require(AbstractProtocolResourceDefinition.DeprecatedAttribute.TYPE.getName()).asString();
PathElement protocolPath = ProtocolResourceDefinition.pathElement(protocol);
PathAddress protocolAddress = address.append(protocolPath);
ModelNode protocolOperation = Util.createAddOperation(protocolAddress);
OperationEntry addOperationEntry = context.getResourceRegistration().getOperationEntry(PathAddress.pathAddress(ProtocolResourceDefinition.WILDCARD_PATH), ModelDescriptionConstants.ADD);
for (AttributeDefinition attribute : addOperationEntry.getOperationDefinition().getParameters()) {
String name = attribute.getName();
if (operation.hasDefined(name)) {
protocolOperation.get(name).set(operation.get(name));
}
}
context.addStep(protocolOperation, addOperationEntry.getOperationHandler(), OperationContext.Stage.MODEL);
}
};
registration.registerOperationHandler(legacyAddProtocolOperation, legacyAddProtocolHandler);
OperationDefinition legacyRemoveProtocolOperation = new SimpleOperationDefinitionBuilder("remove-protocol", this.getResourceDescriptionResolver()).setParameters(AbstractProtocolResourceDefinition.DeprecatedAttribute.TYPE.getDefinition()).setDeprecated(JGroupsModel.VERSION_3_0_0.getVersion()).build();
// Transform legacy /subsystem=jgroups/stack=*:remove-protocol() operation -> /subsystem=jgroups/stack=*/protocol=*:remove()
OperationStepHandler legacyRemoveProtocolHandler = new OperationStepHandler() {
@Override
public void execute(OperationContext context, ModelNode operation) {
PathAddress address = context.getCurrentAddress();
String protocol = operation.require(AbstractProtocolResourceDefinition.DeprecatedAttribute.TYPE.getName()).asString();
PathElement protocolPath = ProtocolResourceDefinition.pathElement(protocol);
PathAddress protocolAddress = address.append(protocolPath);
ModelNode removeOperation = Util.createRemoveOperation(protocolAddress);
context.addStep(removeOperation, context.getResourceRegistration().getOperationHandler(PathAddress.pathAddress(ProtocolResourceDefinition.WILDCARD_PATH), ModelDescriptionConstants.REMOVE), context.getCurrentStage());
}
};
registration.registerOperationHandler(legacyRemoveProtocolOperation, legacyRemoveProtocolHandler);
if (this.allowRuntimeOnlyRegistration) {
new OperationHandler<>(new StackOperationExecutor(), StackOperation.class).register(registration);
}
new TransportRegistration(this.builderFactory).register(registration);
new ProtocolRegistration(this.builderFactory).register(registration);
new RelayResourceDefinition(this.builderFactory).register(registration);
}
use of org.jboss.as.controller.SimpleOperationDefinitionBuilder in project wildfly by wildfly.
the class MessageDrivenBeanResourceDefinition method registerOperations.
@Override
public void registerOperations(ManagementResourceRegistration registry) {
super.registerOperations(registry);
final SimpleOperationDefinition startDelivery = new SimpleOperationDefinitionBuilder(START_DELIVERY, getResourceDescriptionResolver()).setRuntimeOnly().build();
registry.registerOperationHandler(startDelivery, MessageDrivenBeanRuntimeHandler.INSTANCE);
final SimpleOperationDefinition stopDelivery = new SimpleOperationDefinitionBuilder(STOP_DELIVERY, getResourceDescriptionResolver()).setRuntimeOnly().build();
registry.registerOperationHandler(stopDelivery, MessageDrivenBeanRuntimeHandler.INSTANCE);
}
use of org.jboss.as.controller.SimpleOperationDefinitionBuilder in project wildfly by wildfly.
the class AddStepHandler method register.
@Override
public void register(ManagementResourceRegistration registration) {
SimpleOperationDefinitionBuilder builder = new SimpleOperationDefinitionBuilder(ModelDescriptionConstants.ADD, this.descriptor.getDescriptionResolver()).withFlag(OperationEntry.Flag.RESTART_NONE);
if (registration.isOrderedChildResource()) {
builder.addParameter(SimpleAttributeDefinitionBuilder.create(ModelDescriptionConstants.ADD_INDEX, ModelType.INT, true).build());
}
Stream<AttributeDefinition> parameters = this.descriptor.getAttributes().stream();
parameters = Stream.concat(parameters, this.descriptor.getExtraParameters().stream());
parameters = Stream.concat(parameters, this.descriptor.getAttributeTranslations().keySet().stream());
parameters.forEach(attribute -> builder.addParameter(attribute));
registration.registerOperationHandler(builder.build(), this);
}
use of org.jboss.as.controller.SimpleOperationDefinitionBuilder in project wildfly by wildfly.
the class EeLegacySubsystemTestCase method createAdditionalInitialization.
@Override
protected AdditionalInitialization createAdditionalInitialization() {
return new AdditionalInitialization() {
@Override
protected RunningMode getRunningMode() {
return RunningMode.ADMIN_ONLY;
}
@Override
protected void initializeExtraSubystemsAndModel(ExtensionRegistry extensionRegistry, Resource rootResource, ManagementResourceRegistration rootRegistration, RuntimeCapabilityRegistry capabilityRegistry) {
if (!extensionAdded) {
//extensionAdded = true;
//bean validation depends on EE, so we can't use the real subsystem here
final OperationDefinition removeExtension = new SimpleOperationDefinitionBuilder("remove", NonResolvingResourceDescriptionResolver.INSTANCE).build();
final OperationDefinition addExtension = new SimpleOperationDefinitionBuilder("add", NonResolvingResourceDescriptionResolver.INSTANCE).addParameter(new SimpleAttributeDefinition("module", ModelType.STRING, false)).build();
PathElement bvExtension = PathElement.pathElement(EXTENSION, "org.wildfly.extension.bean-validation");
ManagementResourceRegistration extensionRegistration = rootRegistration.registerSubModel(new SimpleResourceDefinition(bvExtension, NonResolvingResourceDescriptionResolver.INSTANCE));
extensionRegistration.registerReadOnlyAttribute(new SimpleAttributeDefinition("module", ModelType.STRING, false), new ReloadRequiredWriteAttributeHandler());
extensionRegistration.registerOperationHandler(removeExtension, new ReloadRequiredRemoveStepHandler());
extensionRegistration.registerOperationHandler(addExtension, new ReloadRequiredAddStepHandler(new SimpleAttributeDefinition("module", ModelType.STRING, false)));
final OperationDefinition removeSubsystem = new SimpleOperationDefinitionBuilder("remove", NonResolvingResourceDescriptionResolver.INSTANCE).build();
final OperationDefinition addSubsystem = new SimpleOperationDefinitionBuilder("add", NonResolvingResourceDescriptionResolver.INSTANCE).build();
PathElement bvSubsystem = PathElement.pathElement(SUBSYSTEM, "bean-validation");
ManagementResourceRegistration subsystemRegistration = rootRegistration.registerSubModel(new SimpleResourceDefinition(bvSubsystem, NonResolvingResourceDescriptionResolver.INSTANCE));
subsystemRegistration.registerOperationHandler(removeSubsystem, new ReloadRequiredRemoveStepHandler());
subsystemRegistration.registerOperationHandler(addSubsystem, new ReloadRequiredAddStepHandler());
}
}
};
}
Aggregations