Search in sources :

Example 36 with SaturnJobConsoleException

use of com.vip.saturn.job.console.exception.SaturnJobConsoleException in project Saturn by vipshop.

the class NamespaceZkClusterMappingController method getZkClusterListWithOnline.

@RequestMapping(value = "getZkClusterListWithOnline", method = RequestMethod.GET)
public RequestResult getZkClusterListWithOnline(HttpServletRequest request) {
    RequestResult requestResult = new RequestResult();
    try {
        List<String> zkClusterListWithOnlineFromCfg = namespaceZkClusterMappingService.getZkClusterListWithOnline();
        requestResult.setObj(zkClusterListWithOnlineFromCfg);
        requestResult.setSuccess(true);
    } catch (SaturnJobConsoleException e) {
        requestResult.setSuccess(false);
        requestResult.setMessage(e.getMessage());
    } catch (Throwable t) {
        LOGGER.error(t.getMessage(), t);
        requestResult.setSuccess(false);
        requestResult.setMessage(t.toString());
    }
    return requestResult;
}
Also used : RequestResult(com.vip.saturn.job.console.domain.RequestResult) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 37 with SaturnJobConsoleException

use of com.vip.saturn.job.console.exception.SaturnJobConsoleException in project Saturn by vipshop.

the class NamespaceZkClusterMappingController method getNamespaceZkclusterMappingList.

@RequestMapping(value = "getNamespaceZkclusterMappingList", method = RequestMethod.GET)
public RequestResult getNamespaceZkclusterMappingList(HttpServletRequest request) {
    RequestResult requestResult = new RequestResult();
    try {
        List<NamespaceZkClusterMappingVo> namespaceZkclusterMappingList = namespaceZkClusterMappingService.getNamespaceZkClusterMappingList();
        requestResult.setObj(namespaceZkclusterMappingList);
        requestResult.setSuccess(true);
    } catch (SaturnJobConsoleException e) {
        requestResult.setSuccess(false);
        requestResult.setMessage(e.getMessage());
    } catch (Throwable t) {
        LOGGER.error(t.getMessage(), t);
        requestResult.setSuccess(false);
        requestResult.setMessage(t.toString());
    }
    return requestResult;
}
Also used : RequestResult(com.vip.saturn.job.console.domain.RequestResult) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException) NamespaceZkClusterMappingVo(com.vip.saturn.job.console.domain.NamespaceZkClusterMappingVo) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 38 with SaturnJobConsoleException

use of com.vip.saturn.job.console.exception.SaturnJobConsoleException in project Saturn by vipshop.

the class SaturnJunkDataController method deleteRunningNode.

@ResponseBody
@RequestMapping(value = "junkData/deleteRunningNode", method = RequestMethod.POST)
public RequestResult deleteRunningNode(String namespace, String jobName, Integer item) {
    RequestResult requestResult = new RequestResult();
    try {
        if (namespace == null || namespace.trim().isEmpty()) {
            throw new SaturnJobConsoleException("The namespace can not be null or empty");
        }
        if (jobName == null || jobName.trim().isEmpty()) {
            throw new SaturnJobConsoleException("The jobName can not be null or empty");
        }
        if (item == null) {
            throw new SaturnJobConsoleException("The item can not be null");
        }
        saturnJunkDataService.deleteRunningNode(namespace, jobName, item);
        LOGGER.info("do junkData/deleteRunningNode success, namespace is {}, jobName is {}, item is {}", namespace, jobName, item);
        requestResult.setSuccess(true);
    } catch (Throwable t) {
        requestResult.setSuccess(false);
        if (t instanceof SaturnJobConsoleException) {
            requestResult.setMessage(t.getMessage());
        } else {
            requestResult.setMessage(t.toString());
        }
        LOGGER.error(t.getMessage(), t);
    }
    return requestResult;
}
Also used : RequestResult(com.vip.saturn.job.console.domain.RequestResult) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 39 with SaturnJobConsoleException

use of com.vip.saturn.job.console.exception.SaturnJobConsoleException in project Saturn by vipshop.

