Skip to content

Commit

Permalink
Merge pull request #11 from MZC-CSC/main
Browse files Browse the repository at this point in the history
Initial version of the API function to update and query migrated infrastructure cost information in AWS.
  • Loading branch information
MZC-CSC authored Aug 19, 2024
2 parents 23db5d0 + b7f480c commit 2191bd3
Show file tree
Hide file tree
Showing 22 changed files with 1,748 additions and 77 deletions.
322 changes: 311 additions & 11 deletions api/docs.go

Large diffs are not rendered by default.

322 changes: 311 additions & 11 deletions api/swagger.json

Large diffs are not rendered by default.

231 changes: 220 additions & 11 deletions api/swagger.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
basePath: /ant
definitions:
app.AntResponse-array_cost_GetCostInfoResult:
properties:
code:
type: integer
errorMessage:
type: string
result:
items:
$ref: '#/definitions/cost.GetCostInfoResult'
type: array
successMessage:
type: string
type: object
app.AntResponse-array_load_LoadTestStatistics:
properties:
code:
Expand Down Expand Up @@ -50,6 +63,17 @@ definitions:
successMessage:
type: string
type: object
app.AntResponse-cost_UpdateCostInfoResult:
properties:
code:
type: integer
errorMessage:
type: string
result:
$ref: '#/definitions/cost.UpdateCostInfoResult'
successMessage:
type: string
type: object
app.AntResponse-int64:
properties:
code:
Expand Down Expand Up @@ -160,6 +184,24 @@ definitions:
successMessage:
type: string
type: object
app.AwsAdditionalInfoReq:
properties:
ownerId:
type: string
regions:
items:
type: string
type: array
type: object
app.CostResourceReq:
properties:
resourceIds:
items:
type: string
type: array
resourceType:
$ref: '#/definitions/constant.ResourceType'
type: object
app.InstallLoadGeneratorReq:
properties:
installLocation:
Expand Down Expand Up @@ -227,6 +269,22 @@ definitions:
loadTestKey:
type: string
type: object
app.UpdateCostInfoReq:
properties:
awsAdditionalInfo:
$ref: '#/definitions/app.AwsAdditionalInfoReq'
connectionName:
type: string
costResources:
items:
$ref: '#/definitions/app.CostResourceReq'
type: array
migrationId:
type: string
required:
- connectionName
- costResources
type: object
constant.ExecutionStatus:
enum:
- on_preparing
Expand Down Expand Up @@ -283,6 +341,18 @@ definitions:
x-enum-varnames:
- PerHour
- PerYear
constant.ResourceType:
enum:
- VM
- VNet
- DataDisk
- Etc
type: string
x-enum-varnames:
- VM
- VNet
- DataDisk
- Etc
cost.AllPriceInfoResult:
properties:
infoSource:
Expand All @@ -294,6 +364,23 @@ definitions:
resultCount:
type: integer
type: object
cost.GetCostInfoResult:
properties:
category:
type: string
date:
type: string
provider:
type: string
resourceId:
type: string
resourceType:
type: string
totalCost:
type: number
unit:
type: string
type: object
cost.PriceInfoResult:
properties:
calculatedMonthlyPrice:
Expand Down Expand Up @@ -333,6 +420,15 @@ definitions:
zoneName:
type: string
type: object
cost.UpdateCostInfoResult:
properties:
fetchedDataCount:
type: integer
insertedDataCount:
type: integer
updatedDataCount:
type: integer
type: object
load.GetAllLoadGeneratorInstallInfoResult:
properties:
loadGeneratorInstallInfoResults:
Expand Down Expand Up @@ -632,8 +728,121 @@ info:
contact: {}
description: CM-ANT REST API swagger document.
title: CM-ANT REST API
version: "0.1"
version: 0.2.2
paths:
/api/v1/cost/info:
get:
consumes:
- application/json
description: Retrieve cost information for specified parameters within a defined
date range. The date range must be within a 6-month period. Optionally, you
can specify cost aggregation type and date order for the results.
operationId: GetCostInfo
parameters:
- description: Start date for the cost information retrieval in 'YYYY-MM-DD'
format
in: query
name: startDate
required: true
type: string
- description: End date for the cost information retrieval in 'YYYY-MM-DD' format
in: query
name: endDate
required: true
type: string
- collectionFormat: csv
description: List of migration IDs to filter the cost information
in: query
items:
type: string
name: migrationIds
type: array
- collectionFormat: csv
description: List of cloud providers to filter the cost information
in: query
items:
type: string
name: provider
type: array
- collectionFormat: csv
description: List of resource types to filter the cost information
in: query
items:
type: string
name: resourceTypes
type: array
- collectionFormat: csv
description: List of resource IDs to filter the cost information
in: query
items:
type: string
name: resourceIds
type: array
- description: Type of cost aggregation for the results (e.g., 'daily', 'weekly',
'monthly')
in: query
name: costAggregationType
required: true
type: string
- description: Order of dates in the result (e.g., 'asc', 'desc')
in: query
name: dateOrder
type: string
- description: Order of resource types in the result (e.g., 'asc', 'desc')
in: query
name: resourceTypeOrder
type: string
produces:
- application/json
responses:
"200":
description: Successfully retrieved cost information
schema:
$ref: '#/definitions/app.AntResponse-array_cost_GetCostInfoResult'
"400":
description: Invalid request parameters
schema:
$ref: '#/definitions/app.AntResponse-string'
"500":
description: Failed to retrieve cost information
schema:
$ref: '#/definitions/app.AntResponse-string'
summary: Get Cost Information
tags:
- '[Cost Management]'
post:
consumes:
- application/json
description: Update cost information for specified resources, including details
such as migration ID, cost resources, and additional AWS info if applicable.
The request body must include a valid migration ID and a list of cost resources.
If AWS-specific details are provided, ensure all required fields are populated.
operationId: UpdateCostInfo
parameters:
- description: Request body containing cost update information
in: body
name: body
required: true
schema:
$ref: '#/definitions/app.UpdateCostInfoReq'
produces:
- application/json
responses:
"200":
description: Successfully updated cost information
schema:
$ref: '#/definitions/app.AntResponse-cost_UpdateCostInfoResult'
"400":
description: Invalid request parameters
schema:
$ref: '#/definitions/app.AntResponse-string'
"500":
description: Failed to update cost information
schema:
$ref: '#/definitions/app.AntResponse-string'
summary: Update Cost Information
tags:
- '[Cost Management]'
/api/v1/load/generators:
get:
consumes:
Expand Down Expand Up @@ -1121,43 +1330,43 @@ paths:
parameters:
- description: Name of the region
in: query
name: RegionName
name: regionName
required: true
type: string
- description: Name of the connection
in: query
name: ConnectionName
name: connectionName
required: true
type: string
- description: Name of the cloud provider
in: query
name: ProviderName
name: providerName
required: true
type: string
- description: Type of the instance
in: query
name: InstanceType
name: instanceType
required: true
type: string
- description: Name of the zone
in: query
name: ZoneName
name: zoneName
type: string
- description: Number of virtual CPUs
in: query
name: VCpu
name: vCpu
type: string
- description: Amount of memory. Don't need to pass unit like 'gb'
in: query
name: Memory
name: memory
type: string
- description: Amount of storage
in: query
name: Storage
name: storage
type: string
- description: Operating system type
in: query
name: OsType
name: osType
type: string
produces:
- application/json
Expand All @@ -1176,5 +1385,5 @@ paths:
$ref: '#/definitions/app.AntResponse-string'
summary: Get Price Information
tags:
- '[Pricing Management]'
- '[Price Management]'
swagger: "2.0"
3 changes: 1 addition & 2 deletions cmd/cm-ant/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@ import (
// InitRouter initializes the routing for CM-ANT API server.

// @title CM-ANT REST API
// @version 0.1
// @version 0.2.2
// @description CM-ANT REST API swagger document.

// @basePath /ant
func main() {

Expand Down
7 changes: 4 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,18 @@ module github.com/cloud-barista/cm-ant
go 1.21.6

require (
github.com/aws/aws-sdk-go v1.55.5
github.com/google/uuid v1.6.0
github.com/labstack/echo/v4 v4.12.0
github.com/melbahja/goph v1.4.0
github.com/pkg/sftp v1.13.6
github.com/rs/zerolog v1.32.0
github.com/spf13/viper v1.18.2
github.com/stretchr/testify v1.9.0
github.com/swaggo/echo-swagger v1.4.1
github.com/swaggo/swag v1.16.3
golang.org/x/crypto v0.25.0
gorm.io/driver/postgres v1.5.9
gorm.io/driver/sqlite v1.5.5
gorm.io/gorm v1.25.11
)
Expand All @@ -33,10 +36,10 @@ require (
github.com/jackc/puddle/v2 v2.2.1 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.5 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/kr/fs v0.1.0 // indirect
github.com/labstack/gommon v0.4.2 // indirect
github.com/lib/pq v1.10.9 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
Expand All @@ -45,7 +48,6 @@ require (
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/pelletier/go-toml/v2 v2.1.1 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pkg/sftp v1.13.6 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/sagikazarmark/locafero v0.4.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
Expand All @@ -69,5 +71,4 @@ require (
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
gorm.io/driver/postgres v1.5.9 // indirect
)
Loading

0 comments on commit 2191bd3

Please sign in to comment.