-
Notifications
You must be signed in to change notification settings - Fork 760
Match name with ResourceCommandService #10370
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
+112
−2
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
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 |
|---|---|---|
|
|
@@ -434,11 +434,25 @@ private async Task<ResourceEvent> WaitForResourceCoreAsync(string resourceName, | |
| /// <summary> | ||
| /// Attempts to retrieve the current state of a resource by resourceId. | ||
| /// </summary> | ||
| /// <param name="resourceId">The resource id.</param> | ||
| /// <remarks> | ||
| /// <para> | ||
| /// A resource id can be either the unique id of the resource or the displayed resource name. | ||
| /// </para> | ||
| /// <para> | ||
| /// Projects, executables and containers typically have a unique id that combines the display name and a unique suffix. For example, a resource named <c>cache</c> could have a resource id of <c>cache-abcdwxyz</c>. | ||
| /// This id is used to uniquely identify the resource in the app host. | ||
| /// </para> | ||
| /// <para> | ||
| /// The resource name can be also be used to retrieve the resource state, but it must be unique. If there are multiple resources with the same name, then this method will not return a match. | ||
| /// For example, if a resource named <c>cache</c> has multiple replicas, then specifing <c>cache</c> won't return a match. | ||
| /// </para> | ||
| /// </remarks> | ||
| /// <param name="resourceId">The resource id. This id can either exactly match the unique id of the resource or the displayed resource name if the resource name doesn't have duplicas (i.e. replicas).</param> | ||
JamesNK marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| /// <param name="resourceEvent">When this method returns, contains the <see cref="ResourceEvent"/> for the specified resource id, if found; otherwise, <see langword="null"/>.</param> | ||
| /// <returns><see langword="true"/> if specified resource id was found; otherwise, <see langword="false"/>.</returns> | ||
| public bool TryGetCurrentState(string resourceId, [NotNullWhen(true)] out ResourceEvent? resourceEvent) | ||
| { | ||
| // Find exact match. | ||
| if (_resourceNotificationStates.TryGetValue(resourceId, out var state)) | ||
| { | ||
| if (state.LastSnapshot is { } snapshot) | ||
|
|
@@ -448,6 +462,29 @@ public bool TryGetCurrentState(string resourceId, [NotNullWhen(true)] out Resour | |
| } | ||
| } | ||
|
|
||
| // Fallback to finding match on resource name. If there are multiple resources with the same name (e.g. replicas) then don't match. | ||
| KeyValuePair<string, ResourceNotificationState>? nameMatch = null; | ||
| foreach (var matchingResource in _resourceNotificationStates.Where(s => string.Equals(s.Value.Resource.Name, resourceId, StringComparisons.ResourceName))) | ||
| { | ||
| if (nameMatch == null) | ||
| { | ||
| nameMatch = matchingResource; | ||
| } | ||
| else | ||
| { | ||
| // Second match found, so we can't return a match based on the name. | ||
| nameMatch = null; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Replicas?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes |
||
| break; | ||
| } | ||
| } | ||
|
|
||
| if (nameMatch is { } m && m.Value.LastSnapshot != null) | ||
| { | ||
| resourceEvent = new ResourceEvent(m.Value.Resource, m.Key, m.Value.LastSnapshot); | ||
| return true; | ||
| } | ||
|
|
||
| // No match. | ||
| resourceEvent = null; | ||
| return false; | ||
| } | ||
|
|
||
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.
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.