Java Code Examples for com.ecwid.consul.v1.health.model.HealthService#Service

The following examples show how to use com.ecwid.consul.v1.health.model.HealthService#Service . 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: ConsulSyncToNacosServiceImplTest.java    From nacos-sync with Apache License 2.0 5 votes vote down vote up
private HealthService buildHealthService(String address,int port,Map<String,String> metadata) {
    HealthService healthService = new HealthService();
    HealthService.Node node = new HealthService.Node();
    node.setMeta(metadata);
    HealthService.Service service = new HealthService.Service();
    service.setAddress(address);
    service.setPort(port);
    healthService.setNode(node);
    healthService.setService(service);

    return healthService;
}
 
Example 2
Source File: ConsulServerContext.java    From pampas with Apache License 2.0 5 votes vote down vote up
private static String findHost(HealthService healthService) {
    HealthService.Service service = healthService.getService();
    HealthService.Node node = healthService.getNode();

    if (StringUtils.isNotBlank(service.getAddress())) {
        return service.getAddress();
    } else if (StringUtils.isNotBlank(node.getAddress())) {
        return node.getAddress();
    }
    return node.getNode();
}
 
Example 3
Source File: ConsulRegistry.java    From dubbox with Apache License 2.0 5 votes vote down vote up
private void doNotify(URL url, Collection<NotifyListener> listeners) {
	List<URL> result = new ArrayList<URL>();
	String consumerService = url.getServiceInterface();
	try {
		Response<List<HealthService>> response = this.consulClient.getHealthServices(consumerService, true, QueryParams.DEFAULT);
		List<HealthService> healthServices = (List<HealthService>) response.getValue();
		Iterator<HealthService> iterator = healthServices.iterator();
		while (iterator.hasNext()) {
			HealthService healthService = (HealthService) iterator.next();
			HealthService.Service service = healthService.getService();
			List<URL> urls = new ArrayList<URL>();
			String serviceURL = URL.decode(service.getAddress());
			URL u = URL.valueOf(serviceURL);
			if (UrlUtils.isMatch(url, u)) {
				urls.add(u);
			}
			result.addAll(urls);
			if (logger.isInfoEnabled()) {
				logger.info("Consul notify:  = " + urls);
			}
		}
		if (result == null || result.size() == 0) {
			return;
		}
		for (NotifyListener listener : listeners) {
			notify(url, listener, result);
		}
	} catch (OperationException e) {
		throw e;
	}
}
 
Example 4
Source File: ConsulHelper.java    From dyno with Apache License 2.0 5 votes vote down vote up
public static String findHost(HealthService healthService) {
    HealthService.Service service = healthService.getService();
    HealthService.Node node = healthService.getNode();

    if (StringUtils.isNotBlank(service.getAddress())) {
        return service.getAddress();
    } else if (StringUtils.isNotBlank(node.getAddress())) {
        return node.getAddress();
    }
    return node.getNode();
}
 
Example 5
Source File: ConsulServerUtils.java    From spring-cloud-consul with Apache License 2.0 5 votes vote down vote up
public static String findHost(HealthService healthService) {
	HealthService.Service service = healthService.getService();
	HealthService.Node node = healthService.getNode();

	if (StringUtils.hasText(service.getAddress())) {
		return fixIPv6Address(service.getAddress());
	}
	else if (StringUtils.hasText(node.getAddress())) {
		return fixIPv6Address(node.getAddress());
	}
	return node.getNode();
}
 
Example 6
Source File: ConsulReactiveDiscoveryClientTests.java    From spring-cloud-consul with Apache License 2.0 5 votes vote down vote up
private Response<List<HealthService>> consulInstancesResponse() {
	HealthService healthService = mock(HealthService.class);
	HealthService.Service service = mock(HealthService.Service.class);

	when(healthService.getService()).thenReturn(service);
	when(service.getAddress()).thenReturn("localhost");
	when(service.getPort()).thenReturn(443);
	lenient().when(service.getTags()).thenReturn(singletonList("secure=true"));

	return new Response<>(singletonList(healthService), 0L, true,
			System.currentTimeMillis());
}