Search in sources :

Example 31 with ZkCluster

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

the class RegistryCenterServiceImpl method createNamespace.

@Transactional(rollbackFor = { Exception.class })
@Override
public void createNamespace(NamespaceDomainInfo namespaceDomainInfo) throws SaturnJobConsoleException {
    String namespace = namespaceDomainInfo.getNamespace();
    String zkClusterKey = namespaceDomainInfo.getZkCluster();
    ZkCluster currentCluster = getZkCluster(zkClusterKey);
    if (currentCluster == null) {
        throw new SaturnJobConsoleHttpException(HttpStatus.BAD_REQUEST.value(), String.format(ERR_MSG_TEMPLATE_FAIL_TO_CREATE, namespace, "not found zkcluster" + zkClusterKey));
    }
    if (checkNamespaceExists(namespace)) {
        throw new SaturnJobConsoleHttpException(HttpStatus.BAD_REQUEST.value(), String.format(ERR_MSG_NS_ALREADY_EXIST, namespace));
    }
    try {
        // 创建 namespaceInfo
        NamespaceInfo namespaceInfo = constructNamespaceInfo(namespaceDomainInfo);
        namespaceInfoService.create(namespaceInfo);
        // 创建 zkcluster 和 namespaceInfo 关系
        namespaceZkClusterMapping4SqlService.insert(namespace, "", zkClusterKey, NAMESPACE_CREATOR_NAME);
        // refresh
        notifyRefreshRegCenter();
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        throw new SaturnJobConsoleHttpException(HttpStatus.INTERNAL_SERVER_ERROR.value(), String.format(ERR_MSG_TEMPLATE_FAIL_TO_CREATE, namespace, e.getMessage()));
    }
}
Also used : ZkCluster(com.vip.saturn.job.console.domain.ZkCluster) SaturnJobConsoleHttpException(com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException) NamespaceInfo(com.vip.saturn.job.console.mybatis.entity.NamespaceInfo) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException) SaturnJobConsoleHttpException(com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 32 with ZkCluster

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

the class RegistryCenterServiceImpl method refreshDashboardLeaderTreeCache.

private void refreshDashboardLeaderTreeCache() {
    closeDeprecatedDashboardLeaderTreeCache();
    Iterator<Entry<String, ZkCluster>> iterator = zkClusterMap.entrySet().iterator();
    while (iterator.hasNext()) {
        Entry<String, ZkCluster> next = iterator.next();
        String zkClusterKey = next.getKey();
        ZkCluster zkCluster = next.getValue();
        if (needToRefreshDashboardTreeCache(zkCluster, zkClusterKey)) {
            DashboardLeaderHandler dashboardLeaderHandler = null;
            try {
                dashboardLeaderHandler = new DashboardLeaderHandler(zkCluster.getZkAlias(), zkCluster.getCuratorFrameworkOp().getCuratorFramework());
                dashboardLeaderHandler.start();
                dashboardLeaderTreeCacheMap.put(zkClusterKey, dashboardLeaderHandler);
            } catch (Exception e) {
                log.error(e.getMessage(), e);
                if (dashboardLeaderHandler != null) {
                    dashboardLeaderHandler.shutdown();
                }
            }
        }
    }
}
Also used : Entry(java.util.Map.Entry) ZkCluster(com.vip.saturn.job.console.domain.ZkCluster) DashboardLeaderHandler(com.vip.saturn.job.console.service.cache.DashboardLeaderHandler) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException) SaturnJobConsoleHttpException(com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException)

Example 33 with ZkCluster

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

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

the class ExecutorConfigController method createOrUpdateConfig.

@ApiResponses(value = { @ApiResponse(code = 200, message = "Success/Fail", response = RequestResult.class) })
@Audit
@PostMapping
public SuccessResponseEntity createOrUpdateConfig(@AuditParam(value = "key") @RequestParam String key, @AuditParam(value = "value") @RequestParam String value) throws SaturnJobConsoleException {
    assertIsPermitted(PermissionKeys.systemConfig);
    String executorConfigsJsonInDB = systemConfigService.getValueDirectly(SystemConfigProperties.EXECUTOR_CONFIGS);
    JSONObject jsonObject = parseExecutorConfigJson(executorConfigsJsonInDB);
    if (jsonObject == null) {
        jsonObject = new JSONObject();
    }
    // I'm sure that key and value is not null, because @RequestParam required is true
    jsonObject.put(key.trim(), value.trim());
    String configStr = jsonObject.toJSONString();
    log.info("Start to update executor config data {}", configStr);
    // update zk
    List<ZkCluster> onlineZkClusterList = registryCenterService.getOnlineZkClusterList();
    for (ZkCluster zkCluster : onlineZkClusterList) {
        updateConfigInZk(configStr, zkCluster);
    }
    // update db
    SystemConfig systemConfig = new SystemConfig();
    systemConfig.setProperty(SystemConfigProperties.EXECUTOR_CONFIGS);
    systemConfig.setValue(configStr);
    systemConfigService.insertOrUpdate(systemConfig);
    log.info("Update executor config to db successfully");
    return new SuccessResponseEntity();
}
Also used : SystemConfig(com.vip.saturn.job.console.mybatis.entity.SystemConfig) JSONObject(com.alibaba.fastjson.JSONObject) SuccessResponseEntity(com.vip.saturn.job.console.controller.SuccessResponseEntity) ZkCluster(com.vip.saturn.job.console.domain.ZkCluster) Audit(com.vip.saturn.job.console.aop.annotation.Audit) PostMapping(org.springframework.web.bind.annotation.PostMapping) ApiResponses(io.swagger.annotations.ApiResponses)

Example 35 with ZkCluster

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

the class DashboardController method getStatistics.

@ApiResponses(value = { @ApiResponse(code = 200, message = "Success/Fail", response = RequestResult.class) })
@GetMapping(value = "/count")
public SuccessResponseEntity getStatistics(@RequestParam(required = false) String zkClusterKey) throws SaturnJobConsoleException {
    Map<String, Integer> countMap = Maps.newHashMap();
    int executorInDockerCount = 0;
    int executorNotInDockerCount = 0;
    int jobCount = 0;
    int domainCount = 0;
    Collection<ZkCluster> zkClusters = null;
    if (StringUtils.isNotBlank(zkClusterKey)) {
        ZkCluster zkCluster = registryCenterService.getZkCluster(zkClusterKey);
        zkClusters = Lists.newArrayList();
        zkClusters.add(zkCluster);
    } else {
        zkClusters = registryCenterService.getZkClusterList();
    }
    for (ZkCluster zkCluster : zkClusters) {
        // 不统计离线的zkcluster
        if (zkCluster.isOffline()) {
            continue;
        }
        String zkAddr = zkCluster.getZkAddr();
        if (zkAddr != null) {
            executorInDockerCount += dashboardService.executorInDockerCount(zkAddr);
            executorNotInDockerCount += dashboardService.executorNotInDockerCount(zkAddr);
            jobCount += dashboardService.jobCount(zkAddr);
        }
        domainCount += registryCenterService.domainCount(zkCluster.getZkClusterKey());
    }
    countMap.put("executorInDockerCount", executorInDockerCount);
    countMap.put("executorNotInDockerCount", executorNotInDockerCount);
    countMap.put("jobCount", jobCount);
    countMap.put("domainCount", domainCount);
    return new SuccessResponseEntity(countMap);
}
Also used : SuccessResponseEntity(com.vip.saturn.job.console.controller.SuccessResponseEntity) ZkCluster(com.vip.saturn.job.console.domain.ZkCluster) ApiResponses(io.swagger.annotations.ApiResponses)

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