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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations