IngestJob extends AbstractJob { protected void processConf(String confAdds, JobConf conf) throws Exception { String[] splits = confAdds.split(";"); if (splits != null && splits.length > 0) { for (String split : splits) { String[] keyVal = split.split("\\["); if (keyVal != null && keyVal.length == 2) { keyVal[1] = keyVal[1].replace(']', ' ').trim(); if (keyVal[1].equalsIgnoreCase("true") || keyVal[1].equalsIgnoreCase("false")) { log.info("Setting {} as a boolean: {}", keyVal[0], keyVal[1]); conf.setBoolean(keyVal[0], Boolean.parseBoolean(keyVal[1])); } else { try { Integer num = Integer.parseInt(keyVal[1]); if (num != null) { log.info("Setting {} as an int: {}", keyVal[0], keyVal[1]); conf.setInt(keyVal[0], num); continue; } } catch (NumberFormatException e) { } try { Float num = Float.parseFloat(keyVal[1]); if (num != null) { log.info("Setting {} as a float: {}", keyVal[0], keyVal[1]); conf.setFloat(keyVal[0], num); continue; } } catch (NumberFormatException e) { } log.info("Setting {} as a String: {}", keyVal[0], keyVal[1]); conf.set(keyVal[0], keyVal[1]); } } else { log.error("Can't parse split {}", split); throw new Exception("Can't parse split: " + split); } } } }  static void main(String[] args); @Override int run(String[] args); void doFinalCommit(JobConf conf, RunningJob job); boolean checkSolrServer(JobConf conf); static final String COLLECTION_OPTION; static final String MIME_TYPE_OPTION; static final String ZK_CONNECT_OPTION; static final String MAPPER_OPTION; static final String REDUCER_OPTION; static final String OVERWRITE_OPTION; static final String INPUT_FORMAT; static final String SOLR_SERVER_OPTION; static final String NUM_REDUCERS_OPTION; static final String OUTPUT_FORMAT; static final String DEFAULT_MAPPER_CLASS; static final String INPUT_FORMAT_OVERRIDE; static final String OUTPUT_FORMAT_OVERRIDE; static final String CONF_OPTION; static final String JOB_NAME_OPTION; static final String QUIET; }
@Test public void testConfHandling() throws Exception { JobConf conf = new JobConf(); TestIngestJob ij = new TestIngestJob(); ij.processConf("foo[true];bar[1];junk[2.3];hockey[this is a string]", conf); assertTrue(conf.getBoolean("foo", false)); assertEquals(1, conf.getInt("bar", 0)); assertEquals(2.3, conf.getFloat("junk", 0), 0.1); assertEquals("this is a string", conf.get("hockey")); try { ij.processConf("foo", conf); fail(); } catch (Exception e) { assertTrue(e.getMessage().startsWith("Can't parse")); } }