the class ZkTreeController method convertFileToZkTree.

@RequestMapping(value = "convertFileToZkTree", method = RequestMethod.POST)
public RequestResult convertFileToZkTree(MultipartHttpServletRequest request) {
    RequestResult requestResult = new RequestResult();
    try {
        Iterator<String> fileNames = request.getFileNames();
        MultipartFile file = null;
        while (fileNames.hasNext()) {
            if (file != null) {
                requestResult.setSuccess(false);
                requestResult.setMessage("仅支持单文件导入");
                return requestResult;
            }
            file = request.getFile(fileNames.next());
        }
        if (file == null) {
            requestResult.setSuccess(false);
            requestResult.setMessage("请选择导入的文件");
            return requestResult;
        }
        String originalFilename = file.getOriginalFilename();
        if (originalFilename == null || !originalFilename.endsWith(".json")) {
            requestResult.setSuccess(false);
            requestResult.setMessage("仅支持.json文件导入");
            return requestResult;
        }
        ZkTree zkTree = zkTreeService.convertInputStreamToZkTree(file.getInputStream());
        requestResult.setObj(zkTree);
        requestResult.setSuccess(true);
    } catch (SaturnJobConsoleException e) {
        requestResult.setSuccess(false);
        requestResult.setMessage(e.getMessage());
    } catch (Throwable t) {
        requestResult.setSuccess(false);
        requestResult.setMessage(t.toString());
    }
    return requestResult;
}
Also used : ZkTree(com.vip.saturn.job.console.domain.ZkTree) RequestResult(com.vip.saturn.job.console.domain.RequestResult) MultipartFile(org.springframework.web.multipart.MultipartFile) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 40 with SaturnJobConsoleException

use of com.vip.saturn.job.console.exception.SaturnJobConsoleException in project Saturn by vipshop.

the class SaturnConsoleUtils method exportExcelFile.

public static void exportExcelFile(HttpServletResponse response, InputStream inputStream, String exportFileName) throws SaturnJobConsoleException {
    try {
        response.setContentType("application/octet-stream");
        response.setHeader("Content-disposition", "attachment; filename=" + new String(exportFileName.getBytes("UTF-8"), "ISO8859-1"));
        try (BufferedInputStream bis = new BufferedInputStream(inputStream);
            BufferedOutputStream bos = new BufferedOutputStream(response.getOutputStream())) {
            byte[] buff = new byte[2048];
            int bytesRead;
            while (-1 != (bytesRead = bis.read(buff, 0, buff.length))) {
                bos.write(buff, 0, bytesRead);
            }
        }
    } catch (Exception e) {
        throw new SaturnJobConsoleException(e);
    }
}
Also used : SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException)

Aggregations

SaturnJobConsoleException (com.vip.saturn.job.console.exception.SaturnJobConsoleException)190 SaturnJobConsoleHttpException (com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException)56 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)56 CuratorRepository (com.vip.saturn.job.console.repository.zookeeper.CuratorRepository)39 RequestResult (com.vip.saturn.job.console.domain.RequestResult)31 ParseException (java.text.ParseException)28 ResponseEntity (org.springframework.http.ResponseEntity)26 Transactional (org.springframework.transaction.annotation.Transactional)23 JobConfig4DB (com.vip.saturn.job.console.mybatis.entity.JobConfig4DB)22 CuratorFrameworkOp (com.vip.saturn.job.console.repository.zookeeper.CuratorRepository.CuratorFrameworkOp)22 IOException (java.io.IOException)19 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)19 StatusLine (org.apache.http.StatusLine)18 HttpEntity (org.apache.http.HttpEntity)16 Audit (com.vip.saturn.job.console.aop.annotation.Audit)13 JobConfig (com.vip.saturn.job.console.domain.JobConfig)11 HttpHeaders (org.springframework.http.HttpHeaders)11 CurrentJobConfig (com.vip.saturn.job.console.mybatis.entity.CurrentJobConfig)9 ZkCluster (com.vip.saturn.job.console.domain.ZkCluster)8 ArrayList (java.util.ArrayList)8