Skip to content

Commit

Permalink
save step to old
Browse files Browse the repository at this point in the history
  • Loading branch information
yanjiaxin534 committed Jan 22, 2025
1 parent c0c5746 commit a75a2cd
Showing 1 changed file with 22 additions and 26 deletions.
48 changes: 22 additions & 26 deletions api/pkg/apis/v1alpha1/managers/solution/solution-manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -740,29 +740,19 @@ func (s *SolutionManager) saveStepResult(ctx context.Context, planState PlanStat
}
lockName := api_utils.GenerateKeyLockName(planState.Namespace, planState.Deployment.Instance.ObjectMeta.Name)
s.KeyLockProvider.TryLock(lockName)
planState.CompletedSteps++
switch planState.Phase {
case PhaseGet:
// Update the GetResult for the specific step
planState.StepStates[stepResult.StepId].GetResult = stepResult.GetResult
log.InfofCtx(ctx, "update plan state planid %s stepId %s stepstates %+v", stepResult.PlanId, stepResult.StepId, planState.StepStates[stepResult.StepId].GetResult)
if stepResult.StepId != len(planState.Steps)-1 {
if stepResult.StepId != planState.TotalSteps-1 {
if err := s.publishDeploymentStep(ctx, stepResult.StepId+1, planState, planState.Remove, planState.Steps[stepResult.StepId+1]); err != nil {
log.InfofCtx(ctx, "failed to publish deployment step %s", err)
// return err
}
} else {
log.InfofCtx(ctx, "V(Solution): handle get plan Complete %+v", planState)
err := s.handlePlanComplete(ctx, planState)
if err != nil {
log.InfoCtx(ctx, "V(Solution): handle plan Complete failed %+v", err)
lockName := api_utils.GenerateKeyLockName(planState.Namespace, planState.Deployment.Instance.ObjectMeta.Name)
s.KeyLockProvider.UnLock(lockName)
}
}
case PhaseApply:
log.InfofCtx(ctx, "before %s ", planState.CompletedSteps)
planState.CompletedSteps++
log.InfofCtx(ctx, "after %s", planState.CompletedSteps)
log.InfofCtx(ctx, "update apply plan state planid %s stepId %s v", stepResult.PlanId, stepResult.StepId)
if stepResult.Error != "" {
// Handle error case and update the target result status and message
Expand Down Expand Up @@ -801,7 +791,7 @@ func (s *SolutionManager) saveStepResult(ctx context.Context, planState PlanStat
}

// publish next step execute event
if stepResult.StepId != len(planState.Steps)-1 {
if stepResult.StepId != planState.TotalSteps-1 {
log.InfoCtx(ctx, "V(Solution): publish apply deployment step id %s step %+v", stepResult.StepId+1, planState.Steps[stepResult.StepId+1].Role)
if err := s.publishDeploymentStep(ctx, stepResult.StepId+1, planState, planState.Remove, planState.Steps[stepResult.StepId+1]); err != nil {
log.InfoCtx(ctx, "V(Solution): publish deployment step failed PlanId %s, stepId %s", planState.PlanId, 0)
Expand All @@ -811,27 +801,33 @@ func (s *SolutionManager) saveStepResult(ctx context.Context, planState PlanStat
if err := s.saveSummaryInfo(ctx, planState, model.SummaryStateRunning); err != nil {
log.ErrorfCtx(ctx, "Failed to save summary progress: %v", err)
}
} else {
// If no components are deployed, set success count to target count
if planState.Summary.CurrentDeployed == 0 && planState.Summary.AllAssignedDeployed {
planState.Summary.SuccessCount = planState.Summary.TargetCount
}
log.InfofCtx(ctx, "V(Solution): handle apply plan Complete %+v", planState)
err := s.handlePlanComplete(ctx, planState)
if err != nil {
log.InfoCtx(ctx, "V(Solution): handle apply plan Complete failed %+v", err)
lockName := api_utils.GenerateKeyLockName(planState.Namespace, planState.Deployment.Instance.ObjectMeta.Name)
s.KeyLockProvider.UnLock(lockName)
}
return nil
}
}
// If no components are deployed, set success count to target count
if planState.Summary.CurrentDeployed == 0 && planState.Summary.AllAssignedDeployed {
planState.Summary.SuccessCount = planState.Summary.TargetCount
}

// Save the summary information
log.InfoCtx(ctx, "Begin to save summary for %s", planState.Deployment.Instance.ObjectMeta.Name)
if err := s.saveSummaryInfo(ctx, planState, model.SummaryStateRunning); err != nil {
log.ErrorfCtx(ctx, "Failed to save summary progress: %v", err)
}
}

// Store the updated plan state
log.InfofCtx(ctx, "upsert here 1")
s.upsertPlanState(ctx, planState.PlanId, planState)
// Check if all steps are completed and handle plan completion
// Check if all steps are completed and handle plan completion
if planState.isCompleted() {
err := s.handlePlanComplete(ctx, planState)
if err != nil {
log.InfoCtx(ctx, "V(Solution): handle plan Complete failed %+v", err)
lockName := api_utils.GenerateKeyLockName(planState.Namespace, planState.Deployment.Instance.ObjectMeta.Name)
s.KeyLockProvider.UnLock(lockName)
}
}
return nil
}

Expand Down

0 comments on commit a75a2cd

Please sign in to comment.