Skip to content

Commit c995133

Browse files
authored
Merge pull request #79081 from dagiro/freshness119
freshness119
2 parents b231c39 + 7b6e6aa commit c995133

File tree

1 file changed

+27
-31
lines changed

1 file changed

+27
-31
lines changed

articles/hdinsight/hdinsight-hadoop-manage-ambari-rest-api.md

Lines changed: 27 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,22 @@ ms.reviewer: jasonh
77
ms.service: hdinsight
88
ms.custom: hdinsightactive
99
ms.topic: conceptual
10-
ms.date: 03/07/2019
10+
ms.date: 06/07/2019
1111
ms.author: hrasheed
12-
1312
---
13+
1414
# Manage HDInsight clusters by using the Apache Ambari REST API
1515

1616
[!INCLUDE [ambari-selector](../../includes/hdinsight-ambari-selector.md)]
1717

1818
Learn how to use the Apache Ambari REST API to manage and monitor Apache Hadoop clusters in Azure HDInsight.
1919

2020
## <a id="whatis"></a>What is Apache Ambari
21+
2122
[Apache Ambari](https://ambari.apache.org) simplifies the management and monitoring of Hadoop clusters by providing an easy to use web UI backed by its [REST APIs](https://github.com/apache/ambari/blob/trunk/ambari-server/docs/api/v1/index.md). Ambari is provided by default with Linux-based HDInsight clusters.
2223

2324
## Prerequisites
25+
2426
* **A Hadoop cluster on HDInsight**. See [Get Started with HDInsight on Linux](hadoop/apache-hadoop-linux-tutorial-get-started.md).
2527

2628
* **Bash on Ubuntu on Windows 10**. The examples in this article use the Bash shell on Windows 10. See [Windows Subsystem for Linux Installation Guide for Windows 10](https://docs.microsoft.com/windows/wsl/install-win10) for installation steps. Other [Unix shells](https://www.gnu.org/software/bash/) will work as well. The examples, with some slight modifications, can work on a Windows Command prompt. Alternatively, you can use Windows PowerShell.
@@ -31,7 +33,7 @@ Learn how to use the Apache Ambari REST API to manage and monitor Apache Hadoop
3133

3234
## Base URI for Ambari Rest API
3335

34-
The base URI for the Ambari REST API on HDInsight is `https://CLUSTERNAME.azurehdinsight.net/api/v1/clusters/CLUSTERNAME`, where `CLUSTERNAME` is the name of your cluster. Cluster names in URIs are **case-sensitive**. While the cluster name in the fully qualified domain name (FQDN) part of the URI (CLUSTERNAME.azurehdinsight.net) is case-insensitive, other occurrences in the URI are case-sensitive.
36+
The base Uniform Resource Identifier (URI) for the Ambari REST API on HDInsight is `https://CLUSTERNAME.azurehdinsight.net/api/v1/clusters/CLUSTERNAME`, where `CLUSTERNAME` is the name of your cluster. Cluster names in URIs are **case-sensitive**. While the cluster name in the fully qualified domain name (FQDN) part of the URI (`CLUSTERNAME.azurehdinsight.net`) is case-insensitive, other occurrences in the URI are case-sensitive.
3537

3638
## Authentication
3739

@@ -56,12 +58,10 @@ $creds = Get-Credential -UserName "admin" -Message "Enter the HDInsight login"
5658
```
5759

5860
### Identify correctly cased cluster name
59-
The actual casing of the cluster name may be different than you expect depending on how the cluster was created. The steps here will show the actual casing, and then store it in a variable for all subsequent examples.
61+
The actual casing of the cluster name may be different than you expect, depending on how the cluster was created. The steps here will show the actual casing, and then store it in a variable for all subsequent examples.
6062

6163
Edit the scripts below to replace `CLUSTERNAME` with your cluster name. Then enter the command. (The cluster name for the FQDN is not case-sensitive.)
6264

63-
**A. Bash**
64-
6565
```bash
6666
export clusterName=$(curl -u admin:$password -sS -G "https://CLUSTERNAME.azurehdinsight.net/api/v1/clusters" | jq -r '.items[].Clusters.cluster_name')
6767
echo $clusterName
@@ -91,7 +91,7 @@ $resp = Invoke-WebRequest -Uri "https://$clusterName.azurehdinsight.net/api/v1/c
9191
-Credential $creds -UseBasicParsing
9292
$respObj = ConvertFrom-Json $resp.Content
9393
$respObj.Clusters.health_report
94-
```
94+
```
9595

9696
### <a name="example-get-the-fqdn-of-cluster-nodes"></a> Get the FQDN of cluster nodes
9797

@@ -101,7 +101,7 @@ When working with HDInsight, you may need to know the fully qualified domain nam
101101

102102
```bash
103103
curl -u admin:$password -sS -G "https://$clusterName.azurehdinsight.net/api/v1/clusters/$clusterName/hosts" \
104-
| jq '.items[].Hosts.host_name'
104+
| jq -r '.items[].Hosts.host_name'
105105
```
106106

107107
```powershell
@@ -115,7 +115,7 @@ $respObj.items.Hosts.host_name
115115

116116
```bash
117117
curl -u admin:$password -sS -G "https://$clusterName.azurehdinsight.net/api/v1/clusters/$clusterName/services/HDFS/components/NAMENODE" \
118-
| jq '.host_components[].HostRoles.host_name'
118+
| jq -r '.host_components[].HostRoles.host_name'
119119
```
120120

121121
```powershell
@@ -129,7 +129,7 @@ $respObj.host_components.HostRoles.host_name
129129

130130
```bash
131131
curl -u admin:$password -sS -G "https://$clusterName.azurehdinsight.net/api/v1/clusters/$clusterName/services/HDFS/components/DATANODE" \
132-
| jq '.host_components[].HostRoles.host_name'
132+
| jq -r '.host_components[].HostRoles.host_name'
133133
```
134134

135135
```powershell
@@ -143,7 +143,7 @@ $respObj.host_components.HostRoles.host_name
143143

144144
```bash
145145
curl -u admin:$password -sS -G "https://$clusterName.azurehdinsight.net/api/v1/clusters/$clusterName/services/ZOOKEEPER/components/ZOOKEEPER_SERVER" \
146-
| jq ".host_components[].HostRoles.host_name"
146+
| jq -r ".host_components[].HostRoles.host_name"
147147
```
148148

149149
```powershell
@@ -191,7 +191,7 @@ The following examples retrieve the default storage configuration from the clust
191191

192192
```bash
193193
curl -u admin:$password -sS -G "https://$clusterName.azurehdinsight.net/api/v1/clusters/$clusterName/configurations/service_config_versions?service_name=HDFS&service_config_version=1" \
194-
| jq '.items[].configurations[].properties["fs.defaultFS"] | select(. != null)'
194+
| jq -r '.items[].configurations[].properties["fs.defaultFS"] | select(. != null)'
195195
```
196196

197197
```powershell
@@ -206,7 +206,7 @@ $respObj.items.configurations.properties.'fs.defaultFS'
206206
207207
The return value is similar to one of the following examples:
208208

209-
* `wasb://[email protected]` - This value indicates that the cluster is using an Azure Storage account for default storage. The `ACCOUNTNAME` value is the name of the storage account. The `CONTAINER` portion is the name of the blob container in the storage account. The container is the root of the HDFS compatible storage for the cluster.
209+
* `wasbs://[email protected]` - This value indicates that the cluster is using an Azure Storage account for default storage. The `ACCOUNTNAME` value is the name of the storage account. The `CONTAINER` portion is the name of the blob container in the storage account. The container is the root of the HDFS compatible storage for the cluster.
210210

211211
* `abfs://[email protected]` - This value indicates that the cluster is using Azure Data Lake Storage Gen2 for default storage. The `ACCOUNTNAME` and `CONTAINER` values have the same meanings as for Azure Storage mentioned previously.
212212

@@ -216,7 +216,7 @@ The return value is similar to one of the following examples:
216216

217217
```bash
218218
curl -u admin:$password -sS -G "https://$clusterName.azurehdinsight.net/api/v1/clusters/$clusterName/configurations/service_config_versions?service_name=HDFS&service_config_version=1" \
219-
| jq '.items[].configurations[].properties["dfs.adls.home.hostname"] | select(. != null)'
219+
| jq -r '.items[].configurations[].properties["dfs.adls.home.hostname"] | select(. != null)'
220220
```
221221

222222
```powershell
@@ -232,7 +232,7 @@ The return value is similar to one of the following examples:
232232

233233
```bash
234234
curl -u admin:$password -sS -G "https://$clusterName.azurehdinsight.net/api/v1/clusters/$clusterName/configurations/service_config_versions?service_name=HDFS&service_config_version=1" \
235-
| jq '.items[].configurations[].properties["dfs.adls.home.mountpoint"] | select(. != null)'
235+
| jq -r '.items[].configurations[].properties["dfs.adls.home.mountpoint"] | select(. != null)'
236236
```
237237

238238
```powershell
@@ -247,7 +247,6 @@ The return value is similar to one of the following examples:
247247
> [!NOTE]
248248
> The [Get-AzHDInsightCluster](https://docs.microsoft.com/powershell/module/az.hdinsight/get-azhdinsightcluster) cmdlet provided by [Azure PowerShell](/powershell/azure/overview) also returns the storage information for the cluster.
249249

250-
251250
### <a name="get-all-configurations"></a> Get all configurations
252251

253252
Get the configurations that are available for your cluster.
@@ -263,7 +262,7 @@ $respObj.Content
263262
```
264263
265264
This example returns a JSON document containing the current configuration (identified by the *tag* value) for the components installed on the cluster. The following example is an excerpt from the data returned from a Spark cluster type.
266-
265+
267266
```json
268267
"jupyter-site" : {
269268
"tag" : "INITIAL",
@@ -307,10 +306,9 @@ This example returns a JSON document containing the current configuration for th
307306
```bash
308307
curl -u admin:$password -sS -G "https://$clusterName.azurehdinsight.net/api/v1/clusters/$clusterName/configurations?type=livy2-conf&tag=INITIAL" \
309308
| jq --arg newtag $(echo version$(date +%s%N)) '.items[] | del(.href, .version, .Config) | .tag |= $newtag | {"Clusters": {"desired_config": .}}' > newconfig.json
310-
311309
```
312310
313-
**B. powershell**
311+
**B. PowerShell**
314312
The PowerShell script uses [jq](https://stedolan.github.io/jq/). Edit `C:\HD\jq\jq-win64` below to reflect your actual path and version of [jq](https://stedolan.github.io/jq/).
315313
316314
```powershell
@@ -398,7 +396,6 @@ At this point, if you look at the Ambari web UI, the Spark service indicates tha
398396
-Method PUT `
399397
-Headers @{"X-Requested-By" = "ambari"} `
400398
-Body '{"RequestInfo": {"context": "turning on maintenance mode for SPARK2"},"Body": {"ServiceInfo": {"maintenance_state":"ON"}}}'
401-
$resp.Content
402399
```
403400
404401
2. Verify maintenance mode
@@ -424,16 +421,16 @@ At this point, if you look at the Ambari web UI, the Spark service indicates tha
424421
425422
```bash
426423
curl -u admin:$password -sS -H "X-Requested-By: ambari" \
427-
-X PUT -d '{"RequestInfo":{"context":"_PARSE_.STOP.SPARK","operation_level":{"level":"SERVICE","cluster_name":"CLUSTERNAME","service_name":"SPARK"}},"Body":{"ServiceInfo":{"state":"INSTALLED"}}}' \
428-
"https://girouxSpark.azurehdinsight.net/api/v1/clusters/girouxspark/services/SPARK2"
424+
-X PUT -d '{"RequestInfo":{"context":"_PARSE_.STOP.SPARK2","operation_level":{"level":"SERVICE","cluster_name":"CLUSTERNAME","service_name":"SPARK"}},"Body":{"ServiceInfo":{"state":"INSTALLED"}}}' \
425+
"https://$clusterName.azurehdinsight.net/api/v1/clusters/$clusterName/services/SPARK2"
429426
```
430427
431428
```powershell
432429
$resp = Invoke-WebRequest -Uri "https://$clusterName.azurehdinsight.net/api/v1/clusters/$clusterName/services/SPARK2" `
433-
-Credential $creds `
430+
-Credential $creds -UseBasicParsing `
434431
-Method PUT `
435432
-Headers @{"X-Requested-By" = "ambari"} `
436-
-Body '{"RequestInfo":{"context":"_PARSE_.STOP.SPARK","operation_level":{"level":"SERVICE","cluster_name":"CLUSTERNAME","service_name":"SPARK"}},"Body":{"ServiceInfo":{"state":"INSTALLED"}}}'
433+
-Body '{"RequestInfo":{"context":"_PARSE_.STOP.SPARK2","operation_level":{"level":"SERVICE","cluster_name":"CLUSTERNAME","service_name":"SPARK"}},"Body":{"ServiceInfo":{"state":"INSTALLED"}}}'
437434
$resp.Content
438435
```
439436
@@ -450,7 +447,7 @@ At this point, if you look at the Ambari web UI, the Spark service indicates tha
450447
```
451448
452449
> [!IMPORTANT]
453-
> The `href` value returned by this URI is using the internal IP address of the cluster node. To use it from outside the cluster, replace the `10.0.0.18:8080' portion with the FQDN of the cluster.
450+
> The `href` value returned by this URI is using the internal IP address of the cluster node. To use it from outside the cluster, replace the `10.0.0.18:8080` portion with the FQDN of the cluster.
454451
455452
4. Verify request.
456453
Edit the command below by replacing `29` with the actual value for `id` returned from the prior step. The following commands retrieve the status of the request:
@@ -471,10 +468,10 @@ At this point, if you look at the Ambari web UI, the Spark service indicates tha
471468
A response of `COMPLETED` indicates that the request has finished.
472469
473470
5. Once the previous request completes, use the following to start the Spark2 service.
474-
471+
475472
```bash
476473
curl -u admin:$password -sS -H "X-Requested-By: ambari" \
477-
-X PUT -d '{"RequestInfo":{"context":"_PARSE_.STOP.SPARK","operation_level":{"level":"SERVICE","cluster_name":"CLUSTERNAME","service_name":"SPARK"}},"Body":{"ServiceInfo":{"state":"STARTED"}}}' \
474+
-X PUT -d '{"RequestInfo":{"context":"_PARSE_.START.SPARK2","operation_level":{"level":"SERVICE","cluster_name":"CLUSTERNAME","service_name":"SPARK"}},"Body":{"ServiceInfo":{"state":"STARTED"}}}' \
478475
"https://$clusterName.azurehdinsight.net/api/v1/clusters/$clusterName/services/SPARK2"
479476
```
480477
@@ -483,7 +480,8 @@ At this point, if you look at the Ambari web UI, the Spark service indicates tha
483480
-Credential $creds -UseBasicParsing `
484481
-Method PUT `
485482
-Headers @{"X-Requested-By" = "ambari"} `
486-
-Body '{"RequestInfo":{"context":"_PARSE_.STOP.SPARK","operation_level":{"level":"SERVICE","cluster_name":"CLUSTERNAME","service_name":"SPARK"}},"Body":{"ServiceInfo":{"state":"STARTED"}}}'
483+
-Body '{"RequestInfo":{"context":"_PARSE_.START.SPARK2","operation_level":{"level":"SERVICE","cluster_name":"CLUSTERNAME","service_name":"SPARK"}},"Body":{"ServiceInfo":{"state":"STARTED"}}}'
484+
$resp.Content
487485
```
488486
489487
The service is now using the new configuration.
@@ -502,10 +500,8 @@ At this point, if you look at the Ambari web UI, the Spark service indicates tha
502500
-Method PUT `
503501
-Headers @{"X-Requested-By" = "ambari"} `
504502
-Body '{"RequestInfo": {"context": "turning off maintenance mode for SPARK2"},"Body": {"ServiceInfo": {"maintenance_state":"OFF"}}}'
505-
506503
```
507504
508505
## Next steps
509506
510-
For a complete reference of the REST API, see [Apache Ambari API Reference V1](https://github.com/apache/ambari/blob/trunk/ambari-server/docs/api/v1/index.md).
511-
507+
For a complete reference of the REST API, see [Apache Ambari API Reference V1](https://github.com/apache/ambari/blob/trunk/ambari-server/docs/api/v1/index.md).

0 commit comments

Comments
 (0)