JobPlanner { public static MapConfig generateSingleJobConfig(Map<String, String> userConfigs) { Map<String, String> generatedConfig = new HashMap<>(userConfigs); if (!userConfigs.containsKey(JobConfig.JOB_NAME) && !userConfigs.containsKey(ApplicationConfig.APP_NAME)) { throw new SamzaException("Samza app name should not be null, Please set either app.name (preferred) or job.name (deprecated) in configs"); } if (userConfigs.containsKey(JobConfig.JOB_ID)) { LOG.warn("{} is a deprecated configuration, use app.id instead.", JobConfig.JOB_ID); } if (userConfigs.containsKey(JobConfig.JOB_NAME)) { LOG.warn("{} is a deprecated configuration, use use app.name instead.", JobConfig.JOB_NAME); } if (userConfigs.containsKey(ApplicationConfig.APP_NAME)) { String appName = userConfigs.get(ApplicationConfig.APP_NAME); LOG.info("app.name is defined, generating job.name equal to app.name value: {}", appName); generatedConfig.put(JobConfig.JOB_NAME, appName); } if (userConfigs.containsKey(ApplicationConfig.APP_ID)) { String appId = userConfigs.get(ApplicationConfig.APP_ID); LOG.info("app.id is defined, generating job.id equal to app.name value: {}", appId); generatedConfig.put(JobConfig.JOB_ID, appId); } return new MapConfig(generatedConfig); } JobPlanner(ApplicationDescriptorImpl<? extends ApplicationDescriptor> descriptor); abstract List<JobConfig> prepareJobs(); static MapConfig generateSingleJobConfig(Map<String, String> userConfigs);  }
@Test public void testJobNameIdConfigGeneration() { Map<String, String> testConfig = new HashMap<>(); testConfig.put("app.name", "samza-app"); testConfig .put("app.id", "id"); MapConfig generatedConfig = JobPlanner.generateSingleJobConfig(testConfig); Assert.assertEquals(generatedConfig.get("job.name"), "samza-app"); Assert.assertEquals(generatedConfig.get("job.id"), "id"); }
@Test public void testAppConfigPrecedence() { Map<String, String> testConfig = new HashMap<>(); testConfig.put("app.name", "samza-app"); testConfig .put("app.id", "id"); testConfig .put("job.id", "should-not-exist-id"); testConfig .put("job.name", "should-not-exist-name"); MapConfig generatedConfig = JobPlanner.generateSingleJobConfig(testConfig); Assert.assertEquals(generatedConfig.get("job.name"), "samza-app"); Assert.assertEquals(generatedConfig.get("job.id"), "id"); }
@Test public void testJobNameId() { Map<String, String> testConfig = new HashMap<>(); testConfig .put("job.id", "should-exist-id"); testConfig .put("job.name", "should-exist-name"); MapConfig generatedConfig = JobPlanner.generateSingleJobConfig(testConfig); Assert.assertEquals(generatedConfig.get("job.name"), "should-exist-name"); Assert.assertEquals(generatedConfig.get("job.id"), "should-exist-id"); }