Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/fix backup doc #36

Merged
merged 2 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 1 addition & 72 deletions websrc/controllers/backupHandlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,80 +16,9 @@ limitations under the License.
package controllers

import (
"net/http"
"os"
"time"

"github.com/cloud-barista/mc-data-manager/websrc/models"
"github.com/labstack/echo/v4"
)

// MigrationDynamoDBToFirestorePostHandler godoc
// @Summary Migrate data from DynamoDB to Firestore
// @Description Migrate data stored in AWS DynamoDB to Google Cloud Firestore.
// @Tags [Data Migration]
// @Accept multipart/form-data
// @Produce json
// @Param AWSMigrationParams formData AWSMigrationParams true "Parameters required for Linux migration"
// @Param GCPMigrationParams formData GCPMigrationParams true "Parameters required for GCP migration"
// @Param gcpCredential formData file true "Parameters required to generate test data"
// @Success 200 {object} models.BasicResponse "Successfully migrated data"
// @Failure 500 {object} models.BasicResponse "Internal Server Error"
// @Router /backup [post]
func BackupRootHandler(ctx echo.Context) error {

start := time.Now()

logger, logstrings := pageLogInit("migDNFS", "Export dynamoDB data to firestoreDB", start)

params := MigrationForm{}
if !getDataWithBind(logger, start, ctx, &params) {
return ctx.JSON(http.StatusInternalServerError, models.BasicResponse{
Result: logstrings.String(),
Error: nil,
})
}

credTmpDir, credFileName, ok := gcpCreateCredFile(logger, start, ctx)
if !ok && params.GCPCredentialJson == "" {
return ctx.JSON(http.StatusInternalServerError, models.BasicResponse{
Result: logstrings.String(),
Error: nil,
})
}
defer os.RemoveAll(credTmpDir)

awsNRDB := getDynamoNRDBC(logger, start, "mig", params)
if awsNRDB == nil {
return ctx.JSON(http.StatusInternalServerError, models.BasicResponse{
Result: logstrings.String(),
Error: nil,
})
}

gcpNRDB := getFirestoreNRDBC(logger, start, "mig", params, credFileName)
if gcpNRDB == nil {
return ctx.JSON(http.StatusInternalServerError, models.BasicResponse{
Result: logstrings.String(),
Error: nil,
})
}

if err := awsNRDB.Copy(gcpNRDB); err != nil {
end := time.Now()
logger.Errorf("NRDBController copy failed : %v", err)
logger.Infof("End time : %s", end.Format("2006-01-02T15:04:05-07:00"))
logger.Infof("Elapsed time : %s", end.Sub(start).String())
return ctx.JSON(http.StatusInternalServerError, models.BasicResponse{
Result: logstrings.String(),
Error: nil,
})
}
func BackupRootHandler(ctx echo.Context) {

// migration success. Send result to client
jobEnd(logger, "Successfully migrated data from dynamoDB to firestoreDB", start)
return ctx.JSON(http.StatusOK, models.BasicResponse{
Result: logstrings.String(),
Error: nil,
})
}
78 changes: 0 additions & 78 deletions websrc/docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,84 +23,6 @@ const docTemplate = `{
"host": "{{.Host}}",
"basePath": "{{.BasePath}}",
"paths": {
"/backup": {
"post": {
"description": "Migrate data stored in AWS DynamoDB to Google Cloud Firestore.",
"consumes": [
"multipart/form-data"
],
"produces": [
"application/json"
],
"tags": [
"[Data Migration]"
],
"summary": "Migrate data from DynamoDB to Firestore",
"parameters": [
{
"type": "string",
"name": "awsAccessKey",
"in": "formData"
},
{
"type": "string",
"name": "awsBucket",
"in": "formData"
},
{
"type": "string",
"name": "awsRegion",
"in": "formData"
},
{
"type": "string",
"name": "awsSecretKey",
"in": "formData"
},
{
"type": "string",
"name": "databaseId",
"in": "formData"
},
{
"type": "string",
"name": "gcpBucket",
"in": "formData"
},
{
"type": "string",
"name": "gcpRegion",
"in": "formData"
},
{
"type": "string",
"name": "projectId",
"in": "formData"
},
{
"type": "file",
"description": "Parameters required to generate test data",
"name": "gcpCredential",
"in": "formData",
"required": true
}
],
"responses": {
"200": {
"description": "Successfully migrated data",
"schema": {
"$ref": "#/definitions/models.BasicResponse"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/models.BasicResponse"
}
}
}
}
},
"/generate/dynamodb": {
"post": {
"description": "Generate test data on AWS DynamoDB.",
Expand Down
78 changes: 0 additions & 78 deletions websrc/docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,84 +16,6 @@
},
"basePath": "/",
"paths": {
"/backup": {
"post": {
"description": "Migrate data stored in AWS DynamoDB to Google Cloud Firestore.",
"consumes": [
"multipart/form-data"
],
"produces": [
"application/json"
],
"tags": [
"[Data Migration]"
],
"summary": "Migrate data from DynamoDB to Firestore",
"parameters": [
{
"type": "string",
"name": "awsAccessKey",
"in": "formData"
},
{
"type": "string",
"name": "awsBucket",
"in": "formData"
},
{
"type": "string",
"name": "awsRegion",
"in": "formData"
},
{
"type": "string",
"name": "awsSecretKey",
"in": "formData"
},
{
"type": "string",
"name": "databaseId",
"in": "formData"
},
{
"type": "string",
"name": "gcpBucket",
"in": "formData"
},
{
"type": "string",
"name": "gcpRegion",
"in": "formData"
},
{
"type": "string",
"name": "projectId",
"in": "formData"
},
{
"type": "file",
"description": "Parameters required to generate test data",
"name": "gcpCredential",
"in": "formData",
"required": true
}
],
"responses": {
"200": {
"description": "Successfully migrated data",
"schema": {
"$ref": "#/definitions/models.BasicResponse"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/models.BasicResponse"
}
}
}
}
},
"/generate/dynamodb": {
"post": {
"description": "Generate test data on AWS DynamoDB.",
Expand Down
49 changes: 0 additions & 49 deletions websrc/docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -221,55 +221,6 @@ info:
title: MC-Data-Manager REST API
version: latest
paths:
/backup:
post:
consumes:
- multipart/form-data
description: Migrate data stored in AWS DynamoDB to Google Cloud Firestore.
parameters:
- in: formData
name: awsAccessKey
type: string
- in: formData
name: awsBucket
type: string
- in: formData
name: awsRegion
type: string
- in: formData
name: awsSecretKey
type: string
- in: formData
name: databaseId
type: string
- in: formData
name: gcpBucket
type: string
- in: formData
name: gcpRegion
type: string
- in: formData
name: projectId
type: string
- description: Parameters required to generate test data
in: formData
name: gcpCredential
required: true
type: file
produces:
- application/json
responses:
"200":
description: Successfully migrated data
schema:
$ref: '#/definitions/models.BasicResponse'
"500":
description: Internal Server Error
schema:
$ref: '#/definitions/models.BasicResponse'
summary: Migrate data from DynamoDB to Firestore
tags:
- '[Data Migration]'
/generate/dynamodb:
post:
consumes:
Expand Down