Search in sources :

Example 36 with RequestResult

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

Example 37 with 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;
}
Also used : RequestResult(com.vip.saturn.job.console.domain.RequestResult) ExecutorProvided(com.vip.saturn.job.console.domain.ExecutorProvided) ParseException(java.text.ParseException) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 38 with 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;
}
Also used : RequestResult(com.vip.saturn.job.console.domain.RequestResult) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException) ParseException(java.text.ParseException) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 39 with 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;
}
Also used : RequestResult(com.vip.saturn.job.console.domain.RequestResult) TimeZone(java.util.TimeZone) HashMap(java.util.HashMap) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) CronExpression(com.vip.saturn.job.console.utils.CronExpression) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 40 with RequestResult

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;
}
Also used : RequestResult(com.vip.saturn.job.console.domain.RequestResult) ExecutorProvided(com.vip.saturn.job.console.domain.ExecutorProvided) ParseException(java.text.ParseException) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

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