com.ecwid.consul.v1.Response.getValue()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(12.0k)|赞(0)|评价(0)|浏览(94)

本文整理了Java中com.ecwid.consul.v1.Response.getValue方法的一些代码示例,展示了Response.getValue的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Response.getValue方法的具体详情如下:
包路径:com.ecwid.consul.v1.Response
类名称:Response
方法名:getValue

Response.getValue介绍

暂无

代码示例

代码示例来源:origin: weibocom/motan

public List<String> getDatacenters() {
  return consulClient.getCatalogDatacenters().getValue();
}

代码示例来源:origin: weibocom/motan

@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;
}

代码示例来源:origin: weibocom/motan

/**
 * 获取指定group的指令列表
 *
 * @param groupName
 * @return
 */
@Override
public String getCommands(String groupName) {
  Response<GetValue> response = consulClient.getKVValue(ConsulConstants.CONSUL_MOTAN_COMMAND + groupName);
  GetValue value = response.getValue();
  String command = "";
  if (value != null && value.getValue() != null) {
    command = new String(Base64.decodeBase64(value.getValue()));
  }
  return command;
}

代码示例来源:origin: weibocom/motan

/**
 * 获取所有指令
 *
 * @return
 */
@Override
public List<JSONObject> getAllCommands() {
  List<JSONObject> commands = new ArrayList<JSONObject>();
  Response<List<GetValue>> response = consulClient.getKVValues(ConsulConstants.CONSUL_MOTAN_COMMAND);
  List<GetValue> values = response.getValue();
  if (values != null) {
    for (GetValue value : values) {
      JSONObject node = new JSONObject();
      if (value.getValue() == null) {
        continue;
      }
      String group = value.getKey().substring(ConsulConstants.CONSUL_MOTAN_COMMAND.length());
      String command = new String(Base64.decodeBase64(value.getValue()));
      node.put("group", group);
      node.put("command", RpcCommandUtil.stringToCommand(command));
      commands.add(node);
    }
  }
  return commands;
}

代码示例来源:origin: weibocom/motan

@Override
public List<JSONObject> getNodes(String dcGroup, String service, String nodeType) {
  List<JSONObject> results = new ArrayList<JSONObject>();
  List<Check> checks = consulClient.getHealthChecksForService(getGroupName(dcGroup), new QueryParams(getDcName(dcGroup))).getValue();
  for (Check check : checks) {
    String serviceId = check.getServiceId();
    String[] strings = serviceId.split("-");
    if (strings[1].equals(service)) {
      Check.CheckStatus status = check.getStatus();
      JSONObject node = new JSONObject();
      if (nodeType.equals(status.toString())) {
        node.put("host", strings[0]);
        node.put("info", null);
        results.add(node);
      }
    }
  }
  return results;
}

代码示例来源:origin: weibocom/motan

private List<CatalogService> getCatalogServicesByGroup(String dcGroup) {
  QueryParams queryParams = new QueryParams(getDcName(dcGroup));
  return consulClient.getCatalogService(getGroupName(dcGroup), queryParams).getValue();
}

代码示例来源:origin: weibocom/motan

/**
 * 更新指定group的指令列表
 *
 * @param command
 * @param group
 * @return
 */
@Override
public boolean setCommand(String group, RpcCommand command) {
  LoggerUtil.info(String.format("set command: group=%s, command=%s: ", group, JSON.toJSONString(command)));
  List<RpcCommand.ClientCommand> newCommandList = new ArrayList<RpcCommand.ClientCommand>();
  for (RpcCommand.ClientCommand clientCommand : command.getClientCommandList()) {
    List<String> newMergeGroups = new ArrayList<String>();
    for (String mergeGroup : clientCommand.getMergeGroups()) {
      mergeGroup = removeGroupNamePrefix(mergeGroup);
      newMergeGroups.add(mergeGroup);
    }
    clientCommand.setMergeGroups(newMergeGroups);
    newCommandList.add(clientCommand);
  }
  command.setClientCommandList(newCommandList);
  Response<Boolean> response = consulClient.setKVValue(
      ConsulConstants.CONSUL_MOTAN_COMMAND + removeDatacenterPrefix(group),
      RpcCommandUtil.commandToString(command));
  return response.getValue();
}

代码示例来源:origin: weibocom/motan

