Search in sources :

Example 41 with CuratorFrameworkOp

use of com.vip.saturn.job.console.repository.zookeeper.CuratorRepository.CuratorFrameworkOp in project Saturn by vipshop.

the class JobServiceImpl method removeJob.

@Transactional(rollbackFor = Exception.class)
@Override
public void removeJob(String namespace, String jobName) throws SaturnJobConsoleException {
    JobConfig4DB jobConfig4DB = currentJobConfigService.findConfigByNamespaceAndJobName(namespace, jobName);
    if (jobConfig4DB == null) {
        throw new SaturnJobConsoleException(ERROR_CODE_NOT_EXISTED, "不能删除该作业(" + jobName + "),因为该作业不存在");
    }
    String upStream = jobConfig4DB.getUpStream();
    if (StringUtils.isNotBlank(upStream)) {
        throw new SaturnJobConsoleException(ERROR_CODE_NOT_EXISTED, "不能删除该作业(" + jobName + "),因为该作业存在上游作业(" + upStream + "),请先断开上下游关系再删除");
    }
    String downStream = jobConfig4DB.getDownStream();
    if (StringUtils.isNotBlank(downStream)) {
        throw new SaturnJobConsoleException(ERROR_CODE_NOT_EXISTED, "不能删除该作业(" + jobName + "),因为该作业存在下游作业(" + downStream + "),请先断开上下游关系再删除");
    }
    CuratorRepository.CuratorFrameworkOp curatorFrameworkOp = registryCenterService.getCuratorFrameworkOp(namespace);
    JobStatus jobStatus = getJobStatus(jobName, curatorFrameworkOp, jobConfig4DB.getEnabled());
    if (JobStatus.STOPPED != jobStatus) {
        throw new SaturnJobConsoleException(ERROR_CODE_BAD_REQUEST, String.format("不能删除该作业(%s),因为该作业不处于STOPPED状态", jobName));
    }
    Stat stat = curatorFrameworkOp.getStat(JobNodePath.getJobNodePath(jobName));
    if (stat != null) {
        long createTimeDiff = System.currentTimeMillis() - stat.getCtime();
        if (createTimeDiff < SaturnConstants.JOB_CAN_BE_DELETE_TIME_LIMIT) {
            throw new SaturnJobConsoleException(ERROR_CODE_BAD_REQUEST, String.format("不能删除该作业(%s),因为该作业创建时间距离现在不超过%d分钟", jobName, SaturnConstants.JOB_CAN_BE_DELETE_TIME_LIMIT / 60000));
        }
    }
    // remove job from db
    currentJobConfigService.deleteByPrimaryKey(jobConfig4DB.getId());
    // remove job from zk
    removeJobFromZk(jobName, curatorFrameworkOp);
}
Also used : Stat(org.apache.zookeeper.data.Stat) CuratorRepository(com.vip.saturn.job.console.repository.zookeeper.CuratorRepository) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException) CuratorFrameworkOp(com.vip.saturn.job.console.repository.zookeeper.CuratorRepository.CuratorFrameworkOp) JobConfig4DB(com.vip.saturn.job.console.mybatis.entity.JobConfig4DB) Transactional(org.springframework.transaction.annotation.Transactional)

Example 42 with CuratorFrameworkOp

use of com.vip.saturn.job.console.repository.zookeeper.CuratorRepository.CuratorFrameworkOp in project Saturn by vipshop.

the class DashboardServiceImpl method cleanShardingCount.

@Override
public void cleanShardingCount(String namespace) throws SaturnJobConsoleException {
    CuratorFrameworkOp curatorFrameworkOp = registryCenterService.getCuratorFrameworkOp(namespace);
    curatorFrameworkOp.update(ExecutorNodePath.SHARDING_COUNT_PATH, "0");
    asyncForceRefreshStatistics(namespace);
}
Also used : CuratorFrameworkOp(com.vip.saturn.job.console.repository.zookeeper.CuratorRepository.CuratorFrameworkOp)

Example 43 with CuratorFrameworkOp

use of com.vip.saturn.job.console.repository.zookeeper.CuratorRepository.CuratorFrameworkOp in project Saturn by vipshop.

the class DashboardServiceImpl method cleanOneJobAnalyse.

@Override
public void cleanOneJobAnalyse(String namespace, String jobName) throws SaturnJobConsoleException {
    CuratorFrameworkOp curatorFrameworkOp = registryCenterService.getCuratorFrameworkOp(namespace);
    updateResetValue(curatorFrameworkOp, jobName, ResetCountType.RESET_ANALYSE);
    resetOneJobAnalyse(jobName, curatorFrameworkOp);
    asyncForceRefreshStatistics(namespace);
}
Also used : CuratorFrameworkOp(com.vip.saturn.job.console.repository.zookeeper.CuratorRepository.CuratorFrameworkOp)

