Skip to content

Commit

Permalink
Merge branch 'dev' into ss/marketplace-better-object-def
Browse files Browse the repository at this point in the history
  • Loading branch information
NicolasMahe committed Apr 16, 2019
2 parents 85c10e6 + 6a42f33 commit 05dfa94
Show file tree
Hide file tree
Showing 36 changed files with 662 additions and 437 deletions.
27 changes: 5 additions & 22 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,29 +19,12 @@ type API struct {
container container.Container
}

// Option is a configuration func for MESG.
type Option func(*API)

// New creates a new API with given options.
func New(db database.ServiceDB, execDB database.ExecutionDB, options ...Option) (*API, error) {
a := &API{db: db, execDB: execDB}
for _, option := range options {
option(a)
}
if a.container == nil {
var err error
a.container, err = container.New()
if err != nil {
return nil, err
}
}
return a, nil
}

// ContainerOption configures underlying container access API.
func ContainerOption(container container.Container) Option {
return func(a *API) {
a.container = container
func New(c container.Container, db database.ServiceDB, execDB database.ExecutionDB) *API {
return &API{
container: c,
db: db,
execDB: execDB,
}
}

Expand Down
3 changes: 1 addition & 2 deletions api/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ func newTesting(t *testing.T) (*API, *apiTesting) {
execDB, err := database.NewExecutionDB(execdbname)
require.NoError(t, err)

a, err := New(db, execDB, ContainerOption(containerMock))
require.NoError(t, err)
a := New(containerMock, db, execDB)

return a, &apiTesting{
T: t,
Expand Down
2 changes: 2 additions & 0 deletions commands/provider/service_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/mesg-foundation/core/commands/provider/assets"
"github.com/mesg-foundation/core/protobuf/acknowledgement"
"github.com/mesg-foundation/core/protobuf/coreapi"
"github.com/mesg-foundation/core/service"
"github.com/mesg-foundation/core/service/importer"
"github.com/mesg-foundation/core/utils/chunker"
"github.com/mesg-foundation/core/utils/pretty"
Expand Down Expand Up @@ -117,6 +118,7 @@ func (p *ServiceProvider) ServiceLogs(id string, dependencies ...string) (logs [
if err != nil {
return nil, nil, nil, err
}
dependencies = append(dependencies, service.MainServiceKey)
for _, dep := range resp.Service.Definition.Dependencies {
dependencies = append(dependencies, dep.Key)
}
Expand Down
2 changes: 2 additions & 0 deletions commands/service_logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"strings"

"github.com/mesg-foundation/core/commands/provider"
"github.com/mesg-foundation/core/service"
"github.com/mesg-foundation/core/utils/pretty"
"github.com/mesg-foundation/core/x/xsignal"
"github.com/mesg-foundation/core/x/xstrings"
Expand Down Expand Up @@ -69,6 +70,7 @@ func showLogs(e ServiceExecutor, serviceID string, dependencies ...string) (clos
// if there was no dependencies copy all returned
// by service logs.
if len(dependencies) == 0 {
dependencies = append(dependencies, service.MainServiceKey)
for _, log := range logs {
dependencies = append(dependencies, log.Dependency)
}
Expand Down
5 changes: 1 addition & 4 deletions core/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,7 @@ func initDependencies() (*dependencies, error) {
}

// init api.
api, err := api.New(serviceDB, executionDB, api.ContainerOption(c))
if err != nil {
return nil, err
}
api := api.New(c, serviceDB, executionDB)

return &dependencies{
config: config,
Expand Down
3 changes: 2 additions & 1 deletion interface/grpc/core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package core
import (
"context"
"encoding/json"
"fmt"
"sync"

"github.com/mesg-foundation/core/api"
Expand Down Expand Up @@ -188,7 +189,7 @@ func (s *Server) ListenResult(request *coreapi.ListenResultRequest, stream corea
func (s *Server) ExecuteTask(ctx context.Context, request *coreapi.ExecuteTaskRequest) (*coreapi.ExecuteTaskReply, error) {
var inputs map[string]interface{}
if err := json.Unmarshal([]byte(request.InputData), &inputs); err != nil {
return nil, err
return nil, fmt.Errorf("cannot parse execution's inputs (JSON format): %s", err)
}

executionID, err := s.api.ExecuteTask(request.ServiceID, request.TaskKey, inputs, request.ExecutionTags)
Expand Down
2 changes: 1 addition & 1 deletion interface/grpc/core/core_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ func TestExecuteWithInvalidJSON(t *testing.T) {
InputData: "",
})
require.Error(t, err)
require.Equal(t, err.Error(), "unexpected end of JSON input")
require.Equal(t, err.Error(), "cannot parse execution's inputs (JSON format): unexpected end of JSON input")
}

func TestExecuteWithInvalidTask(t *testing.T) {
Expand Down
32 changes: 23 additions & 9 deletions interface/grpc/core/proto.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@ func toProtoServices(ss []*service.Service) []*definition.Service {

func toProtoService(s *service.Service) *definition.Service {
return &definition.Service{
Hash: s.Hash,
Sid: s.Sid,
Name: s.Name,
Description: s.Description,
Repository: s.Repository,
Tasks: toProtoTasks(s.Tasks),
Events: toProtoEvents(s.Events),
Dependencies: toProtoDependencies(s.Dependencies),
Hash: s.Hash,
Sid: s.Sid,
Name: s.Name,
Description: s.Description,
Repository: s.Repository,
Tasks: toProtoTasks(s.Tasks),
Events: toProtoEvents(s.Events),
Configuration: toProtoConfiguration(s.Configuration),
Dependencies: toProtoDependencies(s.Dependencies),
}
}

Expand Down Expand Up @@ -95,6 +96,19 @@ func toProtoParameters(params []*service.Parameter) []*definition.Parameter {
return ps
}

func toProtoConfiguration(configuration *service.Dependency) *definition.Configuration {
if configuration == nil {
return nil
}
return &definition.Configuration{
Args: configuration.Args,
Command: configuration.Command,
Ports: configuration.Ports,
Volumes: configuration.Volumes,
VolumesFrom: configuration.VolumesFrom,
}
}

func toProtoDependency(dep *service.Dependency) *definition.Dependency {
if dep == nil {
return nil
Expand All @@ -103,7 +117,7 @@ func toProtoDependency(dep *service.Dependency) *definition.Dependency {
Key: dep.Key,
Image: dep.Image,
Volumes: dep.Volumes,
Volumesfrom: dep.VolumesFrom,
VolumesFrom: dep.VolumesFrom,
Ports: dep.Ports,
Command: dep.Command,
Args: dep.Args,
Expand Down
3 changes: 1 addition & 2 deletions interface/grpc/core/test_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ func newServerWithContainer(t *testing.T, c container.Container) (*Server, func(
execDB, err := database.NewExecutionDB(execdbname)
require.NoError(t, err)

a, err := api.New(db, execDB, api.ContainerOption(c))
require.NoError(t, err)
a := api.New(c, db, execDB)

server := NewServer(a)

Expand Down
4 changes: 3 additions & 1 deletion interface/grpc/service/test_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/docker/docker/pkg/archive"
"github.com/mesg-foundation/core/api"
"github.com/mesg-foundation/core/container"
"github.com/mesg-foundation/core/database"
"github.com/stretchr/testify/require"
)
Expand All @@ -30,9 +31,10 @@ func newServer(t *testing.T) (*Server, func()) {
execDB, err := database.NewExecutionDB(execdbname)
require.NoError(t, err)

a, err := api.New(db, execDB)
c, err := container.New()
require.NoError(t, err)

a := api.New(c, db, execDB)
server := NewServer(a)

closer := func() {
Expand Down
Loading

0 comments on commit 05dfa94

Please sign in to comment.