From 62d26ad12f852502c686a110f85dae0ef6d20dc2 Mon Sep 17 00:00:00 2001 From: Ferdinando Villa Date: Wed, 27 Nov 2024 17:52:24 +0100 Subject: [PATCH] Work --- .../org/integratedmodelling/cli/KlabCLI.java | 25 ++++++---- .../cli/views/CLIObservationView.java | 33 ++++++++++--- .../klab/api/digitaltwin/StateStorage.java | 4 ++ .../klab/api/services/RuntimeService.java | 18 +++++++- .../scope/MessagingChannelImpl.java | 12 ++++- .../distribution/RunningInstanceImpl.java | 5 ++ .../client/runtime/RuntimeClient.java | 21 +++++++++ .../client/scope/ClientContextScope.java | 8 +++- .../client/scope/ClientSessionScope.java | 8 +++- .../runtime/storage/StateStorageImpl.java | 7 +++ .../application/ServiceNetworkedInstance.java | 1 - .../controllers/KlabScopeController.java | 26 +++++++++++ .../klab/services/scopes/ScopeManager.java | 19 ++++++++ .../services/scopes/ServiceContextScope.java | 10 +++- .../services/scopes/ServiceSessionScope.java | 34 +++++++++++++- .../main/resources/local-broker-config.json | 40 ---------------- .../src/main/resources/log4j.yaml | 46 ------------------- .../klab/services/runtime/RuntimeService.java | 25 +++++++++- .../runtime/digitaltwin/DigitalTwinImpl.java | 3 +- .../runtime/neo4j/KnowledgeGraphNeo4j.java | 2 +- 20 files changed, 231 insertions(+), 116 deletions(-) delete mode 100644 klab.core.services/src/main/resources/local-broker-config.json delete mode 100644 klab.core.services/src/main/resources/log4j.yaml diff --git a/klab.cli/src/main/java/org/integratedmodelling/cli/KlabCLI.java b/klab.cli/src/main/java/org/integratedmodelling/cli/KlabCLI.java index e88282e63..f6d313bee 100644 --- a/klab.cli/src/main/java/org/integratedmodelling/cli/KlabCLI.java +++ b/klab.cli/src/main/java/org/integratedmodelling/cli/KlabCLI.java @@ -73,7 +73,7 @@ public enum KlabCLI { private String prompt = "k.LAB> "; private ModelerImpl modeler; - + private LineReader reader; private CLIStartupOptions options; private CommandLine commandLine; @@ -112,6 +112,12 @@ public T service(String service, Class serviceClass) return null; } + public boolean confirm(String prompt) { + commandLine.getOut().println(Ansi.AUTO.string("@|yellow " + prompt + "|@ (Y/n)?")); + var line = reader.readLine(Ansi.AUTO.string("@|cyan Y/n:|@ "), "", (MaskingCallback) null, null); + return line == null || line.isEmpty() || line.trim().equalsIgnoreCase("y"); + } + /** * Top-level command that just prints help. */ @@ -412,19 +418,20 @@ public static void main(String[] args) { systemRegistry.register("help", picocliCommands); KlabCompleter completer = new KlabCompleter(systemRegistry.completer()); History history = new DefaultHistory(); - LineReader reader = + INSTANCE.reader = LineReaderBuilder.builder().terminal(terminal).completer(completer).parser(parser).variable(LineReader.LIST_MAX, 50) // candidates .history(history).build(); - builtins.setLineReader(reader); - commands.setReader(reader); + builtins.setLineReader(INSTANCE.reader); + commands.setReader(INSTANCE.reader); factory.setTerminal(terminal); - history.attach(reader); + history.attach(INSTANCE.reader); - TailTipWidgets widgets = new TailTipWidgets(reader, systemRegistry::commandDescription, 5, + TailTipWidgets widgets = new TailTipWidgets(INSTANCE.reader, + systemRegistry::commandDescription, 5, TailTipWidgets.TipType.COMPLETER); widgets.enable(); - KeyMap keyMap = reader.getKeyMaps().get("main"); + KeyMap keyMap = INSTANCE.reader.getKeyMaps().get("main"); keyMap.bind(new Reference("tailtip-toggle"), KeyMap.alt("s")); /** @@ -457,7 +464,7 @@ public static void main(String[] args) { try { systemRegistry.cleanUp(); - line = reader.readLine(INSTANCE.prompt, INSTANCE.getContextPrompt(), + line = INSTANCE.reader.readLine(INSTANCE.prompt, INSTANCE.getContextPrompt(), (MaskingCallback) null, null); completer.resetSemanticSearch(); boolean aliased = false; @@ -467,7 +474,7 @@ public static void main(String[] args) { * to inquire about the current context in * detail. The right prompt summarizes the current context focus. */ - if (line.trim().startsWith("<") || line.trim().startsWith("@") || line.trim().startsWith(">") || line.trim().startsWith("<") || line.trim().startsWith("?")) { + if (line.trim().startsWith("<") || line.trim().startsWith("@") || line.trim().startsWith(">") || line.trim().startsWith("?")) { INSTANCE.setFocalScope(line.trim()); continue; } else if (line.trim().startsWith("-")) { diff --git a/klab.cli/src/main/java/org/integratedmodelling/cli/views/CLIObservationView.java b/klab.cli/src/main/java/org/integratedmodelling/cli/views/CLIObservationView.java index 545e8f0da..693b6c8d6 100644 --- a/klab.cli/src/main/java/org/integratedmodelling/cli/views/CLIObservationView.java +++ b/klab.cli/src/main/java/org/integratedmodelling/cli/views/CLIObservationView.java @@ -5,6 +5,7 @@ import org.integratedmodelling.klab.api.data.Version; import org.integratedmodelling.klab.api.engine.Engine; import org.integratedmodelling.klab.api.knowledge.KlabAsset; +import org.integratedmodelling.klab.api.scope.ContextScope; import org.integratedmodelling.klab.api.scope.SessionScope; import org.integratedmodelling.klab.api.services.ResourcesService; import org.integratedmodelling.klab.api.services.RuntimeService; @@ -22,7 +23,8 @@ description = { "Commands to create, access and manipulate contexts.", ""}, subcommands = {CLIObservationView.Session.class, - CLIObservationView.Context.class}) + CLIObservationView.Context.class, + CLIObservationView.Clear.class}) public class CLIObservationView extends CLIView implements ContextView, Runnable { private static ContextViewController controller; @@ -108,8 +110,9 @@ public void run() { } } - @CommandLine.Command(name = "clear", mixinStandardHelpOptions = true, version = Version.CURRENT, - description = {"Close the active digital twin(s) and delete all observations"}) + @CommandLine.Command(name = "close", mixinStandardHelpOptions = true, version = Version.CURRENT, + description = {"Close the active digital twin or session and delete all " + + "observations"}) public static class Clear implements Runnable { @CommandLine.ParentCommand @@ -118,15 +121,23 @@ public static class Clear implements Runnable { @CommandLine.Spec CommandLine.Model.CommandSpec commandSpec; + @CommandLine.Option(names = {"-f", "--force"}, defaultValue = "false", + description = {"Close the current scope without asking for confirmation"}, + required = + false) + boolean force = false; + @Override public void run() { PrintWriter out = commandSpec.commandLine().getOut(); PrintWriter err = commandSpec.commandLine().getErr(); + boolean isSession = false; Channel context = KlabCLI.INSTANCE.modeler().getCurrentContext(); if (context == null) { context = KlabCLI.INSTANCE.modeler().getCurrentSession(); + isSession = true; } if (context == null) { @@ -134,12 +145,20 @@ public void run() { return; } - // TODO ask for abundant confirmation + if (force || KlabCLI.INSTANCE.confirm("Delete the current " + + (isSession ? "session" : "context") + " and ALL " + + (isSession ? "contexts and observations in them" : "observations in it"))) { + + context.close(); - KlabCLI.INSTANCE.modeler().setCurrentContext(null); - // TODO null the session if this was one - context.close(); + out.println((isSession ? "Session" : "Context") + " has been permanently closed and all " + + "data have been deleted"); + KlabCLI.INSTANCE.modeler().setCurrentContext(null); + if (isSession) { + KlabCLI.INSTANCE.modeler().setCurrentSession(null); + } + } } } diff --git a/klab.core.api/src/main/java/org/integratedmodelling/klab/api/digitaltwin/StateStorage.java b/klab.core.api/src/main/java/org/integratedmodelling/klab/api/digitaltwin/StateStorage.java index 029a2ae01..3d017b51c 100644 --- a/klab.core.api/src/main/java/org/integratedmodelling/klab/api/digitaltwin/StateStorage.java +++ b/klab.core.api/src/main/java/org/integratedmodelling/klab/api/digitaltwin/StateStorage.java @@ -52,5 +52,9 @@ public interface StateStorage { T promoteStorage(Observation observation, Storage existingStorage, Class storageClass); + /** + * Safely delete everything in the scope we're running. + */ + void clear(); } diff --git a/klab.core.api/src/main/java/org/integratedmodelling/klab/api/services/RuntimeService.java b/klab.core.api/src/main/java/org/integratedmodelling/klab/api/services/RuntimeService.java index 65af65222..76cae6eec 100644 --- a/klab.core.api/src/main/java/org/integratedmodelling/klab/api/services/RuntimeService.java +++ b/klab.core.api/src/main/java/org/integratedmodelling/klab/api/services/RuntimeService.java @@ -8,6 +8,7 @@ import org.integratedmodelling.klab.api.lang.ServiceCall; import org.integratedmodelling.klab.api.scope.ContextScope; import org.integratedmodelling.klab.api.scope.Scope; +import org.integratedmodelling.klab.api.scope.SessionScope; import org.integratedmodelling.klab.api.services.resources.ResourceSet; import org.integratedmodelling.klab.api.services.runtime.Dataflow; import org.integratedmodelling.klab.api.services.runtime.objects.SessionInfo; @@ -66,10 +67,8 @@ public static CoreFunctor classify(ServiceCall serviceCall) { } return null; } - } - default String getServiceName() { return "klab.runtime.service"; } @@ -168,6 +167,21 @@ interface Capabilities extends ServiceCapabilities { */ List getSessionInfo(Scope scope); + /** + * Release the passed session, releasing any context scopes created in it. + * + * @param scope + * @return + */ + boolean releaseSession(SessionScope scope); + + /** + * Release the passed scope, deleting all data. Should + * @param scope + * @return + */ + boolean releaseContext(ContextScope scope); + interface Admin { /** diff --git a/klab.core.common/src/main/java/org/integratedmodelling/common/authentication/scope/MessagingChannelImpl.java b/klab.core.common/src/main/java/org/integratedmodelling/common/authentication/scope/MessagingChannelImpl.java index dd0f347f1..7e91eedc0 100644 --- a/klab.core.common/src/main/java/org/integratedmodelling/common/authentication/scope/MessagingChannelImpl.java +++ b/klab.core.common/src/main/java/org/integratedmodelling/common/authentication/scope/MessagingChannelImpl.java @@ -169,6 +169,7 @@ public Collection setupMessaging(String brokerUrl, String scopeId this.connection = this.connectionFactory.newConnection(); return setupMessagingQueues(scopeId, queuesHeader); } catch (Throwable t) { + error(t); return EnumSet.noneOf(Message.Queue.class); } } @@ -214,7 +215,7 @@ public Collection setupMessagingQueues(String scopeId, var message = Utils.Json.parseObject(new String(delivery.getBody(), StandardCharsets.UTF_8), Message.class); - System.out.println("DIO PESCHIERE " + message); + System.out.println("DIO PESCHIERE " + MessagingChannelImpl.this.getClass().getCanonicalName() + " <- " + message); // if there is a consumer installed fo this queue, run it. Then if it returns // continue, continue, else stop @@ -308,7 +309,14 @@ public Collection setupMessagingQueues(String scopeId, } } - info("Scope connected to queues " + ret); + if (connectionFactory != null) { + info(this.getClass().getCanonicalName() + " scope connected to queues " + + ret + + " through broker " + connectionFactory.getHost() + (receiver ? " (R)" : "") + (sender ? + " (T)" : "")); + } else { + info("CHE CAZZO, connection factory is null for " + this.getClass().getCanonicalName()); + } return ret; } diff --git a/klab.core.common/src/main/java/org/integratedmodelling/common/distribution/RunningInstanceImpl.java b/klab.core.common/src/main/java/org/integratedmodelling/common/distribution/RunningInstanceImpl.java index 6e0fa1f1c..bf6316f8f 100644 --- a/klab.core.common/src/main/java/org/integratedmodelling/common/distribution/RunningInstanceImpl.java +++ b/klab.core.common/src/main/java/org/integratedmodelling/common/distribution/RunningInstanceImpl.java @@ -167,6 +167,11 @@ public boolean start() { CommandLine cmdLine = getCommandLine(scope); +// File logDirectory = BaseService.getConfigurationSubdirectory(options, "logs"); +// File logFile = +// new File(logDirectory + File.separator + options.getServiceType().name().toLowerCase() + +// ".log"); + Logging.INSTANCE.info("Starting " + build.getProduct().getDescription() + " with command line: \"" + cmdLine.toString() + "\""); diff --git a/klab.core.common/src/main/java/org/integratedmodelling/common/services/client/runtime/RuntimeClient.java b/klab.core.common/src/main/java/org/integratedmodelling/common/services/client/runtime/RuntimeClient.java index 8310345ec..d705842e3 100644 --- a/klab.core.common/src/main/java/org/integratedmodelling/common/services/client/runtime/RuntimeClient.java +++ b/klab.core.common/src/main/java/org/integratedmodelling/common/services/client/runtime/RuntimeClient.java @@ -219,6 +219,27 @@ public List getSessionInfo(Scope scope) { return client.withScope(scope).getCollection(ServicesAPI.RUNTIME.GET_SESSION_INFO, SessionInfo.class); } + @Override + public boolean releaseSession(SessionScope scope) { + try { + return client.withScope(scope).get(ServicesAPI.RELEASE_SESSION, Boolean.class); + } catch (Throwable t) { + // just return false + } + return false; + } + + @Override + public boolean releaseContext(ContextScope scope) { + try { + return client.withScope(scope).get(ServicesAPI.RELEASE_CONTEXT, Boolean.class); + } catch (Throwable t) { + // just return false + } + return false; + + } + @Override public List retrieveAssets(ContextScope contextScope, Class assetClass, Object... queryParameters) { diff --git a/klab.core.common/src/main/java/org/integratedmodelling/common/services/client/scope/ClientContextScope.java b/klab.core.common/src/main/java/org/integratedmodelling/common/services/client/scope/ClientContextScope.java index 6f0aca00a..d3c3b5688 100644 --- a/klab.core.common/src/main/java/org/integratedmodelling/common/services/client/scope/ClientContextScope.java +++ b/klab.core.common/src/main/java/org/integratedmodelling/common/services/client/scope/ClientContextScope.java @@ -3,6 +3,7 @@ import org.apache.commons.lang3.concurrent.ConcurrentUtils; import org.integratedmodelling.common.utils.Utils; import org.integratedmodelling.klab.api.data.RuntimeAsset; +import org.integratedmodelling.klab.api.exceptions.KlabInternalErrorException; import org.integratedmodelling.klab.api.knowledge.Observable; import org.integratedmodelling.klab.api.knowledge.observation.Observation; import org.integratedmodelling.klab.api.provenance.Agent; @@ -167,7 +168,12 @@ public Observation getObservation(long id) { @Override public void close() { - // TODO send the signal + var runtime = getService(RuntimeService.class); + if (runtime != null) { + runtime.releaseContext(this); + } else { + throw new KlabInternalErrorException("Context scope: no runtime service available"); + } } @Override diff --git a/klab.core.common/src/main/java/org/integratedmodelling/common/services/client/scope/ClientSessionScope.java b/klab.core.common/src/main/java/org/integratedmodelling/common/services/client/scope/ClientSessionScope.java index 18647b78d..276135b5a 100644 --- a/klab.core.common/src/main/java/org/integratedmodelling/common/services/client/scope/ClientSessionScope.java +++ b/klab.core.common/src/main/java/org/integratedmodelling/common/services/client/scope/ClientSessionScope.java @@ -1,5 +1,6 @@ package org.integratedmodelling.common.services.client.scope; +import org.integratedmodelling.klab.api.exceptions.KlabInternalErrorException; import org.integratedmodelling.klab.api.exceptions.KlabResourceAccessException; import org.integratedmodelling.klab.api.scope.ContextScope; import org.integratedmodelling.klab.api.scope.SessionScope; @@ -72,7 +73,12 @@ public Collection getServices(Class serviceClass) @Override public void close() { - // TODO send the signal + var runtime = getService(RuntimeService.class); + if (runtime != null) { + runtime.releaseSession(this); + } else { + throw new KlabInternalErrorException("Session scope: no runtime service available"); + } } @Override diff --git a/klab.core.services/src/main/java/org/integratedmodelling/klab/runtime/storage/StateStorageImpl.java b/klab.core.services/src/main/java/org/integratedmodelling/klab/runtime/storage/StateStorageImpl.java index 9e5342e8a..b024e624e 100644 --- a/klab.core.services/src/main/java/org/integratedmodelling/klab/runtime/storage/StateStorageImpl.java +++ b/klab.core.services/src/main/java/org/integratedmodelling/klab/runtime/storage/StateStorageImpl.java @@ -220,4 +220,11 @@ public T promoteStorage(Observation observation, Storage exi return null; } + + @Override + public void clear() { + // CHECK the implementation of close() is actually a clear(); close() may save state for later re-opening, + // depending on context persistence + close(); + } } diff --git a/klab.core.services/src/main/java/org/integratedmodelling/klab/services/application/ServiceNetworkedInstance.java b/klab.core.services/src/main/java/org/integratedmodelling/klab/services/application/ServiceNetworkedInstance.java index c72e67f42..0539dcd87 100644 --- a/klab.core.services/src/main/java/org/integratedmodelling/klab/services/application/ServiceNetworkedInstance.java +++ b/klab.core.services/src/main/java/org/integratedmodelling/klab/services/application/ServiceNetworkedInstance.java @@ -144,7 +144,6 @@ public static boolean start(Class cls, props.put("klab.service.options", options); props.put("server.port", "" + options.getPort()); props.put("spring.main.banner-mode", "off"); - props.put("logging.config", "classpath:logback-spring.xml"); props.put("logging.file.name", logFile.toPath().toString()); props.put("server.servlet.contextPath", options.getContextPath()); props.put("spring.servlet.multipart.max-file-size", options.getMaxMultipartFileSize()); diff --git a/klab.core.services/src/main/java/org/integratedmodelling/klab/services/application/controllers/KlabScopeController.java b/klab.core.services/src/main/java/org/integratedmodelling/klab/services/application/controllers/KlabScopeController.java index 3824a2d6c..470977cce 100644 --- a/klab.core.services/src/main/java/org/integratedmodelling/klab/services/application/controllers/KlabScopeController.java +++ b/klab.core.services/src/main/java/org/integratedmodelling/klab/services/application/controllers/KlabScopeController.java @@ -9,6 +9,7 @@ import org.integratedmodelling.common.services.client.runtime.RuntimeClient; import org.integratedmodelling.common.utils.Utils; import org.integratedmodelling.klab.api.ServicesAPI; +import org.integratedmodelling.klab.api.scope.ContextScope; import org.integratedmodelling.klab.api.scope.SessionScope; import org.integratedmodelling.klab.api.scope.UserScope; import org.integratedmodelling.klab.api.services.Reasoner; @@ -233,6 +234,31 @@ public String createContext(@RequestBody ScopeRequest request, return null; } + @GetMapping(ServicesAPI.RELEASE_SESSION) + public boolean closeSession(Principal principal) { + + if (principal instanceof EngineAuthorization authorization) { + var sessionScope = authorization.getScope(SessionScope.class); + if (sessionScope != null) { + sessionScope.close(); + return true; + } + } + return false; + } + + @GetMapping(ServicesAPI.RELEASE_CONTEXT) + public boolean closeContext(Principal principal) { + + if (principal instanceof EngineAuthorization authorization) { + var contextScope = authorization.getScope(ContextScope.class); + if (contextScope != null) { + contextScope.close(); + return true; + } + } + return false; + } } diff --git a/klab.core.services/src/main/java/org/integratedmodelling/klab/services/scopes/ScopeManager.java b/klab.core.services/src/main/java/org/integratedmodelling/klab/services/scopes/ScopeManager.java index eacdf1c6b..f58165f15 100644 --- a/klab.core.services/src/main/java/org/integratedmodelling/klab/services/scopes/ScopeManager.java +++ b/klab.core.services/src/main/java/org/integratedmodelling/klab/services/scopes/ScopeManager.java @@ -227,6 +227,25 @@ public ContextScope contextualizeScope(ServiceContextScope rootScope, return ret; } + public T getScope(String scopeId, Class scopeClass) { + var ret = scopes.get(scopeId); + if (ret != null && ret.getClass().isAssignableFrom(scopeClass)) { + return (T) ret; + } + return null; + } + + /** + * Remove a scope from the catalog. Does not do anything else: meant to be used after scope closing + * and child scope removal. + * + * @param scopeId + * @return + */ + public boolean releaseScope(String scopeId) { + return scopes.remove(scopeId) != null; + } + /** * Get the scope for the passed parameters. If the scope isn't there or has expired, * diff --git a/klab.core.services/src/main/java/org/integratedmodelling/klab/services/scopes/ServiceContextScope.java b/klab.core.services/src/main/java/org/integratedmodelling/klab/services/scopes/ServiceContextScope.java index cb4670000..b4606c792 100644 --- a/klab.core.services/src/main/java/org/integratedmodelling/klab/services/scopes/ServiceContextScope.java +++ b/klab.core.services/src/main/java/org/integratedmodelling/klab/services/scopes/ServiceContextScope.java @@ -20,6 +20,7 @@ import org.integratedmodelling.klab.api.services.runtime.Dataflow; import org.integratedmodelling.klab.api.services.runtime.Message; import org.integratedmodelling.klab.api.services.runtime.Report; +import org.integratedmodelling.klab.services.base.BaseService; import org.ojalgo.concurrent.Parallelism; import java.io.Closeable; @@ -372,14 +373,19 @@ public void close() { // Call close() on all closeables in our dataset, including AutoCloseable if any. for (String key : getData().keySet()) { Object object = getData().get(key); - if (object instanceof Closeable closeable) { + if (object instanceof AutoCloseable closeable) { try { closeable.close(); - } catch (IOException e) { + } catch (Exception e) { throw new RuntimeException(e); } } } + + var runtime = getService(RuntimeService.class); + if (runtime instanceof BaseService baseService) { + baseService.getScopeManager().releaseScope(this.getId()); + } } public Parallelism getParallelism() { diff --git a/klab.core.services/src/main/java/org/integratedmodelling/klab/services/scopes/ServiceSessionScope.java b/klab.core.services/src/main/java/org/integratedmodelling/klab/services/scopes/ServiceSessionScope.java index d0154c237..37abf35a3 100644 --- a/klab.core.services/src/main/java/org/integratedmodelling/klab/services/scopes/ServiceSessionScope.java +++ b/klab.core.services/src/main/java/org/integratedmodelling/klab/services/scopes/ServiceSessionScope.java @@ -1,11 +1,13 @@ package org.integratedmodelling.klab.services.scopes; import org.integratedmodelling.klab.api.collections.Parameters; +import org.integratedmodelling.klab.api.exceptions.KlabInternalErrorException; import org.integratedmodelling.klab.api.lang.kactors.KActorsBehavior.Ref; import org.integratedmodelling.klab.api.scope.ContextScope; import org.integratedmodelling.klab.api.scope.SessionScope; import org.integratedmodelling.klab.api.services.*; import org.integratedmodelling.klab.api.services.runtime.Message; +import org.integratedmodelling.klab.services.base.BaseService; import java.util.ArrayList; import java.util.List; @@ -70,7 +72,9 @@ public T getService(Class serviceClass) { @Override public void close() { - // TODO close all contexts + for (var context : getActiveContexts()) { + context.close(); + } } public boolean isOperative() { @@ -104,6 +108,32 @@ public boolean initializeAgents(String scopeId) { @Override public List getActiveContexts() { - return List.of(); + + List ret = new ArrayList<>(); + + var runtime = getService(RuntimeService.class); + + if (runtime instanceof BaseService baseService) { + + for (var ss : runtime.getSessionInfo(this)) { + if (ss.getId().equals(this.getId())) { + for (var ctx : ss.getContexts()) { + var ctxScope = baseService.getScopeManager().getScope(ctx.getId(), + ContextScope.class); + if (ctxScope != null) { + ret.add(ctxScope); + } + } + } + } + + baseService.getScopeManager().releaseScope(this.getId()); + + } else { + throw new KlabInternalErrorException("Unexpected runtime service implementation for " + + "service-side session scope"); + } + + return ret; } } diff --git a/klab.core.services/src/main/resources/local-broker-config.json b/klab.core.services/src/main/resources/local-broker-config.json deleted file mode 100644 index b5d24c50d..000000000 --- a/klab.core.services/src/main/resources/local-broker-config.json +++ /dev/null @@ -1,40 +0,0 @@ -{ - "name": "Embedded Broker", - "modelVersion": "7.0", - "authenticationproviders" : [ { - "name" : "Scram", - "type" : "SCRAM-SHA-256", - "users" : [ { - "name" : "admin", - "type" : "managed", - "password" : "RlZheCx8NY5fmWpshDA2P1gULzLPA8GtoCe5uJgr4ms=,,mnHeeEsCki4ql4slKwooAncju7cL+5QLSxhUMzmvMJw=,z95S+Lmz5v5mESAmov1mJZN17310oMuAPyJIWtg4gBo=,4096" - } ] - }], - "ports" : [ { - "name" : "AMQP", - "port" : "${qpid.amqp_port}", - "protocols": [ "AMQP_0_9", "AMQP_0_9_1", "AMQP_1_0" ], - "authenticationProvider" : "Scram", - "virtualhostaliases" : [ { - "name" : "nameAlias", - "type" : "nameAlias" - }, { - "name" : "defaultAlias", - "type" : "defaultAlias" - }, { - "name" : "hostnameAlias", - "type" : "hostnameAlias" - } ] - }, { - "name" : "HTTP", - "port" : "${qpid.http_port}", - "authenticationProvider" : "Scram", - "protocols" : [ "HTTP" ] - }], - "virtualhostnodes" : [ { - "name" : "default", - "type" : "Memory", - "defaultVirtualHostNode" : "true", - "virtualHostInitialConfiguration" : "{\"type\": \"Memory\", \"nodeAutoCreationPolicies\": [{\"pattern\":\".*\",\"createdOnPublish\":\"true\",\"createdOnConsume\":\"true\",\"nodeType\":\"queue\",\"attributes\":{}}] }" - }] -} \ No newline at end of file diff --git a/klab.core.services/src/main/resources/log4j.yaml b/klab.core.services/src/main/resources/log4j.yaml deleted file mode 100644 index c800b8b3f..000000000 --- a/klab.core.services/src/main/resources/log4j.yaml +++ /dev/null @@ -1,46 +0,0 @@ -Configuration: - status: warn - name: k.CLI logging configuration - properties: - property: - name: filename - value: target/test-yaml.log - thresholdFilter: - level: debug - appenders: - Console: - name: STDOUT - target: SYSTEM_OUT - PatternLayout: - Pattern: "%m%n" - File: - name: File - fileName: ${filename} - PatternLayout: - Pattern: "%d %p %C{1.} [%t] %m%n" - Filters: - ThresholdFilter: - level: error - - Loggers: - logger: - - - name: org.apache.logging.log4j.test1 - level: debug - additivity: false - ThreadContextMapFilter: - KeyValuePair: - key: test - value: 123 - AppenderRef: - ref: STDOUT - - - name: org.apache.logging.log4j.test2 - level: debug - additivity: false - AppenderRef: - ref: File - Root: - level: error - AppenderRef: - ref: STDOUT \ No newline at end of file diff --git a/klab.services.runtime/src/main/java/org/integratedmodelling/klab/services/runtime/RuntimeService.java b/klab.services.runtime/src/main/java/org/integratedmodelling/klab/services/runtime/RuntimeService.java index 7d6c346db..fd8dcbd6c 100644 --- a/klab.services.runtime/src/main/java/org/integratedmodelling/klab/services/runtime/RuntimeService.java +++ b/klab.services.runtime/src/main/java/org/integratedmodelling/klab/services/runtime/RuntimeService.java @@ -461,7 +461,8 @@ public Observation runDataflow(Dataflow dataflow, ContextScope cont executionSequence.compile(rootActuator); if (!executionSequence.isEmpty()) { if (!executionSequence.run()) { - contextualization.fail(contextScope, dataflow.getTarget(), executionSequence.getCause()); + contextualization.fail(contextScope, dataflow.getTarget(), + executionSequence.getCause()); return Observation.empty(); } } @@ -544,4 +545,26 @@ public List getSessionInfo(Scope scope) { return knowledgeGraph.getSessionInfo(scope); } + @Override + public boolean releaseSession(SessionScope scope) { + try { + scope.close(); + return true; + } catch (Throwable t) { + // + } + return false; + } + + @Override + public boolean releaseContext(ContextScope scope) { + try { + scope.close(); + return true; + } catch (Throwable t) { + // + } + return false; + } + } diff --git a/klab.services.runtime/src/main/java/org/integratedmodelling/klab/services/runtime/digitaltwin/DigitalTwinImpl.java b/klab.services.runtime/src/main/java/org/integratedmodelling/klab/services/runtime/digitaltwin/DigitalTwinImpl.java index 21831799e..52cb88a2b 100644 --- a/klab.services.runtime/src/main/java/org/integratedmodelling/klab/services/runtime/digitaltwin/DigitalTwinImpl.java +++ b/klab.services.runtime/src/main/java/org/integratedmodelling/klab/services/runtime/digitaltwin/DigitalTwinImpl.java @@ -46,7 +46,8 @@ public Dataflow getDataflowGraph(ContextScope context) { @Override public void dispose() { - // TODO. Persistence depends on the database passed at initialization. + this.knowledgeGraph.deleteContext(); + this.stateStorage.clear(); } } diff --git a/klab.services.runtime/src/main/java/org/integratedmodelling/klab/services/runtime/neo4j/KnowledgeGraphNeo4j.java b/klab.services.runtime/src/main/java/org/integratedmodelling/klab/services/runtime/neo4j/KnowledgeGraphNeo4j.java index 45d330f99..ab5bc03ed 100644 --- a/klab.services.runtime/src/main/java/org/integratedmodelling/klab/services/runtime/neo4j/KnowledgeGraphNeo4j.java +++ b/klab.services.runtime/src/main/java/org/integratedmodelling/klab/services/runtime/neo4j/KnowledgeGraphNeo4j.java @@ -56,7 +56,7 @@ public abstract class KnowledgeGraphNeo4j extends AbstractKnowledgeGraph { // all predefined Cypher queries interface Queries { - String REMOVE_CONTEXT = "match (n:Context {id: $contextId})-[*]-(c) detach delete n,c"; + String REMOVE_CONTEXT = "match (n:Context {id: $contextId})-[*]->(c) detach delete n, c"; String FIND_CONTEXT = "MATCH (ctx:Context {id: $contextId}) RETURN ctx"; String CREATE_WITH_PROPERTIES = "CREATE (n:{type}) SET n = $properties RETURN n"; String UPDATE_PROPERTIES = "MATCH (n:{type} {id: $id}) SET n += $properties RETURN n";