Search in sources :

Example 6 with ServiceInstance

use of org.springframework.cloud.client.ServiceInstance in project spring-boot-admin by codecentric.

the class ApplicationDiscoveryListenerTest method deregister_removed_app.

@Test
public void deregister_removed_app() {
    registry.register(Application.create("ignored").withHealthUrl("http://health").withId("abcdef").build());
    registry.register(Application.create("different-source").withHealthUrl("http://health2").withId("abcdef").withSource("http-api").build());
    listener.setIgnoredServices(singleton("ignored"));
    List<ServiceInstance> instances = new ArrayList<>();
    instances.add(new DefaultServiceInstance("service", "localhost", 80, false));
    instances.add(new DefaultServiceInstance("service", "example.net", 80, false));
    when(discovery.getServices()).thenReturn(Collections.singletonList("service"));
    when(discovery.getInstances("service")).thenReturn(instances);
    listener.onApplicationEvent(new HeartbeatEvent(new Object(), new Object()));
    assertEquals(2, registry.getApplicationsByName("service").size());
    assertEquals(1, registry.getApplicationsByName("ignored").size());
    assertEquals(1, registry.getApplicationsByName("different-source").size());
    instances.remove(0);
    listener.onApplicationEvent(new HeartbeatEvent(new Object(), new Object()));
    assertEquals(1, registry.getApplicationsByName("service").size());
    assertEquals(1, registry.getApplicationsByName("ignored").size());
    assertEquals(1, registry.getApplicationsByName("different-source").size());
}
Also used : DefaultServiceInstance(org.springframework.cloud.client.DefaultServiceInstance) ParentHeartbeatEvent(org.springframework.cloud.client.discovery.event.ParentHeartbeatEvent) HeartbeatEvent(org.springframework.cloud.client.discovery.event.HeartbeatEvent) ArrayList(java.util.ArrayList) DefaultServiceInstance(org.springframework.cloud.client.DefaultServiceInstance) ServiceInstance(org.springframework.cloud.client.ServiceInstance) Test(org.junit.Test)

Example 7 with ServiceInstance

use of org.springframework.cloud.client.ServiceInstance in project spring-boot-admin by codecentric.

the class DefaultServiceInstanceConverterTest method test_convert_with_custom_defaults.

