Skip to content

Commit

Permalink
feat(mcm): has pending mappings (#683)
Browse files Browse the repository at this point in the history
[changelog]
Get cluster pending (migrating, creating, deleting) mapping state.
Query cluster pending mapping status, and optionally get cluster mappings.
  • Loading branch information
Ant-hem committed Nov 26, 2019
1 parent e1a9708 commit 7721573
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ public async Task McmTest()
}

await RemovePastUserIDs();

var hasPendingMappings = await BaseTest.McmClient.HasPendingMappingsAsync(true);

Assert.That(hasPendingMappings, Is.Not.Null);
}

private async Task RemovePastUserIDs()
Expand Down
17 changes: 17 additions & 0 deletions src/Algolia.Search/Clients/ISearchClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,23 @@ public interface ISearchClient
Task<RemoveUserIdResponse> RemoveUserIdAsync(string userId, RequestOptions requestOptions = null,
CancellationToken ct = default);

/// <summary>
/// Get cluster pending (migrating, creating, deleting) mapping state. Query cluster pending mapping status and get cluster mappings.
/// </summary>
/// <param name="retrieveMappings">Whether or not the cluster mappings should be retrieved</param>
/// <param name="requestOptions">Add extra http header or query parameters to Algolia</param>
HasPendingMappingsResponse HasPendingMappings(bool retrieveMappings = false,
RequestOptions requestOptions = null);

/// <summary>
/// Get cluster pending (migrating, creating, deleting) mapping state. Query cluster pending mapping status and get cluster mappings.
/// </summary>
/// <param name="retrieveMappings">Whether or not the cluster mappings should be retrieved</param>
/// <param name="requestOptions">Add extra http header or query parameters to Algolia</param>
/// <param name="ct">Optional cancellation token</param>
Task<HasPendingMappingsResponse> HasPendingMappingsAsync(bool retrieveMappings = false,
RequestOptions requestOptions = null, CancellationToken ct = default);

/// <summary>
/// Get the logs of the latest search and indexing operations
/// You can retrieve the logs of your last 1,000 API calls. It is designed for immediate, real-time debugging.
Expand Down
19 changes: 19 additions & 0 deletions src/Algolia.Search/Clients/SearchClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,25 @@ public AssignUserIdResponse
.ConfigureAwait(false);
}

/// <inheritdoc />
public HasPendingMappingsResponse HasPendingMappings(bool retrieveMappings = false,
RequestOptions requestOptions = null) =>
AsyncHelper.RunSync(() => HasPendingMappingsAsync(retrieveMappings, requestOptions));

/// <inheritdoc />
public async Task<HasPendingMappingsResponse> HasPendingMappingsAsync(bool retrieveMappings = false,
RequestOptions requestOptions = null, CancellationToken ct = default)
{
requestOptions = requestOptions.AddQueryParams(
new Dictionary<string, string> { { "getClusters", retrieveMappings.ToString().ToLower() } });

return await _transport.ExecuteRequestAsync<HasPendingMappingsResponse>(
HttpMethod.Get,
"/1/clusters/mapping/pending",
CallType.Read, requestOptions, ct)
.ConfigureAwait(false);
}

/// <inheritdoc />
public LogResponse GetLogs(RequestOptions requestOptions = null, int offset = 0, int length = 10) =>
AsyncHelper.RunSync(() =>
Expand Down
44 changes: 44 additions & 0 deletions src/Algolia.Search/Models/Mcm/HasPendingMappingsResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright (c) 2018 Algolia
* http://www.algolia.com/
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

using System;
using System.Collections.Generic;

namespace Algolia.Search.Models.Mcm
{
/// <summary>
/// Describe cluster pending (migrating, creating, deleting) mapping state.
/// </summary>
public class HasPendingMappingsResponse
{
/// <summary>
/// Has clusters pending mapping in progress?
/// </summary>
public Boolean Pending { get; set; }

/// <summary>
/// Describe cluster pending (migrating, creating, deleting) mapping state.
/// </summary>
public Dictionary<string, IEnumerable<string>> Clusters { get; set; }
}
}

0 comments on commit 7721573

Please sign in to comment.