Example #1
0
        protected override void OnExecuteOperation(DeploymentParameters parameters, ClusterManifestType targetClusterManifest, Infrastructure infrastructure)
        {
            DeployerTrace.UpdateConsoleLevel(EventLevel.Verbose);

            try
            {
                string currentNodeIPAddressOrFQDN = string.Empty;
                if ((infrastructure != null) && (infrastructure.InfrastructureNodes != null))
                {
                    foreach (var infraNode in infrastructure.InfrastructureNodes)
                    {
                        if (NetworkApiHelper.IsAddressForThisMachine(infraNode.IPAddressOrFQDN))
                        {
                            currentNodeIPAddressOrFQDN = infraNode.IPAddressOrFQDN;
                            break;
                        }
                    }
                }

                new DockerDnsHelper(parameters, currentNodeIPAddressOrFQDN).SetupAsync().GetAwaiter().GetResult();
            }
            catch (Exception ex)
            {
                DeployerTrace.WriteWarning(
                    StringResources.Warning_FabricDeployer_DockerDnsSetup_ErrorContinuing2,
                    ex);
            }
        }
Example #2
0
        internal static bool ReduceDynamicPortRange(List <NodeSettings> nodes, bool isScaleMin)
        {
            if (isScaleMin && NetworkApiHelper.IsAddressLoopback(nodes[0].IPAddressOrFQDN))
            {
                return(true);
            }

            List <Tuple <int, int> > portRanges = GetDynamicPortRangeForNodes(nodes);

            foreach (Tuple <int, int> portRange in portRanges)
            {
                ReduceDynamicPortRange(portRange.Item1, portRange.Item2);
            }

            return(true);
        }
Example #3
0
        /// <summary>
        /// This function enables the firewall exceptions for all the nodes provied. The exceptions are for lease driver port, application ports and fabric process.
        /// </summary>
        /// <param name="nodes">The list of nodes for which exceptions need to be provided.</param>
        /// <param name="isScaleMin">Whether te deployment is scale min or not.</param>
        /// <param name="securitySection"> The security section which specifies what type of firewall profiles to set.</param>
        /// <param name="removeRulesIfNotRequired">Should we delete the existing rules that are not required.</param>
        /// <returns>true if exceptions are all enabled, false otherwise.</returns>
        public static bool EnableFirewallSettings(List <NodeSettings> nodes, bool isScaleMin, SettingsOverridesTypeSection securitySection, bool removeRulesIfNotrequired)
        {
            Firewall fw = new Firewall();

            if (!fw.IsEnabled())
            {
                return(true);
            }

            if (isScaleMin && NetworkApiHelper.IsAddressLoopback(nodes[0].IPAddressOrFQDN))
            {
                return(true);
            }

            List <FirewallRule> newRules = GetRulesForNodes(nodes, securitySection);

            fw.UpdateRules(newRules, removeRulesIfNotrequired);
            return(true);
        }
        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);
            }
        }
