Java Code Examples for org.springframework.cloud.netflix.eureka.EurekaInstanceConfigBean#setInstanceId()

The following examples show how to use org.springframework.cloud.netflix.eureka.EurekaInstanceConfigBean#setInstanceId() . 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: EurekaStubsRegistrar.java    From spring-cloud-contract with Apache License 2.0 6 votes vote down vote up
private EurekaInstanceConfigBean registration(
		Map.Entry<StubConfiguration, Integer> entry) {
	EurekaInstanceConfigBean config = new EurekaInstanceConfigBean(this.inetUtils);
	String appName = name(entry.getKey());
	config.setInstanceEnabledOnit(true);
	InetAddress address = this.inetUtils.findFirstNonLoopbackAddress();
	config.setIpAddress(address.getHostAddress());
	config.setHostname(StringUtils.hasText(hostName(entry)) ? hostName(entry)
			: address.getHostName());
	config.setAppname(appName);
	config.setVirtualHostName(appName);
	config.setSecureVirtualHostName(appName);
	int port = port(entry);
	config.setNonSecurePort(port);
	config.setInstanceId(address.getHostAddress() + ":"
			+ entry.getKey().getArtifactId() + ":" + port);
	config.setLeaseRenewalIntervalInSeconds(1);
	return config;
}
 
Example 2
Source File: WebClientEurekaHttpClientTest.java    From spring-cloud-netflix with Apache License 2.0 6 votes vote down vote up
@Before
public void setup() {
	eurekaHttpClient = new WebClientTransportClientFactory()
			.newClient(new DefaultEndpoint(serviceUrl));

	EurekaInstanceConfigBean config = new EurekaInstanceConfigBean(inetUtils);

	String appname = "customapp";
	config.setIpAddress("127.0.0.1");
	config.setHostname("localhost");
	config.setAppname(appname);
	config.setVirtualHostName(appname);
	config.setSecureVirtualHostName(appname);
	config.setNonSecurePort(4444);
	config.setSecurePort(8443);
	config.setInstanceId("127.0.0.1:customapp:4444");

	info = new EurekaConfigBasedInstanceInfoProvider(config).get();
}
 
Example 3
Source File: RestTemplateEurekaHttpClientTest.java    From spring-cloud-netflix with Apache License 2.0 6 votes vote down vote up
@Before
public void setup() {
	eurekaHttpClient = new RestTemplateTransportClientFactory()
			.newClient(new DefaultEndpoint(serviceUrl));

	EurekaInstanceConfigBean config = new EurekaInstanceConfigBean(inetUtils);

	String appname = "customapp";
	config.setIpAddress("127.0.0.1");
	config.setHostname("localhost");
	config.setAppname(appname);
	config.setVirtualHostName(appname);
	config.setSecureVirtualHostName(appname);
	config.setNonSecurePort(4444);
	config.setSecurePort(8443);
	config.setInstanceId("127.0.0.1:customapp:4444");

	info = new EurekaConfigBasedInstanceInfoProvider(config).get();
}
 
Example 4
Source File: EurekaSampleApplication.java    From spring-cloud-netflix with Apache License 2.0 6 votes vote down vote up
@RequestMapping(path = "/register", method = POST)
public String register() {
	EurekaInstanceConfigBean config = new EurekaInstanceConfigBean(inetUtils);
	String appname = "customapp";
	config.setIpAddress("127.0.0.1");
	config.setHostname("localhost");
	config.setAppname(appname);
	config.setVirtualHostName(appname);
	config.setSecureVirtualHostName(appname);
	config.setNonSecurePort(4444);
	config.setInstanceId("127.0.0.1:customapp:4444");

	this.registration = EurekaRegistration.builder(config)
			.with(this.clientConfig, this.context).build();

	this.serviceRegistry.register(this.registration);
	return config.getInstanceId();
}
 
Example 5
Source File: EurekaAutoRegistrationCustomizer.java    From Moss with Apache License 2.0 5 votes vote down vote up
private void customizeMetadata(EurekaInstanceConfigBean instance) {
    instance.setInstanceId(instanceId(instance));
    Map<String, String> metadata = instance.getMetadataMap();
    String processId = metaDataProvider.getProcessId();
    if(metadata != null) {
        metadata.put(MANAGEMENT_PORT, metaDataProvider.getManagementPort() + "");
        metadata.put(PID, processId);
    }
}
 
Example 6
Source File: EurekaAutoRegistrationCustomizer.java    From Moss with Apache License 2.0 5 votes vote down vote up
private void customizeMetadata(EurekaInstanceConfigBean instance) {
    instance.setInstanceId(instanceId(instance));
    Map<String, String> metadata = instance.getMetadataMap();
    String processId = metaDataProvider.getProcessId();
    if(metadata != null) {
        metadata.put(MANAGEMENT_PORT, metaDataProvider.getManagementPort() + "");
        metadata.put(PID, processId);
    }
}
 
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());
}