MapReduce.SDK:如何等待MapReduce作业?

时间:2016-01-29 12:02:42

标签: c# hadoop mapreduce hdinsight cortana-intelligence

我正在使用Microsoft MapReduce SDK来启动Mapper唯一的工作。

hadoop.MapReduceJob.ExecuteJob的调用是立即抛出“响应状态代码并不表示成功:404(未找到)”异常。

检查HDInsight查询控制台时,作业成功启动并稍后完成。它还会写出正确的输出文件。

我的猜测是,ExecuteJob正在尝试在作业完成之前访问输出数据。

处理这种情况的正确方法是什么?

using System;
using System.Linq;
using System.Security.Cryptography.X509Certificates;
using Microsoft.WindowsAzure.Management.HDInsight;
using Microsoft.Hadoop.MapReduce;
using AzureAnalyzer.MultiAnalyzer;

namespace AzureAnalyzer
{
    class Program
    {
        static void Main(string[] args)
        {
            IHadoop hadoop = Hadoop.Connect(Constants.azureClusterUri, Constants.clusterUser,
            Constants.hadoopUser, Constants.clusterPassword, Constants.storageAccount,
            Constants.storageAccountKey, Constants.container, true);

            try {
                var output = hadoop.MapReduceJob.ExecuteJob<MultiAnalyzerJob>();
            }
            catch (Exception ex) 
            {
                Console.WriteLine("\nException: " + ex.Message);
            }
        }  
    }
}

2 个答案:

答案 0 :(得分:1)

我有另一种方法可以做同样的事情,但需要花费一些精力,因为它需要将mapper和reducer文件传输到hadoop集群存储。

您还需要添加Microsoft.Hadoop.Client,然后添加Microsoft Azure HDInsight NuGet包。

var jobcred = new BasicAuthCredential();
        jobcred.UserName = "clusteruserid";
        jobcred.Password = "clusterpassword";
        jobcred.Server = new Uri("https://clusterurl");

 StreamingMapReduceJobCreateParameters jobpara = new StreamingMapReduceJobCreateParameters()
        {
            JobName="mapreduce",
            Mapper = "Mapper.exe",
            Reducer = "Reducer.exe",
            Input= "wasb:///mydata/input",
            Output = "wasb:///mydata/Output",
            StatusFolder= "wasb:///mydata/sOutput"

        };
        jobpara.Files.Add("wasb:///mydata/Mapper.exe");
        jobpara.Files.Add("wasb:///mydata/Reducer.exe");


 // Create a Hadoop client to connect to HDInsight.
        var jobClient = JobSubmissionClientFactory.Connect(jobcred);


        // Run the MapReduce job.
        JobCreationResults mrJobResults = jobClient.CreateStreamingJob(jobpara);


        // Wait for the job to complete.
        Console.Write("Job running...");
        JobDetails jobInProgress = jobClient.GetJob(mrJobResults.JobId);
        while (jobInProgress.StatusCode != JobStatusCode.Completed
          && jobInProgress.StatusCode != JobStatusCode.Failed)
        {
            Console.Write(".");
            jobInProgress = jobClient.GetJob(jobInProgress.JobId);
            Thread.Sleep(TimeSpan.FromSeconds(10));
        }
        // Job is complete.
        Console.WriteLine("!");
        Console.WriteLine("Job complete!");
        Console.WriteLine("Press a key to end.");
        Console.Read();

希望这会有所帮助。我能够运行工作而不会抛出任何异常。

事实上,这等待工作完成。

答案 1 :(得分:0)

请验证运行该程序的所有必需服务是否已启动并正在运行。 404错误表示程序尝试在内部访问的某些URL无法访问。