Search in sources :

Example 86 with SaturnJobConsoleException

use of com.vip.saturn.job.console.exception.SaturnJobConsoleException in project Saturn by vipshop.

the class NamespaceAndJobServiceImpl method createNamespaceAndCloneJobs.

@Override
public void createNamespaceAndCloneJobs(String srcNamespace, String namespace, String zkClusterName, String createBy) throws SaturnJobConsoleException {
    logger.info("start createNamespaceAndCloneJobs, srcNamespace: {}, namespace: {}, zkClusterName: {}", srcNamespace, namespace, zkClusterName);
    NamespaceZkClusterMapping mapping = namespaceZkClusterMappingRepository.selectByNamespace(srcNamespace);
    if (mapping == null) {
        throw new SaturnJobConsoleException("no zkCluster mapping is not found");
    }
    NamespaceDomainInfo namespaceInfo = new NamespaceDomainInfo();
    namespaceInfo.setNamespace(namespace);
    namespaceInfo.setZkCluster(zkClusterName);
    namespaceInfo.setContent("");
    try {
        registryCenterService.createNamespace(namespaceInfo);
        registryCenterService.refreshRegistryCenterForNamespace(zkClusterName, srcNamespace);
    } catch (SaturnJobConsoleHttpException e) {
        if (StringUtils.equals(String.format(ERR_MSG_NS_ALREADY_EXIST, namespace), e.getMessage())) {
            logger.warn("namespace already exists, ignore this exception and move on");
        } else {
            throw e;
        }
    }
    namespaceService.importJobsFromNamespaceToNamespace(srcNamespace, namespace, createBy);
    logger.info("finish createNamespaceAndCloneJobs, srcNamespace: {}, namespace: {}, zkClusterName: {}", srcNamespace, namespace, zkClusterName);
}
Also used : NamespaceZkClusterMapping(com.vip.saturn.job.console.mybatis.entity.NamespaceZkClusterMapping) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException) NamespaceDomainInfo(com.vip.saturn.job.console.domain.NamespaceDomainInfo) SaturnJobConsoleHttpException(com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException)

Example 87 with SaturnJobConsoleException

use of com.vip.saturn.job.console.exception.SaturnJobConsoleException 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 88 with SaturnJobConsoleException

use of com.vip.saturn.job.console.exception.SaturnJobConsoleException in project Saturn by vipshop.

the class NamespaceZkClusterMappingServiceImpl method getNamespaceZkClusterMappingList.

@Override
public List<NamespaceZkClusterMappingVo> getNamespaceZkClusterMappingList() throws SaturnJobConsoleException {
    List<NamespaceZkClusterMappingVo> result = new ArrayList<>();
    List<NamespaceZkClusterMapping> namespaceZkClusterMappingList = namespaceZkclusterMapping4SqlService.getAllMappings();
    if (namespaceZkClusterMappingList != null) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        for (NamespaceZkClusterMapping tmp : namespaceZkClusterMappingList) {
            try {
                if (tmp.getIsDeleted() == 0) {
                    NamespaceZkClusterMappingVo vo = new NamespaceZkClusterMappingVo();
                    vo.setNamespace(tmp.getNamespace());
                    vo.setZkClusterKey(tmp.getZkClusterKey());
                    vo.setCreateTime(sdf.format(tmp.getCreateTime()));
                    vo.setCreatedBy(tmp.getCreatedBy());
                    vo.setLastUpdateTime(sdf.format(tmp.getLastUpdateTime()));
                    vo.setLastUpdatedBy(tmp.getLastUpdatedBy());
                    result.add(vo);
                }
            } catch (Exception e) {
                log.error(e.getMessage(), e);
            }
        }
    }
    return result;
}
Also used : NamespaceZkClusterMapping(com.vip.saturn.job.console.mybatis.entity.NamespaceZkClusterMapping) ArrayList(java.util.ArrayList) NamespaceZkClusterMappingVo(com.vip.saturn.job.console.domain.NamespaceZkClusterMappingVo) SimpleDateFormat(java.text.SimpleDateFormat) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException)

