// Clean install requires machine be free of previous Fabric installations private static bool CheckForCleanInstall(StandAloneInstallerJsonModelBase config, MachineHealthContainer machineHealthContainer, bool isForcedRun = false) { SFDeployerTrace.WriteNoise(StringResources.Info_BPANoFabric); List <string> machineNamesTemp = StandaloneUtility.GetMachineNamesIncludingClient(machineHealthContainer.GetHealthyMachineNames()); var importantSettings = config.GetFabricSystemSettings(); string fabricDataRoot = importantSettings.ContainsKey(DMConstants.FabricDataRootString) ? importantSettings[DMConstants.FabricDataRootString] : null; bool localMachineFailed = false; Parallel.ForEach( machineNamesTemp, (string machineName) => { bool result = true; if (StandaloneUtility.IsFabricInstalled(machineName)) { SFDeployerTrace.WriteError(StringResources.Error_BPAPreviousFabricExists, machineName); result = false; } if (!isForcedRun) { if (fabricDataRoot != null) { IEnumerable <string> machineNodes = config.Nodes.Where(n => n.IPAddress == machineName).Select(n => n.NodeName); foreach (string node in machineNodes) { string nodeDirectory; if (StandaloneUtility.DataRootNodeExists(machineName, node, fabricDataRoot, out nodeDirectory)) { SFDeployerTrace.WriteError(StringResources.Error_BPADataRootNodeExists, node, machineName, nodeDirectory); result = false; } } } } if (!result) { if (Helpers.IsLocalIpAddress(machineName)) { localMachineFailed = true; } else { machineHealthContainer.MarkMachineAsUnhealthy(machineName); } } }); if (localMachineFailed) { return(false); } return(machineHealthContainer.EnoughHealthyMachines()); }
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); } } }
internal static bool IsFabricInstalled(string machineName) { bool result = true; try { if (NodeConfiguration.GetNodeConfiguration(machineName) == null && !FabricDeployerServiceController.ServiceExists(System.Fabric.FabricDeployer.Constants.FabricHostServiceName, machineName)) { SFDeployerTrace.WriteNoise(StringResources.Info_BPAFabricNotInstalledOnMachine, machineName); result = false; } } catch (System.Fabric.FabricException ex) { SFDeployerTrace.WriteNoise(StringResources.Info_BPAFabricInstalledHitFabricException_Formatted, machineName, ex); result = false; } catch (System.InvalidOperationException ex /*Internal exception: System.Xml.Schema.InvalidOperationException*/) { SFDeployerTrace.WriteNoise(StringResources.Info_BPAFabricInstalledHitIOX_Formatted, machineName, ex); result = false; } SFDeployerTrace.WriteNoise(StringResources.Info_BPAFabricInstalledOnMachine, machineName, result); return(result); }
internal static async Task <bool> IsUriReachableAsync( Uri uri, string requestMethod = DMConstants.HttpMethodHead, int operationTimeoutInMs = DMConstants.UriReachableTimeoutInMs, int requestTimeoutInMs = DMConstants.UriRequestTimeoutInMs, int retryIntervalInMs = DMConstants.UriReachableRetryIntervalInMs) { ReleaseAssert.AssertIf(uri == null, "uri cannot be null for IsUriReachableAsync."); if (uri.IsFile) { FileInfo fi = new FileInfo(uri.LocalPath); return(fi.Exists); } else { if (string.IsNullOrWhiteSpace(uri.Host)) { return(false); } var timeout = new System.Fabric.Common.TimeoutHelper(TimeSpan.FromMilliseconds(operationTimeoutInMs)); while (!System.Fabric.Common.TimeoutHelper.HasExpired(timeout)) { WebRequest request = WebRequest.Create(uri); #if !DotNetCoreClrLinux request.Timeout = requestTimeoutInMs; #endif request.Method = requestMethod; try { using (WebResponse response = await request.GetResponseAsync().ConfigureAwait(false)) { if (response is HttpWebResponse) { if (((HttpWebResponse)response).StatusCode == HttpStatusCode.OK) { return(true); } return(false); } else { return(response.ContentLength > 0); } } } catch (WebException ex) { SFDeployerTrace.WriteNoise(StringResources.Error_SFUriUnreachable_Formatted, uri, ex.Message); } System.Threading.Thread.Sleep(retryIntervalInMs); } } return(false); }
public static FileInfo ClusterManifestToFile(ClusterManifestType cm, string clusterName, string version) { string clusterManifestName = string.Format(Microsoft.ServiceFabric.DeploymentManager.Constants.ClusterManifestNameFormat, clusterName, version); string clusterManifestPath = Path.Combine(Path.GetTempPath(), clusterManifestName); SFDeployerTrace.WriteNoise(StringResources.Info_SFWritingClusterManifest, clusterManifestPath); XMLHelper.WriteXmlExclusive <ClusterManifestType>(clusterManifestPath, cm); return(new FileInfo(clusterManifestPath)); }
private static bool CheckLocalAdminPrivilege() { SFDeployerTrace.WriteNoise(StringResources.Info_BPAValidatingAdmin); bool result = AccountHelper.IsAdminUser(); if (!result) { SFDeployerTrace.WriteError(StringResources.Error_SFPreconditionsAdminUserRequired); } return(result); }
private static bool CheckFirewallEnabled(MachineHealthContainer machineHealthContainer) { SFDeployerTrace.WriteNoise(StringResources.Info_BPAWindowsFirewall); Parallel.ForEach( machineHealthContainer.GetHealthyMachineNames(), (string machineName) => { bool result = true; try { FabricDeployerServiceController.ServiceStartupType type = FabricDeployerServiceController.GetServiceStartupType(machineName, DMConstants.FirewallServiceName); if (type == FabricDeployerServiceController.ServiceStartupType.Disabled) { SFDeployerTrace.WriteError(StringResources.Error_BPAFirewallServiceDisabled, machineName); result = false; } } catch (Exception ex) { SFDeployerTrace.WriteError(StringResources.Error_BPAFirewallServiceQueryException, machineName, ex.Message); result = false; } try { ServiceController firewallSvc = FabricDeployerServiceController.GetService(DMConstants.FirewallServiceName, machineName); ServiceControllerStatus status = firewallSvc.Status; if (status == ServiceControllerStatus.Stopped || status == ServiceControllerStatus.StopPending) { SFDeployerTrace.WriteError(StringResources.Error_BPAFirewallServiceNotRunning, machineName, status.ToString()); result = false; } } catch (Exception ex) { SFDeployerTrace.WriteError(StringResources.Error_BPAFirewallServiceStatusException, machineName, ex.Message); result = false; } if (!result) { machineHealthContainer.MarkMachineAsUnhealthy(machineName); } }); return(machineHealthContainer.EnoughHealthyMachines()); }
private static bool CheckRemoteRegistryEnabled(MachineHealthContainer machineHealthContainer) { SFDeployerTrace.WriteNoise(StringResources.Info_BPARemoteRegistry); Parallel.ForEach( machineHealthContainer.GetHealthyMachineNames(), (string machineName) => { bool result = true; int retryCount = 5; for (int i = 0; i < retryCount; i++) { try { FabricDeployerServiceController.ServiceStartupType type = FabricDeployerServiceController.GetServiceStartupType(machineName, DMConstants.RemoteRegistryServiceName); if (type == FabricDeployerServiceController.ServiceStartupType.Disabled) { SFDeployerTrace.WriteError(StringResources.Error_BPARemoteRegistryServiceDisabled, machineName); result = false; } break; } catch (Exception ex) { SFDeployerTrace.WriteError(StringResources.Error_BPARemoteRegistryQueryException, machineName, ex.Message, i); if (i < retryCount - 1) { Thread.Sleep(TimeSpan.FromSeconds(10)); } else { result = false; } } } if (!result) { machineHealthContainer.MarkMachineAsUnhealthy(machineName); } }); return(machineHealthContainer.EnoughHealthyMachines()); }
private static bool CheckIsCabFile(string cabPath) { SFDeployerTrace.WriteNoise(StringResources.Info_BPAValidatingCab, cabPath); bool result = CabFileOperations.IsCabFile(cabPath); if (!result) { SFDeployerTrace.WriteError(StringResources.Error_SFCabInvalid, cabPath); return(result); } result = FileSignatureVerifier.IsSignatureValid(cabPath); if (!result) { SFDeployerTrace.WriteError(StringResources.Error_InvalidCodePackage); } // Add Signature Validation. return(result); }
// Single machine/node override, for AddNode internal static bool CheckForCleanInstall(string machineName, string nodeName, string fabricDataRoot) { SFDeployerTrace.WriteNoise(StringResources.Info_BPANoFabric); bool result = true; if (IsFabricInstalled(machineName)) { SFDeployerTrace.WriteError(StringResources.Error_BPAPreviousFabricExists, machineName); result = false; } string nodeDirectory; if (DataRootNodeExists(machineName, nodeName, fabricDataRoot, out nodeDirectory)) { SFDeployerTrace.WriteError(StringResources.Error_BPADataRootNodeExists, nodeName, machineName, nodeDirectory); result = false; } return(result); }
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); } }
private static bool CheckDataSystemDrives(MachineHealthContainer machineHealthContainer, string fabricDataRoot, string fabricLogRoot) { bool systemDataDriveExists = true; bool systemLogDriveExists = true; if (fabricDataRoot != null) { // Verify path system drive exists on each machine to be deployed Parallel.ForEach( machineHealthContainer.GetHealthyMachineNames(), (string machineName) => { try { string remotePath = Helpers.GetRemotePathIfNotLocalMachine(fabricDataRoot, machineName); var info = new DirectoryInfo(remotePath); if (!info.Root.Exists) { SFDeployerTrace.WriteError(StringResources.Error_BPAJsonDataRootRootDriveDoesNotExist, DMConstants.FabricDataRootString, machineName); systemDataDriveExists = false; machineHealthContainer.MarkMachineAsUnhealthy(machineName); } } catch (Exception ex) { SFDeployerTrace.WriteNoise(StringResources.Error_BPAJsonDataRootRootDriveQueryException, DMConstants.FabricDataRootString, ex); systemDataDriveExists = false; machineHealthContainer.MarkMachineAsUnhealthy(machineName); } }); if (!systemDataDriveExists) { SFDeployerTrace.WriteError(StringResources.Error_BPAJsonDataRootRootDriveDoesNotExistGeneric, DMConstants.FabricDataRootString); } } if (fabricLogRoot != null) { Parallel.ForEach( machineHealthContainer.GetHealthyMachineNames(), (string machineName) => { try { string remotePath = Helpers.GetRemotePathIfNotLocalMachine(fabricLogRoot, machineName); var info = new DirectoryInfo(remotePath); if (!info.Root.Exists) { SFDeployerTrace.WriteError(StringResources.Error_BPAJsonDataRootRootDriveDoesNotExist, DMConstants.FabricLogRootString, machineName); systemLogDriveExists = false; machineHealthContainer.MarkMachineAsUnhealthy(machineName); } } catch (Exception ex) { SFDeployerTrace.WriteError(StringResources.Error_BPAJsonDataRootRootDriveQueryException, DMConstants.FabricLogRootString, ex); systemLogDriveExists = false; machineHealthContainer.MarkMachineAsUnhealthy(machineName); } }); if (!systemLogDriveExists) { SFDeployerTrace.WriteError(StringResources.Error_BPAJsonDataRootRootDriveDoesNotExistGeneric, DMConstants.FabricLogRootString); } } return(machineHealthContainer.EnoughHealthyMachines()); }
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()); }
internal static bool IsMsiInstalled(MachineHealthContainer machineHealthContainer) { SFDeployerTrace.WriteNoise(StringResources.Info_BPAConflictingInstallations); var fabricProductNames = new string[] { "Windows Fabric", "Microsoft Service Fabric", "Microsoft Azure Service Fabric" }; bool localMachineFailed = false; List <string> machineNamesTemp = GetMachineNamesIncludingClient(machineHealthContainer.GetHealthyMachineNames()); Parallel.ForEach( machineNamesTemp, (string machineName) => { bool result = false; using (RegistryKey uninstallKeys = GetHklm(machineName).OpenSubKey(DMConstants.UninstallProgramsBaseKey)) { if (uninstallKeys != null) { Parallel.ForEach( uninstallKeys.GetSubKeyNames(), (string guid) => { using (RegistryKey uninstallKey = uninstallKeys.OpenSubKey(guid)) { string uninstallString = (string)uninstallKey.GetValue("UninstallString", null); if (uninstallString != null) { string displayNameValue = (string)uninstallKey.GetValue("DisplayName", null); if (displayNameValue != null) { displayNameValue = displayNameValue.Trim(); if (uninstallString.IndexOf("msiexec.exe", StringComparison.OrdinalIgnoreCase) >= 0) { foreach (string productName in fabricProductNames) { if (string.Equals(displayNameValue, productName, StringComparison.OrdinalIgnoreCase)) { SFDeployerTrace.WriteError(StringResources.Error_BPAMsiIsInstalled, displayNameValue, machineName); result = true; } } } } } } }); } } if (result) { if (Helpers.IsLocalIpAddress(machineName)) { localMachineFailed = true; } else { machineHealthContainer.MarkMachineAsUnhealthy(machineName); } } }); if (localMachineFailed) { return(true); } return(!machineHealthContainer.EnoughHealthyMachines()); }
internal static bool CheckRequiredPorts(MachineHealthContainer machineHealthContainer) { SFDeployerTrace.WriteNoise(StringResources.Info_BPARequiredPorts); int[] requiredPorts = { DMConstants.SmbFileSharePort }; bool result = true; foreach (string machineFqdn in machineHealthContainer.GetHealthyMachineNames()) { if (Uri.CheckHostName(machineFqdn) == UriHostNameType.Unknown) { result = false; SFDeployerTrace.WriteError(StringResources.Error_BPAMachineNotPingable, machineFqdn); } } if (!result) { return(false); } foreach (int port in requiredPorts) { Parallel.ForEach( machineHealthContainer.GetHealthyMachineNames(), (string machineName) => { result = true; IPAddress address = null; bool isParseableAsIPAddress = IPAddress.TryParse(machineName, out address); if (isParseableAsIPAddress) { if (address.AddressFamily == AddressFamily.InterNetwork) { SFDeployerTrace.WriteNoise("Using IPv4 address for {0}", machineName); } else if (address.AddressFamily == AddressFamily.InterNetworkV6) { SFDeployerTrace.WriteNoise("Using IPv6 address for {0}", machineName); } else { SFDeployerTrace.WriteError(StringResources.Error_BPAPortConnectFailed, machineName, port, "Expected IPv4 or IPv6 address"); result = false; return; } try { using (TcpClient client = new TcpClient(address.AddressFamily)) { client.Connect(address, port); } } catch (SocketException ex) { SFDeployerTrace.WriteError(StringResources.Error_BPAPortConnectFailed, machineName, port, ex.Message); result = false; } } else { try { using (new TcpClient(machineName, port)) { // Intentionally empty. The constructor already establishes a connection } } catch (SocketException ex) { SFDeployerTrace.WriteError(StringResources.Error_BPAPortConnectFailed, machineName, port, ex.Message); result = false; } } if (!result) { machineHealthContainer.MarkMachineAsUnhealthy(machineName); } }); } return(machineHealthContainer.EnoughHealthyMachines()); }