chore(cli): Added methods to EdgeClientInterface and removed unnecessary typecasting
This commit is contained in:
parent
366fa334af
commit
6d8ed1f8d5
2 changed files with 26 additions and 43 deletions
|
|
@ -302,14 +302,8 @@ func (rm *EdgeConnectResourceManager) createApplication(ctx context.Context, act
|
|||
}
|
||||
|
||||
// Create the application
|
||||
if client, ok := rm.client.(interface {
|
||||
CreateApp(ctx context.Context, input *edgeconnect.NewAppInput) error
|
||||
}); ok {
|
||||
if err := client.CreateApp(ctx, appInput); err != nil {
|
||||
return false, fmt.Errorf("failed to create application: %w", err)
|
||||
}
|
||||
} else {
|
||||
return false, fmt.Errorf("client does not support CreateApp operation")
|
||||
if err := rm.client.CreateApp(ctx, appInput); err != nil {
|
||||
return false, fmt.Errorf("failed to create application: %w", err)
|
||||
}
|
||||
|
||||
rm.logf("Successfully created application: %s/%s version %s",
|
||||
|
|
@ -351,14 +345,8 @@ func (rm *EdgeConnectResourceManager) createInstance(ctx context.Context, action
|
|||
}
|
||||
|
||||
// Create the instance
|
||||
if client, ok := rm.client.(interface {
|
||||
CreateAppInstance(ctx context.Context, input *edgeconnect.NewAppInstanceInput) error
|
||||
}); ok {
|
||||
if err := client.CreateAppInstance(ctx, instanceInput); err != nil {
|
||||
return false, fmt.Errorf("failed to create instance: %w", err)
|
||||
}
|
||||
} else {
|
||||
return false, fmt.Errorf("client does not support CreateAppInstance operation")
|
||||
if err := rm.client.CreateAppInstance(ctx, instanceInput); err != nil {
|
||||
return false, fmt.Errorf("failed to create instance: %w", err)
|
||||
}
|
||||
|
||||
rm.logf("Successfully created instance: %s on %s:%s",
|
||||
|
|
@ -498,41 +486,32 @@ func (rm *EdgeConnectResourceManager) rollbackCreateAction(ctx context.Context,
|
|||
|
||||
// rollbackApp deletes an application that was created
|
||||
func (rm *EdgeConnectResourceManager) rollbackApp(ctx context.Context, action ActionResult, plan *DeploymentPlan) error {
|
||||
if client, ok := rm.client.(interface {
|
||||
DeleteApp(ctx context.Context, appKey edgeconnect.AppKey, region string) error
|
||||
}); ok {
|
||||
appKey := edgeconnect.AppKey{
|
||||
Organization: plan.AppAction.Desired.Organization,
|
||||
Name: plan.AppAction.Desired.Name,
|
||||
Version: plan.AppAction.Desired.Version,
|
||||
}
|
||||
return client.DeleteApp(ctx, appKey, plan.AppAction.Desired.Region)
|
||||
appKey := edgeconnect.AppKey{
|
||||
Organization: plan.AppAction.Desired.Organization,
|
||||
Name: plan.AppAction.Desired.Name,
|
||||
Version: plan.AppAction.Desired.Version,
|
||||
}
|
||||
return fmt.Errorf("client does not support DeleteApp operation")
|
||||
|
||||
return rm.client.DeleteApp(ctx, appKey, plan.AppAction.Desired.Region)
|
||||
}
|
||||
|
||||
// rollbackInstance deletes an instance that was created
|
||||
func (rm *EdgeConnectResourceManager) rollbackInstance(ctx context.Context, action ActionResult, plan *DeploymentPlan) error {
|
||||
if client, ok := rm.client.(interface {
|
||||
DeleteAppInstance(ctx context.Context, instanceKey edgeconnect.AppInstanceKey, region string) error
|
||||
}); ok {
|
||||
// Find the instance action to get the details
|
||||
for _, instanceAction := range plan.InstanceActions {
|
||||
if instanceAction.InstanceName == action.Target {
|
||||
instanceKey := edgeconnect.AppInstanceKey{
|
||||
Organization: instanceAction.Target.Organization,
|
||||
Name: instanceAction.InstanceName,
|
||||
CloudletKey: edgeconnect.CloudletKey{
|
||||
Organization: instanceAction.Target.CloudletOrg,
|
||||
Name: instanceAction.Target.CloudletName,
|
||||
},
|
||||
}
|
||||
return client.DeleteAppInstance(ctx, instanceKey, instanceAction.Target.Region)
|
||||
// Find the instance action to get the details
|
||||
for _, instanceAction := range plan.InstanceActions {
|
||||
if instanceAction.InstanceName == action.Target {
|
||||
instanceKey := edgeconnect.AppInstanceKey{
|
||||
Organization: instanceAction.Target.Organization,
|
||||
Name: instanceAction.InstanceName,
|
||||
CloudletKey: edgeconnect.CloudletKey{
|
||||
Organization: instanceAction.Target.CloudletOrg,
|
||||
Name: instanceAction.Target.CloudletName,
|
||||
},
|
||||
}
|
||||
return rm.client.DeleteAppInstance(ctx, instanceKey, instanceAction.Target.Region)
|
||||
}
|
||||
return fmt.Errorf("instance action not found for rollback: %s", action.Target)
|
||||
}
|
||||
return fmt.Errorf("client does not support DeleteAppInstance operation")
|
||||
return fmt.Errorf("instance action not found for rollback: %s", action.Target)
|
||||
}
|
||||
|
||||
// logf logs a message if a logger is configured
|
||||
|
|
|
|||
|
|
@ -18,7 +18,11 @@ import (
|
|||
// EdgeConnectClientInterface defines the methods needed for deployment planning
|
||||
type EdgeConnectClientInterface interface {
|
||||
ShowApp(ctx context.Context, appKey edgeconnect.AppKey, region string) (edgeconnect.App, error)
|
||||
CreateApp(ctx context.Context, input *edgeconnect.NewAppInput) error
|
||||
DeleteApp(ctx context.Context, appKey edgeconnect.AppKey, region string) error
|
||||
ShowAppInstance(ctx context.Context, instanceKey edgeconnect.AppInstanceKey, region string) (edgeconnect.AppInstance, error)
|
||||
CreateAppInstance(ctx context.Context, input *edgeconnect.NewAppInstanceInput) error
|
||||
DeleteAppInstance(ctx context.Context, instanceKey edgeconnect.AppInstanceKey, region string) error
|
||||
}
|
||||
|
||||
// Planner defines the interface for deployment planning
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue