Esempio n. 1
0
 public NodeSettings(FabricNodeType fabricNode, ClusterManifestTypeNodeType nodeType, DeploymentFolders deploymentFolders, bool isScaleMin, FabricEndpointsType endpoints)
 {
     this.Settings              = new List <SettingsTypeSection>();
     this.NodeName              = fabricNode.NodeName;
     this.IPAddressOrFQDN       = fabricNode.IPAddressOrFQDN;
     this.DeploymentFoldersInfo = deploymentFolders;
     AddFabricNodeSection(fabricNode, endpoints, nodeType, isScaleMin);
     AddDomainIds(fabricNode);
     AddNodeProperties(nodeType);
 }
Esempio n. 2
0
        List <NodeSettings> GetNodeSettings(int nodeCount, int start, bool addAppPorts, string ipAddressOrFQDN)
        {
            List <NodeSettings> nodes = new List <NodeSettings>();
            int leasedriverPort       = BaseLeaseDriverPort + start;
            int appPortStart          = BaseAppStartport + start * AppPortRange;
            int appPortEnd            = appPortStart + AppPortRange;
            int httpGatewayPort       = BaseHttpGatewayport + start;
            int httpAppGatewayPort    = BaseHttpAppGatewayport + start;

            for (int i = 0; i < nodeCount; i++)
            {
                string         nodeName   = string.Format(NodeNameTemplate, i + start);
                FabricNodeType fabricNode = new FabricNodeType()
                {
                    NodeName = nodeName, IPAddressOrFQDN = ipAddressOrFQDN, NodeTypeRef = "Test"
                };
                var endpoints = new FabricEndpointsType()
                {
                    LeaseDriverEndpoint = new InternalEndpointType()
                    {
                        Port = string.Format("{0}", leasedriverPort)
                    },
                    ClientConnectionEndpoint = new InputEndpointType {
                        Port = "3999"
                    },
                    ClusterConnectionEndpoint = new InternalEndpointType()
                    {
                        Port = "3998"
                    },
                    HttpGatewayEndpoint = new InputEndpointType {
                        Port = string.Format("{0}", httpGatewayPort)
                    },
                    HttpApplicationGatewayEndpoint = new InputEndpointType {
                        Port = string.Format("{0}", httpAppGatewayPort)
                    },
                    ApplicationEndpoints = addAppPorts ?
                                           new FabricEndpointsTypeApplicationEndpoints()
                    {
                        StartPort = appPortStart,
                        EndPort   = appPortEnd
                    }
                            : null
                };
                ClusterManifestTypeNodeType type    = new ClusterManifestTypeNodeType();
                DeploymentFolders           folders = new DeploymentFolders("", null, FabricDeploymentSpecification.Create(), nodeName, new Versions("", "", "", ""), false);
                NodeSettings setting = new NodeSettings(fabricNode, type, folders, true, endpoints);
                nodes.Add(setting);
                leasedriverPort++;
                appPortStart += AppPortRange;
                appPortEnd   += AppPortRange;
            }
            return(nodes);
        }
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);
        }
