Example #1
0
            internal static Tuple <MembershipEntry, int> GetMembershipEntry(IDataRecord record)
            {
                //TODO: This is a bit of hack way to check in the current version if there's membership data or not, but if there's a start time, there's member.
                DateTime?       startTime = record.GetValueOrDefault <DateTime?>(nameof(Columns.StartTime));
                MembershipEntry entry     = null;

                if (startTime.HasValue)
                {
                    entry = new MembershipEntry
                    {
                        SiloAddress  = GetSiloAddress(record, nameof(Columns.Port)),
                        HostName     = record.GetValue <string>(nameof(Columns.HostName)),
                        Status       = record.GetValue <SiloStatus>(nameof(Columns.Status)),
                        ProxyPort    = record.GetValue <int>(nameof(Columns.ProxyPort)),
                        StartTime    = startTime.Value,
                        IAmAliveTime = record.GetValue <DateTime>(nameof(Columns.IAmAliveTime))
                    };

                    string suspectingSilos = record.GetValueOrDefault <string>(nameof(Columns.SuspectTimes));
                    if (!string.IsNullOrWhiteSpace(suspectingSilos))
                    {
                        entry.SuspectTimes = new List <Tuple <SiloAddress, DateTime> >();
                        entry.SuspectTimes.AddRange(suspectingSilos.Split('|').Select(s =>
                        {
                            var split = s.Split(',');
                            return(new Tuple <SiloAddress, DateTime>(SiloAddress.FromParsableString(split[0]),
                                                                     TraceLogger.ParseDate(split[1])));
                        }));
                    }
                }

                return(Tuple.Create(entry, GetVersion(record)));
            }
Example #2
0
        public void SiloAddress_ToFrom_ParsableString()
        {
            string testName = TestContext.TestName;

            Console.WriteLine(testName);

            SiloAddress address1 = SiloAddress.NewLocalAddress(12345);

            string      addressStr1 = address1.ToParsableString();
            SiloAddress addressObj1 = SiloAddress.FromParsableString(addressStr1);

            Console.WriteLine("Convert -- From: {0} Got result string: '{1}' object: {2}",
                              address1, addressStr1, addressObj1);

            Assert.AreEqual(address1, addressObj1, "SiloAddress equal after To-From-ParsableString");

            //const string addressStr2 = "127.0.0.1-11111-144611139";
            const string addressStr2    = "127.0.0.1:11111@144611139";
            SiloAddress  addressObj2    = SiloAddress.FromParsableString(addressStr2);
            string       addressStr2Out = addressObj2.ToParsableString();

            Console.WriteLine("Convert -- From: {0} Got result string: '{1}' object: {2}",
                              addressStr2, addressStr2Out, addressObj2);

            Assert.AreEqual(addressStr2, addressStr2Out, "SiloAddress equal after From-To-ParsableString");
        }
Example #3
0
 public static ActivationAddress ToActivationAddress(this GrainAddress addr)
 {
     return(ActivationAddress.GetAddress(
                SiloAddress.FromParsableString(addr.SiloAddress),
                GrainId.FromParsableString(addr.GrainId),
                ActivationId.GetActivationId(UniqueKey.Parse(addr.ActivationId.AsSpan()))));
 }
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            JObject     jo   = JObject.Load(reader);
            SiloAddress addr = SiloAddress.FromParsableString(jo["SiloAddress"].ToObject <string>());

            return(addr);
        }
        public async Task DoNotOverrideEntry()
        {
            var expected = new GrainAddress
            {
                ActivationId = ActivationId.NewId(),
                GrainId      = GrainId.Parse("user/someraondomuser_" + Guid.NewGuid().ToString("N")),
                SiloAddress  = SiloAddress.FromParsableString("10.0.23.12:1000@5678")
            };

            var differentActivation = new GrainAddress
            {
                ActivationId = ActivationId.NewId(),
                GrainId      = expected.GrainId,
                SiloAddress  = SiloAddress.FromParsableString("10.0.23.12:1000@5678")
            };

            var differentSilo = new GrainAddress
            {
                ActivationId = expected.ActivationId,
                GrainId      = expected.GrainId,
                SiloAddress  = SiloAddress.FromParsableString("10.0.23.14:1000@4583")
            };

            Assert.Equal(expected, await this.grainDirectory.Register(expected));
            Assert.Equal(expected, await this.grainDirectory.Register(differentActivation));
            Assert.Equal(expected, await this.grainDirectory.Register(differentSilo));

            Assert.Equal(expected, await this.grainDirectory.Lookup(expected.GrainId));
        }
        MembershipEntry GetMembershipEntry(Row row, SiloAddress forAddress = null)
        {
            if (row["start_time"] == null)
            {
                return(null);
            }

            var result = new MembershipEntry
            {
                SiloAddress  = forAddress ?? SiloAddress.New(new IPEndPoint(IPAddress.Parse((string)row["address"]), (int)row["port"]), (int)row["generation"]),
                SiloName     = (string)row["silo_name"],
                HostName     = (string)row["host_name"],
                Status       = (SiloStatus)(int)row["status"],
                ProxyPort    = (int)row["proxy_port"],
                StartTime    = ((DateTimeOffset)row["start_time"]).UtcDateTime,
                IAmAliveTime = ((DateTimeOffset)row["i_am_alive_time"]).UtcDateTime
            };

            var suspectingSilos = (string)row["suspect_times"];

            if (!string.IsNullOrWhiteSpace(suspectingSilos))
            {
                result.SuspectTimes = new List <Tuple <SiloAddress, DateTime> >();
                result.SuspectTimes.AddRange(suspectingSilos.Split('|').Select(s =>
                {
                    var split = s.Split(',');
                    return(new Tuple <SiloAddress, DateTime>(SiloAddress.FromParsableString(split[0]), LogFormatter.ParseDate(split[1])));
                }));
            }

            return(result);
        }
