use of com.vip.saturn.job.console.domain.RequestResult 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;
}
use of com.vip.saturn.job.console.domain.RequestResult in project Saturn by vipshop.
the class HttpClientUtils method toGuiResponseEntity.
public static GuiResponseEntity toGuiResponseEntity(ResponseEntity responseEntity) {
RequestResult requestResult = new Gson().fromJson(responseEntity.getEntity(), RequestResult.class);
GuiResponseEntity guiResponseEntity = new GuiResponseEntity();
guiResponseEntity.setStatusCode(responseEntity.getStatusCode());
guiResponseEntity.setRequestResult(requestResult);
return guiResponseEntity;
}
use of com.vip.saturn.job.console.domain.RequestResult in project Saturn by vipshop.
the class ExecutorServiceImpl method addJobs.
@Override
public RequestResult addJobs(JobConfig jobConfig) {
RequestResult requestResult = new RequestResult();
requestResult.setMessage("");
requestResult.setSuccess(true);
try {
CuratorRepository.CuratorFrameworkOp curatorFrameworkOp = curatorRepository.inSessionClient();
String jobName = jobConfig.getJobName();
if (!curatorFrameworkOp.checkExists(JobNodePath.getConfigNodePath(jobName))) {
int maxJobNum = getMaxJobNum();
if (jobIncExceeds(maxJobNum, 1)) {
requestResult.setSuccess(false);
String errorMsg = String.format("总作业数超过最大限制(%d),作业名%s创建失败", maxJobNum, jobName);
requestResult.setMessage(errorMsg);
} else {
if (jobConfig.getIsCopyJob()) {
// 复制作业
jobOperationService.copyAndPersistJob(jobConfig, curatorFrameworkOp);
} else {
// 新增作业
jobOperationService.persistJob(jobConfig, curatorFrameworkOp);
}
}
} else {
requestResult.setSuccess(false);
requestResult.setMessage("作业名" + jobName + "已经存在");
}
} catch (Throwable t) {
log.error(t.getMessage(), t);
requestResult.setSuccess(false);
requestResult.setMessage(t.getMessage());
}
return requestResult;
}
use of com.vip.saturn.job.console.domain.RequestResult in project Saturn by vipshop.
the class RegistryCenterServiceImpl method refreshRegCenter.
@Override
public RequestResult refreshRegCenter() {
RequestResult result = new RequestResult();
if (refreshingRegCenter.compareAndSet(false, true)) {
try {
log.info("begin to refresh registry center");
refreshAll();
result.setSuccess(true);
} catch (Throwable t) {
log.error(t.getMessage(), t);
result.setSuccess(false);
result.setMessage(ExceptionUtils.getMessage(t));
} finally {
log.info("end refresh registry center");
refreshingRegCenter.set(false);
}
} else {
result.setSuccess(false);
result.setMessage("refreshing, try it later!");
}
return result;
}
use of com.vip.saturn.job.console.domain.RequestResult in project Saturn by vipshop.
the class ContainerController method addContainerScaleJob.
@RequestMapping(value = "/addContainerScaleJob", method = RequestMethod.POST)
public RequestResult addContainerScaleJob(String taskId, String jobDesc, Integer instances, String timeZone, String cron, HttpServletRequest request) {
RequestResult requestResult = new RequestResult();
try {
if (taskId == null) {
throw new SaturnJobConsoleException("The taskId cannot be null");
}
if (jobDesc == null) {
throw new SaturnJobConsoleException("The jobDesc cannot be null");
}
if (instances == null || instances < 0) {
throw new SaturnJobConsoleException("Please input the positive instances");
}
if (timeZone == null || timeZone.trim().length() == 0) {
throw new SaturnJobConsoleException("The timeZone cannot be null or empty");
}
if (cron == null || cron.trim().length() == 0) {
throw new SaturnJobConsoleException("The cron cannot be null or empty");
}
try {
CronExpression.validateExpression(cron);
} catch (ParseException e) {
throw new SaturnJobConsoleException("The cron is not valid, " + e.toString());
}
containerService.addContainerScaleJob(taskId, jobDesc, instances, timeZone, cron);
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;
}
Aggregations