Search in sources :

Example 71 with SaturnJobConsoleException

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

the class MarathonServiceImpl method addContainerScaleJob.

@Override
public void addContainerScaleJob(String namespace, String taskId, String jobDesc, int instances, String timeZone, String cron) throws SaturnJobConsoleException {
    CuratorRepository.CuratorFrameworkOp curatorFrameworkOp = registryCenterService.getCuratorFrameworkOp(namespace);
    String jobName = SaturnConstants.SYSTEM_SCALE_JOB_PREFEX + System.currentTimeMillis();
    ContainerToken containerToken = getContainerToken(namespace);
    JobConfig jobConfig = new JobConfig();
    jobConfig.setJobName(jobName);
    jobConfig.setDescription(jobDesc);
    jobConfig.setTimeZone(timeZone);
    jobConfig.setCron(cron);
    jobConfig.setJobMode(JobMode.system_scale);
    jobConfig.setJobType(JobType.SHELL_JOB.name());
    jobConfig.setPreferList("@" + taskId);
    jobConfig.setShardingTotalCount(1);
    jobConfig.setShardingItemParameters(getContainerScaleJobShardingItemParameters(containerToken, taskId, instances));
    jobConfig.setUseDispreferList(false);
    jobConfig.setTimeout4AlarmSeconds(30);
    jobConfig.setTimeoutSeconds(30);
    jobConfig.setJobParameter("");
    jobConfig.setQueueName("");
    jobConfig.setChannelName("");
    jobConfig.setPausePeriodDate("");
    jobConfig.setPausePeriodTime("");
    jobService.addJob(namespace, jobConfig, "");
    ContainerScaleJobConfig containerScaleJobConfig = new ContainerScaleJobConfig();
    containerScaleJobConfig.setJobName(jobName);
    containerScaleJobConfig.setJobDesc(jobDesc);
    containerScaleJobConfig.setInstances(instances);
    containerScaleJobConfig.setTimeZone(timeZone);
    containerScaleJobConfig.setCron(cron);
    try {
        String containerScaleJobStr = JSON.toJSONString(containerScaleJobConfig);
        String dcosTaskScaleJobNodePath = ContainerNodePath.getDcosTaskScaleJobNodePath(taskId, jobName);
        curatorFrameworkOp.fillJobNodeIfNotExist(dcosTaskScaleJobNodePath, containerScaleJobStr);
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        throw new SaturnJobConsoleException(e.getMessage(), e);
    }
}
Also used : CuratorRepository(com.vip.saturn.job.console.repository.zookeeper.CuratorRepository) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException) JobConfig(com.vip.saturn.job.console.domain.JobConfig) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException)

Example 72 with SaturnJobConsoleException

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

the class UpdateJobConfigServiceImpl method batchUpdatePreferList.

@Override
public void batchUpdatePreferList(List<JobConfigInfo> jobConfigInfos) throws UpdateJobConfigException {
    if (CollectionUtils.isEmpty(jobConfigInfos)) {
        return;
    }
    List<JobConfig4DB> currentJobConfigs = new ArrayList<JobConfig4DB>();
    JobConfig4DB currentJobConfig = null;
    for (JobConfigInfo jobConfigInfo : jobConfigInfos) {
        currentJobConfig = new JobConfig4DB();
        currentJobConfig.setNamespace(jobConfigInfo.getNamespace());
        currentJobConfig.setJobName(jobConfigInfo.getJobName());
        currentJobConfig.setPreferList(jobConfigInfo.getPerferList());
        currentJobConfigs.add(currentJobConfig);
    }
    try {
        currentJobConfigService.batchUpdatePreferList(currentJobConfigs);
    } catch (SaturnJobConsoleException e) {
        throw new UpdateJobConfigException(e);
    }
}
Also used : UpdateJobConfigException(com.vip.saturn.job.integrate.exception.UpdateJobConfigException) JobConfigInfo(com.vip.saturn.job.integrate.entity.JobConfigInfo) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException) ArrayList(java.util.ArrayList) JobConfig4DB(com.vip.saturn.job.console.mybatis.entity.JobConfig4DB)

Example 73 with SaturnJobConsoleException

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

the class ZkDBDiffServiceImpl method diffByCluster.

@Override
public List<JobDiffInfo> diffByCluster(String clusterKey) throws SaturnJobConsoleException {
    long startTime = System.currentTimeMillis();
    List<String> namespaces = namespaceZkClusterMapping4SqlService.getAllNamespacesOfCluster(clusterKey);
    List<Callable<List<JobDiffInfo>>> callableList = Lists.newArrayList();
    for (final String namespace : namespaces) {
        Callable<List<JobDiffInfo>> callable = new Callable<List<JobDiffInfo>>() {

            @Override
            public List<JobDiffInfo> call() throws Exception {
                return diffByNamespace(namespace);
            }
        };
        callableList.add(callable);
    }
    List<JobDiffInfo> resultList = Lists.newArrayList();
    try {
        List<Future<List<JobDiffInfo>>> futures = diffExecutorService.invokeAll(callableList);
        for (Future<List<JobDiffInfo>> future : futures) {
            List<JobDiffInfo> jobDiffInfos = future.get();
            if (jobDiffInfos != null && !jobDiffInfos.isEmpty()) {
                resultList.addAll(jobDiffInfos);
            }
        }
    } catch (InterruptedException e) {
        // NOSONAR
        log.warn("the thread is interrupted", e);
        throw new SaturnJobConsoleException("the diff thread is interrupted", e);
    } catch (Exception e) {
        log.error("exception happens during execute diff operation", e);
        throw new SaturnJobConsoleException(e);
    }
    log.info("Finish diff zkcluster:{}, which cost {}ms", clusterKey, System.currentTimeMillis() - startTime);
    return resultList;
}
Also used : JobDiffInfo(com.vip.saturn.job.console.domain.JobDiffInfo) Callable(java.util.concurrent.Callable) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException) Future(java.util.concurrent.Future) List(java.util.List)

