Search in sources :

Example 36 with CuratorFrameworkOp

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

the class JobServiceImpl method setPreferList.

@Transactional(rollbackFor = Exception.class)
@Override
public void setPreferList(String namespace, String jobName, String preferList, String updatedBy) throws SaturnJobConsoleException {
    // save to db
    JobConfig4DB oldJobConfig = currentJobConfigService.findConfigByNamespaceAndJobName(namespace, jobName);
    if (oldJobConfig == null) {
        throw new SaturnJobConsoleException(ERROR_CODE_NOT_EXISTED, "设置该作业(" + jobName + ")优先Executor失败,因为该作业不存在");
    }
    // 启用状态的本地模式作业,不能设置preferList
    Boolean enabled = oldJobConfig.getEnabled();
    Boolean localMode = oldJobConfig.getLocalMode();
    if (enabled != null && enabled && localMode != null && localMode) {
        throw new SaturnJobConsoleException(ERROR_CODE_BAD_REQUEST, String.format("启用状态的本地模式作业(%s),不能设置优先Executor,请先禁用它", jobName));
    }
    JobConfig4DB newJobConfig = new JobConfig4DB();
    BeanUtils.copyProperties(oldJobConfig, newJobConfig);
    newJobConfig.setPreferList(preferList);
    currentJobConfigService.updateNewAndSaveOld2History(newJobConfig, oldJobConfig, updatedBy);
    // save to zk
    CuratorRepository.CuratorFrameworkOp curatorFrameworkOp = registryCenterService.getCuratorFrameworkOp(namespace);
    String jobConfigPreferListNodePath = SaturnExecutorsNode.getJobConfigPreferListNodePath(jobName);
    curatorFrameworkOp.update(jobConfigPreferListNodePath, preferList);
    // delete and create the forceShard node
    String jobConfigForceShardNodePath = SaturnExecutorsNode.getJobConfigForceShardNodePath(jobName);
    curatorFrameworkOp.delete(jobConfigForceShardNodePath);
    curatorFrameworkOp.create(jobConfigForceShardNodePath);
}
Also used : 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) Boolean(java.lang.Boolean) Transactional(org.springframework.transaction.annotation.Transactional)

Example 37 with CuratorFrameworkOp

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

the class JobServiceImpl method getCandidateExecutors.

@Override
public List<ExecutorProvided> getCandidateExecutors(String namespace, String jobName) throws SaturnJobConsoleException {
    JobConfig4DB currentJobConfig = currentJobConfigService.findConfigByNamespaceAndJobName(namespace, jobName);
    if (currentJobConfig == null) {
        throw new SaturnJobConsoleException(ERROR_CODE_NOT_EXISTED, "不能获取该作业(" + jobName + ")可选择的优先Executor,因为该作业不存在");
    }
    List<ExecutorProvided> executorProvidedList = new ArrayList<>();
    CuratorRepository.CuratorFrameworkOp curatorFrameworkOp = registryCenterService.getCuratorFrameworkOp(namespace);
    String executorsNodePath = SaturnExecutorsNode.getExecutorsNodePath();
    if (!curatorFrameworkOp.checkExists(executorsNodePath)) {
        return executorProvidedList;
    }
    List<String> executors = curatorFrameworkOp.getChildren(executorsNodePath);
    if (executors == null) {
        executors = new ArrayList<>();
    }
    if (!executors.isEmpty()) {
        for (String executor : executors) {
            if (curatorFrameworkOp.checkExists(SaturnExecutorsNode.getExecutorTaskNodePath(executor))) {
                // 过滤容器中的Executor,容器资源只需要可以选择taskId即可
                continue;
            }
            ExecutorProvided executorProvided = new ExecutorProvided();
            executorProvided.setType(ExecutorProvidedType.PHYSICAL);
            executorProvided.setExecutorName(executor);
            executorProvided.setNoTraffic(curatorFrameworkOp.checkExists(SaturnExecutorsNode.getExecutorNoTrafficNodePath(executor)));
            String ip = curatorFrameworkOp.getData(SaturnExecutorsNode.getExecutorIpNodePath(executor));
            if (StringUtils.isNotBlank(ip)) {
                executorProvided.setStatus(ExecutorProvidedStatus.ONLINE);
                executorProvided.setIp(ip);
            } else {
                executorProvided.setStatus(ExecutorProvidedStatus.OFFLINE);
            }
            executorProvidedList.add(executorProvided);
        }
    }
    List<ExecutorProvided> dockerExecutorProvided = getContainerTaskIds(curatorFrameworkOp);
    executorProvidedList.addAll(dockerExecutorProvided);
    if (StringUtils.isBlank(jobName)) {
        return executorProvidedList;
    }
    String preferListNodePath = JobNodePath.getConfigNodePath(jobName, CONFIG_ITEM_PREFER_LIST);
    if (!curatorFrameworkOp.checkExists(preferListNodePath)) {
        return executorProvidedList;
    }
    String preferList = curatorFrameworkOp.getData(preferListNodePath);
    if (Strings.isNullOrEmpty(preferList)) {
        return executorProvidedList;
    }
    handlerPreferListString(curatorFrameworkOp, preferList, executors, dockerExecutorProvided, executorProvidedList);
    return executorProvidedList;
}
Also used : 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)

