protected virtual ClusterManifestTypeInfrastructure OnGetInfrastructure(IClusterTopology inputTopology, IEnumerable <NodeDescription> seedNodes, IEnumerable <ClusterManifestTypeNodeType> nodeTypes)
        {
            IEnumerable <PaaSRoleType> roles = this.TargetCsmConfig.NodeTypes.Select(nodeType => nodeType.ToPaaSRoleType());
            IEnumerable <PaaSVoteType> votes = seedNodes.Select(seedNode => this.ToPaaSVoteType(seedNode, nodeTypes));

            var infra = new ClusterManifestTypeInfrastructurePaaS()
            {
                Roles = roles.ToArray(),
                Votes = votes.ToArray()
            };

            return(new ClusterManifestTypeInfrastructure()
            {
                Item = infra
            });
        }
        private void InitializeInfrastructureSettings(InfrastructureType infrastructureType, bool isScaleMin, int nNodeTypes, int[] nSeedNodes)
        {
            switch (infrastructureType)
            {
            case InfrastructureType.Blackbird:
                return;

            case InfrastructureType.VMM:
                return;

            case InfrastructureType.PaaS:
                var paasInfra = new ClusterManifestTypeInfrastructurePaaS();
                paasInfra.Roles = new PaaSRoleType[nNodeTypes];
                for (int i = 0; i < nNodeTypes; i++)
                {
                    paasInfra.Roles[i]               = new PaaSRoleType();
                    paasInfra.Roles[i].RoleName      = GetRoleOrTiername(i);
                    paasInfra.Roles[i].NodeTypeRef   = GetRoleOrTiername(i);
                    paasInfra.Roles[i].RoleNodeCount = nSeedNodes[i];
                }
                var paasVotes = new List <PaaSVoteType>();
                foreach (var node in this.infraNodes)
                {
                    if (node.IsSeedNode)
                    {
                        paasVotes.Add(new PaaSVoteType()
                        {
                            NodeName        = node.NodeName,
                            IPAddressOrFQDN = node.IPAddressOrFQDN,
                            Port            = Convert.ToInt32(node.Endpoints.ClusterConnectionEndpoint.Port)
                        });
                    }
                }
                paasInfra.Votes          = paasVotes.ToArray();
                this.infrastructure      = new ClusterManifestTypeInfrastructure();
                this.infrastructure.Item = paasInfra;
                return;

            case InfrastructureType.WindowsAzure:
                var azureInfra = new ClusterManifestTypeInfrastructureWindowsAzure();
                azureInfra.Roles = new AzureRoleType[nNodeTypes];
                for (int i = 0; i < nNodeTypes; i++)
                {
                    azureInfra.Roles[i]               = new AzureRoleType();
                    azureInfra.Roles[i].RoleName      = GetRoleOrTiername(i);
                    azureInfra.Roles[i].NodeTypeRef   = GetRoleOrTiername(i);
                    azureInfra.Roles[i].SeedNodeCount = nSeedNodes[i];
                }
                this.infrastructure      = new ClusterManifestTypeInfrastructure();
                this.infrastructure.Item = azureInfra;
                return;

            case InfrastructureType.WindowsServer:
                var infra = new ClusterManifestTypeInfrastructureWindowsServer();
                infra.IsScaleMin         = isScaleMin;
                infra.NodeList           = this.nodes;
                this.infrastructure      = new ClusterManifestTypeInfrastructure();
                this.infrastructure.Item = infra;
                return;
            }
        }
