|
| 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.client; |
| 22 | + |
| 23 | +import io.temporal.api.workflowservice.v1.UpdateWorkerBuildIdCompatibilityRequest; |
| 24 | +import io.temporal.common.Experimental; |
| 25 | +import javax.annotation.Nonnull; |
| 26 | + |
| 27 | +/** |
| 28 | + * The implementations of this class can be passed as parameters to {@link |
| 29 | + * WorkflowClient#updateWorkerBuildIdCompatability(String, BuildIdOperation)} |
| 30 | + * |
| 31 | + * <p>See each public static method to learn about and construct the available operations. |
| 32 | + */ |
| 33 | +@Experimental |
| 34 | +public abstract class BuildIdOperation { |
| 35 | + private BuildIdOperation() {} |
| 36 | + |
| 37 | + abstract void augmentBuilder(UpdateWorkerBuildIdCompatibilityRequest.Builder builder); |
| 38 | + |
| 39 | + /** |
| 40 | + * This operation adds a new Build Id into a new set, which will be used as the default set for |
| 41 | + * the queue. This means all new workflows will start on this Build Id. |
| 42 | + * |
| 43 | + * @param buildId The Build Id to add as the new overall default. |
| 44 | + */ |
| 45 | + public static BuildIdOperation newIdInNewDefaultSet(@Nonnull String buildId) { |
| 46 | + return new NewIdInNewDefaultSet(buildId); |
| 47 | + } |
| 48 | + |
| 49 | + /** |
| 50 | + * This operation adds a new Build Id into an existing compatible set. The newly added ID becomes |
| 51 | + * the default for that compatible set, and thus new workflow tasks for workflows which have been |
| 52 | + * executing on workers in that set will now start on this new Build Id. |
| 53 | + * |
| 54 | + * @param buildId The Build Id to add to an existing compatible set. |
| 55 | + * @param existingCompatibleBuildId A Build Id which must already be defined on the task queue, |
| 56 | + * and is used to find the compatible set to add the new ID to. |
| 57 | + * @param makeSetDefault If set to true, the targeted set will also be promoted to become the |
| 58 | + * overall default set for the queue. |
| 59 | + */ |
| 60 | + public static BuildIdOperation newCompatibleVersion( |
| 61 | + @Nonnull String buildId, @Nonnull String existingCompatibleBuildId, boolean makeSetDefault) { |
| 62 | + return new NewCompatibleVersion(buildId, existingCompatibleBuildId, makeSetDefault); |
| 63 | + } |
| 64 | + |
| 65 | + /** |
| 66 | + * Performs {@link #newCompatibleVersion(String, String, boolean)}, with `makeSetDefault` set to |
| 67 | + * false. |
| 68 | + */ |
| 69 | + public static BuildIdOperation newCompatibleVersion( |
| 70 | + @Nonnull String buildId, @Nonnull String existingCompatibleBuildId) { |
| 71 | + return newCompatibleVersion(buildId, existingCompatibleBuildId, false); |
| 72 | + } |
| 73 | + |
| 74 | + /** |
| 75 | + * This operation promotes a set to become the overall default set for the queue. |
| 76 | + * |
| 77 | + * @param buildId An existing Build Id which is used to find the set to be promoted. |
| 78 | + */ |
| 79 | + public static BuildIdOperation promoteSetByBuildId(@Nonnull String buildId) { |
| 80 | + return new PromoteSetByBuildId(buildId); |
| 81 | + } |
| 82 | + |
| 83 | + /** |
| 84 | + * This operation promotes a Build Id inside some compatible set to become the default ID in that |
| 85 | + * set. |
| 86 | + * |
| 87 | + * @param buildId An existing Build Id which will be promoted within its compatible set. |
| 88 | + */ |
| 89 | + public static BuildIdOperation promoteBuildIdWithinSet(@Nonnull String buildId) { |
| 90 | + return new PromoteBuildIdWithinSet(buildId); |
| 91 | + } |
| 92 | + |
| 93 | + /** |
| 94 | + * This operation merges two sets into one set, thus declaring all the Build Ids in both as |
| 95 | + * compatible with one another. The default of the primary set is maintained as the merged set's |
| 96 | + * overall default. |
| 97 | + * |
| 98 | + * @param primaryBuildId A Build Id which is used to find the primary set to be merged. |
| 99 | + * @param secondaryBuildId A Build Id which is used to find the secondary set to be merged. |
| 100 | + */ |
| 101 | + public static BuildIdOperation mergeSets( |
| 102 | + @Nonnull String primaryBuildId, @Nonnull String secondaryBuildId) { |
| 103 | + return new MergeSets(primaryBuildId, secondaryBuildId); |
| 104 | + } |
| 105 | + |
| 106 | + private static class NewIdInNewDefaultSet extends BuildIdOperation { |
| 107 | + private final String buildId; |
| 108 | + |
| 109 | + public NewIdInNewDefaultSet(String buildId) { |
| 110 | + this.buildId = buildId; |
| 111 | + } |
| 112 | + |
| 113 | + @Override |
| 114 | + void augmentBuilder(UpdateWorkerBuildIdCompatibilityRequest.Builder builder) { |
| 115 | + builder.setAddNewBuildIdInNewDefaultSet(buildId); |
| 116 | + } |
| 117 | + } |
| 118 | + |
| 119 | + private static class NewCompatibleVersion extends BuildIdOperation { |
| 120 | + private final String buildId; |
| 121 | + private final String existingCompatibleBuildId; |
| 122 | + private final boolean makeSetDefault; |
| 123 | + |
| 124 | + public NewCompatibleVersion( |
| 125 | + String buildId, String existingCompatibleBuildId, boolean makeSetDefault) { |
| 126 | + this.buildId = buildId; |
| 127 | + this.existingCompatibleBuildId = existingCompatibleBuildId; |
| 128 | + this.makeSetDefault = makeSetDefault; |
| 129 | + } |
| 130 | + |
| 131 | + @Override |
| 132 | + void augmentBuilder(UpdateWorkerBuildIdCompatibilityRequest.Builder builder) { |
| 133 | + builder.setAddNewCompatibleBuildId( |
| 134 | + UpdateWorkerBuildIdCompatibilityRequest.AddNewCompatibleVersion.newBuilder() |
| 135 | + .setNewBuildId(buildId) |
| 136 | + .setExistingCompatibleBuildId(existingCompatibleBuildId) |
| 137 | + .setMakeSetDefault(makeSetDefault) |
| 138 | + .build()); |
| 139 | + } |
| 140 | + } |
| 141 | + |
| 142 | + private static class PromoteSetByBuildId extends BuildIdOperation { |
| 143 | + private final String buildId; |
| 144 | + |
| 145 | + public PromoteSetByBuildId(String buildId) { |
| 146 | + this.buildId = buildId; |
| 147 | + } |
| 148 | + |
| 149 | + @Override |
| 150 | + void augmentBuilder(UpdateWorkerBuildIdCompatibilityRequest.Builder builder) { |
| 151 | + builder.setPromoteSetByBuildId(buildId); |
| 152 | + } |
| 153 | + } |
| 154 | + |
| 155 | + private static class PromoteBuildIdWithinSet extends BuildIdOperation { |
| 156 | + private final String buildId; |
| 157 | + |
| 158 | + public PromoteBuildIdWithinSet(String buildId) { |
| 159 | + this.buildId = buildId; |
| 160 | + } |
| 161 | + |
| 162 | + @Override |
| 163 | + void augmentBuilder(UpdateWorkerBuildIdCompatibilityRequest.Builder builder) { |
| 164 | + builder.setPromoteBuildIdWithinSet(buildId); |
| 165 | + } |
| 166 | + } |
| 167 | + |
| 168 | + private static class MergeSets extends BuildIdOperation { |
| 169 | + private final String primaryBuildId; |
| 170 | + private final String secondaryBuildId; |
| 171 | + |
| 172 | + public MergeSets(String primaryBuildId, String secondaryBuildId) { |
| 173 | + this.primaryBuildId = primaryBuildId; |
| 174 | + this.secondaryBuildId = secondaryBuildId; |
| 175 | + } |
| 176 | + |
| 177 | + @Override |
| 178 | + void augmentBuilder(UpdateWorkerBuildIdCompatibilityRequest.Builder builder) { |
| 179 | + builder.setMergeSets( |
| 180 | + UpdateWorkerBuildIdCompatibilityRequest.MergeSets.newBuilder() |
| 181 | + .setPrimarySetBuildId(primaryBuildId) |
| 182 | + .setSecondarySetBuildId(secondaryBuildId) |
| 183 | + .build()); |
| 184 | + } |
| 185 | + } |
| 186 | +} |
0 commit comments