Skip to content

Commit

Permalink
[CCM-19455]: Added Cluster Orchestrator Models and Create API (#580)
Browse files Browse the repository at this point in the history
* [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
  • Loading branch information
riyasyash authored Oct 7, 2024
1 parent 6637469 commit cf18ade
Show file tree
Hide file tree
Showing 5 changed files with 257 additions and 0 deletions.
184 changes: 184 additions & 0 deletions harness/nextgen/api_cloud_cost_cluster_orchestrator.go
Original file line number Diff line number Diff line change
@@ -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
}
3 changes: 3 additions & 0 deletions harness/nextgen/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ type APIClient struct {

CloudCostRecommendationsDetailsApi *CloudCostRecommendationsDetailsApiService

CloudCostClusterOrchestratorApi *CloudCostClusterOrchestratorApiService

ConnectorsApi *ConnectorsApiService

DelegateGroupTagsResourceApi *DelegateGroupTagsResourceApiService
Expand Down Expand Up @@ -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)
Expand Down
38 changes: 38 additions & 0 deletions harness/nextgen/model_cluster_orchestrator.go
Original file line number Diff line number Diff line change
@@ -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: [email protected]
* 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"`
}
16 changes: 16 additions & 0 deletions harness/nextgen/model_create_cluster_orchestrator_dto.go
Original file line number Diff line number Diff line change
@@ -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: [email protected]
* 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"`
}
16 changes: 16 additions & 0 deletions harness/nextgen/model_create_cluster_orchestrator_response.go
Original file line number Diff line number Diff line change
@@ -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: [email protected]
* 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"`
}

0 comments on commit cf18ade

Please sign in to comment.