Esempio n. 4
0
        private void InitializeInfrastructureSettings(
            int nNodeTypes,
            bool isScaleMin,
            bool isLogicalDirectories,
            int[] nNodes,
            int[] nSeedNodes,
            int[] nFaultDomains,
            int[] nUpgradDomains,
            InfrastructureType infrastructureType)
        {
            this.nodeTypes = new ClusterManifestTypeNodeType[nNodeTypes];
            int totalNodes = 0;

            for (int i = 0; i < nNodeTypes; i++)
            {
                totalNodes += nNodes[i];
            }
            this.nodes      = new FabricNodeType[totalNodes];
            this.infraNodes = new InfrastructureNodeType[totalNodes];
            int nodeIndex = 0;

            for (int i = 0; i < nNodeTypes; i++)
            {
                int    clientConnectionPort  = 19000 + i;
                int    leaseDriverPort       = 19000 + nNodeTypes + i;
                int    clusterConnectionPort = 19000 + 2 * nNodeTypes + i;
                int    httpGatewayPort       = 19000 + 3 * nNodeTypes + i;
                int    serviceConnectionPort = 19000 + 4 * nNodeTypes + i;
                int    startAppPort          = 30000 + 1000 * i + 1;
                int    endAppPort            = 30000 + 1000 * (i + 1);
                string host                   = isScaleMin ? "localhost" : System.Net.Dns.GetHostName();
                string roleOrTierName         = GetRoleOrTiername(i);
                string faultDomain            = string.Format(CultureInfo.InvariantCulture, "fd:/Rack{0}", i % nFaultDomains[i]);
                string upgradeDomain          = string.Format(CultureInfo.InvariantCulture, "MYUD{0}", i % nUpgradDomains[i]);
                FabricEndpointsType endpoints = new FabricEndpointsType()
                {
                    ApplicationEndpoints = new FabricEndpointsTypeApplicationEndpoints()
                    {
                        StartPort = startAppPort, EndPort = endAppPort
                    },
                    LeaseDriverEndpoint = new InternalEndpointType()
                    {
                        Port = leaseDriverPort.ToString(CultureInfo.InvariantCulture)
                    },
                    ClusterConnectionEndpoint = new InternalEndpointType()
                    {
                        Port = clusterConnectionPort.ToString(CultureInfo.InvariantCulture)
                    },
                    ClientConnectionEndpoint = new InputEndpointType()
                    {
                        Port = clientConnectionPort.ToString(CultureInfo.InvariantCulture)
                    },
                    HttpGatewayEndpoint = new InputEndpointType()
                    {
                        Port = httpGatewayPort.ToString(CultureInfo.InvariantCulture)
                    },
                    ServiceConnectionEndpoint = new InternalEndpointType()
                    {
                        Port = serviceConnectionPort.ToString(CultureInfo.InvariantCulture)
                    }
                };

                for (int j = 0; j < nNodes[i]; j++)
                {
                    bool           isSeedNode = j < nSeedNodes[i];
                    string         nodeName   = string.Format(CultureInfo.InvariantCulture, "{0}.Node.{1}", roleOrTierName, j);
                    FabricNodeType node       = new FabricNodeType()
                    {
                        NodeName = nodeName, FaultDomain = faultDomain, IPAddressOrFQDN = host, IsSeedNode = isSeedNode, NodeTypeRef = roleOrTierName, UpgradeDomain = upgradeDomain
                    };
                    InfrastructureNodeType infraNode = new InfrastructureNodeType()
                    {
                        NodeName = nodeName, FaultDomain = faultDomain, IPAddressOrFQDN = host, IsSeedNode = isSeedNode, NodeTypeRef = roleOrTierName, UpgradeDomain = upgradeDomain, RoleOrTierName = roleOrTierName, Certificates = null, Endpoints = endpoints
                    };
                    this.nodes[nodeIndex]      = node;
                    this.infraNodes[nodeIndex] = infraNode;
                    nodeIndex++;
                }
                nodeTypes[i] = new ClusterManifestTypeNodeType();
                nodeTypes[i].Certificates = null;
                if (infrastructureType == InfrastructureType.WindowsServer || infrastructureType == InfrastructureType.VMM || infrastructureType == InfrastructureType.PaaS)
                {
                    nodeTypes[i].Endpoints = endpoints;
                }

                nodeTypes[i].Name = roleOrTierName;
            }

            if (isLogicalDirectories)
            {
                nodeTypes[0].LogicalDirectories    = new LogicalDirectoryType[5];
                nodeTypes[0].LogicalDirectories[0] = new LogicalDirectoryType
                {
                    LogicalDirectoryName = "0",
                    MappedTo             = TestUtility.LogicalDirectoriesApplicationCheckPointFilesDir,
                    Context = LogicalDirectoryTypeContext.node
                };

                nodeTypes[0].LogicalDirectories[1] = new LogicalDirectoryType
                {
                    LogicalDirectoryName = "1",
                    MappedTo             = TestUtility.LogicalDirectoriesLogDir,
                    Context = LogicalDirectoryTypeContext.node
                };
                nodeTypes[0].LogicalDirectories[2] = new LogicalDirectoryType
                {
                    LogicalDirectoryName = "2",
                    MappedTo             = TestUtility.LogicalDirectoriesBackupDir,
                    Context = LogicalDirectoryTypeContext.application
                };
                nodeTypes[0].LogicalDirectories[3] = new LogicalDirectoryType
                {
                    LogicalDirectoryName = "3",
                    MappedTo             = TestUtility.LogicalDirectoriesUserDefined1Dir
                };
                nodeTypes[0].LogicalDirectories[4] = new LogicalDirectoryType
                {
                    LogicalDirectoryName = "4",
                    MappedTo             = TestUtility.LogicalDirectoriesUserDefined2Dir,
                    Context = LogicalDirectoryTypeContext.node
                };

                nodeTypes[1].LogicalDirectories    = new LogicalDirectoryType[5];
                nodeTypes[1].LogicalDirectories[0] = new LogicalDirectoryType
                {
                    LogicalDirectoryName = "0",
                    MappedTo             = TestUtility.LogicalDirectoriesApplicationCheckPointFilesDir2,
                    Context = LogicalDirectoryTypeContext.application
                };

                nodeTypes[1].LogicalDirectories[1] = new LogicalDirectoryType
                {
                    LogicalDirectoryName = "1",
                    MappedTo             = TestUtility.LogicalDirectoriesLogDir2,
                    Context = LogicalDirectoryTypeContext.application
                };
                nodeTypes[1].LogicalDirectories[2] = new LogicalDirectoryType
                {
                    LogicalDirectoryName = "2",
                    MappedTo             = TestUtility.LogicalDirectoriesBackupDir2,
                    Context = LogicalDirectoryTypeContext.node
                };
                nodeTypes[1].LogicalDirectories[3] = new LogicalDirectoryType
                {
                    LogicalDirectoryName = "3",
                    MappedTo             = TestUtility.LogicalDirectoriesUserDefined1Dir2,
                    Context = LogicalDirectoryTypeContext.application
                };
                nodeTypes[1].LogicalDirectories[4] = new LogicalDirectoryType
                {
                    LogicalDirectoryName = "4",
                    MappedTo             = TestUtility.LogicalDirectoriesUserDefined2Dir2,
                    Context = LogicalDirectoryTypeContext.application
                };
            }
        }
