示例#1
0
 private static void RemoveNodeConfigurationXCopy(string machineName, bool deleteLog, string nodeName)
 {
     try
     {
         string fabricDataRoot = Utility.GetFabricDataRoot(machineName);
         if (string.IsNullOrEmpty(fabricDataRoot))
         {
             DeployerTrace.WriteWarning("FabricDataRoot on machine {0} is empty or not present; no current installation likely exists", machineName);
         }
         else
         {
             DeployerTrace.WriteInfo("FabricDataRoot on machine {0} is {1}", machineName, fabricDataRoot);
             FabricDeployerServiceController.GetServiceInStoppedState(machineName, Constants.FabricInstallerServiceName);
             WriteTargetInformationFile(fabricDataRoot, machineName, deleteLog, nodeName);
             RunInstallerService(machineName);
         }
         FabricDeployerServiceController.DeleteFabricInstallerService(machineName);
         Utility.DeleteRegistryKeyTree(machineName);
     }
     catch (TimeoutException)
     {
         DeployerTrace.WriteError("FabricInstallerSvc timeout on machine {0}. Cleaning up to avoid environment corruption.", machineName);
         SuppressExceptions(() => { FabricDeployerServiceController.StopHostSvc(machineName); });
         SuppressExceptions(() => { FabricDeployerServiceController.DeleteFabricHostService(machineName); });
         SuppressExceptions(() => { FabricDeployerServiceController.StopInstallerSvc(machineName); });
         SuppressExceptions(() => { FabricDeployerServiceController.DeleteFabricInstallerService(machineName); });
         SuppressExceptions(() => { Utility.DeleteRegistryKeyTree(machineName); });
         throw;
     }
 }
