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

Feat/defaultthreadingmodel #443

Merged
merged 2 commits into from
Jan 22, 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
27 changes: 16 additions & 11 deletions docs/usage/neonbee.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,17 +95,22 @@ starting NeonBee.
The NeonBee config must be located in a `config` folder of the working directory. The file must be either in yaml or
json and the name of the file is the fully qualified name of NeonBee (`io.neonbee.NeonBee.yaml`).

| Property | Type | Required | Description |
| :---------------------------------------------- | :-----: |:--------:|:------------------------------------------------------------------------------------------------------------------------|
| `eventBusCodecs` | integer | No | Sets the event bus codecs to be loaded with NeonBee. |
| `eventBusTimeout` | integer | No | Sets the event bus timeout in seconds. Default is 30 seconds. |
| [`health`](#health) | object | No | Sets health config. |
| [`metrics`](#metrics) | object | No | Sets metrics config. |
| [`micrometerRegistries`](#micrometerregistries) | object | No | Sets the list of Micrometer registries for metrics forwarding. |
| [`platformClasses`](#platformclasses) | object | No | Sets classes available by the platform. |
| `trackingDataHandlingStrategy` | string | No | The class to load for tracking data handling. Default: `io.neonbee.internal.tracking.TrackingDataLoggingStrategy` |
| `timeZone` | string | No | Sets the timezone used in NeonBee. Default is `UTC`. |
| `jsonMaxStringSize` | string | No | Set the maximum string length (in chars or bytes, depending on input context) to parse JSON input strings or buffers. |
| Property | Type | Required | Description |
| :---------------------------------------------- | :-----: |:--------:|:------------------------------------------------------------------------------------------------------------------------------|
| `eventBusCodecs` | integer | No | Sets the event bus codecs to be loaded with NeonBee. |
| `eventBusTimeout` | integer | No | Sets the event bus timeout in seconds. Default is 30 seconds. |
| `deploymentTimeout` | integer | No | Sets a timeout in seconds when pending deployments will fail. Default is 30 seconds, negative values disable the timeout. |
| `modelsDeploymentTimeout` | integer | No | Overrides the default deployment timeout for model deployments. |
| `moduleDeploymentTimeout` | integer | No | Overrides the default deployment timeout for module deployments. |
| `verticleDeploymentTimeout` | integer | No | Overrides the default deployment timeout for verticle deployments. |
| `defaultThreadingModel` | string | No | Sets the default [threading model](https://vertx.io/docs/apidocs/io/vertx/core/ThreadingModel.html) used to deploy verticles. |
| [`health`](#health) | object | No | Sets health config. |
| [`metrics`](#metrics) | object | No | Sets metrics config. |
| [`micrometerRegistries`](#micrometerregistries) | object | No | Sets the list of Micrometer registries for metrics forwarding. |
| [`platformClasses`](#platformclasses) | object | No | Sets classes available by the platform. |
| `trackingDataHandlingStrategy` | string | No | The class to load for tracking data handling. Default: `io.neonbee.internal.tracking.TrackingDataLoggingStrategy` |
| `timeZone` | string | No | Sets the timezone used in NeonBee. Default is `UTC`. |
| `jsonMaxStringSize` | string | No | Set the maximum string length (in chars or bytes, depending on input context) to parse JSON input strings or buffers. |

### `health`

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ public class NeonBeeConfigConverter {
static void fromJson(Iterable<java.util.Map.Entry<String, Object>> json, NeonBeeConfig obj) {
for (java.util.Map.Entry<String, Object> member : json) {
switch (member.getKey()) {
case "defaultThreadingModel":
if (member.getValue() instanceof String) {
obj.setDefaultThreadingModel(io.vertx.core.ThreadingModel.valueOf((String) member.getValue()));
}
break;
case "deploymentTimeout":
if (member.getValue() instanceof Number) {
obj.setDeploymentTimeout(((Number) member.getValue()).intValue());
Expand Down Expand Up @@ -111,6 +116,9 @@ static void toJson(NeonBeeConfig obj, JsonObject json) {
}

static void toJson(NeonBeeConfig obj, java.util.Map<String, Object> json) {
if (obj.getDefaultThreadingModel() != null) {
json.put("defaultThreadingModel", obj.getDefaultThreadingModel().name());
}
json.put("deploymentTimeout", obj.getDeploymentTimeout());
if (obj.getEventBusCodecs() != null) {
JsonObject map = new JsonObject();
Expand Down
31 changes: 31 additions & 0 deletions src/main/java/io/neonbee/config/NeonBeeConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
import io.vertx.codegen.annotations.DataObject;
import io.vertx.codegen.annotations.Fluent;
import io.vertx.codegen.json.annotations.JsonGen;
import io.vertx.core.DeploymentOptions;
import io.vertx.core.Future;
import io.vertx.core.ThreadingModel;
import io.vertx.core.Vertx;
import io.vertx.core.json.JsonObject;
import io.vertx.core.metrics.MetricsOptions;
Expand All @@ -52,6 +54,11 @@ public class NeonBeeConfig {
*/
public static final int DEFAULT_DEPLOYMENT_TIMEOUT = 30;

/**
* The default threading model for deploying verticles (event loop).
*/
public static final ThreadingModel DEFAULT_THREADING_MODEL = DeploymentOptions.DEFAULT_MODE;

/**
* The default tracking data handling strategy.
*/
Expand All @@ -75,6 +82,8 @@ public class NeonBeeConfig {

private Integer verticleDeploymentTimeout;

private ThreadingModel defaultThreadingModel = DEFAULT_THREADING_MODEL;

private Map<String, String> eventBusCodecs = Map.of();

private String trackingDataHandlingStrategy = DEFAULT_TRACKING_DATA_HANDLING_STRATEGY;
Expand Down Expand Up @@ -362,6 +371,28 @@ public NeonBeeConfig setVerticleDeploymentTimeout(Integer verticleDeploymentTime
return this;
}

/**
* Get the default threading model to be used when deploying verticles.
*
* @return the default threading model for verticles
*/
public ThreadingModel getDefaultThreadingModel() {
return defaultThreadingModel;
}

/**
* Set the default threading model to be used when deploying verticles. Can be overridden either on runtime or using
* the verticle configuration.
*
* @param threadingModel the threading model to use when deploying verticles
* @return the {@linkplain NeonBeeConfig} for fluent use
*/
@Fluent
public NeonBeeConfig setDefaultThreadingModel(ThreadingModel threadingModel) {
this.defaultThreadingModel = threadingModel;
return this;
}

/**
* Gets a list of default codecs to register on the event bus.
* <p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import java.nio.file.Path;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;

import com.google.common.annotations.VisibleForTesting;
Expand Down Expand Up @@ -251,6 +252,15 @@ static Future<DeploymentOptions> readVerticleConfig(Vertx vertx, String classNam
: config; // if there is no default config, or what we read was the default config return it
}).onFailure(throwable -> {
LOGGER.warn("Could not read deployment options for deployable {}", className, throwable);
}).map(config -> {
if (!config.containsKey("threadingModel")) {
// create a shallow copy, quicker than calling JsonObject.copy()
return new JsonObject(new HashMap<>(config.getMap()))
.put("threadingModel", NeonBee.get(vertx).getConfig()
.getDefaultThreadingModel().toString());
}

return config;
}).map(DeploymentOptions::new);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import io.neonbee.internal.scanner.ClassPathScanner;
import io.vertx.core.DeploymentOptions;
import io.vertx.core.Future;
import io.vertx.core.ThreadingModel;
import io.vertx.core.Verticle;
import io.vertx.core.Vertx;
import io.vertx.core.buffer.Buffer;
Expand Down Expand Up @@ -206,6 +207,24 @@ void testReadVerticleConfigFailure() throws IOException {
.isEqualTo("test");
}

@Test
@DisplayName("test read verticle config threading model")
void testReadVerticleConfigThreadingModel() throws IOException {
NeonBee neonBeeMock = newNeonBeeMockForDeployment(
new NeonBeeOptions.Mutable().setWorkingDirectory(Path.of("")));
Vertx vertxMock = neonBeeMock.getVertx();
FileSystem fileSystemMock = vertxMock.fileSystem();

when(fileSystemMock.readFile(any()))
.thenReturn(failedFuture(new FileSystemException(new NoSuchFileException("file"))));
when(fileSystemMock.readFile(endsWith(".yml")))
.thenReturn(succeededFuture(Buffer.buffer("---\nthreadingModel: WORKER")));

JsonObject defaultObject = new JsonObject().put("threadingModel", "EVENT_LOOP");
assertThat(DeployableVerticle.readVerticleConfig(vertxMock, "test", defaultObject).result().toJson())
.isEqualTo(new DeploymentOptions().setThreadingModel(ThreadingModel.WORKER).toJson());
}

@Test
@DisplayName("test scan class path")
@SuppressWarnings("rawtypes")
Expand Down
Loading