Пример #1
0
 /// <summary>
 /// <para>
 /// Resolves a partition of the specified service by invoking FabricClient's
 /// <see cref="FabricClient.ServiceManagementClient.ResolveServicePartitionAsync(System.Uri)" />method. This uses the default settings for
 /// <see cref="DefaultResolveTimeout">timeout</see> and <see cref="DefaultMaxRetryBackoffInterval">back-off retry</see> intervals.
 /// </para>
 /// </summary>
 /// <param name="serviceUri">Name of the service instance to resolve.</param>
 /// <param name="partitionKey">
 /// <para>
 /// <see cref="ServicePartitionKey">Key</see> that determines the target partition of the service instance. The <see cref="ServicePartitionKind">partitioning scheme</see>
 /// specified in the key should match the partitioning scheme used to create the service instance.
 /// </para>
 /// </param>
 /// <param name="cancellationToken">
 /// <para>
 /// The CancellationToken that this operation is observing. It is used to notify the operation that it should be canceled.
 /// </para>
 /// </param>
 /// <returns>
 /// A <see cref="System.Threading.Tasks.Task">Task</see> that represents outstanding operation. The result from
 /// the task is the <see cref="System.Fabric.ResolvedServicePartition" /> object, that contains the information
 /// about the resolved service partition including the service endpoints.
 /// </returns>
         /// <exception cref="System.Fabric.FabricServiceNotFoundException">
         /// <para>
         /// This method can throw a FabricServiceNotFoundExcepion if there is no service instance in the cluster matching the specified serviceUri.
         /// </para>
         /// </exception>
         /// <exception cref="System.Fabric.FabricException">
         /// <para>
         /// This method can throw a FabricException if the scheme specified in the ServicePartitionKey doesn't match the scheme used to create the service instance.
         /// See also <see href="https://azure.microsoft.com/documentation/articles/service-fabric-errors-and-exceptions/">Errors and Exceptions</see> for handling common FabricClient failures.
         /// </para>
         /// </exception>
         /// <remarks>
         /// <para>
         /// This method retries on all transient exceptions. For cases where you want to limit the max execution time of this method, you should create a <see href="https://docs.microsoft.com/en-us/dotnet/core/api/system.threading.cancellationtokensource#System_Threading_CancellationTokenSource__ctor_System_TimeSpan_">cancellation token associated with that max execution time</see>
         /// and pass that cancellation token to this method.
         /// </para>
         /// </remarks>
 public Task <ResolvedServicePartition> ResolveAsync(
     Uri serviceUri,
     ServicePartitionKey partitionKey,
     CancellationToken cancellationToken)
 {
     return(this.ResolveAsync(
                serviceUri,
                partitionKey,
                DefaultResolveTimeout,
                DefaultMaxRetryBackoffInterval,
                cancellationToken));
 }
Пример #2
0
        /// <summary>
        /// Resolves a partition of the specified service by invoking FabricClient's
        /// <see cref="FabricClient.ServiceManagementClient.ResolveServicePartitionAsync(System.Uri)" /> method with the given timeout and back-off/retry on retry-able errors.
        /// </summary>
        /// <param name="serviceUri">Name of the service instance to resolve.</param>
        /// <param name="partitionKey">
        /// <para>
        /// <see cref="ServicePartitionKey">Key</see> that determines the target partition of the service instance. The <see cref="ServicePartitionKind">partitioning scheme</see>
        /// specified in the key should match the partitioning scheme used to create the service instance.
        /// </para>
        /// </param>
        /// <param name="resolveTimeoutPerTry">The timeout passed to FabricClient's <see cref="FabricClient.ServiceManagementClient.ResolveServicePartitionAsync(System.Uri)" />method.</param>
        /// <param name="maxRetryBackoffInterval">
        /// <para>
        /// The max interval to back-off before retrying when FabricClient's <see cref="FabricClient.ServiceManagementClient.ResolveServicePartitionAsync(System.Uri)" />method fails with a retry-able exception.
        /// The actual back off interval is a random time interval which is less than or equal to the specified maxRetryBackoffInterval.
        /// </para>
        /// </param>
        /// <param name="cancellationToken">
        /// <para>
        /// The CancellationToken that this operation is observing. It is used to notify the operation that it should be canceled.
        /// </para>
        /// </param>
        /// <returns>
        /// A <see cref="System.Threading.Tasks.Task">Task</see> that represents outstanding operation. The result from
        /// the task is the <see cref="System.Fabric.ResolvedServicePartition" /> object, that contains the information
        /// about the resolved service partition including the service endpoints.
        /// </returns>
                /// <exception cref="System.Fabric.FabricServiceNotFoundException">
                /// <para>
                /// This method can throw a FabricServiceNotFoundExcepion if there is no service instance in the cluster matching the specified serviceUri.
                /// </para>
                /// </exception>
                /// <exception cref="System.Fabric.FabricException">
                /// <para>
                /// This can throw a FabricException if the scheme specified in the ServicePartitionKey doesn't match the scheme used to create the service instance.
                /// See also <see href="https://azure.microsoft.com/documentation/articles/service-fabric-errors-and-exceptions/">Errors and Exceptions</see> for more information.
                /// </para>
                /// </exception>
                /// <remarks>
                /// <para>
                /// This method retries on all transient exceptions. For cases where you want to limit the max execution time of this method, you should create a <see href="https://docs.microsoft.com/en-us/dotnet/core/api/system.threading.cancellationtokensource#System_Threading_CancellationTokenSource__ctor_System_TimeSpan_">cancellation token associated with that max execution time</see>
                /// and pass that cancellation token to this method.
                /// </para>
                /// </remarks>
        public Task <ResolvedServicePartition> ResolveAsync(
            Uri serviceUri,
            ServicePartitionKey partitionKey,
            TimeSpan resolveTimeoutPerTry,
            TimeSpan maxRetryBackoffInterval,
            CancellationToken cancellationToken)
        {
            if (partitionKey == null)
            {
                partitionKey = ServicePartitionKey.Singleton;
            }

            switch (partitionKey.Kind)
            {
            case ServicePartitionKind.Singleton:
            {
                return(this.ResolveAsyncHelper(
                           (client, prevRsp, timeout, cancellation) => ResolveSingletonPartitionAsync(
                               client,
                               serviceUri,
                               prevRsp,
                               timeout,
                               cancellation),
                           null,
                           resolveTimeoutPerTry,
                           maxRetryBackoffInterval,
                           cancellationToken));
            }

            case ServicePartitionKind.Named:
            {
                return(this.ResolveAsyncHelper(
                           (client, prevRsp, timeout, cancellation) => ResolveNamedPartitionAsync(
                               client,
                               serviceUri,
                               (string)partitionKey.Value,
                               prevRsp,
                               timeout,
                               cancellation),
                           null,
                           resolveTimeoutPerTry,
                           maxRetryBackoffInterval,
                           cancellationToken));
            }

            case ServicePartitionKind.Int64Range:
            {
                return(this.ResolveAsyncHelper(
                           (client, prevRsp, timeout, cancellation) => ResolveInt64PartitionAsync(
                               client,
                               serviceUri,
                               (long)partitionKey.Value,
                               prevRsp,
                               timeout,
                               cancellation),
                           null,
                           resolveTimeoutPerTry,
                           maxRetryBackoffInterval,
                           cancellationToken));
            }

            default:
                throw new ArgumentOutOfRangeException("partitionKey");
            }
        }