Skip to content

Commit

Permalink
Merge pull request microsoft#101 from microsoft/release_8.1_changes
Browse files Browse the repository at this point in the history
updates for 8.1
  • Loading branch information
jeffj6123 authored Aug 3, 2021
2 parents 0827ea0 + 337cf6f commit 28ad9d6
Show file tree
Hide file tree
Showing 33 changed files with 1,283 additions and 63 deletions.
3 changes: 1 addition & 2 deletions properties/service_fabric_common.props
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@
<!-- Version for binaries, nuget packages generated from this repo. -->
<!-- TODO: Versions numbers are changed here manually for now, Integrate this with GitVersion. -->
<MajorVersion>4</MajorVersion>
<MinorVersion>4</MinorVersion>
<MinorVersion>5</MinorVersion>
<BuildVersion>0</BuildVersion>
<Revision>0</Revision>
<PreviewTag>-preview01</PreviewTag>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,47 @@ HttpRequestMessage RequestFunc()
return this.httpClient.SendAsync(RequestFunc, url, requestId, cancellationToken);
}

/// <inheritdoc />
public Task UpdateApplicationAsync(
string applicationId,
ApplicationUpdateDescription applicationUpdateDescription,
long? serverTimeout = 60,
CancellationToken cancellationToken = default(CancellationToken))
{
applicationId.ThrowIfNull(nameof(applicationId));
applicationUpdateDescription.ThrowIfNull(nameof(applicationUpdateDescription));
serverTimeout?.ThrowIfOutOfInclusiveRange("serverTimeout", 1, 4294967295);
var requestId = Guid.NewGuid().ToString();
var url = "Applications/{applicationId}/$/Update";
url = url.Replace("{applicationId}", applicationId);
var queryParams = new List<string>();

// Append to queryParams if not null.
serverTimeout?.AddToQueryParameters(queryParams, $"timeout={serverTimeout}");
queryParams.Add("api-version=8.1");
url += "?" + string.Join("&", queryParams);

string content;
using (var sw = new StringWriter())
{
ApplicationUpdateDescriptionConverter.Serialize(new JsonTextWriter(sw), applicationUpdateDescription);
content = sw.ToString();
}

HttpRequestMessage RequestFunc()
{
var request = new HttpRequestMessage()
{
Method = HttpMethod.Post,
Content = new StringContent(content, Encoding.UTF8),
};
request.Content.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
return request;
}

return this.httpClient.SendAsync(RequestFunc, url, requestId, cancellationToken);
}

/// <inheritdoc />
public Task ResumeApplicationUpgradeAsync(
string applicationId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -616,5 +616,44 @@ HttpRequestMessage RequestFunc()

return this.httpClient.SendAsync(RequestFunc, url, requestId, cancellationToken);
}

