-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #79 from neuroglia-io/fix-unfault-subscription
Repaired the ability to recover a faulted subscription without restart
- Loading branch information
Showing
6 changed files
with
211 additions
and
9 deletions.
There are no files selected for viewing
This file contains 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 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 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
80 changes: 80 additions & 0 deletions
80
...re/CloudStreams.Core.Application/Commands/Resources/Generic/PatchResourceStatusCommand.cs
This file contains 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,80 @@ | ||
// Copyright © 2024-Present The Cloud Streams Authors | ||
// | ||
// 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. | ||
|
||
namespace CloudStreams.Core.Application.Commands.Resources.Generic; | ||
|
||
/// <summary> | ||
/// Represents the <see cref="ICommand"/> used to patch the status of an existing <see cref="IResource"/> | ||
/// </summary> | ||
/// <typeparam name="TResource">The type of <see cref="IResource"/> to patch</typeparam> | ||
public class PatchResourceStatusCommand<TResource> | ||
: Command<TResource> | ||
where TResource : class, IResource, new() | ||
{ | ||
|
||
/// <summary> | ||
/// Initializes a new <see cref="PatchResourceStatusCommand{TResource}"/> | ||
/// </summary> | ||
/// <param name="name">The name of the <see cref="IResource"/> to patch</param> | ||
/// <param name="namespace">The namespace the <see cref="IResource"/> to patch belongs to</param> | ||
/// <param name="patch">The patch to apply</param> | ||
/// <param name="dryRun">A boolean indicating whether or not to persist changes</param> | ||
public PatchResourceStatusCommand(string name, string? @namespace, Patch patch, bool dryRun) | ||
{ | ||
if (string.IsNullOrWhiteSpace(name)) throw new ArgumentNullException(nameof(name)); | ||
this.Name = name; | ||
this.Namespace = @namespace; | ||
this.Patch = patch ?? throw new ArgumentNullException(nameof(patch)); | ||
this.DryRun = dryRun; | ||
} | ||
|
||
/// <summary> | ||
/// Gets the name of the <see cref="IResource"/> to patch | ||
/// </summary> | ||
public string Name { get; } | ||
|
||
/// <summary> | ||
/// Gets the name of the <see cref="IResource"/> to patch | ||
/// </summary> | ||
public string? Namespace { get; } | ||
|
||
/// <summary> | ||
/// Gets the patch to apply | ||
/// </summary> | ||
public Patch Patch { get; } | ||
|
||
/// <summary> | ||
/// Gets a boolean indicating whether or not to persist changes | ||
/// </summary> | ||
public bool DryRun { get; } | ||
|
||
} | ||
|
||
/// <summary> | ||
/// Represents the service used to handle <see cref="PatchResourceStatusCommand"/>s | ||
/// </summary> | ||
/// <typeparam name="TResource">The type of <see cref="IResource"/> to patch</typeparam> | ||
/// <param name="repository">The service used to manage <see cref="IResource"/>s</param> | ||
public class PatchResourceStatusCommandHandler<TResource>(IResourceRepository repository) | ||
: ICommandHandler<PatchResourceStatusCommand<TResource>, TResource> | ||
where TResource : class, IResource, new() | ||
{ | ||
|
||
/// <inheritdoc/> | ||
public virtual async Task<IOperationResult<TResource>> HandleAsync(PatchResourceStatusCommand<TResource> command, CancellationToken cancellationToken) | ||
{ | ||
var resource = await repository.PatchStatusAsync<TResource>(command.Patch, command.Name, command.Namespace, null, command.DryRun, cancellationToken).ConfigureAwait(false); | ||
return this.Ok(resource); | ||
} | ||
|
||
} |
105 changes: 105 additions & 0 deletions
105
src/core/CloudStreams.Core.Application/Commands/Resources/PatchResourceStatusCommand.cs
This file contains 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,105 @@ | ||
// Copyright © 2024-Present The Cloud Streams Authors | ||
// | ||
// 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. | ||
|
||
namespace CloudStreams.Core.Application.Commands.Resources; | ||
|
||
/// <summary> | ||
/// Represents the <see cref="ICommand"/> used to patch the status of an existing <see cref="IResource"/> | ||
/// </summary> | ||
public class PatchResourceStatusCommand | ||
: Command<IResource> | ||
{ | ||
|
||
/// <summary> | ||
/// Initializes a new <see cref="PatchResourceStatusCommand"/> | ||
/// </summary> | ||
protected PatchResourceStatusCommand() { } | ||
|
||
/// <summary> | ||
/// Initializes a new <see cref="PatchResourceStatusCommand"/> | ||
/// </summary> | ||
/// <param name="group">The API group the resource to patch belongs to</param> | ||
/// <param name="version">The version of the resource to patch</param> | ||
/// <param name="plural">The plural name of the type of resource to patch</param> | ||
/// <param name="name">The name of the <see cref="IResource"/> to patch</param> | ||
/// <param name="namespace">The namespace the <see cref="IResource"/> to patch belongs to</param> | ||
/// <param name="patch">The patch to apply</param> | ||
/// <param name="dryRun">A boolean indicating whether or not to persist changes</param> | ||
public PatchResourceStatusCommand(string group, string version, string plural, string name, string? @namespace, Patch patch, bool dryRun) | ||
{ | ||
if (string.IsNullOrWhiteSpace(group)) throw new ArgumentNullException(nameof(group)); | ||
if (string.IsNullOrWhiteSpace(version)) throw new ArgumentNullException(nameof(version)); | ||
if (string.IsNullOrWhiteSpace(plural)) throw new ArgumentNullException(nameof(plural)); | ||
if (string.IsNullOrWhiteSpace(name)) throw new ArgumentNullException(nameof(name)); | ||
this.Group = group; | ||
this.Version = version; | ||
this.Plural = plural; | ||
this.Name = name; | ||
this.Namespace = @namespace; | ||
this.Patch = patch ?? throw new ArgumentNullException(nameof(patch)); | ||
this.DryRun = dryRun; | ||
} | ||
|
||
/// <summary> | ||
/// Gets the API group the resource to patch belongs to | ||
/// </summary> | ||
public string Group { get; } = null!; | ||
|
||
/// <summary> | ||
/// Gets the version of the resource to patch | ||
/// </summary> | ||
public string Version { get; } = null!; | ||
|
||
/// <summary> | ||
/// Gets the plural name of the type of resource to patch | ||
/// </summary> | ||
public string Plural { get; } = null!; | ||
|
||
/// <summary> | ||
/// Gets the name of the <see cref="IResource"/> to patch | ||
/// </summary> | ||
public string Name { get; } = null!; | ||
|
||
/// <summary> | ||
/// Gets the name of the <see cref="IResource"/> to patch | ||
/// </summary> | ||
public string? Namespace { get; } | ||
|
||
/// <summary> | ||
/// Gets the patch to apply | ||
/// </summary> | ||
public Patch Patch { get; } = null!; | ||
|
||
/// <summary> | ||
/// Gets a boolean indicating whether or not to persist changes | ||
/// </summary> | ||
public bool DryRun { get; } | ||
|
||
} | ||
|
||
/// <summary> | ||
/// Represents the service used to handle <see cref="PatchResourceStatusCommand"/>s | ||
/// </summary> | ||
/// <param name="repository">The service used to manage <see cref="IResource"/>s</param> | ||
public class PatchResourceStatusCommandHandler(IResourceRepository repository) | ||
: ICommandHandler<PatchResourceStatusCommand, IResource> | ||
{ | ||
|
||
/// <inheritdoc/> | ||
public virtual async Task<IOperationResult<IResource>> HandleAsync(PatchResourceStatusCommand command, CancellationToken cancellationToken) | ||
{ | ||
var resource = await repository.PatchSubResourceAsync(command.Patch, command.Group, command.Version, command.Plural, command.Name, "status", command.Namespace, null, command.DryRun, cancellationToken).ConfigureAwait(false); | ||
return this.Ok(resource); | ||
} | ||
|
||
} |
This file contains 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