in tools/mconnect/commands/export/export.go [224:285]
func newExportCmd(castFactory castExporterFactory, mcFactory mcExporterFactory) *cobra.Command {
return &cobra.Command{
Use: "export path project region dataset [flags]",
Short: "Exports CAST report and Migration Center data to BigQuery.",
Long: `Exports CAST report and Migration Center data to BigQuery.
By default it will be assumed that the project and region used for Migration Center and BigQuery are the same.`,
Example: `
mconnect export --path=path/to/cast/analysisResults.csv --project=my-project-id --region=my-region1 # the default dataset will be set to 'mcCast'.
mconnect export --path=path/to/cast/analysisResults.csv --project=my-project-id --region=my-region1 --dataset=dataset-id
mconnect export --path=path/to/cast/analysisResults.csv --project=my-project-id --region=my-region1 --dataset=dataset-id --force=true
mconnect export --path=path/to/cast/analysisResults.csv --project=my-project-id --region=my-region1 --dataset=dataset-id --mc-project=my-mc-project-id --mc-region=my-mc-region
`,
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) != 0 {
return messages.NoArgumentsAcceptedError{Args: args}.Error()
}
// Remove usage printing on error once initial parameter validations are done.
cmd.SilenceUsage = true
if datasetID == "" {
datasetID = defaultDatasetID
}
location := root.DefaultLocation
if region != "" {
location = region
}
// Exporting CAST file to BigQuery
ce := castFactory.build(path, projectID, datasetID, castTableID, location)
err := ce.export()
if err != nil {
if gapiutil.IsErrorWithCode(err, http.StatusConflict) {
err = fmt.Errorf("%w,\n"+messages.ForceExport.String(), err)
}
return messages.WrapError(messages.ErrExportingData, err)
}
fmt.Println(messages.CASTExportSuccess)
// Exporting Migration Center data to BigQurey.
if mcProjectID == "" {
mcProjectID = projectID
}
if mcRegion == "" {
mcRegion = region
}
fmt.Println(messages.CallingMCToBQ{MCProjectID: mcProjectID, MCRegion: mcRegion, BQProjectID: projectID, BQRegion: region, DatasetID: datasetID})
me := mcFactory.build(mcProjectID, mcRegion, projectID, datasetID, force)
err = me.export()
if err != nil {
return messages.WrapError(messages.ErrExportingMCToBQ, err)
}
fmt.Println(messages.MCExportSuccess)
fmt.Println(messages.ExportNextSteps{ProjectID: projectID, DatasetID: datasetID})
return nil
},
}
}