Example 89 with SaturnJobConsoleException

use of com.vip.saturn.job.console.exception.SaturnJobConsoleException in project Saturn by vipshop.

the class MarathonServiceImpl method getContainerScaleJobShardingItemParameters.

private String getContainerScaleJobShardingItemParameters(ContainerToken containerToken, String appId, Integer instances) throws SaturnJobConsoleException {
    try {
        String auth = Base64.encodeBase64String((containerToken.getUserName() + ":" + containerToken.getPassword()).getBytes("UTF-8"));
        String url = "";
        if (SaturnEnvProperties.VIP_SATURN_DCOS_REST_URI != null && SaturnEnvProperties.VIP_SATURN_DCOS_REST_URI.endsWith("/")) {
            url = SaturnEnvProperties.VIP_SATURN_DCOS_REST_URI + "v2/apps/" + appId + "?force=true";
        } else {
            url = SaturnEnvProperties.VIP_SATURN_DCOS_REST_URI + "/v2/apps/" + appId + "?force=true";
        }
        return "0=curl -X PUT -H \"Content-Type:application/json\" -H \"Authorization:Basic " + auth + "\" --data '{\"instances\":" + instances + "}' " + url;
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        throw new SaturnJobConsoleException(e);
    }
}
Also used : SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException)

Example 90 with SaturnJobConsoleException

use of com.vip.saturn.job.console.exception.SaturnJobConsoleException in project Saturn by vipshop.

the class AuthorizationManageServiceImpl method addUserRole.

@Transactional(rollbackFor = Exception.class)
@Override
public void addUserRole(UserRole userRole) throws SaturnJobConsoleException {
    validateUser(userRole);
    // check role is existing
    String roleKey = userRole.getRoleKey();
    Role role = roleRepository.selectByKey(roleKey);
    if (role == null) {
        throw new SaturnJobConsoleException(String.format("角色key(%s)不存在", roleKey));
    }
    // insert or update userRole
    UserRole pre = userRoleRepository.selectWithNotFilterDeleted(userRole);
    if (pre == null) {
        userRoleRepository.insert(userRole);
    } else {
        userRoleRepository.update(pre, userRole);
    }
}
Also used : UserRole(com.vip.saturn.job.console.mybatis.entity.UserRole) Role(com.vip.saturn.job.console.mybatis.entity.Role) UserRole(com.vip.saturn.job.console.mybatis.entity.UserRole) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

SaturnJobConsoleException (com.vip.saturn.job.console.exception.SaturnJobConsoleException)190 SaturnJobConsoleHttpException (com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException)56 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)56 CuratorRepository (com.vip.saturn.job.console.repository.zookeeper.CuratorRepository)39 RequestResult (com.vip.saturn.job.console.domain.RequestResult)31 ParseException (java.text.ParseException)28 ResponseEntity (org.springframework.http.ResponseEntity)26 Transactional (org.springframework.transaction.annotation.Transactional)23 JobConfig4DB (com.vip.saturn.job.console.mybatis.entity.JobConfig4DB)22 CuratorFrameworkOp (com.vip.saturn.job.console.repository.zookeeper.CuratorRepository.CuratorFrameworkOp)22 IOException (java.io.IOException)19 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)19 StatusLine (org.apache.http.StatusLine)18 HttpEntity (org.apache.http.HttpEntity)16 Audit (com.vip.saturn.job.console.aop.annotation.Audit)13 JobConfig (com.vip.saturn.job.console.domain.JobConfig)11 HttpHeaders (org.springframework.http.HttpHeaders)11 CurrentJobConfig (com.vip.saturn.job.console.mybatis.entity.CurrentJobConfig)9 ZkCluster (com.vip.saturn.job.console.domain.ZkCluster)8 ArrayList (java.util.ArrayList)8