Search in sources :

Example 1 with JobDiffInfo

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

the class ZKDBDiffController method diffByCluster.

/**
 * 按照zk集群,对比zk和db的数据差异。<br> 如果console和zk集群不是在同一机房,则会将调用zk所属机房的console rest api去进行对比,如果对比失败,则继续在本机房进行对比;
 *
 * @param request
 * @param zkCluster
 * @return
 */
@RequestMapping(value = "zk_db_diff/diffByCluster", method = RequestMethod.GET)
@ResponseBody
public RequestResult diffByCluster(HttpServletRequest request, String zkCluster) {
    RequestResult requestResult = new RequestResult();
    List<JobDiffInfo> resultList = null;
    try {
        if (!ZkClusterMappingUtils.isCurrentConsoleInTheSameIdc(systemConfigService, zkCluster)) {
            resultList = relayDiffIfPossible(zkCluster);
        } else {
            resultList = zkDBDiffService.diffByCluster(zkCluster);
        }
        requestResult.setSuccess(true);
        requestResult.setObj(resultList);
    } catch (Exception e) {
        requestResult.setSuccess(false);
        requestResult.setMessage(e.toString());
    }
    return requestResult;
}
Also used : RequestResult(com.vip.saturn.job.console.domain.RequestResult) JobDiffInfo(com.vip.saturn.job.console.domain.JobDiffInfo) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException) IOException(java.io.IOException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 2 with JobDiffInfo

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

the class ZkDbDiffRestApiController method diff.

@Audit(type = AuditType.REST)
@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) Audit(com.vip.saturn.job.console.aop.annotation.Audit) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 3 with JobDiffInfo

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

the class ZkDBDiffServiceImpl method diffByCluster.

@Override
public List<JobDiffInfo> diffByCluster(String clusterKey) throws SaturnJobConsoleException {
    long startTime = System.currentTimeMillis();
    List<String> namespaces = namespaceZkClusterMapping4SqlService.getAllNamespacesOfCluster(clusterKey);
    List<Callable<List<JobDiffInfo>>> callableList = Lists.newArrayList();
    for (final String namespace : namespaces) {
        Callable<List<JobDiffInfo>> callable = new Callable<List<JobDiffInfo>>() {

            @Override
            public List<JobDiffInfo> call() throws Exception {
                return diffByNamespace(namespace);
            }
        };
        callableList.add(callable);
    }
    List<JobDiffInfo> resultList = Lists.newArrayList();
    try {
        List<Future<List<JobDiffInfo>>> futures = diffExecutorService.invokeAll(callableList);
        for (Future<List<JobDiffInfo>> future : futures) {
            List<JobDiffInfo> jobDiffInfos = future.get();
            if (jobDiffInfos != null && !jobDiffInfos.isEmpty()) {
                resultList.addAll(jobDiffInfos);
            }
        }
    } catch (InterruptedException e) {
        // NOSONAR
        log.warn("the thread is interrupted", e);
        throw new SaturnJobConsoleException("the diff thread is interrupted", e);
    } catch (Exception e) {
        log.error("exception happens during execute diff operation", e);
        throw new SaturnJobConsoleException(e);
    }
    log.info("Finish diff zkcluster:{}, which cost {}ms", clusterKey, System.currentTimeMillis() - startTime);
    return resultList;
}
Also used : JobDiffInfo(com.vip.saturn.job.console.domain.JobDiffInfo) Callable(java.util.concurrent.Callable) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException) Future(java.util.concurrent.Future) List(java.util.List)

Example 4 with JobDiffInfo

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

the class ZkDBDiffServiceImpl method diffByNamespace.

@Override
public List<JobDiffInfo> diffByNamespace(String namespace) throws SaturnJobConsoleException {
    long startTime = System.currentTimeMillis();
    List<JobDiffInfo> jobDiffInfos = Lists.newArrayList();
    CuratorRepository.CuratorFrameworkOp zkClient;
    try {
        List<JobConfig4DB> dbJobConfigList = currentJobConfigService.findConfigsByNamespace(namespace);
        if (dbJobConfigList == null || dbJobConfigList.isEmpty()) {
            return jobDiffInfos;
        }
        zkClient = initCuratorClient(namespace);
        if (zkClient == null) {
            return jobDiffInfos;
        }
        Set<String> jobNamesInDb = getAllJobNames(dbJobConfigList);
        for (JobConfig4DB dbJobConfig : dbJobConfigList) {
            String jobName = dbJobConfig.getJobName();
            log.info("start to diff job:{}@{}", jobName, namespace);
            if (!checkJobIsExsitInZk(jobName, zkClient)) {
                jobDiffInfos.add(new JobDiffInfo(namespace, jobName, JobDiffInfo.DiffType.DB_ONLY, Lists.<JobDiffInfo.ConfigDiffInfo>newArrayList()));
                continue;
            }
            JobConfig jobConfigFromZK = jobService.getJobConfigFromZK(namespace, jobName);
            JobDiffInfo jobDiffInfo = diff(namespace, dbJobConfig, jobConfigFromZK, false);
            if (jobDiffInfo != null) {
                jobDiffInfos.add(jobDiffInfo);
            }
        }
        List<JobDiffInfo> jobsInZkOnly = getJobNamesWhichInZKOnly(namespace, jobNamesInDb);
        if (jobsInZkOnly != null && !jobsInZkOnly.isEmpty()) {
            jobDiffInfos.addAll(jobsInZkOnly);
        }
    } catch (SaturnJobConsoleException e) {
        log.error(e.getMessage(), e);
        throw e;
    } catch (Exception e) {
        log.error("exception throws during diff by namespace [{}]", namespace, e);
        throw new SaturnJobConsoleException(e);
    } finally {
        log.info("Finish diff namespace:{} which cost {}ms", namespace, System.currentTimeMillis() - startTime);
    }
    return jobDiffInfos;
}
Also used : JobDiffInfo(com.vip.saturn.job.console.domain.JobDiffInfo) 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) CuratorRepository(com.vip.saturn.job.console.repository.zookeeper.CuratorRepository) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException)

Example 5 with JobDiffInfo

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

the class ZKDBDiffController method diffByJob.

/**
 * 对比zk和db的job config数据差异。所有对比都在当前console进行。
 *
 * @param request
 * @param jobName   作业名
 * @param namespace
 * @return
 */
@RequestMapping(value = "zk_db_diff/diffByJob", method = RequestMethod.GET)
@ResponseBody
public RequestResult diffByJob(HttpServletRequest request, String jobName, String namespace) {
    RequestResult requestResult = new RequestResult();
    try {
        JobDiffInfo jobDiffInfo = zkDBDiffService.diffByJob(namespace, jobName);
        requestResult.setSuccess(true);
        requestResult.setObj(jobDiffInfo);
    } catch (Exception e) {
        requestResult.setSuccess(false);
        requestResult.setMessage(e.toString());
    }
    return requestResult;
}
Also used : RequestResult(com.vip.saturn.job.console.domain.RequestResult) JobDiffInfo(com.vip.saturn.job.console.domain.JobDiffInfo) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException) IOException(java.io.IOException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

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