Example #5
0
        private void RemoveLogicalDirectoriesIfExist(string fabricDataRoot, string machineName)
        {
            if (machineName == null)
            {
                machineName = "";
            }

            ClusterManifestType clusterManifest = null;

            var clusterManifestLocation = Helpers.GetCurrentClusterManifestPath(fabricDataRoot);

            if (clusterManifestLocation == null)
            {
                clusterManifestLocation = Directory.EnumerateFiles(
                    fabricDataRoot,
                    "clusterManifest.xml",
                    SearchOption.AllDirectories).FirstOrDefault();
            }

            if (clusterManifestLocation != null)
            {
                clusterManifest = XMLHelper.ReadClusterManifest(clusterManifestLocation);
            }
            else
            {
                DeployerTrace.WriteWarning(string.Format(StringResources.Warning_clusterManifestFileMissingInDataRoot, fabricDataRoot, machineName));
            }

            if (clusterManifest != null)
            {
                InfrastructureInformationType infrastructure = null;
                FabricNodeType[] nodeList;

                if ((clusterManifest.Infrastructure.Item is ClusterManifestTypeInfrastructureWindowsServer &&
                     ((ClusterManifestTypeInfrastructureWindowsServer)clusterManifest.Infrastructure.Item).IsScaleMin) ||
                    (clusterManifest.Infrastructure.Item is ClusterManifestTypeInfrastructureLinux &&
                     ((ClusterManifestTypeInfrastructureLinux)clusterManifest.Infrastructure.Item).IsScaleMin))
                {
                    DeployerTrace.WriteInfo(string.Format("Checking to remove logicalDirectories for one box scale min deployment. Machine name: {0}.", machineName));

                    // Get all the nodes on this IP's LogicalDirectories and remove the all directoies.
                    nodeList = clusterManifest.Infrastructure.Item is ClusterManifestTypeInfrastructureWindowsServer ?
                               ((ClusterManifestTypeInfrastructureWindowsServer)clusterManifest.Infrastructure.Item).NodeList :
                               ((ClusterManifestTypeInfrastructureLinux)clusterManifest.Infrastructure.Item).NodeList;

                    RemoveLogicalDirectoies(clusterManifest, nodeList, machineName);
                }
                else if (clusterManifest.Infrastructure.Item is ClusterManifestTypeInfrastructurePaaS) // PaaS doesn't support scale min.
                {
                    var infrastructureManifestLocation = Helpers.GetInfrastructureManifestPath(fabricDataRoot);
                    if (infrastructureManifestLocation == null)
                    {
                        DeployerTrace.WriteWarning(string.Format(StringResources.Warning_infrastructureManifestFileMissingInDataRoot, fabricDataRoot, machineName));
                        return;
                    }

                    infrastructure = XMLHelper.ReadInfrastructureManifest(infrastructureManifestLocation);

                    // Get all the nodes on this IP's LogicalDirectories and remove the all directories.
                    var len = infrastructure.NodeList.Length;
                    nodeList = new FabricNodeType[len];
                    for (var i = 0; i < len; i++)
                    {
                        FabricNodeType fabricNode = new FabricNodeType()
                        {
                            NodeName        = infrastructure.NodeList[i].NodeName,
                            FaultDomain     = infrastructure.NodeList[i].FaultDomain,
                            IPAddressOrFQDN = infrastructure.NodeList[i].IPAddressOrFQDN,
                            IsSeedNode      = infrastructure.NodeList[i].IsSeedNode,
                            NodeTypeRef     = infrastructure.NodeList[i].NodeTypeRef,
                            UpgradeDomain   = infrastructure.NodeList[i].UpgradeDomain
                        };

                        nodeList[i] = fabricNode;
                    }

                    RemoveLogicalDirectoies(clusterManifest, nodeList, machineName);
                }
                else if (clusterManifest.Infrastructure.Item is ClusterManifestTypeInfrastructureWindowsServer ||
                         clusterManifest.Infrastructure.Item is ClusterManifestTypeInfrastructureLinux)
                {
                    nodeList = clusterManifest.Infrastructure.Item is ClusterManifestTypeInfrastructureWindowsServer ?
                               ((ClusterManifestTypeInfrastructureWindowsServer)clusterManifest.Infrastructure.Item).NodeList :
                               ((ClusterManifestTypeInfrastructureLinux)clusterManifest.Infrastructure.Item).NodeList;
                    if (!string.IsNullOrEmpty(machineName)) //For cab deployment
                    {
                        DeployerTrace.WriteInfo(string.Format("Checking to remove logicalDirectories for WindowsServer/Linux deployment with cab. Machine name: {0}.", machineName));
                        RemoveLogicalDirectoies(clusterManifest, nodeList, machineName);
                    }
                    else
                    {
                        DeployerTrace.WriteInfo(string.Format("Checking to remove logicalDirectories for WindowsServer/Linux deployment with MSI. Machine name: {0}.", machineName));
                        foreach (var node in nodeList)
                        {
                            InfrastructureNodeType infraNode = new InfrastructureNodeType()
                            {
                                NodeName        = node.NodeName,
                                NodeTypeRef     = node.NodeTypeRef,
                                IPAddressOrFQDN = node.IPAddressOrFQDN,
                                IsSeedNode      = node.IsSeedNode,
                                FaultDomain     = node.FaultDomain,
                                UpgradeDomain   = node.UpgradeDomain
                            };

                            bool isNodeForThisMachine = NetworkApiHelper.IsNodeForThisMachine(infraNode);
                            if (isNodeForThisMachine)
                            {
                                FabricNodeType[] fabricNodes = new FabricNodeType[1];
                                FabricNodeType   fabricNode  = new FabricNodeType()
                                {
                                    NodeName        = node.NodeName,
                                    FaultDomain     = node.FaultDomain,
                                    IPAddressOrFQDN = node.IPAddressOrFQDN,
                                    IsSeedNode      = node.IsSeedNode,
                                    NodeTypeRef     = node.NodeTypeRef,
                                    UpgradeDomain   = node.UpgradeDomain
                                };

                                fabricNodes[0] = fabricNode;
                                RemoveLogicalDirectoies(clusterManifest, fabricNodes, machineName);
                            }
                        }
                    }
                }
            }
        }
