diff --git a/CHANGELOG.md b/CHANGELOG.md index b1c0a5bd6..8f607605e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ - (#183) Add a `configuration` attribute in the `mesg.yml` file to accept docker configuration for your service - (#187) Stop all services when the MESG Core stops - (#190) Possibility to `test` or `deploy` a service from a git or GitHub url +- (#235) Add `ListServices` and `GetService` APIs #### Removed diff --git a/api/core/api.pb.go b/api/core/api.pb.go index 331d696e6..efc392b6a 100644 --- a/api/core/api.pb.go +++ b/api/core/api.pb.go @@ -22,6 +22,10 @@ It has these top-level messages: DeployServiceReply DeleteServiceRequest DeleteServiceReply + ListServicesRequest + ListServicesReply + GetServiceRequest + GetServiceReply */ package core @@ -318,6 +322,62 @@ func (m *DeleteServiceReply) String() string { return proto.CompactTe func (*DeleteServiceReply) ProtoMessage() {} func (*DeleteServiceReply) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{13} } +type ListServicesRequest struct { +} + +func (m *ListServicesRequest) Reset() { *m = ListServicesRequest{} } +func (m *ListServicesRequest) String() string { return proto.CompactTextString(m) } +func (*ListServicesRequest) ProtoMessage() {} +func (*ListServicesRequest) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{14} } + +type ListServicesReply struct { + Services []*service.Service `protobuf:"bytes,1,rep,name=services" json:"services,omitempty"` +} + +func (m *ListServicesReply) Reset() { *m = ListServicesReply{} } +func (m *ListServicesReply) String() string { return proto.CompactTextString(m) } +func (*ListServicesReply) ProtoMessage() {} +func (*ListServicesReply) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{15} } + +func (m *ListServicesReply) GetServices() []*service.Service { + if m != nil { + return m.Services + } + return nil +} + +type GetServiceRequest struct { + ServiceID string `protobuf:"bytes,1,opt,name=serviceID" json:"serviceID,omitempty"` +} + +func (m *GetServiceRequest) Reset() { *m = GetServiceRequest{} } +func (m *GetServiceRequest) String() string { return proto.CompactTextString(m) } +func (*GetServiceRequest) ProtoMessage() {} +func (*GetServiceRequest) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{16} } + +func (m *GetServiceRequest) GetServiceID() string { + if m != nil { + return m.ServiceID + } + return "" +} + +type GetServiceReply struct { + Service *service.Service `protobuf:"bytes,1,opt,name=service" json:"service,omitempty"` +} + +func (m *GetServiceReply) Reset() { *m = GetServiceReply{} } +func (m *GetServiceReply) String() string { return proto.CompactTextString(m) } +func (*GetServiceReply) ProtoMessage() {} +func (*GetServiceReply) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{17} } + +func (m *GetServiceReply) GetService() *service.Service { + if m != nil { + return m.Service + } + return nil +} + func init() { proto.RegisterType((*ListenEventRequest)(nil), "api.ListenEventRequest") proto.RegisterType((*ExecuteTaskRequest)(nil), "api.ExecuteTaskRequest") @@ -333,6 +393,10 @@ func init() { proto.RegisterType((*DeployServiceReply)(nil), "api.DeployServiceReply") proto.RegisterType((*DeleteServiceRequest)(nil), "api.DeleteServiceRequest") proto.RegisterType((*DeleteServiceReply)(nil), "api.DeleteServiceReply") + proto.RegisterType((*ListServicesRequest)(nil), "api.ListServicesRequest") + proto.RegisterType((*ListServicesReply)(nil), "api.ListServicesReply") + proto.RegisterType((*GetServiceRequest)(nil), "api.GetServiceRequest") + proto.RegisterType((*GetServiceReply)(nil), "api.GetServiceReply") } // Reference imports to suppress errors if they are not otherwise used. @@ -353,6 +417,8 @@ type CoreClient interface { StopService(ctx context.Context, in *StopServiceRequest, opts ...grpc.CallOption) (*StopServiceReply, error) DeployService(ctx context.Context, in *DeployServiceRequest, opts ...grpc.CallOption) (*DeployServiceReply, error) DeleteService(ctx context.Context, in *DeleteServiceRequest, opts ...grpc.CallOption) (*DeleteServiceReply, error) + ListServices(ctx context.Context, in *ListServicesRequest, opts ...grpc.CallOption) (*ListServicesReply, error) + GetService(ctx context.Context, in *GetServiceRequest, opts ...grpc.CallOption) (*GetServiceReply, error) } type coreClient struct { @@ -472,6 +538,24 @@ func (c *coreClient) DeleteService(ctx context.Context, in *DeleteServiceRequest return out, nil } +func (c *coreClient) ListServices(ctx context.Context, in *ListServicesRequest, opts ...grpc.CallOption) (*ListServicesReply, error) { + out := new(ListServicesReply) + err := grpc.Invoke(ctx, "/api.Core/ListServices", in, out, c.cc, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *coreClient) GetService(ctx context.Context, in *GetServiceRequest, opts ...grpc.CallOption) (*GetServiceReply, error) { + out := new(GetServiceReply) + err := grpc.Invoke(ctx, "/api.Core/GetService", in, out, c.cc, opts...) + if err != nil { + return nil, err + } + return out, nil +} + // Server API for Core service type CoreServer interface { @@ -482,6 +566,8 @@ type CoreServer interface { StopService(context.Context, *StopServiceRequest) (*StopServiceReply, error) DeployService(context.Context, *DeployServiceRequest) (*DeployServiceReply, error) DeleteService(context.Context, *DeleteServiceRequest) (*DeleteServiceReply, error) + ListServices(context.Context, *ListServicesRequest) (*ListServicesReply, error) + GetService(context.Context, *GetServiceRequest) (*GetServiceReply, error) } func RegisterCoreServer(s *grpc.Server, srv CoreServer) { @@ -620,6 +706,42 @@ func _Core_DeleteService_Handler(srv interface{}, ctx context.Context, dec func( return interceptor(ctx, in, info, handler) } +func _Core_ListServices_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(ListServicesRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(CoreServer).ListServices(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/api.Core/ListServices", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(CoreServer).ListServices(ctx, req.(*ListServicesRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Core_GetService_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(GetServiceRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(CoreServer).GetService(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/api.Core/GetService", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(CoreServer).GetService(ctx, req.(*GetServiceRequest)) + } + return interceptor(ctx, in, info, handler) +} + var _Core_serviceDesc = grpc.ServiceDesc{ ServiceName: "api.Core", HandlerType: (*CoreServer)(nil), @@ -644,6 +766,14 @@ var _Core_serviceDesc = grpc.ServiceDesc{ MethodName: "DeleteService", Handler: _Core_DeleteService_Handler, }, + { + MethodName: "ListServices", + Handler: _Core_ListServices_Handler, + }, + { + MethodName: "GetService", + Handler: _Core_GetService_Handler, + }, }, Streams: []grpc.StreamDesc{ { @@ -663,39 +793,43 @@ var _Core_serviceDesc = grpc.ServiceDesc{ func init() { proto.RegisterFile("github.com/mesg-foundation/core/api/core/api.proto", fileDescriptor0) } var fileDescriptor0 = []byte{ - // 531 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x54, 0xdd, 0x6e, 0xd3, 0x30, - 0x14, 0x6e, 0x69, 0xb5, 0xd1, 0x93, 0x02, 0xc5, 0x1d, 0x2c, 0x44, 0x13, 0x9a, 0x7c, 0x85, 0x90, - 0x68, 0x51, 0x37, 0x6e, 0x90, 0xd0, 0xa4, 0xd2, 0x22, 0x21, 0xb8, 0x6a, 0x77, 0xc5, 0x5d, 0x56, - 0x0e, 0x5b, 0xb4, 0x2c, 0x36, 0x89, 0x33, 0xc8, 0x0b, 0xf0, 0x86, 0xbc, 0xcf, 0x74, 0xec, 0xfc, - 0x38, 0x4d, 0xb5, 0xb5, 0x57, 0x89, 0xbf, 0xf3, 0xff, 0x7d, 0x3e, 0x86, 0xc9, 0x65, 0xa0, 0xae, - 0xd2, 0x8b, 0xd1, 0x4a, 0xdc, 0x8c, 0x6f, 0x30, 0xb9, 0x7c, 0xf7, 0x4b, 0xa4, 0xd1, 0x4f, 0x5f, - 0x05, 0x22, 0x1a, 0xaf, 0x44, 0x8c, 0x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xe7, 0x33, 0x34, 0x37, 0x28, 0x9f, 0xa1, 0x71, 0x17, 0x5a, 0x6c, 0x0e, 0x4f, - 0x6a, 0x4a, 0xb2, 0x57, 0xda, 0x73, 0xd3, 0x0d, 0xf1, 0x0e, 0x37, 0x99, 0xac, 0x34, 0x96, 0x4c, - 0x65, 0x9a, 0xa6, 0xe0, 0x65, 0x9a, 0x75, 0x55, 0x79, 0x6b, 0xba, 0xf7, 0xa3, 0x4b, 0x4f, 0xf1, - 0xc5, 0x9e, 0x7e, 0x7b, 0x4f, 0xee, 0x02, 0x00, 0x00, 0xff, 0xff, 0x59, 0x4b, 0x37, 0xd7, 0xed, - 0x05, 0x00, 0x00, + // 606 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x55, 0xdd, 0x6e, 0xd3, 0x30, + 0x14, 0x6e, 0x69, 0xb5, 0xad, 0xa7, 0x85, 0xb5, 0x6e, 0xc7, 0x42, 0x34, 0xa1, 0xca, 0x57, 0x08, + 0x41, 0x0b, 0xdd, 0xb8, 0x41, 0x4c, 0x13, 0xa5, 0x05, 0x21, 0xb8, 0x6a, 0x77, 0xc5, 0x5d, 0x56, + 0xcc, 0x16, 0x2d, 0xab, 0x43, 0xe2, 0x0c, 0xfa, 0x02, 0xbc, 0x22, 0xaf, 0x33, 0x1d, 0xdb, 0x49, + 0x9c, 0x3a, 0xda, 0xda, 0xab, 0xc4, 0xdf, 0xf9, 0xf3, 0xf9, 0xce, 0x97, 0x13, 0x18, 0x5d, 0xfa, + 0xe2, 0x2a, 0xb9, 0x18, 0x2c, 0xf8, 0xcd, 0xf0, 0x86, 0xc5, 0x97, 0xaf, 0x7f, 0xf1, 0x64, 0xf9, + 0xd3, 0x13, 0x3e, 0x5f, 0x0e, 0x17, 0x3c, 0x62, 0x43, 0x2f, 0xf4, 0xb3, 0x97, 0x41, 0x18, 0x71, + 0xc1, 0x49, 0xcd, 0x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, 0x99, 0x6b, 0x82, 0x38, 0x46, 0xf5, 0xc2, 0xe6, 0x70, 0xf7, 0xa5, 0x25, 0xd7, 0xbc, 0xac, + 0x3f, 0x86, 0x96, 0xa9, 0x3e, 0x1d, 0x5e, 0xf2, 0xfd, 0xbb, 0x4f, 0x4b, 0x2c, 0xea, 0x0a, 0x67, + 0xd0, 0x34, 0xc4, 0xaa, 0x7b, 0xb0, 0xb7, 0x81, 0xee, 0xc1, 0xd2, 0x75, 0x85, 0x4c, 0xe1, 0x71, + 0x41, 0x95, 0xe4, 0x99, 0xf4, 0x2c, 0x53, 0xbb, 0x7b, 0x58, 0x66, 0x32, 0xd2, 0x18, 0x92, 0xcb, + 0xd2, 0xd8, 0xe2, 0xcd, 0xd2, 0x58, 0x0a, 0xad, 0x20, 0x25, 0xa6, 0x18, 0x0d, 0x46, 0xd7, 0x64, + 0xab, 0x29, 0xb1, 0x94, 0x4b, 0x2b, 0xe4, 0x03, 0x40, 0x2e, 0x2d, 0xa2, 0xfc, 0x2c, 0x79, 0xba, + 0x3d, 0x0b, 0x97, 0xd1, 0xe3, 0x9d, 0x1f, 0x75, 0xfc, 0xb1, 0x5d, 0xec, 0xc8, 0x3f, 0xd9, 0xf1, + 0x5d, 0x00, 0x00, 0x00, 0xff, 0xff, 0xd3, 0xb8, 0x85, 0x93, 0x3b, 0x07, 0x00, 0x00, } diff --git a/api/core/api.proto b/api/core/api.proto index 1ec8eb248..bad55a7e9 100644 --- a/api/core/api.proto +++ b/api/core/api.proto @@ -13,6 +13,8 @@ service Core { rpc StopService (StopServiceRequest) returns (StopServiceReply) {} rpc DeployService (DeployServiceRequest) returns (DeployServiceReply) {} rpc DeleteService (DeleteServiceRequest) returns (DeleteServiceReply) {} + rpc ListServices (ListServicesRequest) returns (ListServicesReply) {} + rpc GetService (GetServiceRequest) returns (GetServiceReply) {} } message ListenEventRequest { @@ -75,4 +77,19 @@ message DeleteServiceRequest { } message DeleteServiceReply { +} + +message ListServicesRequest { +} + +message ListServicesReply { + repeated service.Service services = 1; +} + +message GetServiceRequest { + string serviceID = 1; +} + +message GetServiceReply { + service.Service service = 1; } \ No newline at end of file diff --git a/api/core/get_service.go b/api/core/get_service.go new file mode 100644 index 000000000..428f88ba2 --- /dev/null +++ b/api/core/get_service.go @@ -0,0 +1,18 @@ +package core + +import ( + "github.com/mesg-foundation/core/database/services" + "golang.org/x/net/context" +) + +// GetService fetch a service in the db and return ot +func (s *Server) GetService(ctx context.Context, request *GetServiceRequest) (reply *GetServiceReply, err error) { + service, err := services.Get(request.ServiceID) + if err != nil { + return + } + reply = &GetServiceReply{ + Service: &service, + } + return +} diff --git a/api/core/get_service_test.go b/api/core/get_service_test.go new file mode 100644 index 000000000..bd3ac14cc --- /dev/null +++ b/api/core/get_service_test.go @@ -0,0 +1,26 @@ +package core + +import ( + "context" + "testing" + + "github.com/mesg-foundation/core/database/services" + + "github.com/mesg-foundation/core/service" + "github.com/stvp/assert" +) + +var servergetservice = new(Server) + +func TestGetService(t *testing.T) { + hash, _ := services.Save(&service.Service{ + Name: "TestGetService", + }) + defer services.Delete(hash) + reply, err := servergetservice.GetService(context.Background(), &GetServiceRequest{ + ServiceID: hash, + }) + assert.Nil(t, err) + assert.NotNil(t, reply) + assert.Equal(t, reply.Service.Name, "TestGetService") +} diff --git a/api/core/list_services.go b/api/core/list_services.go new file mode 100644 index 000000000..6ebeb06ac --- /dev/null +++ b/api/core/list_services.go @@ -0,0 +1,18 @@ +package core + +import ( + "github.com/mesg-foundation/core/database/services" + "golang.org/x/net/context" +) + +// ListServices return all services from the database +func (s *Server) ListServices(ctx context.Context, request *ListServicesRequest) (reply *ListServicesReply, err error) { + services, err := services.All() + if err != nil { + return + } + reply = &ListServicesReply{ + Services: services, + } + return +} diff --git a/api/core/list_services_test.go b/api/core/list_services_test.go new file mode 100644 index 000000000..6a95c7cec --- /dev/null +++ b/api/core/list_services_test.go @@ -0,0 +1,18 @@ +package core + +import ( + "context" + "testing" + + "github.com/mesg-foundation/core/database/services" + "github.com/stvp/assert" +) + +var serverlistservices = new(Server) + +func TestListServices(t *testing.T) { + servicesFromAPI, err := serverlistservices.ListServices(context.Background(), &ListServicesRequest{}) + servicesFromDB, _ := services.All() + assert.Nil(t, err) + assert.Equal(t, len(servicesFromAPI.Services), len(servicesFromDB)) +}