Esempio n. 5
0
        private void ValidateNodeList()
        {
            if (this.infrastructureInformation == null)
            {
                FabricValidator.TraceSource.WriteWarning(
                    FabricValidatorUtility.TraceTag,
                    "Skipping node list validation as it is empty");
                return;
            }

            //Validate StartPort and EndPort number and range
            if (clusterManifest.Infrastructure.Item is ClusterManifestTypeInfrastructureWindowsAzure)
            {
                foreach (InfrastructureNodeType infra in this.infrastructureInformation)
                {
                    try
                    {
                        if (infra.Endpoints.ApplicationEndpoints.StartPort < 0 || infra.Endpoints.ApplicationEndpoints.EndPort < 0)
                        {
                            throw new ArgumentException(
                                      string.Format(
                                          StringResources.Warning_FabricValidatorStartEndPortNegative, infra.NodeName));
                        }

                        if (infra.Endpoints.ApplicationEndpoints.StartPort > infra.Endpoints.ApplicationEndpoints.EndPort)
                        {
                            throw new ArgumentException(
                                      string.Format(
                                          StringResources.Warning_FabricValidatorPortRangeInvalid, infra.NodeName));
                        }

                        //Validate the other five ports
                        ValidateEndpointsPortsHelper(infra.Endpoints.ClientConnectionEndpoint.Port, infra.NodeName, "ClientConnectionEndpoint");
                        ValidateEndpointsPortsHelper(infra.Endpoints.LeaseDriverEndpoint.Port, infra.NodeName, "LeaseDriverEndpoint");
                        ValidateEndpointsPortsHelper(infra.Endpoints.ClusterConnectionEndpoint.Port, infra.NodeName, "ClusterConnectionEndpoint");
                        ValidateEndpointsPortsHelper(infra.Endpoints.HttpGatewayEndpoint.Port, infra.NodeName, "HttpGatewayEndpoint");
                        // TODO add validation for http app gateway endpoint
                        // ValidateEndpointsPortsHelper(infra.Endpoints.HttpApplicationGatewayEndpoint.Port, infra.NodeName, "HttpApplicationGatewayEndpoint");
                        ValidateEndpointsPortsHelper(infra.Endpoints.ServiceConnectionEndpoint.Port, infra.NodeName, "ServiceConnectionEndpoint");
                    }
                    catch (NullReferenceException)
                    {
                        FabricValidator.TraceSource.WriteWarning(
                            FabricValidatorUtility.TraceTag,
                            StringResources.Info_FabricValidatorPortsNull);
                        return;
                    }
                }
            }


#if DotNetCoreClrLinux
            var isServer = clusterManifest.Infrastructure.Item is ClusterManifestTypeInfrastructureLinux;
#else
            var isServer = clusterManifest.Infrastructure.Item is ClusterManifestTypeInfrastructureWindowsServer;
#endif
            if (isServer || clusterManifest.Infrastructure.Item is ClusterManifestTypeInfrastructureWindowsAzureStaticTopology)
            {
                foreach (InfrastructureNodeType infra in this.infrastructureInformation)
                {
                    if (Helpers.isIPV6AddressAndNoBracket(infra.IPAddressOrFQDN))
                    {
                        throw new ArgumentException(StringResources.Error_BracketsAroundIPV6AddressAreMandatory, infra.NodeName);
                    }
                }
            }

            int voteCount = this.NonSeedVoteCount;
            ClusterManifestTypeInfrastructurePaaS paasInfrastructure = clusterManifest.Infrastructure.Item as ClusterManifestTypeInfrastructurePaaS;
            if (paasInfrastructure != null)
            {
                voteCount += paasInfrastructure.Votes.Count();
            }

            bool   matchingLocalNodeFound = false;
            string prevMachine            = this.infrastructureInformation[0].IPAddressOrFQDN;

            if (this.IsScaleMin && !NetworkApiHelper.IsNodeForThisMachine(this.infrastructureInformation[0]))
            {
                this.DoMachineAndNodeHaveSameIPInScaleMin = false;
            }

            bool             hasLoopbackAddressDefined = false;
            HashSet <string> nodeNameDuplicateDetector = new HashSet <string>();
            List <string>    faultDomains = new List <string>();
            foreach (InfrastructureNodeType fabricNode in this.infrastructureInformation)
            {
                ClusterManifestTypeNodeType nodeType = this.clusterManifest.NodeTypes.FirstOrDefault(nodeTypeVar => FabricValidatorUtility.EqualsIgnoreCase(nodeTypeVar.Name, fabricNode.NodeTypeRef));

                if (nodeType == null)
                {
                    if (!(this.DeploymentOperation == DeploymentOperations.Update && this.clusterManifest.Infrastructure.Item is ClusterManifestTypeInfrastructurePaaS))
                    {
                        throw new ArgumentException(
                                  string.Format(
                                      "Node '{0}' has attribute NodeTypeRef='{1}'. However, no NodeType with name {1} exists.",
                                      fabricNode.NodeName,
                                      fabricNode.NodeTypeRef));
                    }
                }

                if (fabricNode.IsSeedNode)
                {
                    voteCount++;
                }

                faultDomains.Add(fabricNode.FaultDomain);
                if (!FabricValidatorUtility.IsValidFileName(fabricNode.NodeName))
                {
                    throw new ArgumentException(
                              string.Format(
                                  "Invalid character found in node name {0}. Node name should be a valid file name.",
                                  fabricNode.NodeName));
                }

                if (!FabricValidatorUtility.IsValidIPAddressOrFQDN(fabricNode.IPAddressOrFQDN))
                {
                    throw new ArgumentException(
                              string.Format(
                                  "Malformed IPAddressOrFQDN found {0}.",
                                  fabricNode.IPAddressOrFQDN));
                }

                if (nodeNameDuplicateDetector.Contains(fabricNode.NodeName))
                {
                    throw new ArgumentException(
                              string.Format(
                                  "Duplicate node name {0} found.",
                                  fabricNode.NodeName));
                }
                else
                {
                    nodeNameDuplicateDetector.Add(fabricNode.NodeName);
                }

                if (fabricNode.IPAddressOrFQDN != prevMachine &&
                    !FabricValidatorUtility.IsNodeAddressLoopback(fabricNode))
                {
                    this.IsSingleMachineDeployment = false;
                }

                if (!hasLoopbackAddressDefined)
                {
                    hasLoopbackAddressDefined = FabricValidatorUtility.IsNodeAddressLoopback(fabricNode);
                }

                FabricValidator.TraceSource.WriteNoise(
                    FabricValidatorUtility.TraceTag,
                    "fabricNode is {0}", fabricNode);

                if (!FabricValidatorUtility.IsNodeForThisMachine(fabricNode))
                {
                    continue;
                }

                if (matchingLocalNodeFound && !this.IsScaleMin)
                {
                    throw new ArgumentException(
                              string.Format(
                                  "The IPAddressorFQDN value in node '{0}' is {1}. Another node is also configured to run on the same machine. " +
                                  "Running multiple nodes on the same machine is not valid in the specified infrastructure.",
                                  fabricNode.NodeName,
                                  fabricNode.IPAddressOrFQDN));
                }
                else
                {
                    matchingLocalNodeFound = true;
                    FabricValidatorUtility.ValidateDomainUri(fabricNode.FaultDomain, fabricNode.NodeName);
                }
            }

            int fdPathCount = -1;
            foreach (string faultDomain in faultDomains)
            {
                if (!string.IsNullOrEmpty(faultDomain))
                {
                    int currentfdPathCount = faultDomain.Split('/').Length;
                    if (fdPathCount == -1)
                    {
                        fdPathCount = currentfdPathCount;
                    }
                    if (fdPathCount != currentfdPathCount)
                    {
                        throw new ArgumentException("All FaultDomains should have the same depth.");
                    }
                }
            }

            if (!matchingLocalNodeFound)
            {
                FabricValidator.TraceSource.WriteWarning(
                    FabricValidatorUtility.TraceTag,
                    "None of the declared nodes is for the current machine.");
            }

            if (!this.IsSingleMachineDeployment && hasLoopbackAddressDefined)
            {
                throw new ArgumentException("Even though the deployment is split over multiple machines there is at least one node with a loopback address");
            }

            if (voteCount == 0)
            {
                throw new ArgumentException("No votes specified. Either seed nodes or sql vote specification is required for cluster to bootstrap");
            }

            if (!this.DoMachineAndNodeHaveSameIPInScaleMin)
            {
                FabricValidator.TraceSource.WriteWarning(
                    FabricValidatorUtility.TraceTag,
                    StringResources.Warning_FirstNodeAndMachineHaveDifferentIP);
                return;
            }
        }
 private int NodeTypeNameComparator(ClusterManifestTypeNodeType nodeType1, ClusterManifestTypeNodeType nodeType2)
 {
     return(string.Compare(nodeType1.Name, nodeType2.Name, StringComparison.OrdinalIgnoreCase));
 }
