Skip to content

Commit 8fff028

Browse files
Added 2-way proto-thrift mapper (#1130)
1 parent 5886e38 commit 8fff028

29 files changed

+9334
-3304
lines changed

internal/compatibility/adapter.go

Lines changed: 264 additions & 74 deletions
Large diffs are not rendered by default.

internal/compatibility/api_test.go

Lines changed: 946 additions & 0 deletions
Large diffs are not rendered by default.

internal/compatibility/enum_test.go

Lines changed: 334 additions & 0 deletions
Large diffs are not rendered by default.

internal/compatibility/error_test.go

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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 compatibility
22+
23+
import (
24+
"reflect"
25+
"testing"
26+
27+
"github.com/stretchr/testify/assert"
28+
"go.uber.org/cadence/internal/compatibility/proto"
29+
"go.uber.org/cadence/internal/compatibility/testdata"
30+
"go.uber.org/cadence/internal/compatibility/thrift"
31+
"go.uber.org/yarpc/yarpcerrors"
32+
)
33+
34+
func TestErrors(t *testing.T) {
35+
for _, err := range []error{
36+
nil, // OK - no error
37+
testdata.AccessDeniedError,
38+
testdata.BadRequestError,
39+
testdata.CancellationAlreadyRequestedError,
40+
testdata.ClientVersionNotSupportedError,
41+
testdata.DomainAlreadyExistsError,
42+
testdata.DomainNotActiveError,
43+
testdata.EntityNotExistsError,
44+
testdata.FeatureNotEnabledError,
45+
testdata.WorkflowExecutionAlreadyCompletedError,
46+
testdata.InternalServiceError,
47+
testdata.LimitExceededError,
48+
testdata.QueryFailedError,
49+
testdata.ServiceBusyError,
50+
testdata.WorkflowExecutionAlreadyStartedError,
51+
testdata.UnknownError,
52+
} {
53+
name := "OK"
54+
if err != nil {
55+
name = reflect.TypeOf(err).Elem().Name()
56+
}
57+
t.Run(name, func(t *testing.T) {
58+
assert.Equal(t, err, proto.Error(thrift.Error(err)))
59+
})
60+
}
61+
62+
timeout := yarpcerrors.DeadlineExceededErrorf("timeout")
63+
assert.Equal(t, timeout, thrift.Error(timeout))
64+
}
Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
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 proto
22+
23+
import (
24+
"go.uber.org/cadence/.gen/go/shared"
25+
apiv1 "go.uber.org/cadence/.gen/proto/api/v1"
26+
)
27+
28+
func DecisionArray(t []*shared.Decision) []*apiv1.Decision {
29+
if t == nil {
30+
return nil
31+
}
32+
v := make([]*apiv1.Decision, len(t))
33+
for i := range t {
34+
v[i] = Decision(t[i])
35+
}
36+
return v
37+
}
38+
39+
func Decision(d *shared.Decision) *apiv1.Decision {
40+
if d == nil {
41+
return nil
42+
}
43+
decision := apiv1.Decision{}
44+
switch *d.DecisionType {
45+
case shared.DecisionTypeScheduleActivityTask:
46+
attr := d.ScheduleActivityTaskDecisionAttributes
47+
decision.Attributes = &apiv1.Decision_ScheduleActivityTaskDecisionAttributes{
48+
ScheduleActivityTaskDecisionAttributes: &apiv1.ScheduleActivityTaskDecisionAttributes{
49+
ActivityId: attr.GetActivityId(),
50+
ActivityType: ActivityType(attr.ActivityType),
51+
Domain: attr.GetDomain(),
52+
TaskList: TaskList(attr.TaskList),
53+
Input: Payload(attr.Input),
54+
ScheduleToCloseTimeout: secondsToDuration(attr.ScheduleToCloseTimeoutSeconds),
55+
ScheduleToStartTimeout: secondsToDuration(attr.ScheduleToStartTimeoutSeconds),
56+
StartToCloseTimeout: secondsToDuration(attr.StartToCloseTimeoutSeconds),
57+
HeartbeatTimeout: secondsToDuration(attr.HeartbeatTimeoutSeconds),
58+
RetryPolicy: RetryPolicy(attr.RetryPolicy),
59+
Header: Header(attr.Header),
60+
RequestLocalDispatch: attr.GetRequestLocalDispatch(),
61+
},
62+
}
63+
case shared.DecisionTypeRequestCancelActivityTask:
64+
attr := d.RequestCancelActivityTaskDecisionAttributes
65+
decision.Attributes = &apiv1.Decision_RequestCancelActivityTaskDecisionAttributes{
66+
RequestCancelActivityTaskDecisionAttributes: &apiv1.RequestCancelActivityTaskDecisionAttributes{
67+
ActivityId: attr.GetActivityId(),
68+
},
69+
}
70+
case shared.DecisionTypeStartTimer:
71+
attr := d.StartTimerDecisionAttributes
72+
decision.Attributes = &apiv1.Decision_StartTimerDecisionAttributes{
73+
StartTimerDecisionAttributes: &apiv1.StartTimerDecisionAttributes{
74+
TimerId: attr.GetTimerId(),
75+
StartToFireTimeout: secondsToDuration(int64To32(attr.StartToFireTimeoutSeconds)),
76+
},
77+
}
78+
case shared.DecisionTypeCompleteWorkflowExecution:
79+
attr := d.CompleteWorkflowExecutionDecisionAttributes
80+
decision.Attributes = &apiv1.Decision_CompleteWorkflowExecutionDecisionAttributes{
81+
CompleteWorkflowExecutionDecisionAttributes: &apiv1.CompleteWorkflowExecutionDecisionAttributes{
82+
Result: Payload(attr.Result),
83+
},
84+
}
85+
case shared.DecisionTypeFailWorkflowExecution:
86+
attr := d.FailWorkflowExecutionDecisionAttributes
87+
decision.Attributes = &apiv1.Decision_FailWorkflowExecutionDecisionAttributes{
88+
FailWorkflowExecutionDecisionAttributes: &apiv1.FailWorkflowExecutionDecisionAttributes{
89+
Failure: Failure(attr.Reason, attr.Details),
90+
},
91+
}
92+
case shared.DecisionTypeCancelTimer:
93+
attr := d.CancelTimerDecisionAttributes
94+
decision.Attributes = &apiv1.Decision_CancelTimerDecisionAttributes{
95+
CancelTimerDecisionAttributes: &apiv1.CancelTimerDecisionAttributes{
96+
TimerId: attr.GetTimerId(),
97+
},
98+
}
99+
case shared.DecisionTypeCancelWorkflowExecution:
100+
attr := d.CancelWorkflowExecutionDecisionAttributes
101+
decision.Attributes = &apiv1.Decision_CancelWorkflowExecutionDecisionAttributes{
102+
CancelWorkflowExecutionDecisionAttributes: &apiv1.CancelWorkflowExecutionDecisionAttributes{
103+
Details: Payload(attr.Details),
104+
},
105+
}
106+
case shared.DecisionTypeRequestCancelExternalWorkflowExecution:
107+
attr := d.RequestCancelExternalWorkflowExecutionDecisionAttributes
108+
decision.Attributes = &apiv1.Decision_RequestCancelExternalWorkflowExecutionDecisionAttributes{
109+
RequestCancelExternalWorkflowExecutionDecisionAttributes: &apiv1.RequestCancelExternalWorkflowExecutionDecisionAttributes{
110+
Domain: attr.GetDomain(),
111+
WorkflowExecution: WorkflowRunPair(attr.WorkflowId, attr.RunId),
112+
Control: attr.Control,
113+
ChildWorkflowOnly: attr.GetChildWorkflowOnly(),
114+
},
115+
}
116+
case shared.DecisionTypeRecordMarker:
117+
attr := d.RecordMarkerDecisionAttributes
118+
decision.Attributes = &apiv1.Decision_RecordMarkerDecisionAttributes{
119+
RecordMarkerDecisionAttributes: &apiv1.RecordMarkerDecisionAttributes{
120+
MarkerName: attr.GetMarkerName(),
121+
Details: Payload(attr.Details),
122+
Header: Header(attr.Header),
123+
},
124+
}
125+
case shared.DecisionTypeContinueAsNewWorkflowExecution:
126+
attr := d.ContinueAsNewWorkflowExecutionDecisionAttributes
127+
decision.Attributes = &apiv1.Decision_ContinueAsNewWorkflowExecutionDecisionAttributes{
128+
ContinueAsNewWorkflowExecutionDecisionAttributes: &apiv1.ContinueAsNewWorkflowExecutionDecisionAttributes{
129+
WorkflowType: WorkflowType(attr.WorkflowType),
130+
TaskList: TaskList(attr.TaskList),
131+
Input: Payload(attr.Input),
132+
ExecutionStartToCloseTimeout: secondsToDuration(attr.ExecutionStartToCloseTimeoutSeconds),
133+
TaskStartToCloseTimeout: secondsToDuration(attr.TaskStartToCloseTimeoutSeconds),
134+
BackoffStartInterval: secondsToDuration(attr.BackoffStartIntervalInSeconds),
135+
RetryPolicy: RetryPolicy(attr.RetryPolicy),
136+
Initiator: ContinueAsNewInitiator(attr.Initiator),
137+
Failure: Failure(attr.FailureReason, attr.FailureDetails),
138+
LastCompletionResult: Payload(attr.LastCompletionResult),
139+
CronSchedule: attr.GetCronSchedule(),
140+
Header: Header(attr.Header),
141+
Memo: Memo(attr.Memo),
142+
SearchAttributes: SearchAttributes(attr.SearchAttributes),
143+
},
144+
}
145+
case shared.DecisionTypeStartChildWorkflowExecution:
146+
attr := d.StartChildWorkflowExecutionDecisionAttributes
147+
decision.Attributes = &apiv1.Decision_StartChildWorkflowExecutionDecisionAttributes{
148+
StartChildWorkflowExecutionDecisionAttributes: &apiv1.StartChildWorkflowExecutionDecisionAttributes{
149+
Domain: attr.GetDomain(),
150+
WorkflowId: attr.GetWorkflowId(),
151+
WorkflowType: WorkflowType(attr.WorkflowType),
152+
TaskList: TaskList(attr.TaskList),
153+
Input: Payload(attr.Input),
154+
ExecutionStartToCloseTimeout: secondsToDuration(attr.ExecutionStartToCloseTimeoutSeconds),
155+
TaskStartToCloseTimeout: secondsToDuration(attr.TaskStartToCloseTimeoutSeconds),
156+
ParentClosePolicy: ParentClosePolicy(attr.ParentClosePolicy),
157+
Control: attr.Control,
158+
WorkflowIdReusePolicy: WorkflowIdReusePolicy(attr.WorkflowIdReusePolicy),
159+
RetryPolicy: RetryPolicy(attr.RetryPolicy),
160+
CronSchedule: attr.GetCronSchedule(),
161+
Header: Header(attr.Header),
162+
Memo: Memo(attr.Memo),
163+
SearchAttributes: SearchAttributes(attr.SearchAttributes),
164+
},
165+
}
166+
case shared.DecisionTypeSignalExternalWorkflowExecution:
167+
attr := d.SignalExternalWorkflowExecutionDecisionAttributes
168+
decision.Attributes = &apiv1.Decision_SignalExternalWorkflowExecutionDecisionAttributes{
169+
SignalExternalWorkflowExecutionDecisionAttributes: &apiv1.SignalExternalWorkflowExecutionDecisionAttributes{
170+
Domain: attr.GetDomain(),
171+
WorkflowExecution: WorkflowExecution(attr.Execution),
172+
SignalName: attr.GetSignalName(),
173+
Input: Payload(attr.Input),
174+
Control: attr.Control,
175+
ChildWorkflowOnly: attr.GetChildWorkflowOnly(),
176+
},
177+
}
178+
case shared.DecisionTypeUpsertWorkflowSearchAttributes:
179+
attr := d.UpsertWorkflowSearchAttributesDecisionAttributes
180+
decision.Attributes = &apiv1.Decision_UpsertWorkflowSearchAttributesDecisionAttributes{
181+
UpsertWorkflowSearchAttributesDecisionAttributes: &apiv1.UpsertWorkflowSearchAttributesDecisionAttributes{
182+
SearchAttributes: SearchAttributes(attr.SearchAttributes),
183+
},
184+
}
185+
default:
186+
panic("unknown decision type")
187+
}
188+
return &decision
189+
}

0 commit comments

Comments
 (0)