Search in sources :

Example 6 with RequestResult

use of com.vip.saturn.job.console.domain.RequestResult in project Saturn by vipshop.

the class ContainerController method deleteContainerScaleJob.

@RequestMapping(value = "/deleteContainerScaleJob", method = RequestMethod.POST)
public RequestResult deleteContainerScaleJob(String taskId, String jobName, HttpServletRequest request) {
    RequestResult requestResult = new RequestResult();
    try {
        if (taskId == null) {
            throw new SaturnJobConsoleException("The taskId cannot be null");
        }
        if (jobName == null) {
            throw new SaturnJobConsoleException("The jobName cannot be null");
        }
        containerService.deleteContainerScaleJob(taskId, jobName);
        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 : RequestResult(com.vip.saturn.job.console.domain.RequestResult) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 7 with RequestResult

use of com.vip.saturn.job.console.domain.RequestResult 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 8 with RequestResult

use of com.vip.saturn.job.console.domain.RequestResult 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 9 with RequestResult

use of com.vip.saturn.job.console.domain.RequestResult 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 10 with RequestResult

use of com.vip.saturn.job.console.domain.RequestResult in project Saturn by vipshop.

the class JobConfigController method getExportStatus.

@RequestMapping(value = "jobconfig/getExportStatus", method = RequestMethod.GET)
@ResponseBody
public RequestResult getExportStatus(HttpServletRequest request) {
    RequestResult requestResult = new RequestResult();
    LOGGER.info("getExportStatus");
    try {
        ExportJobConfigPageStatus exportJobConfigPageStatus = jobConfigInitializationService.getStatus();
        requestResult.setSuccess(true);
        requestResult.setObj(exportJobConfigPageStatus);
    } 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) ExportJobConfigPageStatus(com.vip.saturn.job.console.domain.ExportJobConfigPageStatus) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

RequestResult (com.vip.saturn.job.console.domain.RequestResult)49 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)45 SaturnJobConsoleException (com.vip.saturn.job.console.exception.SaturnJobConsoleException)38 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)12 ParseException (java.text.ParseException)11 IOException (java.io.IOException)3 ExecutorProvided (com.vip.saturn.job.console.domain.ExecutorProvided)2 ExportJobConfigPageStatus (com.vip.saturn.job.console.domain.ExportJobConfigPageStatus)2 JobDiffInfo (com.vip.saturn.job.console.domain.JobDiffInfo)2 JobMigrateInfo (com.vip.saturn.job.console.domain.JobMigrateInfo)2 SystemConfig (com.vip.saturn.job.console.mybatis.entity.SystemConfig)2 CuratorFrameworkOp (com.vip.saturn.job.console.repository.zookeeper.CuratorRepository.CuratorFrameworkOp)2 MultipartFile (org.springframework.web.multipart.MultipartFile)2 Gson (com.google.gson.Gson)1 JobBriefInfo (com.vip.saturn.job.console.domain.JobBriefInfo)1 JobConfig (com.vip.saturn.job.console.domain.JobConfig)1 MoveNamespaceBatchStatus (com.vip.saturn.job.console.domain.MoveNamespaceBatchStatus)1 NamespaceZkClusterMappingVo (com.vip.saturn.job.console.domain.NamespaceZkClusterMappingVo)1 RegistryCenterConfiguration (com.vip.saturn.job.console.domain.RegistryCenterConfiguration)1 SaturnJunkData (com.vip.saturn.job.console.domain.SaturnJunkData)1