Skip to content

Commit c040f0d

Browse files
authored
Add separate deployment name and build id fields for spring (#2681)
1 parent 89c427e commit c040f0d

File tree

4 files changed

+115
-5
lines changed

4 files changed

+115
-5
lines changed

temporal-spring-boot-autoconfigure/src/main/java/io/temporal/spring/boot/autoconfigure/properties/WorkerProperties.java

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,8 @@ public static class WorkerDeploymentConfigurationProperties {
385385
private final @Nullable String deploymentVersion;
386386
private final @Nullable Boolean useVersioning;
387387
private final @Nullable VersioningBehavior defaultVersioningBehavior;
388+
private final @Nullable String deploymentName;
389+
private final @Nullable String buildId;
388390

389391
/**
390392
* Sets options that will be passed to {@link
@@ -396,15 +398,25 @@ public static class WorkerDeploymentConfigurationProperties {
396398
* io.temporal.worker.WorkerDeploymentOptions.Builder#setUseVersioning(boolean)}
397399
* @param defaultVersioningBehavior defines {@link
398400
* io.temporal.worker.WorkerDeploymentOptions.Builder#setDefaultVersioningBehavior(VersioningBehavior)}
401+
* @param deploymentName defines the deployment name component of {@link
402+
* io.temporal.worker.WorkerDeploymentOptions.Builder#setVersion(WorkerDeploymentVersion)}.
403+
* Exclusive with `deploymentVersion`.
404+
* @param buildId defines the build id component of {@link
405+
* io.temporal.worker.WorkerDeploymentOptions.Builder#setVersion(WorkerDeploymentVersion)}.
406+
* Exclusive with `deploymentVersion`.
399407
*/
400408
@ConstructorBinding
401409
public WorkerDeploymentConfigurationProperties(
402-
@Nullable String deploymentVersion,
410+
@Deprecated @Nullable String deploymentVersion,
403411
@Nullable Boolean useVersioning,
404-
@Nullable VersioningBehavior defaultVersioningBehavior) {
412+
@Nullable VersioningBehavior defaultVersioningBehavior,
413+
@Nullable String deploymentName,
414+
@Nullable String buildId) {
405415
this.deploymentVersion = deploymentVersion;
406416
this.useVersioning = useVersioning;
407417
this.defaultVersioningBehavior = defaultVersioningBehavior;
418+
this.deploymentName = deploymentName;
419+
this.buildId = buildId;
408420
}
409421

410422
@Nullable
@@ -421,5 +433,15 @@ public Boolean getUseVersioning() {
421433
public VersioningBehavior getDefaultVersioningBehavior() {
422434
return defaultVersioningBehavior;
423435
}
436+
437+
@Nullable
438+
public String getDeploymentName() {
439+
return deploymentName;
440+
}
441+
442+
@Nullable
443+
public String getBuildId() {
444+
return buildId;
445+
}
424446
}
425447
}

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

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,28 @@ WorkerOptions createWorkerOptions() {
132132
WorkerDeploymentOptions.Builder opts = WorkerDeploymentOptions.newBuilder();
133133
Optional.ofNullable(workerDeploymentConfiguration.getUseVersioning())
134134
.ifPresent(opts::setUseVersioning);
135-
Optional.ofNullable(workerDeploymentConfiguration.getDeploymentVersion())
136-
.ifPresent((v) -> opts.setVersion(WorkerDeploymentVersion.fromCanonicalString(v)));
137135
Optional.ofNullable(workerDeploymentConfiguration.getDefaultVersioningBehavior())
138136
.ifPresent(opts::setDefaultVersioningBehavior);
137+
138+
if (workerDeploymentConfiguration.getDeploymentName() != null
139+
|| workerDeploymentConfiguration.getBuildId() != null) {
140+
if (workerDeploymentConfiguration.getBuildId() == null
141+
|| workerDeploymentConfiguration.getDeploymentName() == null) {
142+
throw new IllegalArgumentException(
143+
"deploymentName and buildId must both be set when either is specified");
144+
}
145+
if (workerDeploymentConfiguration.getDeploymentVersion() != null) {
146+
throw new IllegalArgumentException(
147+
"deploymentVersion is exclusive with deploymentName and buildId");
148+
}
149+
opts.setVersion(
150+
new WorkerDeploymentVersion(
151+
workerDeploymentConfiguration.getDeploymentName(),
152+
workerDeploymentConfiguration.getBuildId()));
153+
} else {
154+
Optional.ofNullable(workerDeploymentConfiguration.getDeploymentVersion())
155+
.ifPresent((v) -> opts.setVersion(WorkerDeploymentVersion.fromCanonicalString(v)));
156+
}
139157
options.setDeploymentOptions(opts.build());
140158
}
141159
}

