org.springframework.cloud.commons.util.InetUtilsProperties Java Examples

The following examples show how to use org.springframework.cloud.commons.util.InetUtilsProperties. 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: EurekaInstanceAutoConfiguration.java    From spring-cloud-services-connector with Apache License 2.0 6 votes vote down vote up
private SanitizingEurekaInstanceConfigBean getDefaults() {
	InetUtilsProperties inetUtilsProperties = new InetUtilsProperties();
	inetUtilsProperties.setDefaultHostname(hostname);
	inetUtilsProperties.setDefaultIpAddress(ip);

	SanitizingEurekaInstanceConfigBean eurekaInstanceConfigBean = new SanitizingEurekaInstanceConfigBean(new InetUtils(inetUtilsProperties));
	eurekaInstanceConfigBean.setHostname(hostname);
	eurekaInstanceConfigBean.setIpAddress(ip);
	Map<String, String> metadataMap = eurekaInstanceConfigBean.getMetadataMap();
	metadataMap.put(SurgicalRoutingRequestTransformer.CF_APP_GUID, cfAppGuid);
	metadataMap.put(SurgicalRoutingRequestTransformer.CF_INSTANCE_INDEX, cfInstanceIndex);
	metadataMap.put(INSTANCE_ID, instanceId);
	metadataMap.put(ZONE, zoneFromUri(zoneUri));

	return eurekaInstanceConfigBean;
}
 
Example #2
Source File: EurekaInstanceAutoConfiguration.java    From spring-cloud-services-starters with Apache License 2.0 6 votes vote down vote up
private SanitizingEurekaInstanceConfigBean getDefaults() {
	InetUtilsProperties inetUtilsProperties = new InetUtilsProperties();
	inetUtilsProperties.setDefaultHostname(hostname);
	inetUtilsProperties.setDefaultIpAddress(ip);

	SanitizingEurekaInstanceConfigBean eurekaInstanceConfigBean = new SanitizingEurekaInstanceConfigBean(
			new InetUtils(inetUtilsProperties));
	eurekaInstanceConfigBean.setHostname(hostname);
	eurekaInstanceConfigBean.setIpAddress(ip);
	Map<String, String> metadataMap = eurekaInstanceConfigBean.getMetadataMap();
	metadataMap.put(SurgicalRoutingRequestTransformer.CF_APP_GUID, cfAppGuid);
	metadataMap.put(SurgicalRoutingRequestTransformer.CF_INSTANCE_INDEX, cfInstanceIndex);
	metadataMap.put(INSTANCE_ID, instanceId);
	metadataMap.put(ZONE, zoneFromUri(zoneUri));

	return eurekaInstanceConfigBean;
}
 
Example #3
Source File: EurekaServiceRegistryTests.java    From spring-cloud-netflix with Apache License 2.0 6 votes vote down vote up
@Test
public void eurekaClientNotShutdownInDeregister() {
	EurekaServiceRegistry registry = new EurekaServiceRegistry();

	CloudEurekaClient eurekaClient = mock(CloudEurekaClient.class);
	ApplicationInfoManager applicationInfoManager = mock(
			ApplicationInfoManager.class);

	when(applicationInfoManager.getInfo()).thenReturn(mock(InstanceInfo.class));

	EurekaRegistration registration = EurekaRegistration
			.builder(new EurekaInstanceConfigBean(
					new InetUtils(new InetUtilsProperties())))
			.with(eurekaClient).with(applicationInfoManager)
			.with(new EurekaClientConfigBean(), mock(ApplicationEventPublisher.class))
			.build();

	registry.deregister(registration);

	verifyNoInteractions(eurekaClient);
}
 
Example #4
Source File: EurekaConfigurationListener.java    From summerframework with Apache License 2.0 5 votes vote down vote up
private HostInfo getFirstNonLoopbackHostInfo(ConfigurableEnvironment environment) {
    InetUtilsProperties target = new InetUtilsProperties();
    ConfigurationPropertySources.attach(environment);
    Binder.get(environment).bind(InetUtilsProperties.PREFIX, Bindable.ofInstance(target));
    try (InetUtils utils = new InetUtils(target)) {
        return utils.findFirstNonLoopbackHostInfo();
    }
}
 
Example #5
Source File: ZookeeperDiscoveryPropertiesTest.java    From spring-cloud-zookeeper with Apache License 2.0 5 votes vote down vote up
@Test
public void should_escape_root() {
	// given:
	ZookeeperDiscoveryProperties zookeeperDiscoveryProperties = new ZookeeperDiscoveryProperties(
			new InetUtils(new InetUtilsProperties()));
	// when:
	zookeeperDiscoveryProperties.setRoot(root);
	// then:
	then(zookeeperDiscoveryProperties.getRoot()).isEqualTo("/es");
}
 
Example #6
Source File: HostInfoEnvironmentPostProcessor.java    From spring-cloud-commons with Apache License 2.0 5 votes vote down vote up
private HostInfo getFirstNonLoopbackHostInfo(ConfigurableEnvironment environment) {
	InetUtilsProperties target = new InetUtilsProperties();
	ConfigurationPropertySources.attach(environment);
	Binder.get(environment).bind(InetUtilsProperties.PREFIX,
			Bindable.ofInstance(target));
	try (InetUtils utils = new InetUtils(target)) {
		return utils.findFirstNonLoopbackHostInfo();
	}
}
 
