From f2f10d4dbb4cad55b3444ea9dff1bae81008e4bb Mon Sep 17 00:00:00 2001 From: Vytautas Date: Thu, 4 Mar 2021 11:01:16 +0200 Subject: [PATCH] Proto mappers (#3902) --- common/types/mapper/proto/admin.go | 636 +++ common/types/mapper/proto/admin_test.go | 174 + common/types/mapper/proto/api.go | 5728 ++++++++++++++++++++ common/types/mapper/proto/api_test.go | 1002 ++++ common/types/mapper/proto/enum_test.go | 409 ++ common/types/mapper/proto/errors.go | 241 + common/types/mapper/proto/errors_test.go | 64 + common/types/mapper/proto/helpers.go | 156 + common/types/mapper/proto/history.go | 1397 +++++ common/types/mapper/proto/history_test.go | 319 ++ common/types/mapper/proto/matching.go | 415 ++ common/types/mapper/proto/matching_test.go | 101 + common/types/mapper/proto/shared.go | 940 ++++ common/types/mapper/proto/shared_test.go | 377 ++ common/types/testdata/common.go | 398 ++ common/types/testdata/decision.go | 189 + common/types/testdata/domain.go | 92 + common/types/testdata/enum.go | 51 + common/types/testdata/error.go | 105 + common/types/testdata/history.go | 581 ++ common/types/testdata/replication.go | 145 + common/types/testdata/service_admin.go | 175 + common/types/testdata/service_frontend.go | 437 ++ common/types/testdata/service_history.go | 292 + common/types/testdata/service_matching.go | 140 + go.mod | 3 +- 26 files changed, 14566 insertions(+), 1 deletion(-) create mode 100644 common/types/mapper/proto/admin.go create mode 100644 common/types/mapper/proto/admin_test.go create mode 100644 common/types/mapper/proto/api.go create mode 100644 common/types/mapper/proto/api_test.go create mode 100644 common/types/mapper/proto/enum_test.go create mode 100644 common/types/mapper/proto/errors.go create mode 100644 common/types/mapper/proto/errors_test.go create mode 100644 common/types/mapper/proto/helpers.go create mode 100644 common/types/mapper/proto/history.go create mode 100644 common/types/mapper/proto/history_test.go create mode 100644 common/types/mapper/proto/matching.go create mode 100644 common/types/mapper/proto/matching_test.go create mode 100644 common/types/mapper/proto/shared.go create mode 100644 common/types/mapper/proto/shared_test.go create mode 100644 common/types/testdata/common.go create mode 100644 common/types/testdata/decision.go create mode 100644 common/types/testdata/domain.go create mode 100644 common/types/testdata/enum.go create mode 100644 common/types/testdata/error.go create mode 100644 common/types/testdata/history.go create mode 100644 common/types/testdata/replication.go create mode 100644 common/types/testdata/service_admin.go create mode 100644 common/types/testdata/service_frontend.go create mode 100644 common/types/testdata/service_history.go create mode 100644 common/types/testdata/service_matching.go diff --git a/common/types/mapper/proto/admin.go b/common/types/mapper/proto/admin.go new file mode 100644 index 00000000000..e0d95b349a7 --- /dev/null +++ b/common/types/mapper/proto/admin.go @@ -0,0 +1,636 @@ +// 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 ( + adminv1 "github.com/uber/cadence/.gen/proto/admin/v1" + "github.com/uber/cadence/common/types" +) + +func FromAdminAddSearchAttributeRequest(t *types.AddSearchAttributeRequest) *adminv1.AddSearchAttributeRequest { + if t == nil { + return nil + } + return &adminv1.AddSearchAttributeRequest{ + SearchAttribute: FromIndexedValueTypeMap(t.SearchAttribute), + SecurityToken: t.SecurityToken, + } +} + +func ToAdminAddSearchAttributeRequest(t *adminv1.AddSearchAttributeRequest) *types.AddSearchAttributeRequest { + if t == nil { + return nil + } + return &types.AddSearchAttributeRequest{ + SearchAttribute: ToIndexedValueTypeMap(t.SearchAttribute), + SecurityToken: t.SecurityToken, + } +} + +func FromAdminCloseShardRequest(t *types.CloseShardRequest) *adminv1.CloseShardRequest { + if t == nil { + return nil + } + return &adminv1.CloseShardRequest{ + ShardId: t.ShardID, + } +} + +func ToAdminCloseShardRequest(t *adminv1.CloseShardRequest) *types.CloseShardRequest { + if t == nil { + return nil + } + return &types.CloseShardRequest{ + ShardID: t.ShardId, + } +} + +func FromAdminDescribeClusterResponse(t *types.DescribeClusterResponse) *adminv1.DescribeClusterResponse { + if t == nil { + return nil + } + return &adminv1.DescribeClusterResponse{ + SupportedClientVersions: FromSupportedClientVersions(t.SupportedClientVersions), + MembershipInfo: FromMembershipInfo(t.MembershipInfo), + } +} + +func ToAdminDescribeClusterResponse(t *adminv1.DescribeClusterResponse) *types.DescribeClusterResponse { + if t == nil { + return nil + } + return &types.DescribeClusterResponse{ + SupportedClientVersions: ToSupportedClientVersions(t.SupportedClientVersions), + MembershipInfo: ToMembershipInfo(t.MembershipInfo), + } +} + +func FromAdminDescribeHistoryHostRequest(t *types.DescribeHistoryHostRequest) *adminv1.DescribeHistoryHostRequest { + if t == nil { + return nil + } + if t.HostAddress != nil { + return &adminv1.DescribeHistoryHostRequest{ + DescribeBy: &adminv1.DescribeHistoryHostRequest_HostAddress{HostAddress: *t.HostAddress}, + } + } + if t.ShardIDForHost != nil { + return &adminv1.DescribeHistoryHostRequest{ + DescribeBy: &adminv1.DescribeHistoryHostRequest_ShardId{ShardId: *t.ShardIDForHost}, + } + } + if t.ExecutionForHost != nil { + return &adminv1.DescribeHistoryHostRequest{ + DescribeBy: &adminv1.DescribeHistoryHostRequest_WorkflowExecution{WorkflowExecution: FromWorkflowExecution(t.ExecutionForHost)}, + } + } + panic("neither oneof field is set for DescribeHistoryHostRequest") +} + +func ToAdminDescribeHistoryHostRequest(t *adminv1.DescribeHistoryHostRequest) *types.DescribeHistoryHostRequest { + if t == nil { + return nil + } + switch describeBy := t.DescribeBy.(type) { + case *adminv1.DescribeHistoryHostRequest_HostAddress: + return &types.DescribeHistoryHostRequest{HostAddress: &describeBy.HostAddress} + case *adminv1.DescribeHistoryHostRequest_ShardId: + return &types.DescribeHistoryHostRequest{ShardIDForHost: &describeBy.ShardId} + case *adminv1.DescribeHistoryHostRequest_WorkflowExecution: + return &types.DescribeHistoryHostRequest{ExecutionForHost: ToWorkflowExecution(describeBy.WorkflowExecution)} + } + panic("neither oneof field is set for DescribeHistoryHostRequest") +} + +func FromAdminDescribeHistoryHostResponse(t *types.DescribeHistoryHostResponse) *adminv1.DescribeHistoryHostResponse { + if t == nil { + return nil + } + return &adminv1.DescribeHistoryHostResponse{ + NumberOfShards: t.NumberOfShards, + ShardIds: t.ShardIDs, + DomainCache: FromDomainCacheInfo(t.DomainCache), + ShardControllerStatus: t.ShardControllerStatus, + Address: t.Address, + } +} + +func ToAdminDescribeHistoryHostResponse(t *adminv1.DescribeHistoryHostResponse) *types.DescribeHistoryHostResponse { + if t == nil { + return nil + } + return &types.DescribeHistoryHostResponse{ + NumberOfShards: t.NumberOfShards, + ShardIDs: t.ShardIds, + DomainCache: ToDomainCacheInfo(t.DomainCache), + ShardControllerStatus: t.ShardControllerStatus, + Address: t.Address, + } +} + +func FromAdminDescribeQueueRequest(t *types.DescribeQueueRequest) *adminv1.DescribeQueueRequest { + if t == nil { + return nil + } + return &adminv1.DescribeQueueRequest{ + ShardId: t.ShardID, + ClusterName: t.ClusterName, + TaskType: FromTaskType(t.Type), + } +} + +func ToAdminDescribeQueueRequest(t *adminv1.DescribeQueueRequest) *types.DescribeQueueRequest { + if t == nil { + return nil + } + return &types.DescribeQueueRequest{ + ShardID: t.ShardId, + ClusterName: t.ClusterName, + Type: ToTaskType(t.TaskType), + } +} + +func FromAdminDescribeQueueResponse(t *types.DescribeQueueResponse) *adminv1.DescribeQueueResponse { + if t == nil { + return nil + } + return &adminv1.DescribeQueueResponse{ + ProcessingQueueStates: t.ProcessingQueueStates, + } +} + +func ToAdminDescribeQueueResponse(t *adminv1.DescribeQueueResponse) *types.DescribeQueueResponse { + if t == nil { + return nil + } + return &types.DescribeQueueResponse{ + ProcessingQueueStates: t.ProcessingQueueStates, + } +} + +func FromAdminDescribeWorkflowExecutionRequest(t *types.AdminDescribeWorkflowExecutionRequest) *adminv1.DescribeWorkflowExecutionRequest { + if t == nil { + return nil + } + return &adminv1.DescribeWorkflowExecutionRequest{ + Domain: t.Domain, + WorkflowExecution: FromWorkflowExecution(t.Execution), + } +} + +func ToAdminDescribeWorkflowExecutionRequest(t *adminv1.DescribeWorkflowExecutionRequest) *types.AdminDescribeWorkflowExecutionRequest { + if t == nil { + return nil + } + return &types.AdminDescribeWorkflowExecutionRequest{ + Domain: t.Domain, + Execution: ToWorkflowExecution(t.WorkflowExecution), + } +} + +func FromAdminDescribeWorkflowExecutionResponse(t *types.AdminDescribeWorkflowExecutionResponse) *adminv1.DescribeWorkflowExecutionResponse { + if t == nil { + return nil + } + return &adminv1.DescribeWorkflowExecutionResponse{ + ShardId: stringToInt32(t.ShardID), + HistoryAddr: t.HistoryAddr, + MutableStateInCache: t.MutableStateInCache, + MutableStateInDatabase: t.MutableStateInDatabase, + } +} + +func ToAdminDescribeWorkflowExecutionResponse(t *adminv1.DescribeWorkflowExecutionResponse) *types.AdminDescribeWorkflowExecutionResponse { + if t == nil { + return nil + } + return &types.AdminDescribeWorkflowExecutionResponse{ + ShardID: int32ToString(t.ShardId), + HistoryAddr: t.HistoryAddr, + MutableStateInCache: t.MutableStateInCache, + MutableStateInDatabase: t.MutableStateInDatabase, + } +} + +func FromAdminGetDLQReplicationMessagesRequest(t *types.GetDLQReplicationMessagesRequest) *adminv1.GetDLQReplicationMessagesRequest { + if t == nil { + return nil + } + return &adminv1.GetDLQReplicationMessagesRequest{ + TaskInfos: FromReplicationTaskInfoArray(t.TaskInfos), + } +} + +func ToAdminGetDLQReplicationMessagesRequest(t *adminv1.GetDLQReplicationMessagesRequest) *types.GetDLQReplicationMessagesRequest { + if t == nil { + return nil + } + return &types.GetDLQReplicationMessagesRequest{ + TaskInfos: ToReplicationTaskInfoArray(t.TaskInfos), + } +} + +func FromAdminGetDLQReplicationMessagesResponse(t *types.GetDLQReplicationMessagesResponse) *adminv1.GetDLQReplicationMessagesResponse { + if t == nil { + return nil + } + return &adminv1.GetDLQReplicationMessagesResponse{ + ReplicationTasks: FromReplicationTaskArray(t.ReplicationTasks), + } +} + +func ToAdminGetDLQReplicationMessagesResponse(t *adminv1.GetDLQReplicationMessagesResponse) *types.GetDLQReplicationMessagesResponse { + if t == nil { + return nil + } + return &types.GetDLQReplicationMessagesResponse{ + ReplicationTasks: ToReplicationTaskArray(t.ReplicationTasks), + } +} + +func FromAdminGetDomainReplicationMessagesRequest(t *types.GetDomainReplicationMessagesRequest) *adminv1.GetDomainReplicationMessagesRequest { + if t == nil { + return nil + } + return &adminv1.GetDomainReplicationMessagesRequest{ + LastRetrievedMessageId: fromInt64Value(t.LastRetrievedMessageID), + LastProcessedMessageId: fromInt64Value(t.LastProcessedMessageID), + ClusterName: t.ClusterName, + } +} + +func ToAdminGetDomainReplicationMessagesRequest(t *adminv1.GetDomainReplicationMessagesRequest) *types.GetDomainReplicationMessagesRequest { + if t == nil { + return nil + } + return &types.GetDomainReplicationMessagesRequest{ + LastRetrievedMessageID: toInt64Value(t.LastRetrievedMessageId), + LastProcessedMessageID: toInt64Value(t.LastProcessedMessageId), + ClusterName: t.ClusterName, + } +} + +func FromAdminGetDomainReplicationMessagesResponse(t *types.GetDomainReplicationMessagesResponse) *adminv1.GetDomainReplicationMessagesResponse { + if t == nil { + return nil + } + return &adminv1.GetDomainReplicationMessagesResponse{ + Messages: FromReplicationMessages(t.Messages), + } +} + +func ToAdminGetDomainReplicationMessagesResponse(t *adminv1.GetDomainReplicationMessagesResponse) *types.GetDomainReplicationMessagesResponse { + if t == nil { + return nil + } + return &types.GetDomainReplicationMessagesResponse{ + Messages: ToReplicationMessages(t.Messages), + } +} + +func FromAdminGetReplicationMessagesRequest(t *types.GetReplicationMessagesRequest) *adminv1.GetReplicationMessagesRequest { + if t == nil { + return nil + } + return &adminv1.GetReplicationMessagesRequest{ + Tokens: FromReplicationTokenArray(t.Tokens), + ClusterName: t.ClusterName, + } +} + +func ToAdminGetReplicationMessagesRequest(t *adminv1.GetReplicationMessagesRequest) *types.GetReplicationMessagesRequest { + if t == nil { + return nil + } + return &types.GetReplicationMessagesRequest{ + Tokens: ToReplicationTokenArray(t.Tokens), + ClusterName: t.ClusterName, + } +} + +func FromAdminGetReplicationMessagesResponse(t *types.GetReplicationMessagesResponse) *adminv1.GetReplicationMessagesResponse { + if t == nil { + return nil + } + return &adminv1.GetReplicationMessagesResponse{ + ShardMessages: FromReplicationMessagesMap(t.MessagesByShard), + } +} + +func ToAdminGetReplicationMessagesResponse(t *adminv1.GetReplicationMessagesResponse) *types.GetReplicationMessagesResponse { + if t == nil { + return nil + } + return &types.GetReplicationMessagesResponse{ + MessagesByShard: ToReplicationMessagesMap(t.ShardMessages), + } +} + +func FromAdminGetWorkflowExecutionRawHistoryV2Request(t *types.GetWorkflowExecutionRawHistoryV2Request) *adminv1.GetWorkflowExecutionRawHistoryV2Request { + if t == nil { + return nil + } + return &adminv1.GetWorkflowExecutionRawHistoryV2Request{ + Domain: t.Domain, + WorkflowExecution: FromWorkflowExecution(t.Execution), + StartEvent: FromEventIDVersionPair(t.StartEventID, t.StartEventVersion), + EndEvent: FromEventIDVersionPair(t.EndEventID, t.EndEventVersion), + PageSize: t.MaximumPageSize, + NextPageToken: t.NextPageToken, + } +} + +func ToAdminGetWorkflowExecutionRawHistoryV2Request(t *adminv1.GetWorkflowExecutionRawHistoryV2Request) *types.GetWorkflowExecutionRawHistoryV2Request { + if t == nil { + return nil + } + return &types.GetWorkflowExecutionRawHistoryV2Request{ + Domain: t.Domain, + Execution: ToWorkflowExecution(t.WorkflowExecution), + StartEventID: ToEventID(t.StartEvent), + StartEventVersion: ToEventVersion(t.StartEvent), + EndEventID: ToEventID(t.EndEvent), + EndEventVersion: ToEventVersion(t.EndEvent), + MaximumPageSize: t.PageSize, + NextPageToken: t.NextPageToken, + } +} + +func FromAdminGetWorkflowExecutionRawHistoryV2Response(t *types.GetWorkflowExecutionRawHistoryV2Response) *adminv1.GetWorkflowExecutionRawHistoryV2Response { + if t == nil { + return nil + } + return &adminv1.GetWorkflowExecutionRawHistoryV2Response{ + NextPageToken: t.NextPageToken, + HistoryBatches: FromDataBlobArray(t.HistoryBatches), + VersionHistory: FromVersionHistory(t.VersionHistory), + } +} + +func ToAdminGetWorkflowExecutionRawHistoryV2Response(t *adminv1.GetWorkflowExecutionRawHistoryV2Response) *types.GetWorkflowExecutionRawHistoryV2Response { + if t == nil { + return nil + } + return &types.GetWorkflowExecutionRawHistoryV2Response{ + NextPageToken: t.NextPageToken, + HistoryBatches: ToDataBlobArray(t.HistoryBatches), + VersionHistory: ToVersionHistory(t.VersionHistory), + } +} + +func FromAdminMergeDLQMessagesRequest(t *types.MergeDLQMessagesRequest) *adminv1.MergeDLQMessagesRequest { + if t == nil { + return nil + } + return &adminv1.MergeDLQMessagesRequest{ + Type: FromDLQType(t.Type), + ShardId: t.ShardID, + SourceCluster: t.SourceCluster, + InclusiveEndMessageId: fromInt64Value(t.InclusiveEndMessageID), + PageSize: t.MaximumPageSize, + NextPageToken: t.NextPageToken, + } +} + +func ToAdminMergeDLQMessagesRequest(t *adminv1.MergeDLQMessagesRequest) *types.MergeDLQMessagesRequest { + if t == nil { + return nil + } + return &types.MergeDLQMessagesRequest{ + Type: ToDLQType(t.Type), + ShardID: t.ShardId, + SourceCluster: t.SourceCluster, + InclusiveEndMessageID: toInt64Value(t.InclusiveEndMessageId), + MaximumPageSize: t.PageSize, + NextPageToken: t.NextPageToken, + } +} + +func FromAdminMergeDLQMessagesResponse(t *types.MergeDLQMessagesResponse) *adminv1.MergeDLQMessagesResponse { + if t == nil { + return nil + } + return &adminv1.MergeDLQMessagesResponse{ + NextPageToken: t.NextPageToken, + } +} + +func ToAdminMergeDLQMessagesResponse(t *adminv1.MergeDLQMessagesResponse) *types.MergeDLQMessagesResponse { + if t == nil { + return nil + } + return &types.MergeDLQMessagesResponse{ + NextPageToken: t.NextPageToken, + } +} + +func FromAdminPurgeDLQMessagesRequest(t *types.PurgeDLQMessagesRequest) *adminv1.PurgeDLQMessagesRequest { + if t == nil { + return nil + } + return &adminv1.PurgeDLQMessagesRequest{ + Type: FromDLQType(t.Type), + ShardId: t.ShardID, + SourceCluster: t.SourceCluster, + InclusiveEndMessageId: fromInt64Value(t.InclusiveEndMessageID), + } +} + +func ToAdminPurgeDLQMessagesRequest(t *adminv1.PurgeDLQMessagesRequest) *types.PurgeDLQMessagesRequest { + if t == nil { + return nil + } + return &types.PurgeDLQMessagesRequest{ + Type: ToDLQType(t.Type), + ShardID: t.ShardId, + SourceCluster: t.SourceCluster, + InclusiveEndMessageID: toInt64Value(t.InclusiveEndMessageId), + } +} + +func FromAdminReadDLQMessagesRequest(t *types.ReadDLQMessagesRequest) *adminv1.ReadDLQMessagesRequest { + if t == nil { + return nil + } + return &adminv1.ReadDLQMessagesRequest{ + Type: FromDLQType(t.Type), + ShardId: t.ShardID, + SourceCluster: t.SourceCluster, + InclusiveEndMessageId: fromInt64Value(t.InclusiveEndMessageID), + PageSize: t.MaximumPageSize, + NextPageToken: t.NextPageToken, + } +} + +func ToAdminReadDLQMessagesRequest(t *adminv1.ReadDLQMessagesRequest) *types.ReadDLQMessagesRequest { + if t == nil { + return nil + } + return &types.ReadDLQMessagesRequest{ + Type: ToDLQType(t.Type), + ShardID: t.ShardId, + SourceCluster: t.SourceCluster, + InclusiveEndMessageID: toInt64Value(t.InclusiveEndMessageId), + MaximumPageSize: t.PageSize, + NextPageToken: t.NextPageToken, + } +} + +func FromAdminReadDLQMessagesResponse(t *types.ReadDLQMessagesResponse) *adminv1.ReadDLQMessagesResponse { + if t == nil { + return nil + } + return &adminv1.ReadDLQMessagesResponse{ + Type: FromDLQType(t.Type), + ReplicationTasks: FromReplicationTaskArray(t.ReplicationTasks), + ReplicationTasksInfo: FromReplicationTaskInfoArray(t.ReplicationTasksInfo), + NextPageToken: t.NextPageToken, + } +} + +func ToAdminReadDLQMessagesResponse(t *adminv1.ReadDLQMessagesResponse) *types.ReadDLQMessagesResponse { + if t == nil { + return nil + } + return &types.ReadDLQMessagesResponse{ + Type: ToDLQType(t.Type), + ReplicationTasks: ToReplicationTaskArray(t.ReplicationTasks), + ReplicationTasksInfo: ToReplicationTaskInfoArray(t.ReplicationTasksInfo), + NextPageToken: t.NextPageToken, + } +} + +func FromAdminReapplyEventsRequest(t *types.ReapplyEventsRequest) *adminv1.ReapplyEventsRequest { + if t == nil { + return nil + } + return &adminv1.ReapplyEventsRequest{ + Domain: t.DomainName, + WorkflowExecution: FromWorkflowExecution(t.WorkflowExecution), + Events: FromDataBlob(t.Events), + } +} + +func ToAdminReapplyEventsRequest(t *adminv1.ReapplyEventsRequest) *types.ReapplyEventsRequest { + if t == nil { + return nil + } + return &types.ReapplyEventsRequest{ + DomainName: t.Domain, + WorkflowExecution: ToWorkflowExecution(t.WorkflowExecution), + Events: ToDataBlob(t.Events), + } +} + +func FromAdminRefreshWorkflowTasksRequest(t *types.RefreshWorkflowTasksRequest) *adminv1.RefreshWorkflowTasksRequest { + if t == nil { + return nil + } + return &adminv1.RefreshWorkflowTasksRequest{ + Domain: t.Domain, + WorkflowExecution: FromWorkflowExecution(t.Execution), + } +} + +func ToAdminRefreshWorkflowTasksRequest(t *adminv1.RefreshWorkflowTasksRequest) *types.RefreshWorkflowTasksRequest { + if t == nil { + return nil + } + return &types.RefreshWorkflowTasksRequest{ + Domain: t.Domain, + Execution: ToWorkflowExecution(t.WorkflowExecution), + } +} + +func FromAdminRemoveTaskRequest(t *types.RemoveTaskRequest) *adminv1.RemoveTaskRequest { + if t == nil { + return nil + } + return &adminv1.RemoveTaskRequest{ + ShardId: t.ShardID, + TaskType: FromTaskType(t.Type), + TaskId: t.TaskID, + VisibilityTime: unixNanoToTime(t.VisibilityTimestamp), + } +} + +func ToAdminRemoveTaskRequest(t *adminv1.RemoveTaskRequest) *types.RemoveTaskRequest { + if t == nil { + return nil + } + return &types.RemoveTaskRequest{ + ShardID: t.ShardId, + Type: ToTaskType(t.TaskType), + TaskID: t.TaskId, + VisibilityTimestamp: timeToUnixNano(t.VisibilityTime), + } +} + +func FromAdminResendReplicationTasksRequest(t *types.ResendReplicationTasksRequest) *adminv1.ResendReplicationTasksRequest { + if t == nil { + return nil + } + return &adminv1.ResendReplicationTasksRequest{ + DomainId: t.DomainID, + WorkflowExecution: FromWorkflowRunPair(t.WorkflowID, t.RunID), + RemoteCluster: t.RemoteCluster, + StartEvent: FromEventIDVersionPair(t.StartEventID, t.StartVersion), + EndEvent: FromEventIDVersionPair(t.EndEventID, t.EndVersion), + } +} + +func ToAdminResendReplicationTasksRequest(t *adminv1.ResendReplicationTasksRequest) *types.ResendReplicationTasksRequest { + if t == nil { + return nil + } + return &types.ResendReplicationTasksRequest{ + DomainID: t.DomainId, + WorkflowID: ToWorkflowID(t.WorkflowExecution), + RunID: ToRunID(t.WorkflowExecution), + RemoteCluster: t.RemoteCluster, + StartEventID: ToEventID(t.StartEvent), + StartVersion: ToEventVersion(t.StartEvent), + EndEventID: ToEventID(t.EndEvent), + EndVersion: ToEventVersion(t.EndEvent), + } +} + +func FromAdminResetQueueRequest(t *types.ResetQueueRequest) *adminv1.ResetQueueRequest { + if t == nil { + return nil + } + return &adminv1.ResetQueueRequest{ + ShardId: t.ShardID, + ClusterName: t.ClusterName, + TaskType: FromTaskType(t.Type), + } +} + +func ToAdminResetQueueRequest(t *adminv1.ResetQueueRequest) *types.ResetQueueRequest { + if t == nil { + return nil + } + return &types.ResetQueueRequest{ + ShardID: t.ShardId, + ClusterName: t.ClusterName, + Type: ToTaskType(t.TaskType), + } +} diff --git a/common/types/mapper/proto/admin_test.go b/common/types/mapper/proto/admin_test.go new file mode 100644 index 00000000000..b7f136e53b8 --- /dev/null +++ b/common/types/mapper/proto/admin_test.go @@ -0,0 +1,174 @@ +// 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 ( + "testing" + + "github.com/stretchr/testify/assert" + + adminv1 "github.com/uber/cadence/.gen/proto/admin/v1" + "github.com/uber/cadence/common/types" + "github.com/uber/cadence/common/types/testdata" +) + +func TestAdminAddSearchAttributeRequest(t *testing.T) { + for _, item := range []*types.AddSearchAttributeRequest{nil, {}, &testdata.AdminAddSearchAttributeRequest} { + assert.Equal(t, item, ToAdminAddSearchAttributeRequest(FromAdminAddSearchAttributeRequest(item))) + } +} +func TestAdminCloseShardRequest(t *testing.T) { + for _, item := range []*types.CloseShardRequest{nil, {}, &testdata.AdminCloseShardRequest} { + assert.Equal(t, item, ToAdminCloseShardRequest(FromAdminCloseShardRequest(item))) + } +} +func TestAdminDescribeClusterResponse(t *testing.T) { + for _, item := range []*types.DescribeClusterResponse{nil, {}, &testdata.AdminDescribeClusterResponse} { + assert.Equal(t, item, ToAdminDescribeClusterResponse(FromAdminDescribeClusterResponse(item))) + } +} +func TestAdminDescribeHistoryHostRequest(t *testing.T) { + for _, item := range []*types.DescribeHistoryHostRequest{ + nil, + &testdata.AdminDescribeHistoryHostRequest_ByHost, + &testdata.AdminDescribeHistoryHostRequest_ByShard, + &testdata.AdminDescribeHistoryHostRequest_ByExecution, + } { + assert.Equal(t, item, ToAdminDescribeHistoryHostRequest(FromAdminDescribeHistoryHostRequest(item))) + } + assert.Panics(t, func() { ToAdminDescribeHistoryHostRequest(&adminv1.DescribeHistoryHostRequest{}) }) + assert.Panics(t, func() { FromAdminDescribeHistoryHostRequest(&types.DescribeHistoryHostRequest{}) }) +} +func TestAdminDescribeHistoryHostResponse(t *testing.T) { + for _, item := range []*types.DescribeHistoryHostResponse{nil, {}, &testdata.AdminDescribeHistoryHostResponse} { + assert.Equal(t, item, ToAdminDescribeHistoryHostResponse(FromAdminDescribeHistoryHostResponse(item))) + } +} +func TestAdminDescribeQueueRequest(t *testing.T) { + for _, item := range []*types.DescribeQueueRequest{nil, {}, &testdata.AdminDescribeQueueRequest} { + assert.Equal(t, item, ToAdminDescribeQueueRequest(FromAdminDescribeQueueRequest(item))) + } +} +func TestAdminDescribeQueueResponse(t *testing.T) { + for _, item := range []*types.DescribeQueueResponse{nil, {}, &testdata.AdminDescribeQueueResponse} { + assert.Equal(t, item, ToAdminDescribeQueueResponse(FromAdminDescribeQueueResponse(item))) + } +} +func TestAdminDescribeWorkflowExecutionRequest(t *testing.T) { + for _, item := range []*types.AdminDescribeWorkflowExecutionRequest{nil, {}, &testdata.AdminDescribeWorkflowExecutionRequest} { + assert.Equal(t, item, ToAdminDescribeWorkflowExecutionRequest(FromAdminDescribeWorkflowExecutionRequest(item))) + } +} +func TestAdminDescribeWorkflowExecutionResponse(t *testing.T) { + for _, item := range []*types.AdminDescribeWorkflowExecutionResponse{nil, {ShardID: "0"}, &testdata.AdminDescribeWorkflowExecutionResponse} { + assert.Equal(t, item, ToAdminDescribeWorkflowExecutionResponse(FromAdminDescribeWorkflowExecutionResponse(item))) + } +} +func TestAdminGetDLQReplicationMessagesRequest(t *testing.T) { + for _, item := range []*types.GetDLQReplicationMessagesRequest{nil, {}, &testdata.AdminGetDLQReplicationMessagesRequest} { + assert.Equal(t, item, ToAdminGetDLQReplicationMessagesRequest(FromAdminGetDLQReplicationMessagesRequest(item))) + } +} +func TestAdminGetDLQReplicationMessagesResponse(t *testing.T) { + for _, item := range []*types.GetDLQReplicationMessagesResponse{nil, {}, &testdata.AdminGetDLQReplicationMessagesResponse} { + assert.Equal(t, item, ToAdminGetDLQReplicationMessagesResponse(FromAdminGetDLQReplicationMessagesResponse(item))) + } +} +func TestAdminGetDomainReplicationMessagesRequest(t *testing.T) { + for _, item := range []*types.GetDomainReplicationMessagesRequest{nil, {}, &testdata.AdminGetDomainReplicationMessagesRequest} { + assert.Equal(t, item, ToAdminGetDomainReplicationMessagesRequest(FromAdminGetDomainReplicationMessagesRequest(item))) + } +} +func TestAdminGetDomainReplicationMessagesResponse(t *testing.T) { + for _, item := range []*types.GetDomainReplicationMessagesResponse{nil, {}, &testdata.AdminGetDomainReplicationMessagesResponse} { + assert.Equal(t, item, ToAdminGetDomainReplicationMessagesResponse(FromAdminGetDomainReplicationMessagesResponse(item))) + } +} +func TestAdminGetReplicationMessagesRequest(t *testing.T) { + for _, item := range []*types.GetReplicationMessagesRequest{nil, {}, &testdata.AdminGetReplicationMessagesRequest} { + assert.Equal(t, item, ToAdminGetReplicationMessagesRequest(FromAdminGetReplicationMessagesRequest(item))) + } +} +func TestAdminGetReplicationMessagesResponse(t *testing.T) { + for _, item := range []*types.GetReplicationMessagesResponse{nil, {}, &testdata.AdminGetReplicationMessagesResponse} { + assert.Equal(t, item, ToAdminGetReplicationMessagesResponse(FromAdminGetReplicationMessagesResponse(item))) + } +} +func TestAdminGetWorkflowExecutionRawHistoryV2Request(t *testing.T) { + for _, item := range []*types.GetWorkflowExecutionRawHistoryV2Request{nil, {}, &testdata.AdminGetWorkflowExecutionRawHistoryV2Request} { + assert.Equal(t, item, ToAdminGetWorkflowExecutionRawHistoryV2Request(FromAdminGetWorkflowExecutionRawHistoryV2Request(item))) + } +} +func TestAdminGetWorkflowExecutionRawHistoryV2Response(t *testing.T) { + for _, item := range []*types.GetWorkflowExecutionRawHistoryV2Response{nil, {}, &testdata.AdminGetWorkflowExecutionRawHistoryV2Response} { + assert.Equal(t, item, ToAdminGetWorkflowExecutionRawHistoryV2Response(FromAdminGetWorkflowExecutionRawHistoryV2Response(item))) + } +} +func TestAdminMergeDLQMessagesRequest(t *testing.T) { + for _, item := range []*types.MergeDLQMessagesRequest{nil, {}, &testdata.AdminMergeDLQMessagesRequest} { + assert.Equal(t, item, ToAdminMergeDLQMessagesRequest(FromAdminMergeDLQMessagesRequest(item))) + } +} +func TestAdminMergeDLQMessagesResponse(t *testing.T) { + for _, item := range []*types.MergeDLQMessagesResponse{nil, {}, &testdata.AdminMergeDLQMessagesResponse} { + assert.Equal(t, item, ToAdminMergeDLQMessagesResponse(FromAdminMergeDLQMessagesResponse(item))) + } +} +func TestAdminPurgeDLQMessagesRequest(t *testing.T) { + for _, item := range []*types.PurgeDLQMessagesRequest{nil, {}, &testdata.AdminPurgeDLQMessagesRequest} { + assert.Equal(t, item, ToAdminPurgeDLQMessagesRequest(FromAdminPurgeDLQMessagesRequest(item))) + } +} +func TestAdminReadDLQMessagesRequest(t *testing.T) { + for _, item := range []*types.ReadDLQMessagesRequest{nil, {}, &testdata.AdminReadDLQMessagesRequest} { + assert.Equal(t, item, ToAdminReadDLQMessagesRequest(FromAdminReadDLQMessagesRequest(item))) + } +} +func TestAdminReadDLQMessagesResponse(t *testing.T) { + for _, item := range []*types.ReadDLQMessagesResponse{nil, {}, &testdata.AdminReadDLQMessagesResponse} { + assert.Equal(t, item, ToAdminReadDLQMessagesResponse(FromAdminReadDLQMessagesResponse(item))) + } +} +func TestAdminReapplyEventsRequest(t *testing.T) { + for _, item := range []*types.ReapplyEventsRequest{nil, {}, &testdata.AdminReapplyEventsRequest} { + assert.Equal(t, item, ToAdminReapplyEventsRequest(FromAdminReapplyEventsRequest(item))) + } +} +func TestAdminRefreshWorkflowTasksRequest(t *testing.T) { + for _, item := range []*types.RefreshWorkflowTasksRequest{nil, {}, &testdata.AdminRefreshWorkflowTasksRequest} { + assert.Equal(t, item, ToAdminRefreshWorkflowTasksRequest(FromAdminRefreshWorkflowTasksRequest(item))) + } +} +func TestAdminRemoveTaskRequest(t *testing.T) { + for _, item := range []*types.RemoveTaskRequest{nil, {}, &testdata.AdminRemoveTaskRequest} { + assert.Equal(t, item, ToAdminRemoveTaskRequest(FromAdminRemoveTaskRequest(item))) + } +} +func TestAdminResendReplicationTasksRequest(t *testing.T) { + for _, item := range []*types.ResendReplicationTasksRequest{nil, {}, &testdata.AdminResendReplicationTasksRequest} { + assert.Equal(t, item, ToAdminResendReplicationTasksRequest(FromAdminResendReplicationTasksRequest(item))) + } +} +func TestAdminResetQueueRequest(t *testing.T) { + for _, item := range []*types.ResetQueueRequest{nil, {}, &testdata.AdminResetQueueRequest} { + assert.Equal(t, item, ToAdminResetQueueRequest(FromAdminResetQueueRequest(item))) + } +} diff --git a/common/types/mapper/proto/api.go b/common/types/mapper/proto/api.go new file mode 100644 index 00000000000..aa5fcc06bbb --- /dev/null +++ b/common/types/mapper/proto/api.go @@ -0,0 +1,5728 @@ +// 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 ( + "google.golang.org/protobuf/types/known/fieldmaskpb" + + apiv1 "github.com/uber/cadence/.gen/proto/api/v1" + "github.com/uber/cadence/common" + "github.com/uber/cadence/common/types" +) + +func FromActivityLocalDispatchInfo(t *types.ActivityLocalDispatchInfo) *apiv1.ActivityLocalDispatchInfo { + if t == nil { + return nil + } + return &apiv1.ActivityLocalDispatchInfo{ + ActivityId: t.ActivityID, + ScheduledTime: unixNanoToTime(t.ScheduledTimestamp), + StartedTime: unixNanoToTime(t.StartedTimestamp), + ScheduledTimeOfThisAttempt: unixNanoToTime(t.ScheduledTimestampOfThisAttempt), + TaskToken: t.TaskToken, + } +} + +func ToActivityLocalDispatchInfo(t *apiv1.ActivityLocalDispatchInfo) *types.ActivityLocalDispatchInfo { + if t == nil { + return nil + } + return &types.ActivityLocalDispatchInfo{ + ActivityID: t.ActivityId, + ScheduledTimestamp: timeToUnixNano(t.ScheduledTime), + StartedTimestamp: timeToUnixNano(t.StartedTime), + ScheduledTimestampOfThisAttempt: timeToUnixNano(t.ScheduledTimeOfThisAttempt), + TaskToken: t.TaskToken, + } +} + +func FromActivityTaskCancelRequestedEventAttributes(t *types.ActivityTaskCancelRequestedEventAttributes) *apiv1.ActivityTaskCancelRequestedEventAttributes { + if t == nil { + return nil + } + return &apiv1.ActivityTaskCancelRequestedEventAttributes{ + ActivityId: t.ActivityID, + DecisionTaskCompletedEventId: t.DecisionTaskCompletedEventID, + } +} + +func ToActivityTaskCancelRequestedEventAttributes(t *apiv1.ActivityTaskCancelRequestedEventAttributes) *types.ActivityTaskCancelRequestedEventAttributes { + if t == nil { + return nil + } + return &types.ActivityTaskCancelRequestedEventAttributes{ + ActivityID: t.ActivityId, + DecisionTaskCompletedEventID: t.DecisionTaskCompletedEventId, + } +} + +func FromActivityTaskCanceledEventAttributes(t *types.ActivityTaskCanceledEventAttributes) *apiv1.ActivityTaskCanceledEventAttributes { + if t == nil { + return nil + } + return &apiv1.ActivityTaskCanceledEventAttributes{ + Details: FromPayload(t.Details), + LatestCancelRequestedEventId: t.LatestCancelRequestedEventID, + ScheduledEventId: t.ScheduledEventID, + StartedEventId: t.StartedEventID, + Identity: t.Identity, + } +} + +func ToActivityTaskCanceledEventAttributes(t *apiv1.ActivityTaskCanceledEventAttributes) *types.ActivityTaskCanceledEventAttributes { + if t == nil { + return nil + } + return &types.ActivityTaskCanceledEventAttributes{ + Details: ToPayload(t.Details), + LatestCancelRequestedEventID: t.LatestCancelRequestedEventId, + ScheduledEventID: t.ScheduledEventId, + StartedEventID: t.StartedEventId, + Identity: t.Identity, + } +} + +func FromActivityTaskCompletedEventAttributes(t *types.ActivityTaskCompletedEventAttributes) *apiv1.ActivityTaskCompletedEventAttributes { + if t == nil { + return nil + } + return &apiv1.ActivityTaskCompletedEventAttributes{ + Result: FromPayload(t.Result), + ScheduledEventId: t.ScheduledEventID, + StartedEventId: t.StartedEventID, + Identity: t.Identity, + } +} + +func ToActivityTaskCompletedEventAttributes(t *apiv1.ActivityTaskCompletedEventAttributes) *types.ActivityTaskCompletedEventAttributes { + if t == nil { + return nil + } + return &types.ActivityTaskCompletedEventAttributes{ + Result: ToPayload(t.Result), + ScheduledEventID: t.ScheduledEventId, + StartedEventID: t.StartedEventId, + Identity: t.Identity, + } +} + +func FromActivityTaskFailedEventAttributes(t *types.ActivityTaskFailedEventAttributes) *apiv1.ActivityTaskFailedEventAttributes { + if t == nil { + return nil + } + return &apiv1.ActivityTaskFailedEventAttributes{ + Failure: FromFailure(t.Reason, t.Details), + ScheduledEventId: t.ScheduledEventID, + StartedEventId: t.StartedEventID, + Identity: t.Identity, + } +} + +func ToActivityTaskFailedEventAttributes(t *apiv1.ActivityTaskFailedEventAttributes) *types.ActivityTaskFailedEventAttributes { + if t == nil { + return nil + } + return &types.ActivityTaskFailedEventAttributes{ + Reason: ToFailureReason(t.Failure), + Details: ToFailureDetails(t.Failure), + ScheduledEventID: t.ScheduledEventId, + StartedEventID: t.StartedEventId, + Identity: t.Identity, + } +} + +func FromActivityTaskScheduledEventAttributes(t *types.ActivityTaskScheduledEventAttributes) *apiv1.ActivityTaskScheduledEventAttributes { + if t == nil { + return nil + } + return &apiv1.ActivityTaskScheduledEventAttributes{ + ActivityId: t.ActivityID, + ActivityType: FromActivityType(t.ActivityType), + Domain: t.Domain, + TaskList: FromTaskList(t.TaskList), + Input: FromPayload(t.Input), + ScheduleToCloseTimeout: secondsToDuration(t.ScheduleToCloseTimeoutSeconds), + ScheduleToStartTimeout: secondsToDuration(t.ScheduleToStartTimeoutSeconds), + StartToCloseTimeout: secondsToDuration(t.StartToCloseTimeoutSeconds), + HeartbeatTimeout: secondsToDuration(t.HeartbeatTimeoutSeconds), + DecisionTaskCompletedEventId: t.DecisionTaskCompletedEventID, + RetryPolicy: FromRetryPolicy(t.RetryPolicy), + Header: FromHeader(t.Header), + } +} + +func ToActivityTaskScheduledEventAttributes(t *apiv1.ActivityTaskScheduledEventAttributes) *types.ActivityTaskScheduledEventAttributes { + if t == nil { + return nil + } + return &types.ActivityTaskScheduledEventAttributes{ + ActivityID: t.ActivityId, + ActivityType: ToActivityType(t.ActivityType), + Domain: t.Domain, + TaskList: ToTaskList(t.TaskList), + Input: ToPayload(t.Input), + ScheduleToCloseTimeoutSeconds: durationToSeconds(t.ScheduleToCloseTimeout), + ScheduleToStartTimeoutSeconds: durationToSeconds(t.ScheduleToStartTimeout), + StartToCloseTimeoutSeconds: durationToSeconds(t.StartToCloseTimeout), + HeartbeatTimeoutSeconds: durationToSeconds(t.HeartbeatTimeout), + DecisionTaskCompletedEventID: t.DecisionTaskCompletedEventId, + RetryPolicy: ToRetryPolicy(t.RetryPolicy), + Header: ToHeader(t.Header), + } +} + +func FromActivityTaskStartedEventAttributes(t *types.ActivityTaskStartedEventAttributes) *apiv1.ActivityTaskStartedEventAttributes { + if t == nil { + return nil + } + return &apiv1.ActivityTaskStartedEventAttributes{ + ScheduledEventId: t.ScheduledEventID, + Identity: t.Identity, + RequestId: t.RequestID, + Attempt: t.Attempt, + LastFailure: FromFailure(t.LastFailureReason, t.LastFailureDetails), + } +} + +func ToActivityTaskStartedEventAttributes(t *apiv1.ActivityTaskStartedEventAttributes) *types.ActivityTaskStartedEventAttributes { + if t == nil { + return nil + } + return &types.ActivityTaskStartedEventAttributes{ + ScheduledEventID: t.ScheduledEventId, + Identity: t.Identity, + RequestID: t.RequestId, + Attempt: t.Attempt, + LastFailureReason: ToFailureReason(t.LastFailure), + LastFailureDetails: ToFailureDetails(t.LastFailure), + } +} + +func FromActivityTaskTimedOutEventAttributes(t *types.ActivityTaskTimedOutEventAttributes) *apiv1.ActivityTaskTimedOutEventAttributes { + if t == nil { + return nil + } + return &apiv1.ActivityTaskTimedOutEventAttributes{ + Details: FromPayload(t.Details), + ScheduledEventId: t.ScheduledEventID, + StartedEventId: t.StartedEventID, + TimeoutType: FromTimeoutType(t.TimeoutType), + LastFailure: FromFailure(t.LastFailureReason, t.LastFailureDetails), + } +} + +func ToActivityTaskTimedOutEventAttributes(t *apiv1.ActivityTaskTimedOutEventAttributes) *types.ActivityTaskTimedOutEventAttributes { + if t == nil { + return nil + } + return &types.ActivityTaskTimedOutEventAttributes{ + Details: ToPayload(t.Details), + ScheduledEventID: t.ScheduledEventId, + StartedEventID: t.StartedEventId, + TimeoutType: ToTimeoutType(t.TimeoutType), + LastFailureReason: ToFailureReason(t.LastFailure), + LastFailureDetails: ToFailureDetails(t.LastFailure), + } +} + +func FromActivityType(t *types.ActivityType) *apiv1.ActivityType { + if t == nil { + return nil + } + return &apiv1.ActivityType{ + Name: t.Name, + } +} + +func ToActivityType(t *apiv1.ActivityType) *types.ActivityType { + if t == nil { + return nil + } + return &types.ActivityType{ + Name: t.Name, + } +} + +func FromArchivalStatus(t *types.ArchivalStatus) apiv1.ArchivalStatus { + if t == nil { + return apiv1.ArchivalStatus_ARCHIVAL_STATUS_INVALID + } + switch *t { + case types.ArchivalStatusDisabled: + return apiv1.ArchivalStatus_ARCHIVAL_STATUS_DISABLED + case types.ArchivalStatusEnabled: + return apiv1.ArchivalStatus_ARCHIVAL_STATUS_ENABLED + } + panic("unexpected enum value") +} + +func ToArchivalStatus(t apiv1.ArchivalStatus) *types.ArchivalStatus { + switch t { + case apiv1.ArchivalStatus_ARCHIVAL_STATUS_INVALID: + return nil + case apiv1.ArchivalStatus_ARCHIVAL_STATUS_DISABLED: + return types.ArchivalStatusDisabled.Ptr() + case apiv1.ArchivalStatus_ARCHIVAL_STATUS_ENABLED: + return types.ArchivalStatusEnabled.Ptr() + } + panic("unexpected enum value") +} + +func FromBadBinaries(t *types.BadBinaries) *apiv1.BadBinaries { + if t == nil { + return nil + } + return &apiv1.BadBinaries{ + Binaries: FromBadBinaryInfoMap(t.Binaries), + } +} + +func ToBadBinaries(t *apiv1.BadBinaries) *types.BadBinaries { + if t == nil { + return nil + } + return &types.BadBinaries{ + Binaries: ToBadBinaryInfoMap(t.Binaries), + } +} + +func FromBadBinaryInfo(t *types.BadBinaryInfo) *apiv1.BadBinaryInfo { + if t == nil { + return nil + } + return &apiv1.BadBinaryInfo{ + Reason: t.Reason, + Operator: t.Operator, + CreatedTime: unixNanoToTime(t.CreatedTimeNano), + } +} + +func ToBadBinaryInfo(t *apiv1.BadBinaryInfo) *types.BadBinaryInfo { + if t == nil { + return nil + } + return &types.BadBinaryInfo{ + Reason: t.Reason, + Operator: t.Operator, + CreatedTimeNano: timeToUnixNano(t.CreatedTime), + } +} + +func FromCancelExternalWorkflowExecutionFailedCause(t *types.CancelExternalWorkflowExecutionFailedCause) apiv1.CancelExternalWorkflowExecutionFailedCause { + if t == nil { + return apiv1.CancelExternalWorkflowExecutionFailedCause_CANCEL_EXTERNAL_WORKFLOW_EXECUTION_FAILED_CAUSE_INVALID + } + switch *t { + case types.CancelExternalWorkflowExecutionFailedCauseUnknownExternalWorkflowExecution: + return apiv1.CancelExternalWorkflowExecutionFailedCause_CANCEL_EXTERNAL_WORKFLOW_EXECUTION_FAILED_CAUSE_UNKNOWN_EXTERNAL_WORKFLOW_EXECUTION + } + panic("unexpected enum value") +} + +func ToCancelExternalWorkflowExecutionFailedCause(t apiv1.CancelExternalWorkflowExecutionFailedCause) *types.CancelExternalWorkflowExecutionFailedCause { + switch t { + case apiv1.CancelExternalWorkflowExecutionFailedCause_CANCEL_EXTERNAL_WORKFLOW_EXECUTION_FAILED_CAUSE_INVALID: + return nil + case apiv1.CancelExternalWorkflowExecutionFailedCause_CANCEL_EXTERNAL_WORKFLOW_EXECUTION_FAILED_CAUSE_UNKNOWN_EXTERNAL_WORKFLOW_EXECUTION: + return types.CancelExternalWorkflowExecutionFailedCauseUnknownExternalWorkflowExecution.Ptr() + } + panic("unexpected enum value") +} + +func FromCancelTimerDecisionAttributes(t *types.CancelTimerDecisionAttributes) *apiv1.CancelTimerDecisionAttributes { + if t == nil { + return nil + } + return &apiv1.CancelTimerDecisionAttributes{ + TimerId: t.TimerID, + } +} + +func ToCancelTimerDecisionAttributes(t *apiv1.CancelTimerDecisionAttributes) *types.CancelTimerDecisionAttributes { + if t == nil { + return nil + } + return &types.CancelTimerDecisionAttributes{ + TimerID: t.TimerId, + } +} + +func FromCancelTimerFailedEventAttributes(t *types.CancelTimerFailedEventAttributes) *apiv1.CancelTimerFailedEventAttributes { + if t == nil { + return nil + } + return &apiv1.CancelTimerFailedEventAttributes{ + TimerId: t.TimerID, + Cause: t.Cause, + DecisionTaskCompletedEventId: t.DecisionTaskCompletedEventID, + Identity: t.Identity, + } +} + +func ToCancelTimerFailedEventAttributes(t *apiv1.CancelTimerFailedEventAttributes) *types.CancelTimerFailedEventAttributes { + if t == nil { + return nil + } + return &types.CancelTimerFailedEventAttributes{ + TimerID: t.TimerId, + Cause: t.Cause, + DecisionTaskCompletedEventID: t.DecisionTaskCompletedEventId, + Identity: t.Identity, + } +} + +func FromCancelWorkflowExecutionDecisionAttributes(t *types.CancelWorkflowExecutionDecisionAttributes) *apiv1.CancelWorkflowExecutionDecisionAttributes { + if t == nil { + return nil + } + return &apiv1.CancelWorkflowExecutionDecisionAttributes{ + Details: FromPayload(t.Details), + } +} + +func ToCancelWorkflowExecutionDecisionAttributes(t *apiv1.CancelWorkflowExecutionDecisionAttributes) *types.CancelWorkflowExecutionDecisionAttributes { + if t == nil { + return nil + } + return &types.CancelWorkflowExecutionDecisionAttributes{ + Details: ToPayload(t.Details), + } +} + +func FromChildWorkflowExecutionCanceledEventAttributes(t *types.ChildWorkflowExecutionCanceledEventAttributes) *apiv1.ChildWorkflowExecutionCanceledEventAttributes { + if t == nil { + return nil + } + return &apiv1.ChildWorkflowExecutionCanceledEventAttributes{ + Domain: t.Domain, + WorkflowExecution: FromWorkflowExecution(t.WorkflowExecution), + WorkflowType: FromWorkflowType(t.WorkflowType), + InitiatedEventId: t.InitiatedEventID, + StartedEventId: t.StartedEventID, + Details: FromPayload(t.Details), + } +} + +func ToChildWorkflowExecutionCanceledEventAttributes(t *apiv1.ChildWorkflowExecutionCanceledEventAttributes) *types.ChildWorkflowExecutionCanceledEventAttributes { + if t == nil { + return nil + } + return &types.ChildWorkflowExecutionCanceledEventAttributes{ + Domain: t.Domain, + WorkflowExecution: ToWorkflowExecution(t.WorkflowExecution), + WorkflowType: ToWorkflowType(t.WorkflowType), + InitiatedEventID: t.InitiatedEventId, + StartedEventID: t.StartedEventId, + Details: ToPayload(t.Details), + } +} + +func FromChildWorkflowExecutionCompletedEventAttributes(t *types.ChildWorkflowExecutionCompletedEventAttributes) *apiv1.ChildWorkflowExecutionCompletedEventAttributes { + if t == nil { + return nil + } + return &apiv1.ChildWorkflowExecutionCompletedEventAttributes{ + Domain: t.Domain, + WorkflowExecution: FromWorkflowExecution(t.WorkflowExecution), + WorkflowType: FromWorkflowType(t.WorkflowType), + InitiatedEventId: t.InitiatedEventID, + StartedEventId: t.StartedEventID, + Result: FromPayload(t.Result), + } +} + +func ToChildWorkflowExecutionCompletedEventAttributes(t *apiv1.ChildWorkflowExecutionCompletedEventAttributes) *types.ChildWorkflowExecutionCompletedEventAttributes { + if t == nil { + return nil + } + return &types.ChildWorkflowExecutionCompletedEventAttributes{ + Domain: t.Domain, + WorkflowExecution: ToWorkflowExecution(t.WorkflowExecution), + WorkflowType: ToWorkflowType(t.WorkflowType), + InitiatedEventID: t.InitiatedEventId, + StartedEventID: t.StartedEventId, + Result: ToPayload(t.Result), + } +} + +func FromChildWorkflowExecutionFailedCause(t *types.ChildWorkflowExecutionFailedCause) apiv1.ChildWorkflowExecutionFailedCause { + if t == nil { + return apiv1.ChildWorkflowExecutionFailedCause_CHILD_WORKFLOW_EXECUTION_FAILED_CAUSE_INVALID + } + switch *t { + case types.ChildWorkflowExecutionFailedCauseWorkflowAlreadyRunning: + return apiv1.ChildWorkflowExecutionFailedCause_CHILD_WORKFLOW_EXECUTION_FAILED_CAUSE_WORKFLOW_ALREADY_RUNNING + } + panic("unexpected enum value") +} + +func ToChildWorkflowExecutionFailedCause(t apiv1.ChildWorkflowExecutionFailedCause) *types.ChildWorkflowExecutionFailedCause { + switch t { + case apiv1.ChildWorkflowExecutionFailedCause_CHILD_WORKFLOW_EXECUTION_FAILED_CAUSE_INVALID: + return nil + case apiv1.ChildWorkflowExecutionFailedCause_CHILD_WORKFLOW_EXECUTION_FAILED_CAUSE_WORKFLOW_ALREADY_RUNNING: + return types.ChildWorkflowExecutionFailedCauseWorkflowAlreadyRunning.Ptr() + } + panic("unexpected enum value") +} + +func FromChildWorkflowExecutionFailedEventAttributes(t *types.ChildWorkflowExecutionFailedEventAttributes) *apiv1.ChildWorkflowExecutionFailedEventAttributes { + if t == nil { + return nil + } + return &apiv1.ChildWorkflowExecutionFailedEventAttributes{ + Domain: t.Domain, + WorkflowExecution: FromWorkflowExecution(t.WorkflowExecution), + WorkflowType: FromWorkflowType(t.WorkflowType), + InitiatedEventId: t.InitiatedEventID, + StartedEventId: t.StartedEventID, + Failure: FromFailure(t.Reason, t.Details), + } +} + +func ToChildWorkflowExecutionFailedEventAttributes(t *apiv1.ChildWorkflowExecutionFailedEventAttributes) *types.ChildWorkflowExecutionFailedEventAttributes { + if t == nil { + return nil + } + return &types.ChildWorkflowExecutionFailedEventAttributes{ + Domain: t.Domain, + WorkflowExecution: ToWorkflowExecution(t.WorkflowExecution), + WorkflowType: ToWorkflowType(t.WorkflowType), + InitiatedEventID: t.InitiatedEventId, + StartedEventID: t.StartedEventId, + Reason: ToFailureReason(t.Failure), + Details: ToFailureDetails(t.Failure), + } +} + +func FromChildWorkflowExecutionStartedEventAttributes(t *types.ChildWorkflowExecutionStartedEventAttributes) *apiv1.ChildWorkflowExecutionStartedEventAttributes { + if t == nil { + return nil + } + return &apiv1.ChildWorkflowExecutionStartedEventAttributes{ + Domain: t.Domain, + WorkflowExecution: FromWorkflowExecution(t.WorkflowExecution), + WorkflowType: FromWorkflowType(t.WorkflowType), + InitiatedEventId: t.InitiatedEventID, + Header: FromHeader(t.Header), + } +} + +func ToChildWorkflowExecutionStartedEventAttributes(t *apiv1.ChildWorkflowExecutionStartedEventAttributes) *types.ChildWorkflowExecutionStartedEventAttributes { + if t == nil { + return nil + } + return &types.ChildWorkflowExecutionStartedEventAttributes{ + Domain: t.Domain, + WorkflowExecution: ToWorkflowExecution(t.WorkflowExecution), + WorkflowType: ToWorkflowType(t.WorkflowType), + InitiatedEventID: t.InitiatedEventId, + Header: ToHeader(t.Header), + } +} + +func FromChildWorkflowExecutionTerminatedEventAttributes(t *types.ChildWorkflowExecutionTerminatedEventAttributes) *apiv1.ChildWorkflowExecutionTerminatedEventAttributes { + if t == nil { + return nil + } + return &apiv1.ChildWorkflowExecutionTerminatedEventAttributes{ + Domain: t.Domain, + WorkflowExecution: FromWorkflowExecution(t.WorkflowExecution), + WorkflowType: FromWorkflowType(t.WorkflowType), + InitiatedEventId: t.InitiatedEventID, + StartedEventId: t.StartedEventID, + } +} + +func ToChildWorkflowExecutionTerminatedEventAttributes(t *apiv1.ChildWorkflowExecutionTerminatedEventAttributes) *types.ChildWorkflowExecutionTerminatedEventAttributes { + if t == nil { + return nil + } + return &types.ChildWorkflowExecutionTerminatedEventAttributes{ + Domain: t.Domain, + WorkflowExecution: ToWorkflowExecution(t.WorkflowExecution), + WorkflowType: ToWorkflowType(t.WorkflowType), + InitiatedEventID: t.InitiatedEventId, + StartedEventID: t.StartedEventId, + } +} + +func FromChildWorkflowExecutionTimedOutEventAttributes(t *types.ChildWorkflowExecutionTimedOutEventAttributes) *apiv1.ChildWorkflowExecutionTimedOutEventAttributes { + if t == nil { + return nil + } + return &apiv1.ChildWorkflowExecutionTimedOutEventAttributes{ + Domain: t.Domain, + WorkflowExecution: FromWorkflowExecution(t.WorkflowExecution), + WorkflowType: FromWorkflowType(t.WorkflowType), + InitiatedEventId: t.InitiatedEventID, + StartedEventId: t.StartedEventID, + TimeoutType: FromTimeoutType(t.TimeoutType), + } +} + +func ToChildWorkflowExecutionTimedOutEventAttributes(t *apiv1.ChildWorkflowExecutionTimedOutEventAttributes) *types.ChildWorkflowExecutionTimedOutEventAttributes { + if t == nil { + return nil + } + return &types.ChildWorkflowExecutionTimedOutEventAttributes{ + Domain: t.Domain, + WorkflowExecution: ToWorkflowExecution(t.WorkflowExecution), + WorkflowType: ToWorkflowType(t.WorkflowType), + InitiatedEventID: t.InitiatedEventId, + StartedEventID: t.StartedEventId, + TimeoutType: ToTimeoutType(t.TimeoutType), + } +} + +func FromClusterReplicationConfiguration(t *types.ClusterReplicationConfiguration) *apiv1.ClusterReplicationConfiguration { + if t == nil { + return nil + } + return &apiv1.ClusterReplicationConfiguration{ + ClusterName: t.ClusterName, + } +} + +func ToClusterReplicationConfiguration(t *apiv1.ClusterReplicationConfiguration) *types.ClusterReplicationConfiguration { + if t == nil { + return nil + } + return &types.ClusterReplicationConfiguration{ + ClusterName: t.ClusterName, + } +} + +func FromCompleteWorkflowExecutionDecisionAttributes(t *types.CompleteWorkflowExecutionDecisionAttributes) *apiv1.CompleteWorkflowExecutionDecisionAttributes { + if t == nil { + return nil + } + return &apiv1.CompleteWorkflowExecutionDecisionAttributes{ + Result: FromPayload(t.Result), + } +} + +func ToCompleteWorkflowExecutionDecisionAttributes(t *apiv1.CompleteWorkflowExecutionDecisionAttributes) *types.CompleteWorkflowExecutionDecisionAttributes { + if t == nil { + return nil + } + return &types.CompleteWorkflowExecutionDecisionAttributes{ + Result: ToPayload(t.Result), + } +} + +func FromContinueAsNewInitiator(t *types.ContinueAsNewInitiator) apiv1.ContinueAsNewInitiator { + if t == nil { + return apiv1.ContinueAsNewInitiator_CONTINUE_AS_NEW_INITIATOR_INVALID + } + switch *t { + case types.ContinueAsNewInitiatorDecider: + return apiv1.ContinueAsNewInitiator_CONTINUE_AS_NEW_INITIATOR_DECIDER + case types.ContinueAsNewInitiatorRetryPolicy: + return apiv1.ContinueAsNewInitiator_CONTINUE_AS_NEW_INITIATOR_RETRY_POLICY + case types.ContinueAsNewInitiatorCronSchedule: + return apiv1.ContinueAsNewInitiator_CONTINUE_AS_NEW_INITIATOR_CRON_SCHEDULE + } + panic("unexpected enum value") +} + +func ToContinueAsNewInitiator(t apiv1.ContinueAsNewInitiator) *types.ContinueAsNewInitiator { + switch t { + case apiv1.ContinueAsNewInitiator_CONTINUE_AS_NEW_INITIATOR_INVALID: + return nil + case apiv1.ContinueAsNewInitiator_CONTINUE_AS_NEW_INITIATOR_DECIDER: + return types.ContinueAsNewInitiatorDecider.Ptr() + case apiv1.ContinueAsNewInitiator_CONTINUE_AS_NEW_INITIATOR_RETRY_POLICY: + return types.ContinueAsNewInitiatorRetryPolicy.Ptr() + case apiv1.ContinueAsNewInitiator_CONTINUE_AS_NEW_INITIATOR_CRON_SCHEDULE: + return types.ContinueAsNewInitiatorCronSchedule.Ptr() + } + panic("unexpected enum value") +} + +func FromContinueAsNewWorkflowExecutionDecisionAttributes(t *types.ContinueAsNewWorkflowExecutionDecisionAttributes) *apiv1.ContinueAsNewWorkflowExecutionDecisionAttributes { + if t == nil { + return nil + } + return &apiv1.ContinueAsNewWorkflowExecutionDecisionAttributes{ + WorkflowType: FromWorkflowType(t.WorkflowType), + TaskList: FromTaskList(t.TaskList), + Input: FromPayload(t.Input), + ExecutionStartToCloseTimeout: secondsToDuration(t.ExecutionStartToCloseTimeoutSeconds), + TaskStartToCloseTimeout: secondsToDuration(t.TaskStartToCloseTimeoutSeconds), + BackoffStartInterval: secondsToDuration(t.BackoffStartIntervalInSeconds), + RetryPolicy: FromRetryPolicy(t.RetryPolicy), + Initiator: FromContinueAsNewInitiator(t.Initiator), + Failure: FromFailure(t.FailureReason, t.FailureDetails), + LastCompletionResult: FromPayload(t.LastCompletionResult), + CronSchedule: t.CronSchedule, + Header: FromHeader(t.Header), + Memo: FromMemo(t.Memo), + SearchAttributes: FromSearchAttributes(t.SearchAttributes), + } +} + +func ToContinueAsNewWorkflowExecutionDecisionAttributes(t *apiv1.ContinueAsNewWorkflowExecutionDecisionAttributes) *types.ContinueAsNewWorkflowExecutionDecisionAttributes { + if t == nil { + return nil + } + return &types.ContinueAsNewWorkflowExecutionDecisionAttributes{ + WorkflowType: ToWorkflowType(t.WorkflowType), + TaskList: ToTaskList(t.TaskList), + Input: ToPayload(t.Input), + ExecutionStartToCloseTimeoutSeconds: durationToSeconds(t.ExecutionStartToCloseTimeout), + TaskStartToCloseTimeoutSeconds: durationToSeconds(t.TaskStartToCloseTimeout), + BackoffStartIntervalInSeconds: durationToSeconds(t.BackoffStartInterval), + RetryPolicy: ToRetryPolicy(t.RetryPolicy), + Initiator: ToContinueAsNewInitiator(t.Initiator), + FailureReason: ToFailureReason(t.Failure), + FailureDetails: ToFailureDetails(t.Failure), + LastCompletionResult: ToPayload(t.LastCompletionResult), + CronSchedule: t.CronSchedule, + Header: ToHeader(t.Header), + Memo: ToMemo(t.Memo), + SearchAttributes: ToSearchAttributes(t.SearchAttributes), + } +} + +func FromCountWorkflowExecutionsRequest(t *types.CountWorkflowExecutionsRequest) *apiv1.CountWorkflowExecutionsRequest { + if t == nil { + return nil + } + return &apiv1.CountWorkflowExecutionsRequest{ + Domain: t.Domain, + Query: t.Query, + } +} + +func ToCountWorkflowExecutionsRequest(t *apiv1.CountWorkflowExecutionsRequest) *types.CountWorkflowExecutionsRequest { + if t == nil { + return nil + } + return &types.CountWorkflowExecutionsRequest{ + Domain: t.Domain, + Query: t.Query, + } +} + +func FromCountWorkflowExecutionsResponse(t *types.CountWorkflowExecutionsResponse) *apiv1.CountWorkflowExecutionsResponse { + if t == nil { + return nil + } + return &apiv1.CountWorkflowExecutionsResponse{ + Count: t.Count, + } +} + +func ToCountWorkflowExecutionsResponse(t *apiv1.CountWorkflowExecutionsResponse) *types.CountWorkflowExecutionsResponse { + if t == nil { + return nil + } + return &types.CountWorkflowExecutionsResponse{ + Count: t.Count, + } +} + +func FromDataBlob(t *types.DataBlob) *apiv1.DataBlob { + if t == nil { + return nil + } + return &apiv1.DataBlob{ + EncodingType: FromEncodingType(t.EncodingType), + Data: t.Data, + } +} + +func ToDataBlob(t *apiv1.DataBlob) *types.DataBlob { + if t == nil { + return nil + } + return &types.DataBlob{ + EncodingType: ToEncodingType(t.EncodingType), + Data: t.Data, + } +} + +func FromDecisionTaskCompletedEventAttributes(t *types.DecisionTaskCompletedEventAttributes) *apiv1.DecisionTaskCompletedEventAttributes { + if t == nil { + return nil + } + return &apiv1.DecisionTaskCompletedEventAttributes{ + ScheduledEventId: t.ScheduledEventID, + StartedEventId: t.StartedEventID, + Identity: t.Identity, + BinaryChecksum: t.BinaryChecksum, + ExecutionContext: t.ExecutionContext, + } +} + +func ToDecisionTaskCompletedEventAttributes(t *apiv1.DecisionTaskCompletedEventAttributes) *types.DecisionTaskCompletedEventAttributes { + if t == nil { + return nil + } + return &types.DecisionTaskCompletedEventAttributes{ + ScheduledEventID: t.ScheduledEventId, + StartedEventID: t.StartedEventId, + Identity: t.Identity, + BinaryChecksum: t.BinaryChecksum, + ExecutionContext: t.ExecutionContext, + } +} + +func FromDecisionTaskFailedCause(t *types.DecisionTaskFailedCause) apiv1.DecisionTaskFailedCause { + if t == nil { + return apiv1.DecisionTaskFailedCause_DECISION_TASK_FAILED_CAUSE_INVALID + } + switch *t { + case types.DecisionTaskFailedCauseUnhandledDecision: + return apiv1.DecisionTaskFailedCause_DECISION_TASK_FAILED_CAUSE_UNHANDLED_DECISION + case types.DecisionTaskFailedCauseBadScheduleActivityAttributes: + return apiv1.DecisionTaskFailedCause_DECISION_TASK_FAILED_CAUSE_BAD_SCHEDULE_ACTIVITY_ATTRIBUTES + case types.DecisionTaskFailedCauseBadRequestCancelActivityAttributes: + return apiv1.DecisionTaskFailedCause_DECISION_TASK_FAILED_CAUSE_BAD_REQUEST_CANCEL_ACTIVITY_ATTRIBUTES + case types.DecisionTaskFailedCauseBadStartTimerAttributes: + return apiv1.DecisionTaskFailedCause_DECISION_TASK_FAILED_CAUSE_BAD_START_TIMER_ATTRIBUTES + case types.DecisionTaskFailedCauseBadCancelTimerAttributes: + return apiv1.DecisionTaskFailedCause_DECISION_TASK_FAILED_CAUSE_BAD_CANCEL_TIMER_ATTRIBUTES + case types.DecisionTaskFailedCauseBadRecordMarkerAttributes: + return apiv1.DecisionTaskFailedCause_DECISION_TASK_FAILED_CAUSE_BAD_RECORD_MARKER_ATTRIBUTES + case types.DecisionTaskFailedCauseBadCompleteWorkflowExecutionAttributes: + return apiv1.DecisionTaskFailedCause_DECISION_TASK_FAILED_CAUSE_BAD_COMPLETE_WORKFLOW_EXECUTION_ATTRIBUTES + case types.DecisionTaskFailedCauseBadFailWorkflowExecutionAttributes: + return apiv1.DecisionTaskFailedCause_DECISION_TASK_FAILED_CAUSE_BAD_FAIL_WORKFLOW_EXECUTION_ATTRIBUTES + case types.DecisionTaskFailedCauseBadCancelWorkflowExecutionAttributes: + return apiv1.DecisionTaskFailedCause_DECISION_TASK_FAILED_CAUSE_BAD_CANCEL_WORKFLOW_EXECUTION_ATTRIBUTES + case types.DecisionTaskFailedCauseBadRequestCancelExternalWorkflowExecutionAttributes: + return apiv1.DecisionTaskFailedCause_DECISION_TASK_FAILED_CAUSE_BAD_REQUEST_CANCEL_EXTERNAL_WORKFLOW_EXECUTION_ATTRIBUTES + case types.DecisionTaskFailedCauseBadContinueAsNewAttributes: + return apiv1.DecisionTaskFailedCause_DECISION_TASK_FAILED_CAUSE_BAD_CONTINUE_AS_NEW_ATTRIBUTES + case types.DecisionTaskFailedCauseStartTimerDuplicateID: + return apiv1.DecisionTaskFailedCause_DECISION_TASK_FAILED_CAUSE_START_TIMER_DUPLICATE_ID + case types.DecisionTaskFailedCauseResetStickyTasklist: + return apiv1.DecisionTaskFailedCause_DECISION_TASK_FAILED_CAUSE_RESET_STICKY_TASK_LIST + case types.DecisionTaskFailedCauseWorkflowWorkerUnhandledFailure: + return apiv1.DecisionTaskFailedCause_DECISION_TASK_FAILED_CAUSE_WORKFLOW_WORKER_UNHANDLED_FAILURE + case types.DecisionTaskFailedCauseBadSignalWorkflowExecutionAttributes: + return apiv1.DecisionTaskFailedCause_DECISION_TASK_FAILED_CAUSE_BAD_SIGNAL_WORKFLOW_EXECUTION_ATTRIBUTES + case types.DecisionTaskFailedCauseBadStartChildExecutionAttributes: + return apiv1.DecisionTaskFailedCause_DECISION_TASK_FAILED_CAUSE_BAD_START_CHILD_EXECUTION_ATTRIBUTES + case types.DecisionTaskFailedCauseForceCloseDecision: + return apiv1.DecisionTaskFailedCause_DECISION_TASK_FAILED_CAUSE_FORCE_CLOSE_DECISION + case types.DecisionTaskFailedCauseFailoverCloseDecision: + return apiv1.DecisionTaskFailedCause_DECISION_TASK_FAILED_CAUSE_FAILOVER_CLOSE_DECISION + case types.DecisionTaskFailedCauseBadSignalInputSize: + return apiv1.DecisionTaskFailedCause_DECISION_TASK_FAILED_CAUSE_BAD_SIGNAL_INPUT_SIZE + case types.DecisionTaskFailedCauseResetWorkflow: + return apiv1.DecisionTaskFailedCause_DECISION_TASK_FAILED_CAUSE_RESET_WORKFLOW + case types.DecisionTaskFailedCauseBadBinary: + return apiv1.DecisionTaskFailedCause_DECISION_TASK_FAILED_CAUSE_BAD_BINARY + case types.DecisionTaskFailedCauseScheduleActivityDuplicateID: + return apiv1.DecisionTaskFailedCause_DECISION_TASK_FAILED_CAUSE_SCHEDULE_ACTIVITY_DUPLICATE_ID + case types.DecisionTaskFailedCauseBadSearchAttributes: + return apiv1.DecisionTaskFailedCause_DECISION_TASK_FAILED_CAUSE_BAD_SEARCH_ATTRIBUTES + } + panic("unexpected enum value") +} + +func ToDecisionTaskFailedCause(t apiv1.DecisionTaskFailedCause) *types.DecisionTaskFailedCause { + switch t { + case apiv1.DecisionTaskFailedCause_DECISION_TASK_FAILED_CAUSE_INVALID: + return nil + case apiv1.DecisionTaskFailedCause_DECISION_TASK_FAILED_CAUSE_UNHANDLED_DECISION: + return types.DecisionTaskFailedCauseUnhandledDecision.Ptr() + case apiv1.DecisionTaskFailedCause_DECISION_TASK_FAILED_CAUSE_BAD_SCHEDULE_ACTIVITY_ATTRIBUTES: + return types.DecisionTaskFailedCauseBadScheduleActivityAttributes.Ptr() + case apiv1.DecisionTaskFailedCause_DECISION_TASK_FAILED_CAUSE_BAD_REQUEST_CANCEL_ACTIVITY_ATTRIBUTES: + return types.DecisionTaskFailedCauseBadRequestCancelActivityAttributes.Ptr() + case apiv1.DecisionTaskFailedCause_DECISION_TASK_FAILED_CAUSE_BAD_START_TIMER_ATTRIBUTES: + return types.DecisionTaskFailedCauseBadStartTimerAttributes.Ptr() + case apiv1.DecisionTaskFailedCause_DECISION_TASK_FAILED_CAUSE_BAD_CANCEL_TIMER_ATTRIBUTES: + return types.DecisionTaskFailedCauseBadCancelTimerAttributes.Ptr() + case apiv1.DecisionTaskFailedCause_DECISION_TASK_FAILED_CAUSE_BAD_RECORD_MARKER_ATTRIBUTES: + return types.DecisionTaskFailedCauseBadRecordMarkerAttributes.Ptr() + case apiv1.DecisionTaskFailedCause_DECISION_TASK_FAILED_CAUSE_BAD_COMPLETE_WORKFLOW_EXECUTION_ATTRIBUTES: + return types.DecisionTaskFailedCauseBadCompleteWorkflowExecutionAttributes.Ptr() + case apiv1.DecisionTaskFailedCause_DECISION_TASK_FAILED_CAUSE_BAD_FAIL_WORKFLOW_EXECUTION_ATTRIBUTES: + return types.DecisionTaskFailedCauseBadFailWorkflowExecutionAttributes.Ptr() + case apiv1.DecisionTaskFailedCause_DECISION_TASK_FAILED_CAUSE_BAD_CANCEL_WORKFLOW_EXECUTION_ATTRIBUTES: + return types.DecisionTaskFailedCauseBadCancelWorkflowExecutionAttributes.Ptr() + case apiv1.DecisionTaskFailedCause_DECISION_TASK_FAILED_CAUSE_BAD_REQUEST_CANCEL_EXTERNAL_WORKFLOW_EXECUTION_ATTRIBUTES: + return types.DecisionTaskFailedCauseBadRequestCancelExternalWorkflowExecutionAttributes.Ptr() + case apiv1.DecisionTaskFailedCause_DECISION_TASK_FAILED_CAUSE_BAD_CONTINUE_AS_NEW_ATTRIBUTES: + return types.DecisionTaskFailedCauseBadContinueAsNewAttributes.Ptr() + case apiv1.DecisionTaskFailedCause_DECISION_TASK_FAILED_CAUSE_START_TIMER_DUPLICATE_ID: + return types.DecisionTaskFailedCauseStartTimerDuplicateID.Ptr() + case apiv1.DecisionTaskFailedCause_DECISION_TASK_FAILED_CAUSE_RESET_STICKY_TASK_LIST: + return types.DecisionTaskFailedCauseResetStickyTasklist.Ptr() + case apiv1.DecisionTaskFailedCause_DECISION_TASK_FAILED_CAUSE_WORKFLOW_WORKER_UNHANDLED_FAILURE: + return types.DecisionTaskFailedCauseWorkflowWorkerUnhandledFailure.Ptr() + case apiv1.DecisionTaskFailedCause_DECISION_TASK_FAILED_CAUSE_BAD_SIGNAL_WORKFLOW_EXECUTION_ATTRIBUTES: + return types.DecisionTaskFailedCauseBadSignalWorkflowExecutionAttributes.Ptr() + case apiv1.DecisionTaskFailedCause_DECISION_TASK_FAILED_CAUSE_BAD_START_CHILD_EXECUTION_ATTRIBUTES: + return types.DecisionTaskFailedCauseBadStartChildExecutionAttributes.Ptr() + case apiv1.DecisionTaskFailedCause_DECISION_TASK_FAILED_CAUSE_FORCE_CLOSE_DECISION: + return types.DecisionTaskFailedCauseForceCloseDecision.Ptr() + case apiv1.DecisionTaskFailedCause_DECISION_TASK_FAILED_CAUSE_FAILOVER_CLOSE_DECISION: + return types.DecisionTaskFailedCauseFailoverCloseDecision.Ptr() + case apiv1.DecisionTaskFailedCause_DECISION_TASK_FAILED_CAUSE_BAD_SIGNAL_INPUT_SIZE: + return types.DecisionTaskFailedCauseBadSignalInputSize.Ptr() + case apiv1.DecisionTaskFailedCause_DECISION_TASK_FAILED_CAUSE_RESET_WORKFLOW: + return types.DecisionTaskFailedCauseResetWorkflow.Ptr() + case apiv1.DecisionTaskFailedCause_DECISION_TASK_FAILED_CAUSE_BAD_BINARY: + return types.DecisionTaskFailedCauseBadBinary.Ptr() + case apiv1.DecisionTaskFailedCause_DECISION_TASK_FAILED_CAUSE_SCHEDULE_ACTIVITY_DUPLICATE_ID: + return types.DecisionTaskFailedCauseScheduleActivityDuplicateID.Ptr() + case apiv1.DecisionTaskFailedCause_DECISION_TASK_FAILED_CAUSE_BAD_SEARCH_ATTRIBUTES: + return types.DecisionTaskFailedCauseBadSearchAttributes.Ptr() + } + panic("unexpected enum value") +} + +func FromDecisionTaskFailedEventAttributes(t *types.DecisionTaskFailedEventAttributes) *apiv1.DecisionTaskFailedEventAttributes { + if t == nil { + return nil + } + return &apiv1.DecisionTaskFailedEventAttributes{ + ScheduledEventId: t.ScheduledEventID, + StartedEventId: t.StartedEventID, + Cause: FromDecisionTaskFailedCause(t.Cause), + Failure: FromFailure(t.Reason, t.Details), + Identity: t.Identity, + BaseRunId: t.BaseRunID, + NewRunId: t.NewRunID, + ForkEventVersion: t.ForkEventVersion, + BinaryChecksum: t.BinaryChecksum, + } +} + +func ToDecisionTaskFailedEventAttributes(t *apiv1.DecisionTaskFailedEventAttributes) *types.DecisionTaskFailedEventAttributes { + if t == nil { + return nil + } + return &types.DecisionTaskFailedEventAttributes{ + ScheduledEventID: t.ScheduledEventId, + StartedEventID: t.StartedEventId, + Cause: ToDecisionTaskFailedCause(t.Cause), + Reason: ToFailureReason(t.Failure), + Details: ToFailureDetails(t.Failure), + Identity: t.Identity, + BaseRunID: t.BaseRunId, + NewRunID: t.NewRunId, + ForkEventVersion: t.ForkEventVersion, + BinaryChecksum: t.BinaryChecksum, + } +} + +func FromDecisionTaskScheduledEventAttributes(t *types.DecisionTaskScheduledEventAttributes) *apiv1.DecisionTaskScheduledEventAttributes { + if t == nil { + return nil + } + return &apiv1.DecisionTaskScheduledEventAttributes{ + TaskList: FromTaskList(t.TaskList), + StartToCloseTimeout: secondsToDuration(t.StartToCloseTimeoutSeconds), + Attempt: int32(t.Attempt), + } +} + +func ToDecisionTaskScheduledEventAttributes(t *apiv1.DecisionTaskScheduledEventAttributes) *types.DecisionTaskScheduledEventAttributes { + if t == nil { + return nil + } + return &types.DecisionTaskScheduledEventAttributes{ + TaskList: ToTaskList(t.TaskList), + StartToCloseTimeoutSeconds: durationToSeconds(t.StartToCloseTimeout), + Attempt: int64(t.Attempt), + } +} + +func FromDecisionTaskStartedEventAttributes(t *types.DecisionTaskStartedEventAttributes) *apiv1.DecisionTaskStartedEventAttributes { + if t == nil { + return nil + } + return &apiv1.DecisionTaskStartedEventAttributes{ + ScheduledEventId: t.ScheduledEventID, + Identity: t.Identity, + RequestId: t.RequestID, + } +} + +func ToDecisionTaskStartedEventAttributes(t *apiv1.DecisionTaskStartedEventAttributes) *types.DecisionTaskStartedEventAttributes { + if t == nil { + return nil + } + return &types.DecisionTaskStartedEventAttributes{ + ScheduledEventID: t.ScheduledEventId, + Identity: t.Identity, + RequestID: t.RequestId, + } +} + +func FromDecisionTaskTimedOutEventAttributes(t *types.DecisionTaskTimedOutEventAttributes) *apiv1.DecisionTaskTimedOutEventAttributes { + if t == nil { + return nil + } + return &apiv1.DecisionTaskTimedOutEventAttributes{ + ScheduledEventId: t.ScheduledEventID, + StartedEventId: t.StartedEventID, + TimeoutType: FromTimeoutType(t.TimeoutType), + BaseRunId: t.BaseRunID, + NewRunId: t.NewRunID, + ForkEventVersion: t.ForkEventVersion, + Reason: t.Reason, + Cause: FromDecisionTaskTimedOutCause(t.Cause), + } +} + +func ToDecisionTaskTimedOutEventAttributes(t *apiv1.DecisionTaskTimedOutEventAttributes) *types.DecisionTaskTimedOutEventAttributes { + if t == nil { + return nil + } + return &types.DecisionTaskTimedOutEventAttributes{ + ScheduledEventID: t.ScheduledEventId, + StartedEventID: t.StartedEventId, + TimeoutType: ToTimeoutType(t.TimeoutType), + BaseRunID: t.BaseRunId, + NewRunID: t.NewRunId, + ForkEventVersion: t.ForkEventVersion, + Reason: t.Reason, + Cause: ToDecisionTaskTimedOutCause(t.Cause), + } +} + +func FromDeprecateDomainRequest(t *types.DeprecateDomainRequest) *apiv1.DeprecateDomainRequest { + if t == nil { + return nil + } + return &apiv1.DeprecateDomainRequest{ + Name: t.Name, + SecurityToken: t.SecurityToken, + } +} + +func ToDeprecateDomainRequest(t *apiv1.DeprecateDomainRequest) *types.DeprecateDomainRequest { + if t == nil { + return nil + } + return &types.DeprecateDomainRequest{ + Name: t.Name, + SecurityToken: t.SecurityToken, + } +} + +func FromDescribeDomainRequest(t *types.DescribeDomainRequest) *apiv1.DescribeDomainRequest { + if t == nil { + return nil + } + if t.UUID != nil { + return &apiv1.DescribeDomainRequest{DescribeBy: &apiv1.DescribeDomainRequest_Id{Id: *t.UUID}} + } + if t.Name != nil { + return &apiv1.DescribeDomainRequest{DescribeBy: &apiv1.DescribeDomainRequest_Name{Name: *t.Name}} + } + panic("neither oneof field is set for DescribeDomainRequest") +} + +func ToDescribeDomainRequest(t *apiv1.DescribeDomainRequest) *types.DescribeDomainRequest { + if t == nil { + return nil + } + switch describeBy := t.DescribeBy.(type) { + case *apiv1.DescribeDomainRequest_Id: + return &types.DescribeDomainRequest{UUID: common.StringPtr(describeBy.Id)} + case *apiv1.DescribeDomainRequest_Name: + return &types.DescribeDomainRequest{Name: common.StringPtr(describeBy.Name)} + } + panic("neither oneof field is set for DescribeDomainRequest") +} + +func FromDescribeDomainResponseDomain(t *types.DescribeDomainResponse) *apiv1.Domain { + if t == nil { + return nil + } + domain := apiv1.Domain{ + FailoverVersion: t.FailoverVersion, + IsGlobalDomain: t.IsGlobalDomain, + } + if info := t.DomainInfo; info != nil { + domain.Id = info.UUID + domain.Name = info.Name + domain.Status = FromDomainStatus(info.Status) + domain.Description = info.Description + domain.OwnerEmail = info.OwnerEmail + domain.Data = info.Data + } + if config := t.Configuration; config != nil { + domain.WorkflowExecutionRetentionPeriod = daysToDuration(&config.WorkflowExecutionRetentionPeriodInDays) + domain.BadBinaries = FromBadBinaries(config.BadBinaries) + domain.HistoryArchivalStatus = FromArchivalStatus(config.HistoryArchivalStatus) + domain.HistoryArchivalUri = config.HistoryArchivalURI + domain.VisibilityArchivalStatus = FromArchivalStatus(config.VisibilityArchivalStatus) + domain.VisibilityArchivalUri = config.VisibilityArchivalURI + } + if repl := t.ReplicationConfiguration; repl != nil { + domain.ActiveClusterName = repl.ActiveClusterName + domain.Clusters = FromClusterReplicationConfigurationArray(repl.Clusters) + } + return &domain +} + +func FromDescribeDomainResponse(t *types.DescribeDomainResponse) *apiv1.DescribeDomainResponse { + if t == nil { + return nil + } + return &apiv1.DescribeDomainResponse{ + Domain: FromDescribeDomainResponseDomain(t), + } +} + +func ToDescribeDomainResponseDomain(t *apiv1.Domain) *types.DescribeDomainResponse { + if t == nil { + return nil + } + return &types.DescribeDomainResponse{ + DomainInfo: &types.DomainInfo{ + Name: t.Name, + Status: ToDomainStatus(t.Status), + Description: t.Description, + OwnerEmail: t.OwnerEmail, + Data: t.Data, + UUID: t.Id, + }, + Configuration: &types.DomainConfiguration{ + WorkflowExecutionRetentionPeriodInDays: common.Int32Default(durationToDays(t.WorkflowExecutionRetentionPeriod)), + EmitMetric: true, + BadBinaries: ToBadBinaries(t.BadBinaries), + HistoryArchivalStatus: ToArchivalStatus(t.HistoryArchivalStatus), + HistoryArchivalURI: t.HistoryArchivalUri, + VisibilityArchivalStatus: ToArchivalStatus(t.VisibilityArchivalStatus), + VisibilityArchivalURI: t.VisibilityArchivalUri, + }, + ReplicationConfiguration: &types.DomainReplicationConfiguration{ + ActiveClusterName: t.ActiveClusterName, + Clusters: ToClusterReplicationConfigurationArray(t.Clusters), + }, + FailoverVersion: t.FailoverVersion, + IsGlobalDomain: t.IsGlobalDomain, + } +} + +func ToDescribeDomainResponse(t *apiv1.DescribeDomainResponse) *types.DescribeDomainResponse { + if t == nil { + return nil + } + return ToDescribeDomainResponseDomain(t.Domain) +} + +func FromDescribeTaskListRequest(t *types.DescribeTaskListRequest) *apiv1.DescribeTaskListRequest { + if t == nil { + return nil + } + return &apiv1.DescribeTaskListRequest{ + Domain: t.Domain, + TaskList: FromTaskList(t.TaskList), + TaskListType: FromTaskListType(t.TaskListType), + IncludeTaskListStatus: t.IncludeTaskListStatus, + } +} + +func ToDescribeTaskListRequest(t *apiv1.DescribeTaskListRequest) *types.DescribeTaskListRequest { + if t == nil { + return nil + } + return &types.DescribeTaskListRequest{ + Domain: t.Domain, + TaskList: ToTaskList(t.TaskList), + TaskListType: ToTaskListType(t.TaskListType), + IncludeTaskListStatus: t.IncludeTaskListStatus, + } +} + +func FromDescribeTaskListResponse(t *types.DescribeTaskListResponse) *apiv1.DescribeTaskListResponse { + if t == nil { + return nil + } + return &apiv1.DescribeTaskListResponse{ + Pollers: FromPollerInfoArray(t.Pollers), + TaskListStatus: FromTaskListStatus(t.TaskListStatus), + } +} + +func ToDescribeTaskListResponse(t *apiv1.DescribeTaskListResponse) *types.DescribeTaskListResponse { + if t == nil { + return nil + } + return &types.DescribeTaskListResponse{ + Pollers: ToPollerInfoArray(t.Pollers), + TaskListStatus: ToTaskListStatus(t.TaskListStatus), + } +} + +func FromDescribeWorkflowExecutionRequest(t *types.DescribeWorkflowExecutionRequest) *apiv1.DescribeWorkflowExecutionRequest { + if t == nil { + return nil + } + return &apiv1.DescribeWorkflowExecutionRequest{ + Domain: t.Domain, + WorkflowExecution: FromWorkflowExecution(t.Execution), + } +} + +func ToDescribeWorkflowExecutionRequest(t *apiv1.DescribeWorkflowExecutionRequest) *types.DescribeWorkflowExecutionRequest { + if t == nil { + return nil + } + return &types.DescribeWorkflowExecutionRequest{ + Domain: t.Domain, + Execution: ToWorkflowExecution(t.WorkflowExecution), + } +} + +func FromDescribeWorkflowExecutionResponse(t *types.DescribeWorkflowExecutionResponse) *apiv1.DescribeWorkflowExecutionResponse { + if t == nil { + return nil + } + return &apiv1.DescribeWorkflowExecutionResponse{ + ExecutionConfiguration: FromWorkflowExecutionConfiguration(t.ExecutionConfiguration), + WorkflowExecutionInfo: FromWorkflowExecutionInfo(t.WorkflowExecutionInfo), + PendingActivities: FromPendingActivityInfoArray(t.PendingActivities), + PendingChildren: FromPendingChildExecutionInfoArray(t.PendingChildren), + PendingDecision: FromPendingDecisionInfo(t.PendingDecision), + } +} + +func ToDescribeWorkflowExecutionResponse(t *apiv1.DescribeWorkflowExecutionResponse) *types.DescribeWorkflowExecutionResponse { + if t == nil { + return nil + } + return &types.DescribeWorkflowExecutionResponse{ + ExecutionConfiguration: ToWorkflowExecutionConfiguration(t.ExecutionConfiguration), + WorkflowExecutionInfo: ToWorkflowExecutionInfo(t.WorkflowExecutionInfo), + PendingActivities: ToPendingActivityInfoArray(t.PendingActivities), + PendingChildren: ToPendingChildExecutionInfoArray(t.PendingChildren), + PendingDecision: ToPendingDecisionInfo(t.PendingDecision), + } +} + +func FromDomainStatus(t *types.DomainStatus) apiv1.DomainStatus { + if t == nil { + return apiv1.DomainStatus_DOMAIN_STATUS_INVALID + } + switch *t { + case types.DomainStatusRegistered: + return apiv1.DomainStatus_DOMAIN_STATUS_REGISTERED + case types.DomainStatusDeprecated: + return apiv1.DomainStatus_DOMAIN_STATUS_DEPRECATED + case types.DomainStatusDeleted: + return apiv1.DomainStatus_DOMAIN_STATUS_DELETED + } + panic("unexpected enum value") +} + +func ToDomainStatus(t apiv1.DomainStatus) *types.DomainStatus { + switch t { + case apiv1.DomainStatus_DOMAIN_STATUS_INVALID: + return nil + case apiv1.DomainStatus_DOMAIN_STATUS_REGISTERED: + return types.DomainStatusRegistered.Ptr() + case apiv1.DomainStatus_DOMAIN_STATUS_DEPRECATED: + return types.DomainStatusDeprecated.Ptr() + case apiv1.DomainStatus_DOMAIN_STATUS_DELETED: + return types.DomainStatusDeleted.Ptr() + } + panic("unexpected enum value") +} + +func FromEncodingType(t *types.EncodingType) apiv1.EncodingType { + if t == nil { + return apiv1.EncodingType_ENCODING_TYPE_INVALID + } + switch *t { + case types.EncodingTypeThriftRW: + return apiv1.EncodingType_ENCODING_TYPE_THRIFTRW + case types.EncodingTypeJSON: + return apiv1.EncodingType_ENCODING_TYPE_JSON + } + panic("unexpected enum value") +} + +func ToEncodingType(t apiv1.EncodingType) *types.EncodingType { + switch t { + case apiv1.EncodingType_ENCODING_TYPE_INVALID: + return nil + case apiv1.EncodingType_ENCODING_TYPE_THRIFTRW: + return types.EncodingTypeThriftRW.Ptr() + case apiv1.EncodingType_ENCODING_TYPE_JSON: + return types.EncodingTypeJSON.Ptr() + case apiv1.EncodingType_ENCODING_TYPE_PROTO3: + panic("not supported yet") + } + panic("unexpected enum value") +} + +func FromEventFilterType(t *types.HistoryEventFilterType) apiv1.EventFilterType { + if t == nil { + return apiv1.EventFilterType_EVENT_FILTER_TYPE_INVALID + } + switch *t { + case types.HistoryEventFilterTypeAllEvent: + return apiv1.EventFilterType_EVENT_FILTER_TYPE_ALL_EVENT + case types.HistoryEventFilterTypeCloseEvent: + return apiv1.EventFilterType_EVENT_FILTER_TYPE_CLOSE_EVENT + } + panic("unexpected enum value") +} + +func ToEventFilterType(t apiv1.EventFilterType) *types.HistoryEventFilterType { + switch t { + case apiv1.EventFilterType_EVENT_FILTER_TYPE_INVALID: + return nil + case apiv1.EventFilterType_EVENT_FILTER_TYPE_ALL_EVENT: + return types.HistoryEventFilterTypeAllEvent.Ptr() + case apiv1.EventFilterType_EVENT_FILTER_TYPE_CLOSE_EVENT: + return types.HistoryEventFilterTypeCloseEvent.Ptr() + } + panic("unexpected enum value") +} + +func FromExternalWorkflowExecutionCancelRequestedEventAttributes(t *types.ExternalWorkflowExecutionCancelRequestedEventAttributes) *apiv1.ExternalWorkflowExecutionCancelRequestedEventAttributes { + if t == nil { + return nil + } + return &apiv1.ExternalWorkflowExecutionCancelRequestedEventAttributes{ + InitiatedEventId: t.InitiatedEventID, + Domain: t.Domain, + WorkflowExecution: FromWorkflowExecution(t.WorkflowExecution), + } +} + +func ToExternalWorkflowExecutionCancelRequestedEventAttributes(t *apiv1.ExternalWorkflowExecutionCancelRequestedEventAttributes) *types.ExternalWorkflowExecutionCancelRequestedEventAttributes { + if t == nil { + return nil + } + return &types.ExternalWorkflowExecutionCancelRequestedEventAttributes{ + InitiatedEventID: t.InitiatedEventId, + Domain: t.Domain, + WorkflowExecution: ToWorkflowExecution(t.WorkflowExecution), + } +} + +func FromExternalWorkflowExecutionSignaledEventAttributes(t *types.ExternalWorkflowExecutionSignaledEventAttributes) *apiv1.ExternalWorkflowExecutionSignaledEventAttributes { + if t == nil { + return nil + } + return &apiv1.ExternalWorkflowExecutionSignaledEventAttributes{ + InitiatedEventId: t.InitiatedEventID, + Domain: t.Domain, + WorkflowExecution: FromWorkflowExecution(t.WorkflowExecution), + Control: t.Control, + } +} + +func ToExternalWorkflowExecutionSignaledEventAttributes(t *apiv1.ExternalWorkflowExecutionSignaledEventAttributes) *types.ExternalWorkflowExecutionSignaledEventAttributes { + if t == nil { + return nil + } + return &types.ExternalWorkflowExecutionSignaledEventAttributes{ + InitiatedEventID: t.InitiatedEventId, + Domain: t.Domain, + WorkflowExecution: ToWorkflowExecution(t.WorkflowExecution), + Control: t.Control, + } +} + +func FromFailWorkflowExecutionDecisionAttributes(t *types.FailWorkflowExecutionDecisionAttributes) *apiv1.FailWorkflowExecutionDecisionAttributes { + if t == nil { + return nil + } + return &apiv1.FailWorkflowExecutionDecisionAttributes{ + Failure: FromFailure(t.Reason, t.Details), + } +} + +func ToFailWorkflowExecutionDecisionAttributes(t *apiv1.FailWorkflowExecutionDecisionAttributes) *types.FailWorkflowExecutionDecisionAttributes { + if t == nil { + return nil + } + return &types.FailWorkflowExecutionDecisionAttributes{ + Reason: ToFailureReason(t.Failure), + Details: ToFailureDetails(t.Failure), + } +} + +func FromGetClusterInfoResponse(t *types.ClusterInfo) *apiv1.GetClusterInfoResponse { + if t == nil { + return nil + } + return &apiv1.GetClusterInfoResponse{ + SupportedClientVersions: FromSupportedClientVersions(t.SupportedClientVersions), + } +} + +func ToGetClusterInfoResponse(t *apiv1.GetClusterInfoResponse) *types.ClusterInfo { + if t == nil { + return nil + } + return &types.ClusterInfo{ + SupportedClientVersions: ToSupportedClientVersions(t.SupportedClientVersions), + } +} + +func FromGetSearchAttributesResponse(t *types.GetSearchAttributesResponse) *apiv1.GetSearchAttributesResponse { + if t == nil { + return nil + } + return &apiv1.GetSearchAttributesResponse{ + Keys: FromIndexedValueTypeMap(t.Keys), + } +} + +func ToGetSearchAttributesResponse(t *apiv1.GetSearchAttributesResponse) *types.GetSearchAttributesResponse { + if t == nil { + return nil + } + return &types.GetSearchAttributesResponse{ + Keys: ToIndexedValueTypeMap(t.Keys), + } +} + +func FromGetWorkflowExecutionHistoryRequest(t *types.GetWorkflowExecutionHistoryRequest) *apiv1.GetWorkflowExecutionHistoryRequest { + if t == nil { + return nil + } + return &apiv1.GetWorkflowExecutionHistoryRequest{ + Domain: t.Domain, + WorkflowExecution: FromWorkflowExecution(t.Execution), + PageSize: t.MaximumPageSize, + NextPageToken: t.NextPageToken, + WaitForNewEvent: t.WaitForNewEvent, + HistoryEventFilterType: FromEventFilterType(t.HistoryEventFilterType), + SkipArchival: t.SkipArchival, + } +} + +func ToGetWorkflowExecutionHistoryRequest(t *apiv1.GetWorkflowExecutionHistoryRequest) *types.GetWorkflowExecutionHistoryRequest { + if t == nil { + return nil + } + return &types.GetWorkflowExecutionHistoryRequest{ + Domain: t.Domain, + Execution: ToWorkflowExecution(t.WorkflowExecution), + MaximumPageSize: t.PageSize, + NextPageToken: t.NextPageToken, + WaitForNewEvent: t.WaitForNewEvent, + HistoryEventFilterType: ToEventFilterType(t.HistoryEventFilterType), + SkipArchival: t.SkipArchival, + } +} + +func FromGetWorkflowExecutionHistoryResponse(t *types.GetWorkflowExecutionHistoryResponse) *apiv1.GetWorkflowExecutionHistoryResponse { + if t == nil { + return nil + } + return &apiv1.GetWorkflowExecutionHistoryResponse{ + History: FromHistory(t.History), + RawHistory: FromDataBlobArray(t.RawHistory), + NextPageToken: t.NextPageToken, + Archived: t.Archived, + } +} + +func ToGetWorkflowExecutionHistoryResponse(t *apiv1.GetWorkflowExecutionHistoryResponse) *types.GetWorkflowExecutionHistoryResponse { + if t == nil { + return nil + } + return &types.GetWorkflowExecutionHistoryResponse{ + History: ToHistory(t.History), + RawHistory: ToDataBlobArray(t.RawHistory), + NextPageToken: t.NextPageToken, + Archived: t.Archived, + } +} + +func FromHeader(t *types.Header) *apiv1.Header { + if t == nil { + return nil + } + return &apiv1.Header{ + Fields: FromPayloadMap(t.Fields), + } +} + +func ToHeader(t *apiv1.Header) *types.Header { + if t == nil { + return nil + } + return &types.Header{ + Fields: ToPayloadMap(t.Fields), + } +} + +func FromHealthResponse(t *types.HealthStatus) *apiv1.HealthResponse { + if t == nil { + return nil + } + return &apiv1.HealthResponse{ + Ok: t.Ok, + Message: t.Msg, + } +} + +func ToHealthResponse(t *apiv1.HealthResponse) *types.HealthStatus { + if t == nil { + return nil + } + return &types.HealthStatus{ + Ok: t.Ok, + Msg: t.Message, + } +} + +func FromHistory(t *types.History) *apiv1.History { + if t == nil { + return nil + } + return &apiv1.History{ + Events: FromHistoryEventArray(t.Events), + } +} + +func ToHistory(t *apiv1.History) *types.History { + if t == nil { + return nil + } + return &types.History{ + Events: ToHistoryEventArray(t.Events), + } +} + +func FromIndexedValueType(t types.IndexedValueType) apiv1.IndexedValueType { + switch t { + case types.IndexedValueTypeString: + return apiv1.IndexedValueType_INDEXED_VALUE_TYPE_STRING + case types.IndexedValueTypeKeyword: + return apiv1.IndexedValueType_INDEXED_VALUE_TYPE_KEYWORD + case types.IndexedValueTypeInt: + return apiv1.IndexedValueType_INDEXED_VALUE_TYPE_INT + case types.IndexedValueTypeDouble: + return apiv1.IndexedValueType_INDEXED_VALUE_TYPE_DOUBLE + case types.IndexedValueTypeBool: + return apiv1.IndexedValueType_INDEXED_VALUE_TYPE_BOOL + case types.IndexedValueTypeDatetime: + return apiv1.IndexedValueType_INDEXED_VALUE_TYPE_DATETIME + } + panic("unexpected enum value") +} + +func ToIndexedValueType(t apiv1.IndexedValueType) types.IndexedValueType { + switch t { + case apiv1.IndexedValueType_INDEXED_VALUE_TYPE_INVALID: + panic("received IndexedValueType_INDEXED_VALUE_TYPE_INVALID") + case apiv1.IndexedValueType_INDEXED_VALUE_TYPE_STRING: + return types.IndexedValueTypeString + case apiv1.IndexedValueType_INDEXED_VALUE_TYPE_KEYWORD: + return types.IndexedValueTypeKeyword + case apiv1.IndexedValueType_INDEXED_VALUE_TYPE_INT: + return types.IndexedValueTypeInt + case apiv1.IndexedValueType_INDEXED_VALUE_TYPE_DOUBLE: + return types.IndexedValueTypeDouble + case apiv1.IndexedValueType_INDEXED_VALUE_TYPE_BOOL: + return types.IndexedValueTypeBool + case apiv1.IndexedValueType_INDEXED_VALUE_TYPE_DATETIME: + return types.IndexedValueTypeDatetime + } + panic("unexpected enum value") +} + +func FromListArchivedWorkflowExecutionsRequest(t *types.ListArchivedWorkflowExecutionsRequest) *apiv1.ListArchivedWorkflowExecutionsRequest { + if t == nil { + return nil + } + return &apiv1.ListArchivedWorkflowExecutionsRequest{ + Domain: t.Domain, + PageSize: t.PageSize, + NextPageToken: t.NextPageToken, + Query: t.Query, + } +} + +func ToListArchivedWorkflowExecutionsRequest(t *apiv1.ListArchivedWorkflowExecutionsRequest) *types.ListArchivedWorkflowExecutionsRequest { + if t == nil { + return nil + } + return &types.ListArchivedWorkflowExecutionsRequest{ + Domain: t.Domain, + PageSize: t.PageSize, + NextPageToken: t.NextPageToken, + Query: t.Query, + } +} + +func FromListArchivedWorkflowExecutionsResponse(t *types.ListArchivedWorkflowExecutionsResponse) *apiv1.ListArchivedWorkflowExecutionsResponse { + if t == nil { + return nil + } + return &apiv1.ListArchivedWorkflowExecutionsResponse{ + Executions: FromWorkflowExecutionInfoArray(t.Executions), + NextPageToken: t.NextPageToken, + } +} + +func ToListArchivedWorkflowExecutionsResponse(t *apiv1.ListArchivedWorkflowExecutionsResponse) *types.ListArchivedWorkflowExecutionsResponse { + if t == nil { + return nil + } + return &types.ListArchivedWorkflowExecutionsResponse{ + Executions: ToWorkflowExecutionInfoArray(t.Executions), + NextPageToken: t.NextPageToken, + } +} + +func FromListClosedWorkflowExecutionsResponse(t *types.ListClosedWorkflowExecutionsResponse) *apiv1.ListClosedWorkflowExecutionsResponse { + if t == nil { + return nil + } + return &apiv1.ListClosedWorkflowExecutionsResponse{ + Executions: FromWorkflowExecutionInfoArray(t.Executions), + NextPageToken: t.NextPageToken, + } +} + +func ToListClosedWorkflowExecutionsResponse(t *apiv1.ListClosedWorkflowExecutionsResponse) *types.ListClosedWorkflowExecutionsResponse { + if t == nil { + return nil + } + return &types.ListClosedWorkflowExecutionsResponse{ + Executions: ToWorkflowExecutionInfoArray(t.Executions), + NextPageToken: t.NextPageToken, + } +} + +func FromListDomainsRequest(t *types.ListDomainsRequest) *apiv1.ListDomainsRequest { + if t == nil { + return nil + } + return &apiv1.ListDomainsRequest{ + PageSize: t.PageSize, + NextPageToken: t.NextPageToken, + } +} + +func ToListDomainsRequest(t *apiv1.ListDomainsRequest) *types.ListDomainsRequest { + if t == nil { + return nil + } + return &types.ListDomainsRequest{ + PageSize: t.PageSize, + NextPageToken: t.NextPageToken, + } +} + +func FromListDomainsResponse(t *types.ListDomainsResponse) *apiv1.ListDomainsResponse { + if t == nil { + return nil + } + return &apiv1.ListDomainsResponse{ + Domains: FromDescribeDomainResponseArray(t.Domains), + NextPageToken: t.NextPageToken, + } +} + +func ToListDomainsResponse(t *apiv1.ListDomainsResponse) *types.ListDomainsResponse { + if t == nil { + return nil + } + return &types.ListDomainsResponse{ + Domains: ToDescribeDomainResponseArray(t.Domains), + NextPageToken: t.NextPageToken, + } +} + +func FromListOpenWorkflowExecutionsResponse(t *types.ListOpenWorkflowExecutionsResponse) *apiv1.ListOpenWorkflowExecutionsResponse { + if t == nil { + return nil + } + return &apiv1.ListOpenWorkflowExecutionsResponse{ + Executions: FromWorkflowExecutionInfoArray(t.Executions), + NextPageToken: t.NextPageToken, + } +} + +func ToListOpenWorkflowExecutionsResponse(t *apiv1.ListOpenWorkflowExecutionsResponse) *types.ListOpenWorkflowExecutionsResponse { + if t == nil { + return nil + } + return &types.ListOpenWorkflowExecutionsResponse{ + Executions: ToWorkflowExecutionInfoArray(t.Executions), + NextPageToken: t.NextPageToken, + } +} + +func FromListTaskListPartitionsRequest(t *types.ListTaskListPartitionsRequest) *apiv1.ListTaskListPartitionsRequest { + if t == nil { + return nil + } + return &apiv1.ListTaskListPartitionsRequest{ + Domain: t.Domain, + TaskList: FromTaskList(t.TaskList), + } +} + +func ToListTaskListPartitionsRequest(t *apiv1.ListTaskListPartitionsRequest) *types.ListTaskListPartitionsRequest { + if t == nil { + return nil + } + return &types.ListTaskListPartitionsRequest{ + Domain: t.Domain, + TaskList: ToTaskList(t.TaskList), + } +} + +func FromListTaskListPartitionsResponse(t *types.ListTaskListPartitionsResponse) *apiv1.ListTaskListPartitionsResponse { + if t == nil { + return nil + } + return &apiv1.ListTaskListPartitionsResponse{ + ActivityTaskListPartitions: FromTaskListPartitionMetadataArray(t.ActivityTaskListPartitions), + DecisionTaskListPartitions: FromTaskListPartitionMetadataArray(t.DecisionTaskListPartitions), + } +} + +func ToListTaskListPartitionsResponse(t *apiv1.ListTaskListPartitionsResponse) *types.ListTaskListPartitionsResponse { + if t == nil { + return nil + } + return &types.ListTaskListPartitionsResponse{ + ActivityTaskListPartitions: ToTaskListPartitionMetadataArray(t.ActivityTaskListPartitions), + DecisionTaskListPartitions: ToTaskListPartitionMetadataArray(t.DecisionTaskListPartitions), + } +} + +func FromListWorkflowExecutionsRequest(t *types.ListWorkflowExecutionsRequest) *apiv1.ListWorkflowExecutionsRequest { + if t == nil { + return nil + } + return &apiv1.ListWorkflowExecutionsRequest{ + Domain: t.Domain, + PageSize: t.PageSize, + NextPageToken: t.NextPageToken, + Query: t.Query, + } +} + +func ToListWorkflowExecutionsRequest(t *apiv1.ListWorkflowExecutionsRequest) *types.ListWorkflowExecutionsRequest { + if t == nil { + return nil + } + return &types.ListWorkflowExecutionsRequest{ + Domain: t.Domain, + PageSize: t.PageSize, + NextPageToken: t.NextPageToken, + Query: t.Query, + } +} + +func FromListWorkflowExecutionsResponse(t *types.ListWorkflowExecutionsResponse) *apiv1.ListWorkflowExecutionsResponse { + if t == nil { + return nil + } + return &apiv1.ListWorkflowExecutionsResponse{ + Executions: FromWorkflowExecutionInfoArray(t.Executions), + NextPageToken: t.NextPageToken, + } +} + +func ToListWorkflowExecutionsResponse(t *apiv1.ListWorkflowExecutionsResponse) *types.ListWorkflowExecutionsResponse { + if t == nil { + return nil + } + return &types.ListWorkflowExecutionsResponse{ + Executions: ToWorkflowExecutionInfoArray(t.Executions), + NextPageToken: t.NextPageToken, + } +} + +func FromMarkerRecordedEventAttributes(t *types.MarkerRecordedEventAttributes) *apiv1.MarkerRecordedEventAttributes { + if t == nil { + return nil + } + return &apiv1.MarkerRecordedEventAttributes{ + MarkerName: t.MarkerName, + Details: FromPayload(t.Details), + DecisionTaskCompletedEventId: t.DecisionTaskCompletedEventID, + Header: FromHeader(t.Header), + } +} + +func ToMarkerRecordedEventAttributes(t *apiv1.MarkerRecordedEventAttributes) *types.MarkerRecordedEventAttributes { + if t == nil { + return nil + } + return &types.MarkerRecordedEventAttributes{ + MarkerName: t.MarkerName, + Details: ToPayload(t.Details), + DecisionTaskCompletedEventID: t.DecisionTaskCompletedEventId, + Header: ToHeader(t.Header), + } +} + +func FromMemo(t *types.Memo) *apiv1.Memo { + if t == nil { + return nil + } + return &apiv1.Memo{ + Fields: FromPayloadMap(t.Fields), + } +} + +func ToMemo(t *apiv1.Memo) *types.Memo { + if t == nil { + return nil + } + return &types.Memo{ + Fields: ToPayloadMap(t.Fields), + } +} + +func FromParentClosePolicy(t *types.ParentClosePolicy) apiv1.ParentClosePolicy { + if t == nil { + return apiv1.ParentClosePolicy_PARENT_CLOSE_POLICY_INVALID + } + switch *t { + case types.ParentClosePolicyAbandon: + return apiv1.ParentClosePolicy_PARENT_CLOSE_POLICY_ABANDON + case types.ParentClosePolicyRequestCancel: + return apiv1.ParentClosePolicy_PARENT_CLOSE_POLICY_REQUEST_CANCEL + case types.ParentClosePolicyTerminate: + return apiv1.ParentClosePolicy_PARENT_CLOSE_POLICY_TERMINATE + } + panic("unexpected enum value") +} + +func ToParentClosePolicy(t apiv1.ParentClosePolicy) *types.ParentClosePolicy { + switch t { + case apiv1.ParentClosePolicy_PARENT_CLOSE_POLICY_INVALID: + return nil + case apiv1.ParentClosePolicy_PARENT_CLOSE_POLICY_ABANDON: + return types.ParentClosePolicyAbandon.Ptr() + case apiv1.ParentClosePolicy_PARENT_CLOSE_POLICY_REQUEST_CANCEL: + return types.ParentClosePolicyRequestCancel.Ptr() + case apiv1.ParentClosePolicy_PARENT_CLOSE_POLICY_TERMINATE: + return types.ParentClosePolicyTerminate.Ptr() + } + panic("unexpected enum value") +} + +func FromPendingActivityInfo(t *types.PendingActivityInfo) *apiv1.PendingActivityInfo { + if t == nil { + return nil + } + return &apiv1.PendingActivityInfo{ + ActivityId: t.ActivityID, + ActivityType: FromActivityType(t.ActivityType), + State: FromPendingActivityState(t.State), + HeartbeatDetails: FromPayload(t.HeartbeatDetails), + LastHeartbeatTime: unixNanoToTime(t.LastHeartbeatTimestamp), + LastStartedTime: unixNanoToTime(t.LastStartedTimestamp), + Attempt: t.Attempt, + MaximumAttempts: t.MaximumAttempts, + ScheduledTime: unixNanoToTime(t.ScheduledTimestamp), + ExpirationTime: unixNanoToTime(t.ExpirationTimestamp), + LastFailure: FromFailure(t.LastFailureReason, t.LastFailureDetails), + LastWorkerIdentity: t.LastWorkerIdentity, + } +} + +func ToPendingActivityInfo(t *apiv1.PendingActivityInfo) *types.PendingActivityInfo { + if t == nil { + return nil + } + return &types.PendingActivityInfo{ + ActivityID: t.ActivityId, + ActivityType: ToActivityType(t.ActivityType), + State: ToPendingActivityState(t.State), + HeartbeatDetails: ToPayload(t.HeartbeatDetails), + LastHeartbeatTimestamp: timeToUnixNano(t.LastHeartbeatTime), + LastStartedTimestamp: timeToUnixNano(t.LastStartedTime), + Attempt: t.Attempt, + MaximumAttempts: t.MaximumAttempts, + ScheduledTimestamp: timeToUnixNano(t.ScheduledTime), + ExpirationTimestamp: timeToUnixNano(t.ExpirationTime), + LastFailureReason: ToFailureReason(t.LastFailure), + LastFailureDetails: ToFailureDetails(t.LastFailure), + LastWorkerIdentity: t.LastWorkerIdentity, + } +} + +func FromPendingActivityState(t *types.PendingActivityState) apiv1.PendingActivityState { + if t == nil { + return apiv1.PendingActivityState_PENDING_ACTIVITY_STATE_INVALID + } + switch *t { + case types.PendingActivityStateScheduled: + return apiv1.PendingActivityState_PENDING_ACTIVITY_STATE_SCHEDULED + case types.PendingActivityStateStarted: + return apiv1.PendingActivityState_PENDING_ACTIVITY_STATE_STARTED + case types.PendingActivityStateCancelRequested: + return apiv1.PendingActivityState_PENDING_ACTIVITY_STATE_CANCEL_REQUESTED + } + panic("unexpected enum value") +} + +func ToPendingActivityState(t apiv1.PendingActivityState) *types.PendingActivityState { + switch t { + case apiv1.PendingActivityState_PENDING_ACTIVITY_STATE_INVALID: + return nil + case apiv1.PendingActivityState_PENDING_ACTIVITY_STATE_SCHEDULED: + return types.PendingActivityStateScheduled.Ptr() + case apiv1.PendingActivityState_PENDING_ACTIVITY_STATE_STARTED: + return types.PendingActivityStateStarted.Ptr() + case apiv1.PendingActivityState_PENDING_ACTIVITY_STATE_CANCEL_REQUESTED: + return types.PendingActivityStateCancelRequested.Ptr() + } + panic("unexpected enum value") +} + +func FromPendingChildExecutionInfo(t *types.PendingChildExecutionInfo) *apiv1.PendingChildExecutionInfo { + if t == nil { + return nil + } + return &apiv1.PendingChildExecutionInfo{ + WorkflowExecution: FromWorkflowRunPair(t.WorkflowID, t.RunID), + WorkflowTypeName: t.WorkflowTypName, + InitiatedId: t.InitiatedID, + ParentClosePolicy: FromParentClosePolicy(t.ParentClosePolicy), + } +} + +func ToPendingChildExecutionInfo(t *apiv1.PendingChildExecutionInfo) *types.PendingChildExecutionInfo { + if t == nil { + return nil + } + return &types.PendingChildExecutionInfo{ + WorkflowID: ToWorkflowID(t.WorkflowExecution), + RunID: ToRunID(t.WorkflowExecution), + WorkflowTypName: t.WorkflowTypeName, + InitiatedID: t.InitiatedId, + ParentClosePolicy: ToParentClosePolicy(t.ParentClosePolicy), + } +} + +func FromPendingDecisionInfo(t *types.PendingDecisionInfo) *apiv1.PendingDecisionInfo { + if t == nil { + return nil + } + return &apiv1.PendingDecisionInfo{ + State: FromPendingDecisionState(t.State), + ScheduledTime: unixNanoToTime(t.ScheduledTimestamp), + StartedTime: unixNanoToTime(t.StartedTimestamp), + Attempt: int32(t.Attempt), + OriginalScheduledTime: unixNanoToTime(t.OriginalScheduledTimestamp), + } +} + +func ToPendingDecisionInfo(t *apiv1.PendingDecisionInfo) *types.PendingDecisionInfo { + if t == nil { + return nil + } + return &types.PendingDecisionInfo{ + State: ToPendingDecisionState(t.State), + ScheduledTimestamp: timeToUnixNano(t.ScheduledTime), + StartedTimestamp: timeToUnixNano(t.StartedTime), + Attempt: int64(t.Attempt), + OriginalScheduledTimestamp: timeToUnixNano(t.OriginalScheduledTime), + } +} + +func FromPendingDecisionState(t *types.PendingDecisionState) apiv1.PendingDecisionState { + if t == nil { + return apiv1.PendingDecisionState_PENDING_DECISION_STATE_INVALID + } + switch *t { + case types.PendingDecisionStateScheduled: + return apiv1.PendingDecisionState_PENDING_DECISION_STATE_SCHEDULED + case types.PendingDecisionStateStarted: + return apiv1.PendingDecisionState_PENDING_DECISION_STATE_STARTED + } + panic("unexpected enum value") +} + +func ToPendingDecisionState(t apiv1.PendingDecisionState) *types.PendingDecisionState { + switch t { + case apiv1.PendingDecisionState_PENDING_DECISION_STATE_INVALID: + return nil + case apiv1.PendingDecisionState_PENDING_DECISION_STATE_SCHEDULED: + return types.PendingDecisionStateScheduled.Ptr() + case apiv1.PendingDecisionState_PENDING_DECISION_STATE_STARTED: + return types.PendingDecisionStateStarted.Ptr() + } + panic("unexpected enum value") +} + +func FromPollForActivityTaskRequest(t *types.PollForActivityTaskRequest) *apiv1.PollForActivityTaskRequest { + if t == nil { + return nil + } + return &apiv1.PollForActivityTaskRequest{ + Domain: t.Domain, + TaskList: FromTaskList(t.TaskList), + Identity: t.Identity, + TaskListMetadata: FromTaskListMetadata(t.TaskListMetadata), + } +} + +func ToPollForActivityTaskRequest(t *apiv1.PollForActivityTaskRequest) *types.PollForActivityTaskRequest { + if t == nil { + return nil + } + return &types.PollForActivityTaskRequest{ + Domain: t.Domain, + TaskList: ToTaskList(t.TaskList), + Identity: t.Identity, + TaskListMetadata: ToTaskListMetadata(t.TaskListMetadata), + } +} + +func FromPollForActivityTaskResponse(t *types.PollForActivityTaskResponse) *apiv1.PollForActivityTaskResponse { + if t == nil { + return nil + } + return &apiv1.PollForActivityTaskResponse{ + TaskToken: t.TaskToken, + WorkflowExecution: FromWorkflowExecution(t.WorkflowExecution), + ActivityId: t.ActivityID, + ActivityType: FromActivityType(t.ActivityType), + Input: FromPayload(t.Input), + ScheduledTime: unixNanoToTime(t.ScheduledTimestamp), + StartedTime: unixNanoToTime(t.StartedTimestamp), + ScheduleToCloseTimeout: secondsToDuration(t.ScheduleToCloseTimeoutSeconds), + StartToCloseTimeout: secondsToDuration(t.StartToCloseTimeoutSeconds), + HeartbeatTimeout: secondsToDuration(t.HeartbeatTimeoutSeconds), + Attempt: t.Attempt, + ScheduledTimeOfThisAttempt: unixNanoToTime(t.ScheduledTimestampOfThisAttempt), + HeartbeatDetails: FromPayload(t.HeartbeatDetails), + WorkflowType: FromWorkflowType(t.WorkflowType), + WorkflowDomain: t.WorkflowDomain, + Header: FromHeader(t.Header), + } +} + +func ToPollForActivityTaskResponse(t *apiv1.PollForActivityTaskResponse) *types.PollForActivityTaskResponse { + if t == nil { + return nil + } + return &types.PollForActivityTaskResponse{ + TaskToken: t.TaskToken, + WorkflowExecution: ToWorkflowExecution(t.WorkflowExecution), + ActivityID: t.ActivityId, + ActivityType: ToActivityType(t.ActivityType), + Input: ToPayload(t.Input), + ScheduledTimestamp: timeToUnixNano(t.ScheduledTime), + StartedTimestamp: timeToUnixNano(t.StartedTime), + ScheduleToCloseTimeoutSeconds: durationToSeconds(t.ScheduleToCloseTimeout), + StartToCloseTimeoutSeconds: durationToSeconds(t.StartToCloseTimeout), + HeartbeatTimeoutSeconds: durationToSeconds(t.HeartbeatTimeout), + Attempt: t.Attempt, + ScheduledTimestampOfThisAttempt: timeToUnixNano(t.ScheduledTimeOfThisAttempt), + HeartbeatDetails: ToPayload(t.HeartbeatDetails), + WorkflowType: ToWorkflowType(t.WorkflowType), + WorkflowDomain: t.WorkflowDomain, + Header: ToHeader(t.Header), + } +} + +func FromPollForDecisionTaskRequest(t *types.PollForDecisionTaskRequest) *apiv1.PollForDecisionTaskRequest { + if t == nil { + return nil + } + return &apiv1.PollForDecisionTaskRequest{ + Domain: t.Domain, + TaskList: FromTaskList(t.TaskList), + Identity: t.Identity, + BinaryChecksum: t.BinaryChecksum, + } +} + +func ToPollForDecisionTaskRequest(t *apiv1.PollForDecisionTaskRequest) *types.PollForDecisionTaskRequest { + if t == nil { + return nil + } + return &types.PollForDecisionTaskRequest{ + Domain: t.Domain, + TaskList: ToTaskList(t.TaskList), + Identity: t.Identity, + BinaryChecksum: t.BinaryChecksum, + } +} + +func FromPollForDecisionTaskResponse(t *types.PollForDecisionTaskResponse) *apiv1.PollForDecisionTaskResponse { + if t == nil { + return nil + } + return &apiv1.PollForDecisionTaskResponse{ + TaskToken: t.TaskToken, + WorkflowExecution: FromWorkflowExecution(t.WorkflowExecution), + WorkflowType: FromWorkflowType(t.WorkflowType), + PreviousStartedEventId: fromInt64Value(t.PreviousStartedEventID), + StartedEventId: t.StartedEventID, + Attempt: t.Attempt, + BacklogCountHint: t.BacklogCountHint, + History: FromHistory(t.History), + NextPageToken: t.NextPageToken, + Query: FromWorkflowQuery(t.Query), + WorkflowExecutionTaskList: FromTaskList(t.WorkflowExecutionTaskList), + ScheduledTime: unixNanoToTime(t.ScheduledTimestamp), + StartedTime: unixNanoToTime(t.StartedTimestamp), + Queries: FromWorkflowQueryMap(t.Queries), + } +} + +func ToPollForDecisionTaskResponse(t *apiv1.PollForDecisionTaskResponse) *types.PollForDecisionTaskResponse { + if t == nil { + return nil + } + return &types.PollForDecisionTaskResponse{ + TaskToken: t.TaskToken, + WorkflowExecution: ToWorkflowExecution(t.WorkflowExecution), + WorkflowType: ToWorkflowType(t.WorkflowType), + PreviousStartedEventID: toInt64Value(t.PreviousStartedEventId), + StartedEventID: t.StartedEventId, + Attempt: t.Attempt, + BacklogCountHint: t.BacklogCountHint, + History: ToHistory(t.History), + NextPageToken: t.NextPageToken, + Query: ToWorkflowQuery(t.Query), + WorkflowExecutionTaskList: ToTaskList(t.WorkflowExecutionTaskList), + ScheduledTimestamp: timeToUnixNano(t.ScheduledTime), + StartedTimestamp: timeToUnixNano(t.StartedTime), + Queries: ToWorkflowQueryMap(t.Queries), + } +} + +func FromPollerInfo(t *types.PollerInfo) *apiv1.PollerInfo { + if t == nil { + return nil + } + return &apiv1.PollerInfo{ + LastAccessTime: unixNanoToTime(t.LastAccessTime), + Identity: t.Identity, + RatePerSecond: t.RatePerSecond, + } +} + +func ToPollerInfo(t *apiv1.PollerInfo) *types.PollerInfo { + if t == nil { + return nil + } + return &types.PollerInfo{ + LastAccessTime: timeToUnixNano(t.LastAccessTime), + Identity: t.Identity, + RatePerSecond: t.RatePerSecond, + } +} + +func FromQueryConsistencyLevel(t *types.QueryConsistencyLevel) apiv1.QueryConsistencyLevel { + if t == nil { + return apiv1.QueryConsistencyLevel_QUERY_CONSISTENCY_LEVEL_INVALID + } + switch *t { + case types.QueryConsistencyLevelEventual: + return apiv1.QueryConsistencyLevel_QUERY_CONSISTENCY_LEVEL_EVENTUAL + case types.QueryConsistencyLevelStrong: + return apiv1.QueryConsistencyLevel_QUERY_CONSISTENCY_LEVEL_STRONG + } + panic("unexpected enum value") +} + +func ToQueryConsistencyLevel(t apiv1.QueryConsistencyLevel) *types.QueryConsistencyLevel { + switch t { + case apiv1.QueryConsistencyLevel_QUERY_CONSISTENCY_LEVEL_INVALID: + return nil + case apiv1.QueryConsistencyLevel_QUERY_CONSISTENCY_LEVEL_EVENTUAL: + return types.QueryConsistencyLevelEventual.Ptr() + case apiv1.QueryConsistencyLevel_QUERY_CONSISTENCY_LEVEL_STRONG: + return types.QueryConsistencyLevelStrong.Ptr() + } + panic("unexpected enum value") +} + +func FromQueryRejectCondition(t *types.QueryRejectCondition) apiv1.QueryRejectCondition { + if t == nil { + return apiv1.QueryRejectCondition_QUERY_REJECT_CONDITION_INVALID + } + switch *t { + case types.QueryRejectConditionNotOpen: + return apiv1.QueryRejectCondition_QUERY_REJECT_CONDITION_NOT_OPEN + case types.QueryRejectConditionNotCompletedCleanly: + return apiv1.QueryRejectCondition_QUERY_REJECT_CONDITION_NOT_COMPLETED_CLEANLY + } + panic("unexpected enum value") +} + +func ToQueryRejectCondition(t apiv1.QueryRejectCondition) *types.QueryRejectCondition { + switch t { + case apiv1.QueryRejectCondition_QUERY_REJECT_CONDITION_INVALID: + return nil + case apiv1.QueryRejectCondition_QUERY_REJECT_CONDITION_NOT_OPEN: + return types.QueryRejectConditionNotOpen.Ptr() + case apiv1.QueryRejectCondition_QUERY_REJECT_CONDITION_NOT_COMPLETED_CLEANLY: + return types.QueryRejectConditionNotCompletedCleanly.Ptr() + } + panic("unexpected enum value") +} + +func FromQueryRejected(t *types.QueryRejected) *apiv1.QueryRejected { + if t == nil { + return nil + } + return &apiv1.QueryRejected{ + CloseStatus: FromWorkflowExecutionCloseStatus(t.CloseStatus), + } +} + +func ToQueryRejected(t *apiv1.QueryRejected) *types.QueryRejected { + if t == nil { + return nil + } + return &types.QueryRejected{ + CloseStatus: ToWorkflowExecutionCloseStatus(t.CloseStatus), + } +} + +func FromQueryResultType(t *types.QueryResultType) apiv1.QueryResultType { + if t == nil { + return apiv1.QueryResultType_QUERY_RESULT_TYPE_INVALID + } + switch *t { + case types.QueryResultTypeAnswered: + return apiv1.QueryResultType_QUERY_RESULT_TYPE_ANSWERED + case types.QueryResultTypeFailed: + return apiv1.QueryResultType_QUERY_RESULT_TYPE_FAILED + } + panic("unexpected enum value") +} + +func ToQueryResultType(t apiv1.QueryResultType) *types.QueryResultType { + switch t { + case apiv1.QueryResultType_QUERY_RESULT_TYPE_INVALID: + return nil + case apiv1.QueryResultType_QUERY_RESULT_TYPE_ANSWERED: + return types.QueryResultTypeAnswered.Ptr() + case apiv1.QueryResultType_QUERY_RESULT_TYPE_FAILED: + return types.QueryResultTypeFailed.Ptr() + } + panic("unexpected enum value") +} + +func FromQueryWorkflowRequest(t *types.QueryWorkflowRequest) *apiv1.QueryWorkflowRequest { + if t == nil { + return nil + } + return &apiv1.QueryWorkflowRequest{ + Domain: t.Domain, + WorkflowExecution: FromWorkflowExecution(t.Execution), + Query: FromWorkflowQuery(t.Query), + QueryRejectCondition: FromQueryRejectCondition(t.QueryRejectCondition), + QueryConsistencyLevel: FromQueryConsistencyLevel(t.QueryConsistencyLevel), + } +} + +func ToQueryWorkflowRequest(t *apiv1.QueryWorkflowRequest) *types.QueryWorkflowRequest { + if t == nil { + return nil + } + return &types.QueryWorkflowRequest{ + Domain: t.Domain, + Execution: ToWorkflowExecution(t.WorkflowExecution), + Query: ToWorkflowQuery(t.Query), + QueryRejectCondition: ToQueryRejectCondition(t.QueryRejectCondition), + QueryConsistencyLevel: ToQueryConsistencyLevel(t.QueryConsistencyLevel), + } +} + +func FromQueryWorkflowResponse(t *types.QueryWorkflowResponse) *apiv1.QueryWorkflowResponse { + if t == nil { + return nil + } + return &apiv1.QueryWorkflowResponse{ + QueryResult: FromPayload(t.QueryResult), + QueryRejected: FromQueryRejected(t.QueryRejected), + } +} + +func ToQueryWorkflowResponse(t *apiv1.QueryWorkflowResponse) *types.QueryWorkflowResponse { + if t == nil { + return nil + } + return &types.QueryWorkflowResponse{ + QueryResult: ToPayload(t.QueryResult), + QueryRejected: ToQueryRejected(t.QueryRejected), + } +} + +func FromRecordActivityTaskHeartbeatByIDRequest(t *types.RecordActivityTaskHeartbeatByIDRequest) *apiv1.RecordActivityTaskHeartbeatByIDRequest { + if t == nil { + return nil + } + return &apiv1.RecordActivityTaskHeartbeatByIDRequest{ + Domain: t.Domain, + WorkflowExecution: FromWorkflowRunPair(t.WorkflowID, t.RunID), + ActivityId: t.ActivityID, + Details: FromPayload(t.Details), + Identity: t.Identity, + } +} + +func ToRecordActivityTaskHeartbeatByIDRequest(t *apiv1.RecordActivityTaskHeartbeatByIDRequest) *types.RecordActivityTaskHeartbeatByIDRequest { + if t == nil { + return nil + } + return &types.RecordActivityTaskHeartbeatByIDRequest{ + Domain: t.Domain, + WorkflowID: ToWorkflowID(t.WorkflowExecution), + RunID: ToRunID(t.WorkflowExecution), + ActivityID: t.ActivityId, + Details: ToPayload(t.Details), + Identity: t.Identity, + } +} + +func FromRecordActivityTaskHeartbeatByIDResponse(t *types.RecordActivityTaskHeartbeatResponse) *apiv1.RecordActivityTaskHeartbeatByIDResponse { + if t == nil { + return nil + } + return &apiv1.RecordActivityTaskHeartbeatByIDResponse{ + CancelRequested: t.CancelRequested, + } +} + +func ToRecordActivityTaskHeartbeatByIDResponse(t *apiv1.RecordActivityTaskHeartbeatByIDResponse) *types.RecordActivityTaskHeartbeatResponse { + if t == nil { + return nil + } + return &types.RecordActivityTaskHeartbeatResponse{ + CancelRequested: t.CancelRequested, + } +} + +func FromRecordActivityTaskHeartbeatRequest(t *types.RecordActivityTaskHeartbeatRequest) *apiv1.RecordActivityTaskHeartbeatRequest { + if t == nil { + return nil + } + return &apiv1.RecordActivityTaskHeartbeatRequest{ + TaskToken: t.TaskToken, + Details: FromPayload(t.Details), + Identity: t.Identity, + } +} + +func ToRecordActivityTaskHeartbeatRequest(t *apiv1.RecordActivityTaskHeartbeatRequest) *types.RecordActivityTaskHeartbeatRequest { + if t == nil { + return nil + } + return &types.RecordActivityTaskHeartbeatRequest{ + TaskToken: t.TaskToken, + Details: ToPayload(t.Details), + Identity: t.Identity, + } +} + +func FromRecordActivityTaskHeartbeatResponse(t *types.RecordActivityTaskHeartbeatResponse) *apiv1.RecordActivityTaskHeartbeatResponse { + if t == nil { + return nil + } + return &apiv1.RecordActivityTaskHeartbeatResponse{ + CancelRequested: t.CancelRequested, + } +} + +func ToRecordActivityTaskHeartbeatResponse(t *apiv1.RecordActivityTaskHeartbeatResponse) *types.RecordActivityTaskHeartbeatResponse { + if t == nil { + return nil + } + return &types.RecordActivityTaskHeartbeatResponse{ + CancelRequested: t.CancelRequested, + } +} + +func FromRecordMarkerDecisionAttributes(t *types.RecordMarkerDecisionAttributes) *apiv1.RecordMarkerDecisionAttributes { + if t == nil { + return nil + } + return &apiv1.RecordMarkerDecisionAttributes{ + MarkerName: t.MarkerName, + Details: FromPayload(t.Details), + Header: FromHeader(t.Header), + } +} + +func ToRecordMarkerDecisionAttributes(t *apiv1.RecordMarkerDecisionAttributes) *types.RecordMarkerDecisionAttributes { + if t == nil { + return nil + } + return &types.RecordMarkerDecisionAttributes{ + MarkerName: t.MarkerName, + Details: ToPayload(t.Details), + Header: ToHeader(t.Header), + } +} + +func FromRegisterDomainRequest(t *types.RegisterDomainRequest) *apiv1.RegisterDomainRequest { + if t == nil { + return nil + } + return &apiv1.RegisterDomainRequest{ + Name: t.Name, + Description: t.Description, + OwnerEmail: t.OwnerEmail, + WorkflowExecutionRetentionPeriod: daysToDuration(&t.WorkflowExecutionRetentionPeriodInDays), + Clusters: FromClusterReplicationConfigurationArray(t.Clusters), + ActiveClusterName: t.ActiveClusterName, + Data: t.Data, + SecurityToken: t.SecurityToken, + IsGlobalDomain: t.IsGlobalDomain, + HistoryArchivalStatus: FromArchivalStatus(t.HistoryArchivalStatus), + HistoryArchivalUri: t.HistoryArchivalURI, + VisibilityArchivalStatus: FromArchivalStatus(t.VisibilityArchivalStatus), + VisibilityArchivalUri: t.VisibilityArchivalURI, + } +} + +func ToRegisterDomainRequest(t *apiv1.RegisterDomainRequest) *types.RegisterDomainRequest { + if t == nil { + return nil + } + return &types.RegisterDomainRequest{ + Name: t.Name, + Description: t.Description, + OwnerEmail: t.OwnerEmail, + WorkflowExecutionRetentionPeriodInDays: *durationToDays(t.WorkflowExecutionRetentionPeriod), + EmitMetric: common.BoolPtr(true), + Clusters: ToClusterReplicationConfigurationArray(t.Clusters), + ActiveClusterName: t.ActiveClusterName, + Data: t.Data, + SecurityToken: t.SecurityToken, + IsGlobalDomain: t.IsGlobalDomain, + HistoryArchivalStatus: ToArchivalStatus(t.HistoryArchivalStatus), + HistoryArchivalURI: t.HistoryArchivalUri, + VisibilityArchivalStatus: ToArchivalStatus(t.VisibilityArchivalStatus), + VisibilityArchivalURI: t.VisibilityArchivalUri, + } +} + +func FromRequestCancelActivityTaskDecisionAttributes(t *types.RequestCancelActivityTaskDecisionAttributes) *apiv1.RequestCancelActivityTaskDecisionAttributes { + if t == nil { + return nil + } + return &apiv1.RequestCancelActivityTaskDecisionAttributes{ + ActivityId: t.ActivityID, + } +} + +func ToRequestCancelActivityTaskDecisionAttributes(t *apiv1.RequestCancelActivityTaskDecisionAttributes) *types.RequestCancelActivityTaskDecisionAttributes { + if t == nil { + return nil + } + return &types.RequestCancelActivityTaskDecisionAttributes{ + ActivityID: t.ActivityId, + } +} + +func FromRequestCancelActivityTaskFailedEventAttributes(t *types.RequestCancelActivityTaskFailedEventAttributes) *apiv1.RequestCancelActivityTaskFailedEventAttributes { + if t == nil { + return nil + } + return &apiv1.RequestCancelActivityTaskFailedEventAttributes{ + ActivityId: t.ActivityID, + Cause: t.Cause, + DecisionTaskCompletedEventId: t.DecisionTaskCompletedEventID, + } +} + +func ToRequestCancelActivityTaskFailedEventAttributes(t *apiv1.RequestCancelActivityTaskFailedEventAttributes) *types.RequestCancelActivityTaskFailedEventAttributes { + if t == nil { + return nil + } + return &types.RequestCancelActivityTaskFailedEventAttributes{ + ActivityID: t.ActivityId, + Cause: t.Cause, + DecisionTaskCompletedEventID: t.DecisionTaskCompletedEventId, + } +} + +func FromRequestCancelExternalWorkflowExecutionDecisionAttributes(t *types.RequestCancelExternalWorkflowExecutionDecisionAttributes) *apiv1.RequestCancelExternalWorkflowExecutionDecisionAttributes { + if t == nil { + return nil + } + return &apiv1.RequestCancelExternalWorkflowExecutionDecisionAttributes{ + Domain: t.Domain, + WorkflowExecution: FromWorkflowRunPair(t.WorkflowID, t.RunID), + Control: t.Control, + ChildWorkflowOnly: t.ChildWorkflowOnly, + } +} + +func ToRequestCancelExternalWorkflowExecutionDecisionAttributes(t *apiv1.RequestCancelExternalWorkflowExecutionDecisionAttributes) *types.RequestCancelExternalWorkflowExecutionDecisionAttributes { + if t == nil { + return nil + } + return &types.RequestCancelExternalWorkflowExecutionDecisionAttributes{ + Domain: t.Domain, + WorkflowID: ToWorkflowID(t.WorkflowExecution), + RunID: ToRunID(t.WorkflowExecution), + Control: t.Control, + ChildWorkflowOnly: t.ChildWorkflowOnly, + } +} + +func FromRequestCancelExternalWorkflowExecutionFailedEventAttributes(t *types.RequestCancelExternalWorkflowExecutionFailedEventAttributes) *apiv1.RequestCancelExternalWorkflowExecutionFailedEventAttributes { + if t == nil { + return nil + } + return &apiv1.RequestCancelExternalWorkflowExecutionFailedEventAttributes{ + Cause: FromCancelExternalWorkflowExecutionFailedCause(t.Cause), + DecisionTaskCompletedEventId: t.DecisionTaskCompletedEventID, + Domain: t.Domain, + WorkflowExecution: FromWorkflowExecution(t.WorkflowExecution), + InitiatedEventId: t.InitiatedEventID, + Control: t.Control, + } +} + +func ToRequestCancelExternalWorkflowExecutionFailedEventAttributes(t *apiv1.RequestCancelExternalWorkflowExecutionFailedEventAttributes) *types.RequestCancelExternalWorkflowExecutionFailedEventAttributes { + if t == nil { + return nil + } + return &types.RequestCancelExternalWorkflowExecutionFailedEventAttributes{ + Cause: ToCancelExternalWorkflowExecutionFailedCause(t.Cause), + DecisionTaskCompletedEventID: t.DecisionTaskCompletedEventId, + Domain: t.Domain, + WorkflowExecution: ToWorkflowExecution(t.WorkflowExecution), + InitiatedEventID: t.InitiatedEventId, + Control: t.Control, + } +} + +func FromRequestCancelExternalWorkflowExecutionInitiatedEventAttributes(t *types.RequestCancelExternalWorkflowExecutionInitiatedEventAttributes) *apiv1.RequestCancelExternalWorkflowExecutionInitiatedEventAttributes { + if t == nil { + return nil + } + return &apiv1.RequestCancelExternalWorkflowExecutionInitiatedEventAttributes{ + DecisionTaskCompletedEventId: t.DecisionTaskCompletedEventID, + Domain: t.Domain, + WorkflowExecution: FromWorkflowExecution(t.WorkflowExecution), + Control: t.Control, + ChildWorkflowOnly: t.ChildWorkflowOnly, + } +} + +func ToRequestCancelExternalWorkflowExecutionInitiatedEventAttributes(t *apiv1.RequestCancelExternalWorkflowExecutionInitiatedEventAttributes) *types.RequestCancelExternalWorkflowExecutionInitiatedEventAttributes { + if t == nil { + return nil + } + return &types.RequestCancelExternalWorkflowExecutionInitiatedEventAttributes{ + DecisionTaskCompletedEventID: t.DecisionTaskCompletedEventId, + Domain: t.Domain, + WorkflowExecution: ToWorkflowExecution(t.WorkflowExecution), + Control: t.Control, + ChildWorkflowOnly: t.ChildWorkflowOnly, + } +} + +func FromRequestCancelWorkflowExecutionRequest(t *types.RequestCancelWorkflowExecutionRequest) *apiv1.RequestCancelWorkflowExecutionRequest { + if t == nil { + return nil + } + return &apiv1.RequestCancelWorkflowExecutionRequest{ + Domain: t.Domain, + WorkflowExecution: FromWorkflowExecution(t.WorkflowExecution), + Identity: t.Identity, + RequestId: t.RequestID, + } +} + +func ToRequestCancelWorkflowExecutionRequest(t *apiv1.RequestCancelWorkflowExecutionRequest) *types.RequestCancelWorkflowExecutionRequest { + if t == nil { + return nil + } + return &types.RequestCancelWorkflowExecutionRequest{ + Domain: t.Domain, + WorkflowExecution: ToWorkflowExecution(t.WorkflowExecution), + Identity: t.Identity, + RequestID: t.RequestId, + } +} + +func FromResetPointInfo(t *types.ResetPointInfo) *apiv1.ResetPointInfo { + if t == nil { + return nil + } + return &apiv1.ResetPointInfo{ + BinaryChecksum: t.BinaryChecksum, + RunId: t.RunID, + FirstDecisionCompletedId: t.FirstDecisionCompletedID, + CreatedTime: unixNanoToTime(t.CreatedTimeNano), + ExpiringTime: unixNanoToTime(t.ExpiringTimeNano), + Resettable: t.Resettable, + } +} + +func ToResetPointInfo(t *apiv1.ResetPointInfo) *types.ResetPointInfo { + if t == nil { + return nil + } + return &types.ResetPointInfo{ + BinaryChecksum: t.BinaryChecksum, + RunID: t.RunId, + FirstDecisionCompletedID: t.FirstDecisionCompletedId, + CreatedTimeNano: timeToUnixNano(t.CreatedTime), + ExpiringTimeNano: timeToUnixNano(t.ExpiringTime), + Resettable: t.Resettable, + } +} + +func FromResetPoints(t *types.ResetPoints) *apiv1.ResetPoints { + if t == nil { + return nil + } + return &apiv1.ResetPoints{ + Points: FromResetPointInfoArray(t.Points), + } +} + +func ToResetPoints(t *apiv1.ResetPoints) *types.ResetPoints { + if t == nil { + return nil + } + return &types.ResetPoints{ + Points: ToResetPointInfoArray(t.Points), + } +} + +func FromResetStickyTaskListRequest(t *types.ResetStickyTaskListRequest) *apiv1.ResetStickyTaskListRequest { + if t == nil { + return nil + } + return &apiv1.ResetStickyTaskListRequest{ + Domain: t.Domain, + WorkflowExecution: FromWorkflowExecution(t.Execution), + } +} + +func ToResetStickyTaskListRequest(t *apiv1.ResetStickyTaskListRequest) *types.ResetStickyTaskListRequest { + if t == nil { + return nil + } + return &types.ResetStickyTaskListRequest{ + Domain: t.Domain, + Execution: ToWorkflowExecution(t.WorkflowExecution), + } +} + +func FromResetWorkflowExecutionRequest(t *types.ResetWorkflowExecutionRequest) *apiv1.ResetWorkflowExecutionRequest { + if t == nil { + return nil + } + return &apiv1.ResetWorkflowExecutionRequest{ + Domain: t.Domain, + WorkflowExecution: FromWorkflowExecution(t.WorkflowExecution), + Reason: t.Reason, + DecisionFinishEventId: t.DecisionFinishEventID, + RequestId: t.RequestID, + SkipSignalReapply: t.SkipSignalReapply, + } +} + +func ToResetWorkflowExecutionRequest(t *apiv1.ResetWorkflowExecutionRequest) *types.ResetWorkflowExecutionRequest { + if t == nil { + return nil + } + return &types.ResetWorkflowExecutionRequest{ + Domain: t.Domain, + WorkflowExecution: ToWorkflowExecution(t.WorkflowExecution), + Reason: t.Reason, + DecisionFinishEventID: t.DecisionFinishEventId, + RequestID: t.RequestId, + SkipSignalReapply: t.SkipSignalReapply, + } +} + +func FromResetWorkflowExecutionResponse(t *types.ResetWorkflowExecutionResponse) *apiv1.ResetWorkflowExecutionResponse { + if t == nil { + return nil + } + return &apiv1.ResetWorkflowExecutionResponse{ + RunId: t.RunID, + } +} + +func ToResetWorkflowExecutionResponse(t *apiv1.ResetWorkflowExecutionResponse) *types.ResetWorkflowExecutionResponse { + if t == nil { + return nil + } + return &types.ResetWorkflowExecutionResponse{ + RunID: t.RunId, + } +} + +func FromRespondActivityTaskCanceledByIDRequest(t *types.RespondActivityTaskCanceledByIDRequest) *apiv1.RespondActivityTaskCanceledByIDRequest { + if t == nil { + return nil + } + return &apiv1.RespondActivityTaskCanceledByIDRequest{ + Domain: t.Domain, + WorkflowExecution: FromWorkflowRunPair(t.WorkflowID, t.RunID), + ActivityId: t.ActivityID, + Details: FromPayload(t.Details), + Identity: t.Identity, + } +} + +func ToRespondActivityTaskCanceledByIDRequest(t *apiv1.RespondActivityTaskCanceledByIDRequest) *types.RespondActivityTaskCanceledByIDRequest { + if t == nil { + return nil + } + return &types.RespondActivityTaskCanceledByIDRequest{ + Domain: t.Domain, + WorkflowID: ToWorkflowID(t.WorkflowExecution), + RunID: ToRunID(t.WorkflowExecution), + ActivityID: t.ActivityId, + Details: ToPayload(t.Details), + Identity: t.Identity, + } +} + +func FromRespondActivityTaskCanceledRequest(t *types.RespondActivityTaskCanceledRequest) *apiv1.RespondActivityTaskCanceledRequest { + if t == nil { + return nil + } + return &apiv1.RespondActivityTaskCanceledRequest{ + TaskToken: t.TaskToken, + Details: FromPayload(t.Details), + Identity: t.Identity, + } +} + +func ToRespondActivityTaskCanceledRequest(t *apiv1.RespondActivityTaskCanceledRequest) *types.RespondActivityTaskCanceledRequest { + if t == nil { + return nil + } + return &types.RespondActivityTaskCanceledRequest{ + TaskToken: t.TaskToken, + Details: ToPayload(t.Details), + Identity: t.Identity, + } +} + +func FromRespondActivityTaskCompletedByIDRequest(t *types.RespondActivityTaskCompletedByIDRequest) *apiv1.RespondActivityTaskCompletedByIDRequest { + if t == nil { + return nil + } + return &apiv1.RespondActivityTaskCompletedByIDRequest{ + Domain: t.Domain, + WorkflowExecution: FromWorkflowRunPair(t.WorkflowID, t.RunID), + ActivityId: t.ActivityID, + Result: FromPayload(t.Result), + Identity: t.Identity, + } +} + +func ToRespondActivityTaskCompletedByIDRequest(t *apiv1.RespondActivityTaskCompletedByIDRequest) *types.RespondActivityTaskCompletedByIDRequest { + if t == nil { + return nil + } + return &types.RespondActivityTaskCompletedByIDRequest{ + Domain: t.Domain, + WorkflowID: ToWorkflowID(t.WorkflowExecution), + RunID: ToRunID(t.WorkflowExecution), + ActivityID: t.ActivityId, + Result: ToPayload(t.Result), + Identity: t.Identity, + } +} + +func FromRespondActivityTaskCompletedRequest(t *types.RespondActivityTaskCompletedRequest) *apiv1.RespondActivityTaskCompletedRequest { + if t == nil { + return nil + } + return &apiv1.RespondActivityTaskCompletedRequest{ + TaskToken: t.TaskToken, + Result: FromPayload(t.Result), + Identity: t.Identity, + } +} + +func ToRespondActivityTaskCompletedRequest(t *apiv1.RespondActivityTaskCompletedRequest) *types.RespondActivityTaskCompletedRequest { + if t == nil { + return nil + } + return &types.RespondActivityTaskCompletedRequest{ + TaskToken: t.TaskToken, + Result: ToPayload(t.Result), + Identity: t.Identity, + } +} + +func FromRespondActivityTaskFailedByIDRequest(t *types.RespondActivityTaskFailedByIDRequest) *apiv1.RespondActivityTaskFailedByIDRequest { + if t == nil { + return nil + } + return &apiv1.RespondActivityTaskFailedByIDRequest{ + Domain: t.Domain, + WorkflowExecution: FromWorkflowRunPair(t.WorkflowID, t.RunID), + ActivityId: t.ActivityID, + Failure: FromFailure(t.Reason, t.Details), + Identity: t.Identity, + } +} + +func ToRespondActivityTaskFailedByIDRequest(t *apiv1.RespondActivityTaskFailedByIDRequest) *types.RespondActivityTaskFailedByIDRequest { + if t == nil { + return nil + } + return &types.RespondActivityTaskFailedByIDRequest{ + Domain: t.Domain, + WorkflowID: ToWorkflowID(t.WorkflowExecution), + RunID: ToRunID(t.WorkflowExecution), + ActivityID: t.ActivityId, + Reason: ToFailureReason(t.Failure), + Details: ToFailureDetails(t.Failure), + Identity: t.Identity, + } +} + +func FromRespondActivityTaskFailedRequest(t *types.RespondActivityTaskFailedRequest) *apiv1.RespondActivityTaskFailedRequest { + if t == nil { + return nil + } + return &apiv1.RespondActivityTaskFailedRequest{ + TaskToken: t.TaskToken, + Failure: FromFailure(t.Reason, t.Details), + Identity: t.Identity, + } +} + +func ToRespondActivityTaskFailedRequest(t *apiv1.RespondActivityTaskFailedRequest) *types.RespondActivityTaskFailedRequest { + if t == nil { + return nil + } + return &types.RespondActivityTaskFailedRequest{ + TaskToken: t.TaskToken, + Reason: ToFailureReason(t.Failure), + Details: ToFailureDetails(t.Failure), + Identity: t.Identity, + } +} + +func FromRespondDecisionTaskCompletedRequest(t *types.RespondDecisionTaskCompletedRequest) *apiv1.RespondDecisionTaskCompletedRequest { + if t == nil { + return nil + } + return &apiv1.RespondDecisionTaskCompletedRequest{ + TaskToken: t.TaskToken, + Decisions: FromDecisionArray(t.Decisions), + ExecutionContext: t.ExecutionContext, + Identity: t.Identity, + StickyAttributes: FromStickyExecutionAttributes(t.StickyAttributes), + ReturnNewDecisionTask: t.ReturnNewDecisionTask, + ForceCreateNewDecisionTask: t.ForceCreateNewDecisionTask, + BinaryChecksum: t.BinaryChecksum, + QueryResults: FromWorkflowQueryResultMap(t.QueryResults), + } +} + +func ToRespondDecisionTaskCompletedRequest(t *apiv1.RespondDecisionTaskCompletedRequest) *types.RespondDecisionTaskCompletedRequest { + if t == nil { + return nil + } + return &types.RespondDecisionTaskCompletedRequest{ + TaskToken: t.TaskToken, + Decisions: ToDecisionArray(t.Decisions), + ExecutionContext: t.ExecutionContext, + Identity: t.Identity, + StickyAttributes: ToStickyExecutionAttributes(t.StickyAttributes), + ReturnNewDecisionTask: t.ReturnNewDecisionTask, + ForceCreateNewDecisionTask: t.ForceCreateNewDecisionTask, + BinaryChecksum: t.BinaryChecksum, + QueryResults: ToWorkflowQueryResultMap(t.QueryResults), + } +} + +func FromRespondDecisionTaskCompletedResponse(t *types.RespondDecisionTaskCompletedResponse) *apiv1.RespondDecisionTaskCompletedResponse { + if t == nil { + return nil + } + return &apiv1.RespondDecisionTaskCompletedResponse{ + DecisionTask: FromPollForDecisionTaskResponse(t.DecisionTask), + ActivitiesToDispatchLocally: FromActivityLocalDispatchInfoMap(t.ActivitiesToDispatchLocally), + } +} + +func ToRespondDecisionTaskCompletedResponse(t *apiv1.RespondDecisionTaskCompletedResponse) *types.RespondDecisionTaskCompletedResponse { + if t == nil { + return nil + } + return &types.RespondDecisionTaskCompletedResponse{ + DecisionTask: ToPollForDecisionTaskResponse(t.DecisionTask), + ActivitiesToDispatchLocally: ToActivityLocalDispatchInfoMap(t.ActivitiesToDispatchLocally), + } +} + +func FromRespondDecisionTaskFailedRequest(t *types.RespondDecisionTaskFailedRequest) *apiv1.RespondDecisionTaskFailedRequest { + if t == nil { + return nil + } + return &apiv1.RespondDecisionTaskFailedRequest{ + TaskToken: t.TaskToken, + Cause: FromDecisionTaskFailedCause(t.Cause), + Details: FromPayload(t.Details), + Identity: t.Identity, + BinaryChecksum: t.BinaryChecksum, + } +} + +func ToRespondDecisionTaskFailedRequest(t *apiv1.RespondDecisionTaskFailedRequest) *types.RespondDecisionTaskFailedRequest { + if t == nil { + return nil + } + return &types.RespondDecisionTaskFailedRequest{ + TaskToken: t.TaskToken, + Cause: ToDecisionTaskFailedCause(t.Cause), + Details: ToPayload(t.Details), + Identity: t.Identity, + BinaryChecksum: t.BinaryChecksum, + } +} + +func FromRespondQueryTaskCompletedRequest(t *types.RespondQueryTaskCompletedRequest) *apiv1.RespondQueryTaskCompletedRequest { + if t == nil { + return nil + } + return &apiv1.RespondQueryTaskCompletedRequest{ + TaskToken: t.TaskToken, + Result: &apiv1.WorkflowQueryResult{ + ResultType: FromQueryTaskCompletedType(t.CompletedType), + Answer: FromPayload(t.QueryResult), + ErrorMessage: t.ErrorMessage, + }, + WorkerVersionInfo: FromWorkerVersionInfo(t.WorkerVersionInfo), + } +} + +func ToRespondQueryTaskCompletedRequest(t *apiv1.RespondQueryTaskCompletedRequest) *types.RespondQueryTaskCompletedRequest { + if t == nil { + return nil + } + return &types.RespondQueryTaskCompletedRequest{ + TaskToken: t.TaskToken, + CompletedType: ToQueryTaskCompletedType(t.Result.ResultType), + QueryResult: ToPayload(t.Result.Answer), + ErrorMessage: t.Result.ErrorMessage, + WorkerVersionInfo: ToWorkerVersionInfo(t.WorkerVersionInfo), + } +} + +func FromQueryTaskCompletedType(t *types.QueryTaskCompletedType) apiv1.QueryResultType { + if t == nil { + return apiv1.QueryResultType_QUERY_RESULT_TYPE_INVALID + } + switch *t { + case types.QueryTaskCompletedTypeCompleted: + return apiv1.QueryResultType_QUERY_RESULT_TYPE_ANSWERED + case types.QueryTaskCompletedTypeFailed: + return apiv1.QueryResultType_QUERY_RESULT_TYPE_FAILED + } + panic("unexpected enum value") +} + +func ToQueryTaskCompletedType(t apiv1.QueryResultType) *types.QueryTaskCompletedType { + switch t { + case apiv1.QueryResultType_QUERY_RESULT_TYPE_INVALID: + return nil + case apiv1.QueryResultType_QUERY_RESULT_TYPE_ANSWERED: + return types.QueryTaskCompletedTypeCompleted.Ptr() + case apiv1.QueryResultType_QUERY_RESULT_TYPE_FAILED: + return types.QueryTaskCompletedTypeFailed.Ptr() + } + panic("unexpected enum value") +} + +func FromRetryPolicy(t *types.RetryPolicy) *apiv1.RetryPolicy { + if t == nil { + return nil + } + return &apiv1.RetryPolicy{ + InitialInterval: secondsToDuration(common.Int32Ptr(t.InitialIntervalInSeconds)), + BackoffCoefficient: t.BackoffCoefficient, + MaximumInterval: secondsToDuration(common.Int32Ptr(t.MaximumIntervalInSeconds)), + MaximumAttempts: t.MaximumAttempts, + NonRetryableErrorReasons: t.NonRetriableErrorReasons, + ExpirationInterval: secondsToDuration(common.Int32Ptr(t.ExpirationIntervalInSeconds)), + } +} + +func ToRetryPolicy(t *apiv1.RetryPolicy) *types.RetryPolicy { + if t == nil { + return nil + } + return &types.RetryPolicy{ + InitialIntervalInSeconds: common.Int32Default(durationToSeconds(t.InitialInterval)), + BackoffCoefficient: t.BackoffCoefficient, + MaximumIntervalInSeconds: common.Int32Default(durationToSeconds(t.MaximumInterval)), + MaximumAttempts: t.MaximumAttempts, + NonRetriableErrorReasons: t.NonRetryableErrorReasons, + ExpirationIntervalInSeconds: common.Int32Default(durationToSeconds(t.ExpirationInterval)), + } +} + +func FromScanWorkflowExecutionsRequest(t *types.ListWorkflowExecutionsRequest) *apiv1.ScanWorkflowExecutionsRequest { + if t == nil { + return nil + } + return &apiv1.ScanWorkflowExecutionsRequest{ + Domain: t.Domain, + PageSize: t.PageSize, + NextPageToken: t.NextPageToken, + Query: t.Query, + } +} + +func ToScanWorkflowExecutionsRequest(t *apiv1.ScanWorkflowExecutionsRequest) *types.ListWorkflowExecutionsRequest { + if t == nil { + return nil + } + return &types.ListWorkflowExecutionsRequest{ + Domain: t.Domain, + PageSize: t.PageSize, + NextPageToken: t.NextPageToken, + Query: t.Query, + } +} + +func FromScanWorkflowExecutionsResponse(t *types.ListWorkflowExecutionsResponse) *apiv1.ScanWorkflowExecutionsResponse { + if t == nil { + return nil + } + return &apiv1.ScanWorkflowExecutionsResponse{ + Executions: FromWorkflowExecutionInfoArray(t.Executions), + NextPageToken: t.NextPageToken, + } +} + +func ToScanWorkflowExecutionsResponse(t *apiv1.ScanWorkflowExecutionsResponse) *types.ListWorkflowExecutionsResponse { + if t == nil { + return nil + } + return &types.ListWorkflowExecutionsResponse{ + Executions: ToWorkflowExecutionInfoArray(t.Executions), + NextPageToken: t.NextPageToken, + } +} + +func FromScheduleActivityTaskDecisionAttributes(t *types.ScheduleActivityTaskDecisionAttributes) *apiv1.ScheduleActivityTaskDecisionAttributes { + if t == nil { + return nil + } + return &apiv1.ScheduleActivityTaskDecisionAttributes{ + ActivityId: t.ActivityID, + ActivityType: FromActivityType(t.ActivityType), + Domain: t.Domain, + TaskList: FromTaskList(t.TaskList), + Input: FromPayload(t.Input), + ScheduleToCloseTimeout: secondsToDuration(t.ScheduleToCloseTimeoutSeconds), + ScheduleToStartTimeout: secondsToDuration(t.ScheduleToStartTimeoutSeconds), + StartToCloseTimeout: secondsToDuration(t.StartToCloseTimeoutSeconds), + HeartbeatTimeout: secondsToDuration(t.HeartbeatTimeoutSeconds), + RetryPolicy: FromRetryPolicy(t.RetryPolicy), + Header: FromHeader(t.Header), + RequestLocalDispatch: t.RequestLocalDispatch, + } +} + +func ToScheduleActivityTaskDecisionAttributes(t *apiv1.ScheduleActivityTaskDecisionAttributes) *types.ScheduleActivityTaskDecisionAttributes { + if t == nil { + return nil + } + return &types.ScheduleActivityTaskDecisionAttributes{ + ActivityID: t.ActivityId, + ActivityType: ToActivityType(t.ActivityType), + Domain: t.Domain, + TaskList: ToTaskList(t.TaskList), + Input: ToPayload(t.Input), + ScheduleToCloseTimeoutSeconds: durationToSeconds(t.ScheduleToCloseTimeout), + ScheduleToStartTimeoutSeconds: durationToSeconds(t.ScheduleToStartTimeout), + StartToCloseTimeoutSeconds: durationToSeconds(t.StartToCloseTimeout), + HeartbeatTimeoutSeconds: durationToSeconds(t.HeartbeatTimeout), + RetryPolicy: ToRetryPolicy(t.RetryPolicy), + Header: ToHeader(t.Header), + RequestLocalDispatch: t.RequestLocalDispatch, + } +} + +func FromSearchAttributes(t *types.SearchAttributes) *apiv1.SearchAttributes { + if t == nil { + return nil + } + return &apiv1.SearchAttributes{ + IndexedFields: FromPayloadMap(t.IndexedFields), + } +} + +func ToSearchAttributes(t *apiv1.SearchAttributes) *types.SearchAttributes { + if t == nil { + return nil + } + return &types.SearchAttributes{ + IndexedFields: ToPayloadMap(t.IndexedFields), + } +} + +func FromSignalExternalWorkflowExecutionDecisionAttributes(t *types.SignalExternalWorkflowExecutionDecisionAttributes) *apiv1.SignalExternalWorkflowExecutionDecisionAttributes { + if t == nil { + return nil + } + return &apiv1.SignalExternalWorkflowExecutionDecisionAttributes{ + Domain: t.Domain, + WorkflowExecution: FromWorkflowExecution(t.Execution), + SignalName: t.SignalName, + Input: FromPayload(t.Input), + Control: t.Control, + ChildWorkflowOnly: t.ChildWorkflowOnly, + } +} + +func ToSignalExternalWorkflowExecutionDecisionAttributes(t *apiv1.SignalExternalWorkflowExecutionDecisionAttributes) *types.SignalExternalWorkflowExecutionDecisionAttributes { + if t == nil { + return nil + } + return &types.SignalExternalWorkflowExecutionDecisionAttributes{ + Domain: t.Domain, + Execution: ToWorkflowExecution(t.WorkflowExecution), + SignalName: t.SignalName, + Input: ToPayload(t.Input), + Control: t.Control, + ChildWorkflowOnly: t.ChildWorkflowOnly, + } +} + +func FromSignalExternalWorkflowExecutionFailedCause(t *types.SignalExternalWorkflowExecutionFailedCause) apiv1.SignalExternalWorkflowExecutionFailedCause { + if t == nil { + return apiv1.SignalExternalWorkflowExecutionFailedCause_SIGNAL_EXTERNAL_WORKFLOW_EXECUTION_FAILED_CAUSE_INVALID + } + switch *t { + case types.SignalExternalWorkflowExecutionFailedCauseUnknownExternalWorkflowExecution: + return apiv1.SignalExternalWorkflowExecutionFailedCause_SIGNAL_EXTERNAL_WORKFLOW_EXECUTION_FAILED_CAUSE_UNKNOWN_EXTERNAL_WORKFLOW_EXECUTION + } + panic("unexpected enum value") +} + +func ToSignalExternalWorkflowExecutionFailedCause(t apiv1.SignalExternalWorkflowExecutionFailedCause) *types.SignalExternalWorkflowExecutionFailedCause { + switch t { + case apiv1.SignalExternalWorkflowExecutionFailedCause_SIGNAL_EXTERNAL_WORKFLOW_EXECUTION_FAILED_CAUSE_INVALID: + return nil + case apiv1.SignalExternalWorkflowExecutionFailedCause_SIGNAL_EXTERNAL_WORKFLOW_EXECUTION_FAILED_CAUSE_UNKNOWN_EXTERNAL_WORKFLOW_EXECUTION: + return types.SignalExternalWorkflowExecutionFailedCauseUnknownExternalWorkflowExecution.Ptr() + } + panic("unexpected enum value") +} + +func FromSignalExternalWorkflowExecutionFailedEventAttributes(t *types.SignalExternalWorkflowExecutionFailedEventAttributes) *apiv1.SignalExternalWorkflowExecutionFailedEventAttributes { + if t == nil { + return nil + } + return &apiv1.SignalExternalWorkflowExecutionFailedEventAttributes{ + Cause: FromSignalExternalWorkflowExecutionFailedCause(t.Cause), + DecisionTaskCompletedEventId: t.DecisionTaskCompletedEventID, + Domain: t.Domain, + WorkflowExecution: FromWorkflowExecution(t.WorkflowExecution), + InitiatedEventId: t.InitiatedEventID, + Control: t.Control, + } +} + +func ToSignalExternalWorkflowExecutionFailedEventAttributes(t *apiv1.SignalExternalWorkflowExecutionFailedEventAttributes) *types.SignalExternalWorkflowExecutionFailedEventAttributes { + if t == nil { + return nil + } + return &types.SignalExternalWorkflowExecutionFailedEventAttributes{ + Cause: ToSignalExternalWorkflowExecutionFailedCause(t.Cause), + DecisionTaskCompletedEventID: t.DecisionTaskCompletedEventId, + Domain: t.Domain, + WorkflowExecution: ToWorkflowExecution(t.WorkflowExecution), + InitiatedEventID: t.InitiatedEventId, + Control: t.Control, + } +} + +func FromSignalExternalWorkflowExecutionInitiatedEventAttributes(t *types.SignalExternalWorkflowExecutionInitiatedEventAttributes) *apiv1.SignalExternalWorkflowExecutionInitiatedEventAttributes { + if t == nil { + return nil + } + return &apiv1.SignalExternalWorkflowExecutionInitiatedEventAttributes{ + DecisionTaskCompletedEventId: t.DecisionTaskCompletedEventID, + Domain: t.Domain, + WorkflowExecution: FromWorkflowExecution(t.WorkflowExecution), + SignalName: t.SignalName, + Input: FromPayload(t.Input), + Control: t.Control, + ChildWorkflowOnly: t.ChildWorkflowOnly, + } +} + +func ToSignalExternalWorkflowExecutionInitiatedEventAttributes(t *apiv1.SignalExternalWorkflowExecutionInitiatedEventAttributes) *types.SignalExternalWorkflowExecutionInitiatedEventAttributes { + if t == nil { + return nil + } + return &types.SignalExternalWorkflowExecutionInitiatedEventAttributes{ + DecisionTaskCompletedEventID: t.DecisionTaskCompletedEventId, + Domain: t.Domain, + WorkflowExecution: ToWorkflowExecution(t.WorkflowExecution), + SignalName: t.SignalName, + Input: ToPayload(t.Input), + Control: t.Control, + ChildWorkflowOnly: t.ChildWorkflowOnly, + } +} + +func FromSignalWithStartWorkflowExecutionRequest(t *types.SignalWithStartWorkflowExecutionRequest) *apiv1.SignalWithStartWorkflowExecutionRequest { + if t == nil { + return nil + } + return &apiv1.SignalWithStartWorkflowExecutionRequest{ + StartRequest: &apiv1.StartWorkflowExecutionRequest{ + Domain: t.Domain, + WorkflowId: t.WorkflowID, + WorkflowType: FromWorkflowType(t.WorkflowType), + TaskList: FromTaskList(t.TaskList), + Input: FromPayload(t.Input), + ExecutionStartToCloseTimeout: secondsToDuration(t.ExecutionStartToCloseTimeoutSeconds), + TaskStartToCloseTimeout: secondsToDuration(t.TaskStartToCloseTimeoutSeconds), + Identity: t.Identity, + RequestId: t.RequestID, + WorkflowIdReusePolicy: FromWorkflowIDReusePolicy(t.WorkflowIDReusePolicy), + RetryPolicy: FromRetryPolicy(t.RetryPolicy), + CronSchedule: t.CronSchedule, + Memo: FromMemo(t.Memo), + SearchAttributes: FromSearchAttributes(t.SearchAttributes), + Header: FromHeader(t.Header), + }, + SignalName: t.SignalName, + SignalInput: FromPayload(t.SignalInput), + Control: t.Control, + } +} + +func ToSignalWithStartWorkflowExecutionRequest(t *apiv1.SignalWithStartWorkflowExecutionRequest) *types.SignalWithStartWorkflowExecutionRequest { + if t == nil { + return nil + } + return &types.SignalWithStartWorkflowExecutionRequest{ + Domain: t.StartRequest.Domain, + WorkflowID: t.StartRequest.WorkflowId, + WorkflowType: ToWorkflowType(t.StartRequest.WorkflowType), + TaskList: ToTaskList(t.StartRequest.TaskList), + Input: ToPayload(t.StartRequest.Input), + ExecutionStartToCloseTimeoutSeconds: durationToSeconds(t.StartRequest.ExecutionStartToCloseTimeout), + TaskStartToCloseTimeoutSeconds: durationToSeconds(t.StartRequest.TaskStartToCloseTimeout), + Identity: t.StartRequest.Identity, + RequestID: t.StartRequest.RequestId, + WorkflowIDReusePolicy: ToWorkflowIDReusePolicy(t.StartRequest.WorkflowIdReusePolicy), + SignalName: t.SignalName, + SignalInput: ToPayload(t.SignalInput), + Control: t.Control, + RetryPolicy: ToRetryPolicy(t.StartRequest.RetryPolicy), + CronSchedule: t.StartRequest.CronSchedule, + Memo: ToMemo(t.StartRequest.Memo), + SearchAttributes: ToSearchAttributes(t.StartRequest.SearchAttributes), + Header: ToHeader(t.StartRequest.Header), + } +} + +func FromSignalWithStartWorkflowExecutionResponse(t *types.StartWorkflowExecutionResponse) *apiv1.SignalWithStartWorkflowExecutionResponse { + if t == nil { + return nil + } + return &apiv1.SignalWithStartWorkflowExecutionResponse{ + RunId: t.RunID, + } +} + +func ToSignalWithStartWorkflowExecutionResponse(t *apiv1.SignalWithStartWorkflowExecutionResponse) *types.StartWorkflowExecutionResponse { + if t == nil { + return nil + } + return &types.StartWorkflowExecutionResponse{ + RunID: t.RunId, + } +} + +func FromSignalWorkflowExecutionRequest(t *types.SignalWorkflowExecutionRequest) *apiv1.SignalWorkflowExecutionRequest { + if t == nil { + return nil + } + return &apiv1.SignalWorkflowExecutionRequest{ + Domain: t.Domain, + WorkflowExecution: FromWorkflowExecution(t.WorkflowExecution), + SignalName: t.SignalName, + SignalInput: FromPayload(t.Input), + Identity: t.Identity, + RequestId: t.RequestID, + Control: t.Control, + } +} + +func ToSignalWorkflowExecutionRequest(t *apiv1.SignalWorkflowExecutionRequest) *types.SignalWorkflowExecutionRequest { + if t == nil { + return nil + } + return &types.SignalWorkflowExecutionRequest{ + Domain: t.Domain, + WorkflowExecution: ToWorkflowExecution(t.WorkflowExecution), + SignalName: t.SignalName, + Input: ToPayload(t.SignalInput), + Identity: t.Identity, + RequestID: t.RequestId, + Control: t.Control, + } +} + +func FromStartChildWorkflowExecutionDecisionAttributes(t *types.StartChildWorkflowExecutionDecisionAttributes) *apiv1.StartChildWorkflowExecutionDecisionAttributes { + if t == nil { + return nil + } + return &apiv1.StartChildWorkflowExecutionDecisionAttributes{ + Domain: t.Domain, + WorkflowId: t.WorkflowID, + WorkflowType: FromWorkflowType(t.WorkflowType), + TaskList: FromTaskList(t.TaskList), + Input: FromPayload(t.Input), + ExecutionStartToCloseTimeout: secondsToDuration(t.ExecutionStartToCloseTimeoutSeconds), + TaskStartToCloseTimeout: secondsToDuration(t.TaskStartToCloseTimeoutSeconds), + ParentClosePolicy: FromParentClosePolicy(t.ParentClosePolicy), + Control: t.Control, + WorkflowIdReusePolicy: FromWorkflowIDReusePolicy(t.WorkflowIDReusePolicy), + RetryPolicy: FromRetryPolicy(t.RetryPolicy), + CronSchedule: t.CronSchedule, + Header: FromHeader(t.Header), + Memo: FromMemo(t.Memo), + SearchAttributes: FromSearchAttributes(t.SearchAttributes), + } +} + +func ToStartChildWorkflowExecutionDecisionAttributes(t *apiv1.StartChildWorkflowExecutionDecisionAttributes) *types.StartChildWorkflowExecutionDecisionAttributes { + if t == nil { + return nil + } + return &types.StartChildWorkflowExecutionDecisionAttributes{ + Domain: t.Domain, + WorkflowID: t.WorkflowId, + WorkflowType: ToWorkflowType(t.WorkflowType), + TaskList: ToTaskList(t.TaskList), + Input: ToPayload(t.Input), + ExecutionStartToCloseTimeoutSeconds: durationToSeconds(t.ExecutionStartToCloseTimeout), + TaskStartToCloseTimeoutSeconds: durationToSeconds(t.TaskStartToCloseTimeout), + ParentClosePolicy: ToParentClosePolicy(t.ParentClosePolicy), + Control: t.Control, + WorkflowIDReusePolicy: ToWorkflowIDReusePolicy(t.WorkflowIdReusePolicy), + RetryPolicy: ToRetryPolicy(t.RetryPolicy), + CronSchedule: t.CronSchedule, + Header: ToHeader(t.Header), + Memo: ToMemo(t.Memo), + SearchAttributes: ToSearchAttributes(t.SearchAttributes), + } +} + +func FromStartChildWorkflowExecutionFailedEventAttributes(t *types.StartChildWorkflowExecutionFailedEventAttributes) *apiv1.StartChildWorkflowExecutionFailedEventAttributes { + if t == nil { + return nil + } + return &apiv1.StartChildWorkflowExecutionFailedEventAttributes{ + Domain: t.Domain, + WorkflowId: t.WorkflowID, + WorkflowType: FromWorkflowType(t.WorkflowType), + Cause: FromChildWorkflowExecutionFailedCause(t.Cause), + Control: t.Control, + InitiatedEventId: t.InitiatedEventID, + DecisionTaskCompletedEventId: t.DecisionTaskCompletedEventID, + } +} + +func ToStartChildWorkflowExecutionFailedEventAttributes(t *apiv1.StartChildWorkflowExecutionFailedEventAttributes) *types.StartChildWorkflowExecutionFailedEventAttributes { + if t == nil { + return nil + } + return &types.StartChildWorkflowExecutionFailedEventAttributes{ + Domain: t.Domain, + WorkflowID: t.WorkflowId, + WorkflowType: ToWorkflowType(t.WorkflowType), + Cause: ToChildWorkflowExecutionFailedCause(t.Cause), + Control: t.Control, + InitiatedEventID: t.InitiatedEventId, + DecisionTaskCompletedEventID: t.DecisionTaskCompletedEventId, + } +} + +func FromStartChildWorkflowExecutionInitiatedEventAttributes(t *types.StartChildWorkflowExecutionInitiatedEventAttributes) *apiv1.StartChildWorkflowExecutionInitiatedEventAttributes { + if t == nil { + return nil + } + return &apiv1.StartChildWorkflowExecutionInitiatedEventAttributes{ + Domain: t.Domain, + WorkflowId: t.WorkflowID, + WorkflowType: FromWorkflowType(t.WorkflowType), + TaskList: FromTaskList(t.TaskList), + Input: FromPayload(t.Input), + ExecutionStartToCloseTimeout: secondsToDuration(t.ExecutionStartToCloseTimeoutSeconds), + TaskStartToCloseTimeout: secondsToDuration(t.TaskStartToCloseTimeoutSeconds), + ParentClosePolicy: FromParentClosePolicy(t.ParentClosePolicy), + Control: t.Control, + DecisionTaskCompletedEventId: t.DecisionTaskCompletedEventID, + WorkflowIdReusePolicy: FromWorkflowIDReusePolicy(t.WorkflowIDReusePolicy), + RetryPolicy: FromRetryPolicy(t.RetryPolicy), + CronSchedule: t.CronSchedule, + Header: FromHeader(t.Header), + Memo: FromMemo(t.Memo), + SearchAttributes: FromSearchAttributes(t.SearchAttributes), + } +} + +func ToStartChildWorkflowExecutionInitiatedEventAttributes(t *apiv1.StartChildWorkflowExecutionInitiatedEventAttributes) *types.StartChildWorkflowExecutionInitiatedEventAttributes { + if t == nil { + return nil + } + return &types.StartChildWorkflowExecutionInitiatedEventAttributes{ + Domain: t.Domain, + WorkflowID: t.WorkflowId, + WorkflowType: ToWorkflowType(t.WorkflowType), + TaskList: ToTaskList(t.TaskList), + Input: ToPayload(t.Input), + ExecutionStartToCloseTimeoutSeconds: durationToSeconds(t.ExecutionStartToCloseTimeout), + TaskStartToCloseTimeoutSeconds: durationToSeconds(t.TaskStartToCloseTimeout), + ParentClosePolicy: ToParentClosePolicy(t.ParentClosePolicy), + Control: t.Control, + DecisionTaskCompletedEventID: t.DecisionTaskCompletedEventId, + WorkflowIDReusePolicy: ToWorkflowIDReusePolicy(t.WorkflowIdReusePolicy), + RetryPolicy: ToRetryPolicy(t.RetryPolicy), + CronSchedule: t.CronSchedule, + Header: ToHeader(t.Header), + Memo: ToMemo(t.Memo), + SearchAttributes: ToSearchAttributes(t.SearchAttributes), + } +} + +func FromStartTimeFilter(t *types.StartTimeFilter) *apiv1.StartTimeFilter { + if t == nil { + return nil + } + return &apiv1.StartTimeFilter{ + EarliestTime: unixNanoToTime(t.EarliestTime), + LatestTime: unixNanoToTime(t.LatestTime), + } +} + +func ToStartTimeFilter(t *apiv1.StartTimeFilter) *types.StartTimeFilter { + if t == nil { + return nil + } + return &types.StartTimeFilter{ + EarliestTime: timeToUnixNano(t.EarliestTime), + LatestTime: timeToUnixNano(t.LatestTime), + } +} + +func FromStartTimerDecisionAttributes(t *types.StartTimerDecisionAttributes) *apiv1.StartTimerDecisionAttributes { + if t == nil { + return nil + } + return &apiv1.StartTimerDecisionAttributes{ + TimerId: t.TimerID, + StartToFireTimeout: secondsToDuration(int64To32(t.StartToFireTimeoutSeconds)), + } +} + +func ToStartTimerDecisionAttributes(t *apiv1.StartTimerDecisionAttributes) *types.StartTimerDecisionAttributes { + if t == nil { + return nil + } + return &types.StartTimerDecisionAttributes{ + TimerID: t.TimerId, + StartToFireTimeoutSeconds: int32To64(durationToSeconds(t.StartToFireTimeout)), + } +} + +func FromStartWorkflowExecutionRequest(t *types.StartWorkflowExecutionRequest) *apiv1.StartWorkflowExecutionRequest { + if t == nil { + return nil + } + return &apiv1.StartWorkflowExecutionRequest{ + Domain: t.Domain, + WorkflowId: t.WorkflowID, + WorkflowType: FromWorkflowType(t.WorkflowType), + TaskList: FromTaskList(t.TaskList), + Input: FromPayload(t.Input), + ExecutionStartToCloseTimeout: secondsToDuration(t.ExecutionStartToCloseTimeoutSeconds), + TaskStartToCloseTimeout: secondsToDuration(t.TaskStartToCloseTimeoutSeconds), + Identity: t.Identity, + RequestId: t.RequestID, + WorkflowIdReusePolicy: FromWorkflowIDReusePolicy(t.WorkflowIDReusePolicy), + RetryPolicy: FromRetryPolicy(t.RetryPolicy), + CronSchedule: t.CronSchedule, + Memo: FromMemo(t.Memo), + SearchAttributes: FromSearchAttributes(t.SearchAttributes), + Header: FromHeader(t.Header), + } +} + +func ToStartWorkflowExecutionRequest(t *apiv1.StartWorkflowExecutionRequest) *types.StartWorkflowExecutionRequest { + if t == nil { + return nil + } + return &types.StartWorkflowExecutionRequest{ + Domain: t.Domain, + WorkflowID: t.WorkflowId, + WorkflowType: ToWorkflowType(t.WorkflowType), + TaskList: ToTaskList(t.TaskList), + Input: ToPayload(t.Input), + ExecutionStartToCloseTimeoutSeconds: durationToSeconds(t.ExecutionStartToCloseTimeout), + TaskStartToCloseTimeoutSeconds: durationToSeconds(t.TaskStartToCloseTimeout), + Identity: t.Identity, + RequestID: t.RequestId, + WorkflowIDReusePolicy: ToWorkflowIDReusePolicy(t.WorkflowIdReusePolicy), + RetryPolicy: ToRetryPolicy(t.RetryPolicy), + CronSchedule: t.CronSchedule, + Memo: ToMemo(t.Memo), + SearchAttributes: ToSearchAttributes(t.SearchAttributes), + Header: ToHeader(t.Header), + } +} + +func FromStartWorkflowExecutionResponse(t *types.StartWorkflowExecutionResponse) *apiv1.StartWorkflowExecutionResponse { + if t == nil { + return nil + } + return &apiv1.StartWorkflowExecutionResponse{ + RunId: t.RunID, + } +} + +func ToStartWorkflowExecutionResponse(t *apiv1.StartWorkflowExecutionResponse) *types.StartWorkflowExecutionResponse { + if t == nil { + return nil + } + return &types.StartWorkflowExecutionResponse{ + RunID: t.RunId, + } +} + +func FromStatusFilter(t *types.WorkflowExecutionCloseStatus) *apiv1.StatusFilter { + if t == nil { + return nil + } + return &apiv1.StatusFilter{ + Status: FromWorkflowExecutionCloseStatus(t), + } +} + +func ToStatusFilter(t *apiv1.StatusFilter) *types.WorkflowExecutionCloseStatus { + if t == nil { + return nil + } + return ToWorkflowExecutionCloseStatus(t.Status) +} + +func FromStickyExecutionAttributes(t *types.StickyExecutionAttributes) *apiv1.StickyExecutionAttributes { + if t == nil { + return nil + } + return &apiv1.StickyExecutionAttributes{ + WorkerTaskList: FromTaskList(t.WorkerTaskList), + ScheduleToStartTimeout: secondsToDuration(t.ScheduleToStartTimeoutSeconds), + } +} + +func ToStickyExecutionAttributes(t *apiv1.StickyExecutionAttributes) *types.StickyExecutionAttributes { + if t == nil { + return nil + } + return &types.StickyExecutionAttributes{ + WorkerTaskList: ToTaskList(t.WorkerTaskList), + ScheduleToStartTimeoutSeconds: durationToSeconds(t.ScheduleToStartTimeout), + } +} + +func FromSupportedClientVersions(t *types.SupportedClientVersions) *apiv1.SupportedClientVersions { + if t == nil { + return nil + } + return &apiv1.SupportedClientVersions{ + GoSdk: t.GoSdk, + JavaSdk: t.JavaSdk, + } +} + +func ToSupportedClientVersions(t *apiv1.SupportedClientVersions) *types.SupportedClientVersions { + if t == nil { + return nil + } + return &types.SupportedClientVersions{ + GoSdk: t.GoSdk, + JavaSdk: t.JavaSdk, + } +} + +func FromTaskIDBlock(t *types.TaskIDBlock) *apiv1.TaskIDBlock { + if t == nil { + return nil + } + return &apiv1.TaskIDBlock{ + StartId: t.StartID, + EndId: t.EndID, + } +} + +func ToTaskIDBlock(t *apiv1.TaskIDBlock) *types.TaskIDBlock { + if t == nil { + return nil + } + return &types.TaskIDBlock{ + StartID: t.StartId, + EndID: t.EndId, + } +} + +func FromTaskList(t *types.TaskList) *apiv1.TaskList { + if t == nil { + return nil + } + return &apiv1.TaskList{ + Name: t.Name, + Kind: FromTaskListKind(t.Kind), + } +} + +func ToTaskList(t *apiv1.TaskList) *types.TaskList { + if t == nil { + return nil + } + return &types.TaskList{ + Name: t.Name, + Kind: ToTaskListKind(t.Kind), + } +} + +func FromTaskListKind(t *types.TaskListKind) apiv1.TaskListKind { + if t == nil { + return apiv1.TaskListKind_TASK_LIST_KIND_INVALID + } + switch *t { + case types.TaskListKindNormal: + return apiv1.TaskListKind_TASK_LIST_KIND_NORMAL + case types.TaskListKindSticky: + return apiv1.TaskListKind_TASK_LIST_KIND_STICKY + } + panic("unexpected enum value") +} + +func ToTaskListKind(t apiv1.TaskListKind) *types.TaskListKind { + switch t { + case apiv1.TaskListKind_TASK_LIST_KIND_INVALID: + return nil + case apiv1.TaskListKind_TASK_LIST_KIND_NORMAL: + return types.TaskListKindNormal.Ptr() + case apiv1.TaskListKind_TASK_LIST_KIND_STICKY: + return types.TaskListKindSticky.Ptr() + } + panic("unexpected enum value") +} + +func FromTaskListMetadata(t *types.TaskListMetadata) *apiv1.TaskListMetadata { + if t == nil { + return nil + } + return &apiv1.TaskListMetadata{ + MaxTasksPerSecond: fromDoubleValue(t.MaxTasksPerSecond), + } +} + +func ToTaskListMetadata(t *apiv1.TaskListMetadata) *types.TaskListMetadata { + if t == nil { + return nil + } + return &types.TaskListMetadata{ + MaxTasksPerSecond: toDoubleValue(t.MaxTasksPerSecond), + } +} + +func FromTaskListPartitionMetadata(t *types.TaskListPartitionMetadata) *apiv1.TaskListPartitionMetadata { + if t == nil { + return nil + } + return &apiv1.TaskListPartitionMetadata{ + Key: t.Key, + OwnerHostName: t.OwnerHostName, + } +} + +func ToTaskListPartitionMetadata(t *apiv1.TaskListPartitionMetadata) *types.TaskListPartitionMetadata { + if t == nil { + return nil + } + return &types.TaskListPartitionMetadata{ + Key: t.Key, + OwnerHostName: t.OwnerHostName, + } +} + +func FromTaskListStatus(t *types.TaskListStatus) *apiv1.TaskListStatus { + if t == nil { + return nil + } + return &apiv1.TaskListStatus{ + BacklogCountHint: t.BacklogCountHint, + ReadLevel: t.ReadLevel, + AckLevel: t.AckLevel, + RatePerSecond: t.RatePerSecond, + TaskIdBlock: FromTaskIDBlock(t.TaskIDBlock), + } +} + +func ToTaskListStatus(t *apiv1.TaskListStatus) *types.TaskListStatus { + if t == nil { + return nil + } + return &types.TaskListStatus{ + BacklogCountHint: t.BacklogCountHint, + ReadLevel: t.ReadLevel, + AckLevel: t.AckLevel, + RatePerSecond: t.RatePerSecond, + TaskIDBlock: ToTaskIDBlock(t.TaskIdBlock), + } +} + +func FromTaskListType(t *types.TaskListType) apiv1.TaskListType { + if t == nil { + return apiv1.TaskListType_TASK_LIST_TYPE_INVALID + } + switch *t { + case types.TaskListTypeDecision: + return apiv1.TaskListType_TASK_LIST_TYPE_DECISION + case types.TaskListTypeActivity: + return apiv1.TaskListType_TASK_LIST_TYPE_ACTIVITY + } + panic("unexpected enum value") +} + +func ToTaskListType(t apiv1.TaskListType) *types.TaskListType { + switch t { + case apiv1.TaskListType_TASK_LIST_TYPE_INVALID: + return nil + case apiv1.TaskListType_TASK_LIST_TYPE_DECISION: + return types.TaskListTypeDecision.Ptr() + case apiv1.TaskListType_TASK_LIST_TYPE_ACTIVITY: + return types.TaskListTypeActivity.Ptr() + } + panic("unexpected enum value") +} + +func FromTerminateWorkflowExecutionRequest(t *types.TerminateWorkflowExecutionRequest) *apiv1.TerminateWorkflowExecutionRequest { + if t == nil { + return nil + } + return &apiv1.TerminateWorkflowExecutionRequest{ + Domain: t.Domain, + WorkflowExecution: FromWorkflowExecution(t.WorkflowExecution), + Reason: t.Reason, + Details: FromPayload(t.Details), + Identity: t.Identity, + } +} + +func ToTerminateWorkflowExecutionRequest(t *apiv1.TerminateWorkflowExecutionRequest) *types.TerminateWorkflowExecutionRequest { + if t == nil { + return nil + } + return &types.TerminateWorkflowExecutionRequest{ + Domain: t.Domain, + WorkflowExecution: ToWorkflowExecution(t.WorkflowExecution), + Reason: t.Reason, + Details: ToPayload(t.Details), + Identity: t.Identity, + } +} + +func FromTimeoutType(t *types.TimeoutType) apiv1.TimeoutType { + if t == nil { + return apiv1.TimeoutType_TIMEOUT_TYPE_INVALID + } + switch *t { + case types.TimeoutTypeStartToClose: + return apiv1.TimeoutType_TIMEOUT_TYPE_START_TO_CLOSE + case types.TimeoutTypeScheduleToStart: + return apiv1.TimeoutType_TIMEOUT_TYPE_SCHEDULE_TO_START + case types.TimeoutTypeScheduleToClose: + return apiv1.TimeoutType_TIMEOUT_TYPE_SCHEDULE_TO_CLOSE + case types.TimeoutTypeHeartbeat: + return apiv1.TimeoutType_TIMEOUT_TYPE_HEARTBEAT + } + panic("unexpected enum value") +} + +func ToTimeoutType(t apiv1.TimeoutType) *types.TimeoutType { + switch t { + case apiv1.TimeoutType_TIMEOUT_TYPE_INVALID: + return nil + case apiv1.TimeoutType_TIMEOUT_TYPE_START_TO_CLOSE: + return types.TimeoutTypeStartToClose.Ptr() + case apiv1.TimeoutType_TIMEOUT_TYPE_SCHEDULE_TO_START: + return types.TimeoutTypeScheduleToStart.Ptr() + case apiv1.TimeoutType_TIMEOUT_TYPE_SCHEDULE_TO_CLOSE: + return types.TimeoutTypeScheduleToClose.Ptr() + case apiv1.TimeoutType_TIMEOUT_TYPE_HEARTBEAT: + return types.TimeoutTypeHeartbeat.Ptr() + } + panic("unexpected enum value") +} + +func FromDecisionTaskTimedOutCause(t *types.DecisionTaskTimedOutCause) apiv1.DecisionTaskTimedOutCause { + if t == nil { + return apiv1.DecisionTaskTimedOutCause_DECISION_TASK_TIMED_OUT_CAUSE_INVALID + } + switch *t { + case types.DecisionTaskTimedOutCauseTimeout: + return apiv1.DecisionTaskTimedOutCause_DECISION_TASK_TIMED_OUT_CAUSE_TIMEOUT + case types.DecisionTaskTimedOutCauseReset: + return apiv1.DecisionTaskTimedOutCause_DECISION_TASK_TIMED_OUT_CAUSE_RESET + } + panic("unexpected enum value") +} + +func ToDecisionTaskTimedOutCause(t apiv1.DecisionTaskTimedOutCause) *types.DecisionTaskTimedOutCause { + switch t { + case apiv1.DecisionTaskTimedOutCause_DECISION_TASK_TIMED_OUT_CAUSE_INVALID: + return nil + case apiv1.DecisionTaskTimedOutCause_DECISION_TASK_TIMED_OUT_CAUSE_TIMEOUT: + return types.DecisionTaskTimedOutCauseTimeout.Ptr() + case apiv1.DecisionTaskTimedOutCause_DECISION_TASK_TIMED_OUT_CAUSE_RESET: + return types.DecisionTaskTimedOutCauseReset.Ptr() + } + panic("unexpected enum value") +} + +func FromTimerCanceledEventAttributes(t *types.TimerCanceledEventAttributes) *apiv1.TimerCanceledEventAttributes { + if t == nil { + return nil + } + return &apiv1.TimerCanceledEventAttributes{ + TimerId: t.TimerID, + StartedEventId: t.StartedEventID, + DecisionTaskCompletedEventId: t.DecisionTaskCompletedEventID, + Identity: t.Identity, + } +} + +func ToTimerCanceledEventAttributes(t *apiv1.TimerCanceledEventAttributes) *types.TimerCanceledEventAttributes { + if t == nil { + return nil + } + return &types.TimerCanceledEventAttributes{ + TimerID: t.TimerId, + StartedEventID: t.StartedEventId, + DecisionTaskCompletedEventID: t.DecisionTaskCompletedEventId, + Identity: t.Identity, + } +} + +func FromTimerFiredEventAttributes(t *types.TimerFiredEventAttributes) *apiv1.TimerFiredEventAttributes { + if t == nil { + return nil + } + return &apiv1.TimerFiredEventAttributes{ + TimerId: t.TimerID, + StartedEventId: t.StartedEventID, + } +} + +func ToTimerFiredEventAttributes(t *apiv1.TimerFiredEventAttributes) *types.TimerFiredEventAttributes { + if t == nil { + return nil + } + return &types.TimerFiredEventAttributes{ + TimerID: t.TimerId, + StartedEventID: t.StartedEventId, + } +} + +func FromTimerStartedEventAttributes(t *types.TimerStartedEventAttributes) *apiv1.TimerStartedEventAttributes { + if t == nil { + return nil + } + return &apiv1.TimerStartedEventAttributes{ + TimerId: t.TimerID, + StartToFireTimeout: secondsToDuration(int64To32(t.StartToFireTimeoutSeconds)), + DecisionTaskCompletedEventId: t.DecisionTaskCompletedEventID, + } +} + +func ToTimerStartedEventAttributes(t *apiv1.TimerStartedEventAttributes) *types.TimerStartedEventAttributes { + if t == nil { + return nil + } + return &types.TimerStartedEventAttributes{ + TimerID: t.TimerId, + StartToFireTimeoutSeconds: int32To64(durationToSeconds(t.StartToFireTimeout)), + DecisionTaskCompletedEventID: t.DecisionTaskCompletedEventId, + } +} + +const ( + DomainUpdateDescriptionField = "description" + DomainUpdateOwnerEmailField = "owner_email" + DomainUpdateDataField = "data" + DomainUpdateRetentionPeriodField = "workflow_execution_retention_period" + DomainUpdateBadBinariesField = "bad_binaries" + DomainUpdateHistoryArchivalStatusField = "history_archival_status" + DomainUpdateHistoryArchivalURIField = "history_archival_uri" + DomainUpdateVisibilityArchivalStatusField = "visibility_archival_status" + DomainUpdateVisibilityArchivalURIField = "visibility_archival_uri" + DomainUpdateActiveClusterNameField = "active_cluster_name" + DomainUpdateClustersField = "clusters" + DomainUpdateDeleteBadBinaryField = "delete_bad_binary" + DomainUpdateFailoverTimeoutField = "failover_timeout" +) + +func FromUpdateDomainRequest(t *types.UpdateDomainRequest) *apiv1.UpdateDomainRequest { + if t == nil { + return nil + } + request := apiv1.UpdateDomainRequest{ + Name: t.Name, + SecurityToken: t.SecurityToken, + } + fields := []string{} + + if t.Description != nil { + request.Description = *t.Description + fields = append(fields, DomainUpdateDescriptionField) + } + if t.OwnerEmail != nil { + request.OwnerEmail = *t.OwnerEmail + fields = append(fields, DomainUpdateOwnerEmailField) + } + if t.Data != nil { + request.Data = t.Data + fields = append(fields, DomainUpdateDataField) + } + if t.WorkflowExecutionRetentionPeriodInDays != nil { + request.WorkflowExecutionRetentionPeriod = daysToDuration(t.WorkflowExecutionRetentionPeriodInDays) + fields = append(fields, DomainUpdateRetentionPeriodField) + } + //if t.EmitMetric != nil {} - DEPRECATED + if t.BadBinaries != nil { + request.BadBinaries = FromBadBinaries(t.BadBinaries) + fields = append(fields, DomainUpdateBadBinariesField) + } + if t.HistoryArchivalStatus != nil { + request.HistoryArchivalStatus = FromArchivalStatus(t.HistoryArchivalStatus) + fields = append(fields, DomainUpdateHistoryArchivalStatusField) + } + if t.HistoryArchivalURI != nil { + request.HistoryArchivalUri = *t.HistoryArchivalURI + fields = append(fields, DomainUpdateHistoryArchivalURIField) + } + if t.VisibilityArchivalStatus != nil { + request.VisibilityArchivalStatus = FromArchivalStatus(t.VisibilityArchivalStatus) + fields = append(fields, DomainUpdateVisibilityArchivalStatusField) + } + if t.VisibilityArchivalURI != nil { + request.VisibilityArchivalUri = *t.VisibilityArchivalURI + fields = append(fields, DomainUpdateVisibilityArchivalURIField) + } + if t.ActiveClusterName != nil { + request.ActiveClusterName = *t.ActiveClusterName + fields = append(fields, DomainUpdateActiveClusterNameField) + } + if t.Clusters != nil { + request.Clusters = FromClusterReplicationConfigurationArray(t.Clusters) + fields = append(fields, DomainUpdateClustersField) + } + if t.DeleteBadBinary != nil { + request.DeleteBadBinary = *t.DeleteBadBinary + fields = append(fields, DomainUpdateDeleteBadBinaryField) + } + if t.FailoverTimeoutInSeconds != nil { + request.FailoverTimeout = secondsToDuration(t.FailoverTimeoutInSeconds) + fields = append(fields, DomainUpdateFailoverTimeoutField) + } + + var err error + request.UpdateMask, err = fieldmaskpb.New(request.ProtoReflect().Interface(), fields...) + if err != nil { + panic(err) + } + + return &request +} + +func ToUpdateDomainRequest(t *apiv1.UpdateDomainRequest) *types.UpdateDomainRequest { + if t == nil { + return nil + } + request := types.UpdateDomainRequest{ + Name: t.Name, + SecurityToken: t.SecurityToken, + EmitMetric: common.BoolPtr(true), // DEPRECATED - defaults to true + } + fs := newFieldSet(t.UpdateMask) + + if fs.isSet(DomainUpdateDescriptionField) { + request.Description = common.StringPtr(t.Description) + } + if fs.isSet(DomainUpdateOwnerEmailField) { + request.OwnerEmail = common.StringPtr(t.OwnerEmail) + } + if fs.isSet(DomainUpdateDataField) { + request.Data = t.Data + } + if fs.isSet(DomainUpdateRetentionPeriodField) { + request.WorkflowExecutionRetentionPeriodInDays = durationToDays(t.WorkflowExecutionRetentionPeriod) + } + if fs.isSet(DomainUpdateBadBinariesField) { + request.BadBinaries = ToBadBinaries(t.BadBinaries) + } + if fs.isSet(DomainUpdateHistoryArchivalStatusField) { + request.HistoryArchivalStatus = ToArchivalStatus(t.HistoryArchivalStatus) + } + if fs.isSet(DomainUpdateHistoryArchivalURIField) { + request.HistoryArchivalURI = common.StringPtr(t.HistoryArchivalUri) + } + if fs.isSet(DomainUpdateVisibilityArchivalStatusField) { + request.VisibilityArchivalStatus = ToArchivalStatus(t.VisibilityArchivalStatus) + } + if fs.isSet(DomainUpdateVisibilityArchivalURIField) { + request.VisibilityArchivalURI = common.StringPtr(t.VisibilityArchivalUri) + } + if fs.isSet(DomainUpdateActiveClusterNameField) { + request.ActiveClusterName = common.StringPtr(t.ActiveClusterName) + } + if fs.isSet(DomainUpdateClustersField) { + request.Clusters = ToClusterReplicationConfigurationArray(t.Clusters) + } + if fs.isSet(DomainUpdateDeleteBadBinaryField) { + request.DeleteBadBinary = common.StringPtr(t.DeleteBadBinary) + } + if fs.isSet(DomainUpdateFailoverTimeoutField) { + request.FailoverTimeoutInSeconds = durationToSeconds(t.FailoverTimeout) + } + + return &request +} + +func FromUpdateDomainResponse(t *types.UpdateDomainResponse) *apiv1.UpdateDomainResponse { + if t == nil { + return nil + } + domain := &apiv1.Domain{ + FailoverVersion: t.FailoverVersion, + IsGlobalDomain: t.IsGlobalDomain, + } + if info := t.DomainInfo; info != nil { + domain.Id = info.UUID + domain.Name = info.Name + domain.Status = FromDomainStatus(info.Status) + domain.Description = info.Description + domain.OwnerEmail = info.OwnerEmail + domain.Data = info.Data + } + if config := t.Configuration; config != nil { + domain.WorkflowExecutionRetentionPeriod = daysToDuration(&config.WorkflowExecutionRetentionPeriodInDays) + domain.BadBinaries = FromBadBinaries(config.BadBinaries) + domain.HistoryArchivalStatus = FromArchivalStatus(config.HistoryArchivalStatus) + domain.HistoryArchivalUri = config.HistoryArchivalURI + domain.VisibilityArchivalStatus = FromArchivalStatus(config.VisibilityArchivalStatus) + domain.VisibilityArchivalUri = config.VisibilityArchivalURI + } + if repl := t.ReplicationConfiguration; repl != nil { + domain.ActiveClusterName = repl.ActiveClusterName + domain.Clusters = FromClusterReplicationConfigurationArray(repl.Clusters) + } + return &apiv1.UpdateDomainResponse{ + Domain: domain, + } +} + +func ToUpdateDomainResponse(t *apiv1.UpdateDomainResponse) *types.UpdateDomainResponse { + if t == nil || t.Domain == nil { + return nil + } + return &types.UpdateDomainResponse{ + DomainInfo: &types.DomainInfo{ + Name: t.Domain.Name, + Status: ToDomainStatus(t.Domain.Status), + Description: t.Domain.Description, + OwnerEmail: t.Domain.OwnerEmail, + Data: t.Domain.Data, + UUID: t.Domain.Id, + }, + Configuration: &types.DomainConfiguration{ + WorkflowExecutionRetentionPeriodInDays: common.Int32Default(durationToDays(t.Domain.WorkflowExecutionRetentionPeriod)), + EmitMetric: true, + BadBinaries: ToBadBinaries(t.Domain.BadBinaries), + HistoryArchivalStatus: ToArchivalStatus(t.Domain.HistoryArchivalStatus), + HistoryArchivalURI: t.Domain.HistoryArchivalUri, + VisibilityArchivalStatus: ToArchivalStatus(t.Domain.VisibilityArchivalStatus), + VisibilityArchivalURI: t.Domain.VisibilityArchivalUri, + }, + ReplicationConfiguration: &types.DomainReplicationConfiguration{ + ActiveClusterName: t.Domain.ActiveClusterName, + Clusters: ToClusterReplicationConfigurationArray(t.Domain.Clusters), + }, + FailoverVersion: t.Domain.FailoverVersion, + IsGlobalDomain: t.Domain.IsGlobalDomain, + } +} + +func FromUpsertWorkflowSearchAttributesDecisionAttributes(t *types.UpsertWorkflowSearchAttributesDecisionAttributes) *apiv1.UpsertWorkflowSearchAttributesDecisionAttributes { + if t == nil { + return nil + } + return &apiv1.UpsertWorkflowSearchAttributesDecisionAttributes{ + SearchAttributes: FromSearchAttributes(t.SearchAttributes), + } +} + +func ToUpsertWorkflowSearchAttributesDecisionAttributes(t *apiv1.UpsertWorkflowSearchAttributesDecisionAttributes) *types.UpsertWorkflowSearchAttributesDecisionAttributes { + if t == nil { + return nil + } + return &types.UpsertWorkflowSearchAttributesDecisionAttributes{ + SearchAttributes: ToSearchAttributes(t.SearchAttributes), + } +} + +func FromUpsertWorkflowSearchAttributesEventAttributes(t *types.UpsertWorkflowSearchAttributesEventAttributes) *apiv1.UpsertWorkflowSearchAttributesEventAttributes { + if t == nil { + return nil + } + return &apiv1.UpsertWorkflowSearchAttributesEventAttributes{ + DecisionTaskCompletedEventId: t.DecisionTaskCompletedEventID, + SearchAttributes: FromSearchAttributes(t.SearchAttributes), + } +} + +func ToUpsertWorkflowSearchAttributesEventAttributes(t *apiv1.UpsertWorkflowSearchAttributesEventAttributes) *types.UpsertWorkflowSearchAttributesEventAttributes { + if t == nil { + return nil + } + return &types.UpsertWorkflowSearchAttributesEventAttributes{ + DecisionTaskCompletedEventID: t.DecisionTaskCompletedEventId, + SearchAttributes: ToSearchAttributes(t.SearchAttributes), + } +} + +func FromWorkerVersionInfo(t *types.WorkerVersionInfo) *apiv1.WorkerVersionInfo { + if t == nil { + return nil + } + return &apiv1.WorkerVersionInfo{ + Impl: t.Impl, + FeatureVersion: t.FeatureVersion, + } +} + +func ToWorkerVersionInfo(t *apiv1.WorkerVersionInfo) *types.WorkerVersionInfo { + if t == nil { + return nil + } + return &types.WorkerVersionInfo{ + Impl: t.Impl, + FeatureVersion: t.FeatureVersion, + } +} + +func FromWorkflowRunPair(workflowID, runID string) *apiv1.WorkflowExecution { + return &apiv1.WorkflowExecution{ + WorkflowId: workflowID, + RunId: runID, + } +} + +func ToWorkflowID(t *apiv1.WorkflowExecution) string { + if t == nil { + return "" + } + return t.WorkflowId +} + +func ToRunID(t *apiv1.WorkflowExecution) string { + if t == nil { + return "" + } + return t.RunId +} + +func FromWorkflowExecution(t *types.WorkflowExecution) *apiv1.WorkflowExecution { + if t == nil { + return nil + } + return &apiv1.WorkflowExecution{ + WorkflowId: t.WorkflowID, + RunId: t.RunID, + } +} + +func ToWorkflowExecution(t *apiv1.WorkflowExecution) *types.WorkflowExecution { + if t == nil { + return nil + } + return &types.WorkflowExecution{ + WorkflowID: t.WorkflowId, + RunID: t.RunId, + } +} + +func FromExternalExecutionInfoFields(we *types.WorkflowExecution, initiatedID *int64) *apiv1.ExternalExecutionInfo { + if we == nil && initiatedID == nil { + return nil + } + if we == nil || initiatedID == nil { + panic("either all or none external execution info fields must be set") + } + return &apiv1.ExternalExecutionInfo{ + WorkflowExecution: FromWorkflowExecution(we), + InitiatedId: *initiatedID, + } +} + +func ToExternalWorkflowExecution(t *apiv1.ExternalExecutionInfo) *types.WorkflowExecution { + if t == nil { + return nil + } + return ToWorkflowExecution(t.WorkflowExecution) +} + +func ToExternalInitiatedID(t *apiv1.ExternalExecutionInfo) *int64 { + if t == nil { + return nil + } + return &t.InitiatedId +} + +func FromWorkflowExecutionCancelRequestedEventAttributes(t *types.WorkflowExecutionCancelRequestedEventAttributes) *apiv1.WorkflowExecutionCancelRequestedEventAttributes { + if t == nil { + return nil + } + return &apiv1.WorkflowExecutionCancelRequestedEventAttributes{ + Cause: t.Cause, + ExternalExecutionInfo: FromExternalExecutionInfoFields(t.ExternalWorkflowExecution, t.ExternalInitiatedEventID), + Identity: t.Identity, + } +} + +func ToWorkflowExecutionCancelRequestedEventAttributes(t *apiv1.WorkflowExecutionCancelRequestedEventAttributes) *types.WorkflowExecutionCancelRequestedEventAttributes { + if t == nil { + return nil + } + return &types.WorkflowExecutionCancelRequestedEventAttributes{ + Cause: t.Cause, + ExternalInitiatedEventID: ToExternalInitiatedID(t.ExternalExecutionInfo), + ExternalWorkflowExecution: ToExternalWorkflowExecution(t.ExternalExecutionInfo), + Identity: t.Identity, + } +} + +func FromWorkflowExecutionCanceledEventAttributes(t *types.WorkflowExecutionCanceledEventAttributes) *apiv1.WorkflowExecutionCanceledEventAttributes { + if t == nil { + return nil + } + return &apiv1.WorkflowExecutionCanceledEventAttributes{ + DecisionTaskCompletedEventId: t.DecisionTaskCompletedEventID, + Details: FromPayload(t.Details), + } +} + +func ToWorkflowExecutionCanceledEventAttributes(t *apiv1.WorkflowExecutionCanceledEventAttributes) *types.WorkflowExecutionCanceledEventAttributes { + if t == nil { + return nil + } + return &types.WorkflowExecutionCanceledEventAttributes{ + DecisionTaskCompletedEventID: t.DecisionTaskCompletedEventId, + Details: ToPayload(t.Details), + } +} + +func FromWorkflowExecutionCloseStatus(t *types.WorkflowExecutionCloseStatus) apiv1.WorkflowExecutionCloseStatus { + if t == nil { + return apiv1.WorkflowExecutionCloseStatus_WORKFLOW_EXECUTION_CLOSE_STATUS_INVALID + } + switch *t { + case types.WorkflowExecutionCloseStatusCompleted: + return apiv1.WorkflowExecutionCloseStatus_WORKFLOW_EXECUTION_CLOSE_STATUS_COMPLETED + case types.WorkflowExecutionCloseStatusFailed: + return apiv1.WorkflowExecutionCloseStatus_WORKFLOW_EXECUTION_CLOSE_STATUS_FAILED + case types.WorkflowExecutionCloseStatusCanceled: + return apiv1.WorkflowExecutionCloseStatus_WORKFLOW_EXECUTION_CLOSE_STATUS_CANCELED + case types.WorkflowExecutionCloseStatusTerminated: + return apiv1.WorkflowExecutionCloseStatus_WORKFLOW_EXECUTION_CLOSE_STATUS_TERMINATED + case types.WorkflowExecutionCloseStatusContinuedAsNew: + return apiv1.WorkflowExecutionCloseStatus_WORKFLOW_EXECUTION_CLOSE_STATUS_CONTINUED_AS_NEW + case types.WorkflowExecutionCloseStatusTimedOut: + return apiv1.WorkflowExecutionCloseStatus_WORKFLOW_EXECUTION_CLOSE_STATUS_TIMED_OUT + } + panic("unexpected enum value") +} + +func ToWorkflowExecutionCloseStatus(t apiv1.WorkflowExecutionCloseStatus) *types.WorkflowExecutionCloseStatus { + switch t { + case apiv1.WorkflowExecutionCloseStatus_WORKFLOW_EXECUTION_CLOSE_STATUS_INVALID: + return nil + case apiv1.WorkflowExecutionCloseStatus_WORKFLOW_EXECUTION_CLOSE_STATUS_COMPLETED: + return types.WorkflowExecutionCloseStatusCompleted.Ptr() + case apiv1.WorkflowExecutionCloseStatus_WORKFLOW_EXECUTION_CLOSE_STATUS_FAILED: + return types.WorkflowExecutionCloseStatusFailed.Ptr() + case apiv1.WorkflowExecutionCloseStatus_WORKFLOW_EXECUTION_CLOSE_STATUS_CANCELED: + return types.WorkflowExecutionCloseStatusCanceled.Ptr() + case apiv1.WorkflowExecutionCloseStatus_WORKFLOW_EXECUTION_CLOSE_STATUS_TERMINATED: + return types.WorkflowExecutionCloseStatusTerminated.Ptr() + case apiv1.WorkflowExecutionCloseStatus_WORKFLOW_EXECUTION_CLOSE_STATUS_CONTINUED_AS_NEW: + return types.WorkflowExecutionCloseStatusContinuedAsNew.Ptr() + case apiv1.WorkflowExecutionCloseStatus_WORKFLOW_EXECUTION_CLOSE_STATUS_TIMED_OUT: + return types.WorkflowExecutionCloseStatusTimedOut.Ptr() + } + panic("unexpected enum value") +} + +func FromWorkflowExecutionCompletedEventAttributes(t *types.WorkflowExecutionCompletedEventAttributes) *apiv1.WorkflowExecutionCompletedEventAttributes { + if t == nil { + return nil + } + return &apiv1.WorkflowExecutionCompletedEventAttributes{ + Result: FromPayload(t.Result), + DecisionTaskCompletedEventId: t.DecisionTaskCompletedEventID, + } +} + +func ToWorkflowExecutionCompletedEventAttributes(t *apiv1.WorkflowExecutionCompletedEventAttributes) *types.WorkflowExecutionCompletedEventAttributes { + if t == nil { + return nil + } + return &types.WorkflowExecutionCompletedEventAttributes{ + Result: ToPayload(t.Result), + DecisionTaskCompletedEventID: t.DecisionTaskCompletedEventId, + } +} + +func FromWorkflowExecutionConfiguration(t *types.WorkflowExecutionConfiguration) *apiv1.WorkflowExecutionConfiguration { + if t == nil { + return nil + } + return &apiv1.WorkflowExecutionConfiguration{ + TaskList: FromTaskList(t.TaskList), + ExecutionStartToCloseTimeout: secondsToDuration(t.ExecutionStartToCloseTimeoutSeconds), + TaskStartToCloseTimeout: secondsToDuration(t.TaskStartToCloseTimeoutSeconds), + } +} + +func ToWorkflowExecutionConfiguration(t *apiv1.WorkflowExecutionConfiguration) *types.WorkflowExecutionConfiguration { + if t == nil { + return nil + } + return &types.WorkflowExecutionConfiguration{ + TaskList: ToTaskList(t.TaskList), + ExecutionStartToCloseTimeoutSeconds: durationToSeconds(t.ExecutionStartToCloseTimeout), + TaskStartToCloseTimeoutSeconds: durationToSeconds(t.TaskStartToCloseTimeout), + } +} + +func FromWorkflowExecutionContinuedAsNewEventAttributes(t *types.WorkflowExecutionContinuedAsNewEventAttributes) *apiv1.WorkflowExecutionContinuedAsNewEventAttributes { + if t == nil { + return nil + } + return &apiv1.WorkflowExecutionContinuedAsNewEventAttributes{ + NewExecutionRunId: t.NewExecutionRunID, + WorkflowType: FromWorkflowType(t.WorkflowType), + TaskList: FromTaskList(t.TaskList), + Input: FromPayload(t.Input), + ExecutionStartToCloseTimeout: secondsToDuration(t.ExecutionStartToCloseTimeoutSeconds), + TaskStartToCloseTimeout: secondsToDuration(t.TaskStartToCloseTimeoutSeconds), + DecisionTaskCompletedEventId: t.DecisionTaskCompletedEventID, + BackoffStartInterval: secondsToDuration(t.BackoffStartIntervalInSeconds), + Initiator: FromContinueAsNewInitiator(t.Initiator), + Failure: FromFailure(t.FailureReason, t.FailureDetails), + LastCompletionResult: FromPayload(t.LastCompletionResult), + Header: FromHeader(t.Header), + Memo: FromMemo(t.Memo), + SearchAttributes: FromSearchAttributes(t.SearchAttributes), + } +} + +func ToWorkflowExecutionContinuedAsNewEventAttributes(t *apiv1.WorkflowExecutionContinuedAsNewEventAttributes) *types.WorkflowExecutionContinuedAsNewEventAttributes { + if t == nil { + return nil + } + return &types.WorkflowExecutionContinuedAsNewEventAttributes{ + NewExecutionRunID: t.NewExecutionRunId, + WorkflowType: ToWorkflowType(t.WorkflowType), + TaskList: ToTaskList(t.TaskList), + Input: ToPayload(t.Input), + ExecutionStartToCloseTimeoutSeconds: durationToSeconds(t.ExecutionStartToCloseTimeout), + TaskStartToCloseTimeoutSeconds: durationToSeconds(t.TaskStartToCloseTimeout), + DecisionTaskCompletedEventID: t.DecisionTaskCompletedEventId, + BackoffStartIntervalInSeconds: durationToSeconds(t.BackoffStartInterval), + Initiator: ToContinueAsNewInitiator(t.Initiator), + FailureReason: ToFailureReason(t.Failure), + FailureDetails: ToFailureDetails(t.Failure), + LastCompletionResult: ToPayload(t.LastCompletionResult), + Header: ToHeader(t.Header), + Memo: ToMemo(t.Memo), + SearchAttributes: ToSearchAttributes(t.SearchAttributes), + } +} + +func FromWorkflowExecutionFailedEventAttributes(t *types.WorkflowExecutionFailedEventAttributes) *apiv1.WorkflowExecutionFailedEventAttributes { + if t == nil { + return nil + } + return &apiv1.WorkflowExecutionFailedEventAttributes{ + Failure: FromFailure(t.Reason, t.Details), + DecisionTaskCompletedEventId: t.DecisionTaskCompletedEventID, + } +} + +func ToWorkflowExecutionFailedEventAttributes(t *apiv1.WorkflowExecutionFailedEventAttributes) *types.WorkflowExecutionFailedEventAttributes { + if t == nil { + return nil + } + return &types.WorkflowExecutionFailedEventAttributes{ + Reason: ToFailureReason(t.Failure), + Details: ToFailureDetails(t.Failure), + DecisionTaskCompletedEventID: t.DecisionTaskCompletedEventId, + } +} + +func FromWorkflowExecutionFilter(t *types.WorkflowExecutionFilter) *apiv1.WorkflowExecutionFilter { + if t == nil { + return nil + } + return &apiv1.WorkflowExecutionFilter{ + WorkflowId: t.WorkflowID, + RunId: t.RunID, + } +} + +func ToWorkflowExecutionFilter(t *apiv1.WorkflowExecutionFilter) *types.WorkflowExecutionFilter { + if t == nil { + return nil + } + return &types.WorkflowExecutionFilter{ + WorkflowID: t.WorkflowId, + RunID: t.RunId, + } +} + +func FromParentExecutionInfo(t *types.ParentExecutionInfo) *apiv1.ParentExecutionInfo { + if t == nil { + return nil + } + return &apiv1.ParentExecutionInfo{ + DomainId: t.DomainUUID, + DomainName: t.Domain, + WorkflowExecution: FromWorkflowExecution(t.Execution), + InitiatedId: t.InitiatedID, + } +} + +func ToParentExecutionInfo(t *apiv1.ParentExecutionInfo) *types.ParentExecutionInfo { + if t == nil { + return nil + } + return &types.ParentExecutionInfo{ + DomainUUID: t.DomainId, + Domain: t.DomainName, + Execution: ToWorkflowExecution(t.WorkflowExecution), + InitiatedID: t.InitiatedId, + } +} + +func FromParentExecutionInfoFields(domainID, domainName *string, we *types.WorkflowExecution, initiatedID *int64) *apiv1.ParentExecutionInfo { + if domainID == nil && domainName == nil && we == nil && initiatedID == nil { + return nil + } + if domainID == nil || domainName == nil || we == nil || initiatedID == nil { + panic("either all or none parent execution info must be set") + } + + return &apiv1.ParentExecutionInfo{ + DomainId: *domainID, + DomainName: *domainName, + WorkflowExecution: FromWorkflowExecution(we), + InitiatedId: *initiatedID, + } +} + +func ToParentDomainID(pei *apiv1.ParentExecutionInfo) *string { + if pei == nil { + return nil + } + return &pei.DomainId +} + +func ToParentDomainName(pei *apiv1.ParentExecutionInfo) *string { + if pei == nil { + return nil + } + return &pei.DomainName +} + +func ToParentWorkflowExecution(pei *apiv1.ParentExecutionInfo) *types.WorkflowExecution { + if pei == nil { + return nil + } + return ToWorkflowExecution(pei.WorkflowExecution) +} + +func ToParentInitiatedID(pei *apiv1.ParentExecutionInfo) *int64 { + if pei == nil { + return nil + } + return &pei.InitiatedId +} + +func FromWorkflowExecutionInfo(t *types.WorkflowExecutionInfo) *apiv1.WorkflowExecutionInfo { + if t == nil { + return nil + } + return &apiv1.WorkflowExecutionInfo{ + WorkflowExecution: FromWorkflowExecution(t.Execution), + Type: FromWorkflowType(t.Type), + StartTime: unixNanoToTime(t.StartTime), + CloseTime: unixNanoToTime(t.CloseTime), + CloseStatus: FromWorkflowExecutionCloseStatus(t.CloseStatus), + HistoryLength: t.HistoryLength, + ParentExecutionInfo: FromParentExecutionInfoFields(t.ParentDomainID, t.ParentDomain, t.ParentExecution, t.ParentInitiatedID), + ExecutionTime: unixNanoToTime(t.ExecutionTime), + Memo: FromMemo(t.Memo), + SearchAttributes: FromSearchAttributes(t.SearchAttributes), + AutoResetPoints: FromResetPoints(t.AutoResetPoints), + TaskList: t.TaskList, + } +} + +func ToWorkflowExecutionInfo(t *apiv1.WorkflowExecutionInfo) *types.WorkflowExecutionInfo { + if t == nil { + return nil + } + return &types.WorkflowExecutionInfo{ + Execution: ToWorkflowExecution(t.WorkflowExecution), + Type: ToWorkflowType(t.Type), + StartTime: timeToUnixNano(t.StartTime), + CloseTime: timeToUnixNano(t.CloseTime), + CloseStatus: ToWorkflowExecutionCloseStatus(t.CloseStatus), + HistoryLength: t.HistoryLength, + ParentDomainID: ToParentDomainID(t.ParentExecutionInfo), + ParentDomain: ToParentDomainName(t.ParentExecutionInfo), + ParentExecution: ToParentWorkflowExecution(t.ParentExecutionInfo), + ParentInitiatedID: ToParentInitiatedID(t.ParentExecutionInfo), + ExecutionTime: timeToUnixNano(t.ExecutionTime), + Memo: ToMemo(t.Memo), + SearchAttributes: ToSearchAttributes(t.SearchAttributes), + AutoResetPoints: ToResetPoints(t.AutoResetPoints), + TaskList: t.TaskList, + } +} + +func FromWorkflowExecutionSignaledEventAttributes(t *types.WorkflowExecutionSignaledEventAttributes) *apiv1.WorkflowExecutionSignaledEventAttributes { + if t == nil { + return nil + } + return &apiv1.WorkflowExecutionSignaledEventAttributes{ + SignalName: t.SignalName, + Input: FromPayload(t.Input), + Identity: t.Identity, + } +} + +func ToWorkflowExecutionSignaledEventAttributes(t *apiv1.WorkflowExecutionSignaledEventAttributes) *types.WorkflowExecutionSignaledEventAttributes { + if t == nil { + return nil + } + return &types.WorkflowExecutionSignaledEventAttributes{ + SignalName: t.SignalName, + Input: ToPayload(t.Input), + Identity: t.Identity, + } +} + +func FromWorkflowExecutionStartedEventAttributes(t *types.WorkflowExecutionStartedEventAttributes) *apiv1.WorkflowExecutionStartedEventAttributes { + if t == nil { + return nil + } + return &apiv1.WorkflowExecutionStartedEventAttributes{ + WorkflowType: FromWorkflowType(t.WorkflowType), + ParentExecutionInfo: FromParentExecutionInfoFields(t.ParentWorkflowDomainID, t.ParentWorkflowDomain, t.ParentWorkflowExecution, t.ParentInitiatedEventID), + TaskList: FromTaskList(t.TaskList), + Input: FromPayload(t.Input), + ExecutionStartToCloseTimeout: secondsToDuration(t.ExecutionStartToCloseTimeoutSeconds), + TaskStartToCloseTimeout: secondsToDuration(t.TaskStartToCloseTimeoutSeconds), + ContinuedExecutionRunId: t.ContinuedExecutionRunID, + Initiator: FromContinueAsNewInitiator(t.Initiator), + ContinuedFailure: FromFailure(t.ContinuedFailureReason, t.ContinuedFailureDetails), + LastCompletionResult: FromPayload(t.LastCompletionResult), + OriginalExecutionRunId: t.OriginalExecutionRunID, + Identity: t.Identity, + FirstExecutionRunId: t.FirstExecutionRunID, + RetryPolicy: FromRetryPolicy(t.RetryPolicy), + Attempt: t.Attempt, + ExpirationTime: unixNanoToTime(t.ExpirationTimestamp), + CronSchedule: t.CronSchedule, + FirstDecisionTaskBackoff: secondsToDuration(t.FirstDecisionTaskBackoffSeconds), + Memo: FromMemo(t.Memo), + SearchAttributes: FromSearchAttributes(t.SearchAttributes), + PrevAutoResetPoints: FromResetPoints(t.PrevAutoResetPoints), + Header: FromHeader(t.Header), + } +} + +func ToWorkflowExecutionStartedEventAttributes(t *apiv1.WorkflowExecutionStartedEventAttributes) *types.WorkflowExecutionStartedEventAttributes { + if t == nil { + return nil + } + return &types.WorkflowExecutionStartedEventAttributes{ + WorkflowType: ToWorkflowType(t.WorkflowType), + ParentWorkflowDomainID: ToParentDomainID(t.ParentExecutionInfo), + ParentWorkflowDomain: ToParentDomainName(t.ParentExecutionInfo), + ParentWorkflowExecution: ToParentWorkflowExecution(t.ParentExecutionInfo), + ParentInitiatedEventID: ToParentInitiatedID(t.ParentExecutionInfo), + TaskList: ToTaskList(t.TaskList), + Input: ToPayload(t.Input), + ExecutionStartToCloseTimeoutSeconds: durationToSeconds(t.ExecutionStartToCloseTimeout), + TaskStartToCloseTimeoutSeconds: durationToSeconds(t.TaskStartToCloseTimeout), + ContinuedExecutionRunID: t.ContinuedExecutionRunId, + Initiator: ToContinueAsNewInitiator(t.Initiator), + ContinuedFailureReason: ToFailureReason(t.ContinuedFailure), + ContinuedFailureDetails: ToFailureDetails(t.ContinuedFailure), + LastCompletionResult: ToPayload(t.LastCompletionResult), + OriginalExecutionRunID: t.OriginalExecutionRunId, + Identity: t.Identity, + FirstExecutionRunID: t.FirstExecutionRunId, + RetryPolicy: ToRetryPolicy(t.RetryPolicy), + Attempt: t.Attempt, + ExpirationTimestamp: timeToUnixNano(t.ExpirationTime), + CronSchedule: t.CronSchedule, + FirstDecisionTaskBackoffSeconds: durationToSeconds(t.FirstDecisionTaskBackoff), + Memo: ToMemo(t.Memo), + SearchAttributes: ToSearchAttributes(t.SearchAttributes), + PrevAutoResetPoints: ToResetPoints(t.PrevAutoResetPoints), + Header: ToHeader(t.Header), + } +} + +func FromWorkflowExecutionTerminatedEventAttributes(t *types.WorkflowExecutionTerminatedEventAttributes) *apiv1.WorkflowExecutionTerminatedEventAttributes { + if t == nil { + return nil + } + return &apiv1.WorkflowExecutionTerminatedEventAttributes{ + Reason: t.Reason, + Details: FromPayload(t.Details), + Identity: t.Identity, + } +} + +func ToWorkflowExecutionTerminatedEventAttributes(t *apiv1.WorkflowExecutionTerminatedEventAttributes) *types.WorkflowExecutionTerminatedEventAttributes { + if t == nil { + return nil + } + return &types.WorkflowExecutionTerminatedEventAttributes{ + Reason: t.Reason, + Details: ToPayload(t.Details), + Identity: t.Identity, + } +} + +func FromWorkflowExecutionTimedOutEventAttributes(t *types.WorkflowExecutionTimedOutEventAttributes) *apiv1.WorkflowExecutionTimedOutEventAttributes { + if t == nil { + return nil + } + return &apiv1.WorkflowExecutionTimedOutEventAttributes{ + TimeoutType: FromTimeoutType(t.TimeoutType), + } +} + +func ToWorkflowExecutionTimedOutEventAttributes(t *apiv1.WorkflowExecutionTimedOutEventAttributes) *types.WorkflowExecutionTimedOutEventAttributes { + if t == nil { + return nil + } + return &types.WorkflowExecutionTimedOutEventAttributes{ + TimeoutType: ToTimeoutType(t.TimeoutType), + } +} + +func FromWorkflowIDReusePolicy(t *types.WorkflowIDReusePolicy) apiv1.WorkflowIdReusePolicy { + if t == nil { + return apiv1.WorkflowIdReusePolicy_WORKFLOW_ID_REUSE_POLICY_INVALID + } + switch *t { + case types.WorkflowIDReusePolicyAllowDuplicateFailedOnly: + return apiv1.WorkflowIdReusePolicy_WORKFLOW_ID_REUSE_POLICY_ALLOW_DUPLICATE_FAILED_ONLY + case types.WorkflowIDReusePolicyAllowDuplicate: + return apiv1.WorkflowIdReusePolicy_WORKFLOW_ID_REUSE_POLICY_ALLOW_DUPLICATE + case types.WorkflowIDReusePolicyRejectDuplicate: + return apiv1.WorkflowIdReusePolicy_WORKFLOW_ID_REUSE_POLICY_REJECT_DUPLICATE + case types.WorkflowIDReusePolicyTerminateIfRunning: + return apiv1.WorkflowIdReusePolicy_WORKFLOW_ID_REUSE_POLICY_TERMINATE_IF_RUNNING + } + panic("unexpected enum value") +} + +func ToWorkflowIDReusePolicy(t apiv1.WorkflowIdReusePolicy) *types.WorkflowIDReusePolicy { + switch t { + case apiv1.WorkflowIdReusePolicy_WORKFLOW_ID_REUSE_POLICY_INVALID: + return nil + case apiv1.WorkflowIdReusePolicy_WORKFLOW_ID_REUSE_POLICY_ALLOW_DUPLICATE_FAILED_ONLY: + return types.WorkflowIDReusePolicyAllowDuplicateFailedOnly.Ptr() + case apiv1.WorkflowIdReusePolicy_WORKFLOW_ID_REUSE_POLICY_ALLOW_DUPLICATE: + return types.WorkflowIDReusePolicyAllowDuplicate.Ptr() + case apiv1.WorkflowIdReusePolicy_WORKFLOW_ID_REUSE_POLICY_REJECT_DUPLICATE: + return types.WorkflowIDReusePolicyRejectDuplicate.Ptr() + case apiv1.WorkflowIdReusePolicy_WORKFLOW_ID_REUSE_POLICY_TERMINATE_IF_RUNNING: + return types.WorkflowIDReusePolicyTerminateIfRunning.Ptr() + } + panic("unexpected enum value") +} + +func FromWorkflowQuery(t *types.WorkflowQuery) *apiv1.WorkflowQuery { + if t == nil { + return nil + } + return &apiv1.WorkflowQuery{ + QueryType: t.QueryType, + QueryArgs: FromPayload(t.QueryArgs), + } +} + +func ToWorkflowQuery(t *apiv1.WorkflowQuery) *types.WorkflowQuery { + if t == nil { + return nil + } + return &types.WorkflowQuery{ + QueryType: t.QueryType, + QueryArgs: ToPayload(t.QueryArgs), + } +} + +func FromWorkflowQueryResult(t *types.WorkflowQueryResult) *apiv1.WorkflowQueryResult { + if t == nil { + return nil + } + return &apiv1.WorkflowQueryResult{ + ResultType: FromQueryResultType(t.ResultType), + Answer: FromPayload(t.Answer), + ErrorMessage: t.ErrorMessage, + } +} + +func ToWorkflowQueryResult(t *apiv1.WorkflowQueryResult) *types.WorkflowQueryResult { + if t == nil { + return nil + } + return &types.WorkflowQueryResult{ + ResultType: ToQueryResultType(t.ResultType), + Answer: ToPayload(t.Answer), + ErrorMessage: t.ErrorMessage, + } +} + +func FromWorkflowType(t *types.WorkflowType) *apiv1.WorkflowType { + if t == nil { + return nil + } + return &apiv1.WorkflowType{ + Name: t.Name, + } +} + +func ToWorkflowType(t *apiv1.WorkflowType) *types.WorkflowType { + if t == nil { + return nil + } + return &types.WorkflowType{ + Name: t.Name, + } +} + +func FromWorkflowTypeFilter(t *types.WorkflowTypeFilter) *apiv1.WorkflowTypeFilter { + if t == nil { + return nil + } + return &apiv1.WorkflowTypeFilter{ + Name: t.Name, + } +} + +func ToWorkflowTypeFilter(t *apiv1.WorkflowTypeFilter) *types.WorkflowTypeFilter { + if t == nil { + return nil + } + return &types.WorkflowTypeFilter{ + Name: t.Name, + } +} + +func FromDataBlobArray(t []*types.DataBlob) []*apiv1.DataBlob { + if t == nil { + return nil + } + v := make([]*apiv1.DataBlob, len(t)) + for i := range t { + v[i] = FromDataBlob(t[i]) + } + return v +} + +func ToDataBlobArray(t []*apiv1.DataBlob) []*types.DataBlob { + if t == nil { + return nil + } + v := make([]*types.DataBlob, len(t)) + for i := range t { + v[i] = ToDataBlob(t[i]) + } + return v +} + +func FromHistoryEventArray(t []*types.HistoryEvent) []*apiv1.HistoryEvent { + if t == nil { + return nil + } + v := make([]*apiv1.HistoryEvent, len(t)) + for i := range t { + v[i] = FromHistoryEvent(t[i]) + } + return v +} + +func ToHistoryEventArray(t []*apiv1.HistoryEvent) []*types.HistoryEvent { + if t == nil { + return nil + } + v := make([]*types.HistoryEvent, len(t)) + for i := range t { + v[i] = ToHistoryEvent(t[i]) + } + return v +} + +func FromTaskListPartitionMetadataArray(t []*types.TaskListPartitionMetadata) []*apiv1.TaskListPartitionMetadata { + if t == nil { + return nil + } + v := make([]*apiv1.TaskListPartitionMetadata, len(t)) + for i := range t { + v[i] = FromTaskListPartitionMetadata(t[i]) + } + return v +} + +func ToTaskListPartitionMetadataArray(t []*apiv1.TaskListPartitionMetadata) []*types.TaskListPartitionMetadata { + if t == nil { + return nil + } + v := make([]*types.TaskListPartitionMetadata, len(t)) + for i := range t { + v[i] = ToTaskListPartitionMetadata(t[i]) + } + return v +} + +func FromDecisionArray(t []*types.Decision) []*apiv1.Decision { + if t == nil { + return nil + } + v := make([]*apiv1.Decision, len(t)) + for i := range t { + v[i] = FromDecision(t[i]) + } + return v +} + +func ToDecisionArray(t []*apiv1.Decision) []*types.Decision { + if t == nil { + return nil + } + v := make([]*types.Decision, len(t)) + for i := range t { + v[i] = ToDecision(t[i]) + } + return v +} + +func FromPollerInfoArray(t []*types.PollerInfo) []*apiv1.PollerInfo { + if t == nil { + return nil + } + v := make([]*apiv1.PollerInfo, len(t)) + for i := range t { + v[i] = FromPollerInfo(t[i]) + } + return v +} + +func ToPollerInfoArray(t []*apiv1.PollerInfo) []*types.PollerInfo { + if t == nil { + return nil + } + v := make([]*types.PollerInfo, len(t)) + for i := range t { + v[i] = ToPollerInfo(t[i]) + } + return v +} + +func FromPendingChildExecutionInfoArray(t []*types.PendingChildExecutionInfo) []*apiv1.PendingChildExecutionInfo { + if t == nil { + return nil + } + v := make([]*apiv1.PendingChildExecutionInfo, len(t)) + for i := range t { + v[i] = FromPendingChildExecutionInfo(t[i]) + } + return v +} + +func ToPendingChildExecutionInfoArray(t []*apiv1.PendingChildExecutionInfo) []*types.PendingChildExecutionInfo { + if t == nil { + return nil + } + v := make([]*types.PendingChildExecutionInfo, len(t)) + for i := range t { + v[i] = ToPendingChildExecutionInfo(t[i]) + } + return v +} + +func FromWorkflowExecutionInfoArray(t []*types.WorkflowExecutionInfo) []*apiv1.WorkflowExecutionInfo { + if t == nil { + return nil + } + v := make([]*apiv1.WorkflowExecutionInfo, len(t)) + for i := range t { + v[i] = FromWorkflowExecutionInfo(t[i]) + } + return v +} + +func ToWorkflowExecutionInfoArray(t []*apiv1.WorkflowExecutionInfo) []*types.WorkflowExecutionInfo { + if t == nil { + return nil + } + v := make([]*types.WorkflowExecutionInfo, len(t)) + for i := range t { + v[i] = ToWorkflowExecutionInfo(t[i]) + } + return v +} + +func FromDescribeDomainResponseArray(t []*types.DescribeDomainResponse) []*apiv1.Domain { + if t == nil { + return nil + } + v := make([]*apiv1.Domain, len(t)) + for i := range t { + v[i] = FromDescribeDomainResponseDomain(t[i]) + } + return v +} + +func ToDescribeDomainResponseArray(t []*apiv1.Domain) []*types.DescribeDomainResponse { + if t == nil { + return nil + } + v := make([]*types.DescribeDomainResponse, len(t)) + for i := range t { + v[i] = ToDescribeDomainResponseDomain(t[i]) + } + return v +} + +func FromResetPointInfoArray(t []*types.ResetPointInfo) []*apiv1.ResetPointInfo { + if t == nil { + return nil + } + v := make([]*apiv1.ResetPointInfo, len(t)) + for i := range t { + v[i] = FromResetPointInfo(t[i]) + } + return v +} + +func ToResetPointInfoArray(t []*apiv1.ResetPointInfo) []*types.ResetPointInfo { + if t == nil { + return nil + } + v := make([]*types.ResetPointInfo, len(t)) + for i := range t { + v[i] = ToResetPointInfo(t[i]) + } + return v +} + +func FromPendingActivityInfoArray(t []*types.PendingActivityInfo) []*apiv1.PendingActivityInfo { + if t == nil { + return nil + } + v := make([]*apiv1.PendingActivityInfo, len(t)) + for i := range t { + v[i] = FromPendingActivityInfo(t[i]) + } + return v +} + +func ToPendingActivityInfoArray(t []*apiv1.PendingActivityInfo) []*types.PendingActivityInfo { + if t == nil { + return nil + } + v := make([]*types.PendingActivityInfo, len(t)) + for i := range t { + v[i] = ToPendingActivityInfo(t[i]) + } + return v +} + +func FromClusterReplicationConfigurationArray(t []*types.ClusterReplicationConfiguration) []*apiv1.ClusterReplicationConfiguration { + if t == nil { + return nil + } + v := make([]*apiv1.ClusterReplicationConfiguration, len(t)) + for i := range t { + v[i] = FromClusterReplicationConfiguration(t[i]) + } + return v +} + +func ToClusterReplicationConfigurationArray(t []*apiv1.ClusterReplicationConfiguration) []*types.ClusterReplicationConfiguration { + if t == nil { + return nil + } + v := make([]*types.ClusterReplicationConfiguration, len(t)) + for i := range t { + v[i] = ToClusterReplicationConfiguration(t[i]) + } + return v +} + +func FromActivityLocalDispatchInfoMap(t map[string]*types.ActivityLocalDispatchInfo) map[string]*apiv1.ActivityLocalDispatchInfo { + if t == nil { + return nil + } + v := make(map[string]*apiv1.ActivityLocalDispatchInfo, len(t)) + for key := range t { + v[key] = FromActivityLocalDispatchInfo(t[key]) + } + return v +} + +func ToActivityLocalDispatchInfoMap(t map[string]*apiv1.ActivityLocalDispatchInfo) map[string]*types.ActivityLocalDispatchInfo { + if t == nil { + return nil + } + v := make(map[string]*types.ActivityLocalDispatchInfo, len(t)) + for key := range t { + v[key] = ToActivityLocalDispatchInfo(t[key]) + } + return v +} + +func FromBadBinaryInfoMap(t map[string]*types.BadBinaryInfo) map[string]*apiv1.BadBinaryInfo { + if t == nil { + return nil + } + v := make(map[string]*apiv1.BadBinaryInfo, len(t)) + for key := range t { + v[key] = FromBadBinaryInfo(t[key]) + } + return v +} + +func ToBadBinaryInfoMap(t map[string]*apiv1.BadBinaryInfo) map[string]*types.BadBinaryInfo { + if t == nil { + return nil + } + v := make(map[string]*types.BadBinaryInfo, len(t)) + for key := range t { + v[key] = ToBadBinaryInfo(t[key]) + } + return v +} + +func FromIndexedValueTypeMap(t map[string]types.IndexedValueType) map[string]apiv1.IndexedValueType { + if t == nil { + return nil + } + v := make(map[string]apiv1.IndexedValueType, len(t)) + for key := range t { + v[key] = FromIndexedValueType(t[key]) + } + return v +} + +func ToIndexedValueTypeMap(t map[string]apiv1.IndexedValueType) map[string]types.IndexedValueType { + if t == nil { + return nil + } + v := make(map[string]types.IndexedValueType, len(t)) + for key := range t { + v[key] = ToIndexedValueType(t[key]) + } + return v +} + +func FromWorkflowQueryMap(t map[string]*types.WorkflowQuery) map[string]*apiv1.WorkflowQuery { + if t == nil { + return nil + } + v := make(map[string]*apiv1.WorkflowQuery, len(t)) + for key := range t { + v[key] = FromWorkflowQuery(t[key]) + } + return v +} + +func ToWorkflowQueryMap(t map[string]*apiv1.WorkflowQuery) map[string]*types.WorkflowQuery { + if t == nil { + return nil + } + v := make(map[string]*types.WorkflowQuery, len(t)) + for key := range t { + v[key] = ToWorkflowQuery(t[key]) + } + return v +} + +func FromWorkflowQueryResultMap(t map[string]*types.WorkflowQueryResult) map[string]*apiv1.WorkflowQueryResult { + if t == nil { + return nil + } + v := make(map[string]*apiv1.WorkflowQueryResult, len(t)) + for key := range t { + v[key] = FromWorkflowQueryResult(t[key]) + } + return v +} + +func ToWorkflowQueryResultMap(t map[string]*apiv1.WorkflowQueryResult) map[string]*types.WorkflowQueryResult { + if t == nil { + return nil + } + v := make(map[string]*types.WorkflowQueryResult, len(t)) + for key := range t { + v[key] = ToWorkflowQueryResult(t[key]) + } + return v +} + +func FromPayload(data []byte) *apiv1.Payload { + if data == nil { + return nil + } + return &apiv1.Payload{ + Data: data, + } +} + +func ToPayload(p *apiv1.Payload) []byte { + if p == nil { + return nil + } + return p.Data +} + +func FromPayloadMap(t map[string][]byte) map[string]*apiv1.Payload { + if t == nil { + return nil + } + v := make(map[string]*apiv1.Payload, len(t)) + for key := range t { + v[key] = FromPayload(t[key]) + } + return v +} + +func ToPayloadMap(t map[string]*apiv1.Payload) map[string][]byte { + if t == nil { + return nil + } + v := make(map[string][]byte, len(t)) + for key := range t { + v[key] = ToPayload(t[key]) + } + return v +} + +func FromFailure(reason *string, details []byte) *apiv1.Failure { + if reason == nil { + return nil + } + return &apiv1.Failure{ + Reason: *reason, + Details: details, + } +} + +func ToFailureReason(failure *apiv1.Failure) *string { + if failure == nil { + return nil + } + return &failure.Reason +} + +func ToFailureDetails(failure *apiv1.Failure) []byte { + if failure == nil { + return nil + } + return failure.Details +} + +func FromHistoryEvent(e *types.HistoryEvent) *apiv1.HistoryEvent { + if e == nil { + return nil + } + event := apiv1.HistoryEvent{ + EventId: e.EventID, + EventTime: unixNanoToTime(e.Timestamp), + Version: e.Version, + TaskId: e.TaskID, + } + switch *e.EventType { + case types.EventTypeWorkflowExecutionStarted: + event.Attributes = &apiv1.HistoryEvent_WorkflowExecutionStartedEventAttributes{ + WorkflowExecutionStartedEventAttributes: FromWorkflowExecutionStartedEventAttributes(e.WorkflowExecutionStartedEventAttributes), + } + case types.EventTypeWorkflowExecutionCompleted: + event.Attributes = &apiv1.HistoryEvent_WorkflowExecutionCompletedEventAttributes{ + WorkflowExecutionCompletedEventAttributes: FromWorkflowExecutionCompletedEventAttributes(e.WorkflowExecutionCompletedEventAttributes), + } + case types.EventTypeWorkflowExecutionFailed: + event.Attributes = &apiv1.HistoryEvent_WorkflowExecutionFailedEventAttributes{ + WorkflowExecutionFailedEventAttributes: FromWorkflowExecutionFailedEventAttributes(e.WorkflowExecutionFailedEventAttributes), + } + case types.EventTypeWorkflowExecutionTimedOut: + event.Attributes = &apiv1.HistoryEvent_WorkflowExecutionTimedOutEventAttributes{ + WorkflowExecutionTimedOutEventAttributes: FromWorkflowExecutionTimedOutEventAttributes(e.WorkflowExecutionTimedOutEventAttributes), + } + case types.EventTypeDecisionTaskScheduled: + event.Attributes = &apiv1.HistoryEvent_DecisionTaskScheduledEventAttributes{ + DecisionTaskScheduledEventAttributes: FromDecisionTaskScheduledEventAttributes(e.DecisionTaskScheduledEventAttributes), + } + case types.EventTypeDecisionTaskStarted: + event.Attributes = &apiv1.HistoryEvent_DecisionTaskStartedEventAttributes{ + DecisionTaskStartedEventAttributes: FromDecisionTaskStartedEventAttributes(e.DecisionTaskStartedEventAttributes), + } + case types.EventTypeDecisionTaskCompleted: + event.Attributes = &apiv1.HistoryEvent_DecisionTaskCompletedEventAttributes{ + DecisionTaskCompletedEventAttributes: FromDecisionTaskCompletedEventAttributes(e.DecisionTaskCompletedEventAttributes), + } + case types.EventTypeDecisionTaskTimedOut: + event.Attributes = &apiv1.HistoryEvent_DecisionTaskTimedOutEventAttributes{ + DecisionTaskTimedOutEventAttributes: FromDecisionTaskTimedOutEventAttributes(e.DecisionTaskTimedOutEventAttributes), + } + case types.EventTypeDecisionTaskFailed: + event.Attributes = &apiv1.HistoryEvent_DecisionTaskFailedEventAttributes{ + DecisionTaskFailedEventAttributes: FromDecisionTaskFailedEventAttributes(e.DecisionTaskFailedEventAttributes), + } + case types.EventTypeActivityTaskScheduled: + event.Attributes = &apiv1.HistoryEvent_ActivityTaskScheduledEventAttributes{ + ActivityTaskScheduledEventAttributes: FromActivityTaskScheduledEventAttributes(e.ActivityTaskScheduledEventAttributes), + } + case types.EventTypeActivityTaskStarted: + event.Attributes = &apiv1.HistoryEvent_ActivityTaskStartedEventAttributes{ + ActivityTaskStartedEventAttributes: FromActivityTaskStartedEventAttributes(e.ActivityTaskStartedEventAttributes), + } + case types.EventTypeActivityTaskCompleted: + event.Attributes = &apiv1.HistoryEvent_ActivityTaskCompletedEventAttributes{ + ActivityTaskCompletedEventAttributes: FromActivityTaskCompletedEventAttributes(e.ActivityTaskCompletedEventAttributes), + } + case types.EventTypeActivityTaskFailed: + event.Attributes = &apiv1.HistoryEvent_ActivityTaskFailedEventAttributes{ + ActivityTaskFailedEventAttributes: FromActivityTaskFailedEventAttributes(e.ActivityTaskFailedEventAttributes), + } + case types.EventTypeActivityTaskTimedOut: + event.Attributes = &apiv1.HistoryEvent_ActivityTaskTimedOutEventAttributes{ + ActivityTaskTimedOutEventAttributes: FromActivityTaskTimedOutEventAttributes(e.ActivityTaskTimedOutEventAttributes), + } + case types.EventTypeActivityTaskCancelRequested: + event.Attributes = &apiv1.HistoryEvent_ActivityTaskCancelRequestedEventAttributes{ + ActivityTaskCancelRequestedEventAttributes: FromActivityTaskCancelRequestedEventAttributes(e.ActivityTaskCancelRequestedEventAttributes), + } + case types.EventTypeRequestCancelActivityTaskFailed: + event.Attributes = &apiv1.HistoryEvent_RequestCancelActivityTaskFailedEventAttributes{ + RequestCancelActivityTaskFailedEventAttributes: FromRequestCancelActivityTaskFailedEventAttributes(e.RequestCancelActivityTaskFailedEventAttributes), + } + case types.EventTypeActivityTaskCanceled: + event.Attributes = &apiv1.HistoryEvent_ActivityTaskCanceledEventAttributes{ + ActivityTaskCanceledEventAttributes: FromActivityTaskCanceledEventAttributes(e.ActivityTaskCanceledEventAttributes), + } + case types.EventTypeTimerStarted: + event.Attributes = &apiv1.HistoryEvent_TimerStartedEventAttributes{ + TimerStartedEventAttributes: FromTimerStartedEventAttributes(e.TimerStartedEventAttributes), + } + case types.EventTypeTimerFired: + event.Attributes = &apiv1.HistoryEvent_TimerFiredEventAttributes{ + TimerFiredEventAttributes: FromTimerFiredEventAttributes(e.TimerFiredEventAttributes), + } + case types.EventTypeTimerCanceled: + event.Attributes = &apiv1.HistoryEvent_TimerCanceledEventAttributes{ + TimerCanceledEventAttributes: FromTimerCanceledEventAttributes(e.TimerCanceledEventAttributes), + } + case types.EventTypeCancelTimerFailed: + event.Attributes = &apiv1.HistoryEvent_CancelTimerFailedEventAttributes{ + CancelTimerFailedEventAttributes: FromCancelTimerFailedEventAttributes(e.CancelTimerFailedEventAttributes), + } + case types.EventTypeWorkflowExecutionCancelRequested: + event.Attributes = &apiv1.HistoryEvent_WorkflowExecutionCancelRequestedEventAttributes{ + WorkflowExecutionCancelRequestedEventAttributes: FromWorkflowExecutionCancelRequestedEventAttributes(e.WorkflowExecutionCancelRequestedEventAttributes), + } + case types.EventTypeWorkflowExecutionCanceled: + event.Attributes = &apiv1.HistoryEvent_WorkflowExecutionCanceledEventAttributes{ + WorkflowExecutionCanceledEventAttributes: FromWorkflowExecutionCanceledEventAttributes(e.WorkflowExecutionCanceledEventAttributes), + } + case types.EventTypeRequestCancelExternalWorkflowExecutionInitiated: + event.Attributes = &apiv1.HistoryEvent_RequestCancelExternalWorkflowExecutionInitiatedEventAttributes{ + RequestCancelExternalWorkflowExecutionInitiatedEventAttributes: FromRequestCancelExternalWorkflowExecutionInitiatedEventAttributes(e.RequestCancelExternalWorkflowExecutionInitiatedEventAttributes), + } + case types.EventTypeRequestCancelExternalWorkflowExecutionFailed: + event.Attributes = &apiv1.HistoryEvent_RequestCancelExternalWorkflowExecutionFailedEventAttributes{ + RequestCancelExternalWorkflowExecutionFailedEventAttributes: FromRequestCancelExternalWorkflowExecutionFailedEventAttributes(e.RequestCancelExternalWorkflowExecutionFailedEventAttributes), + } + case types.EventTypeExternalWorkflowExecutionCancelRequested: + event.Attributes = &apiv1.HistoryEvent_ExternalWorkflowExecutionCancelRequestedEventAttributes{ + ExternalWorkflowExecutionCancelRequestedEventAttributes: FromExternalWorkflowExecutionCancelRequestedEventAttributes(e.ExternalWorkflowExecutionCancelRequestedEventAttributes), + } + case types.EventTypeMarkerRecorded: + event.Attributes = &apiv1.HistoryEvent_MarkerRecordedEventAttributes{ + MarkerRecordedEventAttributes: FromMarkerRecordedEventAttributes(e.MarkerRecordedEventAttributes), + } + case types.EventTypeWorkflowExecutionSignaled: + event.Attributes = &apiv1.HistoryEvent_WorkflowExecutionSignaledEventAttributes{ + WorkflowExecutionSignaledEventAttributes: FromWorkflowExecutionSignaledEventAttributes(e.WorkflowExecutionSignaledEventAttributes), + } + case types.EventTypeWorkflowExecutionTerminated: + event.Attributes = &apiv1.HistoryEvent_WorkflowExecutionTerminatedEventAttributes{ + WorkflowExecutionTerminatedEventAttributes: FromWorkflowExecutionTerminatedEventAttributes(e.WorkflowExecutionTerminatedEventAttributes), + } + case types.EventTypeWorkflowExecutionContinuedAsNew: + event.Attributes = &apiv1.HistoryEvent_WorkflowExecutionContinuedAsNewEventAttributes{ + WorkflowExecutionContinuedAsNewEventAttributes: FromWorkflowExecutionContinuedAsNewEventAttributes(e.WorkflowExecutionContinuedAsNewEventAttributes), + } + case types.EventTypeStartChildWorkflowExecutionInitiated: + event.Attributes = &apiv1.HistoryEvent_StartChildWorkflowExecutionInitiatedEventAttributes{ + StartChildWorkflowExecutionInitiatedEventAttributes: FromStartChildWorkflowExecutionInitiatedEventAttributes(e.StartChildWorkflowExecutionInitiatedEventAttributes), + } + case types.EventTypeStartChildWorkflowExecutionFailed: + event.Attributes = &apiv1.HistoryEvent_StartChildWorkflowExecutionFailedEventAttributes{ + StartChildWorkflowExecutionFailedEventAttributes: FromStartChildWorkflowExecutionFailedEventAttributes(e.StartChildWorkflowExecutionFailedEventAttributes), + } + case types.EventTypeChildWorkflowExecutionStarted: + event.Attributes = &apiv1.HistoryEvent_ChildWorkflowExecutionStartedEventAttributes{ + ChildWorkflowExecutionStartedEventAttributes: FromChildWorkflowExecutionStartedEventAttributes(e.ChildWorkflowExecutionStartedEventAttributes), + } + case types.EventTypeChildWorkflowExecutionCompleted: + event.Attributes = &apiv1.HistoryEvent_ChildWorkflowExecutionCompletedEventAttributes{ + ChildWorkflowExecutionCompletedEventAttributes: FromChildWorkflowExecutionCompletedEventAttributes(e.ChildWorkflowExecutionCompletedEventAttributes), + } + case types.EventTypeChildWorkflowExecutionFailed: + event.Attributes = &apiv1.HistoryEvent_ChildWorkflowExecutionFailedEventAttributes{ + ChildWorkflowExecutionFailedEventAttributes: FromChildWorkflowExecutionFailedEventAttributes(e.ChildWorkflowExecutionFailedEventAttributes), + } + case types.EventTypeChildWorkflowExecutionCanceled: + event.Attributes = &apiv1.HistoryEvent_ChildWorkflowExecutionCanceledEventAttributes{ + ChildWorkflowExecutionCanceledEventAttributes: FromChildWorkflowExecutionCanceledEventAttributes(e.ChildWorkflowExecutionCanceledEventAttributes), + } + case types.EventTypeChildWorkflowExecutionTimedOut: + event.Attributes = &apiv1.HistoryEvent_ChildWorkflowExecutionTimedOutEventAttributes{ + ChildWorkflowExecutionTimedOutEventAttributes: FromChildWorkflowExecutionTimedOutEventAttributes(e.ChildWorkflowExecutionTimedOutEventAttributes), + } + case types.EventTypeChildWorkflowExecutionTerminated: + event.Attributes = &apiv1.HistoryEvent_ChildWorkflowExecutionTerminatedEventAttributes{ + ChildWorkflowExecutionTerminatedEventAttributes: FromChildWorkflowExecutionTerminatedEventAttributes(e.ChildWorkflowExecutionTerminatedEventAttributes), + } + case types.EventTypeSignalExternalWorkflowExecutionInitiated: + event.Attributes = &apiv1.HistoryEvent_SignalExternalWorkflowExecutionInitiatedEventAttributes{ + SignalExternalWorkflowExecutionInitiatedEventAttributes: FromSignalExternalWorkflowExecutionInitiatedEventAttributes(e.SignalExternalWorkflowExecutionInitiatedEventAttributes), + } + case types.EventTypeSignalExternalWorkflowExecutionFailed: + event.Attributes = &apiv1.HistoryEvent_SignalExternalWorkflowExecutionFailedEventAttributes{ + SignalExternalWorkflowExecutionFailedEventAttributes: FromSignalExternalWorkflowExecutionFailedEventAttributes(e.SignalExternalWorkflowExecutionFailedEventAttributes), + } + case types.EventTypeExternalWorkflowExecutionSignaled: + event.Attributes = &apiv1.HistoryEvent_ExternalWorkflowExecutionSignaledEventAttributes{ + ExternalWorkflowExecutionSignaledEventAttributes: FromExternalWorkflowExecutionSignaledEventAttributes(e.ExternalWorkflowExecutionSignaledEventAttributes), + } + case types.EventTypeUpsertWorkflowSearchAttributes: + event.Attributes = &apiv1.HistoryEvent_UpsertWorkflowSearchAttributesEventAttributes{ + UpsertWorkflowSearchAttributesEventAttributes: FromUpsertWorkflowSearchAttributesEventAttributes(e.UpsertWorkflowSearchAttributesEventAttributes), + } + } + return &event +} + +func ToHistoryEvent(e *apiv1.HistoryEvent) *types.HistoryEvent { + if e == nil { + return nil + } + event := types.HistoryEvent{ + EventID: e.EventId, + Timestamp: timeToUnixNano(e.EventTime), + Version: e.Version, + TaskID: e.TaskId, + } + switch attr := e.Attributes.(type) { + case *apiv1.HistoryEvent_WorkflowExecutionStartedEventAttributes: + event.EventType = types.EventTypeWorkflowExecutionStarted.Ptr() + event.WorkflowExecutionStartedEventAttributes = ToWorkflowExecutionStartedEventAttributes(attr.WorkflowExecutionStartedEventAttributes) + case *apiv1.HistoryEvent_WorkflowExecutionCompletedEventAttributes: + event.EventType = types.EventTypeWorkflowExecutionCompleted.Ptr() + event.WorkflowExecutionCompletedEventAttributes = ToWorkflowExecutionCompletedEventAttributes(attr.WorkflowExecutionCompletedEventAttributes) + case *apiv1.HistoryEvent_WorkflowExecutionFailedEventAttributes: + event.EventType = types.EventTypeWorkflowExecutionFailed.Ptr() + event.WorkflowExecutionFailedEventAttributes = ToWorkflowExecutionFailedEventAttributes(attr.WorkflowExecutionFailedEventAttributes) + case *apiv1.HistoryEvent_WorkflowExecutionTimedOutEventAttributes: + event.EventType = types.EventTypeWorkflowExecutionTimedOut.Ptr() + event.WorkflowExecutionTimedOutEventAttributes = ToWorkflowExecutionTimedOutEventAttributes(attr.WorkflowExecutionTimedOutEventAttributes) + case *apiv1.HistoryEvent_DecisionTaskScheduledEventAttributes: + event.EventType = types.EventTypeDecisionTaskScheduled.Ptr() + event.DecisionTaskScheduledEventAttributes = ToDecisionTaskScheduledEventAttributes(attr.DecisionTaskScheduledEventAttributes) + case *apiv1.HistoryEvent_DecisionTaskStartedEventAttributes: + event.EventType = types.EventTypeDecisionTaskStarted.Ptr() + event.DecisionTaskStartedEventAttributes = ToDecisionTaskStartedEventAttributes(attr.DecisionTaskStartedEventAttributes) + case *apiv1.HistoryEvent_DecisionTaskCompletedEventAttributes: + event.EventType = types.EventTypeDecisionTaskCompleted.Ptr() + event.DecisionTaskCompletedEventAttributes = ToDecisionTaskCompletedEventAttributes(attr.DecisionTaskCompletedEventAttributes) + case *apiv1.HistoryEvent_DecisionTaskTimedOutEventAttributes: + event.EventType = types.EventTypeDecisionTaskTimedOut.Ptr() + event.DecisionTaskTimedOutEventAttributes = ToDecisionTaskTimedOutEventAttributes(attr.DecisionTaskTimedOutEventAttributes) + case *apiv1.HistoryEvent_DecisionTaskFailedEventAttributes: + event.EventType = types.EventTypeDecisionTaskFailed.Ptr() + event.DecisionTaskFailedEventAttributes = ToDecisionTaskFailedEventAttributes(attr.DecisionTaskFailedEventAttributes) + case *apiv1.HistoryEvent_ActivityTaskScheduledEventAttributes: + event.EventType = types.EventTypeActivityTaskScheduled.Ptr() + event.ActivityTaskScheduledEventAttributes = ToActivityTaskScheduledEventAttributes(attr.ActivityTaskScheduledEventAttributes) + case *apiv1.HistoryEvent_ActivityTaskStartedEventAttributes: + event.EventType = types.EventTypeActivityTaskStarted.Ptr() + event.ActivityTaskStartedEventAttributes = ToActivityTaskStartedEventAttributes(attr.ActivityTaskStartedEventAttributes) + case *apiv1.HistoryEvent_ActivityTaskCompletedEventAttributes: + event.EventType = types.EventTypeActivityTaskCompleted.Ptr() + event.ActivityTaskCompletedEventAttributes = ToActivityTaskCompletedEventAttributes(attr.ActivityTaskCompletedEventAttributes) + case *apiv1.HistoryEvent_ActivityTaskFailedEventAttributes: + event.EventType = types.EventTypeActivityTaskFailed.Ptr() + event.ActivityTaskFailedEventAttributes = ToActivityTaskFailedEventAttributes(attr.ActivityTaskFailedEventAttributes) + case *apiv1.HistoryEvent_ActivityTaskTimedOutEventAttributes: + event.EventType = types.EventTypeActivityTaskTimedOut.Ptr() + event.ActivityTaskTimedOutEventAttributes = ToActivityTaskTimedOutEventAttributes(attr.ActivityTaskTimedOutEventAttributes) + case *apiv1.HistoryEvent_TimerStartedEventAttributes: + event.EventType = types.EventTypeTimerStarted.Ptr() + event.TimerStartedEventAttributes = ToTimerStartedEventAttributes(attr.TimerStartedEventAttributes) + case *apiv1.HistoryEvent_TimerFiredEventAttributes: + event.EventType = types.EventTypeTimerFired.Ptr() + event.TimerFiredEventAttributes = ToTimerFiredEventAttributes(attr.TimerFiredEventAttributes) + case *apiv1.HistoryEvent_ActivityTaskCancelRequestedEventAttributes: + event.EventType = types.EventTypeActivityTaskCancelRequested.Ptr() + event.ActivityTaskCancelRequestedEventAttributes = ToActivityTaskCancelRequestedEventAttributes(attr.ActivityTaskCancelRequestedEventAttributes) + case *apiv1.HistoryEvent_RequestCancelActivityTaskFailedEventAttributes: + event.EventType = types.EventTypeRequestCancelActivityTaskFailed.Ptr() + event.RequestCancelActivityTaskFailedEventAttributes = ToRequestCancelActivityTaskFailedEventAttributes(attr.RequestCancelActivityTaskFailedEventAttributes) + case *apiv1.HistoryEvent_ActivityTaskCanceledEventAttributes: + event.EventType = types.EventTypeActivityTaskCanceled.Ptr() + event.ActivityTaskCanceledEventAttributes = ToActivityTaskCanceledEventAttributes(attr.ActivityTaskCanceledEventAttributes) + case *apiv1.HistoryEvent_TimerCanceledEventAttributes: + event.EventType = types.EventTypeTimerCanceled.Ptr() + event.TimerCanceledEventAttributes = ToTimerCanceledEventAttributes(attr.TimerCanceledEventAttributes) + case *apiv1.HistoryEvent_CancelTimerFailedEventAttributes: + event.EventType = types.EventTypeCancelTimerFailed.Ptr() + event.CancelTimerFailedEventAttributes = ToCancelTimerFailedEventAttributes(attr.CancelTimerFailedEventAttributes) + case *apiv1.HistoryEvent_MarkerRecordedEventAttributes: + event.EventType = types.EventTypeMarkerRecorded.Ptr() + event.MarkerRecordedEventAttributes = ToMarkerRecordedEventAttributes(attr.MarkerRecordedEventAttributes) + case *apiv1.HistoryEvent_WorkflowExecutionSignaledEventAttributes: + event.EventType = types.EventTypeWorkflowExecutionSignaled.Ptr() + event.WorkflowExecutionSignaledEventAttributes = ToWorkflowExecutionSignaledEventAttributes(attr.WorkflowExecutionSignaledEventAttributes) + case *apiv1.HistoryEvent_WorkflowExecutionTerminatedEventAttributes: + event.EventType = types.EventTypeWorkflowExecutionTerminated.Ptr() + event.WorkflowExecutionTerminatedEventAttributes = ToWorkflowExecutionTerminatedEventAttributes(attr.WorkflowExecutionTerminatedEventAttributes) + case *apiv1.HistoryEvent_WorkflowExecutionCancelRequestedEventAttributes: + event.EventType = types.EventTypeWorkflowExecutionCancelRequested.Ptr() + event.WorkflowExecutionCancelRequestedEventAttributes = ToWorkflowExecutionCancelRequestedEventAttributes(attr.WorkflowExecutionCancelRequestedEventAttributes) + case *apiv1.HistoryEvent_WorkflowExecutionCanceledEventAttributes: + event.EventType = types.EventTypeWorkflowExecutionCanceled.Ptr() + event.WorkflowExecutionCanceledEventAttributes = ToWorkflowExecutionCanceledEventAttributes(attr.WorkflowExecutionCanceledEventAttributes) + case *apiv1.HistoryEvent_RequestCancelExternalWorkflowExecutionInitiatedEventAttributes: + event.EventType = types.EventTypeRequestCancelExternalWorkflowExecutionInitiated.Ptr() + event.RequestCancelExternalWorkflowExecutionInitiatedEventAttributes = ToRequestCancelExternalWorkflowExecutionInitiatedEventAttributes(attr.RequestCancelExternalWorkflowExecutionInitiatedEventAttributes) + case *apiv1.HistoryEvent_RequestCancelExternalWorkflowExecutionFailedEventAttributes: + event.EventType = types.EventTypeRequestCancelExternalWorkflowExecutionFailed.Ptr() + event.RequestCancelExternalWorkflowExecutionFailedEventAttributes = ToRequestCancelExternalWorkflowExecutionFailedEventAttributes(attr.RequestCancelExternalWorkflowExecutionFailedEventAttributes) + case *apiv1.HistoryEvent_ExternalWorkflowExecutionCancelRequestedEventAttributes: + event.EventType = types.EventTypeExternalWorkflowExecutionCancelRequested.Ptr() + event.ExternalWorkflowExecutionCancelRequestedEventAttributes = ToExternalWorkflowExecutionCancelRequestedEventAttributes(attr.ExternalWorkflowExecutionCancelRequestedEventAttributes) + case *apiv1.HistoryEvent_WorkflowExecutionContinuedAsNewEventAttributes: + event.EventType = types.EventTypeWorkflowExecutionContinuedAsNew.Ptr() + event.WorkflowExecutionContinuedAsNewEventAttributes = ToWorkflowExecutionContinuedAsNewEventAttributes(attr.WorkflowExecutionContinuedAsNewEventAttributes) + case *apiv1.HistoryEvent_StartChildWorkflowExecutionInitiatedEventAttributes: + event.EventType = types.EventTypeStartChildWorkflowExecutionInitiated.Ptr() + event.StartChildWorkflowExecutionInitiatedEventAttributes = ToStartChildWorkflowExecutionInitiatedEventAttributes(attr.StartChildWorkflowExecutionInitiatedEventAttributes) + case *apiv1.HistoryEvent_StartChildWorkflowExecutionFailedEventAttributes: + event.EventType = types.EventTypeStartChildWorkflowExecutionFailed.Ptr() + event.StartChildWorkflowExecutionFailedEventAttributes = ToStartChildWorkflowExecutionFailedEventAttributes(attr.StartChildWorkflowExecutionFailedEventAttributes) + case *apiv1.HistoryEvent_ChildWorkflowExecutionStartedEventAttributes: + event.EventType = types.EventTypeChildWorkflowExecutionStarted.Ptr() + event.ChildWorkflowExecutionStartedEventAttributes = ToChildWorkflowExecutionStartedEventAttributes(attr.ChildWorkflowExecutionStartedEventAttributes) + case *apiv1.HistoryEvent_ChildWorkflowExecutionCompletedEventAttributes: + event.EventType = types.EventTypeChildWorkflowExecutionCompleted.Ptr() + event.ChildWorkflowExecutionCompletedEventAttributes = ToChildWorkflowExecutionCompletedEventAttributes(attr.ChildWorkflowExecutionCompletedEventAttributes) + case *apiv1.HistoryEvent_ChildWorkflowExecutionFailedEventAttributes: + event.EventType = types.EventTypeChildWorkflowExecutionFailed.Ptr() + event.ChildWorkflowExecutionFailedEventAttributes = ToChildWorkflowExecutionFailedEventAttributes(attr.ChildWorkflowExecutionFailedEventAttributes) + case *apiv1.HistoryEvent_ChildWorkflowExecutionCanceledEventAttributes: + event.EventType = types.EventTypeChildWorkflowExecutionCanceled.Ptr() + event.ChildWorkflowExecutionCanceledEventAttributes = ToChildWorkflowExecutionCanceledEventAttributes(attr.ChildWorkflowExecutionCanceledEventAttributes) + case *apiv1.HistoryEvent_ChildWorkflowExecutionTimedOutEventAttributes: + event.EventType = types.EventTypeChildWorkflowExecutionTimedOut.Ptr() + event.ChildWorkflowExecutionTimedOutEventAttributes = ToChildWorkflowExecutionTimedOutEventAttributes(attr.ChildWorkflowExecutionTimedOutEventAttributes) + case *apiv1.HistoryEvent_ChildWorkflowExecutionTerminatedEventAttributes: + event.EventType = types.EventTypeChildWorkflowExecutionTerminated.Ptr() + event.ChildWorkflowExecutionTerminatedEventAttributes = ToChildWorkflowExecutionTerminatedEventAttributes(attr.ChildWorkflowExecutionTerminatedEventAttributes) + case *apiv1.HistoryEvent_SignalExternalWorkflowExecutionInitiatedEventAttributes: + event.EventType = types.EventTypeSignalExternalWorkflowExecutionInitiated.Ptr() + event.SignalExternalWorkflowExecutionInitiatedEventAttributes = ToSignalExternalWorkflowExecutionInitiatedEventAttributes(attr.SignalExternalWorkflowExecutionInitiatedEventAttributes) + case *apiv1.HistoryEvent_SignalExternalWorkflowExecutionFailedEventAttributes: + event.EventType = types.EventTypeSignalExternalWorkflowExecutionFailed.Ptr() + event.SignalExternalWorkflowExecutionFailedEventAttributes = ToSignalExternalWorkflowExecutionFailedEventAttributes(attr.SignalExternalWorkflowExecutionFailedEventAttributes) + case *apiv1.HistoryEvent_ExternalWorkflowExecutionSignaledEventAttributes: + event.EventType = types.EventTypeExternalWorkflowExecutionSignaled.Ptr() + event.ExternalWorkflowExecutionSignaledEventAttributes = ToExternalWorkflowExecutionSignaledEventAttributes(attr.ExternalWorkflowExecutionSignaledEventAttributes) + case *apiv1.HistoryEvent_UpsertWorkflowSearchAttributesEventAttributes: + event.EventType = types.EventTypeUpsertWorkflowSearchAttributes.Ptr() + event.UpsertWorkflowSearchAttributesEventAttributes = ToUpsertWorkflowSearchAttributesEventAttributes(attr.UpsertWorkflowSearchAttributesEventAttributes) + } + return &event +} + +func FromDecision(d *types.Decision) *apiv1.Decision { + if d == nil { + return nil + } + decision := apiv1.Decision{} + switch *d.DecisionType { + case types.DecisionTypeScheduleActivityTask: + decision.Attributes = &apiv1.Decision_ScheduleActivityTaskDecisionAttributes{ + ScheduleActivityTaskDecisionAttributes: FromScheduleActivityTaskDecisionAttributes(d.ScheduleActivityTaskDecisionAttributes), + } + case types.DecisionTypeRequestCancelActivityTask: + decision.Attributes = &apiv1.Decision_RequestCancelActivityTaskDecisionAttributes{ + RequestCancelActivityTaskDecisionAttributes: FromRequestCancelActivityTaskDecisionAttributes(d.RequestCancelActivityTaskDecisionAttributes), + } + case types.DecisionTypeStartTimer: + decision.Attributes = &apiv1.Decision_StartTimerDecisionAttributes{ + StartTimerDecisionAttributes: FromStartTimerDecisionAttributes(d.StartTimerDecisionAttributes), + } + case types.DecisionTypeCompleteWorkflowExecution: + decision.Attributes = &apiv1.Decision_CompleteWorkflowExecutionDecisionAttributes{ + CompleteWorkflowExecutionDecisionAttributes: FromCompleteWorkflowExecutionDecisionAttributes(d.CompleteWorkflowExecutionDecisionAttributes), + } + case types.DecisionTypeFailWorkflowExecution: + decision.Attributes = &apiv1.Decision_FailWorkflowExecutionDecisionAttributes{ + FailWorkflowExecutionDecisionAttributes: FromFailWorkflowExecutionDecisionAttributes(d.FailWorkflowExecutionDecisionAttributes), + } + case types.DecisionTypeCancelTimer: + decision.Attributes = &apiv1.Decision_CancelTimerDecisionAttributes{ + CancelTimerDecisionAttributes: FromCancelTimerDecisionAttributes(d.CancelTimerDecisionAttributes), + } + case types.DecisionTypeCancelWorkflowExecution: + decision.Attributes = &apiv1.Decision_CancelWorkflowExecutionDecisionAttributes{ + CancelWorkflowExecutionDecisionAttributes: FromCancelWorkflowExecutionDecisionAttributes(d.CancelWorkflowExecutionDecisionAttributes), + } + case types.DecisionTypeRequestCancelExternalWorkflowExecution: + decision.Attributes = &apiv1.Decision_RequestCancelExternalWorkflowExecutionDecisionAttributes{ + RequestCancelExternalWorkflowExecutionDecisionAttributes: FromRequestCancelExternalWorkflowExecutionDecisionAttributes(d.RequestCancelExternalWorkflowExecutionDecisionAttributes), + } + case types.DecisionTypeRecordMarker: + decision.Attributes = &apiv1.Decision_RecordMarkerDecisionAttributes{ + RecordMarkerDecisionAttributes: FromRecordMarkerDecisionAttributes(d.RecordMarkerDecisionAttributes), + } + case types.DecisionTypeContinueAsNewWorkflowExecution: + decision.Attributes = &apiv1.Decision_ContinueAsNewWorkflowExecutionDecisionAttributes{ + ContinueAsNewWorkflowExecutionDecisionAttributes: FromContinueAsNewWorkflowExecutionDecisionAttributes(d.ContinueAsNewWorkflowExecutionDecisionAttributes), + } + case types.DecisionTypeStartChildWorkflowExecution: + decision.Attributes = &apiv1.Decision_StartChildWorkflowExecutionDecisionAttributes{ + StartChildWorkflowExecutionDecisionAttributes: FromStartChildWorkflowExecutionDecisionAttributes(d.StartChildWorkflowExecutionDecisionAttributes), + } + case types.DecisionTypeSignalExternalWorkflowExecution: + decision.Attributes = &apiv1.Decision_SignalExternalWorkflowExecutionDecisionAttributes{ + SignalExternalWorkflowExecutionDecisionAttributes: FromSignalExternalWorkflowExecutionDecisionAttributes(d.SignalExternalWorkflowExecutionDecisionAttributes), + } + case types.DecisionTypeUpsertWorkflowSearchAttributes: + decision.Attributes = &apiv1.Decision_UpsertWorkflowSearchAttributesDecisionAttributes{ + UpsertWorkflowSearchAttributesDecisionAttributes: FromUpsertWorkflowSearchAttributesDecisionAttributes(d.UpsertWorkflowSearchAttributesDecisionAttributes), + } + } + return &decision +} + +func ToDecision(d *apiv1.Decision) *types.Decision { + if d == nil { + return nil + } + decision := types.Decision{} + switch attr := d.Attributes.(type) { + case *apiv1.Decision_ScheduleActivityTaskDecisionAttributes: + decision.DecisionType = types.DecisionTypeScheduleActivityTask.Ptr() + decision.ScheduleActivityTaskDecisionAttributes = ToScheduleActivityTaskDecisionAttributes(attr.ScheduleActivityTaskDecisionAttributes) + case *apiv1.Decision_StartTimerDecisionAttributes: + decision.DecisionType = types.DecisionTypeStartTimer.Ptr() + decision.StartTimerDecisionAttributes = ToStartTimerDecisionAttributes(attr.StartTimerDecisionAttributes) + case *apiv1.Decision_CompleteWorkflowExecutionDecisionAttributes: + decision.DecisionType = types.DecisionTypeCompleteWorkflowExecution.Ptr() + decision.CompleteWorkflowExecutionDecisionAttributes = ToCompleteWorkflowExecutionDecisionAttributes(attr.CompleteWorkflowExecutionDecisionAttributes) + case *apiv1.Decision_FailWorkflowExecutionDecisionAttributes: + decision.DecisionType = types.DecisionTypeFailWorkflowExecution.Ptr() + decision.FailWorkflowExecutionDecisionAttributes = ToFailWorkflowExecutionDecisionAttributes(attr.FailWorkflowExecutionDecisionAttributes) + case *apiv1.Decision_RequestCancelActivityTaskDecisionAttributes: + decision.DecisionType = types.DecisionTypeRequestCancelActivityTask.Ptr() + decision.RequestCancelActivityTaskDecisionAttributes = ToRequestCancelActivityTaskDecisionAttributes(attr.RequestCancelActivityTaskDecisionAttributes) + case *apiv1.Decision_CancelTimerDecisionAttributes: + decision.DecisionType = types.DecisionTypeCancelTimer.Ptr() + decision.CancelTimerDecisionAttributes = ToCancelTimerDecisionAttributes(attr.CancelTimerDecisionAttributes) + case *apiv1.Decision_CancelWorkflowExecutionDecisionAttributes: + decision.DecisionType = types.DecisionTypeCancelWorkflowExecution.Ptr() + decision.CancelWorkflowExecutionDecisionAttributes = ToCancelWorkflowExecutionDecisionAttributes(attr.CancelWorkflowExecutionDecisionAttributes) + case *apiv1.Decision_RequestCancelExternalWorkflowExecutionDecisionAttributes: + decision.DecisionType = types.DecisionTypeRequestCancelExternalWorkflowExecution.Ptr() + decision.RequestCancelExternalWorkflowExecutionDecisionAttributes = ToRequestCancelExternalWorkflowExecutionDecisionAttributes(attr.RequestCancelExternalWorkflowExecutionDecisionAttributes) + case *apiv1.Decision_RecordMarkerDecisionAttributes: + decision.DecisionType = types.DecisionTypeRecordMarker.Ptr() + decision.RecordMarkerDecisionAttributes = ToRecordMarkerDecisionAttributes(attr.RecordMarkerDecisionAttributes) + case *apiv1.Decision_ContinueAsNewWorkflowExecutionDecisionAttributes: + decision.DecisionType = types.DecisionTypeContinueAsNewWorkflowExecution.Ptr() + decision.ContinueAsNewWorkflowExecutionDecisionAttributes = ToContinueAsNewWorkflowExecutionDecisionAttributes(attr.ContinueAsNewWorkflowExecutionDecisionAttributes) + case *apiv1.Decision_StartChildWorkflowExecutionDecisionAttributes: + decision.DecisionType = types.DecisionTypeStartChildWorkflowExecution.Ptr() + decision.StartChildWorkflowExecutionDecisionAttributes = ToStartChildWorkflowExecutionDecisionAttributes(attr.StartChildWorkflowExecutionDecisionAttributes) + case *apiv1.Decision_SignalExternalWorkflowExecutionDecisionAttributes: + decision.DecisionType = types.DecisionTypeSignalExternalWorkflowExecution.Ptr() + decision.SignalExternalWorkflowExecutionDecisionAttributes = ToSignalExternalWorkflowExecutionDecisionAttributes(attr.SignalExternalWorkflowExecutionDecisionAttributes) + case *apiv1.Decision_UpsertWorkflowSearchAttributesDecisionAttributes: + decision.DecisionType = types.DecisionTypeUpsertWorkflowSearchAttributes.Ptr() + decision.UpsertWorkflowSearchAttributesDecisionAttributes = ToUpsertWorkflowSearchAttributesDecisionAttributes(attr.UpsertWorkflowSearchAttributesDecisionAttributes) + } + return &decision +} + +func FromListClosedWorkflowExecutionsRequest(r *types.ListClosedWorkflowExecutionsRequest) *apiv1.ListClosedWorkflowExecutionsRequest { + if r == nil { + return nil + } + request := apiv1.ListClosedWorkflowExecutionsRequest{ + Domain: r.Domain, + PageSize: r.MaximumPageSize, + NextPageToken: r.NextPageToken, + StartTimeFilter: FromStartTimeFilter(r.StartTimeFilter), + } + if r.ExecutionFilter != nil { + request.Filters = &apiv1.ListClosedWorkflowExecutionsRequest_ExecutionFilter{ + ExecutionFilter: FromWorkflowExecutionFilter(r.ExecutionFilter), + } + } + if r.TypeFilter != nil { + request.Filters = &apiv1.ListClosedWorkflowExecutionsRequest_TypeFilter{ + TypeFilter: FromWorkflowTypeFilter(r.TypeFilter), + } + } + if r.StatusFilter != nil { + request.Filters = &apiv1.ListClosedWorkflowExecutionsRequest_StatusFilter{ + StatusFilter: FromStatusFilter(r.StatusFilter), + } + } + + return &request +} + +func ToListClosedWorkflowExecutionsRequest(r *apiv1.ListClosedWorkflowExecutionsRequest) *types.ListClosedWorkflowExecutionsRequest { + if r == nil { + return nil + } + request := types.ListClosedWorkflowExecutionsRequest{ + Domain: r.Domain, + MaximumPageSize: r.PageSize, + NextPageToken: r.NextPageToken, + StartTimeFilter: ToStartTimeFilter(r.StartTimeFilter), + } + switch filters := r.Filters.(type) { + case *apiv1.ListClosedWorkflowExecutionsRequest_ExecutionFilter: + request.ExecutionFilter = ToWorkflowExecutionFilter(filters.ExecutionFilter) + case *apiv1.ListClosedWorkflowExecutionsRequest_TypeFilter: + request.TypeFilter = ToWorkflowTypeFilter(filters.TypeFilter) + case *apiv1.ListClosedWorkflowExecutionsRequest_StatusFilter: + request.StatusFilter = ToStatusFilter(filters.StatusFilter) + } + + return &request +} + +func FromListOpenWorkflowExecutionsRequest(r *types.ListOpenWorkflowExecutionsRequest) *apiv1.ListOpenWorkflowExecutionsRequest { + if r == nil { + return nil + } + request := apiv1.ListOpenWorkflowExecutionsRequest{ + Domain: r.Domain, + PageSize: r.MaximumPageSize, + NextPageToken: r.NextPageToken, + StartTimeFilter: FromStartTimeFilter(r.StartTimeFilter), + } + if r.ExecutionFilter != nil { + request.Filters = &apiv1.ListOpenWorkflowExecutionsRequest_ExecutionFilter{ + ExecutionFilter: FromWorkflowExecutionFilter(r.ExecutionFilter), + } + } + if r.TypeFilter != nil { + request.Filters = &apiv1.ListOpenWorkflowExecutionsRequest_TypeFilter{ + TypeFilter: FromWorkflowTypeFilter(r.TypeFilter), + } + } + + return &request +} + +func ToListOpenWorkflowExecutionsRequest(r *apiv1.ListOpenWorkflowExecutionsRequest) *types.ListOpenWorkflowExecutionsRequest { + if r == nil { + return nil + } + request := types.ListOpenWorkflowExecutionsRequest{ + Domain: r.Domain, + MaximumPageSize: r.PageSize, + NextPageToken: r.NextPageToken, + StartTimeFilter: ToStartTimeFilter(r.StartTimeFilter), + } + switch filters := r.Filters.(type) { + case *apiv1.ListOpenWorkflowExecutionsRequest_ExecutionFilter: + request.ExecutionFilter = ToWorkflowExecutionFilter(filters.ExecutionFilter) + case *apiv1.ListOpenWorkflowExecutionsRequest_TypeFilter: + request.TypeFilter = ToWorkflowTypeFilter(filters.TypeFilter) + } + return &request +} diff --git a/common/types/mapper/proto/api_test.go b/common/types/mapper/proto/api_test.go new file mode 100644 index 00000000000..31bc3794e01 --- /dev/null +++ b/common/types/mapper/proto/api_test.go @@ -0,0 +1,1002 @@ +// 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 ( + "testing" + + "github.com/stretchr/testify/assert" + + apiv1 "github.com/uber/cadence/.gen/proto/api/v1" + "github.com/uber/cadence/common" + "github.com/uber/cadence/common/types" + "github.com/uber/cadence/common/types/testdata" +) + +func TestActivityLocalDispatchInfo(t *testing.T) { + for _, item := range []*types.ActivityLocalDispatchInfo{nil, {}, &testdata.ActivityLocalDispatchInfo} { + assert.Equal(t, item, ToActivityLocalDispatchInfo(FromActivityLocalDispatchInfo(item))) + } +} +func TestActivityTaskCancelRequestedEventAttributes(t *testing.T) { + for _, item := range []*types.ActivityTaskCancelRequestedEventAttributes{nil, {}, &testdata.ActivityTaskCancelRequestedEventAttributes} { + assert.Equal(t, item, ToActivityTaskCancelRequestedEventAttributes(FromActivityTaskCancelRequestedEventAttributes(item))) + } +} +func TestActivityTaskCanceledEventAttributes(t *testing.T) { + for _, item := range []*types.ActivityTaskCanceledEventAttributes{nil, {}, &testdata.ActivityTaskCanceledEventAttributes} { + assert.Equal(t, item, ToActivityTaskCanceledEventAttributes(FromActivityTaskCanceledEventAttributes(item))) + } +} +func TestActivityTaskCompletedEventAttributes(t *testing.T) { + for _, item := range []*types.ActivityTaskCompletedEventAttributes{nil, {}, &testdata.ActivityTaskCompletedEventAttributes} { + assert.Equal(t, item, ToActivityTaskCompletedEventAttributes(FromActivityTaskCompletedEventAttributes(item))) + } +} +func TestActivityTaskFailedEventAttributes(t *testing.T) { + for _, item := range []*types.ActivityTaskFailedEventAttributes{nil, {}, &testdata.ActivityTaskFailedEventAttributes} { + assert.Equal(t, item, ToActivityTaskFailedEventAttributes(FromActivityTaskFailedEventAttributes(item))) + } +} +func TestActivityTaskScheduledEventAttributes(t *testing.T) { + for _, item := range []*types.ActivityTaskScheduledEventAttributes{nil, {}, &testdata.ActivityTaskScheduledEventAttributes} { + assert.Equal(t, item, ToActivityTaskScheduledEventAttributes(FromActivityTaskScheduledEventAttributes(item))) + } +} +func TestActivityTaskStartedEventAttributes(t *testing.T) { + for _, item := range []*types.ActivityTaskStartedEventAttributes{nil, {}, &testdata.ActivityTaskStartedEventAttributes} { + assert.Equal(t, item, ToActivityTaskStartedEventAttributes(FromActivityTaskStartedEventAttributes(item))) + } +} +func TestActivityTaskTimedOutEventAttributes(t *testing.T) { + for _, item := range []*types.ActivityTaskTimedOutEventAttributes{nil, {}, &testdata.ActivityTaskTimedOutEventAttributes} { + assert.Equal(t, item, ToActivityTaskTimedOutEventAttributes(FromActivityTaskTimedOutEventAttributes(item))) + } +} +func TestActivityType(t *testing.T) { + for _, item := range []*types.ActivityType{nil, {}, &testdata.ActivityType} { + assert.Equal(t, item, ToActivityType(FromActivityType(item))) + } +} +func TestBadBinaries(t *testing.T) { + for _, item := range []*types.BadBinaries{nil, {}, &testdata.BadBinaries} { + assert.Equal(t, item, ToBadBinaries(FromBadBinaries(item))) + } +} +func TestBadBinaryInfo(t *testing.T) { + for _, item := range []*types.BadBinaryInfo{nil, {}, &testdata.BadBinaryInfo} { + assert.Equal(t, item, ToBadBinaryInfo(FromBadBinaryInfo(item))) + } +} +func TestCancelTimerDecisionAttributes(t *testing.T) { + for _, item := range []*types.CancelTimerDecisionAttributes{nil, {}, &testdata.CancelTimerDecisionAttributes} { + assert.Equal(t, item, ToCancelTimerDecisionAttributes(FromCancelTimerDecisionAttributes(item))) + } +} +func TestCancelTimerFailedEventAttributes(t *testing.T) { + for _, item := range []*types.CancelTimerFailedEventAttributes{nil, {}, &testdata.CancelTimerFailedEventAttributes} { + assert.Equal(t, item, ToCancelTimerFailedEventAttributes(FromCancelTimerFailedEventAttributes(item))) + } +} +func TestCancelWorkflowExecutionDecisionAttributes(t *testing.T) { + for _, item := range []*types.CancelWorkflowExecutionDecisionAttributes{nil, {}, &testdata.CancelWorkflowExecutionDecisionAttributes} { + assert.Equal(t, item, ToCancelWorkflowExecutionDecisionAttributes(FromCancelWorkflowExecutionDecisionAttributes(item))) + } +} +func TestChildWorkflowExecutionCanceledEventAttributes(t *testing.T) { + for _, item := range []*types.ChildWorkflowExecutionCanceledEventAttributes{nil, {}, &testdata.ChildWorkflowExecutionCanceledEventAttributes} { + assert.Equal(t, item, ToChildWorkflowExecutionCanceledEventAttributes(FromChildWorkflowExecutionCanceledEventAttributes(item))) + } +} +func TestChildWorkflowExecutionCompletedEventAttributes(t *testing.T) { + for _, item := range []*types.ChildWorkflowExecutionCompletedEventAttributes{nil, {}, &testdata.ChildWorkflowExecutionCompletedEventAttributes} { + assert.Equal(t, item, ToChildWorkflowExecutionCompletedEventAttributes(FromChildWorkflowExecutionCompletedEventAttributes(item))) + } +} +func TestChildWorkflowExecutionFailedEventAttributes(t *testing.T) { + for _, item := range []*types.ChildWorkflowExecutionFailedEventAttributes{nil, {}, &testdata.ChildWorkflowExecutionFailedEventAttributes} { + assert.Equal(t, item, ToChildWorkflowExecutionFailedEventAttributes(FromChildWorkflowExecutionFailedEventAttributes(item))) + } +} +func TestChildWorkflowExecutionStartedEventAttributes(t *testing.T) { + for _, item := range []*types.ChildWorkflowExecutionStartedEventAttributes{nil, {}, &testdata.ChildWorkflowExecutionStartedEventAttributes} { + assert.Equal(t, item, ToChildWorkflowExecutionStartedEventAttributes(FromChildWorkflowExecutionStartedEventAttributes(item))) + } +} +func TestChildWorkflowExecutionTerminatedEventAttributes(t *testing.T) { + for _, item := range []*types.ChildWorkflowExecutionTerminatedEventAttributes{nil, {}, &testdata.ChildWorkflowExecutionTerminatedEventAttributes} { + assert.Equal(t, item, ToChildWorkflowExecutionTerminatedEventAttributes(FromChildWorkflowExecutionTerminatedEventAttributes(item))) + } +} +func TestChildWorkflowExecutionTimedOutEventAttributes(t *testing.T) { + for _, item := range []*types.ChildWorkflowExecutionTimedOutEventAttributes{nil, {}, &testdata.ChildWorkflowExecutionTimedOutEventAttributes} { + assert.Equal(t, item, ToChildWorkflowExecutionTimedOutEventAttributes(FromChildWorkflowExecutionTimedOutEventAttributes(item))) + } +} +func TestClusterReplicationConfiguration(t *testing.T) { + for _, item := range []*types.ClusterReplicationConfiguration{nil, {}, &testdata.ClusterReplicationConfiguration} { + assert.Equal(t, item, ToClusterReplicationConfiguration(FromClusterReplicationConfiguration(item))) + } +} +func TestCompleteWorkflowExecutionDecisionAttributes(t *testing.T) { + for _, item := range []*types.CompleteWorkflowExecutionDecisionAttributes{nil, {}, &testdata.CompleteWorkflowExecutionDecisionAttributes} { + assert.Equal(t, item, ToCompleteWorkflowExecutionDecisionAttributes(FromCompleteWorkflowExecutionDecisionAttributes(item))) + } +} +func TestContinueAsNewWorkflowExecutionDecisionAttributes(t *testing.T) { + for _, item := range []*types.ContinueAsNewWorkflowExecutionDecisionAttributes{nil, {}, &testdata.ContinueAsNewWorkflowExecutionDecisionAttributes} { + assert.Equal(t, item, ToContinueAsNewWorkflowExecutionDecisionAttributes(FromContinueAsNewWorkflowExecutionDecisionAttributes(item))) + } +} +func TestCountWorkflowExecutionsRequest(t *testing.T) { + for _, item := range []*types.CountWorkflowExecutionsRequest{nil, {}, &testdata.CountWorkflowExecutionsRequest} { + assert.Equal(t, item, ToCountWorkflowExecutionsRequest(FromCountWorkflowExecutionsRequest(item))) + } +} +func TestCountWorkflowExecutionsResponse(t *testing.T) { + for _, item := range []*types.CountWorkflowExecutionsResponse{nil, {}, &testdata.CountWorkflowExecutionsResponse} { + assert.Equal(t, item, ToCountWorkflowExecutionsResponse(FromCountWorkflowExecutionsResponse(item))) + } +} +func TestDataBlob(t *testing.T) { + for _, item := range []*types.DataBlob{nil, {}, &testdata.DataBlob} { + assert.Equal(t, item, ToDataBlob(FromDataBlob(item))) + } +} +func TestDecisionTaskCompletedEventAttributes(t *testing.T) { + for _, item := range []*types.DecisionTaskCompletedEventAttributes{nil, {}, &testdata.DecisionTaskCompletedEventAttributes} { + assert.Equal(t, item, ToDecisionTaskCompletedEventAttributes(FromDecisionTaskCompletedEventAttributes(item))) + } +} +func TestDecisionTaskFailedEventAttributes(t *testing.T) { + for _, item := range []*types.DecisionTaskFailedEventAttributes{nil, {}, &testdata.DecisionTaskFailedEventAttributes} { + assert.Equal(t, item, ToDecisionTaskFailedEventAttributes(FromDecisionTaskFailedEventAttributes(item))) + } +} +func TestDecisionTaskScheduledEventAttributes(t *testing.T) { + for _, item := range []*types.DecisionTaskScheduledEventAttributes{nil, {}, &testdata.DecisionTaskScheduledEventAttributes} { + assert.Equal(t, item, ToDecisionTaskScheduledEventAttributes(FromDecisionTaskScheduledEventAttributes(item))) + } +} +func TestDecisionTaskStartedEventAttributes(t *testing.T) { + for _, item := range []*types.DecisionTaskStartedEventAttributes{nil, {}, &testdata.DecisionTaskStartedEventAttributes} { + assert.Equal(t, item, ToDecisionTaskStartedEventAttributes(FromDecisionTaskStartedEventAttributes(item))) + } +} +func TestDecisionTaskTimedOutEventAttributes(t *testing.T) { + for _, item := range []*types.DecisionTaskTimedOutEventAttributes{nil, {}, &testdata.DecisionTaskTimedOutEventAttributes} { + assert.Equal(t, item, ToDecisionTaskTimedOutEventAttributes(FromDecisionTaskTimedOutEventAttributes(item))) + } +} +func TestDeprecateDomainRequest(t *testing.T) { + for _, item := range []*types.DeprecateDomainRequest{nil, {}, &testdata.DeprecateDomainRequest} { + assert.Equal(t, item, ToDeprecateDomainRequest(FromDeprecateDomainRequest(item))) + } +} +func TestDescribeDomainRequest(t *testing.T) { + for _, item := range []*types.DescribeDomainRequest{ + &testdata.DescribeDomainRequest_ID, + &testdata.DescribeDomainRequest_Name, + } { + assert.Equal(t, item, ToDescribeDomainRequest(FromDescribeDomainRequest(item))) + } + assert.Nil(t, ToDescribeDomainRequest(nil)) + assert.Nil(t, FromDescribeDomainRequest(nil)) + assert.Panics(t, func() { ToDescribeDomainRequest(&apiv1.DescribeDomainRequest{}) }) + assert.Panics(t, func() { FromDescribeDomainRequest(&types.DescribeDomainRequest{}) }) +} +func TestDescribeDomainResponse_Domain(t *testing.T) { + for _, item := range []*types.DescribeDomainResponse{nil, &testdata.DescribeDomainResponse} { + assert.Equal(t, item, ToDescribeDomainResponseDomain(FromDescribeDomainResponseDomain(item))) + } +} +func TestDescribeDomainResponse(t *testing.T) { + for _, item := range []*types.DescribeDomainResponse{nil, &testdata.DescribeDomainResponse} { + assert.Equal(t, item, ToDescribeDomainResponse(FromDescribeDomainResponse(item))) + } +} +func TestDescribeTaskListRequest(t *testing.T) { + for _, item := range []*types.DescribeTaskListRequest{nil, {}, &testdata.DescribeTaskListRequest} { + assert.Equal(t, item, ToDescribeTaskListRequest(FromDescribeTaskListRequest(item))) + } +} +func TestDescribeTaskListResponse(t *testing.T) { + for _, item := range []*types.DescribeTaskListResponse{nil, {}, &testdata.DescribeTaskListResponse} { + assert.Equal(t, item, ToDescribeTaskListResponse(FromDescribeTaskListResponse(item))) + } +} +func TestDescribeWorkflowExecutionRequest(t *testing.T) { + for _, item := range []*types.DescribeWorkflowExecutionRequest{nil, {}, &testdata.DescribeWorkflowExecutionRequest} { + assert.Equal(t, item, ToDescribeWorkflowExecutionRequest(FromDescribeWorkflowExecutionRequest(item))) + } +} +func TestDescribeWorkflowExecutionResponse(t *testing.T) { + for _, item := range []*types.DescribeWorkflowExecutionResponse{nil, {}, &testdata.DescribeWorkflowExecutionResponse} { + assert.Equal(t, item, ToDescribeWorkflowExecutionResponse(FromDescribeWorkflowExecutionResponse(item))) + } +} +func TestExternalWorkflowExecutionCancelRequestedEventAttributes(t *testing.T) { + for _, item := range []*types.ExternalWorkflowExecutionCancelRequestedEventAttributes{nil, {}, &testdata.ExternalWorkflowExecutionCancelRequestedEventAttributes} { + assert.Equal(t, item, ToExternalWorkflowExecutionCancelRequestedEventAttributes(FromExternalWorkflowExecutionCancelRequestedEventAttributes(item))) + } +} +func TestExternalWorkflowExecutionSignaledEventAttributes(t *testing.T) { + for _, item := range []*types.ExternalWorkflowExecutionSignaledEventAttributes{nil, {}, &testdata.ExternalWorkflowExecutionSignaledEventAttributes} { + assert.Equal(t, item, ToExternalWorkflowExecutionSignaledEventAttributes(FromExternalWorkflowExecutionSignaledEventAttributes(item))) + } +} +func TestFailWorkflowExecutionDecisionAttributes(t *testing.T) { + for _, item := range []*types.FailWorkflowExecutionDecisionAttributes{nil, {}, &testdata.FailWorkflowExecutionDecisionAttributes} { + assert.Equal(t, item, ToFailWorkflowExecutionDecisionAttributes(FromFailWorkflowExecutionDecisionAttributes(item))) + } +} +func TestGetClusterInfoResponse(t *testing.T) { + for _, item := range []*types.ClusterInfo{nil, {}, &testdata.ClusterInfo} { + assert.Equal(t, item, ToGetClusterInfoResponse(FromGetClusterInfoResponse(item))) + } +} +func TestGetSearchAttributesResponse(t *testing.T) { + for _, item := range []*types.GetSearchAttributesResponse{nil, {}, &testdata.GetSearchAttributesResponse} { + assert.Equal(t, item, ToGetSearchAttributesResponse(FromGetSearchAttributesResponse(item))) + } +} +func TestGetWorkflowExecutionHistoryRequest(t *testing.T) { + for _, item := range []*types.GetWorkflowExecutionHistoryRequest{nil, {}, &testdata.GetWorkflowExecutionHistoryRequest} { + assert.Equal(t, item, ToGetWorkflowExecutionHistoryRequest(FromGetWorkflowExecutionHistoryRequest(item))) + } +} +func TestGetWorkflowExecutionHistoryResponse(t *testing.T) { + for _, item := range []*types.GetWorkflowExecutionHistoryResponse{nil, {}, &testdata.GetWorkflowExecutionHistoryResponse} { + assert.Equal(t, item, ToGetWorkflowExecutionHistoryResponse(FromGetWorkflowExecutionHistoryResponse(item))) + } +} +func TestHeader(t *testing.T) { + for _, item := range []*types.Header{nil, {}, &testdata.Header} { + assert.Equal(t, item, ToHeader(FromHeader(item))) + } +} +func TestHealthResponse(t *testing.T) { + for _, item := range []*types.HealthStatus{nil, {}, &testdata.HealthStatus} { + assert.Equal(t, item, ToHealthResponse(FromHealthResponse(item))) + } +} +func TestHistory(t *testing.T) { + for _, item := range []*types.History{nil, {}, &testdata.History} { + assert.Equal(t, item, ToHistory(FromHistory(item))) + } +} +func TestListArchivedWorkflowExecutionsRequest(t *testing.T) { + for _, item := range []*types.ListArchivedWorkflowExecutionsRequest{nil, {}, &testdata.ListArchivedWorkflowExecutionsRequest} { + assert.Equal(t, item, ToListArchivedWorkflowExecutionsRequest(FromListArchivedWorkflowExecutionsRequest(item))) + } +} +func TestListArchivedWorkflowExecutionsResponse(t *testing.T) { + for _, item := range []*types.ListArchivedWorkflowExecutionsResponse{nil, {}, &testdata.ListArchivedWorkflowExecutionsResponse} { + assert.Equal(t, item, ToListArchivedWorkflowExecutionsResponse(FromListArchivedWorkflowExecutionsResponse(item))) + } +} +func TestListClosedWorkflowExecutionsResponse(t *testing.T) { + for _, item := range []*types.ListClosedWorkflowExecutionsResponse{nil, {}, &testdata.ListClosedWorkflowExecutionsResponse} { + assert.Equal(t, item, ToListClosedWorkflowExecutionsResponse(FromListClosedWorkflowExecutionsResponse(item))) + } +} +func TestListDomainsRequest(t *testing.T) { + for _, item := range []*types.ListDomainsRequest{nil, {}, &testdata.ListDomainsRequest} { + assert.Equal(t, item, ToListDomainsRequest(FromListDomainsRequest(item))) + } +} +func TestListDomainsResponse(t *testing.T) { + for _, item := range []*types.ListDomainsResponse{nil, {}, &testdata.ListDomainsResponse} { + assert.Equal(t, item, ToListDomainsResponse(FromListDomainsResponse(item))) + } +} +func TestListOpenWorkflowExecutionsResponse(t *testing.T) { + for _, item := range []*types.ListOpenWorkflowExecutionsResponse{nil, {}, &testdata.ListOpenWorkflowExecutionsResponse} { + assert.Equal(t, item, ToListOpenWorkflowExecutionsResponse(FromListOpenWorkflowExecutionsResponse(item))) + } +} +func TestListTaskListPartitionsRequest(t *testing.T) { + for _, item := range []*types.ListTaskListPartitionsRequest{nil, {}, &testdata.ListTaskListPartitionsRequest} { + assert.Equal(t, item, ToListTaskListPartitionsRequest(FromListTaskListPartitionsRequest(item))) + } +} +func TestListTaskListPartitionsResponse(t *testing.T) { + for _, item := range []*types.ListTaskListPartitionsResponse{nil, {}, &testdata.ListTaskListPartitionsResponse} { + assert.Equal(t, item, ToListTaskListPartitionsResponse(FromListTaskListPartitionsResponse(item))) + } +} +func TestListWorkflowExecutionsRequest(t *testing.T) { + for _, item := range []*types.ListWorkflowExecutionsRequest{nil, {}, &testdata.ListWorkflowExecutionsRequest} { + assert.Equal(t, item, ToListWorkflowExecutionsRequest(FromListWorkflowExecutionsRequest(item))) + } +} +func TestListWorkflowExecutionsResponse(t *testing.T) { + for _, item := range []*types.ListWorkflowExecutionsResponse{nil, {}, &testdata.ListWorkflowExecutionsResponse} { + assert.Equal(t, item, ToListWorkflowExecutionsResponse(FromListWorkflowExecutionsResponse(item))) + } +} +func TestMarkerRecordedEventAttributes(t *testing.T) { + for _, item := range []*types.MarkerRecordedEventAttributes{nil, {}, &testdata.MarkerRecordedEventAttributes} { + assert.Equal(t, item, ToMarkerRecordedEventAttributes(FromMarkerRecordedEventAttributes(item))) + } +} +func TestMemo(t *testing.T) { + for _, item := range []*types.Memo{nil, {}, &testdata.Memo} { + assert.Equal(t, item, ToMemo(FromMemo(item))) + } +} +func TestPendingActivityInfo(t *testing.T) { + for _, item := range []*types.PendingActivityInfo{nil, {}, &testdata.PendingActivityInfo} { + assert.Equal(t, item, ToPendingActivityInfo(FromPendingActivityInfo(item))) + } +} +func TestPendingChildExecutionInfo(t *testing.T) { + for _, item := range []*types.PendingChildExecutionInfo{nil, {}, &testdata.PendingChildExecutionInfo} { + assert.Equal(t, item, ToPendingChildExecutionInfo(FromPendingChildExecutionInfo(item))) + } +} +func TestPendingDecisionInfo(t *testing.T) { + for _, item := range []*types.PendingDecisionInfo{nil, {}, &testdata.PendingDecisionInfo} { + assert.Equal(t, item, ToPendingDecisionInfo(FromPendingDecisionInfo(item))) + } +} +func TestPollForActivityTaskRequest(t *testing.T) { + for _, item := range []*types.PollForActivityTaskRequest{nil, {}, &testdata.PollForActivityTaskRequest} { + assert.Equal(t, item, ToPollForActivityTaskRequest(FromPollForActivityTaskRequest(item))) + } +} +func TestPollForActivityTaskResponse(t *testing.T) { + for _, item := range []*types.PollForActivityTaskResponse{nil, {}, &testdata.PollForActivityTaskResponse} { + assert.Equal(t, item, ToPollForActivityTaskResponse(FromPollForActivityTaskResponse(item))) + } +} +func TestPollForDecisionTaskRequest(t *testing.T) { + for _, item := range []*types.PollForDecisionTaskRequest{nil, {}, &testdata.PollForDecisionTaskRequest} { + assert.Equal(t, item, ToPollForDecisionTaskRequest(FromPollForDecisionTaskRequest(item))) + } +} +func TestPollForDecisionTaskResponse(t *testing.T) { + for _, item := range []*types.PollForDecisionTaskResponse{nil, {}, &testdata.PollForDecisionTaskResponse} { + assert.Equal(t, item, ToPollForDecisionTaskResponse(FromPollForDecisionTaskResponse(item))) + } +} +func TestPollerInfo(t *testing.T) { + for _, item := range []*types.PollerInfo{nil, {}, &testdata.PollerInfo} { + assert.Equal(t, item, ToPollerInfo(FromPollerInfo(item))) + } +} +func TestQueryRejected(t *testing.T) { + for _, item := range []*types.QueryRejected{nil, {}, &testdata.QueryRejected} { + assert.Equal(t, item, ToQueryRejected(FromQueryRejected(item))) + } +} +func TestQueryWorkflowRequest(t *testing.T) { + for _, item := range []*types.QueryWorkflowRequest{nil, {}, &testdata.QueryWorkflowRequest} { + assert.Equal(t, item, ToQueryWorkflowRequest(FromQueryWorkflowRequest(item))) + } +} +func TestQueryWorkflowResponse(t *testing.T) { + for _, item := range []*types.QueryWorkflowResponse{nil, {}, &testdata.QueryWorkflowResponse} { + assert.Equal(t, item, ToQueryWorkflowResponse(FromQueryWorkflowResponse(item))) + } +} +func TestRecordActivityTaskHeartbeatByIDRequest(t *testing.T) { + for _, item := range []*types.RecordActivityTaskHeartbeatByIDRequest{nil, {}, &testdata.RecordActivityTaskHeartbeatByIDRequest} { + assert.Equal(t, item, ToRecordActivityTaskHeartbeatByIDRequest(FromRecordActivityTaskHeartbeatByIDRequest(item))) + } +} +func TestRecordActivityTaskHeartbeatByIDResponse(t *testing.T) { + for _, item := range []*types.RecordActivityTaskHeartbeatResponse{nil, {}, &testdata.RecordActivityTaskHeartbeatResponse} { + assert.Equal(t, item, ToRecordActivityTaskHeartbeatByIDResponse(FromRecordActivityTaskHeartbeatByIDResponse(item))) + } +} +func TestRecordActivityTaskHeartbeatRequest(t *testing.T) { + for _, item := range []*types.RecordActivityTaskHeartbeatRequest{nil, {}, &testdata.RecordActivityTaskHeartbeatRequest} { + assert.Equal(t, item, ToRecordActivityTaskHeartbeatRequest(FromRecordActivityTaskHeartbeatRequest(item))) + } +} +func TestRecordActivityTaskHeartbeatResponse(t *testing.T) { + for _, item := range []*types.RecordActivityTaskHeartbeatResponse{nil, {}, &testdata.RecordActivityTaskHeartbeatResponse} { + assert.Equal(t, item, ToRecordActivityTaskHeartbeatResponse(FromRecordActivityTaskHeartbeatResponse(item))) + } +} +func TestRecordMarkerDecisionAttributes(t *testing.T) { + for _, item := range []*types.RecordMarkerDecisionAttributes{nil, {}, &testdata.RecordMarkerDecisionAttributes} { + assert.Equal(t, item, ToRecordMarkerDecisionAttributes(FromRecordMarkerDecisionAttributes(item))) + } +} +func TestRegisterDomainRequest(t *testing.T) { + for _, item := range []*types.RegisterDomainRequest{nil, {EmitMetric: common.BoolPtr(true)}, &testdata.RegisterDomainRequest} { + assert.Equal(t, item, ToRegisterDomainRequest(FromRegisterDomainRequest(item))) + } +} +func TestRequestCancelActivityTaskDecisionAttributes(t *testing.T) { + for _, item := range []*types.RequestCancelActivityTaskDecisionAttributes{nil, {}, &testdata.RequestCancelActivityTaskDecisionAttributes} { + assert.Equal(t, item, ToRequestCancelActivityTaskDecisionAttributes(FromRequestCancelActivityTaskDecisionAttributes(item))) + } +} +func TestRequestCancelActivityTaskFailedEventAttributes(t *testing.T) { + for _, item := range []*types.RequestCancelActivityTaskFailedEventAttributes{nil, {}, &testdata.RequestCancelActivityTaskFailedEventAttributes} { + assert.Equal(t, item, ToRequestCancelActivityTaskFailedEventAttributes(FromRequestCancelActivityTaskFailedEventAttributes(item))) + } +} +func TestRequestCancelExternalWorkflowExecutionDecisionAttributes(t *testing.T) { + for _, item := range []*types.RequestCancelExternalWorkflowExecutionDecisionAttributes{nil, {}, &testdata.RequestCancelExternalWorkflowExecutionDecisionAttributes} { + assert.Equal(t, item, ToRequestCancelExternalWorkflowExecutionDecisionAttributes(FromRequestCancelExternalWorkflowExecutionDecisionAttributes(item))) + } +} +func TestRequestCancelExternalWorkflowExecutionFailedEventAttributes(t *testing.T) { + for _, item := range []*types.RequestCancelExternalWorkflowExecutionFailedEventAttributes{nil, {}, &testdata.RequestCancelExternalWorkflowExecutionFailedEventAttributes} { + assert.Equal(t, item, ToRequestCancelExternalWorkflowExecutionFailedEventAttributes(FromRequestCancelExternalWorkflowExecutionFailedEventAttributes(item))) + } +} +func TestRequestCancelExternalWorkflowExecutionInitiatedEventAttributes(t *testing.T) { + for _, item := range []*types.RequestCancelExternalWorkflowExecutionInitiatedEventAttributes{nil, {}, &testdata.RequestCancelExternalWorkflowExecutionInitiatedEventAttributes} { + assert.Equal(t, item, ToRequestCancelExternalWorkflowExecutionInitiatedEventAttributes(FromRequestCancelExternalWorkflowExecutionInitiatedEventAttributes(item))) + } +} +func TestRequestCancelWorkflowExecutionRequest(t *testing.T) { + for _, item := range []*types.RequestCancelWorkflowExecutionRequest{nil, {}, &testdata.RequestCancelWorkflowExecutionRequest} { + assert.Equal(t, item, ToRequestCancelWorkflowExecutionRequest(FromRequestCancelWorkflowExecutionRequest(item))) + } +} +func TestResetPointInfo(t *testing.T) { + for _, item := range []*types.ResetPointInfo{nil, {}, &testdata.ResetPointInfo} { + assert.Equal(t, item, ToResetPointInfo(FromResetPointInfo(item))) + } +} +func TestResetPoints(t *testing.T) { + for _, item := range []*types.ResetPoints{nil, {}, &testdata.ResetPoints} { + assert.Equal(t, item, ToResetPoints(FromResetPoints(item))) + } +} +func TestResetStickyTaskListRequest(t *testing.T) { + for _, item := range []*types.ResetStickyTaskListRequest{nil, {}, &testdata.ResetStickyTaskListRequest} { + assert.Equal(t, item, ToResetStickyTaskListRequest(FromResetStickyTaskListRequest(item))) + } +} +func TestResetWorkflowExecutionRequest(t *testing.T) { + for _, item := range []*types.ResetWorkflowExecutionRequest{nil, {}, &testdata.ResetWorkflowExecutionRequest} { + assert.Equal(t, item, ToResetWorkflowExecutionRequest(FromResetWorkflowExecutionRequest(item))) + } +} +func TestResetWorkflowExecutionResponse(t *testing.T) { + for _, item := range []*types.ResetWorkflowExecutionResponse{nil, {}, &testdata.ResetWorkflowExecutionResponse} { + assert.Equal(t, item, ToResetWorkflowExecutionResponse(FromResetWorkflowExecutionResponse(item))) + } +} +func TestRespondActivityTaskCanceledByIDRequest(t *testing.T) { + for _, item := range []*types.RespondActivityTaskCanceledByIDRequest{nil, {}, &testdata.RespondActivityTaskCanceledByIDRequest} { + assert.Equal(t, item, ToRespondActivityTaskCanceledByIDRequest(FromRespondActivityTaskCanceledByIDRequest(item))) + } +} +func TestRespondActivityTaskCanceledRequest(t *testing.T) { + for _, item := range []*types.RespondActivityTaskCanceledRequest{nil, {}, &testdata.RespondActivityTaskCanceledRequest} { + assert.Equal(t, item, ToRespondActivityTaskCanceledRequest(FromRespondActivityTaskCanceledRequest(item))) + } +} +func TestRespondActivityTaskCompletedByIDRequest(t *testing.T) { + for _, item := range []*types.RespondActivityTaskCompletedByIDRequest{nil, {}, &testdata.RespondActivityTaskCompletedByIDRequest} { + assert.Equal(t, item, ToRespondActivityTaskCompletedByIDRequest(FromRespondActivityTaskCompletedByIDRequest(item))) + } +} +func TestRespondActivityTaskCompletedRequest(t *testing.T) { + for _, item := range []*types.RespondActivityTaskCompletedRequest{nil, {}, &testdata.RespondActivityTaskCompletedRequest} { + assert.Equal(t, item, ToRespondActivityTaskCompletedRequest(FromRespondActivityTaskCompletedRequest(item))) + } +} +func TestRespondActivityTaskFailedByIDRequest(t *testing.T) { + for _, item := range []*types.RespondActivityTaskFailedByIDRequest{nil, {}, &testdata.RespondActivityTaskFailedByIDRequest} { + assert.Equal(t, item, ToRespondActivityTaskFailedByIDRequest(FromRespondActivityTaskFailedByIDRequest(item))) + } +} +func TestRespondActivityTaskFailedRequest(t *testing.T) { + for _, item := range []*types.RespondActivityTaskFailedRequest{nil, {}, &testdata.RespondActivityTaskFailedRequest} { + assert.Equal(t, item, ToRespondActivityTaskFailedRequest(FromRespondActivityTaskFailedRequest(item))) + } +} +func TestRespondDecisionTaskCompletedRequest(t *testing.T) { + for _, item := range []*types.RespondDecisionTaskCompletedRequest{nil, {}, &testdata.RespondDecisionTaskCompletedRequest} { + assert.Equal(t, item, ToRespondDecisionTaskCompletedRequest(FromRespondDecisionTaskCompletedRequest(item))) + } +} +func TestRespondDecisionTaskCompletedResponse(t *testing.T) { + for _, item := range []*types.RespondDecisionTaskCompletedResponse{nil, {}, &testdata.RespondDecisionTaskCompletedResponse} { + assert.Equal(t, item, ToRespondDecisionTaskCompletedResponse(FromRespondDecisionTaskCompletedResponse(item))) + } +} +func TestRespondDecisionTaskFailedRequest(t *testing.T) { + for _, item := range []*types.RespondDecisionTaskFailedRequest{nil, {}, &testdata.RespondDecisionTaskFailedRequest} { + assert.Equal(t, item, ToRespondDecisionTaskFailedRequest(FromRespondDecisionTaskFailedRequest(item))) + } +} +func TestRespondQueryTaskCompletedRequest(t *testing.T) { + for _, item := range []*types.RespondQueryTaskCompletedRequest{nil, {}, &testdata.RespondQueryTaskCompletedRequest} { + assert.Equal(t, item, ToRespondQueryTaskCompletedRequest(FromRespondQueryTaskCompletedRequest(item))) + } +} +func TestRetryPolicy(t *testing.T) { + for _, item := range []*types.RetryPolicy{nil, {}, &testdata.RetryPolicy} { + assert.Equal(t, item, ToRetryPolicy(FromRetryPolicy(item))) + } +} +func TestScanWorkflowExecutionsRequest(t *testing.T) { + for _, item := range []*types.ListWorkflowExecutionsRequest{nil, {}, &testdata.ListWorkflowExecutionsRequest} { + assert.Equal(t, item, ToScanWorkflowExecutionsRequest(FromScanWorkflowExecutionsRequest(item))) + } +} +func TestScanWorkflowExecutionsResponse(t *testing.T) { + for _, item := range []*types.ListWorkflowExecutionsResponse{nil, {}, &testdata.ListWorkflowExecutionsResponse} { + assert.Equal(t, item, ToScanWorkflowExecutionsResponse(FromScanWorkflowExecutionsResponse(item))) + } +} +func TestScheduleActivityTaskDecisionAttributes(t *testing.T) { + for _, item := range []*types.ScheduleActivityTaskDecisionAttributes{nil, {}, &testdata.ScheduleActivityTaskDecisionAttributes} { + assert.Equal(t, item, ToScheduleActivityTaskDecisionAttributes(FromScheduleActivityTaskDecisionAttributes(item))) + } +} +func TestSearchAttributes(t *testing.T) { + for _, item := range []*types.SearchAttributes{nil, {}, &testdata.SearchAttributes} { + assert.Equal(t, item, ToSearchAttributes(FromSearchAttributes(item))) + } +} +func TestSignalExternalWorkflowExecutionDecisionAttributes(t *testing.T) { + for _, item := range []*types.SignalExternalWorkflowExecutionDecisionAttributes{nil, {}, &testdata.SignalExternalWorkflowExecutionDecisionAttributes} { + assert.Equal(t, item, ToSignalExternalWorkflowExecutionDecisionAttributes(FromSignalExternalWorkflowExecutionDecisionAttributes(item))) + } +} +func TestSignalExternalWorkflowExecutionFailedEventAttributes(t *testing.T) { + for _, item := range []*types.SignalExternalWorkflowExecutionFailedEventAttributes{nil, {}, &testdata.SignalExternalWorkflowExecutionFailedEventAttributes} { + assert.Equal(t, item, ToSignalExternalWorkflowExecutionFailedEventAttributes(FromSignalExternalWorkflowExecutionFailedEventAttributes(item))) + } +} +func TestSignalExternalWorkflowExecutionInitiatedEventAttributes(t *testing.T) { + for _, item := range []*types.SignalExternalWorkflowExecutionInitiatedEventAttributes{nil, {}, &testdata.SignalExternalWorkflowExecutionInitiatedEventAttributes} { + assert.Equal(t, item, ToSignalExternalWorkflowExecutionInitiatedEventAttributes(FromSignalExternalWorkflowExecutionInitiatedEventAttributes(item))) + } +} +func TestSignalWithStartWorkflowExecutionRequest(t *testing.T) { + for _, item := range []*types.SignalWithStartWorkflowExecutionRequest{nil, {}, &testdata.SignalWithStartWorkflowExecutionRequest} { + assert.Equal(t, item, ToSignalWithStartWorkflowExecutionRequest(FromSignalWithStartWorkflowExecutionRequest(item))) + } +} +func TestSignalWithStartWorkflowExecutionResponse(t *testing.T) { + for _, item := range []*types.StartWorkflowExecutionResponse{nil, {}, &testdata.StartWorkflowExecutionResponse} { + assert.Equal(t, item, ToSignalWithStartWorkflowExecutionResponse(FromSignalWithStartWorkflowExecutionResponse(item))) + } +} +func TestSignalWorkflowExecutionRequest(t *testing.T) { + for _, item := range []*types.SignalWorkflowExecutionRequest{nil, {}, &testdata.SignalWorkflowExecutionRequest} { + assert.Equal(t, item, ToSignalWorkflowExecutionRequest(FromSignalWorkflowExecutionRequest(item))) + } +} +func TestStartChildWorkflowExecutionDecisionAttributes(t *testing.T) { + for _, item := range []*types.StartChildWorkflowExecutionDecisionAttributes{nil, {}, &testdata.StartChildWorkflowExecutionDecisionAttributes} { + assert.Equal(t, item, ToStartChildWorkflowExecutionDecisionAttributes(FromStartChildWorkflowExecutionDecisionAttributes(item))) + } +} +func TestStartChildWorkflowExecutionFailedEventAttributes(t *testing.T) { + for _, item := range []*types.StartChildWorkflowExecutionFailedEventAttributes{nil, {}, &testdata.StartChildWorkflowExecutionFailedEventAttributes} { + assert.Equal(t, item, ToStartChildWorkflowExecutionFailedEventAttributes(FromStartChildWorkflowExecutionFailedEventAttributes(item))) + } +} +func TestStartChildWorkflowExecutionInitiatedEventAttributes(t *testing.T) { + for _, item := range []*types.StartChildWorkflowExecutionInitiatedEventAttributes{nil, {}, &testdata.StartChildWorkflowExecutionInitiatedEventAttributes} { + assert.Equal(t, item, ToStartChildWorkflowExecutionInitiatedEventAttributes(FromStartChildWorkflowExecutionInitiatedEventAttributes(item))) + } +} +func TestStartTimeFilter(t *testing.T) { + for _, item := range []*types.StartTimeFilter{nil, {}, &testdata.StartTimeFilter} { + assert.Equal(t, item, ToStartTimeFilter(FromStartTimeFilter(item))) + } +} +func TestStartTimerDecisionAttributes(t *testing.T) { + for _, item := range []*types.StartTimerDecisionAttributes{nil, {}, &testdata.StartTimerDecisionAttributes} { + assert.Equal(t, item, ToStartTimerDecisionAttributes(FromStartTimerDecisionAttributes(item))) + } +} +func TestStartWorkflowExecutionRequest(t *testing.T) { + for _, item := range []*types.StartWorkflowExecutionRequest{nil, {}, &testdata.StartWorkflowExecutionRequest} { + assert.Equal(t, item, ToStartWorkflowExecutionRequest(FromStartWorkflowExecutionRequest(item))) + } +} +func TestStartWorkflowExecutionResponse(t *testing.T) { + for _, item := range []*types.StartWorkflowExecutionResponse{nil, {}, &testdata.StartWorkflowExecutionResponse} { + assert.Equal(t, item, ToStartWorkflowExecutionResponse(FromStartWorkflowExecutionResponse(item))) + } +} +func TestStatusFilter(t *testing.T) { + for _, item := range []*types.WorkflowExecutionCloseStatus{nil, &testdata.WorkflowExecutionCloseStatus} { + assert.Equal(t, item, ToStatusFilter(FromStatusFilter(item))) + } +} +func TestStickyExecutionAttributes(t *testing.T) { + for _, item := range []*types.StickyExecutionAttributes{nil, {}, &testdata.StickyExecutionAttributes} { + assert.Equal(t, item, ToStickyExecutionAttributes(FromStickyExecutionAttributes(item))) + } +} +func TestSupportedClientVersions(t *testing.T) { + for _, item := range []*types.SupportedClientVersions{nil, {}, &testdata.SupportedClientVersions} { + assert.Equal(t, item, ToSupportedClientVersions(FromSupportedClientVersions(item))) + } +} +func TestTaskIDBlock(t *testing.T) { + for _, item := range []*types.TaskIDBlock{nil, {}, &testdata.TaskIDBlock} { + assert.Equal(t, item, ToTaskIDBlock(FromTaskIDBlock(item))) + } +} +func TestTaskList(t *testing.T) { + for _, item := range []*types.TaskList{nil, {}, &testdata.TaskList} { + assert.Equal(t, item, ToTaskList(FromTaskList(item))) + } +} +func TestTaskListMetadata(t *testing.T) { + for _, item := range []*types.TaskListMetadata{nil, {}, &testdata.TaskListMetadata} { + assert.Equal(t, item, ToTaskListMetadata(FromTaskListMetadata(item))) + } +} +func TestTaskListPartitionMetadata(t *testing.T) { + for _, item := range []*types.TaskListPartitionMetadata{nil, {}, &testdata.TaskListPartitionMetadata} { + assert.Equal(t, item, ToTaskListPartitionMetadata(FromTaskListPartitionMetadata(item))) + } +} +func TestTaskListStatus(t *testing.T) { + for _, item := range []*types.TaskListStatus{nil, {}, &testdata.TaskListStatus} { + assert.Equal(t, item, ToTaskListStatus(FromTaskListStatus(item))) + } +} +func TestTerminateWorkflowExecutionRequest(t *testing.T) { + for _, item := range []*types.TerminateWorkflowExecutionRequest{nil, {}, &testdata.TerminateWorkflowExecutionRequest} { + assert.Equal(t, item, ToTerminateWorkflowExecutionRequest(FromTerminateWorkflowExecutionRequest(item))) + } +} +func TestTimerCanceledEventAttributes(t *testing.T) { + for _, item := range []*types.TimerCanceledEventAttributes{nil, {}, &testdata.TimerCanceledEventAttributes} { + assert.Equal(t, item, ToTimerCanceledEventAttributes(FromTimerCanceledEventAttributes(item))) + } +} +func TestTimerFiredEventAttributes(t *testing.T) { + for _, item := range []*types.TimerFiredEventAttributes{nil, {}, &testdata.TimerFiredEventAttributes} { + assert.Equal(t, item, ToTimerFiredEventAttributes(FromTimerFiredEventAttributes(item))) + } +} +func TestTimerStartedEventAttributes(t *testing.T) { + for _, item := range []*types.TimerStartedEventAttributes{nil, {}, &testdata.TimerStartedEventAttributes} { + assert.Equal(t, item, ToTimerStartedEventAttributes(FromTimerStartedEventAttributes(item))) + } +} +func TestUpdateDomainRequest(t *testing.T) { + for _, item := range []*types.UpdateDomainRequest{nil, {EmitMetric: common.BoolPtr(true)}, &testdata.UpdateDomainRequest} { + assert.Equal(t, item, ToUpdateDomainRequest(FromUpdateDomainRequest(item))) + } +} +func TestUpdateDomainResponse(t *testing.T) { + for _, item := range []*types.UpdateDomainResponse{nil, &testdata.UpdateDomainResponse} { + assert.Equal(t, item, ToUpdateDomainResponse(FromUpdateDomainResponse(item))) + } +} +func TestUpsertWorkflowSearchAttributesDecisionAttributes(t *testing.T) { + for _, item := range []*types.UpsertWorkflowSearchAttributesDecisionAttributes{nil, {}, &testdata.UpsertWorkflowSearchAttributesDecisionAttributes} { + assert.Equal(t, item, ToUpsertWorkflowSearchAttributesDecisionAttributes(FromUpsertWorkflowSearchAttributesDecisionAttributes(item))) + } +} +func TestUpsertWorkflowSearchAttributesEventAttributes(t *testing.T) { + for _, item := range []*types.UpsertWorkflowSearchAttributesEventAttributes{nil, {}, &testdata.UpsertWorkflowSearchAttributesEventAttributes} { + assert.Equal(t, item, ToUpsertWorkflowSearchAttributesEventAttributes(FromUpsertWorkflowSearchAttributesEventAttributes(item))) + } +} +func TestWorkerVersionInfo(t *testing.T) { + for _, item := range []*types.WorkerVersionInfo{nil, {}, &testdata.WorkerVersionInfo} { + assert.Equal(t, item, ToWorkerVersionInfo(FromWorkerVersionInfo(item))) + } +} +func TestWorkflowExecution(t *testing.T) { + for _, item := range []*types.WorkflowExecution{nil, {}, &testdata.WorkflowExecution} { + assert.Equal(t, item, ToWorkflowExecution(FromWorkflowExecution(item))) + } + assert.Empty(t, ToWorkflowID(nil)) + assert.Empty(t, ToRunID(nil)) +} +func TestExternalExecutionInfo(t *testing.T) { + assert.Nil(t, FromExternalExecutionInfoFields(nil, nil)) + assert.Nil(t, ToExternalWorkflowExecution(nil)) + assert.Nil(t, ToExternalInitiatedID(nil)) + assert.Panics(t, func() { FromExternalExecutionInfoFields(nil, common.Int64Ptr(testdata.EventID1)) }) + assert.Panics(t, func() { FromExternalExecutionInfoFields(&testdata.WorkflowExecution, nil) }) + info := FromExternalExecutionInfoFields(&testdata.WorkflowExecution, common.Int64Ptr(testdata.EventID1)) + assert.Equal(t, testdata.WorkflowExecution, *ToExternalWorkflowExecution(info)) + assert.Equal(t, testdata.EventID1, *ToExternalInitiatedID(info)) +} +func TestWorkflowExecutionCancelRequestedEventAttributes(t *testing.T) { + for _, item := range []*types.WorkflowExecutionCancelRequestedEventAttributes{nil, {}, &testdata.WorkflowExecutionCancelRequestedEventAttributes} { + assert.Equal(t, item, ToWorkflowExecutionCancelRequestedEventAttributes(FromWorkflowExecutionCancelRequestedEventAttributes(item))) + } +} +func TestWorkflowExecutionCanceledEventAttributes(t *testing.T) { + for _, item := range []*types.WorkflowExecutionCanceledEventAttributes{nil, {}, &testdata.WorkflowExecutionCanceledEventAttributes} { + assert.Equal(t, item, ToWorkflowExecutionCanceledEventAttributes(FromWorkflowExecutionCanceledEventAttributes(item))) + } +} +func TestWorkflowExecutionCompletedEventAttributes(t *testing.T) { + for _, item := range []*types.WorkflowExecutionCompletedEventAttributes{nil, {}, &testdata.WorkflowExecutionCompletedEventAttributes} { + assert.Equal(t, item, ToWorkflowExecutionCompletedEventAttributes(FromWorkflowExecutionCompletedEventAttributes(item))) + } +} +func TestWorkflowExecutionConfiguration(t *testing.T) { + for _, item := range []*types.WorkflowExecutionConfiguration{nil, {}, &testdata.WorkflowExecutionConfiguration} { + assert.Equal(t, item, ToWorkflowExecutionConfiguration(FromWorkflowExecutionConfiguration(item))) + } +} +func TestWorkflowExecutionContinuedAsNewEventAttributes(t *testing.T) { + for _, item := range []*types.WorkflowExecutionContinuedAsNewEventAttributes{nil, {}, &testdata.WorkflowExecutionContinuedAsNewEventAttributes} { + assert.Equal(t, item, ToWorkflowExecutionContinuedAsNewEventAttributes(FromWorkflowExecutionContinuedAsNewEventAttributes(item))) + } +} +func TestWorkflowExecutionFailedEventAttributes(t *testing.T) { + for _, item := range []*types.WorkflowExecutionFailedEventAttributes{nil, {}, &testdata.WorkflowExecutionFailedEventAttributes} { + assert.Equal(t, item, ToWorkflowExecutionFailedEventAttributes(FromWorkflowExecutionFailedEventAttributes(item))) + } +} +func TestWorkflowExecutionFilter(t *testing.T) { + for _, item := range []*types.WorkflowExecutionFilter{nil, {}, &testdata.WorkflowExecutionFilter} { + assert.Equal(t, item, ToWorkflowExecutionFilter(FromWorkflowExecutionFilter(item))) + } +} +func TestParentExecutionInfo(t *testing.T) { + for _, item := range []*types.ParentExecutionInfo{nil, {}, &testdata.ParentExecutionInfo} { + assert.Equal(t, item, ToParentExecutionInfo(FromParentExecutionInfo(item))) + } +} +func TestWorkflowExecutionInfo(t *testing.T) { + for _, item := range []*types.WorkflowExecutionInfo{nil, {}, &testdata.WorkflowExecutionInfo} { + assert.Equal(t, item, ToWorkflowExecutionInfo(FromWorkflowExecutionInfo(item))) + } +} +func TestWorkflowExecutionSignaledEventAttributes(t *testing.T) { + for _, item := range []*types.WorkflowExecutionSignaledEventAttributes{nil, {}, &testdata.WorkflowExecutionSignaledEventAttributes} { + assert.Equal(t, item, ToWorkflowExecutionSignaledEventAttributes(FromWorkflowExecutionSignaledEventAttributes(item))) + } +} +func TestWorkflowExecutionStartedEventAttributes(t *testing.T) { + for _, item := range []*types.WorkflowExecutionStartedEventAttributes{nil, {}, &testdata.WorkflowExecutionStartedEventAttributes} { + assert.Equal(t, item, ToWorkflowExecutionStartedEventAttributes(FromWorkflowExecutionStartedEventAttributes(item))) + } +} +func TestWorkflowExecutionTerminatedEventAttributes(t *testing.T) { + for _, item := range []*types.WorkflowExecutionTerminatedEventAttributes{nil, {}, &testdata.WorkflowExecutionTerminatedEventAttributes} { + assert.Equal(t, item, ToWorkflowExecutionTerminatedEventAttributes(FromWorkflowExecutionTerminatedEventAttributes(item))) + } +} +func TestWorkflowExecutionTimedOutEventAttributes(t *testing.T) { + for _, item := range []*types.WorkflowExecutionTimedOutEventAttributes{nil, {}, &testdata.WorkflowExecutionTimedOutEventAttributes} { + assert.Equal(t, item, ToWorkflowExecutionTimedOutEventAttributes(FromWorkflowExecutionTimedOutEventAttributes(item))) + } +} +func TestWorkflowQuery(t *testing.T) { + for _, item := range []*types.WorkflowQuery{nil, {}, &testdata.WorkflowQuery} { + assert.Equal(t, item, ToWorkflowQuery(FromWorkflowQuery(item))) + } +} +func TestWorkflowQueryResult(t *testing.T) { + for _, item := range []*types.WorkflowQueryResult{nil, {}, &testdata.WorkflowQueryResult} { + assert.Equal(t, item, ToWorkflowQueryResult(FromWorkflowQueryResult(item))) + } +} +func TestWorkflowType(t *testing.T) { + for _, item := range []*types.WorkflowType{nil, {}, &testdata.WorkflowType} { + assert.Equal(t, item, ToWorkflowType(FromWorkflowType(item))) + } +} +func TestWorkflowTypeFilter(t *testing.T) { + for _, item := range []*types.WorkflowTypeFilter{nil, {}, &testdata.WorkflowTypeFilter} { + assert.Equal(t, item, ToWorkflowTypeFilter(FromWorkflowTypeFilter(item))) + } +} +func TestDataBlobArray(t *testing.T) { + for _, item := range [][]*types.DataBlob{nil, {}, testdata.DataBlobArray} { + assert.Equal(t, item, ToDataBlobArray(FromDataBlobArray(item))) + } +} +func TestHistoryEventArray(t *testing.T) { + for _, item := range [][]*types.HistoryEvent{nil, {}, testdata.HistoryEventArray} { + assert.Equal(t, item, ToHistoryEventArray(FromHistoryEventArray(item))) + } +} +func TestTaskListPartitionMetadataArray(t *testing.T) { + for _, item := range [][]*types.TaskListPartitionMetadata{nil, {}, testdata.TaskListPartitionMetadataArray} { + assert.Equal(t, item, ToTaskListPartitionMetadataArray(FromTaskListPartitionMetadataArray(item))) + } +} +func TestDecisionArray(t *testing.T) { + for _, item := range [][]*types.Decision{nil, {}, testdata.DecisionArray} { + assert.Equal(t, item, ToDecisionArray(FromDecisionArray(item))) + } +} +func TestPollerInfoArray(t *testing.T) { + for _, item := range [][]*types.PollerInfo{nil, {}, testdata.PollerInfoArray} { + assert.Equal(t, item, ToPollerInfoArray(FromPollerInfoArray(item))) + } +} +func TestPendingChildExecutionInfoArray(t *testing.T) { + for _, item := range [][]*types.PendingChildExecutionInfo{nil, {}, testdata.PendingChildExecutionInfoArray} { + assert.Equal(t, item, ToPendingChildExecutionInfoArray(FromPendingChildExecutionInfoArray(item))) + } +} +func TestWorkflowExecutionInfoArray(t *testing.T) { + for _, item := range [][]*types.WorkflowExecutionInfo{nil, {}, testdata.WorkflowExecutionInfoArray} { + assert.Equal(t, item, ToWorkflowExecutionInfoArray(FromWorkflowExecutionInfoArray(item))) + } +} +func TestDescribeDomainResponseArray(t *testing.T) { + for _, item := range [][]*types.DescribeDomainResponse{nil, {}, testdata.DescribeDomainResponseArray} { + assert.Equal(t, item, ToDescribeDomainResponseArray(FromDescribeDomainResponseArray(item))) + } +} +func TestResetPointInfoArray(t *testing.T) { + for _, item := range [][]*types.ResetPointInfo{nil, {}, testdata.ResetPointInfoArray} { + assert.Equal(t, item, ToResetPointInfoArray(FromResetPointInfoArray(item))) + } +} +func TestPendingActivityInfoArray(t *testing.T) { + for _, item := range [][]*types.PendingActivityInfo{nil, {}, testdata.PendingActivityInfoArray} { + assert.Equal(t, item, ToPendingActivityInfoArray(FromPendingActivityInfoArray(item))) + } +} +func TestClusterReplicationConfigurationArray(t *testing.T) { + for _, item := range [][]*types.ClusterReplicationConfiguration{nil, {}, testdata.ClusterReplicationConfigurationArray} { + assert.Equal(t, item, ToClusterReplicationConfigurationArray(FromClusterReplicationConfigurationArray(item))) + } +} +func TestActivityLocalDispatchInfoMap(t *testing.T) { + for _, item := range []map[string]*types.ActivityLocalDispatchInfo{nil, {}, testdata.ActivityLocalDispatchInfoMap} { + assert.Equal(t, item, ToActivityLocalDispatchInfoMap(FromActivityLocalDispatchInfoMap(item))) + } +} +func TestBadBinaryInfoMap(t *testing.T) { + for _, item := range []map[string]*types.BadBinaryInfo{nil, {}, testdata.BadBinaryInfoMap} { + assert.Equal(t, item, ToBadBinaryInfoMap(FromBadBinaryInfoMap(item))) + } +} +func TestIndexedValueTypeMap(t *testing.T) { + for _, item := range []map[string]types.IndexedValueType{nil, {}, testdata.IndexedValueTypeMap} { + assert.Equal(t, item, ToIndexedValueTypeMap(FromIndexedValueTypeMap(item))) + } +} +func TestWorkflowQueryMap(t *testing.T) { + for _, item := range []map[string]*types.WorkflowQuery{nil, {}, testdata.WorkflowQueryMap} { + assert.Equal(t, item, ToWorkflowQueryMap(FromWorkflowQueryMap(item))) + } +} +func TestWorkflowQueryResultMap(t *testing.T) { + for _, item := range []map[string]*types.WorkflowQueryResult{nil, {}, testdata.WorkflowQueryResultMap} { + assert.Equal(t, item, ToWorkflowQueryResultMap(FromWorkflowQueryResultMap(item))) + } +} +func TestPayload(t *testing.T) { + for _, item := range [][]byte{nil, {}, testdata.Payload1} { + assert.Equal(t, item, ToPayload(FromPayload(item))) + } +} +func TestPayloadMap(t *testing.T) { + for _, item := range []map[string][]byte{nil, {}, testdata.PayloadMap} { + assert.Equal(t, item, ToPayloadMap(FromPayloadMap(item))) + } +} +func TestFailure(t *testing.T) { + assert.Nil(t, FromFailure(nil, nil)) + assert.Nil(t, ToFailureReason(nil)) + assert.Nil(t, ToFailureDetails(nil)) + failure := FromFailure(&testdata.FailureReason, testdata.FailureDetails) + assert.Equal(t, testdata.FailureReason, *ToFailureReason(failure)) + assert.Equal(t, testdata.FailureDetails, ToFailureDetails(failure)) +} +func TestHistoryEvent(t *testing.T) { + for _, item := range []*types.HistoryEvent{ + nil, + &testdata.HistoryEvent_WorkflowExecutionStarted, + &testdata.HistoryEvent_WorkflowExecutionCompleted, + &testdata.HistoryEvent_WorkflowExecutionFailed, + &testdata.HistoryEvent_WorkflowExecutionTimedOut, + &testdata.HistoryEvent_DecisionTaskScheduled, + &testdata.HistoryEvent_DecisionTaskStarted, + &testdata.HistoryEvent_DecisionTaskCompleted, + &testdata.HistoryEvent_DecisionTaskTimedOut, + &testdata.HistoryEvent_DecisionTaskFailed, + &testdata.HistoryEvent_ActivityTaskScheduled, + &testdata.HistoryEvent_ActivityTaskStarted, + &testdata.HistoryEvent_ActivityTaskCompleted, + &testdata.HistoryEvent_ActivityTaskFailed, + &testdata.HistoryEvent_ActivityTaskTimedOut, + &testdata.HistoryEvent_ActivityTaskCancelRequested, + &testdata.HistoryEvent_RequestCancelActivityTaskFailed, + &testdata.HistoryEvent_ActivityTaskCanceled, + &testdata.HistoryEvent_TimerStarted, + &testdata.HistoryEvent_TimerFired, + &testdata.HistoryEvent_CancelTimerFailed, + &testdata.HistoryEvent_TimerCanceled, + &testdata.HistoryEvent_WorkflowExecutionCancelRequested, + &testdata.HistoryEvent_WorkflowExecutionCanceled, + &testdata.HistoryEvent_RequestCancelExternalWorkflowExecutionInitiated, + &testdata.HistoryEvent_RequestCancelExternalWorkflowExecutionFailed, + &testdata.HistoryEvent_ExternalWorkflowExecutionCancelRequested, + &testdata.HistoryEvent_MarkerRecorded, + &testdata.HistoryEvent_WorkflowExecutionSignaled, + &testdata.HistoryEvent_WorkflowExecutionTerminated, + &testdata.HistoryEvent_WorkflowExecutionContinuedAsNew, + &testdata.HistoryEvent_StartChildWorkflowExecutionInitiated, + &testdata.HistoryEvent_StartChildWorkflowExecutionFailed, + &testdata.HistoryEvent_ChildWorkflowExecutionStarted, + &testdata.HistoryEvent_ChildWorkflowExecutionCompleted, + &testdata.HistoryEvent_ChildWorkflowExecutionFailed, + &testdata.HistoryEvent_ChildWorkflowExecutionCanceled, + &testdata.HistoryEvent_ChildWorkflowExecutionTimedOut, + &testdata.HistoryEvent_ChildWorkflowExecutionTerminated, + &testdata.HistoryEvent_SignalExternalWorkflowExecutionInitiated, + &testdata.HistoryEvent_SignalExternalWorkflowExecutionFailed, + &testdata.HistoryEvent_ExternalWorkflowExecutionSignaled, + &testdata.HistoryEvent_UpsertWorkflowSearchAttributes, + } { + assert.Equal(t, item, ToHistoryEvent(FromHistoryEvent(item))) + } + assert.Panics(t, func() { FromHistoryEvent(&types.HistoryEvent{}) }) +} +func TestDecision(t *testing.T) { + for _, item := range []*types.Decision{ + nil, + &testdata.Decision_CancelTimer, + &testdata.Decision_CancelWorkflowExecution, + &testdata.Decision_CompleteWorkflowExecution, + &testdata.Decision_ContinueAsNewWorkflowExecution, + &testdata.Decision_FailWorkflowExecution, + &testdata.Decision_RecordMarker, + &testdata.Decision_RequestCancelActivityTask, + &testdata.Decision_RequestCancelExternalWorkflowExecution, + &testdata.Decision_ScheduleActivityTask, + &testdata.Decision_SignalExternalWorkflowExecution, + &testdata.Decision_StartChildWorkflowExecution, + &testdata.Decision_StartTimer, + &testdata.Decision_UpsertWorkflowSearchAttributes, + } { + assert.Equal(t, item, ToDecision(FromDecision(item))) + } + assert.Panics(t, func() { FromDecision(&types.Decision{}) }) +} +func TestListClosedWorkflowExecutionsRequest(t *testing.T) { + for _, item := range []*types.ListClosedWorkflowExecutionsRequest{ + nil, + {}, + &testdata.ListClosedWorkflowExecutionsRequest_ExecutionFilter, + &testdata.ListClosedWorkflowExecutionsRequest_StatusFilter, + &testdata.ListClosedWorkflowExecutionsRequest_TypeFilter, + } { + assert.Equal(t, item, ToListClosedWorkflowExecutionsRequest(FromListClosedWorkflowExecutionsRequest(item))) + } +} +func TestListOpenWorkflowExecutionsRequest(t *testing.T) { + for _, item := range []*types.ListOpenWorkflowExecutionsRequest{ + nil, + {}, + &testdata.ListOpenWorkflowExecutionsRequest_ExecutionFilter, + &testdata.ListOpenWorkflowExecutionsRequest_TypeFilter, + } { + assert.Equal(t, item, ToListOpenWorkflowExecutionsRequest(FromListOpenWorkflowExecutionsRequest(item))) + } +} diff --git a/common/types/mapper/proto/enum_test.go b/common/types/mapper/proto/enum_test.go new file mode 100644 index 00000000000..b07e1da3e67 --- /dev/null +++ b/common/types/mapper/proto/enum_test.go @@ -0,0 +1,409 @@ +// 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 ( + "testing" + + "github.com/stretchr/testify/assert" + + apiv1 "github.com/uber/cadence/.gen/proto/api/v1" + sharedv1 "github.com/uber/cadence/.gen/proto/shared/v1" + "github.com/uber/cadence/common" + "github.com/uber/cadence/common/persistence" + "github.com/uber/cadence/common/types" +) + +const UnknownValue = 9999 + +func TestTaskSource(t *testing.T) { + for _, item := range []*types.TaskSource{ + nil, + types.TaskSourceHistory.Ptr(), + types.TaskSourceDbBacklog.Ptr(), + } { + assert.Equal(t, item, ToTaskSource(FromTaskSource(item))) + } + assert.Panics(t, func() { ToTaskSource(sharedv1.TaskSource(UnknownValue)) }) + assert.Panics(t, func() { FromTaskSource(types.TaskSource(UnknownValue).Ptr()) }) +} +func TestDLQType(t *testing.T) { + for _, item := range []*types.DLQType{ + nil, + types.DLQTypeReplication.Ptr(), + types.DLQTypeDomain.Ptr(), + } { + assert.Equal(t, item, ToDLQType(FromDLQType(item))) + } + assert.Panics(t, func() { ToDLQType(sharedv1.DLQType(UnknownValue)) }) + assert.Panics(t, func() { FromDLQType(types.DLQType(UnknownValue).Ptr()) }) +} +func TestDomainOperation(t *testing.T) { + for _, item := range []*types.DomainOperation{ + nil, + types.DomainOperationCreate.Ptr(), + types.DomainOperationUpdate.Ptr(), + } { + assert.Equal(t, item, ToDomainOperation(FromDomainOperation(item))) + } + assert.Panics(t, func() { ToDomainOperation(sharedv1.DomainOperation(UnknownValue)) }) + assert.Panics(t, func() { FromDomainOperation(types.DomainOperation(UnknownValue).Ptr()) }) +} +func TestReplicationTaskType(t *testing.T) { + for _, item := range []*types.ReplicationTaskType{ + nil, + types.ReplicationTaskTypeDomain.Ptr(), + types.ReplicationTaskTypeHistory.Ptr(), + types.ReplicationTaskTypeSyncShardStatus.Ptr(), + types.ReplicationTaskTypeSyncActivity.Ptr(), + types.ReplicationTaskTypeHistoryMetadata.Ptr(), + types.ReplicationTaskTypeHistoryV2.Ptr(), + types.ReplicationTaskTypeFailoverMarker.Ptr(), + } { + assert.Equal(t, item, ToReplicationTaskType(FromReplicationTaskType(item))) + } + assert.Panics(t, func() { ToReplicationTaskType(sharedv1.ReplicationTaskType(UnknownValue)) }) + assert.Panics(t, func() { FromReplicationTaskType(types.ReplicationTaskType(UnknownValue).Ptr()) }) +} +func TestArchivalStatus(t *testing.T) { + for _, item := range []*types.ArchivalStatus{ + nil, + types.ArchivalStatusDisabled.Ptr(), + types.ArchivalStatusEnabled.Ptr(), + } { + assert.Equal(t, item, ToArchivalStatus(FromArchivalStatus(item))) + } + assert.Panics(t, func() { ToArchivalStatus(apiv1.ArchivalStatus(UnknownValue)) }) + assert.Panics(t, func() { FromArchivalStatus(types.ArchivalStatus(UnknownValue).Ptr()) }) +} +func TestCancelExternalWorkflowExecutionFailedCause(t *testing.T) { + for _, item := range []*types.CancelExternalWorkflowExecutionFailedCause{ + nil, + types.CancelExternalWorkflowExecutionFailedCauseUnknownExternalWorkflowExecution.Ptr(), + } { + assert.Equal(t, item, ToCancelExternalWorkflowExecutionFailedCause(FromCancelExternalWorkflowExecutionFailedCause(item))) + } + assert.Panics(t, func() { + ToCancelExternalWorkflowExecutionFailedCause(apiv1.CancelExternalWorkflowExecutionFailedCause(UnknownValue)) + }) + assert.Panics(t, func() { + FromCancelExternalWorkflowExecutionFailedCause(types.CancelExternalWorkflowExecutionFailedCause(UnknownValue).Ptr()) + }) +} +func TestChildWorkflowExecutionFailedCause(t *testing.T) { + for _, item := range []*types.ChildWorkflowExecutionFailedCause{ + nil, + types.ChildWorkflowExecutionFailedCauseWorkflowAlreadyRunning.Ptr(), + } { + assert.Equal(t, item, ToChildWorkflowExecutionFailedCause(FromChildWorkflowExecutionFailedCause(item))) + } + assert.Panics(t, func() { ToChildWorkflowExecutionFailedCause(apiv1.ChildWorkflowExecutionFailedCause(UnknownValue)) }) + assert.Panics(t, func() { + FromChildWorkflowExecutionFailedCause(types.ChildWorkflowExecutionFailedCause(UnknownValue).Ptr()) + }) +} +func TestContinueAsNewInitiator(t *testing.T) { + for _, item := range []*types.ContinueAsNewInitiator{ + nil, + types.ContinueAsNewInitiatorDecider.Ptr(), + types.ContinueAsNewInitiatorRetryPolicy.Ptr(), + types.ContinueAsNewInitiatorCronSchedule.Ptr(), + } { + assert.Equal(t, item, ToContinueAsNewInitiator(FromContinueAsNewInitiator(item))) + } + assert.Panics(t, func() { ToContinueAsNewInitiator(apiv1.ContinueAsNewInitiator(UnknownValue)) }) + assert.Panics(t, func() { FromContinueAsNewInitiator(types.ContinueAsNewInitiator(UnknownValue).Ptr()) }) +} +func TestDecisionTaskFailedCause(t *testing.T) { + for _, item := range []*types.DecisionTaskFailedCause{ + nil, + types.DecisionTaskFailedCauseUnhandledDecision.Ptr(), + types.DecisionTaskFailedCauseBadScheduleActivityAttributes.Ptr(), + types.DecisionTaskFailedCauseBadRequestCancelActivityAttributes.Ptr(), + types.DecisionTaskFailedCauseBadStartTimerAttributes.Ptr(), + types.DecisionTaskFailedCauseBadCancelTimerAttributes.Ptr(), + types.DecisionTaskFailedCauseBadRecordMarkerAttributes.Ptr(), + types.DecisionTaskFailedCauseBadCompleteWorkflowExecutionAttributes.Ptr(), + types.DecisionTaskFailedCauseBadFailWorkflowExecutionAttributes.Ptr(), + types.DecisionTaskFailedCauseBadCancelWorkflowExecutionAttributes.Ptr(), + types.DecisionTaskFailedCauseBadRequestCancelExternalWorkflowExecutionAttributes.Ptr(), + types.DecisionTaskFailedCauseBadContinueAsNewAttributes.Ptr(), + types.DecisionTaskFailedCauseStartTimerDuplicateID.Ptr(), + types.DecisionTaskFailedCauseResetStickyTasklist.Ptr(), + types.DecisionTaskFailedCauseWorkflowWorkerUnhandledFailure.Ptr(), + types.DecisionTaskFailedCauseBadSignalWorkflowExecutionAttributes.Ptr(), + types.DecisionTaskFailedCauseBadStartChildExecutionAttributes.Ptr(), + types.DecisionTaskFailedCauseForceCloseDecision.Ptr(), + types.DecisionTaskFailedCauseFailoverCloseDecision.Ptr(), + types.DecisionTaskFailedCauseBadSignalInputSize.Ptr(), + types.DecisionTaskFailedCauseResetWorkflow.Ptr(), + types.DecisionTaskFailedCauseBadBinary.Ptr(), + types.DecisionTaskFailedCauseScheduleActivityDuplicateID.Ptr(), + types.DecisionTaskFailedCauseBadSearchAttributes.Ptr(), + } { + assert.Equal(t, item, ToDecisionTaskFailedCause(FromDecisionTaskFailedCause(item))) + } + assert.Panics(t, func() { ToDecisionTaskFailedCause(apiv1.DecisionTaskFailedCause(UnknownValue)) }) + assert.Panics(t, func() { FromDecisionTaskFailedCause(types.DecisionTaskFailedCause(UnknownValue).Ptr()) }) +} +func TestDomainStatus(t *testing.T) { + for _, item := range []*types.DomainStatus{ + nil, + types.DomainStatusRegistered.Ptr(), + types.DomainStatusDeprecated.Ptr(), + types.DomainStatusDeleted.Ptr(), + } { + assert.Equal(t, item, ToDomainStatus(FromDomainStatus(item))) + } + assert.Panics(t, func() { ToDomainStatus(apiv1.DomainStatus(UnknownValue)) }) + assert.Panics(t, func() { FromDomainStatus(types.DomainStatus(UnknownValue).Ptr()) }) +} +func TestEncodingType(t *testing.T) { + for _, item := range []*types.EncodingType{ + nil, + types.EncodingTypeThriftRW.Ptr(), + types.EncodingTypeJSON.Ptr(), + } { + assert.Equal(t, item, ToEncodingType(FromEncodingType(item))) + } + assert.Panics(t, func() { ToEncodingType(apiv1.EncodingType(UnknownValue)) }) + assert.Panics(t, func() { FromEncodingType(types.EncodingType(UnknownValue).Ptr()) }) +} +func TestEventFilterType(t *testing.T) { + for _, item := range []*types.HistoryEventFilterType{ + nil, + types.HistoryEventFilterTypeAllEvent.Ptr(), + types.HistoryEventFilterTypeCloseEvent.Ptr(), + } { + assert.Equal(t, item, ToEventFilterType(FromEventFilterType(item))) + } + assert.Panics(t, func() { ToEventFilterType(apiv1.EventFilterType(UnknownValue)) }) + assert.Panics(t, func() { FromEventFilterType(types.HistoryEventFilterType(UnknownValue).Ptr()) }) +} +func TestIndexedValueType(t *testing.T) { + for _, item := range []types.IndexedValueType{ + types.IndexedValueTypeString, + types.IndexedValueTypeKeyword, + types.IndexedValueTypeInt, + types.IndexedValueTypeDouble, + types.IndexedValueTypeBool, + types.IndexedValueTypeDatetime, + } { + assert.Equal(t, item, ToIndexedValueType(FromIndexedValueType(item))) + } + assert.Panics(t, func() { ToIndexedValueType(apiv1.IndexedValueType_INDEXED_VALUE_TYPE_INVALID) }) + assert.Panics(t, func() { ToIndexedValueType(apiv1.IndexedValueType(UnknownValue)) }) + assert.Panics(t, func() { FromIndexedValueType(types.IndexedValueType(UnknownValue)) }) +} +func TestParentClosePolicy(t *testing.T) { + for _, item := range []*types.ParentClosePolicy{ + nil, + types.ParentClosePolicyAbandon.Ptr(), + types.ParentClosePolicyRequestCancel.Ptr(), + types.ParentClosePolicyTerminate.Ptr(), + } { + assert.Equal(t, item, ToParentClosePolicy(FromParentClosePolicy(item))) + } + assert.Panics(t, func() { ToParentClosePolicy(apiv1.ParentClosePolicy(UnknownValue)) }) + assert.Panics(t, func() { FromParentClosePolicy(types.ParentClosePolicy(UnknownValue).Ptr()) }) +} +func TestPendingActivityState(t *testing.T) { + for _, item := range []*types.PendingActivityState{ + nil, + types.PendingActivityStateScheduled.Ptr(), + types.PendingActivityStateStarted.Ptr(), + types.PendingActivityStateCancelRequested.Ptr(), + } { + assert.Equal(t, item, ToPendingActivityState(FromPendingActivityState(item))) + } + assert.Panics(t, func() { ToPendingActivityState(apiv1.PendingActivityState(UnknownValue)) }) + assert.Panics(t, func() { FromPendingActivityState(types.PendingActivityState(UnknownValue).Ptr()) }) +} +func TestPendingDecisionState(t *testing.T) { + for _, item := range []*types.PendingDecisionState{ + nil, + types.PendingDecisionStateScheduled.Ptr(), + types.PendingDecisionStateStarted.Ptr(), + } { + assert.Equal(t, item, ToPendingDecisionState(FromPendingDecisionState(item))) + } + assert.Panics(t, func() { ToPendingDecisionState(apiv1.PendingDecisionState(UnknownValue)) }) + assert.Panics(t, func() { FromPendingDecisionState(types.PendingDecisionState(UnknownValue).Ptr()) }) +} +func TestQueryConsistencyLevel(t *testing.T) { + for _, item := range []*types.QueryConsistencyLevel{ + nil, + types.QueryConsistencyLevelEventual.Ptr(), + types.QueryConsistencyLevelStrong.Ptr(), + } { + assert.Equal(t, item, ToQueryConsistencyLevel(FromQueryConsistencyLevel(item))) + } + assert.Panics(t, func() { ToQueryConsistencyLevel(apiv1.QueryConsistencyLevel(UnknownValue)) }) + assert.Panics(t, func() { FromQueryConsistencyLevel(types.QueryConsistencyLevel(UnknownValue).Ptr()) }) +} +func TestQueryRejectCondition(t *testing.T) { + for _, item := range []*types.QueryRejectCondition{ + nil, + types.QueryRejectConditionNotOpen.Ptr(), + types.QueryRejectConditionNotCompletedCleanly.Ptr(), + } { + assert.Equal(t, item, ToQueryRejectCondition(FromQueryRejectCondition(item))) + } + assert.Panics(t, func() { ToQueryRejectCondition(apiv1.QueryRejectCondition(UnknownValue)) }) + assert.Panics(t, func() { FromQueryRejectCondition(types.QueryRejectCondition(UnknownValue).Ptr()) }) +} +func TestQueryResultType(t *testing.T) { + for _, item := range []*types.QueryResultType{ + nil, + types.QueryResultTypeAnswered.Ptr(), + types.QueryResultTypeFailed.Ptr(), + } { + assert.Equal(t, item, ToQueryResultType(FromQueryResultType(item))) + } + assert.Panics(t, func() { ToQueryResultType(apiv1.QueryResultType(UnknownValue)) }) + assert.Panics(t, func() { FromQueryResultType(types.QueryResultType(UnknownValue).Ptr()) }) +} +func TestQueryTaskCompletedType(t *testing.T) { + for _, item := range []*types.QueryTaskCompletedType{ + nil, + types.QueryTaskCompletedTypeCompleted.Ptr(), + types.QueryTaskCompletedTypeFailed.Ptr(), + } { + assert.Equal(t, item, ToQueryTaskCompletedType(FromQueryTaskCompletedType(item))) + } + assert.Panics(t, func() { ToQueryTaskCompletedType(apiv1.QueryResultType(UnknownValue)) }) + assert.Panics(t, func() { FromQueryTaskCompletedType(types.QueryTaskCompletedType(UnknownValue).Ptr()) }) +} +func TestSignalExternalWorkflowExecutionFailedCause(t *testing.T) { + for _, item := range []*types.SignalExternalWorkflowExecutionFailedCause{ + nil, + types.SignalExternalWorkflowExecutionFailedCauseUnknownExternalWorkflowExecution.Ptr(), + } { + assert.Equal(t, item, ToSignalExternalWorkflowExecutionFailedCause(FromSignalExternalWorkflowExecutionFailedCause(item))) + } + assert.Panics(t, func() { + ToSignalExternalWorkflowExecutionFailedCause(apiv1.SignalExternalWorkflowExecutionFailedCause(UnknownValue)) + }) + assert.Panics(t, func() { + FromSignalExternalWorkflowExecutionFailedCause(types.SignalExternalWorkflowExecutionFailedCause(UnknownValue).Ptr()) + }) +} +func TestTaskListKind(t *testing.T) { + for _, item := range []*types.TaskListKind{ + nil, + types.TaskListKindNormal.Ptr(), + types.TaskListKindSticky.Ptr(), + } { + assert.Equal(t, item, ToTaskListKind(FromTaskListKind(item))) + } + assert.Panics(t, func() { ToTaskListKind(apiv1.TaskListKind(UnknownValue)) }) + assert.Panics(t, func() { FromTaskListKind(types.TaskListKind(UnknownValue).Ptr()) }) +} +func TestTaskListType(t *testing.T) { + for _, item := range []*types.TaskListType{ + nil, + types.TaskListTypeDecision.Ptr(), + types.TaskListTypeActivity.Ptr(), + } { + assert.Equal(t, item, ToTaskListType(FromTaskListType(item))) + } + assert.Panics(t, func() { ToTaskListType(apiv1.TaskListType(UnknownValue)) }) + assert.Panics(t, func() { FromTaskListType(types.TaskListType(UnknownValue).Ptr()) }) +} +func TestTimeoutType(t *testing.T) { + for _, item := range []*types.TimeoutType{ + nil, + types.TimeoutTypeStartToClose.Ptr(), + types.TimeoutTypeScheduleToStart.Ptr(), + types.TimeoutTypeScheduleToClose.Ptr(), + types.TimeoutTypeHeartbeat.Ptr(), + } { + assert.Equal(t, item, ToTimeoutType(FromTimeoutType(item))) + } + assert.Panics(t, func() { ToTimeoutType(apiv1.TimeoutType(UnknownValue)) }) + assert.Panics(t, func() { FromTimeoutType(types.TimeoutType(UnknownValue).Ptr()) }) +} +func TestDecisionTaskTimedOutCause(t *testing.T) { + for _, item := range []*types.DecisionTaskTimedOutCause{ + nil, + types.DecisionTaskTimedOutCauseTimeout.Ptr(), + types.DecisionTaskTimedOutCauseReset.Ptr(), + } { + assert.Equal(t, item, ToDecisionTaskTimedOutCause(FromDecisionTaskTimedOutCause(item))) + } + assert.Panics(t, func() { ToDecisionTaskTimedOutCause(apiv1.DecisionTaskTimedOutCause(UnknownValue)) }) + assert.Panics(t, func() { FromDecisionTaskTimedOutCause(types.DecisionTaskTimedOutCause(UnknownValue).Ptr()) }) +} +func TestWorkflowExecutionCloseStatus(t *testing.T) { + for _, item := range []*types.WorkflowExecutionCloseStatus{ + nil, + types.WorkflowExecutionCloseStatusCompleted.Ptr(), + types.WorkflowExecutionCloseStatusFailed.Ptr(), + types.WorkflowExecutionCloseStatusCanceled.Ptr(), + types.WorkflowExecutionCloseStatusTerminated.Ptr(), + types.WorkflowExecutionCloseStatusContinuedAsNew.Ptr(), + types.WorkflowExecutionCloseStatusTimedOut.Ptr(), + } { + assert.Equal(t, item, ToWorkflowExecutionCloseStatus(FromWorkflowExecutionCloseStatus(item))) + } + assert.Panics(t, func() { ToWorkflowExecutionCloseStatus(apiv1.WorkflowExecutionCloseStatus(UnknownValue)) }) + assert.Panics(t, func() { FromWorkflowExecutionCloseStatus(types.WorkflowExecutionCloseStatus(UnknownValue).Ptr()) }) +} +func TestWorkflowIDReusePolicy(t *testing.T) { + for _, item := range []*types.WorkflowIDReusePolicy{ + nil, + types.WorkflowIDReusePolicyAllowDuplicateFailedOnly.Ptr(), + types.WorkflowIDReusePolicyAllowDuplicate.Ptr(), + types.WorkflowIDReusePolicyRejectDuplicate.Ptr(), + types.WorkflowIDReusePolicyTerminateIfRunning.Ptr(), + } { + assert.Equal(t, item, ToWorkflowIDReusePolicy(FromWorkflowIDReusePolicy(item))) + } + assert.Panics(t, func() { ToWorkflowIDReusePolicy(apiv1.WorkflowIdReusePolicy(UnknownValue)) }) + assert.Panics(t, func() { FromWorkflowIDReusePolicy(types.WorkflowIDReusePolicy(UnknownValue).Ptr()) }) +} +func TestWorkflowState(t *testing.T) { + for _, item := range []*int32{ + nil, + common.Int32Ptr(persistence.WorkflowStateCreated), + common.Int32Ptr(persistence.WorkflowStateRunning), + common.Int32Ptr(persistence.WorkflowStateCompleted), + common.Int32Ptr(persistence.WorkflowStateZombie), + common.Int32Ptr(persistence.WorkflowStateVoid), + common.Int32Ptr(persistence.WorkflowStateCorrupted), + } { + assert.Equal(t, item, ToWorkflowState(FromWorkflowState(item))) + } + assert.Panics(t, func() { ToWorkflowState(sharedv1.WorkflowState(UnknownValue)) }) + assert.Panics(t, func() { FromWorkflowState(common.Int32Ptr(UnknownValue)) }) +} +func TestTaskType(t *testing.T) { + for _, item := range []*int32{ + nil, + common.Int32Ptr(int32(common.TaskTypeTransfer)), + common.Int32Ptr(int32(common.TaskTypeTimer)), + common.Int32Ptr(int32(common.TaskTypeReplication)), + } { + assert.Equal(t, item, ToTaskType(FromTaskType(item))) + } + assert.Panics(t, func() { ToTaskType(sharedv1.TaskType(UnknownValue)) }) + assert.Panics(t, func() { FromTaskType(common.Int32Ptr(UnknownValue)) }) +} diff --git a/common/types/mapper/proto/errors.go b/common/types/mapper/proto/errors.go new file mode 100644 index 00000000000..bac685be60c --- /dev/null +++ b/common/types/mapper/proto/errors.go @@ -0,0 +1,241 @@ +// 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 ( + "errors" + + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" + + apiv1 "github.com/uber/cadence/.gen/proto/api/v1" + sharedv1 "github.com/uber/cadence/.gen/proto/shared/v1" + "github.com/uber/cadence/common/types" +) + +func FromError(err error) error { + st, conversionErr := errorToStatus(err) + if conversionErr != nil { + return conversionErr + } + return st.Err() +} + +func errorToStatus(err error) (*status.Status, error) { + if err == nil { + return status.New(codes.OK, ""), nil + } + + switch e := err.(type) { + case types.AccessDeniedError: + return status.New(codes.PermissionDenied, e.Message), nil + case types.InternalServiceError: + return status.New(codes.Internal, e.Message), nil + case types.EntityNotExistsError: + return status.New(codes.NotFound, e.Message).WithDetails(&apiv1.EntityNotExistsError{ + CurrentCluster: e.CurrentCluster, + ActiveCluster: e.ActiveCluster, + }) + case types.BadRequestError: + return status.New(codes.InvalidArgument, e.Message), nil + case types.QueryFailedError: + return status.New(codes.InvalidArgument, e.Message).WithDetails(&apiv1.QueryFailedError{}) + case types.ShardOwnershipLostError: + return status.New(codes.Aborted, e.Message).WithDetails(&sharedv1.ShardOwnershipLostError{ + Owner: e.Owner, + }) + case types.CurrentBranchChangedError: + return status.New(codes.Aborted, e.Message).WithDetails(&sharedv1.CurrentBranchChangedError{ + CurrentBranchToken: e.GetCurrentBranchToken(), + }) + case types.RetryTaskV2Error: + return status.New(codes.Aborted, e.Message).WithDetails(&sharedv1.RetryTaskV2Error{ + DomainId: e.DomainID, + WorkflowExecution: FromWorkflowRunPair(e.WorkflowID, e.RunID), + StartEvent: FromEventIDVersionPair(e.StartEventID, e.StartEventVersion), + EndEvent: FromEventIDVersionPair(e.EndEventID, e.EndEventVersion), + }) + case types.CancellationAlreadyRequestedError: + return status.New(codes.AlreadyExists, e.Message).WithDetails(&apiv1.CancellationAlreadyRequestedError{}) + case types.DomainAlreadyExistsError: + return status.New(codes.AlreadyExists, e.Message).WithDetails(&apiv1.DomainAlreadyExistsError{}) + case types.EventAlreadyStartedError: + return status.New(codes.AlreadyExists, e.Message).WithDetails(&sharedv1.EventAlreadyStartedError{}) + case types.WorkflowExecutionAlreadyStartedError: + return status.New(codes.AlreadyExists, e.Message).WithDetails(&apiv1.WorkflowExecutionAlreadyStartedError{ + StartRequestId: e.StartRequestID, + RunId: e.RunID, + }) + case types.ClientVersionNotSupportedError: + return status.New(codes.FailedPrecondition, "Client version not supported").WithDetails(&apiv1.ClientVersionNotSupportedError{ + FeatureVersion: e.FeatureVersion, + ClientImpl: e.ClientImpl, + SupportedVersions: e.SupportedVersions, + }) + case types.DomainNotActiveError: + return status.New(codes.FailedPrecondition, e.Message).WithDetails(&apiv1.DomainNotActiveError{ + Domain: e.DomainName, + CurrentCluster: e.CurrentCluster, + ActiveCluster: e.ActiveCluster, + }) + case types.InternalDataInconsistencyError: + return status.New(codes.DataLoss, e.Message).WithDetails(&sharedv1.InternalDataInconsistencyError{}) + case types.LimitExceededError: + return status.New(codes.ResourceExhausted, e.Message).WithDetails(&apiv1.LimitExceededError{}) + case types.ServiceBusyError: + return status.New(codes.ResourceExhausted, e.Message).WithDetails(&apiv1.ServiceBusyError{}) + case types.RemoteSyncMatchedError: + return status.New(codes.Unavailable, e.Message).WithDetails(&sharedv1.RemoteSyncMatchedError{}) + } + + return status.New(codes.Unknown, err.Error()), nil +} + +func ToError(err error) error { + status := status.Convert(err) + if status == nil || status.Code() == codes.OK { + return nil + } + + switch status.Code() { + case codes.PermissionDenied: + return types.AccessDeniedError{ + Message: status.Message(), + } + case codes.Internal: + return types.InternalServiceError{ + Message: status.Message(), + } + case codes.NotFound: + switch details := getErrorDetails(status).(type) { + case *apiv1.EntityNotExistsError: + return types.EntityNotExistsError{ + Message: status.Message(), + CurrentCluster: details.CurrentCluster, + ActiveCluster: details.ActiveCluster, + } + } + case codes.InvalidArgument: + switch getErrorDetails(status).(type) { + case nil: + return types.BadRequestError{ + Message: status.Message(), + } + case *apiv1.QueryFailedError: + return types.QueryFailedError{ + Message: status.Message(), + } + } + case codes.Aborted: + switch details := getErrorDetails(status).(type) { + case *sharedv1.ShardOwnershipLostError: + return types.ShardOwnershipLostError{ + Message: status.Message(), + Owner: details.Owner, + } + case *sharedv1.CurrentBranchChangedError: + return types.CurrentBranchChangedError{ + Message: status.Message(), + CurrentBranchToken: details.CurrentBranchToken, + } + case *sharedv1.RetryTaskV2Error: + return types.RetryTaskV2Error{ + Message: status.Message(), + DomainID: details.DomainId, + WorkflowID: ToWorkflowID(details.WorkflowExecution), + RunID: ToRunID(details.WorkflowExecution), + StartEventID: ToEventID(details.StartEvent), + StartEventVersion: ToEventVersion(details.StartEvent), + EndEventID: ToEventID(details.EndEvent), + EndEventVersion: ToEventVersion(details.EndEvent), + } + } + case codes.AlreadyExists: + switch details := getErrorDetails(status).(type) { + case *apiv1.CancellationAlreadyRequestedError: + return types.CancellationAlreadyRequestedError{ + Message: status.Message(), + } + case *apiv1.DomainAlreadyExistsError: + return types.DomainAlreadyExistsError{ + Message: status.Message(), + } + case *sharedv1.EventAlreadyStartedError: + return types.EventAlreadyStartedError{ + Message: status.Message(), + } + case *apiv1.WorkflowExecutionAlreadyStartedError: + return types.WorkflowExecutionAlreadyStartedError{ + Message: status.Message(), + StartRequestID: details.StartRequestId, + RunID: details.RunId, + } + } + case codes.DataLoss: + return types.InternalDataInconsistencyError{ + Message: status.Message(), + } + case codes.FailedPrecondition: + switch details := getErrorDetails(status).(type) { + case *apiv1.ClientVersionNotSupportedError: + return types.ClientVersionNotSupportedError{ + FeatureVersion: details.FeatureVersion, + ClientImpl: details.ClientImpl, + SupportedVersions: details.SupportedVersions, + } + case *apiv1.DomainNotActiveError: + return types.DomainNotActiveError{ + Message: status.Message(), + DomainName: details.Domain, + CurrentCluster: details.CurrentCluster, + ActiveCluster: details.ActiveCluster, + } + } + case codes.ResourceExhausted: + switch getErrorDetails(status).(type) { + case *apiv1.LimitExceededError: + return types.LimitExceededError{ + Message: status.Message(), + } + case *apiv1.ServiceBusyError: + return types.ServiceBusyError{ + Message: status.Message(), + } + } + case codes.Unavailable: + switch getErrorDetails(status).(type) { + case *sharedv1.RemoteSyncMatchedError: + return types.RemoteSyncMatchedError{ + Message: status.Message(), + } + } + } + + return errors.New(status.Message()) +} + +func getErrorDetails(status *status.Status) interface{} { + details := status.Details() + if len(details) > 0 { + return details[0] + } + return nil +} diff --git a/common/types/mapper/proto/errors_test.go b/common/types/mapper/proto/errors_test.go new file mode 100644 index 00000000000..ee9e2a2a828 --- /dev/null +++ b/common/types/mapper/proto/errors_test.go @@ -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 proto + +import ( + "errors" + "reflect" + "testing" + + "github.com/stretchr/testify/assert" + + "github.com/uber/cadence/common/types/testdata" +) + +func TestErrors(t *testing.T) { + for _, err := range []error{ + nil, // OK - no error + testdata.AccessDeniedError, + testdata.BadRequestError, + testdata.CancellationAlreadyRequestedError, + testdata.ClientVersionNotSupportedError, + testdata.CurrentBranchChangedError, + testdata.DomainAlreadyExistsError, + testdata.DomainNotActiveError, + testdata.EntityNotExistsError, + testdata.EventAlreadyStartedError, + testdata.InternalDataInconsistencyError, + testdata.InternalServiceError, + testdata.LimitExceededError, + testdata.QueryFailedError, + testdata.RemoteSyncMatchedError, + testdata.RetryTaskV2Error, + testdata.ServiceBusyError, + testdata.ShardOwnershipLostError, + testdata.WorkflowExecutionAlreadyStartedError, + errors.New("unknown error"), + } { + name := "OK" + if err != nil { + name = reflect.TypeOf(err).Name() + } + t.Run(name, func(t *testing.T) { + assert.Equal(t, err, ToError(FromError(err))) + }) + } +} diff --git a/common/types/mapper/proto/helpers.go b/common/types/mapper/proto/helpers.go new file mode 100644 index 00000000000..4ef688cdc8a --- /dev/null +++ b/common/types/mapper/proto/helpers.go @@ -0,0 +1,156 @@ +// 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 ( + "strconv" + "time" + + "github.com/golang/protobuf/ptypes" + "github.com/golang/protobuf/ptypes/duration" + "github.com/golang/protobuf/ptypes/timestamp" + "github.com/golang/protobuf/ptypes/wrappers" + "google.golang.org/protobuf/types/known/fieldmaskpb" + + "github.com/uber/cadence/common" +) + +func fromDoubleValue(v *float64) *wrappers.DoubleValue { + if v == nil { + return nil + } + return &wrappers.DoubleValue{Value: *v} +} + +func toDoubleValue(v *wrappers.DoubleValue) *float64 { + if v == nil { + return nil + } + return common.Float64Ptr(v.Value) +} + +func fromInt64Value(v *int64) *wrappers.Int64Value { + if v == nil { + return nil + } + return &wrappers.Int64Value{Value: *v} +} + +func toInt64Value(v *wrappers.Int64Value) *int64 { + if v == nil { + return nil + } + return common.Int64Ptr(v.Value) +} + +func unixNanoToTime(t *int64) *timestamp.Timestamp { + if t == nil { + return nil + } + time, err := ptypes.TimestampProto(time.Unix(0, *t)) + if err != nil { + panic(err) + } + return time +} + +func timeToUnixNano(t *timestamp.Timestamp) *int64 { + if t == nil { + return nil + } + return common.Int64Ptr(t.AsTime().UnixNano()) +} + +func daysToDuration(d *int32) *duration.Duration { + if d == nil { + return nil + } + return ptypes.DurationProto(common.DaysToDuration(*d)) +} + +func durationToDays(d *duration.Duration) *int32 { + if d == nil { + return nil + } + return common.Int32Ptr(common.DurationToDays(d.AsDuration())) +} + +func secondsToDuration(d *int32) *duration.Duration { + if d == nil { + return nil + } + return ptypes.DurationProto(common.SecondsToDuration(int64(*d))) +} + +func durationToSeconds(d *duration.Duration) *int32 { + if d == nil { + return nil + } + return common.Int32Ptr(int32(common.DurationToSeconds(d.AsDuration()))) +} + +func int32To64(v *int32) *int64 { + if v == nil { + return nil + } + return common.Int64Ptr(int64(*v)) +} + +func int64To32(v *int64) *int32 { + if v == nil { + return nil + } + return common.Int32Ptr(int32(*v)) +} + +func stringToInt32(s string) int32 { + i, err := strconv.Atoi(s) + if err != nil { + panic(err) + } + return int32(i) +} + +func int32ToString(i int32) string { + s := strconv.Itoa(int(i)) + return s +} + +type fieldSet map[string]struct{} + +func newFieldSet(mask *fieldmaskpb.FieldMask) fieldSet { + if mask == nil { + return nil + } + fs := map[string]struct{}{} + for _, field := range mask.Paths { + fs[field] = struct{}{} + } + return fs +} + +func (fs fieldSet) isSet(field string) bool { + if fs == nil { + return true + } + _, ok := fs[field] + return ok +} diff --git a/common/types/mapper/proto/history.go b/common/types/mapper/proto/history.go new file mode 100644 index 00000000000..89982c6f740 --- /dev/null +++ b/common/types/mapper/proto/history.go @@ -0,0 +1,1397 @@ +// 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 ( + apiv1 "github.com/uber/cadence/.gen/proto/api/v1" + historyv1 "github.com/uber/cadence/.gen/proto/history/v1" + sharedv1 "github.com/uber/cadence/.gen/proto/shared/v1" + "github.com/uber/cadence/common" + "github.com/uber/cadence/common/types" +) + +func FromHistoryCloseShardRequest(t *types.CloseShardRequest) *historyv1.CloseShardRequest { + if t == nil { + return nil + } + return &historyv1.CloseShardRequest{ + ShardId: t.ShardID, + } +} + +func ToHistoryCloseShardRequest(t *historyv1.CloseShardRequest) *types.CloseShardRequest { + if t == nil { + return nil + } + return &types.CloseShardRequest{ + ShardID: t.ShardId, + } +} + +func FromHistoryDescribeHistoryHostRequest(t *types.DescribeHistoryHostRequest) *historyv1.DescribeHistoryHostRequest { + if t == nil { + return nil + } + return &historyv1.DescribeHistoryHostRequest{} +} + +func ToHistoryDescribeHistoryHostRequest(t *historyv1.DescribeHistoryHostRequest) *types.DescribeHistoryHostRequest { + if t == nil { + return nil + } + return &types.DescribeHistoryHostRequest{} +} + +func FromHistoryDescribeHistoryHostResponse(t *types.DescribeHistoryHostResponse) *historyv1.DescribeHistoryHostResponse { + if t == nil { + return nil + } + return &historyv1.DescribeHistoryHostResponse{ + NumberOfShards: t.NumberOfShards, + ShardIds: t.ShardIDs, + DomainCache: FromDomainCacheInfo(t.DomainCache), + ShardControllerStatus: t.ShardControllerStatus, + Address: t.Address, + } +} + +func ToHistoryDescribeHistoryHostResponse(t *historyv1.DescribeHistoryHostResponse) *types.DescribeHistoryHostResponse { + if t == nil { + return nil + } + return &types.DescribeHistoryHostResponse{ + NumberOfShards: t.NumberOfShards, + ShardIDs: t.ShardIds, + DomainCache: ToDomainCacheInfo(t.DomainCache), + ShardControllerStatus: t.ShardControllerStatus, + Address: t.Address, + } +} + +func FromHistoryDescribeMutableStateRequest(t *types.DescribeMutableStateRequest) *historyv1.DescribeMutableStateRequest { + if t == nil { + return nil + } + return &historyv1.DescribeMutableStateRequest{ + DomainId: t.DomainUUID, + WorkflowExecution: FromWorkflowExecution(t.Execution), + } +} + +func ToHistoryDescribeMutableStateRequest(t *historyv1.DescribeMutableStateRequest) *types.DescribeMutableStateRequest { + if t == nil { + return nil + } + return &types.DescribeMutableStateRequest{ + DomainUUID: t.DomainId, + Execution: ToWorkflowExecution(t.WorkflowExecution), + } +} + +func FromHistoryDescribeMutableStateResponse(t *types.DescribeMutableStateResponse) *historyv1.DescribeMutableStateResponse { + if t == nil { + return nil + } + return &historyv1.DescribeMutableStateResponse{ + MutableStateInCache: t.MutableStateInCache, + MutableStateInDatabase: t.MutableStateInDatabase, + } +} + +func ToHistoryDescribeMutableStateResponse(t *historyv1.DescribeMutableStateResponse) *types.DescribeMutableStateResponse { + if t == nil { + return nil + } + return &types.DescribeMutableStateResponse{ + MutableStateInCache: t.MutableStateInCache, + MutableStateInDatabase: t.MutableStateInDatabase, + } +} + +func FromHistoryDescribeQueueRequest(t *types.DescribeQueueRequest) *historyv1.DescribeQueueRequest { + if t == nil { + return nil + } + return &historyv1.DescribeQueueRequest{ + ShardId: t.ShardID, + ClusterName: t.ClusterName, + TaskType: FromTaskType(t.Type), + } +} + +func ToHistoryDescribeQueueRequest(t *historyv1.DescribeQueueRequest) *types.DescribeQueueRequest { + if t == nil { + return nil + } + return &types.DescribeQueueRequest{ + ShardID: t.ShardId, + ClusterName: t.ClusterName, + Type: ToTaskType(t.TaskType), + } +} + +func FromHistoryDescribeQueueResponse(t *types.DescribeQueueResponse) *historyv1.DescribeQueueResponse { + if t == nil { + return nil + } + return &historyv1.DescribeQueueResponse{ + ProcessingQueueStates: t.ProcessingQueueStates, + } +} + +func ToHistoryDescribeQueueResponse(t *historyv1.DescribeQueueResponse) *types.DescribeQueueResponse { + if t == nil { + return nil + } + return &types.DescribeQueueResponse{ + ProcessingQueueStates: t.ProcessingQueueStates, + } +} + +func FromHistoryDescribeWorkflowExecutionRequest(t *types.HistoryDescribeWorkflowExecutionRequest) *historyv1.DescribeWorkflowExecutionRequest { + if t == nil { + return nil + } + return &historyv1.DescribeWorkflowExecutionRequest{ + Request: FromDescribeWorkflowExecutionRequest(t.Request), + DomainId: t.DomainUUID, + } +} + +func ToHistoryDescribeWorkflowExecutionRequest(t *historyv1.DescribeWorkflowExecutionRequest) *types.HistoryDescribeWorkflowExecutionRequest { + if t == nil { + return nil + } + return &types.HistoryDescribeWorkflowExecutionRequest{ + Request: ToDescribeWorkflowExecutionRequest(t.Request), + DomainUUID: t.DomainId, + } +} + +func FromHistoryDescribeWorkflowExecutionResponse(t *types.DescribeWorkflowExecutionResponse) *historyv1.DescribeWorkflowExecutionResponse { + if t == nil { + return nil + } + return &historyv1.DescribeWorkflowExecutionResponse{ + ExecutionConfiguration: FromWorkflowExecutionConfiguration(t.ExecutionConfiguration), + WorkflowExecutionInfo: FromWorkflowExecutionInfo(t.WorkflowExecutionInfo), + PendingActivities: FromPendingActivityInfoArray(t.PendingActivities), + PendingChildren: FromPendingChildExecutionInfoArray(t.PendingChildren), + PendingDecision: FromPendingDecisionInfo(t.PendingDecision), + } +} + +func ToHistoryDescribeWorkflowExecutionResponse(t *historyv1.DescribeWorkflowExecutionResponse) *types.DescribeWorkflowExecutionResponse { + if t == nil { + return nil + } + return &types.DescribeWorkflowExecutionResponse{ + ExecutionConfiguration: ToWorkflowExecutionConfiguration(t.ExecutionConfiguration), + WorkflowExecutionInfo: ToWorkflowExecutionInfo(t.WorkflowExecutionInfo), + PendingActivities: ToPendingActivityInfoArray(t.PendingActivities), + PendingChildren: ToPendingChildExecutionInfoArray(t.PendingChildren), + PendingDecision: ToPendingDecisionInfo(t.PendingDecision), + } +} + +func FromHistoryGetDLQReplicationMessagesRequest(t *types.GetDLQReplicationMessagesRequest) *historyv1.GetDLQReplicationMessagesRequest { + if t == nil { + return nil + } + return &historyv1.GetDLQReplicationMessagesRequest{ + TaskInfos: FromReplicationTaskInfoArray(t.TaskInfos), + } +} + +func ToHistoryGetDLQReplicationMessagesRequest(t *historyv1.GetDLQReplicationMessagesRequest) *types.GetDLQReplicationMessagesRequest { + if t == nil { + return nil + } + return &types.GetDLQReplicationMessagesRequest{ + TaskInfos: ToReplicationTaskInfoArray(t.TaskInfos), + } +} + +func FromHistoryGetDLQReplicationMessagesResponse(t *types.GetDLQReplicationMessagesResponse) *historyv1.GetDLQReplicationMessagesResponse { + if t == nil { + return nil + } + return &historyv1.GetDLQReplicationMessagesResponse{ + ReplicationTasks: FromReplicationTaskArray(t.ReplicationTasks), + } +} + +func ToHistoryGetDLQReplicationMessagesResponse(t *historyv1.GetDLQReplicationMessagesResponse) *types.GetDLQReplicationMessagesResponse { + if t == nil { + return nil + } + return &types.GetDLQReplicationMessagesResponse{ + ReplicationTasks: ToReplicationTaskArray(t.ReplicationTasks), + } +} + +func FromHistoryGetMutableStateRequest(t *types.GetMutableStateRequest) *historyv1.GetMutableStateRequest { + if t == nil { + return nil + } + return &historyv1.GetMutableStateRequest{ + DomainId: t.DomainUUID, + WorkflowExecution: FromWorkflowExecution(t.Execution), + ExpectedNextEventId: t.ExpectedNextEventID, + CurrentBranchToken: t.CurrentBranchToken, + } +} + +func ToHistoryGetMutableStateRequest(t *historyv1.GetMutableStateRequest) *types.GetMutableStateRequest { + if t == nil { + return nil + } + return &types.GetMutableStateRequest{ + DomainUUID: t.DomainId, + Execution: ToWorkflowExecution(t.WorkflowExecution), + ExpectedNextEventID: t.ExpectedNextEventId, + CurrentBranchToken: t.CurrentBranchToken, + } +} + +func FromHistoryGetMutableStateResponse(t *types.GetMutableStateResponse) *historyv1.GetMutableStateResponse { + if t == nil { + return nil + } + var workflowCloseState *types.WorkflowExecutionCloseStatus + if t.WorkflowCloseState != nil { + workflowCloseState = types.WorkflowExecutionCloseStatus(*t.WorkflowCloseState).Ptr() + } + return &historyv1.GetMutableStateResponse{ + WorkflowExecution: FromWorkflowExecution(t.Execution), + WorkflowType: FromWorkflowType(t.WorkflowType), + NextEventId: t.NextEventID, + PreviousStartedEventId: fromInt64Value(t.PreviousStartedEventID), + LastFirstEventId: t.LastFirstEventID, + TaskList: FromTaskList(t.TaskList), + StickyTaskList: FromTaskList(t.StickyTaskList), + ClientLibraryVersion: t.ClientLibraryVersion, + ClientFeatureVersion: t.ClientFeatureVersion, + ClientImpl: t.ClientImpl, + StickyTaskListScheduleToStartTimeout: secondsToDuration(t.StickyTaskListScheduleToStartTimeout), + EventStoreVersion: t.EventStoreVersion, + CurrentBranchToken: t.CurrentBranchToken, + WorkflowState: FromWorkflowState(t.WorkflowState), + WorkflowCloseState: FromWorkflowExecutionCloseStatus(workflowCloseState), + VersionHistories: FromVersionHistories(t.VersionHistories), + IsStickyTaskListEnabled: t.IsStickyTaskListEnabled, + } +} + +func ToHistoryGetMutableStateResponse(t *historyv1.GetMutableStateResponse) *types.GetMutableStateResponse { + if t == nil { + return nil + } + var workflowCloseState *int32 + if s := ToWorkflowExecutionCloseStatus(t.WorkflowCloseState); s != nil { + workflowCloseState = common.Int32Ptr(int32(*s)) + } + return &types.GetMutableStateResponse{ + Execution: ToWorkflowExecution(t.WorkflowExecution), + WorkflowType: ToWorkflowType(t.WorkflowType), + NextEventID: t.NextEventId, + PreviousStartedEventID: toInt64Value(t.PreviousStartedEventId), + LastFirstEventID: t.LastFirstEventId, + TaskList: ToTaskList(t.TaskList), + StickyTaskList: ToTaskList(t.StickyTaskList), + ClientLibraryVersion: t.ClientLibraryVersion, + ClientFeatureVersion: t.ClientFeatureVersion, + ClientImpl: t.ClientImpl, + StickyTaskListScheduleToStartTimeout: durationToSeconds(t.StickyTaskListScheduleToStartTimeout), + EventStoreVersion: t.EventStoreVersion, + CurrentBranchToken: t.CurrentBranchToken, + WorkflowState: ToWorkflowState(t.WorkflowState), + WorkflowCloseState: workflowCloseState, + VersionHistories: ToVersionHistories(t.VersionHistories), + IsStickyTaskListEnabled: t.IsStickyTaskListEnabled, + IsWorkflowRunning: t.WorkflowState == sharedv1.WorkflowState_WORKFLOW_STATE_RUNNING, + } +} + +func FromHistoryGetReplicationMessagesRequest(t *types.GetReplicationMessagesRequest) *historyv1.GetReplicationMessagesRequest { + if t == nil { + return nil + } + return &historyv1.GetReplicationMessagesRequest{ + Tokens: FromReplicationTokenArray(t.Tokens), + ClusterName: t.ClusterName, + } +} + +func ToHistoryGetReplicationMessagesRequest(t *historyv1.GetReplicationMessagesRequest) *types.GetReplicationMessagesRequest { + if t == nil { + return nil + } + return &types.GetReplicationMessagesRequest{ + Tokens: ToReplicationTokenArray(t.Tokens), + ClusterName: t.ClusterName, + } +} + +func FromHistoryGetReplicationMessagesResponse(t *types.GetReplicationMessagesResponse) *historyv1.GetReplicationMessagesResponse { + if t == nil { + return nil + } + return &historyv1.GetReplicationMessagesResponse{ + ShardMessages: FromReplicationMessagesMap(t.MessagesByShard), + } +} + +func ToHistoryGetReplicationMessagesResponse(t *historyv1.GetReplicationMessagesResponse) *types.GetReplicationMessagesResponse { + if t == nil { + return nil + } + return &types.GetReplicationMessagesResponse{ + MessagesByShard: ToReplicationMessagesMap(t.ShardMessages), + } +} + +func FromHistoryMergeDLQMessagesRequest(t *types.MergeDLQMessagesRequest) *historyv1.MergeDLQMessagesRequest { + if t == nil { + return nil + } + return &historyv1.MergeDLQMessagesRequest{ + Type: FromDLQType(t.Type), + ShardId: t.ShardID, + SourceCluster: t.SourceCluster, + InclusiveEndMessageId: fromInt64Value(t.InclusiveEndMessageID), + PageSize: t.MaximumPageSize, + NextPageToken: t.NextPageToken, + } +} + +func ToHistoryMergeDLQMessagesRequest(t *historyv1.MergeDLQMessagesRequest) *types.MergeDLQMessagesRequest { + if t == nil { + return nil + } + return &types.MergeDLQMessagesRequest{ + Type: ToDLQType(t.Type), + ShardID: t.ShardId, + SourceCluster: t.SourceCluster, + InclusiveEndMessageID: toInt64Value(t.InclusiveEndMessageId), + MaximumPageSize: t.PageSize, + NextPageToken: t.NextPageToken, + } +} + +func FromHistoryMergeDLQMessagesResponse(t *types.MergeDLQMessagesResponse) *historyv1.MergeDLQMessagesResponse { + if t == nil { + return nil + } + return &historyv1.MergeDLQMessagesResponse{ + NextPageToken: t.NextPageToken, + } +} + +func ToHistoryMergeDLQMessagesResponse(t *historyv1.MergeDLQMessagesResponse) *types.MergeDLQMessagesResponse { + if t == nil { + return nil + } + return &types.MergeDLQMessagesResponse{ + NextPageToken: t.NextPageToken, + } +} + +func FromHistoryNotifyFailoverMarkersRequest(t *types.NotifyFailoverMarkersRequest) *historyv1.NotifyFailoverMarkersRequest { + if t == nil { + return nil + } + return &historyv1.NotifyFailoverMarkersRequest{ + FailoverMarkerTokens: FromFailoverMarkerTokenArray(t.FailoverMarkerTokens), + } +} + +func ToHistoryNotifyFailoverMarkersRequest(t *historyv1.NotifyFailoverMarkersRequest) *types.NotifyFailoverMarkersRequest { + if t == nil { + return nil + } + return &types.NotifyFailoverMarkersRequest{ + FailoverMarkerTokens: ToFailoverMarkerTokenArray(t.FailoverMarkerTokens), + } +} + +func FromHistoryPollMutableStateRequest(t *types.PollMutableStateRequest) *historyv1.PollMutableStateRequest { + if t == nil { + return nil + } + return &historyv1.PollMutableStateRequest{ + DomainId: t.DomainUUID, + WorkflowExecution: FromWorkflowExecution(t.Execution), + ExpectedNextEventId: t.ExpectedNextEventID, + CurrentBranchToken: t.CurrentBranchToken, + } +} + +func ToHistoryPollMutableStateRequest(t *historyv1.PollMutableStateRequest) *types.PollMutableStateRequest { + if t == nil { + return nil + } + return &types.PollMutableStateRequest{ + DomainUUID: t.DomainId, + Execution: ToWorkflowExecution(t.WorkflowExecution), + ExpectedNextEventID: t.ExpectedNextEventId, + CurrentBranchToken: t.CurrentBranchToken, + } +} + +func FromHistoryPollMutableStateResponse(t *types.PollMutableStateResponse) *historyv1.PollMutableStateResponse { + if t == nil { + return nil + } + var workflowCloseState *types.WorkflowExecutionCloseStatus + if t.WorkflowCloseState != nil { + workflowCloseState = types.WorkflowExecutionCloseStatus(*t.WorkflowCloseState).Ptr() + } + return &historyv1.PollMutableStateResponse{ + WorkflowExecution: FromWorkflowExecution(t.Execution), + WorkflowType: FromWorkflowType(t.WorkflowType), + NextEventId: t.NextEventID, + PreviousStartedEventId: fromInt64Value(t.PreviousStartedEventID), + LastFirstEventId: t.LastFirstEventID, + TaskList: FromTaskList(t.TaskList), + StickyTaskList: FromTaskList(t.StickyTaskList), + ClientLibraryVersion: t.ClientLibraryVersion, + ClientFeatureVersion: t.ClientFeatureVersion, + ClientImpl: t.ClientImpl, + StickyTaskListScheduleToStartTimeout: secondsToDuration(t.StickyTaskListScheduleToStartTimeout), + CurrentBranchToken: t.CurrentBranchToken, + VersionHistories: FromVersionHistories(t.VersionHistories), + WorkflowState: FromWorkflowState(t.WorkflowState), + WorkflowCloseState: FromWorkflowExecutionCloseStatus(workflowCloseState), + } +} + +func ToHistoryPollMutableStateResponse(t *historyv1.PollMutableStateResponse) *types.PollMutableStateResponse { + if t == nil { + return nil + } + var workflowCloseState *int32 + if s := ToWorkflowExecutionCloseStatus(t.WorkflowCloseState); s != nil { + workflowCloseState = common.Int32Ptr(int32(*s)) + } + return &types.PollMutableStateResponse{ + Execution: ToWorkflowExecution(t.WorkflowExecution), + WorkflowType: ToWorkflowType(t.WorkflowType), + NextEventID: t.NextEventId, + PreviousStartedEventID: toInt64Value(t.PreviousStartedEventId), + LastFirstEventID: t.LastFirstEventId, + TaskList: ToTaskList(t.TaskList), + StickyTaskList: ToTaskList(t.StickyTaskList), + ClientLibraryVersion: t.ClientLibraryVersion, + ClientFeatureVersion: t.ClientFeatureVersion, + ClientImpl: t.ClientImpl, + StickyTaskListScheduleToStartTimeout: durationToSeconds(t.StickyTaskListScheduleToStartTimeout), + CurrentBranchToken: t.CurrentBranchToken, + VersionHistories: ToVersionHistories(t.VersionHistories), + WorkflowState: ToWorkflowState(t.WorkflowState), + WorkflowCloseState: workflowCloseState, + } +} + +func FromHistoryPurgeDLQMessagesRequest(t *types.PurgeDLQMessagesRequest) *historyv1.PurgeDLQMessagesRequest { + if t == nil { + return nil + } + return &historyv1.PurgeDLQMessagesRequest{ + Type: FromDLQType(t.Type), + ShardId: t.ShardID, + SourceCluster: t.SourceCluster, + InclusiveEndMessageId: fromInt64Value(t.InclusiveEndMessageID), + } +} + +func ToHistoryPurgeDLQMessagesRequest(t *historyv1.PurgeDLQMessagesRequest) *types.PurgeDLQMessagesRequest { + if t == nil { + return nil + } + return &types.PurgeDLQMessagesRequest{ + Type: ToDLQType(t.Type), + ShardID: t.ShardId, + SourceCluster: t.SourceCluster, + InclusiveEndMessageID: toInt64Value(t.InclusiveEndMessageId), + } +} + +func FromHistoryQueryWorkflowRequest(t *types.HistoryQueryWorkflowRequest) *historyv1.QueryWorkflowRequest { + if t == nil { + return nil + } + return &historyv1.QueryWorkflowRequest{ + Request: FromQueryWorkflowRequest(t.Request), + DomainId: t.DomainUUID, + } +} + +func ToHistoryQueryWorkflowRequest(t *historyv1.QueryWorkflowRequest) *types.HistoryQueryWorkflowRequest { + if t == nil { + return nil + } + return &types.HistoryQueryWorkflowRequest{ + Request: ToQueryWorkflowRequest(t.Request), + DomainUUID: t.DomainId, + } +} + +func FromHistoryQueryWorkflowResponse(t *types.HistoryQueryWorkflowResponse) *historyv1.QueryWorkflowResponse { + if t == nil || t.Response == nil { + return nil + } + return &historyv1.QueryWorkflowResponse{ + QueryResult: FromPayload(t.Response.QueryResult), + QueryRejected: FromQueryRejected(t.Response.QueryRejected), + } +} + +func ToHistoryQueryWorkflowResponse(t *historyv1.QueryWorkflowResponse) *types.HistoryQueryWorkflowResponse { + if t == nil { + return nil + } + return &types.HistoryQueryWorkflowResponse{ + Response: &types.QueryWorkflowResponse{ + QueryResult: ToPayload(t.QueryResult), + QueryRejected: ToQueryRejected(t.QueryRejected), + }, + } +} + +func FromHistoryReadDLQMessagesRequest(t *types.ReadDLQMessagesRequest) *historyv1.ReadDLQMessagesRequest { + if t == nil { + return nil + } + return &historyv1.ReadDLQMessagesRequest{ + Type: FromDLQType(t.Type), + ShardId: t.ShardID, + SourceCluster: t.SourceCluster, + InclusiveEndMessageId: fromInt64Value(t.InclusiveEndMessageID), + PageSize: t.MaximumPageSize, + NextPageToken: t.NextPageToken, + } +} + +func ToHistoryReadDLQMessagesRequest(t *historyv1.ReadDLQMessagesRequest) *types.ReadDLQMessagesRequest { + if t == nil { + return nil + } + return &types.ReadDLQMessagesRequest{ + Type: ToDLQType(t.Type), + ShardID: t.ShardId, + SourceCluster: t.SourceCluster, + InclusiveEndMessageID: toInt64Value(t.InclusiveEndMessageId), + MaximumPageSize: t.PageSize, + NextPageToken: t.NextPageToken, + } +} + +func FromHistoryReadDLQMessagesResponse(t *types.ReadDLQMessagesResponse) *historyv1.ReadDLQMessagesResponse { + if t == nil { + return nil + } + return &historyv1.ReadDLQMessagesResponse{ + Type: FromDLQType(t.Type), + ReplicationTasks: FromReplicationTaskArray(t.ReplicationTasks), + ReplicationTasksInfo: FromReplicationTaskInfoArray(t.ReplicationTasksInfo), + NextPageToken: t.NextPageToken, + } +} + +func ToHistoryReadDLQMessagesResponse(t *historyv1.ReadDLQMessagesResponse) *types.ReadDLQMessagesResponse { + if t == nil { + return nil + } + return &types.ReadDLQMessagesResponse{ + Type: ToDLQType(t.Type), + ReplicationTasks: ToReplicationTaskArray(t.ReplicationTasks), + ReplicationTasksInfo: ToReplicationTaskInfoArray(t.ReplicationTasksInfo), + NextPageToken: t.NextPageToken, + } +} + +func FromHistoryReapplyEventsRequest(t *types.HistoryReapplyEventsRequest) *historyv1.ReapplyEventsRequest { + if t == nil || t.Request == nil { + return nil + } + return &historyv1.ReapplyEventsRequest{ + Domain: t.Request.DomainName, + DomainId: t.DomainUUID, + WorkflowExecution: FromWorkflowExecution(t.Request.WorkflowExecution), + Events: FromDataBlob(t.Request.Events), + } +} + +func ToHistoryReapplyEventsRequest(t *historyv1.ReapplyEventsRequest) *types.HistoryReapplyEventsRequest { + if t == nil { + return nil + } + return &types.HistoryReapplyEventsRequest{ + DomainUUID: t.DomainId, + Request: &types.ReapplyEventsRequest{ + DomainName: t.Domain, + WorkflowExecution: ToWorkflowExecution(t.WorkflowExecution), + Events: ToDataBlob(t.Events), + }, + } +} + +func FromHistoryRecordActivityTaskHeartbeatRequest(t *types.HistoryRecordActivityTaskHeartbeatRequest) *historyv1.RecordActivityTaskHeartbeatRequest { + if t == nil { + return nil + } + return &historyv1.RecordActivityTaskHeartbeatRequest{ + DomainId: t.DomainUUID, + Request: FromRecordActivityTaskHeartbeatRequest(t.HeartbeatRequest), + } +} + +func ToHistoryRecordActivityTaskHeartbeatRequest(t *historyv1.RecordActivityTaskHeartbeatRequest) *types.HistoryRecordActivityTaskHeartbeatRequest { + if t == nil { + return nil + } + return &types.HistoryRecordActivityTaskHeartbeatRequest{ + DomainUUID: t.DomainId, + HeartbeatRequest: ToRecordActivityTaskHeartbeatRequest(t.Request), + } +} + +func FromHistoryRecordActivityTaskHeartbeatResponse(t *types.RecordActivityTaskHeartbeatResponse) *historyv1.RecordActivityTaskHeartbeatResponse { + if t == nil { + return nil + } + return &historyv1.RecordActivityTaskHeartbeatResponse{ + CancelRequested: t.CancelRequested, + } +} + +func ToHistoryRecordActivityTaskHeartbeatResponse(t *historyv1.RecordActivityTaskHeartbeatResponse) *types.RecordActivityTaskHeartbeatResponse { + if t == nil { + return nil + } + return &types.RecordActivityTaskHeartbeatResponse{ + CancelRequested: t.CancelRequested, + } +} + +func FromHistoryRecordActivityTaskStartedRequest(t *types.RecordActivityTaskStartedRequest) *historyv1.RecordActivityTaskStartedRequest { + if t == nil { + return nil + } + return &historyv1.RecordActivityTaskStartedRequest{ + DomainId: t.DomainUUID, + WorkflowExecution: FromWorkflowExecution(t.WorkflowExecution), + ScheduleId: t.ScheduleID, + TaskId: t.TaskID, + RequestId: t.RequestID, + PollRequest: FromPollForActivityTaskRequest(t.PollRequest), + } +} + +func ToHistoryRecordActivityTaskStartedRequest(t *historyv1.RecordActivityTaskStartedRequest) *types.RecordActivityTaskStartedRequest { + if t == nil { + return nil + } + return &types.RecordActivityTaskStartedRequest{ + DomainUUID: t.DomainId, + WorkflowExecution: ToWorkflowExecution(t.WorkflowExecution), + ScheduleID: t.ScheduleId, + TaskID: t.TaskId, + RequestID: t.RequestId, + PollRequest: ToPollForActivityTaskRequest(t.PollRequest), + } +} + +func FromHistoryRecordActivityTaskStartedResponse(t *types.RecordActivityTaskStartedResponse) *historyv1.RecordActivityTaskStartedResponse { + if t == nil { + return nil + } + return &historyv1.RecordActivityTaskStartedResponse{ + ScheduledEvent: FromHistoryEvent(t.ScheduledEvent), + StartedTime: unixNanoToTime(t.StartedTimestamp), + Attempt: int32(t.Attempt), + ScheduledTimeOfThisAttempt: unixNanoToTime(t.ScheduledTimestampOfThisAttempt), + HeartbeatDetails: FromPayload(t.HeartbeatDetails), + WorkflowType: FromWorkflowType(t.WorkflowType), + WorkflowDomain: t.WorkflowDomain, + } +} + +func ToHistoryRecordActivityTaskStartedResponse(t *historyv1.RecordActivityTaskStartedResponse) *types.RecordActivityTaskStartedResponse { + if t == nil { + return nil + } + return &types.RecordActivityTaskStartedResponse{ + ScheduledEvent: ToHistoryEvent(t.ScheduledEvent), + StartedTimestamp: timeToUnixNano(t.StartedTime), + Attempt: int64(t.Attempt), + ScheduledTimestampOfThisAttempt: timeToUnixNano(t.ScheduledTimeOfThisAttempt), + HeartbeatDetails: ToPayload(t.HeartbeatDetails), + WorkflowType: ToWorkflowType(t.WorkflowType), + WorkflowDomain: t.WorkflowDomain, + } +} + +func FromHistoryRecordChildExecutionCompletedRequest(t *types.RecordChildExecutionCompletedRequest) *historyv1.RecordChildExecutionCompletedRequest { + if t == nil { + return nil + } + return &historyv1.RecordChildExecutionCompletedRequest{ + DomainId: t.DomainUUID, + WorkflowExecution: FromWorkflowExecution(t.WorkflowExecution), + InitiatedId: t.InitiatedID, + CompletedExecution: FromWorkflowExecution(t.CompletedExecution), + CompletionEvent: FromHistoryEvent(t.CompletionEvent), + } +} + +func ToHistoryRecordChildExecutionCompletedRequest(t *historyv1.RecordChildExecutionCompletedRequest) *types.RecordChildExecutionCompletedRequest { + if t == nil { + return nil + } + return &types.RecordChildExecutionCompletedRequest{ + DomainUUID: t.DomainId, + WorkflowExecution: ToWorkflowExecution(t.WorkflowExecution), + InitiatedID: t.InitiatedId, + CompletedExecution: ToWorkflowExecution(t.CompletedExecution), + CompletionEvent: ToHistoryEvent(t.CompletionEvent), + } +} + +func FromHistoryRecordDecisionTaskStartedRequest(t *types.RecordDecisionTaskStartedRequest) *historyv1.RecordDecisionTaskStartedRequest { + if t == nil { + return nil + } + return &historyv1.RecordDecisionTaskStartedRequest{ + DomainId: t.DomainUUID, + WorkflowExecution: FromWorkflowExecution(t.WorkflowExecution), + ScheduleId: t.ScheduleID, + TaskId: t.TaskID, + RequestId: t.RequestID, + PollRequest: FromPollForDecisionTaskRequest(t.PollRequest), + } +} + +func ToHistoryRecordDecisionTaskStartedRequest(t *historyv1.RecordDecisionTaskStartedRequest) *types.RecordDecisionTaskStartedRequest { + if t == nil { + return nil + } + return &types.RecordDecisionTaskStartedRequest{ + DomainUUID: t.DomainId, + WorkflowExecution: ToWorkflowExecution(t.WorkflowExecution), + ScheduleID: t.ScheduleId, + TaskID: t.TaskId, + RequestID: t.RequestId, + PollRequest: ToPollForDecisionTaskRequest(t.PollRequest), + } +} + +func FromHistoryRecordDecisionTaskStartedResponse(t *types.RecordDecisionTaskStartedResponse) *historyv1.RecordDecisionTaskStartedResponse { + if t == nil { + return nil + } + return &historyv1.RecordDecisionTaskStartedResponse{ + WorkflowType: FromWorkflowType(t.WorkflowType), + PreviousStartedEventId: fromInt64Value(t.PreviousStartedEventID), + ScheduledEventId: t.ScheduledEventID, + StartedEventId: t.StartedEventID, + NextEventId: t.NextEventID, + Attempt: int32(t.Attempt), + StickyExecutionEnabled: t.StickyExecutionEnabled, + DecisionInfo: FromTransientDecisionInfo(t.DecisionInfo), + WorkflowExecutionTaskList: FromTaskList(t.WorkflowExecutionTaskList), + EventStoreVersion: t.EventStoreVersion, + BranchToken: t.BranchToken, + ScheduledTime: unixNanoToTime(t.ScheduledTimestamp), + StartedTime: unixNanoToTime(t.StartedTimestamp), + Queries: FromWorkflowQueryMap(t.Queries), + } +} + +func ToHistoryRecordDecisionTaskStartedResponse(t *historyv1.RecordDecisionTaskStartedResponse) *types.RecordDecisionTaskStartedResponse { + if t == nil { + return nil + } + return &types.RecordDecisionTaskStartedResponse{ + WorkflowType: ToWorkflowType(t.WorkflowType), + PreviousStartedEventID: toInt64Value(t.PreviousStartedEventId), + ScheduledEventID: t.ScheduledEventId, + StartedEventID: t.StartedEventId, + NextEventID: t.NextEventId, + Attempt: int64(t.Attempt), + StickyExecutionEnabled: t.StickyExecutionEnabled, + DecisionInfo: ToTransientDecisionInfo(t.DecisionInfo), + WorkflowExecutionTaskList: ToTaskList(t.WorkflowExecutionTaskList), + EventStoreVersion: t.EventStoreVersion, + BranchToken: t.BranchToken, + ScheduledTimestamp: timeToUnixNano(t.ScheduledTime), + StartedTimestamp: timeToUnixNano(t.StartedTime), + Queries: ToWorkflowQueryMap(t.Queries), + } +} + +func FromHistoryRefreshWorkflowTasksRequest(t *types.HistoryRefreshWorkflowTasksRequest) *historyv1.RefreshWorkflowTasksRequest { + if t == nil || t.Request == nil { + return nil + } + return &historyv1.RefreshWorkflowTasksRequest{ + DomainId: t.DomainUIID, + Domain: t.Request.Domain, + WorkflowExecution: FromWorkflowExecution(t.Request.Execution), + } +} + +func ToHistoryRefreshWorkflowTasksRequest(t *historyv1.RefreshWorkflowTasksRequest) *types.HistoryRefreshWorkflowTasksRequest { + if t == nil { + return nil + } + return &types.HistoryRefreshWorkflowTasksRequest{ + Request: &types.RefreshWorkflowTasksRequest{ + Domain: t.Domain, + Execution: ToWorkflowExecution(t.WorkflowExecution), + }, + DomainUIID: t.DomainId, + } +} + +func FromHistoryRemoveSignalMutableStateRequest(t *types.RemoveSignalMutableStateRequest) *historyv1.RemoveSignalMutableStateRequest { + if t == nil { + return nil + } + return &historyv1.RemoveSignalMutableStateRequest{ + DomainId: t.DomainUUID, + WorkflowExecution: FromWorkflowExecution(t.WorkflowExecution), + RequestId: t.RequestID, + } +} + +func ToHistoryRemoveSignalMutableStateRequest(t *historyv1.RemoveSignalMutableStateRequest) *types.RemoveSignalMutableStateRequest { + if t == nil { + return nil + } + return &types.RemoveSignalMutableStateRequest{ + DomainUUID: t.DomainId, + WorkflowExecution: ToWorkflowExecution(t.WorkflowExecution), + RequestID: t.RequestId, + } +} + +func FromHistoryRemoveTaskRequest(t *types.RemoveTaskRequest) *historyv1.RemoveTaskRequest { + if t == nil { + return nil + } + return &historyv1.RemoveTaskRequest{ + ShardId: t.ShardID, + TaskType: FromTaskType(t.Type), + TaskId: t.TaskID, + VisibilityTime: unixNanoToTime(t.VisibilityTimestamp), + } +} + +func ToHistoryRemoveTaskRequest(t *historyv1.RemoveTaskRequest) *types.RemoveTaskRequest { + if t == nil { + return nil + } + return &types.RemoveTaskRequest{ + ShardID: t.ShardId, + Type: ToTaskType(t.TaskType), + TaskID: t.TaskId, + VisibilityTimestamp: timeToUnixNano(t.VisibilityTime), + } +} + +func FromHistoryReplicateEventsV2Request(t *types.ReplicateEventsV2Request) *historyv1.ReplicateEventsV2Request { + if t == nil { + return nil + } + return &historyv1.ReplicateEventsV2Request{ + DomainId: t.DomainUUID, + WorkflowExecution: FromWorkflowExecution(t.WorkflowExecution), + VersionHistoryItems: FromVersionHistoryItemArray(t.VersionHistoryItems), + Events: FromDataBlob(t.Events), + NewRunEvents: FromDataBlob(t.NewRunEvents), + } +} + +func ToHistoryReplicateEventsV2Request(t *historyv1.ReplicateEventsV2Request) *types.ReplicateEventsV2Request { + if t == nil { + return nil + } + return &types.ReplicateEventsV2Request{ + DomainUUID: t.DomainId, + WorkflowExecution: ToWorkflowExecution(t.WorkflowExecution), + VersionHistoryItems: ToVersionHistoryItemArray(t.VersionHistoryItems), + Events: ToDataBlob(t.Events), + NewRunEvents: ToDataBlob(t.NewRunEvents), + } +} + +func FromHistoryRequestCancelWorkflowExecutionRequest(t *types.HistoryRequestCancelWorkflowExecutionRequest) *historyv1.RequestCancelWorkflowExecutionRequest { + if t == nil { + return nil + } + return &historyv1.RequestCancelWorkflowExecutionRequest{ + DomainId: t.DomainUUID, + CancelRequest: FromRequestCancelWorkflowExecutionRequest(t.CancelRequest), + ExternalExecutionInfo: FromExternalExecutionInfoFields(t.ExternalWorkflowExecution, t.ExternalInitiatedEventID), + ChildWorkflowOnly: t.ChildWorkflowOnly, + } +} + +func ToHistoryRequestCancelWorkflowExecutionRequest(t *historyv1.RequestCancelWorkflowExecutionRequest) *types.HistoryRequestCancelWorkflowExecutionRequest { + if t == nil { + return nil + } + return &types.HistoryRequestCancelWorkflowExecutionRequest{ + DomainUUID: t.DomainId, + CancelRequest: ToRequestCancelWorkflowExecutionRequest(t.CancelRequest), + ExternalInitiatedEventID: ToExternalInitiatedID(t.ExternalExecutionInfo), + ExternalWorkflowExecution: ToExternalWorkflowExecution(t.ExternalExecutionInfo), + ChildWorkflowOnly: t.ChildWorkflowOnly, + } +} + +func FromHistoryResetQueueRequest(t *types.ResetQueueRequest) *historyv1.ResetQueueRequest { + if t == nil { + return nil + } + return &historyv1.ResetQueueRequest{ + ShardId: t.ShardID, + ClusterName: t.ClusterName, + TaskType: FromTaskType(t.Type), + } +} + +func ToHistoryResetQueueRequest(t *historyv1.ResetQueueRequest) *types.ResetQueueRequest { + if t == nil { + return nil + } + return &types.ResetQueueRequest{ + ShardID: t.ShardId, + ClusterName: t.ClusterName, + Type: ToTaskType(t.TaskType), + } +} + +func FromHistoryResetStickyTaskListRequest(t *types.HistoryResetStickyTaskListRequest) *historyv1.ResetStickyTaskListRequest { + if t == nil { + return nil + } + return &historyv1.ResetStickyTaskListRequest{ + Request: &apiv1.ResetStickyTaskListRequest{ + Domain: "", + WorkflowExecution: FromWorkflowExecution(t.Execution), + }, + DomainId: t.DomainUUID, + } +} + +func ToHistoryResetStickyTaskListRequest(t *historyv1.ResetStickyTaskListRequest) *types.HistoryResetStickyTaskListRequest { + if t == nil || t.Request == nil { + return nil + } + return &types.HistoryResetStickyTaskListRequest{ + DomainUUID: t.DomainId, + Execution: ToWorkflowExecution(t.Request.WorkflowExecution), + } +} + +func FromHistoryResetWorkflowExecutionRequest(t *types.HistoryResetWorkflowExecutionRequest) *historyv1.ResetWorkflowExecutionRequest { + if t == nil { + return nil + } + return &historyv1.ResetWorkflowExecutionRequest{ + Request: FromResetWorkflowExecutionRequest(t.ResetRequest), + DomainId: t.DomainUUID, + } +} + +func ToHistoryResetWorkflowExecutionRequest(t *historyv1.ResetWorkflowExecutionRequest) *types.HistoryResetWorkflowExecutionRequest { + if t == nil { + return nil + } + return &types.HistoryResetWorkflowExecutionRequest{ + ResetRequest: ToResetWorkflowExecutionRequest(t.Request), + DomainUUID: t.DomainId, + } +} + +func FromHistoryResetWorkflowExecutionResponse(t *types.ResetWorkflowExecutionResponse) *historyv1.ResetWorkflowExecutionResponse { + if t == nil { + return nil + } + return &historyv1.ResetWorkflowExecutionResponse{ + RunId: t.RunID, + } +} + +func ToHistoryResetWorkflowExecutionResponse(t *historyv1.ResetWorkflowExecutionResponse) *types.ResetWorkflowExecutionResponse { + if t == nil { + return nil + } + return &types.ResetWorkflowExecutionResponse{ + RunID: t.RunId, + } +} + +func FromHistoryRespondActivityTaskCanceledRequest(t *types.HistoryRespondActivityTaskCanceledRequest) *historyv1.RespondActivityTaskCanceledRequest { + if t == nil { + return nil + } + return &historyv1.RespondActivityTaskCanceledRequest{ + DomainId: t.DomainUUID, + Request: FromRespondActivityTaskCanceledRequest(t.CancelRequest), + } +} + +func ToHistoryRespondActivityTaskCanceledRequest(t *historyv1.RespondActivityTaskCanceledRequest) *types.HistoryRespondActivityTaskCanceledRequest { + if t == nil { + return nil + } + return &types.HistoryRespondActivityTaskCanceledRequest{ + DomainUUID: t.DomainId, + CancelRequest: ToRespondActivityTaskCanceledRequest(t.Request), + } +} + +func FromHistoryRespondActivityTaskCompletedRequest(t *types.HistoryRespondActivityTaskCompletedRequest) *historyv1.RespondActivityTaskCompletedRequest { + if t == nil { + return nil + } + return &historyv1.RespondActivityTaskCompletedRequest{ + DomainId: t.DomainUUID, + Request: FromRespondActivityTaskCompletedRequest(t.CompleteRequest), + } +} + +func ToHistoryRespondActivityTaskCompletedRequest(t *historyv1.RespondActivityTaskCompletedRequest) *types.HistoryRespondActivityTaskCompletedRequest { + if t == nil { + return nil + } + return &types.HistoryRespondActivityTaskCompletedRequest{ + DomainUUID: t.DomainId, + CompleteRequest: ToRespondActivityTaskCompletedRequest(t.Request), + } +} + +func FromHistoryRespondActivityTaskFailedRequest(t *types.HistoryRespondActivityTaskFailedRequest) *historyv1.RespondActivityTaskFailedRequest { + if t == nil { + return nil + } + return &historyv1.RespondActivityTaskFailedRequest{ + DomainId: t.DomainUUID, + Request: FromRespondActivityTaskFailedRequest(t.FailedRequest), + } +} + +func ToHistoryRespondActivityTaskFailedRequest(t *historyv1.RespondActivityTaskFailedRequest) *types.HistoryRespondActivityTaskFailedRequest { + if t == nil { + return nil + } + return &types.HistoryRespondActivityTaskFailedRequest{ + DomainUUID: t.DomainId, + FailedRequest: ToRespondActivityTaskFailedRequest(t.Request), + } +} + +func FromHistoryRespondDecisionTaskCompletedRequest(t *types.HistoryRespondDecisionTaskCompletedRequest) *historyv1.RespondDecisionTaskCompletedRequest { + if t == nil { + return nil + } + return &historyv1.RespondDecisionTaskCompletedRequest{ + DomainId: t.DomainUUID, + Request: FromRespondDecisionTaskCompletedRequest(t.CompleteRequest), + } +} + +func ToHistoryRespondDecisionTaskCompletedRequest(t *historyv1.RespondDecisionTaskCompletedRequest) *types.HistoryRespondDecisionTaskCompletedRequest { + if t == nil { + return nil + } + return &types.HistoryRespondDecisionTaskCompletedRequest{ + DomainUUID: t.DomainId, + CompleteRequest: ToRespondDecisionTaskCompletedRequest(t.Request), + } +} + +func FromHistoryRespondDecisionTaskCompletedResponse(t *types.HistoryRespondDecisionTaskCompletedResponse) *historyv1.RespondDecisionTaskCompletedResponse { + if t == nil { + return nil + } + return &historyv1.RespondDecisionTaskCompletedResponse{ + StartedResponse: FromHistoryRecordDecisionTaskStartedResponse(t.StartedResponse), + ActivitiesToDispatchLocally: FromActivityLocalDispatchInfoMap(t.ActivitiesToDispatchLocally), + } +} + +func ToHistoryRespondDecisionTaskCompletedResponse(t *historyv1.RespondDecisionTaskCompletedResponse) *types.HistoryRespondDecisionTaskCompletedResponse { + if t == nil { + return nil + } + return &types.HistoryRespondDecisionTaskCompletedResponse{ + StartedResponse: ToHistoryRecordDecisionTaskStartedResponse(t.StartedResponse), + ActivitiesToDispatchLocally: ToActivityLocalDispatchInfoMap(t.ActivitiesToDispatchLocally), + } +} + +func FromHistoryRespondDecisionTaskFailedRequest(t *types.HistoryRespondDecisionTaskFailedRequest) *historyv1.RespondDecisionTaskFailedRequest { + if t == nil { + return nil + } + return &historyv1.RespondDecisionTaskFailedRequest{ + DomainId: t.DomainUUID, + Request: FromRespondDecisionTaskFailedRequest(t.FailedRequest), + } +} + +func ToHistoryRespondDecisionTaskFailedRequest(t *historyv1.RespondDecisionTaskFailedRequest) *types.HistoryRespondDecisionTaskFailedRequest { + if t == nil { + return nil + } + return &types.HistoryRespondDecisionTaskFailedRequest{ + DomainUUID: t.DomainId, + FailedRequest: ToRespondDecisionTaskFailedRequest(t.Request), + } +} + +func FromHistoryScheduleDecisionTaskRequest(t *types.ScheduleDecisionTaskRequest) *historyv1.ScheduleDecisionTaskRequest { + if t == nil { + return nil + } + return &historyv1.ScheduleDecisionTaskRequest{ + DomainId: t.DomainUUID, + WorkflowExecution: FromWorkflowExecution(t.WorkflowExecution), + IsFirstDecision: t.IsFirstDecision, + } +} + +func ToHistoryScheduleDecisionTaskRequest(t *historyv1.ScheduleDecisionTaskRequest) *types.ScheduleDecisionTaskRequest { + if t == nil { + return nil + } + return &types.ScheduleDecisionTaskRequest{ + DomainUUID: t.DomainId, + WorkflowExecution: ToWorkflowExecution(t.WorkflowExecution), + IsFirstDecision: t.IsFirstDecision, + } +} + +func FromHistorySignalWithStartWorkflowExecutionRequest(t *types.HistorySignalWithStartWorkflowExecutionRequest) *historyv1.SignalWithStartWorkflowExecutionRequest { + if t == nil { + return nil + } + return &historyv1.SignalWithStartWorkflowExecutionRequest{ + Request: FromSignalWithStartWorkflowExecutionRequest(t.SignalWithStartRequest), + DomainId: t.DomainUUID, + } +} + +func ToHistorySignalWithStartWorkflowExecutionRequest(t *historyv1.SignalWithStartWorkflowExecutionRequest) *types.HistorySignalWithStartWorkflowExecutionRequest { + if t == nil { + return nil + } + return &types.HistorySignalWithStartWorkflowExecutionRequest{ + SignalWithStartRequest: ToSignalWithStartWorkflowExecutionRequest(t.Request), + DomainUUID: t.DomainId, + } +} + +func FromHistorySignalWithStartWorkflowExecutionResponse(t *types.StartWorkflowExecutionResponse) *historyv1.SignalWithStartWorkflowExecutionResponse { + if t == nil { + return nil + } + return &historyv1.SignalWithStartWorkflowExecutionResponse{ + RunId: t.RunID, + } +} + +func ToHistorySignalWithStartWorkflowExecutionResponse(t *historyv1.SignalWithStartWorkflowExecutionResponse) *types.StartWorkflowExecutionResponse { + if t == nil { + return nil + } + return &types.StartWorkflowExecutionResponse{ + RunID: t.RunId, + } +} + +func FromHistorySignalWorkflowExecutionRequest(t *types.HistorySignalWorkflowExecutionRequest) *historyv1.SignalWorkflowExecutionRequest { + if t == nil { + return nil + } + return &historyv1.SignalWorkflowExecutionRequest{ + Request: FromSignalWorkflowExecutionRequest(t.SignalRequest), + DomainId: t.DomainUUID, + ExternalWorkflowExecution: FromWorkflowExecution(t.ExternalWorkflowExecution), + ChildWorkflowOnly: t.ChildWorkflowOnly, + } +} + +func ToHistorySignalWorkflowExecutionRequest(t *historyv1.SignalWorkflowExecutionRequest) *types.HistorySignalWorkflowExecutionRequest { + if t == nil { + return nil + } + return &types.HistorySignalWorkflowExecutionRequest{ + SignalRequest: ToSignalWorkflowExecutionRequest(t.Request), + DomainUUID: t.DomainId, + ExternalWorkflowExecution: ToWorkflowExecution(t.ExternalWorkflowExecution), + ChildWorkflowOnly: t.ChildWorkflowOnly, + } +} + +func FromHistoryStartWorkflowExecutionRequest(t *types.HistoryStartWorkflowExecutionRequest) *historyv1.StartWorkflowExecutionRequest { + if t == nil { + return nil + } + return &historyv1.StartWorkflowExecutionRequest{ + Request: FromStartWorkflowExecutionRequest(t.StartRequest), + DomainId: t.DomainUUID, + ParentExecutionInfo: FromParentExecutionInfo(t.ParentExecutionInfo), + Attempt: t.Attempt, + ExpirationTime: unixNanoToTime(t.ExpirationTimestamp), + ContinueAsNewInitiator: FromContinueAsNewInitiator(t.ContinueAsNewInitiator), + ContinuedFailure: FromFailure(t.ContinuedFailureReason, t.ContinuedFailureDetails), + LastCompletionResult: FromPayload(t.LastCompletionResult), + FirstDecisionTaskBackoff: secondsToDuration(t.FirstDecisionTaskBackoffSeconds), + } +} + +func ToHistoryStartWorkflowExecutionRequest(t *historyv1.StartWorkflowExecutionRequest) *types.HistoryStartWorkflowExecutionRequest { + if t == nil { + return nil + } + return &types.HistoryStartWorkflowExecutionRequest{ + StartRequest: ToStartWorkflowExecutionRequest(t.Request), + DomainUUID: t.DomainId, + ParentExecutionInfo: ToParentExecutionInfo(t.ParentExecutionInfo), + Attempt: t.Attempt, + ExpirationTimestamp: timeToUnixNano(t.ExpirationTime), + ContinueAsNewInitiator: ToContinueAsNewInitiator(t.ContinueAsNewInitiator), + ContinuedFailureReason: ToFailureReason(t.ContinuedFailure), + ContinuedFailureDetails: ToFailureDetails(t.ContinuedFailure), + LastCompletionResult: ToPayload(t.LastCompletionResult), + FirstDecisionTaskBackoffSeconds: durationToSeconds(t.FirstDecisionTaskBackoff), + } +} + +func FromHistoryStartWorkflowExecutionResponse(t *types.StartWorkflowExecutionResponse) *historyv1.StartWorkflowExecutionResponse { + if t == nil { + return nil + } + return &historyv1.StartWorkflowExecutionResponse{ + RunId: t.RunID, + } +} + +func ToHistoryStartWorkflowExecutionResponse(t *historyv1.StartWorkflowExecutionResponse) *types.StartWorkflowExecutionResponse { + if t == nil { + return nil + } + return &types.StartWorkflowExecutionResponse{ + RunID: t.RunId, + } +} + +func FromHistorySyncActivityRequest(t *types.SyncActivityRequest) *historyv1.SyncActivityRequest { + if t == nil { + return nil + } + return &historyv1.SyncActivityRequest{ + DomainId: t.DomainID, + WorkflowExecution: FromWorkflowRunPair(t.WorkflowID, t.RunID), + Version: t.Version, + ScheduledId: t.ScheduledID, + ScheduledTime: unixNanoToTime(t.ScheduledTime), + StartedId: t.StartedID, + StartedTime: unixNanoToTime(t.StartedTime), + LastHeartbeatTime: unixNanoToTime(t.LastHeartbeatTime), + Details: FromPayload(t.Details), + Attempt: t.Attempt, + LastFailure: FromFailure(t.LastFailureReason, t.LastFailureDetails), + LastWorkerIdentity: t.LastWorkerIdentity, + VersionHistory: FromVersionHistory(t.VersionHistory), + } +} + +func ToHistorySyncActivityRequest(t *historyv1.SyncActivityRequest) *types.SyncActivityRequest { + if t == nil { + return nil + } + return &types.SyncActivityRequest{ + DomainID: t.DomainId, + WorkflowID: ToWorkflowID(t.WorkflowExecution), + RunID: ToRunID(t.WorkflowExecution), + Version: t.Version, + ScheduledID: t.ScheduledId, + ScheduledTime: timeToUnixNano(t.ScheduledTime), + StartedID: t.StartedId, + StartedTime: timeToUnixNano(t.StartedTime), + LastHeartbeatTime: timeToUnixNano(t.LastHeartbeatTime), + Details: ToPayload(t.Details), + Attempt: t.Attempt, + LastFailureReason: ToFailureReason(t.LastFailure), + LastFailureDetails: ToFailureDetails(t.LastFailure), + LastWorkerIdentity: t.LastWorkerIdentity, + VersionHistory: ToVersionHistory(t.VersionHistory), + } +} + +func FromHistorySyncShardStatusRequest(t *types.SyncShardStatusRequest) *historyv1.SyncShardStatusRequest { + if t == nil { + return nil + } + return &historyv1.SyncShardStatusRequest{ + SourceCluster: t.SourceCluster, + ShardId: int32(t.ShardID), + Time: unixNanoToTime(t.Timestamp), + } +} + +func ToHistorySyncShardStatusRequest(t *historyv1.SyncShardStatusRequest) *types.SyncShardStatusRequest { + if t == nil { + return nil + } + return &types.SyncShardStatusRequest{ + SourceCluster: t.SourceCluster, + ShardID: int64(t.ShardId), + Timestamp: timeToUnixNano(t.Time), + } +} + +func FromHistoryTerminateWorkflowExecutionRequest(t *types.HistoryTerminateWorkflowExecutionRequest) *historyv1.TerminateWorkflowExecutionRequest { + if t == nil { + return nil + } + return &historyv1.TerminateWorkflowExecutionRequest{ + Request: FromTerminateWorkflowExecutionRequest(t.TerminateRequest), + DomainId: t.DomainUUID, + } +} + +func ToHistoryTerminateWorkflowExecutionRequest(t *historyv1.TerminateWorkflowExecutionRequest) *types.HistoryTerminateWorkflowExecutionRequest { + if t == nil { + return nil + } + return &types.HistoryTerminateWorkflowExecutionRequest{ + TerminateRequest: ToTerminateWorkflowExecutionRequest(t.Request), + DomainUUID: t.DomainId, + } +} diff --git a/common/types/mapper/proto/history_test.go b/common/types/mapper/proto/history_test.go new file mode 100644 index 00000000000..96ea2b92366 --- /dev/null +++ b/common/types/mapper/proto/history_test.go @@ -0,0 +1,319 @@ +// 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 ( + "testing" + + "github.com/stretchr/testify/assert" + + "github.com/uber/cadence/common/types" + "github.com/uber/cadence/common/types/testdata" +) + +func TestHistoryCloseShardRequest(t *testing.T) { + for _, item := range []*types.CloseShardRequest{nil, {}, &testdata.HistoryCloseShardRequest} { + assert.Equal(t, item, ToHistoryCloseShardRequest(FromHistoryCloseShardRequest(item))) + } +} +func TestHistoryDescribeHistoryHostRequest(t *testing.T) { + for _, item := range []*types.DescribeHistoryHostRequest{nil, {}, &testdata.HistoryDescribeHistoryHostRequest} { + assert.Equal(t, item, ToHistoryDescribeHistoryHostRequest(FromHistoryDescribeHistoryHostRequest(item))) + } +} +func TestHistoryDescribeHistoryHostResponse(t *testing.T) { + for _, item := range []*types.DescribeHistoryHostResponse{nil, {}, &testdata.HistoryDescribeHistoryHostResponse} { + assert.Equal(t, item, ToHistoryDescribeHistoryHostResponse(FromHistoryDescribeHistoryHostResponse(item))) + } +} +func TestHistoryDescribeMutableStateRequest(t *testing.T) { + for _, item := range []*types.DescribeMutableStateRequest{nil, {}, &testdata.HistoryDescribeMutableStateRequest} { + assert.Equal(t, item, ToHistoryDescribeMutableStateRequest(FromHistoryDescribeMutableStateRequest(item))) + } +} +func TestHistoryDescribeMutableStateResponse(t *testing.T) { + for _, item := range []*types.DescribeMutableStateResponse{nil, {}, &testdata.HistoryDescribeMutableStateResponse} { + assert.Equal(t, item, ToHistoryDescribeMutableStateResponse(FromHistoryDescribeMutableStateResponse(item))) + } +} +func TestHistoryDescribeQueueRequest(t *testing.T) { + for _, item := range []*types.DescribeQueueRequest{nil, {}, &testdata.HistoryDescribeQueueRequest} { + assert.Equal(t, item, ToHistoryDescribeQueueRequest(FromHistoryDescribeQueueRequest(item))) + } +} +func TestHistoryDescribeQueueResponse(t *testing.T) { + for _, item := range []*types.DescribeQueueResponse{nil, {}, &testdata.HistoryDescribeQueueResponse} { + assert.Equal(t, item, ToHistoryDescribeQueueResponse(FromHistoryDescribeQueueResponse(item))) + } +} +func TestHistoryDescribeWorkflowExecutionRequest(t *testing.T) { + for _, item := range []*types.HistoryDescribeWorkflowExecutionRequest{nil, {}, &testdata.HistoryDescribeWorkflowExecutionRequest} { + assert.Equal(t, item, ToHistoryDescribeWorkflowExecutionRequest(FromHistoryDescribeWorkflowExecutionRequest(item))) + } +} +func TestHistoryDescribeWorkflowExecutionResponse(t *testing.T) { + for _, item := range []*types.DescribeWorkflowExecutionResponse{nil, {}, &testdata.HistoryDescribeWorkflowExecutionResponse} { + assert.Equal(t, item, ToHistoryDescribeWorkflowExecutionResponse(FromHistoryDescribeWorkflowExecutionResponse(item))) + } +} +func TestHistoryGetDLQReplicationMessagesRequest(t *testing.T) { + for _, item := range []*types.GetDLQReplicationMessagesRequest{nil, {}, &testdata.HistoryGetDLQReplicationMessagesRequest} { + assert.Equal(t, item, ToHistoryGetDLQReplicationMessagesRequest(FromHistoryGetDLQReplicationMessagesRequest(item))) + } +} +func TestHistoryGetDLQReplicationMessagesResponse(t *testing.T) { + for _, item := range []*types.GetDLQReplicationMessagesResponse{nil, {}, &testdata.HistoryGetDLQReplicationMessagesResponse} { + assert.Equal(t, item, ToHistoryGetDLQReplicationMessagesResponse(FromHistoryGetDLQReplicationMessagesResponse(item))) + } +} +func TestHistoryGetMutableStateRequest(t *testing.T) { + for _, item := range []*types.GetMutableStateRequest{nil, {}, &testdata.HistoryGetMutableStateRequest} { + assert.Equal(t, item, ToHistoryGetMutableStateRequest(FromHistoryGetMutableStateRequest(item))) + } +} +func TestHistoryGetMutableStateResponse(t *testing.T) { + for _, item := range []*types.GetMutableStateResponse{nil, {}, &testdata.HistoryGetMutableStateResponse} { + assert.Equal(t, item, ToHistoryGetMutableStateResponse(FromHistoryGetMutableStateResponse(item))) + } +} +func TestHistoryGetReplicationMessagesRequest(t *testing.T) { + for _, item := range []*types.GetReplicationMessagesRequest{nil, {}, &testdata.HistoryGetReplicationMessagesRequest} { + assert.Equal(t, item, ToHistoryGetReplicationMessagesRequest(FromHistoryGetReplicationMessagesRequest(item))) + } +} +func TestHistoryGetReplicationMessagesResponse(t *testing.T) { + for _, item := range []*types.GetReplicationMessagesResponse{nil, {}, &testdata.HistoryGetReplicationMessagesResponse} { + assert.Equal(t, item, ToHistoryGetReplicationMessagesResponse(FromHistoryGetReplicationMessagesResponse(item))) + } +} +func TestHistoryMergeDLQMessagesRequest(t *testing.T) { + for _, item := range []*types.MergeDLQMessagesRequest{nil, {}, &testdata.HistoryMergeDLQMessagesRequest} { + assert.Equal(t, item, ToHistoryMergeDLQMessagesRequest(FromHistoryMergeDLQMessagesRequest(item))) + } +} +func TestHistoryMergeDLQMessagesResponse(t *testing.T) { + for _, item := range []*types.MergeDLQMessagesResponse{nil, {}, &testdata.HistoryMergeDLQMessagesResponse} { + assert.Equal(t, item, ToHistoryMergeDLQMessagesResponse(FromHistoryMergeDLQMessagesResponse(item))) + } +} +func TestHistoryNotifyFailoverMarkersRequest(t *testing.T) { + for _, item := range []*types.NotifyFailoverMarkersRequest{nil, {}, &testdata.HistoryNotifyFailoverMarkersRequest} { + assert.Equal(t, item, ToHistoryNotifyFailoverMarkersRequest(FromHistoryNotifyFailoverMarkersRequest(item))) + } +} +func TestHistoryPollMutableStateRequest(t *testing.T) { + for _, item := range []*types.PollMutableStateRequest{nil, {}, &testdata.HistoryPollMutableStateRequest} { + assert.Equal(t, item, ToHistoryPollMutableStateRequest(FromHistoryPollMutableStateRequest(item))) + } +} +func TestHistoryPollMutableStateResponse(t *testing.T) { + for _, item := range []*types.PollMutableStateResponse{nil, {}, &testdata.HistoryPollMutableStateResponse} { + assert.Equal(t, item, ToHistoryPollMutableStateResponse(FromHistoryPollMutableStateResponse(item))) + } +} +func TestHistoryPurgeDLQMessagesRequest(t *testing.T) { + for _, item := range []*types.PurgeDLQMessagesRequest{nil, {}, &testdata.HistoryPurgeDLQMessagesRequest} { + assert.Equal(t, item, ToHistoryPurgeDLQMessagesRequest(FromHistoryPurgeDLQMessagesRequest(item))) + } +} +func TestHistoryQueryWorkflowRequest(t *testing.T) { + for _, item := range []*types.HistoryQueryWorkflowRequest{nil, {}, &testdata.HistoryQueryWorkflowRequest} { + assert.Equal(t, item, ToHistoryQueryWorkflowRequest(FromHistoryQueryWorkflowRequest(item))) + } +} +func TestHistoryQueryWorkflowResponse(t *testing.T) { + for _, item := range []*types.HistoryQueryWorkflowResponse{nil, &testdata.HistoryQueryWorkflowResponse} { + assert.Equal(t, item, ToHistoryQueryWorkflowResponse(FromHistoryQueryWorkflowResponse(item))) + } + assert.Nil(t, FromHistoryQueryWorkflowResponse(&types.HistoryQueryWorkflowResponse{})) +} +func TestHistoryReadDLQMessagesRequest(t *testing.T) { + for _, item := range []*types.ReadDLQMessagesRequest{nil, {}, &testdata.HistoryReadDLQMessagesRequest} { + assert.Equal(t, item, ToHistoryReadDLQMessagesRequest(FromHistoryReadDLQMessagesRequest(item))) + } +} +func TestHistoryReadDLQMessagesResponse(t *testing.T) { + for _, item := range []*types.ReadDLQMessagesResponse{nil, {}, &testdata.HistoryReadDLQMessagesResponse} { + assert.Equal(t, item, ToHistoryReadDLQMessagesResponse(FromHistoryReadDLQMessagesResponse(item))) + } +} +func TestHistoryReapplyEventsRequest(t *testing.T) { + for _, item := range []*types.HistoryReapplyEventsRequest{nil, &testdata.HistoryReapplyEventsRequest} { + assert.Equal(t, item, ToHistoryReapplyEventsRequest(FromHistoryReapplyEventsRequest(item))) + } + assert.Nil(t, FromHistoryReapplyEventsRequest(&types.HistoryReapplyEventsRequest{})) +} +func TestHistoryRecordActivityTaskHeartbeatRequest(t *testing.T) { + for _, item := range []*types.HistoryRecordActivityTaskHeartbeatRequest{nil, {}, &testdata.HistoryRecordActivityTaskHeartbeatRequest} { + assert.Equal(t, item, ToHistoryRecordActivityTaskHeartbeatRequest(FromHistoryRecordActivityTaskHeartbeatRequest(item))) + } +} +func TestHistoryRecordActivityTaskHeartbeatResponse(t *testing.T) { + for _, item := range []*types.RecordActivityTaskHeartbeatResponse{nil, {}, &testdata.HistoryRecordActivityTaskHeartbeatResponse} { + assert.Equal(t, item, ToHistoryRecordActivityTaskHeartbeatResponse(FromHistoryRecordActivityTaskHeartbeatResponse(item))) + } +} +func TestHistoryRecordActivityTaskStartedRequest(t *testing.T) { + for _, item := range []*types.RecordActivityTaskStartedRequest{nil, {}, &testdata.HistoryRecordActivityTaskStartedRequest} { + assert.Equal(t, item, ToHistoryRecordActivityTaskStartedRequest(FromHistoryRecordActivityTaskStartedRequest(item))) + } +} +func TestHistoryRecordActivityTaskStartedResponse(t *testing.T) { + for _, item := range []*types.RecordActivityTaskStartedResponse{nil, {}, &testdata.HistoryRecordActivityTaskStartedResponse} { + assert.Equal(t, item, ToHistoryRecordActivityTaskStartedResponse(FromHistoryRecordActivityTaskStartedResponse(item))) + } +} +func TestHistoryRecordChildExecutionCompletedRequest(t *testing.T) { + for _, item := range []*types.RecordChildExecutionCompletedRequest{nil, {}, &testdata.HistoryRecordChildExecutionCompletedRequest} { + assert.Equal(t, item, ToHistoryRecordChildExecutionCompletedRequest(FromHistoryRecordChildExecutionCompletedRequest(item))) + } +} +func TestHistoryRecordDecisionTaskStartedRequest(t *testing.T) { + for _, item := range []*types.RecordDecisionTaskStartedRequest{nil, {}, &testdata.HistoryRecordDecisionTaskStartedRequest} { + assert.Equal(t, item, ToHistoryRecordDecisionTaskStartedRequest(FromHistoryRecordDecisionTaskStartedRequest(item))) + } +} +func TestHistoryRecordDecisionTaskStartedResponse(t *testing.T) { + for _, item := range []*types.RecordDecisionTaskStartedResponse{nil, {}, &testdata.HistoryRecordDecisionTaskStartedResponse} { + assert.Equal(t, item, ToHistoryRecordDecisionTaskStartedResponse(FromHistoryRecordDecisionTaskStartedResponse(item))) + } +} +func TestHistoryRefreshWorkflowTasksRequest(t *testing.T) { + for _, item := range []*types.HistoryRefreshWorkflowTasksRequest{nil, &testdata.HistoryRefreshWorkflowTasksRequest} { + assert.Equal(t, item, ToHistoryRefreshWorkflowTasksRequest(FromHistoryRefreshWorkflowTasksRequest(item))) + } + assert.Nil(t, FromHistoryRefreshWorkflowTasksRequest(&types.HistoryRefreshWorkflowTasksRequest{})) +} +func TestHistoryRemoveSignalMutableStateRequest(t *testing.T) { + for _, item := range []*types.RemoveSignalMutableStateRequest{nil, {}, &testdata.HistoryRemoveSignalMutableStateRequest} { + assert.Equal(t, item, ToHistoryRemoveSignalMutableStateRequest(FromHistoryRemoveSignalMutableStateRequest(item))) + } +} +func TestHistoryRemoveTaskRequest(t *testing.T) { + for _, item := range []*types.RemoveTaskRequest{nil, {}, &testdata.HistoryRemoveTaskRequest} { + assert.Equal(t, item, ToHistoryRemoveTaskRequest(FromHistoryRemoveTaskRequest(item))) + } +} +func TestHistoryReplicateEventsV2Request(t *testing.T) { + for _, item := range []*types.ReplicateEventsV2Request{nil, {}, &testdata.HistoryReplicateEventsV2Request} { + assert.Equal(t, item, ToHistoryReplicateEventsV2Request(FromHistoryReplicateEventsV2Request(item))) + } +} +func TestHistoryRequestCancelWorkflowExecutionRequest(t *testing.T) { + for _, item := range []*types.HistoryRequestCancelWorkflowExecutionRequest{nil, {}, &testdata.HistoryRequestCancelWorkflowExecutionRequest} { + assert.Equal(t, item, ToHistoryRequestCancelWorkflowExecutionRequest(FromHistoryRequestCancelWorkflowExecutionRequest(item))) + } +} +func TestHistoryResetQueueRequest(t *testing.T) { + for _, item := range []*types.ResetQueueRequest{nil, {}, &testdata.HistoryResetQueueRequest} { + assert.Equal(t, item, ToHistoryResetQueueRequest(FromHistoryResetQueueRequest(item))) + } +} +func TestHistoryResetStickyTaskListRequest(t *testing.T) { + for _, item := range []*types.HistoryResetStickyTaskListRequest{nil, {}, &testdata.HistoryResetStickyTaskListRequest} { + assert.Equal(t, item, ToHistoryResetStickyTaskListRequest(FromHistoryResetStickyTaskListRequest(item))) + } +} +func TestHistoryResetWorkflowExecutionRequest(t *testing.T) { + for _, item := range []*types.HistoryResetWorkflowExecutionRequest{nil, {}, &testdata.HistoryResetWorkflowExecutionRequest} { + assert.Equal(t, item, ToHistoryResetWorkflowExecutionRequest(FromHistoryResetWorkflowExecutionRequest(item))) + } +} +func TestHistoryResetWorkflowExecutionResponse(t *testing.T) { + for _, item := range []*types.ResetWorkflowExecutionResponse{nil, {}, &testdata.HistoryResetWorkflowExecutionResponse} { + assert.Equal(t, item, ToHistoryResetWorkflowExecutionResponse(FromHistoryResetWorkflowExecutionResponse(item))) + } +} +func TestHistoryRespondActivityTaskCanceledRequest(t *testing.T) { + for _, item := range []*types.HistoryRespondActivityTaskCanceledRequest{nil, {}, &testdata.HistoryRespondActivityTaskCanceledRequest} { + assert.Equal(t, item, ToHistoryRespondActivityTaskCanceledRequest(FromHistoryRespondActivityTaskCanceledRequest(item))) + } +} +func TestHistoryRespondActivityTaskCompletedRequest(t *testing.T) { + for _, item := range []*types.HistoryRespondActivityTaskCompletedRequest{nil, {}, &testdata.HistoryRespondActivityTaskCompletedRequest} { + assert.Equal(t, item, ToHistoryRespondActivityTaskCompletedRequest(FromHistoryRespondActivityTaskCompletedRequest(item))) + } +} +func TestHistoryRespondActivityTaskFailedRequest(t *testing.T) { + for _, item := range []*types.HistoryRespondActivityTaskFailedRequest{nil, {}, &testdata.HistoryRespondActivityTaskFailedRequest} { + assert.Equal(t, item, ToHistoryRespondActivityTaskFailedRequest(FromHistoryRespondActivityTaskFailedRequest(item))) + } +} +func TestHistoryRespondDecisionTaskCompletedRequest(t *testing.T) { + for _, item := range []*types.HistoryRespondDecisionTaskCompletedRequest{nil, {}, &testdata.HistoryRespondDecisionTaskCompletedRequest} { + assert.Equal(t, item, ToHistoryRespondDecisionTaskCompletedRequest(FromHistoryRespondDecisionTaskCompletedRequest(item))) + } +} +func TestHistoryRespondDecisionTaskCompletedResponse(t *testing.T) { + for _, item := range []*types.HistoryRespondDecisionTaskCompletedResponse{nil, {}, &testdata.HistoryRespondDecisionTaskCompletedResponse} { + assert.Equal(t, item, ToHistoryRespondDecisionTaskCompletedResponse(FromHistoryRespondDecisionTaskCompletedResponse(item))) + } +} +func TestHistoryRespondDecisionTaskFailedRequest(t *testing.T) { + for _, item := range []*types.HistoryRespondDecisionTaskFailedRequest{nil, {}, &testdata.HistoryRespondDecisionTaskFailedRequest} { + assert.Equal(t, item, ToHistoryRespondDecisionTaskFailedRequest(FromHistoryRespondDecisionTaskFailedRequest(item))) + } +} +func TestHistoryScheduleDecisionTaskRequest(t *testing.T) { + for _, item := range []*types.ScheduleDecisionTaskRequest{nil, {}, &testdata.HistoryScheduleDecisionTaskRequest} { + assert.Equal(t, item, ToHistoryScheduleDecisionTaskRequest(FromHistoryScheduleDecisionTaskRequest(item))) + } +} +func TestHistorySignalWithStartWorkflowExecutionRequest(t *testing.T) { + for _, item := range []*types.HistorySignalWithStartWorkflowExecutionRequest{nil, {}, &testdata.HistorySignalWithStartWorkflowExecutionRequest} { + assert.Equal(t, item, ToHistorySignalWithStartWorkflowExecutionRequest(FromHistorySignalWithStartWorkflowExecutionRequest(item))) + } +} +func TestHistorySignalWithStartWorkflowExecutionResponse(t *testing.T) { + for _, item := range []*types.StartWorkflowExecutionResponse{nil, {}, &testdata.HistorySignalWithStartWorkflowExecutionResponse} { + assert.Equal(t, item, ToHistorySignalWithStartWorkflowExecutionResponse(FromHistorySignalWithStartWorkflowExecutionResponse(item))) + } +} +func TestHistorySignalWorkflowExecutionRequest(t *testing.T) { + for _, item := range []*types.HistorySignalWorkflowExecutionRequest{nil, {}, &testdata.HistorySignalWorkflowExecutionRequest} { + assert.Equal(t, item, ToHistorySignalWorkflowExecutionRequest(FromHistorySignalWorkflowExecutionRequest(item))) + } +} +func TestHistoryStartWorkflowExecutionRequest(t *testing.T) { + for _, item := range []*types.HistoryStartWorkflowExecutionRequest{nil, {}, &testdata.HistoryStartWorkflowExecutionRequest} { + assert.Equal(t, item, ToHistoryStartWorkflowExecutionRequest(FromHistoryStartWorkflowExecutionRequest(item))) + } +} +func TestHistoryStartWorkflowExecutionResponse(t *testing.T) { + for _, item := range []*types.StartWorkflowExecutionResponse{nil, {}, &testdata.HistoryStartWorkflowExecutionResponse} { + assert.Equal(t, item, ToHistoryStartWorkflowExecutionResponse(FromHistoryStartWorkflowExecutionResponse(item))) + } +} +func TestHistorySyncActivityRequest(t *testing.T) { + for _, item := range []*types.SyncActivityRequest{nil, {}, &testdata.HistorySyncActivityRequest} { + assert.Equal(t, item, ToHistorySyncActivityRequest(FromHistorySyncActivityRequest(item))) + } +} +func TestHistorySyncShardStatusRequest(t *testing.T) { + for _, item := range []*types.SyncShardStatusRequest{nil, {}, &testdata.HistorySyncShardStatusRequest} { + assert.Equal(t, item, ToHistorySyncShardStatusRequest(FromHistorySyncShardStatusRequest(item))) + } +} +func TestHistoryTerminateWorkflowExecutionRequest(t *testing.T) { + for _, item := range []*types.HistoryTerminateWorkflowExecutionRequest{nil, {}, &testdata.HistoryTerminateWorkflowExecutionRequest} { + assert.Equal(t, item, ToHistoryTerminateWorkflowExecutionRequest(FromHistoryTerminateWorkflowExecutionRequest(item))) + } +} diff --git a/common/types/mapper/proto/matching.go b/common/types/mapper/proto/matching.go new file mode 100644 index 00000000000..9c696c7db7b --- /dev/null +++ b/common/types/mapper/proto/matching.go @@ -0,0 +1,415 @@ +// 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 ( + matchingv1 "github.com/uber/cadence/.gen/proto/matching/v1" + "github.com/uber/cadence/common" + "github.com/uber/cadence/common/types" +) + +func FromMatchingAddActivityTaskRequest(t *types.AddActivityTaskRequest) *matchingv1.AddActivityTaskRequest { + if t == nil { + return nil + } + return &matchingv1.AddActivityTaskRequest{ + DomainId: t.DomainUUID, + WorkflowExecution: FromWorkflowExecution(t.Execution), + SourceDomainId: t.SourceDomainUUID, + TaskList: FromTaskList(t.TaskList), + ScheduleId: t.ScheduleID, + ScheduleToStartTimeout: secondsToDuration(t.ScheduleToStartTimeoutSeconds), + Source: FromTaskSource(t.Source), + ForwardedFrom: t.ForwardedFrom, + } +} + +func ToMatchingAddActivityTaskRequest(t *matchingv1.AddActivityTaskRequest) *types.AddActivityTaskRequest { + if t == nil { + return nil + } + return &types.AddActivityTaskRequest{ + DomainUUID: t.DomainId, + Execution: ToWorkflowExecution(t.WorkflowExecution), + SourceDomainUUID: t.SourceDomainId, + TaskList: ToTaskList(t.TaskList), + ScheduleID: t.ScheduleId, + ScheduleToStartTimeoutSeconds: durationToSeconds(t.ScheduleToStartTimeout), + Source: ToTaskSource(t.Source), + ForwardedFrom: t.ForwardedFrom, + } +} + +func FromMatchingAddDecisionTaskRequest(t *types.AddDecisionTaskRequest) *matchingv1.AddDecisionTaskRequest { + if t == nil { + return nil + } + return &matchingv1.AddDecisionTaskRequest{ + DomainId: t.DomainUUID, + WorkflowExecution: FromWorkflowExecution(t.Execution), + TaskList: FromTaskList(t.TaskList), + ScheduleId: t.ScheduleID, + ScheduleToStartTimeout: secondsToDuration(t.ScheduleToStartTimeoutSeconds), + Source: FromTaskSource(t.Source), + ForwardedFrom: t.ForwardedFrom, + } +} + +func ToMatchingAddDecisionTaskRequest(t *matchingv1.AddDecisionTaskRequest) *types.AddDecisionTaskRequest { + if t == nil { + return nil + } + return &types.AddDecisionTaskRequest{ + DomainUUID: t.DomainId, + Execution: ToWorkflowExecution(t.WorkflowExecution), + TaskList: ToTaskList(t.TaskList), + ScheduleID: t.ScheduleId, + ScheduleToStartTimeoutSeconds: durationToSeconds(t.ScheduleToStartTimeout), + Source: ToTaskSource(t.Source), + ForwardedFrom: t.ForwardedFrom, + } +} + +func FromMatchingCancelOutstandingPollRequest(t *types.CancelOutstandingPollRequest) *matchingv1.CancelOutstandingPollRequest { + if t == nil { + return nil + } + var taskListType *types.TaskListType + if t.TaskListType != nil { + taskListType = types.TaskListType(*t.TaskListType).Ptr() + } + return &matchingv1.CancelOutstandingPollRequest{ + DomainId: t.DomainUUID, + PollerId: t.PollerID, + TaskListType: FromTaskListType(taskListType), + TaskList: FromTaskList(t.TaskList), + } +} + +func ToMatchingCancelOutstandingPollRequest(t *matchingv1.CancelOutstandingPollRequest) *types.CancelOutstandingPollRequest { + if t == nil { + return nil + } + var taskListType *int32 + if tlt := ToTaskListType(t.TaskListType); tlt != nil { + taskListType = common.Int32Ptr(int32(*tlt)) + } + return &types.CancelOutstandingPollRequest{ + DomainUUID: t.DomainId, + PollerID: t.PollerId, + TaskListType: taskListType, + TaskList: ToTaskList(t.TaskList), + } +} + +func FromMatchingDescribeTaskListRequest(t *types.MatchingDescribeTaskListRequest) *matchingv1.DescribeTaskListRequest { + if t == nil { + return nil + } + return &matchingv1.DescribeTaskListRequest{ + Request: FromDescribeTaskListRequest(t.DescRequest), + DomainId: t.DomainUUID, + } +} + +func ToMatchingDescribeTaskListRequest(t *matchingv1.DescribeTaskListRequest) *types.MatchingDescribeTaskListRequest { + if t == nil { + return nil + } + return &types.MatchingDescribeTaskListRequest{ + DescRequest: ToDescribeTaskListRequest(t.Request), + DomainUUID: t.DomainId, + } +} + +func FromMatchingDescribeTaskListResponse(t *types.DescribeTaskListResponse) *matchingv1.DescribeTaskListResponse { + if t == nil { + return nil + } + return &matchingv1.DescribeTaskListResponse{ + Pollers: FromPollerInfoArray(t.Pollers), + TaskListStatus: FromTaskListStatus(t.TaskListStatus), + } +} + +func ToMatchingDescribeTaskListResponse(t *matchingv1.DescribeTaskListResponse) *types.DescribeTaskListResponse { + if t == nil { + return nil + } + return &types.DescribeTaskListResponse{ + Pollers: ToPollerInfoArray(t.Pollers), + TaskListStatus: ToTaskListStatus(t.TaskListStatus), + } +} + +func FromMatchingListTaskListPartitionsRequest(t *types.MatchingListTaskListPartitionsRequest) *matchingv1.ListTaskListPartitionsRequest { + if t == nil { + return nil + } + return &matchingv1.ListTaskListPartitionsRequest{ + Domain: t.Domain, + TaskList: FromTaskList(t.TaskList), + } +} + +func ToMatchingListTaskListPartitionsRequest(t *matchingv1.ListTaskListPartitionsRequest) *types.MatchingListTaskListPartitionsRequest { + if t == nil { + return nil + } + return &types.MatchingListTaskListPartitionsRequest{ + Domain: t.Domain, + TaskList: ToTaskList(t.TaskList), + } +} + +func FromMatchingListTaskListPartitionsResponse(t *types.ListTaskListPartitionsResponse) *matchingv1.ListTaskListPartitionsResponse { + if t == nil { + return nil + } + return &matchingv1.ListTaskListPartitionsResponse{ + ActivityTaskListPartitions: FromTaskListPartitionMetadataArray(t.ActivityTaskListPartitions), + DecisionTaskListPartitions: FromTaskListPartitionMetadataArray(t.DecisionTaskListPartitions), + } +} + +func ToMatchingListTaskListPartitionsResponse(t *matchingv1.ListTaskListPartitionsResponse) *types.ListTaskListPartitionsResponse { + if t == nil { + return nil + } + return &types.ListTaskListPartitionsResponse{ + ActivityTaskListPartitions: ToTaskListPartitionMetadataArray(t.ActivityTaskListPartitions), + DecisionTaskListPartitions: ToTaskListPartitionMetadataArray(t.DecisionTaskListPartitions), + } +} + +func FromMatchingPollForActivityTaskRequest(t *types.MatchingPollForActivityTaskRequest) *matchingv1.PollForActivityTaskRequest { + if t == nil { + return nil + } + return &matchingv1.PollForActivityTaskRequest{ + Request: FromPollForActivityTaskRequest(t.PollRequest), + DomainId: t.DomainUUID, + PollerId: t.PollerID, + ForwardedFrom: t.ForwardedFrom, + } +} + +func ToMatchingPollForActivityTaskRequest(t *matchingv1.PollForActivityTaskRequest) *types.MatchingPollForActivityTaskRequest { + if t == nil { + return nil + } + return &types.MatchingPollForActivityTaskRequest{ + PollRequest: ToPollForActivityTaskRequest(t.Request), + DomainUUID: t.DomainId, + PollerID: t.PollerId, + ForwardedFrom: t.ForwardedFrom, + } +} + +func FromMatchingPollForActivityTaskResponse(t *types.PollForActivityTaskResponse) *matchingv1.PollForActivityTaskResponse { + if t == nil { + return nil + } + return &matchingv1.PollForActivityTaskResponse{ + TaskToken: t.TaskToken, + WorkflowExecution: FromWorkflowExecution(t.WorkflowExecution), + ActivityId: t.ActivityID, + ActivityType: FromActivityType(t.ActivityType), + Input: FromPayload(t.Input), + ScheduledTime: unixNanoToTime(t.ScheduledTimestamp), + StartedTime: unixNanoToTime(t.StartedTimestamp), + ScheduleToCloseTimeout: secondsToDuration(t.ScheduleToCloseTimeoutSeconds), + StartToCloseTimeout: secondsToDuration(t.StartToCloseTimeoutSeconds), + HeartbeatTimeout: secondsToDuration(t.HeartbeatTimeoutSeconds), + Attempt: t.Attempt, + ScheduledTimeOfThisAttempt: unixNanoToTime(t.ScheduledTimestampOfThisAttempt), + HeartbeatDetails: FromPayload(t.HeartbeatDetails), + WorkflowType: FromWorkflowType(t.WorkflowType), + WorkflowDomain: t.WorkflowDomain, + Header: FromHeader(t.Header), + } +} + +func ToMatchingPollForActivityTaskResponse(t *matchingv1.PollForActivityTaskResponse) *types.PollForActivityTaskResponse { + if t == nil { + return nil + } + return &types.PollForActivityTaskResponse{ + TaskToken: t.TaskToken, + WorkflowExecution: ToWorkflowExecution(t.WorkflowExecution), + ActivityID: t.ActivityId, + ActivityType: ToActivityType(t.ActivityType), + Input: ToPayload(t.Input), + ScheduledTimestamp: timeToUnixNano(t.ScheduledTime), + StartedTimestamp: timeToUnixNano(t.StartedTime), + ScheduleToCloseTimeoutSeconds: durationToSeconds(t.ScheduleToCloseTimeout), + StartToCloseTimeoutSeconds: durationToSeconds(t.StartToCloseTimeout), + HeartbeatTimeoutSeconds: durationToSeconds(t.HeartbeatTimeout), + Attempt: t.Attempt, + ScheduledTimestampOfThisAttempt: timeToUnixNano(t.ScheduledTimeOfThisAttempt), + HeartbeatDetails: ToPayload(t.HeartbeatDetails), + WorkflowType: ToWorkflowType(t.WorkflowType), + WorkflowDomain: t.WorkflowDomain, + Header: ToHeader(t.Header), + } +} + +func FromMatchingPollForDecisionTaskRequest(t *types.MatchingPollForDecisionTaskRequest) *matchingv1.PollForDecisionTaskRequest { + if t == nil { + return nil + } + return &matchingv1.PollForDecisionTaskRequest{ + Request: FromPollForDecisionTaskRequest(t.PollRequest), + DomainId: t.DomainUUID, + PollerId: t.PollerID, + ForwardedFrom: t.ForwardedFrom, + } +} + +func ToMatchingPollForDecisionTaskRequest(t *matchingv1.PollForDecisionTaskRequest) *types.MatchingPollForDecisionTaskRequest { + if t == nil { + return nil + } + return &types.MatchingPollForDecisionTaskRequest{ + PollRequest: ToPollForDecisionTaskRequest(t.Request), + DomainUUID: t.DomainId, + PollerID: t.PollerId, + ForwardedFrom: t.ForwardedFrom, + } +} + +func FromMatchingPollForDecisionTaskResponse(t *types.MatchingPollForDecisionTaskResponse) *matchingv1.PollForDecisionTaskResponse { + if t == nil { + return nil + } + return &matchingv1.PollForDecisionTaskResponse{ + TaskToken: t.TaskToken, + WorkflowExecution: FromWorkflowExecution(t.WorkflowExecution), + WorkflowType: FromWorkflowType(t.WorkflowType), + PreviousStartedEventId: fromInt64Value(t.PreviousStartedEventID), + StartedEventId: t.StartedEventID, + Attempt: int32(t.Attempt), + NextEventId: t.NextEventID, + BacklogCountHint: t.BacklogCountHint, + StickyExecutionEnabled: t.StickyExecutionEnabled, + Query: FromWorkflowQuery(t.Query), + DecisionInfo: FromTransientDecisionInfo(t.DecisionInfo), + WorkflowExecutionTaskList: FromTaskList(t.WorkflowExecutionTaskList), + EventStoreVersion: t.EventStoreVersion, + BranchToken: t.BranchToken, + ScheduledTime: unixNanoToTime(t.ScheduledTimestamp), + StartedTime: unixNanoToTime(t.StartedTimestamp), + Queries: FromWorkflowQueryMap(t.Queries), + } +} + +func ToMatchingPollForDecisionTaskResponse(t *matchingv1.PollForDecisionTaskResponse) *types.MatchingPollForDecisionTaskResponse { + if t == nil { + return nil + } + return &types.MatchingPollForDecisionTaskResponse{ + TaskToken: t.TaskToken, + WorkflowExecution: ToWorkflowExecution(t.WorkflowExecution), + WorkflowType: ToWorkflowType(t.WorkflowType), + PreviousStartedEventID: toInt64Value(t.PreviousStartedEventId), + StartedEventID: t.StartedEventId, + Attempt: int64(t.Attempt), + NextEventID: t.NextEventId, + BacklogCountHint: t.BacklogCountHint, + StickyExecutionEnabled: t.StickyExecutionEnabled, + Query: ToWorkflowQuery(t.Query), + DecisionInfo: ToTransientDecisionInfo(t.DecisionInfo), + WorkflowExecutionTaskList: ToTaskList(t.WorkflowExecutionTaskList), + EventStoreVersion: t.EventStoreVersion, + BranchToken: t.BranchToken, + ScheduledTimestamp: timeToUnixNano(t.ScheduledTime), + StartedTimestamp: timeToUnixNano(t.StartedTime), + Queries: ToWorkflowQueryMap(t.Queries), + } +} + +func FromMatchingQueryWorkflowRequest(t *types.MatchingQueryWorkflowRequest) *matchingv1.QueryWorkflowRequest { + if t == nil { + return nil + } + return &matchingv1.QueryWorkflowRequest{ + Request: FromQueryWorkflowRequest(t.QueryRequest), + DomainId: t.DomainUUID, + TaskList: FromTaskList(t.TaskList), + ForwardedFrom: t.ForwardedFrom, + } +} + +func ToMatchingQueryWorkflowRequest(t *matchingv1.QueryWorkflowRequest) *types.MatchingQueryWorkflowRequest { + if t == nil { + return nil + } + return &types.MatchingQueryWorkflowRequest{ + QueryRequest: ToQueryWorkflowRequest(t.Request), + DomainUUID: t.DomainId, + TaskList: ToTaskList(t.TaskList), + ForwardedFrom: t.ForwardedFrom, + } +} + +func FromMatchingQueryWorkflowResponse(t *types.QueryWorkflowResponse) *matchingv1.QueryWorkflowResponse { + if t == nil { + return nil + } + return &matchingv1.QueryWorkflowResponse{ + QueryResult: FromPayload(t.QueryResult), + QueryRejected: FromQueryRejected(t.QueryRejected), + } +} + +func ToMatchingQueryWorkflowResponse(t *matchingv1.QueryWorkflowResponse) *types.QueryWorkflowResponse { + if t == nil { + return nil + } + return &types.QueryWorkflowResponse{ + QueryResult: ToPayload(t.QueryResult), + QueryRejected: ToQueryRejected(t.QueryRejected), + } +} + +func FromMatchingRespondQueryTaskCompletedRequest(t *types.MatchingRespondQueryTaskCompletedRequest) *matchingv1.RespondQueryTaskCompletedRequest { + if t == nil { + return nil + } + return &matchingv1.RespondQueryTaskCompletedRequest{ + Request: FromRespondQueryTaskCompletedRequest(t.CompletedRequest), + DomainId: t.DomainUUID, + TaskList: FromTaskList(t.TaskList), + TaskId: t.TaskID, + } +} + +func ToMatchingRespondQueryTaskCompletedRequest(t *matchingv1.RespondQueryTaskCompletedRequest) *types.MatchingRespondQueryTaskCompletedRequest { + if t == nil { + return nil + } + return &types.MatchingRespondQueryTaskCompletedRequest{ + CompletedRequest: ToRespondQueryTaskCompletedRequest(t.Request), + DomainUUID: t.DomainId, + TaskList: ToTaskList(t.TaskList), + TaskID: t.TaskId, + } +} diff --git a/common/types/mapper/proto/matching_test.go b/common/types/mapper/proto/matching_test.go new file mode 100644 index 00000000000..70fc8b33b28 --- /dev/null +++ b/common/types/mapper/proto/matching_test.go @@ -0,0 +1,101 @@ +// 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 ( + "testing" + + "github.com/stretchr/testify/assert" + + "github.com/uber/cadence/common/types" + "github.com/uber/cadence/common/types/testdata" +) + +func TestMatchingAddActivityTaskRequest(t *testing.T) { + for _, item := range []*types.AddActivityTaskRequest{nil, {}, &testdata.MatchingAddActivityTaskRequest} { + assert.Equal(t, item, ToMatchingAddActivityTaskRequest(FromMatchingAddActivityTaskRequest(item))) + } +} +func TestMatchingAddDecisionTaskRequest(t *testing.T) { + for _, item := range []*types.AddDecisionTaskRequest{nil, {}, &testdata.MatchingAddDecisionTaskRequest} { + assert.Equal(t, item, ToMatchingAddDecisionTaskRequest(FromMatchingAddDecisionTaskRequest(item))) + } +} +func TestMatchingCancelOutstandingPollRequest(t *testing.T) { + for _, item := range []*types.CancelOutstandingPollRequest{nil, {}, &testdata.MatchingCancelOutstandingPollRequest} { + assert.Equal(t, item, ToMatchingCancelOutstandingPollRequest(FromMatchingCancelOutstandingPollRequest(item))) + } +} +func TestMatchingDescribeTaskListRequest(t *testing.T) { + for _, item := range []*types.MatchingDescribeTaskListRequest{nil, {}, &testdata.MatchingDescribeTaskListRequest} { + assert.Equal(t, item, ToMatchingDescribeTaskListRequest(FromMatchingDescribeTaskListRequest(item))) + } +} +func TestMatchingDescribeTaskListResponse(t *testing.T) { + for _, item := range []*types.DescribeTaskListResponse{nil, {}, &testdata.MatchingDescribeTaskListResponse} { + assert.Equal(t, item, ToMatchingDescribeTaskListResponse(FromMatchingDescribeTaskListResponse(item))) + } +} +func TestMatchingListTaskListPartitionsRequest(t *testing.T) { + for _, item := range []*types.MatchingListTaskListPartitionsRequest{nil, {}, &testdata.MatchingListTaskListPartitionsRequest} { + assert.Equal(t, item, ToMatchingListTaskListPartitionsRequest(FromMatchingListTaskListPartitionsRequest(item))) + } +} +func TestMatchingListTaskListPartitionsResponse(t *testing.T) { + for _, item := range []*types.ListTaskListPartitionsResponse{nil, {}, &testdata.MatchingListTaskListPartitionsResponse} { + assert.Equal(t, item, ToMatchingListTaskListPartitionsResponse(FromMatchingListTaskListPartitionsResponse(item))) + } +} +func TestMatchingPollForActivityTaskRequest(t *testing.T) { + for _, item := range []*types.MatchingPollForActivityTaskRequest{nil, {}, &testdata.MatchingPollForActivityTaskRequest} { + assert.Equal(t, item, ToMatchingPollForActivityTaskRequest(FromMatchingPollForActivityTaskRequest(item))) + } +} +func TestMatchingPollForActivityTaskResponse(t *testing.T) { + for _, item := range []*types.PollForActivityTaskResponse{nil, {}, &testdata.MatchingPollForActivityTaskResponse} { + assert.Equal(t, item, ToMatchingPollForActivityTaskResponse(FromMatchingPollForActivityTaskResponse(item))) + } +} +func TestMatchingPollForDecisionTaskRequest(t *testing.T) { + for _, item := range []*types.MatchingPollForDecisionTaskRequest{nil, {}, &testdata.MatchingPollForDecisionTaskRequest} { + assert.Equal(t, item, ToMatchingPollForDecisionTaskRequest(FromMatchingPollForDecisionTaskRequest(item))) + } +} +func TestMatchingPollForDecisionTaskResponse(t *testing.T) { + for _, item := range []*types.MatchingPollForDecisionTaskResponse{nil, {}, &testdata.MatchingPollForDecisionTaskResponse} { + assert.Equal(t, item, ToMatchingPollForDecisionTaskResponse(FromMatchingPollForDecisionTaskResponse(item))) + } +} +func TestMatchingQueryWorkflowRequest(t *testing.T) { + for _, item := range []*types.MatchingQueryWorkflowRequest{nil, {}, &testdata.MatchingQueryWorkflowRequest} { + assert.Equal(t, item, ToMatchingQueryWorkflowRequest(FromMatchingQueryWorkflowRequest(item))) + } +} +func TestMatchingQueryWorkflowResponse(t *testing.T) { + for _, item := range []*types.QueryWorkflowResponse{nil, {}, &testdata.MatchingQueryWorkflowResponse} { + assert.Equal(t, item, ToMatchingQueryWorkflowResponse(FromMatchingQueryWorkflowResponse(item))) + } +} +func TestMatchingRespondQueryTaskCompletedRequest(t *testing.T) { + for _, item := range []*types.MatchingRespondQueryTaskCompletedRequest{nil, {}, &testdata.MatchingRespondQueryTaskCompletedRequest} { + assert.Equal(t, item, ToMatchingRespondQueryTaskCompletedRequest(FromMatchingRespondQueryTaskCompletedRequest(item))) + } +} diff --git a/common/types/mapper/proto/shared.go b/common/types/mapper/proto/shared.go new file mode 100644 index 00000000000..d2060070f69 --- /dev/null +++ b/common/types/mapper/proto/shared.go @@ -0,0 +1,940 @@ +// 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 ( + sharedv1 "github.com/uber/cadence/.gen/proto/shared/v1" + "github.com/uber/cadence/common" + "github.com/uber/cadence/common/persistence" + "github.com/uber/cadence/common/types" +) + +func FromHostInfo(t *types.HostInfo) *sharedv1.HostInfo { + if t == nil { + return nil + } + return &sharedv1.HostInfo{ + Identity: t.Identity, + } +} + +func ToHostInfo(t *sharedv1.HostInfo) *types.HostInfo { + if t == nil { + return nil + } + return &types.HostInfo{ + Identity: t.Identity, + } +} + +func FromMembershipInfo(t *types.MembershipInfo) *sharedv1.MembershipInfo { + if t == nil { + return nil + } + return &sharedv1.MembershipInfo{ + CurrentHost: FromHostInfo(t.CurrentHost), + ReachableMembers: t.ReachableMembers, + Rings: FromRingInfoArray(t.Rings), + } +} + +func ToMembershipInfo(t *sharedv1.MembershipInfo) *types.MembershipInfo { + if t == nil { + return nil + } + return &types.MembershipInfo{ + CurrentHost: ToHostInfo(t.CurrentHost), + ReachableMembers: t.ReachableMembers, + Rings: ToRingInfoArray(t.Rings), + } +} + +func FromDomainCacheInfo(t *types.DomainCacheInfo) *sharedv1.DomainCacheInfo { + if t == nil { + return nil + } + return &sharedv1.DomainCacheInfo{ + NumOfItemsInCacheById: t.NumOfItemsInCacheByID, + NumOfItemsInCacheByName: t.NumOfItemsInCacheByName, + } +} + +func ToDomainCacheInfo(t *sharedv1.DomainCacheInfo) *types.DomainCacheInfo { + if t == nil { + return nil + } + return &types.DomainCacheInfo{ + NumOfItemsInCacheByID: t.NumOfItemsInCacheById, + NumOfItemsInCacheByName: t.NumOfItemsInCacheByName, + } +} + +func FromRingInfo(t *types.RingInfo) *sharedv1.RingInfo { + if t == nil { + return nil + } + return &sharedv1.RingInfo{ + Role: t.Role, + MemberCount: t.MemberCount, + Members: FromHostInfoArray(t.Members), + } +} + +func ToRingInfo(t *sharedv1.RingInfo) *types.RingInfo { + if t == nil { + return nil + } + return &types.RingInfo{ + Role: t.Role, + MemberCount: t.MemberCount, + Members: ToHostInfoArray(t.Members), + } +} + +func FromTaskSource(t *types.TaskSource) sharedv1.TaskSource { + if t == nil { + return sharedv1.TaskSource_TASK_SOURCE_INVALID + } + switch *t { + case types.TaskSourceHistory: + return sharedv1.TaskSource_TASK_SOURCE_HISTORY + case types.TaskSourceDbBacklog: + return sharedv1.TaskSource_TASK_SOURCE_DB_BACKLOG + } + panic("unexpected enum value") +} + +func ToTaskSource(t sharedv1.TaskSource) *types.TaskSource { + switch t { + case sharedv1.TaskSource_TASK_SOURCE_INVALID: + return nil + case sharedv1.TaskSource_TASK_SOURCE_HISTORY: + return types.TaskSourceHistory.Ptr() + case sharedv1.TaskSource_TASK_SOURCE_DB_BACKLOG: + return types.TaskSourceDbBacklog.Ptr() + } + panic("unexpected enum value") +} + +func FromTransientDecisionInfo(t *types.TransientDecisionInfo) *sharedv1.TransientDecisionInfo { + if t == nil { + return nil + } + return &sharedv1.TransientDecisionInfo{ + ScheduledEvent: FromHistoryEvent(t.ScheduledEvent), + StartedEvent: FromHistoryEvent(t.StartedEvent), + } +} + +func ToTransientDecisionInfo(t *sharedv1.TransientDecisionInfo) *types.TransientDecisionInfo { + if t == nil { + return nil + } + return &types.TransientDecisionInfo{ + ScheduledEvent: ToHistoryEvent(t.ScheduledEvent), + StartedEvent: ToHistoryEvent(t.StartedEvent), + } +} + +func FromVersionHistories(t *types.VersionHistories) *sharedv1.VersionHistories { + if t == nil { + return nil + } + return &sharedv1.VersionHistories{ + CurrentVersionHistoryIndex: t.CurrentVersionHistoryIndex, + Histories: FromVersionHistoryArray(t.Histories), + } +} + +func ToVersionHistories(t *sharedv1.VersionHistories) *types.VersionHistories { + if t == nil { + return nil + } + return &types.VersionHistories{ + CurrentVersionHistoryIndex: t.CurrentVersionHistoryIndex, + Histories: ToVersionHistoryArray(t.Histories), + } +} + +func FromVersionHistory(t *types.VersionHistory) *sharedv1.VersionHistory { + if t == nil { + return nil + } + return &sharedv1.VersionHistory{ + BranchToken: t.BranchToken, + Items: FromVersionHistoryItemArray(t.Items), + } +} + +func ToVersionHistory(t *sharedv1.VersionHistory) *types.VersionHistory { + if t == nil { + return nil + } + return &types.VersionHistory{ + BranchToken: t.BranchToken, + Items: ToVersionHistoryItemArray(t.Items), + } +} + +func FromVersionHistoryItem(t *types.VersionHistoryItem) *sharedv1.VersionHistoryItem { + if t == nil { + return nil + } + return &sharedv1.VersionHistoryItem{ + EventId: t.EventID, + Version: t.Version, + } +} + +func ToVersionHistoryItem(t *sharedv1.VersionHistoryItem) *types.VersionHistoryItem { + if t == nil { + return nil + } + return &types.VersionHistoryItem{ + EventID: t.EventId, + Version: t.Version, + } +} + +func FromWorkflowState(t *int32) sharedv1.WorkflowState { + if t == nil { + return sharedv1.WorkflowState_WORKFLOW_STATE_INVALID + } + switch *t { + case persistence.WorkflowStateCreated: + return sharedv1.WorkflowState_WORKFLOW_STATE_CREATED + case persistence.WorkflowStateRunning: + return sharedv1.WorkflowState_WORKFLOW_STATE_RUNNING + case persistence.WorkflowStateCompleted: + return sharedv1.WorkflowState_WORKFLOW_STATE_COMPLETED + case persistence.WorkflowStateZombie: + return sharedv1.WorkflowState_WORKFLOW_STATE_ZOMBIE + case persistence.WorkflowStateVoid: + return sharedv1.WorkflowState_WORKFLOW_STATE_VOID + case persistence.WorkflowStateCorrupted: + return sharedv1.WorkflowState_WORKFLOW_STATE_CORRUPTED + } + panic("unexpected enum value") +} + +func ToWorkflowState(t sharedv1.WorkflowState) *int32 { + switch t { + case sharedv1.WorkflowState_WORKFLOW_STATE_INVALID: + return nil + case sharedv1.WorkflowState_WORKFLOW_STATE_CREATED: + v := int32(persistence.WorkflowStateCreated) + return &v + case sharedv1.WorkflowState_WORKFLOW_STATE_RUNNING: + v := int32(persistence.WorkflowStateRunning) + return &v + case sharedv1.WorkflowState_WORKFLOW_STATE_COMPLETED: + v := int32(persistence.WorkflowStateCompleted) + return &v + case sharedv1.WorkflowState_WORKFLOW_STATE_ZOMBIE: + v := int32(persistence.WorkflowStateZombie) + return &v + case sharedv1.WorkflowState_WORKFLOW_STATE_VOID: + v := int32(persistence.WorkflowStateVoid) + return &v + case sharedv1.WorkflowState_WORKFLOW_STATE_CORRUPTED: + v := int32(persistence.WorkflowStateCorrupted) + return &v + } + panic("unexpected enum value") +} + +func FromHostInfoArray(t []*types.HostInfo) []*sharedv1.HostInfo { + if t == nil { + return nil + } + v := make([]*sharedv1.HostInfo, len(t)) + for i := range t { + v[i] = FromHostInfo(t[i]) + } + return v +} + +func ToHostInfoArray(t []*sharedv1.HostInfo) []*types.HostInfo { + if t == nil { + return nil + } + v := make([]*types.HostInfo, len(t)) + for i := range t { + v[i] = ToHostInfo(t[i]) + } + return v +} + +func FromVersionHistoryArray(t []*types.VersionHistory) []*sharedv1.VersionHistory { + if t == nil { + return nil + } + v := make([]*sharedv1.VersionHistory, len(t)) + for i := range t { + v[i] = FromVersionHistory(t[i]) + } + return v +} + +func ToVersionHistoryArray(t []*sharedv1.VersionHistory) []*types.VersionHistory { + if t == nil { + return nil + } + v := make([]*types.VersionHistory, len(t)) + for i := range t { + v[i] = ToVersionHistory(t[i]) + } + return v +} + +func FromRingInfoArray(t []*types.RingInfo) []*sharedv1.RingInfo { + if t == nil { + return nil + } + v := make([]*sharedv1.RingInfo, len(t)) + for i := range t { + v[i] = FromRingInfo(t[i]) + } + return v +} + +func ToRingInfoArray(t []*sharedv1.RingInfo) []*types.RingInfo { + if t == nil { + return nil + } + v := make([]*types.RingInfo, len(t)) + for i := range t { + v[i] = ToRingInfo(t[i]) + } + return v +} + +func FromDLQType(t *types.DLQType) sharedv1.DLQType { + if t == nil { + return sharedv1.DLQType_DLQ_TYPE_INVALID + } + switch *t { + case types.DLQTypeReplication: + return sharedv1.DLQType_DLQ_TYPE_REPLICATION + case types.DLQTypeDomain: + return sharedv1.DLQType_DLQ_TYPE_DOMAIN + } + panic("unexpected enum value") +} + +func ToDLQType(t sharedv1.DLQType) *types.DLQType { + switch t { + case sharedv1.DLQType_DLQ_TYPE_INVALID: + return nil + case sharedv1.DLQType_DLQ_TYPE_REPLICATION: + return types.DLQTypeReplication.Ptr() + case sharedv1.DLQType_DLQ_TYPE_DOMAIN: + return types.DLQTypeDomain.Ptr() + } + panic("unexpected enum value") +} + +func FromDomainOperation(t *types.DomainOperation) sharedv1.DomainOperation { + if t == nil { + return sharedv1.DomainOperation_DOMAIN_OPERATION_INVALID + } + switch *t { + case types.DomainOperationCreate: + return sharedv1.DomainOperation_DOMAIN_OPERATION_CREATE + case types.DomainOperationUpdate: + return sharedv1.DomainOperation_DOMAIN_OPERATION_UPDATE + } + panic("unexpected enum value") +} + +func ToDomainOperation(t sharedv1.DomainOperation) *types.DomainOperation { + switch t { + case sharedv1.DomainOperation_DOMAIN_OPERATION_INVALID: + return nil + case sharedv1.DomainOperation_DOMAIN_OPERATION_CREATE: + return types.DomainOperationCreate.Ptr() + case sharedv1.DomainOperation_DOMAIN_OPERATION_UPDATE: + return types.DomainOperationUpdate.Ptr() + } + panic("unexpected enum value") +} + +func FromDomainTaskAttributes(t *types.DomainTaskAttributes) *sharedv1.DomainTaskAttributes { + if t == nil { + return nil + } + return &sharedv1.DomainTaskAttributes{ + DomainOperation: FromDomainOperation(t.DomainOperation), + Id: t.ID, + Domain: FromDescribeDomainResponseDomain(&types.DescribeDomainResponse{ + DomainInfo: t.Info, + Configuration: t.Config, + ReplicationConfiguration: t.ReplicationConfig, + }), + ConfigVersion: t.ConfigVersion, + FailoverVersion: t.FailoverVersion, + PreviousFailoverVersion: t.PreviousFailoverVersion, + } +} + +func ToDomainTaskAttributes(t *sharedv1.DomainTaskAttributes) *types.DomainTaskAttributes { + if t == nil { + return nil + } + domain := ToDescribeDomainResponseDomain(t.Domain) + return &types.DomainTaskAttributes{ + DomainOperation: ToDomainOperation(t.DomainOperation), + ID: t.Id, + Info: domain.DomainInfo, + Config: domain.Configuration, + ReplicationConfig: domain.ReplicationConfiguration, + ConfigVersion: t.ConfigVersion, + FailoverVersion: t.FailoverVersion, + PreviousFailoverVersion: t.PreviousFailoverVersion, + } +} + +func FromFailoverMarkerAttributes(t *types.FailoverMarkerAttributes) *sharedv1.FailoverMarkerAttributes { + if t == nil { + return nil + } + return &sharedv1.FailoverMarkerAttributes{ + DomainId: t.DomainID, + FailoverVersion: t.FailoverVersion, + CreationTime: unixNanoToTime(t.CreationTime), + } +} + +func ToFailoverMarkerAttributes(t *sharedv1.FailoverMarkerAttributes) *types.FailoverMarkerAttributes { + if t == nil { + return nil + } + return &types.FailoverMarkerAttributes{ + DomainID: t.DomainId, + FailoverVersion: t.FailoverVersion, + CreationTime: timeToUnixNano(t.CreationTime), + } +} + +func FromFailoverMarkerToken(t *types.FailoverMarkerToken) *sharedv1.FailoverMarkerToken { + if t == nil { + return nil + } + return &sharedv1.FailoverMarkerToken{ + ShardIds: t.ShardIDs, + FailoverMarker: FromFailoverMarkerAttributes(t.FailoverMarker), + } +} + +func ToFailoverMarkerToken(t *sharedv1.FailoverMarkerToken) *types.FailoverMarkerToken { + if t == nil { + return nil + } + return &types.FailoverMarkerToken{ + ShardIDs: t.ShardIds, + FailoverMarker: ToFailoverMarkerAttributes(t.FailoverMarker), + } +} + +func FromHistoryTaskV2Attributes(t *types.HistoryTaskV2Attributes) *sharedv1.HistoryTaskV2Attributes { + if t == nil { + return nil + } + return &sharedv1.HistoryTaskV2Attributes{ + TaskId: t.TaskID, + DomainId: t.DomainID, + WorkflowExecution: FromWorkflowRunPair(t.WorkflowID, t.RunID), + VersionHistoryItems: FromVersionHistoryItemArray(t.VersionHistoryItems), + Events: FromDataBlob(t.Events), + NewRunEvents: FromDataBlob(t.NewRunEvents), + } +} + +func ToHistoryTaskV2Attributes(t *sharedv1.HistoryTaskV2Attributes) *types.HistoryTaskV2Attributes { + if t == nil { + return nil + } + return &types.HistoryTaskV2Attributes{ + TaskID: t.TaskId, + DomainID: t.DomainId, + WorkflowID: ToWorkflowID(t.WorkflowExecution), + RunID: ToRunID(t.WorkflowExecution), + VersionHistoryItems: ToVersionHistoryItemArray(t.VersionHistoryItems), + Events: ToDataBlob(t.Events), + NewRunEvents: ToDataBlob(t.NewRunEvents), + } +} + +func FromReplicationMessages(t *types.ReplicationMessages) *sharedv1.ReplicationMessages { + if t == nil { + return nil + } + return &sharedv1.ReplicationMessages{ + ReplicationTasks: FromReplicationTaskArray(t.ReplicationTasks), + LastRetrievedMessageId: t.LastRetrievedMessageID, + HasMore: t.HasMore, + SyncShardStatus: FromSyncShardStatus(t.SyncShardStatus), + } +} + +func ToReplicationMessages(t *sharedv1.ReplicationMessages) *types.ReplicationMessages { + if t == nil { + return nil + } + return &types.ReplicationMessages{ + ReplicationTasks: ToReplicationTaskArray(t.ReplicationTasks), + LastRetrievedMessageID: t.LastRetrievedMessageId, + HasMore: t.HasMore, + SyncShardStatus: ToSyncShardStatus(t.SyncShardStatus), + } +} + +func FromReplicationTaskInfo(t *types.ReplicationTaskInfo) *sharedv1.ReplicationTaskInfo { + if t == nil { + return nil + } + return &sharedv1.ReplicationTaskInfo{ + DomainId: t.DomainID, + WorkflowExecution: FromWorkflowRunPair(t.WorkflowID, t.RunID), + TaskType: int32(t.TaskType), + TaskId: t.TaskID, + Version: t.Version, + FirstEventId: t.FirstEventID, + NextEventId: t.NextEventID, + ScheduledId: t.ScheduledID, + } +} + +func ToReplicationTaskInfo(t *sharedv1.ReplicationTaskInfo) *types.ReplicationTaskInfo { + if t == nil { + return nil + } + return &types.ReplicationTaskInfo{ + DomainID: t.DomainId, + WorkflowID: ToWorkflowID(t.WorkflowExecution), + RunID: ToRunID(t.WorkflowExecution), + TaskType: int16(t.TaskType), + TaskID: t.TaskId, + Version: t.Version, + FirstEventID: t.FirstEventId, + NextEventID: t.NextEventId, + ScheduledID: t.ScheduledId, + } +} + +func FromReplicationTaskType(t *types.ReplicationTaskType) sharedv1.ReplicationTaskType { + if t == nil { + return sharedv1.ReplicationTaskType_REPLICATION_TASK_TYPE_INVALID + } + switch *t { + case types.ReplicationTaskTypeDomain: + return sharedv1.ReplicationTaskType_REPLICATION_TASK_TYPE_DOMAIN + case types.ReplicationTaskTypeHistory: + return sharedv1.ReplicationTaskType_REPLICATION_TASK_TYPE_HISTORY + case types.ReplicationTaskTypeSyncShardStatus: + return sharedv1.ReplicationTaskType_REPLICATION_TASK_TYPE_SYNC_SHARD_STATUS + case types.ReplicationTaskTypeSyncActivity: + return sharedv1.ReplicationTaskType_REPLICATION_TASK_TYPE_SYNC_ACTIVITY + case types.ReplicationTaskTypeHistoryMetadata: + return sharedv1.ReplicationTaskType_REPLICATION_TASK_TYPE_HISTORY_METADATA + case types.ReplicationTaskTypeHistoryV2: + return sharedv1.ReplicationTaskType_REPLICATION_TASK_TYPE_HISTORY_V2 + case types.ReplicationTaskTypeFailoverMarker: + return sharedv1.ReplicationTaskType_REPLICATION_TASK_TYPE_FAILOVER_MARKER + } + panic("unexpected enum value") +} + +func ToReplicationTaskType(t sharedv1.ReplicationTaskType) *types.ReplicationTaskType { + switch t { + case sharedv1.ReplicationTaskType_REPLICATION_TASK_TYPE_INVALID: + return nil + case sharedv1.ReplicationTaskType_REPLICATION_TASK_TYPE_DOMAIN: + return types.ReplicationTaskTypeDomain.Ptr() + case sharedv1.ReplicationTaskType_REPLICATION_TASK_TYPE_HISTORY: + return types.ReplicationTaskTypeHistory.Ptr() + case sharedv1.ReplicationTaskType_REPLICATION_TASK_TYPE_SYNC_SHARD_STATUS: + return types.ReplicationTaskTypeSyncShardStatus.Ptr() + case sharedv1.ReplicationTaskType_REPLICATION_TASK_TYPE_SYNC_ACTIVITY: + return types.ReplicationTaskTypeSyncActivity.Ptr() + case sharedv1.ReplicationTaskType_REPLICATION_TASK_TYPE_HISTORY_METADATA: + return types.ReplicationTaskTypeHistoryMetadata.Ptr() + case sharedv1.ReplicationTaskType_REPLICATION_TASK_TYPE_HISTORY_V2: + return types.ReplicationTaskTypeHistoryV2.Ptr() + case sharedv1.ReplicationTaskType_REPLICATION_TASK_TYPE_FAILOVER_MARKER: + return types.ReplicationTaskTypeFailoverMarker.Ptr() + } + panic("unexpected enum value") +} + +func FromReplicationToken(t *types.ReplicationToken) *sharedv1.ReplicationToken { + if t == nil { + return nil + } + return &sharedv1.ReplicationToken{ + ShardId: t.ShardID, + LastRetrievedMessageId: t.LastRetrievedMessageID, + LastProcessedMessageId: t.LastProcessedMessageID, + } +} + +func ToReplicationToken(t *sharedv1.ReplicationToken) *types.ReplicationToken { + if t == nil { + return nil + } + return &types.ReplicationToken{ + ShardID: t.ShardId, + LastRetrievedMessageID: t.LastRetrievedMessageId, + LastProcessedMessageID: t.LastProcessedMessageId, + } +} + +func FromSyncActivityTaskAttributes(t *types.SyncActivityTaskAttributes) *sharedv1.SyncActivityTaskAttributes { + if t == nil { + return nil + } + return &sharedv1.SyncActivityTaskAttributes{ + DomainId: t.DomainID, + WorkflowExecution: FromWorkflowRunPair(t.WorkflowID, t.RunID), + Version: t.Version, + ScheduledId: t.ScheduledID, + ScheduledTime: unixNanoToTime(t.ScheduledTime), + StartedId: t.StartedID, + StartedTime: unixNanoToTime(t.StartedTime), + LastHeartbeatTime: unixNanoToTime(t.LastHeartbeatTime), + Details: FromPayload(t.Details), + Attempt: t.Attempt, + LastFailure: FromFailure(t.LastFailureReason, t.LastFailureDetails), + LastWorkerIdentity: t.LastWorkerIdentity, + VersionHistory: FromVersionHistory(t.VersionHistory), + } +} + +func ToSyncActivityTaskAttributes(t *sharedv1.SyncActivityTaskAttributes) *types.SyncActivityTaskAttributes { + if t == nil { + return nil + } + return &types.SyncActivityTaskAttributes{ + DomainID: t.DomainId, + WorkflowID: ToWorkflowID(t.WorkflowExecution), + RunID: ToRunID(t.WorkflowExecution), + Version: t.Version, + ScheduledID: t.ScheduledId, + ScheduledTime: timeToUnixNano(t.ScheduledTime), + StartedID: t.StartedId, + StartedTime: timeToUnixNano(t.StartedTime), + LastHeartbeatTime: timeToUnixNano(t.LastHeartbeatTime), + Details: ToPayload(t.Details), + Attempt: t.Attempt, + LastFailureReason: ToFailureReason(t.LastFailure), + LastFailureDetails: ToFailureDetails(t.LastFailure), + LastWorkerIdentity: t.LastWorkerIdentity, + VersionHistory: ToVersionHistory(t.VersionHistory), + } +} + +func FromSyncShardStatus(t *types.SyncShardStatus) *sharedv1.SyncShardStatus { + if t == nil { + return nil + } + return &sharedv1.SyncShardStatus{ + Timestamp: unixNanoToTime(t.Timestamp), + } +} + +func ToSyncShardStatus(t *sharedv1.SyncShardStatus) *types.SyncShardStatus { + if t == nil { + return nil + } + return &types.SyncShardStatus{ + Timestamp: timeToUnixNano(t.Timestamp), + } +} + +func FromSyncShardStatusTaskAttributes(t *types.SyncShardStatusTaskAttributes) *sharedv1.SyncShardStatusTaskAttributes { + if t == nil { + return nil + } + return &sharedv1.SyncShardStatusTaskAttributes{ + SourceCluster: t.SourceCluster, + ShardId: int32(t.ShardID), + Timestamp: unixNanoToTime(t.Timestamp), + } +} + +func ToSyncShardStatusTaskAttributes(t *sharedv1.SyncShardStatusTaskAttributes) *types.SyncShardStatusTaskAttributes { + if t == nil { + return nil + } + return &types.SyncShardStatusTaskAttributes{ + SourceCluster: t.SourceCluster, + ShardID: int64(t.ShardId), + Timestamp: timeToUnixNano(t.Timestamp), + } +} + +func FromReplicationTaskInfoArray(t []*types.ReplicationTaskInfo) []*sharedv1.ReplicationTaskInfo { + if t == nil { + return nil + } + v := make([]*sharedv1.ReplicationTaskInfo, len(t)) + for i := range t { + v[i] = FromReplicationTaskInfo(t[i]) + } + return v +} + +func ToReplicationTaskInfoArray(t []*sharedv1.ReplicationTaskInfo) []*types.ReplicationTaskInfo { + if t == nil { + return nil + } + v := make([]*types.ReplicationTaskInfo, len(t)) + for i := range t { + v[i] = ToReplicationTaskInfo(t[i]) + } + return v +} + +func FromReplicationTaskArray(t []*types.ReplicationTask) []*sharedv1.ReplicationTask { + if t == nil { + return nil + } + v := make([]*sharedv1.ReplicationTask, len(t)) + for i := range t { + v[i] = FromReplicationTask(t[i]) + } + return v +} + +func ToReplicationTaskArray(t []*sharedv1.ReplicationTask) []*types.ReplicationTask { + if t == nil { + return nil + } + v := make([]*types.ReplicationTask, len(t)) + for i := range t { + v[i] = ToReplicationTask(t[i]) + } + return v +} + +func FromReplicationTokenArray(t []*types.ReplicationToken) []*sharedv1.ReplicationToken { + if t == nil { + return nil + } + v := make([]*sharedv1.ReplicationToken, len(t)) + for i := range t { + v[i] = FromReplicationToken(t[i]) + } + return v +} + +func ToReplicationTokenArray(t []*sharedv1.ReplicationToken) []*types.ReplicationToken { + if t == nil { + return nil + } + v := make([]*types.ReplicationToken, len(t)) + for i := range t { + v[i] = ToReplicationToken(t[i]) + } + return v +} + +func FromReplicationMessagesMap(t map[int32]*types.ReplicationMessages) map[int32]*sharedv1.ReplicationMessages { + if t == nil { + return nil + } + v := make(map[int32]*sharedv1.ReplicationMessages, len(t)) + for key := range t { + v[key] = FromReplicationMessages(t[key]) + } + return v +} + +func ToReplicationMessagesMap(t map[int32]*sharedv1.ReplicationMessages) map[int32]*types.ReplicationMessages { + if t == nil { + return nil + } + v := make(map[int32]*types.ReplicationMessages, len(t)) + for key := range t { + v[key] = ToReplicationMessages(t[key]) + } + return v +} + +func FromReplicationTask(t *types.ReplicationTask) *sharedv1.ReplicationTask { + if t == nil { + return nil + } + task := sharedv1.ReplicationTask{ + TaskType: FromReplicationTaskType(t.TaskType), + SourceTaskId: t.SourceTaskID, + CreationTime: unixNanoToTime(t.CreationTime), + } + if t.DomainTaskAttributes != nil { + task.Attributes = &sharedv1.ReplicationTask_DomainTaskAttributes{ + DomainTaskAttributes: FromDomainTaskAttributes(t.DomainTaskAttributes), + } + } + if t.SyncShardStatusTaskAttributes != nil { + task.Attributes = &sharedv1.ReplicationTask_SyncShardStatusTaskAttributes{ + SyncShardStatusTaskAttributes: FromSyncShardStatusTaskAttributes(t.SyncShardStatusTaskAttributes), + } + } + if t.SyncActivityTaskAttributes != nil { + task.Attributes = &sharedv1.ReplicationTask_SyncActivityTaskAttributes{ + SyncActivityTaskAttributes: FromSyncActivityTaskAttributes(t.SyncActivityTaskAttributes), + } + } + if t.HistoryTaskV2Attributes != nil { + task.Attributes = &sharedv1.ReplicationTask_HistoryTaskV2Attributes{ + HistoryTaskV2Attributes: FromHistoryTaskV2Attributes(t.HistoryTaskV2Attributes), + } + } + if t.FailoverMarkerAttributes != nil { + task.Attributes = &sharedv1.ReplicationTask_FailoverMarkerAttributes{ + FailoverMarkerAttributes: FromFailoverMarkerAttributes(t.FailoverMarkerAttributes), + } + } + + return &task +} + +func ToReplicationTask(t *sharedv1.ReplicationTask) *types.ReplicationTask { + if t == nil { + return nil + } + task := types.ReplicationTask{ + TaskType: ToReplicationTaskType(t.TaskType), + SourceTaskID: t.SourceTaskId, + CreationTime: timeToUnixNano(t.CreationTime), + } + + switch attr := t.Attributes.(type) { + case *sharedv1.ReplicationTask_DomainTaskAttributes: + task.DomainTaskAttributes = ToDomainTaskAttributes(attr.DomainTaskAttributes) + case *sharedv1.ReplicationTask_SyncShardStatusTaskAttributes: + task.SyncShardStatusTaskAttributes = ToSyncShardStatusTaskAttributes(attr.SyncShardStatusTaskAttributes) + case *sharedv1.ReplicationTask_SyncActivityTaskAttributes: + task.SyncActivityTaskAttributes = ToSyncActivityTaskAttributes(attr.SyncActivityTaskAttributes) + case *sharedv1.ReplicationTask_HistoryTaskV2Attributes: + task.HistoryTaskV2Attributes = ToHistoryTaskV2Attributes(attr.HistoryTaskV2Attributes) + case *sharedv1.ReplicationTask_FailoverMarkerAttributes: + task.FailoverMarkerAttributes = ToFailoverMarkerAttributes(attr.FailoverMarkerAttributes) + } + return &task +} + +func FromTaskType(t *int32) sharedv1.TaskType { + if t == nil { + return sharedv1.TaskType_TASK_TYPE_INVALID + } + switch common.TaskType(*t) { + case common.TaskTypeTransfer: + return sharedv1.TaskType_TASK_TYPE_TRANSFER + case common.TaskTypeTimer: + return sharedv1.TaskType_TASK_TYPE_TIMER + case common.TaskTypeReplication: + return sharedv1.TaskType_TASK_TYPE_REPLICATION + } + panic("unexpected enum value") +} + +func ToTaskType(t sharedv1.TaskType) *int32 { + switch t { + case sharedv1.TaskType_TASK_TYPE_INVALID: + return nil + case sharedv1.TaskType_TASK_TYPE_TRANSFER: + return common.Int32Ptr(int32(common.TaskTypeTransfer)) + case sharedv1.TaskType_TASK_TYPE_TIMER: + return common.Int32Ptr(int32(common.TaskTypeTimer)) + case sharedv1.TaskType_TASK_TYPE_REPLICATION: + return common.Int32Ptr(int32(common.TaskTypeReplication)) + } + panic("unexpected enum value") +} + +func FromFailoverMarkerTokenArray(t []*types.FailoverMarkerToken) []*sharedv1.FailoverMarkerToken { + if t == nil { + return nil + } + v := make([]*sharedv1.FailoverMarkerToken, len(t)) + for i := range t { + v[i] = FromFailoverMarkerToken(t[i]) + } + return v +} + +func ToFailoverMarkerTokenArray(t []*sharedv1.FailoverMarkerToken) []*types.FailoverMarkerToken { + if t == nil { + return nil + } + v := make([]*types.FailoverMarkerToken, len(t)) + for i := range t { + v[i] = ToFailoverMarkerToken(t[i]) + } + return v +} + +func FromVersionHistoryItemArray(t []*types.VersionHistoryItem) []*sharedv1.VersionHistoryItem { + if t == nil { + return nil + } + v := make([]*sharedv1.VersionHistoryItem, len(t)) + for i := range t { + v[i] = FromVersionHistoryItem(t[i]) + } + return v +} + +func ToVersionHistoryItemArray(t []*sharedv1.VersionHistoryItem) []*types.VersionHistoryItem { + if t == nil { + return nil + } + v := make([]*types.VersionHistoryItem, len(t)) + for i := range t { + v[i] = ToVersionHistoryItem(t[i]) + } + return v +} + +func FromEventIDVersionPair(id, version *int64) *sharedv1.VersionHistoryItem { + if id == nil || version == nil { + return nil + } + return &sharedv1.VersionHistoryItem{ + EventId: *id, + Version: *version, + } +} + +func ToEventID(item *sharedv1.VersionHistoryItem) *int64 { + if item == nil { + return nil + } + return common.Int64Ptr(item.EventId) +} + +func ToEventVersion(item *sharedv1.VersionHistoryItem) *int64 { + if item == nil { + return nil + } + return common.Int64Ptr(item.Version) +} diff --git a/common/types/mapper/proto/shared_test.go b/common/types/mapper/proto/shared_test.go new file mode 100644 index 00000000000..b8b33aa007f --- /dev/null +++ b/common/types/mapper/proto/shared_test.go @@ -0,0 +1,377 @@ +// 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 ( + "testing" + + "github.com/stretchr/testify/assert" + + "github.com/uber/cadence/common" + "github.com/uber/cadence/common/types" + "github.com/uber/cadence/common/types/testdata" +) + +func TestHostInfo(t *testing.T) { + for _, item := range []*types.HostInfo{nil, {}, &testdata.HostInfo} { + assert.Equal(t, item, ToHostInfo(FromHostInfo(item))) + } +} +func TestMembershipInfo(t *testing.T) { + for _, item := range []*types.MembershipInfo{nil, {}, &testdata.MembershipInfo} { + assert.Equal(t, item, ToMembershipInfo(FromMembershipInfo(item))) + } +} +func TestDomainCacheInfo(t *testing.T) { + for _, item := range []*types.DomainCacheInfo{nil, {}, &testdata.DomainCacheInfo} { + assert.Equal(t, item, ToDomainCacheInfo(FromDomainCacheInfo(item))) + } +} +func TestRingInfo(t *testing.T) { + for _, item := range []*types.RingInfo{nil, {}, &testdata.RingInfo} { + assert.Equal(t, item, ToRingInfo(FromRingInfo(item))) + } +} +func TestTransientDecisionInfo(t *testing.T) { + for _, item := range []*types.TransientDecisionInfo{nil, {}, &testdata.TransientDecisionInfo} { + assert.Equal(t, item, ToTransientDecisionInfo(FromTransientDecisionInfo(item))) + } +} +func TestVersionHistories(t *testing.T) { + for _, item := range []*types.VersionHistories{nil, {}, &testdata.VersionHistories} { + assert.Equal(t, item, ToVersionHistories(FromVersionHistories(item))) + } +} +func TestVersionHistory(t *testing.T) { + for _, item := range []*types.VersionHistory{nil, {}, &testdata.VersionHistory} { + assert.Equal(t, item, ToVersionHistory(FromVersionHistory(item))) + } +} +func TestVersionHistoryItem(t *testing.T) { + for _, item := range []*types.VersionHistoryItem{nil, {}, &testdata.VersionHistoryItem} { + assert.Equal(t, item, ToVersionHistoryItem(FromVersionHistoryItem(item))) + } +} +func TestHostInfoArray(t *testing.T) { + for _, item := range [][]*types.HostInfo{nil, {}, testdata.HostInfoArray} { + assert.Equal(t, item, ToHostInfoArray(FromHostInfoArray(item))) + } +} +func TestVersionHistoryArray(t *testing.T) { + for _, item := range [][]*types.VersionHistory{nil, {}, testdata.VersionHistoryArray} { + assert.Equal(t, item, ToVersionHistoryArray(FromVersionHistoryArray(item))) + } +} +func TestRingInfoArray(t *testing.T) { + for _, item := range [][]*types.RingInfo{nil, {}, testdata.RingInfoArray} { + assert.Equal(t, item, ToRingInfoArray(FromRingInfoArray(item))) + } +} +func TestDomainTaskAttributes(t *testing.T) { + for _, item := range []*types.DomainTaskAttributes{nil, &testdata.DomainTaskAttributes} { + assert.Equal(t, item, ToDomainTaskAttributes(FromDomainTaskAttributes(item))) + } +} +func TestFailoverMarkerAttributes(t *testing.T) { + for _, item := range []*types.FailoverMarkerAttributes{nil, {}, &testdata.FailoverMarkerAttributes} { + assert.Equal(t, item, ToFailoverMarkerAttributes(FromFailoverMarkerAttributes(item))) + } +} +func TestFailoverMarkerToken(t *testing.T) { + for _, item := range []*types.FailoverMarkerToken{nil, {}, &testdata.FailoverMarkerToken} { + assert.Equal(t, item, ToFailoverMarkerToken(FromFailoverMarkerToken(item))) + } +} +func TestHistoryTaskV2Attributes(t *testing.T) { + for _, item := range []*types.HistoryTaskV2Attributes{nil, {}, &testdata.HistoryTaskV2Attributes} { + assert.Equal(t, item, ToHistoryTaskV2Attributes(FromHistoryTaskV2Attributes(item))) + } +} +func TestReplicationMessages(t *testing.T) { + for _, item := range []*types.ReplicationMessages{nil, {}, &testdata.ReplicationMessages} { + assert.Equal(t, item, ToReplicationMessages(FromReplicationMessages(item))) + } +} +func TestReplicationTaskInfo(t *testing.T) { + for _, item := range []*types.ReplicationTaskInfo{nil, {}, &testdata.ReplicationTaskInfo} { + assert.Equal(t, item, ToReplicationTaskInfo(FromReplicationTaskInfo(item))) + } +} +func TestReplicationToken(t *testing.T) { + for _, item := range []*types.ReplicationToken{nil, {}, &testdata.ReplicationToken} { + assert.Equal(t, item, ToReplicationToken(FromReplicationToken(item))) + } +} +func TestSyncActivityTaskAttributes(t *testing.T) { + for _, item := range []*types.SyncActivityTaskAttributes{nil, {}, &testdata.SyncActivityTaskAttributes} { + assert.Equal(t, item, ToSyncActivityTaskAttributes(FromSyncActivityTaskAttributes(item))) + } +} +func TestSyncShardStatus(t *testing.T) { + for _, item := range []*types.SyncShardStatus{nil, {}, &testdata.SyncShardStatus} { + assert.Equal(t, item, ToSyncShardStatus(FromSyncShardStatus(item))) + } +} +func TestSyncShardStatusTaskAttributes(t *testing.T) { + for _, item := range []*types.SyncShardStatusTaskAttributes{nil, {}, &testdata.SyncShardStatusTaskAttributes} { + assert.Equal(t, item, ToSyncShardStatusTaskAttributes(FromSyncShardStatusTaskAttributes(item))) + } +} +func TestReplicationTaskInfoArray(t *testing.T) { + for _, item := range [][]*types.ReplicationTaskInfo{nil, {}, testdata.ReplicationTaskInfoArray} { + assert.Equal(t, item, ToReplicationTaskInfoArray(FromReplicationTaskInfoArray(item))) + } +} +func TestReplicationTaskArray(t *testing.T) { + for _, item := range [][]*types.ReplicationTask{nil, {}, testdata.ReplicationTaskArray} { + assert.Equal(t, item, ToReplicationTaskArray(FromReplicationTaskArray(item))) + } +} +func TestReplicationTokenArray(t *testing.T) { + for _, item := range [][]*types.ReplicationToken{nil, {}, testdata.ReplicationTokenArray} { + assert.Equal(t, item, ToReplicationTokenArray(FromReplicationTokenArray(item))) + } +} +func TestReplicationMessagesMap(t *testing.T) { + for _, item := range []map[int32]*types.ReplicationMessages{nil, {}, testdata.ReplicationMessagesMap} { + assert.Equal(t, item, ToReplicationMessagesMap(FromReplicationMessagesMap(item))) + } +} +func TestReplicationTask(t *testing.T) { + for _, item := range []*types.ReplicationTask{ + nil, + {}, + &testdata.ReplicationTask_Domain, + &testdata.ReplicationTask_Failover, + &testdata.ReplicationTask_History, + &testdata.ReplicationTask_SyncActivity, + &testdata.ReplicationTask_SyncShard, + } { + assert.Equal(t, item, ToReplicationTask(FromReplicationTask(item))) + } +} +func TestFailoverMarkerTokenArray(t *testing.T) { + for _, item := range [][]*types.FailoverMarkerToken{nil, {}, testdata.FailoverMarkerTokenArray} { + assert.Equal(t, item, ToFailoverMarkerTokenArray(FromFailoverMarkerTokenArray(item))) + } +} +func TestVersionHistoryItemArray(t *testing.T) { + for _, item := range [][]*types.VersionHistoryItem{nil, {}, testdata.VersionHistoryItemArray} { + assert.Equal(t, item, ToVersionHistoryItemArray(FromVersionHistoryItemArray(item))) + } +} +func TestEventIDVersionPair(t *testing.T) { + assert.Nil(t, FromEventIDVersionPair(nil, nil)) + assert.Nil(t, ToEventID(nil)) + assert.Nil(t, ToEventVersion(nil)) + + pair := FromEventIDVersionPair(common.Int64Ptr(testdata.EventID1), common.Int64Ptr(testdata.Version1)) + assert.Equal(t, testdata.EventID1, *ToEventID(pair)) + assert.Equal(t, testdata.Version1, *ToEventVersion(pair)) +} + +/* +func TestHostInfo(t *testing.T) { + item := testdata.HostInfo + assert.Nil(t, ToHostInfo(nil)) + assert.Nil(t, FromHostInfo(nil)) + assert.Equal(t, item, *ToHostInfo(FromHostInfo(&item))) +} +func TestMembershipInfo(t *testing.T) { + item := testdata.MembershipInfo + assert.Nil(t, ToMembershipInfo(nil)) + assert.Nil(t, FromMembershipInfo(nil)) + assert.Equal(t, item, *ToMembershipInfo(FromMembershipInfo(&item))) +} +func TestDomainCacheInfo(t *testing.T) { + item := testdata.DomainCacheInfo + assert.Nil(t, ToDomainCacheInfo(nil)) + assert.Nil(t, FromDomainCacheInfo(nil)) + assert.Equal(t, item, *ToDomainCacheInfo(FromDomainCacheInfo(&item))) +} +func TestRingInfo(t *testing.T) { + item := testdata.RingInfo + assert.Nil(t, ToRingInfo(nil)) + assert.Nil(t, FromRingInfo(nil)) + assert.Equal(t, item, *ToRingInfo(FromRingInfo(&item))) +} +func TestTransientDecisionInfo(t *testing.T) { + item := testdata.TransientDecisionInfo + assert.Nil(t, ToTransientDecisionInfo(nil)) + assert.Nil(t, FromTransientDecisionInfo(nil)) + assert.Equal(t, item, *ToTransientDecisionInfo(FromTransientDecisionInfo(&item))) +} +func TestVersionHistories(t *testing.T) { + item := testdata.VersionHistories + assert.Nil(t, ToVersionHistories(nil)) + assert.Nil(t, FromVersionHistories(nil)) + assert.Equal(t, item, *ToVersionHistories(FromVersionHistories(&item))) +} +func TestVersionHistory(t *testing.T) { + item := testdata.VersionHistory + assert.Nil(t, ToVersionHistory(nil)) + assert.Nil(t, FromVersionHistory(nil)) + assert.Equal(t, item, *ToVersionHistory(FromVersionHistory(&item))) +} +func TestVersionHistoryItem(t *testing.T) { + item := testdata.VersionHistoryItem + assert.Nil(t, ToVersionHistoryItem(nil)) + assert.Nil(t, FromVersionHistoryItem(nil)) + assert.Equal(t, item, *ToVersionHistoryItem(FromVersionHistoryItem(&item))) +} +func TestHostInfoArray(t *testing.T) { + item := testdata.HostInfoArray + assert.Nil(t, ToHostInfoArray(nil)) + assert.Nil(t, FromHostInfoArray(nil)) + assert.Equal(t, item, ToHostInfoArray(FromHostInfoArray(item))) +} +func TestVersionHistoryArray(t *testing.T) { + item := testdata.VersionHistoryArray + assert.Nil(t, ToVersionHistoryArray(nil)) + assert.Nil(t, FromVersionHistoryArray(nil)) + assert.Equal(t, item, ToVersionHistoryArray(FromVersionHistoryArray(item))) +} +func TestRingInfoArray(t *testing.T) { + item := testdata.RingInfoArray + assert.Nil(t, ToRingInfoArray(nil)) + assert.Nil(t, FromRingInfoArray(nil)) + assert.Equal(t, item, ToRingInfoArray(FromRingInfoArray(item))) +} +func TestDomainTaskAttributes(t *testing.T) { + item := testdata.DomainTaskAttributes + assert.Nil(t, ToDomainTaskAttributes(nil)) + assert.Nil(t, FromDomainTaskAttributes(nil)) + assert.Equal(t, item, *ToDomainTaskAttributes(FromDomainTaskAttributes(&item))) +} +func TestFailoverMarkerAttributes(t *testing.T) { + item := testdata.FailoverMarkerAttributes + assert.Nil(t, ToFailoverMarkerAttributes(nil)) + assert.Nil(t, FromFailoverMarkerAttributes(nil)) + assert.Equal(t, item, *ToFailoverMarkerAttributes(FromFailoverMarkerAttributes(&item))) +} +func TestFailoverMarkerToken(t *testing.T) { + item := testdata.FailoverMarkerToken + assert.Nil(t, ToFailoverMarkerToken(nil)) + assert.Nil(t, FromFailoverMarkerToken(nil)) + assert.Equal(t, item, *ToFailoverMarkerToken(FromFailoverMarkerToken(&item))) +} +func TestHistoryTaskV2Attributes(t *testing.T) { + item := testdata.HistoryTaskV2Attributes + assert.Nil(t, ToHistoryTaskV2Attributes(nil)) + assert.Nil(t, FromHistoryTaskV2Attributes(nil)) + assert.Equal(t, item, *ToHistoryTaskV2Attributes(FromHistoryTaskV2Attributes(&item))) +} +func TestReplicationMessages(t *testing.T) { + item := testdata.ReplicationMessages + assert.Nil(t, ToReplicationMessages(nil)) + assert.Nil(t, FromReplicationMessages(nil)) + assert.Equal(t, item, *ToReplicationMessages(FromReplicationMessages(&item))) +} +func TestReplicationTaskInfo(t *testing.T) { + item := testdata.ReplicationTaskInfo + assert.Nil(t, ToReplicationTaskInfo(nil)) + assert.Nil(t, FromReplicationTaskInfo(nil)) + assert.Equal(t, item, *ToReplicationTaskInfo(FromReplicationTaskInfo(&item))) +} +func TestReplicationToken(t *testing.T) { + item := testdata.ReplicationToken + assert.Nil(t, ToReplicationToken(nil)) + assert.Nil(t, FromReplicationToken(nil)) + assert.Equal(t, item, *ToReplicationToken(FromReplicationToken(&item))) +} +func TestSyncActivityTaskAttributes(t *testing.T) { + item := testdata.SyncActivityTaskAttributes + assert.Nil(t, ToSyncActivityTaskAttributes(nil)) + assert.Nil(t, FromSyncActivityTaskAttributes(nil)) + assert.Equal(t, item, *ToSyncActivityTaskAttributes(FromSyncActivityTaskAttributes(&item))) +} +func TestSyncShardStatus(t *testing.T) { + item := testdata.SyncShardStatus + assert.Nil(t, ToSyncShardStatus(nil)) + assert.Nil(t, FromSyncShardStatus(nil)) + assert.Equal(t, item, *ToSyncShardStatus(FromSyncShardStatus(&item))) +} +func TestSyncShardStatusTaskAttributes(t *testing.T) { + item := testdata.SyncShardStatusTaskAttributes + assert.Nil(t, ToSyncShardStatusTaskAttributes(nil)) + assert.Nil(t, FromSyncShardStatusTaskAttributes(nil)) + assert.Equal(t, item, *ToSyncShardStatusTaskAttributes(FromSyncShardStatusTaskAttributes(&item))) +} +func TestReplicationTaskInfoArray(t *testing.T) { + item := testdata.ReplicationTaskInfoArray + assert.Nil(t, ToReplicationTaskInfoArray(nil)) + assert.Nil(t, FromReplicationTaskInfoArray(nil)) + assert.Equal(t, item, ToReplicationTaskInfoArray(FromReplicationTaskInfoArray(item))) +} +func TestReplicationTaskArray(t *testing.T) { + item := testdata.ReplicationTaskArray + assert.Nil(t, ToReplicationTaskArray(nil)) + assert.Nil(t, FromReplicationTaskArray(nil)) + assert.Equal(t, item, ToReplicationTaskArray(FromReplicationTaskArray(item))) +} +func TestReplicationTokenArray(t *testing.T) { + item := testdata.ReplicationTokenArray + assert.Nil(t, ToReplicationTokenArray(nil)) + assert.Nil(t, FromReplicationTokenArray(nil)) + assert.Equal(t, item, ToReplicationTokenArray(FromReplicationTokenArray(item))) +} +func TestReplicationMessagesMap(t *testing.T) { + item := testdata.ReplicationMessagesMap + assert.Nil(t, ToReplicationMessagesMap(nil)) + assert.Nil(t, FromReplicationMessagesMap(nil)) + assert.Equal(t, item, ToReplicationMessagesMap(FromReplicationMessagesMap(item))) +} +func TestReplicationTask(t *testing.T) { + items := []types.ReplicationTask{ + testdata.ReplicationTask_Domain, + testdata.ReplicationTask_Failover, + testdata.ReplicationTask_History, + testdata.ReplicationTask_SyncActivity, + testdata.ReplicationTask_SyncShard, + } + assert.Nil(t, ToReplicationTask(nil)) + assert.Nil(t, FromReplicationTask(nil)) + for _, item := range items { + assert.Equal(t, item, *ToReplicationTask(FromReplicationTask(&item))) + } +} +func TestFailoverMarkerTokenArray(t *testing.T) { + item := testdata.FailoverMarkerTokenArray + assert.Nil(t, ToFailoverMarkerTokenArray(nil)) + assert.Nil(t, FromFailoverMarkerTokenArray(nil)) + assert.Equal(t, item, ToFailoverMarkerTokenArray(FromFailoverMarkerTokenArray(item))) +} +func TestVersionHistoryItemArray(t *testing.T) { + item := testdata.VersionHistoryItemArray + assert.Nil(t, ToVersionHistoryItemArray(nil)) + assert.Nil(t, FromVersionHistoryItemArray(nil)) + assert.Equal(t, item, ToVersionHistoryItemArray(FromVersionHistoryItemArray(item))) +} +func TestEventIdVersionPair(t *testing.T) { + assert.Nil(t, FromEventIdVersionPair(nil, nil)) + assert.Nil(t, ToEventId(nil)) + assert.Nil(t, ToEventVersion(nil)) + + pair := FromEventIdVersionPair(common.Int64Ptr(testdata.EventID1), common.Int64Ptr(testdata.Version1)) + assert.Equal(t, testdata.EventID1, *ToEventId(pair)) + assert.Equal(t, testdata.Version1, *ToEventVersion(pair)) +} +*/ diff --git a/common/types/testdata/common.go b/common/types/testdata/common.go new file mode 100644 index 00000000000..54319480eb3 --- /dev/null +++ b/common/types/testdata/common.go @@ -0,0 +1,398 @@ +// 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 testdata + +import ( + "time" + + "github.com/uber/cadence/common" + "github.com/uber/cadence/common/types" +) + +const ( + WorkflowID = "WorkflowID" + RunID = "RunID" + RunID1 = "RunID1" + RunID2 = "RunID2" + RunID3 = "RunID3" + + ActivityID = "ActivityID" + RequestID = "RequestID" + TimerID = "TimerID" + + WorkflowTypeName = "WorkflowTypeName" + ActivityTypeName = "ActivityTypeName" + TaskListName = "TaskListName" + MarkerName = "MarkerName" + SignalName = "SignalName" + QueryType = "QueryType" + HostName = "HostName" + Identity = "Identity" + CronSchedule = "CronSchedule" + Checksum = "Checksum" + Reason = "Reason" + Cause = "Cause" + SecurityToken = "SecurityToken" + VisibilityQuery = "VisibilityQuery" + FeatureVersion = "FeatureVersion" + ClientImpl = "ClientImpl" + ClientLibraryVersion = "ClientLibraryVersion" + SupportedVersions = "SupportedVersions" + + Attempt = 2 + PageSize = 10 + HistoryLength = 20 + BacklogCountHint = 30 + AckLevel = 1001 + ReadLevel = 1002 + RatePerSecond = 3.14 + TaskID = 444 + ShardID = 12345 + MessageID1 = 50001 + MessageID2 = 50002 + EventStoreVersion = 333 + + EventID1 = int64(1) + EventID2 = int64(2) + EventID3 = int64(3) + EventID4 = int64(4) + + Version1 = int64(11) + Version2 = int64(22) + Version3 = int64(33) +) + +var ( + Timestamp = time.Now().Unix() + Timestamp1 = Timestamp + 1 + Timestamp2 = Timestamp + 2 + Timestamp3 = Timestamp + 3 + Timestamp4 = Timestamp + 4 + Timestamp5 = Timestamp + 5 +) + +var ( + Duration1 = int32(11) + Duration2 = int32(12) + Duration3 = int32(13) + Duration4 = int32(14) +) + +var ( + Token1 = []byte{1, 0} + Token2 = []byte{2, 0} + Token3 = []byte{3, 0} +) + +var ( + Payload1 = []byte{10, 0} + Payload2 = []byte{20, 0} + Payload3 = []byte{30, 0} +) + +var ( + ExecutionContext = []byte{110, 0} + Control = []byte{120, 0} + NextPageToken = []byte{130, 0} + TaskToken = []byte{140, 0} + BranchToken = []byte{150, 0} + QueryArgs = []byte{9, 9, 9} +) + +var ( + FailureReason = "FailureReason" + FailureDetails = []byte{190, 0} +) + +var ( + HealthStatus = types.HealthStatus{ + Ok: true, + Msg: "HealthStatusMessage", + } + WorkflowExecution = types.WorkflowExecution{ + WorkflowID: WorkflowID, + RunID: RunID, + } + WorkflowType = types.WorkflowType{ + Name: WorkflowTypeName, + } + ActivityType = types.ActivityType{ + Name: ActivityTypeName, + } + TaskList = types.TaskList{ + Name: TaskListName, + Kind: types.TaskListKindNormal.Ptr(), + } + RetryPolicy = types.RetryPolicy{ + InitialIntervalInSeconds: 1, + BackoffCoefficient: 1.1, + MaximumIntervalInSeconds: 2, + MaximumAttempts: 3, + NonRetriableErrorReasons: []string{"a", "b"}, + ExpirationIntervalInSeconds: 4, + } + Header = types.Header{ + Fields: map[string][]byte{ + "HeaderField1": {211, 0}, + "HeaderField2": {212, 0}, + }, + } + Memo = types.Memo{ + Fields: map[string][]byte{ + "MemoField1": {221, 0}, + "MemoField2": {222, 0}, + }, + } + SearchAttributes = types.SearchAttributes{ + IndexedFields: map[string][]byte{ + "IndexedField1": {231, 0}, + "IndexedField2": {232, 0}, + }, + } + PayloadMap = map[string][]byte{ + "Payload1": Payload1, + "Payload2": Payload2, + } + ResetPointInfo = types.ResetPointInfo{ + BinaryChecksum: Checksum, + RunID: RunID1, + FirstDecisionCompletedID: EventID1, + CreatedTimeNano: &Timestamp1, + ExpiringTimeNano: &Timestamp2, + Resettable: true, + } + ResetPointInfoArray = []*types.ResetPointInfo{ + &ResetPointInfo, + } + ResetPoints = types.ResetPoints{ + Points: ResetPointInfoArray, + } + DataBlob = types.DataBlob{ + EncodingType: &EncodingType, + Data: []byte{7, 7, 7}, + } + DataBlobArray = []*types.DataBlob{ + &DataBlob, + } + StickyExecutionAttributes = types.StickyExecutionAttributes{ + WorkerTaskList: &TaskList, + ScheduleToStartTimeoutSeconds: &Duration1, + } + ActivityLocalDispatchInfo = types.ActivityLocalDispatchInfo{ + ActivityID: ActivityID, + ScheduledTimestamp: &Timestamp1, + StartedTimestamp: &Timestamp2, + ScheduledTimestampOfThisAttempt: &Timestamp3, + TaskToken: TaskToken, + } + ActivityLocalDispatchInfoMap = map[string]*types.ActivityLocalDispatchInfo{ + ActivityID: &ActivityLocalDispatchInfo, + } + TaskListMetadata = types.TaskListMetadata{ + MaxTasksPerSecond: common.Float64Ptr(RatePerSecond), + } + WorkerVersionInfo = types.WorkerVersionInfo{ + Impl: ClientImpl, + FeatureVersion: FeatureVersion, + } + PollerInfo = types.PollerInfo{ + LastAccessTime: &Timestamp1, + Identity: Identity, + RatePerSecond: RatePerSecond, + } + PollerInfoArray = []*types.PollerInfo{ + &PollerInfo, + } + TaskListStatus = types.TaskListStatus{ + BacklogCountHint: BacklogCountHint, + ReadLevel: ReadLevel, + AckLevel: AckLevel, + RatePerSecond: RatePerSecond, + TaskIDBlock: &TaskIDBlock, + } + TaskIDBlock = types.TaskIDBlock{ + StartID: 551, + EndID: 559, + } + TaskListPartitionMetadata = types.TaskListPartitionMetadata{ + Key: "Key", + OwnerHostName: "HostName", + } + TaskListPartitionMetadataArray = []*types.TaskListPartitionMetadata{ + &TaskListPartitionMetadata, + } + SupportedClientVersions = types.SupportedClientVersions{ + GoSdk: "GoSDK", + JavaSdk: "JavaSDK", + } + IndexedValueTypeMap = map[string]types.IndexedValueType{ + "IndexedValueType1": IndexedValueType, + } + ParentExecutionInfo = types.ParentExecutionInfo{ + DomainUUID: DomainID, + Domain: DomainName, + Execution: &WorkflowExecution, + InitiatedID: EventID1, + } + ClusterInfo = types.ClusterInfo{ + SupportedClientVersions: &SupportedClientVersions, + } + MembershipInfo = types.MembershipInfo{ + CurrentHost: &HostInfo, + ReachableMembers: []string{HostName}, + Rings: RingInfoArray, + } + HostInfo = types.HostInfo{ + Identity: HostName, + } + HostInfoArray = []*types.HostInfo{ + &HostInfo, + } + RingInfo = types.RingInfo{ + Role: "Role", + MemberCount: 1, + Members: HostInfoArray, + } + RingInfoArray = []*types.RingInfo{ + &RingInfo, + } + DomainCacheInfo = types.DomainCacheInfo{ + NumOfItemsInCacheByID: int64(2000), + NumOfItemsInCacheByName: int64(3000), + } + VersionHistoryItem = types.VersionHistoryItem{ + EventID: EventID1, + Version: Version1, + } + VersionHistoryItemArray = []*types.VersionHistoryItem{ + &VersionHistoryItem, + } + VersionHistory = types.VersionHistory{ + BranchToken: BranchToken, + Items: VersionHistoryItemArray, + } + VersionHistoryArray = []*types.VersionHistory{ + &VersionHistory, + } + VersionHistories = types.VersionHistories{ + CurrentVersionHistoryIndex: 1, + Histories: VersionHistoryArray, + } + TransientDecisionInfo = types.TransientDecisionInfo{ + ScheduledEvent: &HistoryEvent_WorkflowExecutionStarted, + StartedEvent: &HistoryEvent_WorkflowExecutionStarted, + } + FailoverMarkerToken = types.FailoverMarkerToken{ + ShardIDs: []int32{ShardID}, + FailoverMarker: &FailoverMarkerAttributes, + } + FailoverMarkerTokenArray = []*types.FailoverMarkerToken{ + &FailoverMarkerToken, + } + WorkflowExecutionFilter = types.WorkflowExecutionFilter{ + WorkflowID: WorkflowID, + RunID: RunID, + } + WorkflowTypeFilter = types.WorkflowTypeFilter{ + Name: WorkflowTypeName, + } + StartTimeFilter = types.StartTimeFilter{ + EarliestTime: &Timestamp1, + LatestTime: &Timestamp2, + } + WorkflowExecutionInfo = types.WorkflowExecutionInfo{ + Execution: &WorkflowExecution, + Type: &WorkflowType, + StartTime: &Timestamp1, + CloseTime: &Timestamp2, + CloseStatus: &WorkflowExecutionCloseStatus, + HistoryLength: HistoryLength, + ParentDomainID: common.StringPtr(DomainID), + ParentDomain: common.StringPtr(DomainName), + ParentExecution: &WorkflowExecution, + ParentInitiatedID: common.Int64Ptr(EventID1), + ExecutionTime: &Timestamp3, + Memo: &Memo, + SearchAttributes: &SearchAttributes, + AutoResetPoints: &ResetPoints, + TaskList: TaskListName, + } + WorkflowExecutionInfoArray = []*types.WorkflowExecutionInfo{&WorkflowExecutionInfo} + + WorkflowQuery = types.WorkflowQuery{ + QueryType: QueryType, + QueryArgs: QueryArgs, + } + WorkflowQueryMap = map[string]*types.WorkflowQuery{ + "WorkflowQuery1": &WorkflowQuery, + } + WorkflowQueryResult = types.WorkflowQueryResult{ + ResultType: &QueryResultType, + Answer: Payload1, + ErrorMessage: ErrorMessage, + } + WorkflowQueryResultMap = map[string]*types.WorkflowQueryResult{ + "WorkflowQuery1": &WorkflowQueryResult, + } + QueryRejected = types.QueryRejected{ + CloseStatus: &WorkflowExecutionCloseStatus, + } + WorkflowExecutionConfiguration = types.WorkflowExecutionConfiguration{ + TaskList: &TaskList, + ExecutionStartToCloseTimeoutSeconds: &Duration1, + TaskStartToCloseTimeoutSeconds: &Duration2, + } + PendingActivityInfo = types.PendingActivityInfo{ + ActivityID: ActivityID, + ActivityType: &ActivityType, + State: &PendingActivityState, + HeartbeatDetails: Payload1, + LastHeartbeatTimestamp: &Timestamp1, + LastStartedTimestamp: &Timestamp2, + Attempt: Attempt, + MaximumAttempts: 3, + ScheduledTimestamp: &Timestamp3, + ExpirationTimestamp: &Timestamp4, + LastFailureReason: &FailureReason, + LastWorkerIdentity: Identity, + LastFailureDetails: FailureDetails, + } + PendingActivityInfoArray = []*types.PendingActivityInfo{ + &PendingActivityInfo, + } + PendingChildExecutionInfo = types.PendingChildExecutionInfo{ + WorkflowID: WorkflowID, + RunID: RunID, + WorkflowTypName: WorkflowTypeName, + InitiatedID: EventID1, + ParentClosePolicy: &ParentClosePolicy, + } + PendingChildExecutionInfoArray = []*types.PendingChildExecutionInfo{ + &PendingChildExecutionInfo, + } + PendingDecisionInfo = types.PendingDecisionInfo{ + State: &PendingDecisionState, + ScheduledTimestamp: &Timestamp1, + StartedTimestamp: &Timestamp2, + Attempt: Attempt, + OriginalScheduledTimestamp: &Timestamp3, + } +) diff --git a/common/types/testdata/decision.go b/common/types/testdata/decision.go new file mode 100644 index 00000000000..8f5312de860 --- /dev/null +++ b/common/types/testdata/decision.go @@ -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 testdata + +import ( + "github.com/uber/cadence/common" + "github.com/uber/cadence/common/types" +) + +var ( + DecisionArray = []*types.Decision{ + &Decision_CancelTimer, + &Decision_CancelWorkflowExecution, + &Decision_CompleteWorkflowExecution, + &Decision_ContinueAsNewWorkflowExecution, + &Decision_FailWorkflowExecution, + &Decision_RecordMarker, + &Decision_RequestCancelActivityTask, + &Decision_RequestCancelExternalWorkflowExecution, + &Decision_ScheduleActivityTask, + &Decision_SignalExternalWorkflowExecution, + &Decision_StartChildWorkflowExecution, + &Decision_StartTimer, + &Decision_UpsertWorkflowSearchAttributes, + } + + Decision_CancelTimer = types.Decision{ + DecisionType: types.DecisionTypeCancelTimer.Ptr(), + CancelTimerDecisionAttributes: &CancelTimerDecisionAttributes, + } + Decision_CancelWorkflowExecution = types.Decision{ + DecisionType: types.DecisionTypeCancelWorkflowExecution.Ptr(), + CancelWorkflowExecutionDecisionAttributes: &CancelWorkflowExecutionDecisionAttributes, + } + Decision_CompleteWorkflowExecution = types.Decision{ + DecisionType: types.DecisionTypeCompleteWorkflowExecution.Ptr(), + CompleteWorkflowExecutionDecisionAttributes: &CompleteWorkflowExecutionDecisionAttributes, + } + Decision_ContinueAsNewWorkflowExecution = types.Decision{ + DecisionType: types.DecisionTypeContinueAsNewWorkflowExecution.Ptr(), + ContinueAsNewWorkflowExecutionDecisionAttributes: &ContinueAsNewWorkflowExecutionDecisionAttributes, + } + Decision_FailWorkflowExecution = types.Decision{ + DecisionType: types.DecisionTypeFailWorkflowExecution.Ptr(), + FailWorkflowExecutionDecisionAttributes: &FailWorkflowExecutionDecisionAttributes, + } + Decision_RecordMarker = types.Decision{ + DecisionType: types.DecisionTypeRecordMarker.Ptr(), + RecordMarkerDecisionAttributes: &RecordMarkerDecisionAttributes, + } + Decision_RequestCancelActivityTask = types.Decision{ + DecisionType: types.DecisionTypeRequestCancelActivityTask.Ptr(), + RequestCancelActivityTaskDecisionAttributes: &RequestCancelActivityTaskDecisionAttributes, + } + Decision_RequestCancelExternalWorkflowExecution = types.Decision{ + DecisionType: types.DecisionTypeRequestCancelExternalWorkflowExecution.Ptr(), + RequestCancelExternalWorkflowExecutionDecisionAttributes: &RequestCancelExternalWorkflowExecutionDecisionAttributes, + } + Decision_ScheduleActivityTask = types.Decision{ + DecisionType: types.DecisionTypeScheduleActivityTask.Ptr(), + ScheduleActivityTaskDecisionAttributes: &ScheduleActivityTaskDecisionAttributes, + } + Decision_SignalExternalWorkflowExecution = types.Decision{ + DecisionType: types.DecisionTypeSignalExternalWorkflowExecution.Ptr(), + SignalExternalWorkflowExecutionDecisionAttributes: &SignalExternalWorkflowExecutionDecisionAttributes, + } + Decision_StartChildWorkflowExecution = types.Decision{ + DecisionType: types.DecisionTypeStartChildWorkflowExecution.Ptr(), + StartChildWorkflowExecutionDecisionAttributes: &StartChildWorkflowExecutionDecisionAttributes, + } + Decision_StartTimer = types.Decision{ + DecisionType: types.DecisionTypeStartTimer.Ptr(), + StartTimerDecisionAttributes: &StartTimerDecisionAttributes, + } + Decision_UpsertWorkflowSearchAttributes = types.Decision{ + DecisionType: types.DecisionTypeUpsertWorkflowSearchAttributes.Ptr(), + UpsertWorkflowSearchAttributesDecisionAttributes: &UpsertWorkflowSearchAttributesDecisionAttributes, + } + + CancelTimerDecisionAttributes = types.CancelTimerDecisionAttributes{ + TimerID: TimerID, + } + CancelWorkflowExecutionDecisionAttributes = types.CancelWorkflowExecutionDecisionAttributes{ + Details: Payload1, + } + CompleteWorkflowExecutionDecisionAttributes = types.CompleteWorkflowExecutionDecisionAttributes{ + Result: Payload1, + } + ContinueAsNewWorkflowExecutionDecisionAttributes = types.ContinueAsNewWorkflowExecutionDecisionAttributes{ + WorkflowType: &WorkflowType, + TaskList: &TaskList, + Input: Payload1, + ExecutionStartToCloseTimeoutSeconds: &Duration1, + TaskStartToCloseTimeoutSeconds: &Duration2, + BackoffStartIntervalInSeconds: &Duration3, + RetryPolicy: &RetryPolicy, + Initiator: &ContinueAsNewInitiator, + FailureReason: &FailureReason, + FailureDetails: FailureDetails, + LastCompletionResult: Payload2, + CronSchedule: CronSchedule, + Header: &Header, + Memo: &Memo, + SearchAttributes: &SearchAttributes, + } + FailWorkflowExecutionDecisionAttributes = types.FailWorkflowExecutionDecisionAttributes{ + Reason: &FailureReason, + Details: FailureDetails, + } + RecordMarkerDecisionAttributes = types.RecordMarkerDecisionAttributes{ + MarkerName: MarkerName, + Details: Payload1, + Header: &Header, + } + RequestCancelActivityTaskDecisionAttributes = types.RequestCancelActivityTaskDecisionAttributes{ + ActivityID: ActivityID, + } + RequestCancelExternalWorkflowExecutionDecisionAttributes = types.RequestCancelExternalWorkflowExecutionDecisionAttributes{ + Domain: DomainName, + WorkflowID: WorkflowID, + RunID: RunID, + Control: Control, + ChildWorkflowOnly: true, + } + ScheduleActivityTaskDecisionAttributes = types.ScheduleActivityTaskDecisionAttributes{ + ActivityID: ActivityID, + ActivityType: &ActivityType, + Domain: DomainName, + TaskList: &TaskList, + Input: Payload1, + ScheduleToCloseTimeoutSeconds: &Duration1, + ScheduleToStartTimeoutSeconds: &Duration2, + StartToCloseTimeoutSeconds: &Duration3, + HeartbeatTimeoutSeconds: &Duration4, + RetryPolicy: &RetryPolicy, + Header: &Header, + RequestLocalDispatch: true, + } + SignalExternalWorkflowExecutionDecisionAttributes = types.SignalExternalWorkflowExecutionDecisionAttributes{ + Domain: DomainName, + Execution: &WorkflowExecution, + SignalName: SignalName, + Input: Payload1, + Control: Control, + ChildWorkflowOnly: true, + } + StartChildWorkflowExecutionDecisionAttributes = types.StartChildWorkflowExecutionDecisionAttributes{ + Domain: DomainName, + WorkflowID: WorkflowID, + WorkflowType: &WorkflowType, + TaskList: &TaskList, + Input: Payload1, + ExecutionStartToCloseTimeoutSeconds: &Duration1, + TaskStartToCloseTimeoutSeconds: &Duration2, + ParentClosePolicy: &ParentClosePolicy, + Control: Control, + WorkflowIDReusePolicy: &WorkflowIDReusePolicy, + RetryPolicy: &RetryPolicy, + CronSchedule: CronSchedule, + Header: &Header, + Memo: &Memo, + SearchAttributes: &SearchAttributes, + } + StartTimerDecisionAttributes = types.StartTimerDecisionAttributes{ + TimerID: TimerID, + StartToFireTimeoutSeconds: common.Int64Ptr(int64(Duration1)), + } + UpsertWorkflowSearchAttributesDecisionAttributes = types.UpsertWorkflowSearchAttributesDecisionAttributes{ + SearchAttributes: &SearchAttributes, + } +) diff --git a/common/types/testdata/domain.go b/common/types/testdata/domain.go new file mode 100644 index 00000000000..3ea227557fa --- /dev/null +++ b/common/types/testdata/domain.go @@ -0,0 +1,92 @@ +// 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 testdata + +import ( + "github.com/uber/cadence/common/types" +) + +const ( + DomainID = "DomainID" + DomainName = "DomainName" + DomainDescription = "DomainDescription" + DomainOwnerEmail = "DomainOwnerEmail" + DomainDataKey = "DomainDataKey" + DomainDataValue = "DomainDataValue" + DomainRetention = 3 + DomainEmitMetric = true + + ClusterName1 = "ClusterName1" + ClusterName2 = "ClusterName2" + + BadBinaryReason = "BadBinaryReason" + BadBinaryOperator = "BadBinaryOperator" + + HistoryArchivalURI = "HistoryArchivalURI" + VisibilityArchivalURI = "VisibilityArchivalURI" + + DeleteBadBinary = "DeleteBadBinary" + + FailoverVersion1 = 301 + FailoverVersion2 = 302 +) + +var ( + BadBinaryInfo = types.BadBinaryInfo{ + Reason: BadBinaryReason, + Operator: BadBinaryOperator, + CreatedTimeNano: &Timestamp1, + } + BadBinaryInfoMap = map[string]*types.BadBinaryInfo{ + "BadBinary1": &BadBinaryInfo, + } + BadBinaries = types.BadBinaries{ + Binaries: BadBinaryInfoMap, + } + DomainData = map[string]string{DomainDataKey: DomainDataValue} + DomainInfo = types.DomainInfo{ + Name: DomainName, + Status: &DomainStatus, + Description: DomainDescription, + OwnerEmail: DomainOwnerEmail, + Data: DomainData, + UUID: DomainID, + } + DomainConfiguration = types.DomainConfiguration{ + WorkflowExecutionRetentionPeriodInDays: DomainRetention, + EmitMetric: DomainEmitMetric, + BadBinaries: &BadBinaries, + HistoryArchivalStatus: &ArchivalStatus, + HistoryArchivalURI: HistoryArchivalURI, + VisibilityArchivalStatus: &ArchivalStatus, + VisibilityArchivalURI: VisibilityArchivalURI, + } + DomainReplicationConfiguration = types.DomainReplicationConfiguration{ + ActiveClusterName: ClusterName1, + Clusters: ClusterReplicationConfigurationArray, + } + ClusterReplicationConfiguration = types.ClusterReplicationConfiguration{ + ClusterName: ClusterName1, + } + ClusterReplicationConfigurationArray = []*types.ClusterReplicationConfiguration{ + &ClusterReplicationConfiguration, + } +) diff --git a/common/types/testdata/enum.go b/common/types/testdata/enum.go new file mode 100644 index 00000000000..607149054fc --- /dev/null +++ b/common/types/testdata/enum.go @@ -0,0 +1,51 @@ +// 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 testdata + +import "github.com/uber/cadence/common/types" + +var ( + ArchivalStatus = types.ArchivalStatusEnabled + CancelExternalWorkflowExecutionFailedCause = types.CancelExternalWorkflowExecutionFailedCauseUnknownExternalWorkflowExecution + ChildWorkflowExecutionFailedCause = types.ChildWorkflowExecutionFailedCauseWorkflowAlreadyRunning + ContinueAsNewInitiator = types.ContinueAsNewInitiatorRetryPolicy + DecisionTaskFailedCause = types.DecisionTaskFailedCauseBadCancelWorkflowExecutionAttributes + DecisionTaskTimedOutCause = types.DecisionTaskTimedOutCauseReset + DecisionType = types.DecisionTypeCancelTimer + DomainStatus = types.DomainStatusRegistered + EncodingType = types.EncodingTypeJSON + EventType = types.EventTypeWorkflowExecutionStarted + HistoryEventFilterType = types.HistoryEventFilterTypeCloseEvent + IndexedValueType = types.IndexedValueTypeInt + ParentClosePolicy = types.ParentClosePolicyTerminate + PendingActivityState = types.PendingActivityStateCancelRequested + PendingDecisionState = types.PendingDecisionStateStarted + QueryConsistencyLevel = types.QueryConsistencyLevelStrong + QueryRejectCondition = types.QueryRejectConditionNotCompletedCleanly + QueryResultType = types.QueryResultTypeFailed + QueryTaskCompletedType = types.QueryTaskCompletedTypeFailed + SignalExternalWorkflowExecutionFailedCause = types.SignalExternalWorkflowExecutionFailedCauseUnknownExternalWorkflowExecution + TaskListKind = types.TaskListKindSticky + TaskListType = types.TaskListTypeActivity + TimeoutType = types.TimeoutTypeScheduleToStart + WorkflowExecutionCloseStatus = types.WorkflowExecutionCloseStatusContinuedAsNew + WorkflowIDReusePolicy = types.WorkflowIDReusePolicyTerminateIfRunning +) diff --git a/common/types/testdata/error.go b/common/types/testdata/error.go new file mode 100644 index 00000000000..72386af4829 --- /dev/null +++ b/common/types/testdata/error.go @@ -0,0 +1,105 @@ +// 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 testdata + +import ( + "github.com/uber/cadence/common" + "github.com/uber/cadence/common/types" +) + +const ( + ErrorMessage = "ErrorMessage" +) + +var ( + AccessDeniedError = types.AccessDeniedError{ + Message: ErrorMessage, + } + BadRequestError = types.BadRequestError{ + Message: ErrorMessage, + } + CancellationAlreadyRequestedError = types.CancellationAlreadyRequestedError{ + Message: ErrorMessage, + } + ClientVersionNotSupportedError = types.ClientVersionNotSupportedError{ + FeatureVersion: FeatureVersion, + ClientImpl: ClientImpl, + SupportedVersions: SupportedVersions, + } + CurrentBranchChangedError = types.CurrentBranchChangedError{ + Message: ErrorMessage, + CurrentBranchToken: BranchToken, + } + DomainAlreadyExistsError = types.DomainAlreadyExistsError{ + Message: ErrorMessage, + } + DomainNotActiveError = types.DomainNotActiveError{ + Message: ErrorMessage, + DomainName: DomainName, + CurrentCluster: ClusterName1, + ActiveCluster: ClusterName2, + } + EntityNotExistsError = types.EntityNotExistsError{ + Message: ErrorMessage, + CurrentCluster: ClusterName1, + ActiveCluster: ClusterName2, + } + EventAlreadyStartedError = types.EventAlreadyStartedError{ + Message: ErrorMessage, + } + InternalDataInconsistencyError = types.InternalDataInconsistencyError{ + Message: ErrorMessage, + } + InternalServiceError = types.InternalServiceError{ + Message: ErrorMessage, + } + LimitExceededError = types.LimitExceededError{ + Message: ErrorMessage, + } + QueryFailedError = types.QueryFailedError{ + Message: ErrorMessage, + } + RemoteSyncMatchedError = types.RemoteSyncMatchedError{ + Message: ErrorMessage, + } + RetryTaskV2Error = types.RetryTaskV2Error{ + Message: ErrorMessage, + DomainID: DomainID, + WorkflowID: WorkflowID, + RunID: RunID, + StartEventID: common.Int64Ptr(EventID1), + StartEventVersion: common.Int64Ptr(Version1), + EndEventID: common.Int64Ptr(EventID2), + EndEventVersion: common.Int64Ptr(Version2), + } + ServiceBusyError = types.ServiceBusyError{ + Message: ErrorMessage, + } + ShardOwnershipLostError = types.ShardOwnershipLostError{ + Message: ErrorMessage, + Owner: HostName, + } + WorkflowExecutionAlreadyStartedError = types.WorkflowExecutionAlreadyStartedError{ + Message: ErrorMessage, + StartRequestID: RequestID, + RunID: RunID, + } +) diff --git a/common/types/testdata/history.go b/common/types/testdata/history.go new file mode 100644 index 00000000000..225fdda21c4 --- /dev/null +++ b/common/types/testdata/history.go @@ -0,0 +1,581 @@ +// 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 testdata + +import ( + "github.com/uber/cadence/common" + "github.com/uber/cadence/common/types" +) + +var ( + History = types.History{ + Events: HistoryEventArray, + } + HistoryEventArray = []*types.HistoryEvent{ + &HistoryEvent_WorkflowExecutionStarted, + &HistoryEvent_WorkflowExecutionStarted, + &HistoryEvent_WorkflowExecutionCompleted, + &HistoryEvent_WorkflowExecutionFailed, + &HistoryEvent_WorkflowExecutionTimedOut, + &HistoryEvent_DecisionTaskScheduled, + &HistoryEvent_DecisionTaskStarted, + &HistoryEvent_DecisionTaskCompleted, + &HistoryEvent_DecisionTaskTimedOut, + &HistoryEvent_DecisionTaskFailed, + &HistoryEvent_ActivityTaskScheduled, + &HistoryEvent_ActivityTaskStarted, + &HistoryEvent_ActivityTaskCompleted, + &HistoryEvent_ActivityTaskFailed, + &HistoryEvent_ActivityTaskTimedOut, + &HistoryEvent_ActivityTaskCancelRequested, + &HistoryEvent_RequestCancelActivityTaskFailed, + &HistoryEvent_ActivityTaskCanceled, + &HistoryEvent_TimerStarted, + &HistoryEvent_TimerFired, + &HistoryEvent_CancelTimerFailed, + &HistoryEvent_TimerCanceled, + &HistoryEvent_WorkflowExecutionCancelRequested, + &HistoryEvent_WorkflowExecutionCanceled, + &HistoryEvent_RequestCancelExternalWorkflowExecutionInitiated, + &HistoryEvent_RequestCancelExternalWorkflowExecutionFailed, + &HistoryEvent_ExternalWorkflowExecutionCancelRequested, + &HistoryEvent_MarkerRecorded, + &HistoryEvent_WorkflowExecutionSignaled, + &HistoryEvent_WorkflowExecutionTerminated, + &HistoryEvent_WorkflowExecutionContinuedAsNew, + &HistoryEvent_StartChildWorkflowExecutionInitiated, + &HistoryEvent_StartChildWorkflowExecutionFailed, + &HistoryEvent_ChildWorkflowExecutionStarted, + &HistoryEvent_ChildWorkflowExecutionCompleted, + &HistoryEvent_ChildWorkflowExecutionFailed, + &HistoryEvent_ChildWorkflowExecutionCanceled, + &HistoryEvent_ChildWorkflowExecutionTimedOut, + &HistoryEvent_ChildWorkflowExecutionTerminated, + &HistoryEvent_SignalExternalWorkflowExecutionInitiated, + &HistoryEvent_SignalExternalWorkflowExecutionFailed, + &HistoryEvent_ExternalWorkflowExecutionSignaled, + &HistoryEvent_UpsertWorkflowSearchAttributes, + } + + HistoryEvent_WorkflowExecutionStarted = generateEvent(func(e *types.HistoryEvent) { + e.EventType = types.EventTypeWorkflowExecutionStarted.Ptr() + e.WorkflowExecutionStartedEventAttributes = &WorkflowExecutionStartedEventAttributes + }) + HistoryEvent_WorkflowExecutionCompleted = generateEvent(func(e *types.HistoryEvent) { + e.EventType = types.EventTypeWorkflowExecutionCompleted.Ptr() + e.WorkflowExecutionCompletedEventAttributes = &WorkflowExecutionCompletedEventAttributes + }) + HistoryEvent_WorkflowExecutionFailed = generateEvent(func(e *types.HistoryEvent) { + e.EventType = types.EventTypeWorkflowExecutionFailed.Ptr() + e.WorkflowExecutionFailedEventAttributes = &WorkflowExecutionFailedEventAttributes + }) + HistoryEvent_WorkflowExecutionTimedOut = generateEvent(func(e *types.HistoryEvent) { + e.EventType = types.EventTypeWorkflowExecutionTimedOut.Ptr() + e.WorkflowExecutionTimedOutEventAttributes = &WorkflowExecutionTimedOutEventAttributes + }) + HistoryEvent_DecisionTaskScheduled = generateEvent(func(e *types.HistoryEvent) { + e.EventType = types.EventTypeDecisionTaskScheduled.Ptr() + e.DecisionTaskScheduledEventAttributes = &DecisionTaskScheduledEventAttributes + }) + HistoryEvent_DecisionTaskStarted = generateEvent(func(e *types.HistoryEvent) { + e.EventType = types.EventTypeDecisionTaskStarted.Ptr() + e.DecisionTaskStartedEventAttributes = &DecisionTaskStartedEventAttributes + }) + HistoryEvent_DecisionTaskCompleted = generateEvent(func(e *types.HistoryEvent) { + e.EventType = types.EventTypeDecisionTaskCompleted.Ptr() + e.DecisionTaskCompletedEventAttributes = &DecisionTaskCompletedEventAttributes + }) + HistoryEvent_DecisionTaskTimedOut = generateEvent(func(e *types.HistoryEvent) { + e.EventType = types.EventTypeDecisionTaskTimedOut.Ptr() + e.DecisionTaskTimedOutEventAttributes = &DecisionTaskTimedOutEventAttributes + }) + HistoryEvent_DecisionTaskFailed = generateEvent(func(e *types.HistoryEvent) { + e.EventType = types.EventTypeDecisionTaskFailed.Ptr() + e.DecisionTaskFailedEventAttributes = &DecisionTaskFailedEventAttributes + }) + HistoryEvent_ActivityTaskScheduled = generateEvent(func(e *types.HistoryEvent) { + e.EventType = types.EventTypeActivityTaskScheduled.Ptr() + e.ActivityTaskScheduledEventAttributes = &ActivityTaskScheduledEventAttributes + }) + HistoryEvent_ActivityTaskStarted = generateEvent(func(e *types.HistoryEvent) { + e.EventType = types.EventTypeActivityTaskStarted.Ptr() + e.ActivityTaskStartedEventAttributes = &ActivityTaskStartedEventAttributes + }) + HistoryEvent_ActivityTaskCompleted = generateEvent(func(e *types.HistoryEvent) { + e.EventType = types.EventTypeActivityTaskCompleted.Ptr() + e.ActivityTaskCompletedEventAttributes = &ActivityTaskCompletedEventAttributes + }) + HistoryEvent_ActivityTaskFailed = generateEvent(func(e *types.HistoryEvent) { + e.EventType = types.EventTypeActivityTaskFailed.Ptr() + e.ActivityTaskFailedEventAttributes = &ActivityTaskFailedEventAttributes + }) + HistoryEvent_ActivityTaskTimedOut = generateEvent(func(e *types.HistoryEvent) { + e.EventType = types.EventTypeActivityTaskTimedOut.Ptr() + e.ActivityTaskTimedOutEventAttributes = &ActivityTaskTimedOutEventAttributes + }) + HistoryEvent_ActivityTaskCancelRequested = generateEvent(func(e *types.HistoryEvent) { + e.EventType = types.EventTypeActivityTaskCancelRequested.Ptr() + e.ActivityTaskCancelRequestedEventAttributes = &ActivityTaskCancelRequestedEventAttributes + }) + HistoryEvent_RequestCancelActivityTaskFailed = generateEvent(func(e *types.HistoryEvent) { + e.EventType = types.EventTypeRequestCancelActivityTaskFailed.Ptr() + e.RequestCancelActivityTaskFailedEventAttributes = &RequestCancelActivityTaskFailedEventAttributes + }) + HistoryEvent_ActivityTaskCanceled = generateEvent(func(e *types.HistoryEvent) { + e.EventType = types.EventTypeActivityTaskCanceled.Ptr() + e.ActivityTaskCanceledEventAttributes = &ActivityTaskCanceledEventAttributes + }) + HistoryEvent_TimerStarted = generateEvent(func(e *types.HistoryEvent) { + e.EventType = types.EventTypeTimerStarted.Ptr() + e.TimerStartedEventAttributes = &TimerStartedEventAttributes + }) + HistoryEvent_TimerFired = generateEvent(func(e *types.HistoryEvent) { + e.EventType = types.EventTypeTimerFired.Ptr() + e.TimerFiredEventAttributes = &TimerFiredEventAttributes + }) + HistoryEvent_CancelTimerFailed = generateEvent(func(e *types.HistoryEvent) { + e.EventType = types.EventTypeCancelTimerFailed.Ptr() + e.CancelTimerFailedEventAttributes = &CancelTimerFailedEventAttributes + }) + HistoryEvent_TimerCanceled = generateEvent(func(e *types.HistoryEvent) { + e.EventType = types.EventTypeTimerCanceled.Ptr() + e.TimerCanceledEventAttributes = &TimerCanceledEventAttributes + }) + HistoryEvent_WorkflowExecutionCancelRequested = generateEvent(func(e *types.HistoryEvent) { + e.EventType = types.EventTypeWorkflowExecutionCancelRequested.Ptr() + e.WorkflowExecutionCancelRequestedEventAttributes = &WorkflowExecutionCancelRequestedEventAttributes + }) + HistoryEvent_WorkflowExecutionCanceled = generateEvent(func(e *types.HistoryEvent) { + e.EventType = types.EventTypeWorkflowExecutionCanceled.Ptr() + e.WorkflowExecutionCanceledEventAttributes = &WorkflowExecutionCanceledEventAttributes + }) + HistoryEvent_RequestCancelExternalWorkflowExecutionInitiated = generateEvent(func(e *types.HistoryEvent) { + e.EventType = types.EventTypeRequestCancelExternalWorkflowExecutionInitiated.Ptr() + e.RequestCancelExternalWorkflowExecutionInitiatedEventAttributes = &RequestCancelExternalWorkflowExecutionInitiatedEventAttributes + }) + HistoryEvent_RequestCancelExternalWorkflowExecutionFailed = generateEvent(func(e *types.HistoryEvent) { + e.EventType = types.EventTypeRequestCancelExternalWorkflowExecutionFailed.Ptr() + e.RequestCancelExternalWorkflowExecutionFailedEventAttributes = &RequestCancelExternalWorkflowExecutionFailedEventAttributes + }) + HistoryEvent_ExternalWorkflowExecutionCancelRequested = generateEvent(func(e *types.HistoryEvent) { + e.EventType = types.EventTypeExternalWorkflowExecutionCancelRequested.Ptr() + e.ExternalWorkflowExecutionCancelRequestedEventAttributes = &ExternalWorkflowExecutionCancelRequestedEventAttributes + }) + HistoryEvent_MarkerRecorded = generateEvent(func(e *types.HistoryEvent) { + e.EventType = types.EventTypeMarkerRecorded.Ptr() + e.MarkerRecordedEventAttributes = &MarkerRecordedEventAttributes + }) + HistoryEvent_WorkflowExecutionSignaled = generateEvent(func(e *types.HistoryEvent) { + e.EventType = types.EventTypeWorkflowExecutionSignaled.Ptr() + e.WorkflowExecutionSignaledEventAttributes = &WorkflowExecutionSignaledEventAttributes + }) + HistoryEvent_WorkflowExecutionTerminated = generateEvent(func(e *types.HistoryEvent) { + e.EventType = types.EventTypeWorkflowExecutionTerminated.Ptr() + e.WorkflowExecutionTerminatedEventAttributes = &WorkflowExecutionTerminatedEventAttributes + }) + HistoryEvent_WorkflowExecutionContinuedAsNew = generateEvent(func(e *types.HistoryEvent) { + e.EventType = types.EventTypeWorkflowExecutionContinuedAsNew.Ptr() + e.WorkflowExecutionContinuedAsNewEventAttributes = &WorkflowExecutionContinuedAsNewEventAttributes + }) + HistoryEvent_StartChildWorkflowExecutionInitiated = generateEvent(func(e *types.HistoryEvent) { + e.EventType = types.EventTypeStartChildWorkflowExecutionInitiated.Ptr() + e.StartChildWorkflowExecutionInitiatedEventAttributes = &StartChildWorkflowExecutionInitiatedEventAttributes + }) + HistoryEvent_StartChildWorkflowExecutionFailed = generateEvent(func(e *types.HistoryEvent) { + e.EventType = types.EventTypeStartChildWorkflowExecutionFailed.Ptr() + e.StartChildWorkflowExecutionFailedEventAttributes = &StartChildWorkflowExecutionFailedEventAttributes + }) + HistoryEvent_ChildWorkflowExecutionStarted = generateEvent(func(e *types.HistoryEvent) { + e.EventType = types.EventTypeChildWorkflowExecutionStarted.Ptr() + e.ChildWorkflowExecutionStartedEventAttributes = &ChildWorkflowExecutionStartedEventAttributes + }) + HistoryEvent_ChildWorkflowExecutionCompleted = generateEvent(func(e *types.HistoryEvent) { + e.EventType = types.EventTypeChildWorkflowExecutionCompleted.Ptr() + e.ChildWorkflowExecutionCompletedEventAttributes = &ChildWorkflowExecutionCompletedEventAttributes + }) + HistoryEvent_ChildWorkflowExecutionFailed = generateEvent(func(e *types.HistoryEvent) { + e.EventType = types.EventTypeChildWorkflowExecutionFailed.Ptr() + e.ChildWorkflowExecutionFailedEventAttributes = &ChildWorkflowExecutionFailedEventAttributes + }) + HistoryEvent_ChildWorkflowExecutionCanceled = generateEvent(func(e *types.HistoryEvent) { + e.EventType = types.EventTypeChildWorkflowExecutionCanceled.Ptr() + e.ChildWorkflowExecutionCanceledEventAttributes = &ChildWorkflowExecutionCanceledEventAttributes + }) + HistoryEvent_ChildWorkflowExecutionTimedOut = generateEvent(func(e *types.HistoryEvent) { + e.EventType = types.EventTypeChildWorkflowExecutionTimedOut.Ptr() + e.ChildWorkflowExecutionTimedOutEventAttributes = &ChildWorkflowExecutionTimedOutEventAttributes + }) + HistoryEvent_ChildWorkflowExecutionTerminated = generateEvent(func(e *types.HistoryEvent) { + e.EventType = types.EventTypeChildWorkflowExecutionTerminated.Ptr() + e.ChildWorkflowExecutionTerminatedEventAttributes = &ChildWorkflowExecutionTerminatedEventAttributes + }) + HistoryEvent_SignalExternalWorkflowExecutionInitiated = generateEvent(func(e *types.HistoryEvent) { + e.EventType = types.EventTypeSignalExternalWorkflowExecutionInitiated.Ptr() + e.SignalExternalWorkflowExecutionInitiatedEventAttributes = &SignalExternalWorkflowExecutionInitiatedEventAttributes + }) + HistoryEvent_SignalExternalWorkflowExecutionFailed = generateEvent(func(e *types.HistoryEvent) { + e.EventType = types.EventTypeSignalExternalWorkflowExecutionFailed.Ptr() + e.SignalExternalWorkflowExecutionFailedEventAttributes = &SignalExternalWorkflowExecutionFailedEventAttributes + }) + HistoryEvent_ExternalWorkflowExecutionSignaled = generateEvent(func(e *types.HistoryEvent) { + e.EventType = types.EventTypeExternalWorkflowExecutionSignaled.Ptr() + e.ExternalWorkflowExecutionSignaledEventAttributes = &ExternalWorkflowExecutionSignaledEventAttributes + }) + HistoryEvent_UpsertWorkflowSearchAttributes = generateEvent(func(e *types.HistoryEvent) { + e.EventType = types.EventTypeUpsertWorkflowSearchAttributes.Ptr() + e.UpsertWorkflowSearchAttributesEventAttributes = &UpsertWorkflowSearchAttributesEventAttributes + }) + + WorkflowExecutionStartedEventAttributes = types.WorkflowExecutionStartedEventAttributes{ + WorkflowType: &WorkflowType, + ParentWorkflowDomainID: common.StringPtr(DomainID), + ParentWorkflowDomain: common.StringPtr(DomainName), + ParentWorkflowExecution: &WorkflowExecution, + ParentInitiatedEventID: common.Int64Ptr(EventID1), + TaskList: &TaskList, + Input: Payload1, + ExecutionStartToCloseTimeoutSeconds: &Duration1, + TaskStartToCloseTimeoutSeconds: &Duration2, + ContinuedExecutionRunID: RunID1, + Initiator: &ContinueAsNewInitiator, + ContinuedFailureReason: &FailureReason, + ContinuedFailureDetails: FailureDetails, + LastCompletionResult: Payload2, + OriginalExecutionRunID: RunID2, + Identity: Identity, + FirstExecutionRunID: RunID3, + RetryPolicy: &RetryPolicy, + Attempt: Attempt, + ExpirationTimestamp: &Timestamp1, + CronSchedule: CronSchedule, + FirstDecisionTaskBackoffSeconds: &Duration3, + Memo: &Memo, + SearchAttributes: &SearchAttributes, + PrevAutoResetPoints: &ResetPoints, + Header: &Header, + } + WorkflowExecutionCompletedEventAttributes = types.WorkflowExecutionCompletedEventAttributes{ + Result: Payload1, + DecisionTaskCompletedEventID: EventID1, + } + WorkflowExecutionFailedEventAttributes = types.WorkflowExecutionFailedEventAttributes{ + Reason: &FailureReason, + Details: FailureDetails, + DecisionTaskCompletedEventID: EventID1, + } + WorkflowExecutionTimedOutEventAttributes = types.WorkflowExecutionTimedOutEventAttributes{ + TimeoutType: &TimeoutType, + } + DecisionTaskScheduledEventAttributes = types.DecisionTaskScheduledEventAttributes{ + TaskList: &TaskList, + StartToCloseTimeoutSeconds: &Duration1, + Attempt: Attempt, + } + DecisionTaskStartedEventAttributes = types.DecisionTaskStartedEventAttributes{ + ScheduledEventID: EventID1, + Identity: Identity, + RequestID: RequestID, + } + DecisionTaskCompletedEventAttributes = types.DecisionTaskCompletedEventAttributes{ + ExecutionContext: ExecutionContext, + ScheduledEventID: EventID1, + StartedEventID: EventID2, + Identity: Identity, + BinaryChecksum: Checksum, + } + DecisionTaskTimedOutEventAttributes = types.DecisionTaskTimedOutEventAttributes{ + ScheduledEventID: EventID1, + StartedEventID: EventID2, + TimeoutType: &TimeoutType, + BaseRunID: RunID1, + NewRunID: RunID2, + ForkEventVersion: Version1, + Reason: Reason, + Cause: &DecisionTaskTimedOutCause, + } + DecisionTaskFailedEventAttributes = types.DecisionTaskFailedEventAttributes{ + ScheduledEventID: EventID1, + StartedEventID: EventID2, + Cause: &DecisionTaskFailedCause, + Details: FailureDetails, + Identity: Identity, + Reason: &FailureReason, + BaseRunID: RunID1, + NewRunID: RunID2, + ForkEventVersion: Version1, + BinaryChecksum: Checksum, + } + ActivityTaskScheduledEventAttributes = types.ActivityTaskScheduledEventAttributes{ + ActivityID: ActivityID, + ActivityType: &ActivityType, + Domain: DomainName, + TaskList: &TaskList, + Input: Payload1, + ScheduleToCloseTimeoutSeconds: &Duration1, + ScheduleToStartTimeoutSeconds: &Duration2, + StartToCloseTimeoutSeconds: &Duration3, + HeartbeatTimeoutSeconds: &Duration4, + DecisionTaskCompletedEventID: EventID1, + RetryPolicy: &RetryPolicy, + Header: &Header, + } + ActivityTaskStartedEventAttributes = types.ActivityTaskStartedEventAttributes{ + ScheduledEventID: EventID1, + Identity: Identity, + RequestID: RequestID, + Attempt: Attempt, + LastFailureReason: &FailureReason, + LastFailureDetails: FailureDetails, + } + ActivityTaskCompletedEventAttributes = types.ActivityTaskCompletedEventAttributes{ + Result: Payload1, + ScheduledEventID: EventID1, + StartedEventID: EventID2, + Identity: Identity, + } + ActivityTaskFailedEventAttributes = types.ActivityTaskFailedEventAttributes{ + Reason: &FailureReason, + Details: FailureDetails, + ScheduledEventID: EventID1, + StartedEventID: EventID2, + Identity: Identity, + } + ActivityTaskTimedOutEventAttributes = types.ActivityTaskTimedOutEventAttributes{ + Details: Payload1, + ScheduledEventID: EventID1, + StartedEventID: EventID2, + TimeoutType: &TimeoutType, + LastFailureReason: &FailureReason, + LastFailureDetails: FailureDetails, + } + TimerStartedEventAttributes = types.TimerStartedEventAttributes{ + TimerID: TimerID, + StartToFireTimeoutSeconds: common.Int64Ptr(int64(Duration1)), + DecisionTaskCompletedEventID: EventID1, + } + TimerFiredEventAttributes = types.TimerFiredEventAttributes{ + TimerID: TimerID, + StartedEventID: EventID1, + } + ActivityTaskCancelRequestedEventAttributes = types.ActivityTaskCancelRequestedEventAttributes{ + ActivityID: ActivityID, + DecisionTaskCompletedEventID: EventID1, + } + RequestCancelActivityTaskFailedEventAttributes = types.RequestCancelActivityTaskFailedEventAttributes{ + ActivityID: ActivityID, + Cause: Cause, + DecisionTaskCompletedEventID: EventID1, + } + ActivityTaskCanceledEventAttributes = types.ActivityTaskCanceledEventAttributes{ + Details: Payload1, + LatestCancelRequestedEventID: EventID1, + ScheduledEventID: EventID2, + StartedEventID: EventID3, + Identity: Identity, + } + TimerCanceledEventAttributes = types.TimerCanceledEventAttributes{ + TimerID: TimerID, + StartedEventID: EventID1, + DecisionTaskCompletedEventID: EventID2, + Identity: Identity, + } + CancelTimerFailedEventAttributes = types.CancelTimerFailedEventAttributes{ + TimerID: TimerID, + Cause: Cause, + DecisionTaskCompletedEventID: EventID1, + Identity: Identity, + } + MarkerRecordedEventAttributes = types.MarkerRecordedEventAttributes{ + MarkerName: MarkerName, + Details: Payload1, + DecisionTaskCompletedEventID: EventID1, + Header: &Header, + } + WorkflowExecutionSignaledEventAttributes = types.WorkflowExecutionSignaledEventAttributes{ + SignalName: SignalName, + Input: Payload1, + Identity: Identity, + } + WorkflowExecutionTerminatedEventAttributes = types.WorkflowExecutionTerminatedEventAttributes{ + Reason: Reason, + Details: Payload1, + Identity: Identity, + } + WorkflowExecutionCancelRequestedEventAttributes = types.WorkflowExecutionCancelRequestedEventAttributes{ + Cause: Cause, + ExternalInitiatedEventID: common.Int64Ptr(EventID1), + ExternalWorkflowExecution: &WorkflowExecution, + Identity: Identity, + } + WorkflowExecutionCanceledEventAttributes = types.WorkflowExecutionCanceledEventAttributes{ + DecisionTaskCompletedEventID: EventID1, + Details: Payload1, + } + RequestCancelExternalWorkflowExecutionInitiatedEventAttributes = types.RequestCancelExternalWorkflowExecutionInitiatedEventAttributes{ + DecisionTaskCompletedEventID: EventID1, + Domain: DomainName, + WorkflowExecution: &WorkflowExecution, + Control: Control, + ChildWorkflowOnly: true, + } + RequestCancelExternalWorkflowExecutionFailedEventAttributes = types.RequestCancelExternalWorkflowExecutionFailedEventAttributes{ + Cause: &CancelExternalWorkflowExecutionFailedCause, + DecisionTaskCompletedEventID: EventID1, + Domain: DomainName, + WorkflowExecution: &WorkflowExecution, + InitiatedEventID: EventID2, + Control: Control, + } + ExternalWorkflowExecutionCancelRequestedEventAttributes = types.ExternalWorkflowExecutionCancelRequestedEventAttributes{ + InitiatedEventID: EventID1, + Domain: DomainName, + WorkflowExecution: &WorkflowExecution, + } + WorkflowExecutionContinuedAsNewEventAttributes = types.WorkflowExecutionContinuedAsNewEventAttributes{ + NewExecutionRunID: RunID1, + WorkflowType: &WorkflowType, + TaskList: &TaskList, + Input: Payload1, + ExecutionStartToCloseTimeoutSeconds: &Duration1, + TaskStartToCloseTimeoutSeconds: &Duration2, + DecisionTaskCompletedEventID: EventID1, + BackoffStartIntervalInSeconds: &Duration3, + Initiator: &ContinueAsNewInitiator, + FailureReason: &FailureReason, + FailureDetails: FailureDetails, + LastCompletionResult: Payload2, + Header: &Header, + Memo: &Memo, + SearchAttributes: &SearchAttributes, + } + StartChildWorkflowExecutionInitiatedEventAttributes = types.StartChildWorkflowExecutionInitiatedEventAttributes{ + Domain: DomainName, + WorkflowID: WorkflowID, + WorkflowType: &WorkflowType, + TaskList: &TaskList, + Input: Payload1, + ExecutionStartToCloseTimeoutSeconds: &Duration1, + TaskStartToCloseTimeoutSeconds: &Duration2, + ParentClosePolicy: &ParentClosePolicy, + Control: Control, + DecisionTaskCompletedEventID: EventID1, + WorkflowIDReusePolicy: &WorkflowIDReusePolicy, + RetryPolicy: &RetryPolicy, + CronSchedule: CronSchedule, + Header: &Header, + Memo: &Memo, + SearchAttributes: &SearchAttributes, + } + StartChildWorkflowExecutionFailedEventAttributes = types.StartChildWorkflowExecutionFailedEventAttributes{ + Domain: DomainName, + WorkflowID: WorkflowID, + WorkflowType: &WorkflowType, + Cause: &ChildWorkflowExecutionFailedCause, + Control: Control, + InitiatedEventID: EventID1, + DecisionTaskCompletedEventID: EventID2, + } + ChildWorkflowExecutionStartedEventAttributes = types.ChildWorkflowExecutionStartedEventAttributes{ + Domain: DomainName, + InitiatedEventID: EventID1, + WorkflowExecution: &WorkflowExecution, + WorkflowType: &WorkflowType, + Header: &Header, + } + ChildWorkflowExecutionCompletedEventAttributes = types.ChildWorkflowExecutionCompletedEventAttributes{ + Result: Payload1, + Domain: DomainName, + WorkflowExecution: &WorkflowExecution, + WorkflowType: &WorkflowType, + InitiatedEventID: EventID1, + StartedEventID: EventID2, + } + ChildWorkflowExecutionFailedEventAttributes = types.ChildWorkflowExecutionFailedEventAttributes{ + Reason: &FailureReason, + Details: FailureDetails, + Domain: DomainName, + WorkflowExecution: &WorkflowExecution, + WorkflowType: &WorkflowType, + InitiatedEventID: EventID1, + StartedEventID: EventID2, + } + ChildWorkflowExecutionCanceledEventAttributes = types.ChildWorkflowExecutionCanceledEventAttributes{ + Details: Payload1, + Domain: DomainName, + WorkflowExecution: &WorkflowExecution, + WorkflowType: &WorkflowType, + InitiatedEventID: EventID1, + StartedEventID: EventID2, + } + ChildWorkflowExecutionTimedOutEventAttributes = types.ChildWorkflowExecutionTimedOutEventAttributes{ + TimeoutType: &TimeoutType, + Domain: DomainName, + WorkflowExecution: &WorkflowExecution, + WorkflowType: &WorkflowType, + InitiatedEventID: EventID1, + StartedEventID: EventID2, + } + ChildWorkflowExecutionTerminatedEventAttributes = types.ChildWorkflowExecutionTerminatedEventAttributes{ + Domain: DomainName, + WorkflowExecution: &WorkflowExecution, + WorkflowType: &WorkflowType, + InitiatedEventID: EventID1, + StartedEventID: EventID2, + } + SignalExternalWorkflowExecutionInitiatedEventAttributes = types.SignalExternalWorkflowExecutionInitiatedEventAttributes{ + DecisionTaskCompletedEventID: EventID1, + Domain: DomainName, + WorkflowExecution: &WorkflowExecution, + SignalName: SignalName, + Input: Payload1, + Control: Control, + ChildWorkflowOnly: true, + } + SignalExternalWorkflowExecutionFailedEventAttributes = types.SignalExternalWorkflowExecutionFailedEventAttributes{ + Cause: &SignalExternalWorkflowExecutionFailedCause, + DecisionTaskCompletedEventID: EventID1, + Domain: DomainName, + WorkflowExecution: &WorkflowExecution, + InitiatedEventID: EventID2, + Control: Control, + } + ExternalWorkflowExecutionSignaledEventAttributes = types.ExternalWorkflowExecutionSignaledEventAttributes{ + InitiatedEventID: EventID1, + Domain: DomainName, + WorkflowExecution: &WorkflowExecution, + Control: Control, + } + UpsertWorkflowSearchAttributesEventAttributes = types.UpsertWorkflowSearchAttributesEventAttributes{ + DecisionTaskCompletedEventID: EventID1, + SearchAttributes: &SearchAttributes, + } +) + +func generateEvent(modifier func(e *types.HistoryEvent)) types.HistoryEvent { + e := types.HistoryEvent{ + EventID: EventID1, + Timestamp: &Timestamp1, + Version: Version1, + TaskID: TaskID, + } + modifier(&e) + return e +} diff --git a/common/types/testdata/replication.go b/common/types/testdata/replication.go new file mode 100644 index 00000000000..6da97437870 --- /dev/null +++ b/common/types/testdata/replication.go @@ -0,0 +1,145 @@ +// 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 testdata + +import "github.com/uber/cadence/common/types" + +const TaskType = int16(1) + +var ( + ReplicationMessages = types.ReplicationMessages{ + ReplicationTasks: ReplicationTaskArray, + LastRetrievedMessageID: MessageID1, + HasMore: true, + SyncShardStatus: &SyncShardStatus, + } + ReplicationMessagesMap = map[int32]*types.ReplicationMessages{ + ShardID: &ReplicationMessages, + } + SyncShardStatus = types.SyncShardStatus{ + Timestamp: &Timestamp1, + } + ReplicationToken = types.ReplicationToken{ + ShardID: ShardID, + LastRetrievedMessageID: MessageID1, + LastProcessedMessageID: MessageID2, + } + ReplicationTokenArray = []*types.ReplicationToken{ + &ReplicationToken, + } + ReplicationTaskInfo = types.ReplicationTaskInfo{ + DomainID: DomainID, + WorkflowID: WorkflowID, + RunID: RunID, + TaskType: TaskType, + TaskID: TaskID, + Version: Version1, + FirstEventID: EventID1, + NextEventID: EventID2, + ScheduledID: EventID3, + } + ReplicationTaskInfoArray = []*types.ReplicationTaskInfo{ + &ReplicationTaskInfo, + } + ReplicationTask_Domain = types.ReplicationTask{ + TaskType: types.ReplicationTaskTypeDomain.Ptr(), + SourceTaskID: TaskID, + DomainTaskAttributes: &DomainTaskAttributes, + CreationTime: &Timestamp1, + } + ReplicationTask_SyncShard = types.ReplicationTask{ + TaskType: types.ReplicationTaskTypeSyncShardStatus.Ptr(), + SourceTaskID: TaskID, + SyncShardStatusTaskAttributes: &SyncShardStatusTaskAttributes, + CreationTime: &Timestamp1, + } + ReplicationTask_SyncActivity = types.ReplicationTask{ + TaskType: types.ReplicationTaskTypeSyncActivity.Ptr(), + SourceTaskID: TaskID, + SyncActivityTaskAttributes: &SyncActivityTaskAttributes, + CreationTime: &Timestamp1, + } + ReplicationTask_History = types.ReplicationTask{ + TaskType: types.ReplicationTaskTypeHistoryV2.Ptr(), + SourceTaskID: TaskID, + HistoryTaskV2Attributes: &HistoryTaskV2Attributes, + CreationTime: &Timestamp1, + } + ReplicationTask_Failover = types.ReplicationTask{ + TaskType: types.ReplicationTaskTypeFailoverMarker.Ptr(), + SourceTaskID: TaskID, + FailoverMarkerAttributes: &FailoverMarkerAttributes, + CreationTime: &Timestamp1, + } + ReplicationTaskArray = []*types.ReplicationTask{ + &ReplicationTask_Domain, + &ReplicationTask_SyncShard, + &ReplicationTask_SyncActivity, + &ReplicationTask_History, + &ReplicationTask_Failover, + } + DomainTaskAttributes = types.DomainTaskAttributes{ + DomainOperation: types.DomainOperationUpdate.Ptr(), + ID: DomainID, + Info: &DomainInfo, + Config: &DomainConfiguration, + ReplicationConfig: &DomainReplicationConfiguration, + ConfigVersion: Version1, + FailoverVersion: FailoverVersion1, + PreviousFailoverVersion: FailoverVersion2, + } + SyncShardStatusTaskAttributes = types.SyncShardStatusTaskAttributes{ + SourceCluster: ClusterName1, + ShardID: ShardID, + Timestamp: &Timestamp1, + } + SyncActivityTaskAttributes = types.SyncActivityTaskAttributes{ + DomainID: DomainID, + WorkflowID: WorkflowID, + RunID: RunID, + Version: Version1, + ScheduledID: EventID1, + ScheduledTime: &Timestamp1, + StartedID: EventID2, + StartedTime: &Timestamp2, + LastHeartbeatTime: &Timestamp3, + Details: Payload1, + Attempt: Attempt, + LastFailureReason: &FailureReason, + LastWorkerIdentity: Identity, + LastFailureDetails: FailureDetails, + VersionHistory: &VersionHistory, + } + HistoryTaskV2Attributes = types.HistoryTaskV2Attributes{ + TaskID: TaskID, + DomainID: DomainID, + WorkflowID: WorkflowID, + RunID: RunID, + VersionHistoryItems: VersionHistoryItemArray, + Events: &DataBlob, + NewRunEvents: &DataBlob, + } + FailoverMarkerAttributes = types.FailoverMarkerAttributes{ + DomainID: DomainID, + FailoverVersion: FailoverVersion1, + CreationTime: &Timestamp1, + } +) diff --git a/common/types/testdata/service_admin.go b/common/types/testdata/service_admin.go new file mode 100644 index 00000000000..99a2bda2441 --- /dev/null +++ b/common/types/testdata/service_admin.go @@ -0,0 +1,175 @@ +// 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 testdata + +import ( + "fmt" + + "github.com/uber/cadence/common" + "github.com/uber/cadence/common/types" +) + +const QueueType = 2 + +var ( + AdminAddSearchAttributeRequest = types.AddSearchAttributeRequest{ + SearchAttribute: IndexedValueTypeMap, + SecurityToken: SecurityToken, + } + AdminCloseShardRequest = types.CloseShardRequest{ + ShardID: ShardID, + } + AdminDescribeClusterResponse = types.DescribeClusterResponse{ + SupportedClientVersions: &SupportedClientVersions, + MembershipInfo: &MembershipInfo, + } + AdminDescribeHistoryHostRequest_ByHost = types.DescribeHistoryHostRequest{ + HostAddress: common.StringPtr(HostName), + } + AdminDescribeHistoryHostRequest_ByShard = types.DescribeHistoryHostRequest{ + ShardIDForHost: common.Int32Ptr(ShardID), + } + AdminDescribeHistoryHostRequest_ByExecution = types.DescribeHistoryHostRequest{ + ExecutionForHost: &WorkflowExecution, + } + AdminDescribeHistoryHostResponse = types.DescribeHistoryHostResponse{ + NumberOfShards: 1, + ShardIDs: []int32{ShardID}, + DomainCache: &DomainCacheInfo, + ShardControllerStatus: "ShardControllerStatus", + Address: HostName, + } + AdminDescribeQueueRequest = types.DescribeQueueRequest{ + ShardID: ShardID, + ClusterName: ClusterName1, + Type: common.Int32Ptr(QueueType), + } + AdminDescribeQueueResponse = types.DescribeQueueResponse{ + ProcessingQueueStates: []string{"state1", "state2"}, + } + AdminDescribeWorkflowExecutionRequest = types.AdminDescribeWorkflowExecutionRequest{ + Domain: DomainName, + Execution: &WorkflowExecution, + } + AdminDescribeWorkflowExecutionResponse = types.AdminDescribeWorkflowExecutionResponse{ + ShardID: fmt.Sprint(ShardID), + HistoryAddr: HostName, + MutableStateInCache: "MutableStateInCache", + MutableStateInDatabase: "MutableStateInDatabase", + } + AdminGetDLQReplicationMessagesRequest = types.GetDLQReplicationMessagesRequest{ + TaskInfos: ReplicationTaskInfoArray, + } + AdminGetDLQReplicationMessagesResponse = types.GetDLQReplicationMessagesResponse{ + ReplicationTasks: ReplicationTaskArray, + } + AdminGetDomainReplicationMessagesRequest = types.GetDomainReplicationMessagesRequest{ + LastRetrievedMessageID: common.Int64Ptr(MessageID1), + LastProcessedMessageID: common.Int64Ptr(MessageID2), + ClusterName: ClusterName1, + } + AdminGetDomainReplicationMessagesResponse = types.GetDomainReplicationMessagesResponse{ + Messages: &ReplicationMessages, + } + AdminGetReplicationMessagesRequest = types.GetReplicationMessagesRequest{ + Tokens: ReplicationTokenArray, + ClusterName: ClusterName1, + } + AdminGetReplicationMessagesResponse = types.GetReplicationMessagesResponse{ + MessagesByShard: ReplicationMessagesMap, + } + AdminGetWorkflowExecutionRawHistoryV2Request = types.GetWorkflowExecutionRawHistoryV2Request{ + Domain: DomainName, + Execution: &WorkflowExecution, + StartEventID: common.Int64Ptr(EventID1), + StartEventVersion: common.Int64Ptr(Version1), + EndEventID: common.Int64Ptr(EventID2), + EndEventVersion: common.Int64Ptr(EventID2), + MaximumPageSize: PageSize, + NextPageToken: NextPageToken, + } + AdminGetWorkflowExecutionRawHistoryV2Response = types.GetWorkflowExecutionRawHistoryV2Response{ + NextPageToken: NextPageToken, + HistoryBatches: DataBlobArray, + VersionHistory: &VersionHistory, + } + AdminMergeDLQMessagesRequest = types.MergeDLQMessagesRequest{ + Type: types.DLQTypeDomain.Ptr(), + ShardID: ShardID, + SourceCluster: ClusterName1, + InclusiveEndMessageID: common.Int64Ptr(MessageID1), + MaximumPageSize: PageSize, + NextPageToken: NextPageToken, + } + AdminMergeDLQMessagesResponse = types.MergeDLQMessagesResponse{ + NextPageToken: NextPageToken, + } + AdminPurgeDLQMessagesRequest = types.PurgeDLQMessagesRequest{ + Type: types.DLQTypeDomain.Ptr(), + ShardID: ShardID, + SourceCluster: ClusterName1, + InclusiveEndMessageID: common.Int64Ptr(MessageID1), + } + AdminReadDLQMessagesRequest = types.ReadDLQMessagesRequest{ + Type: types.DLQTypeDomain.Ptr(), + ShardID: ShardID, + SourceCluster: ClusterName1, + InclusiveEndMessageID: common.Int64Ptr(MessageID1), + MaximumPageSize: PageSize, + NextPageToken: NextPageToken, + } + AdminReadDLQMessagesResponse = types.ReadDLQMessagesResponse{ + Type: types.DLQTypeDomain.Ptr(), + ReplicationTasks: ReplicationTaskArray, + ReplicationTasksInfo: ReplicationTaskInfoArray, + NextPageToken: NextPageToken, + } + AdminReapplyEventsRequest = types.ReapplyEventsRequest{ + DomainName: DomainName, + WorkflowExecution: &WorkflowExecution, + Events: &DataBlob, + } + AdminRefreshWorkflowTasksRequest = types.RefreshWorkflowTasksRequest{ + Domain: DomainName, + Execution: &WorkflowExecution, + } + AdminRemoveTaskRequest = types.RemoveTaskRequest{ + ShardID: ShardID, + Type: common.Int32Ptr(QueueType), + TaskID: TaskID, + VisibilityTimestamp: &Timestamp1, + } + AdminResendReplicationTasksRequest = types.ResendReplicationTasksRequest{ + DomainID: DomainID, + WorkflowID: WorkflowID, + RunID: RunID, + RemoteCluster: ClusterName1, + StartEventID: common.Int64Ptr(EventID1), + StartVersion: common.Int64Ptr(Version1), + EndEventID: common.Int64Ptr(EventID2), + EndVersion: common.Int64Ptr(EventID2), + } + AdminResetQueueRequest = types.ResetQueueRequest{ + ShardID: ShardID, + ClusterName: ClusterName1, + Type: common.Int32Ptr(QueueType), + } +) diff --git a/common/types/testdata/service_frontend.go b/common/types/testdata/service_frontend.go new file mode 100644 index 00000000000..bdd63df94d8 --- /dev/null +++ b/common/types/testdata/service_frontend.go @@ -0,0 +1,437 @@ +// 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 testdata + +import ( + "github.com/uber/cadence/common" + "github.com/uber/cadence/common/types" +) + +var ( + RegisterDomainRequest = types.RegisterDomainRequest{ + Name: DomainName, + Description: DomainDescription, + OwnerEmail: DomainOwnerEmail, + WorkflowExecutionRetentionPeriodInDays: DomainRetention, + EmitMetric: common.BoolPtr(DomainEmitMetric), + Clusters: ClusterReplicationConfigurationArray, + ActiveClusterName: ClusterName1, + Data: DomainData, + SecurityToken: SecurityToken, + IsGlobalDomain: true, + HistoryArchivalStatus: &ArchivalStatus, + HistoryArchivalURI: HistoryArchivalURI, + VisibilityArchivalStatus: &ArchivalStatus, + VisibilityArchivalURI: VisibilityArchivalURI, + } + DescribeDomainRequest_ID = types.DescribeDomainRequest{ + UUID: common.StringPtr(DomainID), + } + DescribeDomainRequest_Name = types.DescribeDomainRequest{ + Name: common.StringPtr(DomainName), + } + DescribeDomainResponse = types.DescribeDomainResponse{ + DomainInfo: &DomainInfo, + Configuration: &DomainConfiguration, + ReplicationConfiguration: &DomainReplicationConfiguration, + FailoverVersion: FailoverVersion1, + IsGlobalDomain: true, + } + ListDomainsRequest = types.ListDomainsRequest{ + PageSize: PageSize, + NextPageToken: NextPageToken, + } + ListDomainsResponse = types.ListDomainsResponse{ + Domains: []*types.DescribeDomainResponse{&DescribeDomainResponse}, + NextPageToken: NextPageToken, + } + UpdateDomainRequest = types.UpdateDomainRequest{ + Name: DomainName, + Description: common.StringPtr(DomainDescription), + OwnerEmail: common.StringPtr(DomainOwnerEmail), + Data: DomainData, + WorkflowExecutionRetentionPeriodInDays: common.Int32Ptr(DomainRetention), + EmitMetric: common.BoolPtr(DomainEmitMetric), + BadBinaries: &BadBinaries, + HistoryArchivalStatus: &ArchivalStatus, + HistoryArchivalURI: common.StringPtr(HistoryArchivalURI), + VisibilityArchivalStatus: &ArchivalStatus, + VisibilityArchivalURI: common.StringPtr(VisibilityArchivalURI), + ActiveClusterName: common.StringPtr(ClusterName1), + Clusters: ClusterReplicationConfigurationArray, + SecurityToken: SecurityToken, + DeleteBadBinary: common.StringPtr(DeleteBadBinary), + FailoverTimeoutInSeconds: &Duration1, + } + UpdateDomainResponse = types.UpdateDomainResponse{ + DomainInfo: &DomainInfo, + Configuration: &DomainConfiguration, + ReplicationConfiguration: &DomainReplicationConfiguration, + FailoverVersion: FailoverVersion1, + IsGlobalDomain: true, + } + DeprecateDomainRequest = types.DeprecateDomainRequest{ + Name: DomainName, + SecurityToken: SecurityToken, + } + ListWorkflowExecutionsRequest = types.ListWorkflowExecutionsRequest{ + Domain: DomainName, + PageSize: PageSize, + NextPageToken: NextPageToken, + Query: VisibilityQuery, + } + ListWorkflowExecutionsResponse = types.ListWorkflowExecutionsResponse{ + Executions: WorkflowExecutionInfoArray, + NextPageToken: NextPageToken, + } + ListOpenWorkflowExecutionsRequest_ExecutionFilter = types.ListOpenWorkflowExecutionsRequest{ + Domain: DomainName, + MaximumPageSize: PageSize, + NextPageToken: NextPageToken, + StartTimeFilter: &StartTimeFilter, + ExecutionFilter: &WorkflowExecutionFilter, + } + ListOpenWorkflowExecutionsRequest_TypeFilter = types.ListOpenWorkflowExecutionsRequest{ + Domain: DomainName, + MaximumPageSize: PageSize, + NextPageToken: NextPageToken, + StartTimeFilter: &StartTimeFilter, + TypeFilter: &WorkflowTypeFilter, + } + ListOpenWorkflowExecutionsResponse = types.ListOpenWorkflowExecutionsResponse{ + Executions: WorkflowExecutionInfoArray, + NextPageToken: NextPageToken, + } + ListClosedWorkflowExecutionsRequest_ExecutionFilter = types.ListClosedWorkflowExecutionsRequest{ + Domain: DomainName, + MaximumPageSize: PageSize, + NextPageToken: NextPageToken, + StartTimeFilter: &StartTimeFilter, + ExecutionFilter: &WorkflowExecutionFilter, + } + ListClosedWorkflowExecutionsRequest_TypeFilter = types.ListClosedWorkflowExecutionsRequest{ + Domain: DomainName, + MaximumPageSize: PageSize, + NextPageToken: NextPageToken, + StartTimeFilter: &StartTimeFilter, + TypeFilter: &WorkflowTypeFilter, + } + ListClosedWorkflowExecutionsRequest_StatusFilter = types.ListClosedWorkflowExecutionsRequest{ + Domain: DomainName, + MaximumPageSize: PageSize, + NextPageToken: NextPageToken, + StartTimeFilter: &StartTimeFilter, + StatusFilter: &WorkflowExecutionCloseStatus, + } + ListClosedWorkflowExecutionsResponse = types.ListClosedWorkflowExecutionsResponse{ + Executions: WorkflowExecutionInfoArray, + NextPageToken: NextPageToken, + } + ListArchivedWorkflowExecutionsRequest = types.ListArchivedWorkflowExecutionsRequest{ + Domain: DomainName, + PageSize: PageSize, + NextPageToken: NextPageToken, + Query: VisibilityQuery, + } + ListArchivedWorkflowExecutionsResponse = types.ListArchivedWorkflowExecutionsResponse{ + Executions: WorkflowExecutionInfoArray, + NextPageToken: NextPageToken, + } + CountWorkflowExecutionsRequest = types.CountWorkflowExecutionsRequest{ + Domain: DomainName, + Query: VisibilityQuery, + } + CountWorkflowExecutionsResponse = types.CountWorkflowExecutionsResponse{ + Count: int64(8), + } + GetSearchAttributesResponse = types.GetSearchAttributesResponse{ + Keys: IndexedValueTypeMap, + } + PollForDecisionTaskRequest = types.PollForDecisionTaskRequest{ + Domain: DomainName, + TaskList: &TaskList, + Identity: Identity, + BinaryChecksum: Checksum, + } + PollForDecisionTaskResponse = types.PollForDecisionTaskResponse{ + TaskToken: TaskToken, + WorkflowExecution: &WorkflowExecution, + WorkflowType: &WorkflowType, + PreviousStartedEventID: common.Int64Ptr(EventID1), + StartedEventID: EventID2, + Attempt: Attempt, + BacklogCountHint: BacklogCountHint, + History: &History, + NextPageToken: NextPageToken, + Query: &WorkflowQuery, + WorkflowExecutionTaskList: &TaskList, + ScheduledTimestamp: &Timestamp1, + StartedTimestamp: &Timestamp2, + Queries: WorkflowQueryMap, + } + RespondDecisionTaskCompletedRequest = types.RespondDecisionTaskCompletedRequest{ + TaskToken: TaskToken, + Decisions: DecisionArray, + ExecutionContext: ExecutionContext, + Identity: Identity, + StickyAttributes: &StickyExecutionAttributes, + ReturnNewDecisionTask: true, + ForceCreateNewDecisionTask: true, + BinaryChecksum: Checksum, + QueryResults: WorkflowQueryResultMap, + } + RespondDecisionTaskCompletedResponse = types.RespondDecisionTaskCompletedResponse{ + DecisionTask: &PollForDecisionTaskResponse, + ActivitiesToDispatchLocally: ActivityLocalDispatchInfoMap, + } + RespondDecisionTaskFailedRequest = types.RespondDecisionTaskFailedRequest{ + TaskToken: TaskToken, + Cause: &DecisionTaskFailedCause, + Details: Payload1, + Identity: Identity, + BinaryChecksum: Checksum, + } + PollForActivityTaskRequest = types.PollForActivityTaskRequest{ + Domain: DomainName, + TaskList: &TaskList, + Identity: Identity, + TaskListMetadata: &TaskListMetadata, + } + PollForActivityTaskResponse = types.PollForActivityTaskResponse{ + TaskToken: TaskToken, + WorkflowExecution: &WorkflowExecution, + ActivityID: ActivityID, + ActivityType: &ActivityType, + Input: Payload1, + ScheduledTimestamp: &Timestamp1, + ScheduleToCloseTimeoutSeconds: &Duration1, + StartedTimestamp: &Timestamp2, + StartToCloseTimeoutSeconds: &Duration2, + HeartbeatTimeoutSeconds: &Duration3, + Attempt: Attempt, + ScheduledTimestampOfThisAttempt: &Timestamp3, + HeartbeatDetails: Payload2, + WorkflowType: &WorkflowType, + WorkflowDomain: DomainName, + Header: &Header, + } + RespondActivityTaskCompletedRequest = types.RespondActivityTaskCompletedRequest{ + TaskToken: TaskToken, + Result: Payload1, + Identity: Identity, + } + RespondActivityTaskCompletedByIDRequest = types.RespondActivityTaskCompletedByIDRequest{ + Domain: DomainName, + WorkflowID: WorkflowID, + RunID: RunID, + ActivityID: ActivityID, + Result: Payload1, + Identity: Identity, + } + RespondActivityTaskFailedRequest = types.RespondActivityTaskFailedRequest{ + TaskToken: TaskToken, + Reason: &FailureReason, + Details: FailureDetails, + Identity: Identity, + } + RespondActivityTaskFailedByIDRequest = types.RespondActivityTaskFailedByIDRequest{ + Domain: DomainName, + WorkflowID: WorkflowID, + RunID: RunID, + ActivityID: ActivityID, + Reason: &FailureReason, + Details: FailureDetails, + Identity: Identity, + } + RespondActivityTaskCanceledRequest = types.RespondActivityTaskCanceledRequest{ + TaskToken: TaskToken, + Details: Payload1, + Identity: Identity, + } + RespondActivityTaskCanceledByIDRequest = types.RespondActivityTaskCanceledByIDRequest{ + Domain: DomainName, + WorkflowID: WorkflowID, + RunID: RunID, + ActivityID: ActivityID, + Details: Payload1, + Identity: Identity, + } + RecordActivityTaskHeartbeatRequest = types.RecordActivityTaskHeartbeatRequest{ + TaskToken: TaskToken, + Details: Payload1, + Identity: Identity, + } + RecordActivityTaskHeartbeatResponse = types.RecordActivityTaskHeartbeatResponse{ + CancelRequested: true, + } + RecordActivityTaskHeartbeatByIDRequest = types.RecordActivityTaskHeartbeatByIDRequest{ + Domain: DomainName, + WorkflowID: WorkflowID, + RunID: RunID, + ActivityID: ActivityID, + Details: Payload1, + Identity: Identity, + } + RespondQueryTaskCompletedRequest = types.RespondQueryTaskCompletedRequest{ + TaskToken: TaskToken, + CompletedType: &QueryTaskCompletedType, + QueryResult: Payload1, + ErrorMessage: ErrorMessage, + WorkerVersionInfo: &WorkerVersionInfo, + } + RequestCancelWorkflowExecutionRequest = types.RequestCancelWorkflowExecutionRequest{ + Domain: DomainName, + WorkflowExecution: &WorkflowExecution, + Identity: Identity, + RequestID: RequestID, + } + StartWorkflowExecutionRequest = types.StartWorkflowExecutionRequest{ + Domain: DomainName, + WorkflowID: WorkflowID, + WorkflowType: &WorkflowType, + TaskList: &TaskList, + Input: Payload1, + ExecutionStartToCloseTimeoutSeconds: &Duration1, + TaskStartToCloseTimeoutSeconds: &Duration2, + Identity: Identity, + RequestID: RequestID, + WorkflowIDReusePolicy: &WorkflowIDReusePolicy, + RetryPolicy: &RetryPolicy, + CronSchedule: CronSchedule, + Memo: &Memo, + SearchAttributes: &SearchAttributes, + Header: &Header, + } + StartWorkflowExecutionResponse = types.StartWorkflowExecutionResponse{ + RunID: RunID, + } + SignalWorkflowExecutionRequest = types.SignalWorkflowExecutionRequest{ + Domain: DomainName, + WorkflowExecution: &WorkflowExecution, + SignalName: SignalName, + Input: Payload1, + Identity: Identity, + RequestID: RequestID, + Control: Control, + } + SignalWithStartWorkflowExecutionRequest = types.SignalWithStartWorkflowExecutionRequest{ + Domain: DomainName, + WorkflowID: WorkflowID, + WorkflowType: &WorkflowType, + TaskList: &TaskList, + Input: Payload1, + ExecutionStartToCloseTimeoutSeconds: &Duration1, + TaskStartToCloseTimeoutSeconds: &Duration2, + Identity: Identity, + RequestID: RequestID, + WorkflowIDReusePolicy: &WorkflowIDReusePolicy, + SignalName: SignalName, + SignalInput: Payload2, + Control: Control, + RetryPolicy: &RetryPolicy, + CronSchedule: CronSchedule, + Memo: &Memo, + SearchAttributes: &SearchAttributes, + Header: &Header, + } + ResetWorkflowExecutionRequest = types.ResetWorkflowExecutionRequest{ + Domain: DomainName, + WorkflowExecution: &WorkflowExecution, + Reason: Reason, + DecisionFinishEventID: EventID1, + RequestID: RequestID, + SkipSignalReapply: true, + } + ResetWorkflowExecutionResponse = types.ResetWorkflowExecutionResponse{ + RunID: RunID, + } + TerminateWorkflowExecutionRequest = types.TerminateWorkflowExecutionRequest{ + Domain: DomainName, + WorkflowExecution: &WorkflowExecution, + Reason: Reason, + Details: Payload1, + Identity: Identity, + } + DescribeWorkflowExecutionRequest = types.DescribeWorkflowExecutionRequest{ + Domain: DomainName, + Execution: &WorkflowExecution, + } + DescribeWorkflowExecutionResponse = types.DescribeWorkflowExecutionResponse{ + ExecutionConfiguration: &WorkflowExecutionConfiguration, + WorkflowExecutionInfo: &WorkflowExecutionInfo, + PendingActivities: PendingActivityInfoArray, + PendingChildren: PendingChildExecutionInfoArray, + PendingDecision: &PendingDecisionInfo, + } + QueryWorkflowRequest = types.QueryWorkflowRequest{ + Domain: DomainName, + Execution: &WorkflowExecution, + Query: &WorkflowQuery, + QueryRejectCondition: &QueryRejectCondition, + QueryConsistencyLevel: &QueryConsistencyLevel, + } + QueryWorkflowResponse = types.QueryWorkflowResponse{ + QueryResult: Payload1, + QueryRejected: &QueryRejected, + } + DescribeTaskListRequest = types.DescribeTaskListRequest{ + Domain: DomainName, + TaskList: &TaskList, + TaskListType: &TaskListType, + IncludeTaskListStatus: true, + } + DescribeTaskListResponse = types.DescribeTaskListResponse{ + Pollers: PollerInfoArray, + TaskListStatus: &TaskListStatus, + } + ListTaskListPartitionsRequest = types.ListTaskListPartitionsRequest{ + Domain: DomainName, + TaskList: &TaskList, + } + ListTaskListPartitionsResponse = types.ListTaskListPartitionsResponse{ + ActivityTaskListPartitions: TaskListPartitionMetadataArray, + DecisionTaskListPartitions: TaskListPartitionMetadataArray, + } + ResetStickyTaskListRequest = types.ResetStickyTaskListRequest{ + Domain: DomainName, + Execution: &WorkflowExecution, + } + ResetStickyTaskListResponse = types.ResetStickyTaskListResponse{} + GetWorkflowExecutionHistoryRequest = types.GetWorkflowExecutionHistoryRequest{ + Domain: DomainName, + Execution: &WorkflowExecution, + MaximumPageSize: PageSize, + NextPageToken: NextPageToken, + WaitForNewEvent: true, + HistoryEventFilterType: &HistoryEventFilterType, + SkipArchival: true, + } + GetWorkflowExecutionHistoryResponse = types.GetWorkflowExecutionHistoryResponse{ + History: &History, + RawHistory: DataBlobArray, + NextPageToken: NextPageToken, + Archived: true, + } + + DescribeDomainResponseArray = []*types.DescribeDomainResponse{ + &DescribeDomainResponse, + } +) diff --git a/common/types/testdata/service_history.go b/common/types/testdata/service_history.go new file mode 100644 index 00000000000..71c0ef4a0cb --- /dev/null +++ b/common/types/testdata/service_history.go @@ -0,0 +1,292 @@ +// 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 testdata + +import ( + "github.com/uber/cadence/common" + "github.com/uber/cadence/common/persistence" + "github.com/uber/cadence/common/types" +) + +var ( + HistoryCloseShardRequest = AdminCloseShardRequest + HistoryDescribeHistoryHostRequest = types.DescribeHistoryHostRequest{} + HistoryDescribeHistoryHostResponse = AdminDescribeHistoryHostResponse + HistoryDescribeMutableStateRequest = types.DescribeMutableStateRequest{ + DomainUUID: DomainID, + Execution: &WorkflowExecution, + } + HistoryDescribeMutableStateResponse = types.DescribeMutableStateResponse{ + MutableStateInCache: "MutableStateInCache", + MutableStateInDatabase: "MutableStateInDatabase", + } + HistoryDescribeQueueRequest = AdminDescribeQueueRequest + HistoryDescribeQueueResponse = AdminDescribeQueueResponse + HistoryDescribeWorkflowExecutionRequest = types.HistoryDescribeWorkflowExecutionRequest{ + DomainUUID: DomainID, + Request: &DescribeWorkflowExecutionRequest, + } + HistoryDescribeWorkflowExecutionResponse = DescribeWorkflowExecutionResponse + HistoryGetDLQReplicationMessagesRequest = AdminGetDLQReplicationMessagesRequest + HistoryGetDLQReplicationMessagesResponse = AdminGetDLQReplicationMessagesResponse + HistoryGetMutableStateRequest = types.GetMutableStateRequest{ + DomainUUID: DomainID, + Execution: &WorkflowExecution, + ExpectedNextEventID: EventID1, + CurrentBranchToken: BranchToken, + } + HistoryGetMutableStateResponse = types.GetMutableStateResponse{ + Execution: &WorkflowExecution, + WorkflowType: &WorkflowType, + NextEventID: EventID1, + PreviousStartedEventID: common.Int64Ptr(EventID2), + LastFirstEventID: EventID3, + TaskList: &TaskList, + StickyTaskList: &TaskList, + ClientLibraryVersion: ClientLibraryVersion, + ClientFeatureVersion: FeatureVersion, + ClientImpl: ClientImpl, + IsWorkflowRunning: true, + StickyTaskListScheduleToStartTimeout: &Duration1, + EventStoreVersion: EventStoreVersion, + CurrentBranchToken: BranchToken, + WorkflowState: common.Int32Ptr(persistence.WorkflowStateRunning), + WorkflowCloseState: common.Int32Ptr(3), + VersionHistories: &VersionHistories, + IsStickyTaskListEnabled: true, + } + HistoryGetReplicationMessagesRequest = AdminGetReplicationMessagesRequest + HistoryGetReplicationMessagesResponse = AdminGetReplicationMessagesResponse + HistoryMergeDLQMessagesRequest = AdminMergeDLQMessagesRequest + HistoryMergeDLQMessagesResponse = AdminMergeDLQMessagesResponse + HistoryNotifyFailoverMarkersRequest = types.NotifyFailoverMarkersRequest{ + FailoverMarkerTokens: FailoverMarkerTokenArray, + } + HistoryPollMutableStateRequest = types.PollMutableStateRequest{ + DomainUUID: DomainID, + Execution: &WorkflowExecution, + ExpectedNextEventID: EventID1, + CurrentBranchToken: BranchToken, + } + HistoryPollMutableStateResponse = types.PollMutableStateResponse{ + Execution: &WorkflowExecution, + WorkflowType: &WorkflowType, + NextEventID: EventID1, + PreviousStartedEventID: common.Int64Ptr(EventID2), + LastFirstEventID: EventID3, + TaskList: &TaskList, + StickyTaskList: &TaskList, + ClientLibraryVersion: ClientLibraryVersion, + ClientFeatureVersion: FeatureVersion, + ClientImpl: ClientImpl, + StickyTaskListScheduleToStartTimeout: &Duration1, + CurrentBranchToken: BranchToken, + VersionHistories: &VersionHistories, + WorkflowState: common.Int32Ptr(2), + WorkflowCloseState: common.Int32Ptr(3), + } + HistoryPurgeDLQMessagesRequest = AdminPurgeDLQMessagesRequest + HistoryQueryWorkflowRequest = types.HistoryQueryWorkflowRequest{ + DomainUUID: DomainID, + Request: &QueryWorkflowRequest, + } + HistoryQueryWorkflowResponse = types.HistoryQueryWorkflowResponse{ + Response: &QueryWorkflowResponse, + } + HistoryReadDLQMessagesRequest = AdminReadDLQMessagesRequest + HistoryReadDLQMessagesResponse = AdminReadDLQMessagesResponse + HistoryReapplyEventsRequest = types.HistoryReapplyEventsRequest{ + DomainUUID: DomainID, + Request: &AdminReapplyEventsRequest, + } + HistoryRecordActivityTaskHeartbeatRequest = types.HistoryRecordActivityTaskHeartbeatRequest{ + DomainUUID: DomainID, + HeartbeatRequest: &RecordActivityTaskHeartbeatRequest, + } + HistoryRecordActivityTaskHeartbeatResponse = RecordActivityTaskHeartbeatResponse + HistoryRecordActivityTaskStartedRequest = types.RecordActivityTaskStartedRequest{ + DomainUUID: DomainID, + WorkflowExecution: &WorkflowExecution, + ScheduleID: EventID1, + TaskID: TaskID, + RequestID: RequestID, + PollRequest: &PollForActivityTaskRequest, + } + HistoryRecordActivityTaskStartedResponse = types.RecordActivityTaskStartedResponse{ + ScheduledEvent: &HistoryEvent_WorkflowExecutionStarted, + StartedTimestamp: &Timestamp1, + Attempt: Attempt, + ScheduledTimestampOfThisAttempt: &Timestamp2, + HeartbeatDetails: Payload1, + WorkflowType: &WorkflowType, + WorkflowDomain: DomainName, + } + HistoryRecordChildExecutionCompletedRequest = types.RecordChildExecutionCompletedRequest{ + DomainUUID: DomainID, + WorkflowExecution: &WorkflowExecution, + InitiatedID: EventID1, + CompletedExecution: &WorkflowExecution, + CompletionEvent: &HistoryEvent_WorkflowExecutionStarted, + } + HistoryRecordDecisionTaskStartedRequest = types.RecordDecisionTaskStartedRequest{ + DomainUUID: DomainID, + WorkflowExecution: &WorkflowExecution, + ScheduleID: EventID1, + TaskID: TaskID, + RequestID: RequestID, + PollRequest: &PollForDecisionTaskRequest, + } + HistoryRecordDecisionTaskStartedResponse = types.RecordDecisionTaskStartedResponse{ + WorkflowType: &WorkflowType, + PreviousStartedEventID: common.Int64Ptr(EventID1), + ScheduledEventID: EventID2, + StartedEventID: EventID3, + NextEventID: EventID4, + Attempt: Attempt, + StickyExecutionEnabled: true, + DecisionInfo: &TransientDecisionInfo, + WorkflowExecutionTaskList: &TaskList, + EventStoreVersion: EventStoreVersion, + BranchToken: BranchToken, + ScheduledTimestamp: &Timestamp1, + StartedTimestamp: &Timestamp2, + Queries: WorkflowQueryMap, + } + HistoryRefreshWorkflowTasksRequest = types.HistoryRefreshWorkflowTasksRequest{ + DomainUIID: DomainID, + Request: &AdminRefreshWorkflowTasksRequest, + } + HistoryRemoveSignalMutableStateRequest = types.RemoveSignalMutableStateRequest{ + DomainUUID: DomainID, + WorkflowExecution: &WorkflowExecution, + RequestID: RequestID, + } + HistoryRemoveTaskRequest = AdminRemoveTaskRequest + HistoryReplicateEventsV2Request = types.ReplicateEventsV2Request{ + DomainUUID: DomainID, + WorkflowExecution: &WorkflowExecution, + VersionHistoryItems: VersionHistoryItemArray, + Events: &DataBlob, + NewRunEvents: &DataBlob, + } + HistoryRequestCancelWorkflowExecutionRequest = types.HistoryRequestCancelWorkflowExecutionRequest{ + DomainUUID: DomainID, + CancelRequest: &RequestCancelWorkflowExecutionRequest, + ExternalInitiatedEventID: common.Int64Ptr(EventID1), + ExternalWorkflowExecution: &WorkflowExecution, + ChildWorkflowOnly: true, + } + HistoryResetQueueRequest = AdminResetQueueRequest + HistoryResetStickyTaskListRequest = types.HistoryResetStickyTaskListRequest{ + DomainUUID: DomainID, + Execution: &WorkflowExecution, + } + HistoryResetWorkflowExecutionRequest = types.HistoryResetWorkflowExecutionRequest{ + DomainUUID: DomainID, + ResetRequest: &ResetWorkflowExecutionRequest, + } + HistoryResetWorkflowExecutionResponse = types.ResetWorkflowExecutionResponse{ + RunID: RunID, + } + HistoryRespondActivityTaskCanceledRequest = types.HistoryRespondActivityTaskCanceledRequest{ + DomainUUID: DomainID, + CancelRequest: &RespondActivityTaskCanceledRequest, + } + HistoryRespondActivityTaskCompletedRequest = types.HistoryRespondActivityTaskCompletedRequest{ + DomainUUID: DomainID, + CompleteRequest: &RespondActivityTaskCompletedRequest, + } + HistoryRespondActivityTaskFailedRequest = types.HistoryRespondActivityTaskFailedRequest{ + DomainUUID: DomainID, + FailedRequest: &RespondActivityTaskFailedRequest, + } + HistoryRespondDecisionTaskCompletedRequest = types.HistoryRespondDecisionTaskCompletedRequest{ + DomainUUID: DomainID, + CompleteRequest: &RespondDecisionTaskCompletedRequest, + } + HistoryRespondDecisionTaskCompletedResponse = types.HistoryRespondDecisionTaskCompletedResponse{ + StartedResponse: &HistoryRecordDecisionTaskStartedResponse, + ActivitiesToDispatchLocally: ActivityLocalDispatchInfoMap, + } + HistoryRespondDecisionTaskFailedRequest = types.HistoryRespondDecisionTaskFailedRequest{ + DomainUUID: DomainID, + FailedRequest: &RespondDecisionTaskFailedRequest, + } + HistoryScheduleDecisionTaskRequest = types.ScheduleDecisionTaskRequest{ + DomainUUID: DomainID, + WorkflowExecution: &WorkflowExecution, + IsFirstDecision: true, + } + HistorySignalWithStartWorkflowExecutionRequest = types.HistorySignalWithStartWorkflowExecutionRequest{ + DomainUUID: DomainID, + SignalWithStartRequest: &SignalWithStartWorkflowExecutionRequest, + } + HistorySignalWithStartWorkflowExecutionResponse = types.StartWorkflowExecutionResponse{ + RunID: RunID, + } + HistorySignalWorkflowExecutionRequest = types.HistorySignalWorkflowExecutionRequest{ + DomainUUID: DomainID, + SignalRequest: &SignalWorkflowExecutionRequest, + ExternalWorkflowExecution: &WorkflowExecution, + ChildWorkflowOnly: true, + } + HistoryStartWorkflowExecutionRequest = types.HistoryStartWorkflowExecutionRequest{ + DomainUUID: DomainID, + StartRequest: &StartWorkflowExecutionRequest, + ParentExecutionInfo: &ParentExecutionInfo, + Attempt: Attempt, + ExpirationTimestamp: &Timestamp1, + ContinueAsNewInitiator: &ContinueAsNewInitiator, + ContinuedFailureReason: &FailureReason, + ContinuedFailureDetails: FailureDetails, + LastCompletionResult: Payload1, + FirstDecisionTaskBackoffSeconds: &Duration1, + } + HistoryStartWorkflowExecutionResponse = types.StartWorkflowExecutionResponse{ + RunID: RunID, + } + HistorySyncActivityRequest = types.SyncActivityRequest{ + DomainID: DomainID, + WorkflowID: WorkflowID, + RunID: RunID, + Version: Version1, + ScheduledID: EventID1, + ScheduledTime: &Timestamp1, + StartedID: EventID1, + StartedTime: &Timestamp2, + LastHeartbeatTime: &Timestamp3, + Details: Payload1, + Attempt: Attempt, + LastFailureReason: &FailureReason, + LastWorkerIdentity: Identity, + LastFailureDetails: FailureDetails, + VersionHistory: &VersionHistory, + } + HistorySyncShardStatusRequest = types.SyncShardStatusRequest{ + SourceCluster: ClusterName1, + ShardID: ShardID, + Timestamp: &Timestamp1, + } + HistoryTerminateWorkflowExecutionRequest = types.HistoryTerminateWorkflowExecutionRequest{ + DomainUUID: DomainID, + TerminateRequest: &TerminateWorkflowExecutionRequest, + } +) diff --git a/common/types/testdata/service_matching.go b/common/types/testdata/service_matching.go new file mode 100644 index 00000000000..bb382992304 --- /dev/null +++ b/common/types/testdata/service_matching.go @@ -0,0 +1,140 @@ +// 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 testdata + +import ( + "github.com/uber/cadence/common" + "github.com/uber/cadence/common/types" +) + +const ( + ForwardedFrom = "ForwardedFrom" + PollerID = "PollerID" +) + +var ( + MatchingAddActivityTaskRequest = types.AddActivityTaskRequest{ + DomainUUID: DomainID, + Execution: &WorkflowExecution, + SourceDomainUUID: DomainID, + TaskList: &TaskList, + ScheduleID: EventID1, + ScheduleToStartTimeoutSeconds: &Duration1, + Source: types.TaskSourceDbBacklog.Ptr(), + ForwardedFrom: ForwardedFrom, + } + MatchingAddDecisionTaskRequest = types.AddDecisionTaskRequest{ + DomainUUID: DomainID, + Execution: &WorkflowExecution, + TaskList: &TaskList, + ScheduleID: EventID1, + ScheduleToStartTimeoutSeconds: &Duration1, + Source: types.TaskSourceDbBacklog.Ptr(), + ForwardedFrom: ForwardedFrom, + } + MatchingCancelOutstandingPollRequest = types.CancelOutstandingPollRequest{ + DomainUUID: DomainID, + TaskListType: common.Int32Ptr(int32(TaskListType)), + TaskList: &TaskList, + PollerID: PollerID, + } + MatchingDescribeTaskListRequest = types.MatchingDescribeTaskListRequest{ + DomainUUID: DomainID, + DescRequest: &DescribeTaskListRequest, + } + MatchingDescribeTaskListResponse = types.DescribeTaskListResponse{ + Pollers: PollerInfoArray, + TaskListStatus: &TaskListStatus, + } + MatchingListTaskListPartitionsRequest = types.MatchingListTaskListPartitionsRequest{ + Domain: DomainName, + TaskList: &TaskList, + } + MatchingListTaskListPartitionsResponse = types.ListTaskListPartitionsResponse{ + ActivityTaskListPartitions: TaskListPartitionMetadataArray, + DecisionTaskListPartitions: TaskListPartitionMetadataArray, + } + MatchingPollForActivityTaskRequest = types.MatchingPollForActivityTaskRequest{ + DomainUUID: DomainID, + PollerID: PollerID, + PollRequest: &PollForActivityTaskRequest, + ForwardedFrom: ForwardedFrom, + } + MatchingPollForActivityTaskResponse = types.PollForActivityTaskResponse{ + TaskToken: TaskToken, + WorkflowExecution: &WorkflowExecution, + ActivityID: ActivityID, + ActivityType: &ActivityType, + Input: Payload1, + ScheduledTimestamp: &Timestamp1, + ScheduleToCloseTimeoutSeconds: &Duration1, + StartedTimestamp: &Timestamp2, + StartToCloseTimeoutSeconds: &Duration2, + HeartbeatTimeoutSeconds: &Duration3, + Attempt: Attempt, + ScheduledTimestampOfThisAttempt: &Timestamp3, + HeartbeatDetails: Payload2, + WorkflowType: &WorkflowType, + WorkflowDomain: DomainName, + Header: &Header, + } + MatchingPollForDecisionTaskRequest = types.MatchingPollForDecisionTaskRequest{ + DomainUUID: DomainID, + PollerID: PollerID, + PollRequest: &PollForDecisionTaskRequest, + ForwardedFrom: ForwardedFrom, + } + MatchingPollForDecisionTaskResponse = types.MatchingPollForDecisionTaskResponse{ + TaskToken: TaskToken, + WorkflowExecution: &WorkflowExecution, + WorkflowType: &WorkflowType, + PreviousStartedEventID: common.Int64Ptr(EventID1), + StartedEventID: EventID2, + Attempt: Attempt, + NextEventID: EventID3, + BacklogCountHint: BacklogCountHint, + StickyExecutionEnabled: true, + Query: &WorkflowQuery, + DecisionInfo: &TransientDecisionInfo, + WorkflowExecutionTaskList: &TaskList, + EventStoreVersion: EventStoreVersion, + BranchToken: BranchToken, + ScheduledTimestamp: &Timestamp1, + StartedTimestamp: &Timestamp2, + Queries: WorkflowQueryMap, + } + MatchingQueryWorkflowRequest = types.MatchingQueryWorkflowRequest{ + DomainUUID: DomainID, + TaskList: &TaskList, + QueryRequest: &QueryWorkflowRequest, + ForwardedFrom: ForwardedFrom, + } + MatchingQueryWorkflowResponse = types.QueryWorkflowResponse{ + QueryResult: Payload1, + QueryRejected: &QueryRejected, + } + MatchingRespondQueryTaskCompletedRequest = types.MatchingRespondQueryTaskCompletedRequest{ + DomainUUID: DomainID, + TaskList: &TaskList, + TaskID: "TaskID", + CompletedRequest: &RespondQueryTaskCompletedRequest, + } +) diff --git a/go.mod b/go.mod index 21891f0f501..d69f40c9951 100644 --- a/go.mod +++ b/go.mod @@ -21,6 +21,7 @@ require ( github.com/go-sql-driver/mysql v1.5.0 github.com/gocql/gocql v0.0.0-20191126110522-1982a06ad6b9 github.com/golang/mock v1.4.4 + github.com/golang/protobuf v1.4.3 github.com/google/uuid v1.1.2 github.com/hashicorp/go-version v1.2.0 github.com/iancoleman/strcase v0.0.0-20190422225806-e506e3ef7365 @@ -69,7 +70,7 @@ require ( golang.org/x/tools v0.1.0 gonum.org/v1/gonum v0.7.0 google.golang.org/api v0.36.0 - google.golang.org/grpc v1.35.0 // indirect + google.golang.org/grpc v1.35.0 google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.1.0 google.golang.org/protobuf v1.25.0 gopkg.in/jcmturner/goidentity.v3 v3.0.0 // indirect