Example 38 with CuratorFrameworkOp

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

the class JobServiceImpl method getJobServerList.

@Override
public List<String> getJobServerList(String namespace, String jobName) throws SaturnJobConsoleException {
    CuratorRepository.CuratorFrameworkOp curatorFrameworkOp = registryCenterService.getCuratorFrameworkOp(namespace);
    String executorsPath = JobNodePath.getServerNodePath(jobName);
    List<String> executors = curatorFrameworkOp.getChildren(executorsPath);
    if (executors == null || CollectionUtils.isEmpty(executors)) {
        return Lists.newArrayList();
    }
    return executors;
}
Also used : CuratorRepository(com.vip.saturn.job.console.repository.zookeeper.CuratorRepository) CuratorFrameworkOp(com.vip.saturn.job.console.repository.zookeeper.CuratorRepository.CuratorFrameworkOp)

Example 39 with CuratorFrameworkOp

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

the class JobServiceImpl method enableJob.

@Transactional(rollbackFor = Exception.class)
@Override
public void enableJob(String namespace, String jobName, String updatedBy) throws SaturnJobConsoleException {
    JobConfig4DB jobConfig = currentJobConfigService.findConfigByNamespaceAndJobName(namespace, jobName);
    if (jobConfig == null) {
        throw new SaturnJobConsoleException(ERROR_CODE_NOT_EXISTED, "不能启用该作业(" + jobName + "),因为该作业不存在");
    }
    if (jobConfig.getEnabled()) {
        throw new SaturnJobConsoleException(ERROR_CODE_BAD_REQUEST, "该作业(" + jobName + ")已经处于启用状态");
    }
    CuratorRepository.CuratorFrameworkOp curatorFrameworkOp = registryCenterService.getCuratorFrameworkOp(namespace);
    boolean allShardsFinished = isAllShardsFinished(jobName, curatorFrameworkOp);
    if (!allShardsFinished) {
        throw new SaturnJobConsoleException(ERROR_CODE_BAD_REQUEST, "不能启用该作业(" + jobName + "),因为该作业不处于STOPPED状态");
    }
    jobConfig.setEnabled(true);
    jobConfig.setLastUpdateTime(new Date());
    jobConfig.setLastUpdateBy(updatedBy);
    currentJobConfigService.updateByPrimaryKey(jobConfig);
    curatorFrameworkOp.update(JobNodePath.getConfigNodePath(jobName, CONFIG_ITEM_ENABLED), true);
}
Also used : 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 40 with CuratorFrameworkOp

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

the class JobServiceImpl method runAtOnce.

@Override
public void runAtOnce(String namespace, String jobName) throws SaturnJobConsoleException {
    JobStatus jobStatus = getJobStatus(namespace, jobName);
    if (!JobStatus.READY.equals(jobStatus)) {
        throw new SaturnJobConsoleException(ERROR_CODE_BAD_REQUEST, String.format("该作业(%s)不处于READY状态,不能立即执行", jobName));
    }
    List<JobServerStatus> jobServersStatus = getJobServersStatus(namespace, jobName);
    if (jobServersStatus != null && !jobServersStatus.isEmpty()) {
        boolean hasOnlineExecutor = false;
        CuratorFrameworkOp curatorFrameworkOp = registryCenterService.getCuratorFrameworkOp(namespace);
        for (JobServerStatus jobServerStatus : jobServersStatus) {
            if (ServerStatus.ONLINE.equals(jobServerStatus.getServerStatus())) {
                hasOnlineExecutor = true;
                String executorName = jobServerStatus.getExecutorName();
                String path = JobNodePath.getRunOneTimePath(jobName, executorName);
                if (curatorFrameworkOp.checkExists(path)) {
                    curatorFrameworkOp.delete(path);
                }
                curatorFrameworkOp.create(path, "null");
                log.info("runAtOnce namespace:{}, jobName:{}, executorName:{}", namespace, jobName, executorName);
            }
        }
        if (!hasOnlineExecutor) {
            throw new SaturnJobConsoleException(ERROR_CODE_BAD_REQUEST, "没有ONLINE的executor,不能立即执行");
        }
    } else {
        throw new SaturnJobConsoleException(ERROR_CODE_BAD_REQUEST, String.format("没有executor接管该作业(%s),不能立即执行", jobName));
    }
}
Also used : SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException) 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