Search in sources :

Example 1 with Applications

use of com.netflix.discovery.shared.Applications in project eureka by Netflix.

the class XmlCodecTest method testEncodingDecodingWithMetaData.

@Test
public void testEncodingDecodingWithMetaData() throws Exception {
    Applications applications = InstanceInfoGenerator.newBuilder(10, 2).withMetaData(true).build().toApplications();
    XStream xstream = XmlXStream.getInstance();
    String xmlDocument = xstream.toXML(applications);
    Applications decodedApplications = (Applications) xstream.fromXML(xmlDocument);
    assertThat(EurekaEntityComparators.equal(decodedApplications, applications), is(true));
}
Also used : Applications(com.netflix.discovery.shared.Applications) XStream(com.thoughtworks.xstream.XStream) Test(org.junit.Test)

Example 2 with Applications

use of com.netflix.discovery.shared.Applications in project eureka by Netflix.

the class XmlCodecTest method testEncodingDecodingWithoutMetaData.

@Test
public void testEncodingDecodingWithoutMetaData() throws Exception {
    Applications applications = InstanceInfoGenerator.newBuilder(10, 2).withMetaData(false).build().toApplications();
    XStream xstream = XmlXStream.getInstance();
    String xmlDocument = xstream.toXML(applications);
    Applications decodedApplications = (Applications) xstream.fromXML(xmlDocument);
    assertThat(EurekaEntityComparators.equal(decodedApplications, applications), is(true));
}
Also used : Applications(com.netflix.discovery.shared.Applications) XStream(com.thoughtworks.xstream.XStream) Test(org.junit.Test)

Example 3 with Applications

use of com.netflix.discovery.shared.Applications in project spring-boot by Linda-Tan.

the class EurekaInstanceCanceledListener method onApplicationEvent.

@Override
public void onApplicationEvent(ApplicationEvent applicationEvent) {
    // 服务挂掉自动通知
    if (applicationEvent instanceof EurekaInstanceCanceledEvent) {
        EurekaInstanceCanceledEvent event = (EurekaInstanceCanceledEvent) applicationEvent;
        // 获取当前Eureka示例中的节点信息
        PeerAwareInstanceRegistry registry = EurekaServerContextHolder.getInstance().getServerContext().getRegistry();
        Applications applications = registry.getApplications();
        // 便利获取已注册节点中与当前失效节点ID一致 的节点信息
        applications.getRegisteredApplications().forEach(registryApplication -> {
            registryApplication.getInstances().forEach(instance -> {
                if (Objects.equals(instance.getInstanceId(), event.getServerId())) {
                    log.info("服务:{}挂啦。。。", instance.getAppName());
                // emailService.send(new SimpleMailMessage());
                }
            });
        });
    }
    if (applicationEvent instanceof EurekaInstanceRegisteredEvent) {
        EurekaInstanceRegisteredEvent event = (EurekaInstanceRegisteredEvent) applicationEvent;
        log.info("服务:{}注册成功啦。。。", event.getInstanceInfo().getAppName());
    }
    if (applicationEvent instanceof EurekaInstanceRenewedEvent) {
        EurekaInstanceRenewedEvent event = (EurekaInstanceRenewedEvent) applicationEvent;
        log.info("心跳检测服务:{}。。。", event.getInstanceInfo().getAppName());
    }
    if (applicationEvent instanceof EurekaRegistryAvailableEvent) {
        log.info("服务 Available。。。");
    }
}
Also used : EurekaInstanceRenewedEvent(org.springframework.cloud.netflix.eureka.server.event.EurekaInstanceRenewedEvent) Applications(com.netflix.discovery.shared.Applications) EurekaInstanceCanceledEvent(org.springframework.cloud.netflix.eureka.server.event.EurekaInstanceCanceledEvent) EurekaRegistryAvailableEvent(org.springframework.cloud.netflix.eureka.server.event.EurekaRegistryAvailableEvent) PeerAwareInstanceRegistry(com.netflix.eureka.registry.PeerAwareInstanceRegistry) EurekaInstanceRegisteredEvent(org.springframework.cloud.netflix.eureka.server.event.EurekaInstanceRegisteredEvent)

Example 4 with Applications

use of com.netflix.discovery.shared.Applications in project spring-cloud-netflix by spring-cloud.

the class RestTemplateEurekaHttpClientTest method testGetApplications.

@Test
public void testGetApplications() {
    Applications entity = eurekaHttpClient.getApplications().getEntity();
    Assert.assertNotNull(entity);
    Assert.assertNotNull(eurekaHttpClient.getApplications("us", "eu").getEntity());
}
Also used : Applications(com.netflix.discovery.shared.Applications) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 5 with Applications

use of com.netflix.discovery.shared.Applications in project spring-cloud-netflix by spring-cloud.

the class EurekaBasedTurbineClustersProvider method getClusterNames.

@Override
public List<String> getClusterNames() {
    Applications applications = eurekaClient.getApplications();
    List<Application> registeredApplications = applications.getRegisteredApplications();
    List<String> appNames = new ArrayList<>(registeredApplications.size());
    for (Application application : registeredApplications) {
        appNames.add(application.getName());
    }
    log.trace("Using clusters names: " + appNames);
    return appNames;
}
Also used : Applications(com.netflix.discovery.shared.Applications) ArrayList(java.util.ArrayList) Application(com.netflix.discovery.shared.Application)

Aggregations

Applications (com.netflix.discovery.shared.Applications)120 Test (org.junit.Test)68 Application (com.netflix.discovery.shared.Application)41 InstanceInfo (com.netflix.appinfo.InstanceInfo)29 EurekaEntityFunctions.mergeApplications (com.netflix.discovery.util.EurekaEntityFunctions.mergeApplications)13 EurekaEntityFunctions.toApplications (com.netflix.discovery.util.EurekaEntityFunctions.toApplications)13 EurekaEntityFunctions.copyApplications (com.netflix.discovery.util.EurekaEntityFunctions.copyApplications)10 InstanceInfoGenerator (com.netflix.discovery.util.InstanceInfoGenerator)7 ArrayList (java.util.ArrayList)7 HashMap (java.util.HashMap)7 DecoderWrapper (com.netflix.discovery.converters.wrappers.DecoderWrapper)6 XStream (com.thoughtworks.xstream.XStream)6 CodecWrappers (com.netflix.discovery.converters.wrappers.CodecWrappers)5 InputStream (java.io.InputStream)5 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)5 Matchers.anyString (org.mockito.Matchers.anyString)5 HazelcastInstance (com.hazelcast.core.HazelcastInstance)4 FileInputStream (java.io.FileInputStream)4 IOException (java.io.IOException)4 HashSet (java.util.HashSet)4