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); }
protected internal virtual void ConfigureInstanceIfNeeded(IEurekaInstanceConfig instConfig) { if (string.IsNullOrEmpty(instConfig.AppName)) { instConfig.AppName = "unknown"; } if (string.IsNullOrEmpty(instConfig.InstanceId)) { var hostName = instConfig.GetHostName(false); var appName = instConfig.AppName; var index = (instConfig.NonSecurePort == -1) ? EurekaInstanceOptions.Default_NonSecurePort.ToString() : instConfig.NonSecurePort.ToString(); instConfig.InstanceId = hostName + ":" + appName + ":" + index; } if (string.IsNullOrEmpty(instConfig.VirtualHostName)) { instConfig.VirtualHostName = instConfig.AppName; } if (string.IsNullOrEmpty(instConfig.SecureVirtualHostName)) { instConfig.SecureVirtualHostName = instConfig.AppName; } }