Example #7
0
        private async Task CollectStatistics(bool canDeactivate)
        {
            var siloAddress     = SiloAddress.FromParsableString(this.GetPrimaryKeyString());
            var managementGrain = GrainFactory.GetGrain <IManagementGrain>(0);

            try
            {
                var results = (await managementGrain.GetRuntimeStatistics(new[] { siloAddress })).FirstOrDefault();

                stats.Enqueue(results);

                while (stats.Count > Dashboard.HistoryLength)
                {
                    stats.Dequeue();
                }
            }
            catch (Exception)
            {
                // we can't get the silo stats, it's probably dead, so kill the grain
                if (canDeactivate)
                {
                    timer?.Dispose();
                    timer = null;

                    DeactivateOnIdle();
                }
            }
        }
Example #8
0
        async Task Callback(object canDeactivate)
        {
            var address = SiloAddress.FromParsableString(this.GetPrimaryKeyString());
            var grain   = this.GrainFactory.GetGrain <IManagementGrain>(0);

            try
            {
                var results = (await grain.GetRuntimeStatistics(new SiloAddress[] { address })).FirstOrDefault();
                stats.Enqueue(results);
                while (this.stats.Count > Dashboard.HistoryLength)
                {
                    this.stats.Dequeue();
                }
            }
            catch (Exception)
            {
                // we can't get the silo stats, it's probably dead, so kill the grain
                if (!(bool)canDeactivate)
                {
                    return;
                }
                if (null != timer)
                {
                    timer.Dispose();
                }
                timer = null;
                this.DeactivateOnIdle();
            }
        }
Example #9
0
        private MembershipEntry Parse(SiloInstanceRecord tableEntry)
        {
            var parse = new MembershipEntry
            {
                HostName = tableEntry.HostName,
                Status   = (SiloStatus)tableEntry.Status
            };

            parse.ProxyPort = tableEntry.ProxyPort;

            parse.SiloAddress = SiloAddress.New(new IPEndPoint(IPAddress.Parse(tableEntry.Address), tableEntry.Port), tableEntry.Generation);

            if (!string.IsNullOrEmpty(tableEntry.SiloName))
            {
                parse.SiloName = tableEntry.SiloName;
            }

            parse.StartTime = !string.IsNullOrEmpty(tableEntry.StartTime) ?
                              LogFormatter.ParseDate(tableEntry.StartTime) : default(DateTime);

            parse.IAmAliveTime = !string.IsNullOrEmpty(tableEntry.IAmAliveTime) ?
                                 LogFormatter.ParseDate(tableEntry.IAmAliveTime) : default(DateTime);

            var suspectingSilos = new List <SiloAddress>();
            var suspectingTimes = new List <DateTime>();

            if (!string.IsNullOrEmpty(tableEntry.SuspectingSilos))
            {
                string[] silos = tableEntry.SuspectingSilos.Split('|');
                foreach (string silo in silos)
                {
                    suspectingSilos.Add(SiloAddress.FromParsableString(silo));
                }
            }

            if (!string.IsNullOrEmpty(tableEntry.SuspectingTimes))
            {
                string[] times = tableEntry.SuspectingTimes.Split('|');
                foreach (string time in times)
                {
                    suspectingTimes.Add(LogFormatter.ParseDate(time));
                }
            }

            if (suspectingSilos.Count != suspectingTimes.Count)
            {
                throw new OrleansException(String.Format("SuspectingSilos.Length of {0} as read from Azure table is not equal to SuspectingTimes.Length of {1}", suspectingSilos.Count, suspectingTimes.Count));
            }

            for (int i = 0; i < suspectingSilos.Count; i++)
            {
                parse.AddSuspector(suspectingSilos[i], suspectingTimes[i]);
            }

            return(parse);
        }