/// <inheritdoc />
public Task MoveAuxiliaryReplicaAsync(
string serviceId,
PartitionId partitionId,
NodeName currentNodeName = default(NodeName),
NodeName newNodeName = default(NodeName),
bool? ignoreConstraints = false,
long? serverTimeout = 60,
CancellationToken cancellationToken = default(CancellationToken))
{
serviceId.ThrowIfNull(nameof(serviceId));
partitionId.ThrowIfNull(nameof(partitionId));
serverTimeout?.ThrowIfOutOfInclusiveRange("serverTimeout", 1, 4294967295);
var requestId = Guid.NewGuid().ToString();
var url = "Services/{serviceId}/$/GetPartitions/{partitionId}/$/MoveAuxiliaryReplica";
url = url.Replace("{serviceId}", serviceId);
url = url.Replace("{partitionId}", partitionId.ToString());
var queryParams = new List<string>();

// Append to queryParams if not null.
currentNodeName?.AddToQueryParameters(queryParams, $"CurrentNodeName={currentNodeName.ToString()}");
newNodeName?.AddToQueryParameters(queryParams, $"NewNodeName={newNodeName.ToString()}");
ignoreConstraints?.AddToQueryParameters(queryParams, $"IgnoreConstraints={ignoreConstraints}");
serverTimeout?.AddToQueryParameters(queryParams, $"timeout={serverTimeout}");
queryParams.Add("api-version=8.1");
url += "?" + string.Join("&", queryParams);

HttpRequestMessage RequestFunc()
{
var request = new HttpRequestMessage()
{
Method = HttpMethod.Post,
};
return request;
}

return this.httpClient.SendAsync(RequestFunc, url, requestId, cancellationToken);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
// ------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
// ------------------------------------------------------------

namespace Microsoft.ServiceFabric.Client.Http.Serialization
{
using System;
using System.Collections.Generic;
using Microsoft.ServiceFabric.Common;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

/// <summary>
/// Converter for <see cref="ApplicationUpdateDescription" />.
/// </summary>
internal class ApplicationUpdateDescriptionConverter
{
/// <summary>
/// Deserializes the JSON representation of the object.
/// </summary>
/// <param name="reader">The <see cref="T: Newtonsoft.Json.JsonReader" /> to read from.</param>
/// <returns>The object Value.</returns>
internal static ApplicationUpdateDescription Deserialize(JsonReader reader)
{
return reader.Deserialize(GetFromJsonProperties);
}

/// <summary>
/// Gets the object from Json properties.
/// </summary>
/// <param name="reader">The <see cref="T: Newtonsoft.Json.JsonReader" /> to read from, reader must be placed at first property.</param>
/// <returns>The object Value.</returns>
internal static ApplicationUpdateDescription GetFromJsonProperties(JsonReader reader)
{
var flags = default(string);
var removeApplicationCapacity = default(bool?);
var minimumNodes = default(long?);
var maximumNodes = default(long?);
var applicationMetrics = default(IEnumerable<ApplicationMetricDescription>);

do
{
var propName = reader.ReadPropertyName();
if (string.Compare("Flags", propName, StringComparison.OrdinalIgnoreCase) == 0)
{
flags = reader.ReadValueAsString();
}
else if (string.Compare("RemoveApplicationCapacity", propName, StringComparison.OrdinalIgnoreCase) == 0)
{
removeApplicationCapacity = reader.ReadValueAsBool();
}
else if (string.Compare("MinimumNodes", propName, StringComparison.OrdinalIgnoreCase) == 0)
{
minimumNodes = reader.ReadValueAsLong();
}
else if (string.Compare("MaximumNodes", propName, StringComparison.OrdinalIgnoreCase) == 0)
{
maximumNodes = reader.ReadValueAsLong();
}
else if (string.Compare("ApplicationMetrics", propName, StringComparison.OrdinalIgnoreCase) == 0)
{
applicationMetrics = reader.ReadList(ApplicationMetricDescriptionConverter.Deserialize);
}
else
{
reader.SkipPropertyValue();
}
}
while (reader.TokenType != JsonToken.EndObject);

return new ApplicationUpdateDescription(
flags: flags,
removeApplicationCapacity: removeApplicationCapacity,
minimumNodes: minimumNodes,
maximumNodes: maximumNodes,
applicationMetrics: applicationMetrics);
}

/// <summary>
/// Serializes the object to JSON.
/// </summary>
/// <param name="writer">The <see cref="T: Newtonsoft.Json.JsonWriter" /> to write to.</param>
/// <param name="obj">The object to serialize to JSON.</param>
internal static void Serialize(JsonWriter writer, ApplicationUpdateDescription obj)
{
// Required properties are always serialized, optional properties are serialized when not null.
writer.WriteStartObject();
if (obj.Flags != null)
{
writer.WriteProperty(obj.Flags, "Flags", JsonWriterExtensions.WriteStringValue);
}

if (obj.RemoveApplicationCapacity != null)
{
writer.WriteProperty(obj.RemoveApplicationCapacity, "RemoveApplicationCapacity", JsonWriterExtensions.WriteBoolValue);
}

if (obj.MinimumNodes != null)
{
writer.WriteProperty(obj.MinimumNodes, "MinimumNodes", JsonWriterExtensions.WriteLongValue);
}

if (obj.MaximumNodes != null)
{
writer.WriteProperty(obj.MaximumNodes, "MaximumNodes", JsonWriterExtensions.WriteLongValue);
}

if (obj.ApplicationMetrics != null)
{
writer.WriteEnumerableProperty(obj.ApplicationMetrics, "ApplicationMetrics", ApplicationMetricDescriptionConverter.Serialize);
}

writer.WriteEndObject();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ internal static HealthEvaluation GetFromJsonProperties(JsonReader reader)
{
obj = UpgradeDomainDeltaNodesCheckHealthEvaluationConverter.GetFromJsonProperties(reader);
}
else if (propValue.Equals("UpgradeDomainDeployedApplications", StringComparison.OrdinalIgnoreCase))
{
obj = UpgradeDomainDeployedApplicationsHealthEvaluationConverter.GetFromJsonProperties(reader);
}
else if (propValue.Equals("UpgradeDomainNodes", StringComparison.OrdinalIgnoreCase))
{
obj = UpgradeDomainNodesHealthEvaluationConverter.GetFromJsonProperties(reader);
Expand Down Expand Up @@ -217,6 +221,10 @@ internal static void Serialize(JsonWriter writer, HealthEvaluation obj)
{
UpgradeDomainDeltaNodesCheckHealthEvaluationConverter.Serialize(writer, (UpgradeDomainDeltaNodesCheckHealthEvaluation)obj);
}
else if (kind.Equals(HealthEvaluationKind.UpgradeDomainDeployedApplications))
{
UpgradeDomainDeployedApplicationsHealthEvaluationConverter.Serialize(writer, (UpgradeDomainDeployedApplicationsHealthEvaluation)obj);
}
else if (kind.Equals(HealthEvaluationKind.UpgradeDomainNodes))
{
UpgradeDomainNodesHealthEvaluationConverter.Serialize(writer, (UpgradeDomainNodesHealthEvaluation)obj);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ internal static PartitionLoadInformation GetFromJsonProperties(JsonReader reader
var partitionId = default(PartitionId);
var primaryLoadMetricReports = default(IEnumerable<LoadMetricReport>);
var secondaryLoadMetricReports = default(IEnumerable<LoadMetricReport>);
var auxiliaryLoadMetricReports = default(IEnumerable<LoadMetricReport>);

do
{
Expand All @@ -52,6 +53,10 @@ internal static PartitionLoadInformation GetFromJsonProperties(JsonReader reader
{
secondaryLoadMetricReports = reader.ReadList(LoadMetricReportConverter.Deserialize);
}
else if (string.Compare("AuxiliaryLoadMetricReports", propName, StringComparison.OrdinalIgnoreCase) == 0)
{
auxiliaryLoadMetricReports = reader.ReadList(LoadMetricReportConverter.Deserialize);
}
else
{
reader.SkipPropertyValue();
Expand All @@ -62,7 +67,8 @@ internal static PartitionLoadInformation GetFromJsonProperties(JsonReader reader
return new PartitionLoadInformation(
partitionId: partitionId,
primaryLoadMetricReports: primaryLoadMetricReports,
secondaryLoadMetricReports: secondaryLoadMetricReports);
secondaryLoadMetricReports: secondaryLoadMetricReports,
auxiliaryLoadMetricReports: auxiliaryLoadMetricReports);
}

/// <summary>
Expand All @@ -89,6 +95,11 @@ internal static void Serialize(JsonWriter writer, PartitionLoadInformation obj)
writer.WriteEnumerableProperty(obj.SecondaryLoadMetricReports, "SecondaryLoadMetricReports", LoadMetricReportConverter.Serialize);
}

if (obj.AuxiliaryLoadMetricReports != null)
{
writer.WriteEnumerableProperty(obj.AuxiliaryLoadMetricReports, "AuxiliaryLoadMetricReports", LoadMetricReportConverter.Serialize);
}

writer.WriteEndObject();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ internal static PartitionMetricLoadDescription GetFromJsonProperties(JsonReader
var primaryReplicaLoadEntries = default(IEnumerable<MetricLoadDescription>);
var secondaryReplicasOrInstancesLoadEntries = default(IEnumerable<MetricLoadDescription>);
var secondaryReplicaOrInstanceLoadEntriesPerNode = default(IEnumerable<ReplicaMetricLoadDescription>);
var auxiliaryReplicasLoadEntries = default(IEnumerable<MetricLoadDescription>);
var auxiliaryReplicaLoadEntriesPerNode = default(IEnumerable<ReplicaMetricLoadDescription>);

do
{
Expand All @@ -57,6 +59,14 @@ internal static PartitionMetricLoadDescription GetFromJsonProperties(JsonReader
{
secondaryReplicaOrInstanceLoadEntriesPerNode = reader.ReadList(ReplicaMetricLoadDescriptionConverter.Deserialize);
}
else if (string.Compare("AuxiliaryReplicasLoadEntries", propName, StringComparison.OrdinalIgnoreCase) == 0)
{
auxiliaryReplicasLoadEntries = reader.ReadList(MetricLoadDescriptionConverter.Deserialize);
}
else if (string.Compare("AuxiliaryReplicaLoadEntriesPerNode", propName, StringComparison.OrdinalIgnoreCase) == 0)
{
auxiliaryReplicaLoadEntriesPerNode = reader.ReadList(ReplicaMetricLoadDescriptionConverter.Deserialize);
}
else
{
reader.SkipPropertyValue();
Expand All @@ -68,7 +78,9 @@ internal static PartitionMetricLoadDescription GetFromJsonProperties(JsonReader
partitionId: partitionId,
primaryReplicaLoadEntries: primaryReplicaLoadEntries,
secondaryReplicasOrInstancesLoadEntries: secondaryReplicasOrInstancesLoadEntries,
secondaryReplicaOrInstanceLoadEntriesPerNode: secondaryReplicaOrInstanceLoadEntriesPerNode);
secondaryReplicaOrInstanceLoadEntriesPerNode: secondaryReplicaOrInstanceLoadEntriesPerNode,
auxiliaryReplicasLoadEntries: auxiliaryReplicasLoadEntries,
auxiliaryReplicaLoadEntriesPerNode: auxiliaryReplicaLoadEntriesPerNode);
}

/// <summary>
Expand Down Expand Up @@ -100,6 +112,16 @@ internal static void Serialize(JsonWriter writer, PartitionMetricLoadDescription
writer.WriteEnumerableProperty(obj.SecondaryReplicaOrInstanceLoadEntriesPerNode, "SecondaryReplicaOrInstanceLoadEntriesPerNode", ReplicaMetricLoadDescriptionConverter.Serialize);
}

if (obj.AuxiliaryReplicasLoadEntries != null)
{
writer.WriteEnumerableProperty(obj.AuxiliaryReplicasLoadEntries, "AuxiliaryReplicasLoadEntries", MetricLoadDescriptionConverter.Serialize);
}

if (obj.AuxiliaryReplicaLoadEntriesPerNode != null)
{
writer.WriteEnumerableProperty(obj.AuxiliaryReplicaLoadEntriesPerNode, "AuxiliaryReplicaLoadEntriesPerNode", ReplicaMetricLoadDescriptionConverter.Serialize);
}

writer.WriteEndObject();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,18 @@ internal class ReplicaRoleConverter
{
obj = ReplicaRole.ActiveSecondary;
}
else if (string.Compare(value, "IdleAuxiliary", StringComparison.OrdinalIgnoreCase) == 0)
{
obj = ReplicaRole.IdleAuxiliary;
}
else if (string.Compare(value, "ActiveAuxiliary", StringComparison.OrdinalIgnoreCase) == 0)
{
obj = ReplicaRole.ActiveAuxiliary;
}
else if (string.Compare(value, "PrimaryAuxiliary", StringComparison.OrdinalIgnoreCase) == 0)
{
obj = ReplicaRole.PrimaryAuxiliary;
}

return obj;
}
Expand Down Expand Up @@ -74,6 +86,15 @@ public static void Serialize(JsonWriter writer, ReplicaRole? value)
case ReplicaRole.ActiveSecondary:
writer.WriteStringValue("ActiveSecondary");
break;
case ReplicaRole.IdleAuxiliary:
writer.WriteStringValue("IdleAuxiliary");
break;
case ReplicaRole.ActiveAuxiliary:
writer.WriteStringValue("ActiveAuxiliary");
break;
case ReplicaRole.PrimaryAuxiliary:
writer.WriteStringValue("PrimaryAuxiliary");
break;
default:
throw new ArgumentException($"Invalid value {value.ToString()} for enum type ReplicaRole");
}
Expand Down
Loading

0 comments on commit 28ad9d6

Please sign in to comment.