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

Add Hash to reply of Deploy API #801

Merged
merged 6 commits into from
Mar 11, 2019
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
2 changes: 1 addition & 1 deletion commands/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type ServiceExecutor interface {
ServiceByID(id string) (*coreapi.Service, error)
ServiceDeleteAll(deleteData bool) error
ServiceDelete(deleteData bool, ids ...string) error
ServiceDeploy(path string, env map[string]string, statuses chan provider.DeployStatus) (id string, validationError, err error)
ServiceDeploy(path string, env map[string]string, statuses chan provider.DeployStatus) (sid string, hash string, validationError, err error)
ServicePublishDefinitionFile(path string) (string, error)
ServiceListenEvents(id, eventFilter string) (chan *coreapi.EventData, chan error, error)
ServiceListenResults(id, taskFilter, outputFilter string, tagFilters []string) (chan *coreapi.ResultData, chan error, error)
Expand Down
17 changes: 12 additions & 5 deletions commands/mocks/Executor.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 12 additions & 11 deletions commands/provider/service_deployer.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,17 @@ type DeployStatus struct {

// deploymentResult keeps information about deployment result.
type deploymentResult struct {
serviceID string
sid string
hash string
err error
validationError error
}

// ServiceDeploy deploys service from given path.
func (p *ServiceProvider) ServiceDeploy(path string, env map[string]string, statuses chan DeployStatus) (id string,
validationError, err error) {
func (p *ServiceProvider) ServiceDeploy(path string, env map[string]string, statuses chan DeployStatus) (sid string, hash string, validationError, err error) {
stream, err := p.client.DeployService(context.Background())
if err != nil {
return "", nil, err
return "", "", nil, err
}

deployment := make(chan deploymentResult)
Expand All @@ -61,21 +61,21 @@ func (p *ServiceProvider) ServiceDeploy(path string, env map[string]string, stat
Value: &coreapi.DeployServiceRequest_Url{Url: path},
Env: env,
}); err != nil {
return "", nil, err
return "", "", nil, err
}
} else {
if err := deployServiceSendServiceContext(path, env, stream); err != nil {
return "", nil, err
return "", "", nil, err
}
}

if err := stream.CloseSend(); err != nil {
return "", nil, err
return "", "", nil, err
}

result := <-deployment
close(statuses)
return result.serviceID, result.validationError, result.err
return result.sid, result.hash, result.validationError, result.err
}

func deployServiceSendServiceContext(path string, env map[string]string, stream coreapi.Core_DeployServiceClient) error {
Expand Down Expand Up @@ -145,7 +145,7 @@ func readDeployReply(stream coreapi.Core_DeployServiceClient, deployment chan de

var (
status = message.GetStatus()
serviceID = message.GetServiceID()
service = message.GetService()
validationError = message.GetValidationError()
)

Expand All @@ -166,8 +166,9 @@ func readDeployReply(stream coreapi.Core_DeployServiceClient, deployment chan de

statuses <- s

case serviceID != "":
result.serviceID = serviceID
case service != nil:
result.sid = service.Sid
result.hash = service.Hash
deployment <- result
return

Expand Down
6 changes: 3 additions & 3 deletions commands/service_deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (c *serviceDeployCmd) runE(cmd *cobra.Command, args []string) error {
printDeployStatuses(statuses)
}()

id, validationError, err := c.e.ServiceDeploy(c.path, c.env, statuses)
sid, hash, validationError, err := c.e.ServiceDeploy(c.path, c.env, statuses)
if err != nil {
return err
}
Expand All @@ -68,8 +68,8 @@ func (c *serviceDeployCmd) runE(cmd *cobra.Command, args []string) error {
errors.New("to get more information, run: mesg-core service validate"),
}
}
fmt.Printf("%s Service deployed with id: %v\n", pretty.SuccessSign, pretty.Success(id))
fmt.Printf("To start it, run the command:\n\tmesg-core service start %s\n", id)
fmt.Printf("%s Service deployed with sid %s and hash %s\n", pretty.SuccessSign, pretty.Success(sid), pretty.Success(hash))
fmt.Printf("To start it, run the command:\n\tmesg-core service start %s\n", sid)
return nil
}

Expand Down
7 changes: 4 additions & 3 deletions commands/service_deploy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ func TestServiceDeployCmdFlags(t *testing.T) {
func TestServiceDeploy(t *testing.T) {
var (
url = "1"
id = "2"
sid = "2"
hash = "3"
env = map[string]string{"A": "3", "B": "4"}
m = newMockExecutor()
c = newServiceDeployCmd(m)
Expand All @@ -47,7 +48,7 @@ func TestServiceDeploy(t *testing.T) {
c.cmd.SetArgs([]string{url})
c.env = env

m.On("ServiceDeploy", serviceDeployParameters...).Return(id, nil, nil).Run(serviceDeployRunFunction)
m.On("ServiceDeploy", serviceDeployParameters...).Return(sid, hash, nil, nil).Run(serviceDeployRunFunction)

closeStd := captureStd(t)
c.cmd.Execute()
Expand All @@ -56,7 +57,7 @@ func TestServiceDeploy(t *testing.T) {

require.Equal(t, "✔ 5", string(readLine(t, r)))
require.Equal(t, "⨯ 6", string(readLine(t, r)))
require.Equal(t, "✔ Service deployed with id: 2", string(readLine(t, r)))
require.Equal(t, "✔ Service deployed with sid 2 and hash 3", string(readLine(t, r)))
require.Equal(t, "To start it, run the command:", string(readLine(t, r)))
require.Equal(t, " mesg-core service start 2", string(readLine(t, r)))

Expand Down
15 changes: 8 additions & 7 deletions commands/service_dev.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func (c *serviceDevCmd) runE(cmd *cobra.Command, args []string) error {
printDeployStatuses(statuses)
}()

id, validationError, err := c.e.ServiceDeploy(c.path, c.env, statuses)
sid, hash, validationError, err := c.e.ServiceDeploy(c.path, c.env, statuses)
if err != nil {
return err
}
Expand All @@ -78,11 +78,12 @@ func (c *serviceDevCmd) runE(cmd *cobra.Command, args []string) error {
errors.New("to get more information, run: mesg-core service validate"),
}
}
fmt.Printf("%s Service deployed with ID: %v\n", pretty.SuccessSign, pretty.Success(id))
fmt.Printf("%s Service deployed with sid %s and hash %s\n", pretty.SuccessSign, pretty.Success(sid), pretty.Success(hash))

defer func() {
var err error
pretty.Progress("Removing the service...", func() {
err = c.e.ServiceDelete(false, id)
err = c.e.ServiceDelete(false, hash)
})
if err != nil {
fmt.Printf("%s Removing the service completed with an error: %s\n", pretty.FailSign, err)
Expand All @@ -91,23 +92,23 @@ func (c *serviceDevCmd) runE(cmd *cobra.Command, args []string) error {
}
}()

pretty.Progress("Starting the service...", func() { err = c.e.ServiceStart(id) })
pretty.Progress("Starting the service...", func() { err = c.e.ServiceStart(hash) })
if err != nil {
return err
}
fmt.Printf("%s Service started\n", pretty.SuccessSign)

listenEventsC, eventsErrC, err := c.e.ServiceListenEvents(id, c.eventFilter)
listenEventsC, eventsErrC, err := c.e.ServiceListenEvents(hash, c.eventFilter)
if err != nil {
return err
}

listenResultsC, resultsErrC, err := c.e.ServiceListenResults(id, c.taskFilter, c.outputFilter, nil)
listenResultsC, resultsErrC, err := c.e.ServiceListenResults(hash, c.taskFilter, c.outputFilter, nil)
if err != nil {
return err
}

closer, logsErrC, err := showLogs(c.e, id)
closer, logsErrC, err := showLogs(c.e, hash)
if err != nil {
return err
}
Expand Down
7 changes: 5 additions & 2 deletions interface/grpc/core/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,11 @@ func (s *Server) DeployService(stream coreapi.Core_DeployServiceServer) error {
}

return stream.Send(&coreapi.DeployServiceReply{
Value: &coreapi.DeployServiceReply_ServiceID{
ServiceID: service.Sid,
Value: &coreapi.DeployServiceReply_Service_{
Service: &coreapi.DeployServiceReply_Service{
Sid: service.Sid,
Hash: service.Hash,
},
},
})
}
Expand Down
5 changes: 3 additions & 2 deletions interface/grpc/core/deploy_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ func TestIntegrationDeployService(t *testing.T) {
stream := newTestDeployStream(url)

require.Nil(t, server.DeployService(stream))
defer server.api.DeleteService(stream.serviceID, false)
defer server.api.DeleteService(stream.hash, false)

require.Len(t, stream.serviceID, 7)
require.Len(t, stream.sid, 7)
require.NotEmpty(t, stream.hash)
require.Contains(t, stream.statuses, api.DeployStatus{
Message: "Image built with success",
Type: api.DonePositive,
Expand Down
15 changes: 9 additions & 6 deletions interface/grpc/core/deploy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ func TestDeployService(t *testing.T) {

stream := newTestDeployStream(url)
require.Nil(t, server.DeployService(stream))
require.Len(t, stream.serviceID, 7)
require.Len(t, stream.sid, 7)
require.NotEmpty(t, stream.hash)

require.Contains(t, stream.statuses, api.DeployStatus{
Message: "Image built with success",
Expand All @@ -30,10 +31,11 @@ func TestDeployService(t *testing.T) {

// TODO(ilgooz) also add tests for receiving chunks.
type testDeployStream struct {
url string // Git repo url.
err error
serviceID string
statuses []api.DeployStatus
url string // Git repo url.
err error
sid string
hash string
statuses []api.DeployStatus
grpc.ServerStream
}

Expand All @@ -42,7 +44,8 @@ func newTestDeployStream(url string) *testDeployStream {
}

func (s *testDeployStream) Send(m *coreapi.DeployServiceReply) error {
s.serviceID = m.GetServiceID()
s.sid = m.GetService().GetSid()
s.hash = m.GetService().GetHash()

status := m.GetStatus()
if status != nil {
Expand Down
2 changes: 1 addition & 1 deletion interface/grpc/core/list_services_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func TestListServices(t *testing.T) {

stream := newTestDeployStream(url)
require.NoError(t, server.DeployService(stream))
defer server.api.DeleteService(stream.serviceID, false)
defer server.api.DeleteService(stream.hash, false)

reply, err := server.ListServices(context.Background(), &coreapi.ListServicesRequest{})
require.NoError(t, err)
Expand Down
Loading