use of com.vip.saturn.job.console.domain.RequestResult in project Saturn by vipshop.
the class JobConfigController method exportAllConfigToDb.
@RequestMapping(value = "jobconfig/exportAllConfigToDb", method = RequestMethod.POST)
@ResponseBody
public RequestResult exportAllConfigToDb(HttpServletRequest request) {
LOGGER.info("exportAllConfigToDb");
RequestResult requestResult = new RequestResult();
try {
ExportJobConfigPageStatus exportJobConfigPageStatus = jobConfigInitializationService.getStatus();
if (exportJobConfigPageStatus != null && exportJobConfigPageStatus.isExported() == false) {
requestResult.setSuccess(false);
requestResult.setMessage("正在导出配置中,如有必要,请稍后再试!");
return requestResult;
}
jobConfigInitializationService.exportAllToDb(null);
requestResult.setSuccess(true);
} catch (Throwable t) {
LOGGER.error(t.getMessage(), 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 JobController method getAllExecutors.
/**
* 获取所有的executor作为优先候选列表
*/
@RequestMapping(value = "getAllExecutors", method = RequestMethod.GET)
public RequestResult getAllExecutors(String jobName) {
RequestResult requestResult = new RequestResult();
try {
List<ExecutorProvided> allExecutors = jobDimensionService.getAllExecutors(jobName);
requestResult.setObj(allExecutors);
requestResult.setSuccess(true);
} catch (Exception e) {
requestResult.setSuccess(false);
requestResult.setMessage(e.toString());
}
return requestResult;
}
use of com.vip.saturn.job.console.domain.RequestResult in project Saturn by vipshop.
the class JobController method batchMigrateJobNewTask.
@RequestMapping(value = "batchMigrateJobNewTask", method = RequestMethod.POST)
public RequestResult batchMigrateJobNewTask(final String jobNames, final String newTask, HttpServletRequest request) {
RequestResult requestResult = new RequestResult();
try {
if (jobNames == null) {
throw new SaturnJobConsoleException("The jobNames cannot be null");
}
if (newTask == null) {
throw new SaturnJobConsoleException("The new task cannot be null");
}
if (jobNames.trim().length() == 0) {
throw new SaturnJobConsoleException("The jobNames cannot be empty string");
}
if (newTask.trim().length() == 0) {
throw new SaturnJobConsoleException("The new task cannot be empty string");
}
jobDimensionService.batchMigrateJobNewTask(jobNames.trim(), newTask.trim());
requestResult.setSuccess(true);
} catch (Exception e) {
requestResult.setSuccess(false);
requestResult.setMessage(e.getMessage());
}
return requestResult;
}
use of com.vip.saturn.job.console.domain.RequestResult in project Saturn by vipshop.
the class JobController method checkAndForecastCron.
@RequestMapping(value = "checkAndForecastCron", method = RequestMethod.POST)
public RequestResult checkAndForecastCron(final String timeZone, final String cron, HttpServletRequest request) {
RequestResult result = new RequestResult();
if (timeZone == null || timeZone.trim().isEmpty()) {
result.setSuccess(false);
result.setMessage("timeZone cannot be null or empty");
return result;
}
if (cron == null || cron.trim().isEmpty()) {
result.setSuccess(false);
result.setMessage("cron cannot be null or empty");
return result;
}
String timeZoneTrim = timeZone.trim();
String cronTrim = cron.trim();
if (!SaturnConstants.TIME_ZONE_IDS.contains(timeZoneTrim)) {
result.setSuccess(false);
result.setMessage("timeZone is not available");
return result;
}
try {
TimeZone tz = TimeZone.getTimeZone(timeZoneTrim);
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
dateFormat.setTimeZone(tz);
CronExpression cronExpression = new CronExpression(cronTrim);
cronExpression.setTimeZone(tz);
Map<String, String> obj = new HashMap<>();
obj.put("timeZone", timeZoneTrim);
StringBuilder sb = new StringBuilder(100);
Date now = new Date();
for (int i = 0; i < 10; i++) {
Date next = cronExpression.getNextValidTimeAfter(now);
if (next != null) {
sb.append(dateFormat.format(next)).append("<br>");
now = next;
}
}
if (sb.length() == 0) {
obj.put("times", "Cron maybe describe the past time, the job will never be executed");
} else {
if (sb.toString().split("<br>") != null && sb.toString().split("<br>").length >= 10) {
sb.append("......");
}
obj.put("times", sb.toString());
}
result.setSuccess(true);
result.setObj(obj);
} catch (ParseException e) {
result.setSuccess(false);
result.setMessage(e.toString());
return result;
}
return result;
}
use of com.vip.saturn.job.console.domain.RequestResult in project Saturn by vipshop.
the class JobController method batchSetPreferExecutorsEnabled.
@RequestMapping(value = "batchSetPreferExecutorsEnabled", method = RequestMethod.GET)
public RequestResult batchSetPreferExecutorsEnabled(HttpServletRequest request) {
RequestResult requestResult = new RequestResult();
try {
List<ExecutorProvided> allExecutorsOfNamespace = jobDimensionService.getAllExecutorsOfNamespace();
requestResult.setSuccess(true);
requestResult.setObj(allExecutorsOfNamespace);
} catch (Exception e) {
requestResult.setSuccess(false);
requestResult.setMessage(e.getMessage());
}
return requestResult;
}
Aggregations