Java Code Examples for com.netflix.appinfo.InstanceInfo#getHostName()
The following examples show how to use
com.netflix.appinfo.InstanceInfo#getHostName() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ArmeriaEurekaClientTest.java From armeria with Apache License 2.0 | 6 votes |
private static com.linecorp.armeria.internal.common.eureka.InstanceInfo convertInstanceInfo( InstanceInfo info) { final PortWrapper port = new PortWrapper(info.isPortEnabled(PortType.UNSECURE), info.getPort()); final PortWrapper securePort = new PortWrapper(info.isPortEnabled(PortType.SECURE), info.getSecurePort()); return new com.linecorp.armeria.internal.common.eureka.InstanceInfo( info.getInstanceId(), info.getAppName(), info.getAppGroupName(), info.getHostName(), info.getIPAddr(), info.getVIPAddress(), info.getSecureVipAddress(), port, securePort, com.linecorp.armeria.internal.common.eureka.InstanceInfo.InstanceStatus .toEnum(info.getStatus().name()), info.getHomePageUrl(), info.getStatusPageUrl(), info.getHealthCheckUrl(), info.getSecureHealthCheckUrl(), convertDataCenterInfo(info.getDataCenterInfo()), convertLeaseInfo(info.getLeaseInfo()), info.getMetadata()); }
Example 2
Source File: EurekaUtils.java From api-layer with Eclipse Public License 2.0 | 5 votes |
/** * Construct base URL for specific InstanceInfo * @param instanceInfo Instance of service, for which we want to get an URL * @return URL to the instance */ public static final String getUrl(InstanceInfo instanceInfo) { if (instanceInfo.getSecurePort() == 0) { return "http://" + instanceInfo.getHostName() + ":" + instanceInfo.getPort(); } else { return "https://" + instanceInfo.getHostName() + ":" + instanceInfo.getSecurePort(); } }
Example 3
Source File: ServiceInstance.java From oneplatform with Apache License 2.0 | 5 votes |
public ServiceInstance(InstanceInfo instanceInfo) { this.appName = instanceInfo.getAppName(); this.instanceId = instanceInfo.getInstanceId(); this.hostName = instanceInfo.getHostName(); this.ipAddr = instanceInfo.getIPAddr(); this.vipAddress = instanceInfo.getVIPAddress(); this.status = instanceInfo.getStatus().name(); this.port = instanceInfo.getPort(); this.healthCheckUrl = instanceInfo.getHealthCheckUrl(); this.lastRenewalTime = new Date(instanceInfo.getLastDirtyTimestamp()); this.nodeId = instanceInfo.getMetadata().get("nodeId"); }
Example 4
Source File: InstanceInfoMapper.java From eureka-consul-adapter with MIT License | 5 votes |
private String getAddress(InstanceInfo instanceInfo) { if (preferHostName) { return instanceInfo.getHostName(); } else { return instanceInfo.getIPAddr(); } }
Example 5
Source File: CloudJacksonJson.java From didi-eureka-server with MIT License | 5 votes |
static InstanceInfo updateIfNeeded(final InstanceInfo info) { if (info.getInstanceId() == null && info.getMetadata() != null) { String instanceId = info.getMetadata().get("instanceId"); if (StringUtils.hasText(instanceId)) { // backwards compatibility for Angel if (StringUtils.hasText(info.getHostName()) && !instanceId.startsWith(info.getHostName())) { instanceId = info.getHostName()+":"+instanceId; } return new InstanceInfo.Builder(info).setInstanceId(instanceId).build(); } } return info; }
Example 6
Source File: CloudJacksonJson.java From spring-cloud-netflix with Apache License 2.0 | 5 votes |
static InstanceInfo updateIfNeeded(final InstanceInfo info) { if (info.getInstanceId() == null && info.getMetadata() != null) { String instanceId = info.getMetadata().get("instanceId"); if (StringUtils.hasText(instanceId)) { // backwards compatibility for Angel if (StringUtils.hasText(info.getHostName()) && !instanceId.startsWith(info.getHostName())) { instanceId = info.getHostName() + ":" + instanceId; } return new InstanceInfo.Builder(info).setInstanceId(instanceId).build(); } } return info; }
Example 7
Source File: DiscoveryEnabledServer.java From ribbon with Apache License 2.0 | 5 votes |
public DiscoveryEnabledServer(final InstanceInfo instanceInfo, boolean useSecurePort, boolean useIpAddr) { super(useIpAddr ? instanceInfo.getIPAddr() : instanceInfo.getHostName(), instanceInfo.getPort()); if(useSecurePort && instanceInfo.isPortEnabled(PortType.SECURE)) super.setPort(instanceInfo.getSecurePort()); this.instanceInfo = instanceInfo; this.serviceInfo = new MetaInfo() { @Override public String getAppName() { return instanceInfo.getAppName(); } @Override public String getServerGroup() { return instanceInfo.getASGName(); } @Override public String getServiceIdForDiscovery() { return instanceInfo.getVIPAddress(); } @Override public String getInstanceId() { return instanceInfo.getId(); } }; }
Example 8
Source File: DIEVCacheKetamaNodeLocatorConfiguration.java From EVCache with Apache License 2.0 | 5 votes |
/** * Returns the socket address of a given MemcachedNode. * * @param node - The MemcachedNode which we're interested in * @return The socket address of the given node format is of the following * format "publicHostname/privateIp:port" (ex - ec2-174-129-159-31.compute-1.amazonaws.com/10.125.47.114:11211) */ @Override public String getKeyForNode(MemcachedNode node, int repetition) { String result = socketAddresses.get(node); if(result == null) { final SocketAddress socketAddress = node.getSocketAddress(); if(socketAddress instanceof InetSocketAddress) { final InetSocketAddress isa = (InetSocketAddress)socketAddress; if(eurekaClient != null ) { final Application app = eurekaClient.getApplication(client.getAppName()); if(app != null) { final List<InstanceInfo> instances = app.getInstances(); for(InstanceInfo info : instances) { final String hostName = info.getHostName(); if(hostName.equalsIgnoreCase(isa.getHostName())) { final String ip = info.getIPAddr(); result = hostName + '/' + ip + ":11211"; break; } } } else { result = ((InetSocketAddress)socketAddress).getHostName() + '/' + ((InetSocketAddress)socketAddress).getAddress().getHostAddress() + ":11211"; } } else { result = isa.getHostName() + '/' + isa.getAddress().getHostAddress() + ":11211"; } } else { result=String.valueOf(socketAddress); if (result.startsWith("/")) { result = result.substring(1); } } socketAddresses.put(node, result); } if(log.isDebugEnabled()) log.debug("Returning : " + (result + "-" + repetition)); return result + "-" + repetition; }
Example 9
Source File: RequestAttempt.java From zuul with Apache License 2.0 | 5 votes |
public RequestAttempt(int attemptNumber, InstanceInfo server, String targetVip, String chosenWarmupLB, int status, String error, String exceptionType, int readTimeout, int connectTimeout, int maxRetries) { if (attemptNumber < 1) { throw new IllegalArgumentException("Attempt number must be greater than 0! - " + attemptNumber); } this.attempt = attemptNumber; this.vip = targetVip; if (server != null) { this.app = server.getAppName().toLowerCase(); this.asg = server.getASGName(); this.instanceId = server.getInstanceId(); this.host = server.getHostName(); this.port = server.getPort(); // If targetVip is null, then try to use the actual server's vip. if (targetVip == null) { this.vip = server.getVIPAddress(); } if (server.getDataCenterInfo() instanceof AmazonInfo) { this.availabilityZone = ((AmazonInfo) server.getDataCenterInfo()).getMetadata().get("availability-zone"); // HACK - get region by just removing the last char from zone. String az = getAvailabilityZone(); if (az != null && az.length() > 0) { this.region = az.substring(0, az.length() - 1); } } } this.status = status; this.error = error; this.exceptionType = exceptionType; this.readTimeout = readTimeout; this.connectTimeout = connectTimeout; this.maxRetries = maxRetries; }
Example 10
Source File: RequestAttempt.java From zuul with Apache License 2.0 | 4 votes |
public RequestAttempt(final Server server, final IClientConfig clientConfig, int attemptNumber, int readTimeout) { this.status = -1; this.attempt = attemptNumber; this.readTimeout = readTimeout; if (server != null) { this.host = server.getHost(); this.port = server.getPort(); this.availabilityZone = server.getZone(); if (server instanceof DiscoveryEnabledServer) { InstanceInfo instanceInfo = ((DiscoveryEnabledServer) server).getInstanceInfo(); this.app = instanceInfo.getAppName().toLowerCase(); this.asg = instanceInfo.getASGName(); this.instanceId = instanceInfo.getInstanceId(); this.host = instanceInfo.getHostName(); this.port = instanceInfo.getPort(); if (server.getPort() == instanceInfo.getSecurePort()) { this.vip = instanceInfo.getSecureVipAddress(); } else { this.vip = instanceInfo.getVIPAddress(); } if (instanceInfo.getDataCenterInfo() instanceof AmazonInfo) { this.availabilityZone = ((AmazonInfo) instanceInfo.getDataCenterInfo()).getMetadata().get("availability-zone"); } } else { final Server.MetaInfo metaInfo = server.getMetaInfo(); if (metaInfo != null) { this.asg = metaInfo.getServerGroup(); this.vip = metaInfo.getServiceIdForDiscovery(); this.instanceId = metaInfo.getInstanceId(); } } // HACK - get region by just removing the last char from zone. if (availabilityZone != null && availabilityZone.length() > 0) { region = availabilityZone.substring(0, availabilityZone.length() - 1); } } if (clientConfig != null) { this.connectTimeout = clientConfig.get(IClientConfigKey.Keys.ConnectTimeout); } }