Skip to content

Commit

Permalink
Stop and rollback for MCIS dynamic with no init
Browse files Browse the repository at this point in the history
  • Loading branch information
cb-github-robot authored Apr 1, 2024
2 parents bd6603e + e9be42a commit e12504f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
20 changes: 8 additions & 12 deletions src/core/mcir/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ import (
"reflect"

validator "github.com/go-playground/validator/v10"

"github.com/rs/zerolog/log"
)

// CB-Store
Expand Down Expand Up @@ -1718,10 +1720,8 @@ func LoadDefaultResource(nsId string, resType string, connectionName string) err

resultInfo, err := CreateVNet(nsId, &reqTmp, "")
if err != nil {
common.CBLog.Error(err)
// If already exist, error will occur
// Even if error, do not return here to update information
// return err
log.Error().Err(err).Msg("Failed to create vNet")
return err
}
fmt.Printf("[%d] Registered Default vNet\n", i)
common.PrintJsonPretty(resultInfo)
Expand Down Expand Up @@ -1755,10 +1755,8 @@ func LoadDefaultResource(nsId string, resType string, connectionName string) err

resultInfo, err := CreateSecurityGroup(nsId, &reqTmp, "")
if err != nil {
common.CBLog.Error(err)
// If already exist, error will occur
// Even if error, do not return here to update information
// return err
log.Error().Err(err).Msg("Failed to create SecurityGroup")
return err
}
fmt.Printf("[%d] Registered Default SecurityGroup\n", i)
common.PrintJsonPretty(resultInfo)
Expand All @@ -1776,10 +1774,8 @@ func LoadDefaultResource(nsId string, resType string, connectionName string) err

resultInfo, err := CreateSshKey(nsId, &reqTmp, "")
if err != nil {
common.CBLog.Error(err)
// If already exist, error will occur
// Even if error, do not return here to update information
// return err
log.Error().Err(err).Msg("Failed to create SshKey")
return err
}
fmt.Printf("[%d] Registered Default SSHKey\n", i)
common.PrintJsonPretty(resultInfo)
Expand Down
12 changes: 11 additions & 1 deletion src/core/mcis/provisioning.go
Original file line number Diff line number Diff line change
Expand Up @@ -1263,7 +1263,17 @@ func CreateMcisDynamic(nsId string, req *TbMcisDynamicReq) (*TbMcisInfo, error)
for _, k := range vmRequest {
vmReq, err := getVmReqFromDynamicReq(nsId, &k)
if err != nil {
common.CBLog.Error(err)
log.Error().Err(err).Msg("Failed to prefare resources for dynamic MCIS creation")
// Rollback created default resources
time.Sleep(5 * time.Second)
log.Info().Msg("Try rollback created default resources")
rollbackResult, rollbackErr := mcir.DelAllDefaultResources(nsId)
if rollbackErr != nil {
err = fmt.Errorf("Failed in rollback operation: %w", rollbackErr)
} else {
ids := strings.Join(rollbackResult.IdList, ", ")
err = fmt.Errorf("Rollback results [%s]: %w", ids, err)
}
return emptyMcis, err
}
mcisReq.Vm = append(mcisReq.Vm, *vmReq)
Expand Down

0 comments on commit e12504f

Please sign in to comment.