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

Workflow graph structure #1209

Merged
merged 16 commits into from
Aug 13, 2019
Merged

Workflow graph structure #1209

merged 16 commits into from
Aug 13, 2019

Conversation

antho1404
Copy link
Member

@antho1404 antho1404 commented Aug 9, 2019

Update the structure of the workflow with a graph approach.

The workflow definition is now created based on a list of nodes and a list of edges that connects these nodes.
Every node need to be unique in the workflow and will be identifiable. With the node identifiable we can now store the current step when creating execution and can drop the height support that was not valid when a workflow was triggered by a result of the same workflow and the same task.

With this new stepID we can simply find the children of this node in the workflow definition graph and execute all the children's tasks.

  • SDK of execution updated to accept the stepID
  • API updated with the new workflow struct and execution stepID

TO TEST

Create and start the services with the cli or API.

// ServiceA
{"name":"serviceA","tasks":[{"inputs":[{"type":"String","key":"message"}],"outputs":[{"type":"String","key":"message"}],"key":"taskX"},{"key":"emits"}],"events":[{"data":[{"type":"String","key":"message"}],"key":"eventX"}],"configuration":{},"hash":"3kWX7CYtNwbeb1h35HiNAPctnh94MU8zstT7PSuusxyy","sid":"serviceA","source":"QmUojyMjo2JUvhktLU4royUBDEsVzU4z1onPovGpVQAFDW"}

// ServiceB
{"name":"serviceB","tasks":[{"inputs":[{"type":"String","key":"message"}],"outputs":[{"type":"String","key":"message"}],"key":"taskY"}],"configuration":{},"hash":"8ExNFweHXavpZSE9iTwjBFSDWzKcRpCXEc4BuX1UwFcg","sid":"serviceB","source":"Qmf2e92jNxxmYyjxEFrCBJdCNUS1LKNWet2ZQt3ByEUpAP"}

// ServiceC
{"name":"serviceC","tasks":[{"inputs":[{"type":"String","key":"message"}],"outputs":[{"type":"String","key":"message"}],"key":"taskZ"},{"inputs":[{"type":"String","key":"message"}],"outputs":[{"type":"String","key":"message"}],"key":"taskA"}],"configuration":{},"hash":"qTtisJG3Bso5rRxSHhnrQSkJpC3JGePD3ovvuEGVgeg","sid":"serviceC","source":"QmPuHX3LumnDkrxY3wUR8J2J9xmXGw8yTVy5jf7P24MprN"}

Create one or all the following workflow(s) with the API

eg: grpcurl -plaintext -d "$(cat result.json| jq -c .)" localhost:50052 api.Workflow/Create

// result.json
{"key":"result","trigger":{"type":2,"instanceHash":"A7712VMAiT2ehXV1nHHUnkvyTbZKVHeFxBZZj4Gx7MZk","key":"taskX","initilNode":"task1"},"nodes":[{"key":"task1","instanceHash":"DUto1J3ZAheVL6PGrwYTtGF4Bnw15CQocVdEmqkHSGbB","taskKey":"taskY"}, {"key":"task2","instanceHash":"FjFzXXme2dkLBsgPk2xgyiPD6dX5EN1dBLGqW6G9tStf","taskKey":"taskZ"}],"edges":[{"src":"task1","dst":"task2"}]}

// event.json
{"key":"event","trigger":{"type":1,"instanceHash":"A7712VMAiT2ehXV1nHHUnkvyTbZKVHeFxBZZj4Gx7MZk","key":"eventX","initialNode":"task1"},"nodes":[{"key":"task1","instanceHash":"DUto1J3ZAheVL6PGrwYTtGF4Bnw15CQocVdEmqkHSGbB","taskKey":"taskY"},{"key":"task2","instanceHash":"FjFzXXme2dkLBsgPk2xgyiPD6dX5EN1dBLGqW6G9tStf","taskKey":"taskZ"}],"edges":[{"src":"task1","dst":"task2"}]}

// result-from-other-workflow
{"key":"result-from-other-workflow","trigger":{"type":2,"instanceHash":"DUto1J3ZAheVL6PGrwYTtGF4Bnw15CQocVdEmqkHSGbB","key":"taskY","initialNode":"task1"},"nodes":[{"key":"task1","instanceHash":"FjFzXXme2dkLBsgPk2xgyiPD6dX5EN1dBLGqW6G9tStf","taskKey":"taskZ"}],"edges":[]}

Then you see the workflow by running either an event with

mesg-cli service:execute serviceA emits

or a task

mesg-cli service:execute serviceA taskX --data message=hello

