Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2024-11-06 03:59:19 -06:00
parent 3903c74fe6
commit 97050dcb9d
1 changed files with 44 additions and 31 deletions

View File

@ -4,41 +4,54 @@ import (
"context" "context"
"errors" "errors"
"fmt" "fmt"
"go.wit.com/lib/protobuf/virtbuf" "go.wit.com/lib/protobuf/virtbuf"
) )
// CloudClusterManager is a concrete implementation of the ClusterManager interface. var me context.Context
type CloudClusterManager struct { var myClient CloudAPIClient
// CloudManager is a concrete implementation of the Manager interface.
type CloudManager struct {
// client represents a hypothetical API client for interacting with the cloud. // client represents a hypothetical API client for interacting with the cloud.
client CloudAPIClient client CloudAPIClient
cluster *virtbuf.NewCluster
} }
// CloudAPIClient defines the methods required from the API client. // CloudAPIClient defines the methods required from the API client.
// This is useful if you want to mock this client for testing. // This is useful if you want to mock this client for testing.
type CloudAPIClient interface { type CloudAPIClient interface {
GetClusterByName(ctx context.Context, name string) (*virtbuf.NewCluster, error) GetDropletByName(name string) (*virtbuf.Droplet, error)
StartCluster(ctx context.Context, clusterID string) error StartCluster(ctx context.Context, clusterID string) error
StopCluster(ctx context.Context, clusterID string) error StopCluster(ctx context.Context, clusterID string) error
ListClusters(ctx context.Context) ([]*virtbuf.NewCluster, error) ListClusters(ctx context.Context) ([]*virtbuf.NewCluster, error)
GetClusterStatus(ctx context.Context, clusterID string) (string, error) GetClusterStatus(ctx context.Context, clusterID string) (string, error)
} }
// NewCloudClusterManager creates a new CloudClusterManager with the provided API client. func NewCloud() *CloudManager {
func NewCloudClusterManager(client CloudAPIClient) *CloudClusterManager { // client := NewRealCloudAPIClient() // This should be replaced with a real implementation
return &CloudClusterManager{client: client} clusterManager := NewCloudManager(myClient)
me = context.Background()
return clusterManager
}
// NewCloudManager creates a new CloudManager with the provided API client.
func NewCloudManager(client CloudAPIClient) *CloudManager {
return &CloudManager{client: client}
} }
// FindByName retrieves a cluster by name. // FindByName retrieves a cluster by name.
func (m *CloudClusterManager) FindByName(ctx context.Context, name string) (*virtbuf.NewCluster, error) { func (m *CloudManager) FindDropletByName(name string) (*virtbuf.Droplet, error) {
cluster, err := m.client.GetClusterByName(ctx, name) d, err := m.client.GetDropletByName(name)
if err != nil { if err != nil {
return nil, fmt.Errorf("error finding cluster by name %q: %w", name, err) return nil, fmt.Errorf("error finding cluster by name %q: %w", name, err)
} }
return cluster, nil return d, nil
} }
// Start initiates the startup process for the specified cluster. // Start initiates the startup process for the specified cluster.
func (m *CloudClusterManager) Start(ctx context.Context, cluster *virtbuf.NewCluster) error { func (m *CloudManager) Start(ctx context.Context, cluster *virtbuf.NewCluster) error {
if cluster == nil { if cluster == nil {
return errors.New("cluster cannot be nil") return errors.New("cluster cannot be nil")
} }
@ -52,7 +65,7 @@ func (m *CloudClusterManager) Start(ctx context.Context, cluster *virtbuf.NewClu
} }
// Stop halts the specified cluster. // Stop halts the specified cluster.
func (m *CloudClusterManager) Stop(ctx context.Context, cluster *virtbuf.NewCluster) error { func (m *CloudManager) Stop(ctx context.Context, cluster *virtbuf.NewCluster) error {
if cluster == nil { if cluster == nil {
return errors.New("cluster cannot be nil") return errors.New("cluster cannot be nil")
} }
@ -66,7 +79,7 @@ func (m *CloudClusterManager) Stop(ctx context.Context, cluster *virtbuf.NewClus
} }
// List retrieves all available clusters. // List retrieves all available clusters.
func (m *CloudClusterManager) List(ctx context.Context) ([]*virtbuf.NewCluster, error) { func (m *CloudManager) List(ctx context.Context) ([]*virtbuf.NewCluster, error) {
/* /*
clusters, err := m.client.ListClusters(ctx) clusters, err := m.client.ListClusters(ctx)
if err != nil { if err != nil {
@ -78,7 +91,7 @@ func (m *CloudClusterManager) List(ctx context.Context) ([]*virtbuf.NewCluster,
} }
// Status checks the current status of a specified cluster. // Status checks the current status of a specified cluster.
func (m *CloudClusterManager) Status(ctx context.Context, cluster *virtbuf.NewCluster) (string, error) { func (m *CloudManager) Status(ctx context.Context, cluster *virtbuf.NewCluster) (string, error) {
if cluster == nil { if cluster == nil {
return "", errors.New("cluster cannot be nil") return "", errors.New("cluster cannot be nil")
} }