本文整理汇总了Java中com.ecwid.consul.v1.health.model.HealthService类的典型用法代码示例。如果您正苦于以下问题:Java HealthService类的具体用法?Java HealthService怎么用?Java HealthService使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
HealthService类属于com.ecwid.consul.v1.health.model包,在下文中一共展示了HealthService类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addInstancesToList
import com.ecwid.consul.v1.health.model.HealthService; //导入依赖的package包/类
private void addInstancesToList(List<ServiceInstance> instances, String serviceId,
QueryParams queryParams) {
String aclToken = properties.getAclToken();
Response<List<HealthService>> services;
if (StringUtils.hasText(aclToken)) {
services = client.getHealthServices(serviceId,
this.properties.getDefaultQueryTag(),
this.properties.isQueryPassing(), queryParams, aclToken);
}
else {
services = client.getHealthServices(serviceId,
this.properties.getDefaultQueryTag(),
this.properties.isQueryPassing(), queryParams);
}
for (HealthService service : services.getValue()) {
String host = findHost(service);
instances.add(new DefaultServiceInstance(serviceId, host, service
.getService().getPort(), false, getMetadata(service)));
}
}
示例2: newServer
import com.ecwid.consul.v1.health.model.HealthService; //导入依赖的package包/类
private ConsulServer newServer(Check.CheckStatus checkStatus) {
HealthService healthService = new HealthService();
HealthService.Node node = new HealthService.Node();
node.setAddress("nodeaddr"+checkStatus.name());
node.setNode("nodenode"+checkStatus.name());
healthService.setNode(node);
HealthService.Service service = new HealthService.Service();
service.setAddress("serviceaddr"+checkStatus.name());
service.setId("serviceid"+checkStatus.name());
service.setPort(8080);
service.setService("serviceservice"+checkStatus.name());
healthService.setService(service);
ArrayList<Check> checks = new ArrayList<>();
Check check = new Check();
check.setStatus(checkStatus);
checks.add(check);
healthService.setChecks(checks);
return new ConsulServer(healthService);
}
示例3: getServiceInstances
import com.ecwid.consul.v1.health.model.HealthService; //导入依赖的package包/类
@Override
protected List<ServerInstance> getServiceInstances(String serviceName) {
List<ServiceInstance> instances = new ArrayList<>();
Response<List<HealthService>> healthServices = consulClient.getHealthServices(serviceName, true, QueryParams.DEFAULT);
for (HealthService healthService : healthServices.getValue()) {
if (isPassingChecks(healthService)) {
String host = findHost(healthService);
instances.add(new DefaultServiceInstance(serviceName, host,
healthService.getService().getPort(), false, getMetadata(healthService)));
}
}
return convertToServerInstanceList(instances);
}
示例4: isPassingChecks
import com.ecwid.consul.v1.health.model.HealthService; //导入依赖的package包/类
/**
* Is passing checks boolean.
*
* @param service the service
* @return the boolean
*/
public boolean isPassingChecks(HealthService service) {
for (Check check : service.getChecks()) {
if (check.getStatus() != Check.CheckStatus.PASSING) {
return false;
}
}
return true;
}
示例5: findHost
import com.ecwid.consul.v1.health.model.HealthService; //导入依赖的package包/类
private static String findHost(HealthService healthService) {
HealthService.Service service = healthService.getService();
HealthService.Node node = healthService.getNode();
if (org.springframework.util.StringUtils.hasText(service.getAddress())) {
return service.getAddress();
} else if (org.springframework.util.StringUtils.hasText(node.getAddress())) {
return node.getAddress();
}
return node.getNode();
}
示例6: lookupHealthService
import com.ecwid.consul.v1.health.model.HealthService; //导入依赖的package包/类
public ConsulServiceResp lookupHealthService(String serviceName, long lastConsulIndex) {
QueryParams queryParams = new QueryParams(ConsulConstants.CONSUL_BLOCK_TIME_SECONDS, lastConsulIndex);
Response<List<HealthService>> orgResponse = client.getHealthServices(serviceName, true, queryParams);
if (orgResponse != null && orgResponse.getValue() != null && !orgResponse.getValue().isEmpty()) {
List<HealthService> HealthServices = orgResponse.getValue();
List<ConsulService> ConsulServcies = Lists.newArrayList();
for (HealthService orgService : HealthServices) {
Service org = orgService.getService();
ConsulService newService = ConsulService.newSalukiService()//
.withAddress(org.getAddress())//
.withName(org.getService())//
.withId(org.getId())//
.withPort(org.getPort().toString())//
.withTags(org.getTags())//
.build();
ConsulServcies.add(newService);
}
if (!ConsulServcies.isEmpty()) {
ConsulServiceResp response = ConsulServiceResp.newResponse()//
.withValue(ConsulServcies)//
.withConsulIndex(orgResponse.getConsulIndex())//
.withConsulLastContact(orgResponse.getConsulLastContact())//
.withConsulKnowLeader(orgResponse.isConsulKnownLeader())//
.build();
return response;
}
}
return null;
}
示例7: getProviderUrls
import com.ecwid.consul.v1.health.model.HealthService; //导入依赖的package包/类
public List<URL> getProviderUrls(String serviceName) {
List<URL> urls = new ArrayList<>();
Response<List<HealthService>> healthServices = consulClient.getHealthServices(serviceName, true, null);
for (HealthService healthService : healthServices.getValue()) {
urls.add(URL.valueOf(healthService.getService().getAddress()));
}
return urls;
}
示例8: findHost
import com.ecwid.consul.v1.health.model.HealthService; //导入依赖的package包/类
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();
}
示例9: findHost
import com.ecwid.consul.v1.health.model.HealthService; //导入依赖的package包/类
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();
}
示例10: ConsulServer
import com.ecwid.consul.v1.health.model.HealthService; //导入依赖的package包/类
public ConsulServer(final HealthService healthService) {
super(findHost(healthService), healthService.getService().getPort());
this.service = healthService;
this.metadata = ConsulServerUtils.getMetadata(this.service);
metaInfo = new MetaInfo() {
@Override
public String getAppName() {
return service.getService().getService();
}
@Override
public String getServerGroup() {
return getMetadata().get("group");
}
@Override
public String getServiceIdForDiscovery() {
return null;
}
@Override
public String getInstanceId() {
return service.getService().getId();
}
};
setAlive(isPassingChecks());
}
示例11: getServers
import com.ecwid.consul.v1.health.model.HealthService; //导入依赖的package包/类
private List<ConsulServer> getServers() {
if (this.client == null) {
return Collections.emptyList();
}
String tag = getTag(); // null is ok
Response<List<HealthService>> response = this.client.getHealthServices(
this.serviceId, tag, this.properties.isQueryPassing(),
createQueryParamsForClientRequest(), this.properties.getAclToken());
if (response.getValue() == null || response.getValue().isEmpty()) {
return Collections.emptyList();
}
return transformResponse(response.getValue());
}
示例12: transformResponse
import com.ecwid.consul.v1.health.model.HealthService; //导入依赖的package包/类
/**
* Transforms the response from Consul in to a list of usable {@link ConsulServer}s.
*
* @param healthServices the initial list of servers from Consul. Guaranteed to be non-empty list
* @return ConsulServer instances
* @see ConsulServer#ConsulServer(HealthService)
*/
protected List<ConsulServer> transformResponse(List<HealthService> healthServices) {
List<ConsulServer> servers = new ArrayList<>();
for (HealthService service : healthServices) {
ConsulServer server = new ConsulServer(service);
if (server.getMetadata().containsKey(this.properties.getDefaultZoneMetadataName())) {
server.setZone(server.getMetadata().get(this.properties.getDefaultZoneMetadataName()));
}
servers.add(server);
}
return servers;
}
示例13: getMetadata
import com.ecwid.consul.v1.health.model.HealthService; //导入依赖的package包/类
private static Map<String, String> getMetadata(HealthService healthService) {
return getMetadata(healthService.getService().getTags());
}
示例14: getHealthServices
import com.ecwid.consul.v1.health.model.HealthService; //导入依赖的package包/类
@Override
public Response<List<HealthService>> getHealthServices(String serviceName,
boolean onlyPassing, QueryParams queryParams) {
return wrapped.getHealthServices(serviceName, onlyPassing, queryParams);
}
示例15: getHealthServices
import com.ecwid.consul.v1.health.model.HealthService; //导入依赖的package包/类
@Override
public Response<List<HealthService>> getHealthServices(String serviceName, boolean onlyPassing, QueryParams queryParams) {
return healthClient.getHealthServices(serviceName, onlyPassing, queryParams);
}