Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add reset reapply to batch reset command #700

Merged
merged 4 commits into from
Nov 19, 2024
Merged
Changes from 1 commit
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
97 changes: 62 additions & 35 deletions temporalcli/commands.workflow_reset.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,33 +77,9 @@ func (c *TemporalWorkflowResetCommand) doWorkflowReset(cctx *CommandContext, cl
}
}

reapplyExcludes := make([]enums.ResetReapplyExcludeType, 0)
for _, exclude := range c.ReapplyExclude.Values {
if strings.ToLower(exclude) == "all" {
for _, excludeType := range enums.ResetReapplyExcludeType_value {
if excludeType == 0 {
continue
}
reapplyExcludes = append(reapplyExcludes, enums.ResetReapplyExcludeType(excludeType))
}
break
}
excludeType, err := enums.ResetReapplyExcludeTypeFromString(exclude)
if err != nil {
return err
}
reapplyExcludes = append(reapplyExcludes, excludeType)
}

reapplyType := enums.RESET_REAPPLY_TYPE_ALL_ELIGIBLE
if c.ReapplyType.Value != "All" {
if len(c.ReapplyExclude.Values) > 0 {
return errors.New("--reapply-type cannot be used with --reapply-exclude. Use --reapply-exclude.")
}
reapplyType, err = enums.ResetReapplyTypeFromString(c.ReapplyType.Value)
if err != nil {
return err
}
reapplyExcludes, reapplyType, err := getResetReapplyAndExcludeTypes(c.ReapplyExclude.Values, c.ReapplyType.Value)
if err != nil {
return fmt.Errorf("getting reset reapply and exclude types failed: %w", err)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the prefix here ("getting reset reapply and...") isn't quite right for a user-facing error message, since it's making reference to an operation that's essentially something CLI internals are doing. I'm thinking just returning err will give the desired error message.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, agree.
Did it cuz it was similar to the error above getting reset event... error. I have also changed that one.

}

cctx.Printer.Printlnf("Resetting workflow %s to event ID %d", c.WorkflowId, eventID)
Expand Down Expand Up @@ -138,10 +114,15 @@ func (c *TemporalWorkflowResetCommand) runBatchReset(cctx *CommandContext, cl cl
VisibilityQuery: c.Query,
Reason: c.Reason,
}

batchResetOptions, err := c.batchResetOptions()
if err != nil {
return err
}
request.Operation = &workflowservice.StartBatchOperationRequest_ResetOperation{
ResetOperation: &batch.BatchOperationReset{
Identity: clientIdentity(),
Options: c.batchResetOptions(c.Type.Value),
Options: batchResetOptions,
},
}
count, err := cl.CountWorkflow(cctx, &workflowservice.CountWorkflowExecutionsRequest{Query: c.Query})
Expand All @@ -160,22 +141,33 @@ func (c *TemporalWorkflowResetCommand) runBatchReset(cctx *CommandContext, cl cl
return startBatchJob(cctx, cl, &request)
}

func (c *TemporalWorkflowResetCommand) batchResetOptions(resetType string) *common.ResetOptions {
switch resetType {
func (c *TemporalWorkflowResetCommand) batchResetOptions() (*common.ResetOptions, error) {
reapplyExcludes, reapplyType, err := getResetReapplyAndExcludeTypes(c.ReapplyExclude.Values, c.ReapplyType.Value)
if err != nil {
return nil, err
}

switch c.Type.Value {
case "FirstWorkflowTask":
return &common.ResetOptions{
Target: &common.ResetOptions_FirstWorkflowTask{},
}
Target: &common.ResetOptions_FirstWorkflowTask{},
ResetReapplyExcludeTypes: reapplyExcludes,
ResetReapplyType: reapplyType,
}, nil
case "LastWorkflowTask":
return &common.ResetOptions{
Target: &common.ResetOptions_LastWorkflowTask{},
}
Target: &common.ResetOptions_LastWorkflowTask{},
ResetReapplyExcludeTypes: reapplyExcludes,
ResetReapplyType: reapplyType,
}, nil
case "BuildId":
return &common.ResetOptions{
Target: &common.ResetOptions_BuildId{
BuildId: c.BuildId,
},
}
ResetReapplyExcludeTypes: reapplyExcludes,
ResetReapplyType: reapplyType,
}, nil
default:
panic("unsupported operation type was filtered by cli framework")
}
Expand Down Expand Up @@ -314,3 +306,38 @@ func getLastContinueAsNewID(ctx context.Context, namespace, wid, rid string, wfs
}
return
}

func getResetReapplyAndExcludeTypes(resetReapplyExclude []string, resetReapplyType string) ([]enums.ResetReapplyExcludeType, enums.ResetReapplyType, error) {
var err error

var reapplyExcludes []enums.ResetReapplyExcludeType
for _, exclude := range resetReapplyExclude {
if strings.ToLower(exclude) == "all" {
for _, excludeType := range enums.ResetReapplyExcludeType_value {
if excludeType == int32(enums.RESET_REAPPLY_EXCLUDE_TYPE_UNSPECIFIED) {
continue
}
reapplyExcludes = append(reapplyExcludes, enums.ResetReapplyExcludeType(excludeType))
}
break
}
excludeType, err := enums.ResetReapplyExcludeTypeFromString(exclude)
if err != nil {
return nil, 0, err
jamipouchi marked this conversation as resolved.
Show resolved Hide resolved
}
reapplyExcludes = append(reapplyExcludes, excludeType)
}

returnReapplyType := enums.RESET_REAPPLY_TYPE_ALL_ELIGIBLE
if resetReapplyType != "All" {
if len(resetReapplyExclude) > 0 {
return nil, 0, errors.New("--reapply-type cannot be used with --reapply-exclude. Use --reapply-exclude")
}
returnReapplyType, err = enums.ResetReapplyTypeFromString(resetReapplyType)
if err != nil {
return nil, 0, err
}
}

return reapplyExcludes, returnReapplyType, nil
}
Loading