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,89 +4,102 @@ 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")
} }
/* /*
err := m.client.StartCluster(ctx, cluster.Id) err := m.client.StartCluster(ctx, cluster.Id)
if err != nil { if err != nil {
return fmt.Errorf("error starting cluster %q: %w", cluster.Id, err) return fmt.Errorf("error starting cluster %q: %w", cluster.Id, err)
} }
*/ */
return nil return nil
} }
// 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")
} }
/* /*
err := m.client.StopCluster(ctx, cluster.Id) err := m.client.StopCluster(ctx, cluster.Id)
if err != nil { if err != nil {
return fmt.Errorf("error stopping cluster %q: %w", cluster.Id, err) return fmt.Errorf("error stopping cluster %q: %w", cluster.Id, err)
} }
*/ */
return nil return nil
} }
// 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 {
return nil, fmt.Errorf("error listing clusters: %w", err) return nil, fmt.Errorf("error listing clusters: %w", err)
} }
return clusters, nil return clusters, nil
*/ */
return nil, errors.New("List not done yet") return nil, errors.New("List not done yet")
} }
// 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")
} }
/* /*
status, err := m.client.GetClusterStatus(ctx, cluster.Id) status, err := m.client.GetClusterStatus(ctx, cluster.Id)
if err != nil { if err != nil {
return "", fmt.Errorf("error getting status of cluster %q: %w", cluster.Id, err) return "", fmt.Errorf("error getting status of cluster %q: %w", cluster.Id, err)
} }
*/ */
return "", nil return "", nil
} }