Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Issue-40] Adds missing attributes #41

Merged
merged 1 commit into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,11 @@ class AddressResolverResourceDefinition extends SimpleResourceDefinition impleme
.setAllowExpression(true)
.build();

public static final SimpleAttributeDefinition ATTR_HOSTS_REFRESH_PERIOD = new SimpleAttributeDefinitionBuilder(VertxConstants.ATTR_HOSTS_REFRESH_PERIOD, ModelType.INT)
.setRequired(false)
.setAllowExpression(true)
.build();

private static final List<AttributeDefinition> VERTX_ADDRESS_RESOLVER_OPTIONS_ATTRS = new ArrayList<>();
static {
VERTX_ADDRESS_RESOLVER_OPTIONS_ATTRS.add(ATTR_HOSTS_PATH);
Expand All @@ -138,6 +143,7 @@ class AddressResolverResourceDefinition extends SimpleResourceDefinition impleme
VERTX_ADDRESS_RESOLVER_OPTIONS_ATTRS.add(ATTR_N_DOTS);
VERTX_ADDRESS_RESOLVER_OPTIONS_ATTRS.add(ATTR_ROTATE_SERVERS);
VERTX_ADDRESS_RESOLVER_OPTIONS_ATTRS.add(ATTR_ROUND_ROBIN_INET_ADDRESS);
VERTX_ADDRESS_RESOLVER_OPTIONS_ATTRS.add(ATTR_HOSTS_REFRESH_PERIOD);
}

