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

Implement execution create api #1132

Merged
merged 5 commits into from
Jun 28, 2019
Merged
Show file tree
Hide file tree
Changes from 4 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
199 changes: 173 additions & 26 deletions protobuf/api/execution.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions protobuf/api/execution.proto
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ package api;
// The source file of this API is hosted on [GitHub](https://github.com/mesg-foundation/engine/blob/master/protobuf/api/execution.proto).

service Execution {
// Create creates a single Execution specified in a request.
rpc Create(CreateExecutionRequest) returns (CreateExecutionResponse) {}

// Get returns a single Execution specified in a request.
rpc Get(GetExecutionRequest) returns (types.Execution) {}

Expand All @@ -22,6 +25,20 @@ service Execution {
rpc Update(UpdateExecutionRequest) returns (UpdateExecutionResponse) {}
}

// CreateExecutionRequest defines request to create a single execution.
message CreateExecutionRequest {
string instanceHash = 1;
string taskKey = 2;
string inputs = 3;
repeated string tags = 4;
}

// CreateExecutionResponse defines response for execution creation.
message CreateExecutionResponse {
// Execution's hash.
string hash = 1;
}

// GetExecutionRequest defines request to retrieve a single execution.
message GetExecutionRequest {
// Execution's hash to fetch.
Expand Down
24 changes: 24 additions & 0 deletions server/grpc/api/execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"errors"
"fmt"

"github.com/mesg-foundation/core/execution"
"github.com/mesg-foundation/core/hash"
Expand All @@ -27,6 +28,29 @@ func NewExecutionServer(sdk *sdk.SDK) *ExecutionServer {
return &ExecutionServer{sdk: sdk}
}

// Create creates an execution.
func (s *ExecutionServer) Create(ctx context.Context, req *api.CreateExecutionRequest) (*api.CreateExecutionResponse, error) {
hash, err := hash.Decode(req.InstanceHash)
if err != nil {
return nil, err
}

var inputs map[string]interface{}
if err := json.Unmarshal([]byte(req.Inputs), &inputs); err != nil {
return nil, fmt.Errorf("cannot parse execution's inputs (JSON format): %s", err)
}

executionHash, err := s.sdk.Execution.Execute(hash, req.TaskKey, inputs, req.Tags)
if err != nil {
return nil, err
}

return &api.CreateExecutionResponse{
Hash: executionHash.String(),
}, nil

NicolasMahe marked this conversation as resolved.
Show resolved Hide resolved
}

// Get returns execution from given hash.
func (s *ExecutionServer) Get(ctx context.Context, req *api.GetExecutionRequest) (*types.Execution, error) {
hash, err := hash.Decode(req.Hash)
Expand Down