Esempio n. 1
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");
        }
        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
        }