Skip to content
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
18 changes: 17 additions & 1 deletion doc/distributed.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,23 @@ Every instance runs the same image, in one of three modes set by `wombat.mode` (
| `aggregator` | | its database | ✓ |
| `worker` | ✓ | the aggregator | |

Outside of the aggregator mode, `POST /api/workers/{worker}/metrics` and `PUT /api/workers/{worker}/environments` answer `404`.
### Features

The mode also sets which functionalities an instance serves:

| Feature | Serves | `standalone` | `aggregator` | `worker` |
|-------------|--------------------------------------------------------------------------------|--------------|--------------|----------|
| `ui` | the web UI and its dashboards, `GET /api/app` | ✓ | ✓ | |
| `api-read` | `/api/impact`, `/api/simulation`, `/api/environments`, `/api/modules` | ✓ | ✓ | |
| `api-write` | `POST /api/workers/{worker}/metrics`, `PUT /api/workers/{worker}/environments` | | ✓ | |
| `admin` | `/api/users`, `/api/keys`, `/api/secrets` | ✓ | ✓ | |

`api-write` only covers what workers push, so only an aggregator serves it. The endpoints managing an instance (users,
API keys, secrets) write too, but fall under `admin`, so that a standalone instance can still be administered.

The endpoints of a disabled feature are not registered: they answer `404` and are left out of the OpenAPI document
(`/api/openapi`). `/q/*` is never gated: a worker serves nothing else, so it needs no authentication. The features are
resolved once at startup and logged.

## Aggregator

Expand Down
6 changes: 6 additions & 0 deletions src/main/java/tech/illuin/wombat/commons/NodeMode.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,10 @@ public enum NodeMode
aggregator,
/** Samples its environments and pushes the metrics to an aggregator instead of its own database. */
worker,
;

public static NodeMode parse(String mode)
{
return NodeMode.valueOf(mode.trim().replace('-', '_').toLowerCase());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
@StaticInitSafe
public class NodeModeConfigSourceFactory implements ConfigSourceFactory
{
public static final String AGGREGATOR_CONFIG_KEY = "_internal.aggregator";
private static final String WORKER_DB_KIND = "sqlite";
private static final String WORKER_JDBC_URL = "jdbc:sqlite::memory:";

Expand All @@ -28,11 +27,9 @@ public class NodeModeConfigSourceFactory implements ConfigSourceFactory
public Iterable<ConfigSource> getConfigSources(ConfigSourceContext context)
{
ConfigValue value = context.getValue("wombat.mode");
NodeMode mode = value.getValue() == null ? null : parse(value.getValue());
NodeMode mode = value.getValue() == null ? null : NodeMode.parse(value.getValue());

Map<String, String> properties = new HashMap<>();
properties.put(AGGREGATOR_CONFIG_KEY, String.valueOf(mode == NodeMode.aggregator));

if (mode == NodeMode.worker)
{
String backend = context.getValue(ACTIVE_BACKEND_CONFIG_KEY).getValue();
Expand All @@ -52,9 +49,4 @@ public Iterable<ConfigSource> getConfigSources(ConfigSourceContext context)
Integer.MAX_VALUE
));
}

private static NodeMode parse(String mode)
{
return NodeMode.valueOf(mode.trim().replace('-', '_').toLowerCase());
}
}
5 changes: 3 additions & 2 deletions src/main/java/tech/illuin/wombat/endpoint/AppController.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package tech.illuin.wombat.endpoint;

import io.quarkus.resteasy.reactive.server.EndpointDisabled;
import io.quarkus.security.identity.SecurityIdentity;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
Expand All @@ -9,15 +10,15 @@
import org.eclipse.microprofile.openapi.annotations.media.Schema;
import org.eclipse.microprofile.openapi.annotations.media.SchemaProperty;
import org.eclipse.microprofile.openapi.annotations.responses.APIResponse;
import tech.illuin.wombat.commons.WombatProperties;
import tech.illuin.wombat.endpoint.response.Response;
import tech.illuin.wombat.endpoint.response.Status;
import tech.illuin.wombat.feature.Feature;
import tech.illuin.wombat.security.AuthProperties;
import tech.illuin.wombat.endpoint.UIProperties;

import java.util.Locale;

@Path("api/app")
@EndpointDisabled(name = Feature.Keys.UI, stringValue = "false")
public class AppController
{
private final SecurityIdentity identity;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package tech.illuin.wombat.endpoint;

import io.quarkus.resteasy.reactive.server.EndpointDisabled;
import io.quarkus.security.PermissionsAllowed;
import jakarta.ws.rs.*;
import jakarta.ws.rs.core.MediaType;
Expand All @@ -16,6 +17,7 @@
import tech.illuin.wombat.engine.context.persistence.AssetRepository;
import tech.illuin.wombat.engine.context.persistence.EnvironmentEntity;
import tech.illuin.wombat.engine.context.persistence.EnvironmentRepository;
import tech.illuin.wombat.feature.Feature;
import tech.illuin.wombat.security.Permission;

import java.util.List;
Expand All @@ -26,6 +28,7 @@
* this controller exposes the current state and the per-asset change history but never mutates config.
*/
@Path("api/environments")
@EndpointDisabled(name = Feature.Keys.API_READ, stringValue = "false")
@PermissionsAllowed(Permission.Names.API_ENVIRONMENT_READ)
public class EnvironmentController
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package tech.illuin.wombat.endpoint;

import io.quarkus.resteasy.reactive.server.EndpointDisabled;
import io.quarkus.security.PermissionsAllowed;
import jakarta.validation.Valid;
import jakarta.ws.rs.*;
Expand All @@ -21,6 +22,7 @@
import tech.illuin.wombat.engine.impact.timeline.TimelineStep;
import tech.illuin.wombat.endpoint.response.Response;
import tech.illuin.wombat.endpoint.response.Status;
import tech.illuin.wombat.feature.Feature;
import tech.illuin.wombat.security.Permission;

import java.time.Duration;
Expand All @@ -33,6 +35,7 @@
import java.util.stream.Collectors;

@Path("api/impact")
@EndpointDisabled(name = Feature.Keys.API_READ, stringValue = "false")
@PermissionsAllowed(Permission.Names.API_IMPACT_READ)
public class ImpactController
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
import org.eclipse.microprofile.openapi.annotations.responses.APIResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import tech.illuin.wombat.commons.NodeModeConfigSourceFactory;
import tech.illuin.wombat.core.asset.AssetIdentity;
import tech.illuin.wombat.core.source.data.MetricData;
import tech.illuin.wombat.endpoint.response.Response;
import tech.illuin.wombat.endpoint.response.Status;
import tech.illuin.wombat.engine.module.registry.ModuleMetadata;
import tech.illuin.wombat.engine.module.registry.ModuleRegistry;
import tech.illuin.wombat.feature.Feature;
import tech.illuin.wombat.persistence.backend.push.PushBackendConfig;
import tech.illuin.wombat.persistence.backend.api.store.MetricSample;
import tech.illuin.wombat.persistence.backend.api.store.MetricStoreContainer;
Expand All @@ -33,15 +33,15 @@
import java.util.Map;

/**
* Receives metrics sampled by workers, see {@link tech.illuin.wombat.persistence.backend.push.PushBackendConfig}. Only
* an {@link NodeMode#AGGREGATOR} serves it. Each worker already aggregated its metrics over its sampling window, so they
* Receives metrics sampled by workers, see {@link tech.illuin.wombat.persistence.backend.push.PushBackendConfig}. Served
* with the {@link Feature#API_WRITE}, by an aggregator by default. Each worker already aggregated its metrics over its sampling window, so they
* are saved to the database as they are, at the start of the worker's window, for the asset {@code workerId.assetId}, see
* {@link WorkerController}. A sample for an asset type without an active module, or of a service family without a store,
* is skipped and reported in the response status, under {@code errors}, with the asset id the worker knows; the others
* are saved.
*/
@Path("api/workers/{worker}/metrics")
@EndpointDisabled(name = NodeModeConfigSourceFactory.AGGREGATOR_CONFIG_KEY, stringValue = "false")
@EndpointDisabled(name = Feature.Keys.API_WRITE, stringValue = "false")
@PermissionsAllowed(Permission.Names.API_METRIC_WRITE)
public class MetricController
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package tech.illuin.wombat.endpoint;

import io.quarkus.resteasy.reactive.server.EndpointDisabled;
import io.quarkus.security.PermissionsAllowed;
import jakarta.ws.rs.*;
import jakarta.ws.rs.core.MediaType;
Expand All @@ -13,12 +14,14 @@
import tech.illuin.wombat.engine.module.registry.ModuleMetadata;
import tech.illuin.wombat.engine.module.registry.ModuleRegistry;
import tech.illuin.wombat.engine.module.registry.schema.AssetSchemaRegistry;
import tech.illuin.wombat.feature.Feature;
import tech.illuin.wombat.security.Permission;
import com.fasterxml.jackson.databind.JsonNode;

import java.util.List;

@Path("api/modules")
@EndpointDisabled(name = Feature.Keys.API_READ, stringValue = "false")
@PermissionsAllowed(Permission.Names.API_MODULE_READ)
public class ModuleController
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package tech.illuin.wombat.endpoint;

import io.quarkus.resteasy.reactive.server.EndpointDisabled;
import io.quarkus.security.PermissionsAllowed;
import jakarta.validation.Valid;
import jakarta.ws.rs.*;
Expand All @@ -16,6 +17,7 @@
import tech.illuin.wombat.core.evaluation.AssetEvaluator;
import tech.illuin.wombat.core.evaluation.WombatEvaluationException;
import tech.illuin.wombat.endpoint.response.Status;
import tech.illuin.wombat.feature.Feature;
import tech.illuin.wombat.security.Permission;

import java.util.ArrayList;
Expand All @@ -25,6 +27,7 @@
import static tech.illuin.wombat.endpoint.SimulationRequest.Scope.IMPACT;

@Path("api/simulation")
@EndpointDisabled(name = Feature.Keys.API_READ, stringValue = "false")
@PermissionsAllowed(Permission.Names.API_SIMULATION_READ)
public class SimulationController
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import org.eclipse.microprofile.openapi.annotations.responses.APIResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import tech.illuin.wombat.commons.NodeModeConfigSourceFactory;
import tech.illuin.wombat.core.asset.Asset;
import tech.illuin.wombat.core.asset.Environment;
import tech.illuin.wombat.core.source.Monitorable;
Expand All @@ -28,6 +27,7 @@
import tech.illuin.wombat.engine.module.registry.ModuleMetadata;
import tech.illuin.wombat.engine.module.registry.ModuleRegistry;
import tech.illuin.wombat.engine.monitor.MonitoredEnvironments;
import tech.illuin.wombat.feature.Feature;
import tech.illuin.wombat.persistence.backend.push.PushBackendConfig;
import tech.illuin.wombat.security.Permission;

Expand All @@ -37,10 +37,11 @@
/**
* Receives the environments declared by workers, so an aggregator evaluates their assets without declaring them itself.
* Each worker owns the assets it declares, see {@link EnvironmentReconciler}, identified as {@code workerId.assetId}, so
* two workers declaring the same asset id declare two assets. Only an {@link NodeMode#AGGREGATOR} serves it.
* two workers declaring the same asset id declare two assets.
* Served with the {@link Feature#API_WRITE}, by an aggregator by default.
*/
@Path("api/workers")
@EndpointDisabled(name = NodeModeConfigSourceFactory.AGGREGATOR_CONFIG_KEY, stringValue = "false")
@EndpointDisabled(name = Feature.Keys.API_WRITE, stringValue = "false")
public class WorkerController
{
private final EnvironmentReconciler reconciler;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package tech.illuin.wombat.endpoint.access;

import io.quarkus.resteasy.reactive.server.EndpointDisabled;
import io.quarkus.security.PermissionsAllowed;
import io.quarkus.security.identity.SecurityIdentity;
import jakarta.ws.rs.*;
Expand All @@ -11,6 +12,7 @@
import org.eclipse.microprofile.openapi.annotations.responses.APIResponse;
import tech.illuin.wombat.endpoint.response.Response;
import tech.illuin.wombat.endpoint.response.Status;
import tech.illuin.wombat.feature.Feature;
import tech.illuin.wombat.security.AuthProperties;
import tech.illuin.wombat.security.Caller;
import tech.illuin.wombat.security.Permission;
Expand All @@ -20,6 +22,7 @@

/** Users manage their own API keys; admins also list ({@code ?all=true}) and revoke everyone's. */
@Path("api/keys")
@EndpointDisabled(name = Feature.Keys.ADMIN, stringValue = "false")
@PermissionsAllowed(Permission.Names.API_APIKEY_MANAGE)
public class ApiKeyController
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package tech.illuin.wombat.endpoint.access;

import io.quarkus.resteasy.reactive.server.EndpointDisabled;
import io.quarkus.security.PermissionsAllowed;
import io.quarkus.security.identity.SecurityIdentity;
import jakarta.ws.rs.GET;
Expand All @@ -14,6 +15,7 @@
import org.eclipse.microprofile.openapi.annotations.responses.APIResponse;
import tech.illuin.wombat.endpoint.response.Response;
import tech.illuin.wombat.endpoint.response.Status;
import tech.illuin.wombat.feature.Feature;
import tech.illuin.wombat.security.AuthProperties;
import tech.illuin.wombat.security.Caller;
import tech.illuin.wombat.security.Permission;
Expand All @@ -29,6 +31,7 @@
import java.util.stream.Collectors;

@Path("api/users")
@EndpointDisabled(name = Feature.Keys.ADMIN, stringValue = "false")
@PermissionsAllowed(Permission.Names.API_USER_READ)
public class UserController
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package tech.illuin.wombat.endpoint.access;

import io.quarkus.resteasy.reactive.server.EndpointDisabled;
import io.quarkus.security.PermissionsAllowed;
import io.quarkus.security.identity.SecurityIdentity;
import jakarta.ws.rs.*;
Expand All @@ -10,13 +11,15 @@
import org.eclipse.microprofile.openapi.annotations.responses.APIResponse;
import tech.illuin.wombat.endpoint.response.Response;
import tech.illuin.wombat.endpoint.response.Status;
import tech.illuin.wombat.feature.Feature;
import tech.illuin.wombat.security.AuthProperties;
import tech.illuin.wombat.security.Caller;
import tech.illuin.wombat.security.Permission;
import tech.illuin.wombat.security.user.RoleGrantService;

/** Admin-only: grants and removes Wombat roles held on top of the identity provider's (see the users page). */
@Path("api/users/{userId}/roles/{role}")
@EndpointDisabled(name = Feature.Keys.ADMIN, stringValue = "false")
@PermissionsAllowed(Permission.Names.API_USER_MANAGE)
public class UserRoleController
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@
import tech.illuin.wombat.core.secret.SecretWriter;
import tech.illuin.wombat.endpoint.response.Response;
import tech.illuin.wombat.endpoint.response.Status;
import tech.illuin.wombat.feature.Feature;
import tech.illuin.wombat.security.Permission;

import java.util.List;

@ApplicationScoped
@Path("api/secrets")
@EndpointDisabled(name = "wombat.secret.write-mode", stringValue = "DISABLED", disableIfMissing = true)
@EndpointDisabled(name = Feature.Keys.ADMIN_SECRETS, stringValue = "false")
@PermissionsAllowed(Permission.Names.API_SECRET_MANAGE)
@Blocking
public class SecretController
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@
import tech.illuin.wombat.endpoint.response.Status;
import tech.illuin.wombat.engine.secret.database.crypto.SecretRewrap;
import tech.illuin.wombat.engine.secret.database.crypto.SecretRewrapService;
import tech.illuin.wombat.feature.Feature;
import tech.illuin.wombat.security.Permission;

@ApplicationScoped
@Path("api/secrets/database")
@EndpointDisabled(name = "wombat.secret.write-mode", stringValue = "DISABLED", disableIfMissing = true)
@EndpointDisabled(name = Feature.Keys.ADMIN_SECRETS, stringValue = "false")
@PermissionsAllowed(Permission.Names.API_SECRET_MANAGE)
@Blocking
public class DatabaseSecretController
Expand Down
Loading
Loading