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