Search in sources :

Example 36 with JobConfig

use of com.vip.saturn.job.console.domain.JobConfig in project Saturn by vipshop.

the class InitJobFailAlarmIT method testC_InitFailOfRuntimeExceptionJob.

@Test
public void testC_InitFailOfRuntimeExceptionJob() throws Exception {
    String executorName = startOneNewExecutorList().getExecutorName();
    Thread.sleep(1000);
    JobConfig jobConfig = new JobConfig();
    jobConfig.setJobName("testC_InitFailOfRuntimeExceptionJob");
    jobConfig.setCron("*/2 * * * * ?");
    jobConfig.setJobType(JobType.JAVA_JOB.toString());
    jobConfig.setJobClass(InitFailOfRuntimeExceptionJob.class.getCanonicalName());
    jobConfig.setShardingTotalCount(1);
    jobConfig.setShardingItemParameters("0=0");
    addJob(jobConfig);
    Thread.sleep(2000);
    assertThat(InitNewJobService.containsJobInitFailedRecord(executorName, jobConfig.getJobName(), "java.lang.RuntimeException: RuntimeException!!!")).isTrue();
    removeJob(jobConfig.getJobName());
}
Also used : JobConfig(com.vip.saturn.job.console.domain.JobConfig)

Example 37 with JobConfig

use of com.vip.saturn.job.console.domain.JobConfig in project Saturn by vipshop.

the class TimeoutJobIT method test_A_JavaJob.

