Skip to content

CWL to graph endpoint - #241

Merged
mr-c merged 14 commits into
mainfrom
cwl-to-graph-endpoint
Sep 30, 2021
Merged

mr-c merged 14 commits into
mainfrom
cwl-to-graph-endpoint

Conversation

@stain

@stain stain commented Nov 21, 2019 •

Copy link
Copy Markdown
Member

Description

Adds REST resources to directly make PNG or SVG of individual CWL file POSTed.

This replaces #239 by merging in #240 to avoid temporary files.

Motivation and Context

Some workflows may need to be roughly visualized even if they are not in a git repository. The native CWL parser in CWL Viewer usually gives a "good enough" diagram when further details are not needed (e.g. labels), and is faster than having to git clone potentially large repository.

How Has This Been Tested?

Tested as part of SEEK workflow branch.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@lgtm-com

lgtm-com Bot commented Nov 21, 2019

Copy link
Copy Markdown

This pull request introduces 1 alert when merging 11a2775 into 8df24dd - view on LGTM.com

new alerts:

  • 1 for Ambiguous HTML id attribute

@lgtm-com

lgtm-com Bot commented Nov 21, 2019

Copy link
Copy Markdown

This pull request introduces 1 alert when merging 6b910b6 into 8df24dd - view on LGTM.com

new alerts:

  • 1 for Ambiguous HTML id attribute

@mr-c
mr-c changed the base branch from master to main April 15, 2021 10:05

@mr-c mr-c left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests in error: 
  CWLServiceTest.parseLobSTRDraft3WorkflowNative:124 » WorkflowNotFound
  CWLServiceTest.parseLobSTRv1WorkflowNative:135 » WorkflowNotFound

@lgtm-com

lgtm-com Bot commented Apr 15, 2021

Copy link
Copy Markdown

This pull request introduces 1 alert when merging 1553779 into aaabd77 - view on LGTM.com

new alerts:

  • 1 for Deserialization of user-controlled data

@kinow kinow left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trying to run the tests locally (learning how to build the project & run tests using this PR 👍 ). Will see if I can pinpoint what's broken in the tests 🤓


// Mock controller/MVC
CWLService mockCWLService = Mockito.mock(CWLService.class);
GraphVizService graphVizService = Mockito.mock(GraphVizService.class);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inconsistent spaces here ☝️ 👇

@kinow kinow left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left two suggestions. One fixes the unit tests. The other fixes the endpoint when using curl.

After applying the two suggestions locally:

  • all tests pass successfully
  • I can successfully download an image using curl, as shown below
curl -X POST -H "accept: image/png" -H "Content-Type: text/x-yaml" --data-binary @test.cwl http://localhost:7999/graph/png -o workflow.png

Where test.cwl has the contents of this workflow: https://raw.githubusercontent.com/common-workflow-language/cwlviewer/main/src/test/resources/cwl/lobstr-v1/lobSTR-workflow.cwl

And the output image is:

workflow

I noticed that I can use the Web UI to upload a CWL file that contains something that doesn't have a top level class attribute, or that has such attribute with a value like CommandLine. There is a button that lets me download the workflow as PNG or SVG.

