From 067d7a727f17721627c78d9066ce07ac70bb1834 Mon Sep 17 00:00:00 2001 From: Aziem Chawdhary <61746398+aziemchawdhary-gs@users.noreply.github.com> Date: Thu, 28 Mar 2024 14:48:07 +0000 Subject: [PATCH] Pure IDE Light: Add support for Pure runtime options (#2738) --- .../pom.xml | 5 ++ .../legend/engine/ide/PureIDEServer.java | 1 + .../engine/ide/api/PureRuntimeOptions.java | 68 +++++++++++++++++++ .../engine/ide/session/PureSession.java | 44 +++++++++++- 4 files changed, 116 insertions(+), 2 deletions(-) create mode 100644 legend-engine-pure/legend-engine-pure-ide/legend-engine-pure-ide-light-http-server/src/main/java/org/finos/legend/engine/ide/api/PureRuntimeOptions.java diff --git a/legend-engine-pure/legend-engine-pure-ide/legend-engine-pure-ide-light-http-server/pom.xml b/legend-engine-pure/legend-engine-pure-ide/legend-engine-pure-ide-light-http-server/pom.xml index 0bf20618d18..f0ee5832290 100644 --- a/legend-engine-pure/legend-engine-pure-ide/legend-engine-pure-ide-light-http-server/pom.xml +++ b/legend-engine-pure/legend-engine-pure-ide/legend-engine-pure-ide-light-http-server/pom.xml @@ -252,6 +252,11 @@ jackson-annotations + + com.fasterxml.jackson.core + jackson-databind + + org.eclipse.collections eclipse-collections diff --git a/legend-engine-pure/legend-engine-pure-ide/legend-engine-pure-ide-light-http-server/src/main/java/org/finos/legend/engine/ide/PureIDEServer.java b/legend-engine-pure/legend-engine-pure-ide/legend-engine-pure-ide-light-http-server/src/main/java/org/finos/legend/engine/ide/PureIDEServer.java index 150e3f049b4..77f2064d6c3 100644 --- a/legend-engine-pure/legend-engine-pure-ide/legend-engine-pure-ide-light-http-server/src/main/java/org/finos/legend/engine/ide/PureIDEServer.java +++ b/legend-engine-pure/legend-engine-pure-ide/legend-engine-pure-ide-light-http-server/src/main/java/org/finos/legend/engine/ide/PureIDEServer.java @@ -103,6 +103,7 @@ public void run(ServerConfiguration configuration, Environment environment) thro environment.jersey().register(new Activities(pureSession)); environment.jersey().register(new FileManagement(pureSession)); environment.jersey().register(new LifeCycle(pureSession)); + environment.jersey().register(new PureRuntimeOptions(pureSession)); environment.jersey().register(new Suggestion(pureSession)); diff --git a/legend-engine-pure/legend-engine-pure-ide/legend-engine-pure-ide-light-http-server/src/main/java/org/finos/legend/engine/ide/api/PureRuntimeOptions.java b/legend-engine-pure/legend-engine-pure-ide/legend-engine-pure-ide-light-http-server/src/main/java/org/finos/legend/engine/ide/api/PureRuntimeOptions.java new file mode 100644 index 00000000000..9f40a2fa384 --- /dev/null +++ b/legend-engine-pure/legend-engine-pure-ide/legend-engine-pure-ide-light-http-server/src/main/java/org/finos/legend/engine/ide/api/PureRuntimeOptions.java @@ -0,0 +1,68 @@ +// Copyright 2020 Goldman Sachs +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package org.finos.legend.engine.ide.api; + +import com.fasterxml.jackson.databind.ObjectMapper; +import io.swagger.annotations.Api; +import org.finos.legend.engine.ide.session.PureSession; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.StreamingOutput; + +@Api(tags = "Pure Runtime Options") +@Path("/pureRuntimeOptions") +public class PureRuntimeOptions +{ + private final PureSession pureSession; + + public PureRuntimeOptions(PureSession session) + { + this.pureSession = session; + } + + @GET + @Path("setPureRuntimeOption/{name}/{value}") + public void setPureRuntimeOption(@PathParam("name") String optionName, @PathParam("value") Boolean value) + { + this.pureSession.setPureRuntimeOption(optionName, value); + } + + @GET + @Path("getPureRuntimeOption/{name}") + public Boolean getPureRuntimeOption(@PathParam("optionName") String optionName) + { + return this.pureSession.getPureRuntimeOption(optionName); + } + + @GET + @Path("getAllPureRuntimeOptions") + public Response getAllPureRuntimeOptions(@Context HttpServletRequest request, @Context HttpServletResponse response) + { + return Response.ok((StreamingOutput) outputStream -> + { + ObjectMapper om = new ObjectMapper(); + outputStream.write(om.writeValueAsBytes(this.pureSession.getAllPureRuntimeOptions())); + outputStream.close(); + }).build(); + } + +} + diff --git a/legend-engine-pure/legend-engine-pure-ide/legend-engine-pure-ide-light-http-server/src/main/java/org/finos/legend/engine/ide/session/PureSession.java b/legend-engine-pure/legend-engine-pure-ide/legend-engine-pure-ide-light-http-server/src/main/java/org/finos/legend/engine/ide/session/PureSession.java index 7dcd1ae6bd7..d84b6253553 100644 --- a/legend-engine-pure/legend-engine-pure-ide/legend-engine-pure-ide-light-http-server/src/main/java/org/finos/legend/engine/ide/session/PureSession.java +++ b/legend-engine-pure/legend-engine-pure-ide/legend-engine-pure-ide-light-http-server/src/main/java/org/finos/legend/engine/ide/session/PureSession.java @@ -22,7 +22,6 @@ import org.finos.legend.engine.ide.SourceLocationConfiguration; import org.finos.legend.engine.ide.api.execution.test.CallBack; import org.finos.legend.engine.ide.helpers.response.IDEResponse; -import org.finos.legend.engine.ide.session.SimpleFunction; import org.finos.legend.pure.m3.SourceMutation; import org.finos.legend.pure.m3.execution.FunctionExecution; import org.finos.legend.pure.m3.execution.test.TestCollection; @@ -47,6 +46,7 @@ import java.io.InputStreamReader; import java.io.OutputStream; import java.nio.file.Paths; +import java.util.Map; import java.util.Optional; import java.util.concurrent.atomic.AtomicInteger; import java.util.regex.Pattern; @@ -66,6 +66,10 @@ public class PureSession public Message message = new Message(""); public MutableList repos; + private final Map pureRuntimeOptions = new ConcurrentHashMap<>(); + + private final String PURE_OPTION_PREFIX = "pure.option."; + public PureSession(SourceLocationConfiguration sourceLocationConfiguration, MutableList repos) { @@ -79,8 +83,28 @@ public PureSession(SourceLocationConfiguration sourceLocationConfiguration, Muta this.functionExecution = new FunctionExecutionInterpreted(VoidExecutionActivityListener.VOID_EXECUTION_ACTIVITY_LISTENER); + for (String property : System.getProperties().stringPropertyNames()) + { + if (property.startsWith(PURE_OPTION_PREFIX)) + { + setPureRuntimeOption(property.substring(PURE_OPTION_PREFIX.length()), Boolean.getBoolean(property)); + } + } + this.codeStorage = new CompositeCodeStorage(this.repos.toArray(new RepositoryCodeStorage[0])); - this.pureRuntime = new PureRuntimeBuilder(this.codeStorage).withMessage(this.message).setUseFastCompiler(true).build(); + this.pureRuntime = new PureRuntimeBuilder(this.codeStorage) + .withMessage(this.message) + .setUseFastCompiler(true) + .withOptions(new RuntimeOptions() + { + @Override + public boolean isOptionSet(String name) + { + return getPureRuntimeOption(name); + } + }) + .build(); + this.functionExecution.init(this.pureRuntime, this.message); this.codeStorage.initialize(this.message); } @@ -100,6 +124,22 @@ public FunctionExecution getFunctionExecution() return this.functionExecution; } + public boolean getPureRuntimeOption(String optionName) + { + Boolean value = this.pureRuntimeOptions.get(optionName); + return value != null && value; + } + + public Map getAllPureRuntimeOptions() + { + return this.pureRuntimeOptions; + } + + public void setPureRuntimeOption(String optionName, boolean value) + { + this.pureRuntimeOptions.put(optionName, value); + } + public TestRunner newTestRunner(int testRunId, TestCollection collection) { TestRunnerWrapper testRunnerWrapper = new TestRunnerWrapper(collection, this.getPureRuntime().executedTestTracker);