From a37dce58dea753fa391976c0009b03cedc9fe56a Mon Sep 17 00:00:00 2001 From: Yuri Date: Thu, 2 Jan 2025 09:55:03 -0800 Subject: [PATCH] Separate some interfaces from implementation --- components/callbacks/executors.go | 5 +-- components/callbacks/hsm_invocation.go | 4 --- components/callbacks/nexus_invocation.go | 4 --- components/common/hsm_completion_callback.go | 33 ++++++++++++++++++++ components/common/nexus_completion.go | 33 ++++++++++++++++++++ service/history/workflow/mutable_state.go | 6 ++-- 6 files changed, 72 insertions(+), 13 deletions(-) create mode 100644 components/common/hsm_completion_callback.go create mode 100644 components/common/nexus_completion.go diff --git a/components/callbacks/executors.go b/components/callbacks/executors.go index f28af2a4a5c..a6284005857 100644 --- a/components/callbacks/executors.go +++ b/components/callbacks/executors.go @@ -32,6 +32,7 @@ import ( "go.temporal.io/server/common/metrics" "go.temporal.io/server/common/namespace" "go.temporal.io/server/common/resource" + components "go.temporal.io/server/components/common" "go.temporal.io/server/service/history/hsm" "go.temporal.io/server/service/history/queues" "go.uber.org/fx" @@ -160,7 +161,7 @@ func (e taskExecutor) loadInvocationArgs( switch variant := callback.GetCallback().GetVariant().(type) { case *persistencespb.Callback_Nexus_: - target, err := hsm.MachineData[CanGetNexusCompletion](node.Parent) + target, err := hsm.MachineData[components.CanGetNexusCompletion](node.Parent) if err != nil { return err } @@ -173,7 +174,7 @@ func (e taskExecutor) loadInvocationArgs( return err } case *persistencespb.Callback_Hsm: - target, err := hsm.MachineData[CanGetHSMCompletionCallbackArg](node.Parent) + target, err := hsm.MachineData[components.CanGetHSMCompletionCallbackArg](node.Parent) if err != nil { return err } diff --git a/components/callbacks/hsm_invocation.go b/components/callbacks/hsm_invocation.go index 080ce0f5ea8..afbf1f1edf4 100644 --- a/components/callbacks/hsm_invocation.go +++ b/components/callbacks/hsm_invocation.go @@ -36,10 +36,6 @@ import ( "google.golang.org/grpc/status" ) -type CanGetHSMCompletionCallbackArg interface { - GetHSMCompletionCallbackArg(ctx context.Context) (*persistencespb.HSMCompletionCallbackArg, error) -} - type hsmInvocation struct { hsm *persistencespb.Callback_HSM callbackArg *persistencespb.HSMCompletionCallbackArg diff --git a/components/callbacks/nexus_invocation.go b/components/callbacks/nexus_invocation.go index af295181d24..26c43a7462c 100644 --- a/components/callbacks/nexus_invocation.go +++ b/components/callbacks/nexus_invocation.go @@ -43,10 +43,6 @@ var retryable4xxErrorTypes = []int{ http.StatusTooManyRequests, } -type CanGetNexusCompletion interface { - GetNexusCompletion(ctx context.Context) (nexus.OperationCompletion, error) -} - type nexusInvocation struct { nexus *persistencespb.Callback_Nexus completion nexus.OperationCompletion diff --git a/components/common/hsm_completion_callback.go b/components/common/hsm_completion_callback.go new file mode 100644 index 00000000000..11b0ee6d9c1 --- /dev/null +++ b/components/common/hsm_completion_callback.go @@ -0,0 +1,33 @@ +// The MIT License +// +// Copyright (c) 2024 Temporal Technologies Inc. All rights reserved. +// +// 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 common + +import ( + "context" + + persistencespb "go.temporal.io/server/api/persistence/v1" +) + +type CanGetHSMCompletionCallbackArg interface { + GetHSMCompletionCallbackArg(ctx context.Context) (*persistencespb.HSMCompletionCallbackArg, error) +} diff --git a/components/common/nexus_completion.go b/components/common/nexus_completion.go new file mode 100644 index 00000000000..1d1992de798 --- /dev/null +++ b/components/common/nexus_completion.go @@ -0,0 +1,33 @@ +// The MIT License +// +// Copyright (c) 2024 Temporal Technologies Inc. All rights reserved. +// +// 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 common + +import ( + "context" + + "github.com/nexus-rpc/sdk-go/nexus" +) + +type CanGetNexusCompletion interface { + GetNexusCompletion(ctx context.Context) (nexus.OperationCompletion, error) +} diff --git a/service/history/workflow/mutable_state.go b/service/history/workflow/mutable_state.go index 65d06c166d2..f28f3324df1 100644 --- a/service/history/workflow/mutable_state.go +++ b/service/history/workflow/mutable_state.go @@ -51,7 +51,7 @@ import ( "go.temporal.io/server/common/definition" "go.temporal.io/server/common/namespace" "go.temporal.io/server/common/persistence" - "go.temporal.io/server/components/callbacks" + components "go.temporal.io/server/components/common" "go.temporal.io/server/service/history/historybuilder" "go.temporal.io/server/service/history/hsm" "go.temporal.io/server/service/history/tasks" @@ -151,8 +151,8 @@ type ( ActivityUpdater func(*persistencespb.ActivityInfo, MutableState) error MutableState interface { - callbacks.CanGetNexusCompletion - callbacks.CanGetHSMCompletionCallbackArg + components.CanGetNexusCompletion + components.CanGetHSMCompletionCallbackArg AddHistoryEvent(t enumspb.EventType, setAttributes func(*historypb.HistoryEvent)) *historypb.HistoryEvent LoadHistoryEvent(ctx context.Context, token []byte) (*historypb.HistoryEvent, error)