From 67a1e1c874f7f1669ff37c3944912e1360dd1854 Mon Sep 17 00:00:00 2001 From: Viktor Lofgren Date: Wed, 29 Nov 2023 15:31:14 +0100 Subject: [PATCH] (control) GUI for triggering control-side actors --- .../java/nu/marginalia/control/Redirects.java | 2 +- .../sys/svc/ControlSysActionsService.java | 68 +++++++----- .../templates/control/node/nodes-list.hdb | 13 +-- .../templates/control/partials/nav.hdb | 1 + .../templates/control/sys/sys-actions.hdb | 102 ++++++++++++++++++ .../executor/svc/ProcessingService.java | 2 +- 6 files changed, 153 insertions(+), 35 deletions(-) create mode 100644 code/services-core/control-service/src/main/resources/templates/control/sys/sys-actions.hdb diff --git a/code/services-core/control-service/src/main/java/nu/marginalia/control/Redirects.java b/code/services-core/control-service/src/main/java/nu/marginalia/control/Redirects.java index ce30b108..2ade2779 100644 --- a/code/services-core/control-service/src/main/java/nu/marginalia/control/Redirects.java +++ b/code/services-core/control-service/src/main/java/nu/marginalia/control/Redirects.java @@ -3,9 +3,9 @@ package nu.marginalia.control; import spark.ResponseTransformer; public class Redirects { - public static final HtmlRedirect redirectToActors = new HtmlRedirect("/actors"); public static final HtmlRedirect redirectToApiKeys = new HtmlRedirect("/api-keys"); public static final HtmlRedirect redirectToStorage = new HtmlRedirect("/storage"); + public static final HtmlRedirect redirectToOverview = new HtmlRedirect("/"); public static final HtmlRedirect redirectToBlacklist = new HtmlRedirect("/blacklist"); public static final HtmlRedirect redirectToComplaints = new HtmlRedirect("/complaints"); public static final HtmlRedirect redirectToMessageQueue = new HtmlRedirect("/message-queue"); diff --git a/code/services-core/control-service/src/main/java/nu/marginalia/control/sys/svc/ControlSysActionsService.java b/code/services-core/control-service/src/main/java/nu/marginalia/control/sys/svc/ControlSysActionsService.java index 1779d24d..bc60c1a3 100644 --- a/code/services-core/control-service/src/main/java/nu/marginalia/control/sys/svc/ControlSysActionsService.java +++ b/code/services-core/control-service/src/main/java/nu/marginalia/control/sys/svc/ControlSysActionsService.java @@ -1,12 +1,16 @@ package nu.marginalia.control.sys.svc; import com.google.inject.Inject; +import lombok.SneakyThrows; import nu.marginalia.client.Context; import nu.marginalia.control.Redirects; +import nu.marginalia.control.actor.ControlActor; +import nu.marginalia.control.actor.ControlActorService; import nu.marginalia.db.DomainTypes; import nu.marginalia.executor.client.ExecutorClient; import nu.marginalia.mq.MessageQueueFactory; import nu.marginalia.mq.outbox.MqOutbox; +import nu.marginalia.renderer.RendererFactory; import nu.marginalia.service.control.ServiceEventLog; import nu.marginalia.service.id.ServiceId; import spark.Request; @@ -19,13 +23,23 @@ public class ControlSysActionsService { private final MqOutbox apiOutbox; private final DomainTypes domainTypes; private final ServiceEventLog eventLog; + private final RendererFactory rendererFactory; + private final ControlActorService controlActorService; private final ExecutorClient executorClient; @Inject - public ControlSysActionsService(MessageQueueFactory mqFactory, DomainTypes domainTypes, ServiceEventLog eventLog, ExecutorClient executorClient) { + public ControlSysActionsService(MessageQueueFactory mqFactory, + DomainTypes domainTypes, + ServiceEventLog eventLog, + RendererFactory rendererFactory, + ControlActorService controlActorService, + ExecutorClient executorClient) + { this.apiOutbox = createApiOutbox(mqFactory); this.eventLog = eventLog; this.domainTypes = domainTypes; + this.rendererFactory = rendererFactory; + this.controlActorService = controlActorService; this.executorClient = executorClient; } @@ -38,12 +52,17 @@ public class ControlSysActionsService { return mqFactory.createOutbox(inboxName, 0, outboxName, 0, UUID.randomUUID()); } + @SneakyThrows public void register() { - Spark.post("/public/actions/flush-api-caches", this::flushApiCaches, Redirects.redirectToActors); - Spark.post("/public/actions/reload-blogs-list", this::reloadBlogsList, Redirects.redirectToActors); - Spark.post("/public/actions/calculate-adjacencies", this::calculateAdjacencies, Redirects.redirectToActors); - Spark.post("/public/actions/truncate-links-database", this::truncateLinkDatabase, Redirects.redirectToActors); - Spark.post("/public/actions/trigger-data-exports", this::triggerDataExports, Redirects.redirectToActors); + var actionsView = rendererFactory.renderer("control/sys/sys-actions"); + + Spark.get("/public/actions", (rq,rsp) -> new Object(), actionsView::render); + Spark.post("/public/actions/recalculate-adjacencies-graph", this::calculateAdjacencies, Redirects.redirectToOverview); + Spark.post("/public/actions/reindex-all", this::reindexAll, Redirects.redirectToOverview); + Spark.post("/public/actions/reprocess-all", this::reprocessAll, Redirects.redirectToOverview); + Spark.post("/public/actions/flush-api-caches", this::flushApiCaches, Redirects.redirectToOverview); + Spark.post("/public/actions/reload-blogs-list", this::reloadBlogsList, Redirects.redirectToOverview); + Spark.post("/public/actions/trigger-data-exports", this::triggerDataExports, Redirects.redirectToOverview); } public Object triggerDataExports(Request request, Response response) throws Exception { @@ -54,23 +73,6 @@ public class ControlSysActionsService { return ""; } - public Object truncateLinkDatabase(Request request, Response response) throws Exception { - - String footgunLicense = request.queryParams("footgun-license"); - - if (!"YES".equals(footgunLicense)) { - Spark.halt(403); - return "You must agree to the footgun license to truncate the link database"; - } - - eventLog.logEvent("USER-ACTION", "FLUSH-LINK-DATABASE"); - - // FIXME: -// actors.start(Actor.TRUNCATE_LINK_DATABASE); - - return ""; - } - public Object reloadBlogsList(Request request, Response response) throws Exception { eventLog.logEvent("USER-ACTION", "RELOAD-BLOGS-LIST"); @@ -89,10 +91,26 @@ public class ControlSysActionsService { public Object calculateAdjacencies(Request request, Response response) throws Exception { eventLog.logEvent("USER-ACTION", "CALCULATE-ADJACENCIES"); - // This is technically not a partitioned operation, but we execute it at node zero + // This is technically not a partitioned operation, but we execute it at node 1 // and let the effects be global :-) - executorClient.calculateAdjacencies(Context.fromRequest(request), 0); + executorClient.calculateAdjacencies(Context.fromRequest(request), 1); + + return ""; + } + + public Object reindexAll(Request request, Response response) throws Exception { + eventLog.logEvent("USER-ACTION", "REINDEX-ALL"); + + controlActorService.start(ControlActor.REINDEX_ALL); + + return ""; + } + + public Object reprocessAll(Request request, Response response) throws Exception { + eventLog.logEvent("USER-ACTION", "REPROCESS-ALL"); + + controlActorService.start(ControlActor.REPROCESS_ALL); return ""; } diff --git a/code/services-core/control-service/src/main/resources/templates/control/node/nodes-list.hdb b/code/services-core/control-service/src/main/resources/templates/control/node/nodes-list.hdb index 7facb92e..3c2fa94c 100644 --- a/code/services-core/control-service/src/main/resources/templates/control/node/nodes-list.hdb +++ b/code/services-core/control-service/src/main/resources/templates/control/node/nodes-list.hdb @@ -14,6 +14,11 @@ {{/unless}} {{#if nodes}} +
+ Index nodes are processing units. The search engine requires at least one, but more can be added + to spread the system load across multiple physical disks or even multiple servers. +
+ @@ -28,14 +33,6 @@ {{/each}}
Node ID
- -
-

Index Nodes

-

- Index nodes are processing units. The search engine requires at least one, but more can be added - to spread the system load across multiple physical disks or even multiple servers. -

-
{{/if}} diff --git a/code/services-core/control-service/src/main/resources/templates/control/partials/nav.hdb b/code/services-core/control-service/src/main/resources/templates/control/partials/nav.hdb index 45e97478..94853a3c 100644 --- a/code/services-core/control-service/src/main/resources/templates/control/partials/nav.hdb +++ b/code/services-core/control-service/src/main/resources/templates/control/partials/nav.hdb @@ -21,6 +21,7 @@