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