Example #10
0
        object GetRuntimeStats(dynamic parameters)
        {
            var address = SiloAddress.FromParsableString((string)parameters.address);
            var grain   = Dashboard.ProviderRuntime.GrainFactory.GetGrain <IManagementGrain>(0);

            var result = Dispatch(async() => {
                return((await grain.GetRuntimeStatistics(new SiloAddress[] { address })).FirstOrDefault());
            });

            return(this.Response.AsJson(result));
        }
Example #11
0
        public static (string key, SiloAddress address) GetCompositeKey(this ISimpleStreamingReplicaGrain grain)
        {
            if (grain is null)
            {
                throw new ArgumentNullException(nameof(grain));
            }

            var components = grain.GetPrimaryKeyString().Split('|');
            var key        = components[0];
            var address    = SiloAddress.FromParsableString(components[1]);

            return(key, address);
        }
        public static MembershipEntry AsMembershipEntry(this ISiloIntance siloIntance)
        {
            var entry = new MembershipEntry
            {
                SiloName     = siloIntance.SiloName,
                HostName     = siloIntance.HostName,
                Status       = (SiloStatus)siloIntance.Status,
                RoleName     = siloIntance.RoleName,
                UpdateZone   = siloIntance.UpdateZone,
                FaultZone    = siloIntance.FaultZone,
                StartTime    = siloIntance.StartTime.UtcDateTime,
                IAmAliveTime = siloIntance.IAmAliveTime.UtcDateTime,
                SiloAddress  = SiloAddress.New(new IPEndPoint(IPAddress.Parse(siloIntance.Address), siloIntance.Port), siloIntance.Generation)
            };

            if (siloIntance.ProxyPort.HasValue)
            {
                entry.ProxyPort = siloIntance.ProxyPort.Value;
            }

            var suspectingSilos = new List <SiloAddress>();
            var suspectingTimes = new List <DateTime>();

            foreach (var silo in siloIntance.SuspectingSilos)
            {
                suspectingSilos.Add(SiloAddress.FromParsableString(silo));
            }

            foreach (var time in siloIntance.SuspectingTimes)
            {
                suspectingTimes.Add(time.UtcDateTime);
            }

            if (suspectingSilos.Count != suspectingTimes.Count)
            {
                throw new OrleansException(
                          $"SuspectingSilos.Length of {suspectingSilos.Count} as read from Cassandra " +
                          $"is not equal to SuspectingTimes.Length of {suspectingTimes.Count}");
            }

            for (var i = 0; i < suspectingSilos.Count; i++)
            {
                entry.AddSuspector(suspectingSilos[i], suspectingTimes[i]);
            }

            return(entry);
        }
Example #13
0
        public async Task RegisterLookupUnregisterLookup()
        {
            var expected = new GrainAddress
            {
                ActivationId = ActivationId.NewId(),
                GrainId      = GrainId.Parse("user/someraondomuser_" + Guid.NewGuid().ToString("N")),
                SiloAddress  = SiloAddress.FromParsableString("10.0.23.12:1000@5678")
            };

            Assert.Equal(expected, await this.grainDirectory.Register(expected));

            Assert.Equal(expected, await this.grainDirectory.Lookup(expected.GrainId));

            await this.grainDirectory.Unregister(expected);

            Assert.Null(await this.grainDirectory.Lookup(expected.GrainId));
        }
