サンプルコード
@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 org.apache.http.entity.* import groovy.json.* def host = "192.168.1.249" // replace this def port = 8080 def user = "admin" def password = "admin" def cluster = "cluster1" def service = "HIVE" def httpclient = new DefaultHttpClient() httpclient.withCloseable { def method = new HttpPut( "http://${user}:${password}@${host}:${port}/api/v1/clusters/${cluster}/services/${service}" ) println method def json = new JsonBuilder() json ( ["Body":[ServiceInfo:[ "state":"INSTALLED" ]]] ) println json method.setHeader("content-Type", "application/x-www-form-urlencoded") method.setHeader("X-Requested-By", "ambari") method.setEntity(new StringEntity(json.toString(), "UTF-8")) def response = httpclient.execute(method) println response.getStatusLine().getStatusCode() def rj = new JsonSlurper().parseText(response.getEntity().getContent().text) println rj }動作環境
Apache Ambari 1.6.1, HDP2.1, groovy 2.3.2
0 件のコメント:
コメントを投稿