Example 74 with SaturnJobConsoleException

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

the class ZkDBDiffServiceImpl method diffByNamespace.

@Override
public List<JobDiffInfo> diffByNamespace(String namespace) throws SaturnJobConsoleException {
    long startTime = System.currentTimeMillis();
    List<JobDiffInfo> jobDiffInfos = Lists.newArrayList();
    CuratorRepository.CuratorFrameworkOp zkClient;
    try {
        List<JobConfig4DB> dbJobConfigList = currentJobConfigService.findConfigsByNamespace(namespace);
        if (dbJobConfigList == null || dbJobConfigList.isEmpty()) {
            return jobDiffInfos;
        }
        zkClient = initCuratorClient(namespace);
        if (zkClient == null) {
            return jobDiffInfos;
        }
        Set<String> jobNamesInDb = getAllJobNames(dbJobConfigList);
        for (JobConfig4DB dbJobConfig : dbJobConfigList) {
            String jobName = dbJobConfig.getJobName();
            log.info("start to diff job:{}@{}", jobName, namespace);
            if (!checkJobIsExsitInZk(jobName, zkClient)) {
                jobDiffInfos.add(new JobDiffInfo(namespace, jobName, JobDiffInfo.DiffType.DB_ONLY, Lists.<JobDiffInfo.ConfigDiffInfo>newArrayList()));
                continue;
            }
            JobConfig jobConfigFromZK = jobService.getJobConfigFromZK(namespace, jobName);
            JobDiffInfo jobDiffInfo = diff(namespace, dbJobConfig, jobConfigFromZK, false);
            if (jobDiffInfo != null) {
                jobDiffInfos.add(jobDiffInfo);
            }
        }
        List<JobDiffInfo> jobsInZkOnly = getJobNamesWhichInZKOnly(namespace, jobNamesInDb);
        if (jobsInZkOnly != null && !jobsInZkOnly.isEmpty()) {
            jobDiffInfos.addAll(jobsInZkOnly);
        }
    } catch (SaturnJobConsoleException e) {
        log.error(e.getMessage(), e);
        throw e;
    } catch (Exception e) {
        log.error("exception throws during diff by namespace [{}]", namespace, e);
        throw new SaturnJobConsoleException(e);
    } finally {
        log.info("Finish diff namespace:{} which cost {}ms", namespace, System.currentTimeMillis() - startTime);
    }
    return jobDiffInfos;
}
Also used : JobDiffInfo(com.vip.saturn.job.console.domain.JobDiffInfo) JobConfig4DB(com.vip.saturn.job.console.mybatis.entity.JobConfig4DB) JobConfig(com.vip.saturn.job.console.domain.JobConfig) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException) CuratorRepository(com.vip.saturn.job.console.repository.zookeeper.CuratorRepository) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException)

Example 75 with SaturnJobConsoleException

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

the class MarathonRestClient method info.

public static String info(String userName, String password, String appId) throws SaturnJobConsoleException {
    String urlStr = SaturnEnvProperties.VIP_SATURN_DCOS_REST_URI + API_VERSION_DES + appId;
    CloseableHttpClient httpClient = HttpClients.createDefault();
    try {
        HttpGet httpGet = new HttpGet(urlStr);
        httpGet.setHeader(AUTHORIZATION_DES, BASIC_DES + Base64.encodeBase64String((userName + ":" + password).getBytes(UTF8_DES)));
        CloseableHttpResponse httpResponse = httpClient.execute(httpGet);
        HttpEntity entity = httpResponse.getEntity();
        if (entity != null) {
            String entityContent = getEntityContent(entity);
            StatusLine statusLine = httpResponse.getStatusLine();
            if (statusLine != null && statusLine.getStatusCode() == 200) {
                return entityContent;
            } else {
                throw new SaturnJobConsoleException(entityContent);
            }
        } else {
            throw new SaturnJobConsoleException("Not data returned, url is " + urlStr);
        }
    } catch (IOException e) {
        log.error(e.getMessage(), e);
        throw new SaturnJobConsoleException(e);
    } finally {
        try {
            httpClient.close();
        } catch (IOException e) {
            log.error(e.getMessage(), e);
        }
    }
}
Also used : StatusLine(org.apache.http.StatusLine) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) HttpEntity(org.apache.http.HttpEntity) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException) IOException(java.io.IOException)

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