Search in sources :

Example 26 with RegistryCenterConfiguration

use of com.vip.saturn.job.console.domain.RegistryCenterConfiguration in project Saturn by vipshop.

the class DashboardServiceImpl method asyncForceRefreshStatistics.

private void asyncForceRefreshStatistics(final String namespace) {
    Runnable runnable = new Runnable() {

        @Override
        public void run() {
            try {
                RegistryCenterConfiguration conf = registryCenterService.findConfigByNamespace(namespace);
                if (conf != null) {
                    statisticsRefreshService.refresh(conf.getZkClusterKey(), false);
                }
            } catch (Throwable t) {
                log.error("async refresh statistics error", t);
            }
        }
    };
    updateStatisticsThreadPool.submit(runnable);
}
Also used : RegistryCenterConfiguration(com.vip.saturn.job.console.domain.RegistryCenterConfiguration)

Example 27 with RegistryCenterConfiguration

use of com.vip.saturn.job.console.domain.RegistryCenterConfiguration 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 28 with RegistryCenterConfiguration

use of com.vip.saturn.job.console.domain.RegistryCenterConfiguration in project Saturn by vipshop.

the class NamespaceServiceImpl method deleteNamespace.

@Override
public void deleteNamespace(String namespace) throws SaturnJobConsoleException {
    boolean online = isExecutorsOnline(namespace);
    if (online) {
        log.info("namespace {} has online executor, can not delete it", namespace);
        throw new SaturnJobConsoleException(ERROR_CODE_BAD_REQUEST, "namespace has online executor, can not delete it");
    } else {
        RegistryCenterConfiguration registryCenterConfiguration = registryCenterService.findConfigByNamespace(namespace);
        deleteInfosInDB(namespace);
        deleteNamespaceInZk(registryCenterConfiguration, namespace);
    }
}
Also used : RegistryCenterConfiguration(com.vip.saturn.job.console.domain.RegistryCenterConfiguration) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException)

Example 29 with RegistryCenterConfiguration

use of com.vip.saturn.job.console.domain.RegistryCenterConfiguration in project Saturn by vipshop.

the class RegistryCenterServiceImpl method refreshRegistryCenter.

private void refreshRegistryCenter() {
    List<String> allOnlineNamespacesTemp = new ArrayList<>();
    // 获取新的zkClusters
    Map<String, ZkCluster> newClusterMap = getZkClusterInfo();
    // 对比旧的。不包含的,关闭操作;包含的,检查属性是否相同,如果相同,则直接赋值,否则,关闭旧的
    closeInvalidZkClient(newClusterMap);
    // 完善curatorFramework。如果没有,则新建
    connectToZkClusterIfPossible(newClusterMap);
    // 完善ZkCluster中的注册中心信息,关闭迁移了的域,新建迁移过来的域
    for (Map.Entry<String, ZkCluster> zkClusterEntry : newClusterMap.entrySet()) {
        ZkCluster zkCluster = zkClusterEntry.getValue();
        String key = zkClusterEntry.getKey();
        List<NamespaceZkClusterMapping> nsZkClusterMappingList = namespaceZkClusterMapping4SqlService.getAllMappingsOfCluster(key);
        // zkCluster对应的namespace列表
        List<RegistryCenterConfiguration> regCenterConfList = zkCluster.getRegCenterConfList();
        closeMoveOutNamespace(key, nsZkClusterMappingList, regCenterConfList);
        initOrUpdateNamespace(allOnlineNamespacesTemp, zkCluster, nsZkClusterMappingList, regCenterConfList);
    }
    // 直接赋值新的
    zkClusterMap = (LinkedHashMap<String, ZkCluster>) newClusterMap;
    log.info("new zkClusterMap is : {}", zkClusterMap);
    allOnlineNamespaces = allOnlineNamespacesTemp;
}
Also used : NamespaceZkClusterMapping(com.vip.saturn.job.console.mybatis.entity.NamespaceZkClusterMapping) RegistryCenterConfiguration(com.vip.saturn.job.console.domain.RegistryCenterConfiguration) ZkCluster(com.vip.saturn.job.console.domain.ZkCluster) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 30 with RegistryCenterConfiguration

