Skip to content

Commit

Permalink
refactor service deploy statuses flags, closes #487
Browse files Browse the repository at this point in the history
  • Loading branch information
ilgooz committed Sep 21, 2018
1 parent 3dbd069 commit dd0a5d7
Show file tree
Hide file tree
Showing 10 changed files with 275 additions and 255 deletions.
19 changes: 11 additions & 8 deletions api/deploy.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package api

import (
"fmt"
"io"
"io/ioutil"
"os"
"path/filepath"

"github.com/logrusorgru/aurora"
"github.com/mesg-foundation/core/database/services"
"github.com/mesg-foundation/core/service"
"github.com/mesg-foundation/core/service/importer"
Expand Down Expand Up @@ -55,11 +53,14 @@ type StatusType int
const (
_ StatusType = iota // skip zero value.

// RUNNING indicates that status message belongs to an active state.
// RUNNING indicates that status message belongs to a continuous state.
RUNNING

// DONE indicates that status message belongs to completed state.
DONE
// DONE_POSITIVE indicates that status message belongs to a positive noncontinuous state.
DONE_POSITIVE

// DONE_NEGATIVE indicates that status message belongs to a negative noncontinuous state.
DONE_NEGATIVE
)

// DeployStatus represents the deployment status.
Expand Down Expand Up @@ -97,7 +98,7 @@ func (d *serviceDeployer) FromGitURL(url string) (*service.Service, *importer.Va
return nil, nil, err
}

d.sendStatus(fmt.Sprintf("%s Service downloaded with success.", aurora.Green("✔")), DONE)
d.sendStatus("Service downloaded with success.", DONE_POSITIVE)
r, err := xarchive.GzippedTar(path)
if err != nil {
return nil, nil, err
Expand Down Expand Up @@ -150,8 +151,10 @@ func (d *serviceDeployer) forwardDeployStatuses(statuses chan service.DeployStat
switch status.Type {
case service.DRUNNING:
t = RUNNING
case service.DDONE:
t = DONE
case service.DDONE_POSITIVE:
t = DONE_POSITIVE
case service.DDONE_NEGATIVE:
t = DONE_NEGATIVE
}
d.sendStatus(status.Message, t)
}
Expand Down
38 changes: 18 additions & 20 deletions api/deploy_test.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
package api

import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strings"
"sync"
"testing"

"github.com/logrusorgru/aurora"
"github.com/mesg-foundation/core/service/importer"
"github.com/mesg-foundation/core/x/xdocker/xarchive"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -43,13 +41,13 @@ func TestDeployService(t *testing.T) {
}, <-statuses)

require.Equal(t, DeployStatus{
Message: fmt.Sprintf("%s Service context received with success.", aurora.Green("✔")),
Type: DONE,
Message: "Service context received with success.",
Type: DONE_POSITIVE,
}, <-statuses)

require.Equal(t, DeployStatus{
Message: fmt.Sprintf("%s [DEPRECATED] Please use .dockerignore instead of .mesgignore", aurora.Red("⨯")),
Type: DONE,
Message: "[DEPRECATED] Please use .dockerignore instead of .mesgignore",
Type: DONE_NEGATIVE,
}, <-statuses)

require.Equal(t, DeployStatus{
Expand All @@ -58,13 +56,13 @@ func TestDeployService(t *testing.T) {
}, <-statuses)

require.Equal(t, DeployStatus{
Message: fmt.Sprintf("%s Image built with success.", aurora.Green("✔")),
Type: DONE,
Message: "Image built with success.",
Type: DONE_POSITIVE,
}, <-statuses)

require.Equal(t, DeployStatus{
Message: fmt.Sprintf("%s Service deployed.", aurora.Green("✔")),
Type: DONE,
Message: "Service deployed.",
Type: DONE_POSITIVE,
}, <-statuses)

wg.Wait()
Expand Down Expand Up @@ -98,8 +96,8 @@ func TestDeployInvalidService(t *testing.T) {
}, <-statuses)

require.Equal(t, DeployStatus{
Message: fmt.Sprintf("%s Service context received with success.", aurora.Green("✔")),
Type: DONE,
Message: "Service context received with success.",
Type: DONE_POSITIVE,
}, <-statuses)

select {
Expand Down Expand Up @@ -135,8 +133,8 @@ func TestDeployServiceFromURL(t *testing.T) {
}, <-statuses)

require.Equal(t, DeployStatus{
Message: fmt.Sprintf("%s Service downloaded with success.", aurora.Green("✔")),
Type: DONE,
Message: "Service downloaded with success.",
Type: DONE_POSITIVE,
}, <-statuses)

require.Equal(t, DeployStatus{
Expand All @@ -145,8 +143,8 @@ func TestDeployServiceFromURL(t *testing.T) {
}, <-statuses)

require.Equal(t, DeployStatus{
Message: fmt.Sprintf("%s Service context received with success.", aurora.Green("✔")),
Type: DONE,
Message: "Service context received with success.",
Type: DONE_POSITIVE,
}, <-statuses)

require.Equal(t, DeployStatus{
Expand All @@ -155,13 +153,13 @@ func TestDeployServiceFromURL(t *testing.T) {
}, <-statuses)

require.Equal(t, DeployStatus{
Message: fmt.Sprintf("%s Image built with success.", aurora.Green("✔")),
Type: DONE,
Message: "Image built with success.",
Type: DONE_POSITIVE,
}, <-statuses)

require.Equal(t, DeployStatus{
Message: fmt.Sprintf("%s Service deployed.", aurora.Green("✔")),
Type: DONE,
Message: "Service deployed.",
Type: DONE_POSITIVE,
}, <-statuses)

wg.Wait()
Expand Down
30 changes: 17 additions & 13 deletions commands/provider/service_deployer.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,14 @@ type StatusType int
const (
_ StatusType = iota // skip zero value.

// RUNNING indicates that status message belongs to an active state.
// RUNNING indicates that status message belongs to a continuous state.
RUNNING

// DONE indicates that status message belongs to completed state.
DONE
// DONE_POSITIVE indicates that status message belongs to a positive noncontinuous state.
DONE_POSITIVE

// DONE_NEGATIVE indicates that status message belongs to a negative noncontinuous state.
DONE_NEGATIVE
)

// DeployStatus represents the deployment status.
Expand Down Expand Up @@ -116,20 +119,21 @@ func readDeployReply(stream coreapi.Core_DeployServiceClient, deployment chan de

switch {
case status != nil:
s := DeployStatus{
Message: status.Message,
}

switch status.Type {
case coreapi.DeployServiceReply_Status_RUNNING:
statuses <- DeployStatus{
Message: status.Message,
Type: RUNNING,
}

case coreapi.DeployServiceReply_Status_DONE:
statuses <- DeployStatus{
Message: status.Message,
Type: DONE,
}
s.Type = RUNNING
case coreapi.DeployServiceReply_Status_DONE_POSITIVE:
s.Type = DONE_POSITIVE
case coreapi.DeployServiceReply_Status_DONE_NEGATIVE:
s.Type = DONE_NEGATIVE
}

statuses <- s

case serviceID != "":
result.serviceID = serviceID
deployment <- result
Expand Down
11 changes: 9 additions & 2 deletions commands/service_deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,16 @@ func printDeployStatuses(statuses chan provider.DeployStatus) {
switch status.Type {
case provider.RUNNING:
pretty.UseSpinner(status.Message)
case provider.DONE:
default:
var sign string
switch status.Type {
case provider.DONE_POSITIVE:
sign = pretty.SuccessSign
case provider.DONE_NEGATIVE:
sign = pretty.FailSign
}
pretty.DestroySpinner()
fmt.Println(status.Message)
fmt.Printf("%s %s\n", sign, status.Message)
}
}
}
6 changes: 4 additions & 2 deletions interface/grpc/core/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,10 @@ func sendDeployStatus(statuses chan api.DeployStatus, stream coreapi.Core_Deploy
switch status.Type {
case api.RUNNING:
typ = coreapi.DeployServiceReply_Status_RUNNING
case api.DONE:
typ = coreapi.DeployServiceReply_Status_DONE
case api.DONE_POSITIVE:
typ = coreapi.DeployServiceReply_Status_DONE_POSITIVE
case api.DONE_NEGATIVE:
typ = coreapi.DeployServiceReply_Status_DONE_NEGATIVE
}

stream.Send(&coreapi.DeployServiceReply{
Expand Down
12 changes: 6 additions & 6 deletions interface/grpc/core/deploy_test.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package core

import (
"fmt"
"io/ioutil"
"strings"
"testing"

"github.com/logrusorgru/aurora"
"github.com/mesg-foundation/core/api"
"github.com/mesg-foundation/core/protobuf/coreapi"
"github.com/stretchr/testify/require"
Expand All @@ -24,8 +22,8 @@ func TestDeployService(t *testing.T) {
require.Len(t, stream.serviceID, 40)

require.Contains(t, stream.statuses, api.DeployStatus{
Message: fmt.Sprintf("%s Service deployed.", aurora.Green("✔")),
Type: api.DONE,
Message: "Service deployed.",
Type: api.DONE_POSITIVE,
})
}

Expand All @@ -51,8 +49,10 @@ func (s *testDeployStream) Send(m *coreapi.DeployServiceReply) error {
switch status.Type {
case coreapi.DeployServiceReply_Status_RUNNING:
typ = api.RUNNING
case coreapi.DeployServiceReply_Status_DONE:
typ = api.DONE
case coreapi.DeployServiceReply_Status_DONE_POSITIVE:
typ = api.DONE_POSITIVE
case coreapi.DeployServiceReply_Status_DONE_NEGATIVE:
typ = api.DONE_NEGATIVE
}
s.statuses = append(s.statuses, api.DeployStatus{
Message: status.Message,
Expand Down
Loading

0 comments on commit dd0a5d7

Please sign in to comment.