From 3ef48ca46857ff19e020a918429938c14dab9e83 Mon Sep 17 00:00:00 2001 From: Lin Gao Date: Thu, 28 Nov 2024 21:48:55 +0800 Subject: [PATCH 1/2] [Issue-43] drop hosts-path attribute from AddressResolverResourceDefinition --- .../vertx/AddressResolverResourceDefinition.java | 9 --------- .../java/org/wildfly/extension/vertx/VertxConstants.java | 1 - .../wildfly/extension/vertx/LocalDescriptions.properties | 1 - .../src/main/resources/schema/wildfly-vertx_1_0_0.xsd | 1 - .../org/wildfly/extension/vertx/vertx-options-full.xml | 2 +- .../basic/management/VertxOptionsManagementTestCase.java | 3 --- 6 files changed, 1 insertion(+), 16 deletions(-) diff --git a/subsystem/src/main/java/org/wildfly/extension/vertx/AddressResolverResourceDefinition.java b/subsystem/src/main/java/org/wildfly/extension/vertx/AddressResolverResourceDefinition.java index dc67140..1a1c4cd 100644 --- a/subsystem/src/main/java/org/wildfly/extension/vertx/AddressResolverResourceDefinition.java +++ b/subsystem/src/main/java/org/wildfly/extension/vertx/AddressResolverResourceDefinition.java @@ -46,11 +46,6 @@ class AddressResolverResourceDefinition extends SimpleResourceDefinition impleme .build(); // AddressResolverOptions - public static final SimpleAttributeDefinition ATTR_HOSTS_PATH = new SimpleAttributeDefinitionBuilder(VertxConstants.ATTR_HOSTS_PATH, ModelType.STRING) - .setRequired(false) - .setAllowExpression(true) - .build(); - public static final SimpleAttributeDefinition ATTR_HOSTS_VALUE = new SimpleAttributeDefinitionBuilder(VertxConstants.ATTR_HOSTS_VALUE, ModelType.STRING) .setRequired(false) .setAllowExpression(true) @@ -129,7 +124,6 @@ class AddressResolverResourceDefinition extends SimpleResourceDefinition impleme private static final List VERTX_ADDRESS_RESOLVER_OPTIONS_ATTRS = new ArrayList<>(); static { - VERTX_ADDRESS_RESOLVER_OPTIONS_ATTRS.add(ATTR_HOSTS_PATH); VERTX_ADDRESS_RESOLVER_OPTIONS_ATTRS.add(ATTR_HOSTS_VALUE); VERTX_ADDRESS_RESOLVER_OPTIONS_ATTRS.add(ATTR_SERVERS); VERTX_ADDRESS_RESOLVER_OPTIONS_ATTRS.add(ATTR_OPT_RES_ENABLED); @@ -218,9 +212,6 @@ public void stop(StopContext stopContext) { private AddressResolverOptions parseAddressResolverOptions(ModelNode operation) throws OperationFailedException { AddressResolverOptions addressResolverOptions = new AddressResolverOptions(); - if (operation.hasDefined(VertxConstants.ATTR_HOSTS_PATH)) { - addressResolverOptions.setHostsPath(ATTR_HOSTS_PATH.validateOperation(operation).asString()); - } if (operation.hasDefined(VertxConstants.ATTR_HOSTS_VALUE)) { addressResolverOptions.setHostsValue(Buffer.buffer(ATTR_HOSTS_VALUE.validateOperation(operation).asString())); } diff --git a/subsystem/src/main/java/org/wildfly/extension/vertx/VertxConstants.java b/subsystem/src/main/java/org/wildfly/extension/vertx/VertxConstants.java index 71e213c..860c672 100644 --- a/subsystem/src/main/java/org/wildfly/extension/vertx/VertxConstants.java +++ b/subsystem/src/main/java/org/wildfly/extension/vertx/VertxConstants.java @@ -47,7 +47,6 @@ public interface VertxConstants { String ATTR_FS_FILE_CACHE_DIR = "file-cache-dir"; // address resolver options - String ATTR_HOSTS_PATH = "hosts-path"; String ATTR_HOSTS_VALUE = "hosts-value"; String ATTR_HOSTS_REFRESH_PERIOD = "hosts-refresh-period"; String ATTR_SERVERS = "servers"; 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 ac6d418..a9bae11 100644 --- a/subsystem/src/main/resources/org/wildfly/extension/vertx/LocalDescriptions.properties +++ b/subsystem/src/main/resources/org/wildfly/extension/vertx/LocalDescriptions.properties @@ -41,7 +41,6 @@ vertx.vertx-option.show-info=Show VertxOptions information vertx.address-resolver-option=Configuration options for Vert.x hostname resolver. vertx.address-resolver-option.add=Add the AddressResolverOptions vertx.address-resolver-option.remove=Remove the AddressResolverOptions -vertx.address-resolver-option.hosts-path=The path of an alternate hosts configuration file to use instead of the one provided by the os. vertx.address-resolver-option.hosts-value=The alternate hosts configuration file to use instead of the one provided by the os. vertx.address-resolver-option.servers=The list of DNS server addresses, an address is the IP of the dns server, followed by an optional colon and a port. vertx.address-resolver-option.opt-resource-enabled=The option to enable the automatic inclusion in DNS queries of an optional record that hints the remote DNS server about how much data the resolver can read per response. 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 87db7e7..c2132f3 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 @@ -86,7 +86,6 @@ - diff --git a/subsystem/src/test/resources/org/wildfly/extension/vertx/vertx-options-full.xml b/subsystem/src/test/resources/org/wildfly/extension/vertx/vertx-options-full.xml index 52b99d1..52e9886 100644 --- a/subsystem/src/test/resources/org/wildfly/extension/vertx/vertx-options-full.xml +++ b/subsystem/src/test/resources/org/wildfly/extension/vertx/vertx-options-full.xml @@ -14,7 +14,7 @@ warning-exception-time="5" warning-exception-time-unit="SECONDS" classpath-resolving-enabled="true" file-cache-enabled="true" file-cache-dir="tmp" /> - serverList = result.get(ATTR_SERVERS).asList().stream().map(ModelNode::asString).collect(Collectors.toList()); Assert.assertTrue(serverList.contains("localhost")); @@ -145,7 +143,6 @@ public void testAddressResolverOption() throws IOException { VertxOptions vertxOptions = readVertxOptions(managementClient, optionName); AddressResolverOptions addressResolverOptions = vertxOptions.getAddressResolverOptions(); Assert.assertNotNull(addressResolverOptions); - Assert.assertEquals("local-path", addressResolverOptions.getHostsPath()); Assert.assertTrue(addressResolverOptions.getServers().contains("localhost")); Assert.assertTrue(addressResolverOptions.getServers().contains("127.0.0.1")); Assert.assertTrue(addressResolverOptions.isOptResourceEnabled()); From 5ff78ffb8ae2de419e22d27058afdba4b45a5a77 Mon Sep 17 00:00:00 2001 From: Lin Gao Date: Thu, 28 Nov 2024 21:58:46 +0800 Subject: [PATCH 2/2] [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. - - - -