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;
}
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);
}
}
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;
}
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;
}
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;
}
Aggregations