|
| 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.common; |
| 22 | + |
| 23 | +import java.util.Objects; |
| 24 | +import javax.annotation.Nonnull; |
| 25 | +import javax.annotation.Nullable; |
| 26 | + |
| 27 | +/** Represents the version of a specific worker deployment. */ |
| 28 | +@Experimental |
| 29 | +public class WorkerDeploymentVersion { |
| 30 | + private final String deploymentName; |
| 31 | + private final String buildId; |
| 32 | + |
| 33 | + /** Build a worker deployment version from an explicit deployment name and build ID. */ |
| 34 | + public WorkerDeploymentVersion(@Nonnull String deploymentName, @Nonnull String buildId) { |
| 35 | + this.deploymentName = deploymentName; |
| 36 | + this.buildId = buildId; |
| 37 | + } |
| 38 | + |
| 39 | + /** |
| 40 | + * Build a worker deployment version from a canonical string representation. |
| 41 | + * |
| 42 | + * @param canonicalString The canonical string representation of the worker deployment version, |
| 43 | + * formatted as "deploymentName.buildId". Deployment name must not have a "." in it. |
| 44 | + * @return A new instance of {@link WorkerDeploymentVersion}. |
| 45 | + * @throws IllegalArgumentException if the input string is not in the expected format. |
| 46 | + */ |
| 47 | + public static WorkerDeploymentVersion fromCanonicalString(String canonicalString) { |
| 48 | + String[] parts = canonicalString.split("\\.", 2); |
| 49 | + if (parts.length != 2) { |
| 50 | + throw new IllegalArgumentException( |
| 51 | + "Invalid canonical string format. Expected 'deploymentName.buildId'"); |
| 52 | + } |
| 53 | + return new WorkerDeploymentVersion(parts[0], parts[1]); |
| 54 | + } |
| 55 | + |
| 56 | + /** |
| 57 | + * @return The canonical string representation of this worker deployment version. |
| 58 | + */ |
| 59 | + public String toCanonicalString() { |
| 60 | + return deploymentName + "." + buildId; |
| 61 | + } |
| 62 | + |
| 63 | + /** |
| 64 | + * @return The name of the deployment. |
| 65 | + */ |
| 66 | + @Nullable // Marked nullable for future compatibility with custom strings |
| 67 | + public String getDeploymentName() { |
| 68 | + return deploymentName; |
| 69 | + } |
| 70 | + |
| 71 | + /** |
| 72 | + * @return The Build ID of this version. |
| 73 | + */ |
| 74 | + @Nullable // Marked nullable for future compatibility with custom strings |
| 75 | + public String getBuildId() { |
| 76 | + return buildId; |
| 77 | + } |
| 78 | + |
| 79 | + @Override |
| 80 | + public boolean equals(Object o) { |
| 81 | + if (o == null || getClass() != o.getClass()) return false; |
| 82 | + WorkerDeploymentVersion that = (WorkerDeploymentVersion) o; |
| 83 | + return Objects.equals(deploymentName, that.deploymentName) |
| 84 | + && Objects.equals(buildId, that.buildId); |
| 85 | + } |
| 86 | + |
| 87 | + @Override |
| 88 | + public int hashCode() { |
| 89 | + return Objects.hash(deploymentName, buildId); |
| 90 | + } |
| 91 | + |
| 92 | + @Override |
| 93 | + public String toString() { |
| 94 | + return "WorkerDeploymentVersion{" |
| 95 | + + "deploymentName='" |
| 96 | + + deploymentName |
| 97 | + + '\'' |
| 98 | + + ", buildId='" |
| 99 | + + buildId |
| 100 | + + '\'' |
| 101 | + + '}'; |
| 102 | + } |
| 103 | +} |
0 commit comments