public static Cluster ToEnvoyEgressCluster(this EndpointType endpointType) { return(new Cluster() { Name = endpointType.EgressId, LbPolicy = Cluster.Types.LbPolicy.RoundRobin, Type = Cluster.Types.DiscoveryType.Eds, ConnectTimeout = Duration.FromTimeSpan(TimeSpan.FromMilliseconds(250)), EdsClusterConfig = new Cluster.Types.EdsClusterConfig() { EdsConfig = new ConfigSource() { Ads = new AggregatedConfigSource() { } } } }); }
private static Route CreateEnvoyRoute(EndpointType e, string clusterName, string prefixRewrite) { var match = new RouteMatch() { Prefix = e.ServiceAbsolutePath.TrimEnd('/') }; if (!e.DefaultEndpoint) { match.Headers.Add(new HeaderMatcher() { Name = "EndpointName", ExactMatch = e.EndpointName }); } if (e.Role == ServiceEndpointRole.StatefulSecondary) { match.Headers.Add(new HeaderMatcher() { Name = "Replica", ExactMatch = "Secondary" }); } var routeAction = new RouteAction { Cluster = clusterName }; if (prefixRewrite != null) { routeAction.PrefixRewrite = prefixRewrite == "/" ? prefixRewrite : prefixRewrite.TrimEnd('/'); } return(new Route { Route_ = routeAction, Match = match }); }
private static List <EndpointInstance> ExtractEndpoints(ServiceReplicaList replicas, Partition partition, Uri service) { List <EndpointInstance> endpointInstances = new List <EndpointInstance>(); foreach (var replica in replicas) { if (replica.ReplicaAddress.Length == 0) { continue; } JObject addresses; try { addresses = JObject.Parse(replica.ReplicaAddress); } catch { continue; } var endpoints = addresses["Endpoints"].Value <JObject>(); foreach (var endpoint in endpoints) { var endpointName = endpoint.Key; var endpointAddress = endpoint.Value.ToString(); if (!endpointAddress.StartsWith("http", StringComparison.InvariantCultureIgnoreCase)) { continue; } EndpointType endpointType = null; if (partition.ServiceKind == ServiceKind.Stateful) { var statefulRole = ((StatefulServiceReplica)replica).ReplicaRole; ServiceEndpointRole role; switch (statefulRole) { case ReplicaRole.Primary: role = ServiceEndpointRole.StatefulPrimary; break; case ReplicaRole.ActiveSecondary: role = ServiceEndpointRole.StatefulSecondary; break; default: role = ServiceEndpointRole.Invalid; break; } switch (partition.PartitionInformation.Kind) { case ServicePartitionKind.Singleton: endpointType = EndpointType.CreateSingleton(service.AbsolutePath, partition.PartitionInformation.Id, endpointName, endpoints.Count == 1, role); break; case ServicePartitionKind.Int64Range: var rangePartitionInformation = (Int64RangePartitionInformation)partition.PartitionInformation; endpointType = EndpointType.CreateInt64Partitioned(service.AbsolutePath, partition.PartitionInformation.Id, endpointName, endpoints.Count == 1, role, rangePartitionInformation.LowKey, rangePartitionInformation.HighKey); break; case ServicePartitionKind.Named: var namedPartitionInformation = (NamedPartitionInformation)partition.PartitionInformation; endpointType = EndpointType.CreateNamedPartitioned(service.AbsolutePath, partition.PartitionInformation.Id, endpointName, endpoints.Count == 1, role, namedPartitionInformation.Name); break; case ServicePartitionKind.Invalid: break; default: throw new ArgumentOutOfRangeException(); } } else { endpointType = EndpointType.CreateStateless(service.AbsolutePath, partition.PartitionInformation.Id, endpointName, endpoints.Count == 1); } if (endpointType != null) { var endpointInstanceObject = new EndpointInstance(endpointType, new Uri(endpointAddress), replica.NodeName); endpointInstances.Add(endpointInstanceObject); } } } return(endpointInstances); }
public EndpointInstance(EndpointType type, Uri networkAddress, string nodeName) { Type = type; NetworkAddress = networkAddress; NodeName = nodeName; }
protected bool Equals(EndpointType other) { return(string.Equals(_key, other._key)); }