@Override
public String lookupCommand(String group) {
  Response<GetValue> response = client.getKVValue(ConsulConstants.CONSUL_MOTAN_COMMAND + ConsulUtils.convertGroupToServiceName(group));
  GetValue value = response.getValue();
  String command = "";
  if (value == null) {
    LoggerUtil.info("no command in group: " + group);
  } else if (value.getValue() != null) {
    command = value.getDecodedValue();
  }
  return command;
}

代码示例来源:origin: weibocom/motan

serviceName, true, queryParams);
ConsulResponse<List<ConsulService>> newResponse = null;
if (orgResponse != null && orgResponse.getValue() != null
    && !orgResponse.getValue().isEmpty()) {
  List<HealthService> HealthServices = orgResponse.getValue();
  List<ConsulService> ConsulServices = new ArrayList<ConsulService>(
      HealthServices.size());

代码示例来源:origin: alipay/sofa-rpc

public Boolean registerEphemralNode(ConsulEphemeralNode ephemralNode) {
  String sessionId = null;
  List<Session> sessions = client.getSessionList(QueryParams.DEFAULT).getValue();
  if (sessions != null && !sessions.isEmpty()) {
    for (Session session : sessions) {
      if (session.getName().equals(ephemralNode.getSessionName())) {
        sessionId = session.getId();
      }
    }
  }
  if (sessionId == null) {
    NewSession newSession = ephemralNode.getNewSession();
    synchronized (lock) {
      sessionId = client.sessionCreate(newSession, QueryParams.DEFAULT).getValue();
    }
  }
  ConsulSession session = new ConsulSession(sessionId, ephemralNode);
  ttlScheduler.addHeartbeatSession(session);
  PutParams kvPutParams = new PutParams();
  kvPutParams.setAcquireSession(sessionId);
  client.getKVValue(ephemralNode.getEphemralNodeKey());
  return client.setKVValue(ephemralNode.getEphemralNodeKey(), ephemralNode.getEphemralNodeValue(),
    kvPutParams).getValue();
}

代码示例来源:origin: alipay/sofa-rpc

public Boolean registerEphemralNode(ConsulEphemeralNode ephemralNode) {
  String sessionId = null;
  List<Session> sessions = client.getSessionList(QueryParams.DEFAULT).getValue();
  if (sessions != null && !sessions.isEmpty()) {
    for (Session session : sessions) {
      if (session.getName().equals(ephemralNode.getSessionName())) {
        sessionId = session.getId();
      }
    }
  }
  if (sessionId == null) {
    NewSession newSession = ephemralNode.getNewSession();
    synchronized (lock) {
      sessionId = client.sessionCreate(newSession, QueryParams.DEFAULT).getValue();
    }
  }
  ConsulSession session = new ConsulSession(sessionId, ephemralNode);
  ttlScheduler.addHeartbeatSession(session);
  PutParams kvPutParams = new PutParams();
  kvPutParams.setAcquireSession(sessionId);
  client.getKVValue(ephemralNode.getEphemralNodeKey());
  return client.setKVValue(ephemralNode.getEphemralNodeKey(), ephemralNode.getEphemralNodeValue(),
    kvPutParams).getValue();
}

代码示例来源:origin: alipay/sofa-rpc

public ConsulRouterResp lookupRouterMessage(String serviceName, long lastConsulIndex) {
  QueryParams queryParams = new QueryParams(ConsulConstants.CONSUL_BLOCK_TIME_SECONDS, lastConsulIndex);
  Response<GetValue> orgResponse = client.getKVValue(serviceName, queryParams);
  GetValue getValue = orgResponse.getValue();
  if (getValue != null && StringUtils.isNotBlank(getValue.getValue())) {
    String router = new String(Base64.decodeBase64(getValue.getValue()));
    ConsulRouterResp response = ConsulRouterResp.newResponse()//
      .withValue(router)//
      .withConsulIndex(orgResponse.getConsulIndex())//
      .withConsulLastContact(orgResponse.getConsulLastContact())//
      .withConsulKnowLeader(orgResponse.isConsulKnownLeader())//
      .build();
    return response;
  }
  return null;
}

代码示例来源:origin: alipay/sofa-rpc

public ConsulRouterResp lookupRouterMessage(String serviceName, long lastConsulIndex) {
  QueryParams queryParams = new QueryParams(ConsulConstants.CONSUL_BLOCK_TIME_SECONDS, lastConsulIndex);
  Response<GetValue> orgResponse = client.getKVValue(serviceName, queryParams);
  GetValue getValue = orgResponse.getValue();
  if (getValue != null && StringUtils.isNotBlank(getValue.getValue())) {
    String router = new String(Base64.decodeBase64(getValue.getValue()));
    ConsulRouterResp response = ConsulRouterResp.newResponse()//
      .withValue(router)//
      .withConsulIndex(orgResponse.getConsulIndex())//
      .withConsulLastContact(orgResponse.getConsulLastContact())//
      .withConsulKnowLeader(orgResponse.isConsulKnownLeader())//
      .build();
    return response;
  }
  return null;
}

代码示例来源:origin: alipay/sofa-rpc

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> consulServices = Lists.newArrayList();
    for (HealthService orgService : healthServices) {
      Service org = orgService.getService();
      ConsulService newService = ConsulService.newService()//
        .withAddress(org.getAddress())//
        .withName(org.getService())//
        .withId(org.getId())//
        .withPort(org.getPort().toString())//
        .withTags(org.getTags())//
        .build();
      consulServices.add(newService);
    }
    if (!consulServices.isEmpty()) {
      ConsulServiceResp response = ConsulServiceResp.newResponse()//
        .withValue(consulServices)//
        .withConsulIndex(orgResponse.getConsulIndex())//
        .withConsulLastContact(orgResponse.getConsulLastContact())//
        .withConsulKnowLeader(orgResponse.isConsulKnownLeader())//
        .build();
      return response;
    }
  }
  return null;
}

