使用 Apache Ambari REST API 管理 HDInsight 群集Manage HDInsight clusters by using the Apache Ambari REST API

了解如何使用 Apache Ambari REST API 管理和监视 Azure HDInsight 中的 Apache Hadoop 群集。Learn how to use the Apache Ambari REST API to manage and monitor Apache Hadoop clusters in Azure HDInsight.

什么是 Apache AmbariWhat is Apache Ambari

Apache Ambari 提供基于 REST API 的简单易用型 Web UI 来简化 Hadoop 群集的管理和监视。Apache Ambari simplifies the management and monitoring of Hadoop clusters by providing an easy to use web UI backed by its REST APIs. 基于 Linux 的 HDInsight 群集已按默认提供 Ambari。Ambari is provided by default with Linux-based HDInsight clusters.

先决条件Prerequisites

用于 Ambari Rest API 的基 URIBase URI for Ambari Rest API

Ambari REST API 在 HDInsight 上的基 URI 是 https://CLUSTERNAME.azurehdinsight.cn/api/v1/clusters/CLUSTERNAME,其中 CLUSTERNAME 是群集的名称。The base URI for the Ambari REST API on HDInsight is https://CLUSTERNAME.azurehdinsight.cn/api/v1/clusters/CLUSTERNAME, where CLUSTERNAME is the name of your cluster. URI 中的群集名称区分大小写Cluster names in URIs are case-sensitive. URI 的完全限定域名 (FQDN) 部分 (CLUSTERNAME.azurehdinsight.cn) 中的群集名称不区分大小写,但 URI 中的其他部分则区分大小写。While the cluster name in the fully qualified domain name (FQDN) part of the URI (CLUSTERNAME.azurehdinsight.cn) is case-insensitive, other occurrences in the URI are case-sensitive.

身份验证Authentication

连接到 HDInsight 上的 Ambari 需要 HTTPS。Connecting to Ambari on HDInsight requires HTTPS. 使用在群集创建过程中提供的管理员帐户名称(默认值是 admin)和密码。Use the admin account name (the default is admin) and password you provided during cluster creation.

示例Examples

设置(保留凭据)Setup (Preserve credentials)

请保留凭据,以免在每个示例中重复输入。Preserve your credentials to avoid reentering them for each example. 群集名称将在单独的步骤中保留。The cluster name will be preserved in a separate step.

A.A. BashBash
编辑以下脚本,将 PASSWORD 替换为实际密码。Edit the script below by replacing PASSWORD with your actual password. 然后输入该命令。Then enter the command.

export password='PASSWORD'

B.B. PowerShellPowerShell

$creds = Get-Credential -UserName "admin" -Message "Enter the HDInsight login"

识别大小写正确的群集名称Identify correctly cased cluster name

群集名称的实际大小写可能不符合预期,具体取决于群集的创建方式。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.

编辑以下脚本,将 CLUSTERNAME 替换为群集名称。Edit the scripts below to replace CLUSTERNAME with your cluster name. 然后输入该命令。Then enter the command. (FQDN 的群集名称不区分大小写。)(The cluster name for the FQDN is not case-sensitive.)

A.A. BashBash

export clusterName=$(curl -u admin:$password -sS -G "https://CLSUTERNAME.azurehdinsight.cn/api/v1/clusters" | jq -r '.items[].Clusters.cluster_name')
echo $clusterName
# Identify properly cased cluster name
$resp = Invoke-WebRequest -Uri "https://CLUSTERNAME.azurehdinsight.cn/api/v1/clusters" `
    -Credential $creds -UseBasicParsing
$clusterName = (ConvertFrom-Json $resp.Content).items.Clusters.cluster_name;

# Show cluster name
$clusterName

分析 JSON 数据Parsing JSON data

以下示例使用 jqConvertFrom-Json 来分析 JSON 响应文档并仅显示结果中的 health_report 信息。The following example uses jq or ConvertFrom-Json to parse the JSON response document and display only the health_report information from the results.

curl -u admin:$password -sS -G "https://$clusterName.azurehdinsight.cn/api/v1/clusters/$clusterName" \
| jq '.Clusters.health_report'
$resp = Invoke-WebRequest -Uri "https://$clusterName.azurehdinsight.cn/api/v1/clusters/$clusterName" `
    -Credential $creds -UseBasicParsing
