/** * Send segment uri using default settings. * * @param uri URI * @param downloadUri Segment download uri * @return Response * @throws IOException * @throws HttpErrorStatusException */ public SimpleHttpResponse sendSegmentUri(URI uri, String downloadUri) throws IOException, HttpErrorStatusException { return sendSegmentUri(uri, downloadUri, null, null, DEFAULT_SOCKET_TIMEOUT_MS); }
public void pushOneTarFile(FileSystem fs, Path path) throws Exception { String fileName = path.getName(); if (!fileName.endsWith(JobConfigConstants.TARGZ)) { return; } try (FileUploadDownloadClient fileUploadDownloadClient = new FileUploadDownloadClient()) { for (String host : _hosts) { String uri = String.format("%s%s%s", _pushUriPrefix, path.toUri().getRawPath(), _pushUriSuffix); LOGGER .info("******** Uploading file: {} to Host: {} and Port: {} with download uri: {} *******", fileName, host, _port, uri); try { SimpleHttpResponse response = fileUploadDownloadClient .sendSegmentUri(FileUploadDownloadClient.getUploadSegmentHttpURI(host, _port), uri); LOGGER.info("Response {}: {}", response.getStatusCode(), response.getResponse()); } catch (Exception e) { LOGGER.error("******** Error Uploading file: {} to Host: {} and Port: {} *******", fileName, host, _port); LOGGER.error("Caught exception during upload", e); throw e; } } } } }
@Override public Integer call() throws Exception { return fileUploadDownloadClient .sendSegmentUri(FileUploadDownloadClient.getUploadSegmentHttpURI(LOCAL_HOST, _controllerPort), downloadUri, httpHeaders, null, 60 * 1000).getStatusCode(); } }));
@Test public void testSendFileWithUriAndCrypter() throws Exception { try (FileUploadDownloadClient fileUploadDownloadClient = new FileUploadDownloadClient()) { Header crypterClassHeader = new BasicHeader(FileUploadDownloadClient.CustomHeaders.CRYPTER, TEST_CRYPTER); List<Header> headers = Collections.singletonList(crypterClassHeader); List<NameValuePair> params = null; SimpleHttpResponse response = fileUploadDownloadClient .sendSegmentUri(FileUploadDownloadClient.getUploadSegmentHttpURI(TEST_HOST, TEST_PORT), TEST_URI, headers, params, FileUploadDownloadClient.DEFAULT_SOCKET_TIMEOUT_MS); Assert.assertEquals(response.getStatusCode(), HttpStatus.SC_OK); Assert.assertEquals(response.getResponse(), "OK"); } }