Esempio n. 7
0
        private void AddFabricNodeSection(FabricNodeType fabricNode, FabricEndpointsType endpoints, ClusterManifestTypeNodeType nodeType, bool isScaleMin)
        {
            CertificatesType certificates = nodeType.Certificates;

            List <SettingsTypeSectionParameter> parameters = new List <SettingsTypeSectionParameter>();

            parameters.Add(new SettingsTypeSectionParameter()
            {
                Name = Constants.ParameterNames.InstanceName, Value = this.NodeName, MustOverride = false
            });

            if (Helpers.isIPV6AddressAndNoBracket(this.IPAddressOrFQDN))
            {
                parameters.Add(new SettingsTypeSectionParameter()
                {
                    Name = Constants.ParameterNames.IPAddressOrFQDN, Value = Helpers.AddBracketsAroundIPV6(this.IPAddressOrFQDN), MustOverride = false
                });
            }
            else
            {
                parameters.Add(new SettingsTypeSectionParameter()
                {
                    Name = Constants.ParameterNames.IPAddressOrFQDN, Value = this.IPAddressOrFQDN, MustOverride = false
                });
            }

            parameters.Add(new SettingsTypeSectionParameter()
            {
                Name = Constants.ParameterNames.WorkingDir, Value = this.DeploymentFoldersInfo.WorkFolder, MustOverride = false
            });
            parameters.Add(new SettingsTypeSectionParameter()
            {
                Name = Constants.ParameterNames.NodeVersion, Value = this.DeploymentFoldersInfo.versions.FabricInstanceVersion, MustOverride = false
            });
            parameters.Add(new SettingsTypeSectionParameter()
            {
                Name = Constants.ParameterNames.NodeType, Value = fabricNode.NodeTypeRef, MustOverride = false
            });
            parameters.Add(new SettingsTypeSectionParameter()
            {
                Name = Constants.ParameterNames.IsScaleMin, Value = isScaleMin.ToString(), MustOverride = false
            });

            //
            // Fill in any KTLLogger values from the NodeTypes
            //
            if (nodeType.KtlLoggerSettings != null)
            {
                if (nodeType.KtlLoggerSettings.SharedLogFilePath != null)
                {
                    parameters.Add(new SettingsTypeSectionParameter()
                    {
                        Name = Constants.ParameterNames.SharedLogFilePath, Value = nodeType.KtlLoggerSettings.SharedLogFilePath.Value, MustOverride = false
                    });
                }

                if (nodeType.KtlLoggerSettings.SharedLogFileId != null)
                {
                    parameters.Add(new SettingsTypeSectionParameter()
                    {
                        Name = Constants.ParameterNames.SharedLogFileId, Value = nodeType.KtlLoggerSettings.SharedLogFileId.Value, MustOverride = false
                    });
                }

                if (nodeType.KtlLoggerSettings.SharedLogFileSizeInMB != null)
                {
                    parameters.Add(new SettingsTypeSectionParameter()
                    {
                        Name = Constants.ParameterNames.SharedLogFileSizeInMB, Value = nodeType.KtlLoggerSettings.SharedLogFileSizeInMB.Value.ToString(), MustOverride = false
                    });
                }
            }

            AddEndpoints(parameters, endpoints);
            AddCertifcateInformation(parameters, certificates);
            this.Settings.Add(new SettingsTypeSection()
            {
                Name = Constants.SectionNames.FabricNode, Parameter = parameters.ToArray()
            });
        }
