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());
}
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"));
}
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"));
}
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;
}
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;
}
Aggregations