use of com.vip.saturn.job.console.mybatis.entity.NamespaceZkClusterMapping in project Saturn by vipshop.
the class RegistryCenterServiceImpl method initMoveInNamespace.
private void initMoveInNamespace(List<String> allOnlineNamespacesTemp, String zkClusterKey, ZkCluster zkCluster, List<NamespaceZkClusterMapping> nsZkClusterMappingList, List<RegistryCenterConfiguration> regCenterConfList) {
if (nsZkClusterMappingList == null || zkCluster.isOffline()) {
return;
}
for (NamespaceZkClusterMapping mapping : nsZkClusterMappingList) {
String namespace = mapping.getNamespace();
String name = StringUtils.deleteWhitespace(mapping.getName());
if (SaturnSelfNodePath.ROOT_NAME.equals(namespace)) {
log.error("The namespace cannot be {}", SaturnSelfNodePath.ROOT_NAME);
continue;
}
boolean include = false;
if (regCenterConfList != null) {
for (RegistryCenterConfiguration conf : regCenterConfList) {
if (!namespace.equals(conf.getNamespace())) {
continue;
}
include = true;
String nnsOld = conf.getNameAndNamespace();
// update name
conf.setName(name);
conf.initNameAndNamespace();
String nnsNew = conf.getNameAndNamespace();
if (!nnsOld.equals(nnsNew)) {
synchronized (getNnsLock(nnsOld)) {
closeNamespace(nnsOld);
log.info("closed the namespace info because it's nns is changed, namespace is {}", namespace);
}
}
break;
}
}
if (!include) {
CuratorFramework curatorFramework = zkCluster.getCuratorFramework();
initNamespaceZkNodeIfNecessary(namespace, curatorFramework);
RegistryCenterConfiguration conf = new RegistryCenterConfiguration(name, namespace, zkCluster.getZkAddr());
conf.setZkClusterKey(zkClusterKey);
conf.setVersion(getVersion(namespace, curatorFramework));
conf.setZkAlias(zkCluster.getZkAlias());
NamespaceInfo namespaceInfo = getNamespaceInfo(namespace);
if (namespaceInfo != null) {
postConstructRegistryCenterConfiguration(conf, namespaceInfo.getContent());
}
zkCluster.getRegCenterConfList().add(conf);
}
if (!allOnlineNamespacesTemp.contains(namespace)) {
allOnlineNamespacesTemp.add(namespace);
}
}
}
use of com.vip.saturn.job.console.mybatis.entity.NamespaceZkClusterMapping in project Saturn by vipshop.
the class NamespaceZkClusterMapping4SqlServiceImpl method getAllNamespacesOfCluster.
@Transactional(readOnly = true)
@Override
public List<String> getAllNamespacesOfCluster(String zkClusterKey) {
List<String> result = new ArrayList<String>();
List<NamespaceZkClusterMapping> namespaceZkClusterMappings = existingAll(namespaceZkClusterMappingRepository.selectByZkClusterKey(zkClusterKey));
for (NamespaceZkClusterMapping mapping : namespaceZkClusterMappings) {
result.add(mapping.getNamespace());
}
return result;
}
use of com.vip.saturn.job.console.mybatis.entity.NamespaceZkClusterMapping in project Saturn by vipshop.
the class NamespaceZkClusterMapping4SqlServiceImpl method insert.
@Transactional
@Override
public Integer insert(String namespace, String name, String zkClusterKey, String createdBy) {
NamespaceZkClusterMapping namespaceZkClusterMapping = namespaceZkClusterMappingRepository.selectByNamespace(namespace);
boolean insert;
if (namespaceZkClusterMapping == null) {
namespaceZkClusterMapping = new NamespaceZkClusterMapping();
insert = true;
} else {
insert = false;
}
Date now = new Date();
namespaceZkClusterMapping.setIsDeleted(0);
namespaceZkClusterMapping.setCreateTime(now);
namespaceZkClusterMapping.setCreatedBy(createdBy);
namespaceZkClusterMapping.setLastUpdateTime(now);
namespaceZkClusterMapping.setLastUpdatedBy(createdBy);
namespaceZkClusterMapping.setNamespace(namespace);
namespaceZkClusterMapping.setName(name);
namespaceZkClusterMapping.setZkClusterKey(zkClusterKey);
if (insert) {
return namespaceZkClusterMappingRepository.insert(namespaceZkClusterMapping);
} else {
return namespaceZkClusterMappingRepository.updateAllById(namespaceZkClusterMapping);
}
}
use of com.vip.saturn.job.console.mybatis.entity.NamespaceZkClusterMapping in project Saturn by vipshop.
the class RegistryCenterServiceImpl method closeMoveOutNamespace.
private void closeMoveOutNamespace(String zkClusterKey, List<NamespaceZkClusterMapping> nsZkClusterMappingList, List<RegistryCenterConfiguration> regCenterConfList) {
if (regCenterConfList == null) {
return;
}
Iterator<RegistryCenterConfiguration> regIter = regCenterConfList.iterator();
while (regIter.hasNext()) {
RegistryCenterConfiguration conf = regIter.next();
String namespace = conf.getNamespace();
String nns = conf.getNameAndNamespace();
boolean include = false;
if (nsZkClusterMappingList != null) {
for (NamespaceZkClusterMapping mapping : nsZkClusterMappingList) {
if (namespace.equals(mapping.getNamespace())) {
include = true;
break;
}
}
}
if (!include) {
synchronized (getNnsLock(nns)) {
regIter.remove();
closeNamespace(nns);
log.info("closed the moved namespace info, namespace is {}, old zkClusterKey is {}", namespace, zkClusterKey);
}
}
}
}
use of com.vip.saturn.job.console.mybatis.entity.NamespaceZkClusterMapping in project Saturn by vipshop.
the class RegistryCenterServiceImpl method initOrUpdateNamespace.
private void initOrUpdateNamespace(List<String> allOnlineNamespacesTemp, ZkCluster zkCluster, List<NamespaceZkClusterMapping> nsZkClusterMappingList, List<RegistryCenterConfiguration> regCenterConfList) {
if (nsZkClusterMappingList == null || zkCluster.isOffline()) {
return;
}
CuratorRepository.CuratorFrameworkOp curatorFrameworkOp = zkCluster.getCuratorFrameworkOp();
ArrayList<RegistryCenterConfiguration> newRegCenterConfList = new ArrayList<>();
try {
for (NamespaceZkClusterMapping mapping : nsZkClusterMappingList) {
String namespace = mapping.getNamespace();
// 过滤$SaturnSelf
if (SaturnSelfNodePath.ROOT_NAME.equals(namespace)) {
continue;
}
// 如果这个标记为true,意味是新域,或者是迁移过来的域
boolean isNamespaceNotIncludeInOriginRegCenerConfList = false;
if (isNamespaceNotIncludeInRegCenterConfList(namespace, regCenterConfList)) {
// 对于新添加的域,需要初始化一些znode
initNamespaceZkNodeIfNecessary(namespace, curatorFrameworkOp);
isNamespaceNotIncludeInOriginRegCenerConfList = true;
}
try {
if (isNamespaceNotIncludeInOriginRegCenerConfList || isNewerVersionSaturnNamespace(namespace, curatorFrameworkOp)) {
NamespaceInfo namespaceInfo = getNamespaceInfo(namespace);
if (namespaceInfo == null && !isNamespaceInfoNotFoundCanBeCalculate()) {
log.warn("No info about namespace {}, just skip it.", namespace);
continue;
}
RegistryCenterConfiguration conf = new RegistryCenterConfiguration(mapping.getName(), namespace, zkCluster.getZkAddr());
conf.setZkClusterKey(zkCluster.getZkClusterKey());
conf.setVersion(getVersion(namespace, curatorFrameworkOp));
conf.setZkAlias(zkCluster.getZkAlias());
if (namespaceInfo != null) {
postConstructRegistryCenterConfiguration(conf, namespaceInfo.getContent());
}
newRegCenterConfList.add(conf);
if (!allOnlineNamespacesTemp.contains(namespace)) {
allOnlineNamespacesTemp.add(namespace);
}
}
} catch (Exception e) {
log.error(e.getMessage(), e);
}
}
} catch (Exception e) {
log.error(e.getMessage(), e);
}
// 如果nns有改变,则需要关闭旧的
if (regCenterConfList != null) {
for (RegistryCenterConfiguration conf : regCenterConfList) {
String namespace = conf.getNamespace();
String nns = conf.getNameAndNamespace();
for (RegistryCenterConfiguration confNew : newRegCenterConfList) {
String namespaceNew = confNew.getNamespace();
if (namespace.equals(namespaceNew)) {
String nnsNew = confNew.getNameAndNamespace();
if (!nns.equals(nnsNew)) {
synchronized (getNnsLock(nns)) {
closeNamespace(nns);
log.info("closed the namespace info because it's nns is changed, namespace is {}", namespace);
}
}
break;
}
}
}
}
int oldSize = regCenterConfList != null ? regCenterConfList.size() : 0;
if (oldSize != newRegCenterConfList.size()) {
log.info("Zkcluster [{}] namespace size change from {} to {}", zkCluster.getZkClusterKey(), oldSize, newRegCenterConfList.size());
}
zkCluster.setRegCenterConfList(newRegCenterConfList);
}
Aggregations