Search in sources :

Example 26 with ZkCluster

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;
}
Also used : ArrayList(java.util.ArrayList) ZkCluster(com.vip.saturn.job.console.domain.ZkCluster)

Example 27 with ZkCluster

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);
    }
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) CuratorRepository(com.vip.saturn.job.console.repository.zookeeper.CuratorRepository) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException) ZkCluster(com.vip.saturn.job.console.domain.ZkCluster) CuratorFrameworkOp(com.vip.saturn.job.console.repository.zookeeper.CuratorRepository.CuratorFrameworkOp) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 28 with ZkCluster

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();
}
Also used : Entry(java.util.Map.Entry) TreeNode(com.vip.saturn.job.console.domain.TreeNode) ZkCluster(com.vip.saturn.job.console.domain.ZkCluster)

Example 29 with ZkCluster

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");
}
Also used : RegistryCenterConfiguration(com.vip.saturn.job.console.domain.RegistryCenterConfiguration) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException) ArrayList(java.util.ArrayList) ZkCluster(com.vip.saturn.job.console.domain.ZkCluster) Test(org.junit.Test)

Example 30 with ZkCluster

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);
}
Also used : ZkCluster(com.vip.saturn.job.console.domain.ZkCluster)

Aggregations

ZkCluster (com.vip.saturn.job.console.domain.ZkCluster)37 SuccessResponseEntity (com.vip.saturn.job.console.controller.SuccessResponseEntity)11 ApiResponses (io.swagger.annotations.ApiResponses)11 SaturnJobConsoleException (com.vip.saturn.job.console.exception.SaturnJobConsoleException)9 SaturnStatistics (com.vip.saturn.job.console.mybatis.entity.SaturnStatistics)8 Entry (java.util.Map.Entry)8 RegistryCenterConfiguration (com.vip.saturn.job.console.domain.RegistryCenterConfiguration)7 HashMap (java.util.HashMap)5 Transactional (org.springframework.transaction.annotation.Transactional)5 SaturnJobConsoleHttpException (com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException)4 ArrayList (java.util.ArrayList)4 CuratorRepository (com.vip.saturn.job.console.repository.zookeeper.CuratorRepository)3 CurrentJobConfig (com.vip.saturn.job.console.mybatis.entity.CurrentJobConfig)2 NamespaceInfo (com.vip.saturn.job.console.mybatis.entity.NamespaceInfo)2 CuratorFramework (org.apache.curator.framework.CuratorFramework)2 JSONObject (com.alibaba.fastjson.JSONObject)1 Audit (com.vip.saturn.job.console.aop.annotation.Audit)1 ExportJobConfigPageStatus (com.vip.saturn.job.console.domain.ExportJobConfigPageStatus)1 JobSettings (com.vip.saturn.job.console.domain.JobSettings)1 TreeNode (com.vip.saturn.job.console.domain.TreeNode)1