示例#2
0
        private void RemoveNodeConfigurationMsi(bool deleteLog)
        {
            DeployerTrace.WriteInfo("Checking if fabric host is running");
            if (FabricDeployerServiceController.IsRunning(Helpers.GetMachine()))
            {
                DeployerTrace.WriteInfo("Stopping fabric host");
                FabricDeployerServiceController.StopHostSvc(Helpers.GetMachine());
            }

            string fabricCodePath = String.Empty;

            try
            {
                fabricCodePath = FabricEnvironment.GetCodePath();
            }
            catch (FabricException)
            {
                DeployerTrace.WriteError(StringResources.Error_FabricCodePathNotFound);
            }

            string fabricSetupFilepath = Path.Combine(fabricCodePath, "FabricSetup.exe");

            ProcessStartInfo FabricSetupExeStartInfo = new ProcessStartInfo();

            FabricSetupExeStartInfo.FileName         = fabricSetupFilepath;
            FabricSetupExeStartInfo.Arguments        = string.Format("/operation:removenodestate");
            FabricSetupExeStartInfo.WorkingDirectory = fabricCodePath == String.Empty ? Directory.GetCurrentDirectory() : fabricCodePath;

            try
            {
                using (Process exeProcess = Process.Start(FabricSetupExeStartInfo))
                {
                    DeployerTrace.WriteInfo("Starting FabricSetup.exe");
                    exeProcess.WaitForExit();
                }
            }
            catch (Exception e)
            {
                DeployerTrace.WriteError("Starting FabricSetup.exe failed with exception {0}.", e);
            }

            string value = deleteLog ? DeleteLogTrue : DeleteLogFalse;

            using (RegistryKey regKey = Registry.LocalMachine.OpenSubKey(FabricConstants.FabricRegistryKeyPath, true))
            {
                regKey.SetValue(Constants.Registry.RemoveNodeConfigurationValue, value);
            }

            DeployerTrace.WriteInfo("Starting fabric host");
            FabricDeployerServiceController.StartHostSvc();

            DeployerTrace.WriteInfo("Stopping fabric host");
            FabricDeployerServiceController.StopHostSvc();

            DeployerTrace.WriteInfo("Cleaning registry value");
            DeleteRemoveNodeConfigurationRegistryValue(string.Empty);

            DeployerTrace.WriteInfo("Done cleaning registry value");
        }
        private void ConfigureFromManifest(DeploymentParameters parameters, ClusterManifestType clusterManifest, Infrastructure infrastructure)
        {
            SetupSettings settings = new SetupSettings(clusterManifest);

#if !DotNetCoreClrLinux
            if (!string.IsNullOrEmpty(settings.ServiceRunAsAccountName))
            {
                FabricDeployerServiceController.SetServiceCredentials(settings.ServiceRunAsAccountName, settings.ServiceRunAsPassword, parameters.MachineName);
                DeployerTrace.WriteInfo("Set Service Fabric Host Service to run as {0}", settings.ServiceRunAsAccountName);
            }
#endif

            string clusterManifestTargetLocation = Helpers.GetRemotePath(Path.Combine(parameters.FabricDataRoot, "clusterManifest.xml"), parameters.MachineName);
            DeployerTrace.WriteInfo("Copying ClusterManifest to {0}", clusterManifestTargetLocation);

            if (!ArePathesEqual(parameters.ClusterManifestLocation, clusterManifestTargetLocation))
            {
                File.Copy(parameters.ClusterManifestLocation, clusterManifestTargetLocation, true);
            }

#if !DotNetCoreClrLinux
            string serviceStartupType = "DelayedAutoStart";
            if (!string.IsNullOrEmpty(parameters.ServiceStartupType))
            {
                FabricDeployerServiceController.SetStartupType(parameters.ServiceStartupType);
                serviceStartupType = parameters.ServiceStartupType;
            }
            else if (!string.IsNullOrEmpty(settings.ServiceStartupType))
            {
                FabricDeployerServiceController.SetStartupType(settings.ServiceStartupType);
                serviceStartupType = settings.ServiceStartupType;
            }
            else
            {
                if (infrastructure is AzureInfrastructure)
                {
                    FabricDeployerServiceController.SetServiceStartupType(FabricDeployerServiceController.ServiceStartupType.Manual, parameters.MachineName);
                    serviceStartupType = FabricDeployerServiceController.ServiceStartupType.Manual.ToString();
                }
                else
                {
                    FabricDeployerServiceController.SetStartupTypeDelayedAuto(parameters.MachineName);
                }
            }
            DeployerTrace.WriteInfo("Set Service Fabric Host Service to start up type to {0}", serviceStartupType);
#endif
        }
        protected override void OnExecuteOperation(DeploymentParameters parameters, ClusterManifestType clusterManifest, Infrastructure infrastructure)
        {
#if !DotNetCoreClrLinux
            if (FabricDeployerServiceController.IsRunning(parameters.MachineName))
            {
                string message = string.Format(StringResources.Error_FabricDeployer_FabricHostStillRunning_Formatted, parameters.MachineName);
                DeployerTrace.WriteError(message);
                throw new InvalidOperationException(message);
            }
#endif
            DeployerTrace.WriteInfo("Creating FabricDataRoot {0}, if it doesn't exist on machine {1}", parameters.FabricDataRoot, parameters.MachineName);
            Helpers.CreateDirectoryIfNotExist(parameters.FabricDataRoot, parameters.MachineName);
            DeployerTrace.WriteInfo("Creating FabricLogRoot {0}, if it doesn't exist on machine {1}", parameters.FabricLogRoot, parameters.MachineName);
            Helpers.CreateDirectoryIfNotExist(Path.Combine(parameters.FabricLogRoot, Constants.TracesFolderName), parameters.MachineName);

            List <LogicalDirectoryType[]> logicalDirectorysSetForThisMachine = new List <LogicalDirectoryType[]>();

            // For single machine scale min, fabric deployer only runs once for all nodes. It may miss the nodeType that has the logicalApplicationDirectory section.
            // So here, we need to extract all the logicalApplicationDirectories sections from clusterManifest.
            if ((clusterManifest.Infrastructure.Item is ClusterManifestTypeInfrastructureWindowsServer &&
                 ((ClusterManifestTypeInfrastructureWindowsServer)clusterManifest.Infrastructure.Item).IsScaleMin) ||
                (clusterManifest.Infrastructure.Item is ClusterManifestTypeInfrastructureLinux &&
                 ((ClusterManifestTypeInfrastructureLinux)clusterManifest.Infrastructure.Item).IsScaleMin))
            {
                FabricNodeType[] nodeList;
                nodeList = clusterManifest.Infrastructure.Item is ClusterManifestTypeInfrastructureWindowsServer ?
                           ((ClusterManifestTypeInfrastructureWindowsServer)clusterManifest.Infrastructure.Item).NodeList :
                           ((ClusterManifestTypeInfrastructureLinux)clusterManifest.Infrastructure.Item).NodeList;

                foreach (var node in nodeList)
                {
                    var logicalDirectories = clusterManifest.NodeTypes.Where(nodeType => nodeType.Name == node.NodeTypeRef).First().LogicalDirectories;
                    if (logicalDirectories != null)
                    {
                        logicalDirectorysSetForThisMachine.Add(logicalDirectories);
                    }
                }
            }
            else if (clusterManifest.Infrastructure.Item is ClusterManifestTypeInfrastructurePaaS ||
                     clusterManifest.Infrastructure.Item is ClusterManifestTypeInfrastructureWindowsServer ||
                     clusterManifest.Infrastructure.Item is ClusterManifestTypeInfrastructureLinux) // PaaS doesn't support Scale Min.
            {
                if (!string.IsNullOrEmpty(parameters.MachineName))                                  //For cab deployment
                {
                    var logicalDirectories = clusterManifest.NodeTypes.Where(nt => nt.Name == Utility.GetNodeTypeFromMachineName(clusterManifest, infrastructure.GetInfrastructureManifest(), parameters.MachineName)).First().LogicalDirectories;
                    if (logicalDirectories != null)
                    {
                        logicalDirectorysSetForThisMachine.Add(logicalDirectories);
                    }
                }
                else //For msi deployment
                {
                    foreach (var infrastructureNode in infrastructure.InfrastructureNodes)
                    {
                        bool isNodeForThisMachine = NetworkApiHelper.IsNodeForThisMachine(infrastructureNode);
                        if (isNodeForThisMachine)
                        {
                            var logicalDirectories = clusterManifest.NodeTypes.Where(nt => nt.Name == infrastructureNode.NodeTypeRef).First().LogicalDirectories;
                            if (logicalDirectories != null)
                            {
                                logicalDirectorysSetForThisMachine.Add(logicalDirectories);
                            }
                        }
                    }
                }
            }

            if (logicalDirectorysSetForThisMachine.Any())
            {
                CreateLogicalDirectoriesForAllTheNodesOnThisMachineAndEnableRegKey(parameters.MachineName, logicalDirectorysSetForThisMachine);
            }

            FabricValidatorWrapper fabricValidator = new FabricValidatorWrapper(parameters, clusterManifest, infrastructure);
            fabricValidator.ValidateAndEnsureDefaultImageStore();

            if (!string.IsNullOrEmpty(parameters.BootstrapMSIPath)) // Mandatory for Standalone path
            {
                CopyBaselinePackageIfPathExists(parameters.BootstrapMSIPath, parameters.FabricDataRoot, parameters.DeploymentPackageType, parameters.MachineName);
            }

            SetFabricRegistrySettings(parameters);
            ConfigureFromManifest(parameters, clusterManifest, infrastructure);

            string destinationCabPath = Path.Combine(parameters.FabricDataRoot, Constants.FileNames.BaselineCab);
            WriteTargetInformationFile(
                parameters.ClusterManifestLocation,
                parameters.InfrastructureManifestLocation,
                parameters.FabricDataRoot,
                parameters.MachineName,
                destinationCabPath,
                parameters.DeploymentPackageType,
                parameters.BootstrapMSIPath);

            WriteFabricHostSettingsFile(parameters.FabricDataRoot, new SettingsType(), parameters.MachineName);

#if !DotNetCoreClrLinux
            if (!string.IsNullOrEmpty(parameters.FabricPackageRoot))
            {
                FabricDeployerServiceController.InstallFabricInstallerService(parameters.FabricPackageRoot, parameters.MachineName);
            }
#endif

            if (!string.IsNullOrEmpty(parameters.JsonClusterConfigLocation))
            {
                string destinationConfigPath = Helpers.GetRemotePath(
                    Path.Combine(parameters.FabricDataRoot, Constants.FileNames.BaselineJsonClusterConfig), parameters.MachineName);
                File.Copy(parameters.JsonClusterConfigLocation, destinationConfigPath, true);
            }
        }
        protected void CleanupDeployment(DeploymentParameters parameters)
        {
#if !DotNetCoreClr // Disable compiling on windows for now. Need to correct when porting FabricDeployer for windows.
            if (AccountHelper.IsAdminUser())
            {
                CollectEventLogs();

                FabricDeployerServiceController.DisableService();
                if (!parameters.SkipFirewallConfiguration)
                {
                    FirewallManager.DisableFirewallSettings();
                }
                DeployerTrace.WriteInfo("Stopping data collectors");
                PerformanceCounters.StopDataCollector();

                DeployerTrace.WriteInfo("Deleting data collectors");
                PerformanceCounters.DeleteDataCollector();
            }
            else
            {
                DeployerTrace.WriteWarning(
                    "Deployer is not run as Administrator. Skipping Firewall Management and Performance Counter Management. Possible Post remove cleanup required");
            }

            if (FabricDeployerServiceController.IsRunning(parameters.MachineName))
            {
                throw new InvalidDeploymentException(StringResources.Error_FabricDeployer_FabricHostStillRunning_Formatted);
            }
#else
            DeployerTrace.WriteInfo("CoreClr: Skipping Firewall Management and Performance Counter Management cleanup on CoreClr.");
#endif
            string targetInformationFileName = Path.Combine(parameters.FabricDataRoot, Constants.FileNames.TargetInformation);
            DeleteTargetInformationFile(targetInformationFileName);

#if DotNetCoreClr // Disable compiling on windows for now. Need to correct when porting FabricDeployer for windows.
            bool skipDeleteFabricDataRoot = Utility.GetSkipDeleteFabricDataRoot() ||
                                            (parameters.SkipDeleteFabricDataRoot != null && string.Equals(parameters.SkipDeleteFabricDataRoot, "true", StringComparison.OrdinalIgnoreCase));
#else
            bool skipDeleteFabricDataRoot = Utility.GetSkipDeleteFabricDataRoot() ||
                                            (parameters.SkipDeleteFabricDataRoot != null && string.Equals(parameters.SkipDeleteFabricDataRoot, "true", StringComparison.InvariantCultureIgnoreCase));
#endif

            if (skipDeleteFabricDataRoot)
            {
                DeployerTrace.WriteInfo("Skipping deletion of Data Root.");
            }
            else
            {
                NetCloseResource(parameters.FabricDataRoot);
                SafeDeleteDirectory(parameters.FabricDataRoot, parameters.FabricLogRoot, Path.Combine(parameters.FabricDataRoot, Constants.FileNames.FabricHostSettings));
                List <SettingsTypeSection> sections = new List <SettingsTypeSection>();
                sections.Add(new SettingsTypeSection()
                {
                    Name = Constants.SectionNames.Setup
                });
                WriteFabricHostSettingsFile(parameters.FabricDataRoot, new SettingsType()
                {
                    Section = sections.ToArray()
                }, parameters.MachineName);
            }

#if !DotNetCoreClr // Disable compiling on windows for now. Need to correct when porting FabricDeployer for windows.
            SpnManager.CleanupSpn();
#else
            DeployerTrace.WriteInfo("CoreClrLinux: SPN cleanning skipped for Linux");
#endif
#if !DotNetCoreClrIOT
            new DockerDnsHelper(parameters, string.Empty).CleanupAsync().GetAwaiter().GetResult();

            // Clean up docker network set up
            var containerNetworkCleanupOperation = new ContainerNetworkCleanupOperation();
            containerNetworkCleanupOperation.ExecuteOperation(parameters.ContainerNetworkName);
#endif
        }
