Search in sources :

Example 21 with SaturnJobConsoleException

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

the class DashboardRefreshRestApiController method dashboardRefresh.

/**
 * 根据ZK集群key,刷新该集群的dashboard信息
 *
 * @param zkClusterKey
 * @param request
 * @return
 * @throws SaturnJobConsoleException
 */
@RequestMapping(value = "/dashboard/refresh", method = { RequestMethod.POST, RequestMethod.GET }, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public ResponseEntity<Object> dashboardRefresh(String zkClusterKey, HttpServletRequest request) throws SaturnJobConsoleException {
    try {
        checkMissingParameter("zkClusterKey", zkClusterKey);
        long beforeRefresh = System.currentTimeMillis();
        dashboardService.refreshStatistics2DB(zkClusterKey);
        long afterRefresh = System.currentTimeMillis();
        long takeTime = afterRefresh - beforeRefresh;
        return new ResponseEntity<Object>(takeTime, HttpStatus.OK);
    } catch (SaturnJobConsoleException e) {
        throw e;
    } catch (Exception e) {
        throw new SaturnJobConsoleHttpException(HttpStatus.INTERNAL_SERVER_ERROR.value(), e.getMessage(), e);
    }
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException) SaturnJobConsoleHttpException(com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException) SaturnJobConsoleHttpException(com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 22 with SaturnJobConsoleException

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

the class ExecutorController method shardAllAtOnce.

@RequestMapping(value = "shardAllAtOnce", method = RequestMethod.POST)
public RequestResult shardAllAtOnce(String nns, HttpServletRequest request, HttpSession httpSession) {
    RequestResult requestResult = new RequestResult();
    LOGGER.info("[tries to sharding all at once.]");
    try {
        requestResult = executorService.shardAllAtOnce();
    } catch (SaturnJobConsoleException e) {
        requestResult.setSuccess(false);
        requestResult.setMessage(e.getMessage());
    } catch (Throwable t) {
        requestResult.setSuccess(false);
        requestResult.setMessage(t.toString());
        LOGGER.error("shardingAllAtOnce exception:", t);
    }
    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 23 with SaturnJobConsoleException

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

the class ExecutorController method batchAddJobs.

@RequestMapping(value = "batchAddJobs", method = RequestMethod.POST)
public RequestResult batchAddJobs(MultipartHttpServletRequest request) {
    RequestResult result = new RequestResult();
    int successCount = 0;
    int failCount = 0;
    String failMessage = "";
    try {
        Iterator<String> fileNames = request.getFileNames();
        MultipartFile file = null;
        while (fileNames.hasNext()) {
            if (file != null) {
                result.setSuccess(false);
                result.setMessage("仅支持单文件导入");
                return result;
            }
            file = request.getFile(fileNames.next());
        }
        if (file == null) {
            result.setSuccess(false);
            result.setMessage("请选择导入的文件");
            return result;
        }
        String originalFilename = file.getOriginalFilename();
        if (originalFilename == null || !originalFilename.endsWith(".xls")) {
            result.setSuccess(false);
            result.setMessage("仅支持.xls文件导入");
            return result;
        }
        Workbook workbook = Workbook.getWorkbook(file.getInputStream());
        Sheet[] sheets = workbook.getSheets();
        List<JobConfig> jobConfigList = new ArrayList<>();
        // 先获取数据并检测内容格式的正确性
        for (int i = 0; i < sheets.length; i++) {
            Sheet sheet = sheets[i];
            int rows = sheet.getRows();
            for (int row = 1; row < rows; row++) {
                Cell[] rowCells = sheet.getRow(row);
                // 如果这一行的表格全为空,则跳过这一行。
                if (!isBlankRow(rowCells)) {
                    jobConfigList.add(convertJobConfig(i + 1, row + 1, rowCells));
                }
            }
        }
        int maxJobNum = executorService.getMaxJobNum();
        if (executorService.jobIncExceeds(maxJobNum, jobConfigList.size())) {
            String errorMsg = String.format("总作业数超过最大限制(%d),导入失败", maxJobNum);
            result.setSuccess(false);
            result.setMessage(errorMsg);
            return result;
        }
        // 再进行添加
        for (JobConfig jobConfig : jobConfigList) {
            RequestResult addJobResult = executorService.addJobs(jobConfig);
            if (addJobResult.isSuccess()) {
                successCount++;
            } else {
                failCount++;
                failMessage += " [" + addJobResult.getMessage() + "]";
            }
        }
    } catch (SaturnJobConsoleException e) {
        result.setSuccess(false);
        result.setMessage("导入失败," + e.getMessage());
        return result;
    } catch (Exception e) {
        result.setSuccess(false);
        result.setMessage("导入失败,错误信息:" + e.toString());
        return result;
    }
    result.setSuccess(true);
    if (failCount > 0) {
        result.setMessage("共导入" + successCount + "个作业,忽略" + failCount + "个。错误信息:" + failMessage);
    } else {
        result.setMessage("共导入" + successCount + "个作业,忽略0个");
    }
    return result;
}
Also used : Workbook(jxl.Workbook) JobConfig(com.vip.saturn.job.console.domain.JobConfig) WriteException(jxl.write.WriteException) ParseException(java.text.ParseException) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException) RequestResult(com.vip.saturn.job.console.domain.RequestResult) MultipartFile(org.springframework.web.multipart.MultipartFile) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException) Sheet(jxl.Sheet) Cell(jxl.Cell) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 24 with SaturnJobConsoleException

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

the class ExecutorController method checkAndAddJobs.

@RequestMapping(value = "checkAndAddJobs", method = RequestMethod.POST)
public RequestResult checkAndAddJobs(JobConfig jobConfig, HttpServletRequest request) {
    RequestResult requestResult = new RequestResult();
    try {
        jobOperationService.validateJobConfig(jobConfig);
        requestResult = executorService.addJobs(jobConfig);
    } catch (SaturnJobConsoleException e) {
        requestResult.setSuccess(false);
        requestResult.setMessage(e.getMessage());
    } catch (Throwable t) {
        requestResult.setSuccess(false);
        requestResult.setMessage(t.toString());
        LOGGER.error("checkAndAddJobs exception:", t);
    }
    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 25 with SaturnJobConsoleException

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

the class JobController method batchSetPreferExecutors.

@RequestMapping(value = "batchSetPreferExecutors", method = RequestMethod.POST)
public RequestResult batchSetPreferExecutors(final String jobNames, final String newPreferExecutors, HttpServletRequest request) {
    RequestResult requestResult = new RequestResult();
    try {
        if (jobNames == null) {
            throw new SaturnJobConsoleException("The jobNames cannot be null");
        }
        if (newPreferExecutors == null) {
            throw new SaturnJobConsoleException("The new prefer executors cannot be null");
        }
        if (jobNames.trim().length() == 0) {
            throw new SaturnJobConsoleException("The jobNames cannot be empty string");
        }
        jobDimensionService.batchSetPreferExecutors(jobNames.trim(), newPreferExecutors.trim());
        requestResult.setSuccess(true);
    } catch (Exception e) {
        requestResult.setSuccess(false);
        requestResult.setMessage(e.getMessage());
    }
    return requestResult;
}
Also used : RequestResult(com.vip.saturn.job.console.domain.RequestResult) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException) ParseException(java.text.ParseException) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

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