Search in sources :

Example 1 with SaturnJobConsoleHttpException

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

the class JobDimensionServiceImpl method savePreferListToDb.

private void savePreferListToDb(String jobName, CuratorRepository.CuratorFrameworkOp curatorFrameworkOp, String newJobConfigPreferList) throws SaturnJobConsoleException, SaturnJobConsoleHttpException {
    String namespace = curatorFrameworkOp.getCuratorFramework().getNamespace();
    CurrentJobConfig oldCurrentJobConfig = currentJobConfigService.findConfigByNamespaceAndJobName(namespace, jobName);
    if (oldCurrentJobConfig == null) {
        log.error("找不到该作业的配置,namespace jobname is:" + namespace + " " + jobName);
        return;
    }
    CurrentJobConfig newCurrentJobConfig = mapper.map(oldCurrentJobConfig, CurrentJobConfig.class);
    newCurrentJobConfig.setPreferList(newJobConfigPreferList);
    try {
        currentJobConfigService.updateConfigAndSave2History(newCurrentJobConfig, oldCurrentJobConfig, null);
    } catch (Exception e) {
        log.error("exception is thrown during change perfer list in db", e);
        throw new SaturnJobConsoleHttpException(HttpStatus.INTERNAL_SERVER_ERROR.value(), e.getMessage(), e);
    }
}
Also used : CurrentJobConfig(com.vip.saturn.job.console.mybatis.entity.CurrentJobConfig) SaturnJobConsoleHttpException(com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException) SaturnJobConsoleHttpException(com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException) ParseException(java.text.ParseException) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException)

Example 2 with SaturnJobConsoleHttpException

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

the class JobOperationServiceImpl method deleteJob.

