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);
}
}
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);
}
}
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;
}
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;
}
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);
}
}
}
Aggregations