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

Decentralization of the processes #1527

Merged
merged 12 commits into from
Dec 11, 2019
14 changes: 1 addition & 13 deletions core/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"github.com/mesg-foundation/engine/config"
"github.com/mesg-foundation/engine/container"
"github.com/mesg-foundation/engine/cosmos"
"github.com/mesg-foundation/engine/database"
"github.com/mesg-foundation/engine/hash"
"github.com/mesg-foundation/engine/logger"
"github.com/mesg-foundation/engine/orchestrator"
Expand All @@ -28,11 +27,6 @@ import (
db "github.com/tendermint/tm-db"
)

func initDatabases(cfg *config.Config) (*database.LevelDBProcessDB, error) {
// init process db.
return database.NewProcessDB(filepath.Join(cfg.Path, cfg.Database.ProcessRelativePath))
}

func stopRunningServices(sdk *enginesdk.SDK, cfg *config.Config, address string) error {
runners, err := sdk.Runner.List(&runnersdk.Filter{Address: address})
if err != nil {
Expand Down Expand Up @@ -125,12 +119,6 @@ func main() {
// init logger.
logger.Init(cfg.Log.Format, cfg.Log.Level, cfg.Log.ForceColors)

// init databases
processDB, err := initDatabases(cfg)
if err != nil {
logrus.WithField("module", "main").Fatalln(err)
}

// init container.
container, err := container.New(cfg.Name)
if err != nil {
Expand Down Expand Up @@ -185,7 +173,7 @@ func main() {
client := cosmos.NewClient(node, kb, genesis.ChainID)

// init sdk
sdk := enginesdk.New(client, kb, processDB, container, cfg.Name, strconv.Itoa(port), cfg.IpfsEndpoint)
sdk := enginesdk.New(client, kb, container, cfg.Name, strconv.Itoa(port), cfg.IpfsEndpoint)

// start tendermint node
logrus.WithField("module", "main").WithField("seeds", cfg.Tendermint.Config.P2P.Seeds).Info("starting tendermint node")
Expand Down
128 changes: 0 additions & 128 deletions database/process_db.go

This file was deleted.

1 change: 0 additions & 1 deletion e2e/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ func TestAPI(t *testing.T) {
// basic tests
t.Run("account", testAccount)
t.Run("service", testService)
t.Run("ownership", testOwnership)
t.Run("runner", testRunner)
t.Run("process", testProcess)
t.Run("instance", testInstance)
Expand Down
32 changes: 0 additions & 32 deletions e2e/ownership_test.go

This file was deleted.

71 changes: 48 additions & 23 deletions e2e/process_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"testing"

"github.com/mesg-foundation/engine/hash"
"github.com/mesg-foundation/engine/ownership"
"github.com/mesg-foundation/engine/process"
pb "github.com/mesg-foundation/engine/protobuf/api"
"github.com/stretchr/testify/require"
Expand All @@ -13,41 +14,45 @@ import (
var testProcessHash hash.Hash

func testProcess(t *testing.T) {
req := &pb.CreateProcessRequest{
Name: "test-process",
Nodes: []*process.Process_Node{
{
Key: "n0",
Type: &process.Process_Node_Event_{
Event: &process.Process_Node_Event{
InstanceHash: testInstanceHash,
EventKey: "test_service_ready",
var (
processHash hash.Hash
req = &pb.CreateProcessRequest{
Name: "test-process",
Nodes: []*process.Process_Node{
{
Key: "n0",
Type: &process.Process_Node_Event_{
Event: &process.Process_Node_Event{
InstanceHash: testInstanceHash,
EventKey: "test_service_ready",
},
},
},
},
{
Key: "n1",
Type: &process.Process_Node_Task_{
Task: &process.Process_Node_Task{
InstanceHash: testInstanceHash,
TaskKey: "test_service_ready",
{
Key: "n1",
Type: &process.Process_Node_Task_{
Task: &process.Process_Node_Task{
InstanceHash: testInstanceHash,
TaskKey: "test_service_ready",
},
},
},
},
},
Edges: []*process.Process_Edge{
{
Src: "n0",
Dst: "n1",
Edges: []*process.Process_Edge{
{
Src: "n0",
Dst: "n1",
},
},
},
}
}
)

t.Run("create", func(t *testing.T) {
resp, err := client.ProcessClient.Create(context.Background(), req)
require.NoError(t, err)
testProcessHash = resp.Hash
})

t.Run("get", func(t *testing.T) {
p, err := client.ProcessClient.Get(context.Background(), &pb.GetProcessRequest{Hash: testProcessHash})
require.NoError(t, err)
Expand All @@ -57,6 +62,20 @@ func testProcess(t *testing.T) {
Nodes: req.Nodes,
Edges: req.Edges,
}))
processHash = p.Hash
})

t.Run("check ownership creation", func(t *testing.T) {
ownerships, err := client.OwnershipClient.List(context.Background(), &pb.ListOwnershipRequest{})
require.NoError(t, err)

acc, err := client.AccountClient.Get(context.Background(), &pb.GetAccountRequest{Name: "engine"})
require.NoError(t, err)

require.Len(t, ownerships.Ownerships, 2)
require.Equal(t, acc.Address, ownerships.Ownerships[0].Owner)
require.Equal(t, ownership.Ownership_Process, ownerships.Ownerships[0].Resource)
require.Equal(t, processHash, ownerships.Ownerships[0].ResourceHash)
})

t.Run("list", func(t *testing.T) {
Expand All @@ -69,4 +88,10 @@ func testProcess(t *testing.T) {
_, err := client.ProcessClient.Delete(context.Background(), &pb.DeleteProcessRequest{Hash: testProcessHash})
require.NoError(t, err)
})

t.Run("check ownership deletion", func(t *testing.T) {
ownerships, err := client.OwnershipClient.List(context.Background(), &pb.ListOwnershipRequest{})
require.NoError(t, err)
require.Len(t, ownerships.Ownerships, 1)
})
}
14 changes: 14 additions & 0 deletions e2e/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"testing"

"github.com/mesg-foundation/engine/hash"
"github.com/mesg-foundation/engine/ownership"
pb "github.com/mesg-foundation/engine/protobuf/api"
"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -47,4 +48,17 @@ func testService(t *testing.T) {
require.NoError(t, err)
require.Equal(t, testServiceHash, resp.Hash)
})

t.Run("check ownership creation", func(t *testing.T) {
ownerships, err := client.OwnershipClient.List(context.Background(), &pb.ListOwnershipRequest{})
require.NoError(t, err)

acc, err := client.AccountClient.Get(context.Background(), &pb.GetAccountRequest{Name: "engine"})
require.NoError(t, err)

require.Len(t, ownerships.Ownerships, 1)
require.Equal(t, acc.Address, ownerships.Ownerships[0].Owner)
require.Equal(t, ownership.Ownership_Service, ownerships.Ownerships[0].Resource)
require.Equal(t, testServiceHash, ownerships.Ownerships[0].ResourceHash)
})
}
8 changes: 0 additions & 8 deletions ownership/codec.go

This file was deleted.

Loading