Exemple #3
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;
            }
        }
        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 GenerateValidClusterManifest(InfrastructureType infaType)
        {
            this.ClusterManifest                = new ClusterManifestType();
            this.ClusterManifest.Name           = "TestClusterManifestAllSettings";
            this.ClusterManifest.Version        = "1.0";
            this.ClusterManifest.Infrastructure = new ClusterManifestTypeInfrastructure();

            if (infaType == InfrastructureType.WindowsServer)
            {
                ClusterManifestTypeInfrastructureWindowsServer infra =
                    new ClusterManifestTypeInfrastructureWindowsServer();
                infra.IsScaleMin  = false;
                infra.NodeList    = new FabricNodeType[1];
                infra.NodeList[0] = new FabricNodeType()
                {
                    FaultDomain     = "fd:/RACK1",
                    UpgradeDomain   = "MYUD1",
                    NodeName        = "Node1",
                    NodeTypeRef     = "NodeType1",
                    IPAddressOrFQDN = "localhost",
                    IsSeedNode      = true
                };

                this.ClusterManifest.Infrastructure.Item = infra;
            }
            else
            {
                ClusterManifestTypeInfrastructurePaaS infra = new ClusterManifestTypeInfrastructurePaaS();
                infra.Roles = new PaaSRoleType[]
                {
                    new PaaSRoleType()
                    {
                        NodeTypeRef = "NodeType1", RoleName = "NodeType1", RoleNodeCount = 5
                    }
                };

                infra.Votes = new PaaSVoteType[]
                {
                    new PaaSVoteType()
                    {
                        IPAddressOrFQDN = "10.0.0.1", NodeName = "_NodeType1_0", Port = 19005
                    },
                    new PaaSVoteType()
                    {
                        IPAddressOrFQDN = "10.0.0.2", NodeName = "_NodeType1_1", Port = 19005
                    },
                    new PaaSVoteType()
                    {
                        IPAddressOrFQDN = "10.0.0.3", NodeName = "_NodeType1_2", Port = 19005
                    }
                };

                this.ClusterManifest.Infrastructure.Item = infra;
            }


            this.ClusterManifest.NodeTypes              = new ClusterManifestTypeNodeType[1];
            this.ClusterManifest.NodeTypes[0]           = new ClusterManifestTypeNodeType();
            this.ClusterManifest.NodeTypes[0].Name      = "NodeType1";
            this.ClusterManifest.NodeTypes[0].Endpoints = new FabricEndpointsType()
            {
                ClientConnectionEndpoint = new InputEndpointType()
                {
                    Port = "19000"
                },
                LeaseDriverEndpoint = new InternalEndpointType()
                {
                    Port = "19001"
                },
                ClusterConnectionEndpoint = new InternalEndpointType()
                {
                    Port = "19002"
                },
                ServiceConnectionEndpoint = new InternalEndpointType()
                {
                    Port = "19003"
                },
                HttpGatewayEndpoint = new InputEndpointType()
                {
                    Port = "19004"
                },
                ApplicationEndpoints = new FabricEndpointsTypeApplicationEndpoints()
                {
                    StartPort = 30001, EndPort = 31000
                },
            };

            this.ClusterManifest.FabricSettings = new SettingsOverridesTypeSection[3];
            List <SettingsOverridesTypeSectionParameter> parameters = new List <SettingsOverridesTypeSectionParameter>();

            parameters.Add(new SettingsOverridesTypeSectionParameter()
            {
                Name = FabricValidatorConstants.ParameterNames.ClusterCredentialType, Value = "None", IsEncrypted = false
            });
            parameters.Add(new SettingsOverridesTypeSectionParameter()
            {
                Name = FabricValidatorConstants.ParameterNames.ServerAuthCredentialType, Value = "None", IsEncrypted = false
            });
            this.ClusterManifest.FabricSettings[0] = new SettingsOverridesTypeSection()
            {
                Name = FabricValidatorConstants.SectionNames.Security, Parameter = parameters.ToArray()
            };
            parameters = new List <SettingsOverridesTypeSectionParameter>();
            parameters.Add(new SettingsOverridesTypeSectionParameter()
            {
                Name = "ExpectedClustersize", Value = "1", IsEncrypted = false
            });
            this.ClusterManifest.FabricSettings[1] = new SettingsOverridesTypeSection()
            {
                Name = "FailoverManager", Parameter = parameters.ToArray()
            };
            parameters = new List <SettingsOverridesTypeSectionParameter>();
            parameters.Add(new SettingsOverridesTypeSectionParameter()
            {
                Name = "ImageStoreConnectionString", Value = "_default_", IsEncrypted = false
            });
            this.ClusterManifest.FabricSettings[2] = new SettingsOverridesTypeSection()
            {
                Name = "Management", Parameter = parameters.ToArray()
            };
        }