Example #14
0
        /// <summary>
        /// Parses the MembershipData to a MembershipEntry
        /// </summary>
        /// <param name="membershipData">
        /// The membership data.
        /// </param>
        /// <returns>
        /// The <see cref="Task"/>.
        /// </returns>
        internal async Task <Tuple <MembershipEntry, string> > Parse(MembershipCollection membershipData)
        {
            // TODO: This is a bit of hack way to check in the current version if there's membership data or not, but if there's a start time, there's member.
            DateTime?       startTime = membershipData.StartTime;
            MembershipEntry entry     = null;

            if (startTime.HasValue)
            {
                entry = new MembershipEntry
                {
                    SiloAddress = ReturnSiloAddress(membershipData),

                    // SiloName = TryGetSiloName(record),
                    HostName     = membershipData.HostName,
                    Status       = (SiloStatus)membershipData.Status,
                    ProxyPort    = membershipData.ProxyPort,
                    StartTime    = startTime.Value,
                    IAmAliveTime = membershipData.IAmAliveTime,
                    SiloName     = membershipData.HostName
                };

                string suspectingSilos = membershipData.SuspectTimes;
                if (!string.IsNullOrWhiteSpace(suspectingSilos))
                {
                    entry.SuspectTimes = new List <Tuple <SiloAddress, DateTime> >();
                    entry.SuspectTimes.AddRange(
                        suspectingSilos.Split('|').Select(
                            s =>
                    {
                        var split = s.Split(',');
                        return(new Tuple <SiloAddress, DateTime>(
                                   SiloAddress.FromParsableString(split[0].Trim()),
                                   LogFormatter.ParseDate(split[1].Trim())));
                    }));
                }
            }

            BsonDocument membershipVersionDocument =
                await
                this.FindDocumentAsync(
                    MembershipVersionCollectionName,
                    MembershipVersionKeyName,
                    membershipData.DeploymentId);

            return(Tuple.Create(entry, membershipVersionDocument["Version"].AsInt32.ToString()));
        }
Example #15
0
        private static MembershipEntry ParseEntity(SiloEntity entity)
        {
            var entry = new MembershipEntry
            {
                HostName = entity.Hostname,
                Status   = entity.Status
            };

            if (entity.ProxyPort.HasValue)
            {
                entry.ProxyPort = entity.ProxyPort.Value;
            }

            entry.SiloAddress = SiloAddress.New(new IPEndPoint(IPAddress.Parse(entity.Address), entity.Port), entity.Generation);

            entry.SiloName = entity.SiloName;

            entry.StartTime = entity.StartTime.UtcDateTime;

            entry.IAmAliveTime = entity.IAmAliveTime.UtcDateTime;

            var suspectingSilos = new List <SiloAddress>();
            var suspectingTimes = new List <DateTime>();

            foreach (var silo in entity.SuspectingSilos)
            {
                suspectingSilos.Add(SiloAddress.FromParsableString(silo));
            }

            foreach (var time in entity.SuspectingTimes)
            {
                suspectingTimes.Add(LogFormatter.ParseDate(time));
            }

            if (suspectingSilos.Count != suspectingTimes.Count)
            {
                throw new OrleansException($"SuspectingSilos.Length of {suspectingSilos.Count} as read from Kubernetes is not equal to SuspectingTimes.Length of {suspectingTimes.Count}");
            }

            for (int i = 0; i < suspectingSilos.Count; i++)
            {
                entry.AddSuspector(suspectingSilos[i], suspectingTimes[i]);
            }

            return(entry);
        }
