public async Task <ServicePartitionList> GetPartitionsAsync(CancellationToken ct) { ReleaseAssert.AssertIfNull(FabricClientRetryErrors.GetPartitionListFabricErrors.Value, "partition list error code"); var retryableErrors = new FabricClientRetryErrors(); retryableErrors.RetryableFabricErrorCodes.AddRangeNullSafe(FabricClientRetryErrors.GetPartitionListFabricErrors.Value.RetryableFabricErrorCodes); retryableErrors.RetryableExceptions.AddRangeNullSafe(FabricClientRetryErrors.GetPartitionListFabricErrors.Value.RetryableExceptions); retryableErrors.RetryableFabricErrorCodes.Add(FabricErrorCode.PartitionNotFound); ServicePartitionList servicePartitionList = new ServicePartitionList(); string continuationToken = null; do { ServicePartitionList queryResult = await FabricClientRetryHelper.ExecuteFabricActionWithRetryAsync( () => this.TestContext.FabricClient.QueryManager.GetPartitionListAsync( this.serviceName, null, continuationToken, this.requestTimeout, ct), retryableErrors, this.operationTimeout, ct).ConfigureAwait(false); servicePartitionList.AddRangeNullSafe(queryResult); continuationToken = queryResult.ContinuationToken; } while (!string.IsNullOrEmpty(continuationToken)); return(servicePartitionList); }
public async Task <ValidationReport> ValidateHealthWithReportAsync(TimeSpan maximumStabilizationTimeout, TimeSpan retryWait, CancellationToken ct) { TestabilityTrace.TraceSource.WriteInfo(TraceSource, "Validating that '{0}' is healthy with timeout '{1}'.", this.serviceName, maximumStabilizationTimeout); TimeoutHelper timer = new TimeoutHelper(maximumStabilizationTimeout); bool success = false; string healthinfo = string.Empty; int retryCount = 1; while (!success && timer.GetRemainingTime() > TimeSpan.Zero) { TestabilityTrace.TraceSource.WriteInfo(TraceSource, "ValidateHealthWithReportAsync(): retryCount='{0}', timer.GetRemainingTime()='{1}'", retryCount, timer.GetRemainingTime()); healthinfo = string.Empty; if (this.TestContext == null) { Console.WriteLine("testcontext is null"); } ReleaseAssert.AssertIfNull(this.TestContext, "test context"); ReleaseAssert.AssertIfNull(this.serviceName, "serviceName"); ReleaseAssert.AssertIfNull(FabricClientRetryErrors.GetEntityHealthFabricErrors.Value, "health error code"); ApplicationHealthPolicy healthPolicy = new ApplicationHealthPolicy(); var serviceHealthResult = await FabricClientRetryHelper.ExecuteFabricActionWithRetryAsync( () => this.TestContext.FabricClient.HealthManager.GetServiceHealthAsync( this.serviceName, healthPolicy, this.requestTimeout, ct), FabricClientRetryErrors.GetEntityHealthFabricErrors.Value, timer.GetRemainingTime(), ct).ConfigureAwait(false); bool checkError = (this.checkFlags & ValidationCheckFlag.CheckError) != 0; bool checkWarning = (this.checkFlags & ValidationCheckFlag.CheckWarning) != 0; if ((checkError && serviceHealthResult.AggregatedHealthState == HealthState.Error) || (checkWarning && serviceHealthResult.AggregatedHealthState == HealthState.Warning) || serviceHealthResult.AggregatedHealthState == HealthState.Invalid || serviceHealthResult.AggregatedHealthState == HealthState.Unknown) { TestabilityTrace.TraceSource.WriteInfo(TraceSource, "{0} is health state is {1}. Will Retry check", this.serviceName, serviceHealthResult.AggregatedHealthState); healthinfo = await this.GetUnhealthyItemsAsync(serviceHealthResult, timer, ct).ConfigureAwait(false); TestabilityTrace.TraceSource.WriteInfo(TraceSource, healthinfo); } else { success = true; } if (!success) { if (retryCount % 10 == 0) { TestabilityTrace.TraceSource.WriteWarning(TraceSource, "Service {0} health validation failed due to issues below, will retry: \n{1}", this.serviceName, healthinfo); } // Delay before querying again so we allow some time for state to change - don't spam the node await AsyncWaiter.WaitAsync(retryWait); } retryCount++; } if (!success) { return(new ValidationReport(true, StringHelper.Format(StringResources.Error_ServiceNotHealthy, serviceName, maximumStabilizationTimeout, healthinfo))); } else { return(ValidationReport.Default); } }