$respObj = ConvertFrom-Json $resp.Content
$respObj.Clusters.health_report

获取群集节点的 FQDNGet the FQDN of cluster nodes

使用 HDInsight 时,可能需要知道群集节点的完全限定域名 (FQDN)。When working with HDInsight, you may need to know the fully qualified domain name (FQDN) of a cluster node. 可使用以下示例轻松检索群集中各个节点的 FQDN:You can easily retrieve the FQDN for the various nodes in the cluster using the following examples:

所有节点All nodes

curl -u admin:$password -sS -G "https://$clusterName.azurehdinsight.cn/api/v1/clusters/$clusterName/hosts" \
| jq '.items[].Hosts.host_name'
$resp = Invoke-WebRequest -Uri "https://$clusterName.azurehdinsight.cn/api/v1/clusters/$clusterName/hosts" `
    -Credential $creds -UseBasicParsing
$respObj = ConvertFrom-Json $resp.Content
$respObj.items.Hosts.host_name

头节点Head nodes

curl -u admin:$password -sS -G "https://$clusterName.azurehdinsight.cn/api/v1/clusters/$clusterName/services/HDFS/components/NAMENODE" \
| jq '.host_components[].HostRoles.host_name'
$resp = Invoke-WebRequest -Uri "https://$clusterName.azurehdinsight.cn/api/v1/clusters/$clusterName/services/HDFS/components/NAMENODE" `
    -Credential $creds -UseBasicParsing
$respObj = ConvertFrom-Json $resp.Content
$respObj.host_components.HostRoles.host_name

辅助角色节点Worker nodes

curl -u admin:$password -sS -G "https://$clusterName.azurehdinsight.cn/api/v1/clusters/$clusterName/services/HDFS/components/DATANODE" \
| jq '.host_components[].HostRoles.host_name'
$resp = Invoke-WebRequest -Uri "https://$clusterName.azurehdinsight.cn/api/v1/clusters/$clusterName/services/HDFS/components/DATANODE" `
    -Credential $creds -UseBasicParsing
$respObj = ConvertFrom-Json $resp.Content
$respObj.host_components.HostRoles.host_name

Zookeeper 节点Zookeeper nodes

curl -u admin:$password -sS -G "https://$clusterName.azurehdinsight.cn/api/v1/clusters/$clusterName/services/ZOOKEEPER/components/ZOOKEEPER_SERVER" \
| jq ".host_components[].HostRoles.host_name"
$resp = Invoke-WebRequest -Uri "https://$clusterName.azurehdinsight.cn/api/v1/clusters/$clusterName/services/ZOOKEEPER/components/ZOOKEEPER_SERVER" `
    -Credential $creds -UseBasicParsing
$respObj = ConvertFrom-Json $resp.Content
$respObj.host_components.HostRoles.host_name

获取群集节点的内部 IP 地址Get the internal IP address of cluster nodes

本部分中的示例所返回的 IP 地址不可直接通过 Internet 进行访问。The IP addresses returned by the examples in this section are not directly accessible over the internet. 仅可在包含 HDInsight 群集的 Azure 虚拟网络内部对其进行访问。They are only accessible within the Azure Virtual Network that contains the HDInsight cluster.

有关将 HDInsight 与虚拟网络配合使用的详细信息,请参阅使用 Azure 虚拟网络扩展 HDInsight 功能For more information on working with HDInsight and virtual networks, see Extend HDInsight capabilities by using a custom Azure Virtual Network.

要查找 IP 地址,必须知道群集节点的内部完全限定的域名 (FQDN)。To find the IP address, you must know the internal fully qualified domain name (FQDN) of the cluster nodes. 拥有 FQDN 后即可获取主机的 IP 地址。Once you have the FQDN, you can then get the IP address of the host. 下面的示例首先会向 Ambari 查询所有主机节点的 FQDN,再向 Ambari 查询每个主机的 IP 地址。The following examples first query Ambari for the FQDN of all the host nodes, then query Ambari for the IP address of each host.

