-
Notifications
You must be signed in to change notification settings - Fork 326
Add versioning to DTFx orchestration dispatch #1201
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| // ---------------------------------------------------------------------------------- | ||
| // Copyright Microsoft Corporation | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
| // ---------------------------------------------------------------------------------- | ||
|
|
||
| using DurableTask.Core.Settings; | ||
| using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
|
|
||
| namespace DurableTask.Core.Tests | ||
| { | ||
| [TestClass] | ||
| public class VersionSettingsTests | ||
| { | ||
| [TestMethod] | ||
| [DataRow("1.0.0", "1.0.0", 0)] | ||
| [DataRow("1.1.0", "1.0.0", 1)] | ||
| [DataRow("1.0.0", "1.1.0", -1)] | ||
| [DataRow("1", "1", 0)] | ||
| [DataRow("2", "1", 1)] | ||
| [DataRow("1", "2", -1)] | ||
| [DataRow("", "1", -1)] | ||
| [DataRow("1", "", 1)] | ||
| [DataRow("", "", 0)] | ||
| public void TestVersionComparison(string orchVersion, string settingVersion, int expectedComparison) | ||
| { | ||
| int result = VersioningSettings.CompareVersions(orchVersion, settingVersion); | ||
|
|
||
| if (expectedComparison == 0) | ||
| { | ||
| Assert.AreEqual(0, result, $"Expected {orchVersion} to be equal to {settingVersion}"); | ||
| } | ||
| else if (expectedComparison < 0) | ||
| { | ||
| Assert.IsTrue(result < 0, $"Expected {orchVersion} to be less than {settingVersion}"); | ||
| } | ||
| else | ||
| { | ||
| Assert.IsTrue(result > 0, $"Expected {orchVersion} to be greater than {settingVersion}"); | ||
| } | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,119 @@ | ||
| // ---------------------------------------------------------------------------------- | ||
| // Copyright Microsoft Corporation | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
| // ---------------------------------------------------------------------------------- | ||
|
|
||
| using System; | ||
|
|
||
| namespace DurableTask.Core.Settings | ||
| { | ||
| /// <summary> | ||
| /// Collection of settings that define the overall versioning behavior. | ||
| /// </summary> | ||
| public class VersioningSettings | ||
| { | ||
| /// <summary> | ||
| /// Defines the version matching strategy for the Durable Task worker. | ||
| /// </summary> | ||
| public enum VersionMatchStrategy | ||
| { | ||
| /// <summary> | ||
| /// Ignore Orchestration version, all work received is processed. | ||
| /// </summary> | ||
| None = 0, | ||
|
|
||
| /// <summary> | ||
| /// Worker will only process Tasks from Orchestrations with the same version as the worker. | ||
| /// </summary> | ||
| Strict = 1, | ||
|
|
||
| /// <summary> | ||
| /// Worker will process Tasks from Orchestrations whose version is less than or equal to the worker. | ||
| /// </summary> | ||
| CurrentOrOlder = 2, | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Defines the versioning failure strategy for the Durable Task worker. | ||
| /// </summary> | ||
| public enum VersionFailureStrategy | ||
| { | ||
| /// <summary> | ||
| /// Do not change the orchestration state if the version does not adhere to the matching strategy. | ||
| /// </summary> | ||
| Reject = 0, | ||
|
|
||
| /// <summary> | ||
| /// Fail the orchestration if the version does not adhere to the matching strategy. | ||
| /// </summary> | ||
| Fail = 1, | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets the version associated with the settings. | ||
| /// </summary> | ||
| public string Version { get; set; } = string.Empty; | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets the <see cref="VersionMatchStrategy"/> that is used for matching versions. | ||
| /// </summary> | ||
| public VersionMatchStrategy MatchStrategy { get; set; } = VersionMatchStrategy.None; | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets the <see cref="VersionFailureStrategy"/> that is used to determine what happens on a versioning failure. | ||
| /// </summary> | ||
| public VersionFailureStrategy FailureStrategy { get; set; } = VersionFailureStrategy.Reject; | ||
|
|
||
| /// <summary> | ||
| /// Compare two versions to each other. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// This method's comparison is handled in the following order: | ||
| /// 1. The versions are checked if they are empty (non-versioned). Both being empty signifies equality. | ||
| /// 2. If sourceVersion is empty but otherVersion is defined, this is treated as the source being less than the other. | ||
| /// 3. If otherVersion is empty but sourceVersion is defined, this is treated as the source being greater than the other. | ||
| /// 4. Both versions are attempted to be parsed into System.Version and compared as such. | ||
| /// 5. If all else fails, a direct string comparison is done between the versions. | ||
| /// </remarks> | ||
| /// <param name="sourceVersion">The source version that will be compared against the other version.</param> | ||
| /// <param name="otherVersion">The other version to compare against.</param> | ||
| /// <returns>An int representing how sourceVersion compares to otherVersion.</returns> | ||
| public static int CompareVersions(string sourceVersion, string otherVersion) | ||
| { | ||
| // Both versions are empty, treat as equal. | ||
| if (string.IsNullOrWhiteSpace(sourceVersion) && string.IsNullOrWhiteSpace(otherVersion)) | ||
| { | ||
| return 0; | ||
| } | ||
|
|
||
| // An empty version in the context is always less than a defined version in the parameter. | ||
| if (string.IsNullOrWhiteSpace(sourceVersion)) | ||
| { | ||
| return -1; | ||
| } | ||
|
|
||
| // An empty version in the parameter is always less than a defined version in the context. | ||
| if (string.IsNullOrWhiteSpace(otherVersion)) | ||
| { | ||
| return 1; | ||
| } | ||
|
|
||
| // If both versions use the .NET Version class, return that comparison. | ||
| if (System.Version.TryParse(sourceVersion, out Version parsedSourceVersion) && System.Version.TryParse(otherVersion, out Version parsedOtherVersion)) | ||
| { | ||
| return parsedSourceVersion.CompareTo(parsedOtherVersion); | ||
| } | ||
|
|
||
| // If we have gotten to here, we don't know the syntax of the versions we are comparing, use a string comparison as a final check. | ||
| return string.Compare(sourceVersion, otherVersion, StringComparison.OrdinalIgnoreCase); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.