Exemple #1
0
        private bool GenerateInfrastructureFile(List <InfrastructureNodeType> infrastructureNodes, out string infrastructureFileName)
        {
            infrastructureFileName = Path.GetTempFileName();
            try
            {
                Logger.LogInfo(LogTag, "Generating infrastructure manifest in {0}", infrastructureFileName);
                XmlWriterSettings settings = new XmlWriterSettings();
                settings.Indent = true;
                using (XmlWriter writer = XmlWriter.Create(infrastructureFileName, settings))
                {
                    XmlSerializer serializer            = new XmlSerializer(typeof(InfrastructureInformationType));
                    InfrastructureInformationType infra = new InfrastructureInformationType();
                    infra.NodeList = infrastructureNodes.ToArray();
                    serializer.Serialize(writer, infra);
                }
            }
            catch (Exception e)
            {
                if (e is ArgumentException ||
                    e is System.IO.PathTooLongException ||
                    e is System.IO.DirectoryNotFoundException ||
                    e is System.IO.IOException ||
                    e is UnauthorizedAccessException ||
                    e is NotSupportedException ||
                    e is System.Security.SecurityException)
                {
                    Logger.LogFatalException(LogTag, e);
                    return(false);
                }

                throw;
            }

            return(true);
        }
Exemple #2
0
        private void GenerateDataDeployment()
        {
            string dataDeploymentPath = this.nodeSettings.DeploymentFoldersInfo.DataDeploymentDirectory;

#if DotNetCoreClrLinux
            FabricDirectory.CreateDirectory(dataDeploymentPath);
#else
            Directory.CreateDirectory(dataDeploymentPath);
#endif
            InfrastructureInformationType infrastructureManifest = this.infrastructure.GetInfrastructureManifest();
            string filePath = this.nodeSettings.DeploymentFoldersInfo.InfrastructureManfiestFile;
            DeployerTrace.WriteNoise("Writing infrastructure manifest file at {0}", filePath);
            WriteManifestFile <InfrastructureInformationType>(filePath, infrastructureManifest);
            CopyClusterSettingsToFabricData();
        }
Exemple #3
0
        internal static InfrastructureInformationType ReadInfrastructureManifest(string infrastructureManifestPath)
        {
            XmlReaderSettings settings = new XmlReaderSettings();

#if !DotNetCoreClr
            // For security, do not resolve external sources
            settings.XmlResolver = null;
#endif
            using (XmlReader reader = XmlReader.Create(infrastructureManifestPath, settings))
            {
                XmlSerializer xmlSrlizer         = new XmlSerializer(typeof(InfrastructureInformationType));
                InfrastructureInformationType im = (InfrastructureInformationType)xmlSrlizer.Deserialize(reader);
                return(im);
            }
        }
 public static void VerifyAreEqual(InfrastructureInformationType im1, InfrastructureInformationType im2)
 {
     Assert.AreEqual(im1.NodeList.Length, im2.NodeList.Length, "InfrastructureManifest.NodeList.Length");
     for (int i = 0; i < im1.NodeList.Length; i++)
     {
         var node1 = im1.NodeList[i];
         var node2 = im2.NodeList[i];
         VerifyAreEqual(node1.Certificates, node2.Certificates);
         VerifyAreEqual(node1.Endpoints, node2.Endpoints);
         Assert.AreEqual(node1.FaultDomain, node2.FaultDomain, "FaultDomain");
         Assert.AreEqual(node1.IPAddressOrFQDN, node2.IPAddressOrFQDN, "IPAddressOrFQDN");
         Assert.AreEqual(node1.IsSeedNode, node2.IsSeedNode, "IsSeedNode");
         Assert.AreEqual(node1.NodeName, node2.NodeName, "NodeName");
         Assert.AreEqual(node1.NodeTypeRef, node2.NodeTypeRef, "NodeTypeRef");
         Assert.AreEqual(node1.RoleOrTierName, node2.RoleOrTierName, "RoleOrTierName");
         Assert.AreEqual(node1.UpgradeDomain, node2.UpgradeDomain, "UpgradeDomain");
     }
 }