for HOSTNAME in $(curl -u admin:$password -sS -G "https://$clusterName.azurehdinsight.cn/api/v1/clusters/$clusterName/hosts" | jq -r '.items[].Hosts.host_name')
do
    IP=$(curl -u admin:$password -sS -G "https://$clusterName.azurehdinsight.cn/api/v1/clusters/$clusterName/hosts/$HOSTNAME" | jq -r '.Hosts.ip')
  echo "$HOSTNAME <--> $IP"
done
$uri = "https://$clusterName.azurehdinsight.cn/api/v1/clusters/$clusterName/hosts" 
$resp = Invoke-WebRequest -Uri $uri -Credential $creds -UseBasicParsing
$respObj = ConvertFrom-Json $resp.Content
foreach($item in $respObj.items) {
    $hostName = [string]$item.Hosts.host_name
    $hostInfoResp = Invoke-WebRequest -Uri "$uri/$hostName" `
        -Credential $creds -UseBasicParsing
    $hostInfoObj = ConvertFrom-Json $hostInfoResp 
    $hostIp = $hostInfoObj.Hosts.ip
    "$hostName <--> $hostIp"
}

获取默认存储Get the default storage

创建 HDInsight 群集时,必须使用 Azure 存储帐户或 Data Lake Storage 作为群集的默认存储。When you create an HDInsight cluster, you must use an Azure Storage Account or Data Lake Storage as the default storage for the cluster. 创建群集后,可以使用 Ambari 来检索此信息。You can use Ambari to retrieve this information after the cluster has been created. 例如,如果要从 HDInsight 外部的容器读取数据或向其写入数据。For example, if you want to read/write data to the container outside HDInsight.

以下示例检索群集的默认存储配置:The following examples retrieve the default storage configuration from the cluster:

curl -u admin:$password -sS -G "https://$clusterName.azurehdinsight.cn/api/v1/clusters/$clusterName/configurations/service_config_versions?service_name=HDFS&service_config_version=1" \
| jq '.items[].configurations[].properties["fs.defaultFS"] | select(. != null)'
$resp = Invoke-WebRequest -Uri "https://$clusterName.azurehdinsight.cn/api/v1/clusters/$clusterName/configurations/service_config_versions?service_name=HDFS&service_config_version=1" `
    -Credential $creds -UseBasicParsing
$respObj = ConvertFrom-Json $resp.Content
$respObj.items.configurations.properties.'fs.defaultFS'

Important

这些示例将返回应用于服务器的第一个配置 (service_config_version=1),其中包含此信息。These examples return the first configuration applied to the server (service_config_version=1) which contains this information. 如果要检索创建群集后修改的值,可能需要列出配置版本并检索最新版本。If you retrieve a value that has been modified after cluster creation, you may need to list the configuration versions and retrieve the latest one.

返回值类似于以下其中一个示例:The return value is similar to one of the following examples:

  • wasb://CONTAINER@ACCOUNTNAME.blob.core.windows.net - 此值指示群集正在将 Azure 存储帐户用于默认存储。- This value indicates that the cluster is using an Azure Storage account for default storage. ACCOUNTNAME 是存储帐户的名称。The ACCOUNTNAME value is the name of the storage account. CONTAINER 部分是存储帐户中 Blob 容器的名称。The CONTAINER portion is the name of the blob container in the storage account. 容器是群集的 HDFS 兼容存储的根。The container is the root of the HDFS compatible storage for the cluster.

  • abfs://CONTAINER@ACCOUNTNAME.dfs.core.windows.net - 此值表示群集使用 Azure Data Lake Storage Gen2 作为默认存储。- This value indicates that the cluster is using Azure Data Lake Storage Gen2 for default storage. ACCOUNTNAMECONTAINER 值对于前面提到的 Azure 存储而言意义相同。The ACCOUNTNAME and CONTAINER values have the same meanings as for Azure Storage mentioned previously.

  • adl://home - 此值表示群集使用 Azure Data Lake Storage Gen1 作为默认存储。- This value indicates that the cluster is using Azure Data Lake Storage Gen1 for default storage.

    若要查找 Data Lake Storage 帐户名称,请使用以下示例:To find the Data Lake Storage account name, use the following examples:

    curl -u admin:$password -sS -G "https://$clusterName.azurehdinsight.cn/api/v1/clusters/$clusterName/configurations/service_config_versions?service_name=HDFS&service_config_version=1" \
    | jq '.items[].configurations[].properties["dfs.adls.home.hostname"] | select(. != null)'
    
    $resp = Invoke-WebRequest -Uri "https://$clusterName.azurehdinsight.cn/api/v1/clusters/$clusterName/configurations/service_config_versions?service_name=HDFS&service_config_version=1" `
        -Credential $creds -UseBasicParsing
    $respObj = ConvertFrom-Json $resp.Content
    $respObj.items.configurations.properties.'dfs.adls.home.hostname'
    

    返回值类似于 ACCOUNTNAME.azuredatalakestore.net,其中,ACCOUNTNAME 是 Data Lake Storage 帐户的名称。The return value is similar to ACCOUNTNAME.azuredatalakestore.net, where ACCOUNTNAME is the name of the Data Lake Storage account.

    若要查找 Data Lake Storage 中包含群集存储的目录,请使用以下示例:To find the directory within Data Lake Storage that contains the storage for the cluster, use the following examples:

    curl -u admin:$password -sS -G "https://$clusterName.azurehdinsight.cn/api/v1/clusters/$clusterName/configurations/service_config_versions?service_name=HDFS&service_config_version=1" \
    | jq '.items[].configurations[].properties["dfs.adls.home.mountpoint"] | select(. != null)'
    
    $resp = Invoke-WebRequest -Uri "https://$clusterName.azurehdinsight.cn/api/v1/clusters/$clusterName/configurations/service_config_versions?service_name=HDFS&service_config_version=1" `
        -Credential $creds -UseBasicParsing
    $respObj = ConvertFrom-Json $resp.Content
    $respObj.items.configurations.properties.'dfs.adls.home.mountpoint'
    

    返回值类似于 /clusters/CLUSTERNAME/The return value is similar to /clusters/CLUSTERNAME/. 此值是 Data Lake Storage 帐户中的一个路径。This value is a path within the Data Lake Storage account. 此路径是群集的 HDFS 兼容文件系统的根目录。This path is the root of the HDFS compatible file system for the cluster.

Note

Azure PowerShell 提供的 Get-AzHDInsightCluster cmdlet 也返回群集的存储信息。The Get-AzHDInsightCluster cmdlet provided by Azure PowerShell also returns the storage information for the cluster.

获取所有配置Get all configurations

获取可用于群集的配置。Get the configurations that are available for your cluster.

curl -u admin:$password -sS -G "https://$clusterName.azurehdinsight.cn/api/v1/clusters/$clusterName?fields=Clusters/desired_configs"
$respObj = Invoke-WebRequest -Uri "https://$clusterName.azurehdinsight.cn/api/v1/clusters/$clusterName`?fields=Clusters/desired_configs" `
    -Credential $creds -UseBasicParsing
$respObj.Content

此示例将返回一个 JSON 文档,其中包含群集上安装的组件的当前配置(由 tag 值标识)。This example returns a JSON document containing the current configuration (identified by the tag value) for the components installed on the cluster. 下面的示例是从 Spark 群集类型返回的数据摘录。The following example is an excerpt from the data returned from a Spark cluster type.

"jupyter-site" : {
  "tag" : "INITIAL",
  "version" : 1
},
"livy2-client-conf" : {
  "tag" : "INITIAL",
  "version" : 1
},
"livy2-conf" : {
  "tag" : "INITIAL",
  "version" : 1
},

获取特定组件的配置Get configuration for specific component

获取你感兴趣的组件的配置。Get the configuration for the component that you are interested in. 在以下示例中,将 INITIAL 替换为从上一请求返回的标记值。In the following example, replace INITIAL with the tag value returned from the previous request.

curl -u admin:$password -sS -G "https://$clusterName.azurehdinsight.cn/api/v1/clusters/$clusterName/configurations?type=livy2-conf&tag=INITIAL"
$resp = Invoke-WebRequest -Uri "https://$clusterName.azurehdinsight.cn/api/v1/clusters/$clusterName/configurations?type=livy2-conf&tag=INITIAL" `
    -Credential $creds -UseBasicParsing
$resp.Content

此示例返回的 JSON 文档包含 livy2-conf 组件的当前配置。This example returns a JSON document containing the current configuration for the livy2-conf component.

更新配置Update configuration

  1. 创建 newconfig.jsonCreate newconfig.json.
    进行修改,然后输入以下命令:Modify, and then enter the commands below:

    • 请将 livy2-conf 替换为所需的组件。Replace livy2-conf with the desired component.

    • 请将 INITIAL 替换为在获取所有配置中检索到的 tag 实际值。Replace INITIAL with actual value retrieved for tag from Get all configurations.

      A.A. BashBash

      curl -u admin:$password -sS -G "https://$clusterName.azurehdinsight.cn/api/v1/clusters/$clusterName/configurations?type=livy2-conf&tag=INITIAL" \
      | jq --arg newtag $(echo version$(date +%s%N)) '.items[] | del(.href, .version, .Config) | .tag |= $newtag | {"Clusters": {"desired_config": .}}' > newconfig.json
      
      

      B.B. powershellpowershell
      PowerShell 脚本使用 jqThe PowerShell script uses jq. 编辑以下 C:\HD\jq\jq-win64,以反映 jq 的实际路径和版本。Edit C:\HD\jq\jq-win64 below to reflect your actual path and version of jq.

      $epoch = Get-Date -Year 1970 -Month 1 -Day 1 -Hour 0 -Minute 0 -Second 0
      $now = Get-Date
      $unixTimeStamp = [math]::truncate($now.ToUniversalTime().Subtract($epoch).TotalMilliSeconds)
      $resp = Invoke-WebRequest -Uri "https://$clusterName.azurehdinsight.cn/api/v1/clusters/$clusterName/configurations?type=livy2-conf&tag=INITIAL" `
        -Credential $creds -UseBasicParsing
      $resp.Content | C:\HD\jq\jq-win64 --arg newtag "version$unixTimeStamp" '.items[] | del(.href, .version, .Config) | .tag |= $newtag | {"Clusters": {"desired_config": .}}' > newconfig.json
      

      Jq 用于将从 HDInsight 中检索的数据转换成新的配置模板。Jq is used to turn the data retrieved from HDInsight into a new configuration template. 具体而言,这些示例会执行以下操作:Specifically, these examples perform the following actions:

    • 创建一个包含字符串“version”和日期并存储在 newtag中的唯一值。Creates a unique value containing the string "version" and the date, which is stored in newtag.

    • 为新的所需配置创建根文档。Creates a root document for the new desired configuration.

    • 获取 .items[] 数组的内容,并将其添加在 desired_config 元素下。Gets the contents of the .items[] array and adds it under the desired_config element.

    • 删除 hrefversionConfig 元素,因为提交新配置时不需要这些元素。Deletes the href, version, and Config elements, as these elements aren't needed to submit a new configuration.

    • 添加一个值为 version#################tag 元素。Adds a tag element with a value of version#################. 数字部分基于当前日期。The numeric portion is based on the current date. 每个配置必须有唯一的标记。Each configuration must have a unique tag.

      最后,数据将保存到 newconfig.json 文档。Finally, the data is saved to the newconfig.json document. 该文档结构类似于下面的示例:The document structure should appear similar to the following example:

      {
        "Clusters": {
          "desired_config": {
            "tag": "version1552064778014",
            "type": "livy2-conf",
            "properties": {
              "livy.environment": "production",
              "livy.impersonation.enabled": "true",
              "livy.repl.enableHiveContext": "true",
              "livy.server.csrf_protection.enabled": "true",
                ....
            },
          },
        }
      }
      
  2. 编辑 newconfig.jsonEdit newconfig.json.
    打开 newconfig.json 文档并在 properties 对象中修改/添加值。Open the newconfig.json document and modify/add values in the properties object. 以下示例将 "livy.server.csrf_protection.enabled" 的值从 "true" 更改为 "false"The following example changes the value of "livy.server.csrf_protection.enabled" from "true" to "false".

     "livy.server.csrf_protection.enabled": "false",
    

    完成修改后,保存该文件。Save the file once you are done making modifications.

  3. 提交 newconfig.jsonSubmit newconfig.json.
    使用以下命令将更新的配置提交到 Ambari。Use the following commands to submit the updated configuration to Ambari.

    curl -u admin:$password -sS -H "X-Requested-By: ambari" -X PUT -d @newconfig.json "https://$clusterName.azurehdinsight.cn/api/v1/clusters/$clusterName"
    
    $newConfig = Get-Content .\newconfig.json
    $resp = Invoke-WebRequest -Uri "https://$clusterName.azurehdinsight.cn/api/v1/clusters/$clusterName" `
        -Credential $creds -UseBasicParsing `
        -Method PUT `
        -Headers @{"X-Requested-By" = "ambari"} `
        -Body $newConfig
    $resp.Content
    

    这些命令会将 newconfig.json 文件的内容提交到群集作为所需的新配置。These commands submit the contents of the newconfig.json file to the cluster as the new desired configuration. 该请求会返回一个 JSON 文档。The request returns a JSON document. 此文档中的 versionTag 元素应该与提交的版本相匹配,并且 configs 对象包含你请求的配置更改。The versionTag element in this document should match the version you submitted, and the configs object contains the configuration changes you requested.

重启服务组件Restart a service component

此时,如果查看 Ambari Web UI,会发现 Spark 服务指出需要将它重新启动才能使新配置生效。At this point, if you look at the Ambari web UI, the Spark service indicates that it needs to be restarted before the new configuration can take effect. 使用以下步骤重新启动该服务。Use the following steps to restart the service.

  1. 使用以下命令启用 Spark2 服务的维护模式:Use the following to enable maintenance mode for the Spark2 service:

    curl -u admin:$password -sS -H "X-Requested-By: ambari" \
    -X PUT -d '{"RequestInfo": {"context": "turning on maintenance mode for SPARK2"},"Body": {"ServiceInfo": {"maintenance_state":"ON"}}}' \
    "https://$clusterName.azurehdinsight.cn/api/v1/clusters/$clusterName/services/SPARK2"
    
    $resp = Invoke-WebRequest -Uri "https://$clusterName.azurehdinsight.cn/api/v1/clusters/$clusterName/services/SPARK2" `
        -Credential $creds -UseBasicParsing `
        -Method PUT `
        -Headers @{"X-Requested-By" = "ambari"} `
        -Body '{"RequestInfo": {"context": "turning on maintenance mode for SPARK2"},"Body": {"ServiceInfo": {"maintenance_state":"ON"}}}'
    $resp.Content
    
  2. 验证维护模式Verify maintenance mode

    这些命令将 JSON 文档发送到启用了维护模式的服务器。These commands send a JSON document to the server that turns on maintenance mode. 可以使用以下请求来验证服务当前是否处于维护模式:You can verify that the service is now in maintenance mode using the following request:

    curl -u admin:$password -sS -H "X-Requested-By: ambari" \
    "https://$clusterName.azurehdinsight.cn/api/v1/clusters/$clusterName/services/SPARK2" \
    | jq .ServiceInfo.maintenance_state
    
    $resp = Invoke-WebRequest -Uri "https://$clusterName.azurehdinsight.cn/api/v1/clusters/$clusterName/services/SPARK2" `
        -Credential $creds -UseBasicParsing
    $respObj = ConvertFrom-Json $resp.Content
    $respObj.ServiceInfo.maintenance_state
    

    返回值为 ONThe return value is ON.

  3. 接下来,使用以下命令关闭 Spark2 服务:Next, use the following to turn off the Spark2 service:

    curl -u admin:$password -sS -H "X-Requested-By: ambari" \
    -X PUT -d '{"RequestInfo":{"context":"_PARSE_.STOP.SPARK","operation_level":{"level":"SERVICE","cluster_name":"CLUSTERNAME","service_name":"SPARK"}},"Body":{"ServiceInfo":{"state":"INSTALLED"}}}' \
    "https://girouxSpark.azurehdinsight.cn/api/v1/clusters/girouxspark/services/SPARK2"
    
    $resp = Invoke-WebRequest -Uri "https://$clusterName.azurehdinsight.cn/api/v1/clusters/$clusterName/services/SPARK2" `
        -Credential $creds `
        -Method PUT `
        -Headers @{"X-Requested-By" = "ambari"} `
        -Body '{"RequestInfo":{"context":"_PARSE_.STOP.SPARK","operation_level":{"level":"SERVICE","cluster_name":"CLUSTERNAME","service_name":"SPARK"}},"Body":{"ServiceInfo":{"state":"INSTALLED"}}}'
    $resp.Content
    

    其响应类似于如下示例:The response is similar to the following example:

    {
        "href" : "http://10.0.0.18:8080/api/v1/clusters/CLUSTERNAME/requests/29",
        "Requests" : {
            "id" : 29,
            "status" : "Accepted"
        }
    }
    

    Important

    href 值正在使用群集节点的内部 IP 地址。The href value returned by this URI is using the internal IP address of the cluster node. 若要从群集外部使用该地址,请将“10.0.0.18:8080”部分替换为群集的 FQDN。To use it from outside the cluster, replace the `10.0.0.18:8080' portion with the FQDN of the cluster.

  4. 验证请求。Verify request.
    编辑以下命令,将 29 替换为上一步骤返回的 id 实际值。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:

    curl -u admin:$password -sS -H "X-Requested-By: ambari" \
    "https://$clusterName.azurehdinsight.cn/api/v1/clusters/$clusterName/requests/29" \
    | jq .Requests.request_status
    
    $resp = Invoke-WebRequest -Uri "https://$clusterName.azurehdinsight.cn/api/v1/clusters/$clusterName/requests/29" `
        -Credential $creds -UseBasicParsing
    $respObj = ConvertFrom-Json $resp.Content
    $respObj.Requests.request_status
    

    响应 COMPLETED 指示请求已完成。A response of COMPLETED indicates that the request has finished.

  5. 完成前一个请求后,使用以下命令启动 Spark2 服务。Once the previous request completes, use the following to start the Spark2 service.

    curl -u admin:$password -sS -H "X-Requested-By: ambari" \
    -X PUT -d '{"RequestInfo":{"context":"_PARSE_.STOP.SPARK","operation_level":{"level":"SERVICE","cluster_name":"CLUSTERNAME","service_name":"SPARK"}},"Body":{"ServiceInfo":{"state":"STARTED"}}}' \
    "https://$clusterName.azurehdinsight.cn/api/v1/clusters/$clusterName/services/SPARK2"
    
    $resp = Invoke-WebRequest -Uri "https://$clusterName.azurehdinsight.cn/api/v1/clusters/$clusterName/services/SPARK2" `
        -Credential $creds -UseBasicParsing `
        -Method PUT `
        -Headers @{"X-Requested-By" = "ambari"} `
        -Body '{"RequestInfo":{"context":"_PARSE_.STOP.SPARK","operation_level":{"level":"SERVICE","cluster_name":"CLUSTERNAME","service_name":"SPARK"}},"Body":{"ServiceInfo":{"state":"STARTED"}}}'
    

    服务现在正在使用新配置。The service is now using the new configuration.

  6. 最后,使用以下命令关闭维护模式。Finally, use the following to turn off maintenance mode.

    curl -u admin:$password -sS -H "X-Requested-By: ambari" \
    -X PUT -d '{"RequestInfo": {"context": "turning off maintenance mode for SPARK2"},"Body": {"ServiceInfo": {"maintenance_state":"OFF"}}}' \
    "https://$clusterName.azurehdinsight.cn/api/v1/clusters/$clusterName/services/SPARK2"
    
    $resp = Invoke-WebRequest -Uri "https://$clusterName.azurehdinsight.cn/api/v1/clusters/$clusterName/services/SPARK2" `
        -Credential $creds -UseBasicParsing `
        -Method PUT `
        -Headers @{"X-Requested-By" = "ambari"} `
        -Body '{"RequestInfo": {"context": "turning off maintenance mode for SPARK2"},"Body": {"ServiceInfo": {"maintenance_state":"OFF"}}}'
    
    

后续步骤Next steps

有关 REST API 的完整参考,请参阅 Apache Ambari API 参考 V1For a complete reference of the REST API, see Apache Ambari API Reference V1.