サンプルコード
@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.240" // replace this def port = 7180 def user = "admin" def password = "admin" def clusterName = "cluster" def serviceName = "hive" def httpclient = new DefaultHttpClient() httpclient.withCloseable { httpclient.getCredentialsProvider().setCredentials( new AuthScope(host, port), new UsernamePasswordCredentials(user, password) ) def cluster = "/api/v7/clusters/${clusterName}" def method = new HttpPost( "http://${host}:${port}${cluster}/services/${serviceName}/commands/start" ) def response = httpclient.execute(method) println response.getStatusLine().getStatusCode() def json = new JsonSlurper().parseText(response.getEntity().getContent().text) println json }動作環境
Apache Ambari 1.6.1, HDP2.1, groovy 2.3.2
0 件のコメント:
コメントを投稿