Skip to content

Commit

Permalink
Merge pull request #29 from gaol/issue-25
Browse files Browse the repository at this point in the history
[issue-25] Move to the new subsystem API
  • Loading branch information
gaol authored Oct 15, 2024
2 parents a2148b4 + 63c7d74 commit a23ab10
Show file tree
Hide file tree
Showing 20 changed files with 271 additions and 293 deletions.
5 changes: 5 additions & 0 deletions subsystem/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@
<artifactId>wildfly-server</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.wildfly.core</groupId>
<artifactId>wildfly-subsystem</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.wildfly</groupId>
<artifactId>wildfly-ee</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
*/
public class NamedVertxOptions {

public static final NamedVertxOptions DEFAULT = new NamedVertxOptions("", new VertxOptions());

/** The name of the configured VertxOptions **/
private final String name;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import org.jboss.msc.service.StopContext;
import org.wildfly.extension.vertx.logging.VertxLogger;

import java.util.Objects;
import java.util.concurrent.CompletableFuture;
import java.util.function.Consumer;
import java.util.function.Supplier;
Expand All @@ -36,10 +35,14 @@ public class VertxProxyService implements Service, VertxConstants {
final Consumer<VertxProxy> vertxProxytConsumer;

static void installService(OperationContext context, String optionName) {
Objects.requireNonNull(optionName, "optionName cannot be null.");
CapabilityServiceBuilder<?> vertxServiceBuilder = context.getCapabilityServiceTarget().addService();
Consumer<VertxProxy> vertxProxytConsumer = vertxServiceBuilder.provides(VERTX_RUNTIME_CAPABILITY);
Supplier<NamedVertxOptions> optionsSupplier = vertxServiceBuilder.requiresCapability(VERTX_OPTIONS_CAPABILITY.getName(), NamedVertxOptions.class, optionName);
final Supplier<NamedVertxOptions> optionsSupplier;
if (optionName == null) {
optionsSupplier = () -> NamedVertxOptions.DEFAULT;
} else {
optionsSupplier = vertxServiceBuilder.requiresCapability(VERTX_OPTIONS_CAPABILITY.getName(), NamedVertxOptions.class, optionName);
}
VertxProxyService vertxProxyService = new VertxProxyService(optionName, optionsSupplier, vertxProxytConsumer);
vertxServiceBuilder.setInstance(vertxProxyService);
vertxServiceBuilder.setInitialMode(ServiceController.Mode.ACTIVE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,8 @@ static class VertxResourceAdd extends AbstractAddStepHandler {

@Override
protected void performRuntime(OperationContext context, ModelNode operation, Resource resource) throws OperationFailedException {
String optionName = operation.hasDefined(ATTR_OPTION_NAME) ? VertxAttributes.OPTION_NAME.resolveModelAttribute(context, operation).asString() : null;
if (optionName != null) {
VertxProxyService.installService(context, optionName);
}
final String optionName = operation.hasDefined(ATTR_OPTION_NAME) ? VertxAttributes.OPTION_NAME.resolveModelAttribute(context, operation).asString() : null;
VertxProxyService.installService(context, optionName);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@
*/
public class VertxSubsystemDefinition extends SimpleResourceDefinition {

static final VertxSubsystemDefinition INSTANCE = new VertxSubsystemDefinition();

VertxSubsystemDefinition() {
super(new SimpleResourceDefinition.Parameters(VertxSubsystemExtension.SUBSYSTEM_PATH,
VertxSubsystemExtension.getResourceDescriptionResolver(VertxSubsystemExtension.SUBSYSTEM_NAME))
VertxSubsystemRegistrar.RESOLVER)
.setAddHandler(new VertxSubsystemAdd())
.setRemoveHandler(ReloadRequiredRemoveStepHandler.INSTANCE)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,24 @@

package org.wildfly.extension.vertx;

import org.jboss.as.controller.Extension;
import org.jboss.as.controller.ExtensionContext;
import org.jboss.as.controller.ModelVersion;
import org.jboss.as.controller.PathElement;
import org.jboss.as.controller.SubsystemRegistration;
import org.jboss.as.controller.SubsystemModel;
import org.jboss.as.controller.descriptions.StandardResourceDescriptionResolver;
import org.jboss.as.controller.operations.common.GenericSubsystemDescribeHandler;
import org.jboss.as.controller.parsing.ExtensionParsingContext;
import org.jboss.as.controller.registry.ManagementResourceRegistration;
import org.jboss.as.version.Stability;
import org.wildfly.subsystem.SubsystemConfiguration;
import org.wildfly.subsystem.SubsystemExtension;
import org.wildfly.subsystem.SubsystemPersistence;

import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SUBSYSTEM;
import static org.wildfly.extension.vertx.VertxConstants.EXTENSION_STABILITY;
import static org.wildfly.extension.vertx.logging.VertxLogger.VERTX_LOGGER;

/**
* @author <a href="aoingl@gmail.com">Lin Gao</a>
*/
public class VertxSubsystemExtension implements Extension {
public static final String EXTENSION_NAME = "org.wildfly.extension.vertx";
public class VertxSubsystemExtension extends SubsystemExtension<VertxSubsystemSchema> {
public static final String SUBSYSTEM_NAME = "vertx";

protected static final ModelVersion VERSION_1_0_0 = ModelVersion.create(1, 0, 0);
private static final ModelVersion CURRENT_MODEL_VERSION = VERSION_1_0_0;

protected static final PathElement SUBSYSTEM_PATH = PathElement.pathElement(SUBSYSTEM, SUBSYSTEM_NAME);
private static final String RESOURCE_NAME = VertxSubsystemExtension.class.getPackage().getName() + ".LocalDescriptions";

Expand All @@ -44,23 +37,34 @@ static StandardResourceDescriptionResolver getResourceDescriptionResolver(final
return new StandardResourceDescriptionResolver(prefix.toString(), RESOURCE_NAME, VertxSubsystemExtension.class.getClassLoader(), true, false);
}

public VertxSubsystemExtension() {
super(SubsystemConfiguration.of(SUBSYSTEM_NAME, VertxSubsystemModel.CURRENT, VertxSubsystemRegistrar::new),
SubsystemPersistence.of(VertxSubsystemSchema.CURRENT));
}

@Override
public Stability getStability() {
return EXTENSION_STABILITY;
}

@Override
public void initialize(ExtensionContext context) {
VERTX_LOGGER.debug("Activating WildFly Vertx Extension.");
final SubsystemRegistration subsystem = context.registerSubsystem(SUBSYSTEM_NAME, CURRENT_MODEL_VERSION);
final ManagementResourceRegistration registration = subsystem.registerSubsystemModel(new VertxSubsystemDefinition());
registration.registerOperationHandler(GenericSubsystemDescribeHandler.DEFINITION, GenericSubsystemDescribeHandler.INSTANCE);
subsystem.registerXMLElementWriter(VertxSubsystemParser_1_0::new);
}
/**
* Model for the vertx subsystem.
*/
enum VertxSubsystemModel implements SubsystemModel {
VERSION_1_0_0(1, 0, 0),
;

@Override
public void initializeParsers(ExtensionParsingContext context) {
context.setSubsystemXmlMapping(SUBSYSTEM_NAME, VertxSubsystemParser_1_0.NAMESPACE, VertxSubsystemParser_1_0::new);
static final VertxSubsystemModel CURRENT = VERSION_1_0_0;
private final ModelVersion version;

VertxSubsystemModel(int major, int minor, int micro) {
this.version = ModelVersion.create(major, minor, micro);
}

@Override
public ModelVersion getVersion() {
return version;
}
}

}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright The WildFly Authors
* SPDX-License-Identifier: Apache-2.0
*/
package org.wildfly.extension.vertx;

import org.jboss.as.controller.SubsystemRegistration;
import org.jboss.as.controller.descriptions.ParentResourceDescriptionResolver;
import org.jboss.as.controller.descriptions.SubsystemResourceDescriptionResolver;
import org.jboss.as.controller.registry.ManagementResourceRegistration;
import org.wildfly.subsystem.resource.ManagementResourceRegistrationContext;
import org.wildfly.subsystem.resource.SubsystemResourceDefinitionRegistrar;

import static org.wildfly.extension.vertx.VertxSubsystemExtension.SUBSYSTEM_NAME;

/**
* @author <a href="mailto:aoingl@gmail.com">Lin Gao</a>
*/
public class VertxSubsystemRegistrar implements SubsystemResourceDefinitionRegistrar {
static final ParentResourceDescriptionResolver RESOLVER = new SubsystemResourceDescriptionResolver(SUBSYSTEM_NAME,
VertxSubsystemRegistrar.class);

@Override
public ManagementResourceRegistration register(SubsystemRegistration parent,
ManagementResourceRegistrationContext managementResourceRegistrationContext) {
return parent.registerSubsystemModel(VertxSubsystemDefinition.INSTANCE);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Copyright The WildFly Authors
* SPDX-License-Identifier: Apache-2.0
*/
package org.wildfly.extension.vertx;

import org.jboss.as.controller.AttributeDefinition;
import org.jboss.as.controller.PersistentResourceXMLDescription;
import org.jboss.as.controller.PersistentSubsystemSchema;
import org.jboss.as.controller.SubsystemSchema;
import org.jboss.as.controller.xml.VersionedNamespace;
import org.jboss.as.version.Stability;
import org.jboss.staxmapper.IntVersion;

import static org.jboss.as.controller.PersistentResourceXMLDescription.builder;
import static org.jboss.as.controller.PersistentResourceXMLDescription.decorator;
import static org.wildfly.extension.vertx.VertxConstants.ELEMENT_VERTX_OPTIONS;
import static org.wildfly.extension.vertx.VertxSubsystemExtension.SUBSYSTEM_NAME;
import static org.wildfly.extension.vertx.VertxSubsystemExtension.SUBSYSTEM_PATH;

/**
* @author <a href="mailto:aoingl@gmail.com">Lin Gao</a>
*/
enum VertxSubsystemSchema implements PersistentSubsystemSchema<VertxSubsystemSchema> {
VERSION_1_0_PREVIEW(1, 0,Stability.PREVIEW),
;

static final VertxSubsystemSchema CURRENT = VERSION_1_0_PREVIEW;

private final VersionedNamespace<IntVersion, VertxSubsystemSchema> namespace;

VertxSubsystemSchema(int major, int minor, Stability stability) {
this.namespace = SubsystemSchema.createSubsystemURN(SUBSYSTEM_NAME, stability,
new IntVersion(major, minor));
}

@Override
public VersionedNamespace<IntVersion, VertxSubsystemSchema> getNamespace() {
return namespace;
}

@Override
public PersistentResourceXMLDescription getXMLDescription() {
return builder(SUBSYSTEM_PATH, namespace)
.addChild(
builder(VertxResourceDefinition.INSTANCE.getPathElement())
.addAttributes(VertxAttributes.getSimpleAttributes().toArray(new AttributeDefinition[0]))
)
.addChild(
decorator(ELEMENT_VERTX_OPTIONS)
.addChild(
builder(VertxOptionFileResourceDefinition.INSTANCE.getPathElement())
.addAttributes(VertxOptionsAttributes.getVertxOptionsFileAttributes().toArray(new AttributeDefinition[0]))
)
.addChild(
builder(VertxOptionsResourceDefinition.INSTANCE.getPathElement())
.addAttributes(VertxOptionsAttributes.getVertxOptionsAttributes().toArray(new AttributeDefinition[0]))
)
.addChild(
builder(AddressResolverResourceDefinition.INSTANCE.getPathElement())
.addAttributes(AddressResolverResourceDefinition.getVertxAddressResolverOptionsAttrs().toArray(new AttributeDefinition[0]))
)
)
.build();
}
}
4 changes: 2 additions & 2 deletions subsystem/src/main/resources/schema/wildfly-vertx_1_0_0.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
~ SPDX-License-Identifier: Apache-2.0
-->
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="urn:wildfly:vertx:1.0"
xmlns="urn:wildfly:vertx:1.0"
targetNamespace="urn:wildfly:vertx:preview:1.0"
xmlns="urn:wildfly:vertx:preview:1.0"
elementFormDefault="qualified"
attributeFormDefault="unqualified"
version="1.0">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Copyright The WildFly Authors
* SPDX-License-Identifier: Apache-2.0
*/
package org.wildfly.extension.vertx;

import org.jboss.as.controller.capability.registry.RuntimeCapabilityRegistry;
import org.jboss.as.controller.extension.ExtensionRegistry;
import org.jboss.as.controller.registry.ManagementResourceRegistration;
import org.jboss.as.controller.registry.Resource;
import org.jboss.as.subsystem.test.AbstractSubsystemBaseTest;
import org.jboss.as.subsystem.test.AdditionalInitialization;
import org.jboss.as.version.Stability;

import java.io.IOException;

import static org.wildfly.extension.vertx.VertxSubsystemExtension.SUBSYSTEM_NAME;

/**
* Standard subsystem test.
*
* @author <a href="aoingl@gmail.com">Lin Gao</a>
*/
public class SubsystemTestCase extends AbstractSubsystemBaseTest {

public SubsystemTestCase() {
super(SUBSYSTEM_NAME, new VertxSubsystemExtension(), Stability.PREVIEW);
}

@Override
protected String getSubsystemXml() throws IOException {
// test configuration put in standalone.xml
return readResource("vertx-options-full.xml");
}

@Override
protected String getSubsystemXsdPath() {
return "schema/wildfly-vertx_1_0_0.xsd";
}

protected AdditionalInitialization createAdditionalInitialization() {
return new AdditionalInitialization.ManagementAdditionalInitialization(Stability.PREVIEW) {

@Override
protected void initializeExtraSubystemsAndModel(ExtensionRegistry extensionRegistry, Resource rootResource,
ManagementResourceRegistration rootRegistration, RuntimeCapabilityRegistry capabilityRegistry) {
super.initializeExtraSubystemsAndModel(extensionRegistry, rootResource, rootRegistration, capabilityRegistry);
registerCapabilities(capabilityRegistry, "org.wildfly.weld");
}
};
}

}
Loading

0 comments on commit a23ab10

Please sign in to comment.