Beispiel #1
0
 public static void OpenRemoteRegistryNamedPipe(string machineName, TimeSpan timeout)
 {
     SFDeployerTrace.WriteNoise(StringResources.Info_SFOpenRegNamedPipe, machineName);
     using (var namedPipeClientStream = new NamedPipeClientStream(machineName, DMConstants.RemoteRegistryNamedPipeName, System.IO.Pipes.PipeDirection.In))
     {
         int timeoutInMs = (int)Math.Max((double)DMConstants.NamedPipeConnectTimeoutInMs, timeout.TotalMilliseconds);
         try
         {
             namedPipeClientStream.Connect(timeoutInMs);
             SFDeployerTrace.WriteInfo(StringResources.Info_SFOpenRegNamedPipeSuccess, machineName);
         }
         catch (TimeoutException ex)
         {
             SFDeployerTrace.WriteWarning(StringResources.Error_SFOpenRegNamedPipeTimeout, machineName, ex.Message);
         }
         catch (InvalidOperationException ex)
         {
             SFDeployerTrace.WriteWarning(StringResources.Error_SFOpenRegNamedPipeAlreadyConnected, machineName, ex.Message);
         }
         catch (IOException ex)
         {
             SFDeployerTrace.WriteWarning(StringResources.Error_SFOpenRegNamedPipeAnotherClientAlreadyConnected, machineName, ex.Message);
         }
     }
 }
Beispiel #2
0
        internal static StandAloneInstallerJsonModelBase GetJsonConfigFromString(string jsonString)
        {
            try
            {
                SFDeployerTrace.WriteNoise(StringResources.Info_BPAConvertingJsonToModel);
                StandAloneInstallerJsonModelBase result = DeserializeJsonConfig(typeof(StandAloneInstallerJsonModelGA), jsonString);

                var entry = StandAloneInstallerJsonModelBase.apiVersionTable.FirstOrDefault(p => p.Item1 == result.ApiVersion);
                if (entry != null)
                {
                    Type modelType = entry.Item2;
                    result = DeserializeJsonConfig(modelType, jsonString);

                    if (DevJsonModel.IsDevCluster(result))
                    {
                        result = DeserializeJsonConfig(typeof(DevJsonModel), jsonString);
                    }

                    return(result);
                }
                else
                {
                    SFDeployerTrace.WriteWarning(string.Format("Json parsing: Unrecognized api version '{0}'", result.ApiVersion));
                    throw new NotSupportedException(result.ApiVersion + " is not supported!");
                }
            }
            catch (Exception e)
            {
                var message = string.Format(
                    CultureInfo.InvariantCulture,
                    "{0}:{1}",
                    StringResources.Error_SFJsonConfigInvalid,
                    e.ToString());
                SFDeployerTrace.WriteError(message);
                return(null);
            }
        }
        internal bool EnoughHealthyMachines()
        {
            int currentHealthyCount = this.machinesHealthDic.Where(machine => machine.Value).Count();

            if (this.MaxPercentFailedNodes == 0)
            {
                return(currentHealthyCount == this.totalMachineCount);
            }

            int unhealthyCount      = this.totalMachineCount - currentHealthyCount;
            int unhealthyPercentage = 100 * unhealthyCount / this.totalMachineCount;

            if (unhealthyPercentage > this.MaxPercentFailedNodes)
            {
                SFDeployerTrace.WriteError(StringResources.Error_NotEnoughHealthyMachines, unhealthyPercentage, unhealthyCount, this.totalMachineCount, this.MaxPercentFailedNodes);
                return(false);
            }
            else if (unhealthyPercentage < 100)
            {
                SFDeployerTrace.WriteWarning(StringResources.Warning_SomeMachinesFailed, currentHealthyCount);
            }

            return(true);
        }
