Search in sources :

Example 1 with ExecutorProvided

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

the class DashboardServiceImpl method isUnableFailoverJob.

// 无法高可用的情况:
// 1、勾选只使用优先executor,preferList只有一个物理机器(剔除offline、deleted的物理机)
// 2、没有勾选只使用优先executor,没有选择容器资源,可供选择的preferList只有一个物理机器(剔除offline、deleted的物理机,剔除容器资源)
private AbnormalJob isUnableFailoverJob(CuratorFramework curatorClient, AbnormalJob unableFailoverJob, CuratorFrameworkOp curatorFrameworkOp) {
    try {
        String jobName = unableFailoverJob.getJobName();
        String preferList = getData(curatorClient, JobNodePath.getConfigNodePath(jobName, "preferList"));
        Boolean onlyUsePreferList = !Boolean.valueOf(getData(curatorClient, JobNodePath.getConfigNodePath(jobName, "useDispreferList")));
        List<ExecutorProvided> preferListProvided = jobDimensionService.getAllExecutors(jobName, curatorFrameworkOp);
        List<String> preferListArr = new ArrayList<>();
        if (preferList != null && preferList.trim().length() > 0) {
            String[] split = preferList.split(",");
            for (String prefer : split) {
                String tmp = prefer.trim();
                if (tmp.length() > 0) {
                    if (!preferListArr.contains(tmp)) {
                        preferListArr.add(tmp);
                    }
                }
            }
        }
        boolean containerSelected = false;
        int count = 0;
        if (onlyUsePreferList) {
            for (ExecutorProvided executorProvided : preferListProvided) {
                if (preferListArr.contains(executorProvided.getExecutorName())) {
                    if (ExecutorProvidedType.DOCKER.equals(executorProvided.getType())) {
                        containerSelected = true;
                        break;
                    } else if (ExecutorProvidedType.ONLINE.equals(executorProvided.getType())) {
                        count++;
                    }
                }
            }
        } else {
            for (ExecutorProvided executorProvided : preferListProvided) {
                if (preferListArr.contains(executorProvided.getExecutorName()) && ExecutorProvidedType.DOCKER.equals(executorProvided.getType())) {
                    containerSelected = true;
                    break;
                }
                if (ExecutorProvidedType.ONLINE.equals(executorProvided.getType())) {
                    count++;
                    if (count > 1) {
                        break;
                    }
                }
            }
        }
        if (!containerSelected && count == 1) {
            return unableFailoverJob;
        }
        return null;
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        return null;
    }
}
Also used : ExecutorProvided(com.vip.saturn.job.console.domain.ExecutorProvided) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException) JobConsoleException(com.vip.saturn.job.console.exception.JobConsoleException) NoNodeException(org.apache.zookeeper.KeeperException.NoNodeException)

Example 2 with ExecutorProvided

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

the class JobController method getAllExecutors.

/**
 * 获取所有的executor作为优先候选列表
 */
@RequestMapping(value = "getAllExecutors", method = RequestMethod.GET)
public RequestResult getAllExecutors(String jobName) {
    RequestResult requestResult = new RequestResult();
    try {
        List<ExecutorProvided> allExecutors = jobDimensionService.getAllExecutors(jobName);
        requestResult.setObj(allExecutors);
        requestResult.setSuccess(true);
    } catch (Exception e) {
        requestResult.setSuccess(false);
        requestResult.setMessage(e.toString());
    }
    return requestResult;
}
Also used : RequestResult(com.vip.saturn.job.console.domain.RequestResult) ExecutorProvided(com.vip.saturn.job.console.domain.ExecutorProvided) ParseException(java.text.ParseException) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with ExecutorProvided

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

the class JobController method batchSetPreferExecutorsEnabled.

@RequestMapping(value = "batchSetPreferExecutorsEnabled", method = RequestMethod.GET)
public RequestResult batchSetPreferExecutorsEnabled(HttpServletRequest request) {
    RequestResult requestResult = new RequestResult();
    try {
        List<ExecutorProvided> allExecutorsOfNamespace = jobDimensionService.getAllExecutorsOfNamespace();
        requestResult.setSuccess(true);
        requestResult.setObj(allExecutorsOfNamespace);
    } catch (Exception e) {
        requestResult.setSuccess(false);
        requestResult.setMessage(e.getMessage());
    }
    return requestResult;
}
Also used : RequestResult(com.vip.saturn.job.console.domain.RequestResult) ExecutorProvided(com.vip.saturn.job.console.domain.ExecutorProvided) ParseException(java.text.ParseException) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

ExecutorProvided (com.vip.saturn.job.console.domain.ExecutorProvided)3 SaturnJobConsoleException (com.vip.saturn.job.console.exception.SaturnJobConsoleException)3 RequestResult (com.vip.saturn.job.console.domain.RequestResult)2 ParseException (java.text.ParseException)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 JobConsoleException (com.vip.saturn.job.console.exception.JobConsoleException)1 NoNodeException (org.apache.zookeeper.KeeperException.NoNodeException)1