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

refactor service deploy statuses flags, closes #487 #490

Merged
merged 2 commits into from
Sep 24, 2018
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
27 changes: 15 additions & 12 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
// Running indicates that status message belongs to a continuous state.
Running

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

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

// DeployStatus represents the deployment status.
Expand All @@ -81,7 +82,7 @@ func newServiceDeployer(api *API, options ...DeployServiceOption) *serviceDeploy

// FromGitURL deploys a service hosted at a Git url.
func (d *serviceDeployer) FromGitURL(url string) (*service.Service, *importer.ValidationError, error) {
d.sendStatus("Downloading service...", RUNNING)
d.sendStatus("Downloading service...", Running)
path, err := d.createTempDir()
if err != nil {
return nil, nil, err
Expand All @@ -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.", DonePositive)
r, err := xarchive.GzippedTar(path)
if err != nil {
return nil, nil, err
Expand Down Expand Up @@ -148,10 +149,12 @@ func (d *serviceDeployer) forwardDeployStatuses(statuses chan service.DeployStat
for status := range statuses {
var t StatusType
switch status.Type {
case service.DRUNNING:
t = RUNNING
case service.DDONE:
t = DONE
case service.DRunning:
t = Running
case service.DDonePositive:
t = DonePositive
case service.DDoneNegative:
t = DoneNegative
}
d.sendStatus(status.Message, t)
}
Expand Down
50 changes: 24 additions & 26 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 @@ -39,32 +37,32 @@ func TestDeployService(t *testing.T) {

require.Equal(t, DeployStatus{
Message: "Receiving service context...",
Type: RUNNING,
Type: Running,
}, <-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: DonePositive,
}, <-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: DoneNegative,
}, <-statuses)

require.Equal(t, DeployStatus{
Message: "Building Docker image...",
Type: RUNNING,
Type: Running,
}, <-statuses)

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

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

wg.Wait()
Expand Down Expand Up @@ -94,12 +92,12 @@ func TestDeployInvalidService(t *testing.T) {

require.Equal(t, DeployStatus{
Message: "Receiving service context...",
Type: RUNNING,
Type: Running,
}, <-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: DonePositive,
}, <-statuses)

select {
Expand Down Expand Up @@ -131,37 +129,37 @@ func TestDeployServiceFromURL(t *testing.T) {

require.Equal(t, DeployStatus{
Message: "Downloading service...",
Type: RUNNING,
Type: Running,
}, <-statuses)

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

require.Equal(t, DeployStatus{
Message: "Receiving service context...",
Type: RUNNING,
Type: Running,
}, <-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: DonePositive,
}, <-statuses)

require.Equal(t, DeployStatus{
Message: "Building Docker image...",
Type: RUNNING,
Type: Running,
}, <-statuses)

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

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

wg.Wait()
Expand Down
32 changes: 18 additions & 14 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
// Running indicates that status message belongs to a continuous state.
Running

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

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

// 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 = DonePositive
case coreapi.DeployServiceReply_Status_DONE_NEGATIVE:
s.Type = DoneNegative
}

statuses <- s

case serviceID != "":
result.serviceID = serviceID
deployment <- result
Expand Down
13 changes: 10 additions & 3 deletions commands/service_deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,18 @@ func (c *serviceDeployCmd) runE(cmd *cobra.Command, args []string) error {
func printDeployStatuses(statuses chan provider.DeployStatus) {
for status := range statuses {
switch status.Type {
case provider.RUNNING:
case provider.Running:
pretty.UseSpinner(status.Message)
case provider.DONE:
default:
var sign string
switch status.Type {
case provider.DonePositive:
sign = pretty.SuccessSign
case provider.DoneNegative:
sign = pretty.FailSign
}
pretty.DestroySpinner()
fmt.Println(status.Message)
fmt.Printf("%s %s\n", sign, status.Message)
}
}
}
8 changes: 5 additions & 3 deletions interface/grpc/core/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,12 @@ func sendDeployStatus(statuses chan api.DeployStatus, stream coreapi.Core_Deploy
for status := range statuses {
var typ coreapi.DeployServiceReply_Status_Type
switch status.Type {
case api.RUNNING:
case api.Running:
typ = coreapi.DeployServiceReply_Status_RUNNING
case api.DONE:
typ = coreapi.DeployServiceReply_Status_DONE
case api.DonePositive:
typ = coreapi.DeployServiceReply_Status_DONE_POSITIVE
case api.DoneNegative:
typ = coreapi.DeployServiceReply_Status_DONE_NEGATIVE
}

stream.Send(&coreapi.DeployServiceReply{
Expand Down
14 changes: 7 additions & 7 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.DonePositive,
})
}

Expand All @@ -50,9 +48,11 @@ func (s *testDeployStream) Send(m *coreapi.DeployServiceReply) error {
var typ api.StatusType
switch status.Type {
case coreapi.DeployServiceReply_Status_RUNNING:
typ = api.RUNNING
case coreapi.DeployServiceReply_Status_DONE:
typ = api.DONE
typ = api.Running
case coreapi.DeployServiceReply_Status_DONE_POSITIVE:
typ = api.DonePositive
case coreapi.DeployServiceReply_Status_DONE_NEGATIVE:
typ = api.DoneNegative
}
s.statuses = append(s.statuses, api.DeployStatus{
Message: status.Message,
Expand Down
Loading