Search in sources :

Example 16 with Service

use of com.ecwid.consul.v1.health.model.HealthService.Service in project spring-cloud-consul by spring-cloud.

the class HealthServiceServerListFilterTests method newServer.

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);
}
Also used : HealthService(com.ecwid.consul.v1.health.model.HealthService) Check(com.ecwid.consul.v1.health.model.Check) ArrayList(java.util.ArrayList) HealthService(com.ecwid.consul.v1.health.model.HealthService)

Example 17 with Service

use of com.ecwid.consul.v1.health.model.HealthService.Service in project cloudbreak by hortonworks.

the class ConsulServiceCheckerTask method checkStatus.

@Override
public boolean checkStatus(ConsulContext consulContext) {
    String serviceName = consulContext.getTargets().get(0);
    ConsulClient client = consulContext.getConsulClient();
    LOGGER.info("Checking consul service registration of '{}'", serviceName);
    List<CatalogService> service = ConsulUtils.getService(Collections.singletonList(client), serviceName);
    if (service.isEmpty()) {
        LOGGER.info("Consul service '{}' is not registered yet", serviceName);
        return false;
    } else {
        LOGGER.info("Consul service '{}' found on '{}'", serviceName, service.get(0).getNode());
        return true;
    }
}
Also used : ConsulClient(com.ecwid.consul.v1.ConsulClient) CatalogService(com.ecwid.consul.v1.catalog.model.CatalogService)

Example 18 with Service

use of com.ecwid.consul.v1.health.model.HealthService.Service in project motan by weibocom.

the class ConsulRegistryService method getGroups.

@Override
public List<String> getGroups() {
    List<String> groups = new ArrayList<String>();
    for (String dc : getDatacenters()) {
        QueryParams queryParams = new QueryParams(dc);
        Map<String, List<String>> serviceMap = consulClient.getCatalogServices(queryParams).getValue();
        serviceMap.remove("consul");
        for (String service : serviceMap.keySet()) {
            groups.add(formatGroupName(dc, service));
        }
    }
    return groups;
}
Also used : QueryParams(com.ecwid.consul.v1.QueryParams)

Example 19 with Service

use of com.ecwid.consul.v1.health.model.HealthService.Service in project motan by weibocom.

the class ConsulEcwidClient method convertService.

private NewService convertService(ConsulService service) {
    NewService newService = new NewService();
    newService.setAddress(service.getAddress());
    newService.setId(service.getId());
    newService.setName(service.getName());
    newService.setPort(service.getPort());
    newService.setTags(service.getTags());
    NewService.Check check = new NewService.Check();
    check.setTtl(service.getTtl() + "s");
    newService.setCheck(check);
    return newService;
}
Also used : NewService(com.ecwid.consul.v1.agent.model.NewService)

Example 20 with Service

use of com.ecwid.consul.v1.health.model.HealthService.Service in project motan by weibocom.

the class ConsulEcwidClient method registerService.

@Override
public void registerService(ConsulService service) {
    NewService newService = convertService(service);
    client.agentServiceRegister(newService);
}
Also used : NewService(com.ecwid.consul.v1.agent.model.NewService)

Aggregations

Test (org.junit.Test)18 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)18 Service (com.ecwid.consul.v1.agent.model.Service)14 Map (java.util.Map)14 NewService (com.ecwid.consul.v1.agent.model.NewService)10 Check (com.ecwid.consul.v1.health.model.Check)6 HealthService (com.ecwid.consul.v1.health.model.HealthService)5 ArrayList (java.util.ArrayList)4 List (java.util.List)4 QueryParams (com.ecwid.consul.v1.QueryParams)3 CatalogService (com.ecwid.consul.v1.catalog.model.CatalogService)2 ConsulService (com.weibo.api.motan.registry.consul.ConsulService)2 JSONObject (com.alibaba.fastjson.JSONObject)1 ConsulClient (com.ecwid.consul.v1.ConsulClient)1 Service (com.ecwid.consul.v1.health.model.HealthService.Service)1 DefaultClientConfigImpl (com.netflix.client.config.DefaultClientConfigImpl)1 DefaultServiceInstance (org.springframework.cloud.client.DefaultServiceInstance)1 ConsulServer (org.springframework.cloud.consul.discovery.ConsulServer)1 ConsulServerList (org.springframework.cloud.consul.discovery.ConsulServerList)1