use of com.vip.saturn.job.console.domain.ZkCluster in project Saturn by vipshop.
the class JobConfigInitializationServiceImpl method exportAllToDb.
@Override
public void exportAllToDb(final String userName) throws SaturnJobConsoleException {
final ExportJobConfigPageStatus exportJobConfigPageStatus = new ExportJobConfigPageStatus();
temporarySharedStatusService.delete(ShareStatusModuleNames.EXPORT_JOB_CONFIG_PAGE_STATUS);
temporarySharedStatusService.create(ShareStatusModuleNames.EXPORT_JOB_CONFIG_PAGE_STATUS, gson.toJson(exportJobConfigPageStatus));
executorService.execute(new Runnable() {
@Override
public void run() {
log.info("start to export all to db");
try {
log.info("start to delete all from table job_config");
deleteAll();
log.info("delete all from table job_config successfully");
Collection<ZkCluster> zkClusters = registryCenterService.getZkClusterList();
if (zkClusters != null) {
for (ZkCluster tmp : zkClusters) {
exportToDbByZkCluster(userName, tmp, exportJobConfigPageStatus);
}
}
exportJobConfigPageStatus.setSuccess(true);
} catch (Exception e) {
log.error(e.getMessage(), e);
exportJobConfigPageStatus.setSuccess(false);
} finally {
exportJobConfigPageStatus.setExported(true);
temporarySharedStatusService.update(ShareStatusModuleNames.EXPORT_JOB_CONFIG_PAGE_STATUS, gson.toJson(exportJobConfigPageStatus));
}
}
});
}
use of com.vip.saturn.job.console.domain.ZkCluster in project Saturn by vipshop.
the class JobConfigInitializationServiceImpl method getRegistryCenterConfigurations.
@Override
public List<RegistryCenterConfiguration> getRegistryCenterConfigurations() throws SaturnJobConsoleException {
Collection<ZkCluster> zkClusterList = registryCenterService.getZkClusterList();
List<RegistryCenterConfiguration> rccs = new ArrayList<>();
if (zkClusterList != null) {
for (ZkCluster zkCluster : zkClusterList) {
if (zkCluster != null && !zkCluster.isOffline()) {
rccs.addAll(zkCluster.getRegCenterConfList());
}
}
}
return rccs;
}
use of com.vip.saturn.job.console.domain.ZkCluster in project Saturn by vipshop.
the class JobConfigInitializationServiceImpl method exportToDbByZkCluster.
private void exportToDbByZkCluster(String userName, ZkCluster tmp, ExportJobConfigPageStatus exportJobConfigPageStatus) throws SaturnJobConsoleException {
log.info(" start to export db by single zkCluster, zkCluster Addr is :{}", tmp.getZkAddr());
ZkCluster zkCluster = tmp;
ArrayList<RegistryCenterConfiguration> oldRccs = zkCluster.getRegCenterConfList();
ArrayList<RegistryCenterConfiguration> rccs = new ArrayList<RegistryCenterConfiguration>(oldRccs);
for (RegistryCenterConfiguration rcc : rccs) {
List<String> jobNames = getAllUnSystemJobs(rcc.getNamespace(), zkCluster.getCuratorFramework());
for (String jobName : jobNames) {
try {
JobSettings jobSettings = getJobSettings(jobName, rcc, zkCluster.getCuratorFramework());
CurrentJobConfig current = mapper.map(jobSettings, CurrentJobConfig.class);
current.setCreateBy(userName);
current.setCreateTime(new Date());
current.setLastUpdateBy(userName);
current.setLastUpdateTime(new Date());
current.setNamespace(rcc.getNamespace());
currentJobConfigService.create(current);
} catch (Exception e) {
log.error(e.getMessage(), e);
throw new SaturnJobConsoleException(e.getMessage());
}
}
exportJobConfigPageStatus.setSuccessJobNum(exportJobConfigPageStatus.getSuccessJobNum() + jobNames.size());
exportJobConfigPageStatus.setSuccessNamespaceNum(exportJobConfigPageStatus.getSuccessNamespaceNum() + 1);
temporarySharedStatusService.update(ShareStatusModuleNames.EXPORT_JOB_CONFIG_PAGE_STATUS, gson.toJson(exportJobConfigPageStatus));
}
log.info("export db by single zkCluster successfully, zkCluster Addr is :{}", tmp.getZkAddr());
}
use of com.vip.saturn.job.console.domain.ZkCluster in project Saturn by vipshop.
the class NamespaceZkClusterMappingServiceImpl method moveNamespaceTo.
@Transactional(rollbackFor = { SaturnJobConsoleException.class })
@Override
public void moveNamespaceTo(String namespace, String zkClusterKeyNew, String lastUpdatedBy, boolean updateDBOnly) throws SaturnJobConsoleException {
try {
log.info("start move {} to {}", namespace, zkClusterKeyNew);
if (updateDBOnly) {
namespaceZkclusterMapping4SqlService.update(namespace, null, zkClusterKeyNew, lastUpdatedBy);
} else {
String zkClusterKey = namespaceZkclusterMapping4SqlService.getZkClusterKey(namespace);
if (zkClusterKey != null && zkClusterKey.equals(zkClusterKeyNew)) {
// see
throw new SaturnJobConsoleException("The namespace(" + namespace + ") is in " + zkClusterKey);
// moveNamespaceBatchTo
// before
// modify
}
ZkCluster zkCluster = registryCenterService.getZkCluster(zkClusterKeyNew);
if (zkCluster == null) {
throw new SaturnJobConsoleException("The " + zkClusterKeyNew + " is not exists");
}
if (zkCluster.isOffline()) {
throw new SaturnJobConsoleException("The " + zkClusterKeyNew + " zkCluster is offline");
}
String zkAddr = zkCluster.getZkAddr();
CuratorRepository.CuratorFrameworkOp curatorFrameworkOp = registryCenterService.connectOnly(zkAddr, null);
if (curatorFrameworkOp == null) {
throw new SaturnJobConsoleException("The " + zkClusterKeyNew + " zkCluster is offline");
}
CuratorFramework curatorFramework = curatorFrameworkOp.getCuratorFramework();
CuratorRepository.CuratorFrameworkOp curatorFrameworkOpByNamespace = registryCenterService.connectOnly(zkAddr, namespace);
CuratorFramework curatorFrameworkByNamespace = curatorFrameworkOpByNamespace.getCuratorFramework();
try {
String namespaceNodePath = "/" + namespace;
if (curatorFramework.checkExists().forPath(namespaceNodePath) != null) {
curatorFramework.delete().deletingChildrenIfNeeded().forPath(namespaceNodePath);
}
String jobsNodePath = namespaceNodePath + JobNodePath.get$JobsNodePath();
curatorFramework.create().creatingParentsIfNeeded().withMode(CreateMode.PERSISTENT).forPath(jobsNodePath);
List<CurrentJobConfig> configs = currentJobConfigService.findConfigsByNamespace(namespace);
log.info("get configs success, {}", namespace);
if (configs != null) {
for (CurrentJobConfig jobConfig : configs) {
jobOperationService.persistJobFromDB(jobConfig, curatorFrameworkOpByNamespace);
log.info("move {}-{} to zk success", namespace, jobConfig.getJobName());
}
}
} finally {
curatorFramework.close();
curatorFrameworkByNamespace.close();
}
log.info("move {} to zk {} success", namespace, zkClusterKeyNew);
namespaceZkclusterMapping4SqlService.update(namespace, null, zkClusterKeyNew, lastUpdatedBy);
log.info("update mapping table success, {}-{}", namespace, zkClusterKeyNew);
}
} catch (SaturnJobConsoleException e) {
log.error(e.getMessage(), e);
throw e;
} catch (Exception e) {
log.error(e.getMessage(), e);
throw new SaturnJobConsoleException(e);
} finally {
log.info("end move {} to {}", namespace, zkClusterKeyNew);
}
}
use of com.vip.saturn.job.console.domain.ZkCluster in project Saturn by vipshop.
the class DashboardController method count.
@RequestMapping(value = "count", method = RequestMethod.POST)
@ResponseBody
public Map<String, Integer> count(Boolean allZkCluster, String zkClusterKey) {
Map<String, Integer> countMap = new HashMap<>();
int executorInDockerCount = 0;
int executorNotInDockerCount = 0;
int jobCount = 0;
int domainCount = 0;
if (allZkCluster != null && allZkCluster) {
Collection<ZkCluster> zkClusterList = registryCenterService.getZkClusterList();
for (ZkCluster zkCluster : zkClusterList) {
String zkAddr = zkCluster.getZkAddr();
if (zkAddr != null) {
executorInDockerCount += dashboardService.executorInDockerCount(zkAddr);
executorNotInDockerCount += dashboardService.executorNotInDockerCount(zkAddr);
jobCount += dashboardService.jobCount(zkAddr);
}
String zck = zkCluster.getZkClusterKey();
if (zck != null) {
domainCount += registryCenterService.domainCount(zck);
}
}
} else {
ZkCluster zkCluster = registryCenterService.getZkCluster(zkClusterKey);
if (zkCluster != null) {
executorInDockerCount = dashboardService.executorInDockerCount(zkCluster.getZkAddr());
executorNotInDockerCount = dashboardService.executorNotInDockerCount(zkCluster.getZkAddr());
jobCount = dashboardService.jobCount(zkCluster.getZkAddr());
domainCount = registryCenterService.domainCount(zkCluster.getZkClusterKey());
}
}
countMap.put("executorInDockerCount", executorInDockerCount);
countMap.put("executorNotInDockerCount", executorNotInDockerCount);
countMap.put("jobCount", jobCount);
countMap.put("domainCount", domainCount);
return countMap;
}
Aggregations