@Test
public void test_A_JavaJob() throws Exception {
    final int shardCount = 3;
    final String jobName = "test_A_JavaJob";
    for (int i = 0; i < shardCount; i++) {
        String key = jobName + "_" + i;
        LongtimeJavaJob.JobStatus status = new LongtimeJavaJob.JobStatus();
        status.runningCount = 0;
        status.sleepSeconds = 30;
        status.finished = false;
        status.timeout = false;
        status.beforeTimeout = false;
        LongtimeJavaJob.statusMap.put(key, status);
    }
    JobConfig jobConfig = new JobConfig();
    jobConfig.setJobName(jobName);
    jobConfig.setCron("9 9 9 9 9 ? 2099");
    jobConfig.setJobType(JobType.JAVA_JOB.toString());
    jobConfig.setJobClass(LongtimeJavaJob.class.getCanonicalName());
    jobConfig.setTimeoutSeconds(3);
    jobConfig.setShardingTotalCount(shardCount);
    jobConfig.setShardingItemParameters("0=0,1=1,2=2");
    addJob(jobConfig);
    Thread.sleep(1000);
    enableJob(jobConfig.getJobName());
    Thread.sleep(1000);
    runAtOnce(jobName);
    try {
        waitForFinish(new FinishCheck() {

            @Override
            public boolean isOk() {
                Collection<LongtimeJavaJob.JobStatus> values = LongtimeJavaJob.statusMap.values();
                for (LongtimeJavaJob.JobStatus status : values) {
                    if (!status.finished || !status.timeout || !status.beforeTimeout) {
                        return false;
                    }
                }
                return true;
            }
        }, 30);
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
    try {
        waitForFinish(new FinishCheck() {

            @Override
            public boolean isOk() {
                for (int j = 0; j < shardCount; j++) {
                    if (!regCenter.isExisted(JobNodePath.getNodeFullPath(jobName, ExecutionNode.getTimeoutNode(j)))) {
                        return false;
                    }
                }
                return true;
            }
        }, 10);
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
    Thread.sleep(1000);
    for (int j = 0; j < shardCount; j++) {
        String key = jobName + "_" + j;
        LongtimeJavaJob.JobStatus status = LongtimeJavaJob.statusMap.get(key);
        assertThat(status.runningCount).isEqualTo(0);
        assertThat(regCenter.isExisted(JobNodePath.getNodeFullPath(jobName, ExecutionNode.getTimeoutNode(j)))).isEqualTo(true);
        assertThat(regCenter.isExisted(JobNodePath.getNodeFullPath(jobName, ExecutionNode.getCompletedNode(j)))).isEqualTo(true);
    }
    disableJob(jobConfig.getJobName());
    Thread.sleep(1000);
    removeJob(jobConfig.getJobName());
    LongtimeJavaJob.statusMap.clear();
}
Also used : FinishCheck(com.vip.saturn.it.base.FinishCheck) Collection(java.util.Collection) JobConfig(com.vip.saturn.job.console.domain.JobConfig) LongtimeJavaJob(com.vip.saturn.it.job.LongtimeJavaJob)

Example 38 with JobConfig

use of com.vip.saturn.job.console.domain.JobConfig in project Saturn by vipshop.

the class JobOperationRestApiController method update.

@Audit(type = AuditType.REST)
@RequestMapping(value = "/{namespace}/jobs/{jobName}", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public ResponseEntity<Object> update(@PathVariable("namespace") String namespace, @PathVariable String jobName, @RequestBody Map<String, Object> reqParams) throws SaturnJobConsoleException {
    try {
        JobConfig jobConfig = constructJobConfigOfUpdate(namespace, jobName, reqParams);
        restApiService.updateJob(namespace, jobName, jobConfig);
        return new ResponseEntity<>(HttpStatus.OK);
    } catch (SaturnJobConsoleException e) {
        throw e;
    } catch (Exception e) {
        throw new SaturnJobConsoleHttpException(HttpStatus.INTERNAL_SERVER_ERROR.value(), e.getMessage(), e);
    }
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException) SaturnJobConsoleHttpException(com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException) JobConfig(com.vip.saturn.job.console.domain.JobConfig) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException) SaturnJobConsoleHttpException(com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException) Audit(com.vip.saturn.job.console.aop.annotation.Audit)

Example 39 with JobConfig

use of com.vip.saturn.job.console.domain.JobConfig in project Saturn by vipshop.

the class JobOperationRestApiController method constructJobConfigOfCreate.

private JobConfig constructJobConfigOfCreate(String namespace, Map<String, Object> reqParams) throws SaturnJobConsoleException {
    checkMissingParameter("namespace", namespace);
    if (!reqParams.containsKey("jobConfig")) {
        throw new SaturnJobConsoleHttpException(HttpStatus.BAD_REQUEST.value(), String.format(INVALID_REQUEST_MSG, "jobConfig", "cannot be blank"));
    }
    JobConfig jobConfig = new JobConfig();
    Map<String, Object> configParams = (Map<String, Object>) reqParams.get("jobConfig");
    jobConfig.setJobName(checkAndGetParametersValueAsString(reqParams, "jobName", true));
    jobConfig.setDescription(checkAndGetParametersValueAsString(reqParams, "description", false));
    jobConfig.setChannelName(checkAndGetParametersValueAsString(configParams, "channelName", false));
    jobConfig.setCron(checkAndGetParametersValueAsString(configParams, "cron", false));
    jobConfig.setJobClass(checkAndGetParametersValueAsString(configParams, "jobClass", false));
    jobConfig.setJobParameter(checkAndGetParametersValueAsString(configParams, "jobParameter", false));
    String jobType = checkAndGetParametersValueAsString(configParams, "jobType", true);
    if (JobType.UNKNOWN_JOB == JobType.getJobType(jobType)) {
        throw new SaturnJobConsoleHttpException(HttpStatus.BAD_REQUEST.value(), String.format(INVALID_REQUEST_MSG, "jobType", "is malformed"));
    }
    jobConfig.setJobType(jobType);
    jobConfig.setLoadLevel(checkAndGetParametersValueAsInteger(configParams, "loadLevel", false));
    jobConfig.setLocalMode(checkAndGetParametersValueAsBoolean(configParams, "localMode", false));
    jobConfig.setPausePeriodDate(checkAndGetParametersValueAsString(configParams, "pausePeriodDate", false));
    jobConfig.setPausePeriodTime(checkAndGetParametersValueAsString(configParams, "pausePeriodTime", false));
    jobConfig.setPreferList(checkAndGetParametersValueAsString(configParams, "preferList", false));
    jobConfig.setQueueName(checkAndGetParametersValueAsString(configParams, "queueName", false));
    jobConfig.setShardingItemParameters(checkAndGetParametersValueAsString(configParams, "shardingItemParameters", true));
    jobConfig.setShardingTotalCount(checkAndGetParametersValueAsInteger(configParams, "shardingTotalCount", true));
    jobConfig.setTimeout4AlarmSeconds(checkAndGetParametersValueAsInteger(configParams, "timeout4AlarmSeconds", false));
    jobConfig.setUseDispreferList(checkAndGetParametersValueAsBoolean(configParams, "useDispreferList", false));
    jobConfig.setUseSerial(checkAndGetParametersValueAsBoolean(configParams, "useSerial", false));
    jobConfig.setJobDegree(checkAndGetParametersValueAsInteger(configParams, "jobDegree", false));
    jobConfig.setDependencies(checkAndGetParametersValueAsString(configParams, "dependencies", false));
    jobConfig.setTimeZone(checkAndGetParametersValueAsString(configParams, "timeZone", false));
    jobConfig.setTimeoutSeconds(checkAndGetParametersValueAsInteger(configParams, "timeoutSeconds", false));
    jobConfig.setProcessCountIntervalSeconds(checkAndGetParametersValueAsInteger(configParams, "processCountIntervalSeconds", false));
    jobConfig.setGroups(checkAndGetParametersValueAsString(configParams, "groups", false));
    jobConfig.setShowNormalLog(checkAndGetParametersValueAsBoolean(configParams, "showNormalLog", false));
    jobConfig.setFailover(checkAndGetParametersValueAsBoolean(configParams, "failover", false));
    jobConfig.setRerun(checkAndGetParametersValueAsBoolean(configParams, "rerun", false));
    jobConfig.setUpStream(checkAndGetParametersValueAsString(configParams, "upStream", false));
    jobConfig.setDownStream(checkAndGetParametersValueAsString(configParams, "downStream", false));
    return jobConfig;
}
Also used : SaturnJobConsoleHttpException(com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException) Map(java.util.Map) JobConfig(com.vip.saturn.job.console.domain.JobConfig)

Example 40 with JobConfig

use of com.vip.saturn.job.console.domain.JobConfig in project Saturn by vipshop.

the class JobOperationRestApiController method create.

@Audit(type = AuditType.REST)
@RequestMapping(value = "/{namespace}/jobs", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public ResponseEntity<Object> create(@PathVariable("namespace") String namespace, @RequestBody Map<String, Object> reqParams) throws SaturnJobConsoleException {
    try {
        JobConfig jobConfig = constructJobConfigOfCreate(namespace, reqParams);
        restApiService.createJob(namespace, jobConfig);
        return new ResponseEntity<>(HttpStatus.CREATED);
    } catch (SaturnJobConsoleException e) {
        throw e;
    } catch (Exception e) {
        throw new SaturnJobConsoleHttpException(HttpStatus.INTERNAL_SERVER_ERROR.value(), e.getMessage(), e);
    }
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException) SaturnJobConsoleHttpException(com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException) JobConfig(com.vip.saturn.job.console.domain.JobConfig) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException) SaturnJobConsoleHttpException(com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException) Audit(com.vip.saturn.job.console.aop.annotation.Audit)

Aggregations

JobConfig (com.vip.saturn.job.console.domain.JobConfig)89 FinishCheck (com.vip.saturn.it.base.FinishCheck)45 SimpleJavaJob (com.vip.saturn.it.job.SimpleJavaJob)37 Test (org.junit.Test)35 Main (com.vip.saturn.job.executor.Main)31 LongtimeJavaJob (com.vip.saturn.it.job.LongtimeJavaJob)12 SaturnJobConsoleException (com.vip.saturn.job.console.exception.SaturnJobConsoleException)10 SaturnJobConsoleHttpException (com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException)9 List (java.util.List)6 Collection (java.util.Collection)5 Map (java.util.Map)4 InitByGroupsJob (com.vip.saturn.it.job.InitByGroupsJob)3 CuratorRepository (com.vip.saturn.job.console.repository.zookeeper.CuratorRepository)3 ArrayList (java.util.ArrayList)3 ResponseEntity (org.springframework.http.ResponseEntity)3 Audit (com.vip.saturn.job.console.aop.annotation.Audit)2 JobDiffInfo (com.vip.saturn.job.console.domain.JobDiffInfo)2 RestApiJobConfig (com.vip.saturn.job.console.domain.RestApiJobConfig)2 JobConfig4DB (com.vip.saturn.job.console.mybatis.entity.JobConfig4DB)2 ParseException (java.text.ParseException)2