示例#6
0
        private static void RunInstallerService(string machineName)
        {
            var      installerSvcStartedTimeout = TimeSpan.FromMinutes(Constants.FabricInstallerServiceStartTimeoutInMinutes);
            TimeSpan retryInterval = TimeSpan.FromSeconds(5);
            int      retryCount    = 20;

            bool isLocalIp = System.Fabric.Common.Helpers.IsLocalIpAddress(machineName);

            Task startInstallerTask = Task.Run(() =>
            {
                try
                {
                    Type[] exceptionTypes = { typeof(InvalidOperationException), typeof(ComponentModel.Win32Exception) };
                    Helpers.PerformWithRetry(() =>
                    {
                        // Each installerSvc handle/manager should be kept in its own thread context. Tossing this around leads to race condition failures in .NET.
                        ServiceController installerSvc = FabricDeployerServiceController.GetService(Constants.FabricInstallerServiceName, machineName);
                        installerSvc.WaitForStatus(ServiceControllerStatus.Running, installerSvcStartedTimeout);
                    },
                                             exceptionTypes,
                                             retryInterval,
                                             retryCount);

                    DeployerTrace.WriteInfo("FabricInstallerSvc started on machine {0}", machineName);
                }
                catch (ServiceProcess.TimeoutException)
                {
                    throw new ServiceProcess.TimeoutException(string.Format("Timed out waiting for Installer Service to start for machine {0}.", machineName));
                }
            });

            {
                ServiceController installerSvc = FabricDeployerServiceController.GetService(Constants.FabricInstallerServiceName, machineName);
                if (isLocalIp)
                {
                    installerSvc.Start();
                }
                else
                {
                    installerSvc.Start(new string[] { Constants.FabricInstallerServiceAutocleanArg });
                }
            }
            startInstallerTask.Wait(installerSvcStartedTimeout); // Locks until service is started or reaches timeout

            DeployerTrace.WriteInfo("Waiting for FabricInstallerService to stop after completing Fabric Uninstallation");
            var waitTimeLimit = TimeSpan.FromMinutes(Constants.FabricUninstallTimeoutInMinutes);

            try
            {
                Type[] exceptionTypes = { typeof(InvalidOperationException), typeof(ComponentModel.Win32Exception) };
                Helpers.PerformWithRetry(() =>
                {
                    ServiceController installerSvc = FabricDeployerServiceController.GetService(Constants.FabricInstallerServiceName, machineName);
                    installerSvc.WaitForStatus(ServiceControllerStatus.Stopped, waitTimeLimit);
                },
                                         exceptionTypes,
                                         retryInterval,
                                         retryCount);
            }
            catch (System.ServiceProcess.TimeoutException)
            {
                DeployerTrace.WriteError("FabricInstallerService Stop timed out after {0}.", waitTimeLimit.ToString());
            }

            {
                ServiceController       installerSvc  = FabricDeployerServiceController.GetService(Constants.FabricInstallerServiceName, machineName);
                ServiceControllerStatus serviceStatus = installerSvc.Status;
                if (serviceStatus != ServiceControllerStatus.Stopped)
                {
                    string errorMessage = string.Format(CultureInfo.InvariantCulture,
                                                        "FabricInstallerService is in {0} state and hasn't returned to STOPPED state after uninstall timeout period",
                                                        serviceStatus.ToString());
                    DeployerTrace.WriteError(errorMessage);
                    throw new System.TimeoutException(errorMessage);
                }
            }
        }