Skip to content

Commit

Permalink
refactor config-structure-update
Browse files Browse the repository at this point in the history
  • Loading branch information
heedaeshin committed Sep 6, 2024
2 parents b5a05a3 + d36c56e commit dad298e
Show file tree
Hide file tree
Showing 1,116 changed files with 6,072,537 additions and 3,769 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/continuous-delivery.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ jobs:
context: ./
file: ./Dockerfile
target: prod
platforms: linux/amd64 # linux/arm/v7,linux/arm64,linux/386,linux/ppc64le,linux/s390x,linux/arm/v6
platforms: linux/amd64 # linux/arm/v7,linux/arm64,linux/386,linux/ppc64le,linux/aws90x,linux/arm/v6
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
cache-from: type=local,src=/tmp/.buildx-cache
Expand Down
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
*.so
*.dylib
tmp
# credential
# profile

# Test binary, built with `go test -c`
*.test
Expand All @@ -25,3 +27,6 @@ go.work

# mc-data-manager binary, built with `go build`
mc-data-manager

# Credential
profile.json
20 changes: 10 additions & 10 deletions cmd/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Semi-structured data: json, xml
You must enter the data size in GB.`,
Run: func(_ *cobra.Command, _ []string) {
logrus.SetFormatter(&log.CustomTextFormatter{CmdName: "create", JobName: "dummy create"})
if err := execfunc.DummyCreate(datamoldParams); err != nil {
if err := execfunc.DummyCreate(commandTask); err != nil {
logrus.Errorf("dummy create failed : %v", err)
}
},
Expand All @@ -46,15 +46,15 @@ You must enter the data size in GB.`,
func init() {
rootCmd.AddCommand(createCmd)

createCmd.Flags().StringVarP(&datamoldParams.DstPath, "dst-path", "d", "", "Directory path to create dummy data")
createCmd.Flags().StringVarP(&commandTask.DummyPath, "dst-path", "d", "", "Directory path to create dummy data")
createCmd.MarkFlagRequired("dst-path")

createCmd.Flags().IntVarP(&datamoldParams.SqlSize, "sql-size", "s", 0, "Total size of sql files")
createCmd.Flags().IntVarP(&datamoldParams.CsvSize, "csv-size", "c", 0, "Total size of csv files")
createCmd.Flags().IntVarP(&datamoldParams.JsonSize, "json-size", "j", 0, "Total size of json files")
createCmd.Flags().IntVarP(&datamoldParams.XmlSize, "xml-size", "x", 0, "Total size of xml files")
createCmd.Flags().IntVarP(&datamoldParams.TxtSize, "txt-size", "t", 0, "Total size of txt files")
createCmd.Flags().IntVarP(&datamoldParams.PngSize, "png-size", "p", 0, "Total size of png files")
createCmd.Flags().IntVarP(&datamoldParams.GifSize, "gif-size", "g", 0, "Total size of gif files")
createCmd.Flags().IntVarP(&datamoldParams.ZipSize, "zip-size", "z", 0, "Total size of zip files")
createCmd.Flags().StringVarP(&commandTask.SizeSQL, "sql-size", "s", "0", "Total size of sql files")
createCmd.Flags().StringVarP(&commandTask.SizeCSV, "csv-size", "c", "0", "Total size of csv files")
createCmd.Flags().StringVarP(&commandTask.SizeJSON, "json-size", "j", "0", "Total size of json files")
createCmd.Flags().StringVarP(&commandTask.SizeXML, "xml-size", "x", "0", "Total size of xml files")
createCmd.Flags().StringVarP(&commandTask.SizeTXT, "txt-size", "t", "0", "Total size of txt files")
createCmd.Flags().StringVarP(&commandTask.SizePNG, "png-size", "p", "0", "Total size of png files")
createCmd.Flags().StringVarP(&commandTask.SizeGIF, "gif-size", "g", "0", "Total size of gif files")
createCmd.Flags().StringVarP(&commandTask.SizeZIP, "zip-size", "z", "0", "Total size of zip files")
}
23 changes: 11 additions & 12 deletions cmd/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,32 +26,31 @@ import (
// deleteCmd represents the delete command
var deleteCmd = &cobra.Command{
Use: "delete",
Short: "Delete dummy data",
Short: "Delete local data",
Long: `Delete unstructured, semi-structured, and structured data,
which are CSP or local dummy data`,
}

var deleteDummyCmd = &cobra.Command{
Use: "dummy",
var deleteLocalCmd = &cobra.Command{
Use: "local",

Run: func(cmd *cobra.Command, args []string) {
logrus.SetFormatter(&log.CustomTextFormatter{CmdName: "delete"})
logrus.WithFields(logrus.Fields{"jobName": "dummy delete"}).Info("start deleting dummy")
logrus.WithFields(logrus.Fields{"jobName": "local delete"}).Info("start deleting local data")

if err := os.RemoveAll(datamoldParams.DstPath); err != nil {
logrus.WithFields(logrus.Fields{"jobName": "dummy delete"}).Errorf("failed to delete dummy : %v", err)
if err := os.RemoveAll(commandTask.Directory); err != nil {
logrus.WithFields(logrus.Fields{"jobName": "local delete"}).Errorf("failed to delete local : %v", err)
return
}
logrus.Infof("successfully deleted : %s\n", datamoldParams.DstPath)
return
logrus.Infof("successfully deleted : %s\n", commandTask.Directory)

},
}

func init() {
rootCmd.AddCommand(deleteCmd)
deleteCmd.AddCommand(deleteDummyCmd)
deleteCmd.AddCommand(deleteLocalCmd)

deleteCmd.PersistentFlags().BoolVarP(&datamoldParams.TaskTarget, "task", "T", false, "Select a destination(src, dst) to work with in the credential-path")
deleteDummyCmd.Flags().StringVarP(&datamoldParams.DstPath, "dst-path", "d", "", "Delete data in directory paths")
deleteDummyCmd.MarkFlagRequired("dst-path")
deleteLocalCmd.Flags().StringVarP(&commandTask.Directory, "dst-path", "d", "", "Delete data in directory paths")
deleteLocalCmd.MarkFlagRequired("dst-path")
}
7 changes: 3 additions & 4 deletions cmd/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ var exportCmd = &cobra.Command{
func init() {
rootCmd.AddCommand(exportCmd)

exportCmd.PersistentFlags().StringVarP(&datamoldParams.CredentialPath, "credential-path", "C", "", "Json file path containing the user's credentials")
exportCmd.PersistentFlags().StringVarP(&datamoldParams.DstPath, "dst-path", "d", "", "Directory path to export data")
exportCmd.PersistentFlags().BoolVarP(&datamoldParams.TaskTarget, "task", "T", false, "Select a destination(src, dst) to work with in the credential-path")
exportCmd.MarkFlagsRequiredTogether("credential-path", "dst-path")
exportCmd.PersistentFlags().StringVarP(&commandTask.TaskFilePath, "task-file-path", "f", "task.json", "Json file path containing the user's task")
exportCmd.PersistentFlags().StringVarP(&commandTask.Directory, "dst-path", "d", "", "Directory path to export data")
exportCmd.MarkFlagsRequiredTogether("task-file-path", "dst-path")
}
7 changes: 3 additions & 4 deletions cmd/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ var importCmd = &cobra.Command{
func init() {
rootCmd.AddCommand(importCmd)

importCmd.PersistentFlags().StringVarP(&datamoldParams.CredentialPath, "credential-path", "C", "", "Json file path containing the user's credentials")
importCmd.PersistentFlags().StringVarP(&datamoldParams.DstPath, "dst-path", "d", "", "Destination path where dummy data exists")
importCmd.PersistentFlags().BoolVarP(&datamoldParams.TaskTarget, "task", "T", false, "Select a destination(src, dst) to work with in the credential-path")
importCmd.MarkFlagsRequiredTogether("credential-path", "dst-path")
importCmd.PersistentFlags().StringVarP(&commandTask.TaskFilePath, "task-file-path", "f", "task.json", "Json file path containing the user's task")
importCmd.PersistentFlags().StringVarP(&commandTask.Directory, "dst-path", "d", "", "Destination path where dummy data exists")
importCmd.MarkFlagsRequiredTogether("task-file-path", "dst-path")
}
5 changes: 2 additions & 3 deletions cmd/migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ var migrationCmd = &cobra.Command{

func init() {
rootCmd.AddCommand(migrationCmd)
migrationCmd.PersistentFlags().BoolVarP(&datamoldParams.TaskTarget, "task", "T", false, "Select a destination(src, dst) to work with in the credential-path")
migrationCmd.PersistentFlags().StringVarP(&datamoldParams.CredentialPath, "credential-path", "C", "", "Json file path containing the user's credentials")
migrationCmd.MarkFlagRequired("credential-path")
migrationCmd.PersistentFlags().StringVarP(&commandTask.TaskFilePath, "task-file-path", "f", "task.json", "Json file path containing the user's task")
migrationCmd.MarkFlagRequired("task-file-path")
}
31 changes: 17 additions & 14 deletions cmd/nrdbms.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,38 +27,41 @@ var importNRDBCmd = &cobra.Command{
Use: "nrdbms",
Aliases: []string{"ndb"},
Run: func(cmd *cobra.Command, args []string) {
auth.PreRun("nrdbms", &datamoldParams, cmd.Parent().Use)
if err := auth.ImportNRDMFunc(&datamoldParams); err != nil {
auth.PreRun("nrdbms", &commandTask, cmd.Parent().Use)
if err := auth.ImportNRDMFunc(&commandTask); err != nil {
os.Exit(1)
}
},
}

var exportNRDBCmd = &cobra.Command{
Use: "nrdbms",
Use: "nrdbms",
Aliases: []string{"ndb"},
Run: func(cmd *cobra.Command, args []string) {
auth.PreRun("nrdbms", &datamoldParams, cmd.Parent().Use)
if err := auth.ExportNRDMFunc(&datamoldParams); err != nil {
auth.PreRun("nrdbms", &commandTask, cmd.Parent().Use)
if err := auth.ExportNRDMFunc(&commandTask); err != nil {
os.Exit(1)
}
},
}

var migrationNRDBCmd = &cobra.Command{
Use: "nrdbms",
Use: "nrdbms",
Aliases: []string{"ndb"},
Run: func(cmd *cobra.Command, args []string) {
auth.PreRun("nrdbms", &datamoldParams, cmd.Parent().Use)
if err := auth.MigrationNRDMFunc(&datamoldParams); err != nil {
auth.PreRun("nrdbms", &commandTask, cmd.Parent().Use)
if err := auth.MigrationNRDMFunc(&commandTask); err != nil {
os.Exit(1)
}
},
}

var deleteNRDBMSCmd = &cobra.Command{
Use: "nrdbms",
Use: "nrdbms",
Aliases: []string{"ndb"},
Run: func(cmd *cobra.Command, args []string) {
auth.PreRun("nrdbms", &datamoldParams, cmd.Parent().Use)
if err := auth.DeleteNRDMFunc(&datamoldParams); err != nil {
auth.PreRun("nrdbms", &commandTask, cmd.Parent().Use)
if err := auth.DeleteNRDMFunc(&commandTask); err != nil {
os.Exit(1)
}
},
Expand All @@ -70,7 +73,7 @@ func init() {
migrationCmd.AddCommand(migrationNRDBCmd)
deleteCmd.AddCommand(deleteNRDBMSCmd)

deleteNRDBMSCmd.Flags().StringVarP(&datamoldParams.CredentialPath, "credential-path", "C", "", "Json file path containing the user's credentials")
deleteNRDBMSCmd.Flags().StringArrayVarP(&datamoldParams.DeleteTableList, "delete-table-list", "D", []string{}, "List of table names to delete")
deleteNRDBMSCmd.MarkFlagsRequiredTogether("credential-path", "delete-table-list")
deleteNRDBMSCmd.PersistentFlags().StringVarP(&commandTask.TaskFilePath, "task-file-path", "f", "task.json", "Json file path containing the user's task")
deleteNRDBMSCmd.Flags().StringArrayVarP(&commandTask.DeleteTableList, "delete-table-list", "D", []string{}, "List of table names to delete")
deleteNRDBMSCmd.MarkFlagsRequiredTogether("task-file-path", "delete-table-list")
}
32 changes: 18 additions & 14 deletions cmd/objectstorage.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,40 +23,44 @@ import (
)

var importOSCmd = &cobra.Command{
Use: "objectstorage",
Use: "objectstorage",
Aliases: []string{"obj"},
Run: func(cmd *cobra.Command, args []string) {
auth.PreRun("objectstorage", &datamoldParams, cmd.Parent().Use)
if err := auth.ImportOSFunc(&datamoldParams); err != nil {
auth.PreRun("objectstorage", &commandTask, cmd.Parent().Use)
if err := auth.ImportOSFunc(&commandTask); err != nil {
os.Exit(1)
}
},
}

var exportOSCmd = &cobra.Command{
Use: "objectstorage",
Use: "objectstorage",
Aliases: []string{"obj"},
Run: func(cmd *cobra.Command, args []string) {
auth.PreRun("objectstorage", &datamoldParams, cmd.Parent().Use)
if err := auth.ExportOSFunc(&datamoldParams); err != nil {
auth.PreRun("objectstorage", &commandTask, cmd.Parent().Use)
if err := auth.ExportOSFunc(&commandTask); err != nil {
os.Exit(1)
}
},
}

var migrationOSCmd = &cobra.Command{
Use: "objectstorage",
Use: "objectstorage",
Aliases: []string{"obj"},
Run: func(cmd *cobra.Command, args []string) {
auth.PreRun("objectstorage", &datamoldParams, cmd.Parent().Use)
if err := auth.MigrationOSFunc(&datamoldParams); err != nil {
auth.PreRun("objectstorage", &commandTask, cmd.Parent().Use)
if err := auth.MigrationOSFunc(&commandTask); err != nil {
os.Exit(1)
}
},
}

var deleteOSCmd = &cobra.Command{
Use: "objectstorage",
Use: "objectstorage",
Aliases: []string{"obj"},
Run: func(cmd *cobra.Command, args []string) {
auth.PreRun("objectstorage", &datamoldParams, cmd.Parent().Use)
if err := auth.DeleteOSFunc(&datamoldParams); err != nil {
auth.PreRun("objectstorage", &commandTask, cmd.Parent().Use)
if err := auth.DeleteOSFunc(&commandTask); err != nil {
os.Exit(1)
}
},
Expand All @@ -68,6 +72,6 @@ func init() {
migrationCmd.AddCommand(migrationOSCmd)
deleteCmd.AddCommand(deleteOSCmd)

deleteOSCmd.Flags().StringVarP(&datamoldParams.CredentialPath, "credential-path", "C", "", "Json file path containing the user's credentials")
deleteOSCmd.MarkFlagRequired("credential-path")
deleteOSCmd.PersistentFlags().StringVarP(&commandTask.TaskFilePath, "task-file-path", "f", "task.json", "Json file path containing the user's task")
deleteOSCmd.MarkFlagRequired("task-file-path")
}
22 changes: 11 additions & 11 deletions cmd/rdbms.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ import (
var importRDBCmd = &cobra.Command{
Use: "rdbms",
Run: func(cmd *cobra.Command, args []string) {
auth.PreRun("rdbms", &datamoldParams, cmd.Parent().Use)
if err := auth.ImportRDMFunc(&datamoldParams); err != nil {
auth.PreRun("rdbms", &commandTask, cmd.Parent().Use)
if err := auth.ImportRDMFunc(&commandTask); err != nil {
os.Exit(1)
}
},
Expand All @@ -36,8 +36,8 @@ var importRDBCmd = &cobra.Command{
var exportRDBCmd = &cobra.Command{
Use: "rdbms",
Run: func(cmd *cobra.Command, args []string) {
auth.PreRun("rdbms", &datamoldParams, cmd.Parent().Use)
if err := auth.ExportRDMFunc(&datamoldParams); err != nil {
auth.PreRun("rdbms", &commandTask, cmd.Parent().Use)
if err := auth.ExportRDMFunc(&commandTask); err != nil {
os.Exit(1)
}
},
Expand All @@ -46,8 +46,8 @@ var exportRDBCmd = &cobra.Command{
var migrationRDBCmd = &cobra.Command{
Use: "rdbms",
Run: func(cmd *cobra.Command, args []string) {
auth.PreRun("rdbms", &datamoldParams, cmd.Parent().Use)
if err := auth.MigrationRDMFunc(&datamoldParams); err != nil {
auth.PreRun("rdbms", &commandTask, cmd.Parent().Use)
if err := auth.MigrationRDMFunc(&commandTask); err != nil {
os.Exit(1)
}
},
Expand All @@ -56,8 +56,8 @@ var migrationRDBCmd = &cobra.Command{
var deleteRDBMSCmd = &cobra.Command{
Use: "rdbms",
Run: func(cmd *cobra.Command, args []string) {
auth.PreRun("rdbms", &datamoldParams, cmd.Parent().Use)
if err := auth.DeleteRDMFunc(&datamoldParams); err != nil {
auth.PreRun("rdbms", &commandTask, cmd.Parent().Use)
if err := auth.DeleteRDMFunc(&commandTask); err != nil {
os.Exit(1)
}
},
Expand All @@ -69,7 +69,7 @@ func init() {
migrationCmd.AddCommand(migrationRDBCmd)
deleteCmd.AddCommand(deleteRDBMSCmd)

deleteRDBMSCmd.Flags().StringVarP(&datamoldParams.CredentialPath, "credential-path", "C", "", "Json file path containing the user's credentials")
deleteRDBMSCmd.Flags().StringArrayVarP(&datamoldParams.DeleteDBList, "delete-db-list", "D", []string{}, "List of db names to delete")
deleteRDBMSCmd.MarkFlagsRequiredTogether("credential-path", "delete-db-list")
deleteRDBMSCmd.PersistentFlags().StringVarP(&commandTask.TaskFilePath, "task-file-path", "f", "task.json", "Json file path containing the user's task")
deleteRDBMSCmd.Flags().StringArrayVarP(&commandTask.DeleteDBList, "delete-db-list", "D", []string{}, "List of db names to delete")
deleteRDBMSCmd.MarkFlagsRequiredTogether("task-file-path", "delete-db-list")
}
6 changes: 2 additions & 4 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,11 @@ package cmd
import (
"os"

"github.com/cloud-barista/mc-data-manager/internal/auth"
"github.com/cloud-barista/mc-data-manager/internal/log"
"github.com/cloud-barista/mc-data-manager/models"
"github.com/spf13/cobra"
)

var datamoldParams auth.DatamoldParams
var commandTask models.CommandTask

// rootCmd represents the base command when called without any subcommands
var rootCmd = &cobra.Command{
Expand All @@ -32,7 +31,6 @@ var rootCmd = &cobra.Command{
Long: `It is a tool that builds an environment for verification of data migration technology and
generates test data necessary for data migration.`,
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
log.LogFile()
return nil
},
}
Expand Down
52 changes: 52 additions & 0 deletions cmd/test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
Copyright 2023 The Cloud-Barista Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package cmd

import (
"github.com/cloud-barista/mc-data-manager/internal/execfunc"
"github.com/cloud-barista/mc-data-manager/internal/log"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)

// testCmd represents the create command
var testCmd = &cobra.Command{
Use: "test",
Short: "test-command",
Long: `test-command`,
Run: func(_ *cobra.Command, _ []string) {
logrus.SetFormatter(&log.CustomTextFormatter{CmdName: "test", JobName: "test dummy create"})
if err := execfunc.DummyCreate(commandTask); err != nil {
logrus.Errorf("test dummy create failed : %v", err)
}
},
}

func init() {
rootCmd.AddCommand(testCmd)

testCmd.Flags().StringVarP(&commandTask.DummyPath, "dst-path", "d", "", "Directory path to create dummy data")
testCmd.MarkFlagRequired("dst-path")

testCmd.Flags().StringVarP(&commandTask.SizeSQL, "sql-size", "s", "0", "Total size of sql files")
testCmd.Flags().StringVarP(&commandTask.SizeCSV, "csv-size", "c", "0", "Total size of csv files")
testCmd.Flags().StringVarP(&commandTask.SizeJSON, "json-size", "j", "0", "Total size of json files")
testCmd.Flags().StringVarP(&commandTask.SizeXML, "xml-size", "x", "0", "Total size of xml files")
testCmd.Flags().StringVarP(&commandTask.SizeTXT, "txt-size", "t", "0", "Total size of txt files")
testCmd.Flags().StringVarP(&commandTask.SizePNG, "png-size", "p", "0", "Total size of png files")
testCmd.Flags().StringVarP(&commandTask.SizeGIF, "gif-size", "g", "0", "Total size of gif files")
testCmd.Flags().StringVarP(&commandTask.SizeZIP, "zip-size", "z", "0", "Total size of zip files")
}
Loading

0 comments on commit dad298e

Please sign in to comment.