private void retryFromNextByte() throws IOException { log.info( "Failed to read byte at position {} (space: {}, contentId: {}, startByte:{}, endByte: {}. " + "Starting attempts to re-acquire stream from current position.", nextBytePos, spaceId, contentId, startByte, endByte); try { //exponential backoff on retries new Retrier(5, 4000, 3).execute(() -> { RestHttpHelper.HttpResponse response = contentStore.doGetContent(spaceId, contentId, nextBytePos, endByte); currentStream = response.getResponseStream(); log.info( "Successfully re-acquired stream (space: {}, contentId: {}, nextBytePos:{}," + " endByte: {}. ", spaceId, contentId, nextBytePos, endByte); return null; }); } catch (Exception e) { log.warn( "Exhausted max retries to re-acquire stream (space: {}, contentId: {}, nextBytePos:{}," + " endByte: {}. ", spaceId, contentId, nextBytePos, endByte, e); throw new IOException(e.getMessage(), e); } }
@Override public List<String> getStorageReportList() throws ReportException { String url = buildGetStorageReportListURL(); try { RestHttpHelper.HttpResponse response = getRestHelper().get(url); checkResponse(response, HttpStatus.SC_OK); InputStream listXml = response.getResponseStream(); StorageReportList reportList = new StorageReportListSerializer().deserialize(listXml); List<String> reportIds = reportList.getStorageReportList(); if(null == reportIds) { reportIds = new ArrayList<String>(); } return reportIds; } catch (Exception e) { String error = "Could not get storage report list due to: " + e.getMessage(); throw new ReportException(error, e); } }
@Override public StorageReportInfo getStorageReportInfo() throws ReportException { String url = buildGetStorageReportInfoURL(); try { RestHttpHelper.HttpResponse response = getRestHelper().get(url); checkResponse(response, HttpStatus.SC_OK); InputStream reportInfoXml = response.getResponseStream(); StorageReportInfoSerializer serializer = new StorageReportInfoSerializer(); return serializer.deserialize(reportInfoXml); } catch (Exception e) { String error = "Could not get storage report info due to: " + e.getMessage(); throw new ReportException(error, e); } }
@Override public BitIntegrityReport getBitIntegrityReport(String spaceId) throws ContentStoreException { String task = "get bit integrity report"; String url = buildBitIntegrityReportURL(spaceId); try { HttpResponse response = restHelper.get(url); if (hasNoContent(response)) { return null; } checkResponse(response, HttpStatus.SC_OK); //This is a workaround for duracloud-1137 //for reasons that are not clear, in the beanstalk environment //the httpclient is swallowing the Content-Length header //leading the BitIntegrityReportProperties.getSize() method to //return 0. This appears to be the case only on the GET call. //To work around it, we are loading the properties with a separate //call that uses the HEAD path. BitIntegrityReportProperties properties = getBitIntegrityReportProperties(spaceId); BitIntegrityReport report = new BitIntegrityReport(response.getResponseStream(), properties); return report; } catch (UnauthorizedException e) { throw new UnauthorizedException(task, spaceId, e); } catch (Exception e) { throw new ContentStoreException(task, spaceId, e); } }
@Override public InputStream getAuditLog(String spaceId) throws ContentStoreException { String task = "get manifest"; String url = buildAuditLogURL(spaceId); try { HttpResponse response = restHelper.get(url); checkResponse(response, HttpStatus.SC_OK); return response.getResponseStream(); } catch (NotFoundException e) { throw new NotFoundException(task, spaceId, e); } catch (UnauthorizedException e) { throw new UnauthorizedException(task, spaceId, e); } catch (Exception e) { throw new ContentStoreException(task, spaceId, e); } }
@Override public InputStream getManifest(String spaceId, ManifestFormat format) throws ContentStoreException { String task = "get manifest"; String url = buildManifestURL(spaceId, format); try { HttpResponse response = restHelper.get(url); checkResponse(response, HttpStatus.SC_OK); return response.getResponseStream(); } catch (NotFoundException e) { throw new NotFoundException(task, spaceId, e); } catch (UnauthorizedException e) { throw new UnauthorizedException(task, spaceId, e); } catch (Exception e) { throw new ContentStoreException(task, spaceId, e); } }
@Override public StorageReport getStorageReport(String reportId) throws NotFoundException, ReportException { String url = buildGetStorageReportURL(reportId); try { RestHttpHelper.HttpResponse response = getRestHelper().get(url); checkResponse(response, HttpStatus.SC_OK); InputStream reportXml = response.getResponseStream(); StorageReportSerializer serializer = new StorageReportSerializer(); return serializer.deserialize(reportXml); } catch (NotFoundException e) { throw e; } catch (Exception e) { String error = "Could not get storage report with ID " + reportId + " due to: " + e.getMessage(); throw new ReportException(error, e); } }
@Override public StorageReport getLatestStorageReport() throws NotFoundException, ReportException { String url = buildBaseStorageReportURL(); try { RestHttpHelper.HttpResponse response = getRestHelper().get(url); checkResponse(response, HttpStatus.SC_OK); InputStream reportXml = response.getResponseStream(); StorageReportSerializer serializer = new StorageReportSerializer(); return serializer.deserialize(reportXml); } catch (NotFoundException e) { throw e; } catch (Exception e) { String error = "Could not get latest storage report due to: " + e.getMessage(); throw new ReportException(error, e); } }
private Content toContent(HttpResponse response, String spaceId, String contentId, Long startByte, Long endByte) throws IOException { Content content = new Content(); content.setId(contentId); content.setStream( new PartialContentRetryInputStream(this, spaceId, contentId, response.getResponseStream(), startByte, endByte)); content.setProperties( mergeMaps(extractPropertiesFromHeaders(response), extractNonPropertiesHeaders(response))); return content; }