コード例 #1
0
  @RequestMapping(value = "/listVariablesHdfs", method = RequestMethod.POST)
  @ResponseStatus(HttpStatus.OK)
  public Response listVariablesHdfs(@RequestBody Map params) {

    Response response = new Response();
    try {
      String clusterName = params.get("clusterName").toString();
      EngineService engineService = this.getEngineService(clusterName);

      VisualService service = engineService.getVisualService();
      Map resultMap = service.listVariablesHdfs(params);

      if ((boolean) resultMap.get("success")) {
        response.setSuccess(true);
        response.getMap().putAll(resultMap);
      } else {
        response.setSuccess(false);
      }

    } catch (Exception ex) {
      response.setSuccess(false);
      response.getError().setMessage(ex.getMessage());
      if (ex.getCause() != null) response.getError().setCause(ex.getCause().getMessage());
      response.getError().setException(ExceptionUtils.getFullStackTrace(ex));
      logger.info(ex.toString());
    }
    return response;
  }
コード例 #2
0
  /**
   * 파일을 업로드한다.
   *
   * @return REST Response JAXB Object
   */
  @RequestMapping(
      value = "/upload",
      method = RequestMethod.POST,
      consumes = {"multipart/form-data"})
  @ResponseStatus(HttpStatus.OK)
  public ResponseEntity<String> upload(HttpServletRequest req) throws IOException {
    Response response = new Response();

    if (!(req instanceof DefaultMultipartHttpServletRequest)) {
      response.setSuccess(false);
      response.getError().setCause("Invalid Request.");
      response.getError().setMessage("Invalid Request.");
      String json = new ObjectMapper().writeValueAsString(response);
      return new ResponseEntity(json, HttpStatus.BAD_REQUEST);
    }

    try {
      DefaultMultipartHttpServletRequest request = (DefaultMultipartHttpServletRequest) req;
      logger.debug(
          "Uploaded File >> Path : {}, Filename : {}, Size: {} bytes",
          new Object[] {
            request.getParameter("path"),
            request.getFile("file").getOriginalFilename(),
            request.getFile("file").getSize()
          });

      String clusterName = request.getParameter("clusterName");
      Map params = new HashMap();

      EngineService engineService = this.getEngineService(clusterName);
      VisualService service = engineService.getVisualService();
      Map resultMap = service.saveFile(request.getFile("file"), request.getParameter("options"));

      response.getMap().putAll(resultMap);
      response.setSuccess(true);
      String json = new ObjectMapper().writeValueAsString(response);
      HttpStatus statusCode = HttpStatus.OK;
      return new ResponseEntity(json, statusCode);
    } catch (Exception ex) {
      response.setSuccess(false);
      response.getError().setMessage(ex.getMessage());
      if (ex.getCause() != null) response.getError().setCause(ex.getCause().getMessage());
      response.getError().setException(ExceptionUtils.getFullStackTrace(ex));

      String json = new ObjectMapper().writeValueAsString(response);
      HttpStatus statusCode = HttpStatus.INTERNAL_SERVER_ERROR;

      logger.debug(ExceptionUtils.getFullStackTrace(ex));

      return new ResponseEntity(json, statusCode);
    }
  }
コード例 #3
0
  @RequestMapping(value = "/reloadData", method = RequestMethod.GET)
  @ResponseStatus(HttpStatus.OK)
  public Response reloadData(@RequestParam Map params) {
    Response response = new Response();
    try {
      String clusterName = params.get("clusterName").toString();
      EngineService engineService = this.getEngineService(clusterName);

      VisualService service = engineService.getVisualService();
      Map resultMap = service.reloadData(params);

      if ((boolean) resultMap.get("success")) {
        response.setSuccess(true);
        response.getMap().putAll(resultMap);
      } else {
        response.setSuccess(false);
      }

    } catch (IOException ex) {
      throw new ServiceException("You can not reload data.", ex);
    }
    return response;
  }