public static string Of(Instance instance) { Preconditions.NotNull(instance, "instance"); String groupId = instance.GroupId; groupId = ServiceGroups.IsDefaultGroupId(groupId) ? ServiceGroups.DEFAULT_GROUP_ID : groupId; return(Of(instance.ServiceId, instance.RegionId, instance.ZoneId, groupId, instance.InstanceId)); }
public static RouteRule newDefaultRouteRule(List <Instance> instances) { return(new RouteRule() { RouteId = DEFAULT_ROUTE_RULE, Groups = new List <ServiceGroup>() { new ServiceGroup() { GroupKey = DEFAULT_GROUP_KEY, Weight = ServiceGroups.FixWeight(null), Instances = instances } }, Strategy = DEFAULT_ROUTE_STRATEGY }); }
public static List <RouteRule> NewRouteRules(this Service service) { List <RouteRule> routeRules = FilterRouteRules(service.RouteRules); Dictionary <string, Instance> groupKey2Instance = GenerateGroupKey2Instances(service.Instances); Dictionary <string, Instance> instanceId2Instance = GenerateInstanceId2Instance(service.Instances, service.LogicInstances); List <RouteRule> newRouteRules = new List <RouteRule>(); HashSet <string> routeRuleIds = new HashSet <string>(); foreach (RouteRule routeRule in routeRules) { List <ServiceGroup> nonemptyServiceGroups = new List <ServiceGroup>(); foreach (ServiceGroup serviceGroup in routeRule.Groups) { if (serviceGroup == null || string.IsNullOrWhiteSpace(serviceGroup.GroupKey)) { continue; } string groupKey = serviceGroup.GroupKey.ToLower(); List <Instance> instances = GenerateGroupInstances(serviceGroup, instanceId2Instance, groupKey2Instance); if (IsCanaryRouteRule(routeRule)) { Dictionary <String, Instance> maps = new Dictionary <string, Instance>(); foreach (Instance instance in instances) { maps[instance.InstanceId] = instance; } foreach (Instance instance in FilterInstances(serviceGroup.Instances)) { if (!maps.ContainsKey(instance.InstanceId)) { instances.Add(instance); } } } if (Conditions.IsNullOrEmpty(instances)) { continue; } ServiceGroup nonemptyServiceGroup = new ServiceGroup() { GroupKey = serviceGroup.GroupKey, Weight = ServiceGroups.FixWeight(serviceGroup.Weight), Instances = instances, Metadata = serviceGroup.Metadata == null ? null : new Dictionary <string, string>(serviceGroup.Metadata) }; nonemptyServiceGroups.Add(nonemptyServiceGroup); } routeRuleIds.Add(routeRule.RouteId.ToLower()); newRouteRules.Add(new RouteRule() { RouteId = routeRule.RouteId, Groups = nonemptyServiceGroups, Strategy = routeRule.Strategy }); } if (!routeRuleIds.Contains(DEFAULT_ROUTE_RULE)) { newRouteRules.Add(newDefaultRouteRule(groupKey2Instance.Values.ToList())); } return(newRouteRules); }