generated from finos/software-project-blueprint
-
Notifications
You must be signed in to change notification settings - Fork 237
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
Add support to debug Pure IDE executions #3314
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
113 changes: 113 additions & 0 deletions
113
...-ide-light-http-server/src/main/java/org/finos/legend/engine/ide/api/debug/Debugging.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
// Copyright 2024 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.debug; | ||
|
||
import io.swagger.annotations.Api; | ||
import java.io.InputStreamReader; | ||
import java.util.List; | ||
import java.util.Map; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
import javax.ws.rs.POST; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.core.Context; | ||
import javax.ws.rs.core.Response; | ||
import org.eclipse.collections.impl.factory.Maps; | ||
import org.finos.legend.engine.ide.session.PureSession; | ||
import org.finos.legend.engine.pure.ide.interpreted.debug.DebugState; | ||
import org.finos.legend.engine.pure.ide.interpreted.debug.FunctionExecutionInterpretedWithDebugSupport; | ||
import org.finos.legend.pure.m3.execution.FunctionExecution; | ||
import org.json.simple.JSONObject; | ||
import org.json.simple.parser.JSONParser; | ||
|
||
@Api(tags = "Debug") | ||
@Path("/") | ||
public class Debugging | ||
{ | ||
private final PureSession pureSession; | ||
|
||
public Debugging(PureSession pureSession) | ||
{ | ||
this.pureSession = pureSession; | ||
} | ||
|
||
@POST | ||
@Path("debugging") | ||
public Response debugging(@Context HttpServletRequest request, @Context HttpServletResponse response) throws Exception | ||
{ | ||
FunctionExecution functionExecution = pureSession.getFunctionExecution(); | ||
if (functionExecution instanceof FunctionExecutionInterpretedWithDebugSupport) | ||
{ | ||
FunctionExecutionInterpretedWithDebugSupport debugSupport = (FunctionExecutionInterpretedWithDebugSupport) functionExecution; | ||
DebugState debugState = debugSupport.getDebugState(); | ||
if (debugState == null) | ||
{ | ||
return Response.ok(getText("Not on debug state!")).build(); | ||
} | ||
|
||
JSONObject mainObject = (JSONObject) new JSONParser().parse(new InputStreamReader(request.getInputStream())); | ||
JSONObject extraParams = (JSONObject) mainObject.get("extraParams"); | ||
List<String> args = (List<String>) extraParams.get("args"); | ||
|
||
if (args.isEmpty()) | ||
{ | ||
args.add("summary"); | ||
} | ||
|
||
switch (args.get(0)) | ||
{ | ||
case "summary": | ||
return debugSummary(debugState); | ||
case "abort": | ||
return debugAbort(debugState); | ||
default: // no command is shortcut for evaluation | ||
return debugEvaluate(debugState, String.join(" ", args)); | ||
} | ||
} | ||
else | ||
{ | ||
return Response.status(Response.Status.BAD_REQUEST).entity("Environment does not support debug!").build(); | ||
} | ||
} | ||
|
||
private Response debugAbort(DebugState debugState) | ||
{ | ||
debugState.abort(); | ||
return Response.ok(getText("aborting execution...")).build(); | ||
} | ||
|
||
private Response debugSummary(DebugState debugState) | ||
{ | ||
return Response.ok(getText(debugState.getSummary())).build(); | ||
} | ||
|
||
private Response debugEvaluate(DebugState debugState, String command) | ||
{ | ||
try | ||
{ | ||
return Response.ok(getText(debugState.evaluate(command))).build(); | ||
} | ||
catch (Exception e) | ||
{ | ||
return Response.status(Response.Status.BAD_REQUEST).entity(getText(e.getMessage())).build(); | ||
} | ||
} | ||
|
||
private static Map<String, String> getText(String value) | ||
{ | ||
return Maps.fixedSize.of("text", value); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
...ne-pure/legend-engine-pure-ide/legend-engine-pure-ide-light-interpreted-functions/pom.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
~ Copyright 2024 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. | ||
~ | ||
--> | ||
|
||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | ||
<parent> | ||
<groupId>org.finos.legend.engine</groupId> | ||
<artifactId>legend-engine-pure-ide</artifactId> | ||
<version>4.67.9-SNAPSHOT</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>legend-engine-pure-ide-light-interpreted-functions</artifactId> | ||
<packaging>jar</packaging> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.finos.legend.engine</groupId> | ||
<artifactId>legend-engine-pure-ide-light-pure</artifactId> | ||
<scope>runtime</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.finos.legend.pure</groupId> | ||
<artifactId>legend-pure-m4</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.finos.legend.pure</groupId> | ||
<artifactId>legend-pure-m3-core</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.finos.legend.pure</groupId> | ||
<artifactId>legend-pure-runtime-java-engine-interpreted</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.eclipse.collections</groupId> | ||
<artifactId>eclipse-collections-api</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.eclipse.collections</groupId> | ||
<artifactId>eclipse-collections</artifactId> | ||
</dependency> | ||
|
||
</dependencies> | ||
</project> |
37 changes: 37 additions & 0 deletions
37
...c/main/java/org/finos/legend/engine/pure/ide/interpreted/PureIDEExtensionInterpreted.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// Copyright 2024 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.pure.ide.interpreted; | ||
|
||
import org.eclipse.collections.impl.factory.Lists; | ||
import org.eclipse.collections.impl.tuple.Tuples; | ||
import org.finos.legend.engine.pure.ide.interpreted.debug.DebugPureIDE; | ||
import org.finos.legend.pure.runtime.java.interpreted.extension.BaseInterpretedExtension; | ||
import org.finos.legend.pure.runtime.java.interpreted.extension.InterpretedExtension; | ||
|
||
public class PureIDEExtensionInterpreted extends BaseInterpretedExtension | ||
{ | ||
public PureIDEExtensionInterpreted() | ||
{ | ||
super(Lists.mutable.with( | ||
Tuples.pair("debug__Nil_0_", DebugPureIDE::new) | ||
)); | ||
} | ||
|
||
public static InterpretedExtension extension() | ||
{ | ||
return new PureIDEExtensionInterpreted(); | ||
} | ||
} |
79 changes: 79 additions & 0 deletions
79
...ctions/src/main/java/org/finos/legend/engine/pure/ide/interpreted/debug/DebugPureIDE.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
// Copyright 2024 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.pure.ide.interpreted.debug; | ||
|
||
import java.util.concurrent.CountDownLatch; | ||
import org.eclipse.collections.api.list.ListIterable; | ||
import org.eclipse.collections.api.map.MutableMap; | ||
import org.eclipse.collections.api.stack.MutableStack; | ||
import org.finos.legend.pure.m3.compiler.Context; | ||
import org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.InstanceValue; | ||
import org.finos.legend.pure.m3.exception.PureAssertFailException; | ||
import org.finos.legend.pure.m3.exception.PureExecutionException; | ||
import org.finos.legend.pure.m3.navigation.Instance; | ||
import org.finos.legend.pure.m3.navigation.M3Paths; | ||
import org.finos.legend.pure.m3.navigation.M3Properties; | ||
import org.finos.legend.pure.m3.navigation.PrimitiveUtilities; | ||
import org.finos.legend.pure.m3.navigation.ProcessorSupport; | ||
import org.finos.legend.pure.m3.navigation.ValueSpecificationBootstrap; | ||
import org.finos.legend.pure.m4.ModelRepository; | ||
import org.finos.legend.pure.m4.coreinstance.CoreInstance; | ||
import org.finos.legend.pure.runtime.java.interpreted.ExecutionSupport; | ||
import org.finos.legend.pure.runtime.java.interpreted.FunctionExecutionInterpreted; | ||
import org.finos.legend.pure.runtime.java.interpreted.VariableContext; | ||
import org.finos.legend.pure.runtime.java.interpreted.natives.InstantiationContext; | ||
import org.finos.legend.pure.runtime.java.interpreted.natives.NativeFunction; | ||
import org.finos.legend.pure.runtime.java.interpreted.profiler.Profiler; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.nio.charset.StandardCharsets; | ||
import java.util.Map; | ||
import java.util.Stack; | ||
|
||
public class DebugPureIDE extends NativeFunction | ||
{ | ||
private final FunctionExecutionInterpreted functionExecution; | ||
|
||
private final ModelRepository repository; | ||
|
||
public DebugPureIDE(FunctionExecutionInterpreted functionExecution, ModelRepository modelRepository) | ||
{ | ||
this.functionExecution = functionExecution; | ||
this.repository = modelRepository; | ||
} | ||
|
||
@Override | ||
public CoreInstance execute(ListIterable<? extends CoreInstance> params, Stack<MutableMap<String, CoreInstance>> resolvedTypeParameters, Stack<MutableMap<String, CoreInstance>> resolvedMultiplicityParameters, VariableContext variableContext, MutableStack<CoreInstance> functionExpressionCallStack, Profiler profiler, InstantiationContext instantiationContext, ExecutionSupport executionSupport, Context context, ProcessorSupport processorSupport) throws PureExecutionException | ||
{ | ||
if (this.functionExecution instanceof FunctionExecutionInterpretedWithDebugSupport) | ||
{ | ||
FunctionExecutionInterpretedWithDebugSupport debugSupport = (FunctionExecutionInterpretedWithDebugSupport) this.functionExecution; | ||
DebugState state = new DebugState( | ||
debugSupport, | ||
variableContext.getParent(), // get out of the debug function... | ||
functionExpressionCallStack | ||
); | ||
state.debug(); | ||
|
||
if (state.aborted()) | ||
{ | ||
throw new PureExecutionException("Aborting execution..."); | ||
} | ||
} | ||
|
||
return ValueSpecificationBootstrap.newBooleanLiteral(this.repository, true, this.functionExecution.getProcessorSupport()); | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To disable, we just need to replace this with the old vlaue.