@Test public void updateJob_MissingCommand() throws Exception { Job job = new Job("existing_job_id", "megatron"); job.setCommand("old-task"); when(spawn.getJob("existing_job_id")).thenReturn(job); kv.add("id", "existing_job_id"); kv.add("config", "my job config"); assertSame("returned job", job, impl.createOrUpdateJob(kv, username, token, sudo, false)); assertEquals("command is unchanged", "old-task", job.getCommand()); }
@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);  }