Tôi cần chuyển các tệp lớn (ít nhất 14MB) từ trường hợp Cosmos của Phòng thí nghiệm FIWARE sang chương trình phụ trợ của tôi.Làm thế nào tôi có thể đọc và chuyển các khối tệp bằng Hadoop WebHDFS?
tôi đã sử dụng RestTemplate mùa xuân như một giao diện khách hàng cho Hadoop WebHDFS REST API được mô tả here nhưng tôi chạy vào một ngoại lệ IO:
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)
Đây là mã thực tế mà tạo ra những ngoại lệ:
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();
Tôi nghĩ rằng điều này là do thời gian chờ truyền trên phiên bản Cosmos, vì vậy tôi đã cố gắng gửi curl
trên đường dẫn bằng cách chỉ định các thông số offset, buffer and length
, nhưng chúng dường như bị bỏ qua: Tôi có toàn bộ tập tin.
Xin cảm ơn trước.
Có thể nhìn vào py webhdfs sẽ cung cấp cho bạn một số manh mối -> https://github.com/pywebhdfs/pywebhdfs/blob/master/pywebhdfs/webhdfs.py#L48 – ravwojdyla
Cảm ơn, nhưng nó không giúp ích gì. Vấn đề là tham số chiều dài tùy chọn của hoạt động OPEN (xem 'def read_file (tự, đường dẫn, ** kwargs)' trong liên kết của bạn) hoàn toàn bị bỏ qua bởi máy chủ –