Beispiel #4
0
        internal static async Task <string> GetContentsFromUriAsyncWithRetry(Uri uri, TimeSpan retryInterval, TimeSpan operationTimeout, CancellationToken cancellationToken)
        {
            string downloadedContent = null;
            var    timeoutHelper     = new System.Fabric.Common.TimeoutHelper(operationTimeout);

            while (!System.Fabric.Common.TimeoutHelper.HasExpired(timeoutHelper))
            {
                cancellationToken.ThrowIfCancellationRequested();

                try
                {
                    if (uri.IsFile)
                    {
                        downloadedContent = File.ReadAllText(uri.LocalPath);
                    }
                    else
                    {
                        using (var wc = new WebClient())
                        {
                            downloadedContent = await wc.DownloadStringTaskAsync(uri).ConfigureAwait(false);
                        }
                    }

                    return(downloadedContent);
                }
                catch (Exception e)
                {
                    SFDeployerTrace.WriteWarning(StringResources.Error_SFUriNotDownloaded, uri, e.ToString());
                }

                await Task.Delay(retryInterval, cancellationToken).ConfigureAwait(false);
            }

            SFDeployerTrace.WriteError(StringResources.Error_SFTimedOut, operationTimeout);
            throw new FabricValidationException(string.Format(StringResources.Error_SFTimedOut, operationTimeout), FabricErrorCode.OperationCanceled);
        }
        private static bool CheckRPCAccess(MachineHealthContainer machineHealthContainer)
        {
            var retryTimeout = new System.Fabric.Common.TimeoutHelper(DMConstants.BpaRpcRetryTimeout);

            SFDeployerTrace.WriteNoise(StringResources.Info_SFRpcInfo);

            Parallel.ForEach <string>(
                machineHealthContainer.GetHealthyMachineNames(),
                (string machine) =>
            {
                bool result = true;
                bool willRetry;

                do
                {
                    willRetry = false;

                    try
                    {
                        Utility.GetTempPath(machine);
                    }
                    catch (Exception ex)
                    {
                        string message;
                        if (ex is System.IO.IOException)
                        {
                            switch (ex.HResult)
                            {
                            // If new failures are discovered: https://msdn.microsoft.com/en-us/library/windows/desktop/ms681382(v=vs.85).aspx
                            case 53:         // ERROR_BAD_NETPATH
                                message   = string.Format(StringResources.Error_SFRpcIoNetpath, machine, ex.HResult);
                                willRetry = true;
                                break;

                            case 1723:         // RPC_S_SERVER_TOO_BUSY
                                message   = string.Format(StringResources.Error_SFRpcIoTooBusy, machine, ex.HResult);
                                willRetry = true;
                                break;

                            case 1727:         // RPC_S_CALL_FAILED_DNE
                                message = string.Format(StringResources.Error_SFRpcIoFailedDne, machine, ex.HResult);
                                break;

                            default:
                                message = string.Format(StringResources.Error_SFRpcIoGeneric, machine, ex.HResult);
                                break;
                            }
                        }
                        else if (ex is System.Security.SecurityException)
                        {
                            switch (ex.HResult)
                            {
                            case -2146233078:         // COR_E_SECURITY
                                message = string.Format(StringResources.Error_SFRpcSecAccess, machine, ex.HResult);
                                break;

                            default:
                                message = string.Format(StringResources.Error_SFRpcSecGeneric, machine, ex.HResult);
                                break;
                            }
                        }
                        else if (ex is NullReferenceException)
                        {
                            switch (ex.HResult)
                            {
                            case -2146232828:         // COR_E_TARGETINVOCATION
                                message = string.Format(StringResources.Error_SFRpcNullRegAccess, machine, ex.HResult);
                                break;

                            default:
                                message = string.Format(StringResources.Error_SFRpcNullGeneric, machine, ex.HResult);
                                break;
                            }
                        }
                        else
                        {
                            // This is to catch coding errors.
                            message = string.Format(StringResources.Error_SFRpcGeneric, machine, ex.HResult);
                        }

                        willRetry &= !System.Fabric.Common.TimeoutHelper.HasExpired(retryTimeout);

                        if (willRetry)
                        {
                            SFDeployerTrace.WriteWarning(message);

                            StandaloneUtility.OpenRemoteRegistryNamedPipe(machine, retryTimeout.GetRemainingTime());

                            Thread.Sleep(TimeSpan.FromSeconds(5));
                        }
                        else
                        {
                            SFDeployerTrace.WriteError(message);

                            result = false;
                        }
                    }
                }while (willRetry);

                if (!result)
                {
                    machineHealthContainer.MarkMachineAsUnhealthy(machine);
                }
            });

            return(machineHealthContainer.EnoughHealthyMachines());
        }