Ho bisogno di trasferire file di grandi dimensioni (almeno 14 MB) dall'istanza Cosmos di FIWARE Lab al mio back-end.Come posso leggere e trasferire blocchi di file con Hadoop WebHDFS?
ho usato primavera RestTemplate come interfaccia client per il Hadoop WebHDFS REST API descritti here ma corro in un'eccezione 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)
Questo è il codice che genera l'eccezione:
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();
Penso che questo sia dovuto a un timeout di trasferimento sull'istanza Cosmos, quindi ho provato a inviare un curl
sul percorso specificando i parametri offset, buffer and length
, ma sembrano essere ignorato: ho ottenuto l'intero file.
Grazie in anticipo.
Forse guardando py webhdfs vi darà alcuni indizi -> https://github.com/pywebhdfs/pywebhdfs/blob/master/pywebhdfs/webhdfs.py#L48 – ravwojdyla
Grazie, ma non aiuta. Il problema è che il parametro di lunghezza opzionale dell'operazione OPEN (vedi 'def read_file (self, path, ** kwargs)' nel tuo link) è totalmente ignorato dal server –