Ambari REST API を使用する
    • PDF

    Ambari REST API を使用する

    • PDF

    Article Summary

    VPC環境で利用できます。

    Apache Ambariは、シンプルなウェブUIとREST APIを提供してHadoopクラスタの管理とモニタリングを簡素化します。このガイドでは、Ambari REST APIの使用方法について説明します。Ambari REST APIの詳細情報は、Ambari APIリファレンスv1をご参照ください。

    Ambari REST APIのURI作成

    次のようにAmbari REST APIのURIを作成してください。

    リクエストを送る環境に応じて、以下のようにAmbari REST APIのURIを作成してください。

    • AMBARI-ADDRESS: クラスタに割り当てられたドメインアドレスの入力
    • CLUSTER-NAME: クラスタ名(クラスタ名は大文字と小文字を区別するため、必ず確認が必要)
    http://<AMBARI-ADDRESS>:8080/api/v1/clusters/<CLUSTER-NAME>
    

    Ambari REST APIのリクエスト

    curlを用いてAmbari REST APIにGETリクエストを行ってください。

    • example/pass123!@#:Ambariの管理者アカウント
    curl -u "example:pass123!@#" -G "http://pub-68u67.hadoop.ntruss.com:8443/api/v1/clusters/test-spark"
    

    上記のクラスタ情報を用いてREST APIを実行すると、以下のJSON文書が返されます。

    # curlの実行
    curl -u obj -G "http://pub-68u67.hadoop.ntruss.com:8443/api/v1/clusters/test-spark"
    {
      "href" : "http://pub-68u67.hadoop.ntruss.com:8443/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を用い、REST APIの結果として返されるJSON文書を一部フィルタリングするか、変換することができます。以下は、jqを用いてJSON結果のうちClustersのhealth_report情報だけフィルタリングする例です。

    curl -u "example:pass123!@#" -G "http://pub-68u67.hadoop.ntruss.com:8443/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:8443/api/v1/clusters/test-spark/hosts" | jq ".items[].Hosts.host_name"
    

    マスターノードのFQDNの特定

    curl -u "example:pass123!@#" -G "http://pub-68u67.hadoop.ntruss.com:8443/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:8443/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:8443/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)"
    

    この記事は役に立ちましたか?

    Changing your password will log you out immediately. Use the new password to log back in.
    First name must have atleast 2 characters. Numbers and special characters are not allowed.
    Last name must have atleast 1 characters. Numbers and special characters are not allowed.
    Enter a valid email
    Enter a valid password
    Your profile has been successfully updated.