use of com.vip.saturn.job.console.domain.ZkCluster in project Saturn by vipshop.
the class NamespaceZkClusterMappingServiceImpl method getZkClusterListWithOnline.
@Override
public List<String> getZkClusterListWithOnline() throws SaturnJobConsoleException {
List<String> zkClusterList = new ArrayList<>();
Collection<ZkCluster> tmp = registryCenterService.getZkClusterList();
if (tmp != null) {
Iterator<ZkCluster> iterator = tmp.iterator();
while (iterator.hasNext()) {
ZkCluster next = iterator.next();
if (!next.isOffline()) {
zkClusterList.add(next.getZkClusterKey());
}
}
}
return zkClusterList;
}
use of com.vip.saturn.job.console.domain.ZkCluster in project Saturn by vipshop.
the class NamespaceZkClusterMappingServiceImpl method migrateNamespaceToNewZk.
@Transactional(rollbackFor = { SaturnJobConsoleException.class })
@Override
public void migrateNamespaceToNewZk(String namespace, String zkClusterKeyNew, String lastUpdatedBy, boolean updateDBOnly) throws SaturnJobConsoleException {
try {
log.info("Start to migrate namespace: [{}] to zk cluster:[{}]", namespace, zkClusterKeyNew);
if (updateDBOnly) {
namespaceZkclusterMapping4SqlService.update(namespace, null, zkClusterKeyNew, lastUpdatedBy);
} else {
String zkClusterKey = namespaceZkclusterMapping4SqlService.getZkClusterKey(namespace);
if (zkClusterKey != null && zkClusterKey.equals(zkClusterKeyNew)) {
// see migrateNamespaceListToNewZk before modify
throw new SaturnJobConsoleException("The namespace(" + namespace + ") is in " + zkClusterKey);
}
ZkCluster zkCluster = registryCenterService.getZkCluster(zkClusterKeyNew);
if (zkCluster == null) {
throw new SaturnJobConsoleException("The " + zkClusterKeyNew + " is not exists");
}
if (zkCluster.isOffline()) {
throw new SaturnJobConsoleException("The " + zkClusterKeyNew + " zkCluster is offline");
}
String zkAddr = zkCluster.getZkAddr();
CuratorRepository.CuratorFrameworkOp targetCuratorFrameworkOpByRoot = registryCenterService.connectOnly(zkAddr, null);
if (targetCuratorFrameworkOpByRoot == null) {
throw new SaturnJobConsoleException("The " + zkClusterKeyNew + " zkCluster is offline");
}
CuratorFramework targetCuratorFrameworkByRoot = targetCuratorFrameworkOpByRoot.getCuratorFramework();
CuratorRepository.CuratorFrameworkOp targetCuratorFrameworkOpByNamespace = registryCenterService.connectOnly(zkAddr, namespace);
CuratorFramework targetCuratorFrameworkByNamespace = targetCuratorFrameworkOpByNamespace.getCuratorFramework();
try {
String namespaceNodePath = "/" + namespace;
if (targetCuratorFrameworkByRoot.checkExists().forPath(namespaceNodePath) != null) {
targetCuratorFrameworkByRoot.delete().deletingChildrenIfNeeded().forPath(namespaceNodePath);
}
String jobsNodePath = namespaceNodePath + JobNodePath.get$JobsNodePath();
targetCuratorFrameworkByRoot.create().creatingParentsIfNeeded().withMode(CreateMode.PERSISTENT).forPath(jobsNodePath);
persistJobsToTargetZkCluster(namespace, targetCuratorFrameworkOpByNamespace);
} finally {
targetCuratorFrameworkByRoot.close();
targetCuratorFrameworkByNamespace.close();
}
namespaceZkclusterMapping4SqlService.update(namespace, null, zkClusterKeyNew, lastUpdatedBy);
log.info("Update zkcluster mapping between ns:[{}] and zk:[{}] in DB successfully", namespace, zkClusterKeyNew);
}
} catch (SaturnJobConsoleException e) {
log.error("Fail to migrate namespace:[" + namespace + "] to zk [" + zkClusterKeyNew + "]", e);
throw e;
} catch (Exception e) {
log.error("Fail to migrate namespace:[" + namespace + "] to zk [" + zkClusterKeyNew + "] with unexpected exception", e);
throw new SaturnJobConsoleException(e.getMessage(), e);
} finally {
log.info("Finish migrate namespace:[{}] to zk zkcluster:[{}]", namespace, zkClusterKeyNew);
}
}
use of com.vip.saturn.job.console.domain.ZkCluster in project Saturn by vipshop.
the class RegistryCenterServiceImpl method refreshTreeData.
private void refreshTreeData() {
// clear removed zkCluster treeData
Iterator<Entry<String, TreeNode>> iterator = InitRegistryCenterService.ZKBSKEY_TO_TREENODE_MAP.entrySet().iterator();
while (iterator.hasNext()) {
Entry<String, TreeNode> next = iterator.next();
String zkClusterKey = next.getKey();
if (!zkClusterMap.containsKey(zkClusterKey)) {
iterator.remove();
}
}
// refresh online zkCluster treeData, clear offline zkCluster treeData
Collection<ZkCluster> zkClusters = zkClusterMap.values();
for (ZkCluster zkCluster : zkClusters) {
refreshTreeData(zkCluster);
}
InitRegistryCenterService.reloadDomainRootTreeNode();
}
use of com.vip.saturn.job.console.domain.ZkCluster in project Saturn by vipshop.
the class RegistryCenterServiceImplTest method testDeleteZkClusterFail.
@Test
public void testDeleteZkClusterFail() throws Exception {
// delete fail
when(zkClusterMap.get("empty")).thenReturn(null);
try {
registryCenterService.deleteZkCluster("empty");
fail("should not be here");
} catch (SaturnJobConsoleException e) {
Assert.assertEquals("fail to delete.for ZkCluster does not exist", e.getMessage());
}
// delete fail
ZkCluster zkCluster = new ZkCluster();
ArrayList<RegistryCenterConfiguration> regCenterConfList = new ArrayList();
zkCluster.setRegCenterConfList(regCenterConfList);
regCenterConfList.add(new RegistryCenterConfiguration());
when(zkClusterMap.get("hasDomains")).thenReturn(zkCluster);
try {
registryCenterService.deleteZkCluster("hasDomains");
fail("should not be here");
} catch (SaturnJobConsoleException e) {
Assert.assertEquals("fail to delete.for ZkCluster still has domains", e.getMessage());
}
// delete fail
when(zkClusterMap.get("noDomainsInMemory")).thenReturn(new ZkCluster());
when(namespaceZkClusterMapping4SqlService.getAllNamespacesOfCluster("noDomainsInMemory")).thenReturn(Arrays.asList(""));
try {
registryCenterService.deleteZkCluster("noDomainsInMemory");
fail("should not be here");
} catch (SaturnJobConsoleException e) {
Assert.assertEquals("fail to delete.for ZkCluster still has domains", e.getMessage());
}
// delete success
when(namespaceZkClusterMapping4SqlService.getAllNamespacesOfCluster("noDomainsInMemory")).thenReturn(null);
registryCenterService.deleteZkCluster("noDomainsInMemory");
verify(zkClusterInfoService, times(1)).deleteZkCluster("noDomainsInMemory");
}
use of com.vip.saturn.job.console.domain.ZkCluster in project Saturn by vipshop.
the class RegistryCenterServiceImpl method refreshRegistryCenterForNamespace.
@Override
public synchronized void refreshRegistryCenterForNamespace(String zkClusterName, String namespace) {
ZkCluster targetZkCluster;
Map<String, ZkCluster> zkClusterMap;
zkClusterMap = getTargetZkCluster(zkClusterName);
updateRegistryCenterConfiguration(namespace, zkClusterMap.get(zkClusterName).getZkAddr(), zkClusterName);
closeInvalidZkClient(zkClusterMap);
connectToZkClusterIfPossible(zkClusterMap);
targetZkCluster = zkClusterMap.get(zkClusterName);
if (targetZkCluster != null) {
List<String> allOnlineNamespacesTemp = new ArrayList<>();
List filteredList = getTargetNamespaceZkClusterMapping(zkClusterName, namespace);
initOrUpdateNamespace(allOnlineNamespacesTemp, targetZkCluster, filteredList, targetZkCluster.getRegCenterConfList());
updateAllOnlineNamespaces(namespace);
}
log.info("refreshRegistryCenterForNamespace done : {}, {}", zkClusterName, namespace);
}
Aggregations