static List<AttributeDefinition> getVertxAddressResolverOptionsAttrs() {
Expand Down Expand Up @@ -256,6 +262,9 @@ private AddressResolverOptions parseAddressResolverOptions(ModelNode operation)
if (operation.hasDefined(VertxConstants.ATTR_ROUND_ROBIN_INET_ADDRESS)) {
addressResolverOptions.setRoundRobinInetAddress(ATTR_ROUND_ROBIN_INET_ADDRESS.validateOperation(operation).asBoolean());
}
if (operation.hasDefined(VertxConstants.ATTR_HOSTS_REFRESH_PERIOD)) {
addressResolverOptions.setHostsRefreshPeriod(ATTR_HOSTS_REFRESH_PERIOD.validateOperation(operation).asInt());
}
return addressResolverOptions;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@
*/
package org.wildfly.extension.vertx;

import io.vertx.core.VertxOptions;
import io.vertx.core.dns.AddressResolverOptions;
import org.jboss.as.controller.OperationContext;
import org.jboss.as.controller.OperationFailedException;
import org.jboss.as.server.ServerEnvironment;
import org.jboss.dmr.ModelNode;
import org.jboss.msc.Service;
import org.jboss.msc.service.ServiceBuilder;
import org.jboss.msc.service.ServiceController;
Expand All @@ -14,9 +18,13 @@
import org.jboss.msc.service.StartException;
import org.jboss.msc.service.StopContext;

import java.nio.file.Path;
import java.util.function.Consumer;
import java.util.function.Supplier;

import static org.wildfly.extension.vertx.VertxConstants.ATTR_FS_FILE_CACHE_DIR;
import static org.wildfly.extension.vertx.VertxConstants.ELEMENT_VERTX_OPTION_ADDRESS_RESOLVER;

/**
* @author <a href="mailto:[email protected]">Lin Gao</a>
*/
Expand All @@ -25,39 +33,65 @@ public class NamedVertxOptionsService implements Service {
private final NamedVertxOptions namedVertxOptions;
private final Consumer<NamedVertxOptions> consumer;
private final Supplier<AddressResolverOptions> addressResolverOptionsSupplier;
private final Supplier<ServerEnvironment> serverEnvironmentSupplier;
private final boolean defaultFileCacheDir;

NamedVertxOptionsService(NamedVertxOptions namedVertxOptions, Consumer<NamedVertxOptions> consumer) {
this(namedVertxOptions, null, consumer);
NamedVertxOptionsService(NamedVertxOptions namedVertxOptions,
Consumer<NamedVertxOptions> consumer) {
this(namedVertxOptions, null, null, false, consumer);
}

NamedVertxOptionsService(NamedVertxOptions namedVertxOptions,
Supplier<AddressResolverOptions> addressResolverOptionsSupplier,
Supplier<ServerEnvironment> serverEnvironmentSupplier,
boolean defaultFileCacheDir,
Consumer<NamedVertxOptions> consumer) {
this.namedVertxOptions = namedVertxOptions;
this.addressResolverOptionsSupplier = addressResolverOptionsSupplier;
this.serverEnvironmentSupplier = serverEnvironmentSupplier;
this.defaultFileCacheDir = defaultFileCacheDir;
this.consumer = consumer;
}

static void installService(OperationContext context, NamedVertxOptions namedVertxOptions,
String addressResolverOptionName) {
ServiceName vertxServiceName = VertxOptionFileResourceDefinition.VERTX_OPTIONS_CAPABILITY.getCapabilityServiceName(namedVertxOptions.getName());
/**
* Install NamedVertxOptionsService from '/subsystem=vertx/vertx-option=xx:add()'
* <p>
* When 'file-cache-dir' is not configured, it defaults to '${jboss.server.temp.dir}/vertx-cache'
* </p>
* @param context the OperationContext to add a VertxOptions with a name
* @param operation the operation ModelNode to add a VertxOptions with a name
* @throws OperationFailedException when anything goes wrong
*/
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);
ServiceBuilder<?> vertxServiceBuilder = context.getCapabilityServiceTarget().addService();
Consumer<NamedVertxOptions> consumer = vertxServiceBuilder.provides(vertxServiceName);
Supplier<AddressResolverOptions> addressResolverOptionsSupplier = null;
if (addressResolverOptionName != null) {
addressResolverOptionsSupplier = vertxServiceBuilder.requires(AddressResolverResourceDefinition.VERTX_OPTIONS_ADDRESS_RESOLVER_CAPABILITY.getCapabilityServiceName(addressResolverOptionName));
if (operation.hasDefined(ELEMENT_VERTX_OPTION_ADDRESS_RESOLVER)) {
String addressResolverOptionName = VertxOptionsAttributes.ATTR_VERTX_OPTION_ADDRESS_RESOLVER.validateOperation(operation).asString();
ServiceName addressResolverServiceName = AddressResolverResourceDefinition.VERTX_OPTIONS_ADDRESS_RESOLVER_CAPABILITY.getCapabilityServiceName(addressResolverOptionName);
addressResolverOptionsSupplier = vertxServiceBuilder.requires(addressResolverServiceName);
}
vertxServiceBuilder.setInstance(new NamedVertxOptionsService(namedVertxOptions, addressResolverOptionsSupplier, consumer));
NamedVertxOptions namedVertxOptions = new NamedVertxOptions(name, vertxOptions);
ServiceName serverEnvServiceName = context.getCapabilityServiceName(ServerEnvironment.SERVICE_DESCRIPTOR);
Supplier<ServerEnvironment> environmentSupplier = vertxServiceBuilder.requires(serverEnvServiceName);
vertxServiceBuilder.setInstance(new NamedVertxOptionsService(namedVertxOptions, addressResolverOptionsSupplier,
environmentSupplier, !operation.hasDefined(ATTR_FS_FILE_CACHE_DIR), vertxServiceBuilder.provides(vertxServiceName)));
vertxServiceBuilder
.setInitialMode(ServiceController.Mode.ACTIVE)
.install();
.setInitialMode(ServiceController.Mode.ACTIVE)
.install();
}

@Override
public void start(StartContext startContext) throws StartException {
if (this.addressResolverOptionsSupplier != null && this.addressResolverOptionsSupplier.get() != null) {
this.namedVertxOptions.getVertxOptions().setAddressResolverOptions(this.addressResolverOptionsSupplier.get());
}
if (defaultFileCacheDir) {
String defaultCacheDir = serverEnvironmentSupplier.get().getServerTempDir().toPath().resolve(Path.of("vertx-cache")).normalize().toString();
this.namedVertxOptions.getVertxOptions().getFileSystemOptions().setFileCacheDir(defaultCacheDir);
}
this.consumer.accept(this.namedVertxOptions);
VertxOptionsRegistry.getInstance().addVertxOptions(this.namedVertxOptions);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,12 @@ public interface VertxConstants {
// file system options
String ATTR_FS_CLASS_PATH_RESOLVING_ENABLED = "classpath-resolving-enabled";
String ATTR_FS_FILE_CACHE_ENABLED = "file-cache-enabled";
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";
String ATTR_OPT_RES_ENABLED = "opt-resource-enabled";
String ATTR_CACHE_MIN_TTL = "cache-min-time-to-live";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@ static List<AttributeDefinition> getVertxOptionsFileAttributes() {
.setAllowExpression(true)
.build();

public static final SimpleAttributeDefinition ATTR_FS_FILE_CACHE_DIR = new SimpleAttributeDefinitionBuilder(VertxConstants.ATTR_FS_FILE_CACHE_DIR, ModelType.STRING)
.setRequired(false)
.setAllowExpression(true)
.build();

// address-resolver-option
public static final SimpleAttributeDefinition ATTR_VERTX_OPTION_ADDRESS_RESOLVER = new SimpleAttributeDefinitionBuilder(VertxConstants.ELEMENT_VERTX_OPTION_ADDRESS_RESOLVER, ModelType.STRING)
.setRequired(false)
Expand All @@ -141,6 +146,7 @@ static List<AttributeDefinition> getVertxOptionsFileAttributes() {
// file system options
VERTX_OPTIONS_ATTRS.add(ATTR_FS_CLASS_PATH_RESOLVING_ENABLED);
VERTX_OPTIONS_ATTRS.add(ATTR_FS_FILE_CACHE_ENABLED);
VERTX_OPTIONS_ATTRS.add(ATTR_FS_FILE_CACHE_DIR);

// address-resolver-option
VERTX_OPTIONS_ATTRS.add(ATTR_VERTX_OPTION_ADDRESS_RESOLVER);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import static org.wildfly.extension.vertx.VertxConstants.ATTR_BLOCKED_THREAD_CHECK_INTERVAL_UNIT;
import static org.wildfly.extension.vertx.VertxConstants.ATTR_EVENTLOOP_POOL_SIZE;
import static org.wildfly.extension.vertx.VertxConstants.ATTR_FS_CLASS_PATH_RESOLVING_ENABLED;
import static org.wildfly.extension.vertx.VertxConstants.ATTR_FS_FILE_CACHE_DIR;
import static org.wildfly.extension.vertx.VertxConstants.ATTR_FS_FILE_CACHE_ENABLED;
import static org.wildfly.extension.vertx.VertxConstants.ATTR_INTERNAL_BLOCKING_POOL_SIZE;
import static org.wildfly.extension.vertx.VertxConstants.ATTR_MAX_EVENTLOOP_EXECUTE_TIME;
Expand All @@ -36,7 +37,6 @@
import static org.wildfly.extension.vertx.VertxConstants.ATTR_WARNING_EXECUTION_TIME_UNIT;
import static org.wildfly.extension.vertx.VertxConstants.ATTR_WORKER_POOL_SIZE;
import static org.wildfly.extension.vertx.VertxConstants.ELEMENT_VERTX_OPTION;
import static org.wildfly.extension.vertx.VertxConstants.ELEMENT_VERTX_OPTION_ADDRESS_RESOLVER;

/**
* @author <a href="mailto:[email protected]">Lin Gao</a>
Expand Down Expand Up @@ -79,66 +79,60 @@ static class VertxOptionAddHandler extends AbstractAddStepHandler {

@Override
protected void performRuntime(OperationContext context, ModelNode operation, Resource resource) throws OperationFailedException {
final String name = context.getCurrentAddressValue();
VertxOptions vertxOptions = parseOptions(operation);
NamedVertxOptions namedVertxOptions = new NamedVertxOptions(name, vertxOptions);

String addressResolverOptionName = null;
if (operation.hasDefined(ELEMENT_VERTX_OPTION_ADDRESS_RESOLVER)) {
addressResolverOptionName = VertxOptionsAttributes.ATTR_VERTX_OPTION_ADDRESS_RESOLVER.validateOperation(operation).asString();
}
NamedVertxOptionsService.installService(context, namedVertxOptions, addressResolverOptionName);
NamedVertxOptionsService.installVertxOptionsService(context, operation);
}
}

VertxOptions parseOptions(ModelNode operation) throws OperationFailedException {
VertxOptions vertxOptions = new VertxOptions();
if (operation.hasDefined(ATTR_EVENTLOOP_POOL_SIZE)) {
vertxOptions.setEventLoopPoolSize(VertxOptionsAttributes.ATTR_EVENTLOOP_POOL_SIZE.validateOperation(operation).asInt());
}
if (operation.hasDefined(ATTR_WORKER_POOL_SIZE)) {
vertxOptions.setWorkerPoolSize(VertxOptionsAttributes.ATTR_WORKER_POOL_SIZE.validateOperation(operation).asInt());
}
if (operation.hasDefined(ATTR_INTERNAL_BLOCKING_POOL_SIZE)) {
vertxOptions.setInternalBlockingPoolSize(VertxOptionsAttributes.ATTR_INTERNAL_BLOCKING_POOL_SIZE.validateOperation(operation).asInt());
}
if (operation.hasDefined(ATTR_PREFER_NATIVE_TRANSPORT)) {
vertxOptions.setPreferNativeTransport(VertxOptionsAttributes.ATTR_PREFER_NATIVE_TRANSPORT.validateOperation(operation).asBoolean());
}
if (operation.hasDefined(ATTR_BLOCKED_THREAD_CHECK_INTERVAL)) {
vertxOptions.setBlockedThreadCheckInterval(VertxOptionsAttributes.ATTR_BLOCKED_THREAD_CHECK_INTERVAL.validateOperation(operation).asLong());
}
if (operation.hasDefined(ATTR_BLOCKED_THREAD_CHECK_INTERVAL_UNIT)) {
vertxOptions.setBlockedThreadCheckIntervalUnit(TimeUnit.valueOf(VertxOptionsAttributes.ATTR_BLOCKED_THREAD_CHECK_INTERVAL_UNIT.validateOperation(operation).asString()));
}
if (operation.hasDefined(ATTR_MAX_EVENTLOOP_EXECUTE_TIME)) {
vertxOptions.setMaxEventLoopExecuteTime(VertxOptionsAttributes.ATTR_MAX_EVENTLOOP_EXECUTE_TIME.validateOperation(operation).asLong());
}
if (operation.hasDefined(ATTR_MAX_EVENTLOOP_EXECUTE_TIME_UNIT)) {
vertxOptions.setMaxEventLoopExecuteTimeUnit(TimeUnit.valueOf(VertxOptionsAttributes.ATTR_MAX_EVENTLOOP_EXECUTE_TIME_UNIT.validateOperation(operation).asString()));
}
if (operation.hasDefined(ATTR_MAX_WORKER_EXECUTE_TIME)) {
vertxOptions.setMaxWorkerExecuteTime(VertxOptionsAttributes.ATTR_MAX_WORKER_EXECUTE_TIME.validateOperation(operation).asLong());
}
if (operation.hasDefined(ATTR_MAX_WORKER_EXECUTE_TIME_UNIT)) {
vertxOptions.setMaxWorkerExecuteTimeUnit(TimeUnit.valueOf(VertxOptionsAttributes.ATTR_MAX_WORKER_EXECUTE_TIME_UNIT.validateOperation(operation).asString()));
}
if (operation.hasDefined(ATTR_WARNING_EXECUTION_TIME)) {
vertxOptions.setWarningExceptionTime(VertxOptionsAttributes.ATTR_WARNING_EXECUTION_TIME.validateOperation(operation).asLong());
}
if (operation.hasDefined(ATTR_WARNING_EXECUTION_TIME_UNIT)) {
vertxOptions.setWarningExceptionTimeUnit(TimeUnit.valueOf(VertxOptionsAttributes.ATTR_WARNING_EXECUTION_TIME_UNIT.validateOperation(operation).asString()));
}

// file system options
if (operation.hasDefined(ATTR_FS_CLASS_PATH_RESOLVING_ENABLED)) {
vertxOptions.getFileSystemOptions().setClassPathResolvingEnabled(VertxOptionsAttributes.ATTR_FS_CLASS_PATH_RESOLVING_ENABLED.validateOperation(operation).asBoolean());
}
if (operation.hasDefined(ATTR_FS_FILE_CACHE_ENABLED)) {
vertxOptions.getFileSystemOptions().setFileCachingEnabled(VertxOptionsAttributes.ATTR_FS_FILE_CACHE_ENABLED.validateOperation(operation).asBoolean());
}
return vertxOptions;
static VertxOptions parseOptions(ModelNode operation) throws OperationFailedException {
VertxOptions vertxOptions = new VertxOptions();
if (operation.hasDefined(ATTR_EVENTLOOP_POOL_SIZE)) {
vertxOptions.setEventLoopPoolSize(VertxOptionsAttributes.ATTR_EVENTLOOP_POOL_SIZE.validateOperation(operation).asInt());
}
if (operation.hasDefined(ATTR_WORKER_POOL_SIZE)) {
vertxOptions.setWorkerPoolSize(VertxOptionsAttributes.ATTR_WORKER_POOL_SIZE.validateOperation(operation).asInt());
}
if (operation.hasDefined(ATTR_INTERNAL_BLOCKING_POOL_SIZE)) {
vertxOptions.setInternalBlockingPoolSize(VertxOptionsAttributes.ATTR_INTERNAL_BLOCKING_POOL_SIZE.validateOperation(operation).asInt());
}
if (operation.hasDefined(ATTR_PREFER_NATIVE_TRANSPORT)) {
vertxOptions.setPreferNativeTransport(VertxOptionsAttributes.ATTR_PREFER_NATIVE_TRANSPORT.validateOperation(operation).asBoolean());
}
if (operation.hasDefined(ATTR_BLOCKED_THREAD_CHECK_INTERVAL)) {
vertxOptions.setBlockedThreadCheckInterval(VertxOptionsAttributes.ATTR_BLOCKED_THREAD_CHECK_INTERVAL.validateOperation(operation).asLong());
}
if (operation.hasDefined(ATTR_BLOCKED_THREAD_CHECK_INTERVAL_UNIT)) {
vertxOptions.setBlockedThreadCheckIntervalUnit(TimeUnit.valueOf(VertxOptionsAttributes.ATTR_BLOCKED_THREAD_CHECK_INTERVAL_UNIT.validateOperation(operation).asString()));
}
if (operation.hasDefined(ATTR_MAX_EVENTLOOP_EXECUTE_TIME)) {
vertxOptions.setMaxEventLoopExecuteTime(VertxOptionsAttributes.ATTR_MAX_EVENTLOOP_EXECUTE_TIME.validateOperation(operation).asLong());
}
if (operation.hasDefined(ATTR_MAX_EVENTLOOP_EXECUTE_TIME_UNIT)) {
vertxOptions.setMaxEventLoopExecuteTimeUnit(TimeUnit.valueOf(VertxOptionsAttributes.ATTR_MAX_EVENTLOOP_EXECUTE_TIME_UNIT.validateOperation(operation).asString()));
}
if (operation.hasDefined(ATTR_MAX_WORKER_EXECUTE_TIME)) {
vertxOptions.setMaxWorkerExecuteTime(VertxOptionsAttributes.ATTR_MAX_WORKER_EXECUTE_TIME.validateOperation(operation).asLong());
}
if (operation.hasDefined(ATTR_MAX_WORKER_EXECUTE_TIME_UNIT)) {
vertxOptions.setMaxWorkerExecuteTimeUnit(TimeUnit.valueOf(VertxOptionsAttributes.ATTR_MAX_WORKER_EXECUTE_TIME_UNIT.validateOperation(operation).asString()));
}
if (operation.hasDefined(ATTR_WARNING_EXECUTION_TIME)) {
vertxOptions.setWarningExceptionTime(VertxOptionsAttributes.ATTR_WARNING_EXECUTION_TIME.validateOperation(operation).asLong());
}
if (operation.hasDefined(ATTR_WARNING_EXECUTION_TIME_UNIT)) {
vertxOptions.setWarningExceptionTimeUnit(TimeUnit.valueOf(VertxOptionsAttributes.ATTR_WARNING_EXECUTION_TIME_UNIT.validateOperation(operation).asString()));
}

// file system options
if (operation.hasDefined(ATTR_FS_CLASS_PATH_RESOLVING_ENABLED)) {
vertxOptions.getFileSystemOptions().setClassPathResolvingEnabled(VertxOptionsAttributes.ATTR_FS_CLASS_PATH_RESOLVING_ENABLED.validateOperation(operation).asBoolean());
}
if (operation.hasDefined(ATTR_FS_FILE_CACHE_ENABLED)) {
vertxOptions.getFileSystemOptions().setFileCachingEnabled(VertxOptionsAttributes.ATTR_FS_FILE_CACHE_ENABLED.validateOperation(operation).asBoolean());
}
if (operation.hasDefined(ATTR_FS_FILE_CACHE_DIR)) {
vertxOptions.getFileSystemOptions().setFileCacheDir(VertxOptionsAttributes.ATTR_FS_FILE_CACHE_DIR.validateOperation(operation).asString());
}
return vertxOptions;
}

private static class ShowInfoHandler implements OperationStepHandler {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ vertx.vertx-option.max-worker-execute-time=The max worker execute time, defaults
vertx.vertx-option.max-worker-execute-time-unit=The max worker execute time unit, defaults to NANOSECONDS
vertx.vertx-option.warning-exception-time=The warning exception time, If a thread is blocked longer than this threshold, the warning log contains a stack trace, defaults to 5 seconds
vertx.vertx-option.warning-exception-time-unit=The warning exception time, defaults to NANOSECONDS
vertx.vertx-option.classpath-resolving-enabled=whether classpath resolving is enabled
vertx.vertx-option.file-cache-enabled=whether file caching is enabled for class path resolving
vertx.vertx-option.classpath-resolving-enabled=Whether classpath resolving is enabled
vertx.vertx-option.file-cache-enabled=Whether file caching is enabled for class path resolving
vertx.vertx-option.file-cache-dir=The file cache directory
vertx.vertx-option.address-resolver-option=The address-resolver-option name used for the AddressResolverOptions
vertx.vertx-option.show-info=Show VertxOptions information

Expand All @@ -54,3 +55,4 @@ vertx.address-resolver-option.search-domains=The lists of DNS search domains. Wh
vertx.address-resolver-option.n-dots=The ndots value used when resolving using search domains, the default value is -1 which determines the value from the OS on Linux or uses the value 1.
vertx.address-resolver-option.rotate-servers=The option to enable round-robin selection of the dns server to use. It spreads the query load among the servers and avoids all lookup to hit the first server of the list.
vertx.address-resolver-option.round-robin-inet-address=The option to enable round-robin inet address selection of the ip address to use.
vertx.address-resolver-option.hosts-refresh-period=The hosts configuration refresh period in millis
Loading