-
Notifications
You must be signed in to change notification settings - Fork 85
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
add admin partition create API support (#379) #380
Draft
larrytamnjong
wants to merge
3
commits into
G-Research:master
Choose a base branch
from
larrytamnjong:create-admin-partition
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+169
−0
Draft
Changes from all commits
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 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,44 @@ | ||
// ----------------------------------------------------------------------- | ||
// <copyright file="AdminPartitionTest.cs" company="G-Research Limited"> | ||
// Copyright 2020 G-Research Limited | ||
// | ||
// 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. | ||
// </copyright> | ||
// ----------------------------------------------------------------------- | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using NuGet.Versioning; | ||
using Xunit; | ||
|
||
namespace Consul.Test | ||
{ | ||
public class AdminPartitionTest : BaseFixture | ||
{ | ||
[EnterpriseOnlyFact] | ||
public async Task AdminPartition_CreateAdminPartition() | ||
{ | ||
var cutOffVersion = SemanticVersion.Parse("1.11.0"); | ||
Skip.If(AgentVersion < cutOffVersion, $"Current version is {AgentVersion}, but `Admin Partition` is only supported from Consul {cutOffVersion}"); | ||
|
||
var check = new Partition { Name = "na-west", Description = "Partition for North America West" }; | ||
|
||
var request = await _client.AdminPartition.Create(check); | ||
|
||
Assert.Equal(check.Name, request.Response.Name); | ||
} | ||
} | ||
} |
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,88 @@ | ||
// ----------------------------------------------------------------------- | ||
// <copyright file="Partition.cs" company="G-Research Limited"> | ||
// Copyright 2020 G-Research Limited | ||
// | ||
// 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. | ||
// </copyright> | ||
// ----------------------------------------------------------------------- | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Consul.Interfaces; | ||
|
||
namespace Consul | ||
{ | ||
/// <summary> | ||
/// Partition is the configuration of a single admin partition. Admin Partitions are a Consul Enterprise feature. | ||
/// </summary> | ||
public class Partition | ||
{ | ||
/// <summary> | ||
/// // Name is the name of the Partition. | ||
/// </summary> | ||
public string Name { get; set; } | ||
/// <summary> | ||
/// Description is where the user puts any information they want | ||
/// about the admin partition. It is not used internally. | ||
/// </summary> | ||
public string Description { get; set; } | ||
} | ||
|
||
public class PartitionResponse : Partition | ||
{ | ||
/// <summary> | ||
/// DeletedAt is the time when the Partition was marked for deletion | ||
/// This is nullable so that we can omit if empty when encoding in JSON | ||
/// </summary> | ||
public DateTime DeletedAt { get; set; } | ||
/// <summary> | ||
/// CreateIndex is the Raft index at which the Partition was created | ||
/// </summary> | ||
public ulong CreateIndex { get; set; } | ||
/// <summary> | ||
/// ModifyIndex is the latest Raft index at which the Partition was modified. | ||
/// </summary> | ||
public ulong ModifyIndex { get; set; } | ||
} | ||
public class AdminPartition : IAdminPartitionEndpoint | ||
{ | ||
private readonly ConsulClient _client; | ||
internal AdminPartition(ConsulClient c) | ||
{ | ||
_client = c; | ||
} | ||
public async Task<WriteResult<PartitionResponse>> Create(Partition p, CancellationToken ct = default) | ||
{ | ||
return await Create(p, WriteOptions.Default, ct).ConfigureAwait(false); | ||
} | ||
public async Task<WriteResult<PartitionResponse>> Create(Partition p, WriteOptions q, CancellationToken ct = default) | ||
{ | ||
var res = await _client.Put<Partition, PartitionResponse>("/v1/partition", p, q).Execute(ct).ConfigureAwait(false); | ||
|
||
return new WriteResult<PartitionResponse>(res, res.Response); | ||
} | ||
} | ||
|
||
public partial class ConsulClient : IConsulClient | ||
{ | ||
private Lazy<AdminPartition> _adminPartition; | ||
|
||
/// <summary> | ||
/// Partition returns a handle to the Partition endpoints | ||
/// </summary> | ||
public IAdminPartitionEndpoint AdminPartition => _adminPartition.Value; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// ----------------------------------------------------------------------- | ||
// <copyright file="IPartition.cs" company="G-Research Limited"> | ||
// Copyright 2020 G-Research Limited | ||
// | ||
// 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. | ||
// </copyright> | ||
// ----------------------------------------------------------------------- | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace Consul.Interfaces | ||
{ | ||
/// <summary> | ||
/// The interface for the Admin Partition API Endpoints | ||
/// </summary> | ||
public interface IAdminPartitionEndpoint | ||
{ | ||
Task<WriteResult<PartitionResponse>> Create(Partition p, WriteOptions q, CancellationToken ct = default); | ||
Task<WriteResult<PartitionResponse>> Create(Partition p, CancellationToken ct = default); | ||
} | ||
} |
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately, as for now we will not be able to run enterprise tests for versions
1.10+
, so these test is going to be skipped, e.g.:We run enterprise tests only for versions before 1.10 -> https://github.com/G-Research/consuldotnet/blob/master/.github/workflows/ci.yml#L82-L88
I'm afraid we will not be able accept this PR because we are unable to test it at the moment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@marcin-krystianc makes sense, thanks. Please take a look at this other PR #382 when you have time.