use of com.vip.saturn.job.console.domain.RegistryCenterConfiguration 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.domain.RegistryCenterConfiguration in project Saturn by vipshop.
the class ReuseUtils method reuse.
public static void reuse(String namespace, RegistryCenterService registryCenterService, CuratorRepository curatorRepository, ReuseCallBackWithoutReturn callBack) throws SaturnJobConsoleException {
try {
RegistryCenterConfiguration registryCenterConfiguration = registryCenterService.findConfigByNamespace(namespace);
if (registryCenterConfiguration == null) {
throw new SaturnJobConsoleException(ERROR_CODE_NOT_EXISTED, String.format(NAMESPACE_NOT_EXIST_TEMPLATE, namespace));
}
RegistryCenterClient registryCenterClient = registryCenterService.connectByNamespace(namespace);
if (registryCenterClient != null && registryCenterClient.isConnected()) {
CuratorFramework curatorClient = registryCenterClient.getCuratorClient();
CuratorRepository.CuratorFrameworkOp curatorFrameworkOp = curatorRepository.newCuratorFrameworkOp(curatorClient);
ThreadLocalCuratorClient.setCuratorClient(curatorClient);
callBack.call(curatorFrameworkOp);
} else {
throw new SaturnJobConsoleException("Connect zookeeper failed");
}
} catch (SaturnJobConsoleException e) {
throw e;
} catch (Throwable t) {
log.error(t.getMessage(), t);
throw new SaturnJobConsoleException(t);
} finally {
ThreadLocalCuratorClient.clear();
}
}
use of com.vip.saturn.job.console.domain.RegistryCenterConfiguration in project Saturn by vipshop.
the class RegistryCenterServiceImpl method updateRegistryCenterConfiguration.
private void updateRegistryCenterConfiguration(String namespace, String zkAddressList, String zkClusterName) {
List<RegistryCenterConfiguration> sourceRegCenterConfList = zkClusterMap.get(zkClusterName).getRegCenterConfList();
boolean regCenterConfAlreadyExisted = false;
for (RegistryCenterConfiguration conf : sourceRegCenterConfList) {
if (conf.getNamespace().equals(namespace)) {
regCenterConfAlreadyExisted = true;
break;
}
}
if (!regCenterConfAlreadyExisted) {
RegistryCenterConfiguration registryCenterConfiguration = new RegistryCenterConfiguration("", namespace, zkAddressList);
zkClusterMap.get(zkClusterName).getRegCenterConfList().add(registryCenterConfiguration);
}
}
use of com.vip.saturn.job.console.domain.RegistryCenterConfiguration in project Saturn by vipshop.
the class RegistryCenterServiceImpl method constructRegistryCenterConfiguration.
protected RegistryCenterConfiguration constructRegistryCenterConfiguration(ZkCluster zkCluster, String namespace) {
RegistryCenterConfiguration config = new RegistryCenterConfiguration("", namespace, zkCluster.getZkAddr());
config.setZkClusterKey(zkCluster.getZkClusterKey());
config.setZkAlias(zkCluster.getZkAlias());
return config;
}
use of com.vip.saturn.job.console.domain.RegistryCenterConfiguration in project Saturn by vipshop.
the class RegistryCenterServiceImpl method exportNamespaceInfo.
@Override
public File exportNamespaceInfo(List<String> namespaceList) throws SaturnJobConsoleException {
Set<String> targetNamespaceSet = null;
if (namespaceList != null) {
targetNamespaceSet = Sets.newHashSet(namespaceList);
}
List<RegistryCenterConfiguration> namespaceInfoList = Lists.newLinkedList();
Collection<ZkCluster> zkClusterList = getZkClusterList();
for (ZkCluster zkCluster : zkClusterList) {
List<RegistryCenterConfiguration> namespacesOfZkCluster = zkCluster.getRegCenterConfList();
for (RegistryCenterConfiguration ns : namespacesOfZkCluster) {
if (targetNamespaceSet == null || targetNamespaceSet.contains(ns.getNamespace())) {
namespaceInfoList.add(ns);
}
}
}
return exportNamespaceInfo2Excel(namespaceInfoList);
}
Aggregations