You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/hdinsight/hadoop/apache-hadoop-use-mapreduce-curl.md
+78-51Lines changed: 78 additions & 51 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,7 +7,7 @@ ms.reviewer: jasonh
7
7
ms.service: hdinsight
8
8
ms.topic: conceptual
9
9
ms.custom: hdinsightactive
10
-
ms.date: 02/27/2018
10
+
ms.date: 01/13/2020
11
11
---
12
12
13
13
# Run MapReduce jobs with Apache Hadoop on HDInsight using REST
@@ -17,45 +17,91 @@ Learn how to use the Apache Hive WebHCat REST API to run MapReduce jobs on an Ap
17
17
> [!NOTE]
18
18
> If you are already familiar with using Linux-based Hadoop servers, but you are new to HDInsight, see the [What you need to know about Linux-based Apache Hadoop on HDInsight](../hdinsight-hadoop-linux-information.md) document.
19
19
20
+
## Prerequisites
20
21
21
-
## <aid="prereq"></a>Prerequisites
22
+
* An Apache Hadoop cluster on HDInsight. See [Create Apache Hadoop clusters using the Azure portal](../hdinsight-hadoop-create-linux-clusters-portal.md).
22
23
23
-
* A Hadoop on HDInsight cluster
24
-
* Windows PowerShell or [Curl](https://curl.haxx.se/) and [jq](https://stedolan.github.io/jq/)
24
+
Either:
25
+
* Windows PowerShell or,
26
+
*[Curl](https://curl.haxx.se/) with [jq](https://stedolan.github.io/jq/)
25
27
26
-
## <aid="curl"></a>Run a MapReduce job
28
+
## Run a MapReduce job
27
29
28
30
> [!NOTE]
29
31
> When you use Curl or any other REST communication with WebHCat, you must authenticate the requests by providing the HDInsight cluster administrator user name and password. You must use the cluster name as part of the URI that is used to send the requests to the server.
30
32
>
31
33
> The REST API is secured by using [basic access authentication](https://en.wikipedia.org/wiki/Basic_access_authentication). You should always make requests by using HTTPS to ensure that your credentials are securely sent to the server.
32
34
33
-
1. To set the cluster login that is used by the scripts in this document, use one of the following commands:
35
+
### Curl
36
+
37
+
1. For ease of use, set the variables below. This example is based on a Windows environment, revise as needed for your environment.
38
+
39
+
```cmd
40
+
set CLUSTERNAME=
41
+
set PASSWORD=
42
+
```
43
+
44
+
1. From a command line, use the following command to verify that you can connect to your HDInsight cluster:
34
45
35
46
```bash
36
-
read -p "Enter your cluster login account name: " LOGIN
$clusterName = Read-Host -Prompt "Enter the HDInsight cluster name"
73
+
The end of the URI (/mapreduce/jar) tells WebHCat that this request starts a MapReduce job from a class in a jar file. The parameters used in this command are as follows:
74
+
75
+
* **-d**: `-G` isn't used, so the request defaults to the POST method. `-d` specifies the data values that are sent with the request.
76
+
* **user.name**: The user who is running the command
77
+
* **jar**: The location of the jar file that contains class to be ran
78
+
* **class**: The class that contains the MapReduce logic
79
+
* **arg**: The arguments to be passed to the MapReduce job. In this case, the input text file and the directory that are used for the output
80
+
81
+
This command should return a job ID that can be used to check the status of the job:
82
+
83
+
job_1415651640909_0026
84
+
85
+
1. To check the status of the job, use the following command. Replace the value for `JOBID` with the **actual** value returned in the previous step. Revise location of **jq** as needed.
1. For ease of use, set the variables below. Replace `CLUSTERNAME` with your actual cluster name. Execute the command and enter the cluster login password when prompted.
1. To submit a MapReduce job, use the following command:
119
+
84
120
```powershell
85
121
$reqParams = @{}
86
122
$reqParams."user.name" = "admin"
@@ -100,52 +136,43 @@ Learn how to use the Apache Hive WebHCat REST API to run MapReduce jobs on an Ap
100
136
101
137
The end of the URI (/mapreduce/jar) tells WebHCat that this request starts a MapReduce job from a class in a jar file. The parameters used in this command are as follows:
102
138
103
-
***-d**: `-G` is not used, so the request defaults to the POST method. `-d` specifies the data values that are sent with the request.
104
-
***user.name**: The user who is running the command
105
-
***jar**: The location of the jar file that contains class to be ran
106
-
***class**: The class that contains the MapReduce logic
107
-
***arg**: The arguments to be passed to the MapReduce job. In this case, the input text file and the directory that are used for the output
139
+
* **user.name**: The user who is running the command
140
+
* **jar**: The location of the jar file that contains class to be ran
141
+
* **class**: The class that contains the MapReduce logic
142
+
* **arg**: The arguments to be passed to the MapReduce job. In this case, the input text file and the directory that are used for the output
108
143
109
144
This command should return a job ID that can be used to check the status of the job:
110
145
111
146
job_1415651640909_0026
112
147
113
-
5. To check the status of the job, use the following command:
# ConvertFrom-JSON can't handle duplicate names with different case
126
158
# So change one to prevent the error
127
159
$fixDup=$resp.Content.Replace("jobID","job_ID")
128
160
(ConvertFrom-Json $fixDup).status.state
129
161
```
130
162
131
-
If the job is complete, the state returned is `SUCCEEDED`.
163
+
### Both methods
132
164
133
-
> [!NOTE]
134
-
> This Curl request returns a JSON document with information about the job. Jq is used to retrieve only the state value.
165
+
1. If the job is complete, the state returned is `SUCCEEDED`.
135
166
136
-
6. When the state of the job has changed to `SUCCEEDED`, you can retrieve the results of the job from Azure Blob storage. The `statusdir` parameter that is passed with the query contains the location of the output file. In this example, the location is `/example/curl`. This address stores the output of the job in the clusters default storage at `/example/curl`.
167
+
1. When the state of the job has changed to `SUCCEEDED`, you can retrieve the results of the job from Azure Blob storage. The `statusdir` parameter that is passed with the query contains the location of the output file. In this example, the location is `/example/curl`. This address stores the output of the job in the clusters default storage at `/example/curl`.
137
168
138
169
You can list and download these files by using the [Azure CLI](https://docs.microsoft.com/cli/azure/install-azure-cli). For more information on working with blobs from the Azure CLI, see the [Using the Azure CLI with Azure Storage](../../storage/common/storage-azure-cli.md#create-and-manage-blobs) document.
139
170
140
-
## <a id="nextsteps"></a>Next steps
141
-
142
-
For general information about MapReduce jobsin HDInsight:
143
-
144
-
* [Use MapReduce with Apache Hadoop on HDInsight](hdinsight-use-mapreduce.md)
171
+
## Next steps
145
172
146
173
For information about other ways you can work with Hadoop on HDInsight:
147
174
175
+
* [Use MapReduce with Apache Hadoop on HDInsight](hdinsight-use-mapreduce.md)
148
176
* [Use Apache Hive with Apache Hadoop on HDInsight](hdinsight-use-hive.md)
149
-
* [Use Apache Pig with Apache Hadoop on HDInsight](hdinsight-use-pig.md)
150
177
151
178
For more information about the REST interface that is used in this article, see the [WebHCat Reference](https://cwiki.apache.org/confluence/display/Hive/WebHCat+Reference).
0 commit comments