use of com.vip.saturn.job.console.mybatis.entity.NamespaceZkClusterMapping in project Saturn by vipshop.
the class NamespaceAndJobServiceImpl method createNamespaceAndCloneJobs.
@Override
public void createNamespaceAndCloneJobs(String srcNamespace, String namespace, String zkClusterName, String createBy) throws SaturnJobConsoleException {
logger.info("start createNamespaceAndCloneJobs, srcNamespace: {}, namespace: {}, zkClusterName: {}", srcNamespace, namespace, zkClusterName);
NamespaceZkClusterMapping mapping = namespaceZkClusterMappingRepository.selectByNamespace(srcNamespace);
if (mapping == null) {
throw new SaturnJobConsoleException("no zkCluster mapping is not found");
}
NamespaceDomainInfo namespaceInfo = new NamespaceDomainInfo();
namespaceInfo.setNamespace(namespace);
namespaceInfo.setZkCluster(zkClusterName);
namespaceInfo.setContent("");
try {
registryCenterService.createNamespace(namespaceInfo);
registryCenterService.refreshRegistryCenterForNamespace(zkClusterName, srcNamespace);
} catch (SaturnJobConsoleHttpException e) {
if (StringUtils.equals(String.format(ERR_MSG_NS_ALREADY_EXIST, namespace), e.getMessage())) {
logger.warn("namespace already exists, ignore this exception and move on");
} else {
throw e;
}
}
namespaceService.importJobsFromNamespaceToNamespace(srcNamespace, namespace, createBy);
logger.info("finish createNamespaceAndCloneJobs, srcNamespace: {}, namespace: {}, zkClusterName: {}", srcNamespace, namespace, zkClusterName);
}
use of com.vip.saturn.job.console.mybatis.entity.NamespaceZkClusterMapping in project Saturn by vipshop.
the class NamespaceZkClusterMappingServiceImpl method getNamespaceZkClusterMappingList.
@Override
public List<NamespaceZkClusterMappingVo> getNamespaceZkClusterMappingList() throws SaturnJobConsoleException {
List<NamespaceZkClusterMappingVo> result = new ArrayList<>();
List<NamespaceZkClusterMapping> namespaceZkClusterMappingList = namespaceZkclusterMapping4SqlService.getAllMappings();
if (namespaceZkClusterMappingList != null) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
for (NamespaceZkClusterMapping tmp : namespaceZkClusterMappingList) {
try {
if (tmp.getIsDeleted() == 0) {
NamespaceZkClusterMappingVo vo = new NamespaceZkClusterMappingVo();
vo.setNamespace(tmp.getNamespace());
vo.setZkClusterKey(tmp.getZkClusterKey());
vo.setCreateTime(sdf.format(tmp.getCreateTime()));
vo.setCreatedBy(tmp.getCreatedBy());
vo.setLastUpdateTime(sdf.format(tmp.getLastUpdateTime()));
vo.setLastUpdatedBy(tmp.getLastUpdatedBy());
result.add(vo);
}
} catch (Exception e) {
log.error(e.getMessage(), e);
}
}
}
return result;
}
use of com.vip.saturn.job.console.mybatis.entity.NamespaceZkClusterMapping 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.mybatis.entity.NamespaceZkClusterMapping in project Saturn by vipshop.
the class RegistryCenterServiceImpl method getTargetNamespaceZkClusterMapping.
private List<NamespaceZkClusterMapping> getTargetNamespaceZkClusterMapping(String zkCluster, String namespace) {
List<NamespaceZkClusterMapping> nsZkClusterMappingList = namespaceZkClusterMapping4SqlService.getAllMappingsOfCluster(zkCluster);
List<NamespaceZkClusterMapping> filteredList = new ArrayList<>();
for (NamespaceZkClusterMapping n : nsZkClusterMappingList) {
if (n.getNamespace().equals(namespace)) {
filteredList.add(n);
break;
}
}
return nsZkClusterMappingList;
}
use of com.vip.saturn.job.console.mybatis.entity.NamespaceZkClusterMapping in project Saturn by vipshop.
the class NamespaceZkClusterMapping4SqlServiceImpl method update.
@Transactional
@Override
public Integer update(String namespace, String name, String zkClusterKey, String lastUpdatedBy) {
NamespaceZkClusterMapping namespaceZkClusterMapping = namespaceZkClusterMappingRepository.selectByNamespace(namespace);
if (name != null) {
namespaceZkClusterMapping.setName(name);
}
if (zkClusterKey != null) {
namespaceZkClusterMapping.setZkClusterKey(zkClusterKey);
}
namespaceZkClusterMapping.setLastUpdatedBy(lastUpdatedBy);
return namespaceZkClusterMappingRepository.updateById(namespaceZkClusterMapping);
}
Aggregations