use of com.ecwid.consul.v1.health.model.HealthService.Service in project motan by weibocom.
the class ConsulEcwidClient method lookupHealthService.
@Override
public ConsulResponse<List<ConsulService>> lookupHealthService(String serviceName, long lastConsulIndex) {
QueryParams queryParams = new QueryParams(ConsulConstants.CONSUL_BLOCK_TIME_SECONDS, lastConsulIndex);
Response<List<HealthService>> orgResponse = client.getHealthServices(serviceName, true, queryParams);
ConsulResponse<List<ConsulService>> newResponse = null;
if (orgResponse != null && orgResponse.getValue() != null && !orgResponse.getValue().isEmpty()) {
List<HealthService> HealthServices = orgResponse.getValue();
List<ConsulService> ConsulServcies = new ArrayList<ConsulService>(HealthServices.size());
for (HealthService orgService : HealthServices) {
try {
ConsulService newService = convertToConsulService(orgService);
ConsulServcies.add(newService);
} catch (Exception e) {
String servcieid = "null";
if (orgService.getService() != null) {
servcieid = orgService.getService().getId();
}
LoggerUtil.error("convert consul service fail. org consulservice:" + servcieid, e);
}
}
if (!ConsulServcies.isEmpty()) {
newResponse = new ConsulResponse<List<ConsulService>>();
newResponse.setValue(ConsulServcies);
newResponse.setConsulIndex(orgResponse.getConsulIndex());
newResponse.setConsulLastContact(orgResponse.getConsulLastContact());
newResponse.setConsulKnownLeader(orgResponse.isConsulKnownLeader());
}
}
return newResponse;
}
use of com.ecwid.consul.v1.health.model.HealthService.Service in project spring-cloud-consul by spring-cloud.
the class ConsulServerListTests method createService.
private NewService createService(String id, int port, List<String> tags) {
NewService service = new NewService();
service.setName(name);
service.setId(name + id);
service.setAddress("localhost");
service.setPort(port);
if (tags != null) {
service.setTags(tags);
}
return service;
}
use of com.ecwid.consul.v1.health.model.HealthService.Service in project spring-cloud-consul by spring-cloud.
the class ConsulDiscoveryClientDefaultQueryTagTests method serviceForEnvironment.
private NewService serviceForEnvironment(String env, int port) {
NewService service = new NewService();
service.setAddress("localhost");
service.setId(NAME + env);
service.setName(NAME);
service.setPort(port);
service.setTags(Arrays.asList(env));
return service;
}
use of com.ecwid.consul.v1.health.model.HealthService.Service in project spring-cloud-consul by spring-cloud.
the class ConsulServiceRegistry method getStatus.
@Override
public Object getStatus(ConsulRegistration registration) {
String serviceId = registration.getServiceId();
Response<List<Check>> response = client.getHealthChecksForService(serviceId, QueryParams.DEFAULT);
List<Check> checks = response.getValue();
for (Check check : checks) {
if (check.getServiceId().equals(registration.getInstanceId())) {
if (check.getName().equalsIgnoreCase("Service Maintenance Mode")) {
return OUT_OF_SERVICE.getCode();
}
}
}
return UP.getCode();
}
use of com.ecwid.consul.v1.health.model.HealthService.Service in project spring-cloud-consul by spring-cloud.
the class ConsulAutoRegistration method lifecycleRegistration.
// TODO: do I need this here, or should I just copy what I need back into lifecycle?
@Deprecated
public static ConsulAutoRegistration lifecycleRegistration(Integer port, String instanceId, AutoServiceRegistrationProperties autoServiceRegistrationProperties, ConsulDiscoveryProperties properties, ApplicationContext context, List<ConsulRegistrationCustomizer> registrationCustomizers, HeartbeatProperties heartbeatProperties) {
NewService service = new NewService();
String appName = getAppName(properties, context.getEnvironment());
service.setId(instanceId);
if (!properties.isPreferAgentAddress()) {
service.setAddress(properties.getHostname());
}
service.setName(normalizeForDns(appName));
service.setTags(createTags(properties));
// If an alternate external port is specified, register using it instead
if (properties.getPort() != null) {
service.setPort(properties.getPort());
} else {
service.setPort(port);
}
Assert.notNull(service.getPort(), "service.port may not be null");
setCheck(service, autoServiceRegistrationProperties, properties, context, heartbeatProperties);
ConsulAutoRegistration registration = new ConsulAutoRegistration(service, autoServiceRegistrationProperties, properties, context, heartbeatProperties);
customize(registrationCustomizers, registration);
return registration;
}
Aggregations