Exemple #5
0
        private static void ExecuteOperationPrivate(DeploymentParameters parameters)
        {
            DeployerTrace.WriteInfo("Executing {0}", parameters.ToString());
            DeploymentOperation operation = null;

            switch (parameters.Operation)
            {
            case DeploymentOperations.Configure:
                operation = new ConfigureOperation();
                break;

            case DeploymentOperations.ValidateClusterManifest:
                operation = new ValidateClusterManifestOperation();
                break;

            case DeploymentOperations.Create:
                operation = new CreateorUpdateOperation();
                break;

            case DeploymentOperations.Update:
                operation = new CreateorUpdateOperation();
                break;

            case DeploymentOperations.UpdateInstanceId:
                operation = new UpdateInstanceIdOperation();
                break;

            case DeploymentOperations.UpdateNodeState:
                operation = new UpdateNodeStateOperation();
                break;

            case DeploymentOperations.None:
                operation = new RestartOperation();
                break;

            case DeploymentOperations.Remove:
                operation = new RemoveOperation();
                break;

#if !DotNetCoreClrLinux
            case DeploymentOperations.RemoveNodeConfig:
                operation = new RemoveNodeConfigOperation();
                break;
#endif
            case DeploymentOperations.Rollback:
                operation = new RollbackOperation();
                break;

            case DeploymentOperations.Validate:
                operation = new ValidateOperation();
                break;

#if !DotNetCoreClrIOT
            case DeploymentOperations.DockerDnsSetup:
                operation = new DockerDnsSetupOperation();
                break;

            case DeploymentOperations.DockerDnsCleanup:
                operation = new DockerDnsCleanupOperation();
                break;

            case DeploymentOperations.ContainerNetworkSetup:
                operation = new ContainerNetworkSetupOperation();
                break;

            case DeploymentOperations.ContainerNetworkCleanup:
                operation = new ContainerNetworkCleanupOperation();
                break;
#endif
            default:
                throw new ArgumentException(StringResources.Warning_DeploymentOperationCantBeNull);
            }

            ClusterManifestType clusterManifest = parameters.ClusterManifestLocation == null ?
                                                  null :
                                                  XmlHelper.ReadXml <ClusterManifestType>(parameters.ClusterManifestLocation, SchemaLocation.GetWindowsFabricSchemaLocation());

            if (parameters.Operation != DeploymentOperations.Validate &&
                parameters.Operation != DeploymentOperations.ValidateClusterManifest &&
                parameters.Operation != DeploymentOperations.UpdateInstanceId &&
                parameters.Operation != DeploymentOperations.Remove &&
                parameters.Operation != DeploymentOperations.RemoveNodeConfig &&
                parameters.Operation != DeploymentOperations.Rollback &&
                parameters.Operation != DeploymentOperations.DockerDnsSetup &&
                parameters.Operation != DeploymentOperations.DockerDnsCleanup &&
                parameters.Operation != DeploymentOperations.ContainerNetworkSetup &&
                parameters.Operation != DeploymentOperations.ContainerNetworkCleanup &&
                parameters.Operation != DeploymentOperations.None &&
                clusterManifest.Infrastructure.Item is ClusterManifestTypeInfrastructureWindowsAzure &&
                parameters.InfrastructureManifestLocation == null)
            {
                throw new ArgumentException("InfrastructureManifestLocation");
            }

            InfrastructureInformationType infrastructureManifest = parameters.InfrastructureManifestLocation == null ?
                                                                   null :
                                                                   XmlHelper.ReadXml <InfrastructureInformationType>(parameters.InfrastructureManifestLocation, SchemaLocation.GetWindowsFabricSchemaLocation());


            Infrastructure infrastructure = clusterManifest == null ? null : Infrastructure.Create(clusterManifest.Infrastructure, infrastructureManifest == null ? null : infrastructureManifest.NodeList, clusterManifest.NodeTypes);
            DeployerTrace.WriteInfo("Running operation {0}", operation.GetType());
#if !DotNetCoreClrLinux
            bool isChangeDeploymentOperationToRemove = false;
#endif

            try
            {
                operation.OnExecuteOperation(parameters, clusterManifest, infrastructure);
            }
            catch (ChangeDeploymentOperationToRemoveException)
            {
#if !DotNetCoreClrLinux
                isChangeDeploymentOperationToRemove = true;
#endif
                DeployerTrace.WriteInfo("Deployment operation modification to remove detected");
            }

#if !DotNetCoreClrLinux
            if (isChangeDeploymentOperationToRemove)
            {
                var infraNode = infrastructure.InfrastructureNodes.SingleOrDefault(n => n.NodeName == parameters.NodeName);
                parameters.DeleteLog             = false;
                parameters.MachineName           = infraNode.IPAddressOrFQDN;
                parameters.DeploymentPackageType = FabricPackageType.XCopyPackage;
                operation = new RemoveNodeConfigOperation();
                DeployerTrace.WriteInfo("Deployment modified to RemoveNodeConfig. New parameters set: parameter.DeleteLog: {0}, parameters.MachineName: {1}, parameters.DeploymentPackageType: {2}",
                                        parameters.DeleteLog,
                                        parameters.MachineName,
                                        parameters.DeploymentPackageType);
                operation.OnExecuteOperation(parameters, clusterManifest, infrastructure);
            }

            if (Utility.GetTestFailDeployer())
            {
                DeployerTrace.WriteInfo("Failing deployment as test hook is found");
                Utility.DeleteTestFailDeployer();
                throw new InvalidDeploymentException(StringResources.Error_FabricDeployer_TestHookFound_Formatted);
            }
#endif
        }
Exemple #6
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);
                            }
                        }
                    }
                }
            }
        }
 internal static string GetNodeTypeFromMachineName(ClusterManifestType clusterManifest, InfrastructureInformationType infrastructure, string machineName)
 {
     if (clusterManifest.Infrastructure.Item is ClusterManifestTypeInfrastructureWindowsServer)
     {
         return(((ClusterManifestTypeInfrastructureWindowsServer)clusterManifest.Infrastructure.Item).NodeList.Where(node => node.IPAddressOrFQDN == machineName).First().NodeTypeRef);
     }
     else if (clusterManifest.Infrastructure.Item is ClusterManifestTypeInfrastructurePaaS || clusterManifest.Infrastructure.Item is ClusterManifestTypeInfrastructureWindowsAzure)
     {
         return(infrastructure.NodeList.Where(node => node.IPAddressOrFQDN == machineName).First().NodeTypeRef);
     }
     else if (clusterManifest.Infrastructure.Item is ClusterManifestTypeInfrastructureWindowsAzureStaticTopology)
     {
         return(((ClusterManifestTypeInfrastructureWindowsAzureStaticTopology)clusterManifest.Infrastructure.Item).NodeList.Where(node => node.IPAddressOrFQDN == machineName).First().NodeTypeRef);
     }
     else if (clusterManifest.Infrastructure.Item is ClusterManifestTypeInfrastructureLinux)
     {
         return(((ClusterManifestTypeInfrastructureLinux)clusterManifest.Infrastructure.Item).NodeList.Where(node => node.IPAddressOrFQDN == machineName).First().NodeTypeRef);
     }
     else
     {
         throw new ArgumentException(StringResources.Error_ClusterManifestTypeNotSupported);
     }
 }