-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
130 additions
and
140 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package backend | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/reecetech/ebs-bootstrap/internal/config" | ||
"github.com/reecetech/ebs-bootstrap/internal/model" | ||
"github.com/reecetech/ebs-bootstrap/internal/service" | ||
) | ||
|
||
type DeviceMetricsBackend interface { | ||
GetBlockDeviceMetrics(name string) (*model.BlockDeviceMetrics, error) | ||
From(config *config.Config) error | ||
} | ||
|
||
type LinuxDeviceMetricsBackend struct { | ||
blockDeviceMetrics map[string]*model.BlockDeviceMetrics | ||
deviceService service.DeviceService | ||
fileSystemServiceFactory service.FileSystemServiceFactory | ||
} | ||
|
||
func NewLinuxDeviceMetricsBackend(ds service.DeviceService, fssf service.FileSystemServiceFactory) *LinuxDeviceMetricsBackend { | ||
return &LinuxDeviceMetricsBackend{ | ||
blockDeviceMetrics: map[string]*model.BlockDeviceMetrics{}, | ||
deviceService: ds, | ||
fileSystemServiceFactory: fssf, | ||
} | ||
} | ||
|
||
func (dmb *LinuxDeviceMetricsBackend) GetBlockDeviceMetrics(name string) (*model.BlockDeviceMetrics, error) { | ||
metrics, exists := dmb.blockDeviceMetrics[name] | ||
if !exists { | ||
return nil, fmt.Errorf("🔴 %s: Could not find block device metrics", name) | ||
} | ||
return metrics, nil | ||
} | ||
|
||
func (dmb *LinuxDeviceMetricsBackend) From(config *config.Config) error { | ||
// Clear in memory representation of metrics and devices | ||
for k := range dmb.blockDeviceMetrics { | ||
delete(dmb.blockDeviceMetrics, k) | ||
} | ||
|
||
for name := range config.Devices { | ||
bd, err := dmb.deviceService.GetBlockDevice(name) | ||
if err != nil { | ||
return err | ||
} | ||
// Can not fetch file system metrics from a device with | ||
// no file system. Therefore, we exit with error if this is the case | ||
// The reason we exit early, rather than continuing is because we want | ||
// to simplify the data view of the Device Resize Backend as much as possible | ||
// With this check, we ensure that all devices in the resize backend have a | ||
// valid file system | ||
if bd.FileSystem == model.Unformatted { | ||
return fmt.Errorf("🔴 %s: Can not resize a device with no file system", bd.Name) | ||
} | ||
fs, err := dmb.fileSystemServiceFactory.Select(bd.FileSystem) | ||
if err != nil { | ||
return err | ||
} | ||
// Block Device Size | ||
bss, err := dmb.deviceService.GetSize(bd.Name) | ||
if err != nil { | ||
return err | ||
} | ||
// File System Size | ||
fss, err := fs.GetSize(bd.Name) | ||
if err != nil { | ||
return err | ||
} | ||
dmb.blockDeviceMetrics[bd.Name] = &model.BlockDeviceMetrics{ | ||
BlockDeviceSize: bss, | ||
FileSystemSize: fss, | ||
} | ||
} | ||
return nil | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters