From 5ff78ffb8ae2de419e22d27058afdba4b45a5a77 Mon Sep 17 00:00:00 2001 From: Lin Gao Date: Thu, 28 Nov 2024 21:58:46 +0800 Subject: [PATCH] [Issue-43] Drop vertx-option-file resource --- ...bstractVertxOptionsResourceDefinition.java | 2 +- .../vertx/NamedVertxOptionsService.java | 8 +- .../VertxOptionFileResourceDefinition.java | 106 ------------------ .../vertx/VertxSubsystemDefinition.java | 1 - .../extension/vertx/VertxSubsystemSchema.java | 4 - .../vertx/LocalDescriptions.properties | 5 - .../resources/schema/wildfly-vertx_1_0_0.xsd | 14 --- 7 files changed, 3 insertions(+), 137 deletions(-) delete mode 100644 subsystem/src/main/java/org/wildfly/extension/vertx/VertxOptionFileResourceDefinition.java diff --git a/subsystem/src/main/java/org/wildfly/extension/vertx/AbstractVertxOptionsResourceDefinition.java b/subsystem/src/main/java/org/wildfly/extension/vertx/AbstractVertxOptionsResourceDefinition.java index 0caf597..af2ed26 100644 --- a/subsystem/src/main/java/org/wildfly/extension/vertx/AbstractVertxOptionsResourceDefinition.java +++ b/subsystem/src/main/java/org/wildfly/extension/vertx/AbstractVertxOptionsResourceDefinition.java @@ -39,7 +39,7 @@ protected AbstractVertxOptionsResourceDefinition(SimpleResourceDefinition.Parame protected static class VertxOptionRemoveHandler extends AbstractVertxOptionRemoveHandler { @Override protected void doPerform(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException { - ServiceName vertxServiceName = VertxOptionFileResourceDefinition.VERTX_OPTIONS_CAPABILITY.getCapabilityServiceName(context.getCurrentAddressValue()); + ServiceName vertxServiceName = VERTX_OPTIONS_CAPABILITY.getCapabilityServiceName(context.getCurrentAddressValue()); context.removeService(vertxServiceName); } diff --git a/subsystem/src/main/java/org/wildfly/extension/vertx/NamedVertxOptionsService.java b/subsystem/src/main/java/org/wildfly/extension/vertx/NamedVertxOptionsService.java index d69ef77..869cc3a 100644 --- a/subsystem/src/main/java/org/wildfly/extension/vertx/NamedVertxOptionsService.java +++ b/subsystem/src/main/java/org/wildfly/extension/vertx/NamedVertxOptionsService.java @@ -22,6 +22,7 @@ import java.util.function.Consumer; import java.util.function.Supplier; +import static org.wildfly.extension.vertx.AbstractVertxOptionsResourceDefinition.VERTX_OPTIONS_CAPABILITY; import static org.wildfly.extension.vertx.VertxConstants.ATTR_FS_FILE_CACHE_DIR; import static org.wildfly.extension.vertx.VertxConstants.ELEMENT_VERTX_OPTION_ADDRESS_RESOLVER; @@ -36,11 +37,6 @@ public class NamedVertxOptionsService implements Service { private final Supplier serverEnvironmentSupplier; private final boolean defaultFileCacheDir; - NamedVertxOptionsService(NamedVertxOptions namedVertxOptions, - Consumer consumer) { - this(namedVertxOptions, null, null, false, consumer); - } - NamedVertxOptionsService(NamedVertxOptions namedVertxOptions, Supplier addressResolverOptionsSupplier, Supplier serverEnvironmentSupplier, @@ -65,7 +61,7 @@ public class NamedVertxOptionsService implements Service { static void installVertxOptionsService(OperationContext context, ModelNode operation) throws OperationFailedException { final String name = context.getCurrentAddressValue(); VertxOptions vertxOptions = VertxOptionsResourceDefinition.parseOptions(operation); - ServiceName vertxServiceName = VertxOptionFileResourceDefinition.VERTX_OPTIONS_CAPABILITY.getCapabilityServiceName(name); + ServiceName vertxServiceName = VERTX_OPTIONS_CAPABILITY.getCapabilityServiceName(name); ServiceBuilder vertxServiceBuilder = context.getCapabilityServiceTarget().addService(); Supplier addressResolverOptionsSupplier = null; if (operation.hasDefined(ELEMENT_VERTX_OPTION_ADDRESS_RESOLVER)) { diff --git a/subsystem/src/main/java/org/wildfly/extension/vertx/VertxOptionFileResourceDefinition.java b/subsystem/src/main/java/org/wildfly/extension/vertx/VertxOptionFileResourceDefinition.java deleted file mode 100644 index 8495402..0000000 --- a/subsystem/src/main/java/org/wildfly/extension/vertx/VertxOptionFileResourceDefinition.java +++ /dev/null @@ -1,106 +0,0 @@ -/* - * Copyright The WildFly Authors - * SPDX-License-Identifier: Apache-2.0 - */ -package org.wildfly.extension.vertx; - -import io.vertx.core.VertxOptions; -import io.vertx.core.json.JsonObject; -import org.jboss.as.controller.AbstractAddStepHandler; -import org.jboss.as.controller.AttributeDefinition; -import org.jboss.as.controller.OperationContext; -import org.jboss.as.controller.OperationFailedException; -import org.jboss.as.controller.PathElement; -import org.jboss.as.controller.SimpleResourceDefinition; -import org.jboss.as.controller.registry.ManagementResourceRegistration; -import org.jboss.as.controller.registry.Resource; -import org.jboss.as.server.ServerEnvironment; -import org.jboss.as.server.ServerEnvironmentService; -import org.jboss.dmr.ModelNode; -import org.jboss.msc.service.ServiceBuilder; -import org.jboss.msc.service.ServiceController; -import org.jboss.msc.service.ServiceName; - -import java.io.File; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.function.Consumer; -import java.util.function.Supplier; - -import static org.wildfly.extension.vertx.VertxConstants.ATTR_PATH; -import static org.wildfly.extension.vertx.VertxConstants.ELEMENT_VERTX_OPTIONS_FILE; -import static org.wildfly.extension.vertx.logging.VertxLogger.VERTX_LOGGER; - -/** - * @author Lin Gao - */ -class VertxOptionFileResourceDefinition extends AbstractVertxOptionsResourceDefinition { - - static VertxOptionFileResourceDefinition INSTANCE = new VertxOptionFileResourceDefinition(); - - VertxOptionFileResourceDefinition() { - super(new SimpleResourceDefinition.Parameters(PathElement.pathElement(ELEMENT_VERTX_OPTIONS_FILE), - VertxSubsystemExtension.getResourceDescriptionResolver(VertxSubsystemExtension.SUBSYSTEM_NAME, ELEMENT_VERTX_OPTIONS_FILE)) - .setAddHandler(new VertxOptionFileAddHandler()) - .setRemoveHandler(new VertxOptionRemoveHandler()) - .setCapabilities(VERTX_OPTIONS_CAPABILITY) - ); - } - - @Override - public void registerAttributes(ManagementResourceRegistration resourceRegistration) { - super.registerAttributes(resourceRegistration); - AttrWriteHandler handler = new AttrWriteHandler(); - for (AttributeDefinition attr : VertxOptionsAttributes.getVertxOptionsFileAttributes()) { - resourceRegistration.registerReadWriteAttribute(attr, null, handler); - } - } - - static class VertxOptionFileAddHandler extends AbstractAddStepHandler { - - @Override - protected void performRuntime(OperationContext context, ModelNode operation, Resource resource) throws OperationFailedException { - final String name = context.getCurrentAddressValue(); - final String optionFilePath = operation.hasDefined(ATTR_PATH) ? VertxOptionsAttributes.VERTX_OPTION_FILE_PATH.resolveModelAttribute(context, operation).asString() : null; - if (optionFilePath == null || optionFilePath.trim().isEmpty()) { - throw VERTX_LOGGER.noOptionsFileSpecified(name); - } - ServiceName vertxServiceName = VertxOptionFileResourceDefinition.VERTX_OPTIONS_CAPABILITY.getCapabilityServiceName(name); - ServiceBuilder vertxServiceBuilder = context.getCapabilityServiceTarget().addService(); - Consumer consumer = vertxServiceBuilder.provides(vertxServiceName); - Supplier serverEnvSupplier = vertxServiceBuilder.requires(ServerEnvironmentService.SERVICE_NAME); - VertxOptions vertxOptions = new VertxOptions(readJsonFromFile(optionFilePath, serverEnvSupplier.get().getServerConfigurationDir())); - NamedVertxOptions namedVertxOptions = new NamedVertxOptions(name, vertxOptions); - vertxServiceBuilder.setInstance(new NamedVertxOptionsService(namedVertxOptions, consumer)); - vertxServiceBuilder - .setInitialMode(ServiceController.Mode.ACTIVE) - .install(); - } - - } - - static JsonObject readJsonFromFile(String vertxOptionsFile, File configDir) throws OperationFailedException { - Path path = Paths.get(vertxOptionsFile); - if (path.isAbsolute()) { - throw VERTX_LOGGER.absoluteDirectoryNotAllowed(vertxOptionsFile); - } - path = configDir.toPath().resolve(vertxOptionsFile); - if (Files.exists(path) && Files.isReadable(path)) { - String jsonContent; - try { - jsonContent = Files.readString(path); - } catch (IOException e) { - throw VERTX_LOGGER.failedToReadVertxOptions(path.toString(), e); - } - if (jsonContent != null) { - return new JsonObject(jsonContent); - } - return new JsonObject(); - } else { - throw VERTX_LOGGER.cannotReadVertxOptionsFile(path.toString()); - } - } - -} diff --git a/subsystem/src/main/java/org/wildfly/extension/vertx/VertxSubsystemDefinition.java b/subsystem/src/main/java/org/wildfly/extension/vertx/VertxSubsystemDefinition.java index 2408d78..426fb8c 100644 --- a/subsystem/src/main/java/org/wildfly/extension/vertx/VertxSubsystemDefinition.java +++ b/subsystem/src/main/java/org/wildfly/extension/vertx/VertxSubsystemDefinition.java @@ -39,7 +39,6 @@ public class VertxSubsystemDefinition extends SimpleResourceDefinition { public void registerChildren(ManagementResourceRegistration resourceRegistration) { super.registerChildren(resourceRegistration); resourceRegistration.registerSubModel(VertxResourceDefinition.INSTANCE); - resourceRegistration.registerSubModel(VertxOptionFileResourceDefinition.INSTANCE); resourceRegistration.registerSubModel(VertxOptionsResourceDefinition.INSTANCE); resourceRegistration.registerSubModel(AddressResolverResourceDefinition.INSTANCE); } diff --git a/subsystem/src/main/java/org/wildfly/extension/vertx/VertxSubsystemSchema.java b/subsystem/src/main/java/org/wildfly/extension/vertx/VertxSubsystemSchema.java index b84c8b8..4bfd0a2 100644 --- a/subsystem/src/main/java/org/wildfly/extension/vertx/VertxSubsystemSchema.java +++ b/subsystem/src/main/java/org/wildfly/extension/vertx/VertxSubsystemSchema.java @@ -48,10 +48,6 @@ public PersistentResourceXMLDescription getXMLDescription() { ) .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])) diff --git a/subsystem/src/main/resources/org/wildfly/extension/vertx/LocalDescriptions.properties b/subsystem/src/main/resources/org/wildfly/extension/vertx/LocalDescriptions.properties index a9bae11..5463df4 100644 --- a/subsystem/src/main/resources/org/wildfly/extension/vertx/LocalDescriptions.properties +++ b/subsystem/src/main/resources/org/wildfly/extension/vertx/LocalDescriptions.properties @@ -10,11 +10,6 @@ vertx.remove=Remove Vertx Subsystem vertx.vertx=The service which provides a Vert.x instance vertx.option-name=The option name used to refer to the VertxOptions definition -vertx.vertx-option-file=VertxOptions that comes from a Json file path -vertx.vertx-option-file.add=Add a VertxOptions by specifying the json file path -vertx.vertx-option-file.remove=Remove a VertxOptions defined by a json file path -vertx.vertx-option-file.path=A JSON file path where to read the VertxOptions from - vertx.vertx-option=The VertxOptions Definition vertx.vertx-option.add=Add a VertxOptions vertx.vertx-option.remove=Remove a VertxOptions diff --git a/subsystem/src/main/resources/schema/wildfly-vertx_1_0_0.xsd b/subsystem/src/main/resources/schema/wildfly-vertx_1_0_0.xsd index c2132f3..b07b305 100644 --- a/subsystem/src/main/resources/schema/wildfly-vertx_1_0_0.xsd +++ b/subsystem/src/main/resources/schema/wildfly-vertx_1_0_0.xsd @@ -28,11 +28,6 @@ - - - Define a VertxOptions from a Json file - - Define a VertxOptions by specifying each property @@ -48,15 +43,6 @@ - - - - - Specify the json file path where to read VertxOptions from. - - - -