Example #16
0
        /// <summary>
        /// Maps the specified source.
        /// </summary>
        /// <param name="src">The source.</param>
        /// <param name="dst">The DST.</param>
        /// <returns></returns>
        internal static MembershipTableData Map(
            List <OrleansEFMembership> src,
            MembershipTableData dst = null
            )
        {
            var entries = src.Select(a =>
            {
                return(new Tuple <MembershipEntry, string>(
                           new MembershipEntry
                {
                    SiloAddress = Map(
                        a.Address,
                        (int)a.Port,
                        a.Generation
                        ),
                    Status = (SiloStatus)a.Status,
                    ProxyPort = (int)a.ProxyPort,
                    HostName = a.HostName,
                    SiloName = a.SiloName,
                    StartTime = a.StartTime,
                    IAmAliveTime = a.IAmAliveTime,
                    UpdateZone = a.UpdateZone,
                    FaultZone = a.FaultZone,
                    SuspectTimes = a.SuspectTimes?.Split(";").Where(b =>
                                                                    !string.IsNullOrWhiteSpace(b)
                                                                    ).Select(b =>
                    {
                        var split = b.Split("::");
                        return new Tuple <SiloAddress, DateTime>(
                            SiloAddress.FromParsableString(split[0]),
                            DateTimeOffset.FromUnixTimeMilliseconds(long.Parse(split[1])).UtcDateTime
                            );
                    }).ToList(),
                },
                           a.DeploymentId
                           ));
            }).ToList();

            dst = new MembershipTableData(
                entries,
                new TableVersion(1, "whatever")
                );

            return(dst);
        }
        public async Task UnregisterMany()
        {
            const int N = 250;
            const int R = 40;

            // Create and insert N entries
            var addresses = new List <GrainAddress>();

            for (var i = 0; i < N; i++)
            {
                var addr = new GrainAddress
                {
                    ActivationId = ActivationId.NewId(),
                    GrainId      = GrainId.Parse("user/someraondomuser_" + Guid.NewGuid().ToString("N")),
                    SiloAddress  = SiloAddress.FromParsableString("10.0.23.12:1000@5678")
                };
                addresses.Add(addr);
                await this.grainDirectory.Register(addr);
            }

            // Modify the Rth entry locally, to simulate another activation tentative by another silo
            var oldActivation = addresses[R].ActivationId;

            addresses[R].ActivationId = ActivationId.NewId();

            // Batch unregister
            await this.grainDirectory.UnregisterMany(addresses);

            // Now we should only find the old Rth entry
            for (int i = 0; i < N; i++)
            {
                if (i == R)
                {
                    var addr = await this.grainDirectory.Lookup(addresses[i].GrainId);

                    Assert.NotNull(addr);
                    Assert.Equal(oldActivation, addr.ActivationId);
                }
                else
                {
                    Assert.Null(await this.grainDirectory.Lookup(addresses[i].GrainId));
                }
            }
        }
        async Task GetRuntimeStats(IOwinContext context, IDictionary <string, string> parameters)
        {
            var address = SiloAddress.FromParsableString(EscapeString(parameters["address"]));
            var grain   = this.ProviderRuntime.GrainFactory.GetGrain <IManagementGrain>(0);

            var result = await Dispatch(async() =>
            {
                Dictionary <SiloAddress, SiloStatus> silos = await grain.GetHosts(true).ConfigureAwait(false);
                SiloStatus siloStatus;
                if (silos.TryGetValue(address, out siloStatus))
                {
                    return((await grain.GetRuntimeStatistics(new SiloAddress[] { address }).ConfigureAwait(false)).FirstOrDefault());
                }
                return(null);
            }).ConfigureAwait(false);


            await context.ReturnJson(result).ConfigureAwait(false);
        }
Example #19
0
        public async Task DoNotDeleteDifferentActivationIdEntry()
        {
            var expected = new GrainAddress
            {
                ActivationId = ActivationId.NewId(),
                GrainId      = GrainId.Parse("user/someraondomuser_" + Guid.NewGuid().ToString("N")),
                SiloAddress  = SiloAddress.FromParsableString("10.0.23.12:1000@5678")
            };

            var otherEntry = new GrainAddress
            {
                ActivationId = ActivationId.NewId(),
                GrainId      = expected.GrainId,
                SiloAddress  = SiloAddress.FromParsableString("10.0.23.12:1000@5678")
            };

            Assert.Equal(expected, await this.grainDirectory.Register(expected));
            await this.grainDirectory.Unregister(otherEntry);

            Assert.Equal(expected, await this.grainDirectory.Lookup(expected.GrainId));
        }
        internal static ConsulSiloRegistration FromKVPairs(String deploymentId, KVPair siloKV, KVPair iAmAliveKV)
        {
            var ret = JsonConvert.DeserializeObject <ConsulSiloRegistration>(Encoding.UTF8.GetString(siloKV.Value));

            var keyParts = siloKV.Key.Split(KeySeparator);

            ret.Address      = SiloAddress.FromParsableString(keyParts.Last());
            ret.DeploymentId = deploymentId;
            ret.LastIndex    = siloKV.ModifyIndex;

            if (iAmAliveKV == null)
            {
                ret.IAmAliveTime = ret.StartTime;
            }
            else
            {
                ret.IAmAliveTime = JsonConvert.DeserializeObject <DateTime>(Encoding.UTF8.GetString(iAmAliveKV.Value));
            }

            return(ret);
        }
