use of com.vip.saturn.job.console.domain.RegistryCenterConfiguration 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.domain.RegistryCenterConfiguration in project Saturn by vipshop.
the class RegistryCenterServiceImpl method findConfigsByZkCluster.
@Override
public List<RegistryCenterConfiguration> findConfigsByZkCluster(ZkCluster zkCluster) {
List<String> namespaces = namespaceZkClusterMapping4SqlService.getAllNamespacesOfCluster(zkCluster.getZkClusterKey());
if (namespaces == null || namespaces.isEmpty()) {
return Lists.newArrayList();
}
List<RegistryCenterConfiguration> configs = Lists.newArrayList();
for (String namespace : namespaces) {
RegistryCenterConfiguration config = constructRegistryCenterConfiguration(zkCluster, namespace);
configs.add(config);
}
return configs;
}
use of com.vip.saturn.job.console.domain.RegistryCenterConfiguration in project Saturn by vipshop.
the class RegistryCenterServiceImpl method closeZkCluster.
/**
* Close dashboardLeaderTreeCache, registryCenterClient, namespaceShardingListenerManager with this zkCluster
*/
private void closeZkCluster(ZkCluster zkCluster) {
try {
try {
DashboardLeaderHandler dashboardLeaderHandler = dashboardLeaderTreeCacheMap.remove(zkCluster.getZkClusterKey());
if (dashboardLeaderHandler != null) {
dashboardLeaderHandler.shutdown();
}
} catch (Exception e) {
log.error(e.getMessage(), e);
}
ArrayList<RegistryCenterConfiguration> regCenterConfList = zkCluster.getRegCenterConfList();
if (regCenterConfList != null) {
for (RegistryCenterConfiguration conf : regCenterConfList) {
String nns = conf.getNameAndNamespace();
synchronized (getNnsLock(nns)) {
closeNamespace(nns);
}
}
}
if (zkCluster.getConnectionListener() != null) {
zkCluster.getConnectionListener().shutdownNowUntilTerminated();
zkCluster.setConnectionListener(null);
}
if (zkCluster.getCuratorFrameworkOp() != null && zkCluster.getCuratorFrameworkOp().getCuratorFramework() != null) {
zkCluster.getCuratorFrameworkOp().getCuratorFramework().close();
}
} catch (Exception e) {
log.error(e.getMessage(), e);
}
}
use of com.vip.saturn.job.console.domain.RegistryCenterConfiguration in project Saturn by vipshop.
the class RegistryCenterServiceImpl method refreshNamespaceShardingListenerManagerMap.
/**
* 创建或者移除namespaceShardingManager.
*/
private void refreshNamespaceShardingListenerManagerMap() {
Iterator<Entry<String, ZkCluster>> iterator = zkClusterMap.entrySet().iterator();
while (iterator.hasNext()) {
Entry<String, ZkCluster> next = iterator.next();
ZkCluster zkCluster = next.getValue();
ArrayList<RegistryCenterConfiguration> regCenterConfList = zkCluster.getRegCenterConfList();
if (regCenterConfList == null) {
continue;
}
for (RegistryCenterConfiguration conf : regCenterConfList) {
String nns = conf.getNameAndNamespace();
if (!namespaceShardingListenerManagerMap.containsKey(nns)) {
if (isZKClusterCanBeComputed(conf.getZkClusterKey())) {
createNamespaceShardingManager(conf, nns);
}
} else {
NamespaceShardingManager namespaceShardingManager = namespaceShardingListenerManagerMap.get(nns);
if (!isZKClusterCanBeComputed(conf.getZkClusterKey())) {
namespaceShardingManager.stopWithCurator();
namespaceShardingListenerManagerMap.remove(nns);
}
}
}
}
}
use of com.vip.saturn.job.console.domain.RegistryCenterConfiguration in project Saturn by vipshop.
the class RegistryCenterServiceImpl method getCuratorFrameworkOp.
@Override
public CuratorRepository.CuratorFrameworkOp getCuratorFrameworkOp(String namespace) throws SaturnJobConsoleException {
CuratorRepository.CuratorFrameworkOp curatorFrameworkOp = null;
try {
RegistryCenterConfiguration registryCenterConfiguration = findConfigByNamespace(namespace);
if (registryCenterConfiguration == null) {
throw new SaturnJobConsoleException("find registryCenterConfiguration failed");
}
String nns = registryCenterConfiguration.getNameAndNamespace();
if (nns == null) {
throw new SaturnJobConsoleException("get name and namespace failed");
}
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 curatorFramework = curatorRepository.connect(zkAddressList, namespace, digest);
if (curatorFramework != null) {
registryCenterClient.setConnected(curatorFramework.getZookeeperClient().isConnected());
registryCenterClient.setCuratorClient(curatorFramework);
registryCenterClientMap.put(nns, registryCenterClient);
curatorFrameworkOp = curatorRepository.newCuratorFrameworkOp(curatorFramework);
}
} else {
RegistryCenterClient registryCenterClient = registryCenterClientMap.get(nns);
if (registryCenterClient != null) {
CuratorFramework curatorFramework = registryCenterClient.getCuratorClient();
if (curatorFramework != null) {
registryCenterClient.setConnected(curatorFramework.getZookeeperClient().isConnected());
curatorFrameworkOp = curatorRepository.newCuratorFrameworkOp(curatorFramework);
}
}
}
}
} catch (SaturnJobConsoleException e) {
throw e;
} catch (Exception e) {
throw new SaturnJobConsoleException(e);
}
if (curatorFrameworkOp == null) {
throw new SaturnJobConsoleException("Connect zookeeper failed");
}
return curatorFrameworkOp;
}
Aggregations