Search in sources :

Example 6 with JobDiffInfo

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

the class ZKDBDiffRestApiController method diff.

@RequestMapping(value = "/diff", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
@ResponseBody
public ResponseEntity<Object> diff(String zkcluster, HttpServletRequest request) throws SaturnJobConsoleHttpException {
    try {
        checkMissingParameter("zkcluster", zkcluster);
        List<JobDiffInfo> resultList = zkDBDiffService.diffByCluster(zkcluster);
        return new ResponseEntity<Object>(resultList, HttpStatus.OK);
    } catch (Exception e) {
        throw new SaturnJobConsoleHttpException(HttpStatus.INTERNAL_SERVER_ERROR.value(), e.getMessage(), e);
    }
}
Also used : JobDiffInfo(com.vip.saturn.job.console.domain.JobDiffInfo) ResponseEntity(org.springframework.http.ResponseEntity) SaturnJobConsoleHttpException(com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException) SaturnJobConsoleHttpException(com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 7 with JobDiffInfo

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

the class ZkDBDiffServiceImpl method getJobNamesWhichInZKOnly.

private List<JobDiffInfo> getJobNamesWhichInZKOnly(String namespace, CuratorRepository.CuratorFrameworkOp zkClient, Set<String> jobNamesInDb) throws SaturnJobConsoleException {
    List<JobDiffInfo> jobsOnlyInZK = Lists.newArrayList();
    List<String> jobNamesInZk = jobDimensionService.getAllJobs(zkClient);
    for (String name : jobNamesInZk) {
        if (jobNamesInDb == null || jobNamesInDb.isEmpty() || !jobNamesInDb.contains(name)) {
            jobsOnlyInZK.add(new JobDiffInfo(namespace, name, JobDiffInfo.DiffType.ZK_ONLY, Lists.<JobDiffInfo.ConfigDiffInfo>newArrayList()));
        }
    }
    return jobsOnlyInZK;
}
Also used : JobDiffInfo(com.vip.saturn.job.console.domain.JobDiffInfo)

Example 8 with JobDiffInfo

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

the class ZkDBDiffServiceImpl method getJobNamesWhichInZKOnly.

private List<JobDiffInfo> getJobNamesWhichInZKOnly(String namespace, Set<String> jobNamesInDb) throws SaturnJobConsoleException {
    List<JobDiffInfo> jobsOnlyInZK = Lists.newArrayList();
    List<String> jobNamesInZk = jobService.getAllJobNamesFromZK(namespace);
    for (String name : jobNamesInZk) {
        if (jobNamesInDb == null || jobNamesInDb.isEmpty() || !jobNamesInDb.contains(name)) {
            jobsOnlyInZK.add(new JobDiffInfo(namespace, name, JobDiffInfo.DiffType.ZK_ONLY, Lists.<JobDiffInfo.ConfigDiffInfo>newArrayList()));
        }
    }
    return jobsOnlyInZK;
}
Also used : JobDiffInfo(com.vip.saturn.job.console.domain.JobDiffInfo)

Example 9 with JobDiffInfo

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

the class ZkDBDiffServiceImpl method diffByJob.

@Override
public JobDiffInfo diffByJob(String namespace, String jobName) throws SaturnJobConsoleException {
    CuratorRepository.CuratorFrameworkOp zkClient;
    try {
        zkClient = initCuratorClient(namespace);
        if (zkClient == null) {
            return null;
        }
        log.info("start to diff job:{}", jobName);
        JobConfig4DB dbJobConfig = currentJobConfigService.findConfigByNamespaceAndJobName(namespace, jobName);
        JobConfig zkJobConfig = jobService.getJobConfigFromZK(namespace, jobName);
        if (dbJobConfig == null) {
            if (zkJobConfig != null) {
                return new JobDiffInfo(namespace, jobName, JobDiffInfo.DiffType.ZK_ONLY, Lists.<JobDiffInfo.ConfigDiffInfo>newArrayList());
            } else {
                return null;
            }
        }
        if (zkJobConfig == null) {
            return new JobDiffInfo(namespace, jobName, JobDiffInfo.DiffType.DB_ONLY, Lists.<JobDiffInfo.ConfigDiffInfo>newArrayList());
        }
        // diff only when dbJobConfig and zkJobConfig both not null
        return diff(namespace, dbJobConfig, zkJobConfig, true);
    } catch (Exception e) {
        log.error("exception throws during diff by namespace [{}] and job [{}]", namespace, jobName, e);
        throw new SaturnJobConsoleException(e);
    }
}
Also used : JobDiffInfo(com.vip.saturn.job.console.domain.JobDiffInfo) CuratorRepository(com.vip.saturn.job.console.repository.zookeeper.CuratorRepository) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException) JobConfig4DB(com.vip.saturn.job.console.mybatis.entity.JobConfig4DB) JobConfig(com.vip.saturn.job.console.domain.JobConfig) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException)

Aggregations

JobDiffInfo (com.vip.saturn.job.console.domain.JobDiffInfo)9 SaturnJobConsoleException (com.vip.saturn.job.console.exception.SaturnJobConsoleException)5 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)4 JobConfig (com.vip.saturn.job.console.domain.JobConfig)2 RequestResult (com.vip.saturn.job.console.domain.RequestResult)2 SaturnJobConsoleHttpException (com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException)2 JobConfig4DB (com.vip.saturn.job.console.mybatis.entity.JobConfig4DB)2 CuratorRepository (com.vip.saturn.job.console.repository.zookeeper.CuratorRepository)2 IOException (java.io.IOException)2 ResponseEntity (org.springframework.http.ResponseEntity)2 Audit (com.vip.saturn.job.console.aop.annotation.Audit)1 List (java.util.List)1 Callable (java.util.concurrent.Callable)1 Future (java.util.concurrent.Future)1