Example #7
Source File: EurekaServiceRegistryTests.java    From spring-cloud-netflix with Apache License 2.0 5 votes vote down vote up
@Test
public void eurekaClientGetStatus() {
	EurekaServiceRegistry registry = new EurekaServiceRegistry();

	EurekaInstanceConfigBean config = new EurekaInstanceConfigBean(
			new InetUtils(new InetUtilsProperties()));
	config.setAppname("myapp");
	config.setInstanceId("1234");

	InstanceInfo local = InstanceInfo.Builder.newBuilder().setAppName("myapp")
			.setInstanceId("1234").setStatus(DOWN).build();

	InstanceInfo remote = InstanceInfo.Builder.newBuilder().setAppName("myapp")
			.setInstanceId("1234").setStatus(DOWN).setOverriddenStatus(OUT_OF_SERVICE)
			.build();

	CloudEurekaClient eurekaClient = mock(CloudEurekaClient.class);
	when(eurekaClient.getInstanceInfo(local.getAppName(), local.getId()))
			.thenReturn(remote);

	ApplicationInfoManager applicationInfoManager = mock(
			ApplicationInfoManager.class);
	when(applicationInfoManager.getInfo()).thenReturn(local);

	EurekaRegistration registration = EurekaRegistration.builder(config)
			.with(eurekaClient).with(applicationInfoManager)
			.with(new EurekaClientConfigBean(), mock(ApplicationEventPublisher.class))
			.build();

	Object status = registry.getStatus(registration);

	assertThat(registration.getInstanceId()).isEqualTo("1234");

	assertThat(status).isInstanceOf(Map.class);

	Map<Object, Object> map = (Map<Object, Object>) status;

	assertThat(map).hasSize(2).containsEntry("status", DOWN.toString())
			.containsEntry("overriddenStatus", OUT_OF_SERVICE.toString());
}
 
Example #8
Source File: EurekaServiceRegistryTests.java    From spring-cloud-netflix with Apache License 2.0 5 votes vote down vote up
@Test
public void eurekaClientGetStatusNoInstance() {
	EurekaServiceRegistry registry = new EurekaServiceRegistry();

	EurekaInstanceConfigBean config = new EurekaInstanceConfigBean(
			new InetUtils(new InetUtilsProperties()));
	config.setAppname("myapp");
	config.setInstanceId("1234");

	CloudEurekaClient eurekaClient = mock(CloudEurekaClient.class);

	when(eurekaClient.getInstanceInfo("myapp", "1234")).thenReturn(null);

	ApplicationInfoManager applicationInfoManager = mock(
			ApplicationInfoManager.class);
	when(applicationInfoManager.getInfo()).thenReturn(mock(InstanceInfo.class));

	EurekaRegistration registration = EurekaRegistration.builder(config)
			.with(eurekaClient).with(applicationInfoManager)
			.with(new EurekaClientConfigBean(), mock(ApplicationEventPublisher.class))
			.build();

	Object status = registry.getStatus(registration);

	assertThat(registration.getInstanceId()).isEqualTo("1234");

	assertThat(status).isInstanceOf(Map.class);

	Map<Object, Object> map = (Map<Object, Object>) status;

	assertThat(map).hasSize(1).containsEntry("status", UNKNOWN.toString());
}
 
Example #9
Source File: InstanceInfoFactoryTests.java    From spring-cloud-netflix with Apache License 2.0 5 votes vote down vote up
@Test
public void instanceIdIsHostNameByDefault() throws IOException {
	InstanceInfo instanceInfo = setupInstance();
	try (InetUtils utils = new InetUtils(new InetUtilsProperties())) {
		assertThat(instanceInfo.getId())
				.isEqualTo(utils.findFirstNonLoopbackHostInfo().getHostname());
	}
}
 
Example #10
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 #11
Source File: EurekaInstanceConfigBeanTests.java    From spring-cloud-netflix with Apache License 2.0 5 votes vote down vote up
@Bean
public EurekaInstanceConfigBean eurekaInstanceConfigBean() {
	EurekaInstanceConfigBean configBean = new EurekaInstanceConfigBean(
			new InetUtils(new InetUtilsProperties()));
	String springAppName = this.env.getProperty("spring.application.name", "");
	if (StringUtils.hasText(springAppName)) {
		configBean.setSecureVirtualHostName(springAppName);
		configBean.setVirtualHostName(springAppName);
		configBean.setAppname(springAppName);
	}
	return configBean;
}
 
Example #12
Source File: ConsulDiscoveryPropertiesTests.java    From spring-cloud-consul with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() {
	this.properties = new ConsulDiscoveryProperties(
			new InetUtils(new InetUtilsProperties()));
	this.properties.setDefaultQueryTag(DEFAULT_TAG);
	this.properties.setServerListQueryTags(this.serverListQueryTags);
	this.properties.setDatacenters(this.datacenters);
}
 
Example #13
Source File: DefaultEndpointLocatorConfigurationTest.java    From spring-cloud-sleuth with Apache License 2.0 4 votes vote down vote up
private InetUtils localAddress(byte[] address) throws UnknownHostException {
	InetUtils mocked = Mockito.spy(new InetUtils(new InetUtilsProperties()));
	Mockito.when(mocked.findFirstNonLoopbackAddress())
			.thenReturn(InetAddress.getByAddress(address));
	return mocked;
}
 
Example #14
Source File: InstanceInfoFactoryTests.java    From spring-cloud-netflix with Apache License 2.0 4 votes vote down vote up
@Bean
public EurekaInstanceConfigBean eurekaInstanceConfigBean() {
	return new EurekaInstanceConfigBean(new InetUtils(new InetUtilsProperties()));
}
 
Example #15
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 #16
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;
		}