use of com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException in project Saturn by vipshop.
the class RestApiServiceImplTest method testUpdateJobFailAsSaturnsIsNotStopped.
@Test
public void testUpdateJobFailAsSaturnsIsNotStopped() throws SaturnJobConsoleException {
String jobName = "testJob";
when(jobService.getJobStatus(TEST_NAME_SPACE_NAME, jobName)).thenReturn(JobStatus.STOPPING);
// run
try {
restApiService.updateJob(TEST_NAME_SPACE_NAME, jobName, buildUpdateJobConfig(jobName));
} catch (SaturnJobConsoleHttpException e) {
assertEquals("status code is not 400", 400, e.getStatusCode());
assertEquals("error message is not equals", "job's status is not {STOPPED}", e.getMessage());
}
}
use of com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException in project Saturn by vipshop.
the class RestApiServiceImplTest method testDeleteJobFailAsStatusIsNotStopped.
@Test
public void testDeleteJobFailAsStatusIsNotStopped() throws SaturnJobConsoleException {
// prepare
String jobName = "testJob";
when(jobService.getJobStatus(TEST_NAME_SPACE_NAME, jobName)).thenReturn(JobStatus.STOPPING);
// run
try {
restApiService.deleteJob(TEST_NAME_SPACE_NAME, jobName);
} catch (SaturnJobConsoleHttpException e) {
assertEquals("status code is not 400", 400, e.getStatusCode());
assertEquals("error message is not equals", "job's status is not {STOPPED}", e.getMessage());
}
// verify
verify(jobService, times(0)).removeJob(TEST_NAME_SPACE_NAME, jobName);
}
use of com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException in project Saturn by vipshop.
the class NamespaceServiceImplTest method testSrcNamespaceIdenticalToDestNamespace.
@Test
public void testSrcNamespaceIdenticalToDestNamespace() throws SaturnJobConsoleException {
SaturnJobConsoleHttpException exception = null;
String srcNamespace = "saturn.vip.vip.com";
String destNamespace = "saturn.vip.vip.com";
try {
namespaceService.importJobsFromNamespaceToNamespace(srcNamespace, destNamespace, null);
} catch (SaturnJobConsoleHttpException e) {
exception = e;
}
Assert.assertNotNull(exception);
Assert.assertEquals(exception.getMessage(), "srcNamespace and destNamespace should be difference");
}
use of com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException 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.exception.SaturnJobConsoleHttpException in project Saturn by vipshop.
the class RegistryCenterServiceImpl method bindNamespaceAndZkCluster.
@Transactional(rollbackFor = { Exception.class })
@Override
public void bindNamespaceAndZkCluster(String namespace, String zkClusterKey, String updatedBy) throws SaturnJobConsoleException {
ZkCluster currentCluster = getZkCluster(zkClusterKey);
if (currentCluster == null) {
throw new SaturnJobConsoleHttpException(HttpStatus.BAD_REQUEST.value(), String.format(ERR_MSG_TEMPLATE_FAIL_TO_CREATE, namespace, "not found zkcluster" + zkClusterKey));
}
// namespace必须要存在
if (!checkNamespaceExists(namespace)) {
throw new SaturnJobConsoleHttpException(HttpStatus.BAD_REQUEST.value(), ERR_MSG_NS_NOT_FOUND);
}
// 判断其它集群是否有该域
String zkClusterKeyOther = namespaceZkClusterMapping4SqlService.getZkClusterKey(namespace);
if (zkClusterKeyOther != null) {
ZkCluster zkClusterOther = getZkCluster(zkClusterKeyOther);
if (zkClusterOther == null) {
throw new SaturnJobConsoleException("zk cluster 不存在:" + zkClusterKeyOther);
}
if (zkClusterOther.getZkClusterKey().equals(zkClusterKey)) {
throw new SaturnJobConsoleException("Namespace已经存在于此zk集群,不能重复添加");
} else {
throw new SaturnJobConsoleException("Namespace存在于另外的zk集群:" + zkClusterOther.getZkClusterKey() + ",不能重复添加");
}
}
try {
namespaceZkClusterMapping4SqlService.insert(namespace, "", zkClusterKey, updatedBy);
postBindNamespaceAndZkCluster(namespace, currentCluster);
// refresh
notifyRefreshRegCenter();
} catch (Exception e) {
namespaceZkClusterMapping4SqlService.remove(namespace, updatedBy);
throw new SaturnJobConsoleException(e.getMessage());
}
}
Aggregations