@Test public void updateJobParameters_OriginalWithDefaultValues() throws Exception { Job job = new Job("existing_job_id", "megatron"); job.setParameters(Lists.newArrayList( new JobParameter("start-date", null, "160712"), new JobParameter("end-date", null, "160712"))); when(spawn.getJob("existing_job_id")).thenReturn(job); kv.add("id", "existing_job_id"); kv.add("config", "%[start-date]% %[end-date]%"); kv.add("sp_start-date", "160712"); kv.add("sp_end-date", "160714"); assertSame("returned job", job, impl.createOrUpdateJob(kv, username, token, sudo, false)); JobParameter endDate = null; JobParameter startDate = null; for (JobParameter jp : job.getParameters()) { if ("start-date".equals(jp.getName())) { startDate = jp; } else if ("end-date".equals(jp.getName())) { endDate = jp; } } assertNotNull("parameter 'start-date' found", startDate); assertEquals("parameter 'start-date' value", "160712", startDate.getValue()); assertNotNull("parameter 'end-date' found", endDate); assertEquals("parameter 'end-date' value", "160714", endDate.getValue()); }
@Override public Job createOrUpdateJob(KVPairs kv, String username, String token, String sudo, boolean defaults) throws Exception { User user = checkUserCredentials(username, token); String id = KVUtils.getValue(kv, "", "id", "job"); String config = kv.getValue("config"); String expandedConfig; String command = kv.getValue("command"); boolean configMayHaveChanged = true; Job job; if (Strings.isNullOrEmpty(id)) { checkArgument(!Strings.isNullOrEmpty(command), "Parameter 'command' is missing"); requireValidCommandParam(command); checkArgument(config != null, "Parameter 'config' is missing"); expandedConfig = tryExpandJobConfigParam(config); checkKvPairs(kv, user); job = spawn.createJob( kv.getValue("creator"), kv.getIntValue("nodes", -1), Splitter.on(',').omitEmptyStrings().trimResults().splitToList(kv.getValue("hosts", "")), kv.getValue("minionType", DEFAULT_MINION_TYPE), command, defaults); } else { job = spawn.getJob(id); checkArgument(job != null, "Job %s does not exist", id); checkJobWritePrivileges(job, username, token, sudo); if (config == null) { configMayHaveChanged = false; config = spawn.getJobConfig(id); } expandedConfig = tryExpandJobConfigParam(config); if (!Strings.isNullOrEmpty(command)) { requireValidCommandParam(command); job.setCommand(command); } } updateBasicSettings(kv, job, username); updateQueryConfig(kv, job); updateJobParameters(kv, job, expandedConfig); updateBasicAlerts(kv, job); spawn.updateJob(job); if (configMayHaveChanged) { spawn.setJobConfig(job.getId(), config); spawn.submitConfigUpdate(job.getId(), username, kv.getValue("commit")); } return job; }
JobRequestHandlerImpl implements JobRequestHandler { @Override public Job createOrUpdateJob(KVPairs kv, String username, String token, String sudo, boolean defaults) throws Exception { User user = checkUserCredentials(username, token); String id = KVUtils.getValue(kv, "", "id", "job"); String config = kv.getValue("config"); String expandedConfig; String command = kv.getValue("command"); boolean configMayHaveChanged = true; Job job; if (Strings.isNullOrEmpty(id)) { checkArgument(!Strings.isNullOrEmpty(command), "Parameter 'command' is missing"); requireValidCommandParam(command); checkArgument(config != null, "Parameter 'config' is missing"); expandedConfig = tryExpandJobConfigParam(config); checkKvPairs(kv, user); job = spawn.createJob( kv.getValue("creator"), kv.getIntValue("nodes", -1), Splitter.on(',').omitEmptyStrings().trimResults().splitToList(kv.getValue("hosts", "")), kv.getValue("minionType", DEFAULT_MINION_TYPE), command, defaults); } else { job = spawn.getJob(id); checkArgument(job != null, "Job %s does not exist", id); checkJobWritePrivileges(job, username, token, sudo); if (config == null) { configMayHaveChanged = false; config = spawn.getJobConfig(id); } expandedConfig = tryExpandJobConfigParam(config); if (!Strings.isNullOrEmpty(command)) { requireValidCommandParam(command); job.setCommand(command); } } updateBasicSettings(kv, job, username); updateQueryConfig(kv, job); updateJobParameters(kv, job, expandedConfig); updateBasicAlerts(kv, job); spawn.updateJob(job); if (configMayHaveChanged) { spawn.setJobConfig(job.getId(), config); spawn.submitConfigUpdate(job.getId(), username, kv.getValue("commit")); } return job; } }
JobRequestHandlerImpl implements JobRequestHandler { @Override public Job createOrUpdateJob(KVPairs kv, String username, String token, String sudo, boolean defaults) throws Exception { User user = checkUserCredentials(username, token); String id = KVUtils.getValue(kv, "", "id", "job"); String config = kv.getValue("config"); String expandedConfig; String command = kv.getValue("command"); boolean configMayHaveChanged = true; Job job; if (Strings.isNullOrEmpty(id)) { checkArgument(!Strings.isNullOrEmpty(command), "Parameter 'command' is missing"); requireValidCommandParam(command); checkArgument(config != null, "Parameter 'config' is missing"); expandedConfig = tryExpandJobConfigParam(config); checkKvPairs(kv, user); job = spawn.createJob( kv.getValue("creator"), kv.getIntValue("nodes", -1), Splitter.on(',').omitEmptyStrings().trimResults().splitToList(kv.getValue("hosts", "")), kv.getValue("minionType", DEFAULT_MINION_TYPE), command, defaults); } else { job = spawn.getJob(id); checkArgument(job != null, "Job %s does not exist", id); checkJobWritePrivileges(job, username, token, sudo); if (config == null) { configMayHaveChanged = false; config = spawn.getJobConfig(id); } expandedConfig = tryExpandJobConfigParam(config); if (!Strings.isNullOrEmpty(command)) { requireValidCommandParam(command); job.setCommand(command); } } updateBasicSettings(kv, job, username); updateQueryConfig(kv, job); updateJobParameters(kv, job, expandedConfig); updateBasicAlerts(kv, job); spawn.updateJob(job); if (configMayHaveChanged) { spawn.setJobConfig(job.getId(), config); spawn.submitConfigUpdate(job.getId(), username, kv.getValue("commit")); } return job; } JobRequestHandlerImpl(Spawn spawn); }
JobRequestHandlerImpl implements JobRequestHandler { @Override public Job createOrUpdateJob(KVPairs kv, String username, String token, String sudo, boolean defaults) throws Exception { User user = checkUserCredentials(username, token); String id = KVUtils.getValue(kv, "", "id", "job"); String config = kv.getValue("config"); String expandedConfig; String command = kv.getValue("command"); boolean configMayHaveChanged = true; Job job; if (Strings.isNullOrEmpty(id)) { checkArgument(!Strings.isNullOrEmpty(command), "Parameter 'command' is missing"); requireValidCommandParam(command); checkArgument(config != null, "Parameter 'config' is missing"); expandedConfig = tryExpandJobConfigParam(config); checkKvPairs(kv, user); job = spawn.createJob( kv.getValue("creator"), kv.getIntValue("nodes", -1), Splitter.on(',').omitEmptyStrings().trimResults().splitToList(kv.getValue("hosts", "")), kv.getValue("minionType", DEFAULT_MINION_TYPE), command, defaults); } else { job = spawn.getJob(id); checkArgument(job != null, "Job %s does not exist", id); checkJobWritePrivileges(job, username, token, sudo); if (config == null) { configMayHaveChanged = false; config = spawn.getJobConfig(id); } expandedConfig = tryExpandJobConfigParam(config); if (!Strings.isNullOrEmpty(command)) { requireValidCommandParam(command); job.setCommand(command); } } updateBasicSettings(kv, job, username); updateQueryConfig(kv, job); updateJobParameters(kv, job, expandedConfig); updateBasicAlerts(kv, job); spawn.updateJob(job); if (configMayHaveChanged) { spawn.setJobConfig(job.getId(), config); spawn.submitConfigUpdate(job.getId(), username, kv.getValue("commit")); } return job; } JobRequestHandlerImpl(Spawn spawn); @Override Job createOrUpdateJob(KVPairs kv, String username, String token, String sudo, boolean defaults); @Override Job updateMinionType(String jobId, String minionType, String username, String token, String sudo); @Override boolean maybeKickJobOrTask(KVPairs kv, Job job); }
JobRequestHandlerImpl implements JobRequestHandler { @Override public Job createOrUpdateJob(KVPairs kv, String username, String token, String sudo, boolean defaults) throws Exception { User user = checkUserCredentials(username, token); String id = KVUtils.getValue(kv, "", "id", "job"); String config = kv.getValue("config"); String expandedConfig; String command = kv.getValue("command"); boolean configMayHaveChanged = true; Job job; if (Strings.isNullOrEmpty(id)) { checkArgument(!Strings.isNullOrEmpty(command), "Parameter 'command' is missing"); requireValidCommandParam(command); checkArgument(config != null, "Parameter 'config' is missing"); expandedConfig = tryExpandJobConfigParam(config); checkKvPairs(kv, user); job = spawn.createJob( kv.getValue("creator"), kv.getIntValue("nodes", -1), Splitter.on(',').omitEmptyStrings().trimResults().splitToList(kv.getValue("hosts", "")), kv.getValue("minionType", DEFAULT_MINION_TYPE), command, defaults); } else { job = spawn.getJob(id); checkArgument(job != null, "Job %s does not exist", id); checkJobWritePrivileges(job, username, token, sudo); if (config == null) { configMayHaveChanged = false; config = spawn.getJobConfig(id); } expandedConfig = tryExpandJobConfigParam(config); if (!Strings.isNullOrEmpty(command)) { requireValidCommandParam(command); job.setCommand(command); } } updateBasicSettings(kv, job, username); updateQueryConfig(kv, job); updateJobParameters(kv, job, expandedConfig); updateBasicAlerts(kv, job); spawn.updateJob(job); if (configMayHaveChanged) { spawn.setJobConfig(job.getId(), config); spawn.submitConfigUpdate(job.getId(), username, kv.getValue("commit")); } return job; } JobRequestHandlerImpl(Spawn spawn); @Override Job createOrUpdateJob(KVPairs kv, String username, String token, String sudo, boolean defaults); @Override Job updateMinionType(String jobId, String minionType, String username, String token, String sudo); @Override boolean maybeKickJobOrTask(KVPairs kv, Job job);  }