-
Notifications
You must be signed in to change notification settings - Fork 0
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
Fix/service set update #272
base: 2.x.x
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ import ( | |
"encoding/json" | ||
"os" | ||
|
||
"github.com/dream11/odin/internal/ui" | ||
"github.com/dream11/odin/pkg/config" | ||
serviceDto "github.com/dream11/odin/proto/gen/go/dream11/od/dto/v1" | ||
serviceProto "github.com/dream11/odin/proto/gen/go/dream11/od/service/v1" | ||
|
@@ -61,8 +62,56 @@ func executeDeployServiceSet(cmd *cobra.Command) { | |
deployServiceSetRequest.Name = serviceSetName | ||
} | ||
|
||
conflictingServicesRequest := &serviceProto.GetConflictingServicesRequest{ | ||
EnvName: env, | ||
Name: deployServiceSetRequest.Name, | ||
} | ||
|
||
services, errs := serviceClient.GetConflictingServices(&ctx, conflictingServicesRequest) | ||
if errs != nil { | ||
log.Fatal("Failed to list services with conflicting versions. ", errs) | ||
return | ||
} | ||
var serviceNames []string | ||
for _, service := range services.Services { | ||
|
||
allowedInputsSlice := []string{"y", "n"} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use constants for "y" or "n" |
||
allowedInputs := make(map[string]struct{}, len(allowedInputsSlice)) | ||
for _, input := range allowedInputsSlice { | ||
allowedInputs[input] = struct{}{} | ||
} | ||
message := "Service already deployed with different version.Do you want to deploy service " + service.Name + " ? (y/n)" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use string formatter |
||
inputHandler := ui.Input{} | ||
val, err := inputHandler.AskWithConstraints(message, allowedInputs) | ||
|
||
if err != nil { | ||
log.Fatal(err.Error()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add some error message here |
||
} | ||
|
||
if val != "y" { | ||
log.Info("Skipping service ", service.Name, " from deploy") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use formatted strings |
||
serviceNames = append(serviceNames, service.Name) | ||
} | ||
// Remove services from deployServiceSetRequest | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this logic be part of the client? Do you think this should be handled by the deployer? |
||
var updatedServices []*serviceProto.ServiceIdentifier | ||
for _, svc := range deployServiceSetRequest.Services { | ||
shouldRemove := false | ||
for _, name := range serviceNames { | ||
if svc.ServiceName == name { | ||
shouldRemove = true | ||
break | ||
} | ||
} | ||
if !shouldRemove { | ||
updatedServices = append(updatedServices, svc) | ||
} | ||
} | ||
deployServiceSetRequest.Services = updatedServices | ||
|
||
} | ||
|
||
err := serviceClient.DeployServiceSet(&ctx, &deployServiceSetRequest) | ||
if err != nil { | ||
log.Fatal("Failed to deploy service ", err) | ||
log.Fatal("Failed to deploy service set. ", err) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this err objected logged? |
||
} | ||
} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,6 +1,7 @@ | ||||||
package service | ||||||
|
||||||
import ( | ||||||
"bytes" | ||||||
"context" | ||||||
"errors" | ||||||
"fmt" | ||||||
|
@@ -11,6 +12,7 @@ import ( | |||||
"github.com/dream11/odin/pkg/util" | ||||||
serviceDto "github.com/dream11/odin/proto/gen/go/dream11/od/dto/v1" | ||||||
serviceProto "github.com/dream11/odin/proto/gen/go/dream11/od/service/v1" | ||||||
"github.com/olekukonko/tablewriter" | ||||||
log "github.com/sirupsen/logrus" | ||||||
) | ||||||
|
||||||
|
@@ -49,7 +51,7 @@ func (e *Service) DeployService(ctx *context.Context, request *serviceProto.Depl | |||||
} | ||||||
|
||||||
if response != nil { | ||||||
message = util.GenerateResponseMessage(response.GetServiceResponse()) | ||||||
message = util.GenerateResponseMessage(response.ServiceResponse) | ||||||
spinnerInstance.Prefix = fmt.Sprintf(" %s ", message) | ||||||
spinnerInstance.Start() | ||||||
} | ||||||
|
@@ -63,6 +65,7 @@ func (e *Service) DeployService(ctx *context.Context, request *serviceProto.Depl | |||||
func (e *Service) DeployServiceSet(ctx *context.Context, request *serviceProto.DeployServiceSetRequest) error { | ||||||
conn, requestCtx, err := grpcClient(ctx) | ||||||
if err != nil { | ||||||
log.Errorf("TraceID: %s", (*requestCtx).Value(constant.TraceIDKey)) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why this is error log? |
||||||
return err | ||||||
} | ||||||
client := serviceProto.NewServiceServiceClient(conn) | ||||||
|
@@ -81,7 +84,7 @@ func (e *Service) DeployServiceSet(ctx *context.Context, request *serviceProto.D | |||||
var message string | ||||||
for { | ||||||
response, err := stream.Recv() | ||||||
spinnerInstance.Stop() | ||||||
|
||||||
if err != nil { | ||||||
if errors.Is(err, context.Canceled) || err == io.EOF { | ||||||
break | ||||||
|
@@ -91,16 +94,34 @@ func (e *Service) DeployServiceSet(ctx *context.Context, request *serviceProto.D | |||||
} | ||||||
|
||||||
if response != nil { | ||||||
message = "" | ||||||
spinnerInstance.Stop() | ||||||
var buf bytes.Buffer | ||||||
table := tablewriter.NewWriter(&buf) | ||||||
table.SetHeader([]string{"Service Name", "Service Version", "Service Tags", "Service Action", "Service Status", "Error"}) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
for _, serviceResponse := range response.GetServices() { | ||||||
message += util.GenerateResponseMessage(serviceResponse.GetServiceResponse()) | ||||||
var errorMessage string | ||||||
if serviceResponse.ServiceResponse.ServiceStatus.ServiceStatus == "FAILED" { | ||||||
traceID := (*requestCtx).Value(constant.TraceIDKey) | ||||||
errorMessage += fmt.Sprintf("[%s] TraceID: %s \n", serviceResponse.ServiceResponse.ServiceStatus.Error, traceID) | ||||||
} | ||||||
row := []string{ | ||||||
serviceResponse.ServiceIdentifier.ServiceName, | ||||||
serviceResponse.ServiceIdentifier.ServiceVersion, | ||||||
serviceResponse.ServiceIdentifier.Tags, | ||||||
serviceResponse.ServiceResponse.ServiceStatus.ServiceAction, | ||||||
serviceResponse.ServiceResponse.ServiceStatus.ServiceStatus, | ||||||
errorMessage, | ||||||
} | ||||||
table.Append(row) | ||||||
} | ||||||
|
||||||
table.Render() | ||||||
message = buf.String() | ||||||
spinnerInstance.Prefix = fmt.Sprintf(" %s ", message) | ||||||
spinnerInstance.Start() | ||||||
} | ||||||
} | ||||||
|
||||||
log.Info(message) | ||||||
fmt.Println(message) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why changed this? |
||||||
return err | ||||||
} | ||||||
|
||||||
|
@@ -301,8 +322,9 @@ func (e *Service) ConvertToDeployServiceSetRequest(serviceSet *serviceDto.Servic | |||||
var services []*serviceProto.ServiceIdentifier | ||||||
for _, service := range serviceSet.Services { | ||||||
services = append(services, &serviceProto.ServiceIdentifier{ | ||||||
ServiceName: service.ServiceName, | ||||||
ServiceVersion: service.ServiceVersion, | ||||||
ServiceName: service.Name, | ||||||
ServiceVersion: service.Version, | ||||||
Tags: service.Tags, | ||||||
}) | ||||||
} | ||||||
|
||||||
|
@@ -328,3 +350,17 @@ func (e *Service) DescribeService(ctx *context.Context, request *serviceProto.De | |||||
|
||||||
return response, nil | ||||||
} | ||||||
|
||||||
// GetConflictingServices deploys service | ||||||
func (e *Service) GetConflictingServices(ctx *context.Context, request *serviceProto.GetConflictingServicesRequest) (*serviceProto.GetConflictingServicesResponse, error) { | ||||||
conn, requestCtx, err := grpcClient(ctx) | ||||||
if err != nil { | ||||||
return &serviceProto.GetConflictingServicesResponse{}, err | ||||||
} | ||||||
client := serviceProto.NewServiceServiceClient(conn) | ||||||
response, err := client.GetConflictingServices(*requestCtx, request) | ||||||
if err != nil { | ||||||
log.Errorf("TraceID: %s", (*requestCtx).Value(constant.TraceIDKey)) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this an error log? |
||||||
} | ||||||
return response, err | ||||||
} |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove this binary |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -10,6 +10,7 @@ import ( | |||||
|
||||||
v1 "github.com/dream11/odin/proto/gen/go/dream11/od/service/v1" | ||||||
"github.com/google/uuid" | ||||||
"github.com/olekukonko/tablewriter" | ||||||
) | ||||||
|
||||||
// SplitProviderAccount splits string into list of cloud provider accounts | ||||||
|
@@ -35,6 +36,27 @@ func GenerateResponseMessage(response *v1.ServiceResponse) string { | |||||
return message | ||||||
} | ||||||
|
||||||
// GenerateServiceSetResponseMessage generate response message from ServiceSetResponse | ||||||
func GenerateServiceSetResponseMessage(response *v1.DeployServiceSetServiceResponse) string { | ||||||
|
||||||
message := fmt.Sprintf("\n Service %s %s %s %s", response.ServiceIdentifier.ServiceName, response.ServiceIdentifier.ServiceVersion, response.ServiceResponse.ServiceStatus.ServiceAction, response.ServiceResponse.ServiceStatus) | ||||||
var tableData [][]string | ||||||
row := []string{ | ||||||
response.ServiceIdentifier.ServiceName, | ||||||
response.ServiceIdentifier.ServiceVersion, | ||||||
response.ServiceResponse.ServiceStatus.ServiceAction, | ||||||
response.ServiceResponse.ServiceStatus.ServiceStatus, | ||||||
} | ||||||
tableData = append(tableData, row) | ||||||
|
||||||
table := tablewriter.NewWriter(os.Stdout) | ||||||
table.SetHeader([]string{"Service Name", "Service Version", "Service Action", "Service Status", "Error"}) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
table.AppendBulk(tableData) | ||||||
table.Render() | ||||||
return message | ||||||
|
||||||
} | ||||||
|
||||||
// FormatToHumanReadableDuration takes a date-time string representing the last deployment time, and returns a human-readable string representing the duration since the last deployment | ||||||
func FormatToHumanReadableDuration(inputDateTime string) string { | ||||||
// Check if the input is a Unix timestamp prefixed by "seconds:" | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,8 +23,9 @@ message ServiceDefinition { | |
} | ||
|
||
message ServiceIdentifier { | ||
string service_name = 1; | ||
string service_version = 2; | ||
string name = 1; | ||
string version = 2; | ||
string tags = 3; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. tags is a string? |
||
} | ||
|
||
message ServiceSet { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the
err
object printed?