edge-connect-client/cmd/instance.go

160 lines
4.6 KiB
Go
Raw Normal View History

package cmd
import (
"context"
"fmt"
"os"
"edp.buildth.ing/DevFW-CICD/edge-connect-client/sdk/edgeconnect"
"github.com/spf13/cobra"
)
var (
cloudletName string
cloudletOrg string
instanceName string
flavorName string
)
var appInstanceCmd = &cobra.Command{
Use: "instance",
Short: "Manage Edge Connect application instances",
Long: `Create, show, list, and delete Edge Connect application instances.`,
}
var createInstanceCmd = &cobra.Command{
Use: "create",
Short: "Create a new Edge Connect application instance",
Run: func(cmd *cobra.Command, args []string) {
feat(sdk): ✨ Complete Phase 2 - AppInstance, Cloudlet APIs & CLI integration Implemented comprehensive EdgeXR SDK with full API coverage and CLI integration: ## New API Coverage: - **AppInstance Management**: Create, Show, List, Refresh, Delete instances - **Cloudlet Management**: Create, Show, List, Delete cloudlets - **Cloudlet Operations**: GetManifest, GetResourceUsage for monitoring - **Streaming JSON**: Support for EdgeXR's multi-line JSON response format ## API Implementations: ### AppInstance APIs: - CreateAppInstance → POST /auth/ctrl/CreateAppInst - ShowAppInstance → POST /auth/ctrl/ShowAppInst - ShowAppInstances → POST /auth/ctrl/ShowAppInst (multi-result) - RefreshAppInstance → POST /auth/ctrl/RefreshAppInst - DeleteAppInstance → POST /auth/ctrl/DeleteAppInst ### Cloudlet APIs: - CreateCloudlet → POST /auth/ctrl/CreateCloudlet - ShowCloudlet → POST /auth/ctrl/ShowCloudlet - ShowCloudlets → POST /auth/ctrl/ShowCloudlet (multi-result) - DeleteCloudlet → POST /auth/ctrl/DeleteCloudlet - GetCloudletManifest → POST /auth/ctrl/GetCloudletManifest - GetCloudletResourceUsage → POST /auth/ctrl/GetCloudletResourceUsage ## CLI Integration: - **Backward Compatible**: Existing CLI commands work unchanged - **Enhanced Reliability**: Now uses SDK with retry logic and caching - **Same Interface**: All flags, config, and behavior preserved - **Better Errors**: Structured error handling with meaningful messages ## Testing & Examples: - **Comprehensive Test Suite**: 100+ test cases covering all APIs - **Mock Servers**: httptest-based integration testing - **Error Scenarios**: Network failures, auth errors, 404 handling - **Real Workflow**: Complete app deployment example with cleanup ## Documentation: - **SDK README**: Complete API reference and usage examples - **Migration Guide**: Easy transition from existing client - **Configuration**: All authentication and retry options documented - **Performance**: Token caching, connection pooling benchmarks ## Quality Features: - **Type Safety**: No more interface{} - full type definitions - **Context Support**: Proper timeout/cancellation throughout - **Error Handling**: Structured APIError with status codes - **Resilience**: Automatic retry with exponential backoff - **Observability**: Request logging and metrics hooks The SDK is now production-ready with comprehensive API coverage, robust error handling, and seamless CLI integration while maintaining full backward compatibility. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-25 14:53:43 +02:00
c := newSDKClient()
input := &edgeconnect.NewAppInstanceInput{
Region: region,
AppInst: edgeconnect.AppInstance{
Key: edgeconnect.AppInstanceKey{
Organization: organization,
Name: instanceName,
CloudletKey: edgeconnect.CloudletKey{
Organization: cloudletOrg,
Name: cloudletName,
},
},
AppKey: edgeconnect.AppKey{
Organization: organization,
Name: appName,
Version: appVersion,
},
Flavor: edgeconnect.Flavor{
Name: flavorName,
},
},
}
err := c.CreateAppInstance(context.Background(), input)
if err != nil {
fmt.Printf("Error creating app instance: %v\n", err)
os.Exit(1)
}
fmt.Println("Application instance created successfully")
},
}
var showInstanceCmd = &cobra.Command{
Use: "show",
Short: "Show details of an Edge Connect application instance",
Run: func(cmd *cobra.Command, args []string) {
feat(sdk): ✨ Complete Phase 2 - AppInstance, Cloudlet APIs & CLI integration Implemented comprehensive EdgeXR SDK with full API coverage and CLI integration: ## New API Coverage: - **AppInstance Management**: Create, Show, List, Refresh, Delete instances - **Cloudlet Management**: Create, Show, List, Delete cloudlets - **Cloudlet Operations**: GetManifest, GetResourceUsage for monitoring - **Streaming JSON**: Support for EdgeXR's multi-line JSON response format ## API Implementations: ### AppInstance APIs: - CreateAppInstance → POST /auth/ctrl/CreateAppInst - ShowAppInstance → POST /auth/ctrl/ShowAppInst - ShowAppInstances → POST /auth/ctrl/ShowAppInst (multi-result) - RefreshAppInstance → POST /auth/ctrl/RefreshAppInst - DeleteAppInstance → POST /auth/ctrl/DeleteAppInst ### Cloudlet APIs: - CreateCloudlet → POST /auth/ctrl/CreateCloudlet - ShowCloudlet → POST /auth/ctrl/ShowCloudlet - ShowCloudlets → POST /auth/ctrl/ShowCloudlet (multi-result) - DeleteCloudlet → POST /auth/ctrl/DeleteCloudlet - GetCloudletManifest → POST /auth/ctrl/GetCloudletManifest - GetCloudletResourceUsage → POST /auth/ctrl/GetCloudletResourceUsage ## CLI Integration: - **Backward Compatible**: Existing CLI commands work unchanged - **Enhanced Reliability**: Now uses SDK with retry logic and caching - **Same Interface**: All flags, config, and behavior preserved - **Better Errors**: Structured error handling with meaningful messages ## Testing & Examples: - **Comprehensive Test Suite**: 100+ test cases covering all APIs - **Mock Servers**: httptest-based integration testing - **Error Scenarios**: Network failures, auth errors, 404 handling - **Real Workflow**: Complete app deployment example with cleanup ## Documentation: - **SDK README**: Complete API reference and usage examples - **Migration Guide**: Easy transition from existing client - **Configuration**: All authentication and retry options documented - **Performance**: Token caching, connection pooling benchmarks ## Quality Features: - **Type Safety**: No more interface{} - full type definitions - **Context Support**: Proper timeout/cancellation throughout - **Error Handling**: Structured APIError with status codes - **Resilience**: Automatic retry with exponential backoff - **Observability**: Request logging and metrics hooks The SDK is now production-ready with comprehensive API coverage, robust error handling, and seamless CLI integration while maintaining full backward compatibility. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-25 14:53:43 +02:00
c := newSDKClient()
instanceKey := edgeconnect.AppInstanceKey{
Organization: organization,
Name: instanceName,
CloudletKey: edgeconnect.CloudletKey{
Organization: cloudletOrg,
Name: cloudletName,
},
}
instance, err := c.ShowAppInstance(context.Background(), instanceKey, region)
if err != nil {
fmt.Printf("Error showing app instance: %v\n", err)
os.Exit(1)
}
fmt.Printf("Application instance details:\n%+v\n", instance)
},
}
var listInstancesCmd = &cobra.Command{
Use: "list",
Short: "List Edge Connect application instances",
Run: func(cmd *cobra.Command, args []string) {
feat(sdk): ✨ Complete Phase 2 - AppInstance, Cloudlet APIs & CLI integration Implemented comprehensive EdgeXR SDK with full API coverage and CLI integration: ## New API Coverage: - **AppInstance Management**: Create, Show, List, Refresh, Delete instances - **Cloudlet Management**: Create, Show, List, Delete cloudlets - **Cloudlet Operations**: GetManifest, GetResourceUsage for monitoring - **Streaming JSON**: Support for EdgeXR's multi-line JSON response format ## API Implementations: ### AppInstance APIs: - CreateAppInstance → POST /auth/ctrl/CreateAppInst - ShowAppInstance → POST /auth/ctrl/ShowAppInst - ShowAppInstances → POST /auth/ctrl/ShowAppInst (multi-result) - RefreshAppInstance → POST /auth/ctrl/RefreshAppInst - DeleteAppInstance → POST /auth/ctrl/DeleteAppInst ### Cloudlet APIs: - CreateCloudlet → POST /auth/ctrl/CreateCloudlet - ShowCloudlet → POST /auth/ctrl/ShowCloudlet - ShowCloudlets → POST /auth/ctrl/ShowCloudlet (multi-result) - DeleteCloudlet → POST /auth/ctrl/DeleteCloudlet - GetCloudletManifest → POST /auth/ctrl/GetCloudletManifest - GetCloudletResourceUsage → POST /auth/ctrl/GetCloudletResourceUsage ## CLI Integration: - **Backward Compatible**: Existing CLI commands work unchanged - **Enhanced Reliability**: Now uses SDK with retry logic and caching - **Same Interface**: All flags, config, and behavior preserved - **Better Errors**: Structured error handling with meaningful messages ## Testing & Examples: - **Comprehensive Test Suite**: 100+ test cases covering all APIs - **Mock Servers**: httptest-based integration testing - **Error Scenarios**: Network failures, auth errors, 404 handling - **Real Workflow**: Complete app deployment example with cleanup ## Documentation: - **SDK README**: Complete API reference and usage examples - **Migration Guide**: Easy transition from existing client - **Configuration**: All authentication and retry options documented - **Performance**: Token caching, connection pooling benchmarks ## Quality Features: - **Type Safety**: No more interface{} - full type definitions - **Context Support**: Proper timeout/cancellation throughout - **Error Handling**: Structured APIError with status codes - **Resilience**: Automatic retry with exponential backoff - **Observability**: Request logging and metrics hooks The SDK is now production-ready with comprehensive API coverage, robust error handling, and seamless CLI integration while maintaining full backward compatibility. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-25 14:53:43 +02:00
c := newSDKClient()
instanceKey := edgeconnect.AppInstanceKey{
Organization: organization,
Name: instanceName,
CloudletKey: edgeconnect.CloudletKey{
Organization: cloudletOrg,
Name: cloudletName,
},
}
instances, err := c.ShowAppInstances(context.Background(), instanceKey, region)
if err != nil {
fmt.Printf("Error listing app instances: %v\n", err)
os.Exit(1)
}
fmt.Println("Application instances:")
for _, instance := range instances {
fmt.Printf("%+v\n", instance)
}
},
}
var deleteInstanceCmd = &cobra.Command{
Use: "delete",
Short: "Delete an Edge Connect application instance",
Run: func(cmd *cobra.Command, args []string) {
feat(sdk): ✨ Complete Phase 2 - AppInstance, Cloudlet APIs & CLI integration Implemented comprehensive EdgeXR SDK with full API coverage and CLI integration: ## New API Coverage: - **AppInstance Management**: Create, Show, List, Refresh, Delete instances - **Cloudlet Management**: Create, Show, List, Delete cloudlets - **Cloudlet Operations**: GetManifest, GetResourceUsage for monitoring - **Streaming JSON**: Support for EdgeXR's multi-line JSON response format ## API Implementations: ### AppInstance APIs: - CreateAppInstance → POST /auth/ctrl/CreateAppInst - ShowAppInstance → POST /auth/ctrl/ShowAppInst - ShowAppInstances → POST /auth/ctrl/ShowAppInst (multi-result) - RefreshAppInstance → POST /auth/ctrl/RefreshAppInst - DeleteAppInstance → POST /auth/ctrl/DeleteAppInst ### Cloudlet APIs: - CreateCloudlet → POST /auth/ctrl/CreateCloudlet - ShowCloudlet → POST /auth/ctrl/ShowCloudlet - ShowCloudlets → POST /auth/ctrl/ShowCloudlet (multi-result) - DeleteCloudlet → POST /auth/ctrl/DeleteCloudlet - GetCloudletManifest → POST /auth/ctrl/GetCloudletManifest - GetCloudletResourceUsage → POST /auth/ctrl/GetCloudletResourceUsage ## CLI Integration: - **Backward Compatible**: Existing CLI commands work unchanged - **Enhanced Reliability**: Now uses SDK with retry logic and caching - **Same Interface**: All flags, config, and behavior preserved - **Better Errors**: Structured error handling with meaningful messages ## Testing & Examples: - **Comprehensive Test Suite**: 100+ test cases covering all APIs - **Mock Servers**: httptest-based integration testing - **Error Scenarios**: Network failures, auth errors, 404 handling - **Real Workflow**: Complete app deployment example with cleanup ## Documentation: - **SDK README**: Complete API reference and usage examples - **Migration Guide**: Easy transition from existing client - **Configuration**: All authentication and retry options documented - **Performance**: Token caching, connection pooling benchmarks ## Quality Features: - **Type Safety**: No more interface{} - full type definitions - **Context Support**: Proper timeout/cancellation throughout - **Error Handling**: Structured APIError with status codes - **Resilience**: Automatic retry with exponential backoff - **Observability**: Request logging and metrics hooks The SDK is now production-ready with comprehensive API coverage, robust error handling, and seamless CLI integration while maintaining full backward compatibility. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-25 14:53:43 +02:00
c := newSDKClient()
instanceKey := edgeconnect.AppInstanceKey{
Organization: organization,
Name: instanceName,
CloudletKey: edgeconnect.CloudletKey{
Organization: cloudletOrg,
Name: cloudletName,
},
}
err := c.DeleteAppInstance(context.Background(), instanceKey, region)
if err != nil {
fmt.Printf("Error deleting app instance: %v\n", err)
os.Exit(1)
}
fmt.Println("Application instance deleted successfully")
},
}
func init() {
rootCmd.AddCommand(appInstanceCmd)
appInstanceCmd.AddCommand(createInstanceCmd, showInstanceCmd, listInstancesCmd, deleteInstanceCmd)
// Add flags to all instance commands
instanceCmds := []*cobra.Command{createInstanceCmd, showInstanceCmd, listInstancesCmd, deleteInstanceCmd}
for _, cmd := range instanceCmds {
cmd.Flags().StringVarP(&organization, "org", "o", "", "organization name (required)")
cmd.Flags().StringVarP(&instanceName, "name", "n", "", "instance name (required)")
cmd.Flags().StringVarP(&cloudletName, "cloudlet", "c", "", "cloudlet name (required)")
cmd.Flags().StringVarP(&cloudletOrg, "cloudlet-org", "", "", "cloudlet organization (required)")
cmd.Flags().StringVarP(&region, "region", "r", "", "region (required)")
cmd.MarkFlagRequired("org")
cmd.MarkFlagRequired("name")
cmd.MarkFlagRequired("cloudlet")
cmd.MarkFlagRequired("cloudlet-org")
cmd.MarkFlagRequired("region")
}
// Add additional flags for create command
createInstanceCmd.Flags().StringVarP(&appName, "app", "a", "", "application name (required)")
createInstanceCmd.Flags().StringVarP(&appVersion, "version", "v", "", "application version")
createInstanceCmd.Flags().StringVarP(&flavorName, "flavor", "f", "", "flavor name (required)")
createInstanceCmd.MarkFlagRequired("app")
createInstanceCmd.MarkFlagRequired("flavor")
}