From cf18adee14a996eafd1c6bdb19628dc36faff8b8 Mon Sep 17 00:00:00 2001 From: RIYAS P <riyasyash@gmail.com> Date: Mon, 7 Oct 2024 13:04:21 +0530 Subject: [PATCH] [CCM-19455]: Added Cluster Orchestrator Models and Create API (#580) * [CCM-19455]: Added Cluster Orchestrator Models and Create API * added CloudCostClusterOrchestratorApiService to Client * added ClusterOrchestratorDetails method * changed response of cluster orch details api * Added K8sConnID to CreateClusterOrchestratorDto * Added application/json content type --- .../api_cloud_cost_cluster_orchestrator.go | 184 ++++++++++++++++++ harness/nextgen/client.go | 3 + harness/nextgen/model_cluster_orchestrator.go | 38 ++++ .../model_create_cluster_orchestrator_dto.go | 16 ++ ...el_create_cluster_orchestrator_response.go | 16 ++ 5 files changed, 257 insertions(+) create mode 100644 harness/nextgen/api_cloud_cost_cluster_orchestrator.go create mode 100644 harness/nextgen/model_cluster_orchestrator.go create mode 100644 harness/nextgen/model_create_cluster_orchestrator_dto.go create mode 100644 harness/nextgen/model_create_cluster_orchestrator_response.go diff --git a/harness/nextgen/api_cloud_cost_cluster_orchestrator.go b/harness/nextgen/api_cloud_cost_cluster_orchestrator.go new file mode 100644 index 00000000..59816f9f --- /dev/null +++ b/harness/nextgen/api_cloud_cost_cluster_orchestrator.go @@ -0,0 +1,184 @@ +package nextgen + +import ( + "context" + "fmt" + "io/ioutil" + "net/http" + "net/url" + "strings" +) + +type CloudCostClusterOrchestratorApiService service + +func (a *CloudCostClusterOrchestratorApiService) CreateClusterOrchestrator(ctx context.Context, accountIdentifier string, body CreateClusterOrchestratorDto) (ClusterOrchestratorResponse, *http.Response, error) { + var ( + localVarHttpMethod = strings.ToUpper("Post") + localVarPostBody interface{} + localVarFileName string + localVarFileBytes []byte + localVarReturnValue ClusterOrchestratorResponse + ) + + localVarPath := a.client.cfg.BasePath + "/lw/api/accounts/{account_id}/clusters/orchestrator" + localVarPath = strings.Replace(localVarPath, "{"+"account_id"+"}", fmt.Sprintf("%v", accountIdentifier), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + localVarQueryParams.Add("accountIdentifier", parameterToString(accountIdentifier, "")) + // to determine the Content-Type header + localVarHttpContentTypes := []string{"application/json"} + + // set Content-Type header + localVarHttpContentType := selectHeaderContentType(localVarHttpContentTypes) + if localVarHttpContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHttpContentType + } + + // to determine the Accept header + localVarHttpHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHttpHeaderAccept := selectHeaderAccept(localVarHttpHeaderAccepts) + if localVarHttpHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHttpHeaderAccept + } + // body params + localVarPostBody = &body + if ctx != nil { + // API Key Authentication + if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok { + var key string + if auth.Prefix != "" { + key = auth.Prefix + " " + auth.Key + } else { + key = auth.Key + } + localVarHeaderParams["x-api-key"] = key + + } + } + r, err := a.client.prepareRequest(ctx, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes) + if err != nil { + return localVarReturnValue, nil, err + } + + localVarHttpResponse, err := a.client.callAPI(r) + if err != nil || localVarHttpResponse == nil { + return localVarReturnValue, localVarHttpResponse, err + } + + localVarBody, err := ioutil.ReadAll(localVarHttpResponse.Body) + localVarHttpResponse.Body.Close() + if err != nil { + return localVarReturnValue, localVarHttpResponse, err + } + + err = a.client.decode(&localVarReturnValue, localVarBody, localVarHttpResponse.Header.Get("Content-Type")) + if localVarHttpResponse.StatusCode < 300 { + // If we succeed, return the data, otherwise pass on to decode error. + return localVarReturnValue, localVarHttpResponse, err + } + + if localVarHttpResponse.StatusCode >= 300 { + newErr := GenericSwaggerError{ + body: localVarBody, + error: localVarHttpResponse.Status, + } + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHttpResponse, newErr + } + newErr.error = strings.Join(localVarReturnValue.Errors, ", ") + return localVarReturnValue, localVarHttpResponse, newErr + } + + return localVarReturnValue, localVarHttpResponse, nil +} +func (a *CloudCostClusterOrchestratorApiService) ClusterOrchestratorDetails(ctx context.Context, accountIdentifier string, Identifier string) (ClusterOrchestratorResponse, *http.Response, error) { + var ( + localVarHttpMethod = strings.ToUpper("Get") + localVarPostBody interface{} + localVarFileName string + localVarFileBytes []byte + localVarReturnValue ClusterOrchestratorResponse + ) + + // create path and map variables + localVarPath := a.client.cfg.BasePath + "/lw/api/accounts/{account_id}/clusters/orchestrator/{cluster_id}" + localVarPath = strings.Replace(localVarPath, "{"+"account_id"+"}", fmt.Sprintf("%v", accountIdentifier), -1) + localVarPath = strings.Replace(localVarPath, "{"+"cluster_id"+"}", fmt.Sprintf("%v", Identifier), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + localVarQueryParams.Add("accountIdentifier", parameterToString(accountIdentifier, "")) + // to determine the Content-Type header + localVarHttpContentTypes := []string{} + + // set Content-Type header + localVarHttpContentType := selectHeaderContentType(localVarHttpContentTypes) + if localVarHttpContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHttpContentType + } + + // to determine the Accept header + localVarHttpHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHttpHeaderAccept := selectHeaderAccept(localVarHttpHeaderAccepts) + if localVarHttpHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHttpHeaderAccept + } + if ctx != nil { + // API Key Authentication + if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok { + var key string + if auth.Prefix != "" { + key = auth.Prefix + " " + auth.Key + } else { + key = auth.Key + } + localVarHeaderParams["x-api-key"] = key + } + } + r, err := a.client.prepareRequest(ctx, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes) + if err != nil { + return localVarReturnValue, nil, err + } + + localVarHttpResponse, err := a.client.callAPI(r) + if err != nil || localVarHttpResponse == nil { + return localVarReturnValue, localVarHttpResponse, err + } + + localVarBody, err := ioutil.ReadAll(localVarHttpResponse.Body) + localVarHttpResponse.Body.Close() + if err != nil { + return localVarReturnValue, localVarHttpResponse, err + } + + err = a.client.decode(&localVarReturnValue, localVarBody, localVarHttpResponse.Header.Get("Content-Type")) + if localVarHttpResponse.StatusCode < 300 { + // If we succeed, return the data, otherwise pass on to decode error. + return localVarReturnValue, localVarHttpResponse, err + } + + if localVarHttpResponse.StatusCode >= 300 { + newErr := GenericSwaggerError{ + body: localVarBody, + error: localVarHttpResponse.Status, + } + if err != nil { + newErr.error = err.Error() + return localVarReturnValue, localVarHttpResponse, newErr + } + newErr.error = strings.Join(localVarReturnValue.Errors, ", ") + return localVarReturnValue, localVarHttpResponse, newErr + } + + return localVarReturnValue, localVarHttpResponse, nil +} diff --git a/harness/nextgen/client.go b/harness/nextgen/client.go index a8c8fd07..da133b04 100644 --- a/harness/nextgen/client.go +++ b/harness/nextgen/client.go @@ -94,6 +94,8 @@ type APIClient struct { CloudCostRecommendationsDetailsApi *CloudCostRecommendationsDetailsApiService + CloudCostClusterOrchestratorApi *CloudCostClusterOrchestratorApiService + ConnectorsApi *ConnectorsApiService DelegateGroupTagsResourceApi *DelegateGroupTagsResourceApiService @@ -266,6 +268,7 @@ func NewAPIClient(cfg *Configuration) *APIClient { c.CloudCostPerspectivesApi = (*CloudCostPerspectivesApiService)(&c.common) c.CloudCostRecommendationsApi = (*CloudCostRecommendationsApiService)(&c.common) c.CloudCostRecommendationsDetailsApi = (*CloudCostRecommendationsDetailsApiService)(&c.common) + c.CloudCostClusterOrchestratorApi = (*CloudCostClusterOrchestratorApiService)(&c.common) c.ConnectorsApi = (*ConnectorsApiService)(&c.common) c.DelegateGroupTagsResourceApi = (*DelegateGroupTagsResourceApiService)(&c.common) c.DelegateTokenResourceApi = (*DelegateTokenResourceApiService)(&c.common) diff --git a/harness/nextgen/model_cluster_orchestrator.go b/harness/nextgen/model_cluster_orchestrator.go new file mode 100644 index 00000000..445243a9 --- /dev/null +++ b/harness/nextgen/model_cluster_orchestrator.go @@ -0,0 +1,38 @@ +/* + * Harness NextGen Software Delivery Platform API Reference + * + * This is the Open Api Spec 3 for the NextGen Manager. This is under active development. Beware of the breaking change with respect to the generated code stub # Authentication <!-- ReDoc-Inject: <security-definitions> --> + * + * API version: 3.0 + * Contact: contact@harness.io + * Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git) + */ +package nextgen + +type ClusterOrchDistributionSelector string +type ClusterOrchNodeDistributionStrategy string + +type ClusterOrchConfig struct { + SpotDistribution ClusterOrchDistributionSelector `json:"spot_distribution"` + NodeDeletionDelay int `json:"node_deletion_delay"` + DistributionStrategy ClusterOrchNodeDistributionStrategy `json:"distribution_strategy"` + BaseOnDemandCapacity int `json:"base_on_demand_capacity"` + SpotSplit int `json:"spot_split"` + OnDemandSplit int `json:"on_demand_split"` +} + +type ClusterOrchestratorUserConfig struct { + ClusterEndPoint string `json:"cluster_endpoint"` +} + +type ClusterOrchestrator struct { + ID string `json:"id" db:"id"` + AccountID string `json:"account_id" db:"account_id"` + K8sConnectorID string `json:"k8s_connector_id" db:"k8s_connector_id"` + CloudAccID string `json:"cloud_account_id" db:"cloud_account_id"` + Name string `json:"name" db:"name"` + Config *ClusterOrchConfig `json:"config" db:"config"` + UserConfig *ClusterOrchestratorUserConfig `json:"user_config,omitempty" db:"user_config"` + OptimizationEnabled bool `json:"optimization_enabled" db:"optimization_enabled"` + Disabled bool `json:"-" db:"disabled"` +} diff --git a/harness/nextgen/model_create_cluster_orchestrator_dto.go b/harness/nextgen/model_create_cluster_orchestrator_dto.go new file mode 100644 index 00000000..f0cffc2e --- /dev/null +++ b/harness/nextgen/model_create_cluster_orchestrator_dto.go @@ -0,0 +1,16 @@ +/* + * Harness NextGen Software Delivery Platform API Reference + * + * This is the Open Api Spec 3 for the NextGen Manager. This is under active development. Beware of the breaking change with respect to the generated code stub # Authentication <!-- ReDoc-Inject: <security-definitions> --> + * + * API version: 3.0 + * Contact: contact@harness.io + * Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git) + */ +package nextgen + +type CreateClusterOrchestratorDto struct { + Name string `json:"name"` + K8sConnID string `json:"k8s_connector_id"` + UserConfig ClusterOrchestratorUserConfig `json:"user_config"` +} diff --git a/harness/nextgen/model_create_cluster_orchestrator_response.go b/harness/nextgen/model_create_cluster_orchestrator_response.go new file mode 100644 index 00000000..bc51d23c --- /dev/null +++ b/harness/nextgen/model_create_cluster_orchestrator_response.go @@ -0,0 +1,16 @@ +/* + * Harness NextGen Software Delivery Platform API Reference + * + * This is the Open Api Spec 3 for the NextGen Manager. This is under active development. Beware of the breaking change with respect to the generated code stub # Authentication <!-- ReDoc-Inject: <security-definitions> --> + * + * API version: 3.0 + * Contact: contact@harness.io + * Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git) + */ +package nextgen + +type ClusterOrchestratorResponse struct { + Response *ClusterOrchestrator `json:"response,omitempty"` + Errors []string `json:"errors,omitempty"` + Success bool `json:"success"` +}