Java Code Examples for org.springframework.cloud.commons.util.InetUtils#HostInfo

The following examples show how to use org.springframework.cloud.commons.util.InetUtils#HostInfo . 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: HeartBeatService.java    From influx-proxy with Apache License 2.0 6 votes vote down vote up
@Scheduled(fixedRate = 5_000)
public void heartBeat() {
    if(proxyConfiguration.isEnable()||StringUtils.isEmpty(opsPath)){
        return;
    }
    try{
        InetUtils.HostInfo hostInfo = inetUtils.findFirstNonLoopbackHostInfo();
        restTemplate.getForObject(opsPath + "/ping?ip={1}&port={2}&managementPort={3}&hostname={4}",
                String.class,
                hostInfo.getIpAddress(),
                port,
                managementPort,
                hostInfo.getHostname());
    }catch (Throwable ignore){
        log.warn("Failed to ping {}",opsPath);
    }
}
 
Example 2
Source File: DubboServiceMetadataRepository.java    From spring-cloud-alibaba with Apache License 2.0 5 votes vote down vote up
public void exportURL(URL url) {
	URL actualURL = url;
	InetUtils.HostInfo hostInfo = inetUtils.findFirstNonLoopbackHostInfo();
	String ipAddress = hostInfo.getIpAddress();
	// To use InetUtils to set IP if they are different
	// issue :
	// https://github.com/spring-cloud-incubator/spring-cloud-alibaba/issues/589
	if (!Objects.equals(url.getHost(), ipAddress)) {
		actualURL = url.setHost(ipAddress);
	}
	this.allExportedURLs.add(actualURL.getServiceKey(), actualURL);
}
 
Example 3
Source File: HostInfoEnvironmentPostProcessor.java    From spring-cloud-commons with Apache License 2.0 5 votes vote down vote up
@Override
public void postProcessEnvironment(ConfigurableEnvironment environment,
		SpringApplication application) {
	InetUtils.HostInfo hostInfo = getFirstNonLoopbackHostInfo(environment);
	LinkedHashMap<String, Object> map = new LinkedHashMap<>();
	map.put("spring.cloud.client.hostname", hostInfo.getHostname());
	map.put("spring.cloud.client.ip-address", hostInfo.getIpAddress());
	MapPropertySource propertySource = new MapPropertySource(
			"springCloudClientHostInfo", map);
	environment.getPropertySources().addLast(propertySource);
}
 
Example 4
Source File: EurekaInstanceConfigBeanTests.java    From spring-cloud-netflix with Apache License 2.0 5 votes vote down vote up
@Before
public void init() throws Exception {
	try (InetUtils utils = new InetUtils(new InetUtilsProperties())) {
		InetUtils.HostInfo hostInfo = utils.findFirstNonLoopbackHostInfo();
		this.hostName = hostInfo.getHostname();
		this.ipAddress = hostInfo.getIpAddress();
	}
}
 
Example 5
Source File: SanitizingEurekaInstanceConfigBeanTest.java    From spring-cloud-services-connector with Apache License 2.0 3 votes vote down vote up
private InetUtils getInetUtils() {

			InetUtils.HostInfo hostInfo = new InetUtils(new InetUtilsProperties()).findFirstNonLoopbackHostInfo();

			InetUtils inetUtils = mock(InetUtils.class);
			when(inetUtils.findFirstNonLoopbackHostInfo()).thenReturn(hostInfo);

			return inetUtils;
		}
 
Example 6
Source File: SanitizingEurekaInstanceConfigBeanTest.java    From spring-cloud-services-starters with Apache License 2.0 3 votes vote down vote up
private InetUtils getInetUtils() {

			InetUtils.HostInfo hostInfo = new InetUtils(new InetUtilsProperties()).findFirstNonLoopbackHostInfo();

			InetUtils inetUtils = mock(InetUtils.class);
			when(inetUtils.findFirstNonLoopbackHostInfo()).thenReturn(hostInfo);

			return inetUtils;
		}