Example 44 with CuratorFrameworkOp

use of com.vip.saturn.job.console.repository.zookeeper.CuratorRepository.CuratorFrameworkOp in project Saturn by vipshop.

the class ExecutorServiceImpl method getExecutorAllocation.

@Override
public ServerAllocationInfo getExecutorAllocation(String namespace, String executorName) throws SaturnJobConsoleException {
    CuratorRepository.CuratorFrameworkOp curatorFrameworkOp = getCuratorFrameworkOp(namespace);
    List<JobConfig> unSystemJobs = jobService.getUnSystemJobs(namespace);
    ServerAllocationInfo serverAllocationInfo = new ServerAllocationInfo(executorName);
    for (JobConfig jobConfig : unSystemJobs) {
        String jobName = jobConfig.getJobName();
        String serverNodePath = JobNodePath.getServerNodePath(jobName);
        if (!curatorFrameworkOp.checkExists(serverNodePath)) {
            continue;
        }
        String sharding = curatorFrameworkOp.getData(JobNodePath.getServerNodePath(jobName, executorName, "sharding"));
        if (StringUtils.isNotBlank(sharding)) {
            // 作业状态为STOPPED的即使有残留分片也不显示该分片
            if (JobStatus.STOPPED.equals(jobService.getJobStatus(namespace, jobName))) {
                continue;
            }
            // concat executorSharding
            serverAllocationInfo.getAllocationMap().put(jobName, sharding);
            // calculate totalLoad
            String loadLevelNode = curatorFrameworkOp.getData(JobNodePath.getConfigNodePath(jobName, "loadLevel"));
            Integer loadLevel = 1;
            if (StringUtils.isNotBlank(loadLevelNode)) {
                loadLevel = Integer.valueOf(loadLevelNode);
            }
            int shardingItemNum = sharding.split(",").length;
            int curJobLoad = shardingItemNum * loadLevel;
            int totalLoad = serverAllocationInfo.getTotalLoadLevel();
            serverAllocationInfo.setTotalLoadLevel(totalLoad + curJobLoad);
        }
    }
    return serverAllocationInfo;
}
Also used : CuratorRepository(com.vip.saturn.job.console.repository.zookeeper.CuratorRepository) CuratorFrameworkOp(com.vip.saturn.job.console.repository.zookeeper.CuratorRepository.CuratorFrameworkOp)

Example 45 with CuratorFrameworkOp

use of com.vip.saturn.job.console.repository.zookeeper.CuratorRepository.CuratorFrameworkOp in project Saturn by vipshop.

the class ExecutorServiceImpl method extractTraffic.

@Override
public void extractTraffic(String namespace, String executorName) throws SaturnJobConsoleException {
    CuratorRepository.CuratorFrameworkOp curatorFrameworkOp = getCuratorFrameworkOp(namespace);
    validateIfExecutorNameExisted(executorName, curatorFrameworkOp);
    curatorFrameworkOp.create(ExecutorNodePath.getExecutorNoTrafficNodePath(executorName));
}
Also used : CuratorRepository(com.vip.saturn.job.console.repository.zookeeper.CuratorRepository) CuratorFrameworkOp(com.vip.saturn.job.console.repository.zookeeper.CuratorRepository.CuratorFrameworkOp)

Aggregations

CuratorFrameworkOp (com.vip.saturn.job.console.repository.zookeeper.CuratorRepository.CuratorFrameworkOp)49 CuratorRepository (com.vip.saturn.job.console.repository.zookeeper.CuratorRepository)35 SaturnJobConsoleException (com.vip.saturn.job.console.exception.SaturnJobConsoleException)22 Transactional (org.springframework.transaction.annotation.Transactional)9 JobConfig4DB (com.vip.saturn.job.console.mybatis.entity.JobConfig4DB)8 SaturnJobConsoleHttpException (com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException)6 ParseException (java.text.ParseException)6 Stat (org.apache.zookeeper.data.Stat)3 RequestResult (com.vip.saturn.job.console.domain.RequestResult)2 Boolean (java.lang.Boolean)2 CuratorFramework (org.apache.curator.framework.CuratorFramework)2 JobConsoleException (com.vip.saturn.job.console.exception.JobConsoleException)1 CurrentJobConfig (com.vip.saturn.job.console.mybatis.entity.CurrentJobConfig)1 SaturnStatistics (com.vip.saturn.job.console.mybatis.entity.SaturnStatistics)1 ZkClusterInfo (com.vip.saturn.job.console.mybatis.entity.ZkClusterInfo)1 GetJobConfigVo (com.vip.saturn.job.console.vo.GetJobConfigVo)1 File (java.io.File)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 Label (jxl.write.Label)1 WritableSheet (jxl.write.WritableSheet)1