Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Service rm #253

Merged
merged 3 commits into from
Sep 26, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions api/rpc/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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)
}
189 changes: 117 additions & 72 deletions api/rpc/service/service.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 22 additions & 17 deletions api/rpc/service/service.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why ident instead of id?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

making it clear it can be an ID, short ID, or name. Actually, that was something that @freignat91 recommended. I have no problem calling it id, which matches docker docs.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds fine, it could use a comment to make that clear.

follow up: should RemoveResponse return an ident instead of an id?

}

message RemoveResponse {
string ident = 1;
}


service Service {
rpc Create (ServiceCreateRequest) returns (ServiceCreateResponse) {}
rpc Remove (RemoveRequest) returns (RemoveResponse) {}
}
6 changes: 2 additions & 4 deletions api/rpc/stack/stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down Expand Up @@ -207,15 +206,14 @@ 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 {
return err
}
var removeErr error
for _, key := range listKeys.List {
err := server.Remove(ctx, key)
err := service.Remove(ctx, key)
if err != nil {
removeErr = err
}
Expand Down
7 changes: 7 additions & 0 deletions api/rpc/stack/test_samples/sample-05-labels.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
pinger:
image: appcelerator/pinger
labels:
- "foo=bar"
public:
- publish_port: 3000
internal_port: 3000
7 changes: 7 additions & 0 deletions api/rpc/stack/test_samples/sample-06-labels.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
pinger:
image: appcelerator/pinger
labels:
foo: bar
public:
- publish_port: 3000
internal_port: 3000
Loading