diff --git a/io/subsystem/src/main/java/org/wildfly/extension/io/BufferPoolResourceDefinition.java b/io/subsystem/src/main/java/org/wildfly/extension/io/BufferPoolResourceDefinition.java index 9453d53e933..b62b97e00ad 100644 --- a/io/subsystem/src/main/java/org/wildfly/extension/io/BufferPoolResourceDefinition.java +++ b/io/subsystem/src/main/java/org/wildfly/extension/io/BufferPoolResourceDefinition.java @@ -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, diff --git a/io/subsystem/src/main/java/org/wildfly/extension/io/IOExtension.java b/io/subsystem/src/main/java/org/wildfly/extension/io/IOExtension.java index 34345f128c1..18fa370d58f 100644 --- a/io/subsystem/src/main/java/org/wildfly/extension/io/IOExtension.java +++ b/io/subsystem/src/main/java/org/wildfly/extension/io/IOExtension.java @@ -17,6 +17,6 @@ public class IOExtension extends SubsystemExtension { 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)); } } diff --git a/io/subsystem/src/main/java/org/wildfly/extension/io/IOExtensionTransformerRegistration.java b/io/subsystem/src/main/java/org/wildfly/extension/io/IOExtensionTransformerRegistration.java index 2eb51a464d9..9922459e6da 100644 --- a/io/subsystem/src/main/java/org/wildfly/extension/io/IOExtensionTransformerRegistration.java +++ b/io/subsystem/src/main/java/org/wildfly/extension/io/IOExtensionTransformerRegistration.java @@ -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); } } diff --git a/io/subsystem/src/main/java/org/wildfly/extension/io/IOSubsystemResourceDescription.java b/io/subsystem/src/main/java/org/wildfly/extension/io/IOSubsystemResourceDescription.java new file mode 100644 index 00000000000..1019b9f60dd --- /dev/null +++ b/io/subsystem/src/main/java/org/wildfly/extension/io/IOSubsystemResourceDescription.java @@ -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 DEFAULT_WORKER_CAPABILITY = RuntimeCapability.Builder.of(IOServiceDescriptor.DEFAULT_WORKER).build(); + + static final CapabilityReferenceAttributeDefinition 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 getAttributes() { + return Stream.of(DEFAULT_WORKER); + } +} diff --git a/io/subsystem/src/main/java/org/wildfly/extension/io/IOSubsystemRegistrar.java b/io/subsystem/src/main/java/org/wildfly/extension/io/IOSubsystemResourceRegistrar.java similarity index 69% rename from io/subsystem/src/main/java/org/wildfly/extension/io/IOSubsystemRegistrar.java rename to io/subsystem/src/main/java/org/wildfly/extension/io/IOSubsystemResourceRegistrar.java index ca603c1282c..39d9ad39ae4 100644 --- a/io/subsystem/src/main/java/org/wildfly/extension/io/IOSubsystemRegistrar.java +++ b/io/subsystem/src/main/java/org/wildfly/extension/io/IOSubsystemResourceRegistrar.java @@ -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; @@ -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; @@ -38,32 +34,24 @@ /** * @author Tomaz Cerar (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 MAX_THREADS_CAPABILITY = RuntimeCapability.Builder.of(IOServiceDescriptor.MAX_THREADS).build(); - static final RuntimeCapability DEFAULT_WORKER_CAPABILITY = RuntimeCapability.Builder.of(IOServiceDescriptor.DEFAULT_WORKER).build(); - static final ModelNode LEGACY_DEFAULT_WORKER = new ModelNode("default"); - static final CapabilityReferenceAttributeDefinition 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); @@ -82,9 +70,9 @@ public ResourceServiceInstaller configure(OperationContext context, ModelNode mo List installers = new ArrayList<>(2); installers.add(CapabilityServiceInstaller.builder(MAX_THREADS_CAPABILITY, AtomicInteger::intValue, Functions.constantSupplier(this.maxThreads)).build()); - ServiceDependency defaultWorker = DEFAULT_WORKER.resolve(context, model); + ServiceDependency 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); diff --git a/io/subsystem/src/main/java/org/wildfly/extension/io/IOSubsystemSchema.java b/io/subsystem/src/main/java/org/wildfly/extension/io/IOSubsystemSchema.java index 30e30890da5..9ed74f0c9dc 100644 --- a/io/subsystem/src/main/java/org/wildfly/extension/io/IOSubsystemSchema.java +++ b/io/subsystem/src/main/java/org/wildfly/extension/io/IOSubsystemSchema.java @@ -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 { +public enum IOSubsystemSchema implements SubsystemResourceXMLSchema { 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 @@ -32,7 +30,7 @@ public enum IOSubsystemSchema implements PersistentSubsystemSchema 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 @@ -41,32 +39,29 @@ public VersionedNamespace 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 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 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.appendChild(factory.createBuilder(ResourceDescription.of(OutboundBindAddressResourceDefinition.PATH, OutboundBindAddressResourceDefinition.ATTRIBUTES)).build()); } - - return builder.addChild(workerBuilder.build()) - .addChild(factory.builder(BufferPoolResourceDefinition.PATH).addAttributes(BufferPoolResourceDefinition.ATTRIBUTES.stream()).build()) + return builder.appendChild(workerBuilder.build()) + .appendChild(factory.createBuilder(ResourceDescription.of(BufferPoolResourceDefinition.PATH, BufferPoolResourceDefinition.ATTRIBUTES)).build()) .build(); } } diff --git a/io/subsystem/src/main/java/org/wildfly/extension/io/IOSubsystemTransformationDescriptionFactory.java b/io/subsystem/src/main/java/org/wildfly/extension/io/IOSubsystemTransformationDescriptionFactory.java index fc25a8a59da..c3285854fba 100644 --- a/io/subsystem/src/main/java/org/wildfly/extension/io/IOSubsystemTransformationDescriptionFactory.java +++ b/io/subsystem/src/main/java/org/wildfly/extension/io/IOSubsystemTransformationDescriptionFactory.java @@ -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(); diff --git a/io/subsystem/src/main/java/org/wildfly/extension/io/OutboundBindAddressResourceDefinition.java b/io/subsystem/src/main/java/org/wildfly/extension/io/OutboundBindAddressResourceDefinition.java index daae9ec665f..d40ba3a1bea 100644 --- a/io/subsystem/src/main/java/org/wildfly/extension/io/OutboundBindAddressResourceDefinition.java +++ b/io/subsystem/src/main/java/org/wildfly/extension/io/OutboundBindAddressResourceDefinition.java @@ -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()) ); diff --git a/io/subsystem/src/main/java/org/wildfly/extension/io/WorkerResourceDefinition.java b/io/subsystem/src/main/java/org/wildfly/extension/io/WorkerResourceDefinition.java index db17ee3abf5..a2462805f45 100644 --- a/io/subsystem/src/main/java/org/wildfly/extension/io/WorkerResourceDefinition.java +++ b/io/subsystem/src/main/java/org/wildfly/extension/io/WorkerResourceDefinition.java @@ -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)); diff --git a/io/subsystem/src/main/java/org/wildfly/extension/io/WorkerServerDefinition.java b/io/subsystem/src/main/java/org/wildfly/extension/io/WorkerServerDefinition.java index 659646a9d27..1365725736a 100644 --- a/io/subsystem/src/main/java/org/wildfly/extension/io/WorkerServerDefinition.java +++ b/io/subsystem/src/main/java/org/wildfly/extension/io/WorkerServerDefinition.java @@ -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()); } diff --git a/io/tests/src/test/java/org/wildfly/extension/io/IOSubsystemTestCase.java b/io/tests/src/test/java/org/wildfly/extension/io/IOSubsystemTestCase.java index 39e3a62f326..1468c7b1db5 100644 --- a/io/tests/src/test/java/org/wildfly/extension/io/IOSubsystemTestCase.java +++ b/io/tests/src/test/java/org/wildfly/extension/io/IOSubsystemTestCase.java @@ -45,7 +45,7 @@ public static Iterable parameters() { } public IOSubsystemTestCase(IOSubsystemSchema schema) { - super(IOSubsystemRegistrar.NAME, new IOExtension(), schema, IOSubsystemSchema.CURRENT); + super(IOSubsystemResourceDescription.INSTANCE.getName(), new IOExtension(), schema, IOSubsystemSchema.CURRENT); } @Test diff --git a/io/tests/src/test/java/org/wildfly/extension/io/IOSubsystemTransformerTestCase.java b/io/tests/src/test/java/org/wildfly/extension/io/IOSubsystemTransformerTestCase.java index ec8ff7f6ff2..0cc7291489a 100644 --- a/io/tests/src/test/java/org/wildfly/extension/io/IOSubsystemTransformerTestCase.java +++ b/io/tests/src/test/java/org/wildfly/extension/io/IOSubsystemTransformerTestCase.java @@ -40,7 +40,7 @@ public static Iterable 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; @@ -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;