Skip to content

Commit

Permalink
fix error msg (#135)
Browse files Browse the repository at this point in the history
fix error msg
  • Loading branch information
SparkYuan authored Sep 6, 2022
1 parent eb45080 commit f0553fe
Showing 1 changed file with 15 additions and 16 deletions.
31 changes: 15 additions & 16 deletions pkg/engine/operation/models/operation_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,15 @@ import (
"fmt"
"sync"

"kusionstack.io/kusion/pkg/engine/operation/types"
"github.com/jinzhu/copier"

"kusionstack.io/kusion/pkg/engine/models"
"kusionstack.io/kusion/pkg/engine/operation/types"
"kusionstack.io/kusion/pkg/engine/runtime"
"kusionstack.io/kusion/pkg/util/kdump"

"github.com/jinzhu/copier"

"kusionstack.io/kusion/pkg/engine/states"
"kusionstack.io/kusion/pkg/log"
"kusionstack.io/kusion/pkg/util"
jsonutil "kusionstack.io/kusion/pkg/util/json"
)

// Operation is the base model for all operations
Expand Down Expand Up @@ -94,23 +92,24 @@ func (o *Operation) RefreshResourceIndex(resourceKey string, resource *models.Re
}

func (o *Operation) InitStates(request *Request) (*states.State, *states.State) {
query := &states.StateQuery{
Tenant: request.Tenant,
Stack: request.Stack,
Project: request.Project,
Cluster: request.Cluster,
}
latestState, err := o.StateStorage.GetLatestState(
&states.StateQuery{
Tenant: request.Tenant,
Stack: request.Stack,
Project: request.Project,
Cluster: request.Cluster,
},
query,
)
util.CheckNotError(err, fmt.Sprintf("GetLatestState failed with request: %v", kdump.FormatN(request)))
util.CheckNotError(err, fmt.Sprintf("get the latest State failed with query: %v", jsonutil.Marshal2PrettyString(query)))
if latestState == nil {
log.Infof("can't find states with request: %v", kdump.FormatN(request))
log.Infof("can't find states with request: %v", jsonutil.Marshal2PrettyString(request))
latestState = states.NewState()
}
resultState := states.NewState()
resultState.Serial = latestState.Serial
err = copier.Copy(resultState, request)
util.CheckNotError(err, "Copy request to ResultState, request")
util.CheckNotError(err, fmt.Sprintf("copy request to result State failed, request:%v", jsonutil.Marshal2PrettyString(request)))
resultState.Resources = nil

return latestState, resultState
Expand All @@ -136,8 +135,8 @@ func (o *Operation) UpdateState(resourceIndex map[string]*models.Resource) error
state.Resources = res
err := o.StateStorage.Apply(state)
if err != nil {
return fmt.Errorf("insert priorState failed. %w", err)
return fmt.Errorf("apply State failed. %w", err)
}
log.Infof("UpdateState:%v success", state.ID)
log.Infof("update State:%v success", state.ID)
return nil
}

0 comments on commit f0553fe

Please sign in to comment.