public Task <IList <Uri> > GetGateways()
 {
     if (database.KeyExists(clusterId))
     {
         var val = database.StringGet(clusterId);
         RedisMembershipCollection collection = serializer.Deserialize <RedisMembershipCollection>(val);
         try
         {
             return(Task.FromResult <IList <Uri> >(collection.Where(x => x.Status == SiloStatus.Active && x.ProxyPort != 0)
                                                   .Select(y =>
             {
                 var endpoint = new IPEndPoint(y.Address.Endpoint.Address, y.ProxyPort);
                 var gatewayAddress = SiloAddress.New(endpoint, y.Address.Generation);
                 return gatewayAddress.ToGatewayUri();
             }).ToList()));
         }
         catch
         {
             return(Task.FromResult <IList <Uri> >(null));
         }
     }
     else
     {
         return(Task.FromResult <IList <Uri> >(null));
     }
 }
        public Task <IList <Uri> > GetGateways()
        {
            if (database.KeyExists(clusterId))
            {
                var val = database.StringGet(clusterId);
                RedisMembershipCollection collection = serializer.Deserialize <RedisMembershipCollection>(val);
                try
                {
                    return(Task.FromResult <IList <Uri> >(collection
                                                          .Where(x => x.Status == SiloStatus.Active && x.ProxyPort != 0)
                                                          .Select(y =>
                    {
                        var endpoint = new IPEndPoint(y.Address.Endpoint.Address, y.ProxyPort);
                        var gatewayAddress = SiloAddress.New(endpoint, y.Address.Generation);
                        return gatewayAddress.ToGatewayUri();
                    }).ToList()));
                }
                catch (Exception ex)
                {
                    logger?.LogErrorAsync(ex, "Redis Gateway List Provider - GetGateways").GetAwaiter();
                    return(Task.FromResult <IList <Uri> >(null));
                }
            }

            logger?.LogWarningAsync("Redis Gateway List Provider - No Cluster ID exists.").GetAwaiter();
            return(Task.FromResult <IList <Uri> >(null));
        }
Esempio n. 3
0
        public async Task <bool> UpdateRow(MembershipEntry entry, string etag, TableVersion tableVersion)
        {
            bool ret = false;

            try
            {
                while (true)
                {
                    long ticks = DateTime.UtcNow.Ticks;
                    await database.StringSetAsync("locktoken", ticks.ToString(), new TimeSpan(0, 0, 10));

                    if (string.IsNullOrEmpty(etag))
                    {
                        etag = "0";
                    }


                    var rentry = RedisMembershipEntry.Create(clusterId, entry, etag);
                    var val    = await database.StringGetAsync(clusterId);

                    if (!val.IsNull)
                    {
                        RedisMembershipCollection collection = serializer.Deserialize <RedisMembershipCollection>(val);
                        var items = collection.Where((x) => x.DeploymentId == clusterId && x.Address.ToParsableString() == rentry.Address.ToParsableString());
                        if (items != null && items.Count() > 0)
                        {
                            RedisMembershipEntry oldEntry = items.First();
                            rentry.LastIndex = oldEntry.LastIndex++;
                            collection.Remove(oldEntry);
                            collection.Add(rentry);

                            string tokenValue = await database.StringGetAsync("locktoken");

                            if (tokenValue != ticks.ToString())
                            {
                                continue;
                            }
                            else
                            {
                                ret = await database.StringSetAsync(clusterId, serializer.Serialize(collection));

                                break;
                            }
                        }
                    }
                }

                return(ret);
            }
            catch (Exception ex)
            {
                logger?.LogError(ex, "Redis membership table key '{0}' failed update row.", clusterId);
                throw ex;
            }
        }
Esempio n. 4
0
        public async Task <bool> UpdateRow(MembershipEntry entry, string etag, TableVersion tableVersion)
        {
            try
            {
                bool ret = false;

                if (string.IsNullOrEmpty(etag))
                {
                    etag = "0";
                }


                var rentry = RedisMembershipEntry.Create(clusterId, entry, etag);
                var val    = await database.StringGetAsync(clusterId);

                if (!val.IsNull)
                {
                    RedisMembershipCollection collection = serializer.Deserialize <RedisMembershipCollection>(val);
                    var items = collection.Where((x) => x.DeploymentId == clusterId && x.Address.ToParsableString() == rentry.Address.ToParsableString());
                    if (items != null && items.Count() > 0)
                    {
                        RedisMembershipEntry oldEntry = items.First();
                        rentry.LastIndex = oldEntry.LastIndex++;
                        collection.Remove(oldEntry);
                        collection.Add(rentry);
                        ret = await database.StringSetAsync(clusterId, serializer.Serialize(collection));
                    }
                }
                return(ret);
            }
            catch (Exception ex)
            {
                logger?.LogError(ex, "Redis membership table key '{0}' failed update row.", clusterId);
                throw ex;
            }
        }