Java Code Examples for com.netflix.appinfo.InstanceInfo#getIPAddr()

The following examples show how to use com.netflix.appinfo.InstanceInfo#getIPAddr() . 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 vote down vote up
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: DefaultServerStore.java    From qconfig with MIT License 5 votes vote down vote up
@Override
public List<QConfigServer> getAvailableServers() {
    DiscoveryClient client = DiscoveryManager.getInstance().getDiscoveryClient();
    Application application = client.getApplication("eureka");
    if (application == null) {
        logger.warn("eureka application is null");
        return emptyServers();
    }

    List<InstanceInfo> instances = application.getInstances();
    if (instances == null || instances.isEmpty()) {
        logger.warn("eureka instance is empty");
        return emptyServers();
    }

    List<QConfigServer> servers = Lists.newArrayListWithCapacity(instances.size());
    for (InstanceInfo instance : instances) {
        logger.debug("eureka qconfig server instance {}:{}", instance.getIPAddr(), instance.getPort());
        try {
            String ip = instance.getIPAddr();
            if ("127.0.0.1".equals(ip)) {
                logger.warn("illegal qconfig server ip 127.0.0.1");
                Monitor.serverLocalIpError.inc();
                continue;
            }
            servers.add(new QConfigServer(ip, instance.getPort(), getRoom(ip)));
        } catch (Exception e) {
            // get room info error
            continue;
        }
    }

    if (servers.isEmpty()) {
        logger.warn("no legal eureka servers");
        return emptyServers();
    }
    return servers;
}
 
Example 3
Source File: EurekaRegisterHandler.java    From TarsJava with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private EndpointF convert2Endpoint(InstanceInfo instanceInfo) {
    EndpointF endpoint = null;
    if (instanceInfo == null) {
        return endpoint;
    }
    int istcp = instanceInfo.getMetadata().get("isTcp") == null ? 1 : Integer.parseInt(instanceInfo.getMetadata().get("isTcp"));
    int timeOut = instanceInfo.getMetadata().get("timeOut") == null ? 6000 : Integer.parseInt(instanceInfo.getMetadata().get("timeOut"));
    int grid = instanceInfo.getMetadata().get("grid") == null ? 0 : Integer.parseInt(instanceInfo.getMetadata().get("grid"));
    int qos = instanceInfo.getMetadata().get("qos") == null ? 0 : Integer.parseInt(instanceInfo.getMetadata().get("qos"));
    int weight = instanceInfo.getMetadata().get("weight") == null ? 0 : Integer.parseInt(instanceInfo.getMetadata().get("weight"));
    int weightType = instanceInfo.getMetadata().get("weightType") == null ? 0 : Integer.parseInt(instanceInfo.getMetadata().get("weightType"));
    endpoint = new EndpointF(instanceInfo.getIPAddr(), instanceInfo.getPort(), timeOut, istcp, grid, 0, 0, null, qos, 0, weight, weightType);
    return endpoint;
}
 
Example 4
Source File: ServiceInstance.java    From oneplatform with Apache License 2.0 5 votes vote down vote up
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 5
Source File: InstanceInfoMapper.java    From eureka-consul-adapter with MIT License 5 votes vote down vote up
private String getAddress(InstanceInfo instanceInfo) {
    if (preferHostName) {
        return instanceInfo.getHostName();
    } else {
        return instanceInfo.getIPAddr();
    }
}
 
Example 6
Source File: TxServiceImpl.java    From tx-lcn with Apache License 2.0 5 votes vote down vote up
private List<String> getServices(){
    List<String> urls = new ArrayList<>();
    List<InstanceInfo> instanceInfos =discoveryService.getConfigServiceInstances();
    for (InstanceInfo instanceInfo : instanceInfos) {
        String url = instanceInfo.getHomePageUrl();
        String address = instanceInfo.getIPAddr();
        if (isIp(address)) {
            urls.add(url);
        }else{
            url = url.replace(address,"127.0.0.1");
            urls.add(url);
        }
    }
    return urls;
}
 
Example 7
Source File: ServiceGovenImpl.java    From hippo with Apache License 2.0 5 votes vote down vote up
@Override
public String getServiceAddress(String arg0) {
    try {
        InstanceInfo instanceInfo = getDiscoverClient().getNextServerFromEureka(arg0, false);
        if (instanceInfo != null) {
            return instanceInfo.getIPAddr() + ":" + instanceInfo.getPort();
        }
    } catch (Exception e) {
        LOGGER.error("can not get an instance of service from euraka server " + arg0, e);
        discoveryShutdown();
    }
    return "";
}
 
Example 8
Source File: DiscoveryEnabledServer.java    From ribbon with Apache License 2.0 5 votes vote down vote up
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 9
Source File: DIEVCacheKetamaNodeLocatorConfiguration.java    From EVCache with Apache License 2.0 5 votes vote down vote up
/**
 * 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 10
Source File: EurekaClientWrapper.java    From summerframework with Apache License 2.0 4 votes vote down vote up
private List<InstanceInfo> filterInstance(List<InstanceInfo> instanceList) {
    List<InstanceInfo> filteredInsantce = Lists.newArrayList();
    List<InstanceInfo> toDeleteInstance = Lists.newArrayList();
    for (InstanceInfo insaceInfo : instanceList) {
        final String serviceId = insaceInfo.getVIPAddress();
        final String instanceIpAddr = insaceInfo.getIPAddr();
        final Map<String, String> instanceMeta = insaceInfo.getMetadata();
        String reference = environment.getProperty(Constants.CONSUMER_INSTANCE_REFERENCE);
        if (this.reference != null && reference != null) {
            if (!this.reference.equals(reference)) {
                this.initReferenceCache();
                this.reference = reference;
            }
        }
        Pair<String, String> groupVersion = this.getGroupVersion(serviceId);
        if (groupVersion != null) {
            String group = instanceMeta.get(Constants.EUREKA_METADATA_GROUP);
            String version = instanceMeta.get(Constants.EUREKA_METADATA_VERSION);
            if (group != null && version != null) {
                boolean groupEqual = StringUtils.equals(groupVersion.getLeft(), group);
                boolean versionEqual = StringUtils.equals(groupVersion.getRight(), version);
                if (groupEqual && versionEqual) {
                    filteredInsantce.add(insaceInfo);
                }
            } else {
                filteredInsantce.add(insaceInfo);
            }
        } else {
            filteredInsantce.add(insaceInfo);
        }
        String ipAddress = eurekaRuleCache.get(serviceId);
        if (StringUtils.isNotEmpty(ipAddress)) {
            List<String> ipAddressList = Arrays.asList(StringUtils.split(ipAddress, ","));
            if (ipAddressList.contains(instanceIpAddr)) {
                toDeleteInstance.add(insaceInfo);
            }
        }
    }
    if (toDeleteInstance.size() != 0) {
        @SuppressWarnings("unchecked")
        Collection<InstanceInfo> remainList = CollectionUtils.removeAll(filteredInsantce, toDeleteInstance);
        return Lists.newArrayList(remainList);
    } else {
        return filteredInsantce;
    }
}
 
Example 11
Source File: EurekaRegistry.java    From oneplatform with Apache License 2.0 4 votes vote down vote up
public String getRealServerHost(String serviceId){
	InstanceInfo serverInfo = eurekaClient.getNextServerFromEureka(serviceId, false);
	String realServerName = serverInfo.getIPAddr() + ":" + serverInfo.getPort();
	return realServerName;
}