use of com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException in project Saturn by vipshop.
the class JobOperationRestApiController method constructJobConfig.
private JobConfig constructJobConfig(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.UNKOWN_JOB.equals(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.setTimeoutSeconds(checkAndGetParametersValueAsInteger(configParams, "timeout4Seconds", 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));
return jobConfig;
}
use of com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException in project Saturn by vipshop.
the class NamespaceManagementRestApiControllerTest method queryFailAsNamespaceNotFound.
@Test
public void queryFailAsNamespaceNotFound() throws Exception {
String ns = "testns";
given(registryCenterService.getNamespace(ns)).willThrow(new SaturnJobConsoleHttpException(HttpStatus.NOT_FOUND.value(), "The namespace does not exists."));
MvcResult result = mvc.perform(get("/rest/v1/namespaces/" + ns)).andExpect(status().isNotFound()).andReturn();
String message = fetchErrorMessage(result);
assertEquals("error message not equal", "The namespace does not exists.", message);
}
use of com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException in project Saturn by vipshop.
the class RestApiServiceImplTest method testStopAtOnceFailForJavaJobAsStatusIsNotStopping.
@Test
public void testStopAtOnceFailForJavaJobAsStatusIsNotStopping() throws SaturnJobConsoleException {
// prepare
String jobName = "testJob";
when(jobService.getJobStatus(TEST_NAME_SPACE_NAME, jobName)).thenReturn(JobStatus.READY);
List<JobServer> servers = Lists.newArrayList();
when(jobService.getJobServers(TEST_NAME_SPACE_NAME, jobName)).thenReturn(servers);
// run
try {
restApiService.stopJobAtOnce(TEST_NAME_SPACE_NAME, jobName);
} catch (SaturnJobConsoleHttpException e) {
assertEquals("status code is not 400", 400, e.getStatusCode());
assertEquals("error message is not equals", "job cannot be stopped while its status is READY or RUNNING", e.getMessage());
}
}
use of com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException in project Saturn by vipshop.
the class AlarmRestApiControllerTest method testRaiseAlarmFailWithExpectedException.
@Test
public void testRaiseAlarmFailWithExpectedException() throws Exception {
String customErrMsg = "some exception throws";
willThrow(new SaturnJobConsoleHttpException(400, customErrMsg)).given(restApiService).raiseAlarm(any(String.class), any(String.class), any(String.class), any(Integer.class), any(AlarmInfo.class));
AlarmEntity alarmEntity = new AlarmEntity("job", "exec", "name", "title", "CRITICAL");
MvcResult result = mvc.perform(post("/rest/v1/mydomain/alarms/raise").contentType(MediaType.APPLICATION_JSON).content(alarmEntity.toJSON())).andExpect(status().isBadRequest()).andReturn();
assertEquals("error message not equal", customErrMsg, fetchErrorMessage(result));
}
use of com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException in project Saturn by vipshop.
the class JobOperationRestApiControllerTest method testCreateFailAsSaturnJobHttpExceptionThrows.
@Test
public void testCreateFailAsSaturnJobHttpExceptionThrows() throws Exception {
String customErrMsg = "some exception throws";
willThrow(new SaturnJobConsoleHttpException(400, customErrMsg)).given(restApiService).createJob(any(String.class), any(JobConfig.class));
JobEntity jobEntity = constructJobEntity("job1");
MvcResult result = mvc.perform(post("/rest/v1/domain/jobs").contentType(MediaType.APPLICATION_JSON).content(jobEntity.toJSON())).andExpect(status().isBadRequest()).andReturn();
String message = fetchErrorMessage(result);
assertEquals("error message not equal", customErrMsg, message);
}
Aggregations