@Transactional
@Override
public void deleteJob(String jobName, CuratorRepository.CuratorFrameworkOp curatorFrameworkOp) throws SaturnJobConsoleException {
    try {
        String enabledNodePath = JobNodePath.getConfigNodePath(jobName, "enabled");
        long creationTime = curatorFrameworkOp.getCtime(enabledNodePath);
        long timeDiff = System.currentTimeMillis() - creationTime;
        if (timeDiff < SaturnConstants.JOB_CAN_BE_DELETE_TIME_LIMIT) {
            String errMessage = "Job cannot be deleted until " + (SaturnConstants.JOB_CAN_BE_DELETE_TIME_LIMIT / 1000) + " seconds after job creation";
            throw new SaturnJobConsoleHttpException(HttpStatus.BAD_REQUEST.value(), errMessage);
        }
        // 1.作业的executor全online的情况,添加toDelete节点,触发监听器动态删除节点
        String toDeleteNodePath = JobNodePath.getConfigNodePath(jobName, "toDelete");
        if (curatorFrameworkOp.checkExists(toDeleteNodePath)) {
            curatorFrameworkOp.deleteRecursive(toDeleteNodePath);
        }
        curatorFrameworkOp.create(toDeleteNodePath);
        for (int i = 0; i < 20; i++) {
            // 2.作业的executor全offline的情况,或有几个online,几个offline的情况
            String jobServerPath = JobNodePath.getServerNodePath(jobName);
            if (!curatorFrameworkOp.checkExists(jobServerPath)) {
                // (1)如果不存在$Job/JobName/servers节点,说明该作业没有任何executor接管,可直接删除作业节点
                curatorFrameworkOp.deleteRecursive(JobNodePath.getJobNodePath(jobName));
                return;
            }
            // (2)如果该作业servers下没有任何executor,可直接删除作业节点
            List<String> executors = curatorFrameworkOp.getChildren(jobServerPath);
            if (CollectionUtils.isEmpty(executors)) {
                curatorFrameworkOp.deleteRecursive(JobNodePath.getJobNodePath(jobName));
                return;
            }
            // (3)只要该作业没有一个能运行的该作业的executor在线,那么直接删除作业节点
            boolean hasOnlineExecutor = false;
            for (String executor : executors) {
                if (curatorFrameworkOp.checkExists(ExecutorNodePath.getExecutorNodePath(executor, "ip")) && curatorFrameworkOp.checkExists(JobNodePath.getServerStatus(jobName, executor))) {
                    hasOnlineExecutor = true;
                } else {
                    curatorFrameworkOp.deleteRecursive(JobNodePath.getServerNodePath(jobName, executor));
                }
            }
            if (!hasOnlineExecutor) {
                curatorFrameworkOp.deleteRecursive(JobNodePath.getJobNodePath(jobName));
            }
            Thread.sleep(200);
        }
    } catch (SaturnJobConsoleException e) {
        throw e;
    } catch (Throwable t) {
        log.error("exception is thrown during delete job", t);
        throw new SaturnJobConsoleHttpException(HttpStatus.INTERNAL_SERVER_ERROR.value(), t.getMessage(), t);
    }
}
Also used : SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException) SaturnJobConsoleHttpException(com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with SaturnJobConsoleHttpException

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

the class RestApiServiceImpl method getNamespace.

@Override
public NamespaceDomainInfo getNamespace(String namespace) throws SaturnJobConsoleException {
    if (namespaceInfoService.selectByNamespace(namespace) == null) {
        throw new SaturnJobConsoleHttpException(HttpStatus.NOT_FOUND.value(), ERR_MSG_NS_NOT_FOUND);
    }
    String zkClusterKey = namespaceZkClusterMapping4SqlService.getZkClusterKey(namespace);
    if (StringUtils.isBlank(zkClusterKey)) {
        throw new SaturnJobConsoleHttpException(HttpStatus.NOT_FOUND.value(), ERR_MSG_NS_NOT_FOUND);
    }
    NamespaceDomainInfo namespaceDomainInfo = new NamespaceDomainInfo();
    namespaceDomainInfo.setNamespace(namespace);
    namespaceDomainInfo.setZkCluster(zkClusterKey);
    return namespaceDomainInfo;
}
Also used : NamespaceDomainInfo(com.vip.saturn.job.console.domain.NamespaceDomainInfo) SaturnJobConsoleHttpException(com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException)

Example 4 with SaturnJobConsoleHttpException

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

the class RestApiServiceImpl method stopAtOnce.

private void stopAtOnce(String jobName, CuratorRepository.CuratorFrameworkOp curatorFrameworkOp) throws SaturnJobConsoleHttpException {
    Collection<JobServer> servers = jobDimensionService.getServers(jobName, curatorFrameworkOp);
    if (CollectionUtils.isEmpty(servers)) {
        throw new SaturnJobConsoleHttpException(HttpStatus.BAD_REQUEST.value(), NO_EXECUTOR_FOUND);
    }
    for (JobServer server : servers) {
        log.info("stop at once: job:{} executor:{}", jobName, server.getExecutorName());
        jobOperationService.stopAtOnceByJobnameAndExecutorName(jobName, server.getExecutorName(), curatorFrameworkOp);
    }
}
Also used : JobServer(com.vip.saturn.job.console.domain.JobServer) SaturnJobConsoleHttpException(com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException)

Example 5 with SaturnJobConsoleHttpException

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

the class DashboardRefreshRestApiController method dashboardRefresh.

/**
 * 根据ZK集群key,刷新该集群的dashboard信息
 *
 * @param zkClusterKey
 * @param request
 * @return
 * @throws SaturnJobConsoleException
 */
@RequestMapping(value = "/dashboard/refresh", method = { RequestMethod.POST, RequestMethod.GET }, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public ResponseEntity<Object> dashboardRefresh(String zkClusterKey, HttpServletRequest request) throws SaturnJobConsoleException {
    try {
        checkMissingParameter("zkClusterKey", zkClusterKey);
        long beforeRefresh = System.currentTimeMillis();
        dashboardService.refreshStatistics2DB(zkClusterKey);
        long afterRefresh = System.currentTimeMillis();
        long takeTime = afterRefresh - beforeRefresh;
        return new ResponseEntity<Object>(takeTime, HttpStatus.OK);
    } catch (SaturnJobConsoleException e) {
        throw e;
    } catch (Exception e) {
        throw new SaturnJobConsoleHttpException(HttpStatus.INTERNAL_SERVER_ERROR.value(), e.getMessage(), e);
    }
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException) SaturnJobConsoleHttpException(com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException) SaturnJobConsoleHttpException(com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

SaturnJobConsoleHttpException (com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException)68 SaturnJobConsoleException (com.vip.saturn.job.console.exception.SaturnJobConsoleException)40 ResponseEntity (org.springframework.http.ResponseEntity)30 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)24 Test (org.junit.Test)15 HttpHeaders (org.springframework.http.HttpHeaders)13 Audit (com.vip.saturn.job.console.aop.annotation.Audit)12 JobConfig (com.vip.saturn.job.console.domain.JobConfig)10 Matchers.anyString (org.mockito.Matchers.anyString)8 NamespaceDomainInfo (com.vip.saturn.job.console.domain.NamespaceDomainInfo)7 AbstractSaturnConsoleTest (com.vip.saturn.job.console.AbstractSaturnConsoleTest)5 CurrentJobConfig (com.vip.saturn.job.console.mybatis.entity.CurrentJobConfig)5 WebMvcTest (org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest)5 MvcResult (org.springframework.test.web.servlet.MvcResult)5 Transactional (org.springframework.transaction.annotation.Transactional)5 NamespaceInfo (com.vip.saturn.job.console.mybatis.entity.NamespaceInfo)4 AlarmInfo (com.vip.saturn.job.integrate.entity.AlarmInfo)4 ParseException (java.text.ParseException)4 Map (java.util.Map)4 ZkCluster (com.vip.saturn.job.console.domain.ZkCluster)3