示例#1
0
        public void FromJavaMillis()
        {
            long     millis = 1457973741708;
            DateTime dt     = DateTimeConversions.FromJavaMillis(millis);

            Assert.Equal(3, dt.Month);
            Assert.Equal(14, dt.Day);
            Assert.Equal(2016, dt.Year);
            Assert.Equal(16, dt.Hour);
            Assert.Equal(42, dt.Minute);
            Assert.Equal(21, dt.Second);
            Assert.Equal(708, dt.Millisecond);
        }
示例#2
0
        private static void OnTimedEvent(Object source, ElapsedEventArgs e)
        {
            //Console.WriteLine("Eviction Service cleans at {0:HH:mm:ss.fff}", e.SignalTime);

            // evict outdated peers
            var peersEvicted = _memoryDiscoveryPeerRepository.EvictPeers(Program.InstanceConfig.PeerEvictionInSecs);

            //Console.WriteLine("Peers evicted {0}", peersEvicted);

            // evict outdated instances for all tenants
            lock (ServicesRuntime.AllApplications.Applications)
            {
                foreach (var app in ServicesRuntime.AllApplications.Applications)
                {
                    List <Instance> instancesToRemove = new List <Instance>();
                    foreach (var instance in app.Instances)
                    {
                        var instanceLastUpdate = DateTimeConversions.FromJavaMillis(instance.LastUpdatedTimestamp);

                        // if no heartbeat first take down instance
                        if (instanceLastUpdate.AddSeconds(Program.InstanceConfig.EvictionInSecs) < DateTime.UtcNow)
                        {
                            ServicesRuntime.AllApplications.VersionsDelta += 1;
                            instance.Status = "DOWN";
                        }

                        // if no heartbeat after the DOWN Duration then avict the instance
                        if (instanceLastUpdate.AddSeconds(Program.InstanceConfig.EvictionInSecs + Program.InstanceConfig.DurationInSecs) < DateTime.UtcNow)
                        {
                            instancesToRemove.Add(instance);
                        }
                    }

                    if (instancesToRemove.Count > 0)
                    {
                        foreach (var inst in instancesToRemove)
                        {
                            app.Instances.Remove(inst);
                        }

                        // increase version after eviction
                        ServicesRuntime.AllApplications.VersionsDelta += 1;
                    }

                    //Console.WriteLine("For app '{0}' instances evicted {1}", app.Name, instancesToRemove.Count);
                }
            }
        }
示例#3
0
        internal static LeaseInfo FromJson(JsonLeaseInfo jinfo)
        {
            LeaseInfo info = new LeaseInfo();

            if (jinfo != null)
            {
                info.RenewalIntervalInSecs      = jinfo.RenewalIntervalInSecs;
                info.DurationInSecs             = jinfo.DurationInSecs;
                info.RegistrationTimestamp      = DateTimeConversions.FromJavaMillis(jinfo.RegistrationTimestamp).Ticks;
                info.LastRenewalTimestamp       = DateTimeConversions.FromJavaMillis(jinfo.LastRenewalTimestamp).Ticks;
                info.LastRenewalTimestampLegacy = DateTimeConversions.FromJavaMillis(jinfo.LastRenewalTimestampLegacy).Ticks;
                info.EvictionTimestamp          = DateTimeConversions.FromJavaMillis(jinfo.EvictionTimestamp).Ticks;
                info.ServiceUpTimestamp         = DateTimeConversions.FromJavaMillis(jinfo.ServiceUpTimestamp).Ticks;
            }
            return(info);
        }
示例#4
0
        internal static InstanceInfo FromJsonInstance(JsonInstanceInfo json)
        {
            var info = new InstanceInfo();

            if (json != null)
            {
                info._sid                          = json.Sid ?? "na";
                info.AppName                       = json.AppName;
                info.AppGroupName                  = json.AppGroupName;
                info.IpAddr                        = json.IpAddr;
                info.Port                          = (json.Port == null) ? 0 : json.Port.Port;
                info.IsUnsecurePortEnabled         = json.Port != null && json.Port.Enabled;
                info.SecurePort                    = (json.SecurePort == null) ? 0 : json.SecurePort.Port;
                info.IsSecurePortEnabled           = json.SecurePort != null && json.SecurePort.Enabled;
                info.HomePageUrl                   = json.HomePageUrl;
                info.StatusPageUrl                 = json.StatusPageUrl;
                info.HealthCheckUrl                = json.HealthCheckUrl;
                info.SecureHealthCheckUrl          = json.SecureHealthCheckUrl;
                info.VipAddress                    = json.VipAddress;
                info.SecureVipAddress              = json.SecureVipAddress;
                info.CountryId                     = json.CountryId;
                info.DataCenterInfo                = (json.DataCenterInfo == null) ? null : AppInfo.DataCenterInfo.FromJson(json.DataCenterInfo);
                info.HostName                      = json.HostName;
                info.Status                        = json.Status;
                info.OverriddenStatus              = json.OverriddenStatus;
                info.LeaseInfo                     = LeaseInfo.FromJson(json.LeaseInfo);
                info.IsCoordinatingDiscoveryServer = json.IsCoordinatingDiscoveryServer;
                info.LastUpdatedTimestamp          = DateTimeConversions.FromJavaMillis(json.LastUpdatedTimestamp).Ticks;
                info.LastDirtyTimestamp            = DateTimeConversions.FromJavaMillis(json.LastDirtyTimestamp).Ticks;
                info.Actiontype                    = json.Actiontype;
                info.AsgName                       = json.AsgName;
                info._metaData                     = GetMetaDataFromJson(json.Metadata);
                info.InstanceId                    = GetInstanceIdFromJson(json, info._metaData);
            }

            return(info);
        }
示例#5
0
        internal static InstanceInfo FromJsonInstance(JsonInstanceInfo json)
        {
            InstanceInfo info = new InstanceInfo();

            if (json != null)
            {
                info._sid                           = (json.Sid == null) ? "na" : json.Sid;
                info._appName                       = json.AppName;
                info._appGroupName                  = json.AppGroupName;
                info._ipAddr                        = json.IpAddr;
                info._port                          = (json.Port == null) ? 0 : json.Port.Port;
                info._isUnsecurePortEnabled         = (json.Port == null) ? false : Boolean.Parse(json.Port.Enabled);
                info._securePort                    = (json.SecurePort == null) ? 0 : json.SecurePort.Port;
                info._isSecurePortEnabled           = (json.Port == null) ? false : Boolean.Parse(json.SecurePort.Enabled);
                info._homePageUrl                   = json.HomePageUrl;
                info._statusPageUrl                 = json.StatusPageUrl;
                info._healthCheckUrl                = json.HealthCheckUrl;
                info._secureHealthCheckUrl          = json.SecureHealthCheckUrl;
                info._vipAddress                    = json.VipAddress;
                info._secureVipAddress              = json.SecureVipAddress;
                info._countryId                     = json.CountryId;
                info._dataCenterInfo                = (json.DataCenterInfo == null) ? null : AppInfo.DataCenterInfo.FromJson(json.DataCenterInfo);
                info._hostName                      = json.HostName;
                info._status                        = json.Status;
                info._overRiddenStatus              = json.OverriddenStatus;
                info._leaseInfo                     = LeaseInfo.FromJson(json.LeaseInfo);
                info._isCoordinatingDiscoveryServer = json.IsCoordinatingDiscoveryServer;
                info._lastUpdatedTimestamp          = DateTimeConversions.FromJavaMillis(json.LastUpdatedTimestamp).Ticks;
                info._lastDirtyTimestamp            = DateTimeConversions.FromJavaMillis(json.LastDirtyTimestamp).Ticks;
                info._actionType                    = json.Actiontype;
                info._asgName                       = json.AsgName;
                info._metaData                      = GetMetaDataFromJson(json.Metadata);
                info._instanceId                    = GetInstanceIdFromJson(json, info._metaData);
            }
            return(info);
        }