Skip to content

Commit

Permalink
merge summary manager and solution manager
Browse files Browse the repository at this point in the history
  • Loading branch information
linyguo committed Jan 21, 2025
1 parent 3e5a41c commit f356d1d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 13 deletions.
10 changes: 5 additions & 5 deletions api/pkg/apis/v1alpha1/managers/solution/solution-manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ func (s *SolutionManager) Init(context *contexts.VendorContext, config managers.
return nil
}

func (s *SolutionManager) GetSummary(ctx context.Context, key string, namespace string) (model.SummaryResult, error) {
return s.SummaryManager.GetSummary(ctx, fmt.Sprintf("%s-%s", "summary", key), namespace)
func (s *SolutionManager) GetSummary(ctx context.Context, summaryId string, name string, namespace string) (model.SummaryResult, error) {
return s.SummaryManager.GetSummary(ctx, fmt.Sprintf("%s-%s", "summary", summaryId), name, namespace)
}

func (s *SolutionManager) DeleteSummary(ctx context.Context, key string, namespace string) error {
Expand Down Expand Up @@ -528,9 +528,9 @@ func (s *SolutionManager) getTargetStateForStep(step model.DeploymentStep, deplo

func (s *SolutionManager) saveSummary(ctx context.Context, objectName string, summaryId string, generation string, hash string, summary model.SummarySpec, state model.SummaryState, namespace string) error {
// TODO: delete this state when time expires. This should probably be invoked by the vendor (via GetSummary method, for instance)
log.DebugfCtx(ctx, " M (Solution): saving summary, objectName: %s, state: %s, namespace: %s, jobid: %s, hash %s, targetCount %d, successCount %d",
objectName, state, namespace, summary.JobID, hash, summary.TargetCount, summary.SuccessCount)
return s.SummaryManager.UpsertSummary(ctx, fmt.Sprintf("%s-%s", "summary", objectName), generation, hash, summary, state, namespace)
log.DebugfCtx(ctx, " M (Solution): saving summary, objectName: %s, summaryId: %s, state: %v, namespace: %s, jobid: %s, hash %s, targetCount %d, successCount %d",
objectName, summaryId, state, namespace, summary.JobID, hash, summary.TargetCount, summary.SuccessCount)
return s.SummaryManager.UpsertSummary(ctx, fmt.Sprintf("%s-%s", "summary", summaryId), generation, hash, summary, state, namespace)
}

func (s *SolutionManager) saveSummaryProgress(ctx context.Context, objectName string, summaryId string, generation string, hash string, summary model.SummarySpec, namespace string) error {
Expand Down
29 changes: 21 additions & 8 deletions api/pkg/apis/v1alpha1/managers/solution/summary-manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,15 @@ func (s *SummaryManager) DeleteDeploymentState(ctx context.Context, instance str
return err
}

func (s *SummaryManager) GetSummary(ctx context.Context, summaryId string, namespace string) (model.SummaryResult, error) {
func (s *SummaryManager) GetSummary(ctx context.Context, summaryId string, name string, namespace string) (model.SummaryResult, error) {
ctx, span := observability.StartSpan("Summary Manager", ctx, &map[string]string{
"method": "GetSummary",
})
var err error = nil
defer observ_utils.CloseSpanWithError(span, &err)
defer observ_utils.EmitUserDiagnosticsLogs(ctx, &err)

log.InfofCtx(ctx, " M (Summary): get summary, key: %s, namespace: %s", summaryId, namespace)
log.InfofCtx(ctx, " M (Summary): get summary, name: %s, summaryId: %s, namespace: %s", name, summaryId, namespace)

var state states.StateEntry
state, err = s.StateProvider.Get(ctx, states.GetRequest{
Expand All @@ -118,6 +118,19 @@ func (s *SummaryManager) GetSummary(ctx context.Context, summaryId string, names
"resource": Summary,
},
})
if err != nil && api_utils.IsNotFound(err) && name != "" {
// if get summary by guid not found, try to get the summary by name
log.InfofCtx(ctx, " M (Summary): failed to get deployment summary[%s] by summaryId, error: %+v. Try to get summary by name", summaryId, err)
state, err = s.StateProvider.Get(ctx, states.GetRequest{
ID: fmt.Sprintf("%s-%s", "summary", name),
Metadata: map[string]interface{}{
"namespace": namespace,
"group": model.SolutionGroup,
"version": "v1",
"resource": Summary,
},
})
}
if err != nil {
log.ErrorfCtx(ctx, " M (Summary): failed to get deployment summary[%s]: %+v", summaryId, err)
return model.SummaryResult{}, err
Expand Down Expand Up @@ -163,7 +176,7 @@ func (s *SummaryManager) ListSummary(ctx context.Context, namespace string) ([]m
}

func (s *SummaryManager) UpsertSummary(ctx context.Context, summaryId string, generation string, hash string, summary model.SummarySpec, state model.SummaryState, namespace string) error {
oldSummary, err := s.GetSummary(ctx, summaryId, namespace)
oldSummary, err := s.GetSummary(ctx, summaryId, "", namespace)
if err != nil && !v1alpha2.IsNotFound(err) {
log.ErrorfCtx(ctx, " M (Summary): failed to get previous summary: %+v", err)
return err
Expand Down Expand Up @@ -206,18 +219,18 @@ func (s *SummaryManager) UpsertSummary(ctx context.Context, summaryId string, ge
return err
}

func (s *SummaryManager) DeleteSummary(ctx context.Context, id string, namespace string) error {
func (s *SummaryManager) DeleteSummary(ctx context.Context, summaryId string, namespace string) error {
ctx, span := observability.StartSpan("Summary Manager", ctx, &map[string]string{
"method": "DeleteSummary",
})
var err error = nil
defer observ_utils.CloseSpanWithError(span, &err)
defer observ_utils.EmitUserDiagnosticsLogs(ctx, &err)

log.InfofCtx(ctx, " M (Summary): delete summary, key: %s, namespace: %s", id, namespace)
log.InfofCtx(ctx, " M (Summary): delete summary, key: %s, namespace: %s", summaryId, namespace)

err = s.StateProvider.Delete(ctx, states.DeleteRequest{
ID: id,
ID: summaryId,
Metadata: map[string]interface{}{
"namespace": namespace,
"group": model.SolutionGroup,
Expand All @@ -228,10 +241,10 @@ func (s *SummaryManager) DeleteSummary(ctx context.Context, id string, namespace

if err != nil {
if api_utils.IsNotFound(err) {
log.DebugfCtx(ctx, " M (Summary): DeleteSummary NoutFound, id: %s, namespace: %s", id, namespace)
log.DebugfCtx(ctx, " M (Summary): DeleteSummary NoutFound, id: %s, namespace: %s", summaryId, namespace)
return nil
}
log.ErrorfCtx(ctx, " M (Summary): failed to get summary[%s]: %+v", id, err)
log.ErrorfCtx(ctx, " M (Summary): failed to get summary[%s]: %+v", summaryId, err)
return err
}

Expand Down

0 comments on commit f356d1d

Please sign in to comment.