go.uber.org/cadence@v1.2.9/internal/compatibility/thrift/types.go (about) 1 // Copyright (c) 2021 Uber Technologies, Inc. 2 // 3 // Permission is hereby granted, free of charge, to any person obtaining a copy 4 // of this software and associated documentation files (the "Software"), to deal 5 // in the Software without restriction, including without limitation the rights 6 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 // copies of the Software, and to permit persons to whom the Software is 8 // furnished to do so, subject to the following conditions: 9 // 10 // The above copyright notice and this permission notice shall be included in 11 // all copies or substantial portions of the Software. 12 // 13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 // THE SOFTWARE. 20 21 package thrift 22 23 import ( 24 "go.uber.org/cadence/.gen/go/shared" 25 "go.uber.org/cadence/internal/common" 26 27 apiv1 "github.com/uber/cadence-idl/go/proto/api/v1" 28 ) 29 30 func Payload(p *apiv1.Payload) []byte { 31 if p == nil { 32 return nil 33 } 34 if p.Data == nil { 35 // protoPayload will not generate this case 36 // however, Data field will be dropped by the encoding if it's empty 37 // and receiver side will see nil for the Data field 38 // since we already know p is not nil, Data field must be an empty byte array 39 return []byte{} 40 } 41 return p.Data 42 } 43 44 func FailureReason(failure *apiv1.Failure) *string { 45 if failure == nil { 46 return nil 47 } 48 return &failure.Reason 49 } 50 51 func FailureDetails(failure *apiv1.Failure) []byte { 52 if failure == nil { 53 return nil 54 } 55 return failure.Details 56 } 57 58 func WorkflowExecution(t *apiv1.WorkflowExecution) *shared.WorkflowExecution { 59 if t == nil { 60 return nil 61 } 62 return &shared.WorkflowExecution{ 63 WorkflowId: &t.WorkflowId, 64 RunId: &t.RunId, 65 } 66 } 67 68 func WorkflowId(t *apiv1.WorkflowExecution) *string { 69 if t == nil { 70 return nil 71 } 72 return &t.WorkflowId 73 } 74 75 func RunId(t *apiv1.WorkflowExecution) *string { 76 if t == nil { 77 return nil 78 } 79 return &t.RunId 80 } 81 82 func ActivityType(t *apiv1.ActivityType) *shared.ActivityType { 83 if t == nil { 84 return nil 85 } 86 return &shared.ActivityType{ 87 Name: &t.Name, 88 } 89 } 90 91 func WorkflowType(t *apiv1.WorkflowType) *shared.WorkflowType { 92 if t == nil { 93 return nil 94 } 95 return &shared.WorkflowType{ 96 Name: &t.Name, 97 } 98 } 99 100 func TaskList(t *apiv1.TaskList) *shared.TaskList { 101 if t == nil { 102 return nil 103 } 104 return &shared.TaskList{ 105 Name: &t.Name, 106 Kind: TaskListKind(t.Kind), 107 } 108 } 109 110 func TaskListMetadata(t *apiv1.TaskListMetadata) *shared.TaskListMetadata { 111 if t == nil { 112 return nil 113 } 114 return &shared.TaskListMetadata{ 115 MaxTasksPerSecond: toDoubleValue(t.MaxTasksPerSecond), 116 } 117 } 118 119 func RetryPolicy(t *apiv1.RetryPolicy) *shared.RetryPolicy { 120 if t == nil { 121 return nil 122 } 123 return &shared.RetryPolicy{ 124 InitialIntervalInSeconds: durationToSeconds(t.InitialInterval), 125 BackoffCoefficient: &t.BackoffCoefficient, 126 MaximumIntervalInSeconds: durationToSeconds(t.MaximumInterval), 127 MaximumAttempts: &t.MaximumAttempts, 128 NonRetriableErrorReasons: t.NonRetryableErrorReasons, 129 ExpirationIntervalInSeconds: durationToSeconds(t.ExpirationInterval), 130 } 131 } 132 133 func Header(t *apiv1.Header) *shared.Header { 134 if t == nil { 135 return nil 136 } 137 return &shared.Header{ 138 Fields: PayloadMap(t.Fields), 139 } 140 } 141 142 func Memo(t *apiv1.Memo) *shared.Memo { 143 if t == nil { 144 return nil 145 } 146 return &shared.Memo{ 147 Fields: PayloadMap(t.Fields), 148 } 149 } 150 151 func SearchAttributes(t *apiv1.SearchAttributes) *shared.SearchAttributes { 152 if t == nil { 153 return nil 154 } 155 return &shared.SearchAttributes{ 156 IndexedFields: PayloadMap(t.IndexedFields), 157 } 158 } 159 160 func BadBinaries(t *apiv1.BadBinaries) *shared.BadBinaries { 161 if t == nil { 162 return nil 163 } 164 return &shared.BadBinaries{ 165 Binaries: BadBinaryInfoMap(t.Binaries), 166 } 167 } 168 169 func BadBinaryInfo(t *apiv1.BadBinaryInfo) *shared.BadBinaryInfo { 170 if t == nil { 171 return nil 172 } 173 return &shared.BadBinaryInfo{ 174 Reason: &t.Reason, 175 Operator: &t.Operator, 176 CreatedTimeNano: timeToUnixNano(t.CreatedTime), 177 } 178 } 179 180 func ClusterReplicationConfiguration(t *apiv1.ClusterReplicationConfiguration) *shared.ClusterReplicationConfiguration { 181 if t == nil { 182 return nil 183 } 184 return &shared.ClusterReplicationConfiguration{ 185 ClusterName: &t.ClusterName, 186 } 187 } 188 189 func WorkflowQuery(t *apiv1.WorkflowQuery) *shared.WorkflowQuery { 190 if t == nil { 191 return nil 192 } 193 return &shared.WorkflowQuery{ 194 QueryType: &t.QueryType, 195 QueryArgs: Payload(t.QueryArgs), 196 } 197 } 198 199 func WorkflowQueryResult(t *apiv1.WorkflowQueryResult) *shared.WorkflowQueryResult { 200 if t == nil { 201 return nil 202 } 203 return &shared.WorkflowQueryResult{ 204 ResultType: QueryResultType(t.ResultType), 205 Answer: Payload(t.Answer), 206 ErrorMessage: &t.ErrorMessage, 207 } 208 } 209 210 func StickyExecutionAttributes(t *apiv1.StickyExecutionAttributes) *shared.StickyExecutionAttributes { 211 if t == nil { 212 return nil 213 } 214 return &shared.StickyExecutionAttributes{ 215 WorkerTaskList: TaskList(t.WorkerTaskList), 216 ScheduleToStartTimeoutSeconds: durationToSeconds(t.ScheduleToStartTimeout), 217 } 218 } 219 220 func WorkerVersionInfo(t *apiv1.WorkerVersionInfo) *shared.WorkerVersionInfo { 221 if t == nil { 222 return nil 223 } 224 return &shared.WorkerVersionInfo{ 225 Impl: &t.Impl, 226 FeatureVersion: &t.FeatureVersion, 227 } 228 } 229 230 func StartTimeFilter(t *apiv1.StartTimeFilter) *shared.StartTimeFilter { 231 if t == nil { 232 return nil 233 } 234 return &shared.StartTimeFilter{ 235 EarliestTime: timeToUnixNano(t.EarliestTime), 236 LatestTime: timeToUnixNano(t.LatestTime), 237 } 238 } 239 240 func WorkflowExecutionFilter(t *apiv1.WorkflowExecutionFilter) *shared.WorkflowExecutionFilter { 241 if t == nil { 242 return nil 243 } 244 return &shared.WorkflowExecutionFilter{ 245 WorkflowId: &t.WorkflowId, 246 RunId: &t.RunId, 247 } 248 } 249 250 func WorkflowTypeFilter(t *apiv1.WorkflowTypeFilter) *shared.WorkflowTypeFilter { 251 if t == nil { 252 return nil 253 } 254 return &shared.WorkflowTypeFilter{ 255 Name: &t.Name, 256 } 257 } 258 259 func StatusFilter(t *apiv1.StatusFilter) *shared.WorkflowExecutionCloseStatus { 260 if t == nil { 261 return nil 262 } 263 return WorkflowExecutionCloseStatus(t.Status) 264 } 265 266 func PayloadMap(t map[string]*apiv1.Payload) map[string][]byte { 267 if t == nil { 268 return nil 269 } 270 v := make(map[string][]byte, len(t)) 271 for key := range t { 272 v[key] = Payload(t[key]) 273 } 274 return v 275 } 276 277 func BadBinaryInfoMap(t map[string]*apiv1.BadBinaryInfo) map[string]*shared.BadBinaryInfo { 278 if t == nil { 279 return nil 280 } 281 v := make(map[string]*shared.BadBinaryInfo, len(t)) 282 for key := range t { 283 v[key] = BadBinaryInfo(t[key]) 284 } 285 return v 286 } 287 288 func ClusterReplicationConfigurationArray(t []*apiv1.ClusterReplicationConfiguration) []*shared.ClusterReplicationConfiguration { 289 if t == nil { 290 return nil 291 } 292 v := make([]*shared.ClusterReplicationConfiguration, len(t)) 293 for i := range t { 294 v[i] = ClusterReplicationConfiguration(t[i]) 295 } 296 return v 297 } 298 299 func WorkflowQueryResultMap(t map[string]*apiv1.WorkflowQueryResult) map[string]*shared.WorkflowQueryResult { 300 if t == nil { 301 return nil 302 } 303 v := make(map[string]*shared.WorkflowQueryResult, len(t)) 304 for key := range t { 305 v[key] = WorkflowQueryResult(t[key]) 306 } 307 return v 308 } 309 310 func DataBlob(t *apiv1.DataBlob) *shared.DataBlob { 311 if t == nil { 312 return nil 313 } 314 return &shared.DataBlob{ 315 EncodingType: EncodingType(t.EncodingType), 316 Data: t.Data, 317 } 318 } 319 320 func ExternalInitiatedId(t *apiv1.ExternalExecutionInfo) *int64 { 321 if t == nil { 322 return nil 323 } 324 return &t.InitiatedId 325 } 326 327 func ExternalWorkflowExecution(t *apiv1.ExternalExecutionInfo) *shared.WorkflowExecution { 328 if t == nil { 329 return nil 330 } 331 return WorkflowExecution(t.WorkflowExecution) 332 } 333 334 func ResetPoints(t *apiv1.ResetPoints) *shared.ResetPoints { 335 if t == nil { 336 return nil 337 } 338 return &shared.ResetPoints{ 339 Points: ResetPointInfoArray(t.Points), 340 } 341 } 342 343 func ResetPointInfo(t *apiv1.ResetPointInfo) *shared.ResetPointInfo { 344 if t == nil { 345 return nil 346 } 347 return &shared.ResetPointInfo{ 348 BinaryChecksum: &t.BinaryChecksum, 349 RunId: &t.RunId, 350 FirstDecisionCompletedId: &t.FirstDecisionCompletedId, 351 CreatedTimeNano: timeToUnixNano(t.CreatedTime), 352 ExpiringTimeNano: timeToUnixNano(t.ExpiringTime), 353 Resettable: &t.Resettable, 354 } 355 } 356 357 func PollerInfo(t *apiv1.PollerInfo) *shared.PollerInfo { 358 if t == nil { 359 return nil 360 } 361 return &shared.PollerInfo{ 362 LastAccessTime: timeToUnixNano(t.LastAccessTime), 363 Identity: &t.Identity, 364 RatePerSecond: &t.RatePerSecond, 365 } 366 } 367 368 func TaskListStatus(t *apiv1.TaskListStatus) *shared.TaskListStatus { 369 if t == nil { 370 return nil 371 } 372 return &shared.TaskListStatus{ 373 BacklogCountHint: &t.BacklogCountHint, 374 ReadLevel: &t.ReadLevel, 375 AckLevel: &t.AckLevel, 376 RatePerSecond: &t.RatePerSecond, 377 TaskIDBlock: TaskIdBlock(t.TaskIdBlock), 378 } 379 } 380 381 func TaskIdBlock(t *apiv1.TaskIDBlock) *shared.TaskIDBlock { 382 if t == nil { 383 return nil 384 } 385 return &shared.TaskIDBlock{ 386 StartID: &t.StartId, 387 EndID: &t.EndId, 388 } 389 } 390 391 func WorkflowExecutionConfiguration(t *apiv1.WorkflowExecutionConfiguration) *shared.WorkflowExecutionConfiguration { 392 if t == nil { 393 return nil 394 } 395 return &shared.WorkflowExecutionConfiguration{ 396 TaskList: TaskList(t.TaskList), 397 ExecutionStartToCloseTimeoutSeconds: durationToSeconds(t.ExecutionStartToCloseTimeout), 398 TaskStartToCloseTimeoutSeconds: durationToSeconds(t.TaskStartToCloseTimeout), 399 } 400 } 401 402 func WorkflowExecutionInfo(t *apiv1.WorkflowExecutionInfo) *shared.WorkflowExecutionInfo { 403 if t == nil { 404 return nil 405 } 406 return &shared.WorkflowExecutionInfo{ 407 Execution: WorkflowExecution(t.WorkflowExecution), 408 Type: WorkflowType(t.Type), 409 StartTime: timeToUnixNano(t.StartTime), 410 CloseTime: timeToUnixNano(t.CloseTime), 411 CloseStatus: WorkflowExecutionCloseStatus(t.CloseStatus), 412 HistoryLength: &t.HistoryLength, 413 ParentDomainId: ParentDomainId(t.ParentExecutionInfo), 414 ParentExecution: ParentWorkflowExecution(t.ParentExecutionInfo), 415 ExecutionTime: timeToUnixNano(t.ExecutionTime), 416 Memo: Memo(t.Memo), 417 SearchAttributes: SearchAttributes(t.SearchAttributes), 418 AutoResetPoints: ResetPoints(t.AutoResetPoints), 419 TaskList: &t.TaskList, 420 IsCron: &t.IsCron, 421 } 422 } 423 424 func ParentDomainId(pei *apiv1.ParentExecutionInfo) *string { 425 if pei == nil { 426 return nil 427 } 428 return &pei.DomainId 429 } 430 431 func ParentDomainName(pei *apiv1.ParentExecutionInfo) *string { 432 if pei == nil { 433 return nil 434 } 435 return &pei.DomainName 436 } 437 438 func ParentInitiatedId(pei *apiv1.ParentExecutionInfo) *int64 { 439 if pei == nil { 440 return nil 441 } 442 return &pei.InitiatedId 443 } 444 445 func ParentWorkflowExecution(pei *apiv1.ParentExecutionInfo) *shared.WorkflowExecution { 446 if pei == nil { 447 return nil 448 } 449 return WorkflowExecution(pei.WorkflowExecution) 450 } 451 452 func PendingActivityInfo(t *apiv1.PendingActivityInfo) *shared.PendingActivityInfo { 453 if t == nil { 454 return nil 455 } 456 return &shared.PendingActivityInfo{ 457 ActivityID: &t.ActivityId, 458 ActivityType: ActivityType(t.ActivityType), 459 State: PendingActivityState(t.State), 460 HeartbeatDetails: Payload(t.HeartbeatDetails), 461 LastHeartbeatTimestamp: timeToUnixNano(t.LastHeartbeatTime), 462 LastStartedTimestamp: timeToUnixNano(t.LastStartedTime), 463 Attempt: &t.Attempt, 464 MaximumAttempts: &t.MaximumAttempts, 465 ScheduledTimestamp: timeToUnixNano(t.ScheduledTime), 466 ExpirationTimestamp: timeToUnixNano(t.ExpirationTime), 467 LastFailureReason: FailureReason(t.LastFailure), 468 LastFailureDetails: FailureDetails(t.LastFailure), 469 LastWorkerIdentity: &t.LastWorkerIdentity, 470 } 471 } 472 473 func PendingChildExecutionInfo(t *apiv1.PendingChildExecutionInfo) *shared.PendingChildExecutionInfo { 474 if t == nil { 475 return nil 476 } 477 return &shared.PendingChildExecutionInfo{ 478 WorkflowID: WorkflowId(t.WorkflowExecution), 479 RunID: RunId(t.WorkflowExecution), 480 WorkflowTypName: &t.WorkflowTypeName, 481 InitiatedID: &t.InitiatedId, 482 ParentClosePolicy: ParentClosePolicy(t.ParentClosePolicy), 483 } 484 } 485 486 func PendingDecisionInfo(t *apiv1.PendingDecisionInfo) *shared.PendingDecisionInfo { 487 if t == nil { 488 return nil 489 } 490 return &shared.PendingDecisionInfo{ 491 State: PendingDecisionState(t.State), 492 ScheduledTimestamp: timeToUnixNano(t.ScheduledTime), 493 StartedTimestamp: timeToUnixNano(t.StartedTime), 494 Attempt: common.Int64Ptr(int64(t.Attempt)), 495 OriginalScheduledTimestamp: timeToUnixNano(t.OriginalScheduledTime), 496 } 497 } 498 499 func ActivityLocalDispatchInfo(t *apiv1.ActivityLocalDispatchInfo) *shared.ActivityLocalDispatchInfo { 500 if t == nil { 501 return nil 502 } 503 return &shared.ActivityLocalDispatchInfo{ 504 ActivityId: &t.ActivityId, 505 ScheduledTimestamp: timeToUnixNano(t.ScheduledTime), 506 StartedTimestamp: timeToUnixNano(t.StartedTime), 507 ScheduledTimestampOfThisAttempt: timeToUnixNano(t.ScheduledTimeOfThisAttempt), 508 TaskToken: t.TaskToken, 509 } 510 } 511 512 func SupportedClientVersions(t *apiv1.SupportedClientVersions) *shared.SupportedClientVersions { 513 if t == nil { 514 return nil 515 } 516 return &shared.SupportedClientVersions{ 517 GoSdk: &t.GoSdk, 518 JavaSdk: &t.JavaSdk, 519 } 520 } 521 522 func DescribeDomainResponseDomain(t *apiv1.Domain) *shared.DescribeDomainResponse { 523 if t == nil { 524 return nil 525 } 526 return &shared.DescribeDomainResponse{ 527 DomainInfo: &shared.DomainInfo{ 528 Name: &t.Name, 529 Status: DomainStatus(t.Status), 530 Description: &t.Description, 531 OwnerEmail: &t.OwnerEmail, 532 Data: t.Data, 533 UUID: &t.Id, 534 }, 535 Configuration: &shared.DomainConfiguration{ 536 WorkflowExecutionRetentionPeriodInDays: durationToDays(t.WorkflowExecutionRetentionPeriod), 537 EmitMetric: boolPtr(true), 538 BadBinaries: BadBinaries(t.BadBinaries), 539 HistoryArchivalStatus: ArchivalStatus(t.HistoryArchivalStatus), 540 HistoryArchivalURI: &t.HistoryArchivalUri, 541 VisibilityArchivalStatus: ArchivalStatus(t.VisibilityArchivalStatus), 542 VisibilityArchivalURI: &t.VisibilityArchivalUri, 543 }, 544 ReplicationConfiguration: &shared.DomainReplicationConfiguration{ 545 ActiveClusterName: &t.ActiveClusterName, 546 Clusters: ClusterReplicationConfigurationArray(t.Clusters), 547 }, 548 FailoverVersion: &t.FailoverVersion, 549 IsGlobalDomain: &t.IsGlobalDomain, 550 } 551 } 552 553 func TaskListPartitionMetadata(t *apiv1.TaskListPartitionMetadata) *shared.TaskListPartitionMetadata { 554 if t == nil { 555 return nil 556 } 557 return &shared.TaskListPartitionMetadata{ 558 Key: &t.Key, 559 OwnerHostName: &t.OwnerHostName, 560 } 561 } 562 563 func QueryRejected(t *apiv1.QueryRejected) *shared.QueryRejected { 564 if t == nil { 565 return nil 566 } 567 return &shared.QueryRejected{ 568 CloseStatus: WorkflowExecutionCloseStatus(t.CloseStatus), 569 } 570 } 571 572 func PollerInfoArray(t []*apiv1.PollerInfo) []*shared.PollerInfo { 573 if t == nil { 574 return nil 575 } 576 v := make([]*shared.PollerInfo, len(t)) 577 for i := range t { 578 v[i] = PollerInfo(t[i]) 579 } 580 return v 581 } 582 583 func ResetPointInfoArray(t []*apiv1.ResetPointInfo) []*shared.ResetPointInfo { 584 if t == nil { 585 return nil 586 } 587 v := make([]*shared.ResetPointInfo, len(t)) 588 for i := range t { 589 v[i] = ResetPointInfo(t[i]) 590 } 591 return v 592 } 593 594 func PendingActivityInfoArray(t []*apiv1.PendingActivityInfo) []*shared.PendingActivityInfo { 595 if t == nil { 596 return nil 597 } 598 v := make([]*shared.PendingActivityInfo, len(t)) 599 for i := range t { 600 v[i] = PendingActivityInfo(t[i]) 601 } 602 return v 603 } 604 605 func PendingChildExecutionInfoArray(t []*apiv1.PendingChildExecutionInfo) []*shared.PendingChildExecutionInfo { 606 if t == nil { 607 return nil 608 } 609 v := make([]*shared.PendingChildExecutionInfo, len(t)) 610 for i := range t { 611 v[i] = PendingChildExecutionInfo(t[i]) 612 } 613 return v 614 } 615 616 func IndexedValueTypeMap(t map[string]apiv1.IndexedValueType) map[string]shared.IndexedValueType { 617 if t == nil { 618 return nil 619 } 620 v := make(map[string]shared.IndexedValueType, len(t)) 621 for key := range t { 622 v[key] = IndexedValueType(t[key]) 623 } 624 return v 625 } 626 627 func DataBlobArray(t []*apiv1.DataBlob) []*shared.DataBlob { 628 if t == nil { 629 return nil 630 } 631 v := make([]*shared.DataBlob, len(t)) 632 for i := range t { 633 v[i] = DataBlob(t[i]) 634 } 635 return v 636 } 637 638 func WorkflowExecutionInfoArray(t []*apiv1.WorkflowExecutionInfo) []*shared.WorkflowExecutionInfo { 639 if t == nil { 640 return nil 641 } 642 v := make([]*shared.WorkflowExecutionInfo, len(t)) 643 for i := range t { 644 v[i] = WorkflowExecutionInfo(t[i]) 645 } 646 return v 647 } 648 649 func DescribeDomainResponseArray(t []*apiv1.Domain) []*shared.DescribeDomainResponse { 650 if t == nil { 651 return nil 652 } 653 v := make([]*shared.DescribeDomainResponse, len(t)) 654 for i := range t { 655 v[i] = DescribeDomainResponseDomain(t[i]) 656 } 657 return v 658 } 659 660 func TaskListPartitionMetadataArray(t []*apiv1.TaskListPartitionMetadata) []*shared.TaskListPartitionMetadata { 661 if t == nil { 662 return nil 663 } 664 v := make([]*shared.TaskListPartitionMetadata, len(t)) 665 for i := range t { 666 v[i] = TaskListPartitionMetadata(t[i]) 667 } 668 return v 669 } 670 671 func WorkflowQueryMap(t map[string]*apiv1.WorkflowQuery) map[string]*shared.WorkflowQuery { 672 if t == nil { 673 return nil 674 } 675 v := make(map[string]*shared.WorkflowQuery, len(t)) 676 for key := range t { 677 v[key] = WorkflowQuery(t[key]) 678 } 679 return v 680 } 681 682 func ActivityLocalDispatchInfoMap(t map[string]*apiv1.ActivityLocalDispatchInfo) map[string]*shared.ActivityLocalDispatchInfo { 683 if t == nil { 684 return nil 685 } 686 v := make(map[string]*shared.ActivityLocalDispatchInfo, len(t)) 687 for key := range t { 688 v[key] = ActivityLocalDispatchInfo(t[key]) 689 } 690 return v 691 }