Java代码或Oozie

时间:2014-11-06 09:21:36

标签: java hadoop mahout oozie

我是Hadoop的新手,所以我怀疑在下一个案例中该怎么做。 我有一个算法,包括多个不同作业的运行,有时多次运行一个作业(在一个循环中)。

我应该如何使用Oozie或使用Java代码实现这一目标?我正在查看Mahout代码并在ClusterIterator函数函数中找到了这个:

 public static void iterateMR(Configuration conf, Path inPath, Path priorPath, Path outPath, int numIterations)
               throws IOException, InterruptedException, ClassNotFoundException {

    ClusteringPolicy policy = ClusterClassifier.readPolicy(priorPath);
    Path clustersOut = null;
   int iteration = 1;
   while (iteration <= numIterations) {
      conf.set(PRIOR_PATH_KEY, priorPath.toString());

      String jobName = "Cluster Iterator running iteration " + iteration + " over priorPath: " + priorPath;
      Job job = new Job(conf, jobName);
      job.setMapOutputKeyClass(IntWritable.class);
      job.setMapOutputValueClass(ClusterWritable.class);
      job.setOutputKeyClass(IntWritable.class);
      job.setOutputValueClass(ClusterWritable.class);

      job.setInputFormatClass(SequenceFileInputFormat.class);
      job.setOutputFormatClass(SequenceFileOutputFormat.class);
      job.setMapperClass(CIMapper.class);
      job.setReducerClass(CIReducer.class);

      FileInputFormat.addInputPath(job, inPath);
      clustersOut = new Path(outPath, Cluster.CLUSTERS_DIR + iteration);
      priorPath = clustersOut;
      FileOutputFormat.setOutputPath(job, clustersOut);

      job.setJarByClass(ClusterIterator.class);
      if (!job.waitForCompletion(true)) {
         throw new InterruptedException("Cluster Iteration " + iteration + " failed processing " + priorPath);
      }
      ClusterClassifier.writePolicy(policy, clustersOut);
      FileSystem fs = FileSystem.get(outPath.toUri(), conf);
      iteration++;
      if (isConverged(clustersOut, conf, fs)) {
        break;
      }
    }
    Path finalClustersIn = new Path(outPath, Cluster.CLUSTERS_DIR + (iteration - 1) + Cluster.FINAL_ITERATION_SUFFIX);
    FileSystem.get(clustersOut.toUri(), conf).rename(clustersOut, finalClustersIn);
   }

因此,他们有一个循环,他们运行MR工作。这是一个好方法吗?我知道Oozie用于DAG,可以和其他组件一起使用,比如Pig,但是我应该考虑将它用于这样的东西吗?

如果我想多次运行聚类算法,让我们说聚类(使用特定的驱动程序),我应该在循环中执行,还是使用Oozie。

由于

1 个答案:

答案 0 :(得分:0)

如果您只想运行map reduce jobs,那么您可以考虑以下方式

  • 使用Map减少作业Control API链式MR作业。

http://hadoop.apache.org/docs/r2.5.0/api/org/apache/hadoop/mapreduce/lib/jobcontrol/JobControl.html

  • 从单个驱动程序类提交多个MR作业。

    Job job1 = new Job(getConf()); job.waitForCompletion(true);

    如果(job.isSuccessful()){     //用不同的Mapper开始另一份工作。

    //change config
    Job job2 = new Job( getConf() );
    

    }

如果您有复杂的DAG或涉及多种生态系统工具,如蜂巢,猪,那么Oozie非常适合。