temporal-spring-boot-autoconfigure/src/test/java/io/temporal/spring/boot/autoconfigure/WorkerVersioningMissingAnnotationTest.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,39 @@ void testFailsToLoad() {
2929
assertThat(e).hasMessageContaining("must have a VersioningBehavior set");
3030
}
3131

32+
@Test
33+
void testFailsWithMissingBuildId() {
34+
BeanCreationException e =
35+
assertThrows(
36+
BeanCreationException.class,
37+
() -> {
38+
try (ConfigurableApplicationContext ignored =
39+
new SpringApplicationBuilder(Configuration.class)
40+
.profiles("worker-versioning-need-both-deployname-buildid")
41+
.run()) {
42+
fail("Should not load");
43+
}
44+
});
45+
assertThat(e).hasMessageContaining("deploymentName and buildId must both be set");
46+
}
47+
48+
@Test
49+
void testFailsWithBothVersionOptions() {
50+
BeanCreationException e =
51+
assertThrows(
52+
BeanCreationException.class,
53+
() -> {
54+
try (ConfigurableApplicationContext ignored =
55+
new SpringApplicationBuilder(Configuration.class)
56+
.profiles("worker-versioning-cant-use-old-version-and-new")
57+
.run()) {
58+
fail("Should not load");
59+
}
60+
});
61+
assertThat(e)
62+
.hasMessageContaining("deploymentVersion is exclusive with deploymentName and buildId");
63+
}
64+
3265
@ComponentScan(
3366
excludeFilters =
3467
@ComponentScan.Filter(

temporal-spring-boot-autoconfigure/src/test/resources/application.yml

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,8 @@ spring:
190190
name: mainWorker
191191
deployment-properties:
192192
default-versioning-behavior: PINNED
193-
deployment-version: "dname.bid"
193+
deployment-name: "dname"
194+
build-id: "bid"
194195
use-versioning: true
195196

196197
---
@@ -210,3 +211,39 @@ spring:
210211
# missing default is the key thing here
211212
deployment-version: "dname.bid"
212213
use-versioning: true
214+
---
215+
spring:
216+
config:
217+
activate:
218+
on-profile: worker-versioning-need-both-deployname-buildid
219+
temporal:
220+
namespace: UnitTest
221+
workers-auto-discovery:
222+
packages:
223+
- io.temporal.spring.boot.autoconfigure.workerversioning
224+
workers:
225+
- task-queue: UnitTest
226+
name: mainWorker
227+
deployment-properties:
228+
use-versioning: true
229+
default-versioning-behavior: PINNED
230+
deployment-name: "dname"
231+
---
232+
spring:
233+
config:
234+
activate:
235+
on-profile: worker-versioning-cant-use-old-version-and-new
236+
temporal:
237+
namespace: UnitTest
238+
workers-auto-discovery:
239+
packages:
240+
- io.temporal.spring.boot.autoconfigure.workerversioning
241+
workers:
242+
- task-queue: UnitTest
243+
name: mainWorker
244+
deployment-properties:
245+
use-versioning: true
246+
default-versioning-behavior: PINNED
247+
deployment-name: "dname"
248+
build-id: "bid"
249+
deployment-version: "dname.bid"

0 commit comments

Comments
 (0)