--- title: "Ambari REST API を使用する" slug: "hadoop-chadoop-3-9" updated: 2026-09-17T09:25:49Z published: 2026-09-17T09:25:49Z canonical: "guide.ncloud-docs.com/hadoop-chadoop-3-9" stale: true --- > ## Documentation Index > Fetch the complete documentation index at: https://guide.ncloud-docs.com/llms.txt > Use this file to discover all available pages before exploring further. # Ambari REST API を使用する Classic環境で利用できます。 Apache Ambariは、簡単なウェブUIとREST APIを提供してHadoopクラスタの管理とモニタリングを簡素化します。 このガイドでは、Ambari REST APIの使用方法について説明します。 Ambari REST APIの詳細情報は、[Ambari APIリファレンスv1](https://github.com/apache/ambari/blob/trunk/ambari-server/docs/api/v1/index.md)をご参照ください。 ## Ambari REST APIのURI作成 以下のようにAmbari REST APIのURIを作成します。 - `AMBARI-ADDRESS`:グローバルIPまたはPublicドメインを入力 - `CLUSTER-NAME`:クラスタの名前(クラスタ名は大文字・小文字を区分するため、確認が必要) ``` http://:8080/api/v1/clusters/ ``` ## Ambari REST APIのリクエスト cURLを用いてAmbari REST APIにGETリクエストを行います。 - `example`/`pass123!@#`:Ambariの管理者アカウント ``` curl -u "example:pass123!@#" -G "http://pub-68u67.hadoop.ntruss.com:8080/api/v1/clusters/test-spark" ``` 上記のクラスタ情報を用いてREST APIを実行すると、以下のJSON文書が返されます。 ``` # cURLの実行 curl -u obj -G "http://pub-68u67.hadoop.ntruss.com:8080/api/v1/clusters/test-spark" { "href" : "http://pub-68u67.hadoop.ntruss.com:8080/api/v1/clusters/test-spark", "Clusters" : { "cluster_id" : 2, "cluster_name" : "SPARK", "health_report" : { "Host/stale_config" : 0, "Host/maintenance_state" : 0, "Host/host_state/HEALTHY" : 3, "Host/host_state/UNHEALTHY" : 0, "Host/host_state/HEARTBEAT_LOST" : 0, "Host/host_state/INIT" : 0, "Host/host_status/HEALTHY" : 3, "Host/host_status/UNHEALTHY" : 0, "Host/host_status/UNKNOWN" : 0, "Host/host_status/ALERT" : 0 .... ``` ## jqコマンドによる戻り値のパース [jq](https://stedolan.github.io/jq/)を用い、REST APIの結果として返されるJSON文書を一部フィルタリングするか、変換することができます。 以下は、jqを用いてJSON結果の中でClustersの`health_report`情報だけフィルタリングする例です。 ``` curl -u "example:pass123!@#" -G "http://pub-68u67.hadoop.ntruss.com:8080/api/v1/clusters/test-spark" | jq ".Clusters.health_report" { "Host/stale_config": 0, "Host/maintenance_state": 0, "Host/host_state/HEALTHY": 4, "Host/host_state/UNHEALTHY": 0, "Host/host_state/HEARTBEAT_LOST": 0, "Host/host_state/INIT": 0, "Host/host_status/HEALTHY": 4, "Host/host_status/UNHEALTHY": 0, "Host/host_status/UNKNOWN": 0, "Host/host_status/ALERT": 0 } ``` ## 使用例 ### すべてのノードのFQDN(完全修飾ドメイン名)の特定 ``` curl -u "example:pass123!@#" -G "http://pub-68u67.hadoop.ntruss.com:8080/api/v1/clusters/test-spark/hosts" | jq ".items[].Hosts.host_name" ``` ### マスターノードのFQDNの特定 ``` curl -u "example:pass123!@#" -G "http://pub-68u67.hadoop.ntruss.com:8080/api/v1/clusters/test-spark/services/HDFS/components/NAMENODE" | jq ".host_components[].HostRoles.host_name" ``` ### ワーカーノードのFQDNの特定 ``` curl -u "example:pass123!@#" -G "http://pub-68u67.hadoop.ntruss.com:8080/api/v1/clusters/test-spark/services/HDFS/components/DATANODE" | jq ".host_components[].HostRoles.host_name" ``` ### クラスタノード内部のIPアドレスの特定 IPアドレスを特定するには、クラスタノード内部のFQDNが必要です。 先にAmbariにクエリしてホストノードのFQDNを取得し、再びAmbariにクエリして各ホストのIPアドレスを取得します。 ``` curl -u "example:pass123!@#" -G "http://pub-68u67.hadoop.ntruss.com:8080/api/v1/clusters/test-spark/hosts/d-002-test-spark-36m-hd" | jq ".Hosts.ip" ``` ### default.FSの特定 Cloud Hadoopは、デフォルトの保存場所としてObject Storageを使用しており、APIの結果値は`hdfs://<クラスタ名(namespace名)>`で返されます。 ``` curl -u "example:pass123!@#" -G "http://pub-68u67.hadoop.ntruss.com:8080/api/v1/clusters/test-spark/configurations/service_config_versions?service_name=HDFS&service_config_version=1" | jq ".items[].configurations[].properties["fs.defaultFS"] | select(. != null)" ```