Example #6
0
        protected override void OnExecuteOperation(DeploymentParameters parameters, ClusterManifestType clusterManifest, Infrastructure infrastructure)
        {
            var isRunningAsAdmin = AccountHelper.IsAdminUser();

            if (!isRunningAsAdmin)
            {
                DeployerTrace.WriteWarning(StringResources.Warning_DeployerNotRunAsAdminSkipFirewallAndPerformanceCounter);
                return;
            }

            if (clusterManifest == null)
            {
                DeployerTrace.WriteError(StringResources.Error_FabricHostStartedWithoutConfiguringTheNode);
                throw new ArgumentException(StringResources.Error_FabricHostStartedWithoutConfiguringTheNode);
            }

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

            if (!parameters.SkipFirewallConfiguration)
            {
                var securitySection = manifest.FabricSettings.FirstOrDefault(fabSetting => fabSetting.Name.Equals(Constants.SectionNames.Security, StringComparison.OrdinalIgnoreCase));

#if DotNetCoreClrLinux
                if (isRunningAsAdmin && clusterManifest.Infrastructure.Item is ClusterManifestTypeInfrastructureLinux)
                {
                    var currentInfrastructure = clusterManifest.Infrastructure.Item as ClusterManifestTypeInfrastructureLinux;
#else
                if (isRunningAsAdmin && clusterManifest.Infrastructure.Item is ClusterManifestTypeInfrastructureWindowsServer)
                {
                    var currentInfrastructure = clusterManifest.Infrastructure.Item as ClusterManifestTypeInfrastructureWindowsServer;
#endif

                    var nodeSettings = GetNodeSettings();
                    var isScaleMin   = currentInfrastructure.IsScaleMin;
                    FirewallManager.EnableFirewallSettings(nodeSettings, isScaleMin, securitySection, this is UpdateNodeStateOperation);
                    NetworkApiHelper.ReduceDynamicPortRange(nodeSettings, isScaleMin);
                }
                else if (isRunningAsAdmin)
                {
                    var nodeSettings = GetNodeSettings();
                    FirewallManager.EnableFirewallSettings(nodeSettings, false, securitySection, this is UpdateNodeStateOperation);
                    NetworkApiHelper.ReduceDynamicPortRange(nodeSettings, false);
                }
            }

#if !DotNetCoreClrIOT && !DotNetCoreClrLinux
            ResetNetworks(parameters, clusterManifest, infrastructure);
#endif

#if !DotNetCoreClrIOT
            if (parameters.ContainerDnsSetup == ContainerDnsSetup.Allow || parameters.ContainerDnsSetup == ContainerDnsSetup.Require)
            {
                try
                {
                    string currentNodeIPAddressOrFQDN = string.Empty;
                    if ((infrastructure != null) && (infrastructure.InfrastructureNodes != null))
                    {
                        foreach (var infraNode in infrastructure.InfrastructureNodes)
                        {
                            DeployerTrace.WriteInfo("Infra node <{0}> params.NodeName <{1}>", infraNode.NodeName, parameters.NodeName);
                            if (NetworkApiHelper.IsAddressForThisMachine(infraNode.IPAddressOrFQDN))
                            {
                                currentNodeIPAddressOrFQDN = infraNode.IPAddressOrFQDN;
                                DeployerTrace.WriteInfo("Found node IPAddressOrFQDN <{0}>", currentNodeIPAddressOrFQDN);
                                break;
                            }
                        }
                    }

                    new DockerDnsHelper(parameters, currentNodeIPAddressOrFQDN).SetupAsync().GetAwaiter().GetResult();
                }
                catch (Exception ex)
                {
                    if (parameters.ContainerDnsSetup == ContainerDnsSetup.Require)
                    {
                        DeployerTrace.WriteError(
                            StringResources.Error_FabricDeployer_DockerDnsSetup_ErrorNotContinuing,
                            Constants.ParameterNames.ContainerDnsSetup,
                            parameters.ContainerDnsSetup,
                            ex);
                        throw;
                    }

                    DeployerTrace.WriteWarning(
                        StringResources.Warning_FabricDeployer_DockerDnsSetup_ErrorContinuing,
                        Constants.ParameterNames.ContainerDnsSetup,
                        parameters.ContainerDnsSetup,
                        ex);
                }
            }
            else if (parameters.ContainerDnsSetup == ContainerDnsSetup.Disallow)
            {
                // cleanupasync catches all exceptions
                new DockerDnsHelper(parameters, string.Empty).CleanupAsync().GetAwaiter().GetResult();
            }
#endif

#if !DotNetCoreClr // Disable compiling on windows for now. Need to correct when porting FabricDeployer for windows.
            if (!PerformanceCounters.StartCollection(clusterManifest.FabricSettings, parameters.DeploymentSpecification))
            {
                DeployerTrace.WriteWarning(StringResources.Error_FabricDeployer_StartCounterCollectionFailed_Formatted);
            }

            if (fabricValidator.ShouldRegisterSpnForMachineAccount)
            {
                if (!SpnManager.EnsureSpn())
                {
                    throw new InvalidDeploymentException(StringResources.Error_FabricDeployer_FailedToRegisterSpn_Formatted);
                }
            }
#endif
        }
Example #7
0
        public List <NodeSettings> GetNodeSettings()
        {
            var versions = new Versions(
                manifest.Version,
                parameters.InstanceId,
                parameters.TargetVersion,
                parameters.CurrentVersion ?? Utility.GetCurrentCodeVersion(null));

            List <NodeSettings> nodeSettings = new List <NodeSettings>();

            for (int i = 0; i < RestartOperation.RetryCount; i++)
            {
                foreach (var infrastructureNode in infrastructure.InfrastructureNodes)
                {
                    bool isNodeForThisMachine = NetworkApiHelper.IsNodeForThisMachine(infrastructureNode);
                    if (isNodeForThisMachine)
                    {
                        ClusterManifestTypeNodeType nodeType = manifest.NodeTypes.FirstOrDefault(nodeTypeVar => nodeTypeVar.Name.Equals(infrastructureNode.NodeTypeRef, StringComparison.OrdinalIgnoreCase));

                        // Ensuring literal IPv6 address
                        IPAddress ipAddress;
                        bool      isIPv6Address = IPAddress.TryParse(infrastructureNode.IPAddressOrFQDN, out ipAddress) &&
                                                  (ipAddress.AddressFamily == AddressFamily.InterNetworkV6);
                        if (isIPv6Address)
                        {
                            infrastructureNode.IPAddressOrFQDN = string.Format(CultureInfo.InvariantCulture, "[{0}]", ipAddress.ToString());
                        }

                        nodeSettings.Add(new NodeSettings(
                                             new FabricNodeType()
                        {
                            FaultDomain     = infrastructureNode.FaultDomain,
                            IPAddressOrFQDN = infrastructureNode.IPAddressOrFQDN,
                            IsSeedNode      = infrastructureNode.IsSeedNode,
                            NodeName        = infrastructureNode.NodeName,
                            NodeTypeRef     = infrastructureNode.NodeTypeRef,
                            UpgradeDomain   = infrastructureNode.UpgradeDomain
                        },
                                             nodeType,
                                             new DeploymentFolders(
                                                 parameters.FabricBinRoot,
                                                 manifest.FabricSettings,
                                                 parameters.DeploymentSpecification,
                                                 infrastructureNode.NodeName,
                                                 versions,
                                                 infrastructure.IsScaleMin),
                                             infrastructure.IsScaleMin,
                                             infrastructureNode.Endpoints));
                    }
                }

                if (nodeSettings.Count != 0)
                {
                    break;
                }

                Thread.Sleep(RestartOperation.RetryInterval);
                NetworkApiHelper.CurrentMachineAddresses = NetworkApiHelper.GetCurrentMachineAddresses();
            }

            return(nodeSettings);
        }
Example #8
0
        protected override void OnExecuteOperation(DeploymentParameters parameters, ClusterManifestType clusterManifest, Infrastructure infrastructure)
        {
            var isRunningAsAdmin = AccountHelper.IsAdminUser();

            if (!isRunningAsAdmin)
            {
                DeployerTrace.WriteWarning(StringResources.Warning_DeployerNotRunAsAdminSkipFirewallAndPerformanceCounter);
                return;
            }

            if (clusterManifest == null)
            {
                DeployerTrace.WriteError(StringResources.Error_FabricHostStartedWithoutConfiguringTheNode);
                throw new ArgumentException(StringResources.Error_FabricHostStartedWithoutConfiguringTheNode);
            }

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

            if (!parameters.SkipFirewallConfiguration)
            {
                var securitySection = manifest.FabricSettings.FirstOrDefault(fabSetting => fabSetting.Name.Equals(Constants.SectionNames.Security, StringComparison.OrdinalIgnoreCase));

#if DotNetCoreClrLinux
                if (isRunningAsAdmin && clusterManifest.Infrastructure.Item is ClusterManifestTypeInfrastructureLinux)
                {
                    var currentInfrastructure = clusterManifest.Infrastructure.Item as ClusterManifestTypeInfrastructureLinux;
#else
                if (isRunningAsAdmin && clusterManifest.Infrastructure.Item is ClusterManifestTypeInfrastructureWindowsServer)
                {
                    var currentInfrastructure = clusterManifest.Infrastructure.Item as ClusterManifestTypeInfrastructureWindowsServer;
#endif

                    var nodeSettings = GetNodeSettings();
                    var isScaleMin   = currentInfrastructure.IsScaleMin;
                    FirewallManager.EnableFirewallSettings(nodeSettings, isScaleMin, securitySection, this is UpdateNodeStateOperation);
                    NetworkApiHelper.ReduceDynamicPortRange(nodeSettings, isScaleMin);
                }
                else if (isRunningAsAdmin)
                {
                    var nodeSettings = GetNodeSettings();
                    FirewallManager.EnableFirewallSettings(nodeSettings, false, securitySection, this is UpdateNodeStateOperation);
                    NetworkApiHelper.ReduceDynamicPortRange(nodeSettings, false);
                }
            }

#if !DotNetCoreClrIOT && !DotNetCoreClrLinux
            #region Container Network Reset
            // CreateOrUpdate operation inherits from RestartOperation.
            // This check will invoke network reset only in the restart case.
            // This is a work around to handle the case where the flat network was not usable after VM reboot.
            if (parameters.Operation == DeploymentOperations.None)
            {
                if (!parameters.SkipContainerNetworkResetOnReboot)
                {
                    var lastBootUpTimeFromRegistry = Utility.GetNodeLastBootUpTimeFromRegistry();
                    var lastBootUpTimeFromSystem   = Utility.GetNodeLastBootUpTimeFromSystem();
                    DeployerTrace.WriteInfo("Last boot up time from registry:{0} from system:{1}", lastBootUpTimeFromRegistry, lastBootUpTimeFromSystem);

                    if (!string.Equals(lastBootUpTimeFromRegistry.ToString(), lastBootUpTimeFromSystem.ToString(), StringComparison.OrdinalIgnoreCase))
                    {
                        DeployerTrace.WriteInfo("Invoking container network reset.");

                        // This check is needed to allow clean up on azure. This is symmetrical to the set up condition.
                        if (clusterManifest.Infrastructure.Item is ClusterManifestTypeInfrastructureWindowsAzure ||
                            clusterManifest.Infrastructure.Item is ClusterManifestTypeInfrastructurePaaS)
                        {
                            var containerNetworkCleanupOperation = new ContainerNetworkCleanupOperation();
                            containerNetworkCleanupOperation.ExecuteOperation(parameters.ContainerNetworkName, parameters.Operation);
                        }

                        if (parameters.ContainerNetworkSetup)
                        {
                            // set up docker network.
                            var containerNetworkSetupOperation = new ContainerNetworkSetupOperation();
                            containerNetworkSetupOperation.ExecuteOperation(parameters, clusterManifest, infrastructure);
                        }

                        // Record last boot up time
                        Utility.SaveNodeLastBootUpTimeToRegistry(lastBootUpTimeFromSystem);
                    }
                }
                else
                {
                    DeployerTrace.WriteInfo("Skipping container network reset on reboot because SkipContainerNetworkResetOnReboot flag is enabled.");
                }
            }
            #endregion
#endif

#if !DotNetCoreClrIOT
            if (parameters.ContainerDnsSetup == ContainerDnsSetup.Allow || parameters.ContainerDnsSetup == ContainerDnsSetup.Require)
            {
                try
                {
                    string currentNodeIPAddressOrFQDN = string.Empty;
                    if ((infrastructure != null) && (infrastructure.InfrastructureNodes != null))
                    {
                        foreach (var infraNode in infrastructure.InfrastructureNodes)
                        {
                            DeployerTrace.WriteInfo("Infra node <{0}> params.NodeName <{1}>", infraNode.NodeName, parameters.NodeName);
                            if (NetworkApiHelper.IsAddressForThisMachine(infraNode.IPAddressOrFQDN))
                            {
                                currentNodeIPAddressOrFQDN = infraNode.IPAddressOrFQDN;
                                DeployerTrace.WriteInfo("Found node IPAddressOrFQDN <{0}>", currentNodeIPAddressOrFQDN);
                                break;
                            }
                        }
                    }

                    new DockerDnsHelper(parameters, currentNodeIPAddressOrFQDN).SetupAsync().GetAwaiter().GetResult();
                }
                catch (Exception ex)
                {
                    if (parameters.ContainerDnsSetup == ContainerDnsSetup.Require)
                    {
                        DeployerTrace.WriteError(
                            StringResources.Error_FabricDeployer_DockerDnsSetup_ErrorNotContinuing,
                            Constants.ParameterNames.ContainerDnsSetup,
                            parameters.ContainerDnsSetup,
                            ex);
                        throw;
                    }

                    DeployerTrace.WriteWarning(
                        StringResources.Warning_FabricDeployer_DockerDnsSetup_ErrorContinuing,
                        Constants.ParameterNames.ContainerDnsSetup,
                        parameters.ContainerDnsSetup,
                        ex);
                }
            }
            else if (parameters.ContainerDnsSetup == ContainerDnsSetup.Disallow)
            {
                // cleanupasync catches all exceptions
                new DockerDnsHelper(parameters, string.Empty).CleanupAsync().GetAwaiter().GetResult();
            }
#endif

#if !DotNetCoreClr // Disable compiling on windows for now. Need to correct when porting FabricDeployer for windows.
            if (!PerformanceCounters.StartCollection(clusterManifest.FabricSettings, parameters.DeploymentSpecification))
            {
                DeployerTrace.WriteWarning(StringResources.Error_FabricDeployer_StartCounterCollectionFailed_Formatted);
            }

            if (fabricValidator.ShouldRegisterSpnForMachineAccount)
            {
                if (!SpnManager.EnsureSpn())
                {
                    throw new InvalidDeploymentException(StringResources.Error_FabricDeployer_FailedToRegisterSpn_Formatted);
                }
            }
#endif
        }