Search in sources :

Example 1 with RestApiJobInfo

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

the class RestApiServiceImpl method constructJobInfo.

private RestApiJobInfo constructJobInfo(CuratorRepository.CuratorFrameworkOp curatorFrameworkOp, String job) {
    RestApiJobInfo restApiJobInfo = new RestApiJobInfo();
    restApiJobInfo.setJobName(job);
    // 设置作业配置信息
    setJobConfig(curatorFrameworkOp, restApiJobInfo, job);
    // 设置运行状态
    setRunningStatus(curatorFrameworkOp, restApiJobInfo, job);
    // 设置统计信息
    RestApiJobStatistics restApiJobStatistics = new RestApiJobStatistics();
    setStatics(curatorFrameworkOp, restApiJobStatistics, job);
    restApiJobInfo.setStatistics(restApiJobStatistics);
    return restApiJobInfo;
}
Also used : RestApiJobStatistics(com.vip.saturn.job.console.domain.RestApiJobStatistics) RestApiJobInfo(com.vip.saturn.job.console.domain.RestApiJobInfo)

Example 2 with RestApiJobInfo

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

the class JobOperationRestApiController method queryAll.

@RequestMapping(value = "/{namespace}/jobs", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public ResponseEntity<Object> queryAll(@PathVariable("namespace") String namespace) throws SaturnJobConsoleException {
    HttpHeaders httpHeaders = new HttpHeaders();
    try {
        checkMissingParameter("namespace", namespace);
        List<RestApiJobInfo> restApiJobInfos = restApiService.getRestApiJobInfos(namespace);
        return new ResponseEntity<Object>(restApiJobInfos, httpHeaders, HttpStatus.OK);
    } catch (SaturnJobConsoleException e) {
        throw e;
    } catch (Exception e) {
        throw new SaturnJobConsoleHttpException(HttpStatus.INTERNAL_SERVER_ERROR.value(), e.getMessage(), e);
    }
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) ResponseEntity(org.springframework.http.ResponseEntity) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException) SaturnJobConsoleHttpException(com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException) RestApiJobInfo(com.vip.saturn.job.console.domain.RestApiJobInfo) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException) SaturnJobConsoleHttpException(com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with RestApiJobInfo

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

the class JobOperationRestApiController method query.

@RequestMapping(value = "/{namespace}/jobs/{jobName}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public ResponseEntity<Object> query(@PathVariable("namespace") String namespace, @PathVariable("jobName") String jobName) throws SaturnJobConsoleException {
    HttpHeaders httpHeaders = new HttpHeaders();
    try {
        checkMissingParameter("namespace", namespace);
        checkMissingParameter("jobName", jobName);
        RestApiJobInfo restAPIJobInfo = restApiService.getRestAPIJobInfo(namespace, jobName);
        return new ResponseEntity<Object>(restAPIJobInfo, httpHeaders, HttpStatus.OK);
    } catch (SaturnJobConsoleException e) {
        throw e;
    } catch (Exception e) {
        throw new SaturnJobConsoleHttpException(HttpStatus.INTERNAL_SERVER_ERROR.value(), e.getMessage(), e);
    }
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) ResponseEntity(org.springframework.http.ResponseEntity) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException) SaturnJobConsoleHttpException(com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException) RestApiJobInfo(com.vip.saturn.job.console.domain.RestApiJobInfo) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException) SaturnJobConsoleHttpException(com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 4 with RestApiJobInfo

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

the class JobOperationRestApiControllerTest method testQuerySuccessfully.

@Test
public void testQuerySuccessfully() throws Exception {
    String jobName = "job1";
    RestApiJobInfo jobInfo = constructJobInfo("domain", jobName);
    given(restApiService.getRestAPIJobInfo("domain", jobName)).willReturn(jobInfo);
    MvcResult result = mvc.perform(get("/rest/v1/domain/jobs/" + jobName)).andExpect(status().isOk()).andReturn();
    String body = result.getResponse().getContentAsString();
    Map<String, Object> resultMap = JSONObject.parseObject(body, Map.class);
    assertEquals("jobname not equal", jobName, resultMap.get("jobName"));
    assertEquals("description not equal", jobInfo.getDescription(), resultMap.get("description"));
    Map<String, Object> jobConfigMap = (Map<String, Object>) resultMap.get("jobConfig");
    assertEquals("cron not equal", jobInfo.getJobConfig().getCron(), jobConfigMap.get("cron"));
    Map<String, Object> statisticsMap = (Map<String, Object>) resultMap.get("statistics");
    assertEquals("nextFireTime not equal", jobInfo.getStatistics().getNextFireTime(), new Long((Integer) statisticsMap.get("nextFireTime")));
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) MvcResult(org.springframework.test.web.servlet.MvcResult) Map(java.util.Map) RestApiJobInfo(com.vip.saturn.job.console.domain.RestApiJobInfo) Test(org.junit.Test) WebMvcTest(org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest) AbstractSaturnConsoleTest(com.vip.saturn.job.console.AbstractSaturnConsoleTest)

Example 5 with RestApiJobInfo

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

the class JobOperationRestApiControllerTest method constructJobInfo.

private RestApiJobInfo constructJobInfo(String domain, String jobName) {
    RestApiJobInfo jobInfo = new RestApiJobInfo();
    jobInfo.setJobName(jobName);
    jobInfo.setEnabled(true);
    jobInfo.setDescription("this is a decription of " + jobName);
    RestApiJobConfig jobConfig = new RestApiJobConfig();
    jobConfig.setCron("0 */1 * * * ?");
    jobInfo.setJobConfig(jobConfig);
    RestApiJobStatistics statistics = new RestApiJobStatistics();
    statistics.setNextFireTime(1234567L);
    jobInfo.setStatistics(statistics);
    return jobInfo;
}
Also used : RestApiJobStatistics(com.vip.saturn.job.console.domain.RestApiJobStatistics) RestApiJobConfig(com.vip.saturn.job.console.domain.RestApiJobConfig) RestApiJobInfo(com.vip.saturn.job.console.domain.RestApiJobInfo)

Aggregations

RestApiJobInfo (com.vip.saturn.job.console.domain.RestApiJobInfo)5 RestApiJobStatistics (com.vip.saturn.job.console.domain.RestApiJobStatistics)2 SaturnJobConsoleException (com.vip.saturn.job.console.exception.SaturnJobConsoleException)2 SaturnJobConsoleHttpException (com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException)2 HttpHeaders (org.springframework.http.HttpHeaders)2 ResponseEntity (org.springframework.http.ResponseEntity)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 JSONObject (com.alibaba.fastjson.JSONObject)1 AbstractSaturnConsoleTest (com.vip.saturn.job.console.AbstractSaturnConsoleTest)1 RestApiJobConfig (com.vip.saturn.job.console.domain.RestApiJobConfig)1 Map (java.util.Map)1 Test (org.junit.Test)1 WebMvcTest (org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest)1 MvcResult (org.springframework.test.web.servlet.MvcResult)1