Skip to content

Commit

Permalink
service sdk: improve namings
Browse files Browse the repository at this point in the history
  • Loading branch information
ilgooz committed Jun 3, 2019
1 parent e181e84 commit f5d8b1b
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 23 deletions.
2 changes: 2 additions & 0 deletions protobuf/api/service.proto
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ 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) {}
}
Expand Down
14 changes: 7 additions & 7 deletions sdk/sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (

// SDK exposes all functionalities of MESG core.
type SDK struct {
ServiceSDK *servicesdk.Service
Service *servicesdk.Service

ps *pubsub.PubSub

Expand All @@ -31,12 +31,12 @@ 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{
ServiceSDK: servicesdk.New(m, c, db, execDB),
ps: pubsub.New(0),
m: m,
container: c,
db: db,
execDB: execDB,
Service: servicesdk.New(m, c, db, execDB),
ps: pubsub.New(0),
m: m,
container: c,
db: db,
execDB: execDB,
}
}

Expand Down
30 changes: 15 additions & 15 deletions server/grpc/api/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,41 +13,41 @@ func FromProtoService(s *definition.Service) *service.Service {
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),
Tasks: fromProtoTasks(s.Tasks),
Events: fromProtoEvents(s.Events),
Configuration: fromProtoConfiguration(s.Configuration),
Dependencies: fromProtoDependencies(s.Dependencies),
}
}

func FromProtoTasks(tasks []*definition.Task) []*service.Task {
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),
Inputs: fromProtoParameters(task.Inputs),
Outputs: fromProtoParameters(task.Outputs),
}
}
return ts
}

func FromProtoEvents(events []*definition.Event) []*service.Event {
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),
Data: fromProtoParameters(event.Data),
}
}
return es
}

func FromProtoParameters(params []*definition.Parameter) []*service.Parameter {
func fromProtoParameters(params []*definition.Parameter) []*service.Parameter {
ps := make([]*service.Parameter, len(params))
for i, param := range params {
ps[i] = &service.Parameter{
Expand All @@ -57,13 +57,13 @@ func FromProtoParameters(params []*definition.Parameter) []*service.Parameter {
Type: param.Type,
Repeated: param.Repeated,
Optional: param.Optional,
Object: FromProtoParameters(param.Object),
Object: fromProtoParameters(param.Object),
}
}
return ps
}

func FromProtoConfiguration(configuration *definition.Configuration) *service.Dependency {
func fromProtoConfiguration(configuration *definition.Configuration) *service.Dependency {
if configuration == nil {
return nil
}
Expand All @@ -76,7 +76,7 @@ func FromProtoConfiguration(configuration *definition.Configuration) *service.De
}
}

func FromProtoDependency(dep *definition.Dependency) *service.Dependency {
func fromProtoDependency(dep *definition.Dependency) *service.Dependency {
if dep == nil {
return nil
}
Expand All @@ -91,10 +91,10 @@ func FromProtoDependency(dep *definition.Dependency) *service.Dependency {
}
}

func FromProtoDependencies(deps []*definition.Dependency) []*service.Dependency {
func fromProtoDependencies(deps []*definition.Dependency) []*service.Dependency {
ds := make([]*service.Dependency, len(deps))
for i, dep := range deps {
ds[i] = FromProtoDependency(dep)
ds[i] = fromProtoDependency(dep)
}
return ds
}
2 changes: 1 addition & 1 deletion server/grpc/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func NewServiceServer(sdk *sdk.SDK) *ServiceServer {
// 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.ServiceSDK.Create(srv); err != nil {
if err := s.sdk.Service.Create(srv); err != nil {
return nil, err
}
return &protobuf_api.CreateServiceResponse{Sid: srv.Sid, Hash: srv.Hash}, nil
Expand Down

0 comments on commit f5d8b1b

Please sign in to comment.