go.uber.org/cadence@v1.2.9/internal/compatibility/thrift/decision.go (about)

     1  // Copyright (c) 2021 Uber Technologies, Inc.
     2  //
     3  // Permission is hereby granted, free of charge, to any person obtaining a copy
     4  // of this software and associated documentation files (the "Software"), to deal
     5  // in the Software without restriction, including without limitation the rights
     6  // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
     7  // copies of the Software, and to permit persons to whom the Software is
     8  // furnished to do so, subject to the following conditions:
     9  //
    10  // The above copyright notice and this permission notice shall be included in
    11  // all copies or substantial portions of the Software.
    12  //
    13  // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    14  // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    15  // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    16  // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    17  // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    18  // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    19  // THE SOFTWARE.
    20  
    21  package thrift
    22  
    23  import (
    24  	"go.uber.org/cadence/.gen/go/shared"
    25  
    26  	apiv1 "github.com/uber/cadence-idl/go/proto/api/v1"
    27  )
    28  
    29  func DecisionArray(t []*apiv1.Decision) []*shared.Decision {
    30  	if t == nil {
    31  		return nil
    32  	}
    33  	v := make([]*shared.Decision, len(t))
    34  	for i := range t {
    35  		v[i] = Decision(t[i])
    36  	}
    37  	return v
    38  }
    39  
    40  func Decision(d *apiv1.Decision) *shared.Decision {
    41  	if d == nil {
    42  		return nil
    43  	}
    44  	decision := shared.Decision{}
    45  	switch attr := d.Attributes.(type) {
    46  	case *apiv1.Decision_ScheduleActivityTaskDecisionAttributes:
    47  		decision.DecisionType = shared.DecisionTypeScheduleActivityTask.Ptr()
    48  		a := attr.ScheduleActivityTaskDecisionAttributes
    49  		decision.ScheduleActivityTaskDecisionAttributes = &shared.ScheduleActivityTaskDecisionAttributes{
    50  			ActivityId:                    &a.ActivityId,
    51  			ActivityType:                  ActivityType(a.ActivityType),
    52  			Domain:                        &a.Domain,
    53  			TaskList:                      TaskList(a.TaskList),
    54  			Input:                         Payload(a.Input),
    55  			ScheduleToCloseTimeoutSeconds: durationToSeconds(a.ScheduleToCloseTimeout),
    56  			ScheduleToStartTimeoutSeconds: durationToSeconds(a.ScheduleToStartTimeout),
    57  			StartToCloseTimeoutSeconds:    durationToSeconds(a.StartToCloseTimeout),
    58  			HeartbeatTimeoutSeconds:       durationToSeconds(a.HeartbeatTimeout),
    59  			RetryPolicy:                   RetryPolicy(a.RetryPolicy),
    60  			Header:                        Header(a.Header),
    61  			RequestLocalDispatch:          &a.RequestLocalDispatch,
    62  		}
    63  	case *apiv1.Decision_StartTimerDecisionAttributes:
    64  		decision.DecisionType = shared.DecisionTypeStartTimer.Ptr()
    65  		a := attr.StartTimerDecisionAttributes
    66  		decision.StartTimerDecisionAttributes = &shared.StartTimerDecisionAttributes{
    67  			TimerId:                   &a.TimerId,
    68  			StartToFireTimeoutSeconds: int32To64(durationToSeconds(a.StartToFireTimeout)),
    69  		}
    70  	case *apiv1.Decision_CompleteWorkflowExecutionDecisionAttributes:
    71  		decision.DecisionType = shared.DecisionTypeCompleteWorkflowExecution.Ptr()
    72  		a := attr.CompleteWorkflowExecutionDecisionAttributes
    73  		decision.CompleteWorkflowExecutionDecisionAttributes = &shared.CompleteWorkflowExecutionDecisionAttributes{
    74  			Result: Payload(a.Result),
    75  		}
    76  	case *apiv1.Decision_FailWorkflowExecutionDecisionAttributes:
    77  		decision.DecisionType = shared.DecisionTypeFailWorkflowExecution.Ptr()
    78  		a := attr.FailWorkflowExecutionDecisionAttributes
    79  		decision.FailWorkflowExecutionDecisionAttributes = &shared.FailWorkflowExecutionDecisionAttributes{
    80  			Reason:  FailureReason(a.Failure),
    81  			Details: FailureDetails(a.Failure),
    82  		}
    83  	case *apiv1.Decision_RequestCancelActivityTaskDecisionAttributes:
    84  		decision.DecisionType = shared.DecisionTypeRequestCancelActivityTask.Ptr()
    85  		a := attr.RequestCancelActivityTaskDecisionAttributes
    86  		decision.RequestCancelActivityTaskDecisionAttributes = &shared.RequestCancelActivityTaskDecisionAttributes{
    87  			ActivityId: &a.ActivityId,
    88  		}
    89  	case *apiv1.Decision_CancelTimerDecisionAttributes:
    90  		decision.DecisionType = shared.DecisionTypeCancelTimer.Ptr()
    91  		a := attr.CancelTimerDecisionAttributes
    92  		decision.CancelTimerDecisionAttributes = &shared.CancelTimerDecisionAttributes{
    93  			TimerId: &a.TimerId,
    94  		}
    95  	case *apiv1.Decision_CancelWorkflowExecutionDecisionAttributes:
    96  		decision.DecisionType = shared.DecisionTypeCancelWorkflowExecution.Ptr()
    97  		a := attr.CancelWorkflowExecutionDecisionAttributes
    98  		decision.CancelWorkflowExecutionDecisionAttributes = &shared.CancelWorkflowExecutionDecisionAttributes{
    99  			Details: Payload(a.Details),
   100  		}
   101  	case *apiv1.Decision_RequestCancelExternalWorkflowExecutionDecisionAttributes:
   102  		decision.DecisionType = shared.DecisionTypeRequestCancelExternalWorkflowExecution.Ptr()
   103  		a := attr.RequestCancelExternalWorkflowExecutionDecisionAttributes
   104  		decision.RequestCancelExternalWorkflowExecutionDecisionAttributes = &shared.RequestCancelExternalWorkflowExecutionDecisionAttributes{
   105  			Domain:            &a.Domain,
   106  			WorkflowId:        WorkflowId(a.WorkflowExecution),
   107  			RunId:             RunId(a.WorkflowExecution),
   108  			Control:           a.Control,
   109  			ChildWorkflowOnly: &a.ChildWorkflowOnly,
   110  		}
   111  	case *apiv1.Decision_RecordMarkerDecisionAttributes:
   112  		decision.DecisionType = shared.DecisionTypeRecordMarker.Ptr()
   113  		a := attr.RecordMarkerDecisionAttributes
   114  		decision.RecordMarkerDecisionAttributes = &shared.RecordMarkerDecisionAttributes{
   115  			MarkerName: &a.MarkerName,
   116  			Details:    Payload(a.Details),
   117  			Header:     Header(a.Header),
   118  		}
   119  	case *apiv1.Decision_ContinueAsNewWorkflowExecutionDecisionAttributes:
   120  		decision.DecisionType = shared.DecisionTypeContinueAsNewWorkflowExecution.Ptr()
   121  		a := attr.ContinueAsNewWorkflowExecutionDecisionAttributes
   122  		decision.ContinueAsNewWorkflowExecutionDecisionAttributes = &shared.ContinueAsNewWorkflowExecutionDecisionAttributes{
   123  			WorkflowType:                        WorkflowType(a.WorkflowType),
   124  			TaskList:                            TaskList(a.TaskList),
   125  			Input:                               Payload(a.Input),
   126  			ExecutionStartToCloseTimeoutSeconds: durationToSeconds(a.ExecutionStartToCloseTimeout),
   127  			TaskStartToCloseTimeoutSeconds:      durationToSeconds(a.TaskStartToCloseTimeout),
   128  			BackoffStartIntervalInSeconds:       durationToSeconds(a.BackoffStartInterval),
   129  			RetryPolicy:                         RetryPolicy(a.RetryPolicy),
   130  			Initiator:                           ContinueAsNewInitiator(a.Initiator),
   131  			FailureReason:                       FailureReason(a.Failure),
   132  			FailureDetails:                      FailureDetails(a.Failure),
   133  			LastCompletionResult:                Payload(a.LastCompletionResult),
   134  			CronSchedule:                        &a.CronSchedule,
   135  			Header:                              Header(a.Header),
   136  			Memo:                                Memo(a.Memo),
   137  			SearchAttributes:                    SearchAttributes(a.SearchAttributes),
   138  			JitterStartSeconds:                  durationToSeconds(a.JitterStart),
   139  		}
   140  	case *apiv1.Decision_StartChildWorkflowExecutionDecisionAttributes:
   141  		decision.DecisionType = shared.DecisionTypeStartChildWorkflowExecution.Ptr()
   142  		a := attr.StartChildWorkflowExecutionDecisionAttributes
   143  		decision.StartChildWorkflowExecutionDecisionAttributes = &shared.StartChildWorkflowExecutionDecisionAttributes{
   144  			Domain:                              &a.Domain,
   145  			WorkflowId:                          &a.WorkflowId,
   146  			WorkflowType:                        WorkflowType(a.WorkflowType),
   147  			TaskList:                            TaskList(a.TaskList),
   148  			Input:                               Payload(a.Input),
   149  			ExecutionStartToCloseTimeoutSeconds: durationToSeconds(a.ExecutionStartToCloseTimeout),
   150  			TaskStartToCloseTimeoutSeconds:      durationToSeconds(a.TaskStartToCloseTimeout),
   151  			ParentClosePolicy:                   ParentClosePolicy(a.ParentClosePolicy),
   152  			Control:                             a.Control,
   153  			WorkflowIdReusePolicy:               WorkflowIdReusePolicy(a.WorkflowIdReusePolicy),
   154  			RetryPolicy:                         RetryPolicy(a.RetryPolicy),
   155  			CronSchedule:                        &a.CronSchedule,
   156  			Header:                              Header(a.Header),
   157  			Memo:                                Memo(a.Memo),
   158  			SearchAttributes:                    SearchAttributes(a.SearchAttributes),
   159  		}
   160  	case *apiv1.Decision_SignalExternalWorkflowExecutionDecisionAttributes:
   161  		decision.DecisionType = shared.DecisionTypeSignalExternalWorkflowExecution.Ptr()
   162  		a := attr.SignalExternalWorkflowExecutionDecisionAttributes
   163  		decision.SignalExternalWorkflowExecutionDecisionAttributes = &shared.SignalExternalWorkflowExecutionDecisionAttributes{
   164  			Domain:            &a.Domain,
   165  			Execution:         WorkflowExecution(a.WorkflowExecution),
   166  			SignalName:        &a.SignalName,
   167  			Input:             Payload(a.Input),
   168  			Control:           a.Control,
   169  			ChildWorkflowOnly: &a.ChildWorkflowOnly,
   170  		}
   171  	case *apiv1.Decision_UpsertWorkflowSearchAttributesDecisionAttributes:
   172  		decision.DecisionType = shared.DecisionTypeUpsertWorkflowSearchAttributes.Ptr()
   173  		a := attr.UpsertWorkflowSearchAttributesDecisionAttributes
   174  		decision.UpsertWorkflowSearchAttributesDecisionAttributes = &shared.UpsertWorkflowSearchAttributesDecisionAttributes{
   175  			SearchAttributes: SearchAttributes(a.SearchAttributes),
   176  		}
   177  	default:
   178  		panic("unknown decision type")
   179  	}
   180  	return &decision
   181  }