在研究如何修改YARN的资源池的时候,发现了Hortwork在github上面开源了一个Ambari Client;
不过使用groovy写的;但是没关系,在pom文件中添加了两个依赖之后,mvn package即可(groovy会编译生成jar文件)。不过我是把真个ambari的工程都下载到了本地;如果单独下载一个client,是否能够编译打包并没有尝试。
1 <dependency> 2 <groupId>org.codehaus.groovy</groupId> 3 <artifactId>groovy-eclipse-compiler</artifactId> 4 <version>2.9.2-01</version> 5 <type>maven-plugin</type> 6 </dependency> 7 <dependency> 8 <groupId>org.codehaus.groovy</groupId> 9 <artifactId>groovy-eclipse-batch</artifactId> 10 <version>2.4.3-01</version> 11 </dependenc>
java代码如下,我是尝试访问了一下yarn的schedule属性(资源池)。
1 AmbariClient aClient = new AmbariClient("10.1.108.45", "8080", "admin", "admin"); 2 String typeName = "capacity-scheduler"; 3 String propertieName = "yarn.scheduler.capacity.root.unfunded.capacity"; 4 Map<String, Map<String, String>> map = aClient.getServiceConfigMap(typeName); 5 for (String key : map.keySet()) { 6 System.out.println("key: " + key + ";"); 7 Map<String, String> kvs = map.get(key); 8 for (String name : kvs.keySet()) { 9 if (name.equals(propertieName)) { 10 System.out.println("name: " + name + "; value: " + kvs.get(name)); 11 } 12 } 13 } 14 15 Map<String, String> mapUpdate = new HashMap<String, String>(); 16 17 mapUpdate.put(propertieName, "55"); 18 aClient.modifyConfiguration(typeName, mapUpdate);