/// <summary> /// Instantiates a ServicePartitionResolver, uses the given security credentials, FabricClient Settings and the connectionEndpoints /// to create a new instance of FabricClient. /// </summary> /// <param name="credential">Security credentials for the fabric client.</param> /// <param name="settings">Fabric client Settings.</param> /// <param name="connectionEndpoints">Array of management endpoints of the cluster.</param> public ServicePartitionResolver( SecurityCredentials credential, FabricClientSettings settings, params string[] connectionEndpoints) : this(() => new FabricClient(credential, settings, connectionEndpoints)) { }
public void FabricClientRetryPolicy_2_OperationShouldTimeout() { FabricClientSettings fcs = new FabricClientSettings() { ConnectionInitializationTimeout = TimeSpan.FromSeconds(5) }; FabricClientRetryPolicy rp = new FabricClientRetryPolicy(fcs, 5, new FixedWaitingPolicy(TimeSpan.FromMilliseconds(10)), AllErrorsTransientDetectionStrategy.Instance); Stopwatch sp = Stopwatch.StartNew(); bool operationCanceled = false; int attempts = 0; try { rp.ExecuteWithRetriesAsync((ct) => Task.Run(async() => { attempts++; await Task.Delay(Timeout.Infinite, ct); }), TimeSpan.FromMilliseconds(50), CancellationToken.None).GetAwaiter().GetResult(); } catch (TimeoutException) { Assert.IsTrue(sp.Elapsed < TimeSpan.FromSeconds(5), sp.Elapsed.ToString()); operationCanceled = true; } Assert.IsNotNull(rp.Client); Assert.AreEqual(5, attempts); Assert.AreEqual(true, operationCanceled); }
public FabricClientHelperInfo(string name, string[] gatewayAddresses, string[] httpGatewayAddresses, SecurityCredentials securityCredentials, FabricClientSettings clientSettings, FabricClientTypes type) { ThrowIf.NullOrEmpty(name, "name"); this.Name = name; if (gatewayAddresses != null && gatewayAddresses.Length > 0) { this.GatewayAddresses = gatewayAddresses; } if (httpGatewayAddresses != null && httpGatewayAddresses.Length > 0) { this.HttpGatewayAddresses = httpGatewayAddresses; } this.SecurityCredentials = securityCredentials; this.ClientSettings = clientSettings; this.ClientTypes = type; }
/// <summary> /// Creates a new instance of the <see cref="FabricClientRetryPolicy"/> type. /// </summary> /// <param name="settings"><see cref="FabricClientSettings"/> instance.</param> /// <param name="maxAttempts">The maximum number of times an operation should be retried, must be positive.</param> /// <param name="waitingPolicy">The waiting policy to use, cannot be null.</param> /// <param name="defaultErrorDetectionStrategy">The default error detection strategy to use, cannot be null.</param> /// <param name="useFastRetriesForTesting">A flag indicating if we should use fast retries for testing, default is False</param> /// <exception cref="ArgumentNullException">If some of the non-nullable arguments are null.</exception> /// <exception cref="ArgumentOutOfRangeException">If the <paramref name="maxAttempts"/> argument is not positive.</exception> public FabricClientRetryPolicy(FabricClientSettings settings, int maxAttempts, WaitingPolicy waitingPolicy, ITransientErrorDetectionStrategy defaultErrorDetectionStrategy, bool useFastRetriesForTesting = false) { // Check the pre-conditions Guard.ArgumentNotNull(settings, nameof(settings)); Guard.ArgumentNotZeroOrNegativeValue(maxAttempts, nameof(maxAttempts)); Guard.ArgumentNotNull(waitingPolicy, nameof(waitingPolicy)); Guard.ArgumentNotNull(defaultErrorDetectionStrategy, nameof(defaultErrorDetectionStrategy)); // Assign the fields _fabricClientSettings = settings; Client = CreateClient(); MaxAttempts = maxAttempts; WaitingPolicy = waitingPolicy; DefaultErrorDetectionStrategy = defaultErrorDetectionStrategy; UseFastRetriesForTesting = useFastRetriesForTesting; }
private static int Main(string[] args) { try { string message = string.Format("NodeAgentSFUtility called with Arguments = {0}", string.Join(", ", args)); Console.WriteLine(message); ServiceEventSource.Current.InfoMessage(message); FabricClientSettings settings = new FabricClientSettings(); settings.HealthReportSendInterval = TimeSpan.FromSeconds(0); FabricClient fabricClient = new FabricClient(settings); Microsoft.ServiceFabric.PatchOrchestration.NodeAgentSFUtility.CommandProcessor commandProcessor = new Microsoft.ServiceFabric.PatchOrchestration.NodeAgentSFUtility.CommandProcessor(fabricClient, ServiceEventSource.Current); var task = commandProcessor.ProcessArguments(args); task.Wait(); message = string.Format("NodeAgentSFUtility returned = {0}", task.Result); Console.WriteLine(message); ServiceEventSource.Current.InfoMessage(message); return((int)task.Result); } catch (Exception e) { string message = string.Format("NodeAgentSFUtility failed with exception : {0}", e); Console.WriteLine(message); ServiceEventSource.Current.ErrorMessage(message); if (e is DllNotFoundException) { return((int)NodeAgentSfUtilityExitCodes.DllNotFoundException); } else if (e is FabricTransientException) { return((int)NodeAgentSfUtilityExitCodes.RetryableException); } else { return((int)NodeAgentSfUtilityExitCodes.Failure); } } }
/// <summary> /// Instantiates a ServicePartitionResolver, uses the given FabricClient Settings and the connectionEndpoints to create /// a new instance of FabricClient. /// </summary> /// <param name="settings">Fabric client Settings.</param> /// <param name="connectionEndpoints">Array of management endpoints of the cluster.</param> public ServicePartitionResolver( FabricClientSettings settings, params string[] connectionEndpoints) : this(() => new FabricClient(settings, connectionEndpoints)) { }