サンプルコード
@Grab(group='org.apache.httpcomponents', module='httpclient', version='4.3.5') import org.apache.http.client.methods.* import org.apache.http.impl.client.* import org.apache.http.message.* import org.apache.http.auth.* import groovy.json.* def host = "192.168.1.249" // replace this def port = 8080 def user = "admin" def password = "admin" def cluster = "cluster1" def httpclient = new DefaultHttpClient() httpclient.withCloseable { def method = new HttpGet( "http://${user}:${password}@${host}:${port}/api/v1/clusters/${cluster}/services?fields=ServiceInfo/state" ) def response = httpclient.execute(method) println response.getStatusLine().getStatusCode() def json = new JsonSlurper().parseText(response.getEntity().getContent().text) for(item in json.items){ println "service name:${item.ServiceInfo.service_name}" println "state:${item.ServiceInfo.state}" println "href:${item.href}" } }動作環境
Apache Ambari 1.6.1, HDP2.1, groovy 2.3.2
0 件のコメント:
コメントを投稿