@Test public void updateJobParameters() throws Exception { Job job = new Job("existing_job_id", "megatron"); job.setParameters(Lists.newArrayList( new JobParameter("start-date", "140908", null), new JobParameter("end-date", "140908", null))); when(spawn.getJob("existing_job_id")).thenReturn(job); kv.add("id", "existing_job_id"); kv.add("config", "%[start-date]% %[foo]%"); kv.add("command", "default-task"); kv.add("sp_start-date", "140908"); kv.add("sp_end-date", "140908"); kv.add("sp_foo", "foo"); kv.add("sp_bar", "bar"); assertSame("returned job", job, impl.createOrUpdateJob(kv, username, token, sudo, false)); assertEquals("# of parameters", 2, job.getParameters().size()); JobParameter foo = null; JobParameter startDate = null; for (JobParameter jp : job.getParameters()) { if ("start-date".equals(jp.getName())) { startDate = jp; } else if ("foo".equals(jp.getName())) { foo = jp; } } assertNotNull("parameter 'start-date' found", startDate); assertEquals("parameter 'start-date' value", "140908", startDate.getValue()); assertNotNull("parameter 'foo' found", foo); assertEquals("parameter 'foo' value", "foo", foo.getValue()); }
private void updateJobParameters(KVPairs kv, IJob job, String expandedConfig) { Map<String, String> setParams = new LinkedHashMap<>(); Collection<JobParameter> oldParams = job.getParameters(); if (oldParams != null) { List<JobParameter> paramList = oldParams.stream().filter(p -> !kv.hasKey("rp_" + p.getName())).collect( Collectors.toList()); for (JobParameter jp: paramList) { if (!setParams.containsKey(jp.getName())) { setParams.put(jp.getName(), jp.getValue()); } } } for (KVPair kvp : kv) { if (kvp.getKey().startsWith("sp_")) { setParams.put(kvp.getKey().substring(3), kvp.getValue()); } } Map<String, JobParameter> macroParams = JobExpand.macroFindParameters(expandedConfig); List<JobParameter> newparams = new ArrayList<>(macroParams.size()); for (JobParameter param : macroParams.values()) { String name = param.getName(); String value = setParams.get(name); param.setValue(value); newparams.add(param); } job.setParameters(newparams); }
JobRequestHandlerImpl implements JobRequestHandler { private void updateJobParameters(KVPairs kv, IJob job, String expandedConfig) { Map<String, String> setParams = new LinkedHashMap<>(); Collection<JobParameter> oldParams = job.getParameters(); if (oldParams != null) { List<JobParameter> paramList = oldParams.stream().filter(p -> !kv.hasKey("rp_" + p.getName())).collect( Collectors.toList()); for (JobParameter jp: paramList) { if (!setParams.containsKey(jp.getName())) { setParams.put(jp.getName(), jp.getValue()); } } } for (KVPair kvp : kv) { if (kvp.getKey().startsWith("sp_")) { setParams.put(kvp.getKey().substring(3), kvp.getValue()); } } Map<String, JobParameter> macroParams = JobExpand.macroFindParameters(expandedConfig); List<JobParameter> newparams = new ArrayList<>(macroParams.size()); for (JobParameter param : macroParams.values()) { String name = param.getName(); String value = setParams.get(name); param.setValue(value); newparams.add(param); } job.setParameters(newparams); } }
JobRequestHandlerImpl implements JobRequestHandler { private void updateJobParameters(KVPairs kv, IJob job, String expandedConfig) { Map<String, String> setParams = new LinkedHashMap<>(); Collection<JobParameter> oldParams = job.getParameters(); if (oldParams != null) { List<JobParameter> paramList = oldParams.stream().filter(p -> !kv.hasKey("rp_" + p.getName())).collect( Collectors.toList()); for (JobParameter jp: paramList) { if (!setParams.containsKey(jp.getName())) { setParams.put(jp.getName(), jp.getValue()); } } } for (KVPair kvp : kv) { if (kvp.getKey().startsWith("sp_")) { setParams.put(kvp.getKey().substring(3), kvp.getValue()); } } Map<String, JobParameter> macroParams = JobExpand.macroFindParameters(expandedConfig); List<JobParameter> newparams = new ArrayList<>(macroParams.size()); for (JobParameter param : macroParams.values()) { String name = param.getName(); String value = setParams.get(name); param.setValue(value); newparams.add(param); } job.setParameters(newparams); } JobRequestHandlerImpl(Spawn spawn); }
JobRequestHandlerImpl implements JobRequestHandler { private void updateJobParameters(KVPairs kv, IJob job, String expandedConfig) { Map<String, String> setParams = new LinkedHashMap<>(); Collection<JobParameter> oldParams = job.getParameters(); if (oldParams != null) { List<JobParameter> paramList = oldParams.stream().filter(p -> !kv.hasKey("rp_" + p.getName())).collect( Collectors.toList()); for (JobParameter jp: paramList) { if (!setParams.containsKey(jp.getName())) { setParams.put(jp.getName(), jp.getValue()); } } } for (KVPair kvp : kv) { if (kvp.getKey().startsWith("sp_")) { setParams.put(kvp.getKey().substring(3), kvp.getValue()); } } Map<String, JobParameter> macroParams = JobExpand.macroFindParameters(expandedConfig); List<JobParameter> newparams = new ArrayList<>(macroParams.size()); for (JobParameter param : macroParams.values()) { String name = param.getName(); String value = setParams.get(name); param.setValue(value); newparams.add(param); } job.setParameters(newparams); } 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 { private void updateJobParameters(KVPairs kv, IJob job, String expandedConfig) { Map<String, String> setParams = new LinkedHashMap<>(); Collection<JobParameter> oldParams = job.getParameters(); if (oldParams != null) { List<JobParameter> paramList = oldParams.stream().filter(p -> !kv.hasKey("rp_" + p.getName())).collect( Collectors.toList()); for (JobParameter jp: paramList) { if (!setParams.containsKey(jp.getName())) { setParams.put(jp.getName(), jp.getValue()); } } } for (KVPair kvp : kv) { if (kvp.getKey().startsWith("sp_")) { setParams.put(kvp.getKey().substring(3), kvp.getValue()); } } Map<String, JobParameter> macroParams = JobExpand.macroFindParameters(expandedConfig); List<JobParameter> newparams = new ArrayList<>(macroParams.size()); for (JobParameter param : macroParams.values()) { String name = param.getName(); String value = setParams.get(name); param.setValue(value); newparams.add(param); } job.setParameters(newparams); } 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);  }