Uploaded image for project: 'Help-Desk'
  1. Help-Desk
  2. HELP-9087

[fiware-stackoverflow] How can I Read and Transfer chunks of file with Hadoop WebHDFS?

    Details

      Description

      Created question in FIWARE Q/A platform on 28-11-2015 at 19:11
      Please, ANSWER this question AT https://stackoverflow.com/questions/33974754/how-can-i-read-and-transfer-chunks-of-file-with-hadoop-webhdfs

      Question:
      How can I Read and Transfer chunks of file with Hadoop WebHDFS?

      Description:
      I need to transfer big files (at least 14MB) from the Cosmos instance of the FIWARE Lab to my backend.

      I used the Spring RestTemplate as a client interface for the Hadoop WebHDFS REST API described here but I run into an IO Exception:

      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)

      This is the actual code that generates the Exception:

      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();

      I think this is due to a transfer timeout on the Cosmos instance, so I tried to
      send a curl on the path by specifying offset, buffer and length parameters, but they seem to be ignored: I got the whole file.

      Thanks in advance.

        Activity

        Transition Time In Source Status Execution Times Last Executer Last Execution Date
        Open Open In Progress In Progress
        2h 54m 1 Backlog Manager 22/May/17 6:10 PM
        In Progress In Progress Closed Closed
        3h 1 Backlog Manager 22/May/17 9:10 PM
        fla Fernando Lopez made changes -
        Fix Version/s 2021 [ 12600 ]
        fla Fernando Lopez made changes -
        Assignee Backlog Manager [ backlogmanager ]
        fla Fernando Lopez made changes -
        HD-Enabler Cosmos [ 10872 ]
        Description
        Created question in FIWARE Q/A platform on 28-11-2015 at 19:11
        {color: red}Please, ANSWER this question AT{color} https://stackoverflow.com/questions/33974754/how-can-i-read-and-transfer-chunks-of-file-with-hadoop-webhdfs


        +Question:+
        How can I Read and Transfer chunks of file with Hadoop WebHDFS?

        +Description:+
        I need to transfer big files (at least 14MB) from the Cosmos instance of the FIWARE Lab to my backend.

        I used the Spring RestTemplate as a client interface for the Hadoop WebHDFS REST API described here but I run into an IO Exception:

        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/&lt;user.name&gt;/&lt;path&gt;?op=open&amp;user.name=&lt;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)


        This is the actual code that generates the Exception:

        RestTemplate restTemplate = new RestTemplate();
        restTemplate.setRequestFactory(new HttpComponentsClientHttpRequestFactory());
        restTemplate.getMessageConverters().add(new ByteArrayHttpMessageConverter());
        HttpEntity&lt;?&gt; entity = new HttpEntity&lt;&gt;(headers);

        UriComponentsBuilder builder =
            UriComponentsBuilder.fromHttpUrl(hdfs_path)
                .queryParam("op", "OPEN")
                .queryParam("user.name", user_name);

        ResponseEntity&lt;byte[]&gt; 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();


        I think this is due to a transfer timeout on the Cosmos instance, so I tried to
        send a curl on the path by specifying offset, buffer and length parameters, but they seem to be ignored: I got the whole file.

        Thanks in advance.
        Created question in FIWARE Q/A platform on 28-11-2015 at 19:11
        {color: red}Please, ANSWER this question AT{color} https://stackoverflow.com/questions/33974754/how-can-i-read-and-transfer-chunks-of-file-with-hadoop-webhdfs


        +Question:+
        How can I Read and Transfer chunks of file with Hadoop WebHDFS?

        +Description:+
        I need to transfer big files (at least 14MB) from the Cosmos instance of the FIWARE Lab to my backend.

        I used the Spring RestTemplate as a client interface for the Hadoop WebHDFS REST API described here but I run into an IO Exception:

        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/&lt;user.name&gt;/&lt;path&gt;?op=open&amp;user.name=&lt;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)


        This is the actual code that generates the Exception:

        RestTemplate restTemplate = new RestTemplate();
        restTemplate.setRequestFactory(new HttpComponentsClientHttpRequestFactory());
        restTemplate.getMessageConverters().add(new ByteArrayHttpMessageConverter());
        HttpEntity&lt;?&gt; entity = new HttpEntity&lt;&gt;(headers);

        UriComponentsBuilder builder =
            UriComponentsBuilder.fromHttpUrl(hdfs_path)
                .queryParam("op", "OPEN")
                .queryParam("user.name", user_name);

        ResponseEntity&lt;byte[]&gt; 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();


        I think this is due to a transfer timeout on the Cosmos instance, so I tried to
        send a curl on the path by specifying offset, buffer and length parameters, but they seem to be ignored: I got the whole file.

        Thanks in advance.
        Hide
        backlogmanager Backlog Manager added a comment -

        2017-05-22 21:12|UPDATED status: transition Finish| # answers= 1, accepted answer= True

        Show
        backlogmanager Backlog Manager added a comment - 2017-05-22 21:12|UPDATED status: transition Finish| # answers= 1, accepted answer= True
        backlogmanager Backlog Manager made changes -
        Resolution Done [ 10000 ]
        Status In Progress [ 3 ] Closed [ 6 ]
        Hide
        backlogmanager Backlog Manager added a comment -

        2017-05-22 18:12|UPDATED status: transition Answer| # answers= 1, accepted answer= True

        Show
        backlogmanager Backlog Manager added a comment - 2017-05-22 18:12|UPDATED status: transition Answer| # answers= 1, accepted answer= True
        backlogmanager Backlog Manager made changes -
        Status Open [ 1 ] In Progress [ 3 ]
        backlogmanager Backlog Manager made changes -
        Field Original Value New Value
        Component/s FIWARE-TECH-HELP [ 10278 ]
        Hide
        backlogmanager Backlog Manager added a comment -

        2017-05-22 15:17|CREATED monitor | # answers= 1, accepted answer= True

        Show
        backlogmanager Backlog Manager added a comment - 2017-05-22 15:17|CREATED monitor | # answers= 1, accepted answer= True
        backlogmanager Backlog Manager created issue -

          People

          • Assignee:
            backlogmanager Backlog Manager
            Reporter:
            backlogmanager Backlog Manager
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: