Skip to content

Commit

Permalink
Conformation for autoscaling enabled scaler onboarded components (#201)
Browse files Browse the repository at this point in the history
Co-authored-by: rahulrayal <[email protected]>
  • Loading branch information
rahulrayal and rahulrayal authored Jul 12, 2023
1 parent bb234d1 commit bfa32a0
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 3 deletions.
4 changes: 4 additions & 0 deletions api/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,7 @@ type OperationRequest struct {
type OperationValidationResponse struct {
Response OperationValidationResponseBody `yaml:"resp,omitempty" json:"resp,omitempty"`
}

type ScalingConsentResponse struct {
Response []string `yaml:"resp,omitempty" json:"resp,omitempty"`
}
2 changes: 1 addition & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ type application struct {
// App (Application) interface
var App application = application{
Name: "odin",
Version: "1.3.1-beta.1",
Version: "1.3.1",
}
12 changes: 12 additions & 0 deletions internal/backend/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,3 +186,15 @@ func (s *Service) OperateService(serviceName string, data service.OperationReque
response := client.streamWithRetry(path.Join(serviceEntity, serviceName)+"/operate/", "PUT", data)
response.Process(true)
}

func (s *Service) ScalingServiceConsent(serviceName string, data interface{}) (service.ScalingConsentResponse, error) {
client := newApiClient()

response := client.actionWithRetry(path.Join(serviceEntity, serviceName)+"/reactive-scaled-scaler-components", "POST", data)
response.Process(true)

var scalingConsentResponse service.ScalingConsentResponse
err := json.Unmarshal(response.Body, &scalingConsentResponse)

return scalingConsentResponse, err
}
27 changes: 27 additions & 0 deletions internal/command/commands/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,33 @@ func (c *Component) Run(args []string) int {
}
}

dataForScalingConsent := map[string]interface{}{
"env_name": *envName,
"component_name": *name,
"action": *operation,
"config": optionsData,
}
componentListResponse, err := serviceClient.ScalingServiceConsent(*serviceName, dataForScalingConsent)
if err != nil {
c.Logger.Error(err.Error())
return 1
}
for _, component := range componentListResponse.Response {
consentMessage := fmt.Sprintf("\nAs you have enabled ASG auto scaling policy for %s, It will no longer be scaled using Scaler post this operation. Do you wish to continue? [Y/n]:", component)
allowedInputs := map[string]struct{}{"Y": {}, "n": {}}
val, err := c.Input.AskWithConstraints(consentMessage, allowedInputs)

if err != nil {
c.Logger.Error(err.Error())
return 1
}

if val != "Y" {
c.Logger.Info("Aborting...")
return 1
}
}

componentClient.OperateComponent(*name, data)
return 0
}
Expand Down
47 changes: 45 additions & 2 deletions internal/command/commands/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ func (s *Service) Run(args []string) int {
}

if !isOperationPresnt {
s.Logger.Error("--opertion cannot be blank")
s.Logger.Error("--operation cannot be blank")
return 1
}

Expand Down Expand Up @@ -399,6 +399,16 @@ func (s *Service) Run(args []string) int {
return 1
}

dataForScalingConsent := map[string]interface{}{
"env_name": *envName,
"action": *operation,
"config": optionsData,
}
scalingConsent := s.askForScalingConsent(serviceName, envName, dataForScalingConsent)
if scalingConsent == 1 {
return 1
}

data := service.OperationRequest{
EnvName: *envName,
Operations: []service.Operation{
Expand Down Expand Up @@ -471,6 +481,30 @@ func (s *Service) askForConsent(envName *string) int {
return 0
}

func (s *Service) askForScalingConsent(serviceName *string, envName *string, data map[string]interface{}) int {
componentListResponse, err := serviceClient.ScalingServiceConsent(*serviceName, data)
if err != nil {
s.Logger.Error(err.Error())
return 1
}
for _, component := range componentListResponse.Response {
consentMessage := fmt.Sprintf("\nAs you have enabled ASG auto scaling policy for %s, It will no longer be scaled using Scaler post this operation. Do you wish to continue? [Y/n]:", component)
allowedInputs := map[string]struct{}{"Y": {}, "n": {}}
val, err := s.Input.AskWithConstraints(consentMessage, allowedInputs)

if err != nil {
s.Logger.Error(err.Error())
return 1
}

if val != "Y" {
s.Logger.Info("\nAborting...")
return 1
}
}
return 0
}

func (s *Service) deployUnreleasedService(envName *string, serviceDefinition map[string]interface{}, provisioningConfigFile *string, configStoreNamespace *string) int {

if serviceDefinition["name"] == nil || len(serviceDefinition["name"].(string)) == 0 {
Expand Down Expand Up @@ -500,7 +534,16 @@ func (s *Service) deployReleasedService(envName *string, serviceName *string, se
if done {
return i
}

dataForScalingConsent := map[string]interface{}{
"env_name": *envName,
"service_version": *serviceVersion,
"action": "released_service_deploy",
"config": parsedProvisioningConfig,
}
scalingConsent := s.askForScalingConsent(serviceName, envName, dataForScalingConsent)
if scalingConsent == 1 {
return 1
}
s.Logger.Debug(fmt.Sprintf("%s: %s : %s: %s:", *serviceName, *serviceVersion, *envName, *configStoreNamespace))
s.Logger.Info("Initiating service deployment: " + *serviceName + "@" + *serviceVersion + " in " + *envName)
serviceClient.DeployReleasedServiceStream(*serviceName, *serviceVersion, *envName, *configStoreNamespace, parsedProvisioningConfig)
Expand Down

0 comments on commit bfa32a0

Please sign in to comment.