Esempio n. 8
0
        private void AddNodeProperties(ClusterManifestTypeNodeType nodeType)
        {
            List <SettingsTypeSectionParameter> parameters = GetSectionProperties(nodeType.PlacementProperties);

            if (parameters != null)
            {
                this.Settings.Add(new SettingsTypeSection()
                {
                    Name = Constants.SectionNames.NodeProperties, Parameter = parameters.ToArray()
                });
            }
            parameters = GetSectionProperties(nodeType.Capacities);
            if (parameters != null)
            {
                this.Settings.Add(new SettingsTypeSection()
                {
                    Name = Constants.SectionNames.NodeCapacities, Parameter = parameters.ToArray()
                });
            }
            parameters = GetSectionProperties(nodeType.SfssRgPolicies);
            if (parameters != null)
            {
                this.Settings.Add(new SettingsTypeSection()
                {
                    Name = Constants.SectionNames.NodeSfssRgPolicies, Parameter = parameters.ToArray()
                });
            }

            if (nodeType.LogicalDirectories != null)
            {
                List <KeyValuePairType> logicalApplicationDirectories = new List <KeyValuePairType>();
                List <KeyValuePairType> logicalNodeDirectories        = new List <KeyValuePairType>();

                foreach (var dir in nodeType.LogicalDirectories)
                {
                    KeyValuePairType pair = new KeyValuePairType
                    {
                        Name  = dir.LogicalDirectoryName,
                        Value = dir.MappedTo
                    };

                    if (dir.Context == LogicalDirectoryTypeContext.application)
                    {
                        logicalApplicationDirectories.Add(pair);
                    }
                    else
                    {
                        logicalNodeDirectories.Add(pair);
                    }
                }

                if (logicalApplicationDirectories.Count > 0)
                {
                    parameters = GetSectionProperties(logicalApplicationDirectories.ToArray());
                    if (parameters != null && parameters.Count > 0)
                    {
                        this.Settings.Add(new SettingsTypeSection()
                        {
                            Name = Constants.SectionNames.LogicalApplicationDirectories, Parameter = parameters.ToArray()
                        });
                    }
                }

                if (logicalNodeDirectories.Count > 0)
                {
                    parameters = GetSectionProperties(logicalNodeDirectories.ToArray());
                    if (parameters != null && parameters.Count > 0)
                    {
                        this.Settings.Add(new SettingsTypeSection()
                        {
                            Name = Constants.SectionNames.LogicalNodeDirectories, Parameter = parameters.ToArray()
                        });
                    }
                }
            }

#if false
            parameters = GetSectionProperties(nodeType.CapacityRatios);
            if (parameters != null)
            {
                this.Settings.Add(new SettingsTypeSection()
                {
                    Name = FabricValidatorConstants.SectionNames.NodeCapacityRatios, Parameter = parameters.ToArray()
                });
            }
#endif
        }
        protected IEnumerable <ClusterManifestTypeNodeType> GetNodeTypes(
            IEnumerable <NodeTypeDescription> nodeTypeDescriptions,
            Security security,
            ClusterManifestType existingClusterManifestType = null)
        {
            //// TODO: Implement smarter port selection to avoid conflicts with ports specified by the user

            var result = new List <ClusterManifestTypeNodeType>();

            foreach (var nodeTypeDescription in nodeTypeDescriptions)
            {
                ClusterManifestTypeNodeType matchigExistingNodeType = null;
                if (existingClusterManifestType != null)
                {
                    matchigExistingNodeType =
                        existingClusterManifestType.NodeTypes.FirstOrDefault(
                            existingNodeType => existingNodeType.Name.Equals(nodeTypeDescription.Name));
                }

                var clusterConnectionEndpointPort = matchigExistingNodeType == null
                                                    ? this.ClusterManifestGeneratorSettings.ClusterConnectionEndpointPort.ToString()
                                                    : matchigExistingNodeType.Endpoints.ClusterConnectionEndpoint.Port;

                var leaseDriverEndpointPort = matchigExistingNodeType == null
                                              ? this.ClusterManifestGeneratorSettings.LeaseDriverEndpointPort.ToString()
                                              : matchigExistingNodeType.Endpoints.LeaseDriverEndpoint.Port;

                var serviceConnectionEndpointPort = matchigExistingNodeType == null
                                                    ? this.ClusterManifestGeneratorSettings.ServiceConnectionEndpointPort.ToString()
                                                    : matchigExistingNodeType.Endpoints.ServiceConnectionEndpoint.Port;

                var nodeType = nodeTypeDescription.ToClusterManifestTypeNodeType();

                var defaultPlacementProperty = new KeyValuePairType()
                {
                    Name  = StringConstants.DefaultPlacementConstraintsKey,
                    Value = nodeType.Name
                };

                if (nodeType.PlacementProperties == null)
                {
                    nodeType.PlacementProperties = new[] { defaultPlacementProperty };
                }
                else
                {
                    var existingPlacementProperties = nodeType.PlacementProperties.ToList();
                    existingPlacementProperties.Add(defaultPlacementProperty);

                    nodeType.PlacementProperties = existingPlacementProperties.ToArray();
                }

                nodeType.Endpoints.ClusterConnectionEndpoint = new InternalEndpointType()
                {
                    Port     = nodeTypeDescription.ClusterConnectionEndpointPort == 0 ? clusterConnectionEndpointPort : nodeTypeDescription.ClusterConnectionEndpointPort.ToString(),
                    Protocol = InternalEndpointTypeProtocol.tcp
                };

                nodeType.Endpoints.LeaseDriverEndpoint = new InternalEndpointType()
                {
                    Port     = nodeTypeDescription.LeaseDriverEndpointPort == 0 ? leaseDriverEndpointPort : nodeTypeDescription.LeaseDriverEndpointPort.ToString(),
                    Protocol = InternalEndpointTypeProtocol.tcp
                };

                nodeType.Endpoints.ServiceConnectionEndpoint = new InternalEndpointType()
                {
                    Port     = nodeTypeDescription.ServiceConnectionEndpointPort == 0 ? serviceConnectionEndpointPort : nodeTypeDescription.ServiceConnectionEndpointPort.ToString(),
                    Protocol = InternalEndpointTypeProtocol.tcp
                };

                nodeType.Endpoints.ApplicationEndpoints = new FabricEndpointsTypeApplicationEndpoints()
                {
                    StartPort = nodeTypeDescription.ApplicationPorts.StartPort,
                    EndPort   = nodeTypeDescription.ApplicationPorts.EndPort
                };

                if (nodeTypeDescription.EphemeralPorts != null)
                {
                    nodeType.Endpoints.EphemeralEndpoints = new FabricEndpointsTypeEphemeralEndpoints()
                    {
                        StartPort = nodeTypeDescription.EphemeralPorts.StartPort,
                        EndPort   = nodeTypeDescription.EphemeralPorts.EndPort
                    };
                }

                if (nodeTypeDescription.KtlLogger != null)
                {
                    nodeType.KtlLoggerSettings = nodeTypeDescription.KtlLogger.ToFabricKtlLoggerSettingsType();
                }

                if (nodeTypeDescription.LogicalDirectories != null && nodeTypeDescription.LogicalDirectories.Length > 0)
                {
                    LogicalDirectoryType[] logicalDirectories = new LogicalDirectoryType[nodeTypeDescription.LogicalDirectories.Count()];
                    var i = 0;
                    foreach (var dir in nodeTypeDescription.LogicalDirectories)
                    {
                        logicalDirectories[i++] = dir.ToLogicalDirectoryType();
                    }

                    nodeType.LogicalDirectories = logicalDirectories;
                }

                if (security != null && security.CertificateInformation != null &&
                    (security.CertificateInformation.ClusterCertificate != null || security.CertificateInformation.ClusterCertificateCommonNames != null ||
                     security.CertificateInformation.ServerCertificate != null || security.CertificateInformation.ServerCertificateCommonNames != null))
                {
                    nodeType.Endpoints.HttpGatewayEndpoint.Protocol = InputEndpointTypeProtocol.https;

                    FabricCertificateType clusterCertificate = null;
                    FabricCertificateType serverCertificate  = null;

                    if (security.CertificateInformation.ClusterCertificate != null)
                    {
                        clusterCertificate = security.CertificateInformation.ClusterCertificate.ToFabricCertificateType();
                    }
                    else if (security.CertificateInformation.ClusterCertificateCommonNames != null)
                    {
                        clusterCertificate = security.CertificateInformation.ClusterCertificateCommonNames.ToFabricCertificateType();
                    }

                    if (security.CertificateInformation.ServerCertificate != null)
                    {
                        serverCertificate = security.CertificateInformation.ServerCertificate.ToFabricCertificateType();
                    }
                    else if (security.CertificateInformation.ServerCertificateCommonNames != null)
                    {
                        serverCertificate = security.CertificateInformation.ServerCertificateCommonNames.ToFabricCertificateType();
                    }

                    nodeType.Certificates = new CertificatesType()
                    {
                        ClientCertificate  = clusterCertificate != null ? clusterCertificate : serverCertificate,
                        ClusterCertificate = clusterCertificate,
                        ServerCertificate  = serverCertificate
                    };
                }

                if (nodeType.Endpoints.HttpApplicationGatewayEndpoint != null &&
                    this.TargetCsmConfig.Security != null &&
                    this.TargetCsmConfig.Security.CertificateInformation != null &&
                    (this.TargetCsmConfig.Security.CertificateInformation.ReverseProxyCertificate != null ||
                     (this.TargetCsmConfig.Security.CertificateInformation.ReverseProxyCertificateCommonNames != null &&
                      this.TargetCsmConfig.Security.CertificateInformation.ReverseProxyCertificateCommonNames.Any())))
                {
                    nodeType.Endpoints.HttpApplicationGatewayEndpoint.Protocol = InputEndpointTypeProtocol.https;
                }

                result.Add(nodeType);
            }

            return(result);
        }
