Skip to content

Commit

Permalink
feat: adds continue on err #538 (#539)
Browse files Browse the repository at this point in the history
* feat: adds continue on err #538

* bug: create proxy kvms first #538
  • Loading branch information
srinandan authored Sep 13, 2024
1 parent ce1c532 commit d201967
Showing 1 changed file with 32 additions and 21 deletions.
53 changes: 32 additions & 21 deletions internal/cmd/kvm/impkvms.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,60 +50,71 @@ var ImpCmd = &cobra.Command{
kvmFile := filepath.Base(orgKVMFile)
kvmMetadata := strings.Split(kvmFile, utils.DefaultFileSplitter)
clilog.Info.Printf("\tCreating KVM %s\n", orgKVMFile)
if _, err = kvm.Create("", kvmMetadata[1], true); err != nil {
if _, err = kvm.Create("", kvmMetadata[1], true); proceedOnError(err) != nil {
return err
}
clilog.Info.Printf("\tImporting entries for %s\n", orgKVMFile)
if err = kvm.ImportEntries("", kvmMetadata[1], conn, orgKVMFile); err != nil {
if err = kvm.ImportEntries("", kvmMetadata[1], conn, orgKVMFile); proceedOnError(err) != nil {
return err
}
}
}

if len(envKVMFileList) > 0 {
clilog.Info.Println("Importing env scoped KVMs...")
for _, envKVMFile := range envKVMFileList {
kvmFile := filepath.Base(envKVMFile)
if len(proxyKVMFileList) > 0 {
clilog.Info.Println("Importing proxy scoped KVMs...")
for _, proxyKVMFile := range proxyKVMFileList {
kvmFile := filepath.Base(proxyKVMFile)
kvmMetadata := strings.Split(kvmFile, utils.DefaultFileSplitter)
apiclient.SetApigeeEnv(kvmMetadata[1])
clilog.Info.Printf("\tCreating KVM %s\n", envKVMFile)
if _, err = kvm.Create("", kvmMetadata[2], true); err != nil {
clilog.Info.Printf("\tCreating KVM %s\n", proxyKVMFile)
if _, err = kvm.Create(kvmMetadata[1], kvmMetadata[2], true); proceedOnError(err) != nil {
return err
}
clilog.Info.Printf("\tImporting entries for %s\n", envKVMFile)
if err = kvm.ImportEntries("", kvmMetadata[2], conn, envKVMFile); err != nil {
clilog.Info.Printf("\tImporting entries for %s\n", proxyKVMFile)
if err = kvm.ImportEntries(kvmMetadata[1], kvmMetadata[2], conn, proxyKVMFile); proceedOnError(err) != nil {
return err
}
}
}

if len(proxyKVMFileList) > 0 {
clilog.Info.Println("Importing proxy scoped KVMs...")
for _, proxyKVMFile := range proxyKVMFileList {
kvmFile := filepath.Base(proxyKVMFile)
if len(envKVMFileList) > 0 {
clilog.Info.Println("Importing env scoped KVMs...")
for _, envKVMFile := range envKVMFileList {
kvmFile := filepath.Base(envKVMFile)
kvmMetadata := strings.Split(kvmFile, utils.DefaultFileSplitter)
clilog.Info.Printf("\tCreating KVM %s\n", proxyKVMFile)
if _, err = kvm.Create(kvmMetadata[1], kvmMetadata[2], true); err != nil {
apiclient.SetApigeeEnv(kvmMetadata[1])
clilog.Info.Printf("\tCreating KVM %s\n", envKVMFile)
if _, err = kvm.Create("", kvmMetadata[2], true); proceedOnError(err) != nil {
return err
}
clilog.Info.Printf("\tImporting entries for %s\n", proxyKVMFile)
if err = kvm.ImportEntries(kvmMetadata[1], kvmMetadata[2], conn, proxyKVMFile); err != nil {
clilog.Info.Printf("\tImporting entries for %s\n", envKVMFile)
if err = kvm.ImportEntries("", kvmMetadata[2], conn, envKVMFile); proceedOnError(err) != nil {
return err
}
}
}

return err
},
}

var folder string
var (
folder string
continueOnErr bool
)

func init() {
ImpCmd.Flags().StringVarP(&folder, "folder", "f",
"", "The absolute path to the folder containing KVM entries")
ImpCmd.Flags().IntVarP(&conn, "conn", "c",
4, "Number of connections")
ImpCmd.Flags().BoolVarP(&continueOnErr, "continue-on-error", "",
false, "Ignore errors and continue importing data")

_ = ImpCmd.MarkFlagRequired("folder")
}

func proceedOnError(e error) error {
if continueOnErr {
return nil
}
return e
}

0 comments on commit d201967

Please sign in to comment.