Example #21
0
        internal static Tuple <MembershipEntry, String> ToMembershipEntry(CouchBaseSiloRegistration siloRegistration, string cas = "")
        {
            siloRegistration.Address = SiloAddress.FromParsableString(siloRegistration.SerializedAddress);
            var entry = new MembershipEntry
            {
                SiloAddress  = siloRegistration.Address,
                HostName     = siloRegistration.Hostname,
                Status       = siloRegistration.Status,
                ProxyPort    = siloRegistration.ProxyPort,
                StartTime    = siloRegistration.StartTime,
                SuspectTimes = siloRegistration.SuspectingSilos.Select(silo => new Tuple <SiloAddress, DateTime>(SiloAddress.FromParsableString(silo.Id), silo.Time)).ToList(),
                IAmAliveTime = siloRegistration.IAmAliveTime,
                //SiloName = siloRegistration.SiloName,

                // Optional - only for Azure role so initialised here
                RoleName   = String.Empty,
                UpdateZone = 0,
                FaultZone  = 0
            };

            return(new Tuple <MembershipEntry, String>(entry, cas));
        }
Example #22
0
        public void SiloAddress_ToFrom_ParsableString()
        {
            SiloAddress address1 = SiloAddress.NewLocalAddress(12345);

            string      addressStr1 = address1.ToParsableString();
            SiloAddress addressObj1 = SiloAddress.FromParsableString(addressStr1);

            output.WriteLine("Convert -- From: {0} Got result string: '{1}' object: {2}",
                             address1, addressStr1, addressObj1);

            Assert.Equal(address1, addressObj1); // SiloAddress equal after To-From-ParsableString

            //const string addressStr2 = "127.0.0.1-11111-144611139";
            const string addressStr2    = "127.0.0.1:11111@144611139";
            SiloAddress  addressObj2    = SiloAddress.FromParsableString(addressStr2);
            string       addressStr2Out = addressObj2.ToParsableString();

            output.WriteLine("Convert -- From: {0} Got result string: '{1}' object: {2}",
                             addressStr2, addressStr2Out, addressObj2);

            Assert.Equal(addressStr2, addressStr2Out); // SiloAddress equal after From-To-ParsableString
        }
Example #23
0
        private static MembershipEntry ConvertFromRow(SqlDataReader results, out string eTag, out int tableVersion, out string versionETag)
        {
            var entry = new MembershipEntry();

            int port = results.GetInt32(PortIdx);
            int gen  = results.GetInt32(GenerationIdx);

            entry.SiloAddress = SiloAddress.New(new IPEndPoint(IPAddress.Parse(results.GetString(AddressIdx)), port), gen);

            entry.HostName = results.GetString(HostNameIdx);
            entry.Status   = (SiloStatus)results.GetInt32(StatusIdx);
            if (!results.GetSqlInt32(ProxyPortIdx).IsNull)
            {
                entry.ProxyPort = results.GetInt32(ProxyPortIdx);
            }
            if (!results.GetSqlBoolean(PrimaryIdx).IsNull)
            {
                entry.IsPrimary = results.GetBoolean(PrimaryIdx);
            }

            entry.RoleName     = results.GetString(RoleNameIdx);
            entry.InstanceName = results.GetString(InstanceNameIdx);
            if (!results.GetSqlInt32(UpdateZoneIdx).IsNull)
            {
                entry.UpdateZone = results.GetInt32(UpdateZoneIdx);
            }
            if (!results.GetSqlInt32(FaultZoneIdx).IsNull)
            {
                entry.FaultZone = results.GetInt32(FaultZoneIdx);
            }

            if (!results.GetSqlDateTime(StartTimeIdx).IsNull)
            {
                entry.StartTime = results.GetDateTime(StartTimeIdx);
            }
            if (!results.GetSqlDateTime(IAmAliveTimeIdx).IsNull)
            {
                entry.IAmAliveTime = results.GetDateTime(IAmAliveTimeIdx);
            }
            eTag         = results.GetString(ETagIdx);
            tableVersion = (int)results.GetInt64(VersionIdx);
            versionETag  = results.GetString(VersionETagIdx);

            var suspectingSilosString = results.GetSqlString(SuspectingSilosIdx);
            var suspectingTimesString = results.GetSqlString(SuspectingTimesIdx);

            List <SiloAddress> suspectingSilos = new List <SiloAddress>();
            List <DateTime>    suspectingTimes = new List <DateTime>();

            if (!suspectingSilosString.IsNull && !string.IsNullOrEmpty(suspectingSilosString.Value))
            {
                string[] silos = suspectingSilosString.Value.Split('|');
                foreach (string silo in silos)
                {
                    suspectingSilos.Add(SiloAddress.FromParsableString(silo));
                }
            }

            if (!suspectingTimesString.IsNull && !string.IsNullOrEmpty(suspectingTimesString.Value))
            {
                string[] times = suspectingTimesString.Value.Split('|');
                foreach (string time in times)
                {
                    suspectingTimes.Add(TraceLogger.ParseDate(time));
                }
            }

            if (suspectingSilos.Count != suspectingTimes.Count)
            {
                throw new OrleansException(String.Format("SuspectingSilos.Length of {0} as read from SQL table is not eqaul to SuspectingTimes.Length of {1}", suspectingSilos.Count, suspectingTimes.Count));
            }

            for (int i = 0; i < suspectingSilos.Count; i++)
            {
                entry.AddSuspector(suspectingSilos[i], suspectingTimes[i]);
            }
            return(entry);
        }
