Search in sources :

Example 1 with InstanceInfo

use of com.netflix.appinfo.InstanceInfo in project spring-boot-admin by codecentric.

the class EurekaServiceInstanceConverterTest method convert_secure_healthUrl.

@Test
public void convert_secure_healthUrl() {
    InstanceInfo instanceInfo = mock(InstanceInfo.class);
    when(instanceInfo.getSecureHealthCheckUrl()).thenReturn("https://localhost:80/health");
    EurekaServiceInstance service = mock(EurekaServiceInstance.class);
    when(service.getInstanceInfo()).thenReturn(instanceInfo);
    when(service.getUri()).thenReturn(URI.create("http://localhost:80"));
    when(service.getServiceId()).thenReturn("test");
    Application application = new EurekaServiceInstanceConverter().convert(service);
    assertThat(application.getHealthUrl(), is("https://localhost:80/health"));
}
Also used : EurekaServiceInstance(org.springframework.cloud.netflix.eureka.EurekaDiscoveryClient.EurekaServiceInstance) InstanceInfo(com.netflix.appinfo.InstanceInfo) Application(de.codecentric.boot.admin.model.Application) Test(org.junit.Test)

Example 2 with InstanceInfo

use of com.netflix.appinfo.InstanceInfo in project spring-boot-admin by codecentric.

the class EurekaServiceInstanceConverterTest method convert_secure.

@Test
public void convert_secure() {
    InstanceInfo instanceInfo = mock(InstanceInfo.class);
    when(instanceInfo.getSecureHealthCheckUrl()).thenReturn("");
    when(instanceInfo.getHealthCheckUrl()).thenReturn("http://localhost:80/mgmt/ping");
    EurekaServiceInstance service = mock(EurekaServiceInstance.class);
    when(service.getInstanceInfo()).thenReturn(instanceInfo);
    when(service.getUri()).thenReturn(URI.create("http://localhost:80"));
    when(service.getServiceId()).thenReturn("test");
    when(service.getMetadata()).thenReturn(singletonMap("management.context-path", "/mgmt"));
    Application application = new EurekaServiceInstanceConverter().convert(service);
    assertThat(application.getId(), nullValue());
    assertThat(application.getName(), is("test"));
    assertThat(application.getServiceUrl(), is("http://localhost:80"));
    assertThat(application.getManagementUrl(), is("http://localhost:80/mgmt"));
    assertThat(application.getHealthUrl(), is("http://localhost:80/mgmt/ping"));
}
Also used : EurekaServiceInstance(org.springframework.cloud.netflix.eureka.EurekaDiscoveryClient.EurekaServiceInstance) InstanceInfo(com.netflix.appinfo.InstanceInfo) Application(de.codecentric.boot.admin.model.Application) Test(org.junit.Test)

Example 3 with InstanceInfo

use of com.netflix.appinfo.InstanceInfo in project spring-boot-admin by codecentric.

the class EurekaServiceInstanceConverterTest method convert_missing_mgmtpath.

@Test
public void convert_missing_mgmtpath() {
    InstanceInfo instanceInfo = mock(InstanceInfo.class);
    when(instanceInfo.getHealthCheckUrl()).thenReturn("http://localhost:80/mgmt/ping");
    EurekaServiceInstance service = mock(EurekaServiceInstance.class);
    when(service.getInstanceInfo()).thenReturn(instanceInfo);
    when(service.getUri()).thenReturn(URI.create("http://localhost:80"));
    when(service.getServiceId()).thenReturn("test");
    Application application = new EurekaServiceInstanceConverter().convert(service);
    assertThat(application.getManagementUrl(), is("http://localhost:80"));
}
Also used : EurekaServiceInstance(org.springframework.cloud.netflix.eureka.EurekaDiscoveryClient.EurekaServiceInstance) InstanceInfo(com.netflix.appinfo.InstanceInfo) Application(de.codecentric.boot.admin.model.Application) Test(org.junit.Test)

Example 4 with InstanceInfo

use of com.netflix.appinfo.InstanceInfo in project spring-boot-admin by codecentric.

the class EurekaServiceInstanceConverter method getHealthUrl.

@Override
protected URI getHealthUrl(ServiceInstance instance) {
    Assert.isInstanceOf(EurekaServiceInstance.class, instance, "serviceInstance must be of type EurekaServiceInstance");
    InstanceInfo instanceInfo = ((EurekaServiceInstance) instance).getInstanceInfo();
    String healthUrl = instanceInfo.getSecureHealthCheckUrl();
    if (StringUtils.isEmpty(healthUrl)) {
        healthUrl = instanceInfo.getHealthCheckUrl();
    }
    return URI.create(healthUrl);
}
Also used : EurekaServiceInstance(org.springframework.cloud.netflix.eureka.EurekaDiscoveryClient.EurekaServiceInstance) InstanceInfo(com.netflix.appinfo.InstanceInfo)

Example 5 with InstanceInfo

use of com.netflix.appinfo.InstanceInfo in project SimianArmy by Netflix.

the class DiscoveryASGInstanceValidator method isActiveInstance.

/**
     * Returns true if the instance is registered in Eureka/Discovery.
     * @param instanceId the instance id
     * @return true if the instance is active, false otherwise
     */
private boolean isActiveInstance(String instanceId) {
    Validate.notNull(instanceId);
    LOGGER.debug(String.format("Checking if instance %s is active", instanceId));
    List<InstanceInfo> instanceInfos = discoveryClient.getInstancesById(instanceId);
    for (InstanceInfo info : instanceInfos) {
        InstanceStatus status = info.getStatus();
        if (status == InstanceStatus.UP || status == InstanceStatus.STARTING) {
            LOGGER.debug(String.format("Instance %s is active in Discovery.", instanceId));
            return true;
        }
    }
    LOGGER.debug(String.format("Instance %s is not active in Discovery.", instanceId));
    return false;
}
Also used : InstanceStatus(com.netflix.appinfo.InstanceInfo.InstanceStatus) InstanceInfo(com.netflix.appinfo.InstanceInfo)

Aggregations

InstanceInfo (com.netflix.appinfo.InstanceInfo)192 Test (org.junit.Test)74 Application (com.netflix.discovery.shared.Application)35 Applications (com.netflix.discovery.shared.Applications)22 AmazonInfo (com.netflix.appinfo.AmazonInfo)21 ArrayList (java.util.ArrayList)19 InstanceStatus (com.netflix.appinfo.InstanceInfo.InstanceStatus)11 Before (org.junit.Before)11 DiscoveryClient (com.netflix.discovery.DiscoveryClient)10 DecoderWrapper (com.netflix.discovery.converters.wrappers.DecoderWrapper)10 Lease (com.netflix.eureka.lease.Lease)9 HashMap (java.util.HashMap)8 Response (javax.ws.rs.core.Response)8 DataCenterInfo (com.netflix.appinfo.DataCenterInfo)7 CodecWrappers (com.netflix.discovery.converters.wrappers.CodecWrappers)7 EncoderWrapper (com.netflix.discovery.converters.wrappers.EncoderWrapper)7 ByteArrayInputStream (java.io.ByteArrayInputStream)7 ApplicationInfoManager (com.netflix.appinfo.ApplicationInfoManager)6 EurekaEntityFunctions.mergeApplications (com.netflix.discovery.util.EurekaEntityFunctions.mergeApplications)6 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)6