Skip to content
Open
Show file tree
Hide file tree
Changes from 12 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
29 changes: 19 additions & 10 deletions internal/actionplan/actionplan.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/Azure/azure-extension-platform/pkg/extensionevents"
"github.com/Azure/azure-extension-platform/pkg/handlerenv"
"github.com/Azure/azure-extension-platform/pkg/logging"
vmextensionhelper "github.com/Azure/azure-extension-platform/vmextension"
)

type action struct {
Expand Down Expand Up @@ -117,14 +118,19 @@ func updateFailDeploymentError(failDeploymentError *failedDeploymentError, act *
}

type ExecuteError struct {
failedDeploymentErr *failedDeploymentError
combinedExecuteErrors error
failedDeploymentErr *failedDeploymentError
combinedExecuteErrors error
errorWithClarification vmextensionhelper.ErrorWithClarification
}

func (executeError *ExecuteError) GetCombinedExecuteError() error {
return executeError.combinedExecuteErrors
}

func (executeError *ExecuteError) GetErrorWithClarification() vmextensionhelper.ErrorWithClarification {
return executeError.errorWithClarification
}

func (executeError *ExecuteError) SetFailedDeploymentErr(err *failedDeploymentError) {
executeError.failedDeploymentErr = err
}
Expand All @@ -133,9 +139,12 @@ func (executeError *ExecuteError) SetCombinedExecuteErrors(errs error) {
executeError.combinedExecuteErrors = errs
}

func (exeucuteError *ExecuteError) update(act *action, singleExecutionError error) {
func (exeucuteError *ExecuteError) update(act *action, singleExecutionError error, code ...vmextensionhelper.ErrorWithClarification) {
exeucuteError.failedDeploymentErr = updateFailDeploymentError(exeucuteError.failedDeploymentErr, act, singleExecutionError)
exeucuteError.combinedExecuteErrors = extensionerrors.CombineErrors(exeucuteError.combinedExecuteErrors, singleExecutionError)
if len(code) != 0 {
exeucuteError.errorWithClarification = vmextensionhelper.NewErrorWithClarification(code[0].ErrorCode, code[0].Err)
}
}

func (exeucuteError *ExecuteError) GetErrorIfDeploymentFailed() error {
Expand Down Expand Up @@ -233,7 +242,7 @@ func (actionPlan *ActionPlan) insertOperation(order *int, dependentActions1 ...*
}

func (actionPlan *ActionPlan) Execute(registryHandler packageregistry.IPackageRegistry, eem *extensionevents.ExtensionEventManager, commandHandler commandhandler.ICommandHandler) (*ExecuteError, IResult) {
var executeError *ExecuteError = &ExecuteError{failedDeploymentErr: nil, combinedExecuteErrors: nil}
var executeError *ExecuteError = &ExecuteError{failedDeploymentErr: nil, combinedExecuteErrors: nil, errorWithClarification: vmextensionhelper.ErrorWithClarification{}}
// registry will be mutated and written to disk so that we can keep track of all the actions that have happened
registry, err := registryHandler.GetExistingPackages()
if err != nil {
Expand All @@ -243,9 +252,9 @@ func (actionPlan *ActionPlan) Execute(registryHandler packageregistry.IPackageRe

// handle unordered implicit uninstalls
for _, act := range actionPlan.unorderedImplicitUninstalls {
newError := actionPlan.executeHelper(registryHandler, commandHandler, registry, act, eem)
ewc, newError := actionPlan.executeHelper(registryHandler, commandHandler, registry, act, eem)
appendExecutionResult(&executionResult, act, newError)
executeError.update(act, newError)
executeError.update(act, newError, ewc)
}

// handle ordered operations
Expand Down Expand Up @@ -274,8 +283,8 @@ func (actionPlan *ActionPlan) Execute(registryHandler packageregistry.IPackageRe
break
}

newError := actionPlan.executeHelper(registryHandler, commandHandler, registry, act, eem)
executeError.update(act, newError)
ewc, newError := actionPlan.executeHelper(registryHandler, commandHandler, registry, act, eem)
executeError.update(act, newError, ewc)
appendExecutionResult(&executionResult, act, newError)

if newError != nil {
Expand All @@ -292,8 +301,8 @@ func (actionPlan *ActionPlan) Execute(registryHandler packageregistry.IPackageRe
// handle remaining unordered operations
for _, depActions := range actionPlan.unorderedOperations {
for _, act := range depActions {
newError := actionPlan.executeHelper(registryHandler, commandHandler, registry, act, eem)
executeError.update(act, newError)
ewc, newError := actionPlan.executeHelper(registryHandler, commandHandler, registry, act, eem)
executeError.update(act, newError, ewc)
appendExecutionResult(&executionResult, act, newError)

if newError != nil {
Expand Down
Loading