public void ApplicationHealthSerializationTest() { ApplicationHealth appHealth = this.random.CreateRandom <ApplicationHealth>(); var deployedApplicationHealthState = new DeployedApplicationHealthState() { ApplicationName = new Uri("fabric:/" + "testApp" + this.random.CreateRandom <string>()), NodeName = "NodeName_" + this.random.CreateRandom <string>(), AggregatedHealthState = this.random.CreateRandom <HealthState>() }; appHealth.DeployedApplicationHealthStates = new List <DeployedApplicationHealthState>() { deployedApplicationHealthState }; var serviceHealthState = new ServiceHealthState() { ServiceName = new Uri("fabric:/" + "testSvc" + this.random.CreateRandom <string>()), AggregatedHealthState = this.random.CreateRandom <HealthState>() }; appHealth.ServiceHealthStates = new List <ServiceHealthState>() { serviceHealthState }; TestUsingSerializer(this.Serializer, appHealth); }
private static async Task DumpClusterHealthAsync(FabricClient fc) { FabricClient.HealthClient hm = fc.HealthManager; ClusterHealth clusterHealth = await hm.GetClusterHealthAsync(); WriteLine($"Cluster: State={clusterHealth.AggregatedHealthState}"); foreach (HealthEvent healthEvent in clusterHealth.HealthEvents) { healthEvent.WriteHealth(); } foreach (HealthEvaluation healthEval in clusterHealth.UnhealthyEvaluations) { WriteLine(healthEval); } foreach (NodeHealthState nodeHealth in clusterHealth.NodeHealthStates) { WriteLine($"Node: State={nodeHealth.AggregatedHealthState}, Name={nodeHealth.NodeName}"); } foreach (ApplicationHealthState appHealthState in clusterHealth.ApplicationHealthStates) { WriteLine($"App: State={appHealthState.AggregatedHealthState}, Name={appHealthState.ApplicationName}"); } //await hm.GetNodeHealthAsync() ApplicationHealth appHealth = await hm.GetApplicationHealthAsync(new Uri(@"fabric:/")); WriteLine($"App: State={appHealth.AggregatedHealthState}, Name={appHealth.ApplicationName}"); foreach (HealthEvent healthEvent in appHealth.HealthEvents) { healthEvent.WriteHealth(); } }
/// <summary> /// Overloaded ToString function for formatting the output on the console. /// </summary> /// <param name="applicationHealth"> Object of type ApplicationHealth </param> /// <returns> /// Returns formatted string. /// </returns> public static string ToString(ApplicationHealth applicationHealth) { var strBuilder = new StringBuilder(); strBuilder.Append(string.Format(CultureInfo.CurrentCulture, "{0} : {1}", "ApplicationName", applicationHealth.Name)); strBuilder.Append(Environment.NewLine); strBuilder.Append(string.Format(CultureInfo.CurrentCulture, "{0} : {1}", "ServiceHealthStates", OutputFormatter.ToString(applicationHealth.ServiceHealthStates.ToList()))); strBuilder.Append(Environment.NewLine); strBuilder.Append(string.Format(CultureInfo.CurrentCulture, "{0} : {1}", "AggregatedHealthState", applicationHealth.AggregatedHealthState)); strBuilder.Append(Environment.NewLine); strBuilder.Append(string.Format(CultureInfo.CurrentCulture, "{0} : {1}", "DeployedApplicationHealthStates", OutputFormatter.ToString(applicationHealth.DeployedApplicationHealthStates.ToList()))); strBuilder.Append(Environment.NewLine); strBuilder.Append(string.Format(CultureInfo.CurrentCulture, "{0} : {1}", "HealthEvents", OutputFormatter.ToString(applicationHealth.HealthEvents.ToList()))); strBuilder.Append(Environment.NewLine); strBuilder.Append(string.Format(CultureInfo.CurrentCulture, "{0} : {1}", "HealthStatistics", OutputFormatter.ToString(applicationHealth.HealthStatistics))); 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, ApplicationHealth obj) { // Required properties are always serialized, optional properties are serialized when not null. writer.WriteStartObject(); writer.WriteProperty(obj.AggregatedHealthState, "AggregatedHealthState", HealthStateConverter.Serialize); if (obj.HealthEvents != null) { writer.WriteEnumerableProperty(obj.HealthEvents, "HealthEvents", HealthEventConverter.Serialize); } if (obj.UnhealthyEvaluations != null) { writer.WriteEnumerableProperty(obj.UnhealthyEvaluations, "UnhealthyEvaluations", HealthEvaluationWrapperConverter.Serialize); } if (obj.HealthStatistics != null) { writer.WriteProperty(obj.HealthStatistics, "HealthStatistics", HealthStatisticsConverter.Serialize); } if (obj.Name != null) { writer.WriteProperty(obj.Name, "Name", ApplicationNameConverter.Serialize); } if (obj.ServiceHealthStates != null) { writer.WriteEnumerableProperty(obj.ServiceHealthStates, "ServiceHealthStates", ServiceHealthStateConverter.Serialize); } if (obj.DeployedApplicationHealthStates != null) { writer.WriteEnumerableProperty(obj.DeployedApplicationHealthStates, "DeployedApplicationHealthStates", DeployedApplicationHealthStateConverter.Serialize); } writer.WriteEndObject(); }
public static void PreStart() { ApplicationHealth.sendApplicationHealth(); }
public ActionResult GetStatus() { var health = new ApplicationHealth(_settings.Version, _settings.Environment, "OK"); return(Ok(health)); }