Esempio n. 10
0
        public PaasInfrastructure(ClusterManifestTypeInfrastructure cmInfrastructure, InfrastructureNodeType[] infrastructureNodes, Dictionary <string, ClusterManifestTypeNodeType> nameToNodeTypeMap)
        {
            this.votes = new List <SettingsTypeSectionParameter>();
            this.nodes = new List <InfrastructureNodeType>();
            this.seedNodeClientConnectionAddresses = new List <SettingsTypeSectionParameter>();

            ClusterManifestTypeInfrastructurePaaS infrastructure = cmInfrastructure.Item as ClusterManifestTypeInfrastructurePaaS;
            Dictionary <string, string>           roleToTypeMap  = new Dictionary <string, string>();

            foreach (var role in infrastructure.Roles)
            {
                try
                {
                    roleToTypeMap.Add(role.RoleName, role.NodeTypeRef);
                }
                catch (ArgumentException)
                {
                    throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "Role name {0} is duplicate", role.RoleName));
                }
            }

            foreach (var nodeInfo in infrastructureNodes)
            {
                ClusterManifestTypeNodeType nodeType = null;
                if (!nameToNodeTypeMap.TryGetValue(nodeInfo.NodeTypeRef, out nodeType) || nodeType == null)
                {
                    continue;
                }

                var node = (new InfrastructureNodeType()
                {
                    Certificates = nodeType.Certificates,
                    Endpoints = nodeType.Endpoints,
                    FaultDomain = nodeInfo.FaultDomain,
                    IPAddressOrFQDN = nodeInfo.IPAddressOrFQDN,
                    IsSeedNode = nodeInfo.IsSeedNode,
                    NodeName = nodeInfo.NodeName,
                    NodeTypeRef = nodeInfo.NodeTypeRef,
                    RoleOrTierName = nodeInfo.NodeTypeRef,
                    UpgradeDomain = nodeInfo.UpgradeDomain
                });

                this.nodes.Add(node);

                if (node.IsSeedNode)
                {
                    string key = node.NodeName;
                    string clientConnectionAddress = string.Format(CultureInfo.InvariantCulture, "{0}:{1}", node.IPAddressOrFQDN, node.Endpoints.ClientConnectionEndpoint.Port);
                    this.seedNodeClientConnectionAddresses.Add(new SettingsTypeSectionParameter()
                    {
                        Name = key, Value = clientConnectionAddress, MustOverride = false
                    });
                    FabricValidator.TraceSource.WriteNoise(FabricValidatorUtility.TraceTag, "Seed Nodes {0}-{1} added", key, clientConnectionAddress);
                }
            }

            foreach (var vote in infrastructure.Votes)
            {
                string key = vote.NodeName;
                string connectionAddress = string.Format(CultureInfo.InvariantCulture, "{0}:{1}", vote.IPAddressOrFQDN, vote.Port);
                string value             = string.Format(CultureInfo.InvariantCulture, "{0},{1}", "SeedNode", connectionAddress);
                this.votes.Add(new SettingsTypeSectionParameter()
                {
                    Name = key, Value = value, MustOverride = false
                });
                FabricValidator.TraceSource.WriteNoise(FabricValidatorUtility.TraceTag, "Vote {0}-{1} added", key, value);
            }
        }
        private void InitializeFromServiceRuntimeTopologyProvider(ClusterManifestTypeInfrastructureWindowsAzure azureInfrastructure, InfrastructureNodeType[] inputInfrastructureNodes, Dictionary <string, ClusterManifestTypeNodeType> nameToNodeTypeMap)
        {
            // For service runtime topology provider, source of cluster topology is infrastructure manifest provided by azure wrapper service.
            // Seed nodes are determined as the first SeedNodeCount nodes of the seed node role.
            ReleaseAssert.AssertIfNull(inputInfrastructureNodes, "inputInfrastructureNodes");

            Dictionary <string, int>    seedInfo      = new Dictionary <string, int>();
            Dictionary <string, string> roleToTypeMap = new Dictionary <string, string>();

            foreach (var role in azureInfrastructure.Roles)
            {
                try
                {
                    seedInfo.Add(role.RoleName, role.SeedNodeCount);
                    roleToTypeMap.Add(role.RoleName, role.NodeTypeRef);
                }
                catch (ArgumentException)
                {
                    throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "Role name {0} is duplicate", role.RoleName));
                }
            }

            foreach (var nodeInfo in inputInfrastructureNodes)
            {
                string nodeIndex = nodeInfo.NodeName.Split(".".ToCharArray()).Last();
                int    index     = int.Parse(nodeIndex);
                ClusterManifestTypeNodeType nodeType = null;
                if (roleToTypeMap.ContainsKey(nodeInfo.RoleOrTierName))
                {
                    var nodeTypeName = roleToTypeMap[nodeInfo.RoleOrTierName];
                    if (nameToNodeTypeMap.ContainsKey(nodeTypeName))
                    {
                        nodeType = nameToNodeTypeMap[nodeTypeName];
                    }
                    else
                    {
                        throw new ArgumentException(
                                  string.Format(
                                      CultureInfo.InvariantCulture,
                                      "Node type {0} specified for role {1} in node {2} not found",
                                      nodeTypeName,
                                      nodeInfo.RoleOrTierName,
                                      nodeInfo.NodeName));
                    }
                }
                else
                {
                    throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "Role name {0} specified in node {1} not found", nodeInfo.NodeName, nodeInfo.RoleOrTierName));
                }

                var node = new InfrastructureNodeType()
                {
                    FaultDomain     = nodeInfo.FaultDomain,
                    IPAddressOrFQDN = nodeInfo.IPAddressOrFQDN,
                    IsSeedNode      = index < seedInfo[nodeInfo.RoleOrTierName],
                    NodeName        = nodeInfo.NodeName,
                    NodeTypeRef     = roleToTypeMap[nodeInfo.RoleOrTierName],
                    UpgradeDomain   = nodeInfo.UpgradeDomain,
                    RoleOrTierName  = nodeInfo.RoleOrTierName,
                    Endpoints       = nodeInfo.Endpoints,
                    Certificates    = nodeType.Certificates
                };

                this.nodes.Add(node);

                if (node.IsSeedNode)
                {
                    // Add vote mappings
                    string connectionAddress = string.Format(CultureInfo.InvariantCulture, "{0}:{1}", node.IPAddressOrFQDN, node.Endpoints.ClusterConnectionEndpoint.Port);
                    this.voteMappings.Add(node.NodeName, connectionAddress);
                    FabricValidator.TraceSource.WriteNoise(FabricValidatorUtility.TraceTag, "Mapping {0}-{1} added", node.NodeName, connectionAddress);

                    // Add votes.
                    string key   = node.NodeName;
                    string value = string.Format(CultureInfo.InvariantCulture, "{0},{1}", "WindowsAzure", node.NodeName);
                    this.votes.Add(new SettingsTypeSectionParameter()
                    {
                        Name = key, Value = value, MustOverride = false
                    });
                    FabricValidator.TraceSource.WriteNoise(FabricValidatorUtility.TraceTag, "Vote {0}-{1} added", key, value);

                    string clientConnectionAddress = string.Format(CultureInfo.InvariantCulture, "{0}:{1}", node.IPAddressOrFQDN, node.Endpoints.ClientConnectionEndpoint.Port);
                    this.seedNodeClientConnectionAddresses.Add(new SettingsTypeSectionParameter()
                    {
                        Name = key, Value = clientConnectionAddress, MustOverride = false
                    });
                    FabricValidator.TraceSource.WriteNoise(FabricValidatorUtility.TraceTag, "Seed Nodes {0}-{1} added", key, clientConnectionAddress);
                }
            }

            this.isScaleMin = FabricValidatorUtility.IsAddressLoopback(nodes[0].IPAddressOrFQDN);
        }