use of com.vip.saturn.job.console.domain.RegistryCenterConfiguration in project Saturn by vipshop.

the class RegistryCenterServiceImpl method exportNamespaceInfo2Excel.

/**
 * Export namespac
 */
File exportNamespaceInfo2Excel(List<RegistryCenterConfiguration> namespaceInfoList) throws SaturnJobConsoleException {
    try {
        File tmpFile = SaturnConsoleUtils.createTmpFile();
        WritableWorkbook writableWorkbook = Workbook.createWorkbook(tmpFile);
        WritableSheet sheet1 = writableWorkbook.createSheet("ns", 0);
        sheet1.addCell(new Label(0, 0, "域名"));
        sheet1.addCell(new Label(1, 0, "描述"));
        sheet1.addCell(new Label(2, 0, "重要等级"));
        sheet1.addCell(new Label(3, 0, "Executor版本"));
        sheet1.addCell(new Label(4, 0, "ZK集群"));
        for (int i = 0; i < namespaceInfoList.size(); i++) {
            RegistryCenterConfiguration namespaceInfo = namespaceInfoList.get(i);
            sheet1.addCell(new Label(0, i + 1, namespaceInfo.getNamespace()));
            sheet1.addCell(new Label(1, i + 1, namespaceInfo.getName()));
            sheet1.addCell(new Label(2, i + 1, namespaceInfo.getDegree()));
            sheet1.addCell(new Label(3, i + 1, namespaceInfo.getVersion()));
            sheet1.addCell(new Label(4, i + 1, namespaceInfo.getZkAlias()));
        }
        writableWorkbook.write();
        writableWorkbook.close();
        return tmpFile;
    } catch (Exception e) {
        throw new SaturnJobConsoleException(e);
    }
}
Also used : WritableWorkbook(jxl.write.WritableWorkbook) RegistryCenterConfiguration(com.vip.saturn.job.console.domain.RegistryCenterConfiguration) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException) Label(jxl.write.Label) WritableSheet(jxl.write.WritableSheet) File(java.io.File) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException) SaturnJobConsoleHttpException(com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException)

Aggregations

RegistryCenterConfiguration (com.vip.saturn.job.console.domain.RegistryCenterConfiguration)31 RegistryCenterClient (com.vip.saturn.job.console.domain.RegistryCenterClient)9 SaturnJobConsoleException (com.vip.saturn.job.console.exception.SaturnJobConsoleException)9 ZkCluster (com.vip.saturn.job.console.domain.ZkCluster)7 CuratorFramework (org.apache.curator.framework.CuratorFramework)7 SaturnJobConsoleHttpException (com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException)4 NamespaceZkClusterMapping (com.vip.saturn.job.console.mybatis.entity.NamespaceZkClusterMapping)4 CuratorRepository (com.vip.saturn.job.console.repository.zookeeper.CuratorRepository)4 ArrayList (java.util.ArrayList)3 TreeNode (com.vip.saturn.job.console.domain.TreeNode)2 NamespaceInfo (com.vip.saturn.job.console.mybatis.entity.NamespaceInfo)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 JobSettings (com.vip.saturn.job.console.domain.JobSettings)1 RequestResult (com.vip.saturn.job.console.domain.RequestResult)1 CurrentJobConfig (com.vip.saturn.job.console.mybatis.entity.CurrentJobConfig)1 DashboardLeaderHandler (com.vip.saturn.job.console.service.cache.DashboardLeaderHandler)1 NamespaceShardingManager (com.vip.saturn.job.sharding.NamespaceShardingManager)1 File (java.io.File)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1