From 6c17911b72b7ba6ee7a6e920288ccf17905121fa Mon Sep 17 00:00:00 2001 From: Lasith Koswatta Gamage Date: Tue, 28 Nov 2023 01:27:39 +0000 Subject: [PATCH] (feat): Move layer success warnings into method --- internal/layer/directory.go | 6 ++++-- internal/layer/format.go | 6 ++++-- internal/layer/label.go | 6 ++++-- internal/layer/layer.go | 4 ++++ internal/layer/mount.go | 8 +++++--- internal/layer/owner.go | 6 ++++-- internal/layer/permissions.go | 6 ++++-- internal/layer/resize.go | 6 ++++-- 8 files changed, 33 insertions(+), 15 deletions(-) diff --git a/internal/layer/directory.go b/internal/layer/directory.go index dc3c81b..6ce644b 100644 --- a/internal/layer/directory.go +++ b/internal/layer/directory.go @@ -2,7 +2,6 @@ package layer import ( "fmt" - "log" "os" "github.com/reecetech/ebs-bootstrap/internal/action" @@ -65,10 +64,13 @@ func (fdl *CreateDirectoryLayer) Validate(c *config.Config) error { return fmt.Errorf("🔴 %s: Failed directory validation checks. %s does not exist or is not a directory", name, cd.MountPoint) } } - log.Println("🟢 Passed directory validation checks") return nil } func (fdl *CreateDirectoryLayer) Warning() string { return DisableWarning } + +func (fdl *CreateDirectoryLayer) Success() string { + return "Passed directory validation checks" +} diff --git a/internal/layer/format.go b/internal/layer/format.go index b897ff8..ea95198 100644 --- a/internal/layer/format.go +++ b/internal/layer/format.go @@ -2,7 +2,6 @@ package layer import ( "fmt" - "log" "github.com/reecetech/ebs-bootstrap/internal/action" "github.com/reecetech/ebs-bootstrap/internal/backend" @@ -59,10 +58,13 @@ func (fdl *FormatDeviceLayer) Validate(c *config.Config) error { return fmt.Errorf("🔴 %s: Failed file system validation checks. Expected=%s, Actual=%s", name, cd.Fs, d.FileSystem) } } - log.Println("🟢 Passed file system validation checks") return nil } func (fdl *FormatDeviceLayer) Warning() string { return "Formatting larger disks can take several seconds ⌛" } + +func (fdl *FormatDeviceLayer) Success() string { + return "Passed file system validation checks" +} diff --git a/internal/layer/label.go b/internal/layer/label.go index 8bf80da..b87c8ec 100644 --- a/internal/layer/label.go +++ b/internal/layer/label.go @@ -2,7 +2,6 @@ package layer import ( "fmt" - "log" "github.com/reecetech/ebs-bootstrap/internal/action" "github.com/reecetech/ebs-bootstrap/internal/backend" @@ -62,10 +61,13 @@ func (fdl *LabelDeviceLayer) Validate(c *config.Config) error { return fmt.Errorf("🔴 %s: Failed label validation checks. Expected=%s, Actual=%s", name, cd.Label, d.Label) } } - log.Println("🟢 Passed label validation checks") return nil } func (fdl *LabelDeviceLayer) Warning() string { return "Certain file systems require that devices be unmounted prior to labeling" } + +func (fdl *LabelDeviceLayer) Success() string { + return "Passed label validation checks" +} diff --git a/internal/layer/layer.go b/internal/layer/layer.go index bc65b77..bc25a3c 100644 --- a/internal/layer/layer.go +++ b/internal/layer/layer.go @@ -25,6 +25,7 @@ type Layer interface { Modify(c *config.Config) ([]action.Action, error) Validate(config *config.Config) error Warning() string + Success() string } type LayerExecutor interface { @@ -47,6 +48,7 @@ func NewExponentialBackoffLayerExecutor(layers []Layer, ae *action.ActionExecuto // Calculate the maximum elapsed time for the backoff strategy based on the provided MaxRetries and InitialInterval. // This formula calculates the maximum elapsed time as a geometric series sum for a given number of retries and interval. bo.MaxElapsedTime = time.Duration((math.Pow(Multiplier, MaxRetries)-1)/(Multiplier-1)) * InitialInterval + bo.MaxInterval = InitialInterval * time.Duration(math.Pow(Multiplier, MaxRetries-1)) return &ExponentialBackoffLayerExecutor{ backoff: bo, actionExecutor: ae, @@ -73,6 +75,7 @@ func (le *ExponentialBackoffLayerExecutor) Execute(config *config.Config) error if err != nil { return err } + // Reset exponential backoff timer le.backoff.Reset() err = backoff.Retry(func() error { return le.validate(layer, config) @@ -80,6 +83,7 @@ func (le *ExponentialBackoffLayerExecutor) Execute(config *config.Config) error if err != nil { return err } + log.Printf("🟢 %s", layer.Success()) } return nil } diff --git a/internal/layer/mount.go b/internal/layer/mount.go index 3d49328..d1d9ad8 100644 --- a/internal/layer/mount.go +++ b/internal/layer/mount.go @@ -2,7 +2,6 @@ package layer import ( "fmt" - "log" "github.com/reecetech/ebs-bootstrap/internal/action" "github.com/reecetech/ebs-bootstrap/internal/backend" @@ -84,10 +83,13 @@ func (fdl *MountDeviceLayer) Validate(c *config.Config) error { return fmt.Errorf("🔴 %s: Failed mountpoint validation checks. Device not mounted to %s", name, bd.MountPoint) } } - log.Printf("🟢 Passed mountpoint validation checks") return nil } func (fdl *MountDeviceLayer) Warning() string { - return "Devices mounted to a location not specified in the configuration will be unmounted" + return "Devices mounted to a location, not specified in the configuration, will be unmounted" +} + +func (fdl *MountDeviceLayer) Success() string { + return "Passed mountpoint validation checks" } diff --git a/internal/layer/owner.go b/internal/layer/owner.go index 27d7b43..1495fdd 100644 --- a/internal/layer/owner.go +++ b/internal/layer/owner.go @@ -2,7 +2,6 @@ package layer import ( "fmt" - "log" "github.com/reecetech/ebs-bootstrap/internal/action" "github.com/reecetech/ebs-bootstrap/internal/backend" @@ -116,10 +115,13 @@ func (fdl *ChangeOwnerLayer) Validate(c *config.Config) error { return fmt.Errorf("🔴 %s: Failed ownership validation checks. %s Group Expected=%d, Actual=%d", name, cd.MountPoint, d.Gid, gid) } } - log.Printf("🟢 Passed ownership validation checks") return nil } func (fdl *ChangeOwnerLayer) Warning() string { return DisableWarning } + +func (fdl *ChangeOwnerLayer) Success() string { + return "Passed ownership validation checks" +} diff --git a/internal/layer/permissions.go b/internal/layer/permissions.go index 31d1b21..e8da561 100644 --- a/internal/layer/permissions.go +++ b/internal/layer/permissions.go @@ -2,7 +2,6 @@ package layer import ( "fmt" - "log" "github.com/reecetech/ebs-bootstrap/internal/action" "github.com/reecetech/ebs-bootstrap/internal/backend" @@ -67,10 +66,13 @@ func (fdl *ChangePermissionsLayer) Validate(c *config.Config) error { return fmt.Errorf("🔴 %s: Failed permissions validation checks. %s Permissions Expected=%s, Actual=%s", name, cd.MountPoint, cd.Permissions, d.Permissions) } } - log.Printf("🟢 Passed permissions validation checks") return nil } func (fdl *ChangePermissionsLayer) Warning() string { return DisableWarning } + +func (fdl *ChangePermissionsLayer) Success() string { + return "Passed permissions validation checks" +} diff --git a/internal/layer/resize.go b/internal/layer/resize.go index 117723f..2632f0f 100644 --- a/internal/layer/resize.go +++ b/internal/layer/resize.go @@ -2,7 +2,6 @@ package layer import ( "fmt" - "log" "github.com/reecetech/ebs-bootstrap/internal/action" "github.com/reecetech/ebs-bootstrap/internal/backend" @@ -61,10 +60,13 @@ func (fdl *ResizeDeviceLayer) Validate(c *config.Config) error { return fmt.Errorf("🔴 %s: Failed to resize file system. File System=%d Block Device=%d (bytes)", name, metrics.FileSystemSize, metrics.BlockDeviceSize) } } - log.Println("🟢 Passed file system resize checks") return nil } func (fdl *ResizeDeviceLayer) Warning() string { return DisableWarning } + +func (fdl *ResizeDeviceLayer) Success() string { + return "Passed file system resize checks" +}