public void ClusterHealthSerializationTest() { ClusterHealth clusterHealth = this.random.CreateRandom <ClusterHealth>(); var appHS = new ApplicationHealthState() { ApplicationName = new Uri("fabric:/" + "testAppManifest" + this.random.CreateRandom <string>()), AggregatedHealthState = this.random.CreateRandom <HealthState>() }; var nodeHS = new NodeHealthState() { NodeName = "NodeName_" + this.random.CreateRandom <string>(), AggregatedHealthState = this.random.CreateRandom <HealthState>() }; clusterHealth.ApplicationHealthStates = new List <ApplicationHealthState>() { appHS }; clusterHealth.NodeHealthStates = new List <NodeHealthState>() { nodeHS }; TestUsingSerializer(this.Serializer, clusterHealth); }
/// <summary> /// Overloaded ToString function for formatting the output on the console. /// </summary> /// <param name="nodeHealthState"> Object of type NodeHealthState </param> /// <returns> /// Returns formatted string. /// </returns> public static string ToString(NodeHealthState nodeHealthState) { var strBuilder = new StringBuilder(); strBuilder.Append(string.Format(CultureInfo.CurrentCulture, "{0, -21} : {1}", "NodeName", nodeHealthState.Name)); strBuilder.Append(Environment.NewLine); strBuilder.Append(string.Format(CultureInfo.CurrentCulture, "{0, -21} : {1}", "AggregatedHealthState", nodeHealthState.AggregatedHealthState)); strBuilder.Append(Environment.NewLine); return(strBuilder.ToString()); }
/// <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, NodeHealthState obj) { // Required properties are always serialized, optional properties are serialized when not null. writer.WriteStartObject(); writer.WriteProperty(obj.AggregatedHealthState, "AggregatedHealthState", HealthStateConverter.Serialize); if (obj.Name != null) { writer.WriteProperty(obj.Name, "Name", NodeNameConverter.Serialize); } if (obj.Id != null) { writer.WriteProperty(obj.Id, "Id", NodeIdConverter.Serialize); } writer.WriteEndObject(); }
protected override void ParseNodeHealthNode(string clusterName, TreeNode node) { var nodeHealth = node.Health as NodeHealth; var nodeHealthState = new NodeHealthState(nodeHealth.NodeName, nodeHealth.AggregatedHealthState); var nodeMock = this.Create_NodeHealthMock( nodeHealth.NodeName, nodeHealth.AggregatedHealthState, nodeHealth.HealthEvents, nodeHealth.UnhealthyEvaluations); this.Mock .Setup(mock => mock.GetNodeHealthAsync( It.Is <string>(nodeName => nodeName == nodeMock.NodeName), It.IsAny <TimeSpan>(), It.Is <CancellationToken>(token => token.Equals(this.token)))) .Returns(Task.FromResult(nodeMock)); }
private static ClusterHealth CreateDefaultClusterHealth( int totalApplicationCount, int totalNodeCount, int unhealthyApplicationsCount = 0, int unhealthyNodeCount = 0, bool isSystemServicesUnhealthy = false) { HealthState aggregatedHealthState = (unhealthyApplicationsCount > 0 || unhealthyNodeCount > 0 || isSystemServicesUnhealthy) ? HealthState.Error : HealthState.Ok; List <ApplicationHealthState> applicationHealthStates = new List <ApplicationHealthState>(); for (int i = 0; i < totalApplicationCount; i++) { HealthState healthState = HealthState.Ok; if (unhealthyApplicationsCount > 0) { healthState = HealthState.Error; unhealthyApplicationsCount--; } ApplicationHealthState appHealthState = new ApplicationHealthState() { AggregatedHealthState = healthState, ApplicationName = new Uri(string.Format("fabric:/app{0}", i)) }; applicationHealthStates.Add(appHealthState); } ApplicationHealthState systemServiceAppHealthState = new ApplicationHealthState() { AggregatedHealthState = isSystemServicesUnhealthy ? HealthState.Error : HealthState.Ok, ApplicationName = new Uri("fabric:/System") }; applicationHealthStates.Add(systemServiceAppHealthState); List <NodeHealthState> nodeHealthStates = new List <NodeHealthState>(); for (int i = 0; i < totalNodeCount; i++) { HealthState healthState = HealthState.Ok; if (unhealthyNodeCount > 0) { healthState = HealthState.Error; unhealthyNodeCount--; } NodeHealthState nodeHealthState = new NodeHealthState() { AggregatedHealthState = healthState, NodeName = "_node_" + i.ToString() }; nodeHealthStates.Add(nodeHealthState); } return(new ClusterHealth() { AggregatedHealthState = aggregatedHealthState, ApplicationHealthStates = applicationHealthStates, NodeHealthStates = nodeHealthStates, HealthEvents = new List <HealthEvent>(), UnhealthyEvaluations = new List <HealthEvaluation>() }); }