use of com.vip.saturn.job.console.domain.JobConfig in project Saturn by vipshop.
the class JobOperationRestApiControllerTest method convert2JobConfig.
private JobConfig convert2JobConfig(String namespace, JobEntity jobEntity) {
JobConfig jobConfig = new JobConfig();
jobConfig.setJobName(jobEntity.getJobName());
jobConfig.setCron((String) jobEntity.getConfig("cron"));
jobConfig.setJobType((String) jobEntity.getConfig("jobType"));
jobConfig.setShardingTotalCount((Integer) jobEntity.getConfig("shardingTotalCount"));
jobConfig.setShardingItemParameters((String) jobEntity.getConfig("shardingItemParameters"));
jobConfig.setDescription(jobEntity.getDescription());
jobConfig.setLocalMode(null);
jobConfig.setUseSerial(null);
return jobConfig;
}
use of com.vip.saturn.job.console.domain.JobConfig in project Saturn by vipshop.
the class NamespaceServiceImplTest method testFailToImportJobs.
@Test
public void testFailToImportJobs() throws Exception {
List<JobConfig> jobConfigs = new ArrayList<>();
jobConfigs.add(new JobConfig());
when(jobService.getUnSystemJobs("saturn.vip.vip.com")).thenReturn(jobConfigs);
doThrow(new RuntimeException()).when(jobService).addJob(anyString(), any(JobConfig.class), anyString());
Exception exception = null;
try {
namespaceService.importJobsFromNamespaceToNamespace("saturn.vip.vip.com", "saturn.vip.vip.com_tt", "ray.leung");
} catch (Exception e) {
exception = e;
}
Assert.assertNotNull(exception);
}
use of com.vip.saturn.job.console.domain.JobConfig in project Saturn by vipshop.
the class NamespaceServiceImpl method importJobsFromNamespaceToNamespace.
@Override
public Map<String, List> importJobsFromNamespaceToNamespace(String srcNamespace, String destNamespace, String createdBy) throws SaturnJobConsoleException {
if (StringUtils.isBlank(srcNamespace)) {
throw new SaturnJobConsoleHttpException(HttpStatus.BAD_REQUEST.value(), "srcNamespace should not be null");
}
if (StringUtils.isBlank(destNamespace)) {
throw new SaturnJobConsoleHttpException(HttpStatus.BAD_REQUEST.value(), "destNamespace should not be null");
}
if (StringUtils.equals(srcNamespace, destNamespace)) {
throw new SaturnJobConsoleHttpException(HttpStatus.BAD_REQUEST.value(), "srcNamespace and destNamespace should be difference");
}
try {
List<String> successfullyImportedJobs = new ArrayList<>();
List<String> failedJobs = new ArrayList<>();
Map<String, List> result = new HashMap<>();
result.put("success", successfullyImportedJobs);
result.put("fail", failedJobs);
List<JobConfig> jobConfigs = jobService.getUnSystemJobs(srcNamespace);
List<JobConfig> jobConfigUpdatedList = new ArrayList<>();
for (JobConfig jobConfig : jobConfigs) {
String jobName = jobConfig.getJobName();
try {
// 如果存在上下游关联关系,直接导入会检验不通过;需要先解除关联关系,创建成功后再更新关联关系
JobConfig jobConfigUpdated = null;
if (StringUtils.isBlank(jobConfig.getUpStream()) || StringUtils.isBlank(jobConfig.getDownStream())) {
jobConfigUpdated = new JobConfig();
jobConfigUpdated.setJobName(jobName);
jobConfigUpdated.setUpStream(jobConfig.getUpStream());
jobConfigUpdated.setDownStream(jobConfig.getDownStream());
jobConfig.setUpStream(null);
jobConfig.setDownStream(null);
}
jobService.addJob(destNamespace, jobConfig, createdBy);
if (jobConfigUpdated != null) {
jobConfigUpdatedList.add(jobConfigUpdated);
}
successfullyImportedJobs.add(jobName);
} catch (SaturnJobConsoleException e) {
log.warn("fail to import job {} from {} to {}", jobName, srcNamespace, destNamespace, e);
failedJobs.add(jobName);
}
}
for (JobConfig jobConfig : jobConfigUpdatedList) {
String jobName = jobConfig.getJobName();
try {
jobService.updateJobConfig(destNamespace, jobConfig, createdBy);
} catch (SaturnJobConsoleException e) {
log.warn("fail to update job upStream or downStream, namespace is {} jobName is {}", destNamespace, jobName, e);
failedJobs.add(jobName);
successfullyImportedJobs.remove(jobName);
}
}
return result;
} catch (SaturnJobConsoleException e) {
log.warn("import jobs from {} to {} fail", srcNamespace, destNamespace, e);
throw e;
}
}
use of com.vip.saturn.job.console.domain.JobConfig 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.domain.JobConfig 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;
}
Aggregations