Ambari REST API 사용
    • PDF

    Ambari REST API 사용

    • PDF

    Article Summary

    Apache Ambari는 손쉬운 Web UI 및 REST API를 제공하여 Hadoop 클러스터 관리 및 모니터링을 간소화합니다. 이 가이드에서는 Ambari REST API를 사용하는 방법에 대해 설명합니다. Ambari REST API의 더 자세한 정보는 Ambari API 참조 v1을 참고해 주십시오.

    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.fin-ntruss.com:8080/api/v1/clusters/test-spark"
    

    위 클러스터 정보를 사용하여 REST API를 실행하면 아래와 같은 JSON 문서가 반환됩니다.

    # curl 수행
    curl -u obj -G "http://pub-68u67.hadoop.fin-ntruss.com:8080/api/v1/clusters/test-spark"
    {
      "href" : "http://pub-68u67.hadoop.fin-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를 이용하여 REST API 결과로 반환되는 JSON 문서를 일부 필터링하거나 변환할 수 있습니다. 아래는 jq를 통해 JSON 결과 중 Clusters의 health_report 정보만 필터링하는 예입니다.

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

    마스터 노드 FQDN 구하기

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