public static async Task <bool> IsInDatalossStateAsync(CancellationToken cancellationToken) { try { FabricClient fc = new FabricClient(); var healthQuery = new ClusterHealthQueryDescription() { EventsFilter = new HealthEventsFilter() { HealthStateFilterValue = HealthStateFilter.Error } }; var clusterHealth = await fc.HealthManager.GetClusterHealthAsync(healthQuery, Constants.FabricQueryTimeoutInMinutes, cancellationToken); foreach (var healthEvent in clusterHealth.HealthEvents) { if (healthEvent != null && healthEvent.HealthInformation != null && string.Equals(healthEvent.HealthInformation.SourceId, Constants.UpgradeOrchestrationHealthSourceId, StringComparison.OrdinalIgnoreCase) && string.Equals(healthEvent.HealthInformation.Property, Constants.DatalossHealthProperty, StringComparison.OrdinalIgnoreCase)) { return(true); } } return(false); } catch (Exception ex) { UpgradeOrchestrationTrace.TraceSource.WriteWarning(FabricUpgradeOrchestrationService.TraceType, "IsInDatalossStateAsync failed with {0}... Continuing assuming no data loss has occured.", ex); return(false); } }
protected override void ProcessRecord() { var clusterConnection = this.GetClusterConnection(); try { var queryDescription = new ClusterHealthQueryDescription(); if (this.ConsiderWarningAsError.HasValue || this.MaxPercentUnhealthyNodes.HasValue || this.MaxPercentUnhealthyApplications.HasValue || this.ApplicationTypeHealthPolicyMap != null) { queryDescription.HealthPolicy = new ClusterHealthPolicy() { ConsiderWarningAsError = this.ConsiderWarningAsError.GetValueOrDefault(), MaxPercentUnhealthyApplications = this.MaxPercentUnhealthyApplications.GetValueOrDefault(), MaxPercentUnhealthyNodes = this.MaxPercentUnhealthyNodes.GetValueOrDefault() }; if (this.ApplicationTypeHealthPolicyMap != null) { foreach (var entry in this.ApplicationTypeHealthPolicyMap) { queryDescription.HealthPolicy.ApplicationTypeHealthPolicyMap.Add(entry.Key, entry.Value); } } } if (this.EventsHealthStateFilter.HasValue) { this.WriteWarning(StringResources.PowerShell_EventsHealthStateFilter_Deprecated); if (!this.EventsFilter.HasValue) { this.EventsFilter = (HealthStateFilter)this.EventsHealthStateFilter; } } if (this.EventsFilter.HasValue) { queryDescription.EventsFilter = new HealthEventsFilter() { HealthStateFilterValue = this.EventsFilter.Value, }; } if (this.NodesHealthStateFilter.HasValue) { this.WriteWarning(StringResources.PowerShell_NodesHealthStateFilter_Deprecated); if (!this.NodesFilter.HasValue) { this.NodesFilter = (HealthStateFilter)this.NodesHealthStateFilter; } } if (this.NodesFilter.HasValue) { queryDescription.NodesFilter = new NodeHealthStatesFilter() { HealthStateFilterValue = this.NodesFilter.Value, }; } if (this.ApplicationsHealthStateFilter.HasValue) { this.WriteWarning(StringResources.PowerShell_ApplicationsHealthStateFilter_Deprecated); if (!this.ApplicationsFilter.HasValue) { this.ApplicationsFilter = (HealthStateFilter)this.ApplicationsHealthStateFilter; } } if (this.ApplicationsFilter.HasValue) { queryDescription.ApplicationsFilter = new ApplicationHealthStatesFilter() { HealthStateFilterValue = this.ApplicationsFilter.Value, }; } if (this.ApplicationHealthPolicyMap != null) { foreach (var entry in this.ApplicationHealthPolicyMap) { queryDescription.ApplicationHealthPolicyMap.Add(entry.Key, entry.Value); } } if (this.ExcludeHealthStatistics) { queryDescription.HealthStatisticsFilter = new ClusterHealthStatisticsFilter() { ExcludeHealthStatistics = this.ExcludeHealthStatistics }; } if (this.IncludeSystemApplicationHealthStatistics) { queryDescription.HealthStatisticsFilter = new ClusterHealthStatisticsFilter() { IncludeSystemApplicationHealthStatistics = this.IncludeSystemApplicationHealthStatistics }; } var clusterHealth = clusterConnection.GetClusterHealthAsync( queryDescription, this.GetTimeout(), this.GetCancellationToken()).Result; this.WriteObject(this.FormatOutput(clusterHealth)); } catch (AggregateException aggregateException) { aggregateException.Handle((ae) => { this.ThrowTerminatingError( ae, Constants.GetClusterHealthErrorId, clusterConnection); return(true); }); } }
public GetClusterHealthRequest(ClusterHealthQueryDescription queryDescription, IFabricClient fabricClient, TimeSpan timeout) : base(fabricClient, timeout) { ThrowIf.Null(queryDescription, "queryDescription"); this.QueryDescription = queryDescription; }