From 1b2aff6cfd76d2924980222eafcd7462c2e15729 Mon Sep 17 00:00:00 2001 From: Anthony ESTEBE Date: Sat, 3 Aug 2019 16:40:45 +0700 Subject: [PATCH 1/9] move workflow model to its own ressource --- engine/workflow.go | 129 +++++++++++++++++++++++ service/type.go | 49 --------- service/workflow.go | 35 ------- workflow/type.go | 49 +++++++++ workflow/workflow.go | 136 ++++--------------------- {service => workflow}/workflow_test.go | 18 ++-- 6 files changed, 208 insertions(+), 208 deletions(-) create mode 100644 engine/workflow.go delete mode 100644 service/workflow.go create mode 100644 workflow/type.go rename {service => workflow}/workflow_test.go (69%) diff --git a/engine/workflow.go b/engine/workflow.go new file mode 100644 index 000000000..8a0f93ecd --- /dev/null +++ b/engine/workflow.go @@ -0,0 +1,129 @@ +package workflow + +import ( + "fmt" + + "github.com/mesg-foundation/engine/execution" + "github.com/mesg-foundation/engine/hash" + eventsdk "github.com/mesg-foundation/engine/sdk/event" + executionsdk "github.com/mesg-foundation/engine/sdk/execution" + servicesdk "github.com/mesg-foundation/engine/sdk/service" + "github.com/mesg-foundation/engine/workflow" +) + +// Workflow exposes functions of the workflow +type Workflow struct { + event *eventsdk.Event + eventStream *eventsdk.Listener + + execution *executionsdk.Execution + executionStream *executionsdk.Listener + + service *servicesdk.Service + + ErrC chan error +} + +// New creates a new Workflow instance +func New(event *eventsdk.Event, execution *executionsdk.Execution, service *servicesdk.Service) *Workflow { + return &Workflow{ + event: event, + execution: execution, + service: service, + ErrC: make(chan error), + } +} + +// Start the workflow engine +func (w *Workflow) Start() error { + if w.eventStream != nil || w.executionStream != nil { + return fmt.Errorf("workflow engine already running") + } + w.eventStream = w.event.GetStream(nil) + w.executionStream = w.execution.GetStream(&executionsdk.Filter{ + Statuses: []execution.Status{execution.Completed}, + }) + for { + select { + case event := <-w.eventStream.C: + go w.processTrigger(workflow.EVENT, event.InstanceHash, event.Key, event.Data, event.Hash, nil) + case execution := <-w.executionStream.C: + go w.processTrigger(workflow.RESULT, execution.InstanceHash, execution.TaskKey, execution.Outputs, nil, execution) + go w.processExecution(execution) + } + } +} + +func (w *Workflow) processTrigger(trigger workflow.TriggerType, instanceHash hash.Hash, key string, data map[string]interface{}, eventHash hash.Hash, exec *execution.Execution) { + services, err := w.service.List() + if err != nil { + w.ErrC <- err + return + } + for _, service := range services { + for _, wf := range service.Workflows { + if wf.Trigger.Match(trigger, instanceHash, key, data) { + if err := w.triggerExecution(wf, exec, eventHash, data); err != nil { + w.ErrC <- err + } + } + } + } +} + +func (w *Workflow) processExecution(exec *execution.Execution) error { + if exec.WorkflowHash.IsZero() { + return nil + } + wf, err := w.service.FindWorkflow(exec.WorkflowHash) + if err != nil { + return err + } + return w.triggerExecution(wf, exec, nil, exec.Outputs) +} + +func (w *Workflow) triggerExecution(wf *workflow.Workflow, prev *execution.Execution, eventHash hash.Hash, data map[string]interface{}) error { + height, err := w.getHeight(wf, prev) + if err != nil { + return err + } + if len(wf.Tasks) <= height { + // end of workflow + return nil + } + var parentHash hash.Hash + if prev != nil { + parentHash = prev.Hash + } + task := wf.Tasks[height] + if _, err := w.execution.Execute(wf.Hash, task.InstanceHash, eventHash, parentHash, task.TaskKey, data, []string{}); err != nil { + return err + } + return nil +} + +func (w *Workflow) getHeight(wf *workflow.Workflow, exec *execution.Execution) (int, error) { + if exec == nil { + return 0, nil + } + // Result from other workflow + if !exec.WorkflowHash.Equal(wf.Hash) { + return 0, nil + } + // Execution triggered by an event + if !exec.EventHash.IsZero() { + return 1, nil + } + if exec.ParentHash.IsZero() { + panic("parent hash should be present if event is not") + } + if exec.ParentHash.Equal(exec.Hash) { + panic("parent hash cannot be equal to execution hash") + } + parent, err := w.execution.Get(exec.ParentHash) + if err != nil { + return 0, err + } + parentHeight, err := w.getHeight(wf, parent) + return parentHeight + 1, err +} diff --git a/service/type.go b/service/type.go index b03d56b99..aa8cd2b66 100644 --- a/service/type.go +++ b/service/type.go @@ -32,23 +32,6 @@ func (s StatusType) String() string { } } -// TriggerType is the type for the possible triggers for a workflow -type TriggerType uint - -// List of possible triggers for a workflow -const ( - EVENT TriggerType = iota + 1 - RESULT -) - -// WorkflowPredicate is the type of conditions that can be applied in a filter of a workflow trigger -type WorkflowPredicate uint - -// List of possible conditions for workflow's filter -const ( - EQ WorkflowPredicate = iota + 1 -) - // WARNING about hash tags on Service type and its inner types: // * never change the name attr of hash tag. use an incremented value for // name attr when a new configuration field added to Service. @@ -91,9 +74,6 @@ type Service struct { // Source is the hash id of service's source code on IPFS. Source string `hash:"name:9" validate:"required,printascii"` - - // Workflows is a list of workflows that the service implements - Workflows []*Workflow `hash:"name:10" validate:"dive,required"` } // Dependency represents a Docker container and it holds instructions about @@ -181,32 +161,3 @@ type Parameter struct { // Definition of the structure of the object when the type is object Object []*Parameter `hash:"name:7" validate:"unique,dive,required"` } - -// Workflow describes a workflow of a service -type Workflow struct { - Hash hash.Hash `hash:"-" validate:"required"` - Trigger *WorkflowTrigger `hash:"name:1" validate:"required"` - Tasks []*WorkflowTask `hash:"name:2" validate:"required"` - Key string `hash:"name:3" validate:"required"` -} - -// WorkflowTask describes the instructions for the workflow to execute a task -type WorkflowTask struct { - InstanceHash hash.Hash `hash:"name:1" validate:"required"` - TaskKey string `hash:"name:2" validate:"printascii"` -} - -// WorkflowTrigger is an event that triggers a workflow -type WorkflowTrigger struct { - InstanceHash hash.Hash `hash:"name:1" validate:"required"` - Key string `hash:"name:2" validate:"printascii,printascii"` - Type TriggerType `hash:"name:3" validate:"required"` - Filters []*WorkflowTriggerFilter `hash:"name:4" validate:"dive,required"` -} - -// WorkflowTriggerFilter is the filter definition that can be applied to a workflow trigger -type WorkflowTriggerFilter struct { - Key string `hash:"name:1" validate:"required,printascii"` - Predicate WorkflowPredicate `hash:"name:2" validate:"required"` - Value interface{} `hash:"name:3"` -} diff --git a/service/workflow.go b/service/workflow.go deleted file mode 100644 index 3eba2dc94..000000000 --- a/service/workflow.go +++ /dev/null @@ -1,35 +0,0 @@ -package service - -import "github.com/mesg-foundation/engine/hash" - -// Match returns true if a workflow trigger is matching the given parameters -func (t *WorkflowTrigger) Match(trigger TriggerType, instanceHash hash.Hash, key string, data map[string]interface{}) bool { - if t.Type != trigger { - return false - } - if !t.InstanceHash.Equal(instanceHash) { - return false - } - - if t.Key != key { - return false - } - - for _, filter := range t.Filters { - if !filter.Match(data) { - return false - } - } - - return true -} - -// Match returns true the current filter matches the given data -func (f *WorkflowTriggerFilter) Match(inputs map[string]interface{}) bool { - switch f.Predicate { - case EQ: - return inputs[f.Key] == f.Value - default: - return false - } -} diff --git a/workflow/type.go b/workflow/type.go new file mode 100644 index 000000000..a9033d62a --- /dev/null +++ b/workflow/type.go @@ -0,0 +1,49 @@ +package workflow + +import "github.com/mesg-foundation/engine/hash" + +// TriggerType is the type for the possible triggers for a workflow +type TriggerType uint + +// List of possible triggers for a workflow +const ( + EVENT TriggerType = iota + 1 + RESULT +) + +// Predicate is the type of conditions that can be applied in a filter of a workflow trigger +type Predicate uint + +// List of possible conditions for workflow's filter +const ( + EQ Predicate = iota + 1 +) + +// Workflow describes a workflow of a service +type Workflow struct { + Hash hash.Hash `hash:"-" validate:"required"` + Trigger *Trigger `hash:"name:1" validate:"required"` + Tasks []*Task `hash:"name:2" validate:"required"` + Key string `hash:"name:3" validate:"required"` +} + +// Task describes the instructions for the workflow to execute a task +type Task struct { + InstanceHash hash.Hash `hash:"name:1" validate:"required"` + TaskKey string `hash:"name:2" validate:"printascii"` +} + +// Trigger is an event that triggers a workflow +type Trigger struct { + InstanceHash hash.Hash `hash:"name:1" validate:"required"` + Key string `hash:"name:2" validate:"printascii,printascii"` + Type TriggerType `hash:"name:3" validate:"required"` + Filters []*TriggerFilter `hash:"name:4" validate:"dive,required"` +} + +// TriggerFilter is the filter definition that can be applied to a workflow trigger +type TriggerFilter struct { + Key string `hash:"name:1" validate:"required,printascii"` + Predicate Predicate `hash:"name:2" validate:"required"` + Value interface{} `hash:"name:3"` +} diff --git a/workflow/workflow.go b/workflow/workflow.go index e6f095773..fe32b421d 100644 --- a/workflow/workflow.go +++ b/workflow/workflow.go @@ -1,129 +1,35 @@ package workflow -import ( - "fmt" +import "github.com/mesg-foundation/engine/hash" - "github.com/mesg-foundation/engine/execution" - "github.com/mesg-foundation/engine/hash" - eventsdk "github.com/mesg-foundation/engine/sdk/event" - executionsdk "github.com/mesg-foundation/engine/sdk/execution" - servicesdk "github.com/mesg-foundation/engine/sdk/service" - "github.com/mesg-foundation/engine/service" -) - -// Workflow exposes functions of the workflow -type Workflow struct { - event *eventsdk.Event - eventStream *eventsdk.Listener - - execution *executionsdk.Execution - executionStream *executionsdk.Listener - - service *servicesdk.Service - - ErrC chan error -} - -// New creates a new Workflow instance -func New(event *eventsdk.Event, execution *executionsdk.Execution, service *servicesdk.Service) *Workflow { - return &Workflow{ - event: event, - execution: execution, - service: service, - ErrC: make(chan error), +// Match returns true if a workflow trigger is matching the given parameters +func (t *Trigger) Match(trigger TriggerType, instanceHash hash.Hash, key string, data map[string]interface{}) bool { + if t.Type != trigger { + return false } -} - -// Start the workflow engine -func (w *Workflow) Start() error { - if w.eventStream != nil || w.executionStream != nil { - return fmt.Errorf("workflow engine already running") - } - w.eventStream = w.event.GetStream(nil) - w.executionStream = w.execution.GetStream(&executionsdk.Filter{ - Statuses: []execution.Status{execution.Completed}, - }) - for { - select { - case event := <-w.eventStream.C: - go w.processTrigger(service.EVENT, event.InstanceHash, event.Key, event.Data, event.Hash, nil) - case execution := <-w.executionStream.C: - go w.processTrigger(service.RESULT, execution.InstanceHash, execution.TaskKey, execution.Outputs, nil, execution) - go w.processExecution(execution) - } + if !t.InstanceHash.Equal(instanceHash) { + return false } -} -func (w *Workflow) processTrigger(trigger service.TriggerType, instanceHash hash.Hash, key string, data map[string]interface{}, eventHash hash.Hash, exec *execution.Execution) { - services, err := w.service.List() - if err != nil { - w.ErrC <- err - return - } - for _, service := range services { - for _, wf := range service.Workflows { - if wf.Trigger.Match(trigger, instanceHash, key, data) { - if err := w.triggerExecution(wf, exec, eventHash, data); err != nil { - w.ErrC <- err - } - } - } + if t.Key != key { + return false } -} -func (w *Workflow) processExecution(exec *execution.Execution) error { - if exec.WorkflowHash.IsZero() { - return nil - } - wf, err := w.service.FindWorkflow(exec.WorkflowHash) - if err != nil { - return err + for _, filter := range t.Filters { + if !filter.Match(data) { + return false + } } - return w.triggerExecution(wf, exec, nil, exec.Outputs) -} -func (w *Workflow) triggerExecution(wf *service.Workflow, prev *execution.Execution, eventHash hash.Hash, data map[string]interface{}) error { - height, err := w.getHeight(wf, prev) - if err != nil { - return err - } - if len(wf.Tasks) <= height { - // end of workflow - return nil - } - var parentHash hash.Hash - if prev != nil { - parentHash = prev.Hash - } - task := wf.Tasks[height] - if _, err := w.execution.Execute(wf.Hash, task.InstanceHash, eventHash, parentHash, task.TaskKey, data, []string{}); err != nil { - return err - } - return nil + return true } -func (w *Workflow) getHeight(wf *service.Workflow, exec *execution.Execution) (int, error) { - if exec == nil { - return 0, nil - } - // Result from other workflow - if !exec.WorkflowHash.Equal(wf.Hash) { - return 0, nil - } - // Execution triggered by an event - if !exec.EventHash.IsZero() { - return 1, nil - } - if exec.ParentHash.IsZero() { - panic("parent hash should be present if event is not") - } - if exec.ParentHash.Equal(exec.Hash) { - panic("parent hash cannot be equal to execution hash") - } - parent, err := w.execution.Get(exec.ParentHash) - if err != nil { - return 0, err +// Match returns true the current filter matches the given data +func (f *TriggerFilter) Match(inputs map[string]interface{}) bool { + switch f.Predicate { + case EQ: + return inputs[f.Key] == f.Value + default: + return false } - parentHeight, err := w.getHeight(wf, parent) - return parentHeight + 1, err } diff --git a/service/workflow_test.go b/workflow/workflow_test.go similarity index 69% rename from service/workflow_test.go rename to workflow/workflow_test.go index f1f016553..7a01d47a6 100644 --- a/service/workflow_test.go +++ b/workflow/workflow_test.go @@ -1,4 +1,4 @@ -package service +package workflow import ( "testing" @@ -9,31 +9,31 @@ import ( func TestMatch(t *testing.T) { var tests = []struct { - trigger *WorkflowTrigger + trigger *Trigger instanceHash hash.Hash key string data map[string]interface{} match bool }{ { // matching event - trigger: &WorkflowTrigger{InstanceHash: hash.Int(1), Key: "xx", Type: EVENT}, + trigger: &Trigger{InstanceHash: hash.Int(1), Key: "xx", Type: EVENT}, instanceHash: hash.Int(1), key: "xx", match: true, }, { // not matching instance - trigger: &WorkflowTrigger{InstanceHash: hash.Int(1), Type: EVENT}, + trigger: &Trigger{InstanceHash: hash.Int(1), Type: EVENT}, instanceHash: hash.Int(2), match: false, }, { // not matching event - trigger: &WorkflowTrigger{InstanceHash: hash.Int(1), Key: "xx", Type: EVENT}, + trigger: &Trigger{InstanceHash: hash.Int(1), Key: "xx", Type: EVENT}, instanceHash: hash.Int(1), key: "yy", match: false, }, { // matching filter - trigger: &WorkflowTrigger{InstanceHash: hash.Int(1), Key: "xx", Type: EVENT, Filters: []*WorkflowTriggerFilter{ + trigger: &Trigger{InstanceHash: hash.Int(1), Key: "xx", Type: EVENT, Filters: []*TriggerFilter{ {Key: "foo", Predicate: EQ, Value: "bar"}, }}, instanceHash: hash.Int(1), @@ -42,7 +42,7 @@ func TestMatch(t *testing.T) { match: true, }, { // not matching filter - trigger: &WorkflowTrigger{InstanceHash: hash.Int(1), Key: "xx", Type: EVENT, Filters: []*WorkflowTriggerFilter{ + trigger: &Trigger{InstanceHash: hash.Int(1), Key: "xx", Type: EVENT, Filters: []*TriggerFilter{ {Key: "foo", Predicate: EQ, Value: "xx"}, }}, instanceHash: hash.Int(1), @@ -51,7 +51,7 @@ func TestMatch(t *testing.T) { match: false, }, { // matching multiple filters - trigger: &WorkflowTrigger{InstanceHash: hash.Int(1), Key: "xx", Type: EVENT, Filters: []*WorkflowTriggerFilter{ + trigger: &Trigger{InstanceHash: hash.Int(1), Key: "xx", Type: EVENT, Filters: []*TriggerFilter{ {Key: "foo", Predicate: EQ, Value: "bar"}, {Key: "xxx", Predicate: EQ, Value: "yyy"}, }}, @@ -65,7 +65,7 @@ func TestMatch(t *testing.T) { match: true, }, { // non matching multiple filters - trigger: &WorkflowTrigger{InstanceHash: hash.Int(1), Key: "xx", Type: EVENT, Filters: []*WorkflowTriggerFilter{ + trigger: &Trigger{InstanceHash: hash.Int(1), Key: "xx", Type: EVENT, Filters: []*TriggerFilter{ {Key: "foo", Predicate: EQ, Value: "bar"}, {Key: "xxx", Predicate: EQ, Value: "aaa"}, }}, From f20537b0b412bb74223506547e3265a9e74d1d1a Mon Sep 17 00:00:00 2001 From: Anthony ESTEBE Date: Sat, 3 Aug 2019 16:40:55 +0700 Subject: [PATCH 2/9] create workflow db --- database/workflow_db.go | 130 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 130 insertions(+) create mode 100644 database/workflow_db.go diff --git a/database/workflow_db.go b/database/workflow_db.go new file mode 100644 index 000000000..850082768 --- /dev/null +++ b/database/workflow_db.go @@ -0,0 +1,130 @@ +package database + +import ( + "encoding/json" + "fmt" + + "github.com/mesg-foundation/engine/hash" + "github.com/mesg-foundation/engine/workflow" + "github.com/sirupsen/logrus" + "github.com/syndtr/goleveldb/leveldb" +) + +// WorkflowDB describes the API of database package. +type WorkflowDB interface { + // Save saves a workflow to database. + Save(s *workflow.Workflow) error + + // Get gets a workflow from database by its unique hash. + Get(hash hash.Hash) (*workflow.Workflow, error) + + // Delete deletes a workflow from database by its unique hash. + Delete(hash hash.Hash) error + + // All returns all workflows from database. + All() ([]*workflow.Workflow, error) + + // Close closes underlying database connection. + Close() error +} + +// LevelDBWorkflowDB is a database for storing workflows definition. +type LevelDBWorkflowDB struct { + db *leveldb.DB +} + +// NewWorkflowDB returns the database which is located under given path. +func NewWorkflowDB(path string) (*LevelDBWorkflowDB, error) { + db, err := leveldb.OpenFile(path, nil) + if err != nil { + return nil, err + } + return &LevelDBWorkflowDB{db: db}, nil +} + +// marshal returns the byte slice from workflow. +func (d *LevelDBWorkflowDB) marshal(s *workflow.Workflow) ([]byte, error) { + return json.Marshal(s) +} + +// unmarshal returns the workflow from byte slice. +func (d *LevelDBWorkflowDB) unmarshal(hash hash.Hash, value []byte) (*workflow.Workflow, error) { + var s workflow.Workflow + if err := json.Unmarshal(value, &s); err != nil { + return nil, fmt.Errorf("database: could not decode workflow %q: %s", hash, err) + } + return &s, nil +} + +// All returns every workflow in database. +func (d *LevelDBWorkflowDB) All() ([]*workflow.Workflow, error) { + var ( + workflows []*workflow.Workflow + iter = d.db.NewIterator(nil, nil) + ) + for iter.Next() { + hash := hash.Hash(iter.Key()) + s, err := d.unmarshal(hash, iter.Value()) + if err != nil { + // NOTE: Ignore all decode errors (possibly due to a workflow + // structure change or database corruption) + logrus.WithField("workflow", hash.String()).Warning(err.Error()) + continue + } + workflows = append(workflows, s) + } + iter.Release() + return workflows, iter.Error() +} + +// Delete deletes workflow from database. +func (d *LevelDBWorkflowDB) Delete(hash hash.Hash) error { + tx, err := d.db.OpenTransaction() + if err != nil { + return err + } + if _, err := tx.Get(hash, nil); err != nil { + tx.Discard() + if err == leveldb.ErrNotFound { + return &ErrNotFound{resource: "workflow", hash: hash} + } + return err + } + if err := tx.Delete(hash, nil); err != nil { + tx.Discard() + return err + } + return tx.Commit() + +} + +// Get retrives workflow from database. +func (d *LevelDBWorkflowDB) Get(hash hash.Hash) (*workflow.Workflow, error) { + b, err := d.db.Get(hash, nil) + if err != nil { + if err == leveldb.ErrNotFound { + return nil, &ErrNotFound{resource: "workflow", hash: hash} + } + return nil, err + } + return d.unmarshal(hash, b) +} + +// Save stores workflow in database. +// If there is an another workflow that uses the same sid, it'll be deleted. +func (d *LevelDBWorkflowDB) Save(s *workflow.Workflow) error { + if s.Hash.IsZero() { + return errCannotSaveWithoutHash + } + + b, err := d.marshal(s) + if err != nil { + return err + } + return d.db.Put(s.Hash, b, nil) +} + +// Close closes database. +func (d *LevelDBWorkflowDB) Close() error { + return d.db.Close() +} From 0287034edb158fe787dba91a72c857453588b25c Mon Sep 17 00:00:00 2001 From: Anthony ESTEBE Date: Sat, 3 Aug 2019 17:54:40 +0700 Subject: [PATCH 3/9] move workflow from service to its own ressource and api --- protobuf/api/service.pb.go | 75 +++-- protobuf/api/service.proto | 4 - protobuf/api/workflow.pb.go | 528 ++++++++++++++++++++++++++++++++++ protobuf/api/workflow.proto | 65 +++++ protobuf/types/service.pb.go | 389 +++---------------------- protobuf/types/service.proto | 46 --- protobuf/types/workflow.pb.go | 347 ++++++++++++++++++++++ protobuf/types/workflow.proto | 49 ++++ scripts/build-proto.sh | 2 + 9 files changed, 1059 insertions(+), 446 deletions(-) create mode 100644 protobuf/api/workflow.pb.go create mode 100644 protobuf/api/workflow.proto create mode 100644 protobuf/types/workflow.pb.go create mode 100644 protobuf/types/workflow.proto diff --git a/protobuf/api/service.pb.go b/protobuf/api/service.pb.go index dfabcac59..c8fb60b8a 100644 --- a/protobuf/api/service.pb.go +++ b/protobuf/api/service.pb.go @@ -42,12 +42,10 @@ type CreateServiceRequest struct { // Service's repository url. Repository string `protobuf:"bytes,8,opt,name=repository,proto3" json:"repository,omitempty"` // The hash id of service's source code on IPFS. - Source string `protobuf:"bytes,9,opt,name=source,proto3" json:"source,omitempty"` - // List of workflows associated to the service - Workflows []*types.Service_Workflow `protobuf:"bytes,10,rep,name=workflows,proto3" json:"workflows,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` + Source string `protobuf:"bytes,9,opt,name=source,proto3" json:"source,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` } func (m *CreateServiceRequest) Reset() { *m = CreateServiceRequest{} } @@ -138,13 +136,6 @@ func (m *CreateServiceRequest) GetSource() string { return "" } -func (m *CreateServiceRequest) GetWorkflows() []*types.Service_Workflow { - if m != nil { - return m.Workflows - } - return nil -} - // The response's data for the `Create` API. type CreateServiceResponse struct { // The service's hash created. @@ -386,36 +377,34 @@ func init() { func init() { proto.RegisterFile("protobuf/api/service.proto", fileDescriptor_0615fe53b372bcb1) } var fileDescriptor_0615fe53b372bcb1 = []byte{ - // 449 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x93, 0x41, 0x6f, 0xd3, 0x4c, - 0x10, 0x86, 0xe3, 0xcf, 0xa9, 0xdb, 0x4c, 0x3e, 0x10, 0x4c, 0xd3, 0x66, 0x6b, 0x55, 0x28, 0xf2, - 0x85, 0x50, 0x90, 0x23, 0x05, 0x71, 0x42, 0x1c, 0x4a, 0x8b, 0x7a, 0xe1, 0x64, 0x90, 0x38, 0xbb, - 0xce, 0x84, 0xae, 0x52, 0xbc, 0xcb, 0xce, 0xa6, 0x55, 0x7e, 0x12, 0x3f, 0x12, 0x09, 0x79, 0xbd, - 0x2d, 0xb1, 0xe3, 0x03, 0xb7, 0xf5, 0xbc, 0xcf, 0xcc, 0xec, 0x3b, 0xb3, 0x86, 0x58, 0x1b, 0x65, - 0xd5, 0xf5, 0x7a, 0x39, 0xcb, 0xb5, 0x9c, 0x31, 0x99, 0x3b, 0x59, 0x50, 0xea, 0x82, 0x18, 0xe6, - 0x5a, 0xc6, 0xa7, 0x8f, 0x80, 0xdd, 0x68, 0xe2, 0x26, 0x92, 0xfc, 0x0a, 0x61, 0x74, 0x61, 0x28, - 0xb7, 0xf4, 0xa5, 0x8e, 0x67, 0xf4, 0x73, 0x4d, 0x6c, 0xf1, 0x19, 0x84, 0x2c, 0x17, 0x22, 0x98, - 0x04, 0xd3, 0x41, 0x56, 0x1d, 0x11, 0xa1, 0x5f, 0xe6, 0x3f, 0x48, 0xfc, 0xe7, 0x42, 0xee, 0x8c, - 0x13, 0x18, 0x2e, 0x88, 0x0b, 0x23, 0xb5, 0x95, 0xaa, 0x14, 0xa1, 0x93, 0xb6, 0x43, 0xf8, 0x11, - 0x9e, 0x14, 0xaa, 0x5c, 0xca, 0xef, 0x6b, 0x93, 0x3b, 0xa6, 0x3f, 0x09, 0xa6, 0xc3, 0xf9, 0x69, - 0xea, 0x6e, 0x93, 0xfa, 0xae, 0xe9,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bf, 0x03, 0xd8, 0xf7, - 0x51, 0x3c, 0x87, 0xa8, 0xf6, 0x8f, 0x27, 0x69, 0xae, 0x65, 0xda, 0xf5, 0x6e, 0xe3, 0xb8, 0x4b, - 0xf2, 0x76, 0x7a, 0x55, 0x89, 0xda, 0xa9, 0x2f, 0xd1, 0x35, 0x22, 0x5f, 0xa2, 0x7b, 0x22, 0x3d, - 0x9c, 0x41, 0x78, 0x45, 0x16, 0x8f, 0x1d, 0xb4, 0x33, 0x9d, 0xb8, 0x65, 0x25, 0xe9, 0xe1, 0x7b, - 0xe8, 0x57, 0x53, 0xc0, 0xb1, 0xcb, 0xd8, 0x1d, 0x53, 0x2c, 0x76, 0x85, 0x87, 0x6e, 0xd7, 0x91, - 0xfb, 0x4d, 0xdf, 0xfe, 0x09, 0x00, 0x00, 0xff, 0xff, 0xbb, 0xcb, 0x6b, 0x98, 0xe7, 0x03, 0x00, - 0x00, + // 424 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x93, 0x4f, 0x6f, 0xd3, 0x40, + 0x10, 0xc5, 0xe3, 0x3a, 0x75, 0xdb, 0x09, 0x20, 0x98, 0xa6, 0xed, 0xd6, 0xaa, 0x50, 0xe4, 0x0b, + 0xa1, 0x20, 0x47, 0x0a, 0x47, 0xc4, 0xa1, 0xb4, 0xa8, 0x17, 0x4e, 0x86, 0x2f, 0xb0, 0x75, 0xa6, + 0x74, 0x55, 0xf0, 0x2e, 0x3b, 0x9b, 0x4a, 0xf9, 0xda, 0xdc, 0x91, 0x90, 0xd7, 0xdb, 0x2a, 0xfe, + 0x73, 0xe0, 0x36, 0x79, 0xef, 0x37, 0xb3, 0x3b, 0x2f, 0x6b, 0x48, 0x8d, 0xd5, 0x4e, 0xdf, 0xac, + 0x6f, 0x17, 0xd2, 0xa8, 0x05, 0x93, 0x7d, 0x50, 0x25, 0xe5, 0x5e, 0xc4, 0x58, 0x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xd1, 0x15, 0x53, 0x1d, 0xf1, 0x9d, 0xe4, 0xbb, 0x90, 0xba, 0xaf, 0xb3, + 0x73, 0x98, 0x5e, 0xd1, 0x4f, 0xea, 0xfd, 0x41, 0x43, 0xec, 0x09, 0x1c, 0x75, 0xd8, 0x66, 0x70, + 0xf6, 0x06, 0x5e, 0x5d, 0x93, 0xfb, 0x8f, 0x09, 0x53, 0xc0, 0xaf, 0x8a, 0x3b, 0x64, 0x76, 0x01, + 0x87, 0x2d, 0x35, 0x5c, 0xf7, 0x1c, 0xf6, 0xc3, 0x6b, 0x62, 0x11, 0xf9, 0xe8, 0x5e, 0xb4, 0xa3, + 0x2b, 0x9e, 0xfc, 0xe5, 0xdf, 0x08, 0xf6, 0x82, 0x8a, 0x17, 0x90, 0x34, 0xfb, 0xe3, 0x69, 0x2e, + 0x8d, 0xca, 0x87, 0x1e, 0x60, 0x9a, 0x0e, 0x59, 0x61, 0x9d, 0x51, 0x3d, 0xa2, 0xd9, 0x34, 0x8c, + 0x18, 0x8a, 0x28, 0x8c, 0x18, 0x4e, 0x64, 0x84, 0x0b, 0x88, 0xaf, 0xc9, 0xe1, 0xb1, 0x87, 0x7a, + 0xe9, 0xa4, 0x9d, 0x55, 0xb2, 0x11, 0x7e, 0x84, 0x71, 0x9d, 0x02, 0x9e, 0xf8, 0x8e, 0x7e, 0x4c, + 0xa9, 0xe8, 0x1b, 0x8f, 0xa7, 0xdd, 0x24, 0xfe, 0x7b, 0xfb, 0xf0, 0x2f, 0x00, 0x00, 0xff, 0xff, + 0x08, 0x1c, 0xaf, 0x2d, 0xb0, 0x03, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. diff --git a/protobuf/api/service.proto b/protobuf/api/service.proto index 88e578964..c63909caa 100644 --- a/protobuf/api/service.proto +++ b/protobuf/api/service.proto @@ -54,10 +54,6 @@ message CreateServiceRequest { // The hash id of service's source code on IPFS. string source = 9; - - // List of workflows associated to the service - repeated types.Service.Workflow workflows = 10; - } // The response's data for the `Create` API. diff --git a/protobuf/api/workflow.pb.go b/protobuf/api/workflow.pb.go new file mode 100644 index 000000000..75c512a7a --- /dev/null +++ b/protobuf/api/workflow.pb.go @@ -0,0 +1,528 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// source: protobuf/api/workflow.proto + +package api + +import ( + context "context" + fmt "fmt" + proto "github.com/golang/protobuf/proto" + types "github.com/mesg-foundation/engine/protobuf/types" + grpc "google.golang.org/grpc" + math "math" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package + +// The request's data for the `Create` API. +type CreateWorkflowRequest struct { + Key string `protobuf:"bytes,2,opt,name=key,proto3" json:"key,omitempty"` + Trigger *types.Workflow_Trigger `protobuf:"bytes,3,opt,name=trigger,proto3" json:"trigger,omitempty"` + Tasks []*types.Workflow_Task `protobuf:"bytes,4,rep,name=tasks,proto3" json:"tasks,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *CreateWorkflowRequest) Reset() { *m = CreateWorkflowRequest{} } +func (m *CreateWorkflowRequest) String() string { return proto.CompactTextString(m) } +func (*CreateWorkflowRequest) ProtoMessage() {} +func (*CreateWorkflowRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_2568c098005b7b27, []int{0} +} + +func (m *CreateWorkflowRequest) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_CreateWorkflowRequest.Unmarshal(m, b) +} +func (m *CreateWorkflowRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_CreateWorkflowRequest.Marshal(b, m, deterministic) +} +func (m *CreateWorkflowRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_CreateWorkflowRequest.Merge(m, src) +} +func (m *CreateWorkflowRequest) XXX_Size() int { + return xxx_messageInfo_CreateWorkflowRequest.Size(m) +} +func (m *CreateWorkflowRequest) XXX_DiscardUnknown() { + xxx_messageInfo_CreateWorkflowRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_CreateWorkflowRequest proto.InternalMessageInfo + +func (m *CreateWorkflowRequest) GetKey() string { + if m != nil { + return m.Key + } + return "" +} + +func (m *CreateWorkflowRequest) GetTrigger() *types.Workflow_Trigger { + if m != nil { + return m.Trigger + } + return nil +} + +func (m *CreateWorkflowRequest) GetTasks() []*types.Workflow_Task { + if m != nil { + return m.Tasks + } + return nil +} + +// The response's data for the `Create` API. +type CreateWorkflowResponse struct { + // The workflow's hash created. + Hash string `protobuf:"bytes,1,opt,name=hash,proto3" json:"hash,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *CreateWorkflowResponse) Reset() { *m = CreateWorkflowResponse{} } +func (m *CreateWorkflowResponse) String() string { return proto.CompactTextString(m) } +func (*CreateWorkflowResponse) ProtoMessage() {} +func (*CreateWorkflowResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_2568c098005b7b27, []int{1} +} + +func (m *CreateWorkflowResponse) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_CreateWorkflowResponse.Unmarshal(m, b) +} +func (m *CreateWorkflowResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_CreateWorkflowResponse.Marshal(b, m, deterministic) +} +func (m *CreateWorkflowResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_CreateWorkflowResponse.Merge(m, src) +} +func (m *CreateWorkflowResponse) XXX_Size() int { + return xxx_messageInfo_CreateWorkflowResponse.Size(m) +} +func (m *CreateWorkflowResponse) XXX_DiscardUnknown() { + xxx_messageInfo_CreateWorkflowResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_CreateWorkflowResponse proto.InternalMessageInfo + +func (m *CreateWorkflowResponse) GetHash() string { + if m != nil { + return m.Hash + } + return "" +} + +// The request's data for the `Delete` API. +type DeleteWorkflowRequest struct { + // The workflow's hash to delete. + Hash string `protobuf:"bytes,1,opt,name=hash,proto3" json:"hash,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *DeleteWorkflowRequest) Reset() { *m = DeleteWorkflowRequest{} } +func (m *DeleteWorkflowRequest) String() string { return proto.CompactTextString(m) } +func (*DeleteWorkflowRequest) ProtoMessage() {} +func (*DeleteWorkflowRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_2568c098005b7b27, []int{2} +} + +func (m *DeleteWorkflowRequest) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_DeleteWorkflowRequest.Unmarshal(m, b) +} +func (m *DeleteWorkflowRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_DeleteWorkflowRequest.Marshal(b, m, deterministic) +} +func (m *DeleteWorkflowRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_DeleteWorkflowRequest.Merge(m, src) +} +func (m *DeleteWorkflowRequest) XXX_Size() int { + return xxx_messageInfo_DeleteWorkflowRequest.Size(m) +} +func (m *DeleteWorkflowRequest) XXX_DiscardUnknown() { + xxx_messageInfo_DeleteWorkflowRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_DeleteWorkflowRequest proto.InternalMessageInfo + +func (m *DeleteWorkflowRequest) GetHash() string { + if m != nil { + return m.Hash + } + return "" +} + +// The response's data for the `Delete` API, doesn't contain anything. +type DeleteWorkflowResponse struct { + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *DeleteWorkflowResponse) Reset() { *m = DeleteWorkflowResponse{} } +func (m *DeleteWorkflowResponse) String() string { return proto.CompactTextString(m) } +func (*DeleteWorkflowResponse) ProtoMessage() {} +func (*DeleteWorkflowResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_2568c098005b7b27, []int{3} +} + +func (m *DeleteWorkflowResponse) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_DeleteWorkflowResponse.Unmarshal(m, b) +} +func (m *DeleteWorkflowResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_DeleteWorkflowResponse.Marshal(b, m, deterministic) +} +func (m *DeleteWorkflowResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_DeleteWorkflowResponse.Merge(m, src) +} +func (m *DeleteWorkflowResponse) XXX_Size() int { + return xxx_messageInfo_DeleteWorkflowResponse.Size(m) +} +func (m *DeleteWorkflowResponse) XXX_DiscardUnknown() { + xxx_messageInfo_DeleteWorkflowResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_DeleteWorkflowResponse proto.InternalMessageInfo + +// The request's data for the `Get` API. +type GetWorkflowRequest struct { + // The workflow's hash to fetch. + Hash string `protobuf:"bytes,1,opt,name=hash,proto3" json:"hash,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *GetWorkflowRequest) Reset() { *m = GetWorkflowRequest{} } +func (m *GetWorkflowRequest) String() string { return proto.CompactTextString(m) } +func (*GetWorkflowRequest) ProtoMessage() {} +func (*GetWorkflowRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_2568c098005b7b27, []int{4} +} + +func (m *GetWorkflowRequest) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_GetWorkflowRequest.Unmarshal(m, b) +} +func (m *GetWorkflowRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_GetWorkflowRequest.Marshal(b, m, deterministic) +} +func (m *GetWorkflowRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_GetWorkflowRequest.Merge(m, src) +} +func (m *GetWorkflowRequest) XXX_Size() int { + return xxx_messageInfo_GetWorkflowRequest.Size(m) +} +func (m *GetWorkflowRequest) XXX_DiscardUnknown() { + xxx_messageInfo_GetWorkflowRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_GetWorkflowRequest proto.InternalMessageInfo + +func (m *GetWorkflowRequest) GetHash() string { + if m != nil { + return m.Hash + } + return "" +} + +// The request's data for the `List` API. +type ListWorkflowRequest struct { + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *ListWorkflowRequest) Reset() { *m = ListWorkflowRequest{} } +func (m *ListWorkflowRequest) String() string { return proto.CompactTextString(m) } +func (*ListWorkflowRequest) ProtoMessage() {} +func (*ListWorkflowRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_2568c098005b7b27, []int{5} +} + +func (m *ListWorkflowRequest) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_ListWorkflowRequest.Unmarshal(m, b) +} +func (m *ListWorkflowRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_ListWorkflowRequest.Marshal(b, m, deterministic) +} +func (m *ListWorkflowRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_ListWorkflowRequest.Merge(m, src) +} +func (m *ListWorkflowRequest) XXX_Size() int { + return xxx_messageInfo_ListWorkflowRequest.Size(m) +} +func (m *ListWorkflowRequest) XXX_DiscardUnknown() { + xxx_messageInfo_ListWorkflowRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_ListWorkflowRequest proto.InternalMessageInfo + +// The response's data for the `List` API. +type ListWorkflowResponse struct { + // List of workflows that match the request's filters. + Workflows []*types.Workflow `protobuf:"bytes,1,rep,name=workflows,proto3" json:"workflows,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *ListWorkflowResponse) Reset() { *m = ListWorkflowResponse{} } +func (m *ListWorkflowResponse) String() string { return proto.CompactTextString(m) } +func (*ListWorkflowResponse) ProtoMessage() {} +func (*ListWorkflowResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_2568c098005b7b27, []int{6} +} + +func (m *ListWorkflowResponse) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_ListWorkflowResponse.Unmarshal(m, b) +} +func (m *ListWorkflowResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_ListWorkflowResponse.Marshal(b, m, deterministic) +} +func (m *ListWorkflowResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_ListWorkflowResponse.Merge(m, src) +} +func (m *ListWorkflowResponse) XXX_Size() int { + return xxx_messageInfo_ListWorkflowResponse.Size(m) +} +func (m *ListWorkflowResponse) XXX_DiscardUnknown() { + xxx_messageInfo_ListWorkflowResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_ListWorkflowResponse proto.InternalMessageInfo + +func (m *ListWorkflowResponse) GetWorkflows() []*types.Workflow { + if m != nil { + return m.Workflows + } + return nil +} + +func init() { + proto.RegisterType((*CreateWorkflowRequest)(nil), "api.CreateWorkflowRequest") + proto.RegisterType((*CreateWorkflowResponse)(nil), "api.CreateWorkflowResponse") + proto.RegisterType((*DeleteWorkflowRequest)(nil), "api.DeleteWorkflowRequest") + proto.RegisterType((*DeleteWorkflowResponse)(nil), "api.DeleteWorkflowResponse") + proto.RegisterType((*GetWorkflowRequest)(nil), "api.GetWorkflowRequest") + proto.RegisterType((*ListWorkflowRequest)(nil), "api.ListWorkflowRequest") + proto.RegisterType((*ListWorkflowResponse)(nil), "api.ListWorkflowResponse") +} + +func init() { proto.RegisterFile("protobuf/api/workflow.proto", fileDescriptor_2568c098005b7b27) } + +var fileDescriptor_2568c098005b7b27 = []byte{ + // 325 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x92, 0x4d, 0x4f, 0xfa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 0x96, 0xea, 0x77, 0xbb, 0x60, 0x06, 0x03, 0x1b, 0x2e, 0xa4, 0xc3, + 0x08, 0x70, 0x41, 0xfa, 0x2f, 0x1a, 0x7d, 0x38, 0x7f, 0x4a, 0x94, 0x8d, 0x86, 0x8f, 0xd0, 0xfb, + 0xd9, 0x2e, 0x6f, 0xbe, 0x85, 0x4e, 0x15, 0xb5, 0x62, 0x9e, 0x71, 0x7f, 0x6a, 0xb9, 0x8f, 0xbf, + 0x89, 0xd9, 0x7b, 0x13, 0x4e, 0xaa, 0x3e, 0xce, 0xa1, 0x5d, 0x24, 0x81, 0x01, 0x17, 0x32, 0xe1, + 0xce, 0x1f, 0x14, 0x8c, 0x9c, 0xb3, 0xd2, 0x57, 0xe3, 0x28, 0x52, 0x78, 0x2e, 0x45, 0x9c, 0x69, + 0x95, 0x22, 0xbf, 0x84, 0xd3, 0xc0, 0x29, 0xf8, 0x0b, 0xd2, 0x38, 0x34, 0x54, 0x3d, 0xa8, 0xc0, + 0xb6, 0x14, 0x36, 0xf0, 0x1e, 0x5a, 0xc7, 0x40, 0x90, 0x99, 0x1d, 0x47, 0x64, 0xc1, 0x85, 0x63, + 0x52, 0x7d, 0x71, 0xd9, 0x36, 0xef, 0xf2, 0xee, 0x33, 0x00, 0x00, 0xff, 0xff, 0xce, 0x68, 0x11, + 0xba, 0xda, 0x02, 0x00, 0x00, +} + +// Reference imports to suppress errors if they are not otherwise used. +var _ context.Context +var _ grpc.ClientConn + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +const _ = grpc.SupportPackageIsVersion4 + +// WorkflowClient is the client API for Workflow service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. +type WorkflowClient interface { + // Create a Workflow from a Workflow Definition. + // It will return an unique identifier which is used to interact with the Workflow. + Create(ctx context.Context, in *CreateWorkflowRequest, opts ...grpc.CallOption) (*CreateWorkflowResponse, error) + // Delete a workflow. + // An error is returned if one or more Instances of the workflow are running. + Delete(ctx context.Context, in *DeleteWorkflowRequest, opts ...grpc.CallOption) (*DeleteWorkflowResponse, error) + // Get returns a workflow matching the criteria of the request. + Get(ctx context.Context, in *GetWorkflowRequest, opts ...grpc.CallOption) (*types.Workflow, error) + // List returns workflows specified in a request. + List(ctx context.Context, in *ListWorkflowRequest, opts ...grpc.CallOption) (*ListWorkflowResponse, error) +} + +type workflowClient struct { + cc *grpc.ClientConn +} + +func NewWorkflowClient(cc *grpc.ClientConn) WorkflowClient { + return &workflowClient{cc} +} + +func (c *workflowClient) Create(ctx context.Context, in *CreateWorkflowRequest, opts ...grpc.CallOption) (*CreateWorkflowResponse, error) { + out := new(CreateWorkflowResponse) + err := c.cc.Invoke(ctx, "/api.Workflow/Create", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *workflowClient) Delete(ctx context.Context, in *DeleteWorkflowRequest, opts ...grpc.CallOption) (*DeleteWorkflowResponse, error) { + out := new(DeleteWorkflowResponse) + err := c.cc.Invoke(ctx, "/api.Workflow/Delete", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *workflowClient) Get(ctx context.Context, in *GetWorkflowRequest, opts ...grpc.CallOption) (*types.Workflow, error) { + out := new(types.Workflow) + err := c.cc.Invoke(ctx, "/api.Workflow/Get", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *workflowClient) List(ctx context.Context, in *ListWorkflowRequest, opts ...grpc.CallOption) (*ListWorkflowResponse, error) { + out := new(ListWorkflowResponse) + err := c.cc.Invoke(ctx, "/api.Workflow/List", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// WorkflowServer is the server API for Workflow service. +type WorkflowServer interface { + // Create a Workflow from a Workflow Definition. + // It will return an unique identifier which is used to interact with the Workflow. + Create(context.Context, *CreateWorkflowRequest) (*CreateWorkflowResponse, error) + // Delete a workflow. + // An error is returned if one or more Instances of the workflow are running. + Delete(context.Context, *DeleteWorkflowRequest) (*DeleteWorkflowResponse, error) + // Get returns a workflow matching the criteria of the request. + Get(context.Context, *GetWorkflowRequest) (*types.Workflow, error) + // List returns workflows specified in a request. + List(context.Context, *ListWorkflowRequest) (*ListWorkflowResponse, error) +} + +func RegisterWorkflowServer(s *grpc.Server, srv WorkflowServer) { + s.RegisterService(&_Workflow_serviceDesc, srv) +} + +func _Workflow_Create_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(CreateWorkflowRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(WorkflowServer).Create(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/api.Workflow/Create", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(WorkflowServer).Create(ctx, req.(*CreateWorkflowRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Workflow_Delete_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(DeleteWorkflowRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(WorkflowServer).Delete(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/api.Workflow/Delete", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(WorkflowServer).Delete(ctx, req.(*DeleteWorkflowRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Workflow_Get_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(GetWorkflowRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(WorkflowServer).Get(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/api.Workflow/Get", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(WorkflowServer).Get(ctx, req.(*GetWorkflowRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Workflow_List_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(ListWorkflowRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(WorkflowServer).List(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/api.Workflow/List", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(WorkflowServer).List(ctx, req.(*ListWorkflowRequest)) + } + return interceptor(ctx, in, info, handler) +} + +var _Workflow_serviceDesc = grpc.ServiceDesc{ + ServiceName: "api.Workflow", + HandlerType: (*WorkflowServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "Create", + Handler: _Workflow_Create_Handler, + }, + { + MethodName: "Delete", + Handler: _Workflow_Delete_Handler, + }, + { + MethodName: "Get", + Handler: _Workflow_Get_Handler, + }, + { + MethodName: "List", + Handler: _Workflow_List_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "protobuf/api/workflow.proto", +} diff --git a/protobuf/api/workflow.proto b/protobuf/api/workflow.proto new file mode 100644 index 000000000..91b5b93ae --- /dev/null +++ b/protobuf/api/workflow.proto @@ -0,0 +1,65 @@ +syntax = "proto3"; + +import "protobuf/types/workflow.proto"; + +package api; + +// This is the API to interact with the Workflows. +// +// This API is a [gRPC](https://grpc.io/) API. +// +// The source file of this API is hosted on [GitHub](https://github.com/mesg-foundation/engine/blob/master/protobuf/api/workflow.proto). +service Workflow { + + // Create a Workflow from a Workflow Definition. + // It will return an unique identifier which is used to interact with the Workflow. + rpc Create (CreateWorkflowRequest) returns (CreateWorkflowResponse) {} + + // Delete a workflow. + // An error is returned if one or more Instances of the workflow are running. + rpc Delete (DeleteWorkflowRequest) returns (DeleteWorkflowResponse) {} + + // Get returns a workflow matching the criteria of the request. + rpc Get(GetWorkflowRequest) returns (types.Workflow) {} + + // List returns workflows specified in a request. + rpc List(ListWorkflowRequest) returns (ListWorkflowResponse) {} +} + +// The request's data for the `Create` API. +message CreateWorkflowRequest { + string key = 2; // Workflow's key + types.Workflow.Trigger trigger = 3; // Trigger for the workflow. + repeated types.Workflow.Task tasks = 4; // Task to execute when the trigger is valid. +} + +// The response's data for the `Create` API. +message CreateWorkflowResponse { + // The workflow's hash created. + string hash = 1; +} + +// The request's data for the `Delete` API. +message DeleteWorkflowRequest { + // The workflow's hash to delete. + string hash = 1; +} + +// The response's data for the `Delete` API, doesn't contain anything. +message DeleteWorkflowResponse { +} + +// The request's data for the `Get` API. +message GetWorkflowRequest { + // The workflow's hash to fetch. + string hash = 1; +} + +// The request's data for the `List` API. +message ListWorkflowRequest {} + +// The response's data for the `List` API. +message ListWorkflowResponse { + // List of workflows that match the request's filters. + repeated types.Workflow workflows = 1; +} diff --git a/protobuf/types/service.pb.go b/protobuf/types/service.pb.go index b29562ce0..992ffd428 100644 --- a/protobuf/types/service.pb.go +++ b/protobuf/types/service.pb.go @@ -20,61 +20,6 @@ var _ = math.Inf // proto package needs to be updated. const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package -// Type of trigger available. Event to react to an event. Result to react to a result of an execution. -type Service_Workflow_Trigger_Type int32 - -const ( - Service_Workflow_Trigger_Unknown Service_Workflow_Trigger_Type = 0 - Service_Workflow_Trigger_Event Service_Workflow_Trigger_Type = 1 - Service_Workflow_Trigger_Result Service_Workflow_Trigger_Type = 2 -) - -var Service_Workflow_Trigger_Type_name = map[int32]string{ - 0: "Unknown", - 1: "Event", - 2: "Result", -} - -var Service_Workflow_Trigger_Type_value = map[string]int32{ - "Unknown": 0, - "Event": 1, - "Result": 2, -} - -func (x Service_Workflow_Trigger_Type) String() string { - return proto.EnumName(Service_Workflow_Trigger_Type_name, int32(x)) -} - -func (Service_Workflow_Trigger_Type) EnumDescriptor() ([]byte, []int) { - return fileDescriptor_578ec16019661f8f, []int{0, 5, 0, 0} -} - -// Type of condition available to compare the values. -type Service_Workflow_Trigger_Filter_Predicate int32 - -const ( - Service_Workflow_Trigger_Filter_Unknown Service_Workflow_Trigger_Filter_Predicate = 0 - Service_Workflow_Trigger_Filter_EQ Service_Workflow_Trigger_Filter_Predicate = 1 -) - -var Service_Workflow_Trigger_Filter_Predicate_name = map[int32]string{ - 0: "Unknown", - 1: "EQ", -} - -var Service_Workflow_Trigger_Filter_Predicate_value = map[string]int32{ - "Unknown": 0, - "EQ": 1, -} - -func (x Service_Workflow_Trigger_Filter_Predicate) String() string { - return proto.EnumName(Service_Workflow_Trigger_Filter_Predicate_name, int32(x)) -} - -func (Service_Workflow_Trigger_Filter_Predicate) EnumDescriptor() ([]byte, []int) { - return fileDescriptor_578ec16019661f8f, []int{0, 5, 0, 0, 0} -} - // Service represents the service's type. type Service struct { Hash string `protobuf:"bytes,10,opt,name=hash,proto3" json:"hash,omitempty"` @@ -87,7 +32,6 @@ type Service struct { Dependencies []*Service_Dependency `protobuf:"bytes,7,rep,name=dependencies,proto3" json:"dependencies,omitempty"` Repository string `protobuf:"bytes,9,opt,name=repository,proto3" json:"repository,omitempty"` Source string `protobuf:"bytes,13,opt,name=source,proto3" json:"source,omitempty"` - Workflows []*Service_Workflow `protobuf:"bytes,14,rep,name=workflows,proto3" json:"workflows,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -188,13 +132,6 @@ func (m *Service) GetSource() string { return "" } -func (m *Service) GetWorkflows() []*Service_Workflow { - if m != nil { - return m.Workflows - } - return nil -} - // Events are emitted by the service whenever the service wants. type Service_Event struct { Key string `protobuf:"bytes,4,opt,name=key,proto3" json:"key,omitempty"` @@ -595,306 +532,52 @@ func (m *Service_Dependency) GetEnv() []string { return nil } -// A workflow is a configuration to trigger a specific task when certains conditions of a trigger are valid. -type Service_Workflow struct { - Hash string `protobuf:"bytes,4,opt,name=hash,proto3" json:"hash,omitempty"` - Key string `protobuf:"bytes,3,opt,name=key,proto3" json:"key,omitempty"` - Trigger *Service_Workflow_Trigger `protobuf:"bytes,1,opt,name=trigger,proto3" json:"trigger,omitempty"` - Tasks []*Service_Workflow_Task `protobuf:"bytes,2,rep,name=tasks,proto3" json:"tasks,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *Service_Workflow) Reset() { *m = Service_Workflow{} } -func (m *Service_Workflow) String() string { return proto.CompactTextString(m) } -func (*Service_Workflow) ProtoMessage() {} -func (*Service_Workflow) Descriptor() ([]byte, []int) { - return fileDescriptor_578ec16019661f8f, []int{0, 5} -} - -func (m *Service_Workflow) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_Service_Workflow.Unmarshal(m, b) -} -func (m *Service_Workflow) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_Service_Workflow.Marshal(b, m, deterministic) -} -func (m *Service_Workflow) XXX_Merge(src proto.Message) { - xxx_messageInfo_Service_Workflow.Merge(m, src) -} -func (m *Service_Workflow) XXX_Size() int { - return xxx_messageInfo_Service_Workflow.Size(m) -} -func (m *Service_Workflow) XXX_DiscardUnknown() { - xxx_messageInfo_Service_Workflow.DiscardUnknown(m) -} - -var xxx_messageInfo_Service_Workflow proto.InternalMessageInfo - -func (m *Service_Workflow) GetHash() string { - if m != nil { - return m.Hash - } - return "" -} - -func (m *Service_Workflow) GetKey() string { - if m != nil { - return m.Key - } - return "" -} - -func (m *Service_Workflow) GetTrigger() *Service_Workflow_Trigger { - if m != nil { - return m.Trigger - } - return nil -} - -func (m *Service_Workflow) GetTasks() []*Service_Workflow_Task { - if m != nil { - return m.Tasks - } - return nil -} - -// Trigger is the configuration that will trigger a workflow. -type Service_Workflow_Trigger struct { - Type Service_Workflow_Trigger_Type `protobuf:"varint,1,opt,name=type,proto3,enum=types.Service_Workflow_Trigger_Type" json:"type,omitempty"` - InstanceHash string `protobuf:"bytes,2,opt,name=instanceHash,proto3" json:"instanceHash,omitempty"` - Key string `protobuf:"bytes,3,opt,name=key,proto3" json:"key,omitempty"` - Filters []*Service_Workflow_Trigger_Filter `protobuf:"bytes,4,rep,name=filters,proto3" json:"filters,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *Service_Workflow_Trigger) Reset() { *m = Service_Workflow_Trigger{} } -func (m *Service_Workflow_Trigger) String() string { return proto.CompactTextString(m) } -func (*Service_Workflow_Trigger) ProtoMessage() {} -func (*Service_Workflow_Trigger) Descriptor() ([]byte, []int) { - return fileDescriptor_578ec16019661f8f, []int{0, 5, 0} -} - -func (m *Service_Workflow_Trigger) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_Service_Workflow_Trigger.Unmarshal(m, b) -} -func (m *Service_Workflow_Trigger) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_Service_Workflow_Trigger.Marshal(b, m, deterministic) -} -func (m *Service_Workflow_Trigger) XXX_Merge(src proto.Message) { - xxx_messageInfo_Service_Workflow_Trigger.Merge(m, src) -} -func (m *Service_Workflow_Trigger) XXX_Size() int { - return xxx_messageInfo_Service_Workflow_Trigger.Size(m) -} -func (m *Service_Workflow_Trigger) XXX_DiscardUnknown() { - xxx_messageInfo_Service_Workflow_Trigger.DiscardUnknown(m) -} - -var xxx_messageInfo_Service_Workflow_Trigger proto.InternalMessageInfo - -func (m *Service_Workflow_Trigger) GetType() Service_Workflow_Trigger_Type { - if m != nil { - return m.Type - } - return Service_Workflow_Trigger_Unknown -} - -func (m *Service_Workflow_Trigger) GetInstanceHash() string { - if m != nil { - return m.InstanceHash - } - return "" -} - -func (m *Service_Workflow_Trigger) GetKey() string { - if m != nil { - return m.Key - } - return "" -} - -func (m *Service_Workflow_Trigger) GetFilters() []*Service_Workflow_Trigger_Filter { - if m != nil { - return m.Filters - } - return nil -} - -// Filter is applied on the data of the event/result. -type Service_Workflow_Trigger_Filter struct { - Key string `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` - Predicate Service_Workflow_Trigger_Filter_Predicate `protobuf:"varint,2,opt,name=predicate,proto3,enum=types.Service_Workflow_Trigger_Filter_Predicate" json:"predicate,omitempty"` - Value string `protobuf:"bytes,3,opt,name=value,proto3" json:"value,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *Service_Workflow_Trigger_Filter) Reset() { *m = Service_Workflow_Trigger_Filter{} } -func (m *Service_Workflow_Trigger_Filter) String() string { return proto.CompactTextString(m) } -func (*Service_Workflow_Trigger_Filter) ProtoMessage() {} -func (*Service_Workflow_Trigger_Filter) Descriptor() ([]byte, []int) { - return fileDescriptor_578ec16019661f8f, []int{0, 5, 0, 0} -} - -func (m *Service_Workflow_Trigger_Filter) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_Service_Workflow_Trigger_Filter.Unmarshal(m, b) -} -func (m *Service_Workflow_Trigger_Filter) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_Service_Workflow_Trigger_Filter.Marshal(b, m, deterministic) -} -func (m *Service_Workflow_Trigger_Filter) XXX_Merge(src proto.Message) { - xxx_messageInfo_Service_Workflow_Trigger_Filter.Merge(m, src) -} -func (m *Service_Workflow_Trigger_Filter) XXX_Size() int { - return xxx_messageInfo_Service_Workflow_Trigger_Filter.Size(m) -} -func (m *Service_Workflow_Trigger_Filter) XXX_DiscardUnknown() { - xxx_messageInfo_Service_Workflow_Trigger_Filter.DiscardUnknown(m) -} - -var xxx_messageInfo_Service_Workflow_Trigger_Filter proto.InternalMessageInfo - -func (m *Service_Workflow_Trigger_Filter) GetKey() string { - if m != nil { - return m.Key - } - return "" -} - -func (m *Service_Workflow_Trigger_Filter) GetPredicate() Service_Workflow_Trigger_Filter_Predicate { - if m != nil { - return m.Predicate - } - return Service_Workflow_Trigger_Filter_Unknown -} - -func (m *Service_Workflow_Trigger_Filter) GetValue() string { - if m != nil { - return m.Value - } - return "" -} - -// Definition of the task to execute when the workflow is triggered. -type Service_Workflow_Task struct { - InstanceHash string `protobuf:"bytes,1,opt,name=instanceHash,proto3" json:"instanceHash,omitempty"` - TaskKey string `protobuf:"bytes,2,opt,name=taskKey,proto3" json:"taskKey,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *Service_Workflow_Task) Reset() { *m = Service_Workflow_Task{} } -func (m *Service_Workflow_Task) String() string { return proto.CompactTextString(m) } -func (*Service_Workflow_Task) ProtoMessage() {} -func (*Service_Workflow_Task) Descriptor() ([]byte, []int) { - return fileDescriptor_578ec16019661f8f, []int{0, 5, 1} -} - -func (m *Service_Workflow_Task) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_Service_Workflow_Task.Unmarshal(m, b) -} -func (m *Service_Workflow_Task) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_Service_Workflow_Task.Marshal(b, m, deterministic) -} -func (m *Service_Workflow_Task) XXX_Merge(src proto.Message) { - xxx_messageInfo_Service_Workflow_Task.Merge(m, src) -} -func (m *Service_Workflow_Task) XXX_Size() int { - return xxx_messageInfo_Service_Workflow_Task.Size(m) -} -func (m *Service_Workflow_Task) XXX_DiscardUnknown() { - xxx_messageInfo_Service_Workflow_Task.DiscardUnknown(m) -} - -var xxx_messageInfo_Service_Workflow_Task proto.InternalMessageInfo - -func (m *Service_Workflow_Task) GetInstanceHash() string { - if m != nil { - return m.InstanceHash - } - return "" -} - -func (m *Service_Workflow_Task) GetTaskKey() string { - if m != nil { - return m.TaskKey - } - return "" -} - func init() { - proto.RegisterEnum("types.Service_Workflow_Trigger_Type", Service_Workflow_Trigger_Type_name, Service_Workflow_Trigger_Type_value) - proto.RegisterEnum("types.Service_Workflow_Trigger_Filter_Predicate", Service_Workflow_Trigger_Filter_Predicate_name, Service_Workflow_Trigger_Filter_Predicate_value) proto.RegisterType((*Service)(nil), "types.Service") proto.RegisterType((*Service_Event)(nil), "types.Service.Event") proto.RegisterType((*Service_Task)(nil), "types.Service.Task") proto.RegisterType((*Service_Parameter)(nil), "types.Service.Parameter") proto.RegisterType((*Service_Configuration)(nil), "types.Service.Configuration") proto.RegisterType((*Service_Dependency)(nil), "types.Service.Dependency") - proto.RegisterType((*Service_Workflow)(nil), "types.Service.Workflow") - proto.RegisterType((*Service_Workflow_Trigger)(nil), "types.Service.Workflow.Trigger") - proto.RegisterType((*Service_Workflow_Trigger_Filter)(nil), "types.Service.Workflow.Trigger.Filter") - proto.RegisterType((*Service_Workflow_Task)(nil), "types.Service.Workflow.Task") } func init() { proto.RegisterFile("protobuf/types/service.proto", fileDescriptor_578ec16019661f8f) } var fileDescriptor_578ec16019661f8f = []byte{ - // 801 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x55, 0xdd, 0x8a, 0xec, 0x44, - 0x10, 0x36, 0x33, 0x99, 0x64, 0x52, 0xb3, 0xbb, 0x0e, 0xed, 0xa2, 0x6d, 0x58, 0x74, 0x58, 0x44, - 0x56, 0x39, 0xce, 0x2c, 0x11, 0x41, 0x2f, 0x04, 0x39, 0x9e, 0x73, 0x10, 0x04, 0x39, 0xb6, 0x2b, - 0x82, 0x77, 0xbd, 0x49, 0x4d, 0x36, 0xce, 0xa4, 0x3b, 0x74, 0x77, 0x66, 0x99, 0x0b, 0xdf, 0xc0, - 0x67, 0x10, 0xf4, 0x19, 0x7c, 0x06, 0xef, 0x7d, 0x17, 0x1f, 0x40, 0xba, 0x93, 0xcc, 0x1f, 0xfb, - 0xe3, 0xdf, 0x5d, 0xfd, 0x7c, 0x95, 0xaa, 0xaf, 0xaa, 0xba, 0x02, 0x67, 0x95, 0x92, 0x46, 0x5e, - 0xd7, 0xf3, 0x99, 0x59, 0x57, 0xa8, 0x67, 0x1a, 0xd5, 0xaa,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7d, 0xde, 0xdb, - 0x7e, 0xfe, 0x2b, 0x88, 0x2a, 0x85, 0x59, 0x91, 0x72, 0x83, 0xae, 0xa2, 0x93, 0xe4, 0xf2, 0xef, - 0x25, 0x98, 0xbe, 0xec, 0xe2, 0xd8, 0xf6, 0x13, 0x76, 0x45, 0x56, 0x7c, 0x59, 0x77, 0x0f, 0xb7, - 0x51, 0xce, 0x27, 0x10, 0x6d, 0xd0, 0x64, 0x04, 0xe1, 0xb7, 0x62, 0x21, 0xe4, 0xad, 0x18, 0xbf, - 0x42, 0x02, 0xe8, 0x3d, 0xff, 0x7a, 0xec, 0x9d, 0xbf, 0x0f, 0xbe, 0x6d, 0xd5, 0xbe, 0x33, 0x6a, - 0x0f, 0xf2, 0xd8, 0x23, 0x00, 0x01, 0x43, 0x5d, 0x2f, 0xcd, 0xb8, 0x17, 0x3f, 0x6b, 0xef, 0xe4, - 0x61, 0x43, 0xbd, 0x3b, 0x1a, 0x4a, 0x21, 0xb4, 0x33, 0xfc, 0x12, 0xd7, 0x6d, 0xbf, 0x3b, 0xf5, - 0x69, 0xf2, 0xfd, 0x65, 0x5e, 0x98, 0x9b, 0xfa, 0x7a, 0x9a, 0xca, 0x72, 0x56, 0xa2, 0xce, 0x3f, - 0x98, 0xcb, 0x5a, 0x64, 0xee, 0xbd, 0xcf, 0x50, 0xe4, 0x85, 0xc0, 0xd9, 0xfe, 0x9f, 0xfe, 0x3a, - 0x70, 0xfa, 0x87, 0x7f, 0x05, 0x00, 0x00, 0xff, 0xff, 0x1d, 0x24, 0x55, 0x33, 0x02, 0x08, 0x00, - 0x00, + // 546 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x54, 0x4b, 0x8e, 0xd3, 0x40, + 0x10, 0x95, 0xc7, 0x9f, 0xc4, 0x95, 0x89, 0x84, 0x9a, 0x08, 0x35, 0xd6, 0x08, 0x45, 0xac, 0x82, + 0x34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x3e, 0x7d, 0xc6, 0xa1, + 0xb7, 0x51, 0x37, 0x4d, 0x85, 0x86, 0x7b, 0x63, 0x7f, 0x12, 0xa7, 0x1d, 0x74, 0x5e, 0x76, 0xe5, + 0x5b, 0xad, 0x2a, 0x7e, 0x46, 0xdd, 0x43, 0x8a, 0x8d, 0x20, 0xac, 0x95, 0xb6, 0x86, 0xbe, 0x83, + 0x38, 0x6d, 0x81, 0x73, 0x28, 0x74, 0x61, 0x78, 0x40, 0x24, 0xd5, 0x6e, 0x4b, 0xa6, 0xaa, 0x4a, + 0xc8, 0x9c, 0x87, 0x64, 0xbc, 0x83, 0x2e, 0x57, 0x94, 0x1b, 0x7a, 0xc8, 0x38, 0x75, 0x65, 0xf2, + 0xcd, 0x03, 0xf8, 0xf5, 0x13, 0xb8, 0x25, 0xf8, 0x11, 0x84, 0x65, 0x25, 0x8a, 0x2e, 0xf9, 0x16, + 0x1c, 0x1a, 0x39, 0xbb, 0xd3, 0x88, 0x7f, 0x87, 0x91, 0xe0, 0x36, 0x23, 0xd1, 0x9f, 0x18, 0x89, + 0xf7, 0x46, 0xae, 0xe7, 0x1f, 0xaf, 0x8a, 0xd2, 0xae, 0x9a, 0xc5, 0x34, 0x53, 0xd5, 0xac, 0x42, + 0x53, 0x3c, 0x5f, 0xaa, 0x46, 0xe6, 0x14, 0xfc, 0x0c, 0x65, 0x51, 0x4a, 0x9c, 0x1d, 0xff, 0x77, + 0x2e, 0x22, 0xc2, 0x2f, 0x7e, 0x06, 0x00, 0x00, 0xff, 0xff, 0xb0, 0x5c, 0xe1, 0xfb, 0x54, 0x05, + 0x00, 0x00, } diff --git a/protobuf/types/service.proto b/protobuf/types/service.proto index 6d652d3fe..e57ee7d96 100644 --- a/protobuf/types/service.proto +++ b/protobuf/types/service.proto @@ -55,51 +55,6 @@ message Service { repeated string env = 9; // Default env vars to apply to dependency on runtime. } - // A workflow is a configuration to trigger a specific task when certains conditions of a trigger are valid. - message Workflow { - - // Trigger is the configuration that will trigger a workflow. - message Trigger { - - // Type of trigger available. Event to react to an event. Result to react to a result of an execution. - enum Type { - Unknown = 0; // Event type not defined. - Event = 1; // React to event. - Result = 2; // React to result of an execution. - } - - // Filter is applied on the data of the event/result. - message Filter { - - // Type of condition available to compare the values. - enum Predicate { - Unknown = 0; // Predicate not defined. - EQ = 1; // Equal - } - - string key = 1; // Key to check. - Predicate predicate = 2; // Type of condition to apply. - string value = 3; // Value of the filter - } - - Type type = 1; // Type of trigger. - string instanceHash = 2; // Hash of the instance that triggers the workflow. - string key = 3; // Key that triggers the workflow (event key or task key). - repeated Filter filters = 4; // List of filters to apply on the data of the event/result. - } - - // Definition of the task to execute when the workflow is triggered. - message Task { - string instanceHash = 1; // Hash of the instance to execute. - string taskKey = 2; // Task of the instance to execute. - } - - string hash = 4; // Workflow's hash - string key = 3; // Workflow's key - Trigger trigger = 1; // Trigger for the workflow. - repeated Task tasks = 2; // Task to execute when the trigger is valid. - } - string hash = 10; // Service's hash. string sid = 12; // Service's sid. string name = 1; // Service's name. @@ -110,5 +65,4 @@ message Service { repeated Dependency dependencies = 7; // The container dependencies this service requires. string repository = 9; // Service's repository url. string source = 13; // The hash id of service's source code on IPFS. - repeated Workflow workflows = 14; // List of workflows defined by this service. } diff --git a/protobuf/types/workflow.pb.go b/protobuf/types/workflow.pb.go new file mode 100644 index 000000000..599ebae4f --- /dev/null +++ b/protobuf/types/workflow.pb.go @@ -0,0 +1,347 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// source: protobuf/types/workflow.proto + +package types + +import ( + fmt "fmt" + proto "github.com/golang/protobuf/proto" + math "math" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package + +// Type of trigger available. Event to react to an event. Result to react to a result of an execution. +type Workflow_Trigger_Type int32 + +const ( + Workflow_Trigger_Unknown Workflow_Trigger_Type = 0 + Workflow_Trigger_Event Workflow_Trigger_Type = 1 + Workflow_Trigger_Result Workflow_Trigger_Type = 2 +) + +var Workflow_Trigger_Type_name = map[int32]string{ + 0: "Unknown", + 1: "Event", + 2: "Result", +} + +var Workflow_Trigger_Type_value = map[string]int32{ + "Unknown": 0, + "Event": 1, + "Result": 2, +} + +func (x Workflow_Trigger_Type) String() string { + return proto.EnumName(Workflow_Trigger_Type_name, int32(x)) +} + +func (Workflow_Trigger_Type) EnumDescriptor() ([]byte, []int) { + return fileDescriptor_980f671c228050a1, []int{0, 0, 0} +} + +// Type of condition available to compare the values. +type Workflow_Trigger_Filter_Predicate int32 + +const ( + Workflow_Trigger_Filter_Unknown Workflow_Trigger_Filter_Predicate = 0 + Workflow_Trigger_Filter_EQ Workflow_Trigger_Filter_Predicate = 1 +) + +var Workflow_Trigger_Filter_Predicate_name = map[int32]string{ + 0: "Unknown", + 1: "EQ", +} + +var Workflow_Trigger_Filter_Predicate_value = map[string]int32{ + "Unknown": 0, + "EQ": 1, +} + +func (x Workflow_Trigger_Filter_Predicate) String() string { + return proto.EnumName(Workflow_Trigger_Filter_Predicate_name, int32(x)) +} + +func (Workflow_Trigger_Filter_Predicate) EnumDescriptor() ([]byte, []int) { + return fileDescriptor_980f671c228050a1, []int{0, 0, 0, 0} +} + +// A workflow is a configuration to trigger a specific task when certains conditions of a trigger are valid. +type Workflow struct { + Hash string `protobuf:"bytes,1,opt,name=hash,proto3" json:"hash,omitempty"` + Key string `protobuf:"bytes,2,opt,name=key,proto3" json:"key,omitempty"` + Trigger *Workflow_Trigger `protobuf:"bytes,3,opt,name=trigger,proto3" json:"trigger,omitempty"` + Tasks []*Workflow_Task `protobuf:"bytes,4,rep,name=tasks,proto3" json:"tasks,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *Workflow) Reset() { *m = Workflow{} } +func (m *Workflow) String() string { return proto.CompactTextString(m) } +func (*Workflow) ProtoMessage() {} +func (*Workflow) Descriptor() ([]byte, []int) { + return fileDescriptor_980f671c228050a1, []int{0} +} + +func (m *Workflow) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_Workflow.Unmarshal(m, b) +} +func (m *Workflow) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_Workflow.Marshal(b, m, deterministic) +} +func (m *Workflow) XXX_Merge(src proto.Message) { + xxx_messageInfo_Workflow.Merge(m, src) +} +func (m *Workflow) XXX_Size() int { + return xxx_messageInfo_Workflow.Size(m) +} +func (m *Workflow) XXX_DiscardUnknown() { + xxx_messageInfo_Workflow.DiscardUnknown(m) +} + +var xxx_messageInfo_Workflow proto.InternalMessageInfo + +func (m *Workflow) GetHash() string { + if m != nil { + return m.Hash + } + return "" +} + +func (m *Workflow) GetKey() string { + if m != nil { + return m.Key + } + return "" +} + +func (m *Workflow) GetTrigger() *Workflow_Trigger { + if m != nil { + return m.Trigger + } + return nil +} + +func (m *Workflow) GetTasks() []*Workflow_Task { + if m != nil { + return m.Tasks + } + return nil +} + +// Trigger is the configuration that will trigger a workflow. +type Workflow_Trigger struct { + Type Workflow_Trigger_Type `protobuf:"varint,1,opt,name=type,proto3,enum=types.Workflow_Trigger_Type" json:"type,omitempty"` + InstanceHash string `protobuf:"bytes,2,opt,name=instanceHash,proto3" json:"instanceHash,omitempty"` + Key string `protobuf:"bytes,3,opt,name=key,proto3" json:"key,omitempty"` + Filters []*Workflow_Trigger_Filter `protobuf:"bytes,4,rep,name=filters,proto3" json:"filters,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *Workflow_Trigger) Reset() { *m = Workflow_Trigger{} } +func (m *Workflow_Trigger) String() string { return proto.CompactTextString(m) } +func (*Workflow_Trigger) ProtoMessage() {} +func (*Workflow_Trigger) Descriptor() ([]byte, []int) { + return fileDescriptor_980f671c228050a1, []int{0, 0} +} + +func (m *Workflow_Trigger) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_Workflow_Trigger.Unmarshal(m, b) +} +func (m *Workflow_Trigger) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_Workflow_Trigger.Marshal(b, m, deterministic) +} +func (m *Workflow_Trigger) XXX_Merge(src proto.Message) { + xxx_messageInfo_Workflow_Trigger.Merge(m, src) +} +func (m *Workflow_Trigger) XXX_Size() int { + return xxx_messageInfo_Workflow_Trigger.Size(m) +} +func (m *Workflow_Trigger) XXX_DiscardUnknown() { + xxx_messageInfo_Workflow_Trigger.DiscardUnknown(m) +} + +var xxx_messageInfo_Workflow_Trigger proto.InternalMessageInfo + +func (m *Workflow_Trigger) GetType() Workflow_Trigger_Type { + if m != nil { + return m.Type + } + return Workflow_Trigger_Unknown +} + +func (m *Workflow_Trigger) GetInstanceHash() string { + if m != nil { + return m.InstanceHash + } + return "" +} + +func (m *Workflow_Trigger) GetKey() string { + if m != nil { + return m.Key + } + return "" +} + +func (m *Workflow_Trigger) GetFilters() []*Workflow_Trigger_Filter { + if m != nil { + return m.Filters + } + return nil +} + +// Filter is applied on the data of the event/result. +type Workflow_Trigger_Filter struct { + Key string `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` + Predicate Workflow_Trigger_Filter_Predicate `protobuf:"varint,2,opt,name=predicate,proto3,enum=types.Workflow_Trigger_Filter_Predicate" json:"predicate,omitempty"` + Value string `protobuf:"bytes,3,opt,name=value,proto3" json:"value,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *Workflow_Trigger_Filter) Reset() { *m = Workflow_Trigger_Filter{} } +func (m *Workflow_Trigger_Filter) String() string { return proto.CompactTextString(m) } +func (*Workflow_Trigger_Filter) ProtoMessage() {} +func (*Workflow_Trigger_Filter) Descriptor() ([]byte, []int) { + return fileDescriptor_980f671c228050a1, []int{0, 0, 0} +} + +func (m *Workflow_Trigger_Filter) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_Workflow_Trigger_Filter.Unmarshal(m, b) +} +func (m *Workflow_Trigger_Filter) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_Workflow_Trigger_Filter.Marshal(b, m, deterministic) +} +func (m *Workflow_Trigger_Filter) XXX_Merge(src proto.Message) { + xxx_messageInfo_Workflow_Trigger_Filter.Merge(m, src) +} +func (m *Workflow_Trigger_Filter) XXX_Size() int { + return xxx_messageInfo_Workflow_Trigger_Filter.Size(m) +} +func (m *Workflow_Trigger_Filter) XXX_DiscardUnknown() { + xxx_messageInfo_Workflow_Trigger_Filter.DiscardUnknown(m) +} + +var xxx_messageInfo_Workflow_Trigger_Filter proto.InternalMessageInfo + +func (m *Workflow_Trigger_Filter) GetKey() string { + if m != nil { + return m.Key + } + return "" +} + +func (m *Workflow_Trigger_Filter) GetPredicate() Workflow_Trigger_Filter_Predicate { + if m != nil { + return m.Predicate + } + return Workflow_Trigger_Filter_Unknown +} + +func (m *Workflow_Trigger_Filter) GetValue() string { + if m != nil { + return m.Value + } + return "" +} + +// Definition of the task to execute when the workflow is triggered. +type Workflow_Task struct { + InstanceHash string `protobuf:"bytes,1,opt,name=instanceHash,proto3" json:"instanceHash,omitempty"` + TaskKey string `protobuf:"bytes,2,opt,name=taskKey,proto3" json:"taskKey,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *Workflow_Task) Reset() { *m = Workflow_Task{} } +func (m *Workflow_Task) String() string { return proto.CompactTextString(m) } +func (*Workflow_Task) ProtoMessage() {} +func (*Workflow_Task) Descriptor() ([]byte, []int) { + return fileDescriptor_980f671c228050a1, []int{0, 1} +} + +func (m *Workflow_Task) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_Workflow_Task.Unmarshal(m, b) +} +func (m *Workflow_Task) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_Workflow_Task.Marshal(b, m, deterministic) +} +func (m *Workflow_Task) XXX_Merge(src proto.Message) { + xxx_messageInfo_Workflow_Task.Merge(m, src) +} +func (m *Workflow_Task) XXX_Size() int { + return xxx_messageInfo_Workflow_Task.Size(m) +} +func (m *Workflow_Task) XXX_DiscardUnknown() { + xxx_messageInfo_Workflow_Task.DiscardUnknown(m) +} + +var xxx_messageInfo_Workflow_Task proto.InternalMessageInfo + +func (m *Workflow_Task) GetInstanceHash() string { + if m != nil { + return m.InstanceHash + } + return "" +} + +func (m *Workflow_Task) GetTaskKey() string { + if m != nil { + return m.TaskKey + } + return "" +} + +func init() { + proto.RegisterEnum("types.Workflow_Trigger_Type", Workflow_Trigger_Type_name, Workflow_Trigger_Type_value) + proto.RegisterEnum("types.Workflow_Trigger_Filter_Predicate", Workflow_Trigger_Filter_Predicate_name, Workflow_Trigger_Filter_Predicate_value) + proto.RegisterType((*Workflow)(nil), "types.Workflow") + proto.RegisterType((*Workflow_Trigger)(nil), "types.Workflow.Trigger") + proto.RegisterType((*Workflow_Trigger_Filter)(nil), "types.Workflow.Trigger.Filter") + proto.RegisterType((*Workflow_Task)(nil), "types.Workflow.Task") +} + +func init() { proto.RegisterFile("protobuf/types/workflow.proto", fileDescriptor_980f671c228050a1) } + +var fileDescriptor_980f671c228050a1 = []byte{ + // 380 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x7c, 0x52, 0xcd, 0xca, 0xd3, 0x40, + 0x14, 0x75, 0xf2, 0x6b, 0x6e, 0xa5, 0x84, 0xa1, 0x60, 0x28, 0x2a, 0x21, 0xab, 0x50, 0x30, 0xa9, + 0x71, 0xe3, 0x5a, 0x6c, 0x11, 0xdc, 0x68, 0xa8, 0x08, 0xee, 0xd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2d, 0x55, 0xf4, 0xe9, 0x1f, 0x04, 0xd6, 0x80, 0x29, 0x59, 0x74, 0x95, 0x5d, 0x82, 0xd3, + 0xb4, 0x64, 0x5b, 0x6e, 0x32, 0x41, 0xa4, 0x93, 0x71, 0x12, 0x3e, 0x2f, 0x1c, 0x7d, 0x57, 0xfc, + 0xf4, 0xfa, 0x15, 0x4f, 0xc0, 0x3c, 0x64, 0x75, 0x47, 0xce, 0x96, 0x87, 0x20, 0xf0, 0xc1, 0xb9, + 0xb0, 0xf1, 0x08, 0xec, 0x9f, 0xb4, 0xa2, 0xec, 0x48, 0xdd, 0x17, 0xd8, 0x02, 0x6d, 0xf1, 0xc3, + 0x45, 0xc1, 0x0c, 0x8c, 0x7e, 0x34, 0xb7, 0x49, 0x07, 0xcc, 0xc5, 0x81, 0x50, 0xe1, 0x22, 0x0c, + 0x60, 0xa5, 0x84, 0x77, 0xb5, 0x70, 0xb5, 0xe9, 0x17, 0x30, 0xfa, 0x2d, 0xdc, 0x0d, 0x10, 0x3d, + 0x31, 0x40, 0x0f, 0xec, 0x7e, 0x57, 0xdf, 0x2e, 0x77, 0xa1, 0xc2, 0xcf, 0xc9, 0xef, 0x79, 0x51, + 0x8a, 0x5d, 0xb7, 0x8e, 0x36, 0x6c, 0x1f, 0xef, 0x09, 0x2f, 0xde, 0xe7, 0xac, 0xa3, 0xdb, 0x4c, + 0x94, 0x8c, 0xc6, 0x84, 0x16, 0x25, 0x25, 0xf1, 0xed, 0x61, 0xae, 0x2d, 0x19, 0x7f, 0xfc, 0x1f, + 0x00, 0x00, 0xff, 0xff, 0xe0, 0x2b, 0xd9, 0xd4, 0xb1, 0x02, 0x00, 0x00, +} diff --git a/protobuf/types/workflow.proto b/protobuf/types/workflow.proto new file mode 100644 index 000000000..6b185d3dd --- /dev/null +++ b/protobuf/types/workflow.proto @@ -0,0 +1,49 @@ +syntax = "proto3"; + +package types; +option go_package = "github.com/mesg-foundation/engine/protobuf/types"; + +// A workflow is a configuration to trigger a specific task when certains conditions of a trigger are valid. +message Workflow { + + // Trigger is the configuration that will trigger a workflow. + message Trigger { + + // Type of trigger available. Event to react to an event. Result to react to a result of an execution. + enum Type { + Unknown = 0; // Event type not defined. + Event = 1; // React to event. + Result = 2; // React to result of an execution. + } + + // Filter is applied on the data of the event/result. + message Filter { + + // Type of condition available to compare the values. + enum Predicate { + Unknown = 0; // Predicate not defined. + EQ = 1; // Equal + } + + string key = 1; // Key to check. + Predicate predicate = 2; // Type of condition to apply. + string value = 3; // Value of the filter + } + + Type type = 1; // Type of trigger. + string instanceHash = 2; // Hash of the instance that triggers the workflow. + string key = 3; // Key that triggers the workflow (event key or task key). + repeated Filter filters = 4; // List of filters to apply on the data of the event/result. + } + + // Definition of the task to execute when the workflow is triggered. + message Task { + string instanceHash = 1; // Hash of the instance to execute. + string taskKey = 2; // Task of the instance to execute. + } + + string hash = 1; // Workflow's hash + string key = 2; // Workflow's key + Trigger trigger = 3; // Trigger for the workflow. + repeated Task tasks = 4; // Task to execute when the trigger is valid. +} diff --git a/scripts/build-proto.sh b/scripts/build-proto.sh index c6f5c9454..c471e2065 100755 --- a/scripts/build-proto.sh +++ b/scripts/build-proto.sh @@ -11,10 +11,12 @@ protoc $GRPC_PLUGIN --proto_path=$PROJECT $GRPC/types/event.proto protoc $GRPC_PLUGIN --proto_path=$PROJECT $GRPC/types/execution.proto protoc $GRPC_PLUGIN --proto_path=$PROJECT $GRPC/types/instance.proto protoc $GRPC_PLUGIN --proto_path=$PROJECT $GRPC/types/service.proto +protoc $GRPC_PLUGIN --proto_path=$PROJECT $GRPC/types/workflow.proto protoc $GRPC_PLUGIN --proto_path=$PROJECT $GRPC/api/event.proto protoc $GRPC_PLUGIN --proto_path=$PROJECT $GRPC/api/execution.proto protoc $GRPC_PLUGIN --proto_path=$PROJECT $GRPC/api/instance.proto protoc $GRPC_PLUGIN --proto_path=$PROJECT $GRPC/api/service.proto +protoc $GRPC_PLUGIN --proto_path=$PROJECT $GRPC/api/workflow.proto protoc $GRPC_PLUGIN --proto_path=$PROJECT $GRPC/coreapi/api.proto From e3a45fcbb180c11fe368866f0d2aefe0c6654e1d Mon Sep 17 00:00:00 2001 From: Anthony ESTEBE Date: Sat, 3 Aug 2019 17:57:11 +0700 Subject: [PATCH 4/9] create and use workflow sdk --- config/config.go | 3 ++ core/main.go | 14 +++++++-- engine/workflow.go | 24 +++++++-------- sdk/execution/execution.go | 7 +++-- sdk/sdk.go | 8 +++-- sdk/service/service.go | 19 ------------ sdk/workflow/workflow.go | 61 ++++++++++++++++++++++++++++++++++++++ 7 files changed, 97 insertions(+), 39 deletions(-) create mode 100644 sdk/workflow/workflow.go diff --git a/config/config.go b/config/config.go index 9e0786eee..6b9cb420a 100644 --- a/config/config.go +++ b/config/config.go @@ -18,6 +18,7 @@ const ( serviceDBVersion = "v3" executionDBVersion = "v2" instanceDBVersion = "v1" + workflowDBVersion = "v1" ) var ( @@ -44,6 +45,7 @@ type Config struct { ServiceRelativePath string InstanceRelativePath string ExecutionRelativePath string + WorkflowRelativePath string } SystemServices []*ServiceConfig @@ -66,6 +68,7 @@ func New() (*Config, error) { c.Database.ServiceRelativePath = filepath.Join("database", "services", serviceDBVersion) c.Database.InstanceRelativePath = filepath.Join("database", "instance", instanceDBVersion) c.Database.ExecutionRelativePath = filepath.Join("database", "executions", executionDBVersion) + c.Database.WorkflowRelativePath = filepath.Join("database", "workflows", workflowDBVersion) c.setupServices() return &c, nil } diff --git a/core/main.go b/core/main.go index abfe32c8a..481c5e846 100644 --- a/core/main.go +++ b/core/main.go @@ -8,6 +8,7 @@ import ( "github.com/mesg-foundation/engine/config" "github.com/mesg-foundation/engine/container" "github.com/mesg-foundation/engine/database" + "github.com/mesg-foundation/engine/engine" "github.com/mesg-foundation/engine/hash" "github.com/mesg-foundation/engine/logger" "github.com/mesg-foundation/engine/sdk" @@ -15,7 +16,6 @@ import ( servicesdk "github.com/mesg-foundation/engine/sdk/service" "github.com/mesg-foundation/engine/server/grpc" "github.com/mesg-foundation/engine/version" - "github.com/mesg-foundation/engine/workflow" "github.com/mesg-foundation/engine/x/xerrors" "github.com/mesg-foundation/engine/x/xnet" "github.com/mesg-foundation/engine/x/xos" @@ -27,6 +27,7 @@ type dependencies struct { config *config.Config serviceDB database.ServiceDB executionDB database.ExecutionDB + workflowDB database.WorkflowDB container container.Container sdk *sdk.SDK } @@ -56,6 +57,12 @@ func initDependencies() (*dependencies, error) { return nil, err } + // init workflow db. + workflowDB, err := database.NewWorkflowDB(filepath.Join(config.Path, config.Database.WorkflowRelativePath)) + if err != nil { + return nil, err + } + // init container. c, err := container.New(config.Name) if err != nil { @@ -65,13 +72,14 @@ func initDependencies() (*dependencies, error) { _, port, _ := xnet.SplitHostPort(config.Server.Address) // init sdk. - sdk := sdk.New(c, serviceDB, instanceDB, executionDB, config.Name, strconv.Itoa(port)) + sdk := sdk.New(c, serviceDB, instanceDB, executionDB, workflowDB, config.Name, strconv.Itoa(port)) return &dependencies{ config: config, container: c, serviceDB: serviceDB, executionDB: executionDB, + workflowDB: workflowDB, sdk: sdk, }, nil } @@ -165,7 +173,7 @@ func main() { }() logrus.Info("starting workflow engine") - wf := workflow.New(dep.sdk.Event, dep.sdk.Execution, dep.sdk.Service) + wf := engine.New(dep.sdk.Event, dep.sdk.Execution, dep.sdk.Workflow) go func() { if err := wf.Start(); err != nil { logrus.Fatalln(err) diff --git a/engine/workflow.go b/engine/workflow.go index 8a0f93ecd..1b61dc6af 100644 --- a/engine/workflow.go +++ b/engine/workflow.go @@ -1,4 +1,4 @@ -package workflow +package engine import ( "fmt" @@ -7,7 +7,7 @@ import ( "github.com/mesg-foundation/engine/hash" eventsdk "github.com/mesg-foundation/engine/sdk/event" executionsdk "github.com/mesg-foundation/engine/sdk/execution" - servicesdk "github.com/mesg-foundation/engine/sdk/service" + workflowsdk "github.com/mesg-foundation/engine/sdk/workflow" "github.com/mesg-foundation/engine/workflow" ) @@ -19,17 +19,17 @@ type Workflow struct { execution *executionsdk.Execution executionStream *executionsdk.Listener - service *servicesdk.Service + workflow *workflowsdk.Workflow ErrC chan error } // New creates a new Workflow instance -func New(event *eventsdk.Event, execution *executionsdk.Execution, service *servicesdk.Service) *Workflow { +func New(event *eventsdk.Event, execution *executionsdk.Execution, workflow *workflowsdk.Workflow) *Workflow { return &Workflow{ event: event, execution: execution, - service: service, + workflow: workflow, ErrC: make(chan error), } } @@ -55,17 +55,15 @@ func (w *Workflow) Start() error { } func (w *Workflow) processTrigger(trigger workflow.TriggerType, instanceHash hash.Hash, key string, data map[string]interface{}, eventHash hash.Hash, exec *execution.Execution) { - services, err := w.service.List() + workflows, err := w.workflow.List() if err != nil { w.ErrC <- err return } - for _, service := range services { - for _, wf := range service.Workflows { - if wf.Trigger.Match(trigger, instanceHash, key, data) { - if err := w.triggerExecution(wf, exec, eventHash, data); err != nil { - w.ErrC <- err - } + for _, wf := range workflows { + if wf.Trigger.Match(trigger, instanceHash, key, data) { + if err := w.triggerExecution(wf, exec, eventHash, data); err != nil { + w.ErrC <- err } } } @@ -75,7 +73,7 @@ func (w *Workflow) processExecution(exec *execution.Execution) error { if exec.WorkflowHash.IsZero() { return nil } - wf, err := w.service.FindWorkflow(exec.WorkflowHash) + wf, err := w.workflow.Get(exec.WorkflowHash) if err != nil { return err } diff --git a/sdk/execution/execution.go b/sdk/execution/execution.go index 15048916a..4f55192f1 100644 --- a/sdk/execution/execution.go +++ b/sdk/execution/execution.go @@ -9,6 +9,7 @@ import ( "github.com/mesg-foundation/engine/hash" instancesdk "github.com/mesg-foundation/engine/sdk/instance" servicesdk "github.com/mesg-foundation/engine/sdk/service" + workflowsdk "github.com/mesg-foundation/engine/sdk/workflow" ) const ( @@ -22,15 +23,17 @@ type Execution struct { ps *pubsub.PubSub service *servicesdk.Service instance *instancesdk.Instance + workflow *workflowsdk.Workflow execDB database.ExecutionDB } // New creates a new Execution SDK with given options. -func New(ps *pubsub.PubSub, service *servicesdk.Service, instance *instancesdk.Instance, execDB database.ExecutionDB) *Execution { +func New(ps *pubsub.PubSub, service *servicesdk.Service, instance *instancesdk.Instance, workflow *workflowsdk.Workflow, execDB database.ExecutionDB) *Execution { return &Execution{ ps: ps, service: service, instance: instance, + workflow: workflow, execDB: execDB, } } @@ -137,7 +140,7 @@ func (e *Execution) Execute(workflowHash, instanceHash, eventHash, parentHash ha } if !workflowHash.IsZero() { - _, err := e.service.FindWorkflow(workflowHash) + _, err := e.workflow.Get(workflowHash) if err != nil { return nil, err } diff --git a/sdk/sdk.go b/sdk/sdk.go index 7a689b3bd..e48683f7d 100644 --- a/sdk/sdk.go +++ b/sdk/sdk.go @@ -8,6 +8,7 @@ import ( executionsdk "github.com/mesg-foundation/engine/sdk/execution" instancesdk "github.com/mesg-foundation/engine/sdk/instance" servicesdk "github.com/mesg-foundation/engine/sdk/service" + workflowsdk "github.com/mesg-foundation/engine/sdk/workflow" ) // SDK exposes all functionalities of MESG Engine. @@ -16,19 +17,22 @@ type SDK struct { Instance *instancesdk.Instance Execution *executionsdk.Execution Event *eventsdk.Event + Workflow *workflowsdk.Workflow } // New creates a new SDK with given options. -func New(c container.Container, serviceDB database.ServiceDB, instanceDB database.InstanceDB, execDB database.ExecutionDB, engineName, port string) *SDK { +func New(c container.Container, serviceDB database.ServiceDB, instanceDB database.InstanceDB, execDB database.ExecutionDB, workflowDB database.WorkflowDB, engineName, port string) *SDK { ps := pubsub.New(0) serviceSDK := servicesdk.New(c, serviceDB) instanceSDK := instancesdk.New(c, serviceSDK, instanceDB, engineName, port) - executionSDK := executionsdk.New(ps, serviceSDK, instanceSDK, execDB) + workflowSDK := workflowsdk.New(workflowDB) + executionSDK := executionsdk.New(ps, serviceSDK, instanceSDK, workflowSDK, execDB) eventSDK := eventsdk.New(ps, serviceSDK, instanceSDK) return &SDK{ Service: serviceSDK, Instance: instanceSDK, Execution: executionSDK, Event: eventSDK, + Workflow: workflowSDK, } } diff --git a/sdk/service/service.go b/sdk/service/service.go index 68abbc47f..792d4b6b6 100644 --- a/sdk/service/service.go +++ b/sdk/service/service.go @@ -59,10 +59,6 @@ func (s *Service) Create(srv *service.Service) (*service.Service, error) { return nil, err } - for _, wf := range srv.Workflows { - wf.Hash = hash.Dump(wf) - } - // calculate and apply hash to service. dh := dirhash.New(path) h, err := dh.Sum(hash.Dump(srv)) @@ -109,21 +105,6 @@ func (s *Service) List() ([]*service.Service, error) { return s.serviceDB.All() } -// FindWorkflow will return the workflow or an error -func (s *Service) FindWorkflow(hash hash.Hash) (*service.Workflow, error) { - services, err := s.List() - if err != nil { - return nil, err - } - for _, srv := range services { - for _, wf := range srv.Workflows { - if wf.Hash.Equal(hash) { - return wf, nil - } - } - } - return nil, fmt.Errorf("not exists") -} // AlreadyExistsError is an not found error. type AlreadyExistsError struct { diff --git a/sdk/workflow/workflow.go b/sdk/workflow/workflow.go new file mode 100644 index 000000000..a25e4000a --- /dev/null +++ b/sdk/workflow/workflow.go @@ -0,0 +1,61 @@ +package workflowsdk + +import ( + "fmt" + + "github.com/mesg-foundation/engine/database" + "github.com/mesg-foundation/engine/hash" + "github.com/mesg-foundation/engine/workflow" + validator "gopkg.in/go-playground/validator.v9" +) + +// Workflow exposes workflow APIs of MESG. +type Workflow struct { + workflowDB database.WorkflowDB +} + +// New creates a new Workflow SDK with given options. +func New(workflowDB database.WorkflowDB) *Workflow { + return &Workflow{ + workflowDB: workflowDB, + } +} + +// Create creates a new service from definition. +func (w *Workflow) Create(wf *workflow.Workflow) (*workflow.Workflow, error) { + wf.Hash = hash.Dump(wf) + + // check if workflow already exists. + if _, err := w.workflowDB.Get(wf.Hash); err == nil { + return nil, &AlreadyExistsError{Hash: wf.Hash} + } + + if err := validator.New().Struct(wf); err != nil { + return nil, err + } + return wf, w.workflowDB.Save(wf) +} + +// Delete deletes the workflow by hash. +func (w *Workflow) Delete(hash hash.Hash) error { + return w.workflowDB.Delete(hash) +} + +// Get returns the workflow that matches given hash. +func (w *Workflow) Get(hash hash.Hash) (*workflow.Workflow, error) { + return w.workflowDB.Get(hash) +} + +// List returns all workflows. +func (w *Workflow) List() ([]*workflow.Workflow, error) { + return w.workflowDB.All() +} + +// AlreadyExistsError is an not found error. +type AlreadyExistsError struct { + Hash hash.Hash +} + +func (e *AlreadyExistsError) Error() string { + return fmt.Sprintf("workflow %q already exists", e.Hash.String()) +} From b1a546bda3116c24304e51940a1ab7798117fe9d Mon Sep 17 00:00:00 2001 From: Anthony ESTEBE Date: Sat, 3 Aug 2019 17:57:41 +0700 Subject: [PATCH 5/9] create workflow api --- server/grpc/api/mapping.go | 124 ---------------------- server/grpc/api/service.go | 1 - server/grpc/api/workflow.go | 199 ++++++++++++++++++++++++++++++++++++ 3 files changed, 199 insertions(+), 125 deletions(-) create mode 100644 server/grpc/api/workflow.go diff --git a/server/grpc/api/mapping.go b/server/grpc/api/mapping.go index aa229d300..2eae29319 100644 --- a/server/grpc/api/mapping.go +++ b/server/grpc/api/mapping.go @@ -1,17 +1,12 @@ package api import ( - "github.com/mesg-foundation/engine/hash" "github.com/mesg-foundation/engine/protobuf/types" "github.com/mesg-foundation/engine/service" ) // fromProtoService converts a the protobuf types to the internal service struct func fromProtoService(s *types.Service) (*service.Service, error) { - workflows, err := fromProtoWorkflows(s.Workflows) - if err != nil { - return nil, err - } return &service.Service{ Sid: s.Sid, Name: s.Name, @@ -22,7 +17,6 @@ func fromProtoService(s *types.Service) (*service.Service, error) { Events: fromProtoEvents(s.Events), Configuration: fromProtoConfiguration(s.Configuration), Dependencies: fromProtoDependencies(s.Dependencies), - Workflows: workflows, }, nil } @@ -105,70 +99,6 @@ func fromProtoDependencies(deps []*types.Service_Dependency) []*service.Dependen return ds } -func fromProtoFilters(filters []*types.Service_Workflow_Trigger_Filter) []*service.WorkflowTriggerFilter { - fs := make([]*service.WorkflowTriggerFilter, len(filters)) - for i, filter := range filters { - var predicate service.WorkflowPredicate - // switch filter.Predicate { - if filter.Predicate == types.Service_Workflow_Trigger_Filter_EQ { - predicate = service.EQ - } - fs[i] = &service.WorkflowTriggerFilter{ - Key: filter.Key, - Predicate: predicate, - Value: filter.Value, - } - } - return fs -} - -func fromProtoWorkflowTasks(tasks []*types.Service_Workflow_Task) ([]*service.WorkflowTask, error) { - res := make([]*service.WorkflowTask, len(tasks)) - for i, task := range tasks { - instanceHash, err := hash.Decode(task.InstanceHash) - if err != nil { - return nil, err - } - res[i] = &service.WorkflowTask{ - InstanceHash: instanceHash, - TaskKey: task.TaskKey, - } - } - return res, nil -} - -func fromProtoWorkflows(workflows []*types.Service_Workflow) ([]*service.Workflow, error) { - wfs := make([]*service.Workflow, len(workflows)) - for i, wf := range workflows { - var triggerType service.TriggerType - switch wf.Trigger.Type { - case types.Service_Workflow_Trigger_Result: - triggerType = service.RESULT - case types.Service_Workflow_Trigger_Event: - triggerType = service.EVENT - } - instanceHash, err := hash.Decode(wf.Trigger.InstanceHash) - if err != nil { - return nil, err - } - tasks, err := fromProtoWorkflowTasks(wf.Tasks) - if err != nil { - return nil, err - } - wfs[i] = &service.Workflow{ - Key: wf.Key, - Trigger: &service.WorkflowTrigger{ - Type: triggerType, - InstanceHash: instanceHash, - Key: wf.Trigger.Key, - Filters: fromProtoFilters(wf.Trigger.Filters), - }, - Tasks: tasks, - } - } - return wfs, nil -} - // toProtoService converts an internal service struct to the protobuf types func toProtoService(s *service.Service) *types.Service { return &types.Service{ @@ -182,7 +112,6 @@ func toProtoService(s *service.Service) *types.Service { Events: toProtoEvents(s.Events), Configuration: toProtoConfiguration(s.Configuration), Dependencies: toProtoDependencies(s.Dependencies), - Workflows: toProtoWorkflows(s.Workflows), } } @@ -260,56 +189,3 @@ func toProtoDependencies(deps []*service.Dependency) []*types.Service_Dependency } return ds } - -func toProtoFilters(filters []*service.WorkflowTriggerFilter) []*types.Service_Workflow_Trigger_Filter { - fs := make([]*types.Service_Workflow_Trigger_Filter, len(filters)) - for i, filter := range filters { - var predicate types.Service_Workflow_Trigger_Filter_Predicate - // switch filter.Predicate { - if filter.Predicate == service.EQ { - predicate = types.Service_Workflow_Trigger_Filter_EQ - } - fs[i] = &types.Service_Workflow_Trigger_Filter{ - Key: filter.Key, - Predicate: predicate, - Value: filter.Value.(string), - } - } - return fs -} - -func toProtoWorkflowTasks(tasks []*service.WorkflowTask) []*types.Service_Workflow_Task { - res := make([]*types.Service_Workflow_Task, len(tasks)) - for i, task := range tasks { - res[i] = &types.Service_Workflow_Task{ - InstanceHash: task.InstanceHash.String(), - TaskKey: task.TaskKey, - } - } - return res -} - -func toProtoWorkflows(workflows []*service.Workflow) []*types.Service_Workflow { - wfs := make([]*types.Service_Workflow, len(workflows)) - for i, wf := range workflows { - var triggerType types.Service_Workflow_Trigger_Type - switch wf.Trigger.Type { - case service.EVENT: - triggerType = types.Service_Workflow_Trigger_Event - case service.RESULT: - triggerType = types.Service_Workflow_Trigger_Result - } - wfs[i] = &types.Service_Workflow{ - Hash: wf.Hash.String(), - Key: wf.Key, - Trigger: &types.Service_Workflow_Trigger{ - Type: triggerType, - InstanceHash: wf.Trigger.InstanceHash.String(), - Key: wf.Trigger.Key, - Filters: toProtoFilters(wf.Trigger.Filters), - }, - Tasks: toProtoWorkflowTasks(wf.Tasks), - } - } - return wfs -} diff --git a/server/grpc/api/service.go b/server/grpc/api/service.go index 5ca0c9a6b..afc06089a 100644 --- a/server/grpc/api/service.go +++ b/server/grpc/api/service.go @@ -33,7 +33,6 @@ func (s *ServiceServer) Create(ctx context.Context, req *protobuf_api.CreateServ Dependencies: req.Dependencies, Repository: req.Repository, Source: req.Source, - Workflows: req.Workflows, }) if err != nil { return nil, err diff --git a/server/grpc/api/workflow.go b/server/grpc/api/workflow.go new file mode 100644 index 000000000..980051b4e --- /dev/null +++ b/server/grpc/api/workflow.go @@ -0,0 +1,199 @@ +package api + +import ( + "context" + + "github.com/mesg-foundation/engine/hash" + "github.com/mesg-foundation/engine/protobuf/api" + "github.com/mesg-foundation/engine/protobuf/types" + "github.com/mesg-foundation/engine/sdk" + "github.com/mesg-foundation/engine/workflow" +) + +// WorkflowServer is the type to aggregate all Service APIs. +type WorkflowServer struct { + sdk *sdk.SDK +} + +// NewWorkflowServer creates a new WorkflowServer. +func NewWorkflowServer(sdk *sdk.SDK) *WorkflowServer { + return &WorkflowServer{sdk: sdk} +} + +// Create creates a new service from definition. +func (s *WorkflowServer) Create(ctx context.Context, req *api.CreateWorkflowRequest) (*api.CreateWorkflowResponse, error) { + wf, err := fromProtoWorkflow(&types.Workflow{ + Key: req.Key, + Trigger: req.Trigger, + Tasks: req.Tasks, + }) + srv, err := s.sdk.Workflow.Create(wf) + if err != nil { + return nil, err + } + return &api.CreateWorkflowResponse{Hash: srv.Hash.String()}, nil +} + +// Delete deletes service by hash or sid. +func (s *WorkflowServer) Delete(ctx context.Context, request *api.DeleteWorkflowRequest) (*api.DeleteWorkflowResponse, error) { + hash, err := hash.Decode(request.Hash) + if err != nil { + return nil, err + } + return &api.DeleteWorkflowResponse{}, s.sdk.Workflow.Delete(hash) +} + +// Get returns service from given hash. +func (s *WorkflowServer) Get(ctx context.Context, req *api.GetWorkflowRequest) (*types.Workflow, error) { + hash, err := hash.Decode(req.Hash) + if err != nil { + return nil, err + } + + wf, err := s.sdk.Workflow.Get(hash) + if err != nil { + return nil, err + } + return toProtoWorkflow(wf), nil +} + +// List returns all workflows. +func (s *WorkflowServer) List(ctx context.Context, req *api.ListWorkflowRequest) (*api.ListWorkflowResponse, error) { + workflows, err := s.sdk.Workflow.List() + if err != nil { + return nil, err + } + wfs := toProtoWorkflows(workflows) + return &api.ListWorkflowResponse{ + Workflows: wfs, + }, nil +} + +func fromProtoFilters(filters []*types.Workflow_Trigger_Filter) []*workflow.TriggerFilter { + fs := make([]*workflow.TriggerFilter, len(filters)) + for i, filter := range filters { + var predicate workflow.Predicate + // switch filter.Predicate { + if filter.Predicate == types.Workflow_Trigger_Filter_EQ { + predicate = workflow.EQ + } + fs[i] = &workflow.TriggerFilter{ + Key: filter.Key, + Predicate: predicate, + Value: filter.Value, + } + } + return fs +} + +func fromProtoWorkflowTasks(tasks []*types.Workflow_Task) ([]*workflow.Task, error) { + res := make([]*workflow.Task, len(tasks)) + for i, task := range tasks { + instanceHash, err := hash.Decode(task.InstanceHash) + if err != nil { + return nil, err + } + res[i] = &workflow.Task{ + InstanceHash: instanceHash, + TaskKey: task.TaskKey, + } + } + return res, nil +} + +func fromProtoWorkflow(wf *types.Workflow) (*workflow.Workflow, error) { + var triggerType workflow.TriggerType + switch wf.Trigger.Type { + case types.Workflow_Trigger_Result: + triggerType = workflow.RESULT + case types.Workflow_Trigger_Event: + triggerType = workflow.EVENT + } + instanceHash, err := hash.Decode(wf.Trigger.InstanceHash) + if err != nil { + return nil, err + } + tasks, err := fromProtoWorkflowTasks(wf.Tasks) + if err != nil { + return nil, err + } + return &workflow.Workflow{ + Key: wf.Key, + Trigger: &workflow.Trigger{ + Type: triggerType, + InstanceHash: instanceHash, + Key: wf.Trigger.Key, + Filters: fromProtoFilters(wf.Trigger.Filters), + }, + Tasks: tasks, + }, nil +} + +func fromProtoWorkflows(workflows []*types.Workflow) ([]*workflow.Workflow, error) { + wfs := make([]*workflow.Workflow, len(workflows)) + for i, wf := range workflows { + w, err := fromProtoWorkflow(wf) + if err != nil { + return nil, err + } + wfs[i] = w + } + return wfs, nil +} + +func toProtoFilters(filters []*workflow.TriggerFilter) []*types.Workflow_Trigger_Filter { + fs := make([]*types.Workflow_Trigger_Filter, len(filters)) + for i, filter := range filters { + var predicate types.Workflow_Trigger_Filter_Predicate + // switch filter.Predicate { + if filter.Predicate == workflow.EQ { + predicate = types.Workflow_Trigger_Filter_EQ + } + fs[i] = &types.Workflow_Trigger_Filter{ + Key: filter.Key, + Predicate: predicate, + Value: filter.Value.(string), + } + } + return fs +} + +func toProtoWorkflowTasks(tasks []*workflow.Task) []*types.Workflow_Task { + res := make([]*types.Workflow_Task, len(tasks)) + for i, task := range tasks { + res[i] = &types.Workflow_Task{ + InstanceHash: task.InstanceHash.String(), + TaskKey: task.TaskKey, + } + } + return res +} + +func toProtoWorkflow(wf *workflow.Workflow) *types.Workflow { + var triggerType types.Workflow_Trigger_Type + switch wf.Trigger.Type { + case workflow.EVENT: + triggerType = types.Workflow_Trigger_Event + case workflow.RESULT: + triggerType = types.Workflow_Trigger_Result + } + return &types.Workflow{ + Hash: wf.Hash.String(), + Key: wf.Key, + Trigger: &types.Workflow_Trigger{ + Type: triggerType, + InstanceHash: wf.Trigger.InstanceHash.String(), + Key: wf.Trigger.Key, + Filters: toProtoFilters(wf.Trigger.Filters), + }, + Tasks: toProtoWorkflowTasks(wf.Tasks), + } +} + +func toProtoWorkflows(workflows []*workflow.Workflow) []*types.Workflow { + wfs := make([]*types.Workflow, len(workflows)) + for i, wf := range workflows { + wfs[i] = toProtoWorkflow(wf) + } + return wfs +} From b0737c7fb61204ccd6a4cb4bf35998e6a9911546 Mon Sep 17 00:00:00 2001 From: Anthony ESTEBE Date: Sat, 3 Aug 2019 18:56:32 +0700 Subject: [PATCH 6/9] expose workflow api --- server/grpc/server.go | 1 + 1 file changed, 1 insertion(+) diff --git a/server/grpc/server.go b/server/grpc/server.go index c7358d3ed..d62feca34 100644 --- a/server/grpc/server.go +++ b/server/grpc/server.go @@ -67,6 +67,7 @@ func (s *Server) register() { protobuf_api.RegisterExecutionServer(s.instance, api.NewExecutionServer(s.sdk)) protobuf_api.RegisterInstanceServer(s.instance, api.NewInstanceServer(s.sdk)) protobuf_api.RegisterServiceServer(s.instance, api.NewServiceServer(s.sdk)) + protobuf_api.RegisterWorkflowServer(s.instance, api.NewWorkflowServer(s.sdk)) reflection.Register(s.instance) } From 5fab386fa54d2481eb70f884c318b32c731372e5 Mon Sep 17 00:00:00 2001 From: Anthony ESTEBE Date: Sat, 3 Aug 2019 19:33:34 +0700 Subject: [PATCH 7/9] add instance validation --- sdk/sdk.go | 2 +- sdk/workflow/workflow.go | 14 +++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/sdk/sdk.go b/sdk/sdk.go index e48683f7d..050b2f6e1 100644 --- a/sdk/sdk.go +++ b/sdk/sdk.go @@ -25,7 +25,7 @@ func New(c container.Container, serviceDB database.ServiceDB, instanceDB databas ps := pubsub.New(0) serviceSDK := servicesdk.New(c, serviceDB) instanceSDK := instancesdk.New(c, serviceSDK, instanceDB, engineName, port) - workflowSDK := workflowsdk.New(workflowDB) + workflowSDK := workflowsdk.New(instanceSDK, workflowDB) executionSDK := executionsdk.New(ps, serviceSDK, instanceSDK, workflowSDK, execDB) eventSDK := eventsdk.New(ps, serviceSDK, instanceSDK) return &SDK{ diff --git a/sdk/workflow/workflow.go b/sdk/workflow/workflow.go index a25e4000a..43bae5ed6 100644 --- a/sdk/workflow/workflow.go +++ b/sdk/workflow/workflow.go @@ -5,6 +5,7 @@ import ( "github.com/mesg-foundation/engine/database" "github.com/mesg-foundation/engine/hash" + instancesdk "github.com/mesg-foundation/engine/sdk/instance" "github.com/mesg-foundation/engine/workflow" validator "gopkg.in/go-playground/validator.v9" ) @@ -12,12 +13,14 @@ import ( // Workflow exposes workflow APIs of MESG. type Workflow struct { workflowDB database.WorkflowDB + instance *instancesdk.Instance } // New creates a new Workflow SDK with given options. -func New(workflowDB database.WorkflowDB) *Workflow { +func New(instance *instancesdk.Instance, workflowDB database.WorkflowDB) *Workflow { return &Workflow{ workflowDB: workflowDB, + instance: instance, } } @@ -25,6 +28,15 @@ func New(workflowDB database.WorkflowDB) *Workflow { func (w *Workflow) Create(wf *workflow.Workflow) (*workflow.Workflow, error) { wf.Hash = hash.Dump(wf) + if _, err := w.instance.Get(wf.Trigger.InstanceHash); err != nil { + return nil, err + } + for _, task := range wf.Tasks { + if _, err := w.instance.Get(task.InstanceHash); err != nil { + return nil, err + } + } + // check if workflow already exists. if _, err := w.workflowDB.Get(wf.Hash); err == nil { return nil, &AlreadyExistsError{Hash: wf.Hash} From 41c9aa1c11a556d7c77aeb00a7bb94b7c458db2b Mon Sep 17 00:00:00 2001 From: Anthony ESTEBE Date: Sat, 3 Aug 2019 20:41:11 +0700 Subject: [PATCH 8/9] tests and code cleanup --- sdk/execution/execution_test.go | 18 ++++++++++++++---- sdk/service/service.go | 1 - server/grpc/api/execution_test.go | 4 ++-- server/grpc/api/mapping.go | 4 ++-- server/grpc/api/service.go | 5 +---- server/grpc/api/workflow.go | 15 +++------------ server/grpc/core/test_test.go | 6 +++++- 7 files changed, 27 insertions(+), 26 deletions(-) diff --git a/sdk/execution/execution_test.go b/sdk/execution/execution_test.go index ebe3e2d36..b1756681c 100644 --- a/sdk/execution/execution_test.go +++ b/sdk/execution/execution_test.go @@ -12,14 +12,16 @@ import ( "github.com/mesg-foundation/engine/instance" instancesdk "github.com/mesg-foundation/engine/sdk/instance" servicesdk "github.com/mesg-foundation/engine/sdk/service" + workflowsdk "github.com/mesg-foundation/engine/sdk/workflow" "github.com/mesg-foundation/engine/service" "github.com/stretchr/testify/require" ) const ( - servicedbname = "service.db.test" - instdbname = "instance.db.test" - execdbname = "exec.db.test" + servicedbname = "service.db.test" + instdbname = "instance.db.test" + execdbname = "exec.db.test" + workflowdbname = "workflow.db.test" ) type apiTesting struct { @@ -27,15 +29,18 @@ type apiTesting struct { serviceDB *database.LevelDBServiceDB executionDB *database.LevelDBExecutionDB instanceDB *database.LevelDBInstanceDB + workflowDB *database.LevelDBWorkflowDB } func (t *apiTesting) close() { require.NoError(t, t.serviceDB.Close()) require.NoError(t, t.executionDB.Close()) require.NoError(t, t.instanceDB.Close()) + require.NoError(t, t.workflowDB.Close()) require.NoError(t, os.RemoveAll(servicedbname)) require.NoError(t, os.RemoveAll(execdbname)) require.NoError(t, os.RemoveAll(instdbname)) + require.NoError(t, os.RemoveAll(workflowdbname)) } func newTesting(t *testing.T) (*Execution, *apiTesting) { @@ -51,13 +56,18 @@ func newTesting(t *testing.T) (*Execution, *apiTesting) { execDB, err := database.NewExecutionDB(execdbname) require.NoError(t, err) - sdk := New(pubsub.New(0), service, instance, execDB) + workflowDB, err := database.NewWorkflowDB(workflowdbname) + require.NoError(t, err) + workflow := workflowsdk.New(instance, workflowDB) + + sdk := New(pubsub.New(0), service, instance, workflow, execDB) return sdk, &apiTesting{ T: t, serviceDB: db, executionDB: execDB, instanceDB: instDB, + workflowDB: workflowDB, } } diff --git a/sdk/service/service.go b/sdk/service/service.go index 792d4b6b6..0086e6d9d 100644 --- a/sdk/service/service.go +++ b/sdk/service/service.go @@ -105,7 +105,6 @@ func (s *Service) List() ([]*service.Service, error) { return s.serviceDB.All() } - // AlreadyExistsError is an not found error. type AlreadyExistsError struct { Hash hash.Hash diff --git a/server/grpc/api/execution_test.go b/server/grpc/api/execution_test.go index b560bdb17..73f0996cf 100644 --- a/server/grpc/api/execution_test.go +++ b/server/grpc/api/execution_test.go @@ -26,7 +26,7 @@ func TestGet(t *testing.T) { want, err := toProtoExecution(exec) require.NoError(t, err) - sdk := sdk.New(nil, nil, nil, db, "", "") + sdk := sdk.New(nil, nil, nil, db, nil, "", "") s := NewExecutionServer(sdk) got, err := s.Get(context.Background(), &api.GetExecutionRequest{Hash: exec.Hash.String()}) @@ -43,7 +43,7 @@ func TestUpdate(t *testing.T) { exec := execution.New(nil, nil, nil, nil, "", nil, nil) require.NoError(t, db.Save(exec)) - sdk := sdk.New(nil, nil, nil, db, "", "") + sdk := sdk.New(nil, nil, nil, db, nil, "", "") s := NewExecutionServer(sdk) _, err = s.Update(context.Background(), &api.UpdateExecutionRequest{Hash: exec.Hash.String()}) diff --git a/server/grpc/api/mapping.go b/server/grpc/api/mapping.go index 2eae29319..9c814edad 100644 --- a/server/grpc/api/mapping.go +++ b/server/grpc/api/mapping.go @@ -6,7 +6,7 @@ import ( ) // fromProtoService converts a the protobuf types to the internal service struct -func fromProtoService(s *types.Service) (*service.Service, error) { +func fromProtoService(s *types.Service) *service.Service { return &service.Service{ Sid: s.Sid, Name: s.Name, @@ -17,7 +17,7 @@ func fromProtoService(s *types.Service) (*service.Service, error) { Events: fromProtoEvents(s.Events), Configuration: fromProtoConfiguration(s.Configuration), Dependencies: fromProtoDependencies(s.Dependencies), - }, nil + } } func fromProtoTasks(tasks []*types.Service_Task) []*service.Task { diff --git a/server/grpc/api/service.go b/server/grpc/api/service.go index afc06089a..bd2dd97ff 100644 --- a/server/grpc/api/service.go +++ b/server/grpc/api/service.go @@ -23,7 +23,7 @@ func NewServiceServer(sdk *sdk.SDK) *ServiceServer { // Create creates a new service from definition. func (s *ServiceServer) Create(ctx context.Context, req *protobuf_api.CreateServiceRequest) (*protobuf_api.CreateServiceResponse, error) { - definition, err := fromProtoService(&types.Service{ + definition := fromProtoService(&types.Service{ Sid: req.Sid, Name: req.Name, Description: req.Description, @@ -34,9 +34,6 @@ func (s *ServiceServer) Create(ctx context.Context, req *protobuf_api.CreateServ Repository: req.Repository, Source: req.Source, }) - if err != nil { - return nil, err - } srv, err := s.sdk.Service.Create(definition) if err != nil { return nil, err diff --git a/server/grpc/api/workflow.go b/server/grpc/api/workflow.go index 980051b4e..26b4f786e 100644 --- a/server/grpc/api/workflow.go +++ b/server/grpc/api/workflow.go @@ -27,6 +27,9 @@ func (s *WorkflowServer) Create(ctx context.Context, req *api.CreateWorkflowRequ Trigger: req.Trigger, Tasks: req.Tasks, }) + if err != nil { + return nil, err + } srv, err := s.sdk.Workflow.Create(wf) if err != nil { return nil, err @@ -129,18 +132,6 @@ func fromProtoWorkflow(wf *types.Workflow) (*workflow.Workflow, error) { }, nil } -func fromProtoWorkflows(workflows []*types.Workflow) ([]*workflow.Workflow, error) { - wfs := make([]*workflow.Workflow, len(workflows)) - for i, wf := range workflows { - w, err := fromProtoWorkflow(wf) - if err != nil { - return nil, err - } - wfs[i] = w - } - return wfs, nil -} - func toProtoFilters(filters []*workflow.TriggerFilter) []*types.Workflow_Trigger_Filter { fs := make([]*types.Workflow_Trigger_Filter, len(filters)) for i, filter := range filters { diff --git a/server/grpc/core/test_test.go b/server/grpc/core/test_test.go index 2a637001e..65155ac42 100644 --- a/server/grpc/core/test_test.go +++ b/server/grpc/core/test_test.go @@ -14,6 +14,7 @@ const ( servicedbname = "service.db.test" instancedbname = "instance.db.test" execdbname = "exec.db.test" + workflowdbname = "workflow.db.test" ) func newServerWithContainer(t *testing.T, c container.Container) (*Server, func()) { @@ -26,7 +27,10 @@ func newServerWithContainer(t *testing.T, c container.Container) (*Server, func( execDB, err := database.NewExecutionDB(execdbname) require.NoError(t, err) - a := sdk.New(c, db, instanceDB, execDB, "", "") + workflowDB, err := database.NewWorkflowDB(workflowdbname) + require.NoError(t, err) + + a := sdk.New(c, db, instanceDB, execDB, workflowDB, "", "") server := NewServer(a) From 665ef5c5f0fa0b6feb4878ebab997a2a03f4fb84 Mon Sep 17 00:00:00 2001 From: Anthony Date: Thu, 8 Aug 2019 16:31:46 +0700 Subject: [PATCH 9/9] Update workflow/type.go MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Nicolas Mahé --- workflow/type.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/workflow/type.go b/workflow/type.go index a9033d62a..816358a91 100644 --- a/workflow/type.go +++ b/workflow/type.go @@ -36,7 +36,7 @@ type Task struct { // Trigger is an event that triggers a workflow type Trigger struct { InstanceHash hash.Hash `hash:"name:1" validate:"required"` - Key string `hash:"name:2" validate:"printascii,printascii"` + Key string `hash:"name:2" validate:"printascii"` Type TriggerType `hash:"name:3" validate:"required"` Filters []*TriggerFilter `hash:"name:4" validate:"dive,required"` }