Skip to content

Commit

Permalink
Added 2-way proto-thrift mapper (#1130)
Browse files Browse the repository at this point in the history
  • Loading branch information
vytautas-karpavicius committed Sep 30, 2021
1 parent 5886e38 commit 8fff028
Show file tree
Hide file tree
Showing 29 changed files with 9,334 additions and 3,304 deletions.
338 changes: 264 additions & 74 deletions internal/compatibility/adapter.go

Large diffs are not rendered by default.

946 changes: 946 additions & 0 deletions internal/compatibility/api_test.go

Large diffs are not rendered by default.

334 changes: 334 additions & 0 deletions internal/compatibility/enum_test.go

Large diffs are not rendered by default.

64 changes: 64 additions & 0 deletions internal/compatibility/error_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// Copyright (c) 2021 Uber Technologies, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

package compatibility

import (
"reflect"
"testing"

"github.com/stretchr/testify/assert"
"go.uber.org/cadence/internal/compatibility/proto"
"go.uber.org/cadence/internal/compatibility/testdata"
"go.uber.org/cadence/internal/compatibility/thrift"
"go.uber.org/yarpc/yarpcerrors"
)

func TestErrors(t *testing.T) {
for _, err := range []error{
nil, // OK - no error
testdata.AccessDeniedError,
testdata.BadRequestError,
testdata.CancellationAlreadyRequestedError,
testdata.ClientVersionNotSupportedError,
testdata.DomainAlreadyExistsError,
testdata.DomainNotActiveError,
testdata.EntityNotExistsError,
testdata.FeatureNotEnabledError,
testdata.WorkflowExecutionAlreadyCompletedError,
testdata.InternalServiceError,
testdata.LimitExceededError,
testdata.QueryFailedError,
testdata.ServiceBusyError,
testdata.WorkflowExecutionAlreadyStartedError,
testdata.UnknownError,
} {
name := "OK"
if err != nil {
name = reflect.TypeOf(err).Elem().Name()
}
t.Run(name, func(t *testing.T) {
assert.Equal(t, err, proto.Error(thrift.Error(err)))
})
}

timeout := yarpcerrors.DeadlineExceededErrorf("timeout")
assert.Equal(t, timeout, thrift.Error(timeout))
}
189 changes: 189 additions & 0 deletions internal/compatibility/proto/decision.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
// Copyright (c) 2021 Uber Technologies, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

package proto

import (
"go.uber.org/cadence/.gen/go/shared"
apiv1 "go.uber.org/cadence/.gen/proto/api/v1"
)

func DecisionArray(t []*shared.Decision) []*apiv1.Decision {
if t == nil {
return nil
}
v := make([]*apiv1.Decision, len(t))
for i := range t {
v[i] = Decision(t[i])
}
return v
}

func Decision(d *shared.Decision) *apiv1.Decision {
if d == nil {
return nil
}
decision := apiv1.Decision{}
switch *d.DecisionType {
case shared.DecisionTypeScheduleActivityTask:
attr := d.ScheduleActivityTaskDecisionAttributes
decision.Attributes = &apiv1.Decision_ScheduleActivityTaskDecisionAttributes{
ScheduleActivityTaskDecisionAttributes: &apiv1.ScheduleActivityTaskDecisionAttributes{
ActivityId: attr.GetActivityId(),
ActivityType: ActivityType(attr.ActivityType),
Domain: attr.GetDomain(),
TaskList: TaskList(attr.TaskList),
Input: Payload(attr.Input),
ScheduleToCloseTimeout: secondsToDuration(attr.ScheduleToCloseTimeoutSeconds),
ScheduleToStartTimeout: secondsToDuration(attr.ScheduleToStartTimeoutSeconds),
StartToCloseTimeout: secondsToDuration(attr.StartToCloseTimeoutSeconds),
HeartbeatTimeout: secondsToDuration(attr.HeartbeatTimeoutSeconds),
RetryPolicy: RetryPolicy(attr.RetryPolicy),
Header: Header(attr.Header),
RequestLocalDispatch: attr.GetRequestLocalDispatch(),
},
}
case shared.DecisionTypeRequestCancelActivityTask:
attr := d.RequestCancelActivityTaskDecisionAttributes
decision.Attributes = &apiv1.Decision_RequestCancelActivityTaskDecisionAttributes{
RequestCancelActivityTaskDecisionAttributes: &apiv1.RequestCancelActivityTaskDecisionAttributes{
ActivityId: attr.GetActivityId(),
},
}
case shared.DecisionTypeStartTimer:
attr := d.StartTimerDecisionAttributes
decision.Attributes = &apiv1.Decision_StartTimerDecisionAttributes{
StartTimerDecisionAttributes: &apiv1.StartTimerDecisionAttributes{
TimerId: attr.GetTimerId(),
StartToFireTimeout: secondsToDuration(int64To32(attr.StartToFireTimeoutSeconds)),
},
}
case shared.DecisionTypeCompleteWorkflowExecution:
attr := d.CompleteWorkflowExecutionDecisionAttributes
decision.Attributes = &apiv1.Decision_CompleteWorkflowExecutionDecisionAttributes{
CompleteWorkflowExecutionDecisionAttributes: &apiv1.CompleteWorkflowExecutionDecisionAttributes{
Result: Payload(attr.Result),
},
}
case shared.DecisionTypeFailWorkflowExecution:
attr := d.FailWorkflowExecutionDecisionAttributes
decision.Attributes = &apiv1.Decision_FailWorkflowExecutionDecisionAttributes{
FailWorkflowExecutionDecisionAttributes: &apiv1.FailWorkflowExecutionDecisionAttributes{
Failure: Failure(attr.Reason, attr.Details),
},
}
case shared.DecisionTypeCancelTimer:
attr := d.CancelTimerDecisionAttributes
decision.Attributes = &apiv1.Decision_CancelTimerDecisionAttributes{
CancelTimerDecisionAttributes: &apiv1.CancelTimerDecisionAttributes{
TimerId: attr.GetTimerId(),
},
}
case shared.DecisionTypeCancelWorkflowExecution:
attr := d.CancelWorkflowExecutionDecisionAttributes
decision.Attributes = &apiv1.Decision_CancelWorkflowExecutionDecisionAttributes{
CancelWorkflowExecutionDecisionAttributes: &apiv1.CancelWorkflowExecutionDecisionAttributes{
Details: Payload(attr.Details),
},
}
case shared.DecisionTypeRequestCancelExternalWorkflowExecution:
attr := d.RequestCancelExternalWorkflowExecutionDecisionAttributes
decision.Attributes = &apiv1.Decision_RequestCancelExternalWorkflowExecutionDecisionAttributes{
RequestCancelExternalWorkflowExecutionDecisionAttributes: &apiv1.RequestCancelExternalWorkflowExecutionDecisionAttributes{
Domain: attr.GetDomain(),
WorkflowExecution: WorkflowRunPair(attr.WorkflowId, attr.RunId),
Control: attr.Control,
ChildWorkflowOnly: attr.GetChildWorkflowOnly(),
},
}
case shared.DecisionTypeRecordMarker:
attr := d.RecordMarkerDecisionAttributes
decision.Attributes = &apiv1.Decision_RecordMarkerDecisionAttributes{
RecordMarkerDecisionAttributes: &apiv1.RecordMarkerDecisionAttributes{
MarkerName: attr.GetMarkerName(),
Details: Payload(attr.Details),
Header: Header(attr.Header),
},
}
case shared.DecisionTypeContinueAsNewWorkflowExecution:
attr := d.ContinueAsNewWorkflowExecutionDecisionAttributes
decision.Attributes = &apiv1.Decision_ContinueAsNewWorkflowExecutionDecisionAttributes{
ContinueAsNewWorkflowExecutionDecisionAttributes: &apiv1.ContinueAsNewWorkflowExecutionDecisionAttributes{
WorkflowType: WorkflowType(attr.WorkflowType),
TaskList: TaskList(attr.TaskList),
Input: Payload(attr.Input),
ExecutionStartToCloseTimeout: secondsToDuration(attr.ExecutionStartToCloseTimeoutSeconds),
TaskStartToCloseTimeout: secondsToDuration(attr.TaskStartToCloseTimeoutSeconds),
BackoffStartInterval: secondsToDuration(attr.BackoffStartIntervalInSeconds),
RetryPolicy: RetryPolicy(attr.RetryPolicy),
Initiator: ContinueAsNewInitiator(attr.Initiator),
Failure: Failure(attr.FailureReason, attr.FailureDetails),
LastCompletionResult: Payload(attr.LastCompletionResult),
CronSchedule: attr.GetCronSchedule(),
Header: Header(attr.Header),
Memo: Memo(attr.Memo),
SearchAttributes: SearchAttributes(attr.SearchAttributes),
},
}
case shared.DecisionTypeStartChildWorkflowExecution:
attr := d.StartChildWorkflowExecutionDecisionAttributes
decision.Attributes = &apiv1.Decision_StartChildWorkflowExecutionDecisionAttributes{
StartChildWorkflowExecutionDecisionAttributes: &apiv1.StartChildWorkflowExecutionDecisionAttributes{
Domain: attr.GetDomain(),
WorkflowId: attr.GetWorkflowId(),
WorkflowType: WorkflowType(attr.WorkflowType),
TaskList: TaskList(attr.TaskList),
Input: Payload(attr.Input),
ExecutionStartToCloseTimeout: secondsToDuration(attr.ExecutionStartToCloseTimeoutSeconds),
TaskStartToCloseTimeout: secondsToDuration(attr.TaskStartToCloseTimeoutSeconds),
ParentClosePolicy: ParentClosePolicy(attr.ParentClosePolicy),
Control: attr.Control,
WorkflowIdReusePolicy: WorkflowIdReusePolicy(attr.WorkflowIdReusePolicy),
RetryPolicy: RetryPolicy(attr.RetryPolicy),
CronSchedule: attr.GetCronSchedule(),
Header: Header(attr.Header),
Memo: Memo(attr.Memo),
SearchAttributes: SearchAttributes(attr.SearchAttributes),
},
}
case shared.DecisionTypeSignalExternalWorkflowExecution:
attr := d.SignalExternalWorkflowExecutionDecisionAttributes
decision.Attributes = &apiv1.Decision_SignalExternalWorkflowExecutionDecisionAttributes{
SignalExternalWorkflowExecutionDecisionAttributes: &apiv1.SignalExternalWorkflowExecutionDecisionAttributes{
Domain: attr.GetDomain(),
WorkflowExecution: WorkflowExecution(attr.Execution),
SignalName: attr.GetSignalName(),
Input: Payload(attr.Input),
Control: attr.Control,
ChildWorkflowOnly: attr.GetChildWorkflowOnly(),
},
}
case shared.DecisionTypeUpsertWorkflowSearchAttributes:
attr := d.UpsertWorkflowSearchAttributesDecisionAttributes
decision.Attributes = &apiv1.Decision_UpsertWorkflowSearchAttributesDecisionAttributes{
UpsertWorkflowSearchAttributesDecisionAttributes: &apiv1.UpsertWorkflowSearchAttributesDecisionAttributes{
SearchAttributes: SearchAttributes(attr.SearchAttributes),
},
}
default:
panic("unknown decision type")
}
return &decision
}
Loading

0 comments on commit 8fff028

Please sign in to comment.