Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,8 @@ public static class WorkerDeploymentConfigurationProperties {
private final @Nullable String deploymentVersion;
private final @Nullable Boolean useVersioning;
private final @Nullable VersioningBehavior defaultVersioningBehavior;
private final @Nullable String deploymentName;
private final @Nullable String buildId;

/**
* Sets options that will be passed to {@link
Expand All @@ -396,15 +398,25 @@ public static class WorkerDeploymentConfigurationProperties {
* io.temporal.worker.WorkerDeploymentOptions.Builder#setUseVersioning(boolean)}
* @param defaultVersioningBehavior defines {@link
* io.temporal.worker.WorkerDeploymentOptions.Builder#setDefaultVersioningBehavior(VersioningBehavior)}
* @param deploymentName defines the deployment name component of {@link
* io.temporal.worker.WorkerDeploymentOptions.Builder#setVersion(WorkerDeploymentVersion)}.
* Exclusive with `deploymentVersion`.
* @param buildId defines the build id component of {@link
* io.temporal.worker.WorkerDeploymentOptions.Builder#setVersion(WorkerDeploymentVersion)}.
* Exclusive with `deploymentVersion`.
*/
@ConstructorBinding
public WorkerDeploymentConfigurationProperties(
@Nullable String deploymentVersion,
@Deprecated @Nullable String deploymentVersion,
@Nullable Boolean useVersioning,
@Nullable VersioningBehavior defaultVersioningBehavior) {
@Nullable VersioningBehavior defaultVersioningBehavior,
@Nullable String deploymentName,
@Nullable String buildId) {
this.deploymentVersion = deploymentVersion;
this.useVersioning = useVersioning;
this.defaultVersioningBehavior = defaultVersioningBehavior;
this.deploymentName = deploymentName;
this.buildId = buildId;
}

@Nullable
Expand All @@ -421,5 +433,15 @@ public Boolean getUseVersioning() {
public VersioningBehavior getDefaultVersioningBehavior() {
return defaultVersioningBehavior;
}

@Nullable
public String getDeploymentName() {
return deploymentName;
}

@Nullable
public String getBuildId() {
return buildId;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,28 @@ WorkerOptions createWorkerOptions() {
WorkerDeploymentOptions.Builder opts = WorkerDeploymentOptions.newBuilder();
Optional.ofNullable(workerDeploymentConfiguration.getUseVersioning())
.ifPresent(opts::setUseVersioning);
Optional.ofNullable(workerDeploymentConfiguration.getDeploymentVersion())
.ifPresent((v) -> opts.setVersion(WorkerDeploymentVersion.fromCanonicalString(v)));
Optional.ofNullable(workerDeploymentConfiguration.getDefaultVersioningBehavior())
.ifPresent(opts::setDefaultVersioningBehavior);

if (workerDeploymentConfiguration.getDeploymentName() != null
|| workerDeploymentConfiguration.getBuildId() != null) {
if (workerDeploymentConfiguration.getBuildId() == null
|| workerDeploymentConfiguration.getDeploymentName() == null) {
throw new IllegalArgumentException(
"deploymentName and buildId must both be set when either is specified");
}
if (workerDeploymentConfiguration.getDeploymentVersion() != null) {
throw new IllegalArgumentException(
"deploymentVersion is exclusive with deploymentName and buildId");
}
opts.setVersion(
new WorkerDeploymentVersion(
workerDeploymentConfiguration.getDeploymentName(),
workerDeploymentConfiguration.getBuildId()));
} else {
Optional.ofNullable(workerDeploymentConfiguration.getDeploymentVersion())
.ifPresent((v) -> opts.setVersion(WorkerDeploymentVersion.fromCanonicalString(v)));
}
options.setDeploymentOptions(opts.build());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,39 @@ void testFailsToLoad() {
assertThat(e).hasMessageContaining("must have a VersioningBehavior set");
}

@Test
void testFailsWithMissingBuildId() {
BeanCreationException e =
assertThrows(
BeanCreationException.class,
() -> {
try (ConfigurableApplicationContext ignored =
new SpringApplicationBuilder(Configuration.class)
.profiles("worker-versioning-need-both-deployname-buildid")
.run()) {
fail("Should not load");
}
});
assertThat(e).hasMessageContaining("deploymentName and buildId must both be set");
}

@Test
void testFailsWithBothVersionOptions() {
BeanCreationException e =
assertThrows(
BeanCreationException.class,
() -> {
try (ConfigurableApplicationContext ignored =
new SpringApplicationBuilder(Configuration.class)
.profiles("worker-versioning-cant-use-old-version-and-new")
.run()) {
fail("Should not load");
}
});
assertThat(e)
.hasMessageContaining("deploymentVersion is exclusive with deploymentName and buildId");
}

@ComponentScan(
excludeFilters =
@ComponentScan.Filter(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,8 @@ spring:
name: mainWorker
deployment-properties:
default-versioning-behavior: PINNED
deployment-version: "dname.bid"
deployment-name: "dname"
build-id: "bid"
use-versioning: true

---
Expand All @@ -210,3 +211,39 @@ spring:
# missing default is the key thing here
deployment-version: "dname.bid"
use-versioning: true
---
spring:
config:
activate:
on-profile: worker-versioning-need-both-deployname-buildid
temporal:
namespace: UnitTest
workers-auto-discovery:
packages:
- io.temporal.spring.boot.autoconfigure.workerversioning
workers:
- task-queue: UnitTest
name: mainWorker
deployment-properties:
use-versioning: true
default-versioning-behavior: PINNED
deployment-name: "dname"
---
spring:
config:
activate:
on-profile: worker-versioning-cant-use-old-version-and-new
temporal:
namespace: UnitTest
workers-auto-discovery:
packages:
- io.temporal.spring.boot.autoconfigure.workerversioning
workers:
- task-queue: UnitTest
name: mainWorker
deployment-properties:
use-versioning: true
default-versioning-behavior: PINNED
deployment-name: "dname"
build-id: "bid"
deployment-version: "dname.bid"
Loading