@Test public void testSrcNamespaceIsNull() throws SaturnJobConsoleException { SaturnJobConsoleHttpException exception = null; try { namespaceService.importJobsFromNamespaceToNamespace(null, null, null); } catch (SaturnJobConsoleHttpException e) { exception = e; } Assert.assertNotNull(exception); Assert.assertEquals(exception.getMessage(), "srcNamespace should not be null"); }
@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; } }
NamespaceServiceImpl implements NamespaceService { @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; } } }
NamespaceServiceImpl implements NamespaceService { @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; } }  }
NamespaceServiceImpl implements NamespaceService { @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; } }  @Override Map<String, List> importJobsFromNamespaceToNamespace(String srcNamespace, String destNamespace,
			String createdBy); @Override void deleteNamespace(String namespace); }
NamespaceServiceImpl implements NamespaceService { @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; } }  @Override Map<String, List> importJobsFromNamespaceToNamespace(String srcNamespace, String destNamespace,
			String createdBy); @Override void deleteNamespace(String namespace);  }