代码示例来源:origin: alipay/sofa-rpc

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> consulServices = Lists.newArrayList();
    for (HealthService orgService : healthServices) {
      Service org = orgService.getService();
      ConsulService newService = ConsulService.newService()//
        .withAddress(org.getAddress())//
        .withName(org.getService())//
        .withId(org.getId())//
        .withPort(org.getPort().toString())//
        .withTags(org.getTags())//
        .build();
      consulServices.add(newService);
    }
    if (!consulServices.isEmpty()) {
      ConsulServiceResp response = ConsulServiceResp.newResponse()//
        .withValue(consulServices)//
        .withConsulIndex(orgResponse.getConsulIndex())//
        .withConsulLastContact(orgResponse.getConsulLastContact())//
        .withConsulKnowLeader(orgResponse.isConsulKnownLeader())//
        .build();
      return response;
    }
  }
  return null;
}

代码示例来源:origin: marcosbarbero/spring-cloud-zuul-ratelimit

@Override
protected Rate getRate(String key) {
  Rate rate = null;
  GetValue value = this.consulClient.getKVValue(key).getValue();
  if (value != null && value.getDecodedValue() != null) {
    try {
      rate = this.objectMapper.readValue(value.getDecodedValue(), Rate.class);
    } catch (IOException e) {
      log.error("Failed to deserialize Rate", e);
    }
  }
  return rate;
}

代码示例来源:origin: spring-cloud/spring-cloud-consul

@Override
public List<String> getServices() {
  String aclToken = properties.getAclToken();
  if (StringUtils.hasText(aclToken)) {
    return new ArrayList<>(client.getCatalogServices(QueryParams.DEFAULT, aclToken).getValue()
        .keySet());
  } else {
    return new ArrayList<>(client.getCatalogServices(QueryParams.DEFAULT).getValue()
        .keySet());
  }
}

代码示例来源:origin: spring-cloud/spring-cloud-consul

public List<ServiceInstance> getAllInstances() {
  List<ServiceInstance> instances = new ArrayList<>();
  Response<Map<String, List<String>>> services = client
      .getCatalogServices(QueryParams.DEFAULT);
  for (String serviceId : services.getValue().keySet()) {
    addInstancesToList(instances, serviceId, QueryParams.DEFAULT);
  }
  return instances;
}

代码示例来源:origin: spring-cloud/spring-cloud-consul

public Event fire(String name, String payload) {
  Response<Event> response = consul.eventFire(name, payload, new EventParams(),
      QueryParams.DEFAULT);
  return response.getValue();
}

代码示例来源:origin: org.springframework.cloud/spring-cloud-consul-core

@Override
  protected void doHealthCheck(Health.Builder builder) throws Exception {
    final Response<String> leaderStatus = consul.getStatusLeader();
    final Response<Map<String, List<String>>> services = consul
        .getCatalogServices(QueryParams.DEFAULT);
    builder.up().withDetail("leader", leaderStatus.getValue()).withDetail("services",
        services.getValue());
  }
}

相关文章