C#Map使用" {"响应状态代码不表示成功:403(禁止)。"}有时401:需要凭据

时间:2016-09-02 06:57:45

标签: azure hadoop mapreduce hdinsight bigdata

System.AggregateException

中发生了mscorlib.dll类型的未处理异常

内部异常:{"Response status code does not indicate success: 403 (Forbidden)."} 有时得到:{"Response status code does not indicate success: 401 (Credentials required)."}

所有登录都是正确的。 Hadoop.Connect()连接正确。

堆栈追踪:

  

at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean   includeTaskCanceledExceptions)at   System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout,   取消语音取消语言)   System.Threading.Tasks.Task.Wait()at   Microsoft.Hadoop.WebClient.WebHCatClient.WebHcatMapReduceStreamingExecutor.Execute(布尔   throwOnError)at   Microsoft.Hadoop.MapReduce.Execution.Hadoop.StreamingJobExecutorBase.ExecuteCore(类型   mapper,Type reducer,Type combiner,HadoopJobConfiguration config)
  在   Microsoft.Hadoop.MapReduce.Execution.Hadoop.StreamingJobExecutorBase.Execute(类型   mapperType,Type reducerType,Type combinerType,   HadoopJobConfiguration配置)   Microsoft.Hadoop.MapReduce.Execution.Hadoop.StreamingJobExecutorBase.Execute [TMapper,TReducer](HadoopJobConfiguration   配置)在C:\ ASC中的Pwc.Demo.HDPClient.Program.Main(String [] args)   项目信息\ TalentExchange \ Demo   project \ Pwc.Demo.HDPClient \ Pwc.Demo.HDPClient \ Program.cs:第49行at   System.AppDomain._nExecuteAssembly(RuntimeAssembly程序集,String []   args)在System.AppDomain.ExecuteAssembly(String assemblyFile,   证据assemblySecurity,String [] args)at   Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
  在System.Threading.ThreadHelper.ThreadStart_Context(对象状态)
  在System.Threading.ExecutionContext.RunInternal(ExecutionContext   executionContext,ContextCallback回调,对象状态,布尔值   preserveSyncCtx)at   System.Threading.ExecutionContext.Run(执行上下文   executionContext,ContextCallback回调,对象状态,布尔值   preserveSyncCtx)at   System.Threading.ExecutionContext.Run(执行上下文   executionContext,ContextCallback回调,对象状态)at   System.Threading.ThreadHelper.ThreadStart()

class Program
       {
            static void Main(string[] args)
           {
              HadoopJobConfiguration myConfig = new   HadoopJobConfiguration();

            myConfig.InputPath = "asv://hdsto-something-.net/data/in/reviews.txt";
            myConfig.OutputFolder = "asv://hd-something-.blob.core.windows.net/data/out/";
            Environment.SetEnvironmentVariable("HADOOP_HOME", @"C:\apps\dist\hadoop-2.7.1.2.3.3.1-25\bin");
            Environment.SetEnvironmentVariable("JAVA_HOME", @"C:\Program Files\Java\jre1.8.0_101\bin\javaw.exe");

            Uri azureCluster = new Uri("https://somename--Demo.azurehdinsight.net");
            string clusterUserName = "***";
            string clusterPassword = "****";

            // This is the name of the account under which Hadoop will execute jobs.
            // Normally this is just "Hadoop".
            string hadoopUserName = "Hadoop";

            // Azure Storage Information.
            string azureStorageAccount = "somestore.blob.core.windows.net";
            string azureStorageKey = "***==";
            string azureStorageContainer = "**";
            bool createContinerIfNotExist = false;

            IHadoop myCluster = Hadoop.Connect(azureCluster,
                                        clusterUserName,
                                        hadoopUserName,
                                        clusterPassword,
                                        azureStorageAccount,
                                        azureStorageKey,
                                        azureStorageContainer,
                                        createContinerIfNotExist);

            //execute mapreduce job

            MapReduceResult jobResult =

                myCluster.MapReduceJob.Execute<MySimpleMapper, MySimpleReducer>(myConfig);

            int exitCode = jobResult.Info.ExitCode;
            string exitStatus = "Failure";
            if (exitCode == 0) exitStatus = "Success";
            exitStatus = exitCode + " (" + exitStatus + ")";
            Console.WriteLine();
            Console.Write("Exit Code = " + exitStatus);
            Console.Read();
        }
    }

    public class MySimpleMapper : MapperBase
    {
        public override void Map(string inputLine, MapperContext context)
        {
            int value = int.Parse(inputLine);
            string key = (value % 2 == 0) ? "even" : "odd";
            context.EmitKeyValue(key, value.ToString());
        }
    }

    public class MySimpleReducer : ReducerCombinerBase
    {
        public override void Reduce(string key, IEnumerable<string> values, ReducerCombinerContext context)
        {
            //initialize counters
            int myCount = 0;
            int mySum = 0;
            //count and sum incoming values
            foreach (string value in values)
            {
                mySum += int.Parse(value);
                myCount++;
            }
            context.EmitKeyValue(key, myCount + "t" + mySum);

        }
    }

错误快照: enter image description here

1 个答案:

答案 0 :(得分:0)

您的输入路径不应该是特定文件,而是目录。该目录应该只包含文件而不包含文件夹。

myConfig.InputPath = "asv://hdsto-something-.net/data/in/";