通过API访问Ambari的配置
1 HttpClient client = new HttpClient(); 2 Base64.Encoder encoder = Base64.getEncoder(); 3 HttpMethod method = new GetMethod("http://hdp0:8080/api/v1/clusters/HDP/configurations"); 4 method.addRequestHeader("Authorization", 5 "Basic " + encoder.encodeToString("admin:admin".getBytes("iso-8859-1"))); 6 method.addRequestHeader("X-Requested-By", "ambari"); 7 client.executeMethod(method);
8 // 获取YARN的capacity-scheduler属性信息 9 AmbariClient aClient = new AmbariClient("10.1.108.45", "8080", "admin", "admin"); 10 String typeName = "capacity-scheduler"; 11 String propertieName = "yarn.scheduler.capacity.root.unfunded.capacity"; 12 Map<String, Map<String, String>> map = aClient.getServiceConfigMap(typeName); 13 for (String key : map.keySet()) { 14 System.out.println("key: " + key + ";"); 15 Map<String, String> kvs = map.get(key); 16 for (String name : kvs.keySet()) { 17 if (name.equals(propertieName)) { 18 System.out.println("name: " + name + "; value: " + kvs.get(name)); 19 } 20 } 21 } 22 // 修改配置信息 23 Map<String, String> mapUpdate = new HashMap<String, String>(); 24 25 mapUpdate.put(propertieName, "55"); 26 aClient.modifyConfiguration(typeName, mapUpdate); 27 28 map = aClient.getServiceConfigMap(typeName); 29 for (String key : map.keySet()) { 30 System.out.println("key: " + key + ";"); 31 Map<String, String> kvs = map.get(key); 32 for (String name : kvs.keySet()) { 33 if (name.equals(propertieName)) { 34 System.out.println("name: " + name + "; value: " + kvs.get(name)); 35 } 36 } 37 }
Ambari所有的服务的组件列表:
{"service_name":"HDFS","component_name":"DATANODE","hosts":"c6401.ambari.apache.org"},
{"service_name":"HDFS","component_name":"HDFS_CLIENT","hosts":"c6401.ambari.apache.org"},
{"service_name":"HDFS","component_name":"NAMENODE","hosts":"c6401.ambari.apache.org"},
{"service_name":"HDFS","component_name":"SECONDARY_NAMENODE","hosts":"c6401.ambari.apache.org"},
{"service_name":"HIVE","component_name":"HCAT","hosts":"c6401.ambari.apache.org"},
{"service_name":"HIVE","component_name":"HIVE_CLIENT","hosts":"c6401.ambari.apache.org"},
{"service_name":"HIVE","component_name":"HIVE_METASTORE","hosts":"c6401.ambari.apache.org"},
{"service_name":"HIVE","component_name":"HIVE_SERVER","hosts":"c6401.ambari.apache.org"},
{"service_name":"HIVE","component_name":"MYSQL_SERVER","hosts":"c6401.ambari.apache.org"},
{"service_name":"HIVE","component_name":"WEBHCAT_SERVER","hosts":"c6401.ambari.apache.org"},
{"service_name":"YARN","component_name":"APP_TIMELINE_SERVER","hosts":"c6401.ambari.apache.org"},
{"service_name":"YARN","component_name":"NODEMANAGER","hosts":"c6401.ambari.apache.org"},
{"service_name":"YARN","component_name":"RESOURCEMANAGER","hosts":"c6401.ambari.apache.org"},
{"service_name":"YARN","component_name":"YARN_CLIENT","hosts":"c6401.ambari.apache.org"},
{"service_name":"MAPREDUCE2","component_name":"HISTORYSERVER","hosts":"c6401.ambari.apache.org"},
{"service_name":"MAPREDUCE2","component_name":"MAPREDUCE2_CLIENT","hosts":"c6401.ambari.apache.org"},
{"service_name":"AMBARI_METRICS","component_name":"METRICS_COLLECTOR","hosts":"c6401.ambari.apache.org"},
{"service_name":"AMBARI_METRICS","component_name":"METRICS_MONITOR","hosts":"c6401.ambari.apache.org"},
{"service_name":"PIG","component_name":"PIG","hosts":"c6401.ambari.apache.org"},
{"service_name":"TEZ","component_name":"TEZ_CLIENT","hosts":"c6401.ambari.apache.org"},
{"service_name":"ZOOKEEPER","component_name":"ZOOKEEPER_CLIENT","hosts":"c6401.ambari.apache.org"},
{"service_name":"ZOOKEEPER","component_name":"ZOOKEEPER_SERVER","hosts":"c6401.ambari.apache.org"}