internal 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(false);
            }

            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);
        }
Exemple #2
0
        internal static LeaseInfo FromConfig(IEurekaInstanceConfig config)
        {
            var info = new LeaseInfo()
            {
                RenewalIntervalInSecs = config.LeaseRenewalIntervalInSeconds,
                DurationInSecs        = config.LeaseExpirationDurationInSeconds
            };

            return(info);
        }
Exemple #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);
        }
Exemple #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);
        }
Exemple #5
0
        internal JsonInstanceInfo ToJsonInstance()
        {
            var 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);
        }
Exemple #6
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);
        }