diff --git a/go.mod b/go.mod index 2176a67e9..c8edf877a 100644 --- a/go.mod +++ b/go.mod @@ -7,17 +7,17 @@ require ( github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5 // indirect github.com/alcortesm/tgz v0.0.0-20161220082320-9c5fe88206d7 // indirect github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239 // indirect - github.com/briandowns/spinner v0.0.0-20180822135157-9f016caa1359 + github.com/briandowns/spinner v0.0.0-20180822135157-9f016caa1359 // indirect github.com/cnf/structhash v0.0.0-20180104161610-62a607eb0224 github.com/containerd/continuity v0.0.0-20180712174259-0377f7d76720 // indirect github.com/cskr/pubsub v1.0.2 - github.com/docker/cli v0.0.0-20190129171106-b258f458cc8d + github.com/docker/cli v0.0.0-20190129171106-b258f458cc8d // indirect github.com/docker/distribution v0.0.0-20180720172123-0dae0957e5fe // indirect github.com/docker/docker v0.0.0-20180803200506-eeea12db7a65 github.com/docker/go-connections v0.0.0-20180212134524-7beb39f0b969 // indirect github.com/docker/go-units v0.3.3 // indirect github.com/emirpasic/gods v0.0.0-20180618112450-bba54c718c4e // indirect - github.com/fatih/color v0.0.0-20170926111411-5df930a27be2 + github.com/fatih/color v0.0.0-20170926111411-5df930a27be2 // indirect github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568 // indirect github.com/gliderlabs/ssh v0.1.1 // indirect github.com/go-bindata/go-bindata v0.0.0-20181025070752-41975c0ccc30 @@ -33,7 +33,7 @@ require ( github.com/goware/prefixer v0.0.0-20160118172347-395022866408 // indirect github.com/grpc-ecosystem/go-grpc-middleware v0.0.0-20180522105215-e9c5d9645c43 github.com/hinshun/vt10x v0.0.0-20180809195222-d55458df857c // indirect - github.com/hokaccha/go-prettyjson v0.0.0-20180920040306-f579f869bbfe + github.com/hokaccha/go-prettyjson v0.0.0-20180920040306-f579f869bbfe // indirect github.com/inconshreveable/mousetrap v1.0.0 // indirect github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect github.com/kelseyhightower/envconfig v1.3.0 @@ -42,7 +42,7 @@ require ( github.com/leodido/go-urn v1.1.0 // indirect github.com/mattn/go-colorable v0.0.0-20180310133214-efa589957cd0 // indirect github.com/mattn/go-isatty v0.0.3 // indirect - github.com/mesg-foundation/prefixer v0.0.0-20180907095533-d7dbe41616bd + github.com/mesg-foundation/prefixer v0.0.0-20180907095533-d7dbe41616bd // indirect github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b // indirect github.com/mitchellh/go-homedir v0.0.0-20161203194507-b8bc1bf76747 github.com/mr-tron/base58 v1.1.1 @@ -52,14 +52,14 @@ require ( github.com/opencontainers/image-spec v1.0.1 // indirect github.com/opencontainers/runc v0.1.1 // indirect github.com/pelletier/go-buffruneio v0.0.0-20180119162133-e2f66f8164ca // indirect - github.com/pkg/errors v0.8.0 + github.com/pkg/errors v0.8.0 // indirect github.com/pseudomuto/protoc-gen-doc v1.1.0 github.com/pseudomuto/protokit v0.1.0 // indirect github.com/satori/go.uuid v1.2.0 github.com/sergi/go-diff v0.0.0-20180205163309-da645544ed44 // indirect github.com/sirupsen/logrus v1.0.6 - github.com/spf13/cobra v0.0.0-20171207074935-ccaecb155a21 - github.com/spf13/pflag v0.0.0-20180601132542-3ebe029320b2 + github.com/spf13/cobra v0.0.0-20171207074935-ccaecb155a21 // indirect + github.com/spf13/pflag v0.0.0-20180601132542-3ebe029320b2 // indirect github.com/src-d/gcfg v1.3.0 // indirect github.com/stretchr/testify v1.3.0 github.com/syndtr/goleveldb v0.0.0-20180708030551-c4c61651e9e3 @@ -72,7 +72,7 @@ require ( golang.org/x/tools v0.0.0-20190111214448-fc1d57b08d7b // indirect google.golang.org/genproto v0.0.0-20180709204101-e92b11657268 // indirect google.golang.org/grpc v0.0.0-20180710012024-c491b25057c8 - gopkg.in/AlecAivazis/survey.v1 v1.6.1 + gopkg.in/AlecAivazis/survey.v1 v1.6.1 // indirect gopkg.in/airbrake/gobrake.v2 v2.0.9 // indirect gopkg.in/gemnasium/logrus-airbrake-hook.v2 v2.1.2 // indirect gopkg.in/go-playground/assert.v1 v1.2.1 // indirect diff --git a/protobuf/api/service.pb.go b/protobuf/api/service.pb.go new file mode 100644 index 000000000..8ce453547 --- /dev/null +++ b/protobuf/api/service.pb.go @@ -0,0 +1,204 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// source: protobuf/api/service.proto + +package api + +import proto "github.com/golang/protobuf/proto" +import fmt "fmt" +import math "math" +import definition "github.com/mesg-foundation/core/protobuf/definition" + +import ( + context "golang.org/x/net/context" + grpc "google.golang.org/grpc" +) + +// 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.ProtoPackageIsVersion2 // please upgrade the proto package + +type CreateServiceRequest struct { + Definition *definition.Service `protobuf:"bytes,1,opt,name=definition,proto3" json:"definition,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *CreateServiceRequest) Reset() { *m = CreateServiceRequest{} } +func (m *CreateServiceRequest) String() string { return proto.CompactTextString(m) } +func (*CreateServiceRequest) ProtoMessage() {} +func (*CreateServiceRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_service_cdb2d5a31910dd99, []int{0} +} +func (m *CreateServiceRequest) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_CreateServiceRequest.Unmarshal(m, b) +} +func (m *CreateServiceRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_CreateServiceRequest.Marshal(b, m, deterministic) +} +func (dst *CreateServiceRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_CreateServiceRequest.Merge(dst, src) +} +func (m *CreateServiceRequest) XXX_Size() int { + return xxx_messageInfo_CreateServiceRequest.Size(m) +} +func (m *CreateServiceRequest) XXX_DiscardUnknown() { + xxx_messageInfo_CreateServiceRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_CreateServiceRequest proto.InternalMessageInfo + +func (m *CreateServiceRequest) GetDefinition() *definition.Service { + if m != nil { + return m.Definition + } + return nil +} + +type CreateServiceResponse struct { + Sid string `protobuf:"bytes,1,opt,name=sid,proto3" json:"sid,omitempty"` + Hash string `protobuf:"bytes,2,opt,name=hash,proto3" json:"hash,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *CreateServiceResponse) Reset() { *m = CreateServiceResponse{} } +func (m *CreateServiceResponse) String() string { return proto.CompactTextString(m) } +func (*CreateServiceResponse) ProtoMessage() {} +func (*CreateServiceResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_service_cdb2d5a31910dd99, []int{1} +} +func (m *CreateServiceResponse) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_CreateServiceResponse.Unmarshal(m, b) +} +func (m *CreateServiceResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_CreateServiceResponse.Marshal(b, m, deterministic) +} +func (dst *CreateServiceResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_CreateServiceResponse.Merge(dst, src) +} +func (m *CreateServiceResponse) XXX_Size() int { + return xxx_messageInfo_CreateServiceResponse.Size(m) +} +func (m *CreateServiceResponse) XXX_DiscardUnknown() { + xxx_messageInfo_CreateServiceResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_CreateServiceResponse proto.InternalMessageInfo + +func (m *CreateServiceResponse) GetSid() string { + if m != nil { + return m.Sid + } + return "" +} + +func (m *CreateServiceResponse) GetHash() string { + if m != nil { + return m.Hash + } + return "" +} + +func init() { + proto.RegisterType((*CreateServiceRequest)(nil), "api.CreateServiceRequest") + proto.RegisterType((*CreateServiceResponse)(nil), "api.CreateServiceResponse") +} + +// Reference imports to suppress errors if they are not otherwise used. +var _ context.Context +var _ grpc.ClientConn + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +const _ = grpc.SupportPackageIsVersion4 + +// ServiceXClient is the client API for ServiceX service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. +type ServiceXClient interface { + Create(ctx context.Context, in *CreateServiceRequest, opts ...grpc.CallOption) (*CreateServiceResponse, error) +} + +type serviceXClient struct { + cc *grpc.ClientConn +} + +func NewServiceXClient(cc *grpc.ClientConn) ServiceXClient { + return &serviceXClient{cc} +} + +func (c *serviceXClient) Create(ctx context.Context, in *CreateServiceRequest, opts ...grpc.CallOption) (*CreateServiceResponse, error) { + out := new(CreateServiceResponse) + err := c.cc.Invoke(ctx, "/api.ServiceX/Create", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// ServiceXServer is the server API for ServiceX service. +type ServiceXServer interface { + Create(context.Context, *CreateServiceRequest) (*CreateServiceResponse, error) +} + +func RegisterServiceXServer(s *grpc.Server, srv ServiceXServer) { + s.RegisterService(&_ServiceX_serviceDesc, srv) +} + +func _ServiceX_Create_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(CreateServiceRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ServiceXServer).Create(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/api.ServiceX/Create", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ServiceXServer).Create(ctx, req.(*CreateServiceRequest)) + } + return interceptor(ctx, in, info, handler) +} + +var _ServiceX_serviceDesc = grpc.ServiceDesc{ + ServiceName: "api.ServiceX", + HandlerType: (*ServiceXServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "Create", + Handler: _ServiceX_Create_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "protobuf/api/service.proto", +} + +func init() { proto.RegisterFile("protobuf/api/service.proto", fileDescriptor_service_cdb2d5a31910dd99) } + +var fileDescriptor_service_cdb2d5a31910dd99 = []byte{ + // 187 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0x2a, 0x28, 0xca, 0x2f, + 0xc9, 0x4f, 0x2a, 0x4d, 0xd3, 0x4f, 0x2c, 0xc8, 0xd4, 0x2f, 0x4e, 0x2d, 0x2a, 0xcb, 0x4c, 0x4e, + 0xd5, 0x03, 0x0b, 0x0a, 0x31, 0x27, 0x16, 0x64, 0x4a, 0x29, 0xc2, 0x15, 0xa4, 0xa4, 0xa6, 0x65, + 0xe6, 0x65, 0x96, 0x64, 0xe6, 0xe7, 0xa1, 0xaa, 0x53, 0xf2, 0xe6, 0x12, 0x71, 0x2e, 0x4a, 0x4d, + 0x2c, 0x49, 0x0d, 0x86, 0x08, 0x07, 0xa5, 0x16, 0x96, 0xa6, 0x16, 0x97, 0x08, 0x19, 0x73, 0x71, + 0x21, 0xf4, 0x48, 0x30, 0x2a, 0x30, 0x6a, 0x70, 0x1b, 0x09, 0xeb, 0x21, 0x84, 0xf4, 0x60, 0xea, + 0x91, 0x94, 0x29, 0xd9, 0x72, 0x89, 0xa2, 0x19, 0x56, 0x5c, 0x90, 0x9f, 0x57, 0x9c, 0x2a, 0x24, + 0xc0, 0xc5, 0x5c, 0x9c, 0x99, 0x02, 0x36, 0x86, 0x33, 0x08, 0xc4, 0x14, 0x12, 0xe2, 0x62, 0xc9, + 0x48, 0x2c, 0xce, 0x90, 0x60, 0x02, 0x0b, 0x81, 0xd9, 0x46, 0xbe, 0x5c, 0x1c, 0x50, 0x8d, 0x11, + 0x42, 0x8e, 0x5c, 0x6c, 0x10, 0xa3, 0x84, 0x24, 0xf5, 0x12, 0x0b, 0x32, 0xf5, 0xb0, 0x39, 0x52, + 0x4a, 0x0a, 0x9b, 0x14, 0xc4, 0x4a, 0x25, 0x86, 0x24, 0x36, 0xb0, 0x0f, 0x8d, 0x01, 0x01, 0x00, + 0x00, 0xff, 0xff, 0x2b, 0xb6, 0x9f, 0xac, 0x27, 0x01, 0x00, 0x00, +} diff --git a/protobuf/api/service.proto b/protobuf/api/service.proto new file mode 100644 index 000000000..fa864d7de --- /dev/null +++ b/protobuf/api/service.proto @@ -0,0 +1,20 @@ +syntax = "proto3"; + +import "protobuf/definition/service.proto"; + +package api; + +// TODO(ilgooz): FIXME: this should be renamed to Service. +// right now we have conflicts with api.Service. +service ServiceX { + rpc Create (CreateServiceRequest) returns (CreateServiceResponse) {} +} + +message CreateServiceRequest { + definition.Service definition = 1; +} + +message CreateServiceResponse { + string sid = 1; + string hash = 2; +} diff --git a/protobuf/definition/service.pb.go b/protobuf/definition/service.pb.go index 8d5f785d3..1ec0f345f 100644 --- a/protobuf/definition/service.pb.go +++ b/protobuf/definition/service.pb.go @@ -29,6 +29,7 @@ type Service struct { Events []*Event `protobuf:"bytes,6,rep,name=events,proto3" json:"events,omitempty"` Dependencies []*Dependency `protobuf:"bytes,7,rep,name=dependencies,proto3" json:"dependencies,omitempty"` Repository string `protobuf:"bytes,9,opt,name=repository,proto3" json:"repository,omitempty"` + Source string `protobuf:"bytes,13,opt,name=source,proto3" json:"source,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -38,7 +39,7 @@ func (m *Service) Reset() { *m = Service{} } func (m *Service) String() string { return proto.CompactTextString(m) } func (*Service) ProtoMessage() {} func (*Service) Descriptor() ([]byte, []int) { - return fileDescriptor_service_903acffdb08adb24, []int{0} + return fileDescriptor_service_88ddda8ce50fbb96, []int{0} } func (m *Service) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_Service.Unmarshal(m, b) @@ -121,6 +122,13 @@ func (m *Service) GetRepository() string { return "" } +func (m *Service) GetSource() string { + if m != nil { + return m.Source + } + return "" +} + // Events are emitted by the service whenever the service wants. type Event struct { Key string `protobuf:"bytes,4,opt,name=key,proto3" json:"key,omitempty"` @@ -136,7 +144,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_service_903acffdb08adb24, []int{1} + return fileDescriptor_service_88ddda8ce50fbb96, []int{1} } func (m *Event) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_Event.Unmarshal(m, b) @@ -200,7 +208,7 @@ func (m *Task) Reset() { *m = Task{} } func (m *Task) String() string { return proto.CompactTextString(m) } func (*Task) ProtoMessage() {} func (*Task) Descriptor() ([]byte, []int) { - return fileDescriptor_service_903acffdb08adb24, []int{2} + return fileDescriptor_service_88ddda8ce50fbb96, []int{2} } func (m *Task) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_Task.Unmarshal(m, b) @@ -273,7 +281,7 @@ func (m *Parameter) Reset() { *m = Parameter{} } func (m *Parameter) String() string { return proto.CompactTextString(m) } func (*Parameter) ProtoMessage() {} func (*Parameter) Descriptor() ([]byte, []int) { - return fileDescriptor_service_903acffdb08adb24, []int{3} + return fileDescriptor_service_88ddda8ce50fbb96, []int{3} } func (m *Parameter) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_Parameter.Unmarshal(m, b) @@ -357,7 +365,7 @@ func (m *Configuration) Reset() { *m = Configuration{} } func (m *Configuration) String() string { return proto.CompactTextString(m) } func (*Configuration) ProtoMessage() {} func (*Configuration) Descriptor() ([]byte, []int) { - return fileDescriptor_service_903acffdb08adb24, []int{4} + return fileDescriptor_service_88ddda8ce50fbb96, []int{4} } func (m *Configuration) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_Configuration.Unmarshal(m, b) @@ -430,7 +438,7 @@ func (m *Dependency) Reset() { *m = Dependency{} } func (m *Dependency) String() string { return proto.CompactTextString(m) } func (*Dependency) ProtoMessage() {} func (*Dependency) Descriptor() ([]byte, []int) { - return fileDescriptor_service_903acffdb08adb24, []int{5} + return fileDescriptor_service_88ddda8ce50fbb96, []int{5} } func (m *Dependency) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_Dependency.Unmarshal(m, b) @@ -509,42 +517,43 @@ func init() { } func init() { - proto.RegisterFile("protobuf/definition/service.proto", fileDescriptor_service_903acffdb08adb24) + proto.RegisterFile("protobuf/definition/service.proto", fileDescriptor_service_88ddda8ce50fbb96) } -var fileDescriptor_service_903acffdb08adb24 = []byte{ - // 523 bytes of a gzipped FileDescriptorProto +var fileDescriptor_service_88ddda8ce50fbb96 = []byte{ + // 535 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x94, 0xcf, 0x8e, 0xd3, 0x30, - 0x10, 0xc6, 0x95, 0x26, 0xe9, 0x9f, 0xe9, 0xae, 0xb4, 0x58, 0x0b, 0x32, 0x1c, 0x50, 0xc9, 0x01, - 0x75, 0x0f, 0xdb, 0x48, 0xbb, 0xe2, 0xc2, 0x05, 0x89, 0x7f, 0x67, 0x14, 0x38, 0x71, 0x73, 0x93, - 0x69, 0x6b, 0xba, 0x89, 0x23, 0xdb, 0xa9, 0x14, 0x5e, 0x82, 0x37, 0xe1, 0xc4, 0x73, 0x70, 0xe3, - 0x7d, 0x90, 0x27, 0x4d, 0x9b, 0x4a, 0xa5, 0x42, 0xb0, 0xb7, 0x99, 0xf9, 0x7e, 0xee, 0x7c, 0xfe, - 0x1c, 0x15, 0x9e, 0x95, 0x5a, 0x59, 0x35, 0xaf, 0x16, 0x71, 0x86, 0x0b, 0x59, 0x48, 0x2b, 0x55, - 0x11, 0x1b, 0xd4, 0x1b, 0x99, 0xe2, 0x8c, 0x34, 0x06, 0x7b, 0x25, 0xfa, 0xd5, 0x83, 0xc1, 0xc7, - 0x46, 0x65, 0x0c, 0x82, 0x95, 0x30, 0x2b, 0x0e, 0x13, 0x6f, 0x3a, 0x4a, 0xa8, 0x66, 0x17, 0xe0, - 0x1b, 0x99, 0xf1, 0x33, 0x1a, 0xb9, 0xd2, 0x51, 0x85, 0xc8, 0x91, 0x7b, 0x0d, 0xe5, 0x6a, 0x36, - 0x81, 0x71, 0x86, 0x26, 0xd5, 0xb2, 0x74, 0x3f, 0xca, 0x7b, 0x24, 0x75, 0x47, 0xec, 0x15, 0x9c, - 0xa7, 0xaa, 0x58, 0xc8, 0x65, 0xa5, 0x05, 0x31, 0xc3, 0x89, 0x37, 0x1d, 0xdf, 0x3c, 0x9e, 0xed, - 0xbd, 0xcc, 0xde, 0x74, 0x81, 0xe4, 0x90, 0x67, 0xcf, 0x21, 0xb4, 0xc2, 0xac, 0x0d, 0x0f, 0x27, - 0xfe, 0x74, 0x7c, 0x73, 0xd1, 0x3d, 0xf8, 0x49, 0x98, 0x75, 0xd2, 0xc8, 0xec, 0x0a, 0xfa, 0xb8, - 0xc1, 0xc2, 0x1a, 0xde, 0x27, 0xf0, 0x41, 0x17, 0x7c, 0xe7, 0x94, 0x64, 0x0b, 0xb0, 0x97, 0x70, - 0x96, 0x61, 0x89, 0x45, 0x86, 0x45, 0x2a, 0xd1, 0xf0, 0x01, 0x1d, 0x78, 0xd4, 0x3d, 0xf0, 0xb6, - 0xd5, 0xeb, 0xe4, 0x80, 0x65, 0x4f, 0x01, 0x34, 0x96, 0xca, 0x48, 0xab, 0x74, 0xcd, 0x47, 0x74, - 0xe1, 0xce, 0x24, 0xfa, 0x0a, 0x21, 0x2d, 0x73, 0x01, 0xae, 0xb1, 0xe6, 0x41, 0x13, 0xe0, 0x1a, - 0xeb, 0x7f, 0x0c, 0xf0, 0x0a, 0x82, 0x4c, 0x58, 0xc1, 0x7d, 0x32, 0xf9, 0xb0, 0x6b, 0xf2, 0x83, - 0xd0, 0x22, 0x47, 0x8b, 0x3a, 0x21, 0x24, 0xfa, 0xee, 0x41, 0xe0, 0x22, 0x69, 0x77, 0x0f, 0xff, - 0x77, 0xf7, 0x35, 0xf4, 0x65,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f7, 0x25, 0x05, 0x00, 0x00, } diff --git a/protobuf/definition/service.proto b/protobuf/definition/service.proto index 91c45d9eb..d66f0c3a1 100644 --- a/protobuf/definition/service.proto +++ b/protobuf/definition/service.proto @@ -14,6 +14,7 @@ message Service { repeated Event events = 6; // The list of events this service can emit. repeated Dependency dependencies = 7; // The container dependencies this service requires. string repository = 9; // Service's repository url. + string source = 13; // The hash id of service's source code on IPFS. } // Events are emitted by the service whenever the service wants. diff --git a/scripts/build-proto.sh b/scripts/build-proto.sh index 59285c365..7d0752c40 100755 --- a/scripts/build-proto.sh +++ b/scripts/build-proto.sh @@ -8,6 +8,7 @@ GRPC=$PROJECT/protobuf GRPC_PLUGIN="--go_out=plugins=grpc,paths=source_relative:." protoc $GRPC_PLUGIN --proto_path=$PROJECT $GRPC/definition/execution.proto protoc $GRPC_PLUGIN --proto_path=$PROJECT $GRPC/definition/service.proto +protoc $GRPC_PLUGIN --proto_path=$PROJECT $GRPC/api/service.proto protoc $GRPC_PLUGIN --proto_path=$PROJECT $GRPC/coreapi/api.proto protoc $GRPC_PLUGIN --proto_path=$PROJECT $GRPC/api/execution.proto protoc $GRPC_PLUGIN --proto_path=$PROJECT $GRPC/serviceapi/api.proto diff --git a/sdk/sdk.go b/sdk/sdk.go index 13d17f36b..bbb162893 100644 --- a/sdk/sdk.go +++ b/sdk/sdk.go @@ -9,6 +9,7 @@ import ( "github.com/mesg-foundation/core/database" "github.com/mesg-foundation/core/event" "github.com/mesg-foundation/core/execution" + servicesdk "github.com/mesg-foundation/core/sdk/service" "github.com/mesg-foundation/core/service" "github.com/mesg-foundation/core/service/manager" "github.com/mesg-foundation/core/utils/hash" @@ -20,6 +21,8 @@ const executionStreamTopic = "execution-stream" // SDK exposes all functionalities of MESG core. type SDK struct { + Service *servicesdk.Service + ps *pubsub.PubSub m manager.Manager @@ -31,6 +34,7 @@ type SDK struct { // New creates a new SDK with given options. func New(m manager.Manager, c container.Container, db database.ServiceDB, execDB database.ExecutionDB) *SDK { return &SDK{ + Service: servicesdk.New(m, c, db, execDB), ps: pubsub.New(0), m: m, container: c, diff --git a/sdk/service/service.go b/sdk/service/service.go new file mode 100644 index 000000000..85a8ccb13 --- /dev/null +++ b/sdk/service/service.go @@ -0,0 +1,89 @@ +package servicesdk + +import ( + "errors" + "io/ioutil" + "net/http" + "os" + + "github.com/cnf/structhash" + "github.com/cskr/pubsub" + "github.com/docker/docker/pkg/archive" + "github.com/mesg-foundation/core/container" + "github.com/mesg-foundation/core/database" + "github.com/mesg-foundation/core/service" + "github.com/mesg-foundation/core/service/manager" + "github.com/mesg-foundation/core/utils/dirhash" + "github.com/mr-tron/base58" +) + +// Service exposes service APIs of MESG. +type Service struct { + ps *pubsub.PubSub + + m manager.Manager + container container.Container + db database.ServiceDB + execDB database.ExecutionDB +} + +// New creates a new Service SDK with given options. +func New(m manager.Manager, c container.Container, db database.ServiceDB, execDB database.ExecutionDB) *Service { + return &Service{ + ps: pubsub.New(0), + m: m, + container: c, + db: db, + execDB: execDB, + } +} + +// Create creates a new service from definition. +func (s *Service) Create(srv *service.Service) error { + // download and untar service context into path. + path, err := ioutil.TempDir("", "mesg") + if err != nil { + return err + } + defer os.RemoveAll(path) + + resp, err := http.Get("http://ipfs.app.mesg.com:8080/ipfs/" + srv.Source) + if err != nil { + return err + } + if resp.StatusCode != 200 { + return errors.New("service's source code is not reachable") + } + defer resp.Body.Close() + + if err := archive.Untar(resp.Body, path, nil); err != nil { + return err + } + + // calculate and apply hash to service. + dh := dirhash.New(path) + h, err := dh.Sum(structhash.Sha1(srv, 1)) + if err != nil { + return err + } + srv.Hash = base58.Encode(h) + + // check if service is already deployed. + if _, err := s.db.Get(srv.Hash); err == nil { + return errors.New("service is already deployed") + } + + // build service's Docker image and apply to service. + imageHash, err := s.container.Build(path) + if err != nil { + return err + } + srv.Configuration.Image = imageHash + // TODO: the following test should be moved in New function + if srv.Sid == "" { + // make sure that sid doesn't have the same length with id. + srv.Sid = "_" + srv.Hash + } + + return s.db.Save(srv) +} diff --git a/server/grpc/api/service.go b/server/grpc/api/service.go new file mode 100644 index 000000000..654ea9af1 --- /dev/null +++ b/server/grpc/api/service.go @@ -0,0 +1,100 @@ +package api + +import ( + "github.com/mesg-foundation/core/protobuf/definition" + "github.com/mesg-foundation/core/service" +) + +func FromProtoService(s *definition.Service) *service.Service { + return &service.Service{ + Hash: s.Hash, + Sid: s.Sid, + Name: s.Name, + Description: s.Description, + Repository: s.Repository, + Source: s.Source, + Tasks: fromProtoTasks(s.Tasks), + Events: fromProtoEvents(s.Events), + Configuration: fromProtoConfiguration(s.Configuration), + Dependencies: fromProtoDependencies(s.Dependencies), + } +} + +func fromProtoTasks(tasks []*definition.Task) []*service.Task { + ts := make([]*service.Task, len(tasks)) + for i, task := range tasks { + ts[i] = &service.Task{ + Key: task.Key, + Name: task.Name, + Description: task.Description, + Inputs: fromProtoParameters(task.Inputs), + Outputs: fromProtoParameters(task.Outputs), + } + } + return ts +} + +func fromProtoEvents(events []*definition.Event) []*service.Event { + es := make([]*service.Event, len(events)) + for i, event := range events { + es[i] = &service.Event{ + Key: event.Key, + Name: event.Name, + Description: event.Description, + Data: fromProtoParameters(event.Data), + } + } + return es +} + +func fromProtoParameters(params []*definition.Parameter) []*service.Parameter { + ps := make([]*service.Parameter, len(params)) + for i, param := range params { + ps[i] = &service.Parameter{ + Key: param.Key, + Name: param.Name, + Description: param.Description, + Type: param.Type, + Repeated: param.Repeated, + Optional: param.Optional, + Object: fromProtoParameters(param.Object), + } + } + return ps +} + +func fromProtoConfiguration(configuration *definition.Configuration) *service.Dependency { + if configuration == nil { + return nil + } + return &service.Dependency{ + Args: configuration.Args, + Command: configuration.Command, + Ports: configuration.Ports, + Volumes: configuration.Volumes, + VolumesFrom: configuration.VolumesFrom, + } +} + +func fromProtoDependency(dep *definition.Dependency) *service.Dependency { + if dep == nil { + return nil + } + return &service.Dependency{ + Key: dep.Key, + Image: dep.Image, + Volumes: dep.Volumes, + VolumesFrom: dep.VolumesFrom, + Ports: dep.Ports, + Command: dep.Command, + Args: dep.Args, + } +} + +func fromProtoDependencies(deps []*definition.Dependency) []*service.Dependency { + ds := make([]*service.Dependency, len(deps)) + for i, dep := range deps { + ds[i] = fromProtoDependency(dep) + } + return ds +} diff --git a/server/grpc/server.go b/server/grpc/server.go index 483451f58..0be0376f8 100644 --- a/server/grpc/server.go +++ b/server/grpc/server.go @@ -7,6 +7,7 @@ import ( grpc_middleware "github.com/grpc-ecosystem/go-grpc-middleware" grpc_logrus "github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus" + protobuf_api "github.com/mesg-foundation/core/protobuf/api" "github.com/mesg-foundation/core/protobuf/coreapi" "github.com/mesg-foundation/core/protobuf/serviceapi" "github.com/mesg-foundation/core/sdk" @@ -102,10 +103,12 @@ func (s *Server) Close() { // register all server func (s *Server) register() error { coreServer := core.NewServer(s.sdk) + coreServiceServer := NewServiceServer(s.sdk) serviceServer := service.NewServer(s.sdk) serviceapi.RegisterServiceServer(s.instance, serviceServer) coreapi.RegisterCoreServer(s.instance, coreServer) + protobuf_api.RegisterServiceXServer(s.instance, coreServiceServer) reflection.Register(s.instance) return nil diff --git a/server/grpc/service.go b/server/grpc/service.go new file mode 100644 index 000000000..59c4c6e7e --- /dev/null +++ b/server/grpc/service.go @@ -0,0 +1,28 @@ +package grpc + +import ( + "context" + + protobuf_api "github.com/mesg-foundation/core/protobuf/api" + "github.com/mesg-foundation/core/sdk" + "github.com/mesg-foundation/core/server/grpc/api" +) + +// ServiceServer is the type to aggregate all Service APIs. +type ServiceServer struct { + sdk *sdk.SDK +} + +// NewServiceServer creates a new ServiceServer. +func NewServiceServer(sdk *sdk.SDK) *ServiceServer { + return &ServiceServer{sdk: sdk} +} + +// Create creates a new service from definition. +func (s *ServiceServer) Create(ctx context.Context, request *protobuf_api.CreateServiceRequest) (*protobuf_api.CreateServiceResponse, error) { + srv := api.FromProtoService(request.Definition) + if err := s.sdk.Service.Create(srv); err != nil { + return nil, err + } + return &protobuf_api.CreateServiceResponse{Sid: srv.Sid, Hash: srv.Hash}, nil +} diff --git a/service/service.go b/service/service.go index 9c5ec71f1..d368f5b29 100644 --- a/service/service.go +++ b/service/service.go @@ -53,6 +53,9 @@ type Service struct { // a Git host. Repository string `hash:"name:7"` + // Source is the hash id of service's source code on IPFS. + Source string `hash:"name:9"` + // DeployedAt holds the creation time of service. DeployedAt time.Time `hash:"-"` }