Esempio n. 1
0
        /*public static async Task<TargetGroup> GetTargetGroupByNameAsync(
         *  this ELBHelper elbh,
         *  string loadBalancerName,
         *  string targetGroupName,
         *  bool throwIfNotFound)
         * {
         *  var albs = await elbh.GetLoadBalancersByName(loadBalancerName, throwIfNotFound: throwIfNotFound);
         *  var albsCount = (albs?.Count() ?? 0);
         *
         *  if (albsCount > 1)
         *      throw new Exception($"Found more then one Loadbalancer with name '{loadBalancerName}'.");
         *  else if(albsCount <= 0)
         *  {
         *      if (throwIfNotFound)
         *          throw new Exception($"Loadbalancer with name '{loadBalancerName}' was not found.");
         *      else
         *          return null;
         *  }
         *
         *  var alb = albs.Single();
         *  IEnumerable<TargetGroup> tgs;
         *
         *  if (!throwIfNotFound)
         *  {
         *      try
         *      {
         *          tgs = await elbh.DescribeTargetGroupsAsync(alb.LoadBalancerArn, names: new List<string>() { targetGroupName });
         *      }
         *      catch (TargetGroupNotFoundException ex)
         *      {
         *          return null;
         *      }
         *  }
         *  else
         *      tgs = await elbh.DescribeTargetGroupsAsync(alb.LoadBalancerArn, names: new List<string>() { targetGroupName });
         *
         *  var tgsCount = (tgs?.Count() ?? 0);
         *
         *  if (tgsCount > 1)
         *      throw new Exception($"Found more then one Target Group with name '{targetGroupName}'.");
         *  else if (tgsCount <= 0)
         *  {
         *      if (throwIfNotFound)
         *          throw new Exception($"Target Group with name '{targetGroupName}' was not found.");
         *      else
         *          return null;
         *  }
         *
         *  return tgs.Single();
         * }*/

        public static async Task <TargetGroup> GetTargetGroupByNameAsync(
            this ELBHelper elbh,
            string targetGroupName,
            bool throwIfNotFound)
        {
            IEnumerable <TargetGroup> tgs;

            if (!throwIfNotFound)
            {
                try
                {
                    tgs = await elbh.DescribeTargetGroupsAsync(loadBalancerArn : null, names : new List <string>()
                    {
                        targetGroupName
                    });
                }
                catch (TargetGroupNotFoundException)
                {
                    return(null);
                }
            }
            else
            {
                tgs = await elbh.DescribeTargetGroupsAsync(loadBalancerArn : null, names : new List <string>()
                {
                    targetGroupName
                });
            }

            var tgsCount = (tgs?.Count() ?? 0);

            if (tgsCount > 1)
            {
                throw new Exception($"Found more then one Target Group with name '{targetGroupName}'.");
            }
            else if (tgsCount <= 0)
            {
                if (throwIfNotFound)
                {
                    throw new Exception($"Target Group with name '{targetGroupName}' was not found.");
                }
                else
                {
                    return(null);
                }
            }

            return(tgs.Single());
        }
Esempio n. 2
0
 public static async Task <IEnumerable <string> > ListTargetGroupsAsync(
     this ELBHelper elbh,
     string loadBalancerArn,
     IEnumerable <string> names           = null,
     IEnumerable <string> targetGroupArns = null,
     CancellationToken cancellationToken  = default(CancellationToken))
 => (await elbh.DescribeTargetGroupsAsync(loadBalancerArn, names, targetGroupArns, cancellationToken)).Select(x => x.TargetGroupArn);
Esempio n. 3
0
        public static async Task <TargetGroup> GetTargetGroupByName(this ELBHelper elbh, string name, LoadBalancer lb, bool throwIfNotFound, CancellationToken cancellationToken = default(CancellationToken))
        {
            var tgs = await elbh.DescribeTargetGroupsAsync(lb.LoadBalancerArn);

            var tg = tgs.SingleOrDefault(x => x.TargetGroupName == name);

            if (throwIfNotFound && tg == null)
            {
                throw new Exception($"Could not find Target Group '{name}' for Load Balancer '{lb.LoadBalancerName}'");
            }

            return(tg);
        }
Esempio n. 4
0
        public static async Task <IEnumerable <TargetGroup> > DescribeLoadBalancerTargetGroupsAsync(
            this ELBHelper elbh,
            string loadBalancerName,
            bool thowIfNotFound,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            var loadbalancer = (await elbh.GetLoadBalancersByName(loadBalancerName, thowIfNotFound, cancellationToken)).SingleOrDefault();

            if (!thowIfNotFound)
            {
                return(null);
            }

            return(await elbh.DescribeTargetGroupsAsync(loadBalancerArn : loadbalancer.LoadBalancerArn, cancellationToken : cancellationToken));
        }