/*
 * Druid - a distributed column store.
 * Copyright (C) 2012, 2013  Metamarkets Group Inc.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

package io.druid.cli;

import com.google.api.client.repackaged.com.google.common.base.Throwables;
import com.google.api.client.util.Lists;
import com.metamx.common.logger.Logger;
import io.airlift.command.Arguments;
import io.airlift.command.Command;
import io.druid.indexer.HadoopDruidDetermineConfigurationJob;
import io.druid.indexer.HadoopDruidIndexerConfig;
import io.druid.indexer.HadoopDruidIndexerJob;
import io.druid.indexer.JobHelper;
import io.druid.indexer.Jobby;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

/**
 */
@Command(
    name = "hadoop-indexer",
    description = "Runs the batch Hadoop Druid Indexer, see https://github.com/metamx/druid/wiki/Batch-ingestion for a description."
)
public class CliInternalHadoopIndexer implements Runnable
{
  private static final Logger log = new Logger(CliHadoopIndexer.class);
  @Arguments(description = "A JSON object or the path to a file that contains a JSON object", required = true)
  private String argumentSpec;

  @Override
  public void run()
  {
    try {
      HadoopDruidIndexerConfig config = getHadoopDruidIndexerConfig();
      List<Jobby> jobs = Lists.newArrayList();
      jobs.add(new HadoopDruidDetermineConfigurationJob(config));
      jobs.add(new HadoopDruidIndexerJob(config));
      JobHelper.runJobs(jobs, config);

    }
    catch (Exception e) {
      throw Throwables.propagate(e);
    }
  }

  public HadoopDruidIndexerConfig getHadoopDruidIndexerConfig()
  {
    try {
      if (argumentSpec.startsWith("{")) {
        return HadoopDruidIndexerConfig.fromString(argumentSpec);
      } else {
        return HadoopDruidIndexerConfig.fromFile(new File(argumentSpec));
      }
    }
    catch (Exception e) {
      throw Throwables.propagate(e);
    }
  }
}
@@ -1220,24 +1220,69 @@
 IndexerJob;%0A
+import io.druid.indexer.HadoopIngestionSpec;%0A
 import io.dr
@@ -1361,36 +1361,8 @@
 le;%0A
-import java.util.ArrayList;%0A
 impo
@@ -2313,24 +2313,56 @@
 %7B%0A    try %7B%0A
+      HadoopIngestionSpec spec;%0A
       if (ar
@@ -2391,38 +2391,38 @@
 %22%7B%22)) %7B%0A        
-return
+spec =
  HadoopDruidInde
@@ -2435,31 +2435,68 @@
 fig.
-fromString(argumentSpec
+jsonMapper.readValue(argumentSpec, HadoopIngestionSpec.class
 );%0A 
@@ -2521,14 +2521,14 @@
     
-return
+spec =
  Had
@@ -2553,15 +2553,27 @@
 fig.
-fromFil
+jsonMapper.readValu
 e(ne
@@ -2592,26 +2592,109 @@
 entSpec)
-);%0A      %7D
+, HadoopIngestionSpec.class);%0A      %7D%0A      return HadoopDruidIndexerConfig.fromSchema(spec);
 %0A    %7D%0A 

fix backwards compatibility