Skip to content

Commit

Permalink
progress after testing
Browse files Browse the repository at this point in the history
  • Loading branch information
janelletavares committed Feb 7, 2022
1 parent f899587 commit 57d2358
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
23 changes: 16 additions & 7 deletions cmd/meroxa/root/environments/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package environments

import (
"context"
"encoding/json"
"errors"
"fmt"
"strings"
Expand Down Expand Up @@ -129,25 +130,33 @@ func (c *Create) Execute(ctx context.Context) error {
c.logger.Infof(ctx, "Provisioning environment...")

environment, err := c.client.CreateEnvironment(ctx, e)
fmt.Printf("err: %+v\n", err)
fmt.Printf("env: %+v\n", environment)

if err != nil {
c.logger.JSON(ctx, environment.Status.State)
if environment.Status.State == meroxa.EnvironmentStatePreflightError {
c.logger.JSON(ctx, environment.Status.PreflightDetails)
}
return err
}

c.logger.Infof(ctx, "Environment %q is being provisioned. Run `meroxa env describe %s` for status", environment.Name, environment.Name)

if environment.Status.State == meroxa.EnvironmentStatePreflightSuccess {
if environment.Status.State == meroxa.EnvironmentStatePreflightError {
details, _ := prettyString(environment.Status.PreflightDetails)
c.logger.Errorf(ctx, "Environment %q could not be provisioned because it failed the preflight checks\n%s\n", environment.Name, details)
} else if environment.Status.State == meroxa.EnvironmentStatePreflightSuccess {
environment.Status.PreflightDetails = nil
c.logger.Infof(ctx, "Preflight checks have passed. Environment %q is being provisioned. Run `meroxa env describe %s` for status", environment.Name, environment.Name)
}

c.logger.JSON(ctx, environment)
return nil
}

func prettyString(a interface{}) (string, error) {
j, err := json.MarshalIndent(a, "", " ")
if err != nil {
return "", err
}
return string(j), nil
}

func (c *Create) NotConfirmed() string {
return "\nTo view all options for creating a Meroxa Environment,\n " +
"please run \"meroxa help env create\". \n"
Expand Down
2 changes: 1 addition & 1 deletion utils/display.go
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ func EnvironmentTable(environment *meroxa.Environment) string {
{Text: strings.Join(environment.Status.PreflightDetails.PreflightPermissions.S3, " ; ")},
},
{
{Align: simpletable.AlignRight, Text: "AWS Service Quotas Permissions Status:"},
{Align: simpletable.AlignRight, Text: "AWS ServiceQuotas Permissions Status:"},
{Text: strings.Join(environment.Status.PreflightDetails.PreflightPermissions.ServiceQuotas, " ; ")},
},
{
Expand Down
6 changes: 3 additions & 3 deletions utils/tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,12 @@ func GenerateEnvironmentFailed(environmentName string) meroxa.Environment {
Status: meroxa.EnvironmentViewStatus{
State: meroxa.EnvironmentStatePreflightError,
Details: "",
PreflightDetails: meroxa.PreflightDetails{
PreflightPermissions: meroxa.PreflightPermissions{
PreflightDetails: &meroxa.PreflightDetails{
PreflightPermissions: &meroxa.PreflightPermissions{
S3: []string{"missing read permission for S3", "missing write permissions for S3"},
EC2: []string{"missing read permission for S3", "missing write permissions for S3"},
},
PreflightLimits: meroxa.PreflightLimits{
PreflightLimits: &meroxa.PreflightLimits{
EIP: "",
},
},
Expand Down

0 comments on commit 57d2358

Please sign in to comment.