Skip to content

Commit

Permalink
Migrate IO subsystem to SubsystemResourceXMLSchema.
Browse files Browse the repository at this point in the history
  • Loading branch information
pferraro committed Dec 16, 2024
1 parent 6f00f89 commit 70e0f35
Show file tree
Hide file tree
Showing 12 changed files with 77 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class BufferPoolResourceDefinition extends PersistentResourceDefinition {
);

BufferPoolResourceDefinition() {
super(new SimpleResourceDefinition.Parameters(PATH, IOSubsystemRegistrar.RESOLVER.createChildResolver(PATH))
super(new SimpleResourceDefinition.Parameters(PATH, IOSubsystemResourceRegistrar.RESOLVER.createChildResolver(PATH))
.setAddHandler(new BufferPoolAdd())
.setRemoveHandler(ReloadRequiredRemoveStepHandler.INSTANCE)
.addCapabilities(IO_POOL_RUNTIME_CAPABILITY,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@
public class IOExtension extends SubsystemExtension<IOSubsystemSchema> {

public IOExtension() {
super(SubsystemConfiguration.of(IOSubsystemRegistrar.NAME, IOSubsystemModel.CURRENT, IOSubsystemRegistrar::new), SubsystemPersistence.of(IOSubsystemSchema.CURRENT));
super(SubsystemConfiguration.of(IOSubsystemResourceDescription.INSTANCE, IOSubsystemModel.CURRENT, IOSubsystemResourceRegistrar::new), SubsystemPersistence.of(IOSubsystemSchema.CURRENT));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@
public class IOExtensionTransformerRegistration extends SubsystemExtensionTransformerRegistration {

public IOExtensionTransformerRegistration() {
super(IOSubsystemRegistrar.NAME, IOSubsystemModel.CURRENT, IOSubsystemTransformationDescriptionFactory.INSTANCE);
super(IOSubsystemResourceDescription.INSTANCE, IOSubsystemModel.CURRENT, IOSubsystemTransformationDescriptionFactory.INSTANCE);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright The WildFly Authors
* SPDX-License-Identifier: Apache-2.0
*/

package org.wildfly.extension.io;

import java.util.stream.Stream;

import org.jboss.as.controller.AttributeDefinition;
import org.jboss.as.controller.SubsystemResourceDescription;
import org.jboss.as.controller.capability.RuntimeCapability;
import org.wildfly.io.IOServiceDescriptor;
import org.wildfly.subsystem.resource.capability.CapabilityReference;
import org.wildfly.subsystem.resource.capability.CapabilityReferenceAttributeDefinition;
import org.xnio.XnioWorker;

/**
* Describes the IO subsystem resource.
*/
public enum IOSubsystemResourceDescription implements SubsystemResourceDescription {
INSTANCE;

static final RuntimeCapability<Void> DEFAULT_WORKER_CAPABILITY = RuntimeCapability.Builder.of(IOServiceDescriptor.DEFAULT_WORKER).build();

static final CapabilityReferenceAttributeDefinition<XnioWorker> DEFAULT_WORKER = new CapabilityReferenceAttributeDefinition.Builder<>("default-worker", CapabilityReference.builder(DEFAULT_WORKER_CAPABILITY, IOServiceDescriptor.NAMED_WORKER).build())
.setRequired(false)
.build();

@Override
public String getName() {
return "io";
}

@Override
public Stream<AttributeDefinition> getAttributes() {
return Stream.of(DEFAULT_WORKER);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@

import org.jboss.as.controller.OperationContext;
import org.jboss.as.controller.OperationFailedException;
import org.jboss.as.controller.PathElement;
import org.jboss.as.controller.ResourceDefinition;
import org.jboss.as.controller.ResourceRegistration;
import org.jboss.as.controller.SubsystemRegistration;
import org.jboss.as.controller.capability.RuntimeCapability;
import org.jboss.as.controller.descriptions.ParentResourceDescriptionResolver;
Expand All @@ -26,8 +24,6 @@
import org.wildfly.subsystem.resource.ManagementResourceRegistrationContext;
import org.wildfly.subsystem.resource.ResourceDescriptor;
import org.wildfly.subsystem.resource.SubsystemResourceDefinitionRegistrar;
import org.wildfly.subsystem.resource.capability.CapabilityReference;
import org.wildfly.subsystem.resource.capability.CapabilityReferenceAttributeDefinition;
import org.wildfly.subsystem.resource.operation.ResourceOperationRuntimeHandler;
import org.wildfly.subsystem.service.ResourceServiceConfigurator;
import org.wildfly.subsystem.service.ResourceServiceInstaller;
Expand All @@ -38,32 +34,24 @@
/**
* @author <a href="mailto:[email protected]">Tomaz Cerar</a> (c) 2013 Red Hat Inc.
*/
class IOSubsystemRegistrar implements SubsystemResourceDefinitionRegistrar, ResourceServiceConfigurator {
class IOSubsystemResourceRegistrar implements SubsystemResourceDefinitionRegistrar, ResourceServiceConfigurator {

static final String NAME = "io";
static final PathElement PATH = SubsystemResourceDefinitionRegistrar.pathElement(NAME);
static final ParentResourceDescriptionResolver RESOLVER = new SubsystemResourceDescriptionResolver(NAME, IOSubsystemRegistrar.class);
static final ParentResourceDescriptionResolver RESOLVER = new SubsystemResourceDescriptionResolver(IOSubsystemResourceDescription.INSTANCE.getName(), IOSubsystemResourceRegistrar.class);

static final RuntimeCapability<Void> MAX_THREADS_CAPABILITY = RuntimeCapability.Builder.of(IOServiceDescriptor.MAX_THREADS).build();

static final RuntimeCapability<Void> DEFAULT_WORKER_CAPABILITY = RuntimeCapability.Builder.of(IOServiceDescriptor.DEFAULT_WORKER).build();

static final ModelNode LEGACY_DEFAULT_WORKER = new ModelNode("default");

static final CapabilityReferenceAttributeDefinition<XnioWorker> DEFAULT_WORKER = new CapabilityReferenceAttributeDefinition.Builder<>("default-worker", CapabilityReference.builder(DEFAULT_WORKER_CAPABILITY, IOServiceDescriptor.NAMED_WORKER).build())
.setRequired(false)
.build();

// Tracks max-threads for all workers
private final AtomicInteger maxThreads = new AtomicInteger();

@Override
public ManagementResourceRegistration register(SubsystemRegistration parent, ManagementResourceRegistrationContext context) {
ManagementResourceRegistration registration = parent.registerSubsystemModel(ResourceDefinition.builder(ResourceRegistration.of(PATH), RESOLVER).build());
ManagementResourceRegistration registration = parent.registerSubsystemModel(ResourceDefinition.builder(IOSubsystemResourceDescription.INSTANCE, RESOLVER).build());

ResourceDescriptor descriptor = ResourceDescriptor.builder(RESOLVER)
.addAttributes(List.of(DEFAULT_WORKER))
.addCapabilities(List.of(DEFAULT_WORKER_CAPABILITY, MAX_THREADS_CAPABILITY))
.addAttributes(IOSubsystemResourceDescription.INSTANCE.getAttributes().toList())
.addCapabilities(List.of(IOSubsystemResourceDescription.DEFAULT_WORKER_CAPABILITY, MAX_THREADS_CAPABILITY))
.withRuntimeHandler(ResourceOperationRuntimeHandler.configureParentService(this))
.build();
ManagementResourceRegistrar.of(descriptor).register(registration);
Expand All @@ -82,9 +70,9 @@ public ResourceServiceInstaller configure(OperationContext context, ModelNode mo
List<ResourceServiceInstaller> installers = new ArrayList<>(2);
installers.add(CapabilityServiceInstaller.builder(MAX_THREADS_CAPABILITY, AtomicInteger::intValue, Functions.constantSupplier(this.maxThreads)).build());

ServiceDependency<XnioWorker> defaultWorker = DEFAULT_WORKER.resolve(context, model);
ServiceDependency<XnioWorker> defaultWorker = IOSubsystemResourceDescription.DEFAULT_WORKER.resolve(context, model);
if (defaultWorker.isPresent()) {
installers.add(CapabilityServiceInstaller.builder(DEFAULT_WORKER_CAPABILITY, defaultWorker).build());
installers.add(CapabilityServiceInstaller.builder(IOSubsystemResourceDescription.DEFAULT_WORKER_CAPABILITY, defaultWorker).build());
}

return ResourceServiceInstaller.combine(installers);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,20 @@
package org.wildfly.extension.io;

import java.util.List;
import java.util.function.Predicate;
import java.util.stream.Stream;
import java.util.function.UnaryOperator;

import org.jboss.as.controller.PathAddress;
import org.jboss.as.controller.PersistentResourceXMLDescription;
import org.jboss.as.controller.PersistentSubsystemSchema;
import org.jboss.as.controller.ResourceDescription;
import org.jboss.as.controller.SubsystemSchema;
import org.jboss.as.controller.persistence.xml.ResourceXMLElement;
import org.jboss.as.controller.persistence.xml.SubsystemResourceXMLSchema;
import org.jboss.as.controller.xml.VersionedNamespace;
import org.jboss.dmr.ModelNode;
import org.jboss.staxmapper.IntVersion;
import org.wildfly.io.OptionAttributeDefinition;

/**
* Enumerates the supported schemas of the IO subsystem.
*/
public enum IOSubsystemSchema implements PersistentSubsystemSchema<IOSubsystemSchema> {
public enum IOSubsystemSchema implements SubsystemResourceXMLSchema<IOSubsystemSchema> {
VERSION_1_1(1, 1), // WildFly 8.1 - 10.1
VERSION_2_0(2, 0), // WildFly 11 - 12
VERSION_3_0(3, 0), // WildFly 13 - 31
Expand All @@ -32,7 +30,7 @@ public enum IOSubsystemSchema implements PersistentSubsystemSchema<IOSubsystemSc
private final VersionedNamespace<IntVersion, IOSubsystemSchema> namespace;

IOSubsystemSchema(int major, int minor) {
this.namespace = SubsystemSchema.createLegacySubsystemURN(IOSubsystemRegistrar.NAME, new IntVersion(major, minor));
this.namespace = SubsystemSchema.createLegacySubsystemURN(IOSubsystemResourceDescription.INSTANCE.getName(), new IntVersion(major, minor));
}

@Override
Expand All @@ -41,32 +39,29 @@ public VersionedNamespace<IntVersion, IOSubsystemSchema> getNamespace() {
}

@Override
public PersistentResourceXMLDescription getXMLDescription() {
PersistentResourceXMLDescription.Factory factory = PersistentResourceXMLDescription.factory(this);
PersistentResourceXMLDescription.Builder builder = factory.builder(IOSubsystemRegistrar.PATH);
if (this.since(VERSION_4_0)) {
builder.addAttribute(IOSubsystemRegistrar.DEFAULT_WORKER);
} else {
builder.setAdditionalOperationsGenerator(new PersistentResourceXMLDescription.AdditionalOperationsGenerator() {
public ResourceXMLElement getSubsystemResourceXMLElement() {
ResourceXMLElement.Builder.Factory factory = ResourceXMLElement.Builder.Factory.newInstance(this);
ResourceXMLElement.Builder builder = factory.createBuilder(IOSubsystemResourceDescription.INSTANCE);
if (!this.since(VERSION_4_0)) {
builder.excludeAttribute(IOSubsystemResourceDescription.DEFAULT_WORKER);
builder.withOperationTransformation(new UnaryOperator<>() {
@Override
public void additionalOperations(PathAddress address, ModelNode addOperation, List<ModelNode> operations) {
public ModelNode apply(ModelNode operation) {
// Apply "magic" default worker referenced by other subsystems
addOperation.get(IOSubsystemRegistrar.DEFAULT_WORKER.getName()).set(IOSubsystemRegistrar.LEGACY_DEFAULT_WORKER);
operation.get(IOSubsystemResourceDescription.DEFAULT_WORKER.getName()).set(IOSubsystemResourceRegistrar.LEGACY_DEFAULT_WORKER);
return operation;
}
});
}

Stream<OptionAttributeDefinition> workerAttributes = Stream.of(WorkerResourceDefinition.ATTRIBUTES);
ResourceXMLElement.Builder workerBuilder = factory.createBuilder(ResourceDescription.of(WorkerResourceDefinition.PATH, List.of(WorkerResourceDefinition.ATTRIBUTES)));
if (!this.since(VERSION_3_0)) {
workerAttributes = workerAttributes.filter(Predicate.not(WorkerResourceDefinition.WORKER_TASK_CORE_THREADS::equals));
workerBuilder.excludeAttribute(WorkerResourceDefinition.WORKER_TASK_CORE_THREADS);
}
PersistentResourceXMLDescription.Builder workerBuilder = factory.builder(WorkerResourceDefinition.PATH).addAttributes(workerAttributes);
if (this.since(VERSION_2_0)) {
workerBuilder.addChild(factory.builder(OutboundBindAddressResourceDefinition.PATH).addAttributes(OutboundBindAddressResourceDefinition.ATTRIBUTES.stream()).build());
workerBuilder.addChild(factory.createBuilder(ResourceDescription.of(OutboundBindAddressResourceDefinition.PATH, OutboundBindAddressResourceDefinition.ATTRIBUTES)).build());
}

return builder.addChild(workerBuilder.build())
.addChild(factory.builder(BufferPoolResourceDefinition.PATH).addAttributes(BufferPoolResourceDefinition.ATTRIBUTES.stream()).build())
.addChild(factory.createBuilder(ResourceDescription.of(BufferPoolResourceDefinition.PATH, BufferPoolResourceDefinition.ATTRIBUTES)).build())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ public TransformationDescription apply(ModelVersion version) {
ResourceTransformationDescriptionBuilder builder = TransformationDescriptionBuilder.Factory.createSubsystemInstance();
if (IOSubsystemModel.VERSION_6_0_0.requiresTransformation(version)) {
builder.getAttributeBuilder()
.setDiscard(new DiscardAttributeChecker.DiscardAttributeValueChecker(IOSubsystemRegistrar.LEGACY_DEFAULT_WORKER), IOSubsystemRegistrar.DEFAULT_WORKER)
.addRejectCheck(RejectAttributeChecker.DEFINED, IOSubsystemRegistrar.DEFAULT_WORKER)
.setDiscard(new DiscardAttributeChecker.DiscardAttributeValueChecker(IOSubsystemResourceRegistrar.LEGACY_DEFAULT_WORKER), IOSubsystemResourceDescription.DEFAULT_WORKER)
.addRejectCheck(RejectAttributeChecker.DEFINED, IOSubsystemResourceDescription.DEFAULT_WORKER)
.end();
}
return builder.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public class OutboundBindAddressResourceDefinition extends PersistentResourceDef
static final OutboundBindAddressResourceDefinition INSTANCE = new OutboundBindAddressResourceDefinition();

private OutboundBindAddressResourceDefinition() {
super(new SimpleResourceDefinition.Parameters(PATH, IOSubsystemRegistrar.RESOLVER.createChildResolver(PATH))
super(new SimpleResourceDefinition.Parameters(PATH, IOSubsystemResourceRegistrar.RESOLVER.createChildResolver(PATH))
.setAddHandler(new OutboundBindAddressAddHandler())
.setRemoveHandler(new OutboundBindAddressRemoveHandler())
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class WorkerResourceDefinition extends PersistentResourceDefinition {
private static final AttributeDefinition BUSY_WORKER_THREAD_COUNT = new SimpleAttributeDefinitionBuilder("busy-task-thread-count", ModelType.INT).build();

WorkerResourceDefinition(AtomicInteger maxThreads) {
super(new SimpleResourceDefinition.Parameters(PATH, IOSubsystemRegistrar.RESOLVER.createChildResolver(PATH))
super(new SimpleResourceDefinition.Parameters(PATH, IOSubsystemResourceRegistrar.RESOLVER.createChildResolver(PATH))
.setAddHandler(new WorkerAdd(maxThreads))
.setRemoveHandler(ReloadRequiredRemoveStepHandler.INSTANCE)
.addCapabilities(CAPABILITY));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class WorkerServerDefinition extends SimpleResourceDefinition {
static final ModelNode NO_METRICS = new ModelNode(IOLogger.ROOT_LOGGER.noMetrics());

WorkerServerDefinition() {
super(new Parameters(PATH, IOSubsystemRegistrar.RESOLVER.createChildResolver(PathElement.pathElement(WorkerResourceDefinition.PATH.getKey(), PATH.getKey())))
super(new Parameters(PATH, IOSubsystemResourceRegistrar.RESOLVER.createChildResolver(PathElement.pathElement(WorkerResourceDefinition.PATH.getKey(), PATH.getKey())))
.setRuntime());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public static Iterable<IOSubsystemSchema> parameters() {
}

public IOSubsystemTestCase(IOSubsystemSchema schema) {
super(IOSubsystemRegistrar.NAME, new IOExtension(), schema, IOSubsystemSchema.CURRENT);
super(IOSubsystemResourceDescription.INSTANCE.getName(), new IOExtension(), schema, IOSubsystemSchema.CURRENT);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public static Iterable<ModelTestControllerVersion> parameters() {
private final ModelVersion version;

public IOSubsystemTransformerTestCase(ModelTestControllerVersion controller) {
super(IOSubsystemRegistrar.NAME, new IOExtension());
super(IOSubsystemResourceDescription.INSTANCE.getName(), new IOExtension());
this.controller = controller;
this.version = this.getModelVersion().getVersion();
this.additionalInitialization = AdditionalInitialization.MANAGEMENT;
Expand Down Expand Up @@ -129,10 +129,10 @@ public void testRejections() throws Exception {

private FailedOperationTransformationConfig createFailedOperationTransformationConfig() {
FailedOperationTransformationConfig config = new FailedOperationTransformationConfig();
PathAddress subsystemAddress = PathAddress.pathAddress(IOSubsystemRegistrar.PATH);
PathAddress subsystemAddress = PathAddress.pathAddress(IOSubsystemResourceDescription.INSTANCE.getPathElement());

if (IOSubsystemModel.VERSION_6_0_0.requiresTransformation(this.version)) {
config.addFailedAttribute(subsystemAddress, new FailedOperationTransformationConfig.NewAttributesConfig(IOSubsystemRegistrar.DEFAULT_WORKER.getName()));
config.addFailedAttribute(subsystemAddress, new FailedOperationTransformationConfig.NewAttributesConfig(IOSubsystemResourceDescription.DEFAULT_WORKER.getName()));
}

return config;
Expand Down

0 comments on commit 70e0f35

Please sign in to comment.