Example #24
0
        private static Uri ReturnGatewayUri(MongoMembershipDocument record)
        {
            var siloAddress = SiloAddress.FromParsableString(record.SiloAddress);

            return(SiloAddress.New(new IPEndPoint(siloAddress.Endpoint.Address, record.ProxyPort), siloAddress.Generation).ToGatewayUri());
        }
 private static SiloAddress Silo(string value) => SiloAddress.FromParsableString(value);
Example #26
0
        private static MembershipEntry Parse(SiloInstanceTableEntry tableEntry)
        {
            var parse = new MembershipEntry
            {
                HostName = tableEntry.HostName,
                Status   = (SiloStatus)Enum.Parse(typeof(SiloStatus), tableEntry.Status)
            };

            if (!string.IsNullOrEmpty(tableEntry.ProxyPort))
            {
                parse.ProxyPort = int.Parse(tableEntry.ProxyPort);
            }

            parse.IsPrimary = false; // there are no primaries with in Azure table.

            int port = 0;

            if (!string.IsNullOrEmpty(tableEntry.Port))
            {
                int.TryParse(tableEntry.Port, out port);
            }

            int gen = 0;

            if (!string.IsNullOrEmpty(tableEntry.Generation))
            {
                int.TryParse(tableEntry.Generation, out gen);
            }

            parse.SiloAddress = SiloAddress.New(new IPEndPoint(IPAddress.Parse(tableEntry.Address), port), gen);

            parse.RoleName     = tableEntry.RoleName;
            parse.InstanceName = tableEntry.InstanceName;
            if (!string.IsNullOrEmpty(tableEntry.UpdateZone))
            {
                parse.UpdateZone = int.Parse(tableEntry.UpdateZone);
            }

            if (!string.IsNullOrEmpty(tableEntry.FaultZone))
            {
                parse.FaultZone = int.Parse(tableEntry.FaultZone);
            }

            parse.StartTime = !string.IsNullOrEmpty(tableEntry.StartTime) ?
                              TraceLogger.ParseDate(tableEntry.StartTime) : default(DateTime);

            parse.IAmAliveTime = !string.IsNullOrEmpty(tableEntry.IAmAliveTime) ?
                                 TraceLogger.ParseDate(tableEntry.IAmAliveTime) : default(DateTime);

            var suspectingSilos = new List <SiloAddress>();
            var suspectingTimes = new List <DateTime>();

            if (!string.IsNullOrEmpty(tableEntry.SuspectingSilos))
            {
                string[] silos = tableEntry.SuspectingSilos.Split('|');
                foreach (string silo in silos)
                {
                    suspectingSilos.Add(SiloAddress.FromParsableString(silo));
                }
            }

            if (!string.IsNullOrEmpty(tableEntry.SuspectingTimes))
            {
                string[] times = tableEntry.SuspectingTimes.Split('|');
                foreach (string time in times)
                {
                    suspectingTimes.Add(TraceLogger.ParseDate(time));
                }
            }

            if (suspectingSilos.Count != suspectingTimes.Count)
            {
                throw new OrleansException(String.Format("SuspectingSilos.Length of {0} as read from Azure table is not eqaul to SuspectingTimes.Length of {1}", suspectingSilos.Count, suspectingTimes.Count));
            }

            for (int i = 0; i < suspectingSilos.Count; i++)
            {
                parse.AddSuspector(suspectingSilos[i], suspectingTimes[i]);
            }

            return(parse);
        }
