Skip to content

Commit c012357

Browse files
authored
add WorkflowImplementationOptions customizer (#1835)
add WorkflowImplementationOptions customizer
1 parent 0f37297 commit c012357

File tree

7 files changed

+86
-12
lines changed

7 files changed

+86
-12
lines changed

temporal-spring-boot-autoconfigure-alpha/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ Where `OptionsType` may be one of:
153153
- `WorkflowClientOption.Builder`
154154
- `WorkerFactoryOptions.Builder`
155155
- `WorkerOptions.Builder`
156+
- `WorkflowImplementationOptions.Builder`
156157
- `TestEnvironmentOptions.Builder`
157158

158159
`io.temporal.spring.boot.WorkerOptionsCustomizer` may be used instead of `TemporalOptionsCustomizer<WorkerOptions.Builder>`

temporal-spring-boot-autoconfigure-alpha/src/main/java/io/temporal/spring/boot/TemporalOptionsCustomizer.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import io.temporal.testing.TestEnvironmentOptions;
2626
import io.temporal.worker.WorkerFactoryOptions;
2727
import io.temporal.worker.WorkerOptions;
28+
import io.temporal.worker.WorkflowImplementationOptions;
2829
import javax.annotation.Nonnull;
2930

3031
/**
@@ -36,7 +37,7 @@
3637
* @param <T> Temporal Options Builder to customize. Respected types: {@link
3738
* WorkflowServiceStubsOptions.Builder}, {@link WorkflowClientOptions.Builder}, {@link
3839
* TestEnvironmentOptions.Builder}, {@link WorkerOptions.Builder}, {@link
39-
* WorkerFactoryOptions.Builder}
40+
* WorkerFactoryOptions.Builder}, {@link WorkflowImplementationOptions.Builder}
4041
* @see WorkerOptionsCustomizer to get access to a name and task queue of a worker that's being
4142
* customized
4243
*/

temporal-spring-boot-autoconfigure-alpha/src/main/java/io/temporal/spring/boot/autoconfigure/RootNamespaceAutoConfiguration.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,7 @@
3333
import io.temporal.spring.boot.autoconfigure.template.NamespaceTemplate;
3434
import io.temporal.spring.boot.autoconfigure.template.TestWorkflowEnvironmentAdapter;
3535
import io.temporal.spring.boot.autoconfigure.template.WorkersTemplate;
36-
import io.temporal.worker.Worker;
37-
import io.temporal.worker.WorkerFactory;
38-
import io.temporal.worker.WorkerFactoryOptions;
39-
import io.temporal.worker.WorkerOptions;
36+
import io.temporal.worker.*;
4037
import java.util.Collection;
4138
import java.util.List;
4239
import javax.annotation.Nonnull;
@@ -90,7 +87,10 @@ public NamespaceTemplate rootNamespaceTemplate(
9087
@Autowired(required = false) @Nullable
9188
TemporalOptionsCustomizer<WorkflowClientOptions.Builder> clientCustomizer,
9289
@Autowired(required = false) @Nullable
93-
TemporalOptionsCustomizer<ScheduleClientOptions.Builder> scheduleCustomize) {
90+
TemporalOptionsCustomizer<ScheduleClientOptions.Builder> scheduleCustomizer,
91+
@Autowired(required = false) @Nullable
92+
TemporalOptionsCustomizer<WorkflowImplementationOptions.Builder>
93+
workflowImplementationCustomizer) {
9494
DataConverter chosenDataConverter =
9595
AutoConfigurationUtils.choseDataConverter(dataConverters, mainDataConverter);
9696
return new NamespaceTemplate(
@@ -103,7 +103,8 @@ public NamespaceTemplate rootNamespaceTemplate(
103103
workerFactoryCustomizer,
104104
workerCustomizer,
105105
clientCustomizer,
106-
scheduleCustomize);
106+
scheduleCustomizer,
107+
workflowImplementationCustomizer);
107108
}
108109

109110
/** Client */

temporal-spring-boot-autoconfigure-alpha/src/main/java/io/temporal/spring/boot/autoconfigure/template/NamespaceTemplate.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import io.temporal.spring.boot.autoconfigure.properties.TemporalProperties;
3131
import io.temporal.worker.WorkerFactoryOptions;
3232
import io.temporal.worker.WorkerOptions;
33+
import io.temporal.worker.WorkflowImplementationOptions;
3334
import javax.annotation.Nonnull;
3435
import javax.annotation.Nullable;
3536

@@ -47,6 +48,8 @@ public class NamespaceTemplate {
4748
private final @Nullable TemporalOptionsCustomizer<WorkflowClientOptions.Builder> clientCustomizer;
4849
private final @Nullable TemporalOptionsCustomizer<ScheduleClientOptions.Builder>
4950
scheduleCustomizer;
51+
private final @Nullable TemporalOptionsCustomizer<WorkflowImplementationOptions.Builder>
52+
workflowImplementationCustomizer;
5053

5154
private ClientTemplate clientTemplate;
5255
private WorkersTemplate workersTemplate;
@@ -61,7 +64,10 @@ public NamespaceTemplate(
6164
@Nullable TemporalOptionsCustomizer<WorkerFactoryOptions.Builder> workerFactoryCustomizer,
6265
@Nullable TemporalOptionsCustomizer<WorkerOptions.Builder> workerCustomizer,
6366
@Nullable TemporalOptionsCustomizer<WorkflowClientOptions.Builder> clientCustomizer,
64-
@Nullable TemporalOptionsCustomizer<ScheduleClientOptions.Builder> scheduleCustomizer) {
67+
@Nullable TemporalOptionsCustomizer<ScheduleClientOptions.Builder> scheduleCustomizer,
68+
@Nullable
69+
TemporalOptionsCustomizer<WorkflowImplementationOptions.Builder>
70+
workflowImplementationCustomizer) {
6571
this.properties = properties;
6672
this.namespaceProperties = namespaceProperties;
6773
this.workflowServiceStubs = workflowServiceStubs;
@@ -73,6 +79,7 @@ public NamespaceTemplate(
7379
this.workerCustomizer = workerCustomizer;
7480
this.clientCustomizer = clientCustomizer;
7581
this.scheduleCustomizer = scheduleCustomizer;
82+
this.workflowImplementationCustomizer = workflowImplementationCustomizer;
7683
}
7784

7885
public ClientTemplate getClientTemplate() {
@@ -100,7 +107,8 @@ public WorkersTemplate getWorkersTemplate() {
100107
tracer,
101108
testWorkflowEnvironment,
102109
workerFactoryCustomizer,
103-
workerCustomizer);
110+
workerCustomizer,
111+
workflowImplementationCustomizer);
104112
}
105113
return this.workersTemplate;
106114
}

temporal-spring-boot-autoconfigure-alpha/src/main/java/io/temporal/spring/boot/autoconfigure/template/WorkersTemplate.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ public class WorkersTemplate implements BeanFactoryAware, EnvironmentAware {
6666
workerFactoryCustomizer;
6767

6868
private final @Nullable TemporalOptionsCustomizer<WorkerOptions.Builder> workerCustomizer;
69+
private final @Nullable TemporalOptionsCustomizer<WorkflowImplementationOptions.Builder>
70+
workflowImplementationCustomizer;
6971

7072
private ConfigurableListableBeanFactory beanFactory;
7173
private Environment environment;
@@ -80,7 +82,10 @@ public WorkersTemplate(
8082
@Nullable Tracer tracer,
8183
@Nullable TestWorkflowEnvironmentAdapter testWorkflowEnvironment,
8284
@Nullable TemporalOptionsCustomizer<WorkerFactoryOptions.Builder> workerFactoryCustomizer,
83-
@Nullable TemporalOptionsCustomizer<WorkerOptions.Builder> workerCustomizer) {
85+
@Nullable TemporalOptionsCustomizer<WorkerOptions.Builder> workerCustomizer,
86+
@Nullable
87+
TemporalOptionsCustomizer<WorkflowImplementationOptions.Builder>
88+
workflowImplementationCustomizer) {
8489
this.properties = properties;
8590
this.namespaceProperties = namespaceProperties;
8691
this.tracer = tracer;
@@ -89,6 +94,7 @@ public WorkersTemplate(
8994

9095
this.workerFactoryCustomizer = workerFactoryCustomizer;
9196
this.workerCustomizer = workerCustomizer;
97+
this.workflowImplementationCustomizer = workflowImplementationCustomizer;
9298
}
9399

94100
public WorkerFactory getWorkerFactory() {
@@ -363,10 +369,15 @@ private <T> void configureWorkflowImplementation(Worker worker, Class<?> clazz)
363369
+ clazz);
364370
}
365371

372+
WorkflowImplementationOptions workflowImplementationOptions =
373+
new WorkflowImplementationOptionsTemplate(workflowImplementationCustomizer)
374+
.createWorkflowImplementationOptions();
375+
366376
for (POJOWorkflowMethodMetadata workflowMethod : workflowMetadata.getWorkflowMethods()) {
367377
worker.registerWorkflowImplementationFactory(
368378
(Class<T>) workflowMethod.getWorkflowInterface(),
369-
() -> (T) beanFactory.createBean(clazz));
379+
() -> (T) beanFactory.createBean(clazz),
380+
workflowImplementationOptions);
370381
}
371382
}
372383

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Copyright (C) 2022 Temporal Technologies, Inc. All Rights Reserved.
3+
*
4+
* Copyright (C) 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
5+
*
6+
* Modifications copyright (C) 2017 Uber Technologies, Inc.
7+
*
8+
* Licensed under the Apache License, Version 2.0 (the "License");
9+
* you may not use this material except in compliance with the License.
10+
* You may obtain a copy of the License at
11+
*
12+
* http://www.apache.org/licenses/LICENSE-2.0
13+
*
14+
* Unless required by applicable law or agreed to in writing, software
15+
* distributed under the License is distributed on an "AS IS" BASIS,
16+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
* See the License for the specific language governing permissions and
18+
* limitations under the License.
19+
*/
20+
21+
package io.temporal.spring.boot.autoconfigure.template;
22+
23+
import io.temporal.spring.boot.TemporalOptionsCustomizer;
24+
import io.temporal.worker.WorkflowImplementationOptions;
25+
import javax.annotation.Nullable;
26+
27+
public class WorkflowImplementationOptionsTemplate {
28+
private final @Nullable TemporalOptionsCustomizer<WorkflowImplementationOptions.Builder>
29+
customizer;
30+
31+
public WorkflowImplementationOptionsTemplate(
32+
@Nullable TemporalOptionsCustomizer<WorkflowImplementationOptions.Builder> customizer) {
33+
this.customizer = customizer;
34+
}
35+
36+
public WorkflowImplementationOptions createWorkflowImplementationOptions() {
37+
WorkflowImplementationOptions.Builder options = WorkflowImplementationOptions.newBuilder();
38+
39+
if (customizer != null) {
40+
options = customizer.customize(options);
41+
}
42+
43+
return options.build();
44+
}
45+
}

