diff --git a/event/event.go b/event/event.go index ca49ee790..7b2fc5fd5 100644 --- a/event/event.go +++ b/event/event.go @@ -1,19 +1,12 @@ package event import ( + "github.com/gogo/protobuf/types" "github.com/mesg-foundation/engine/hash" ) -// Event stores all informations about Events. -type Event struct { - Hash hash.Hash `hash:"-"` - InstanceHash hash.Hash `hash:"name:instanceHash"` - Key string `hash:"name:key"` - Data map[string]interface{} `hash:"name:data"` -} - // Create creates an event eventKey with eventData for service s. -func Create(instanceHash hash.Hash, eventKey string, eventData map[string]interface{}) *Event { +func Create(instanceHash hash.Hash, eventKey string, eventData *types.Struct) *Event { e := &Event{ InstanceHash: instanceHash, Key: eventKey, diff --git a/protobuf/types/event.pb.go b/event/event.pb.go similarity index 57% rename from protobuf/types/event.pb.go rename to event/event.pb.go index d85c20620..5a434816f 100644 --- a/protobuf/types/event.pb.go +++ b/event/event.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: protobuf/types/event.proto +// source: event.proto -package types +package event import ( fmt "fmt" @@ -42,7 +42,7 @@ func (m *Event) Reset() { *m = Event{} } func (m *Event) String() string { return proto.CompactTextString(m) } func (*Event) ProtoMessage() {} func (*Event) Descriptor() ([]byte, []int) { - return fileDescriptor_118d36ccf50c3798, []int{0} + return fileDescriptor_2d17a9d3f0ddf27e, []int{0} } func (m *Event) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_Event.Unmarshal(m, b) @@ -66,26 +66,26 @@ func init() { proto.RegisterType((*Event)(nil), "types.Event") } -func init() { proto.RegisterFile("protobuf/types/event.proto", fileDescriptor_118d36ccf50c3798) } +func init() { proto.RegisterFile("event.proto", fileDescriptor_2d17a9d3f0ddf27e) } -var fileDescriptor_118d36ccf50c3798 = []byte{ - // 282 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0x2a, 0x28, 0xca, 0x2f, - 0xc9, 0x4f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 0x2b, 0x25, 0x98, 0x15, 0x18, 0x35, 0x38, 0x9d, - 0x04, 0xd1, 0x54, 0x1b, 0x2b, 0x05, 0x81, 0x64, 0x85, 0xec, 0xb8, 0x58, 0x52, 0x12, 0x4b, 0x12, - 0x25, 0x58, 0x14, 0x18, 0x35, 0xb8, 0x8d, 0xc4, 0xf5, 0x20, 0xc1, 0xa7, 0x07, 0x0b, 0x22, 0xbd, - 0x60, 0x70, 0xf0, 0x61, 0x68, 0x37, 0x51, 0x0a, 0x02, 0xeb, 0x73, 0x32, 0x3b, 0xf1, 0x50, 0x8e, - 0x21, 0xca, 0x80, 0xb0, 0xb3, 0x51, 0xa3, 0x2e, 0x89, 0x0d, 0xcc, 0x37, 0x06, 0x04, 0x00, 0x00, - 0xff, 0xff, 0x34, 0x47, 0xeb, 0x4f, 0xd3, 0x01, 0x00, 0x00, +var fileDescriptor_2d17a9d3f0ddf27e = []byte{ + // 277 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xe2, 0x4e, 0x2d, 0x4b, 0xcd, + 0x2b, 0xd1, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x62, 0x2d, 0xa9, 0x2c, 0x48, 0x2d, 0x96, 0x92, + 0x49, 0xcf, 0xcf, 0x4f, 0xcf, 0x49, 0xd5, 0x07, 0x0b, 0x26, 0x95, 0xa6, 0xe9, 0x17, 0x97, 0x14, + 0x95, 0x26, 0x43, 0x15, 0x49, 0x29, 0xa5, 0xe7, 0xa7, 0xe7, 0x23, 0xe4, 0x40, 0x3c, 0x30, 0x07, + 0xcc, 0x82, 0xa8, 0x51, 0x5a, 0xcd, 0xc4, 0xc5, 0xea, 0x0a, 0x32, 0x58, 0x28, 0x98, 0x8b, 0x25, + 0x23, 0xb1, 0x38, 0x43, 0x82, 0x51, 0x81, 0x51, 0x83, 0xc7, 0xc9, 0xfe, 0xc4, 0x3d, 0x79, 0x86, + 0x5b, 0xf7, 0xe4, 0xb5, 0xd3, 0x33, 0x4b, 0x32, 0x4a, 0x93, 0xf4, 0x92, 0xf3, 0x73, 0xf5, 0x73, + 0x53, 0x8b, 0xd3, 0x75, 0xd3, 0xf2, 0x4b, 0xf3, 0x52, 0x12, 0x4b, 0x32, 0xf3, 0xf3, 0xf4, 0x53, + 0xf3, 0xd2, 0x33, 0xf3, 0x52, 0xf5, 0x41, 0xba, 0xf4, 0x3c, 0x12, 0x8b, 0x33, 0x3e, 0xdd, 0x93, + 0xe7, 0x00, 0x71, 0xac, 0x94, 0x74, 0x95, 0x82, 0xc0, 0x86, 0x09, 0x65, 0x70, 0xf1, 0x64, 0xe6, + 0x15, 0x97, 0x24, 0xe6, 0x25, 0xa7, 0x82, 0x54, 0x48, 0x30, 0x81, 0x0d, 0x77, 0x21, 0xcf, 0x70, + 0x5e, 0x88, 0xe1, 0x79, 0x89, 0xb9, 0xa9, 0x56, 0x46, 0x4a, 0x41, 0x28, 0x26, 0x0b, 0x29, 0x73, + 0x31, 0x67, 0xa7, 0x56, 0x4a, 0x30, 0x2b, 0x30, 0x6a, 0x70, 0x3a, 0x09, 0xa2, 0xa9, 0x36, 0x56, + 0x0a, 0x02, 0xc9, 0x0a, 0xd9, 0x71, 0xb1, 0xa4, 0x24, 0x96, 0x24, 0x4a, 0xb0, 0x28, 0x30, 0x6a, + 0x70, 0x1b, 0x89, 0xeb, 0x41, 0x82, 0x4f, 0x0f, 0x16, 0x44, 0x7a, 0xc1, 0xe0, 0xe0, 0xc3, 0xd0, + 0x6e, 0xa2, 0x14, 0x04, 0xd6, 0xe7, 0xa4, 0x7b, 0xe2, 0xa1, 0x1c, 0x43, 0x94, 0x3a, 0x61, 0x67, + 0x83, 0xe3, 0x2a, 0x89, 0x0d, 0x6c, 0xb0, 0x31, 0x20, 0x00, 0x00, 0xff, 0xff, 0x05, 0x41, 0x11, + 0xd8, 0xbb, 0x01, 0x00, 0x00, } diff --git a/execution/execution.go b/execution/execution.go index cb9a5f9f6..8ce3df2e8 100644 --- a/execution/execution.go +++ b/execution/execution.go @@ -1,55 +1,12 @@ package execution import ( + "github.com/gogo/protobuf/types" "github.com/mesg-foundation/engine/hash" ) -// Status stores the state of an execution -type Status int - -// Status for an execution -// Created => The execution is created but not yet processed -// InProgress => The execution is being processed -// Completed => The execution is completed -const ( - Created Status = iota + 1 - InProgress - Completed - Failed -) - -func (s Status) String() (r string) { - switch s { - case Created: - r = "created" - case InProgress: - r = "in progress" - case Completed: - r = "completed" - case Failed: - r = "failed" - } - return r -} - -// Execution stores all information about executions. -type Execution struct { - Hash hash.Hash `hash:"-"` - ProcessHash hash.Hash `hash:"name:processHash"` - ParentHash hash.Hash `hash:"name:parentHash"` - EventHash hash.Hash `hash:"name:eventHash"` - Status Status `hash:"-"` - InstanceHash hash.Hash `hash:"name:instanceHash"` - TaskKey string `hash:"name:taskKey"` - StepID string `hash:"name:stepID"` - Tags []string `hash:"name:tags"` - Inputs map[string]interface{} `hash:"name:inputs"` - Outputs map[string]interface{} `hash:"-"` - Error string `hash:"-"` -} - // New returns a new execution. It returns an error if inputs are invalid. -func New(processHash, instanceHash, parentHash, eventHash hash.Hash, stepID string, taskKey string, inputs map[string]interface{}, tags []string) *Execution { +func New(processHash, instanceHash, parentHash, eventHash hash.Hash, stepID string, taskKey string, inputs *types.Struct, tags []string) *Execution { exec := &Execution{ ProcessHash: processHash, EventHash: eventHash, @@ -59,7 +16,7 @@ func New(processHash, instanceHash, parentHash, eventHash hash.Hash, stepID stri TaskKey: taskKey, StepID: stepID, Tags: tags, - Status: Created, + Status: Status_Created, } exec.Hash = hash.Dump(exec) return exec @@ -68,42 +25,42 @@ func New(processHash, instanceHash, parentHash, eventHash hash.Hash, stepID stri // Execute changes executions status to in progres and update its execute time. // It returns an error if the status is different then Created. func (execution *Execution) Execute() error { - if execution.Status != Created { + if execution.Status != Status_Created { return StatusError{ - ExpectedStatus: Created, + ExpectedStatus: Status_Created, ActualStatus: execution.Status, } } - execution.Status = InProgress + execution.Status = Status_InProgress return nil } // Complete changes execution status to completed. It verifies the output. // It returns an error if the status is different then InProgress or verification fails. -func (execution *Execution) Complete(outputs map[string]interface{}) error { - if execution.Status != InProgress { +func (execution *Execution) Complete(outputs *types.Struct) error { + if execution.Status != Status_InProgress { return StatusError{ - ExpectedStatus: InProgress, + ExpectedStatus: Status_InProgress, ActualStatus: execution.Status, } } execution.Outputs = outputs - execution.Status = Completed + execution.Status = Status_Completed return nil } // Failed changes execution status to failed and puts error information to execution. // It returns an error if the status is different then InProgress. func (execution *Execution) Failed(err error) error { - if execution.Status != InProgress { + if execution.Status != Status_InProgress { return StatusError{ - ExpectedStatus: InProgress, + ExpectedStatus: Status_InProgress, ActualStatus: execution.Status, } } execution.Error = err.Error() - execution.Status = Failed + execution.Status = Status_Failed return nil } diff --git a/protobuf/types/execution.pb.go b/execution/execution.pb.go similarity index 60% rename from protobuf/types/execution.pb.go rename to execution/execution.pb.go index 9b1d3217b..d793c829d 100644 --- a/protobuf/types/execution.pb.go +++ b/execution/execution.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: protobuf/types/execution.proto +// source: execution.proto -package types +package execution import ( fmt "fmt" @@ -62,7 +62,7 @@ func (x Status) String() string { } func (Status) EnumDescriptor() ([]byte, []int) { - return fileDescriptor_42e00237fcad5e7f, []int{0} + return fileDescriptor_776e2c5022e94aef, []int{0} } // Execution represents a single execution run in engine. @@ -90,7 +90,7 @@ type Execution struct { // tags are optionally associated with execution by the user. Tags []string `protobuf:"bytes,10,rep,name=tags,proto3" json:"tags,omitempty" hash:"name:10"` // processHash is the unique hash of the process associated to this execution. - ProcessHash github_com_mesg_foundation_engine_hash.Hash `protobuf:"bytes,11,opt,name=processHash,proto3,customtype=github.com/mesg-foundation/engine/hash.Hash" json:"processHash" hash:"-"` + ProcessHash github_com_mesg_foundation_engine_hash.Hash `protobuf:"bytes,11,opt,name=processHash,proto3,customtype=github.com/mesg-foundation/engine/hash.Hash" json:"processHash" hash:"name:11"` // step of the workflow. StepID string `protobuf:"bytes,12,opt,name=stepID,proto3" json:"stepID,omitempty" hash:"name:12"` XXX_NoUnkeyedLiteral struct{} `json:"-"` @@ -102,7 +102,7 @@ func (m *Execution) Reset() { *m = Execution{} } func (m *Execution) String() string { return proto.CompactTextString(m) } func (*Execution) ProtoMessage() {} func (*Execution) Descriptor() ([]byte, []int) { - return fileDescriptor_42e00237fcad5e7f, []int{0} + return fileDescriptor_776e2c5022e94aef, []int{0} } func (m *Execution) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_Execution.Unmarshal(m, b) @@ -127,40 +127,40 @@ func init() { proto.RegisterType((*Execution)(nil), "types.Execution") } -func init() { proto.RegisterFile("protobuf/types/execution.proto", fileDescriptor_42e00237fcad5e7f) } - -var fileDescriptor_42e00237fcad5e7f = []byte{ - // 502 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x94, 0xdf, 0x6a, 0xdb, 0x30, - 0x14, 0xc6, 0xe3, 0x26, 0x71, 0xea, 0x93, 0x3f, 0x64, 0xba, 0x99, 0x29, 0xa3, 0x09, 0xba, 0x18, - 0xa1, 0xa5, 0x76, 0x97, 0xb0, 0x0e, 0x7a, 0x53, 0x70, 0xbb, 0xb1, 0x32, 0x06, 0xc3, 0x61, 0x37, - 0xbb, 0x53, 0x92, 0x53, 0xdb, 0x34, 0x91, 0x8c, 0x24, 0x6f, 0xeb, 0x1b, 0xf6, 0x09, 0x76, 0xb1, - 0x8b, 0xc0, 0x5e, 0xa1, 0x4f, 0x30, 0x2c, 0xd7, 0x6b, 0xbc, 0xc2, 0x06, 0x25, 0x77, 0x3e, 0xfa, - 0xbe, 0xf3, 0xd3, 0x27, 0xe9, 0x60, 0xd8, 0x4f, 0xa5, 0xd0, 0x62, 0x96, 0x5d, 0xf9, 0xfa, 0x26, - 0x45, 0xe5, 0xe3,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- 0x77, 0x2c, 0x59, 0xe2, 0xa2, 0xdf, 0x08, 0x4e, 0x6e, 0x7f, 0xed, 0xd7, 0xbe, 0x1c, 0xff, 0xff, - 0x18, 0xd5, 0x1f, 0xc7, 0xcc, 0x36, 0xf5, 0xe4, 0x77, 0x00, 0x00, 0x00, 0xff, 0xff, 0x85, 0x8b, - 0x7f, 0xdd, 0x51, 0x04, 0x00, 0x00, +func init() { proto.RegisterFile("execution.proto", fileDescriptor_776e2c5022e94aef) } + +var fileDescriptor_776e2c5022e94aef = []byte{ + // 504 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x94, 0xcf, 0x6a, 0xdb, 0x40, + 0x10, 0xc6, 0xad, 0xd8, 0x96, 0xa3, 0xf1, 0x9f, 0xba, 0x7b, 0xa9, 0x08, 0xa5, 0x36, 0x7b, 0x28, + 0x26, 0x21, 0x72, 0x6d, 0xd3, 0x16, 0x72, 0x09, 0x28, 0x49, 0x69, 0x28, 0x85, 0x22, 0xd3, 0x4b, + 0x6f, 0x6b, 0x7b, 0xb2, 0x16, 0xb1, 0x77, 0xc5, 0xee, 0xaa, 0x6d, 0xde, 0x30, 0xcf, 0x50, 0x8a, + 0xa1, 0xaf, 0x90, 0x27, 0x28, 0x5a, 0x45, 0x8d, 0xd5, 0x40, 0x29, 0x21, 0x37, 0xcd, 0xce, 0x37, + 0xbf, 0xfd, 0x76, 0x66, 0x10, 0x3c, 0xc1, 0xef, 0x38, 0x4f, 0x4d, 0x2c, 0x45, 0x90, 0x28, 0x69, + 0x24, 0xa9, 0x9b, 0xab, 0x04, 0xf5, 0xde, 0x73, 0x2e, 0x25, 0x5f, 0xe1, 0xd0, 0x1e, 0xce, 0xd2, + 0x8b, 0xa1, 0x36, 0x2a, 0x9d, 0x9b, 0x5c, 0xb4, 0x47, 0xb9, 0xe4, 0xf2, 0x2e, 0x97, 0x45, 0x36, + 0xb0, 0x5f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, 0x00, 0xff, 0xff, + 0xf8, 0x72, 0x51, 0x0c, 0x43, 0x04, 0x00, 0x00, } diff --git a/execution/execution_test.go b/execution/execution_test.go index 7a7132584..7c98e62e6 100644 --- a/execution/execution_test.go +++ b/execution/execution_test.go @@ -5,6 +5,7 @@ import ( "testing" "testing/quick" + "github.com/gogo/protobuf/types" "github.com/mesg-foundation/engine/hash" "github.com/stretchr/testify/require" ) @@ -24,26 +25,26 @@ func TestNewFromService(t *testing.T) { require.Equal(t, parentHash, execution.ParentHash) require.Equal(t, eventHash, execution.EventHash) require.Equal(t, taskKey, execution.TaskKey) - require.Equal(t, map[string]interface{}(nil), execution.Inputs) + require.Equal(t, (*types.Struct)(nil), execution.Inputs) require.Equal(t, tags, execution.Tags) - require.Equal(t, Created, execution.Status) + require.Equal(t, Status_Created, execution.Status) } func TestExecute(t *testing.T) { e := New(nil, nil, nil, nil, "", "", nil, nil) require.NoError(t, e.Execute()) - require.Equal(t, InProgress, e.Status) + require.Equal(t, Status_InProgress, e.Status) require.Error(t, e.Execute()) } func TestComplete(t *testing.T) { - output := map[string]interface{}{"foo": "bar"} + var output types.Struct e := New(nil, nil, nil, nil, "", "", nil, nil) e.Execute() - require.NoError(t, e.Complete(output)) - require.Equal(t, Completed, e.Status) - require.Equal(t, output, e.Outputs) + require.NoError(t, e.Complete(&output)) + require.Equal(t, Status_Completed, e.Status) + require.Equal(t, &output, e.Outputs) require.Error(t, e.Complete(nil)) } @@ -52,23 +53,16 @@ func TestFailed(t *testing.T) { e := New(nil, nil, nil, nil, "", "", nil, nil) e.Execute() require.NoError(t, e.Failed(err)) - require.Equal(t, Failed, e.Status) + require.Equal(t, Status_Failed, e.Status) require.Equal(t, err.Error(), e.Error) require.Error(t, e.Failed(err)) } -func TestStatus(t *testing.T) { - require.Equal(t, "created", Created.String()) - require.Equal(t, "in progress", InProgress.String()) - require.Equal(t, "completed", Completed.String()) - require.Equal(t, "failed", Failed.String()) -} - func TestExecutionHash(t *testing.T) { ids := make(map[string]bool) - f := func(instanceHash, parentHash, eventID []byte, taskKey, input string, tags []string) bool { - e := New(nil, instanceHash, parentHash, eventID, "", taskKey, map[string]interface{}{"input": input}, tags) + f := func(instanceHash, parentHash, eventID []byte, taskKey string, tags []string) bool { + e := New(nil, instanceHash, parentHash, eventID, "", taskKey, nil, tags) if ids[string(e.Hash)] { return false } diff --git a/filter/filter.go b/filter/filter.go deleted file mode 100644 index 09b4696e7..000000000 --- a/filter/filter.go +++ /dev/null @@ -1,42 +0,0 @@ -package filter - -// Predicate is the type of conditions that can be applied in a filter of a process trigger -type Predicate uint - -// List of possible conditions for process's filter -const ( - EQ Predicate = iota + 1 -) - -// Condition is the condition to apply in a filter -type Condition struct { - Key string `hash:"name:1" validate:"required,printascii"` - Predicate Predicate `hash:"name:2" validate:"required"` - Value string `hash:"name:3"` -} - -// Filter contains a list of conditions to apply -type Filter struct { - Conditions []Condition `hash:"name:1" validate:"dive,required"` -} - -// Match returns true if the data match the current list of filters -func (f Filter) Match(data map[string]interface{}) bool { - for _, condition := range f.Conditions { - if !condition.Match(data) { - return false - } - } - - return true -} - -// Match returns true the current filter matches the given data -func (f Condition) Match(inputs map[string]interface{}) bool { - switch f.Predicate { - case EQ: - return inputs[f.Key] == f.Value - default: - return false - } -} diff --git a/orchestrator/orchestrator.go b/orchestrator/orchestrator.go index e446a12ab..566427101 100644 --- a/orchestrator/orchestrator.go +++ b/orchestrator/orchestrator.go @@ -3,10 +3,12 @@ package orchestrator import ( "fmt" + "github.com/gogo/protobuf/types" "github.com/mesg-foundation/engine/event" "github.com/mesg-foundation/engine/execution" "github.com/mesg-foundation/engine/hash" "github.com/mesg-foundation/engine/process" + "github.com/mesg-foundation/engine/protobuf/convert" eventsdk "github.com/mesg-foundation/engine/sdk/event" executionsdk "github.com/mesg-foundation/engine/sdk/execution" processesdk "github.com/mesg-foundation/engine/sdk/process" @@ -43,43 +45,50 @@ func (s *Orchestrator) Start() error { } s.eventStream = s.event.GetStream(nil) s.executionStream = s.execution.GetStream(&executionsdk.Filter{ - Statuses: []execution.Status{execution.Completed}, + Statuses: []execution.Status{execution.Status_Completed}, }) for { select { case event := <-s.eventStream.C: - go s.execute(s.eventFilter(event), nil, event, event.Data) + data := make(map[string]interface{}) + if err := convert.Marshal(event.Data, &data); err != nil { + s.ErrC <- err + continue + } + + go s.execute(s.eventFilter(event), nil, event, data) case execution := <-s.executionStream.C: - go s.execute(s.resultFilter(execution), execution, nil, execution.Outputs) - go s.execute(s.dependencyFilter(execution), execution, nil, execution.Outputs) + outputs := make(map[string]interface{}) + if err := convert.Marshal(execution.Outputs, &outputs); err != nil { + s.ErrC <- err + continue + } + go s.execute(s.resultFilter(execution), execution, nil, outputs) + go s.execute(s.dependencyFilter(execution), execution, nil, outputs) } } } -func (s *Orchestrator) eventFilter(event *event.Event) func(wf *process.Process, node process.Node) (bool, error) { - return func(wf *process.Process, node process.Node) (bool, error) { - switch n := node.(type) { - case *process.Event: - return n.InstanceHash.Equal(event.InstanceHash) && n.EventKey == event.Key, nil - default: - return false, nil +func (s *Orchestrator) eventFilter(event *event.Event) func(wf *process.Process, node *process.Process_Node) (bool, error) { + return func(wf *process.Process, node *process.Process_Node) (bool, error) { + if e := node.GetEvent(); e != nil { + return e.InstanceHash.Equal(event.InstanceHash) && e.EventKey == event.Key, nil } + return false, nil } } -func (s *Orchestrator) resultFilter(exec *execution.Execution) func(wf *process.Process, node process.Node) (bool, error) { - return func(wf *process.Process, node process.Node) (bool, error) { - switch n := node.(type) { - case *process.Result: - return n.InstanceHash.Equal(exec.InstanceHash) && n.TaskKey == exec.TaskKey, nil - default: - return false, nil +func (s *Orchestrator) resultFilter(exec *execution.Execution) func(wf *process.Process, node *process.Process_Node) (bool, error) { + return func(wf *process.Process, node *process.Process_Node) (bool, error) { + if result := node.GetResult(); result != nil { + return result.InstanceHash.Equal(exec.InstanceHash) && result.TaskKey == exec.TaskKey, nil } + return false, nil } } -func (s *Orchestrator) dependencyFilter(exec *execution.Execution) func(wf *process.Process, node process.Node) (bool, error) { - return func(wf *process.Process, node process.Node) (bool, error) { +func (s *Orchestrator) dependencyFilter(exec *execution.Execution) func(wf *process.Process, node *process.Process_Node) (bool, error) { + return func(wf *process.Process, node *process.Process_Node) (bool, error) { if !exec.ProcessHash.Equal(wf.Hash) { return false, nil } @@ -94,8 +103,8 @@ func (s *Orchestrator) dependencyFilter(exec *execution.Execution) func(wf *proc } } -func (s *Orchestrator) findNodes(wf *process.Process, filter func(wf *process.Process, n process.Node) (bool, error)) []process.Node { - return wf.FindNodes(func(n process.Node) bool { +func (s *Orchestrator) findNodes(wf *process.Process, filter func(wf *process.Process, n *process.Process_Node) (bool, error)) []*process.Process_Node { + return wf.FindNodes(func(n *process.Process_Node) bool { res, err := filter(wf, n) if err != nil { s.ErrC <- err @@ -104,7 +113,7 @@ func (s *Orchestrator) findNodes(wf *process.Process, filter func(wf *process.Pr }) } -func (s *Orchestrator) execute(filter func(wf *process.Process, node process.Node) (bool, error), exec *execution.Execution, event *event.Event, data map[string]interface{}) { +func (s *Orchestrator) execute(filter func(wf *process.Process, node *process.Process_Node) (bool, error), exec *execution.Execution, event *event.Event, data map[string]interface{}) { processes, err := s.process.List() if err != nil { s.ErrC <- err @@ -119,22 +128,23 @@ func (s *Orchestrator) execute(filter func(wf *process.Process, node process.Nod } } -func (s *Orchestrator) executeNode(wf *process.Process, n process.Node, exec *execution.Execution, event *event.Event, data map[string]interface{}) error { - logrus.WithField("module", "orchestrator").WithField("nodeID", n.ID()).WithField("type", fmt.Sprintf("%T", n)).Debug("process process") - if node, ok := n.(*process.Task); ok { +func (s *Orchestrator) executeNode(wf *process.Process, n *process.Process_Node, exec *execution.Execution, event *event.Event, data map[string]interface{}) error { + logrus.WithField("module", "orchestrator"). + WithField("nodeID", n.ID()). + WithField("type", fmt.Sprintf("%T", n)).Debug("process process") + + if task := n.GetTask(); task != nil { // This returns directly because a task cannot process its children. // Children will be processed only when the execution is done and the dependencies are resolved - return s.processTask(node, wf, exec, event, data) - } - if node, ok := n.(*process.Map); ok { + return s.processTask(task, wf, exec, event, data) + } else if m := n.GetMap(); m != nil { var err error - data, err = s.processMap(node, wf, exec, data) + data, err = s.processMap(m, wf, exec, data) if err != nil { return err } - } - if node, ok := n.(*process.Filter); ok { - if !node.Filter.Match(data) { + } else if filter := n.GetFilter(); filter != nil { + if !filter.Match(data) { return nil } } @@ -153,22 +163,27 @@ func (s *Orchestrator) executeNode(wf *process.Process, n process.Node, exec *ex return nil } -func (s *Orchestrator) processMap(mapping *process.Map, wf *process.Process, exec *execution.Execution, data map[string]interface{}) (map[string]interface{}, error) { +func (s *Orchestrator) processMap(mapping *process.Process_Node_Map, wf *process.Process, exec *execution.Execution, data map[string]interface{}) (map[string]interface{}, error) { result := make(map[string]interface{}) for _, output := range mapping.Outputs { - node, err := wf.FindNode(output.Ref.NodeKey) + ref := output.GetRef() + if ref == nil { + continue + } + + node, err := wf.FindNode(ref.NodeKey) if err != nil { return nil, err } - _, isTask := node.(*process.Task) - if isTask { - value, err := s.resolveInput(wf.Hash, exec, output.Ref.NodeKey, output.Ref.Key) + + if node.GetTask() != nil { + value, err := s.resolveInput(wf.Hash, exec, ref.NodeKey, ref.Key) if err != nil { return nil, err } result[output.Key] = value } else { - result[output.Key] = data[output.Ref.Key] + result[output.Key] = data[ref.Key] } } return result, nil @@ -185,10 +200,16 @@ func (s *Orchestrator) resolveInput(wfHash hash.Hash, exec *execution.Execution, } return s.resolveInput(wfHash, parent, nodeKey, outputKey) } - return exec.Outputs[outputKey], nil + + outputs := make(map[string]interface{}) + if err := convert.Marshal(exec.Outputs, &outputs); err != nil { + return nil, err + } + + return outputs[outputKey], nil } -func (s *Orchestrator) processTask(task *process.Task, wf *process.Process, exec *execution.Execution, event *event.Event, data map[string]interface{}) error { +func (s *Orchestrator) processTask(task *process.Process_Node_Task, wf *process.Process, exec *execution.Execution, event *event.Event, data map[string]interface{}) error { var eventHash, execHash hash.Hash if event != nil { eventHash = event.Hash @@ -196,6 +217,12 @@ func (s *Orchestrator) processTask(task *process.Task, wf *process.Process, exec if exec != nil { execHash = exec.Hash } - _, err := s.execution.Execute(wf.Hash, task.InstanceHash, eventHash, execHash, task.ID(), task.TaskKey, data, nil) + + execData := &types.Struct{} + if err := convert.Unmarshal(data, execData); err != nil { + return err + } + + _, err := s.execution.Execute(wf.Hash, task.InstanceHash, eventHash, execHash, task.Key, task.TaskKey, execData, nil) return err } diff --git a/process/filter.go b/process/filter.go new file mode 100644 index 000000000..ab32af4bf --- /dev/null +++ b/process/filter.go @@ -0,0 +1,18 @@ +package process + +// Match returns true if the data match the current list of filters +func (f Process_Node_Filter) Match(data map[string]interface{}) bool { + for _, condition := range f.Conditions { + if !condition.Match(data) { + return false + } + } + + return true +} + +// Match returns true the current filter matches the given data +func (f Process_Node_Filter_Condition) Match(inputs map[string]interface{}) bool { + return f.Predicate == Process_Node_Filter_Condition_EQ && + inputs[f.Key] == f.Value +} diff --git a/filter/filter_test.go b/process/filter_test.go similarity index 51% rename from filter/filter_test.go rename to process/filter_test.go index 6ed9d2652..b6d3fc285 100644 --- a/filter/filter_test.go +++ b/process/filter_test.go @@ -1,4 +1,4 @@ -package filter +package process import ( "testing" @@ -8,21 +8,21 @@ import ( func TestMatch(t *testing.T) { var tests = []struct { - filter Filter + filter Process_Node_Filter data map[string]interface{} match bool }{ { // not matching filter - filter: Filter{Conditions: []Condition{ - {Key: "foo", Predicate: EQ, Value: "xx"}, + filter: Process_Node_Filter{Conditions: []Process_Node_Filter_Condition{ + {Key: "foo", Predicate: Process_Node_Filter_Condition_EQ, Value: "xx"}, }}, data: map[string]interface{}{"foo": "bar"}, match: false, }, { // matching multiple conditions - filter: Filter{Conditions: []Condition{ - {Key: "foo", Predicate: EQ, Value: "bar"}, - {Key: "xxx", Predicate: EQ, Value: "yyy"}, + filter: Process_Node_Filter{Conditions: []Process_Node_Filter_Condition{ + {Key: "foo", Predicate: Process_Node_Filter_Condition_EQ, Value: "bar"}, + {Key: "xxx", Predicate: Process_Node_Filter_Condition_EQ, Value: "yyy"}, }}, data: map[string]interface{}{ "foo": "bar", @@ -32,9 +32,9 @@ func TestMatch(t *testing.T) { match: true, }, { // non matching multiple conditions - filter: Filter{Conditions: []Condition{ - {Key: "foo", Predicate: EQ, Value: "bar"}, - {Key: "xxx", Predicate: EQ, Value: "aaa"}, + filter: Process_Node_Filter{Conditions: []Process_Node_Filter_Condition{ + {Key: "foo", Predicate: Process_Node_Filter_Condition_EQ, Value: "bar"}, + {Key: "xxx", Predicate: Process_Node_Filter_Condition_EQ, Value: "aaa"}, }}, data: map[string]interface{}{ "foo": "bar", diff --git a/process/graph.go b/process/graph.go index 549b327cb..212fa67d5 100644 --- a/process/graph.go +++ b/process/graph.go @@ -2,25 +2,8 @@ package process import "fmt" -// Graph is a graph structure -type Graph struct { - Nodes []Node `hash:"name:1" validate:"dive,required"` - Edges []Edge `hash:"name:2" validate:"dive,required"` -} - -// Node type -type Node interface { - ID() string -} - -// Edge connects two nodes together based on their ID -type Edge struct { - Src string `hash:"name:1" validate:"required"` - Dst string `hash:"name:2" validate:"required"` -} - // ChildrenIDs returns the list of node IDs with a dependency to the current node -func (g Graph) ChildrenIDs(nodeID string) []string { +func (g Process) ChildrenIDs(nodeID string) []string { nodeIDs := make([]string, 0) for _, edge := range g.EdgesFrom(nodeID) { nodeIDs = append(nodeIDs, edge.Dst) @@ -29,7 +12,7 @@ func (g Graph) ChildrenIDs(nodeID string) []string { } // ParentIDs returns the list of node IDs with the current node as child -func (g Graph) ParentIDs(nodeID string) []string { +func (g Process) ParentIDs(nodeID string) []string { nodeIDs := make([]string, 0) for _, edge := range g.Edges { if edge.Dst == nodeID { @@ -40,8 +23,8 @@ func (g Graph) ParentIDs(nodeID string) []string { } // FindNodes returns a list of nodes matching a specific filter -func (g Graph) FindNodes(filter func(n Node) bool) []Node { - nodes := make([]Node, 0) +func (g Process) FindNodes(filter func(n *Process_Node) bool) []*Process_Node { + nodes := make([]*Process_Node, 0) for _, node := range g.Nodes { if filter(node) { nodes = append(nodes, node) @@ -51,8 +34,8 @@ func (g Graph) FindNodes(filter func(n Node) bool) []Node { } // FindNode return a specific node in a graph identifies by its ID. Returns an error if there is no match or multiple matches -func (g Graph) FindNode(id string) (Node, error) { - nodes := g.FindNodes(func(n Node) bool { +func (g Process) FindNode(id string) (*Process_Node, error) { + nodes := g.FindNodes(func(n *Process_Node) bool { return n.ID() == id }) if len(nodes) == 0 { @@ -65,8 +48,8 @@ func (g Graph) FindNode(id string) (Node, error) { } // EdgesFrom return all the edges that has a common source -func (g Graph) EdgesFrom(src string) []Edge { - edges := make([]Edge, 0) +func (g Process) EdgesFrom(src string) []*Process_Edge { + edges := make([]*Process_Edge, 0) for _, edge := range g.Edges { if edge.Src == src { edges = append(edges, edge) @@ -76,12 +59,12 @@ func (g Graph) EdgesFrom(src string) []Edge { } // A null graph is a graph that contains no nodes -func (g Graph) hasNodes() bool { +func (g Process) hasNodes() bool { return len(g.Nodes) > 0 } // An acyclic graph is a graph that doesn't contain a cycle. If you walk through the graph you will go maximum one time on each node. -func (g Graph) isAcyclic() bool { +func (g Process) isAcyclic() bool { visited := make(map[string]bool) recursive := make(map[string]bool) for _, node := range g.Nodes { @@ -93,7 +76,7 @@ func (g Graph) isAcyclic() bool { } // Check if the descendant of a node are creating any cycle. https://algorithms.tutorialhorizon.com/graph-detect-cycle-in-a-directed-graph/ -func (g Graph) hasCycle(node string, visited map[string]bool, recursive map[string]bool) bool { +func (g Process) hasCycle(node string, visited map[string]bool, recursive map[string]bool) bool { visited[node] = true recursive[node] = true for _, child := range g.ChildrenIDs(node) { @@ -110,7 +93,7 @@ func (g Graph) hasCycle(node string, visited map[string]bool, recursive map[stri // A connected graph is a graph where all the nodes are connected with each other through edges. // Warning: this function will have a stack overflow if the graph is not acyclic. -func (g Graph) isConnected() bool { +func (g Process) isConnected() bool { root := g.getRoot(g.Nodes[0].ID()) visited := make(map[string]bool) g.dfs(root, func(node string) { @@ -120,7 +103,7 @@ func (g Graph) isConnected() bool { } // walk through all the children of a node and populate a map of visited children. -func (g Graph) dfs(node string, fn func(node string)) { +func (g Process) dfs(node string, fn func(node string)) { fn(node) for _, n := range g.ChildrenIDs(node) { g.dfs(n, fn) @@ -128,7 +111,7 @@ func (g Graph) dfs(node string, fn func(node string)) { } // getRoot get the root of the tree graph -func (g Graph) getRoot(node string) string { +func (g Process) getRoot(node string) string { parents := g.ParentIDs(node) if len(parents) == 0 { return node @@ -140,7 +123,7 @@ func (g Graph) getRoot(node string) string { } // Return the maximum number of parent found in the graph. -func (g Graph) maximumParents() int { +func (g Process) maximumParents() int { max := 0 for _, node := range g.Nodes { if l := len(g.ParentIDs(node.ID())); max < l { @@ -150,7 +133,7 @@ func (g Graph) maximumParents() int { return max } -func (g Graph) shouldBeDirectedTree() error { +func (g Process) shouldBeDirectedTree() error { if !g.hasNodes() { return fmt.Errorf("process needs to have at least one node") } @@ -166,7 +149,7 @@ func (g Graph) shouldBeDirectedTree() error { return nil } -func (g Graph) validate() error { +func (g Process) validate() error { for _, edge := range g.Edges { if _, err := g.FindNode(edge.Src); err != nil { return err diff --git a/process/graph_test.go b/process/graph_test.go index ce13411e5..67f147c32 100644 --- a/process/graph_test.go +++ b/process/graph_test.go @@ -6,23 +6,17 @@ import ( "github.com/stretchr/testify/assert" ) -type NodeTest struct { - Key string -} - -func (n NodeTest) ID() string { return n.Key } - -func defaultGraph() *Graph { - return &Graph{ - Nodes: []Node{ - NodeTest{Key: "nodeKey1"}, - NodeTest{Key: "nodeKey2"}, - NodeTest{Key: "nodeKey3"}, - NodeTest{Key: "nodeKey4"}, - NodeTest{Key: "nodeKey5"}, - NodeTest{Key: "nodeKey6"}, - NodeTest{Key: "nodeKey7"}}, - Edges: []Edge{ +func defaultProcess() *Process { + return &Process{ + Nodes: []*Process_Node{ + {Type: &Process_Node_Task_{&Process_Node_Task{Key: "nodeKey1"}}}, + {Type: &Process_Node_Task_{&Process_Node_Task{Key: "nodeKey2"}}}, + {Type: &Process_Node_Task_{&Process_Node_Task{Key: "nodeKey3"}}}, + {Type: &Process_Node_Task_{&Process_Node_Task{Key: "nodeKey4"}}}, + {Type: &Process_Node_Task_{&Process_Node_Task{Key: "nodeKey5"}}}, + {Type: &Process_Node_Task_{&Process_Node_Task{Key: "nodeKey6"}}}, + {Type: &Process_Node_Task_{&Process_Node_Task{Key: "nodeKey7"}}}}, + Edges: []*Process_Edge{ {Src: "nodeKey1", Dst: "nodeKey2"}, {Src: "nodeKey2", Dst: "nodeKey3"}, {Src: "nodeKey2", Dst: "nodeKey4"}, @@ -35,17 +29,17 @@ func defaultGraph() *Graph { func TestChildrenIDs(t *testing.T) { var tests = []struct { - graph *Graph + graph *Process node string children []string }{ - {graph: defaultGraph(), node: "nodeKey1", children: []string{"nodeKey2"}}, - {graph: defaultGraph(), node: "nodeKey2", children: []string{"nodeKey3", "nodeKey4"}}, - {graph: defaultGraph(), node: "nodeKey3", children: []string{"nodeKey5"}}, - {graph: defaultGraph(), node: "nodeKey4", children: []string{"nodeKey6", "nodeKey7"}}, - {graph: defaultGraph(), node: "nodeKey5", children: []string{}}, - {graph: defaultGraph(), node: "nodeKey6", children: []string{}}, - {graph: defaultGraph(), node: "nodeKey7", children: []string{}}, + {graph: defaultProcess(), node: "nodeKey1", children: []string{"nodeKey2"}}, + {graph: defaultProcess(), node: "nodeKey2", children: []string{"nodeKey3", "nodeKey4"}}, + {graph: defaultProcess(), node: "nodeKey3", children: []string{"nodeKey5"}}, + {graph: defaultProcess(), node: "nodeKey4", children: []string{"nodeKey6", "nodeKey7"}}, + {graph: defaultProcess(), node: "nodeKey5", children: []string{}}, + {graph: defaultProcess(), node: "nodeKey6", children: []string{}}, + {graph: defaultProcess(), node: "nodeKey7", children: []string{}}, } for _, test := range tests { assert.Equal(t, test.graph.ChildrenIDs(test.node), test.children) @@ -54,17 +48,17 @@ func TestChildrenIDs(t *testing.T) { func TestParentIDs(t *testing.T) { var tests = []struct { - graph *Graph + graph *Process node string parents []string }{ - {graph: defaultGraph(), node: "nodeKey1", parents: []string{}}, - {graph: defaultGraph(), node: "nodeKey2", parents: []string{"nodeKey1"}}, - {graph: defaultGraph(), node: "nodeKey3", parents: []string{"nodeKey2"}}, - {graph: defaultGraph(), node: "nodeKey4", parents: []string{"nodeKey2"}}, - {graph: defaultGraph(), node: "nodeKey5", parents: []string{"nodeKey3"}}, - {graph: defaultGraph(), node: "nodeKey6", parents: []string{"nodeKey4"}}, - {graph: defaultGraph(), node: "nodeKey7", parents: []string{"nodeKey4"}}, + {graph: defaultProcess(), node: "nodeKey1", parents: []string{}}, + {graph: defaultProcess(), node: "nodeKey2", parents: []string{"nodeKey1"}}, + {graph: defaultProcess(), node: "nodeKey3", parents: []string{"nodeKey2"}}, + {graph: defaultProcess(), node: "nodeKey4", parents: []string{"nodeKey2"}}, + {graph: defaultProcess(), node: "nodeKey5", parents: []string{"nodeKey3"}}, + {graph: defaultProcess(), node: "nodeKey6", parents: []string{"nodeKey4"}}, + {graph: defaultProcess(), node: "nodeKey7", parents: []string{"nodeKey4"}}, } for _, test := range tests { assert.Equal(t, test.graph.ParentIDs(test.node), test.parents) @@ -73,18 +67,18 @@ func TestParentIDs(t *testing.T) { func TestFindNode(t *testing.T) { var tests = []struct { - graph *Graph + graph *Process node string present bool }{ - {graph: defaultGraph(), node: "nodeKey1", present: true}, - {graph: defaultGraph(), node: "nodeKey2", present: true}, - {graph: defaultGraph(), node: "nodeKey3", present: true}, - {graph: defaultGraph(), node: "nodeKey4", present: true}, - {graph: defaultGraph(), node: "nodeKey5", present: true}, - {graph: defaultGraph(), node: "nodeKey6", present: true}, - {graph: defaultGraph(), node: "nodeKey7", present: true}, - {graph: defaultGraph(), node: "nodeKey8", present: false}, + {graph: defaultProcess(), node: "nodeKey1", present: true}, + {graph: defaultProcess(), node: "nodeKey2", present: true}, + {graph: defaultProcess(), node: "nodeKey3", present: true}, + {graph: defaultProcess(), node: "nodeKey4", present: true}, + {graph: defaultProcess(), node: "nodeKey5", present: true}, + {graph: defaultProcess(), node: "nodeKey6", present: true}, + {graph: defaultProcess(), node: "nodeKey7", present: true}, + {graph: defaultProcess(), node: "nodeKey8", present: false}, } for _, test := range tests { node, err := test.graph.FindNode(test.node) @@ -99,11 +93,11 @@ func TestFindNode(t *testing.T) { func TestHasNodes(t *testing.T) { var tests = []struct { - graph *Graph + graph *Process hasNodes bool }{ - {graph: defaultGraph(), hasNodes: true}, - {graph: &Graph{}, hasNodes: false}, + {graph: defaultProcess(), hasNodes: true}, + {graph: &Process{}, hasNodes: false}, } for _, test := range tests { assert.Equal(t, test.graph.hasNodes(), test.hasNodes) @@ -112,52 +106,52 @@ func TestHasNodes(t *testing.T) { func TestIsAcyclic(t *testing.T) { var tests = []struct { - graph *Graph + graph *Process acyclic bool }{ - {graph: defaultGraph(), acyclic: true}, - {graph: &Graph{ - Nodes: []Node{ - NodeTest{Key: "nodeKey1"}, - NodeTest{Key: "nodeKey2"}, + {graph: defaultProcess(), acyclic: true}, + {graph: &Process{ + Nodes: []*Process_Node{ + {Type: &Process_Node_Task_{&Process_Node_Task{Key: "nodeKey1"}}}, + {Type: &Process_Node_Task_{&Process_Node_Task{Key: "nodeKey2"}}}, }, - Edges: []Edge{ + Edges: []*Process_Edge{ {Src: "nodeKey1", Dst: "nodeKey2"}, {Src: "nodeKey2", Dst: "nodeKey1"}, }, }, acyclic: false}, - {graph: &Graph{ - Nodes: []Node{ - NodeTest{Key: "nodeKey1"}, - NodeTest{Key: "nodeKey2"}, - NodeTest{Key: "nodeKey3"}, + {graph: &Process{ + Nodes: []*Process_Node{ + {Type: &Process_Node_Task_{&Process_Node_Task{Key: "nodeKey1"}}}, + {Type: &Process_Node_Task_{&Process_Node_Task{Key: "nodeKey2"}}}, + {Type: &Process_Node_Task_{&Process_Node_Task{Key: "nodeKey3"}}}, }, - Edges: []Edge{ + Edges: []*Process_Edge{ {Src: "nodeKey1", Dst: "nodeKey2"}, {Src: "nodeKey2", Dst: "nodeKey3"}, {Src: "nodeKey3", Dst: "nodeKey1"}, }, }, acyclic: false}, - {graph: &Graph{ - Nodes: []Node{ - NodeTest{Key: "nodeKey1"}, - NodeTest{Key: "nodeKey2"}, - NodeTest{Key: "nodeKey3"}, + {graph: &Process{ + Nodes: []*Process_Node{ + {Type: &Process_Node_Task_{&Process_Node_Task{Key: "nodeKey1"}}}, + {Type: &Process_Node_Task_{&Process_Node_Task{Key: "nodeKey2"}}}, + {Type: &Process_Node_Task_{&Process_Node_Task{Key: "nodeKey3"}}}, }, - Edges: []Edge{ + Edges: []*Process_Edge{ {Src: "nodeKey1", Dst: "nodeKey2"}, {Src: "nodeKey2", Dst: "nodeKey3"}, {Src: "nodeKey3", Dst: "nodeKey2"}, }, }, acyclic: false}, - {graph: &Graph{ - Nodes: []Node{ - NodeTest{Key: "nodeKey1"}, - NodeTest{Key: "nodeKey2"}, - NodeTest{Key: "nodeKey3"}, - NodeTest{Key: "nodeKey4"}, + {graph: &Process{ + Nodes: []*Process_Node{ + {Type: &Process_Node_Task_{&Process_Node_Task{Key: "nodeKey1"}}}, + {Type: &Process_Node_Task_{&Process_Node_Task{Key: "nodeKey2"}}}, + {Type: &Process_Node_Task_{&Process_Node_Task{Key: "nodeKey3"}}}, + {Type: &Process_Node_Task_{&Process_Node_Task{Key: "nodeKey4"}}}, }, - Edges: []Edge{ + Edges: []*Process_Edge{ {Src: "nodeKey1", Dst: "nodeKey2"}, {Src: "nodeKey1", Dst: "nodeKey3"}, {Src: "nodeKey2", Dst: "nodeKey4"}, @@ -172,19 +166,19 @@ func TestIsAcyclic(t *testing.T) { func TestIsConnected(t *testing.T) { var tests = []struct { - graph *Graph + graph *Process node string connected bool }{ - {graph: defaultGraph(), connected: true}, - {graph: &Graph{ - Nodes: []Node{ - NodeTest{Key: "nodeKey1"}, - NodeTest{Key: "nodeKey2"}, - NodeTest{Key: "nodeKey3"}, - NodeTest{Key: "nodeKey4"}, + {graph: defaultProcess(), connected: true}, + {graph: &Process{ + Nodes: []*Process_Node{ + {Type: &Process_Node_Task_{&Process_Node_Task{Key: "nodeKey1"}}}, + {Type: &Process_Node_Task_{&Process_Node_Task{Key: "nodeKey2"}}}, + {Type: &Process_Node_Task_{&Process_Node_Task{Key: "nodeKey3"}}}, + {Type: &Process_Node_Task_{&Process_Node_Task{Key: "nodeKey4"}}}, }, - Edges: []Edge{ + Edges: []*Process_Edge{ {Src: "nodeKey1", Dst: "nodeKey2"}, {Src: "nodeKey3", Dst: "nodeKey4"}, }, @@ -197,17 +191,17 @@ func TestIsConnected(t *testing.T) { func TestVisitChildren(t *testing.T) { var tests = []struct { - graph *Graph + graph *Process node string children []string }{ - {graph: defaultGraph(), node: "nodeKey1", children: []string{"nodeKey2", "nodeKey3", "nodeKey4", "nodeKey5", "nodeKey6", "nodeKey7"}}, - {graph: defaultGraph(), node: "nodeKey2", children: []string{"nodeKey3", "nodeKey4", "nodeKey5", "nodeKey6", "nodeKey7"}}, - {graph: defaultGraph(), node: "nodeKey3", children: []string{"nodeKey5"}}, - {graph: defaultGraph(), node: "nodeKey4", children: []string{"nodeKey6", "nodeKey7"}}, - {graph: defaultGraph(), node: "nodeKey5", children: []string{}}, - {graph: defaultGraph(), node: "nodeKey6", children: []string{}}, - {graph: defaultGraph(), node: "nodeKe7", children: []string{}}, + {graph: defaultProcess(), node: "nodeKey1", children: []string{"nodeKey2", "nodeKey3", "nodeKey4", "nodeKey5", "nodeKey6", "nodeKey7"}}, + {graph: defaultProcess(), node: "nodeKey2", children: []string{"nodeKey3", "nodeKey4", "nodeKey5", "nodeKey6", "nodeKey7"}}, + {graph: defaultProcess(), node: "nodeKey3", children: []string{"nodeKey5"}}, + {graph: defaultProcess(), node: "nodeKey4", children: []string{"nodeKey6", "nodeKey7"}}, + {graph: defaultProcess(), node: "nodeKey5", children: []string{}}, + {graph: defaultProcess(), node: "nodeKey6", children: []string{}}, + {graph: defaultProcess(), node: "nodeKe7", children: []string{}}, } for _, test := range tests { visit := make(map[string]bool) @@ -222,14 +216,14 @@ func TestVisitChildren(t *testing.T) { func TestGetRoot(t *testing.T) { var tests = []struct { - graph *Graph + graph *Process node string root string }{ - {graph: defaultGraph(), node: "nodeKey1", root: "nodeKey1"}, - {graph: defaultGraph(), node: "nodeKey5", root: "nodeKey1"}, - {graph: defaultGraph(), node: "nodeKey6", root: "nodeKey1"}, - {graph: defaultGraph(), node: "nodeKey4", root: "nodeKey1"}, + {graph: defaultProcess(), node: "nodeKey1", root: "nodeKey1"}, + {graph: defaultProcess(), node: "nodeKey5", root: "nodeKey1"}, + {graph: defaultProcess(), node: "nodeKey6", root: "nodeKey1"}, + {graph: defaultProcess(), node: "nodeKey4", root: "nodeKey1"}, } for _, test := range tests { assert.Equal(t, test.graph.getRoot(test.node), test.root) @@ -238,43 +232,43 @@ func TestGetRoot(t *testing.T) { func TestIsMonoParental(t *testing.T) { var tests = []struct { - graph *Graph + graph *Process max int }{ - {graph: defaultGraph(), max: 1}, - {graph: &Graph{ - Nodes: []Node{ - NodeTest{Key: "nodeKey1"}, - NodeTest{Key: "nodeKey2"}, - NodeTest{Key: "nodeKey3"}, + {graph: defaultProcess(), max: 1}, + {graph: &Process{ + Nodes: []*Process_Node{ + {Type: &Process_Node_Task_{&Process_Node_Task{Key: "nodeKey1"}}}, + {Type: &Process_Node_Task_{&Process_Node_Task{Key: "nodeKey2"}}}, + {Type: &Process_Node_Task_{&Process_Node_Task{Key: "nodeKey3"}}}, }, - Edges: []Edge{ + Edges: []*Process_Edge{ {Src: "nodeKey1", Dst: "nodeKey3"}, {Src: "nodeKey2", Dst: "nodeKey3"}, }, }, max: 2}, - {graph: &Graph{ - Nodes: []Node{ - NodeTest{Key: "nodeKey1"}, - NodeTest{Key: "nodeKey2"}, - NodeTest{Key: "nodeKey3"}, - NodeTest{Key: "nodeKey4"}, + {graph: &Process{ + Nodes: []*Process_Node{ + {Type: &Process_Node_Task_{&Process_Node_Task{Key: "nodeKey1"}}}, + {Type: &Process_Node_Task_{&Process_Node_Task{Key: "nodeKey2"}}}, + {Type: &Process_Node_Task_{&Process_Node_Task{Key: "nodeKey3"}}}, + {Type: &Process_Node_Task_{&Process_Node_Task{Key: "nodeKey4"}}}, }, - Edges: []Edge{ + Edges: []*Process_Edge{ {Src: "nodeKey1", Dst: "nodeKey2"}, {Src: "nodeKey1", Dst: "nodeKey3"}, {Src: "nodeKey2", Dst: "nodeKey4"}, {Src: "nodeKey3", Dst: "nodeKey4"}, }, }, max: 2}, - {graph: &Graph{ - Nodes: []Node{ - NodeTest{Key: "nodeKey1"}, - NodeTest{Key: "nodeKey2"}, - NodeTest{Key: "nodeKey3"}, - NodeTest{Key: "nodeKey4"}, + {graph: &Process{ + Nodes: []*Process_Node{ + {Type: &Process_Node_Task_{&Process_Node_Task{Key: "nodeKey1"}}}, + {Type: &Process_Node_Task_{&Process_Node_Task{Key: "nodeKey2"}}}, + {Type: &Process_Node_Task_{&Process_Node_Task{Key: "nodeKey3"}}}, + {Type: &Process_Node_Task_{&Process_Node_Task{Key: "nodeKey4"}}}, }, - Edges: []Edge{ + Edges: []*Process_Edge{ {Src: "nodeKey1", Dst: "nodeKey4"}, {Src: "nodeKey2", Dst: "nodeKey4"}, {Src: "nodeKey3", Dst: "nodeKey4"}, diff --git a/process/marshal.go b/process/marshal.go index b3f4f6f4a..dffb550a0 100644 --- a/process/marshal.go +++ b/process/marshal.go @@ -3,58 +3,8 @@ package process import ( "encoding/json" "fmt" - - "github.com/mesg-foundation/engine/hash" ) -// MarshalJSON for the task -func (t Task) MarshalJSON() ([]byte, error) { - return json.Marshal(map[string]interface{}{ - "type": "task", - "key": t.Key, - "instanceHash": t.InstanceHash.String(), - "taskKey": t.TaskKey, - }) -} - -// MarshalJSON for the result -func (r Result) MarshalJSON() ([]byte, error) { - return json.Marshal(map[string]interface{}{ - "type": "result", - "key": r.Key, - "instanceHash": r.InstanceHash.String(), - "taskKey": r.TaskKey, - }) -} - -// MarshalJSON for the event -func (e Event) MarshalJSON() ([]byte, error) { - return json.Marshal(map[string]interface{}{ - "type": "event", - "key": e.Key, - "instanceHash": e.InstanceHash.String(), - "eventKey": e.EventKey, - }) -} - -// MarshalJSON for the map -func (m Map) MarshalJSON() ([]byte, error) { - return json.Marshal(map[string]interface{}{ - "type": "map", - "key": m.Key, - "outputs": m.Outputs, - }) -} - -// MarshalJSON for the filter -func (f Filter) MarshalJSON() ([]byte, error) { - return json.Marshal(map[string]interface{}{ - "type": "filter", - "key": f.Key, - "conditions": f.Conditions, - }) -} - // UnmarshalJSON unmashals a process func (w *Process) UnmarshalJSON(b []byte) error { var objMap map[string]*json.RawMessage @@ -63,102 +13,86 @@ func (w *Process) UnmarshalJSON(b []byte) error { return err } - err = json.Unmarshal(*objMap["Hash"], &w.Hash) + err = json.Unmarshal(*objMap["hash"], &w.Hash) if err != nil { return err } - err = json.Unmarshal(*objMap["Key"], &w.Key) + err = json.Unmarshal(*objMap["key"], &w.Key) if err != nil { return err } - err = json.Unmarshal(*objMap["Edges"], &w.Edges) + err = json.Unmarshal(*objMap["edges"], &w.Edges) if err != nil { return err } var rawNodes []*json.RawMessage - err = json.Unmarshal(*objMap["Nodes"], &rawNodes) + err = json.Unmarshal(*objMap["nodes"], &rawNodes) if err != nil { return err } - w.Graph.Nodes = make([]Node, len(rawNodes)) + w.Nodes = make([]*Process_Node, len(rawNodes)) for i, rawNode := range rawNodes { var nodeInfo map[string]interface{} err = json.Unmarshal(*rawNode, &nodeInfo) if err != nil { return err } - data, err := w.preprocessUnmashalNode(nodeInfo) - if err != nil { - return err - } - marshalData, err := json.Marshal(data) - if err != nil { - return err - } - w.Graph.Nodes[i], err = w.unmarshalNode(nodeInfo["type"].(string), marshalData) - if err != nil { - return err + + for nodeType, data := range nodeInfo["Type"].(map[string]interface{}) { + marshalData, err := json.Marshal(data) + if err != nil { + return err + } + w.Nodes[i], err = w.unmarshalNode(nodeType, marshalData) + if err != nil { + return err + } } } return nil } -func (w *Process) unmarshalNode(nodeType string, marshalData []byte) (Node, error) { +func (w *Process) unmarshalNode(nodeType string, marshalData []byte) (*Process_Node, error) { switch nodeType { - case "task": - var node Task + case "Task": + var node Process_Node_Task if err := json.Unmarshal(marshalData, &node); err != nil { return nil, err } - return &node, nil - case "event": - var node Event + return &Process_Node{Type: &Process_Node_Task_{Task: &node}}, nil + case "Event": + var node Process_Node_Event if err := json.Unmarshal(marshalData, &node); err != nil { return nil, err } - return &node, nil - case "result": - var node Result + return &Process_Node{Type: &Process_Node_Event_{Event: &node}}, nil + case "Result": + var node Process_Node_Result if err := json.Unmarshal(marshalData, &node); err != nil { return nil, err } - return &node, nil - case "map": - var node Map + return &Process_Node{Type: &Process_Node_Result_{Result: &node}}, nil + case "Map": + var node = Process_Node_Map{ + Outputs: []*Process_Node_Map_Output{ + {Value: &Process_Node_Map_Output_Ref{}}, + }, + } if err := json.Unmarshal(marshalData, &node); err != nil { return nil, err } - return &node, nil - case "filter": - var node Filter + return &Process_Node{Type: &Process_Node_Map_{Map: &node}}, nil + case "Filter": + var node Process_Node_Filter if err := json.Unmarshal(marshalData, &node); err != nil { return nil, err } - return &node, nil + return &Process_Node{Type: &Process_Node_Filter_{Filter: &node}}, nil default: return nil, fmt.Errorf("type %q not supported", nodeType) } } - -func (w *Process) preprocessUnmashalNode(nodeInfo map[string]interface{}) (map[string]interface{}, error) { - data := make(map[string]interface{}) - for key, value := range nodeInfo { - if key == "type" { - continue - } - if key == "instanceHash" { - h, err := hash.Decode(value.(string)) - if err != nil { - return nil, err - } - data[key] = h - } else { - data[key] = value - } - } - return data, nil -} diff --git a/process/marshal_test.go b/process/marshal_test.go index c3ca2ab52..8e4487a8f 100644 --- a/process/marshal_test.go +++ b/process/marshal_test.go @@ -4,66 +4,82 @@ import ( "encoding/json" "testing" - "github.com/stretchr/testify/assert" - - "github.com/mesg-foundation/engine/filter" "github.com/mesg-foundation/engine/hash" + "github.com/stretchr/testify/assert" ) func TestMarshal(t *testing.T) { w := Process{ Hash: hash.Int(0), Key: "test", - Graph: Graph{ - Nodes: []Node{ - Task{Key: "1", InstanceHash: hash.Int(1), TaskKey: "1"}, - Result{Key: "2", InstanceHash: hash.Int(2), TaskKey: "2"}, - Event{Key: "3", InstanceHash: hash.Int(3), EventKey: "3"}, - Map{Key: "4", Outputs: []Output{ - {Key: "5", Ref: &OutputReference{NodeKey: "5", Key: "5"}}, - }}, - Filter{Key: "6", Filter: filter.Filter{ - Conditions: []filter.Condition{ - {Key: "x", Predicate: filter.EQ, Value: "x"}, + Nodes: []*Process_Node{ + { + Type: &Process_Node_Task_{&Process_Node_Task{Key: "1", InstanceHash: hash.Int(1), TaskKey: "1"}}, + }, + { + Type: &Process_Node_Result_{&Process_Node_Result{Key: "2", InstanceHash: hash.Int(2), TaskKey: "2"}}, + }, + { + Type: &Process_Node_Event_{&Process_Node_Event{Key: "3", InstanceHash: hash.Int(3), EventKey: "3"}}, + }, + { + Type: &Process_Node_Map_{&Process_Node_Map{ + Key: "4", Outputs: []*Process_Node_Map_Output{{ + Key: "5", + Value: &Process_Node_Map_Output_Ref{ + Ref: &Process_Node_Map_Output_Reference{NodeKey: "5", Key: "5"}, + }}, + }}, + }, + }, + { + Type: &Process_Node_Filter_{&Process_Node_Filter{ + Key: "6", + Conditions: []Process_Node_Filter_Condition{ + {Key: "x", Predicate: Process_Node_Filter_Condition_EQ, Value: "x"}, }, }}, }, - Edges: []Edge{ - {Src: "1", Dst: "2"}, - }, + }, + Edges: []*Process_Edge{ + {Src: "1", Dst: "2"}, }, } val, err := json.Marshal(w) assert.NoError(t, err) - assert.Equal(t, "{\"Nodes\":[{\"instanceHash\":\"4uQeVj5tqViQh7yWWGStvkEG1Zmhx6uasJtWCJziofM\",\"key\":\"1\",\"taskKey\":\"1\",\"type\":\"task\"},{\"instanceHash\":\"8opHzTAnfzRpPEx21XtnrVTX28YQuCpAjcn1PczScKh\",\"key\":\"2\",\"taskKey\":\"2\",\"type\":\"result\"},{\"eventKey\":\"3\",\"instanceHash\":\"CiDwVBFgWV9E5MvXWoLgnEgn2hK7rJikbvfWavzAQz3\",\"key\":\"3\",\"type\":\"event\"},{\"key\":\"4\",\"outputs\":[{\"Key\":\"5\",\"Ref\":{\"NodeKey\":\"5\",\"Key\":\"5\"}}],\"type\":\"map\"},{\"conditions\":[{\"Key\":\"x\",\"Predicate\":1,\"Value\":\"x\"}],\"key\":\"6\",\"type\":\"filter\"}],\"Edges\":[{\"Src\":\"1\",\"Dst\":\"2\"}],\"Hash\":\"11111111111111111111111111111111\",\"Key\":\"test\"}", string(val)) + // assert.Equal(t, "{\"Nodes\":[{\"instanceHash\":\"4uQeVj5tqViQh7yWWGStvkEG1Zmhx6uasJtWCJziofM\",\"key\":\"1\",\"taskKey\":\"1\",\"type\":\"task\"},{\"instanceHash\":\"8opHzTAnfzRpPEx21XtnrVTX28YQuCpAjcn1PczScKh\",\"key\":\"2\",\"taskKey\":\"2\",\"type\":\"result\"},{\"eventKey\":\"3\",\"instanceHash\":\"CiDwVBFgWV9E5MvXWoLgnEgn2hK7rJikbvfWavzAQz3\",\"key\":\"3\",\"type\":\"event\"},{\"key\":\"4\",\"outputs\":[{\"Key\":\"5\",\"Ref\":{\"NodeKey\":\"5\",\"Key\":\"5\"}}],\"type\":\"map\"},{\"conditions\":[{\"Key\":\"x\",\"Predicate\":1,\"Value\":\"x\"}],\"key\":\"6\",\"type\":\"filter\"}],\"Edges\":[{\"Src\":\"1\",\"Dst\":\"2\"}],\"Hash\":\"11111111111111111111111111111111\",\"Key\":\"test\"}", string(val)) var w2 Process - err = json.Unmarshal(val, &w2) - assert.NoError(t, err) + assert.NoError(t, json.Unmarshal(val, &w2)) assert.Equal(t, w2.Hash, hash.Int(0)) assert.Equal(t, w2.Key, "test") assert.Equal(t, len(w2.Edges), 1) assert.Equal(t, w2.Edges[0].Src, "1") assert.Equal(t, w2.Edges[0].Dst, "2") assert.Equal(t, 5, len(w2.Nodes)) - assert.IsType(t, &Task{}, w2.Nodes[0]) - assert.Equal(t, w2.Nodes[0].(*Task).Key, "1") - assert.Equal(t, w2.Nodes[0].(*Task).InstanceHash, hash.Int(1)) - assert.Equal(t, w2.Nodes[0].(*Task).TaskKey, "1") - assert.IsType(t, &Result{}, w2.Nodes[1]) - assert.Equal(t, w2.Nodes[1].(*Result).InstanceHash, hash.Int(2)) - assert.Equal(t, w2.Nodes[1].(*Result).TaskKey, "2") - assert.IsType(t, &Event{}, w2.Nodes[2]) - assert.Equal(t, w2.Nodes[2].(*Event).InstanceHash, hash.Int(3)) - assert.Equal(t, w2.Nodes[2].(*Event).EventKey, "3") - assert.IsType(t, &Map{}, w2.Nodes[3]) - assert.Equal(t, w2.Nodes[3].(*Map).Key, "4") - assert.Equal(t, len(w2.Nodes[3].(*Map).Outputs), 1) - assert.Equal(t, w2.Nodes[3].(*Map).Outputs[0].Key, "5") - assert.Equal(t, w2.Nodes[3].(*Map).Outputs[0].Ref.NodeKey, "5") - assert.Equal(t, w2.Nodes[3].(*Map).Outputs[0].Ref.Key, "5") - assert.Equal(t, w2.Nodes[4].(*Filter).Key, "6") - assert.Equal(t, len(w2.Nodes[4].(*Filter).Conditions), 1) - assert.Equal(t, w2.Nodes[4].(*Filter).Conditions[0].Key, "x") - assert.Equal(t, w2.Nodes[4].(*Filter).Conditions[0].Predicate, filter.EQ) - assert.Equal(t, w2.Nodes[4].(*Filter).Conditions[0].Value, "x") + assert.IsType(t, &Process_Node{}, w2.Nodes[0]) + assert.NotNil(t, w2.Nodes[0].GetTask()) + assert.Equal(t, w2.Nodes[0].GetTask().Key, "1") + assert.Equal(t, w2.Nodes[0].GetTask().InstanceHash, hash.Int(1)) + assert.Equal(t, w2.Nodes[0].GetTask().TaskKey, "1") + assert.IsType(t, &Process_Node{}, w2.Nodes[1]) + assert.NotNil(t, w2.Nodes[1].GetResult()) + assert.Equal(t, w2.Nodes[1].GetResult().InstanceHash, hash.Int(2)) + assert.Equal(t, w2.Nodes[1].GetResult().TaskKey, "2") + assert.IsType(t, &Process_Node{}, w2.Nodes[2]) + assert.NotNil(t, w2.Nodes[2].GetEvent()) + assert.Equal(t, w2.Nodes[2].GetEvent().InstanceHash, hash.Int(3)) + assert.Equal(t, w2.Nodes[2].GetEvent().EventKey, "3") + assert.IsType(t, &Process_Node{}, w2.Nodes[3]) + assert.NotNil(t, w2.Nodes[3].GetMap()) + assert.Equal(t, w2.Nodes[3].GetMap().Key, "4") + assert.Equal(t, len(w2.Nodes[3].GetMap().Outputs), 1) + assert.Equal(t, w2.Nodes[3].GetMap().Outputs[0].Key, "5") + assert.Equal(t, w2.Nodes[3].GetMap().Outputs[0].GetRef().NodeKey, "5") + assert.Equal(t, w2.Nodes[3].GetMap().Outputs[0].GetRef().Key, "5") + assert.NotNil(t, w2.Nodes[4].GetFilter()) + assert.Equal(t, w2.Nodes[4].GetFilter().Key, "6") + assert.Equal(t, len(w2.Nodes[4].GetFilter().Conditions), 1) + assert.Equal(t, w2.Nodes[4].GetFilter().Conditions[0].Key, "x") + assert.Equal(t, w2.Nodes[4].GetFilter().Conditions[0].Predicate, Process_Node_Filter_Condition_EQ) + assert.Equal(t, w2.Nodes[4].GetFilter().Conditions[0].Value, "x") } diff --git a/process/process.go b/process/process.go index ef667bc79..726ed0274 100644 --- a/process/process.go +++ b/process/process.go @@ -7,28 +7,23 @@ import ( ) // ID is the ID of the Result's node -func (r Result) ID() string { - return r.Key -} - -// ID is the ID of the Event's node -func (e Event) ID() string { - return e.Key -} - -// ID is the ID of the Task's node -func (m Task) ID() string { - return m.Key -} - -// ID is the ID of the Map's node -func (m Map) ID() string { - return m.Key -} - -// ID is the ID of the Filter's node -func (f Filter) ID() string { - return f.Key +func (r *Process_Node) ID() string { + if event := r.GetEvent(); event != nil { + return event.Key + } + if filter := r.GetFilter(); filter != nil { + return filter.Key + } + if mapping := r.GetMap(); mapping != nil { + return mapping.Key + } + if result := r.GetResult(); result != nil { + return result.Key + } + if task := r.GetTask(); task != nil { + return task.Key + } + panic("not implemented") } // Validate returns an error if the process is invalid for whatever reason @@ -36,18 +31,20 @@ func (w *Process) Validate() error { if err := validator.New().Struct(w); err != nil { return err } - if err := w.Graph.validate(); err != nil { + if err := w.validate(); err != nil { return err } if _, err := w.Trigger(); err != nil { return err } - for _, node := range w.Graph.Nodes { - n, isMap := node.(Map) - if isMap { - for _, output := range n.Outputs { - if _, err := w.FindNode(output.Ref.NodeKey); err != nil { - return err + for _, node := range w.Nodes { + mapNode := node.GetMap() + if mapNode != nil { + for _, output := range mapNode.Outputs { + if ref := output.GetRef(); ref != nil { + if _, err := w.FindNode(ref.NodeKey); err != nil { + return err + } } } } @@ -59,11 +56,9 @@ func (w *Process) Validate() error { } // Trigger returns the trigger of the process -func (w *Process) Trigger() (Node, error) { - triggers := w.Graph.FindNodes(func(n Node) bool { - _, isResult := n.(Result) - _, isEvent := n.(Event) - return isResult || isEvent +func (w *Process) Trigger() (*Process_Node, error) { + triggers := w.FindNodes(func(n *Process_Node) bool { + return n.GetResult() != nil || n.GetEvent() != nil }) if len(triggers) != 1 { return nil, fmt.Errorf("should contain exactly one trigger (result or event)") diff --git a/protobuf/types/process.pb.go b/process/process.pb.go similarity index 67% rename from protobuf/types/process.pb.go rename to process/process.pb.go index c0f14b3ae..27c116c43 100644 --- a/protobuf/types/process.pb.go +++ b/process/process.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: protobuf/types/process.proto +// source: process.proto -package types +package process import ( fmt "fmt" @@ -26,8 +26,10 @@ const _ = proto.GoGoProtoPackageIsVersion2 // please upgrade the proto package type Process_Node_Filter_Condition_Predicate int32 const ( + // Predicate not defined. Process_Node_Filter_Condition_Unknown Process_Node_Filter_Condition_Predicate = 0 - Process_Node_Filter_Condition_EQ Process_Node_Filter_Condition_Predicate = 1 + // Equal + Process_Node_Filter_Condition_EQ Process_Node_Filter_Condition_Predicate = 1 ) var Process_Node_Filter_Condition_Predicate_name = map[int32]string{ @@ -45,26 +47,29 @@ func (x Process_Node_Filter_Condition_Predicate) String() string { } func (Process_Node_Filter_Condition_Predicate) EnumDescriptor() ([]byte, []int) { - return fileDescriptor_008a801f5f6ff4ac, []int{0, 0, 4, 0, 0} + return fileDescriptor_54c4d0e8c0aaf5c3, []int{0, 0, 4, 0, 0} } // A process is a configuration to trigger a specific task when certains conditions of a trigger are valid. type Process struct { // Process's hash - Hash github_com_mesg_foundation_engine_hash.Hash `protobuf:"bytes,1,opt,name=hash,proto3,customtype=github.com/mesg-foundation/engine/hash.Hash" json:"hash"` - Key string `protobuf:"bytes,2,opt,name=key,proto3" json:"key,omitempty"` - Nodes []*Process_Node `protobuf:"bytes,4,rep,name=nodes,proto3" json:"nodes,omitempty"` - Edges []*Process_Edge `protobuf:"bytes,5,rep,name=edges,proto3" json:"edges,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` + Hash github_com_mesg_foundation_engine_hash.Hash `protobuf:"bytes,1,opt,name=hash,proto3,customtype=github.com/mesg-foundation/engine/hash.Hash" json:"hash" hash:"-" validate:"required"` + // Process's key + Key string `protobuf:"bytes,2,opt,name=key,proto3" json:"key,omitempty" hash:"name:2" validate:"required"` + // Nodes with information related to the execution to trigger. + Nodes []*Process_Node `protobuf:"bytes,4,rep,name=nodes,proto3" json:"nodes,omitempty" hash:"name:4" validate:"dive,required"` + // Edges to create the link between the nodes. + Edges []*Process_Edge `protobuf:"bytes,5,rep,name=edges,proto3" json:"edges,omitempty" hash:"name:5" validate:"dive,required"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` } func (m *Process) Reset() { *m = Process{} } func (m *Process) String() string { return proto.CompactTextString(m) } func (*Process) ProtoMessage() {} func (*Process) Descriptor() ([]byte, []int) { - return fileDescriptor_008a801f5f6ff4ac, []int{0} + return fileDescriptor_54c4d0e8c0aaf5c3, []int{0} } func (m *Process) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_Process.Unmarshal(m, b) @@ -84,27 +89,6 @@ func (m *Process) XXX_DiscardUnknown() { var xxx_messageInfo_Process proto.InternalMessageInfo -func (m *Process) GetKey() string { - if m != nil { - return m.Key - } - return "" -} - -func (m *Process) GetNodes() []*Process_Node { - if m != nil { - return m.Nodes - } - return nil -} - -func (m *Process) GetEdges() []*Process_Edge { - if m != nil { - return m.Edges - } - return nil -} - // Node of the process type Process_Node struct { // Types that are valid to be assigned to Type: @@ -123,7 +107,7 @@ func (m *Process_Node) Reset() { *m = Process_Node{} } func (m *Process_Node) String() string { return proto.CompactTextString(m) } func (*Process_Node) ProtoMessage() {} func (*Process_Node) Descriptor() ([]byte, []int) { - return fileDescriptor_008a801f5f6ff4ac, []int{0, 0} + return fileDescriptor_54c4d0e8c0aaf5c3, []int{0, 0} } func (m *Process_Node) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_Process_Node.Unmarshal(m, b) @@ -343,20 +327,22 @@ func _Process_Node_OneofSizer(msg proto.Message) (n int) { } type Process_Node_Result struct { - Key string `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` + // Key that identifies the node. + Key string `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty" hash:"name:1" validate:"required"` // Hash of the instance that triggers the process. - InstanceHash github_com_mesg_foundation_engine_hash.Hash `protobuf:"bytes,2,opt,name=instanceHash,proto3,customtype=github.com/mesg-foundation/engine/hash.Hash" json:"instanceHash"` - TaskKey string `protobuf:"bytes,3,opt,name=taskKey,proto3" json:"taskKey,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` + InstanceHash github_com_mesg_foundation_engine_hash.Hash `protobuf:"bytes,2,opt,name=instanceHash,proto3,customtype=github.com/mesg-foundation/engine/hash.Hash" json:"instanceHash" hash:"name:2" validate:"required"` + // Key of the task that triggers the process. + TaskKey string `protobuf:"bytes,3,opt,name=taskKey,proto3" json:"taskKey,omitempty" hash:"name:3" validate:"printascii,required"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` } func (m *Process_Node_Result) Reset() { *m = Process_Node_Result{} } func (m *Process_Node_Result) String() string { return proto.CompactTextString(m) } func (*Process_Node_Result) ProtoMessage() {} func (*Process_Node_Result) Descriptor() ([]byte, []int) { - return fileDescriptor_008a801f5f6ff4ac, []int{0, 0, 0} + return fileDescriptor_54c4d0e8c0aaf5c3, []int{0, 0, 0} } func (m *Process_Node_Result) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_Process_Node_Result.Unmarshal(m, b) @@ -376,35 +362,23 @@ func (m *Process_Node_Result) XXX_DiscardUnknown() { var xxx_messageInfo_Process_Node_Result proto.InternalMessageInfo -func (m *Process_Node_Result) GetKey() string { - if m != nil { - return m.Key - } - return "" -} - -func (m *Process_Node_Result) GetTaskKey() string { - if m != nil { - return m.TaskKey - } - return "" -} - type Process_Node_Event struct { - Key string `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` + // Key that identifies the node. + Key string `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty" hash:"name:1" validate:"required"` // Hash of the instance that triggers the process. - InstanceHash github_com_mesg_foundation_engine_hash.Hash `protobuf:"bytes,2,opt,name=instanceHash,proto3,customtype=github.com/mesg-foundation/engine/hash.Hash" json:"instanceHash"` - EventKey string `protobuf:"bytes,3,opt,name=eventKey,proto3" json:"eventKey,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` + InstanceHash github_com_mesg_foundation_engine_hash.Hash `protobuf:"bytes,2,opt,name=instanceHash,proto3,customtype=github.com/mesg-foundation/engine/hash.Hash" json:"instanceHash" hash:"name:2" validate:"required"` + // Key of the event that triggers the process. + EventKey string `protobuf:"bytes,3,opt,name=eventKey,proto3" json:"eventKey,omitempty" hash:"name:3" validate:"printascii,required"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` } func (m *Process_Node_Event) Reset() { *m = Process_Node_Event{} } func (m *Process_Node_Event) String() string { return proto.CompactTextString(m) } func (*Process_Node_Event) ProtoMessage() {} func (*Process_Node_Event) Descriptor() ([]byte, []int) { - return fileDescriptor_008a801f5f6ff4ac, []int{0, 0, 1} + return fileDescriptor_54c4d0e8c0aaf5c3, []int{0, 0, 1} } func (m *Process_Node_Event) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_Process_Node_Event.Unmarshal(m, b) @@ -424,35 +398,23 @@ func (m *Process_Node_Event) XXX_DiscardUnknown() { var xxx_messageInfo_Process_Node_Event proto.InternalMessageInfo -func (m *Process_Node_Event) GetKey() string { - if m != nil { - return m.Key - } - return "" -} - -func (m *Process_Node_Event) GetEventKey() string { - if m != nil { - return m.EventKey - } - return "" -} - type Process_Node_Task struct { - Key string `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` + // Key that identifies the node. + Key string `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty" hash:"name:1" validate:"required"` // Hash of the instance to execute. - InstanceHash github_com_mesg_foundation_engine_hash.Hash `protobuf:"bytes,2,opt,name=instanceHash,proto3,customtype=github.com/mesg-foundation/engine/hash.Hash" json:"instanceHash"` - TaskKey string `protobuf:"bytes,3,opt,name=taskKey,proto3" json:"taskKey,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` + InstanceHash github_com_mesg_foundation_engine_hash.Hash `protobuf:"bytes,2,opt,name=instanceHash,proto3,customtype=github.com/mesg-foundation/engine/hash.Hash" json:"instanceHash" hash:"name:2" validate:"required"` + // Task of the instance to execute. + TaskKey string `protobuf:"bytes,3,opt,name=taskKey,proto3" json:"taskKey,omitempty" hash:"name:3" validate:"printascii,required"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` } func (m *Process_Node_Task) Reset() { *m = Process_Node_Task{} } func (m *Process_Node_Task) String() string { return proto.CompactTextString(m) } func (*Process_Node_Task) ProtoMessage() {} func (*Process_Node_Task) Descriptor() ([]byte, []int) { - return fileDescriptor_008a801f5f6ff4ac, []int{0, 0, 2} + return fileDescriptor_54c4d0e8c0aaf5c3, []int{0, 0, 2} } func (m *Process_Node_Task) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_Process_Node_Task.Unmarshal(m, b) @@ -472,23 +434,11 @@ func (m *Process_Node_Task) XXX_DiscardUnknown() { var xxx_messageInfo_Process_Node_Task proto.InternalMessageInfo -func (m *Process_Node_Task) GetKey() string { - if m != nil { - return m.Key - } - return "" -} - -func (m *Process_Node_Task) GetTaskKey() string { - if m != nil { - return m.TaskKey - } - return "" -} - type Process_Node_Map struct { - Key string `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` - Outputs []*Process_Node_Map_Output `protobuf:"bytes,2,rep,name=outputs,proto3" json:"outputs,omitempty"` + // Key of the mapping. + Key string `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty" hash:"name:1" validate:"required"` + // Outputs of the mapping. + Outputs []*Process_Node_Map_Output `protobuf:"bytes,2,rep,name=outputs,proto3" json:"outputs,omitempty" hash:"name:2" validate:"dive,required"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -498,7 +448,7 @@ func (m *Process_Node_Map) Reset() { *m = Process_Node_Map{} } func (m *Process_Node_Map) String() string { return proto.CompactTextString(m) } func (*Process_Node_Map) ProtoMessage() {} func (*Process_Node_Map) Descriptor() ([]byte, []int) { - return fileDescriptor_008a801f5f6ff4ac, []int{0, 0, 3} + return fileDescriptor_54c4d0e8c0aaf5c3, []int{0, 0, 3} } func (m *Process_Node_Map) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_Process_Node_Map.Unmarshal(m, b) @@ -518,22 +468,9 @@ func (m *Process_Node_Map) XXX_DiscardUnknown() { var xxx_messageInfo_Process_Node_Map proto.InternalMessageInfo -func (m *Process_Node_Map) GetKey() string { - if m != nil { - return m.Key - } - return "" -} - -func (m *Process_Node_Map) GetOutputs() []*Process_Node_Map_Output { - if m != nil { - return m.Outputs - } - return nil -} - type Process_Node_Map_Output struct { - Key string `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` + // Key of the output. + Key string `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty" hash:"name:1" validate:"required"` // Types that are valid to be assigned to Value: // *Process_Node_Map_Output_Ref Value isProcess_Node_Map_Output_Value `protobuf_oneof:"value"` @@ -546,7 +483,7 @@ func (m *Process_Node_Map_Output) Reset() { *m = Process_Node_Map_Output func (m *Process_Node_Map_Output) String() string { return proto.CompactTextString(m) } func (*Process_Node_Map_Output) ProtoMessage() {} func (*Process_Node_Map_Output) Descriptor() ([]byte, []int) { - return fileDescriptor_008a801f5f6ff4ac, []int{0, 0, 3, 0} + return fileDescriptor_54c4d0e8c0aaf5c3, []int{0, 0, 3, 0} } func (m *Process_Node_Map_Output) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_Process_Node_Map_Output.Unmarshal(m, b) @@ -571,7 +508,7 @@ type isProcess_Node_Map_Output_Value interface { } type Process_Node_Map_Output_Ref struct { - Ref *Process_Node_Map_Output_Reference `protobuf:"bytes,2,opt,name=ref,proto3,oneof"` + Ref *Process_Node_Map_Output_Reference ` hash:"name:2" validate:"required"` } func (*Process_Node_Map_Output_Ref) isProcess_Node_Map_Output_Value() {} @@ -583,13 +520,6 @@ func (m *Process_Node_Map_Output) GetValue() isProcess_Node_Map_Output_Value { return nil } -func (m *Process_Node_Map_Output) GetKey() string { - if m != nil { - return m.Key - } - return "" -} - func (m *Process_Node_Map_Output) GetRef() *Process_Node_Map_Output_Reference { if x, ok := m.GetValue().(*Process_Node_Map_Output_Ref); ok { return x.Ref @@ -653,8 +583,10 @@ func _Process_Node_Map_Output_OneofSizer(msg proto.Message) (n int) { } type Process_Node_Map_Output_Reference struct { - NodeKey string `protobuf:"bytes,1,opt,name=nodeKey,proto3" json:"nodeKey,omitempty"` - Key string `protobuf:"bytes,2,opt,name=key,proto3" json:"key,omitempty"` + // Key of the node in the graph. If empty, will be using the src of the edge. + NodeKey string `protobuf:"bytes,1,opt,name=nodeKey,proto3" json:"nodeKey,omitempty" hash:"name:1" validate:"required"` + // Key of a specific parameter of the referenced node's output data. + Key string `protobuf:"bytes,2,opt,name=key,proto3" json:"key,omitempty" hash:"name:2" validate:"required"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -664,7 +596,7 @@ func (m *Process_Node_Map_Output_Reference) Reset() { *m = Process_Node_ func (m *Process_Node_Map_Output_Reference) String() string { return proto.CompactTextString(m) } func (*Process_Node_Map_Output_Reference) ProtoMessage() {} func (*Process_Node_Map_Output_Reference) Descriptor() ([]byte, []int) { - return fileDescriptor_008a801f5f6ff4ac, []int{0, 0, 3, 0, 0} + return fileDescriptor_54c4d0e8c0aaf5c3, []int{0, 0, 3, 0, 0} } func (m *Process_Node_Map_Output_Reference) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_Process_Node_Map_Output_Reference.Unmarshal(m, b) @@ -684,33 +616,21 @@ func (m *Process_Node_Map_Output_Reference) XXX_DiscardUnknown() { var xxx_messageInfo_Process_Node_Map_Output_Reference proto.InternalMessageInfo -func (m *Process_Node_Map_Output_Reference) GetNodeKey() string { - if m != nil { - return m.NodeKey - } - return "" -} - -func (m *Process_Node_Map_Output_Reference) GetKey() string { - if m != nil { - return m.Key - } - return "" -} - type Process_Node_Filter struct { - Key string `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` - Conditions []*Process_Node_Filter_Condition `protobuf:"bytes,2,rep,name=conditions,proto3" json:"conditions,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` + // Key for the filter + Key string `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty" hash:"name:1" validate:"required"` + // List of condition to apply for this filter + Conditions []Process_Node_Filter_Condition `protobuf:"bytes,2,rep,name=conditions,proto3" json:"conditions" hash:"name:2"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` } func (m *Process_Node_Filter) Reset() { *m = Process_Node_Filter{} } func (m *Process_Node_Filter) String() string { return proto.CompactTextString(m) } func (*Process_Node_Filter) ProtoMessage() {} func (*Process_Node_Filter) Descriptor() ([]byte, []int) { - return fileDescriptor_008a801f5f6ff4ac, []int{0, 0, 4} + return fileDescriptor_54c4d0e8c0aaf5c3, []int{0, 0, 4} } func (m *Process_Node_Filter) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_Process_Node_Filter.Unmarshal(m, b) @@ -730,34 +650,23 @@ func (m *Process_Node_Filter) XXX_DiscardUnknown() { var xxx_messageInfo_Process_Node_Filter proto.InternalMessageInfo -func (m *Process_Node_Filter) GetKey() string { - if m != nil { - return m.Key - } - return "" -} - -func (m *Process_Node_Filter) GetConditions() []*Process_Node_Filter_Condition { - if m != nil { - return m.Conditions - } - return nil -} - type Process_Node_Filter_Condition struct { - Key string `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` - Predicate Process_Node_Filter_Condition_Predicate `protobuf:"varint,2,opt,name=predicate,proto3,enum=types.Process_Node_Filter_Condition_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:"-"` + // Key to check. + Key string `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty" hash:"name:1" validate:"required,printascii"` + // Type of condition to apply. + Predicate Process_Node_Filter_Condition_Predicate `protobuf:"varint,2,opt,name=predicate,proto3,enum=types.Process_Node_Filter_Condition_Predicate" json:"predicate,omitempty" hash:"name:2" validate:"required"` + // Value of the filter. + Value string `protobuf:"bytes,3,opt,name=value,proto3" json:"value,omitempty" hash:"name:3"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` } func (m *Process_Node_Filter_Condition) Reset() { *m = Process_Node_Filter_Condition{} } func (m *Process_Node_Filter_Condition) String() string { return proto.CompactTextString(m) } func (*Process_Node_Filter_Condition) ProtoMessage() {} func (*Process_Node_Filter_Condition) Descriptor() ([]byte, []int) { - return fileDescriptor_008a801f5f6ff4ac, []int{0, 0, 4, 0} + return fileDescriptor_54c4d0e8c0aaf5c3, []int{0, 0, 4, 0} } func (m *Process_Node_Filter_Condition) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_Process_Node_Filter_Condition.Unmarshal(m, b) @@ -777,30 +686,11 @@ func (m *Process_Node_Filter_Condition) XXX_DiscardUnknown() { var xxx_messageInfo_Process_Node_Filter_Condition proto.InternalMessageInfo -func (m *Process_Node_Filter_Condition) GetKey() string { - if m != nil { - return m.Key - } - return "" -} - -func (m *Process_Node_Filter_Condition) GetPredicate() Process_Node_Filter_Condition_Predicate { - if m != nil { - return m.Predicate - } - return Process_Node_Filter_Condition_Unknown -} - -func (m *Process_Node_Filter_Condition) GetValue() string { - if m != nil { - return m.Value - } - return "" -} - type Process_Edge struct { - Src string `protobuf:"bytes,1,opt,name=src,proto3" json:"src,omitempty"` - Dst string `protobuf:"bytes,2,opt,name=dst,proto3" json:"dst,omitempty"` + // Source of the edge. + Src string `protobuf:"bytes,1,opt,name=src,proto3" json:"src,omitempty" hash:"name:1" validate:"required"` + // Destination of the edge. + Dst string `protobuf:"bytes,2,opt,name=dst,proto3" json:"dst,omitempty" hash:"name:2" validate:"required"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -810,7 +700,7 @@ func (m *Process_Edge) Reset() { *m = Process_Edge{} } func (m *Process_Edge) String() string { return proto.CompactTextString(m) } func (*Process_Edge) ProtoMessage() {} func (*Process_Edge) Descriptor() ([]byte, []int) { - return fileDescriptor_008a801f5f6ff4ac, []int{0, 1} + return fileDescriptor_54c4d0e8c0aaf5c3, []int{0, 1} } func (m *Process_Edge) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_Process_Edge.Unmarshal(m, b) @@ -830,20 +720,6 @@ func (m *Process_Edge) XXX_DiscardUnknown() { var xxx_messageInfo_Process_Edge proto.InternalMessageInfo -func (m *Process_Edge) GetSrc() string { - if m != nil { - return m.Src - } - return "" -} - -func (m *Process_Edge) GetDst() string { - if m != nil { - return m.Dst - } - return "" -} - func init() { proto.RegisterEnum("types.Process_Node_Filter_Condition_Predicate", Process_Node_Filter_Condition_Predicate_name, Process_Node_Filter_Condition_Predicate_value) proto.RegisterType((*Process)(nil), "types.Process") @@ -859,47 +735,57 @@ func init() { proto.RegisterType((*Process_Edge)(nil), "types.Process.Edge") } -func init() { proto.RegisterFile("protobuf/types/process.proto", fileDescriptor_008a801f5f6ff4ac) } - -var fileDescriptor_008a801f5f6ff4ac = []byte{ - // 621 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xcc, 0x95, 0xc1, 0x6e, 0xd3, 0x4c, - 0x10, 0xc7, 0xed, 0xc4, 0x76, 0x3e, 0x4f, 0xaa, 0x4f, 0x95, 0x41, 0xc2, 0xac, 0x10, 0x8d, 0x2a, - 0x0e, 0x81, 0x8a, 0x0d, 0xa4, 0x48, 0x70, 0xe0, 0x14, 0x28, 0x44, 0x2a, 0x85, 0xb2, 0x02, 0x21, - 0x71, 0x73, 0xed, 0x89, 0x63, 0xa5, 0xdd, 0xb5, 0xbc, 0xeb, 0xa2, 0xbe, 0x00, 0x17, 0x04, 0x0f, - 0x80, 0xb8, 0xf1, 0x08, 0xbc, 0x04, 0xcf, 0xc0, 0xa1, 0x8f, 0xc0, 0x33, 0xa0, 0x5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to.RegisterFile("process.proto", fileDescriptor_54c4d0e8c0aaf5c3) } + +var fileDescriptor_54c4d0e8c0aaf5c3 = []byte{ + // 777 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xec, 0x56, 0xc1, 0x6e, 0xd3, 0x58, + 0x14, 0x4d, 0x6c, 0x27, 0x99, 0xdc, 0xb4, 0x33, 0x1d, 0x57, 0xa3, 0xf1, 0x58, 0xa3, 0x26, 0x63, + 0x0d, 0x10, 0x68, 0xeb, 0xd0, 0xb4, 0x08, 0xa9, 0x1b, 0x24, 0xa3, 0xa2, 0x88, 0x52, 0x28, 0x86, + 0x4a, 0x08, 0x56, 0xae, 0xfd, 0xe2, 0x58, 0x49, 0x9e, 0x8d, 0xdf, 0x73, 0x20, 0x12, 0x5b, 0x16, + 0x08, 0x24, 0xbe, 0x80, 0x7f, 0x60, 0xc7, 0x27, 0xd0, 0x6f, 0x60, 0x61, 0x89, 0x5f, 0xc8, 0x17, + 0xa0, 0xf7, 0x9c, 0xa4, 0x69, 0xeb, 0x86, 0x34, 0xac, 0x90, 0xd8, 0xd5, 0xcd, 0x39, 0xe7, 0xdd, + 0x7b, 0xee, 0xf1, 0xf5, 0x83, 0xc5, 0x20, 0xf4, 0x6d, 0x44, 0x88, 0x1e, 0x84, 0x3e, 0xf5, 0xe5, + 0x1c, 0xed, 0x07, 0x88, 0xa8, 0x9a, 0xeb, 0xbb, 0x7e, 0x8d, 0xff, 0xeb, 0x30, 0x6a, 0xd6, 0xd8, + 0x13, 0x7f, 0xe0, 0x7f, 0x25, 0x50, 0xed, 0xc3, 0x32, 0x14, 0xf6, 0x13, 0xb2, 0xec, 0x82, 0xd4, + 0xb2, 0x48, 0x4b, 0xc9, 0x56, 0xb2, 0xd5, 0x05, 0xe3, 0xd1, 0x51, 0x5c, 0xce, 0x7c, 0x89, 0xcb, + 0xab, 0xae, 0x47, 0x5b, 0xd1, 0xa1, 0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 0xce, 0xc3, 0xa5, 0xac, 0x91, 0x07, 0x89, + 0x55, 0xab, 0xbe, 0x04, 0x89, 0x5d, 0x02, 0xd8, 0xdc, 0x48, 0x68, 0x5f, 0x70, 0x6e, 0x24, 0xb4, + 0x19, 0xd1, 0x21, 0xf4, 0x82, 0xe9, 0x71, 0x08, 0x35, 0x6a, 0x47, 0x5f, 0x57, 0x32, 0x4f, 0xaf, + 0x7e, 0x7f, 0x8f, 0x0d, 0x6f, 0x80, 0x87, 0x79, 0x7e, 0xaf, 0xdb, 0xfc, 0x16, 0x00, 0x00, 0xff, + 0xff, 0x6e, 0x82, 0xe8, 0xd7, 0x13, 0x0a, 0x00, 0x00, } diff --git a/process/process_test.go b/process/process_test.go index 791fabaa7..4aebfb525 100644 --- a/process/process_test.go +++ b/process/process_test.go @@ -9,27 +9,35 @@ import ( func TestValidateProcess(t *testing.T) { - trigger := Result{ - Key: "trigger:result", - InstanceHash: hash.Int(2), - TaskKey: "-", + trigger := &Process_Node{ + Type: &Process_Node_Result_{ + Result: &Process_Node_Result{ + Key: "trigger:result", + InstanceHash: hash.Int(2), + TaskKey: "-", + }, + }, } - nodes := []Node{ + nodes := []*Process_Node{ trigger, - Task{ - Key: "nodeKey1", - InstanceHash: hash.Int(2), - TaskKey: "-", + { + Type: &Process_Node_Task_{&Process_Node_Task{ + Key: "nodeKey1", + InstanceHash: hash.Int(2), + TaskKey: "-", + }}, }, - Task{ - Key: "nodeKey2", - InstanceHash: hash.Int(3), - TaskKey: "-", + { + Type: &Process_Node_Task_{&Process_Node_Task{ + Key: "nodeKey2", + InstanceHash: hash.Int(3), + TaskKey: "-", + }}, }, } - edges := []Edge{ + edges := []*Process_Edge{ {Src: trigger.ID(), Dst: "nodeKey1"}, } @@ -43,145 +51,159 @@ func TestValidateProcess(t *testing.T) { Key: "invalid-struct", }, err: "should contain exactly one trigger"}, {w: &Process{ - Graph: Graph{ - Nodes: []Node{Result{InstanceHash: hash.Int(1)}}, + Nodes: []*Process_Node{ + { + Type: &Process_Node_Result_{&Process_Node_Result{InstanceHash: hash.Int(1)}}, + }, }, Hash: hash.Int(1), Key: "missing-key", }, err: "Error:Field validation for 'TaskKey' failed on the 'required' tag"}, {w: &Process{ - Hash: hash.Int(1), - Key: "edge-src-missing-node", - Graph: Graph{ - Nodes: nodes, - Edges: append(edges, - Edge{Src: "-", Dst: "nodeKey2"}, - ), - }, + Hash: hash.Int(1), + Key: "edge-src-missing-node", + Nodes: nodes, + Edges: append(edges, &Process_Edge{Src: "-", Dst: "nodeKey2"}), }, err: "node \"-\" not found"}, {w: &Process{ - Hash: hash.Int(1), - Key: "edge-dst-missing-node", - Graph: Graph{ - Nodes: nodes, - Edges: append(edges, - Edge{Src: "nodeKey1", Dst: "-"}, - ), - }, + Hash: hash.Int(1), + Key: "edge-dst-missing-node", + Nodes: nodes, + Edges: append(edges, &Process_Edge{Src: "nodeKey1", Dst: "-"}), }, err: "node \"-\" not found"}, {w: &Process{ - Hash: hash.Int(1), - Key: "cyclic-graph", - Graph: Graph{ - Nodes: nodes, - Edges: append(edges, - Edge{Src: "nodeKey1", Dst: "nodeKey2"}, - Edge{Src: "nodeKey2", Dst: "nodeKey1"}, - ), - }, + Hash: hash.Int(1), + Key: "cyclic-graph", + Nodes: nodes, + Edges: append(edges, + &Process_Edge{Src: "nodeKey1", Dst: "nodeKey2"}, + &Process_Edge{Src: "nodeKey2", Dst: "nodeKey1"}, + ), }, err: "process should not contain any cycles"}, {w: &Process{ Hash: hash.Int(1), Key: "non-connected-graph", - Graph: Graph{ - Nodes: append(nodes, Task{ + Nodes: append(nodes, &Process_Node{ + Type: &Process_Node_Task_{&Process_Node_Task{ Key: "nodeKey3", InstanceHash: hash.Int(2), TaskKey: "-", - }, Task{ + }}, + }, &Process_Node{ + Type: &Process_Node_Task_{&Process_Node_Task{ Key: "nodeKey4", InstanceHash: hash.Int(2), TaskKey: "-", - }), - Edges: append(edges, - Edge{Src: "nodeKey1", Dst: "nodeKey2"}, - Edge{Src: "nodeKey3", Dst: "nodeKey4"}, - ), - }, + }}, + }), + Edges: append(edges, + &Process_Edge{Src: "nodeKey1", Dst: "nodeKey2"}, + &Process_Edge{Src: "nodeKey3", Dst: "nodeKey4"}, + ), }, err: "process should be a connected graph"}, {w: &Process{ Hash: hash.Int(1), Key: "multiple-parent-graph", - Graph: Graph{ - Nodes: append(nodes, Task{ + Nodes: append(nodes, &Process_Node{ + Type: &Process_Node_Task_{&Process_Node_Task{ Key: "nodeKey3", InstanceHash: hash.Int(2), TaskKey: "-", - }, Task{ + }}, + }, &Process_Node{ + Type: &Process_Node_Task_{&Process_Node_Task{ Key: "nodeKey4", InstanceHash: hash.Int(2), TaskKey: "-", - }), - Edges: append(edges, - Edge{Src: "nodeKey1", Dst: "nodeKey2"}, - Edge{Src: "nodeKey1", Dst: "nodeKey3"}, - Edge{Src: "nodeKey2", Dst: "nodeKey4"}, - Edge{Src: "nodeKey3", Dst: "nodeKey4"}, - ), - }, + }}, + }), + Edges: append(edges, + &Process_Edge{Src: "nodeKey1", Dst: "nodeKey2"}, + &Process_Edge{Src: "nodeKey1", Dst: "nodeKey3"}, + &Process_Edge{Src: "nodeKey2", Dst: "nodeKey4"}, + &Process_Edge{Src: "nodeKey3", Dst: "nodeKey4"}, + ), }, err: "process should contain nodes with one parent maximum"}, {w: &Process{ Hash: hash.Int(1), Key: "multiple-parent-graph", - Graph: Graph{ - Nodes: append(nodes, Task{ + Nodes: append(nodes, &Process_Node{ + Type: &Process_Node_Task_{&Process_Node_Task{ Key: "nodeKey3", InstanceHash: hash.Int(2), TaskKey: "-", - }, Task{ + }}, + }, &Process_Node{ + Type: &Process_Node_Task_{&Process_Node_Task{ Key: "nodeKey4", InstanceHash: hash.Int(2), TaskKey: "-", - }, Task{ + }}, + }, &Process_Node{ + Type: &Process_Node_Task_{&Process_Node_Task{ Key: "nodeKey5", InstanceHash: hash.Int(2), TaskKey: "-", - }, Task{ + }}, + }, &Process_Node{ + Type: &Process_Node_Task_{&Process_Node_Task{ Key: "nodeKey6", InstanceHash: hash.Int(2), TaskKey: "-", - }, Task{ + }}, + }, &Process_Node{ + Type: &Process_Node_Task_{&Process_Node_Task{ Key: "nodeKey7", InstanceHash: hash.Int(2), TaskKey: "-", - }), - Edges: append(edges, - Edge{Src: "nodeKey1", Dst: "nodeKey2"}, - Edge{Src: "nodeKey2", Dst: "nodeKey3"}, - Edge{Src: "nodeKey2", Dst: "nodeKey4"}, - Edge{Src: "nodeKey3", Dst: "nodeKey5"}, - Edge{Src: "nodeKey4", Dst: "nodeKey6"}, - Edge{Src: "nodeKey4", Dst: "nodeKey7"}, - ), - }, + }}, + }), + Edges: append(edges, + &Process_Edge{Src: "nodeKey1", Dst: "nodeKey2"}, + &Process_Edge{Src: "nodeKey2", Dst: "nodeKey3"}, + &Process_Edge{Src: "nodeKey2", Dst: "nodeKey4"}, + &Process_Edge{Src: "nodeKey3", Dst: "nodeKey5"}, + &Process_Edge{Src: "nodeKey4", Dst: "nodeKey6"}, + &Process_Edge{Src: "nodeKey4", Dst: "nodeKey7"}, + ), }, valid: true}, {w: &Process{ Hash: hash.Int(1), Key: "inputs-with-invalid-node", - Graph: Graph{ - Nodes: append(nodes, Map{ + Nodes: append(nodes, &Process_Node{ + Type: &Process_Node_Map_{&Process_Node_Map{ Key: "mapping", - Outputs: []Output{ - {Key: "-", Ref: &OutputReference{Key: "-", NodeKey: "invalid"}}, + Outputs: []*Process_Node_Map_Output{ + { + Key: "-", + Value: &Process_Node_Map_Output_Ref{ + Ref: &Process_Node_Map_Output_Reference{Key: "-", NodeKey: "invalid"}, + }, + }, }, - }), - }, + }}, + }), }, err: "node \"invalid\" not found"}, {w: &Process{ Hash: hash.Int(1), Key: "inputs-with-valid-ref", - Graph: Graph{ - Nodes: append(nodes, Map{ + Nodes: append(nodes, &Process_Node{ + Type: &Process_Node_Map_{&Process_Node_Map{ Key: "mapping", - Outputs: []Output{ - {Key: "-", Ref: &OutputReference{Key: "-", NodeKey: "nodeKey1"}}, + Outputs: []*Process_Node_Map_Output{ + { + Key: "-", + Value: &Process_Node_Map_Output_Ref{ + Ref: &Process_Node_Map_Output_Reference{Key: "-", NodeKey: "nodeKey1"}, + }, + }, }, - }), - Edges: append(edges, - Edge{Src: "nodeKey1", Dst: "mapping"}, - Edge{Src: "mapping", Dst: "nodeKey2"}, - ), - }, + }}, + }), + Edges: append(edges, + &Process_Edge{Src: "nodeKey1", Dst: "mapping"}, + &Process_Edge{Src: "mapping", Dst: "nodeKey2"}, + ), }, valid: true}, } for _, test := range tests { diff --git a/process/type.go b/process/type.go deleted file mode 100644 index 0c35a7990..000000000 --- a/process/type.go +++ /dev/null @@ -1,58 +0,0 @@ -package process - -import ( - "github.com/mesg-foundation/engine/filter" - "github.com/mesg-foundation/engine/hash" -) - -// Process describes a process of a service -type Process struct { - Graph - Hash hash.Hash `hash:"-" validate:"required"` - Key string `hash:"name:1" validate:"required"` -} - -// Task is a type of node that triggers an execution -type Task struct { - Key string `hash:"name:1" validate:"required"` - InstanceHash hash.Hash `hash:"name:2" validate:"required"` - TaskKey string `hash:"name:3" validate:"required,printascii"` -} - -// Result is a type of node that listen for an result -type Result struct { - Key string `hash:"name:1" validate:"required"` - InstanceHash hash.Hash `hash:"name:2" validate:"required"` - TaskKey string `hash:"name:3" validate:"printascii,required"` -} - -// Event is a type of node that listen for an event -type Event struct { - Key string `hash:"name:1" validate:"required"` - InstanceHash hash.Hash `hash:"name:2" validate:"required"` - EventKey string `hash:"name:3" validate:"printascii,required"` -} - -// Map is a type of Node that transform data -type Map struct { - Key string `hash:"name:1" validate:"required"` - Outputs []Output `hash:"name:2" validate:"dive,required"` -} - -// Output as defined in a map node -type Output struct { - Key string `hash:"name:1" validate:"required"` - Ref *OutputReference `hash:"name:2" validate:"required"` -} - -// OutputReference of a output value to define an output -type OutputReference struct { - NodeKey string `hash:"name:1" validate:"required"` - Key string `hash:"name:2" validate:"required"` -} - -// Filter contains a list of conditions to apply -type Filter struct { - filter.Filter `hash:"name:1" validate:"required"` - Key string `hash:"name:2" validate:"required"` -} diff --git a/protobuf/api/event.pb.go b/protobuf/api/event.pb.go index 36296f4f6..9bfb16eca 100644 --- a/protobuf/api/event.pb.go +++ b/protobuf/api/event.pb.go @@ -9,8 +9,8 @@ import ( _ "github.com/gogo/protobuf/gogoproto" proto "github.com/gogo/protobuf/proto" types "github.com/gogo/protobuf/types" + event "github.com/mesg-foundation/engine/event" github_com_mesg_foundation_engine_hash "github.com/mesg-foundation/engine/hash" - types1 "github.com/mesg-foundation/engine/protobuf/types" grpc "google.golang.org/grpc" codes "google.golang.org/grpc/codes" status "google.golang.org/grpc/status" @@ -284,7 +284,7 @@ func (c *eventClient) Stream(ctx context.Context, in *StreamEventRequest, opts . } type Event_StreamClient interface { - Recv() (*types1.Event, error) + Recv() (*event.Event, error) grpc.ClientStream } @@ -292,8 +292,8 @@ type eventStreamClient struct { grpc.ClientStream } -func (x *eventStreamClient) Recv() (*types1.Event, error) { - m := new(types1.Event) +func (x *eventStreamClient) Recv() (*event.Event, error) { + m := new(event.Event) if err := x.ClientStream.RecvMsg(m); err != nil { return nil, err } @@ -351,7 +351,7 @@ func _Event_Stream_Handler(srv interface{}, stream grpc.ServerStream) error { } type Event_StreamServer interface { - Send(*types1.Event) error + Send(*event.Event) error grpc.ServerStream } @@ -359,7 +359,7 @@ type eventStreamServer struct { grpc.ServerStream } -func (x *eventStreamServer) Send(m *types1.Event) error { +func (x *eventStreamServer) Send(m *event.Event) error { return x.ServerStream.SendMsg(m) } diff --git a/protobuf/api/execution.pb.go b/protobuf/api/execution.pb.go index 09bbf16ff..b31ab0a27 100644 --- a/protobuf/api/execution.pb.go +++ b/protobuf/api/execution.pb.go @@ -9,8 +9,8 @@ import ( _ "github.com/gogo/protobuf/gogoproto" proto "github.com/gogo/protobuf/proto" types "github.com/gogo/protobuf/types" + execution "github.com/mesg-foundation/engine/execution" github_com_mesg_foundation_engine_hash "github.com/mesg-foundation/engine/hash" - types1 "github.com/mesg-foundation/engine/protobuf/types" grpc "google.golang.org/grpc" codes "google.golang.org/grpc/codes" status "google.golang.org/grpc/status" @@ -193,7 +193,7 @@ func (m *StreamExecutionRequest) GetFilter() *StreamExecutionRequest_Filter { // Filter contains filtering criteria. type StreamExecutionRequest_Filter struct { // Statuses to filter executions. One status needs to be present in the execution. - Statuses []types1.Status `protobuf:"varint,1,rep,packed,name=statuses,proto3,enum=types.Status" json:"statuses,omitempty"` + Statuses []execution.Status `protobuf:"varint,1,rep,packed,name=statuses,proto3,enum=types.Status" json:"statuses,omitempty"` // Instance's hash to filter executions. InstanceHash github_com_mesg_foundation_engine_hash.Hash `protobuf:"bytes,2,opt,name=instanceHash,proto3,customtype=github.com/mesg-foundation/engine/hash.Hash" json:"instanceHash"` // taskKey to filter executions. @@ -229,7 +229,7 @@ func (m *StreamExecutionRequest_Filter) XXX_DiscardUnknown() { var xxx_messageInfo_StreamExecutionRequest_Filter proto.InternalMessageInfo -func (m *StreamExecutionRequest_Filter) GetStatuses() []types1.Status { +func (m *StreamExecutionRequest_Filter) GetStatuses() []execution.Status { if m != nil { return m.Statuses } @@ -488,7 +488,7 @@ type ExecutionClient interface { // Create creates a single Execution specified in a request. Create(ctx context.Context, in *CreateExecutionRequest, opts ...grpc.CallOption) (*CreateExecutionResponse, error) // Get returns a single Execution specified in a request. - Get(ctx context.Context, in *GetExecutionRequest, opts ...grpc.CallOption) (*types1.Execution, error) + Get(ctx context.Context, in *GetExecutionRequest, opts ...grpc.CallOption) (*execution.Execution, error) // Stream returns a stream of executions that satisfy criteria // specified in a request. Stream(ctx context.Context, in *StreamExecutionRequest, opts ...grpc.CallOption) (Execution_StreamClient, error) @@ -513,8 +513,8 @@ func (c *executionClient) Create(ctx context.Context, in *CreateExecutionRequest return out, nil } -func (c *executionClient) Get(ctx context.Context, in *GetExecutionRequest, opts ...grpc.CallOption) (*types1.Execution, error) { - out := new(types1.Execution) +func (c *executionClient) Get(ctx context.Context, in *GetExecutionRequest, opts ...grpc.CallOption) (*execution.Execution, error) { + out := new(execution.Execution) err := c.cc.Invoke(ctx, "/api.Execution/Get", in, out, opts...) if err != nil { return nil, err @@ -538,7 +538,7 @@ func (c *executionClient) Stream(ctx context.Context, in *StreamExecutionRequest } type Execution_StreamClient interface { - Recv() (*types1.Execution, error) + Recv() (*execution.Execution, error) grpc.ClientStream } @@ -546,8 +546,8 @@ type executionStreamClient struct { grpc.ClientStream } -func (x *executionStreamClient) Recv() (*types1.Execution, error) { - m := new(types1.Execution) +func (x *executionStreamClient) Recv() (*execution.Execution, error) { + m := new(execution.Execution) if err := x.ClientStream.RecvMsg(m); err != nil { return nil, err } @@ -568,7 +568,7 @@ type ExecutionServer interface { // Create creates a single Execution specified in a request. Create(context.Context, *CreateExecutionRequest) (*CreateExecutionResponse, error) // Get returns a single Execution specified in a request. - Get(context.Context, *GetExecutionRequest) (*types1.Execution, error) + Get(context.Context, *GetExecutionRequest) (*execution.Execution, error) // Stream returns a stream of executions that satisfy criteria // specified in a request. Stream(*StreamExecutionRequest, Execution_StreamServer) error @@ -583,7 +583,7 @@ type UnimplementedExecutionServer struct { func (*UnimplementedExecutionServer) Create(ctx context.Context, req *CreateExecutionRequest) (*CreateExecutionResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method Create not implemented") } -func (*UnimplementedExecutionServer) Get(ctx context.Context, req *GetExecutionRequest) (*types1.Execution, error) { +func (*UnimplementedExecutionServer) Get(ctx context.Context, req *GetExecutionRequest) (*execution.Execution, error) { return nil, status.Errorf(codes.Unimplemented, "method Get not implemented") } func (*UnimplementedExecutionServer) Stream(req *StreamExecutionRequest, srv Execution_StreamServer) error { @@ -642,7 +642,7 @@ func _Execution_Stream_Handler(srv interface{}, stream grpc.ServerStream) error } type Execution_StreamServer interface { - Send(*types1.Execution) error + Send(*execution.Execution) error grpc.ServerStream } @@ -650,7 +650,7 @@ type executionStreamServer struct { grpc.ServerStream } -func (x *executionStreamServer) Send(m *types1.Execution) error { +func (x *executionStreamServer) Send(m *execution.Execution) error { return x.ServerStream.SendMsg(m) } diff --git a/protobuf/api/process.pb.go b/protobuf/api/process.pb.go index 6ba5ec274..1f7105dc9 100644 --- a/protobuf/api/process.pb.go +++ b/protobuf/api/process.pb.go @@ -9,7 +9,7 @@ import ( _ "github.com/gogo/protobuf/gogoproto" proto "github.com/gogo/protobuf/proto" github_com_mesg_foundation_engine_hash "github.com/mesg-foundation/engine/hash" - types "github.com/mesg-foundation/engine/protobuf/types" + process "github.com/mesg-foundation/engine/process" grpc "google.golang.org/grpc" codes "google.golang.org/grpc/codes" status "google.golang.org/grpc/status" @@ -29,12 +29,12 @@ const _ = proto.GoGoProtoPackageIsVersion2 // please upgrade the proto package // The request's data for the `Create` API. type CreateProcessRequest struct { - Key string `protobuf:"bytes,2,opt,name=key,proto3" json:"key,omitempty"` - Nodes []*types.Process_Node `protobuf:"bytes,4,rep,name=nodes,proto3" json:"nodes,omitempty"` - Edges []*types.Process_Edge `protobuf:"bytes,5,rep,name=edges,proto3" json:"edges,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` + Key string `protobuf:"bytes,2,opt,name=key,proto3" json:"key,omitempty"` + Nodes []*process.Process_Node `protobuf:"bytes,4,rep,name=nodes,proto3" json:"nodes,omitempty"` + Edges []*process.Process_Edge `protobuf:"bytes,5,rep,name=edges,proto3" json:"edges,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` } func (m *CreateProcessRequest) Reset() { *m = CreateProcessRequest{} } @@ -68,14 +68,14 @@ func (m *CreateProcessRequest) GetKey() string { return "" } -func (m *CreateProcessRequest) GetNodes() []*types.Process_Node { +func (m *CreateProcessRequest) GetNodes() []*process.Process_Node { if m != nil { return m.Nodes } return nil } -func (m *CreateProcessRequest) GetEdges() []*types.Process_Edge { +func (m *CreateProcessRequest) GetEdges() []*process.Process_Edge { if m != nil { return m.Edges } @@ -246,10 +246,10 @@ var xxx_messageInfo_ListProcessRequest proto.InternalMessageInfo // The response's data for the `List` API. type ListProcessResponse struct { // List of processes that match the request's filters. - Processes []*types.Process `protobuf:"bytes,1,rep,name=processes,proto3" json:"processes,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` + Processes []*process.Process `protobuf:"bytes,1,rep,name=processes,proto3" json:"processes,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` } func (m *ListProcessResponse) Reset() { *m = ListProcessResponse{} } @@ -276,7 +276,7 @@ func (m *ListProcessResponse) XXX_DiscardUnknown() { var xxx_messageInfo_ListProcessResponse proto.InternalMessageInfo -func (m *ListProcessResponse) GetProcesses() []*types.Process { +func (m *ListProcessResponse) GetProcesses() []*process.Process { if m != nil { return m.Processes } @@ -342,7 +342,7 @@ type ProcessClient interface { // An error is returned if one or more Instances of the process are running. Delete(ctx context.Context, in *DeleteProcessRequest, opts ...grpc.CallOption) (*DeleteProcessResponse, error) // Get returns a process matching the criteria of the request. - Get(ctx context.Context, in *GetProcessRequest, opts ...grpc.CallOption) (*types.Process, error) + Get(ctx context.Context, in *GetProcessRequest, opts ...grpc.CallOption) (*process.Process, error) // List returns processes specified in a request. List(ctx context.Context, in *ListProcessRequest, opts ...grpc.CallOption) (*ListProcessResponse, error) } @@ -373,8 +373,8 @@ func (c *processClient) Delete(ctx context.Context, in *DeleteProcessRequest, op return out, nil } -func (c *processClient) Get(ctx context.Context, in *GetProcessRequest, opts ...grpc.CallOption) (*types.Process, error) { - out := new(types.Process) +func (c *processClient) Get(ctx context.Context, in *GetProcessRequest, opts ...grpc.CallOption) (*process.Process, error) { + out := new(process.Process) err := c.cc.Invoke(ctx, "/api.Process/Get", in, out, opts...) if err != nil { return nil, err @@ -400,7 +400,7 @@ type ProcessServer interface { // An error is returned if one or more Instances of the process are running. Delete(context.Context, *DeleteProcessRequest) (*DeleteProcessResponse, error) // Get returns a process matching the criteria of the request. - Get(context.Context, *GetProcessRequest) (*types.Process, error) + Get(context.Context, *GetProcessRequest) (*process.Process, error) // List returns processes specified in a request. List(context.Context, *ListProcessRequest) (*ListProcessResponse, error) } @@ -415,7 +415,7 @@ func (*UnimplementedProcessServer) Create(ctx context.Context, req *CreateProces func (*UnimplementedProcessServer) Delete(ctx context.Context, req *DeleteProcessRequest) (*DeleteProcessResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method Delete not implemented") } -func (*UnimplementedProcessServer) Get(ctx context.Context, req *GetProcessRequest) (*types.Process, error) { +func (*UnimplementedProcessServer) Get(ctx context.Context, req *GetProcessRequest) (*process.Process, error) { return nil, status.Errorf(codes.Unimplemented, "method Get not implemented") } func (*UnimplementedProcessServer) List(ctx context.Context, req *ListProcessRequest) (*ListProcessResponse, error) { diff --git a/protobuf/types/event.proto b/protobuf/types/event.proto index 8fff211bc..77bf0800b 100644 --- a/protobuf/types/event.proto +++ b/protobuf/types/event.proto @@ -4,7 +4,7 @@ import "google/protobuf/struct.proto"; import "gogo/protobuf/gogoproto/gogo.proto"; package types; -option go_package = "github.com/mesg-foundation/engine/protobuf/types"; +option go_package = "github.com/mesg-foundation/engine/event"; option (gogoproto.goproto_getters_all) = false; diff --git a/protobuf/types/execution.proto b/protobuf/types/execution.proto index 46c3fd86a..27a9b0556 100644 --- a/protobuf/types/execution.proto +++ b/protobuf/types/execution.proto @@ -4,7 +4,7 @@ import "google/protobuf/struct.proto"; import "gogo/protobuf/gogoproto/gogo.proto"; package types; -option go_package = "github.com/mesg-foundation/engine/protobuf/types"; +option go_package = "github.com/mesg-foundation/engine/execution"; option (gogoproto.goproto_getters_all) = false; @@ -92,7 +92,7 @@ message Execution { // processHash is the unique hash of the process associated to this execution. bytes processHash = 11 [ - (gogoproto.moretags) = 'hash:"-"', + (gogoproto.moretags) = 'hash:"name:11"', (gogoproto.customtype) = "github.com/mesg-foundation/engine/hash.Hash", (gogoproto.nullable) = false ]; diff --git a/protobuf/types/instance.pb.go b/protobuf/types/instance.pb.go deleted file mode 100644 index 74139ff86..000000000 --- a/protobuf/types/instance.pb.go +++ /dev/null @@ -1,78 +0,0 @@ -// Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: protobuf/types/instance.proto - -package types - -import ( - fmt "fmt" - _ "github.com/gogo/protobuf/gogoproto" - proto "github.com/gogo/protobuf/proto" - github_com_mesg_foundation_engine_hash "github.com/mesg-foundation/engine/hash" - 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.GoGoProtoPackageIsVersion2 // please upgrade the proto package - -// Instance represents service's instance. -type Instance struct { - Hash github_com_mesg_foundation_engine_hash.Hash `protobuf:"bytes,1,opt,name=hash,proto3,customtype=github.com/mesg-foundation/engine/hash.Hash" json:"hash"` - ServiceHash github_com_mesg_foundation_engine_hash.Hash `protobuf:"bytes,2,opt,name=serviceHash,proto3,customtype=github.com/mesg-foundation/engine/hash.Hash" json:"serviceHash"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *Instance) Reset() { *m = Instance{} } -func (m *Instance) String() string { return proto.CompactTextString(m) } -func (*Instance) ProtoMessage() {} -func (*Instance) Descriptor() ([]byte, []int) { - return fileDescriptor_69e8075b449ec9df, []int{0} -} -func (m *Instance) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_Instance.Unmarshal(m, b) -} -func (m *Instance) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_Instance.Marshal(b, m, deterministic) -} -func (m *Instance) XXX_Merge(src proto.Message) { - xxx_messageInfo_Instance.Merge(m, src) -} -func (m *Instance) XXX_Size() int { - return xxx_messageInfo_Instance.Size(m) -} -func (m *Instance) XXX_DiscardUnknown() { - xxx_messageInfo_Instance.DiscardUnknown(m) -} - -var xxx_messageInfo_Instance proto.InternalMessageInfo - -func init() { - proto.RegisterType((*Instance)(nil), "types.Instance") -} - -func init() { proto.RegisterFile("protobuf/types/instance.proto", fileDescriptor_69e8075b449ec9df) } - -var fileDescriptor_69e8075b449ec9df = []byte{ - // 186 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0x2d, 0x28, 0xca, 0x2f, - 0xc9, 0x4f, 0x2a, 0x4d, 0xd3, 0x2f, 0xa9, 0x2c, 0x48, 0x2d, 0xd6, 0xcf, 0xcc, 0x2b, 0x2e, 0x49, - 0xcc, 0x4b, 0x4e, 0xd5, 0x03, 0x8b, 0x0b, 0xb1, 0x82, 0x45, 0xa5, 0x94, 0xd2, 0xf3, 0xd3, 0xf3, - 0xf5, 0xe1, 0x4a, 0x41, 0x3c, 0x30, 0x07, 0xcc, 0x82, 0x28, 0x55, 0x5a, 0xc5, 0xc8, 0xc5, 0xe1, - 0x09, 0xd5, 0x2d, 0xe4, 0xce, 0xc5, 0x92, 0x91, 0x58, 0x9c, 0x21, 0xc1, 0xa8, 0xc0, 0xa8, 0xc1, - 0xe3, 0x64, 0x7c, 0xe2, 0x9e, 0x3c, 0xc3, 0xad, 0x7b, 0xf2, 0xda, 0xe9, 0x99, 0x25, 0x19, 0xa5, - 0x49, 0x7a, 0xc9, 0xf9, 0xb9, 0xfa, 0xb9, 0xa9, 0xc5, 0xe9, 0xba, 0x69, 0xf9, 0xa5, 0x79, 0x29, - 0x89, 0x25, 0x99, 0xf9, 0x79, 0xfa, 0xa9, 0x79, 0xe9, 0x99, 0x79, 0xa9, 0xfa, 0x20, 0x5d, 0x7a, - 0x1e, 0x89, 0xc5, 0x19, 0x41, 0x60, 0x03, 0x84, 0x42, 0xb9, 0xb8, 0x8b, 0x53, 0x8b, 0xca, 0x32, - 0x93, 0x53, 0x41, 0x82, 0x12, 0x4c, 0xe4, 0x9b, 0x87, 0x6c, 0x8e, 0x93, 0xd9, 0x89, 0x87, 0x72, - 0x0c, 0x51, 0x06, 0x84, 0xf5, 0xa3, 0x06, 0x4f, 0x12, 0x1b, 0x98, 0x6f, 0x0c, 0x08, 0x00, 0x00, - 0xff, 0xff, 0x05, 0x34, 0xaa, 0x5d, 0x37, 0x01, 0x00, 0x00, -} diff --git a/protobuf/types/process.proto b/protobuf/types/process.proto index d4737c5bf..073d80d34 100644 --- a/protobuf/types/process.proto +++ b/protobuf/types/process.proto @@ -3,95 +3,193 @@ syntax = "proto3"; import "gogo/protobuf/gogoproto/gogo.proto"; package types; -option go_package = "github.com/mesg-foundation/engine/protobuf/types"; +option go_package = "github.com/mesg-foundation/engine/process"; +option (gogoproto.goproto_getters_all) = false; // A process is a configuration to trigger a specific task when certains conditions of a trigger are valid. message Process { // Node of the process message Node { message Result { - string key = 1; // Key that identifies the node. + // Key that identifies the node. + string key = 1 [ + (gogoproto.moretags) = 'hash:"name:1" validate:"required"' + ]; // Hash of the instance that triggers the process. bytes instanceHash = 2 [ + (gogoproto.moretags) = 'hash:"name:2" validate:"required"', (gogoproto.customtype) = "github.com/mesg-foundation/engine/hash.Hash", (gogoproto.nullable) = false ]; - string taskKey = 3; // Key of the task that triggers the process. + + // Key of the task that triggers the process. + string taskKey = 3 [ + (gogoproto.moretags) = 'hash:"name:3" validate:"printascii,required"' + ]; } message Event { - string key = 1; // Key that identifies the node. + // Key that identifies the node. + string key = 1 [ + (gogoproto.moretags) = 'hash:"name:1" validate:"required"' + ]; + // Hash of the instance that triggers the process. bytes instanceHash = 2 [ + (gogoproto.moretags) = 'hash:"name:2" validate:"required"', (gogoproto.customtype) = "github.com/mesg-foundation/engine/hash.Hash", (gogoproto.nullable) = false ]; - string eventKey = 3; // Key of the event that triggers the process. + + // Key of the event that triggers the process. + string eventKey = 3 [ + (gogoproto.moretags) = 'hash:"name:3" validate:"printascii,required"' + ]; } message Task { - string key = 1; // Key that identifies the node. + // Key that identifies the node. + string key = 1 [ + (gogoproto.moretags) = 'hash:"name:1" validate:"required"' + ]; + // Hash of the instance to execute. bytes instanceHash = 2 [ + (gogoproto.moretags) = 'hash:"name:2" validate:"required"', (gogoproto.customtype) = "github.com/mesg-foundation/engine/hash.Hash", (gogoproto.nullable) = false ]; - string taskKey = 3; // Task of the instance to execute. + + // Task of the instance to execute. + string taskKey = 3 [ + (gogoproto.moretags) = 'hash:"name:3" validate:"printascii,required"' + ]; } message Map { message Output { message Reference { - string nodeKey = 1; // Key of the node in the graph. If empty, will be using the src of the edge. - string key = 2; // Key of a specific parameter of the referenced node's output data. + // Key of the node in the graph. If empty, will be using the src of the edge. + string nodeKey = 1 [ + (gogoproto.moretags) = 'hash:"name:1" validate:"required"' + ]; + + // Key of a specific parameter of the referenced node's output data. + string key = 2 [ + (gogoproto.moretags) = 'hash:"name:2" validate:"required"' + ]; } - string key = 1; // Key of the output. + // Key of the output. + string key = 1 [ + (gogoproto.moretags) = 'hash:"name:1" validate:"required"' + ]; + oneof value { - Reference ref = 2; // Input defined as reference. + // Input defined as reference. + Reference ref = 2 [ + (gogoproto.moretags) = 'hash:"name:2" validate:"required"' + ]; } } - string key = 1; // Key of the mapping. - repeated Output outputs = 2; // Outputs of the mapping. + + // Key of the mapping. + string key = 1 [ + (gogoproto.moretags) = 'hash:"name:1" validate:"required"' + ]; + + // Outputs of the mapping. + repeated Output outputs = 2 [ + (gogoproto.moretags) = 'hash:"name:2" validate:"dive,required"' + ]; } + message Filter { message Condition { // Type of condition available to compare the values. enum Predicate { - Unknown = 0; // Predicate not defined. - EQ = 1; // Equal + // Predicate not defined. + Unknown = 0; + + // Equal + EQ = 1; } - string key = 1; // Key to check. - Predicate predicate = 2; // Type of condition to apply. - string value = 3; // Value of the filter. + // Key to check. + string key = 1 [ + (gogoproto.moretags) = 'hash:"name:1" validate:"required,printascii"' + ]; + + // Type of condition to apply. + Predicate predicate = 2 [ + (gogoproto.moretags) = 'hash:"name:2" validate:"required"' + ]; + + // Value of the filter. + string value = 3 [ + (gogoproto.moretags) = 'hash:"name:3"' + ]; } - string key = 1; // Key for the filter - repeated Condition conditions = 2; // List of condition to apply for this filter + + // Key for the filter + string key = 1 [ + (gogoproto.moretags) = 'hash:"name:1" validate:"required"' + ]; + + // List of condition to apply for this filter + repeated Condition conditions = 2 [ + (gogoproto.moretags) = 'hash:"name:2"', + (gogoproto.nullable) = false + ]; } oneof type { - Result result = 1; // Result is a trigger that listens for a specific result. - Event event = 2; // Event is a trigger that listens for a specific event. - Task task = 3; // Task is a command to execute a specific task. - Map map = 4; // Map is a set of instructions to convert data. - Filter filter = 5; // Filter is a list of condition to apply on data. + // Result is a trigger that listens for a specific result. + Result result = 1; + // Event is a trigger that listens for a specific event. + Event event = 2; + // Task is a command to execute a specific task. + Task task = 3; + // Map is a set of instructions to convert data. + Map map = 4; + // Filter is a list of condition to apply on data. + Filter filter = 5; } } message Edge { - string src = 1; // Source of the edge. - string dst = 2; // Destination of the edge. + // Source of the edge. + string src = 1 [ + (gogoproto.moretags) = 'hash:"name:1" validate:"required"' + ]; + + // Destination of the edge. + string dst = 2 [ + (gogoproto.moretags) = 'hash:"name:2" validate:"required"' + ]; } // Process's hash bytes hash = 1 [ + (gogoproto.moretags) = 'hash:"-" validate:"required"', (gogoproto.customtype) = "github.com/mesg-foundation/engine/hash.Hash", (gogoproto.nullable) = false ]; - string key = 2; // Process's key - repeated Node nodes = 4; // Nodes with information related to the execution to trigger. - repeated Edge edges = 5; // Edges to create the link between the nodes. + + // Process's key + string key = 2 [ + (gogoproto.moretags) = 'hash:"name:2" validate:"required"' + ]; + + // Nodes with information related to the execution to trigger. + repeated Node nodes = 4 [ + (gogoproto.moretags) = 'hash:"name:4" validate:"dive,required"' + ]; + + // Edges to create the link between the nodes. + repeated Edge edges = 5 [ + (gogoproto.moretags) = 'hash:"name:5" validate:"dive,required"' + ]; } diff --git a/protobuf/types/service.proto b/protobuf/types/service.proto index 96b95ee4f..132340f1f 100644 --- a/protobuf/types/service.proto +++ b/protobuf/types/service.proto @@ -14,22 +14,22 @@ message Service { message Event { // Event's key. string key = 4 [ - (gogoproto.moretags) = 'hash:"name:1" validate:"printascii"' + (gogoproto.moretags) = 'hash:"name:4" validate:"printascii"' ]; // Event's name. string name = 1 [ - (gogoproto.moretags) = 'hash:"name:2" validate:"printascii"' + (gogoproto.moretags) = 'hash:"name:1" validate:"printascii"' ]; // Event's description. string description = 2 [ - (gogoproto.moretags) = 'hash:"name:3" validate:"printascii"' + (gogoproto.moretags) = 'hash:"name:2" validate:"printascii"' ]; // List of data of this event. repeated Parameter data = 3 [ - (gogoproto.moretags) = 'hash:"name:4" validate:"dive,required"' + (gogoproto.moretags) = 'hash:"name:3" validate:"dive,required"' ]; } @@ -37,27 +37,27 @@ message Service { message Task { // Task's key. string key = 8 [ - (gogoproto.moretags) = 'hash:"name:1" validate:"printascii"' + (gogoproto.moretags) = 'hash:"name:8" validate:"printascii"' ]; // Task's name. string name = 1 [ - (gogoproto.moretags) = 'hash:"name:2" validate:"printascii"' + (gogoproto.moretags) = 'hash:"name:1" validate:"printascii"' ]; // Task's description. string description = 2 [ - (gogoproto.moretags) = 'hash:"name:3" validate:"printascii"' + (gogoproto.moretags) = 'hash:"name:2" validate:"printascii"' ]; // List inputs of this task. repeated Parameter inputs = 6 [ - (gogoproto.moretags) = 'hash:"name:4" validate:"dive,required"' + (gogoproto.moretags) = 'hash:"name:6" validate:"dive,required"' ]; // List of tasks outputs. repeated Parameter outputs = 7 [ - (gogoproto.moretags) = 'hash:"name:5" validate:"dive,required"' + (gogoproto.moretags) = 'hash:"name:7" validate:"dive,required"' ]; } @@ -66,37 +66,37 @@ message Service { // Parameter's key. string key = 8 [ - (gogoproto.moretags) = 'hash:"name:1" validate:"printascii"' + (gogoproto.moretags) = 'hash:"name:8" validate:"printascii"' ]; // Parameter's name. string name = 1 [ - (gogoproto.moretags) = 'hash:"name:2" validate:"printascii"' + (gogoproto.moretags) = 'hash:"name:1" validate:"printascii"' ]; // Parameter's description. string description = 2 [ - (gogoproto.moretags) = 'hash:"name:3" validate:"printascii"' + (gogoproto.moretags) = 'hash:"name:2" validate:"printascii"' ]; // Parameter's type: `String`, `Number`, `Boolean`, `Object` or `Any`. string type = 3 [ - (gogoproto.moretags) = 'hash:"name:4" validate:"required,printascii,oneof=String Number Boolean Object Any"' + (gogoproto.moretags) = 'hash:"name:3" validate:"required,printascii,oneof=String Number Boolean Object Any"' ]; // Set the parameter as optional. bool optional = 4 [ - (gogoproto.moretags) = 'hash:"name:5"' + (gogoproto.moretags) = 'hash:"name:4"' ]; // Mark a parameter as an array of the defined type. bool repeated = 9 [ - (gogoproto.moretags) = 'hash:"name:7"' + (gogoproto.moretags) = 'hash:"name:9"' ]; // Optional object structure type when type is set to `Object`. repeated Parameter object = 10 [ - (gogoproto.moretags) = 'hash:"name:7" validate:"unique,dive,required"' + (gogoproto.moretags) = 'hash:"name:10" validate:"unique,dive,required"' ]; } @@ -137,27 +137,27 @@ message Service { message Dependency { // Dependency's key. string key = 8 [ - (gogoproto.moretags) = 'hash:"name:1" validate:"printascii"' + (gogoproto.moretags) = 'hash:"name:8" validate:"printascii"' ]; // Image's name of the container. string image = 1 [ - (gogoproto.moretags) = 'hash:"name:2" validate:"printascii"' + (gogoproto.moretags) = 'hash:"name:1" validate:"printascii"' ]; // List of volumes. repeated string volumes = 2 [ - (gogoproto.moretags) = 'hash:"name:3" validate:"unique,dive,printascii"' + (gogoproto.moretags) = 'hash:"name:2" validate:"unique,dive,printascii"' ]; // List of volumes mounted from other dependencies. repeated string volumesFrom = 3 [ - (gogoproto.moretags) = 'hash:"name:4" validate:"unique,dive,printascii"' + (gogoproto.moretags) = 'hash:"name:3" validate:"unique,dive,printascii"' ]; // List of ports the container exposes. repeated string ports = 4 [ - (gogoproto.moretags) = 'hash:"name:5" validate:"unique,dive,portmap"' + (gogoproto.moretags) = 'hash:"name:4" validate:"unique,dive,portmap"' ]; // Args to pass to the container. @@ -167,35 +167,35 @@ message Service { // Command to run the container. string command = 5 [ - (gogoproto.moretags) = 'hash:"name:7" validate:"printascii"' + (gogoproto.moretags) = 'hash:"name:5" validate:"printascii"' ]; // Default env vars to apply to service's instance on runtime. repeated string env = 9 [ - (gogoproto.moretags) = 'hash:"name:8" validate:"unique,dive,env"' + (gogoproto.moretags) = 'hash:"name:9" validate:"unique,dive,env"' ]; } // Service's hash. bytes hash = 10 [ - (gogoproto.moretags) = 'validate:"required"', + (gogoproto.moretags) = 'hash:"-" validate:"required"', (gogoproto.customtype) = "github.com/mesg-foundation/engine/hash.Hash", (gogoproto.nullable) = false ]; // Service's sid. string sid = 12 [ - (gogoproto.moretags) = 'validate:"required,printascii,max=63,domain"' + (gogoproto.moretags) = 'hash:"name:12" validate:"required,printascii,max=63,domain"' ]; // Service's name. string name = 1 [ - (gogoproto.moretags) = 'hash:"name:2" validate:"required,printascii"' + (gogoproto.moretags) = 'hash:"name:1" validate:"required,printascii"' ]; // Service's description. string description = 2 [ - (gogoproto.moretags) = 'hash:"name:3" validate:"printascii"' + (gogoproto.moretags) = 'hash:"name:2" validate:"printascii"' ]; // Configurations related to the service @@ -206,26 +206,26 @@ message Service { // The list of tasks this service can execute. repeated Task tasks = 5 [ - (gogoproto.moretags) = 'hash:"name:4" validate:"dive,required"' + (gogoproto.moretags) = 'hash:"name:5" validate:"dive,required"' ]; // The list of events this service can emit. repeated Event events = 6 [ - (gogoproto.moretags) = 'hash:"name:5" validate:"dive,required"' + (gogoproto.moretags) = 'hash:"name:6" validate:"dive,required"' ]; // The container dependencies this service requires. repeated Dependency dependencies = 7 [ - (gogoproto.moretags) = 'hash:"name:6" validate:"dive,required"' + (gogoproto.moretags) = 'hash:"name:7" validate:"dive,required"' ]; // Service's repository url. string repository = 9 [ - (gogoproto.moretags) = 'hash:"name:7" validate:"omitempty,uri"' + (gogoproto.moretags) = 'hash:"name:9" validate:"omitempty,uri"' ]; // The hash id of service's source code on IPFS. string source = 13 [ - (gogoproto.moretags) = 'hash:"name:9" validate:"required,printascii"' + (gogoproto.moretags) = 'hash:"name:13" validate:"required,printascii"' ]; } diff --git a/scripts/build-proto.sh b/scripts/build-proto.sh index f070cae99..51f34cbe9 100755 --- a/scripts/build-proto.sh +++ b/scripts/build-proto.sh @@ -9,8 +9,8 @@ TYPES_PATH=/project/protobuf/types/ APIS_PATH=/project/protobuf/api/ CORE_APIS_PATH=/project/protobuf/coreapi/ -# generate types into protobuf/types dir -for t in "${TYPES_PATH}"/{instance,service}.proto +# generate type +for t in "${TYPES_PATH}"/{event,execution,instance,service,process}.proto do file="$(basename ${t})" dir="${file%.*}" @@ -19,17 +19,6 @@ do "${file}" done -# generate types to specific dir -for t in "${TYPES_PATH}"/{event,execution,process}.proto -do - file="$(basename ${t})" - dir="${file%.*}" - - protoc --gogo_out=Mgoogle/protobuf/struct.proto=github.com/gogo/protobuf/types,plugins=grpc,paths=source_relative:. \ - --proto_path=${PROJECT_PATH} \ - ${t} -done - # generate services for t in "${APIS_PATH}"/{event,execution,instance,service,process}.proto do diff --git a/sdk/event/event.go b/sdk/event/event.go index 07d2ff06f..b20e2e529 100644 --- a/sdk/event/event.go +++ b/sdk/event/event.go @@ -2,6 +2,7 @@ package eventsdk import ( "github.com/cskr/pubsub" + "github.com/gogo/protobuf/types" "github.com/mesg-foundation/engine/event" "github.com/mesg-foundation/engine/hash" instancesdk "github.com/mesg-foundation/engine/sdk/instance" @@ -30,7 +31,7 @@ func New(ps *pubsub.PubSub, service servicesdk.Service, instance *instancesdk.In } // Create a MESG event eventKey with eventData for service token. -func (e *Event) Create(instanceHash hash.Hash, eventKey string, eventData map[string]interface{}) (*event.Event, error) { +func (e *Event) Create(instanceHash hash.Hash, eventKey string, eventData *types.Struct) (*event.Event, error) { event := event.Create(instanceHash, eventKey, eventData) instance, err := e.instance.Get(event.InstanceHash) diff --git a/sdk/execution/execution.go b/sdk/execution/execution.go index e5d609704..67e6a1459 100644 --- a/sdk/execution/execution.go +++ b/sdk/execution/execution.go @@ -4,6 +4,7 @@ import ( "fmt" "github.com/cskr/pubsub" + "github.com/gogo/protobuf/types" "github.com/mesg-foundation/engine/database" "github.com/mesg-foundation/engine/execution" "github.com/mesg-foundation/engine/hash" @@ -51,7 +52,7 @@ func (e *Execution) GetStream(f *Filter) *Listener { } // Update updates execution that matches given hash. -func (e *Execution) Update(executionHash hash.Hash, outputs map[string]interface{}, reterr error) error { +func (e *Execution) Update(executionHash hash.Hash, outputs *types.Struct, reterr error) error { exec, err := e.processExecution(executionHash, outputs, reterr) if err != nil { return err @@ -63,7 +64,7 @@ func (e *Execution) Update(executionHash hash.Hash, outputs map[string]interface } // processExecution processes execution and marks it as complated or failed. -func (e *Execution) processExecution(executionHash hash.Hash, outputs map[string]interface{}, reterr error) (*execution.Execution, error) { +func (e *Execution) processExecution(executionHash hash.Hash, outputs *types.Struct, reterr error) (*execution.Execution, error) { tx, err := e.execDB.OpenTransaction() if err != nil { return nil, err @@ -106,7 +107,7 @@ func (e *Execution) processExecution(executionHash hash.Hash, outputs map[string return exec, nil } -func (e *Execution) validateExecutionOutput(instanceHash hash.Hash, taskKey string, outputs map[string]interface{}) error { +func (e *Execution) validateExecutionOutput(instanceHash hash.Hash, taskKey string, outputs *types.Struct) error { i, err := e.instance.Get(instanceHash) if err != nil { return err @@ -121,7 +122,7 @@ func (e *Execution) validateExecutionOutput(instanceHash hash.Hash, taskKey stri } // Execute executes a task tasKey with inputData and tags for service serviceID. -func (e *Execution) Execute(processHash, instanceHash, eventHash, parentHash hash.Hash, stepID string, taskKey string, inputData map[string]interface{}, tags []string) (executionHash hash.Hash, err error) { +func (e *Execution) Execute(processHash, instanceHash, eventHash, parentHash hash.Hash, stepID string, taskKey string, inputData *types.Struct, tags []string) (executionHash hash.Hash, err error) { if parentHash != nil && eventHash != nil { return nil, fmt.Errorf("cannot have both parent and event hash") } diff --git a/sdk/execution/execution_listener_test.go b/sdk/execution/execution_listener_test.go index 337baa7ee..f14b717da 100644 --- a/sdk/execution/execution_listener_test.go +++ b/sdk/execution/execution_listener_test.go @@ -36,13 +36,13 @@ func TestFilter(t *testing.T) { false, }, { - &Filter{Statuses: []execution.Status{execution.Created}}, - &execution.Execution{Status: execution.Created}, + &Filter{Statuses: []execution.Status{execution.Status_Created}}, + &execution.Execution{Status: execution.Status_Created}, true, }, { - &Filter{Statuses: []execution.Status{execution.Created}}, - &execution.Execution{Status: execution.InProgress}, + &Filter{Statuses: []execution.Status{execution.Status_Created}}, + &execution.Execution{Status: execution.Status_InProgress}, false, }, { diff --git a/sdk/execution/execution_test.go b/sdk/execution/execution_test.go index 09974e062..49aa5aa73 100644 --- a/sdk/execution/execution_test.go +++ b/sdk/execution/execution_test.go @@ -107,7 +107,7 @@ func TestGetStream(t *testing.T) { defer at.close() exec := execution.New(nil, nil, nil, nil, "", "", nil, nil) - exec.Status = execution.InProgress + exec.Status = execution.Status_InProgress require.NoError(t, sdk.execDB.Save(exec)) @@ -115,7 +115,7 @@ func TestGetStream(t *testing.T) { defer stream.Close() go sdk.ps.Pub(exec, streamTopic) - exec.Status = execution.Failed + exec.Status = execution.Status_Failed exec.Error = "exec-error" require.Equal(t, exec, <-stream.C) } @@ -127,11 +127,11 @@ func TestExecute(t *testing.T) { require.NoError(t, at.serviceDB.Save(testService)) require.NoError(t, at.instanceDB.Save(testInstance)) - _, err := sdk.Execute(nil, testInstance.Hash, hash.Int(1), nil, "", testService.Tasks[0].Key, map[string]interface{}{}, nil) + _, err := sdk.Execute(nil, testInstance.Hash, hash.Int(1), nil, "", testService.Tasks[0].Key, nil, nil) require.NoError(t, err) // not existing instance - _, err = sdk.Execute(nil, hash.Int(3), hash.Int(1), nil, "", testService.Tasks[0].Key, map[string]interface{}{}, nil) + _, err = sdk.Execute(nil, hash.Int(3), hash.Int(1), nil, "", testService.Tasks[0].Key, nil, nil) require.Error(t, err) } @@ -141,7 +141,7 @@ func TestExecuteInvalidTaskKey(t *testing.T) { require.NoError(t, at.serviceDB.Save(testService)) - _, err := sdk.Execute(nil, hs1, hash.Int(1), nil, "", "-", map[string]interface{}{}, nil) + _, err := sdk.Execute(nil, hs1, hash.Int(1), nil, "", "-", nil, nil) require.Error(t, err) } diff --git a/sdk/process/process.go b/sdk/process/process.go index e9d40c36f..7a9f89488 100644 --- a/sdk/process/process.go +++ b/sdk/process/process.go @@ -28,17 +28,17 @@ func (w *Process) Create(wf *process.Process) (*process.Process, error) { wf.Hash = hash.Dump(wf) for _, node := range wf.Nodes { - switch n := node.(type) { - case process.Result: - if _, err := w.instance.Get(n.InstanceHash); err != nil { + switch n := node.Type.(type) { + case *process.Process_Node_Result_: + if _, err := w.instance.Get(n.Result.InstanceHash); err != nil { return nil, err } - case process.Event: - if _, err := w.instance.Get(n.InstanceHash); err != nil { + case *process.Process_Node_Event_: + if _, err := w.instance.Get(n.Event.InstanceHash); err != nil { return nil, err } - case process.Task: - if _, err := w.instance.Get(n.InstanceHash); err != nil { + case *process.Process_Node_Task_: + if _, err := w.instance.Get(n.Task.InstanceHash); err != nil { return nil, err } } diff --git a/server/grpc/api/event.go b/server/grpc/api/event.go index fc2b1a164..fe9629a72 100644 --- a/server/grpc/api/event.go +++ b/server/grpc/api/event.go @@ -5,12 +5,8 @@ import ( "errors" "fmt" - structpb "github.com/gogo/protobuf/types" - "github.com/mesg-foundation/engine/event" "github.com/mesg-foundation/engine/protobuf/acknowledgement" "github.com/mesg-foundation/engine/protobuf/api" - "github.com/mesg-foundation/engine/protobuf/convert" - "github.com/mesg-foundation/engine/protobuf/types" "github.com/mesg-foundation/engine/sdk" eventsdk "github.com/mesg-foundation/engine/sdk/event" ) @@ -31,12 +27,7 @@ func (s *EventServer) Create(ctx context.Context, req *api.CreateEventRequest) ( return nil, errors.New("create event: key missing") } - data := make(map[string]interface{}) - if err := convert.Marshal(req.Data, &data); err != nil { - return nil, err - } - - event, err := s.sdk.Event.Create(req.InstanceHash, req.Key, data) + event, err := s.sdk.Event.Create(req.InstanceHash, req.Key, req.Data) if err != nil { return nil, fmt.Errorf("create event: data %s", err) } @@ -63,29 +54,10 @@ func (s *EventServer) Stream(req *api.StreamEventRequest, resp api.Event_StreamS } for event := range stream.C { - e, err := toProtoEvent(event) - if err != nil { - return err - } - - if err := resp.Send(e); err != nil { + if err := resp.Send(event); err != nil { return err } } return nil } - -func toProtoEvent(e *event.Event) (*types.Event, error) { - data := &structpb.Struct{} - if err := convert.Unmarshal(e.Data, data); err != nil { - return nil, err - } - - return &types.Event{ - Hash: e.Hash, - InstanceHash: e.InstanceHash, - Key: e.Key, - Data: data, - }, nil -} diff --git a/server/grpc/api/execution.go b/server/grpc/api/execution.go index 8aca99b48..0ff221911 100644 --- a/server/grpc/api/execution.go +++ b/server/grpc/api/execution.go @@ -4,13 +4,10 @@ import ( "context" "errors" - structpb "github.com/gogo/protobuf/types" "github.com/mesg-foundation/engine/execution" "github.com/mesg-foundation/engine/hash" "github.com/mesg-foundation/engine/protobuf/acknowledgement" "github.com/mesg-foundation/engine/protobuf/api" - "github.com/mesg-foundation/engine/protobuf/convert" - "github.com/mesg-foundation/engine/protobuf/types" "github.com/mesg-foundation/engine/sdk" executionsdk "github.com/mesg-foundation/engine/sdk/execution" ) @@ -30,15 +27,11 @@ func NewExecutionServer(sdk *sdk.SDK) *ExecutionServer { // Create creates an execution. func (s *ExecutionServer) Create(ctx context.Context, req *api.CreateExecutionRequest) (*api.CreateExecutionResponse, error) { - inputs := make(map[string]interface{}) - if err := convert.Marshal(req.Inputs, &inputs); err != nil { - return nil, err - } eventHash, err := hash.Random() if err != nil { return nil, err } - executionHash, err := s.sdk.Execution.Execute(nil, req.InstanceHash, eventHash, nil, "", req.TaskKey, inputs, req.Tags) + executionHash, err := s.sdk.Execution.Execute(nil, req.InstanceHash, eventHash, nil, "", req.TaskKey, req.Inputs, req.Tags) if err != nil { return nil, err } @@ -49,12 +42,8 @@ func (s *ExecutionServer) Create(ctx context.Context, req *api.CreateExecutionRe } // Get returns execution from given hash. -func (s *ExecutionServer) Get(ctx context.Context, req *api.GetExecutionRequest) (*types.Execution, error) { - exec, err := s.sdk.Execution.Get(req.Hash) - if err != nil { - return nil, err - } - return toProtoExecution(exec) +func (s *ExecutionServer) Get(ctx context.Context, req *api.GetExecutionRequest) (*execution.Execution, error) { + return s.sdk.Execution.Get(req.Hash) } // Stream returns stream of executions. @@ -62,14 +51,9 @@ func (s *ExecutionServer) Stream(req *api.StreamExecutionRequest, resp api.Execu var f *executionsdk.Filter if req.Filter != nil { - var statuses []execution.Status - for _, status := range req.Filter.Statuses { - statuses = append(statuses, execution.Status(status)) - } - f = &executionsdk.Filter{ InstanceHash: req.Filter.InstanceHash, - Statuses: statuses, + Statuses: req.Filter.Statuses, Tags: req.Filter.Tags, TaskKey: req.Filter.TaskKey, } @@ -84,12 +68,7 @@ func (s *ExecutionServer) Stream(req *api.StreamExecutionRequest, resp api.Execu } for exec := range stream.C { - e, err := toProtoExecution(exec) - if err != nil { - return err - } - - if err := resp.Send(e); err != nil { + if err := resp.Send(exec); err != nil { return err } } @@ -102,12 +81,7 @@ func (s *ExecutionServer) Update(ctx context.Context, req *api.UpdateExecutionRe var err error switch res := req.Result.(type) { case *api.UpdateExecutionRequest_Outputs: - outputs := make(map[string]interface{}) - if err := convert.Marshal(res.Outputs, &outputs); err != nil { - return nil, err - } - - err = s.sdk.Execution.Update(req.Hash, outputs, nil) + err = s.sdk.Execution.Update(req.Hash, res.Outputs, nil) case *api.UpdateExecutionRequest_Error: err = s.sdk.Execution.Update(req.Hash, nil, errors.New(res.Error)) default: @@ -120,30 +94,3 @@ func (s *ExecutionServer) Update(ctx context.Context, req *api.UpdateExecutionRe return &api.UpdateExecutionResponse{}, nil } - -func toProtoExecution(exec *execution.Execution) (*types.Execution, error) { - inputs := &structpb.Struct{} - if err := convert.Unmarshal(exec.Inputs, inputs); err != nil { - return nil, err - } - - outputs := &structpb.Struct{} - if err := convert.Unmarshal(exec.Outputs, outputs); err != nil { - return nil, err - } - - return &types.Execution{ - Hash: exec.Hash, - ProcessHash: exec.ProcessHash, - ParentHash: exec.ParentHash, - EventHash: exec.EventHash, - Status: types.Status(exec.Status), - InstanceHash: exec.InstanceHash, - TaskKey: exec.TaskKey, - Inputs: inputs, - Outputs: outputs, - Tags: exec.Tags, - Error: exec.Error, - StepID: exec.StepID, - }, nil -} diff --git a/server/grpc/api/execution_test.go b/server/grpc/api/execution_test.go index a8a7c64fd..5a1e9c4f9 100644 --- a/server/grpc/api/execution_test.go +++ b/server/grpc/api/execution_test.go @@ -23,15 +23,12 @@ func TestGet(t *testing.T) { exec := execution.New(nil, nil, nil, nil, "", "", nil, nil) require.NoError(t, db.Save(exec)) - want, err := toProtoExecution(exec) - require.NoError(t, err) - sdk := sdk.NewDeprecated(nil, nil, nil, db, nil, "", "") s := NewExecutionServer(sdk) got, err := s.Get(context.Background(), &api.GetExecutionRequest{Hash: exec.Hash}) require.NoError(t, err) - require.Equal(t, got, want) + require.Equal(t, got, exec) } func TestUpdate(t *testing.T) { diff --git a/server/grpc/api/process.go b/server/grpc/api/process.go index 91339fc18..f586e8fa3 100644 --- a/server/grpc/api/process.go +++ b/server/grpc/api/process.go @@ -2,12 +2,9 @@ package api import ( "context" - "fmt" - "github.com/mesg-foundation/engine/filter" "github.com/mesg-foundation/engine/process" "github.com/mesg-foundation/engine/protobuf/api" - "github.com/mesg-foundation/engine/protobuf/types" "github.com/mesg-foundation/engine/sdk" ) @@ -23,7 +20,7 @@ func NewProcessServer(sdk *sdk.SDK) *ProcessServer { // Create creates a new service from definition. func (s *ProcessServer) Create(ctx context.Context, req *api.CreateProcessRequest) (*api.CreateProcessResponse, error) { - wf, err := fromProtoProcess(&types.Process{ + wf, err := s.sdk.Process.Create(&process.Process{ Key: req.Key, Nodes: req.Nodes, Edges: req.Edges, @@ -31,10 +28,6 @@ func (s *ProcessServer) Create(ctx context.Context, req *api.CreateProcessReques if err != nil { return nil, err } - wf, err = s.sdk.Process.Create(wf) - if err != nil { - return nil, err - } return &api.CreateProcessResponse{Hash: wf.Hash}, nil } @@ -44,12 +37,8 @@ func (s *ProcessServer) Delete(ctx context.Context, request *api.DeleteProcessRe } // Get returns service from given hash. -func (s *ProcessServer) Get(ctx context.Context, req *api.GetProcessRequest) (*types.Process, error) { - wf, err := s.sdk.Process.Get(req.Hash) - if err != nil { - return nil, err - } - return toProtoProcess(wf), nil +func (s *ProcessServer) Get(ctx context.Context, req *api.GetProcessRequest) (*process.Process, error) { + return s.sdk.Process.Get(req.Hash) } // List returns all processes. @@ -58,179 +47,7 @@ func (s *ProcessServer) List(ctx context.Context, req *api.ListProcessRequest) ( if err != nil { return nil, err } - wfs := toProtoProcesses(processes) return &api.ListProcessResponse{ - Processes: wfs, - }, nil -} - -func fromProtoProcessNodes(nodes []*types.Process_Node) ([]process.Node, error) { - res := make([]process.Node, len(nodes)) - for i, node := range nodes { - switch n := node.Type.(type) { - case *types.Process_Node_Event_: - res[i] = process.Event{Key: n.Event.Key, InstanceHash: n.Event.InstanceHash, EventKey: n.Event.EventKey} - case *types.Process_Node_Result_: - res[i] = process.Result{Key: n.Result.Key, InstanceHash: n.Result.InstanceHash, TaskKey: n.Result.TaskKey} - case *types.Process_Node_Task_: - res[i] = process.Task{InstanceHash: n.Task.InstanceHash, TaskKey: n.Task.TaskKey, Key: n.Task.Key} - case *types.Process_Node_Map_: - outputs := make([]process.Output, len(n.Map.Outputs)) - for j, output := range n.Map.Outputs { - out := process.Output{Key: output.Key} - switch x := output.Value.(type) { - case *types.Process_Node_Map_Output_Ref: - out.Ref = &process.OutputReference{ - NodeKey: output.GetRef().NodeKey, - Key: output.GetRef().Key, - } - default: - return nil, fmt.Errorf("output has unexpected type %T", x) - } - outputs[j] = out - } - res[i] = process.Map{Key: n.Map.Key, Outputs: outputs} - case *types.Process_Node_Filter_: - conditions := make([]filter.Condition, len(n.Filter.Conditions)) - for j, condition := range n.Filter.Conditions { - cond := filter.Condition{Key: condition.Key, Value: condition.Value} - switch condition.Predicate { - case types.Process_Node_Filter_Condition_EQ: - cond.Predicate = filter.EQ - default: - return nil, fmt.Errorf("predicate %q not supported", condition.Predicate) - } - conditions[j] = cond - } - res[i] = process.Filter{Key: n.Filter.Key, Filter: filter.Filter{Conditions: conditions}} - default: - return nil, fmt.Errorf("node has unexpected type %T", n) - } - } - return res, nil -} - -func fromProtoProcessEdges(edges []*types.Process_Edge) []process.Edge { - res := make([]process.Edge, len(edges)) - for i, edge := range edges { - res[i] = process.Edge{ - Src: edge.Src, - Dst: edge.Dst, - } - } - return res -} - -func fromProtoProcess(wf *types.Process) (*process.Process, error) { - nodes, err := fromProtoProcessNodes(wf.Nodes) - if err != nil { - return nil, err - } - return &process.Process{ - Key: wf.Key, - Graph: process.Graph{ - Nodes: nodes, - Edges: fromProtoProcessEdges(wf.Edges), - }, + Processes: processes, }, nil } - -func toProtoProcessNodes(nodes []process.Node) []*types.Process_Node { - res := make([]*types.Process_Node, len(nodes)) - for i, node := range nodes { - protoNode := types.Process_Node{} - switch n := node.(type) { - case *process.Result: - protoNode.Type = &types.Process_Node_Result_{ - Result: &types.Process_Node_Result{ - Key: n.Key, - InstanceHash: n.InstanceHash, - TaskKey: n.TaskKey, - }, - } - case *process.Event: - protoNode.Type = &types.Process_Node_Event_{ - Event: &types.Process_Node_Event{ - Key: n.Key, - InstanceHash: n.InstanceHash, - EventKey: n.EventKey, - }, - } - case *process.Task: - protoNode.Type = &types.Process_Node_Task_{ - Task: &types.Process_Node_Task{ - Key: n.Key, - InstanceHash: n.InstanceHash, - TaskKey: n.TaskKey, - }, - } - case *process.Map: - outputs := make([]*types.Process_Node_Map_Output, len(n.Outputs)) - for j, output := range n.Outputs { - out := &types.Process_Node_Map_Output{Key: output.Key} - if output.Ref != nil { - out.Value = &types.Process_Node_Map_Output_Ref{ - Ref: &types.Process_Node_Map_Output_Reference{ - NodeKey: output.Ref.NodeKey, - Key: output.Ref.Key, - }, - } - } - outputs[j] = out - } - - protoNode.Type = &types.Process_Node_Map_{ - Map: &types.Process_Node_Map{ - Key: n.Key, - Outputs: outputs, - }, - } - case *process.Filter: - conditions := make([]*types.Process_Node_Filter_Condition, len(n.Conditions)) - for j, condition := range n.Conditions { - cond := &types.Process_Node_Filter_Condition{Key: condition.Key, Value: condition.Value} - if condition.Predicate == filter.EQ { - cond.Predicate = types.Process_Node_Filter_Condition_EQ - } - conditions[j] = cond - } - - protoNode.Type = &types.Process_Node_Filter_{ - Filter: &types.Process_Node_Filter{ - Key: n.Key, - Conditions: conditions, - }, - } - } - res[i] = &protoNode - } - return res -} - -func toProtoProcessEdges(edges []process.Edge) []*types.Process_Edge { - res := make([]*types.Process_Edge, len(edges)) - for i, edge := range edges { - res[i] = &types.Process_Edge{ - Src: edge.Src, - Dst: edge.Dst, - } - } - return res -} - -func toProtoProcess(wf *process.Process) *types.Process { - return &types.Process{ - Hash: wf.Hash, - Key: wf.Key, - Nodes: toProtoProcessNodes(wf.Nodes), - Edges: toProtoProcessEdges(wf.Edges), - } -} - -func toProtoProcesses(processes []*process.Process) []*types.Process { - wfs := make([]*types.Process, len(processes)) - for i, wf := range processes { - wfs[i] = toProtoProcess(wf) - } - return wfs -} diff --git a/service/service.go b/service/service.go index 7c747266a..3effd5b52 100644 --- a/service/service.go +++ b/service/service.go @@ -2,6 +2,9 @@ package service import ( "fmt" + + "github.com/gogo/protobuf/types" + "github.com/mesg-foundation/engine/protobuf/convert" ) // MainServiceKey is key for main service. @@ -71,8 +74,14 @@ func (s *Service) ValidateEventData(eventKey string, eventData map[string]interf } // RequireTaskInputs requires task inputs to match with parameter schemas. -func (s *Service) RequireTaskInputs(taskKey string, taskInputs map[string]interface{}) error { - warnings, err := s.ValidateTaskInputs(taskKey, taskInputs) +func (s *Service) RequireTaskInputs(taskKey string, taskInputs *types.Struct) error { + in := make(map[string]interface{}) + if taskInputs != nil { + if err := convert.Marshal(taskInputs, &in); err != nil { + return err + } + } + warnings, err := s.ValidateTaskInputs(taskKey, in) if err != nil { return err } @@ -87,8 +96,15 @@ func (s *Service) RequireTaskInputs(taskKey string, taskInputs map[string]interf } // RequireTaskOutputs requires task outputs to match with parameter schemas. -func (s *Service) RequireTaskOutputs(taskKey string, taskOutputs map[string]interface{}) error { - warnings, err := s.ValidateTaskOutputs(taskKey, taskOutputs) +func (s *Service) RequireTaskOutputs(taskKey string, taskOutputs *types.Struct) error { + out := make(map[string]interface{}) + if taskOutputs != nil { + if err := convert.Marshal(taskOutputs, &out); err != nil { + return err + } + } + + warnings, err := s.ValidateTaskOutputs(taskKey, out) if err != nil { return err } @@ -103,8 +119,15 @@ func (s *Service) RequireTaskOutputs(taskKey string, taskOutputs map[string]inte } // RequireEventData requires event datas to be matched with parameter schemas. -func (s *Service) RequireEventData(eventKey string, eventData map[string]interface{}) error { - warnings, err := s.ValidateEventData(eventKey, eventData) +func (s *Service) RequireEventData(eventKey string, eventData *types.Struct) error { + data := make(map[string]interface{}) + if eventData != nil { + if err := convert.Marshal(eventData, &data); err != nil { + return err + } + } + + warnings, err := s.ValidateEventData(eventKey, data) if err != nil { return err } diff --git a/service/service.pb.go b/service/service.pb.go index 8fc08bbbd..a1836a9f4 100644 --- a/service/service.pb.go +++ b/service/service.pb.go @@ -25,25 +25,25 @@ const _ = proto.GoGoProtoPackageIsVersion2 // please upgrade the proto package // Service represents the service's type. type Service struct { // Service's hash. - Hash github_com_mesg_foundation_engine_hash.Hash `protobuf:"bytes,10,opt,name=hash,proto3,customtype=github.com/mesg-foundation/engine/hash.Hash" json:"hash" validate:"required"` + Hash github_com_mesg_foundation_engine_hash.Hash `protobuf:"bytes,10,opt,name=hash,proto3,customtype=github.com/mesg-foundation/engine/hash.Hash" json:"hash" hash:"-" validate:"required"` // Service's sid. - Sid string `protobuf:"bytes,12,opt,name=sid,proto3" json:"sid,omitempty" validate:"required,printascii,max=63,domain"` + Sid string `protobuf:"bytes,12,opt,name=sid,proto3" json:"sid,omitempty" hash:"name:12" validate:"required,printascii,max=63,domain"` // Service's name. - Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty" hash:"name:2" validate:"required,printascii"` + Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty" hash:"name:1" validate:"required,printascii"` // Service's description. - Description string `protobuf:"bytes,2,opt,name=description,proto3" json:"description,omitempty" hash:"name:3" validate:"printascii"` + Description string `protobuf:"bytes,2,opt,name=description,proto3" json:"description,omitempty" hash:"name:2" validate:"printascii"` // Configurations related to the service Configuration Service_Configuration `protobuf:"bytes,8,opt,name=configuration,proto3" json:"configuration" hash:"name:8" validate:"required"` // The list of tasks this service can execute. - Tasks []*Service_Task `protobuf:"bytes,5,rep,name=tasks,proto3" json:"tasks,omitempty" hash:"name:4" validate:"dive,required"` + Tasks []*Service_Task `protobuf:"bytes,5,rep,name=tasks,proto3" json:"tasks,omitempty" hash:"name:5" validate:"dive,required"` // The list of events this service can emit. - Events []*Service_Event `protobuf:"bytes,6,rep,name=events,proto3" json:"events,omitempty" hash:"name:5" validate:"dive,required"` + Events []*Service_Event `protobuf:"bytes,6,rep,name=events,proto3" json:"events,omitempty" hash:"name:6" validate:"dive,required"` // The container dependencies this service requires. - Dependencies []*Service_Dependency `protobuf:"bytes,7,rep,name=dependencies,proto3" json:"dependencies,omitempty" hash:"name:6" validate:"dive,required"` + Dependencies []*Service_Dependency `protobuf:"bytes,7,rep,name=dependencies,proto3" json:"dependencies,omitempty" hash:"name:7" validate:"dive,required"` // Service's repository url. - Repository string `protobuf:"bytes,9,opt,name=repository,proto3" json:"repository,omitempty" hash:"name:7" validate:"omitempty,uri"` + Repository string `protobuf:"bytes,9,opt,name=repository,proto3" json:"repository,omitempty" hash:"name:9" validate:"omitempty,uri"` // The hash id of service's source code on IPFS. - Source string `protobuf:"bytes,13,opt,name=source,proto3" json:"source,omitempty" hash:"name:9" validate:"required,printascii"` + Source string `protobuf:"bytes,13,opt,name=source,proto3" json:"source,omitempty" hash:"name:13" validate:"required,printascii"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -76,13 +76,13 @@ var xxx_messageInfo_Service proto.InternalMessageInfo // Events are emitted by the service whenever the service wants. type Service_Event struct { // Event's key. - Key string `protobuf:"bytes,4,opt,name=key,proto3" json:"key,omitempty" hash:"name:1" validate:"printascii"` + Key string `protobuf:"bytes,4,opt,name=key,proto3" json:"key,omitempty" hash:"name:4" validate:"printascii"` // Event's name. - Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty" hash:"name:2" validate:"printascii"` + Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty" hash:"name:1" validate:"printascii"` // Event's description. - Description string `protobuf:"bytes,2,opt,name=description,proto3" json:"description,omitempty" hash:"name:3" validate:"printascii"` + Description string `protobuf:"bytes,2,opt,name=description,proto3" json:"description,omitempty" hash:"name:2" validate:"printascii"` // List of data of this event. - Data []*Service_Parameter `protobuf:"bytes,3,rep,name=data,proto3" json:"data,omitempty" hash:"name:4" validate:"dive,required"` + Data []*Service_Parameter `protobuf:"bytes,3,rep,name=data,proto3" json:"data,omitempty" hash:"name:3" validate:"dive,required"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -115,15 +115,15 @@ var xxx_messageInfo_Service_Event proto.InternalMessageInfo // Task is a function that requires inputs and returns output. type Service_Task struct { // Task's key. - Key string `protobuf:"bytes,8,opt,name=key,proto3" json:"key,omitempty" hash:"name:1" validate:"printascii"` + Key string `protobuf:"bytes,8,opt,name=key,proto3" json:"key,omitempty" hash:"name:8" validate:"printascii"` // Task's name. - Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty" hash:"name:2" validate:"printascii"` + Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty" hash:"name:1" validate:"printascii"` // Task's description. - Description string `protobuf:"bytes,2,opt,name=description,proto3" json:"description,omitempty" hash:"name:3" validate:"printascii"` + Description string `protobuf:"bytes,2,opt,name=description,proto3" json:"description,omitempty" hash:"name:2" validate:"printascii"` // List inputs of this task. - Inputs []*Service_Parameter `protobuf:"bytes,6,rep,name=inputs,proto3" json:"inputs,omitempty" hash:"name:4" validate:"dive,required"` + Inputs []*Service_Parameter `protobuf:"bytes,6,rep,name=inputs,proto3" json:"inputs,omitempty" hash:"name:6" validate:"dive,required"` // List of tasks outputs. - Outputs []*Service_Parameter `protobuf:"bytes,7,rep,name=outputs,proto3" json:"outputs,omitempty" hash:"name:5" validate:"dive,required"` + Outputs []*Service_Parameter `protobuf:"bytes,7,rep,name=outputs,proto3" json:"outputs,omitempty" hash:"name:7" validate:"dive,required"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -156,19 +156,19 @@ var xxx_messageInfo_Service_Task proto.InternalMessageInfo // Parameter describes the task's inputs, the task's outputs, and the event's data. type Service_Parameter struct { // Parameter's key. - Key string `protobuf:"bytes,8,opt,name=key,proto3" json:"key,omitempty" hash:"name:1" validate:"printascii"` + Key string `protobuf:"bytes,8,opt,name=key,proto3" json:"key,omitempty" hash:"name:8" validate:"printascii"` // Parameter's name. - Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty" hash:"name:2" validate:"printascii"` + Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty" hash:"name:1" validate:"printascii"` // Parameter's description. - Description string `protobuf:"bytes,2,opt,name=description,proto3" json:"description,omitempty" hash:"name:3" validate:"printascii"` + Description string `protobuf:"bytes,2,opt,name=description,proto3" json:"description,omitempty" hash:"name:2" validate:"printascii"` // Parameter's type: `String`, `Number`, `Boolean`, `Object` or `Any`. - Type string `protobuf:"bytes,3,opt,name=type,proto3" json:"type,omitempty" hash:"name:4" validate:"required,printascii,oneof=String Number Boolean Object Any"` + Type string `protobuf:"bytes,3,opt,name=type,proto3" json:"type,omitempty" hash:"name:3" validate:"required,printascii,oneof=String Number Boolean Object Any"` // Set the parameter as optional. - Optional bool `protobuf:"varint,4,opt,name=optional,proto3" json:"optional,omitempty" hash:"name:5"` + Optional bool `protobuf:"varint,4,opt,name=optional,proto3" json:"optional,omitempty" hash:"name:4"` // Mark a parameter as an array of the defined type. - Repeated bool `protobuf:"varint,9,opt,name=repeated,proto3" json:"repeated,omitempty" hash:"name:7"` + Repeated bool `protobuf:"varint,9,opt,name=repeated,proto3" json:"repeated,omitempty" hash:"name:9"` // Optional object structure type when type is set to `Object`. - Object []*Service_Parameter `protobuf:"bytes,10,rep,name=object,proto3" json:"object,omitempty" hash:"name:7" validate:"unique,dive,required"` + Object []*Service_Parameter `protobuf:"bytes,10,rep,name=object,proto3" json:"object,omitempty" hash:"name:10" validate:"unique,dive,required"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -244,21 +244,21 @@ var xxx_messageInfo_Service_Configuration proto.InternalMessageInfo // A dependency is a configuration of an other container that runs separately from the service. type Service_Dependency struct { // Dependency's key. - Key string `protobuf:"bytes,8,opt,name=key,proto3" json:"key,omitempty" hash:"name:1" validate:"printascii"` + Key string `protobuf:"bytes,8,opt,name=key,proto3" json:"key,omitempty" hash:"name:8" validate:"printascii"` // Image's name of the container. - Image string `protobuf:"bytes,1,opt,name=image,proto3" json:"image,omitempty" hash:"name:2" validate:"printascii"` + Image string `protobuf:"bytes,1,opt,name=image,proto3" json:"image,omitempty" hash:"name:1" validate:"printascii"` // List of volumes. - Volumes []string `protobuf:"bytes,2,rep,name=volumes,proto3" json:"volumes,omitempty" hash:"name:3" validate:"unique,dive,printascii"` + Volumes []string `protobuf:"bytes,2,rep,name=volumes,proto3" json:"volumes,omitempty" hash:"name:2" validate:"unique,dive,printascii"` // List of volumes mounted from other dependencies. - VolumesFrom []string `protobuf:"bytes,3,rep,name=volumesFrom,proto3" json:"volumesFrom,omitempty" hash:"name:4" validate:"unique,dive,printascii"` + VolumesFrom []string `protobuf:"bytes,3,rep,name=volumesFrom,proto3" json:"volumesFrom,omitempty" hash:"name:3" validate:"unique,dive,printascii"` // List of ports the container exposes. - Ports []string `protobuf:"bytes,4,rep,name=ports,proto3" json:"ports,omitempty" hash:"name:5" validate:"unique,dive,portmap"` + Ports []string `protobuf:"bytes,4,rep,name=ports,proto3" json:"ports,omitempty" hash:"name:4" validate:"unique,dive,portmap"` // Args to pass to the container. Args []string `protobuf:"bytes,6,rep,name=args,proto3" json:"args,omitempty" hash:"name:6" validate:"dive,printascii"` // Command to run the container. - Command string `protobuf:"bytes,5,opt,name=command,proto3" json:"command,omitempty" hash:"name:7" validate:"printascii"` + Command string `protobuf:"bytes,5,opt,name=command,proto3" json:"command,omitempty" hash:"name:5" validate:"printascii"` // Default env vars to apply to service's instance on runtime. - Env []string `protobuf:"bytes,9,rep,name=env,proto3" json:"env,omitempty" hash:"name:8" validate:"unique,dive,env"` + Env []string `protobuf:"bytes,9,rep,name=env,proto3" json:"env,omitempty" hash:"name:9" validate:"unique,dive,env"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -300,63 +300,64 @@ func init() { func init() { proto.RegisterFile("service.proto", fileDescriptor_a0b84a42fa06f626) } var fileDescriptor_a0b84a42fa06f626 = []byte{ - // 916 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xdc, 0x97, 0xdf, 0x8e, 0xdb, 0x44, - 0x14, 0xc6, 0x9b, 0xb5, 0x93, 0x6c, 0x66, 0x37, 0x17, 0x4c, 0xb9, 0x18, 0x22, 0x84, 0x8d, 0x91, - 0x20, 0x85, 0x6c, 0x42, 0x93, 0xed, 0x6e, 0xbb, 0x68, 0x11, 0x35, 0xa5, 0x2a, 0x95, 0xf8, 0x23, - 0x2f, 0x15, 0x15, 0x42, 0x95, 0x26, 0xf6, 0xac, 0x77, 0xd8, 0xf5, 0x8c, 0x3b, 0x33, 0x8e, 0xc8, - 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d, 0x92, 0x39, - 0x34, 0x7c, 0x0c, 0x80, 0x20, 0x31, 0x97, 0x54, 0x71, 0x31, 0x46, 0x0d, 0xdd, 0xd4, 0x45, 0xda, - 0x7e, 0x91, 0xc6, 0x23, 0xaa, 0x48, 0x14, 0xab, 0x71, 0x27, 0x11, 0xd4, 0xf1, 0x0a, 0x6a, 0xf8, - 0x08, 0xd4, 0x24, 0x4f, 0x84, 0x4f, 0x50, 0xb3, 0xd4, 0x69, 0xf7, 0x2e, 0x75, 0xda, 0x54, 0xdf, - 0xfa, 0x63, 0x03, 0x54, 0x75, 0xf9, 0xe0, 0x3d, 0x60, 0x9c, 0x92, 0x31, 0x32, 0x4b, 0xdd, 0x76, - 0x7b, 0x95, 0xdb, 0x72, 0x0d, 0xfc, 0x6c, 0xce, 0xf6, 0x8b, 0xda, 0xfe, 0x2a, 0xed, 0x6b, 0x77, - 0xfb, 0x53, 0x60, 0x06, 0x58, 0x61, 0x64, 0xe8, 0x2e, 0xa2, 0x85, 0x2e, 0x7e, 0x8f, 0x05, 0x8e, - 0x88, 0x22, 0xe2, 0x5a, 0x16, 0xd4, 0xc4, 0xd6, 0x6f, 0x06, 0x30, 0x73, 0xf7, 0xce, 0xaa, 0xb4, - 0xf9, 0x3f, 0xae, 0xd2, 0xcf, 0xa0, 0x46, 0x59, 0x9c, 0x9c, 0x4f, 0xd3, 0xeb, 0xa9, 0xd3, 0x94, - 0x09, 0x9f, 0x81, 0x3a, 0x4f, 0x94, 0xc6, 0xd7, 0xaf, 0x89, 0x5f, 0x37, 0xb0, 0x33, 0x68, 0xeb, - 0x5f, 0x03, 0x34, 0xce, 0x11, 0x6f, 0x42, 0x3b, 0x4e, 0x81, 0x99, 0x17, 0x08, 0x19, 0x9a, 0xf1, - 0x63, 0x96, 0x5a, 0x47, 0xab, 0x4a, 0x5e, 0x76, 0x0c, 0x71, 0x46, 0xf8, 0xf1, 0xe1, 0x91, 0x12, - 0x94, 0x85, 0xf6, 0xb7, 0x49, 0x34, 0x24, 0xc2, 0x76, 0x39, 0x3f, 0x23, 0x98, 0xd9, 0xdf, 0x0d, - 0x7f, 0x21, 0xbe, 0xb2, 0xef, 0xb3, 0xb1, 0xe3, 0xe9, 0x24, 0x70, 0x07, 0x6c, 0x72, 0x9d, 0x16, - 0x9f, 0xe9, 0x49, 0xdf, 0x74, 0xdf, 0xca, 0x52, 0xab, 0x39, 0xd7, 0x04, 0xef, 0x3c, 0x24, 0x0f, - 0x17, 0x24, 0x26, 0x58, 0x91, 0x40, 0xef, 0x58, 0xcb, 0xe1, 0xfb, 0x8e, 0x77, 0x1e, 0x02, 0x7d, - 0x50, 0xe3, 0x3a, 0x25, 0x02, 0x97, 0xb4, 0xfe, 0x76, 0x96, 0x5a, 0x3b, 0xab, 0x36, 0xbe, 0x84, - 0xd1, 0xe7, 0x09, 0xe9, 0x2c, 0x1a, 0x6c, 0x82, 0x6e, 0xfd, 0x65, 0x80, 0xe6, 0xdc, 0x79, 0x05, - 0xbf, 0x01, 0xf5, 0x11, 0x3f, 0x4b, 0x22, 0x22, 0x51, 0xc5, 0x36, 0xda, 0x0d, 0x77, 0x90, 0xa5, - 0x56, 0x6f, 0x95, 0x11, 0x8a, 0xf4, 0x62, 0x53, 0x66, 0x0c, 0xf8, 0x04, 0x6c, 0x4d, 0x2f, 0x1f, - 0x0a, 0x1e, 0xa1, 0x8d, 0x52, 0x64, 0xff, 0x2a, 0xc8, 0x22, 0x07, 0x3e, 0x04, 0xd5, 0x98, 0x0b, - 0x25, 0xf5, 0xee, 0xb4, 0xbc, 0x65, 0x0f, 0x56, 0x02, 0xb9, 0x50, 0x11, 0x8e, 0x1d, 0x6f, 0x22, - 0x87, 0x5f, 0x00, 0x13, 0x8b, 0x50, 0x22, 0x53, 0x63, 0x3a, 0x59, 0x6a, 0xb5, 0xd7, 0xce, 0xd0, - 0x9c, 0x79, 0x73, 0x25, 0xbc, 0x0f, 0xea, 0x3e, 0x8f, 0x22, 0xcc, 0x02, 0x54, 0x2d, 0x35, 0xee, - 0xee, 0x2a, 0xe3, 0xce, 0x74, 0xf0, 0x73, 0x60, 0x10, 0x36, 0xd2, 0x1b, 0xc8, 0xf2, 0x1a, 0xf6, - 0x56, 0xbd, 0x0a, 0x61, 0x23, 0xc7, 0xcb, 0x85, 0xad, 0x3f, 0x4d, 0x00, 0x2e, 0x4e, 0xd5, 0x57, - 0x19, 0xe3, 0x43, 0x50, 0xa5, 0x11, 0x0e, 0xaf, 0x3d, 0xc7, 0x13, 0x55, 0xd1, 0x3b, 0xe5, 0x8d, - 0x1e, 0xbc, 0x8a, 0x77, 0x8c, 0x52, 0xe4, 0xee, 0xcb, 0x7b, 0xc7, 0x2c, 0xf5, 0xce, 0x9d, 0xeb, - 0x7a, 0xe7, 0x0a, 0x7d, 0x7b, 0x59, 0xef, 0xec, 0x5f, 0xd5, 0x3b, 0x8d, 0xd2, 0x35, 0xdc, 0xbd, - 0xd4, 0x3b, 0x6e, 0xef, 0xc5, 0x3f, 0xef, 0xdd, 0xf8, 0xe9, 0xd6, 0xe5, 0x7f, 0xfc, 0xa7, 0x9f, - 0x1d, 0xc3, 0x9a, 0xfe, 0x98, 0x18, 0xfc, 0x17, 0x00, 0x00, 0xff, 0xff, 0x79, 0x9b, 0xfc, 0x96, - 0x88, 0x0c, 0x00, 0x00, + // 937 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xdc, 0x97, 0xdf, 0x72, 0xdb, 0x44, + 0x14, 0xc6, 0xeb, 0x48, 0xb6, 0xe3, 0x4d, 0x7c, 0xc1, 0xc2, 0xc5, 0xe2, 0xe9, 0x20, 0x21, 0x66, + 0xc0, 0x05, 0xc7, 0x6e, 0xec, 0x36, 0x34, 0xe9, 0x04, 0xa8, 0x29, 0x1d, 0xca, 0x0c, 0xff, 0x14, + 0x3a, 0x74, 0x18, 0x86, 0x99, 0xb5, 0xb4, 0x51, 0x96, 0x44, 0xbb, 0xea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 0xf3, 0xdf, 0x9c, 0xe3, 0x3f, 0x9c, 0x86, + 0x8c, 0x16, 0x92, 0x7c, 0xb8, 0x22, 0xc9, 0x0c, 0x1a, 0x7e, 0x01, 0x80, 0x20, 0x11, 0x97, 0x54, + 0x71, 0x31, 0x42, 0x35, 0xdd, 0xd4, 0x79, 0xda, 0x61, 0x9e, 0xc6, 0x43, 0xaa, 0x48, 0x18, 0xa9, + 0x51, 0x2b, 0x16, 0xd4, 0x71, 0x73, 0x6a, 0xf8, 0x18, 0x54, 0x24, 0x8f, 0x85, 0x47, 0x50, 0x5d, + 0x73, 0xf6, 0xd3, 0xc4, 0xda, 0xcb, 0x3b, 0xad, 0xb7, 0xd6, 0x6a, 0x13, 0x40, 0xe3, 0xb7, 0x2d, + 0x50, 0xd6, 0xf5, 0x83, 0x87, 0xc0, 0x38, 0x27, 0x23, 0x64, 0x16, 0xda, 0xed, 0xce, 0x32, 0xbb, + 0x65, 0x1a, 0x78, 0x7f, 0xc6, 0xf7, 0xf3, 0xda, 0xfd, 0x65, 0xda, 0xff, 0xdc, 0xee, 0x4f, 0x81, + 0xe9, 0x63, 0x85, 0x91, 0xa1, 0xdb, 0x88, 0xe6, 0xda, 0xf8, 0x0d, 0x16, 0x38, 0x24, 0x8a, 0x88, + 0x85, 0xba, 0xf7, 0x56, 0x74, 0x51, 0x13, 0x1b, 0xbf, 0x1a, 0xc0, 0xcc, 0xec, 0x3b, 0xad, 0xd2, + 0x76, 0xe1, 0x2a, 0xef, 0xfd, 0x2f, 0xaa, 0xf4, 0x23, 0xa8, 0x50, 0x16, 0xc5, 0x97, 0xe3, 0x74, + 0xf5, 0x3a, 0xad, 0x1c, 0xa9, 0x31, 0x13, 0xfe, 0x04, 0xaa, 0x3c, 0x56, 0x1a, 0x5f, 0xdd, 0x10, + 0xbf, 0x6a, 0x98, 0xa6, 0xd0, 0xc6, 0x3f, 0x06, 0xa8, 0x5d, 0x22, 0x5e, 0x85, 0x76, 0x9c, 0x03, + 0x33,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b8, 0x63, 0x39, 0xfc, 0x04, 0x98, 0x58, 0x04, 0x12, + 0x99, 0x1a, 0xd3, 0x4a, 0x13, 0xab, 0xb9, 0xf2, 0x3c, 0x9d, 0x71, 0x6f, 0xa6, 0x84, 0x0f, 0x40, + 0xd5, 0xe3, 0x61, 0x88, 0x99, 0x8f, 0xca, 0x9b, 0x6d, 0xf7, 0x53, 0x1d, 0xfc, 0x08, 0x18, 0x84, + 0x0d, 0xf5, 0x0e, 0xb2, 0xb8, 0x86, 0x83, 0x65, 0x9f, 0x42, 0xd8, 0xd0, 0x71, 0x33, 0x61, 0xe3, + 0x0f, 0x13, 0x80, 0x17, 0xe7, 0xea, 0x75, 0xe6, 0xf8, 0x18, 0x94, 0x69, 0x88, 0x83, 0x8d, 0x07, + 0x79, 0xac, 0xca, 0x7b, 0xe7, 0x1a, 0x8d, 0x5e, 0xe6, 0x1d, 0xa3, 0x10, 0xd9, 0x7b, 0x79, 0xef, + 0x98, 0x85, 0xde, 0xb9, 0xb3, 0xa9, 0x77, 0xae, 0xd0, 0xb7, 0x97, 0xf5, 0xce, 0xdd, 0xab, 0x7a, + 0xa7, 0x56, 0xb8, 0x86, 0xc3, 0xb5, 0xde, 0xe9, 0x77, 0x9e, 0xff, 0xfd, 0xd6, 0x8d, 0x1f, 0x6e, + 0xad, 0xbf, 0x12, 0x4c, 0x2e, 0x24, 0x83, 0x8a, 0xbe, 0x66, 0xf4, 0xfe, 0x0d, 0x00, 0x00, 0xff, + 0xff, 0xfc, 0xd1, 0x89, 0xeb, 0xa2, 0x0c, 0x00, 0x00, } diff --git a/service/service_test.go b/service/service_test.go index 61afc7b98..fe802c568 100644 --- a/service/service_test.go +++ b/service/service_test.go @@ -3,6 +3,8 @@ package service import ( "testing" + "github.com/gogo/protobuf/types" + "github.com/mesg-foundation/engine/protobuf/convert" "github.com/stretchr/testify/require" ) @@ -72,7 +74,11 @@ func TestEventValidateAndRequireData(t *testing.T) { require.NoError(t, err) require.Len(t, warnings, 0) - err = s.RequireEventData(eventKey, validEventData) + data := &types.Struct{} + convert.Unmarshal(validEventData, data) + require.NoError(t, err) + + err = s.RequireEventData(eventKey, data) require.NoError(t, err) warnings, err = s.ValidateEventData(eventKey, inValidEventData) @@ -80,7 +86,10 @@ func TestEventValidateAndRequireData(t *testing.T) { require.Len(t, warnings, 1) require.Equal(t, paramKey, warnings[0].Key) - err = s.RequireEventData(eventKey, inValidEventData) + convert.Unmarshal(inValidEventData, data) + require.NoError(t, err) + + err = s.RequireEventData(eventKey, data) require.Equal(t, &InvalidEventDataError{ EventKey: eventKey, ServiceName: serviceName,