However, these endpoints in this PR only allow for CWL files with a class: Workflow I think? Not a blocker IMO, thanks @stain !

}
if (!found && ! packedWorkflowId.isEmpty()) throw new WorkflowNotFoundException();
}
if (! found && extractProcess(cwlFile) != CWLProcess.WORKFLOW) {

@kinow kinow Sep 30, 2021 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stain I think this is the cause of the two test failures pointed by @mr-c . The comment below says “Check the current json node is a workflow”. But the if statement here checks that extractProcess(cwlFile) (which returns a WORKFLOW for the lobstr file used in the failing test) is checking that the returned value is not a workflow?

Inverting it all the tests pass, and it matches your comment below.

Suggested change
if (! found && extractProcess(cwlFile) != CWLProcess.WORKFLOW) {
if (! found && extractProcess(cwlFile) == CWLProcess.WORKFLOW) {


private Resource getGraphFromInputStream(InputStream in, String format)
throws IOException, NoSuchAlgorithmException {
Workflow workflow = cwlService.parseWorkflowNative(in, "", "workflow"); // first workflow will do

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stain I think here packedWorkflowId needs to be null. Otherwise posting via curl results in Workflow not found, because the parseWorkflowNative will check if (packedWorkflowId != null) and will throw WorkflowNotFoundException since it couldn't locate the packed workflow.

Suggested change
Workflow workflow = cwlService.parseWorkflowNative(in, "", "workflow"); // first workflow will do
Workflow workflow = cwlService.parseWorkflowNative(in, null, "workflow"); // first workflow will do

@mr-c

mr-c commented Sep 30, 2021

Copy link
Copy Markdown
Member

@kinow Thank you for your review and testing!

I've sent you an invite to join https://github.com/orgs/common-workflow-language/teams/people/ ( check your email ) ; once you do that you can push commits directly to this branch. Would you please accept and implement your suggestions?

@kinow

kinow commented Sep 30, 2021 •

Copy link
Copy Markdown
Member

@kinow Thank you for your review and testing!

I've sent you an invite to join https://github.com/orgs/common-workflow-language/teams/people/ ( check your email ) ; once you do that you can push commits directly to this branch.

Hi @mr-c ! I will gladly accept and join 🎉

Would you please accept and implement your suggestions?

Sure thing, will push the changes in a few minutes. Thanks!

@mr-c mr-c left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kinow Hmm.. some test failures

 Tests in error: 
  WorkflowControllerTest.downloadGraphPngFromFile:439 » NestedServlet Request pr...
  WorkflowControllerTest.downloadGraphSvgFromFile:407 » NestedServlet Request pr...

https://github.com/common-workflow-language/cwlviewer/pull/241/checks?check_run_id=3754948234#step:8:1429

@lgtm-com

lgtm-com Bot commented Sep 30, 2021

Copy link
Copy Markdown

This pull request introduces 1 alert when merging 18e0ae1 into 2dd7df5 - view on LGTM.com

new alerts:

  • 1 for Deserialization of user-controlled data

@kinow
kinow force-pushed the cwl-to-graph-endpoint branch from 18e0ae1 to d0565ca Compare September 30, 2021 10:54
@kinow

kinow commented Sep 30, 2021

Copy link
Copy Markdown
Member

@kinow Hmm.. some test failures

Sorry, forgot to update the mocked test. Edited my last commit updating the test too. In the meantime I'll test everything again locally with docker-compose to confirm everything seems to be working OK.

Let me know if you'd like me to try to rebase this PR too @mr-c 👍

@kinow

kinow commented Sep 30, 2021

Copy link
Copy Markdown
Member

Tests passed, curl downloaded image, and downloaded image via the browser too using the drop down to download as SVG.

@lgtm-com

lgtm-com Bot commented Sep 30, 2021

Copy link
Copy Markdown

This pull request introduces 1 alert when merging d0565ca into 2dd7df5 - view on LGTM.com

new alerts:

  • 1 for Deserialization of user-controlled data

@mr-c

mr-c commented Sep 30, 2021

Copy link
Copy Markdown
Member

@kinow Feel free to clean up the git history, yes please.

Any thoughts about https://github.com/common-workflow-language/cwlviewer/pull/241/files#annotation_2003129099 ?

@kinow
kinow force-pushed the cwl-to-graph-endpoint branch from d0565ca to f5e751d Compare September 30, 2021 11:28
@kinow

kinow commented Sep 30, 2021 •

Copy link
Copy Markdown
Member

@mr-c

@kinow Feel free to clean up the git history, yes please.

Rebased without - hopefully - messing up the history. Kept all commits in this branch, just had to update where a method was now using Path instead of File, and sort out some imports.

Any thoughts about https://github.com/common-workflow-language/cwlviewer/pull/241/files#annotation_2003129099 ?

IMO that issue is correct in point that there is a risk of serializing user input directly. We could either sandbox it (Jenkins does something like that with XML/XStream), or try using a library that handles that.

But that would probably be in a follow-up issue/pull request I think. It looks like this issue is being raised in a part of the file that was not changed in this PR? (sorry, not too familiar with code base yet)

@lgtm-com

lgtm-com Bot commented Sep 30, 2021

Copy link
Copy Markdown

This pull request introduces 1 alert when merging f5e751d into 2502986 - view on LGTM.com

new alerts:

  • 1 for Deserialization of user-controlled data

@mr-c

mr-c commented Sep 30, 2021

Copy link
Copy Markdown
Member

It looks like this issue is being raised in a part of the file that was not changed in this PR? (sorry, not too familiar with code base yet)

Well, now we push data directly from HTTP into YAML deserialization; where as before the data only came from Git clones (but also untrusted data). So I guess it should be a separate, but important, issue. Can you open that?

@kinow

kinow commented Sep 30, 2021

Copy link
Copy Markdown
Member

It looks like this issue is being raised in a part of the file that was not changed in this PR? (sorry, not too familiar with code base yet)

Well, now we push data directly from HTTP into YAML deserialization; where as before the data only came from Git clones (but also untrusted data).

Yup, you are correct. Just had a look at the lgtm.com link to see why the bot kept insisting that "This pull request introduces 1 alert when merging f5e751d into 2502986". Indeed we are now passing the InputStream directly to the YAML serializer.

Sorry, I thought that was already the case for that other option that downloads SVG & PNG 😳

So I guess it should be a separate, but important, issue. Can you open that?

Agreed! Will open the issue and link to this PR 👍

@lgtm-com

lgtm-com Bot commented Sep 30, 2021

Copy link
Copy Markdown

This pull request introduces 1 alert when merging d75eff1 into 2502986 - view on LGTM.com

new alerts:

  • 1 for Deserialization of user-controlled data

@mr-c
mr-c merged commit 7b8eb67 into main Sep 30, 2021
@mr-c
mr-c deleted the cwl-to-graph-endpoint branch September 30, 2021 11:52
@mr-c

mr-c commented Sep 30, 2021

Copy link
Copy Markdown
Member

Thank you @kinow @stain @fbacall !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants