public static void ThrowTransientExceptionIfRetryable(Exception e)
 {
     if (e is OperationCanceledException ||
         e is TransactionFaultedException ||
         e is FabricNotReadableException ||
         e is FabricNotPrimaryException)
     {
         throw FaultAnalysisServiceUtility.CreateException(TraceType, Interop.NativeTypes.FABRIC_ERROR_CODE.E_ABORT, "Operation cancelled");
     }
 }
        public static async Task <Node> GetNodeInfoAsync(
            Guid operationId,
            FabricClient fc,
            string nodeName,
            IStatefulServicePartition partition,
            IReliableStateManager stateManager,
            IReliableDictionary <string, bool> stoppedNodeTable,
            TimeSpan requestTimeout,
            TimeSpan operationTimeout,
            CancellationToken cancellationToken)
        {
            // validate
            var nodeList = await FabricClientRetryHelper.ExecuteFabricActionWithRetryAsync(
                () => fc.TestManager.GetNodeListInternalAsync(
                    nodeName,
                    NodeStatusFilter.All,
                    null,
                    true,
                    requestTimeout,
                    cancellationToken),
                operationTimeout,
                cancellationToken).ConfigureAwait(false);

            if (nodeList.Count == 0 ||
                (nodeList[0].NodeStatus == NodeStatus.Invalid ||
                 nodeList[0].NodeStatus == NodeStatus.Unknown ||
                 nodeList[0].NodeStatus == NodeStatus.Removed))
            {
                await FaultAnalysisServiceUtility.SetStoppedNodeStateAsync(
                    operationId,
                    partition,
                    stateManager,
                    stoppedNodeTable,
                    nodeName,
                    false,
                    cancellationToken).ConfigureAwait(false);

                // this is fatal, fail the command
                Exception nodeNotFound = FaultAnalysisServiceUtility.CreateException(
                    TraceType,
                    NativeTypes.FABRIC_ERROR_CODE.FABRIC_E_NODE_NOT_FOUND,
                    string.Format(CultureInfo.InvariantCulture, "Node {0} not found", nodeName),
                    FabricErrorCode.NodeNotFound);
                throw new FatalException("fatal", nodeNotFound);
            }

            return(nodeList[0]);
        }