Skip to content

Commit a0a78b0

Browse files
committed
Move to RootComponent method
1 parent 0d5496e commit a0a78b0

10 files changed

Lines changed: 70 additions & 22 deletions

File tree

chasm/component.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ type TerminateComponentResponse struct{}
4444
// TODO: (not yet true) Visibility record will no longer be updated after RootComponent is closed.
4545
type RootComponent interface {
4646
TerminableComponent
47+
48+
// ContextMetadata returns execution metadata to propagate to the request context.
49+
ContextMetadata(Context) map[string]string
4750
}
4851

4952
// Embed UnimplementedComponent to get forward compatibility

chasm/component_mock.go

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

chasm/context_metadata.go

Lines changed: 0 additions & 8 deletions
This file was deleted.

chasm/lib/activity/activity.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,11 @@ func (a *Activity) LifecycleState(_ chasm.Context) chasm.LifecycleState {
106106
}
107107
}
108108

109+
func (a *Activity) ContextMetadata(_ chasm.Context) map[string]string {
110+
// TODO: Export standalone activity context metadata.
111+
return nil
112+
}
113+
109114
// NewStandaloneActivity creates a new activity component and adds associated tasks to start execution.
110115
func NewStandaloneActivity(
111116
ctx chasm.MutableContext,

chasm/lib/scheduler/scheduler.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,11 @@ func (s *Scheduler) LifecycleState(ctx chasm.Context) chasm.LifecycleState {
288288
return chasm.LifecycleStateRunning
289289
}
290290

291+
func (s *Scheduler) ContextMetadata(_ chasm.Context) map[string]string {
292+
// TODO: Export scheduler context metadata.
293+
return nil
294+
}
295+
291296
// Terminate implements the chasm.RootComponent interface.
292297
func (s *Scheduler) Terminate(
293298
_ chasm.MutableContext,

chasm/lib/tests/payload.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,12 @@ func (s *PayloadStore) Cancel(
115115
return CancelPayloadStoreResponse{}, nil
116116
}
117117

118+
func (s *PayloadStore) ContextMetadata(_ chasm.Context) map[string]string {
119+
return map[string]string{
120+
string(componentCtxKey): componentCtxVal,
121+
}
122+
}
123+
118124
func (s *PayloadStore) AddPayload(
119125
mutableContext chasm.MutableContext,
120126
request AddPayloadRequest,

chasm/lib/workflow/workflow.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ func (w *Workflow) LifecycleState(
4646
return chasm.LifecycleStateRunning
4747
}
4848

49+
func (w *Workflow) ContextMetadata(_ chasm.Context) map[string]string {
50+
// TODO: Export workflow metadata from the CHASM workflow root instead of CloseTransaction().
51+
return nil
52+
}
53+
4954
// ProcessCloseCallbacks triggers "WorkflowClosed" callbacks using the CHASM implementation.
5055
// It iterates through all callbacks and schedules WorkflowClosed ones that are in STANDBY state.
5156
func (w *Workflow) ProcessCloseCallbacks(ctx chasm.MutableContext) error {

chasm/test_component_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ var (
8080

8181
_ VisibilitySearchAttributesProvider = (*TestComponent)(nil)
8282
_ VisibilityMemoProvider = (*TestComponent)(nil)
83+
_ RootComponent = (*TestComponent)(nil)
8384
)
8485

8586
func (tc *TestComponent) LifecycleState(_ Context) LifecycleState {
@@ -109,6 +110,11 @@ func (tc *TestComponent) Fail(_ MutableContext) {
109110
tc.ComponentData.Status = enumspb.WORKFLOW_EXECUTION_STATUS_FAILED
110111
}
111112

113+
func (tc *TestComponent) ContextMetadata(_ Context) map[string]string {
114+
// TODO: Export context metadata from this test root.
115+
return nil
116+
}
117+
112118
// SearchAttributes implements VisibilitySearchAttributesProvider interface.
113119
func (tc *TestComponent) SearchAttributes(_ Context) []SearchAttributeKeyValue {
114120
return []SearchAttributeKeyValue{

service/history/chasm_engine.go

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -128,27 +128,33 @@ func (e *ChasmEngine) setContextMetadata(
128128
return chasmContext
129129
}
130130

131-
provider, ok := rootComponent.(chasm.ContextMetadataProvider)
131+
root, ok := rootComponent.(chasm.RootComponent)
132132
if !ok {
133+
softassert.Fail(
134+
e.logger,
135+
"root node must implement RootComponent interface",
136+
tag.NewStringTag("component_type", fmt.Sprintf("%T", rootComponent)),
137+
)
133138
return chasmContext
134139
}
135140

136-
for key, value := range provider.ContextMetadata(chasmContext) {
141+
for key, value := range root.ContextMetadata(chasmContext) {
137142
contextutil.ContextMetadataSet(ctx, key, value)
138143
}
139144

140145
return chasmContext
141146
}
142147

143148
func chasmTreeFromMutableState(
149+
logger log.Logger,
144150
mutableState historyi.MutableState,
145151
) (*chasm.Node, error) {
146152
chasmTree, ok := mutableState.ChasmTree().(*chasm.Node)
147153
if !ok {
148-
return nil, serviceerror.NewInternalf(
149-
"CHASM tree implementation not properly wired up, encountered type: %T, expected type: %T",
150-
mutableState.ChasmTree(),
151-
&chasm.Node{},
154+
return nil, softassert.UnexpectedInternalErr(
155+
logger,
156+
"CHASM tree implementation not properly wired up",
157+
fmt.Errorf("encountered type: %T, expected type: %T", mutableState.ChasmTree(), &chasm.Node{}),
152158
)
153159
}
154160
return chasmTree, nil
@@ -158,7 +164,7 @@ func (e *ChasmEngine) setContextMetadataFromMutableState(
158164
ctx context.Context,
159165
mutableState historyi.MutableState,
160166
) {
161-
chasmTree, err := chasmTreeFromMutableState(mutableState)
167+
chasmTree, err := chasmTreeFromMutableState(e.logger, mutableState)
162168
if err != nil {
163169
e.logger.Error("Failed to resolve CHASM tree for context metadata", tag.Error(err))
164170
return
@@ -413,7 +419,7 @@ func (e *ChasmEngine) applyUpdateWithLease(
413419
updateFn func(chasm.MutableContext, chasm.Component) error,
414420
) ([]byte, error) {
415421
mutableState := executionLease.GetMutableState()
416-
chasmTree, err := chasmTreeFromMutableState(mutableState)
422+
chasmTree, err := chasmTreeFromMutableState(shardContext.GetLogger(), mutableState)
417423
if err != nil {
418424
return nil, err
419425
}
@@ -641,7 +647,7 @@ func (e *ChasmEngine) readComponent(
641647
executionLease.GetReleaseFn()(nil)
642648
}()
643649

644-
chasmTree, err := chasmTreeFromMutableState(executionLease.GetMutableState())
650+
chasmTree, err := chasmTreeFromMutableState(e.logger, executionLease.GetMutableState())
645651
if err != nil {
646652
return err
647653
}
@@ -743,7 +749,7 @@ func (e *ChasmEngine) predicateSatisfied(
743749
ref chasm.ComponentRef,
744750
executionLease api.WorkflowLease,
745751
) ([]byte, error) {
746-
chasmTree, err := chasmTreeFromMutableState(executionLease.GetMutableState())
752+
chasmTree, err := chasmTreeFromMutableState(e.logger, executionLease.GetMutableState())
747753
if err != nil {
748754
return nil, err
749755
}

service/history/chasm_engine_test.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,7 @@ func (s *chasmEngineSuite) TestSetContextMetadata_StateAndRequestScopedValues()
550550
},
551551
)
552552

553-
chasmTree, err := chasmTreeFromMutableState(mutableState)
553+
chasmTree, err := chasmTreeFromMutableState(s.mockShard.GetLogger(), mutableState)
554554
s.NoError(err)
555555

556556
requestCtx := newTestMetadataContext("helper-request")
@@ -575,7 +575,7 @@ func (s *chasmEngineSuite) TestSetContextMetadata_NoProvider() {
575575
},
576576
)
577577

578-
chasmTree, err := chasmTreeFromMutableState(mutableState)
578+
chasmTree, err := chasmTreeFromMutableState(s.mockShard.GetLogger(), mutableState)
579579
s.NoError(err)
580580

581581
requestCtx := contextutil.WithMetadataContext(context.Background())
@@ -2002,7 +2002,7 @@ func (s *chasmEngineSuite) newTestMutableState(
20022002
s.mockShard.GetTimeSource().Now(),
20032003
)
20042004

2005-
chasmTree, err := chasmTreeFromMutableState(mutableState)
2005+
chasmTree, err := chasmTreeFromMutableState(s.mockShard.GetLogger(), mutableState)
20062006
s.NoError(err)
20072007
s.NoError(chasmTree.SetRootComponent(rootComponent))
20082008

@@ -2043,7 +2043,8 @@ var (
20432043

20442044
_ chasm.VisibilitySearchAttributesProvider = (*testComponent)(nil)
20452045
_ chasm.VisibilityMemoProvider = (*testComponent)(nil)
2046-
_ chasm.ContextMetadataProvider = (*testComponent)(nil)
2046+
_ chasm.RootComponent = (*testComponent)(nil)
2047+
_ chasm.RootComponent = (*testComponentNoMetadata)(nil)
20472048
)
20482049

20492050
type testRequestContextKey struct{}
@@ -2099,6 +2100,11 @@ func (l *testComponentNoMetadata) LifecycleState(_ chasm.Context) chasm.Lifecycl
20992100
return chasm.LifecycleStateRunning
21002101
}
21012102

2103+
func (l *testComponentNoMetadata) ContextMetadata(_ chasm.Context) map[string]string {
2104+
// TODO: Export context metadata from this root.
2105+
return nil
2106+
}
2107+
21022108
func (l *testComponentNoMetadata) Terminate(
21032109
_ chasm.MutableContext,
21042110
_ chasm.TerminateComponentRequest,

0 commit comments

Comments
 (0)