@Test
public void test_convert_with_custom_defaults() {
    DefaultServiceInstanceConverter converter = new DefaultServiceInstanceConverter();
    converter.setHealthEndpointPath("ping");
    converter.setManagementContextPath("mgmt");
    ServiceInstance service = new DefaultServiceInstance("test", "localhost", 80, false);
    Application application = converter.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 : DefaultServiceInstance(org.springframework.cloud.client.DefaultServiceInstance) DefaultServiceInstance(org.springframework.cloud.client.DefaultServiceInstance) ServiceInstance(org.springframework.cloud.client.ServiceInstance) Application(de.codecentric.boot.admin.model.Application) Test(org.junit.Test)

Example 8 with ServiceInstance

use of org.springframework.cloud.client.ServiceInstance in project spring-boot-admin by codecentric.

the class DefaultServiceInstanceConverterTest method test_convert_with_defaults.

@Test
public void test_convert_with_defaults() {
    ServiceInstance service = new DefaultServiceInstance("test", "localhost", 80, false);
    Application application = new DefaultServiceInstanceConverter().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"));
    assertThat(application.getHealthUrl(), is("http://localhost:80/health"));
}
Also used : DefaultServiceInstance(org.springframework.cloud.client.DefaultServiceInstance) DefaultServiceInstance(org.springframework.cloud.client.DefaultServiceInstance) ServiceInstance(org.springframework.cloud.client.ServiceInstance) Application(de.codecentric.boot.admin.model.Application) Test(org.junit.Test)

Example 9 with ServiceInstance

use of org.springframework.cloud.client.ServiceInstance in project java-chassis by ServiceComb.

the class CseDiscoveryClient method getInstances.

@Override
public List<ServiceInstance> getInstances(final String serviceId) {
    List<ServiceInstance> instances = new ArrayList<ServiceInstance>();
    ServiceRegistryClient client = RegistryClientFactory.getRegistryClient();
    String appId = DynamicPropertyFactory.getInstance().getStringProperty("APPLICATION_ID", "default").get();
    ReferenceConfig referenceConfig = consumerProviderManager.getReferenceConfig(serviceId);
    String versionRule = referenceConfig.getMicroserviceVersionRule();
    String cseServiceID = client.getMicroserviceId(appId, serviceId, versionRule);
    List<MicroserviceInstance> cseServices = client.getMicroserviceInstance(cseServiceID, cseServiceID);
    if (null != cseServices && !cseServices.isEmpty()) {
        for (MicroserviceInstance instance : cseServices) {
            List<String> eps = instance.getEndpoints();
            for (String ep : eps) {
                URIEndpointObject uri = new URIEndpointObject(ep);
                instances.add(new DefaultServiceInstance(instance.getServiceId(), uri.getHostOrIp(), uri.getPort(), false));
            }
        }
    }
    return instances;
}
Also used : DefaultServiceInstance(org.springframework.cloud.client.DefaultServiceInstance) ArrayList(java.util.ArrayList) DefaultServiceInstance(org.springframework.cloud.client.DefaultServiceInstance) ServiceInstance(org.springframework.cloud.client.ServiceInstance) MicroserviceInstance(io.servicecomb.serviceregistry.api.registry.MicroserviceInstance) ServiceRegistryClient(io.servicecomb.serviceregistry.client.ServiceRegistryClient) URIEndpointObject(io.servicecomb.foundation.common.net.URIEndpointObject)

Example 10 with ServiceInstance

use of org.springframework.cloud.client.ServiceInstance in project incubator-servicecomb-java-chassis by apache.

the class CseDiscoveryClient method getInstances.

@Override
public List<ServiceInstance> getInstances(final String serviceId) {
    DiscoveryContext context = new DiscoveryContext();
    context.setInputParameters(serviceId);
    DiscoveryTree discoveryTree = discoveryTrees.computeIfAbsent(serviceId, key -> {
        return new DiscoveryTree();
    });
    VersionedCache serversVersionedCache = discoveryTree.discovery(context, RegistryUtils.getAppId(), serviceId, DefinitionConst.VERSION_RULE_ALL);
    Map<String, MicroserviceInstance> servers = serversVersionedCache.data();
    List<ServiceInstance> instances = new ArrayList<>(servers.size());
    for (MicroserviceInstance s : servers.values()) {
        for (String endpoint : s.getEndpoints()) {
            URIEndpointObject uri = new URIEndpointObject(endpoint);
            instances.add(new DefaultServiceInstance(serviceId, uri.getHostOrIp(), uri.getPort(), uri.isSslEnabled()));
        }
    }
    return instances;
}
Also used : DefaultServiceInstance(org.springframework.cloud.client.DefaultServiceInstance) DiscoveryContext(org.apache.servicecomb.serviceregistry.discovery.DiscoveryContext) VersionedCache(org.apache.servicecomb.foundation.common.cache.VersionedCache) ArrayList(java.util.ArrayList) MicroserviceInstance(org.apache.servicecomb.serviceregistry.api.registry.MicroserviceInstance) DefaultServiceInstance(org.springframework.cloud.client.DefaultServiceInstance) ServiceInstance(org.springframework.cloud.client.ServiceInstance) URIEndpointObject(org.apache.servicecomb.foundation.common.net.URIEndpointObject) DiscoveryTree(org.apache.servicecomb.serviceregistry.discovery.DiscoveryTree)

Aggregations

ServiceInstance (org.springframework.cloud.client.ServiceInstance)73 DefaultServiceInstance (org.springframework.cloud.client.DefaultServiceInstance)25 Test (org.junit.Test)24 HashMap (java.util.HashMap)12 URI (java.net.URI)11 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)11 Registration (de.codecentric.boot.admin.server.domain.values.Registration)10 ArrayList (java.util.ArrayList)10 Test (org.junit.jupiter.api.Test)10 Application (de.codecentric.boot.admin.model.Application)7 Map (java.util.Map)7 List (java.util.List)6 RibbonServer (org.springframework.cloud.netflix.ribbon.RibbonLoadBalancerClient.RibbonServer)6 IClientConfig (com.netflix.client.config.IClientConfig)5 Random (java.util.Random)4 Collections (java.util.Collections)3 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)3 MonitorProperties (com.alibaba.druid.admin.config.MonitorProperties)2 ServiceNode (com.alibaba.druid.admin.model.ServiceNode)2 ConnectionResult (com.alibaba.druid.admin.model.dto.ConnectionResult)2