use of com.vip.saturn.job.console.domain.RegistryCenterConfiguration in project Saturn by vipshop.
the class RegistryCenterServiceImpl method connect.
@Override
public RegistryCenterClient connect(final String nameAndNameSpace) {
final RegistryCenterClient registryCenterClient = new RegistryCenterClient();
registryCenterClient.setNameAndNamespace(nameAndNameSpace);
if (nameAndNameSpace == null) {
return registryCenterClient;
}
synchronized (getNnsLock(nameAndNameSpace)) {
if (!registryCenterClientMap.containsKey(nameAndNameSpace)) {
RegistryCenterConfiguration registryCenterConfiguration = findConfig(nameAndNameSpace);
if (registryCenterConfiguration == null) {
return registryCenterClient;
}
String zkAddressList = registryCenterConfiguration.getZkAddressList();
String namespace = registryCenterConfiguration.getNamespace();
String digest = registryCenterConfiguration.getDigest();
registryCenterClient.setZkAddr(zkAddressList);
CuratorFramework client = curatorRepository.connect(zkAddressList, namespace, digest);
if (client == null) {
return registryCenterClient;
}
registryCenterClient.setConnected(client.getZookeeperClient().isConnected());
registryCenterClient.setCuratorClient(client);
registryCenterClientMap.put(nameAndNameSpace, registryCenterClient);
return registryCenterClient;
} else {
RegistryCenterClient registryCenterClient2 = registryCenterClientMap.get(nameAndNameSpace);
if (registryCenterClient2 != null) {
if (registryCenterClient2.getCuratorClient() != null) {
registryCenterClient2.setConnected(registryCenterClient2.getCuratorClient().getZookeeperClient().isConnected());
} else {
registryCenterClient2.setConnected(false);
}
return registryCenterClient2;
}
return registryCenterClient;
}
}
}
use of com.vip.saturn.job.console.domain.RegistryCenterConfiguration 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);
}
use of com.vip.saturn.job.console.domain.RegistryCenterConfiguration in project Saturn by vipshop.
the class RegistryCenterServiceImpl method connectByNamespace.
@Override
public RegistryCenterClient connectByNamespace(String namespace) {
RegistryCenterConfiguration registryCenterConfiguration = findConfigByNamespace(namespace);
if (registryCenterConfiguration == null) {
return new RegistryCenterClient();
}
String nns = registryCenterConfiguration.getNameAndNamespace();
if (nns == null) {
return new RegistryCenterClient();
}
String zkAddressList = registryCenterConfiguration.getZkAddressList();
String digest = registryCenterConfiguration.getDigest();
synchronized (getNnsLock(nns)) {
if (!registryCenterClientMap.containsKey(nns)) {
final RegistryCenterClient registryCenterClient = new RegistryCenterClient();
registryCenterClient.setNameAndNamespace(nns);
registryCenterClient.setZkAddr(zkAddressList);
CuratorFramework client = curatorRepository.connect(zkAddressList, namespace, digest);
if (client == null) {
return registryCenterClient;
}
registryCenterClient.setConnected(client.getZookeeperClient().isConnected());
registryCenterClient.setCuratorClient(client);
registryCenterClientMap.put(nns, registryCenterClient);
return registryCenterClient;
} else {
RegistryCenterClient registryCenterClient = registryCenterClientMap.get(nns);
if (registryCenterClient == null) {
registryCenterClient = new RegistryCenterClient();
registryCenterClient.setNameAndNamespace(namespace);
registryCenterClient.setZkAddr(zkAddressList);
} else {
if (registryCenterClient.getCuratorClient() != null) {
registryCenterClient.setConnected(registryCenterClient.getCuratorClient().getZookeeperClient().isConnected());
} else {
registryCenterClient.setConnected(false);
}
}
return registryCenterClient;
}
}
}
use of com.vip.saturn.job.console.domain.RegistryCenterConfiguration in project Saturn by vipshop.
the class ZkDBDiffServiceImpl method initCuratorClient.
private CuratorRepository.CuratorFrameworkOp initCuratorClient(String namespace) {
RegistryCenterConfiguration registryCenterConfiguration = registryCenterService.findConfigByNamespace(namespace);
if (registryCenterConfiguration == null) {
String errMsg = String.format(NAMESPACE_NOT_EXIST_TEMPLATE, namespace);
log.warn(ERR_MSG_SKIP_DIFF, namespace, errMsg);
return null;
}
RegistryCenterClient registryCenterClient = registryCenterService.connectByNamespace(namespace);
if (registryCenterClient != null && registryCenterClient.isConnected()) {
return curatorRepository.newCuratorFrameworkOp(registryCenterClient.getCuratorClient());
}
log.warn(ERR_MSG_SKIP_DIFF, namespace, "fail to connect to zk.");
return null;
}
use of com.vip.saturn.job.console.domain.RegistryCenterConfiguration in project Saturn by vipshop.
the class InitRegistryCenterService method initTreeJson.
/**
* transfer /a/b/b1, /a/b/b2 to {"title":"a", "children":["title":"b", "children": ["title": b1, "title": b2]]}
*
* @param registryCenterConfiguration 注册中心配置类
*/
public static void initTreeJson(Set<RegistryCenterConfiguration> registryCenterConfiguration) {
TreeNode treeData = new TreeNode();
for (RegistryCenterConfiguration conf : registryCenterConfiguration) {
String nameAndnameSpace = conf.getNameAndNamespace();
if (nameAndnameSpace.startsWith("/")) {
nameAndnameSpace = nameAndnameSpace.substring(1);
}
treeData = parseDirectory2Tree(nameAndnameSpace, treeData, conf.getNameAndNamespace(), conf.getDegree());
}
log.info("init tree data: {}", treeData);
}
Aggregations