Example #1
0
 private boolean checkInspectBaseStatus(StringBuilder msg, InspectBase inspectBase) {
   boolean flag = true;
   InspectStatus inspectStatus = inspectBase.checkStatus();
   if (inspectStatus.isError()) {
     flag = false;
     msg.append(InspectUtil.formatStatusForWeb(inspectStatus)).append("\n");
   }
   return flag;
 }
Example #2
0
  @RequestMapping(method = RequestMethod.GET)
  public ResponseEntity<String> opList(HttpServletRequest request) {

    String inspectKey = request.getParameter("key");

    if (inspectMap == null || inspectMap.isEmpty()) {
      return new ResponseEntity<String>("no inspect", HttpStatus.OK);
    }

    boolean flag = true;
    StringBuilder msg = new StringBuilder();
    try {
      if (StringUtil.isEmpty(inspectKey)) { // 无key,返回所有

        for (Entry<String, InspectBase> entry : inspectMap.entrySet()) {
          InspectBase inspectBase = entry.getValue();
          if (!checkInspectBaseStatus(msg, inspectBase)) {
            flag = false;
          }
        }

      } else { // 有key
        InspectBase inspect = inspectMap.get(inspectKey);

        if (null != inspect) {
          logger.info("start inspect base check {}", inspect.getInspectName());
          flag = checkInspectBaseStatus(msg, inspect);
          logger.info("finish inspect base  check {}", inspect.getInspectName());
        } else {
          return new ResponseEntity<String>("unknown key", HttpStatus.OK);
        }
      }
    } catch (RuntimeException e) {
      logger.error("interal error", e);
      return new ResponseEntity<String>(e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
    }

    if (flag) {
      return new ResponseEntity<String>("OK", HttpStatus.OK);
    } else {
      logger.error("not ok, msg:{}", msg.toString());
      return new ResponseEntity<String>(msg.toString(), HttpStatus.INTERNAL_SERVER_ERROR);
    }
  }