サンプルプログラム
@Grab(group='org.apache.httpcomponents', module='httpclient', version='4.3.5') @Grab(group='org.apache.httpcomponents', module='httpmime', 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.mime.* import org.apache.http.protocol.* import groovy.json.* def host = "192.168.206.132" // replace this def port = 50070 def path = "/user/hadoop25b" def user = "hadoop25b" def file = "03_2012.csv" def context = new BasicHttpContext() def httpclient = new DefaultHttpClient() def datanode httpclient.withCloseable { def method = new HttpPut("http://${host}:${port}/webhdfs/v1${path}/${file}?op=CREATE&user.name=${user}") def response = httpclient.execute(method, context) println response.getStatusLine().getStatusCode() datanode = response.getHeaders("Location")[0].value println "DN:" + datanode } httpclient = new DefaultHttpClient() httpclient.withCloseable { method = new HttpPut("${datanode}") def builder = MultipartEntityBuilder.create() builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE) builder.addBinaryBody("file", new File(file)) method.setEntity(builder.build()) response = httpclient.execute(method) println response.getStatusLine().getStatusCode() }動作環境
Hadoop 2.5.0
0 件のコメント:
コメントを投稿