temporal-spring-boot-autoconfigure-alpha/src/test/java/io/temporal/spring/boot/autoconfigure/OptionsCustomizersTest.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import io.temporal.spring.boot.WorkerOptionsCustomizer;
3030
import io.temporal.testing.TestEnvironmentOptions;
3131
import io.temporal.worker.WorkerFactoryOptions;
32+
import io.temporal.worker.WorkflowImplementationOptions;
3233
import java.util.List;
3334
import org.junit.jupiter.api.BeforeEach;
3435
import org.junit.jupiter.api.Test;
@@ -59,7 +60,7 @@ void setUp() {
5960
@Test
6061
@Timeout(value = 10)
6162
public void testCustomizersGotCalled() {
62-
assertEquals(4, customizers.size());
63+
assertEquals(5, customizers.size());
6364
customizers.forEach(c -> verify(c).customize(any()));
6465
verify(workerCustomizer).customize(any(), eq("UnitTest"), eq("UnitTest"));
6566
}
@@ -86,6 +87,12 @@ public TemporalOptionsCustomizer<WorkerFactoryOptions.Builder> workerFactoryCust
8687
return getReturningMock();
8788
}
8889

90+
@Bean
91+
public TemporalOptionsCustomizer<WorkflowImplementationOptions.Builder>
92+
WorkflowImplementationCustomizer() {
93+
return getReturningMock();
94+
}
95+
8996
@Bean
9097
public WorkerOptionsCustomizer workerCustomizer() {
9198
WorkerOptionsCustomizer mock = mock(WorkerOptionsCustomizer.class);

0 commit comments

Comments
 (0)