feat(api): Added AppKey property to ShowAppInstances
This commit is contained in:
parent
ece3dddfe6
commit
a51e2ae454
11 changed files with 35 additions and 25 deletions
|
|
@ -15,6 +15,7 @@ var (
|
||||||
cloudletOrg string
|
cloudletOrg string
|
||||||
instanceName string
|
instanceName string
|
||||||
flavorName string
|
flavorName string
|
||||||
|
appId string
|
||||||
)
|
)
|
||||||
|
|
||||||
var appInstanceCmd = &cobra.Command{
|
var appInstanceCmd = &cobra.Command{
|
||||||
|
|
@ -104,7 +105,8 @@ var showInstanceCmd = &cobra.Command{
|
||||||
Name: cloudletName,
|
Name: cloudletName,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
instance, err := c.ShowAppInstance(context.Background(), instanceKey, region)
|
appkey := edgeconnect.AppKey{Name: appId}
|
||||||
|
instance, err := c.ShowAppInstance(context.Background(), instanceKey, appkey, region)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("Error showing app instance: %v\n", err)
|
fmt.Printf("Error showing app instance: %v\n", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
|
|
@ -120,7 +122,8 @@ var showInstanceCmd = &cobra.Command{
|
||||||
Name: cloudletName,
|
Name: cloudletName,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
instance, err := c.ShowAppInstance(context.Background(), instanceKey, region)
|
appkey := v2.AppKey{Name: appId}
|
||||||
|
instance, err := c.ShowAppInstance(context.Background(), instanceKey, appkey, region)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("Error showing app instance: %v\n", err)
|
fmt.Printf("Error showing app instance: %v\n", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
|
|
@ -229,6 +232,7 @@ func init() {
|
||||||
cmd.Flags().StringVarP(&cloudletName, "cloudlet", "c", "", "cloudlet name (required)")
|
cmd.Flags().StringVarP(&cloudletName, "cloudlet", "c", "", "cloudlet name (required)")
|
||||||
cmd.Flags().StringVarP(&cloudletOrg, "cloudlet-org", "", "", "cloudlet organization (required)")
|
cmd.Flags().StringVarP(&cloudletOrg, "cloudlet-org", "", "", "cloudlet organization (required)")
|
||||||
cmd.Flags().StringVarP(®ion, "region", "r", "", "region (required)")
|
cmd.Flags().StringVarP(®ion, "region", "r", "", "region (required)")
|
||||||
|
cmd.Flags().StringVarP(&appId, "app-id", "i", "", "application id")
|
||||||
|
|
||||||
if err := cmd.MarkFlagRequired("org"); err != nil {
|
if err := cmd.MarkFlagRequired("org"); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ type EdgeConnectClientInterface interface {
|
||||||
CreateApp(ctx context.Context, input *edgeconnect.NewAppInput) error
|
CreateApp(ctx context.Context, input *edgeconnect.NewAppInput) error
|
||||||
UpdateApp(ctx context.Context, input *edgeconnect.UpdateAppInput) error
|
UpdateApp(ctx context.Context, input *edgeconnect.UpdateAppInput) error
|
||||||
DeleteApp(ctx context.Context, appKey edgeconnect.AppKey, region string) error
|
DeleteApp(ctx context.Context, appKey edgeconnect.AppKey, region string) error
|
||||||
ShowAppInstance(ctx context.Context, instanceKey edgeconnect.AppInstanceKey, region string) (edgeconnect.AppInstance, error)
|
ShowAppInstance(ctx context.Context, instanceKey edgeconnect.AppInstanceKey, appKey edgeconnect.AppKey, region string) (edgeconnect.AppInstance, error)
|
||||||
CreateAppInstance(ctx context.Context, input *edgeconnect.NewAppInstanceInput) error
|
CreateAppInstance(ctx context.Context, input *edgeconnect.NewAppInstanceInput) error
|
||||||
UpdateAppInstance(ctx context.Context, input *edgeconnect.UpdateAppInstanceInput) error
|
UpdateAppInstance(ctx context.Context, input *edgeconnect.UpdateAppInstanceInput) error
|
||||||
DeleteAppInstance(ctx context.Context, instanceKey edgeconnect.AppInstanceKey, region string) error
|
DeleteAppInstance(ctx context.Context, instanceKey edgeconnect.AppInstanceKey, region string) error
|
||||||
|
|
@ -342,8 +342,11 @@ func (p *EdgeConnectPlanner) getCurrentInstanceState(ctx context.Context, desire
|
||||||
Name: desired.CloudletName,
|
Name: desired.CloudletName,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
appKey := edgeconnect.AppKey{
|
||||||
|
Name: desired.AppName,
|
||||||
|
}
|
||||||
|
|
||||||
instance, err := p.client.ShowAppInstance(timeoutCtx, instanceKey, desired.Region)
|
instance, err := p.client.ShowAppInstance(timeoutCtx, instanceKey, appKey, desired.Region)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,7 @@ func (m *MockEdgeConnectClient) ShowApp(ctx context.Context, appKey edgeconnect.
|
||||||
return args.Get(0).(edgeconnect.App), args.Error(1)
|
return args.Get(0).(edgeconnect.App), args.Error(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *MockEdgeConnectClient) ShowAppInstance(ctx context.Context, instanceKey edgeconnect.AppInstanceKey, region string) (edgeconnect.AppInstance, error) {
|
func (m *MockEdgeConnectClient) ShowAppInstance(ctx context.Context, instanceKey edgeconnect.AppInstanceKey, appKey edgeconnect.AppKey, region string) (edgeconnect.AppInstance, error) {
|
||||||
args := m.Called(ctx, instanceKey, region)
|
args := m.Called(ctx, instanceKey, region)
|
||||||
if args.Get(0) == nil {
|
if args.Get(0) == nil {
|
||||||
return edgeconnect.AppInstance{}, args.Error(1)
|
return edgeconnect.AppInstance{}, args.Error(1)
|
||||||
|
|
@ -75,14 +75,6 @@ func (m *MockEdgeConnectClient) ShowApps(ctx context.Context, appKey edgeconnect
|
||||||
return args.Get(0).([]edgeconnect.App), args.Error(1)
|
return args.Get(0).([]edgeconnect.App), args.Error(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *MockEdgeConnectClient) ShowAppInstances(ctx context.Context, instanceKey edgeconnect.AppInstanceKey, region string) ([]edgeconnect.AppInstance, error) {
|
|
||||||
args := m.Called(ctx, instanceKey, region)
|
|
||||||
if args.Get(0) == nil {
|
|
||||||
return nil, args.Error(1)
|
|
||||||
}
|
|
||||||
return args.Get(0).([]edgeconnect.AppInstance), args.Error(1)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestNewPlanner(t *testing.T) {
|
func TestNewPlanner(t *testing.T) {
|
||||||
mockClient := &MockEdgeConnectClient{}
|
mockClient := &MockEdgeConnectClient{}
|
||||||
planner := NewPlanner(mockClient)
|
planner := NewPlanner(mockClient)
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ type EdgeConnectClientInterface interface {
|
||||||
CreateApp(ctx context.Context, input *v2.NewAppInput) error
|
CreateApp(ctx context.Context, input *v2.NewAppInput) error
|
||||||
UpdateApp(ctx context.Context, input *v2.UpdateAppInput) error
|
UpdateApp(ctx context.Context, input *v2.UpdateAppInput) error
|
||||||
DeleteApp(ctx context.Context, appKey v2.AppKey, region string) error
|
DeleteApp(ctx context.Context, appKey v2.AppKey, region string) error
|
||||||
ShowAppInstance(ctx context.Context, instanceKey v2.AppInstanceKey, region string) (v2.AppInstance, error)
|
ShowAppInstance(ctx context.Context, instanceKey v2.AppInstanceKey, appKey v2.AppKey, region string) (v2.AppInstance, error)
|
||||||
CreateAppInstance(ctx context.Context, input *v2.NewAppInstanceInput) error
|
CreateAppInstance(ctx context.Context, input *v2.NewAppInstanceInput) error
|
||||||
UpdateAppInstance(ctx context.Context, input *v2.UpdateAppInstanceInput) error
|
UpdateAppInstance(ctx context.Context, input *v2.UpdateAppInstanceInput) error
|
||||||
DeleteAppInstance(ctx context.Context, instanceKey v2.AppInstanceKey, region string) error
|
DeleteAppInstance(ctx context.Context, instanceKey v2.AppInstanceKey, region string) error
|
||||||
|
|
@ -343,7 +343,10 @@ func (p *EdgeConnectPlanner) getCurrentInstanceState(ctx context.Context, desire
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
instance, err := p.client.ShowAppInstance(timeoutCtx, instanceKey, desired.Region)
|
appKey := v2.AppKey{ Name: desired.AppName}
|
||||||
|
|
||||||
|
|
||||||
|
instance, err := p.client.ShowAppInstance(timeoutCtx, instanceKey, appKey, desired.Region)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,7 @@ func (m *MockEdgeConnectClient) ShowApp(ctx context.Context, appKey v2.AppKey, r
|
||||||
return args.Get(0).(v2.App), args.Error(1)
|
return args.Get(0).(v2.App), args.Error(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *MockEdgeConnectClient) ShowAppInstance(ctx context.Context, instanceKey v2.AppInstanceKey, region string) (v2.AppInstance, error) {
|
func (m *MockEdgeConnectClient) ShowAppInstance(ctx context.Context, instanceKey v2.AppInstanceKey, appKey v2.AppKey, region string) (v2.AppInstance, error) {
|
||||||
args := m.Called(ctx, instanceKey, region)
|
args := m.Called(ctx, instanceKey, region)
|
||||||
if args.Get(0) == nil {
|
if args.Get(0) == nil {
|
||||||
return v2.AppInstance{}, args.Error(1)
|
return v2.AppInstance{}, args.Error(1)
|
||||||
|
|
|
||||||
|
|
@ -586,7 +586,9 @@ func (r *RecreateStrategy) backupInstance(ctx context.Context, action InstanceAc
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
instance, err := r.client.ShowAppInstance(ctx, instanceKey, action.Target.Region)
|
appKey := v2.AppKey{ Name: action.Desired.AppName }
|
||||||
|
|
||||||
|
instance, err := r.client.ShowAppInstance(ctx, instanceKey, appKey, action.Target.Region)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to fetch instance for backup: %w", err)
|
return nil, fmt.Errorf("failed to fetch instance for backup: %w", err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -45,12 +45,12 @@ func (c *Client) CreateAppInstance(ctx context.Context, input *NewAppInstanceInp
|
||||||
|
|
||||||
// ShowAppInstance retrieves a single application instance by key and region
|
// ShowAppInstance retrieves a single application instance by key and region
|
||||||
// Maps to POST /auth/ctrl/ShowAppInst
|
// Maps to POST /auth/ctrl/ShowAppInst
|
||||||
func (c *Client) ShowAppInstance(ctx context.Context, appInstKey AppInstanceKey, region string) (AppInstance, error) {
|
func (c *Client) ShowAppInstance(ctx context.Context, appInstKey AppInstanceKey, appKey AppKey, region string) (AppInstance, error) {
|
||||||
transport := c.getTransport()
|
transport := c.getTransport()
|
||||||
url := c.BaseURL + "/api/v1/auth/ctrl/ShowAppInst"
|
url := c.BaseURL + "/api/v1/auth/ctrl/ShowAppInst"
|
||||||
|
|
||||||
filter := AppInstanceFilter{
|
filter := AppInstanceFilter{
|
||||||
AppInstance: AppInstance{Key: appInstKey},
|
AppInstance: AppInstance{AppKey: appKey, Key: appInstKey},
|
||||||
Region: region,
|
Region: region,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -156,6 +156,7 @@ func TestCreateAppInstance(t *testing.T) {
|
||||||
func TestShowAppInstance(t *testing.T) {
|
func TestShowAppInstance(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
|
appKey AppKey
|
||||||
appInstKey AppInstanceKey
|
appInstKey AppInstanceKey
|
||||||
region string
|
region string
|
||||||
mockStatusCode int
|
mockStatusCode int
|
||||||
|
|
@ -173,6 +174,7 @@ func TestShowAppInstance(t *testing.T) {
|
||||||
Name: "testcloudlet",
|
Name: "testcloudlet",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
appKey: AppKey{Name: "test-app-id"},
|
||||||
region: "us-west",
|
region: "us-west",
|
||||||
mockStatusCode: 200,
|
mockStatusCode: 200,
|
||||||
mockResponse: `{"data": {"key": {"organization": "testorg", "name": "testinst", "cloudlet_key": {"organization": "cloudletorg", "name": "testcloudlet"}}, "state": "Ready"}}
|
mockResponse: `{"data": {"key": {"organization": "testorg", "name": "testinst", "cloudlet_key": {"organization": "cloudletorg", "name": "testcloudlet"}}, "state": "Ready"}}
|
||||||
|
|
@ -190,6 +192,7 @@ func TestShowAppInstance(t *testing.T) {
|
||||||
Name: "testcloudlet",
|
Name: "testcloudlet",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
appKey: AppKey{Name: "test-app-id"},
|
||||||
region: "us-west",
|
region: "us-west",
|
||||||
mockStatusCode: 404,
|
mockStatusCode: 404,
|
||||||
mockResponse: "",
|
mockResponse: "",
|
||||||
|
|
@ -219,7 +222,7 @@ func TestShowAppInstance(t *testing.T) {
|
||||||
|
|
||||||
// Execute test
|
// Execute test
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
appInst, err := client.ShowAppInstance(ctx, tt.appInstKey, tt.region)
|
appInst, err := client.ShowAppInstance(ctx, tt.appInstKey, tt.appKey, tt.region)
|
||||||
|
|
||||||
// Verify results
|
// Verify results
|
||||||
if tt.expectError {
|
if tt.expectError {
|
||||||
|
|
|
||||||
|
|
@ -47,7 +47,7 @@ func (c *Client) CreateAppInstance(ctx context.Context, input *NewAppInstanceInp
|
||||||
|
|
||||||
// ShowAppInstance retrieves a single application instance by key and region
|
// ShowAppInstance retrieves a single application instance by key and region
|
||||||
// Maps to POST /auth/ctrl/ShowAppInst
|
// Maps to POST /auth/ctrl/ShowAppInst
|
||||||
func (c *Client) ShowAppInstance(ctx context.Context, appInstKey AppInstanceKey, region string) (AppInstance, error) {
|
func (c *Client) ShowAppInstance(ctx context.Context, appInstKey AppInstanceKey, appKey AppKey, region string) (AppInstance, error) {
|
||||||
transport := c.getTransport()
|
transport := c.getTransport()
|
||||||
url := c.BaseURL + "/api/v1/auth/ctrl/ShowAppInst"
|
url := c.BaseURL + "/api/v1/auth/ctrl/ShowAppInst"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -157,6 +157,7 @@ func TestShowAppInstance(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
appInstKey AppInstanceKey
|
appInstKey AppInstanceKey
|
||||||
|
appKey AppKey
|
||||||
region string
|
region string
|
||||||
mockStatusCode int
|
mockStatusCode int
|
||||||
mockResponse string
|
mockResponse string
|
||||||
|
|
@ -173,6 +174,7 @@ func TestShowAppInstance(t *testing.T) {
|
||||||
Name: "testcloudlet",
|
Name: "testcloudlet",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
appKey: AppKey{ Name: "testapp" },
|
||||||
region: "us-west",
|
region: "us-west",
|
||||||
mockStatusCode: 200,
|
mockStatusCode: 200,
|
||||||
mockResponse: `{"data": {"key": {"organization": "testorg", "name": "testinst", "cloudlet_key": {"organization": "cloudletorg", "name": "testcloudlet"}}, "state": "Ready"}}
|
mockResponse: `{"data": {"key": {"organization": "testorg", "name": "testinst", "cloudlet_key": {"organization": "cloudletorg", "name": "testcloudlet"}}, "state": "Ready"}}
|
||||||
|
|
@ -190,6 +192,7 @@ func TestShowAppInstance(t *testing.T) {
|
||||||
Name: "testcloudlet",
|
Name: "testcloudlet",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
appKey: AppKey{ Name: "testapp" },
|
||||||
region: "us-west",
|
region: "us-west",
|
||||||
mockStatusCode: 404,
|
mockStatusCode: 404,
|
||||||
mockResponse: "",
|
mockResponse: "",
|
||||||
|
|
@ -219,7 +222,7 @@ func TestShowAppInstance(t *testing.T) {
|
||||||
|
|
||||||
// Execute test
|
// Execute test
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
appInst, err := client.ShowAppInstance(ctx, tt.appInstKey, tt.region)
|
appInst, err := client.ShowAppInstance(ctx, tt.appInstKey, tt.appKey, tt.region)
|
||||||
|
|
||||||
// Verify results
|
// Verify results
|
||||||
if tt.expectError {
|
if tt.expectError {
|
||||||
|
|
|
||||||
|
|
@ -193,7 +193,7 @@ func runComprehensiveWorkflow(ctx context.Context, c *v2.Client, config Workflow
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
instanceDetails, err := waitForInstanceReady(ctx, c, instanceKey, config.Region, 5*time.Minute)
|
instanceDetails, err := waitForInstanceReady(ctx, c, instanceKey, v2.AppKey{}, config.Region, 5*time.Minute)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to wait for instance ready: %w", err)
|
return fmt.Errorf("failed to wait for instance ready: %w", err)
|
||||||
}
|
}
|
||||||
|
|
@ -306,7 +306,7 @@ func getEnvOrDefault(key, defaultValue string) string {
|
||||||
}
|
}
|
||||||
|
|
||||||
// waitForInstanceReady polls the instance status until it's no longer "Creating" or timeout
|
// waitForInstanceReady polls the instance status until it's no longer "Creating" or timeout
|
||||||
func waitForInstanceReady(ctx context.Context, c *v2.Client, instanceKey v2.AppInstanceKey, region string, timeout time.Duration) (v2.AppInstance, error) {
|
func waitForInstanceReady(ctx context.Context, c *v2.Client, instanceKey v2.AppInstanceKey, appKey v2.AppKey, region string, timeout time.Duration) (v2.AppInstance, error) {
|
||||||
timeoutCtx, cancel := context.WithTimeout(ctx, timeout)
|
timeoutCtx, cancel := context.WithTimeout(ctx, timeout)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
|
|
@ -321,7 +321,7 @@ func waitForInstanceReady(ctx context.Context, c *v2.Client, instanceKey v2.AppI
|
||||||
return v2.AppInstance{}, fmt.Errorf("timeout waiting for instance to be ready after %v", timeout)
|
return v2.AppInstance{}, fmt.Errorf("timeout waiting for instance to be ready after %v", timeout)
|
||||||
|
|
||||||
case <-ticker.C:
|
case <-ticker.C:
|
||||||
instance, err := c.ShowAppInstance(timeoutCtx, instanceKey, region)
|
instance, err := c.ShowAppInstance(timeoutCtx, instanceKey, appKey, region)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// Log error but continue polling
|
// Log error but continue polling
|
||||||
fmt.Printf(" ⚠️ Error checking instance state: %v\n", err)
|
fmt.Printf(" ⚠️ Error checking instance state: %v\n", err)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue