Пример #1
0
        public static InstanceInfo FromInstanceConfig(IEurekaInstanceConfig instanceConfig)
        {
            InstanceInfo info = new InstanceInfo
            {
                LeaseInfo  = LeaseInfo.FromConfig(instanceConfig),
                InstanceId = instanceConfig.InstanceId
            };

            if (string.IsNullOrEmpty(info.InstanceId))
            {
                info.InstanceId = instanceConfig.GetHostName(true) + ":" + instanceConfig.AppName + ":" + instanceConfig.NonSecurePort;
            }

            string defaultAddress = instanceConfig.GetHostName(false);

            if (instanceConfig.PreferIpAddress || string.IsNullOrEmpty(defaultAddress))
            {
                defaultAddress = instanceConfig.IpAddress;
            }

            info.AppName               = instanceConfig.AppName.ToUpperInvariant();
            info.AppGroupName          = instanceConfig.AppGroupName?.ToUpperInvariant();
            info.DataCenterInfo        = instanceConfig.DataCenterInfo;
            info.IpAddr                = instanceConfig.IpAddress;
            info.HostName              = defaultAddress;
            info.Port                  = (instanceConfig.NonSecurePort == -1) ? EurekaInstanceConfig.Default_NonSecurePort : instanceConfig.NonSecurePort;
            info.IsUnsecurePortEnabled = instanceConfig.IsNonSecurePortEnabled;
            info.SecurePort            = (instanceConfig.SecurePort == -1) ? EurekaInstanceConfig.Default_SecurePort : instanceConfig.SecurePort;
            info.IsSecurePortEnabled   = instanceConfig.SecurePortEnabled;
            info.VipAddress            = instanceConfig.VirtualHostName;
            info.SecureVipAddress      = instanceConfig.SecureVirtualHostName;
            info.HomePageUrl           = MakeUrl(info, instanceConfig.HomePageUrlPath, instanceConfig.HomePageUrl);
            info.StatusPageUrl         = MakeUrl(info, instanceConfig.StatusPageUrlPath, instanceConfig.StatusPageUrl);
            info.AsgName               = instanceConfig.ASGName;
            info.HealthCheckUrl        = MakeUrl(info, instanceConfig.HealthCheckUrlPath, instanceConfig.HealthCheckUrl, instanceConfig.SecureHealthCheckUrl);

            if (!instanceConfig.IsInstanceEnabledOnInit)
            {
                info._status = InstanceStatus.STARTING;
            }

            if (!string.IsNullOrEmpty(info.InstanceId))
            {
                InstanceInfo me = ApplicationInfoManager.Instance.InstanceInfo;
                if (me != null)
                {
                    if (info.InstanceId.Equals(me.InstanceId))
                    {
                        info.IsCoordinatingDiscoveryServer = true;
                    }
                }
            }

            if (instanceConfig.MetadataMap != null && instanceConfig.MetadataMap.Count > 0)
            {
                info._metaData = new Dictionary <string, string>(instanceConfig.MetadataMap);
            }

            return(info);
        }
Пример #2
0
        public static LeaseInfo FromConfig(IEurekaInstanceConfig config)
        {
            LeaseInfo info = new LeaseInfo()
            {
                RenewalIntervalInSecs = config.LeaseRenewalIntervalInSeconds,
                DurationInSecs        = config.LeaseExpirationDurationInSeconds
            };

            return(info);
        }
Пример #3
0
        public 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
        public static InstanceInfo FromJsonInstance(JsonInstanceInfo json)
        {
            InstanceInfo 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) ? false : json.Port.Enabled;
                info.SecurePort                    = (json.SecurePort == null) ? 0 : json.SecurePort.Port;
                info.IsSecurePortEnabled           = (json.SecurePort == null) ? false : 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
        public JsonInstanceInfo ToJsonInstance()
        {
            JsonInstanceInfo jinfo = new JsonInstanceInfo
            {
                InstanceId                    = InstanceId,
                Sid                           = Sid ?? "na",
                AppName                       = AppName,
                AppGroupName                  = AppGroupName,
                IpAddr                        = IpAddr,
                Port                          = new JsonInstanceInfo.JsonPortWrapper(IsUnsecurePortEnabled, Port),
                SecurePort                    = new JsonInstanceInfo.JsonPortWrapper(IsSecurePortEnabled, SecurePort),
                HomePageUrl                   = HomePageUrl,
                StatusPageUrl                 = StatusPageUrl,
                HealthCheckUrl                = HealthCheckUrl,
                SecureHealthCheckUrl          = SecureHealthCheckUrl,
                VipAddress                    = VipAddress,
                SecureVipAddress              = SecureVipAddress,
                CountryId                     = CountryId,
                DataCenterInfo                = (DataCenterInfo == null) ? null : ((DataCenterInfo)DataCenterInfo).ToJson(),
                HostName                      = HostName,
                Status                        = Status,
                OverriddenStatus              = OverriddenStatus,
                LeaseInfo                     = LeaseInfo?.ToJson(),
                IsCoordinatingDiscoveryServer = IsCoordinatingDiscoveryServer,
                LastUpdatedTimestamp          = DateTimeConversions.ToJavaMillis(new DateTime(LastUpdatedTimestamp, DateTimeKind.Utc)),
                LastDirtyTimestamp            = DateTimeConversions.ToJavaMillis(new DateTime(LastDirtyTimestamp, DateTimeKind.Utc)),
                Actiontype                    = Actiontype,
                AsgName                       = AsgName,
                Metadata                      = (Metadata.Count == 0) ? new Dictionary <string, string>()
                {
                    { "@class", "java.util.Collections$EmptyMap" }
                } : Metadata
            };

            return(jinfo);
        }