FIWARE LabのCosmosインスタンスから大きなファイル(最低14MB)をバックエンドに転送する必要があります。Hadoop WebHDFSでファイルのチャンクを読み込んで転送するにはどうすればよいですか?
HadoopのWebHDFS REST APIのクライアント・インタフェースがhereを説明したが、私はIO例外に遭遇すると、私は春RestTemplateを使用:
Exception in thread "main" org.springframework.web.client.ResourceAccessException: I/O error on GET request for "http://cosmos.lab.fiware.org:14000/webhdfs/v1/user/<user.name>/<path>?op=open&user.name=<user.name>":Truncated chunk (expected size: 14744230; actual size: 11285103); nested exception is org.apache.http.TruncatedChunkException: Truncated chunk (expected size: 14744230; actual size: 11285103)
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:580)
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:545)
at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:466)
これは、例外を生成し、実際のコードです:
RestTemplate restTemplate = new RestTemplate();
restTemplate.setRequestFactory(new HttpComponentsClientHttpRequestFactory());
restTemplate.getMessageConverters().add(new ByteArrayHttpMessageConverter());
HttpEntity<?> entity = new HttpEntity<>(headers);
UriComponentsBuilder builder =
UriComponentsBuilder.fromHttpUrl(hdfs_path)
.queryParam("op", "OPEN")
.queryParam("user.name", user_name);
ResponseEntity<byte[]> response =
restTemplate
.exchange(builder.build().encode().toUri(), HttpMethod.GET, entity, byte[].class);
FileOutputStream output = new FileOutputStream(new File(local_path));
IOUtils.write(response.getBody(), output);
output.close();
私はこれがCosmosインスタンスの転送タイムアウトに起因すると考えています。したがって、 はをパスにoffset, buffer and length
パラメータを指定して送信しようとしましたが、そのように見えます無視される:私はファイル全体を得た。
ありがとうございます。
py webhdfsを見てみると、いくつかの手がかりを得ることができます - > https://github.com/pywebhdfs/pywebhdfs/blob/master/pywebhdfs/webhdfs.py#L48 – ravwojdyla
ありがとうございますが、助けになりません。問題は、OPEN操作のオプションの長さパラメータ(リンク内の 'def read_file(self、path、** kwargs)'を参照)がサーバーによって完全に無視されることです –