use of com.vip.saturn.job.console.domain.ZkCluster in project Saturn by vipshop.
the class RegistryCenterServiceImpl method createNamespace.
@Transactional(rollbackFor = { Exception.class })
@Override
public void createNamespace(NamespaceDomainInfo namespaceDomainInfo) throws SaturnJobConsoleException {
String namespace = namespaceDomainInfo.getNamespace();
String zkClusterKey = namespaceDomainInfo.getZkCluster();
ZkCluster currentCluster = getZkCluster(zkClusterKey);
if (currentCluster == null) {
throw new SaturnJobConsoleHttpException(HttpStatus.BAD_REQUEST.value(), String.format(ERR_MSG_TEMPLATE_FAIL_TO_CREATE, namespace, "not found zkcluster" + zkClusterKey));
}
if (checkNamespaceExists(namespace)) {
throw new SaturnJobConsoleHttpException(HttpStatus.BAD_REQUEST.value(), String.format(ERR_MSG_NS_ALREADY_EXIST, namespace));
}
try {
// 创建 namespaceInfo
NamespaceInfo namespaceInfo = constructNamespaceInfo(namespaceDomainInfo);
namespaceInfoService.create(namespaceInfo);
// 创建 zkcluster 和 namespaceInfo 关系
namespaceZkClusterMapping4SqlService.insert(namespace, "", zkClusterKey, NAMESPACE_CREATOR_NAME);
// refresh
notifyRefreshRegCenter();
} catch (Exception e) {
log.error(e.getMessage(), e);
throw new SaturnJobConsoleHttpException(HttpStatus.INTERNAL_SERVER_ERROR.value(), String.format(ERR_MSG_TEMPLATE_FAIL_TO_CREATE, namespace, e.getMessage()));
}
}
use of com.vip.saturn.job.console.domain.ZkCluster in project Saturn by vipshop.
the class RegistryCenterServiceImpl method refreshDashboardLeaderTreeCache.
private void refreshDashboardLeaderTreeCache() {
closeDeprecatedDashboardLeaderTreeCache();
Iterator<Entry<String, ZkCluster>> iterator = zkClusterMap.entrySet().iterator();
while (iterator.hasNext()) {
Entry<String, ZkCluster> next = iterator.next();
String zkClusterKey = next.getKey();
ZkCluster zkCluster = next.getValue();
if (needToRefreshDashboardTreeCache(zkCluster, zkClusterKey)) {
DashboardLeaderHandler dashboardLeaderHandler = null;
try {
dashboardLeaderHandler = new DashboardLeaderHandler(zkCluster.getZkAlias(), zkCluster.getCuratorFrameworkOp().getCuratorFramework());
dashboardLeaderHandler.start();
dashboardLeaderTreeCacheMap.put(zkClusterKey, dashboardLeaderHandler);
} catch (Exception e) {
log.error(e.getMessage(), e);
if (dashboardLeaderHandler != null) {
dashboardLeaderHandler.shutdown();
}
}
}
}
}
use of com.vip.saturn.job.console.domain.ZkCluster in project Saturn by vipshop.
the class RegistryCenterServiceImpl method refreshRegistryCenter.
private void refreshRegistryCenter() {
List<String> allOnlineNamespacesTemp = new ArrayList<>();
// 获取新的zkClusters
Map<String, ZkCluster> newClusterMap = getZkClusterInfo();
// 对比旧的。不包含的,关闭操作;包含的,检查属性是否相同,如果相同,则直接赋值,否则,关闭旧的
closeInvalidZkClient(newClusterMap);
// 完善curatorFramework。如果没有,则新建
connectToZkClusterIfPossible(newClusterMap);
// 完善ZkCluster中的注册中心信息,关闭迁移了的域,新建迁移过来的域
for (Map.Entry<String, ZkCluster> zkClusterEntry : newClusterMap.entrySet()) {
ZkCluster zkCluster = zkClusterEntry.getValue();
String key = zkClusterEntry.getKey();
List<NamespaceZkClusterMapping> nsZkClusterMappingList = namespaceZkClusterMapping4SqlService.getAllMappingsOfCluster(key);
// zkCluster对应的namespace列表
List<RegistryCenterConfiguration> regCenterConfList = zkCluster.getRegCenterConfList();
closeMoveOutNamespace(key, nsZkClusterMappingList, regCenterConfList);
initOrUpdateNamespace(allOnlineNamespacesTemp, zkCluster, nsZkClusterMappingList, regCenterConfList);
}
// 直接赋值新的
zkClusterMap = (LinkedHashMap<String, ZkCluster>) newClusterMap;
log.info("new zkClusterMap is : {}", zkClusterMap);
allOnlineNamespaces = allOnlineNamespacesTemp;
}
use of com.vip.saturn.job.console.domain.ZkCluster in project Saturn by vipshop.
the class ExecutorConfigController method createOrUpdateConfig.
@ApiResponses(value = { @ApiResponse(code = 200, message = "Success/Fail", response = RequestResult.class) })
@Audit
@PostMapping
public SuccessResponseEntity createOrUpdateConfig(@AuditParam(value = "key") @RequestParam String key, @AuditParam(value = "value") @RequestParam String value) throws SaturnJobConsoleException {
assertIsPermitted(PermissionKeys.systemConfig);
String executorConfigsJsonInDB = systemConfigService.getValueDirectly(SystemConfigProperties.EXECUTOR_CONFIGS);
JSONObject jsonObject = parseExecutorConfigJson(executorConfigsJsonInDB);
if (jsonObject == null) {
jsonObject = new JSONObject();
}
// I'm sure that key and value is not null, because @RequestParam required is true
jsonObject.put(key.trim(), value.trim());
String configStr = jsonObject.toJSONString();
log.info("Start to update executor config data {}", configStr);
// update zk
List<ZkCluster> onlineZkClusterList = registryCenterService.getOnlineZkClusterList();
for (ZkCluster zkCluster : onlineZkClusterList) {
updateConfigInZk(configStr, zkCluster);
}
// update db
SystemConfig systemConfig = new SystemConfig();
systemConfig.setProperty(SystemConfigProperties.EXECUTOR_CONFIGS);
systemConfig.setValue(configStr);
systemConfigService.insertOrUpdate(systemConfig);
log.info("Update executor config to db successfully");
return new SuccessResponseEntity();
}
use of com.vip.saturn.job.console.domain.ZkCluster in project Saturn by vipshop.
the class DashboardController method getStatistics.
@ApiResponses(value = { @ApiResponse(code = 200, message = "Success/Fail", response = RequestResult.class) })
@GetMapping(value = "/count")
public SuccessResponseEntity getStatistics(@RequestParam(required = false) String zkClusterKey) throws SaturnJobConsoleException {
Map<String, Integer> countMap = Maps.newHashMap();
int executorInDockerCount = 0;
int executorNotInDockerCount = 0;
int jobCount = 0;
int domainCount = 0;
Collection<ZkCluster> zkClusters = null;
if (StringUtils.isNotBlank(zkClusterKey)) {
ZkCluster zkCluster = registryCenterService.getZkCluster(zkClusterKey);
zkClusters = Lists.newArrayList();
zkClusters.add(zkCluster);
} else {
zkClusters = registryCenterService.getZkClusterList();
}
for (ZkCluster zkCluster : zkClusters) {
// 不统计离线的zkcluster
if (zkCluster.isOffline()) {
continue;
}
String zkAddr = zkCluster.getZkAddr();
if (zkAddr != null) {
executorInDockerCount += dashboardService.executorInDockerCount(zkAddr);
executorNotInDockerCount += dashboardService.executorNotInDockerCount(zkAddr);
jobCount += dashboardService.jobCount(zkAddr);
}
domainCount += registryCenterService.domainCount(zkCluster.getZkClusterKey());
}
countMap.put("executorInDockerCount", executorInDockerCount);
countMap.put("executorNotInDockerCount", executorNotInDockerCount);
countMap.put("jobCount", jobCount);
countMap.put("domainCount", domainCount);
return new SuccessResponseEntity(countMap);
}
Aggregations