@antho1404 antho1404 force-pushed the feature/steps-hash-graph branch from 56c96f7 to 6ce9291 Compare August 9, 2019 09:35
@antho1404 antho1404 self-assigned this Aug 9, 2019
@antho1404 antho1404 added the enhancement New feature or request label Aug 9, 2019
@antho1404 antho1404 added this to the next milestone Aug 9, 2019
@antho1404 antho1404 requested review from krhubert and NicolasMahe and removed request for krhubert August 9, 2019 10:19
@antho1404 antho1404 marked this pull request as ready for review August 9, 2019 10:19
@antho1404 antho1404 changed the title Feature/steps hash graph Workflow graph structure Aug 9, 2019
protobuf/api/workflow.proto Outdated Show resolved Hide resolved
protobuf/api/workflow.proto Outdated Show resolved Hide resolved
protobuf/types/execution.proto Outdated Show resolved Hide resolved
protobuf/types/execution.proto Outdated Show resolved Hide resolved
protobuf/types/workflow.proto Outdated Show resolved Hide resolved
protobuf/types/workflow.proto Outdated Show resolved Hide resolved
protobuf/types/workflow.proto Outdated Show resolved Hide resolved
workflow/type.go Outdated Show resolved Hide resolved
workflow/type.go Outdated Show resolved Hide resolved
workflow/type.go Outdated Show resolved Hide resolved
antho1404 and others added 2 commits August 9, 2019 18:41
Co-Authored-By: Nicolas Mahé <nicolas@mesg.com>
@antho1404 antho1404 force-pushed the feature/steps-hash-graph branch from 3fc0f0a to 2dfde78 Compare August 9, 2019 11:52
Key string `hash:"name:3" validate:"required"`
Key string `hash:"name:1" validate:"required"`
Trigger Trigger `hash:"name:2" validate:"required"`
Nodes []Node `hash:"name:3" validate:"dive,required"`
Copy link
Contributor

Choose a reason for hiding this comment

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

What do you think about moving the graph as a separate structure? In that case you can control and test all graph functions like searching path, walking order and more without Workflow and workflow will just use it like:

type Workflow struct {
    // ....
    g wgraph
}

Copy link
Member Author

Choose a reason for hiding this comment

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

for now, the workflow is pretty much only the graph but yes I agree that could be nice. I would still keep that as a future refactoring if the package gets bigger or we need to reuse the graph


// Edge describes the instructions for the workflow to execute a task
type Edge struct {
Src string `hash:"name:1" validate:"required"`
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't see a validation if the edge has proper src and dst.

Copy link
Member Author

Choose a reason for hiding this comment

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

yes not yet, I wanted to add the validation of nodes/edges and also the instances on another pr

@NicolasMahe
Copy link
Member

Fixed workflows to send to API:

// result.json
{"key":"result","trigger":{"type":2,"instanceHash":"HX6xrMxEZRgSN97qL6GUo6aAqpnrNDWoPiS1wae9Qi2s","key":"taskX","nodeKey":"task1"},"nodes":[{"key":"task1","instanceHash":"37Hmvhp2xmH9JPmipk1ES2ATbSVJPGt7z2cD3VDJ1dtf","taskKey":"taskY"}, {"key":"task2","instanceHash":"GbDa3xsmzY3V6HvF8XKL9gxvV6aFZoj5nNvCrFq8GDTd","taskKey":"taskZ"}],"edges":[{"src":"task1","dst":"task2"}]}

// event.json
{"key":"event","trigger":{"type":1,"instanceHash":"HX6xrMxEZRgSN97qL6GUo6aAqpnrNDWoPiS1wae9Qi2s","key":"eventX","nodeKey":"task1"},"nodes":[{"key":"task1","instanceHash":"37Hmvhp2xmH9JPmipk1ES2ATbSVJPGt7z2cD3VDJ1dtf","taskKey":"taskY"},{"key":"task2","instanceHash":"GbDa3xsmzY3V6HvF8XKL9gxvV6aFZoj5nNvCrFq8GDTd","taskKey":"taskZ"}],"edges":[{"src":"task1","dst":"task2"}]}

// result-from-other-workflow
{"key":"result-from-other-workflow","trigger":{"type":2,"instanceHash":"37Hmvhp2xmH9JPmipk1ES2ATbSVJPGt7z2cD3VDJ1dtf","key":"taskY","nodeKey":"task1"},"nodes":[{"key":"task1","instanceHash":"GbDa3xsmzY3V6HvF8XKL9gxvV6aFZoj5nNvCrFq8GDTd","taskKey":"taskZ"}],"edges":[]}

@NicolasMahe NicolasMahe merged commit 2bbcdd3 into dev Aug 13, 2019
@NicolasMahe NicolasMahe deleted the feature/steps-hash-graph branch August 13, 2019 05:37
This was referenced Aug 13, 2019
@NicolasMahe NicolasMahe modified the milestones: next, v0.13.0 Aug 16, 2019
@NicolasMahe NicolasMahe added the release:change Pull requests that change something existant label Aug 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request release:change Pull requests that change something existant
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants