From a04f5f74fcc0fcec3803ae18500e9836ea1fe429 Mon Sep 17 00:00:00 2001 From: Tony Pujals Date: Sun, 25 Sep 2016 11:10:49 -0700 Subject: [PATCH 1/3] adding more sample files --- api/rpc/stack/test_samples/sample-05-labels.yml | 7 +++++++ api/rpc/stack/test_samples/sample-06-labels.yml | 7 +++++++ api/rpc/stack/test_samples/sample-07-env.yml | 7 +++++++ api/rpc/stack/test_samples/sample-08-env.yml | 7 +++++++ 4 files changed, 28 insertions(+) create mode 100644 api/rpc/stack/test_samples/sample-05-labels.yml create mode 100644 api/rpc/stack/test_samples/sample-06-labels.yml create mode 100644 api/rpc/stack/test_samples/sample-07-env.yml create mode 100644 api/rpc/stack/test_samples/sample-08-env.yml diff --git a/api/rpc/stack/test_samples/sample-05-labels.yml b/api/rpc/stack/test_samples/sample-05-labels.yml new file mode 100644 index 000000000..3a5ade19c --- /dev/null +++ b/api/rpc/stack/test_samples/sample-05-labels.yml @@ -0,0 +1,7 @@ +pinger: + image: appcelerator/pinger + label: + - "foo=bar" + public: + - publish_port: 3000 + internal_port: 3000 diff --git a/api/rpc/stack/test_samples/sample-06-labels.yml b/api/rpc/stack/test_samples/sample-06-labels.yml new file mode 100644 index 000000000..b4c8a3f37 --- /dev/null +++ b/api/rpc/stack/test_samples/sample-06-labels.yml @@ -0,0 +1,7 @@ +pinger: + image: appcelerator/pinger + label: + foo: bar + public: + - publish_port: 3000 + internal_port: 3000 diff --git a/api/rpc/stack/test_samples/sample-07-env.yml b/api/rpc/stack/test_samples/sample-07-env.yml new file mode 100644 index 000000000..45e6bc2d1 --- /dev/null +++ b/api/rpc/stack/test_samples/sample-07-env.yml @@ -0,0 +1,7 @@ +pinger: + image: appcelerator/pinger + env: + - "foo=bar" + public: + - publish_port: 3000 + internal_port: 3000 diff --git a/api/rpc/stack/test_samples/sample-08-env.yml b/api/rpc/stack/test_samples/sample-08-env.yml new file mode 100644 index 000000000..7238a20eb --- /dev/null +++ b/api/rpc/stack/test_samples/sample-08-env.yml @@ -0,0 +1,7 @@ +pinger: + image: appcelerator/pinger + env: + foo: bar + public: + - publish_port: 3000 + internal_port: 3000 From b9b1b5ee49f7c93b17dd01fe7a568dd1bb660336 Mon Sep 17 00:00:00 2001 From: Tony Pujals Date: Sun, 25 Sep 2016 14:03:01 -0700 Subject: [PATCH 2/3] added label support for service create, updated stack parser tests --- api/rpc/stack/test_samples/sample-05-labels.yml | 2 +- api/rpc/stack/test_samples/sample-06-labels.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/api/rpc/stack/test_samples/sample-05-labels.yml b/api/rpc/stack/test_samples/sample-05-labels.yml index 3a5ade19c..62f944f40 100644 --- a/api/rpc/stack/test_samples/sample-05-labels.yml +++ b/api/rpc/stack/test_samples/sample-05-labels.yml @@ -1,6 +1,6 @@ pinger: image: appcelerator/pinger - label: + labels: - "foo=bar" public: - publish_port: 3000 diff --git a/api/rpc/stack/test_samples/sample-06-labels.yml b/api/rpc/stack/test_samples/sample-06-labels.yml index b4c8a3f37..5274d092d 100644 --- a/api/rpc/stack/test_samples/sample-06-labels.yml +++ b/api/rpc/stack/test_samples/sample-06-labels.yml @@ -1,6 +1,6 @@ pinger: image: appcelerator/pinger - label: + labels: foo: bar public: - publish_port: 3000 From 489dbe09a316bd8b6295cc8a0613d737a3981622 Mon Sep 17 00:00:00 2001 From: Tony Pujals Date: Sun, 25 Sep 2016 17:32:24 -0700 Subject: [PATCH 3/3] added service rm --- api/rpc/service/service.go | 23 ++++- api/rpc/service/service.pb.go | 189 +++++++++++++++++++++------------- api/rpc/service/service.proto | 39 ++++--- api/rpc/stack/stack.go | 6 +- cmd/amp/service-create.go | 2 +- cmd/amp/service-rm.go | 65 ++++++++++++ 6 files changed, 225 insertions(+), 99 deletions(-) create mode 100644 cmd/amp/service-rm.go diff --git a/api/rpc/service/service.go b/api/rpc/service/service.go index 06f7c24f0..16c02e40e 100644 --- a/api/rpc/service/service.go +++ b/api/rpc/service/service.go @@ -35,13 +35,26 @@ func init() { // Create implements ServiceServer func (s *Service) Create(ctx context.Context, req *ServiceCreateRequest) (*ServiceCreateResponse, error) { - // TODO: pass-through right now, but will be refactored into a helper library - response, err := CreateService(docker, ctx, req) + response, err := Create(ctx, req) return response, err } -// CreateService uses docker api to create a service -func CreateService(docker *client.Client, ctx context.Context, req *ServiceCreateRequest) (*ServiceCreateResponse, error) { +// Remove implements ServiceServer +func (s *Service) Remove(ctx context.Context, req *RemoveRequest) (*RemoveResponse, error) { + err := Remove(ctx, req.Ident) + if err != nil { + return nil, err + } + + response := &RemoveResponse{ + Ident: req.Ident, + } + + return response, nil +} + +// Create uses docker api to create a service +func Create(ctx context.Context, req *ServiceCreateRequest) (*ServiceCreateResponse, error) { serv := req.ServiceSpec service := swarm.ServiceSpec{ @@ -129,7 +142,7 @@ func CreateService(docker *client.Client, ctx context.Context, req *ServiceCreat } // Remove uses docker api to remove a service -func (s *Service) Remove(ctx context.Context, ID string) error { +func Remove(ctx context.Context, ID string) error { fmt.Printf("Service removed %s\n", ID) return docker.ServiceRemove(ctx, ID) } diff --git a/api/rpc/service/service.pb.go b/api/rpc/service/service.pb.go index b3c7c5719..eb8b86c37 100644 --- a/api/rpc/service/service.pb.go +++ b/api/rpc/service/service.pb.go @@ -9,11 +9,12 @@ It is generated from these files: github.com/appcelerator/amp/api/rpc/service/service.proto It has these top-level messages: - ServiceCreateRequest - ServiceCreateResponse - ServiceRemoveRequest ServiceSpec PublishSpec + ServiceCreateRequest + ServiceCreateResponse + RemoveRequest + RemoveResponse */ package service @@ -37,40 +38,6 @@ var _ = math.Inf // proto package needs to be updated. const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package -type ServiceCreateRequest struct { - ServiceSpec *ServiceSpec `protobuf:"bytes,1,opt,name=service_spec,json=serviceSpec" json:"service_spec,omitempty"` -} - -func (m *ServiceCreateRequest) Reset() { *m = ServiceCreateRequest{} } -func (m *ServiceCreateRequest) String() string { return proto.CompactTextString(m) } -func (*ServiceCreateRequest) ProtoMessage() {} -func (*ServiceCreateRequest) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{0} } - -func (m *ServiceCreateRequest) GetServiceSpec() *ServiceSpec { - if m != nil { - return m.ServiceSpec - } - return nil -} - -type ServiceCreateResponse struct { - Id string `protobuf:"bytes,1,opt,name=id" json:"id,omitempty"` -} - -func (m *ServiceCreateResponse) Reset() { *m = ServiceCreateResponse{} } -func (m *ServiceCreateResponse) String() string { return proto.CompactTextString(m) } -func (*ServiceCreateResponse) ProtoMessage() {} -func (*ServiceCreateResponse) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{1} } - -type ServiceRemoveRequest struct { - ServiceId string `protobuf:"bytes,1,opt,name=service_id,json=serviceId" json:"service_id,omitempty"` -} - -func (m *ServiceRemoveRequest) Reset() { *m = ServiceRemoveRequest{} } -func (m *ServiceRemoveRequest) String() string { return proto.CompactTextString(m) } -func (*ServiceRemoveRequest) ProtoMessage() {} -func (*ServiceRemoveRequest) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{2} } - type ServiceSpec struct { Image string `protobuf:"bytes,1,opt,name=image" json:"image,omitempty"` Name string `protobuf:"bytes,2,opt,name=name" json:"name,omitempty"` @@ -84,7 +51,7 @@ type ServiceSpec struct { func (m *ServiceSpec) Reset() { *m = ServiceSpec{} } func (m *ServiceSpec) String() string { return proto.CompactTextString(m) } func (*ServiceSpec) ProtoMessage() {} -func (*ServiceSpec) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{3} } +func (*ServiceSpec) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{0} } func (m *ServiceSpec) GetLabels() map[string]string { if m != nil { @@ -117,14 +84,58 @@ type PublishSpec struct { func (m *PublishSpec) Reset() { *m = PublishSpec{} } func (m *PublishSpec) String() string { return proto.CompactTextString(m) } func (*PublishSpec) ProtoMessage() {} -func (*PublishSpec) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{4} } +func (*PublishSpec) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{1} } + +type ServiceCreateRequest struct { + ServiceSpec *ServiceSpec `protobuf:"bytes,1,opt,name=service_spec,json=serviceSpec" json:"service_spec,omitempty"` +} + +func (m *ServiceCreateRequest) Reset() { *m = ServiceCreateRequest{} } +func (m *ServiceCreateRequest) String() string { return proto.CompactTextString(m) } +func (*ServiceCreateRequest) ProtoMessage() {} +func (*ServiceCreateRequest) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{2} } + +func (m *ServiceCreateRequest) GetServiceSpec() *ServiceSpec { + if m != nil { + return m.ServiceSpec + } + return nil +} + +type ServiceCreateResponse struct { + Id string `protobuf:"bytes,1,opt,name=id" json:"id,omitempty"` +} + +func (m *ServiceCreateResponse) Reset() { *m = ServiceCreateResponse{} } +func (m *ServiceCreateResponse) String() string { return proto.CompactTextString(m) } +func (*ServiceCreateResponse) ProtoMessage() {} +func (*ServiceCreateResponse) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{3} } + +type RemoveRequest struct { + Ident string `protobuf:"bytes,1,opt,name=ident" json:"ident,omitempty"` +} + +func (m *RemoveRequest) Reset() { *m = RemoveRequest{} } +func (m *RemoveRequest) String() string { return proto.CompactTextString(m) } +func (*RemoveRequest) ProtoMessage() {} +func (*RemoveRequest) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{4} } + +type RemoveResponse struct { + Ident string `protobuf:"bytes,1,opt,name=ident" json:"ident,omitempty"` +} + +func (m *RemoveResponse) Reset() { *m = RemoveResponse{} } +func (m *RemoveResponse) String() string { return proto.CompactTextString(m) } +func (*RemoveResponse) ProtoMessage() {} +func (*RemoveResponse) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{5} } func init() { - proto.RegisterType((*ServiceCreateRequest)(nil), "service.ServiceCreateRequest") - proto.RegisterType((*ServiceCreateResponse)(nil), "service.ServiceCreateResponse") - proto.RegisterType((*ServiceRemoveRequest)(nil), "service.ServiceRemoveRequest") proto.RegisterType((*ServiceSpec)(nil), "service.ServiceSpec") proto.RegisterType((*PublishSpec)(nil), "service.PublishSpec") + proto.RegisterType((*ServiceCreateRequest)(nil), "service.ServiceCreateRequest") + proto.RegisterType((*ServiceCreateResponse)(nil), "service.ServiceCreateResponse") + proto.RegisterType((*RemoveRequest)(nil), "service.RemoveRequest") + proto.RegisterType((*RemoveResponse)(nil), "service.RemoveResponse") } // Reference imports to suppress errors if they are not otherwise used. @@ -139,6 +150,7 @@ const _ = grpc.SupportPackageIsVersion3 type ServiceClient interface { Create(ctx context.Context, in *ServiceCreateRequest, opts ...grpc.CallOption) (*ServiceCreateResponse, error) + Remove(ctx context.Context, in *RemoveRequest, opts ...grpc.CallOption) (*RemoveResponse, error) } type serviceClient struct { @@ -158,10 +170,20 @@ func (c *serviceClient) Create(ctx context.Context, in *ServiceCreateRequest, op return out, nil } +func (c *serviceClient) Remove(ctx context.Context, in *RemoveRequest, opts ...grpc.CallOption) (*RemoveResponse, error) { + out := new(RemoveResponse) + err := grpc.Invoke(ctx, "/service.Service/Remove", in, out, c.cc, opts...) + if err != nil { + return nil, err + } + return out, nil +} + // Server API for Service service type ServiceServer interface { Create(context.Context, *ServiceCreateRequest) (*ServiceCreateResponse, error) + Remove(context.Context, *RemoveRequest) (*RemoveResponse, error) } func RegisterServiceServer(s *grpc.Server, srv ServiceServer) { @@ -186,6 +208,24 @@ func _Service_Create_Handler(srv interface{}, ctx context.Context, dec func(inte return interceptor(ctx, in, info, handler) } +func _Service_Remove_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(RemoveRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ServiceServer).Remove(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/service.Service/Remove", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ServiceServer).Remove(ctx, req.(*RemoveRequest)) + } + return interceptor(ctx, in, info, handler) +} + var _Service_serviceDesc = grpc.ServiceDesc{ ServiceName: "service.Service", HandlerType: (*ServiceServer)(nil), @@ -194,6 +234,10 @@ var _Service_serviceDesc = grpc.ServiceDesc{ MethodName: "Create", Handler: _Service_Create_Handler, }, + { + MethodName: "Remove", + Handler: _Service_Remove_Handler, + }, }, Streams: []grpc.StreamDesc{}, Metadata: fileDescriptor0, @@ -204,34 +248,35 @@ func init() { } var fileDescriptor0 = []byte{ - // 449 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0x94, 0x53, 0x5d, 0x6b, 0xdb, 0x30, - 0x14, 0x9d, 0xe3, 0x34, 0x59, 0xae, 0x93, 0xad, 0x88, 0x0c, 0x4c, 0xa0, 0xc3, 0xf3, 0x1e, 0x96, - 0xbd, 0xc4, 0x90, 0x31, 0xd6, 0xec, 0x71, 0x65, 0x0f, 0x85, 0xc1, 0x8a, 0xdb, 0xf7, 0xa0, 0x28, - 0x97, 0x56, 0xcc, 0x96, 0x34, 0x49, 0x09, 0xf4, 0x07, 0xec, 0xf7, 0xec, 0x2f, 0x0e, 0xcb, 0xb2, - 0xe3, 0x94, 0xec, 0xa1, 0x4f, 0xb9, 0xe7, 0xea, 0xe4, 0xdc, 0x8f, 0x73, 0x0d, 0xab, 0x7b, 0x6e, - 0x1f, 0x76, 0x9b, 0x05, 0x93, 0x65, 0x46, 0x95, 0x62, 0x58, 0xa0, 0xa6, 0x56, 0xea, 0x8c, 0x96, - 0x2a, 0xa3, 0x8a, 0x67, 0x5a, 0xb1, 0xcc, 0xa0, 0xde, 0x73, 0x86, 0xcd, 0xef, 0x42, 0x69, 0x69, - 0x25, 0x19, 0x7a, 0x98, 0xfe, 0x84, 0xe9, 0x6d, 0x1d, 0x5e, 0x69, 0xa4, 0x16, 0x73, 0xfc, 0xbd, - 0x43, 0x63, 0xc9, 0x17, 0x18, 0x7b, 0xca, 0xda, 0x28, 0x64, 0x71, 0x90, 0x04, 0xf3, 0x68, 0x39, - 0x5d, 0x34, 0x32,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 0x3e, 0xfa, 0x7d, 0x55, 0x61, 0xb5, 0xc3, - 0x3d, 0x2d, 0x76, 0xcd, 0xba, 0x6a, 0xf0, 0xb5, 0x77, 0x19, 0xcc, 0xbe, 0xc1, 0xf4, 0x54, 0x7b, - 0xcf, 0xd1, 0x48, 0xff, 0x04, 0x10, 0x75, 0x9a, 0x6b, 0xbd, 0x09, 0x8e, 0xbd, 0x71, 0x87, 0xc9, - 0x64, 0xe1, 0x05, 0x5a, 0x4c, 0xde, 0x41, 0x33, 0xce, 0x5a, 0x49, 0x6d, 0x9d, 0x77, 0x93, 0x3c, - 0xf2, 0xb9, 0x1b, 0xa9, 0x2d, 0x79, 0x0f, 0x13, 0x2e, 0x2c, 0x6a, 0x41, 0x8b, 0x9a, 0xd3, 0x77, - 0x9c, 0x71, 0x93, 0xac, 0x48, 0xcb, 0x3b, 0x18, 0xfa, 0xb5, 0x93, 0x6b, 0x18, 0xd4, 0xd7, 0x49, - 0x2e, 0x9e, 0x5a, 0x72, 0xf4, 0x19, 0xcc, 0xde, 0xfe, 0xef, 0xb9, 0x3e, 0xea, 0xf4, 0xc5, 0x66, - 0xe0, 0xfa, 0xfc, 0xf4, 0x2f, 0x00, 0x00, 0xff, 0xff, 0x3d, 0x21, 0xe4, 0xff, 0x8d, 0x03, 0x00, - 0x00, + // 476 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0x94, 0x52, 0xc1, 0x6e, 0xd3, 0x40, + 0x10, 0xc5, 0x71, 0xea, 0xd0, 0x71, 0x52, 0xaa, 0x55, 0x00, 0xcb, 0x12, 0xc8, 0x18, 0x01, 0xe1, + 0x12, 0x4b, 0xe5, 0x40, 0x03, 0x37, 0x2a, 0x0e, 0x48, 0x48, 0x54, 0x2e, 0xf7, 0x68, 0xb3, 0x19, + 0xb5, 0x2b, 0x6c, 0xef, 0xb2, 0xbb, 0x89, 0xd4, 0x0f, 0xe0, 0x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0x2f, 0x10, 0x34, 0xc3, 0xc9, 0xb3, 0xfd, 0x85, 0x77, 0xae, + 0x8c, 0x9f, 0xff, 0xef, 0x73, 0x33, 0x2a, 0x7d, 0x40, 0x3e, 0x42, 0xd0, 0x8c, 0x27, 0x4f, 0x3a, + 0xee, 0xce, 0xda, 0xf1, 0xd3, 0x7f, 0xfa, 0xed, 0x9f, 0x57, 0x81, 0x8d, 0xeb, 0xdd, 0xdf, 0x00, + 0x00, 0x00, 0xff, 0xff, 0x3b, 0xd3, 0xd5, 0x30, 0xe3, 0x03, 0x00, 0x00, } diff --git a/api/rpc/service/service.proto b/api/rpc/service/service.proto index 8b39a1fe3..30c03b12f 100644 --- a/api/rpc/service/service.proto +++ b/api/rpc/service/service.proto @@ -2,23 +2,6 @@ syntax = "proto3"; package service; -service Service { - rpc Create (ServiceCreateRequest) returns (ServiceCreateResponse) {} -} - -message ServiceCreateRequest { - ServiceSpec service_spec = 1; -} - -message ServiceCreateResponse { - string id = 1; -} - -message ServiceRemoveRequest { - string service_id = 1; -} - - message ServiceSpec { string image = 1; string name = 2; @@ -35,3 +18,25 @@ message PublishSpec { uint32 publish_port = 3; uint32 internal_port = 4; } + +message ServiceCreateRequest { + ServiceSpec service_spec = 1; +} + +message ServiceCreateResponse { + string id = 1; +} + +message RemoveRequest { + string ident = 1; +} + +message RemoveResponse { + string ident = 1; +} + + +service Service { + rpc Create (ServiceCreateRequest) returns (ServiceCreateResponse) {} + rpc Remove (RemoveRequest) returns (RemoveResponse) {} +} diff --git a/api/rpc/stack/stack.go b/api/rpc/stack/stack.go index 82ea536ab..3121a67af 100644 --- a/api/rpc/stack/stack.go +++ b/api/rpc/stack/stack.go @@ -86,10 +86,9 @@ func (s *Server) getStack(ctx context.Context, in *StackRequest) (*Stack, error) // clean up if error happended during stack creation, delete all created services and all etcd data func (s *Server) rollbackServiceStack(ctx context.Context, stackID string, serviceIDList []string) { fmt.Printf("removing created services %s\n", stackID) - server := service.Service{} for _, ID := range serviceIDList { if ID != "" { - server.Remove(ctx, ID) + service.Remove(ctx, ID) s.Store.Delete(ctx, path.Join(servicesRootKey, ID), true, nil) } } @@ -207,7 +206,6 @@ func (s *Server) Stop(ctx context.Context, in *StackRequest) (*StackReply, error } func (s *Server) stopStackServices(ctx context.Context, ID string, force bool) error { - server := service.Service{} listKeys := &ServiceIdList{} err := s.Store.Get(ctx, path.Join(stackRootKey, ID, servicesRootKey), listKeys, true) if err != nil && !force { @@ -215,7 +213,7 @@ func (s *Server) stopStackServices(ctx context.Context, ID string, force bool) e } var removeErr error for _, key := range listKeys.List { - err := server.Remove(ctx, key) + err := service.Remove(ctx, key) if err != nil { removeErr = err } diff --git a/cmd/amp/service-create.go b/cmd/amp/service-create.go index f49ef7597..61e937b49 100644 --- a/cmd/amp/service-create.go +++ b/cmd/amp/service-create.go @@ -13,7 +13,7 @@ import ( var ( createCmd = &cobra.Command{ Use: "create [OPTIONS] IMAGE [CMD] [ARG...]", - Short: "Create a service", + Short: "Create a new service", Long: `Create a new service`, Run: func(cmd *cobra.Command, args []string) { err := create(AMP, cmd, args) diff --git a/cmd/amp/service-rm.go b/cmd/amp/service-rm.go new file mode 100644 index 000000000..54c8195e1 --- /dev/null +++ b/cmd/amp/service-rm.go @@ -0,0 +1,65 @@ +package main + +import ( + "fmt" + "strings" + + "github.com/appcelerator/amp/api/client" + "github.com/appcelerator/amp/api/rpc/service" + "github.com/spf13/cobra" + "golang.org/x/net/context" +) + +var ( + // TODO: add support for 'remove' alias + serviceRmCmd = &cobra.Command{ + Use: "rm [OPTIONS] SERVICE [SERVICE...]", + Short: "Remove one or more services", + Long: `Remove one or more services`, + Run: func(cmd *cobra.Command, args []string) { + err := rm(AMP, cmd, args) + if err != nil { + fmt.Println(err) + } + }, + } + + // services to remove + services []string +) + +func init() { + ServiceCmd.AddCommand(serviceRmCmd) +} + +func rm(amp *client.AMP, cmd *cobra.Command, args []string) error { + if len(args) < 1 { + // TODO use standard errors and print usage + return fmt.Errorf("\"amp service rm\" requires at least 1 argument(s)") + } + + client := service.NewServiceClient(amp.Conn) + + for _, ident := range args { + req := &service.RemoveRequest{ + Ident: ident, + } + + resp, err := client.Remove(context.Background(), req) + if err != nil { + pattern := "daemon: " + errstr := fmt.Sprintf("%s", err) + index := strings.LastIndex(errstr, pattern) + if index > -1 { + errmsg := fmt.Sprintf("Error: %s", errstr[index+len(pattern):]) + fmt.Println(errmsg) + } else { + fmt.Printf("Error: %s\n", err) + } + } else { + fmt.Println(resp.Ident) + } + } + + return nil +}