Example #27
0
        public Task <MembershipTableData> ReadAll()
        {
            return(UsingZookeeper(async zk =>
            {
                var childrenResult = await zk.getChildrenAsync("/"); //get all the child nodes (without the data)

                var childrenTasks =                                  //get the data from each child node
                                    childrenResult.Children.Select(child => GetRow(zk, SiloAddress.FromParsableString(child))).ToList();

                var childrenTaskResults = await Task.WhenAll(childrenTasks);

                var tableVersion = ConvertToTableVersion(childrenResult.Stat);//this is the current table version

                return new MembershipTableData(childrenTaskResults.ToList(), tableVersion);
            }, true));
        }
Example #28
0
        private static MembershipEntry Parse(SiloInstanceTableEntry tableEntry)
        {
            var parse = new MembershipEntry
            {
                HostName = tableEntry.HostName,
                Status   = (SiloStatus)Enum.Parse(typeof(SiloStatus), tableEntry.Status)
            };

            if (!string.IsNullOrEmpty(tableEntry.ProxyPort))
            {
                parse.ProxyPort = int.Parse(tableEntry.ProxyPort);
            }

            int port = 0;

            if (!string.IsNullOrEmpty(tableEntry.Port))
            {
                int.TryParse(tableEntry.Port, out port);
            }

            int gen = 0;

            if (!string.IsNullOrEmpty(tableEntry.Generation))
            {
                int.TryParse(tableEntry.Generation, out gen);
            }

            parse.SiloAddress = SiloAddress.New(new IPEndPoint(IPAddress.Parse(tableEntry.Address), port), gen);

            parse.RoleName = tableEntry.RoleName;
            if (!string.IsNullOrEmpty(tableEntry.SiloName))
            {
                parse.SiloName = tableEntry.SiloName;
            }
            else if (!string.IsNullOrEmpty(tableEntry.InstanceName))
            {
                // this is for backward compatability: in a mixed cluster of old and new version,
                // some entries will have the old InstanceName column.
                parse.SiloName = tableEntry.InstanceName;
            }
            if (!string.IsNullOrEmpty(tableEntry.UpdateZone))
            {
                parse.UpdateZone = int.Parse(tableEntry.UpdateZone);
            }

            if (!string.IsNullOrEmpty(tableEntry.FaultZone))
            {
                parse.FaultZone = int.Parse(tableEntry.FaultZone);
            }

            parse.StartTime = !string.IsNullOrEmpty(tableEntry.StartTime) ?
                              LogFormatter.ParseDate(tableEntry.StartTime) : default(DateTime);

            parse.IAmAliveTime = !string.IsNullOrEmpty(tableEntry.IAmAliveTime) ?
                                 LogFormatter.ParseDate(tableEntry.IAmAliveTime) : default(DateTime);

            var suspectingSilos = new List <SiloAddress>();
            var suspectingTimes = new List <DateTime>();

            if (!string.IsNullOrEmpty(tableEntry.SuspectingSilos))
            {
                string[] silos = tableEntry.SuspectingSilos.Split('|');
                foreach (string silo in silos)
                {
                    suspectingSilos.Add(SiloAddress.FromParsableString(silo));
                }
            }

            if (!string.IsNullOrEmpty(tableEntry.SuspectingTimes))
            {
                string[] times = tableEntry.SuspectingTimes.Split('|');
                foreach (string time in times)
                {
                    suspectingTimes.Add(LogFormatter.ParseDate(time));
                }
            }

            if (suspectingSilos.Count != suspectingTimes.Count)
            {
                throw new OrleansException(String.Format("SuspectingSilos.Length of {0} as read from Azure table is not eqaul to SuspectingTimes.Length of {1}", suspectingSilos.Count, suspectingTimes.Count));
            }

            for (int i = 0; i < suspectingSilos.Count; i++)
            {
                parse.AddSuspector(suspectingSilos[i], suspectingTimes[i]);
            }

            return(parse);
        }
Example #29
0
 private static SiloAddress ParseSilo(string s)
 {
     return(SiloAddress.FromParsableString(s));
 }
 public Tuple <SiloAddress, DateTime> ToTuple()
 {
     return(Tuple.Create(SiloAddress.FromParsableString(Address), LogFormatter.ParseDate(IAmAliveTime)));
 }