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

Pure IDE Light: Add support for Pure runtime options #2738

Merged
merged 1 commit into from
Mar 28, 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
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,11 @@
<artifactId>jackson-annotations</artifactId>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>

<dependency>
<groupId>org.eclipse.collections</groupId>
<artifactId>eclipse-collections</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down
Original file line number Diff line number Diff line change
@@ -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();
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -66,6 +66,10 @@ public class PureSession
public Message message = new Message("");

public MutableList<RepositoryCodeStorage> repos;
private final Map<String, Boolean> pureRuntimeOptions = new ConcurrentHashMap<>();

private final String PURE_OPTION_PREFIX = "pure.option.";


public PureSession(SourceLocationConfiguration sourceLocationConfiguration, MutableList<RepositoryCodeStorage> repos)
{
Expand All @@ -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);
}
Expand All @@ -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<String, Boolean> 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);
Expand Down
Loading