protected String callBridge(RestHttpHelper restHelper, String bridgeURL) { log.info("Making bridge call to get snapshot list. URL: {}", bridgeURL); try { RestHttpHelper.HttpResponse response = restHelper.get(bridgeURL); int statusCode = response.getStatusCode(); if (statusCode != 200) { throw new RuntimeException("Unexpected response code: " + statusCode); } return response.getResponseBody(); } catch (Exception e) { throw new TaskException("Exception encountered attempting to " + "get list of snapshots. " + "Error reported: " + e.getMessage(), e); } }
protected String callBridge(RestHttpHelper restHelper, String bridgeURL) { log.info("Making bridge call to get snapshot status. URL: {}", bridgeURL); try { RestHttpHelper.HttpResponse response = restHelper.get(bridgeURL); int statusCode = response.getStatusCode(); if (statusCode != 200) { throw new RuntimeException("Unexpected response code: " + statusCode); } return response.getResponseBody(); } catch (Exception e) { throw new TaskException("Exception encountered attempting to " + "get snapshot. " + "Error reported: " + e.getMessage(), e); } }
protected String callBridge(RestHttpHelper restHelper, String bridgeURL) { log.info("Making bridge call to get snapshot history. URL: {}", bridgeURL); try { RestHttpHelper.HttpResponse response = restHelper.get(bridgeURL); int statusCode = response.getStatusCode(); if (statusCode != 200) { throw new RuntimeException("Unexpected response code: " + statusCode); } return response.getResponseBody(); } catch (Exception e) { throw new TaskException("Exception encountered attempting to " + "get snapshot history. " + "Error reported: " + e.getMessage(), e); } }
protected String callBridge(RestHttpHelper restHelper, String bridgeURL) { log.info("Making bridge call to get restore status. URL: {}", bridgeURL); try { RestHttpHelper.HttpResponse response = restHelper.get(bridgeURL); int statusCode = response.getStatusCode(); if (statusCode != 200) { throw new RuntimeException("Unexpected response code: " + statusCode); } return response.getResponseBody(); } catch (Exception e) { throw new TaskException("Exception encountered attempting to " + "get restore. " + "Error reported: " + e.getMessage(), e); } }
protected String callBridge(RestHttpHelper restHelper, String bridgeURL) { log.info("Making bridge call to get snapshot contents. URL: {}", bridgeURL); try { RestHttpHelper.HttpResponse response = restHelper.get(bridgeURL); int statusCode = response.getStatusCode(); if (statusCode != 200) { throw new RuntimeException("Unexpected response code: " + statusCode); } return response.getResponseBody(); } catch (Exception e) { throw new TaskException("Exception encountered attempting to " + "get snapshot contents. " + "Error reported: " + e.getMessage(), e); } }
protected HttpResponse doGetContent(String spaceId, String contentId, Long startByte, Long endByte) throws ContentStoreException { String task = "get content"; String url = buildContentURL(spaceId, contentId); try { final boolean hasRange = !(startByte == 0l && endByte == null); final HttpResponse response; if (!hasRange) { response = restHelper.get(url); } else { Map<String, String> headers = new HashMap<>(); headers.put("Range", "bytes=" + startByte + "-" + (endByte != null ? endByte : "")); response = restHelper.get(url, headers); } checkResponse(response, hasRange ? HttpStatus.SC_PARTIAL_CONTENT : HttpStatus.SC_OK); return response; } catch (NotFoundException e) { throw new NotFoundException(task, spaceId, contentId, e); } catch (UnauthorizedException e) { throw new UnauthorizedException(task, spaceId, contentId, e); } catch (Exception e) { throw new ContentStoreException(task, spaceId, contentId, e); } }
HttpResponse response = restHelper.get(url); checkResponse(response, HttpStatus.SC_OK); String responseText = response.getResponseBody();
private List<String> doGetSupportedTasks() throws ContentStoreException { String url = buildTaskURL(); try { HttpResponse response = restHelper.get(url); checkResponse(response, HttpStatus.SC_OK); String reponseText = response.getResponseBody(); return SerializationUtil.deserializeList(reponseText); } catch (UnauthorizedException e) { throw new UnauthorizedException("Not authorized to get supported " + "tasks", e); } catch (Exception e) { throw new ContentStoreException("Error getting supported tasks: " + e.getMessage(), e); } }
String url = buildSpaceURL(spaceId, prefix, maxResults, marker); try { HttpResponse response = restHelper.get(url); checkResponse(response, HttpStatus.SC_OK); Space space = new Space();
@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 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); } }
@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 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 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 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 SpaceStatsDTOList getStorageProviderStatsByDay(Date date) throws ContentStoreException { String url = buildStorageProviderStatsURL(date); try { HttpResponse response = restHelper.get(url); checkResponse(response, HttpStatus.SC_OK); String body = response.getResponseBody(); JaxbJsonSerializer<SpaceStatsDTOList> serializer = new JaxbJsonSerializer<>(SpaceStatsDTOList.class); return serializer.deserialize(body); } catch (UnauthorizedException e) { throw new UnauthorizedException(storeId, e); } catch (Exception e) { throw new ContentStoreException("failed to retrieve storage provider stats for " + storeId, e); } }
String error = "Error retrieving content stores. "; try { response = getRestHelper().get(url); if (response.getStatusCode() == HttpStatus.SC_OK) { String storesXML = response.getResponseBody();
@Override public SpaceStatsDTOList getSpaceStats(String spaceId, Date start, Date end) throws ContentStoreException { String url = buildSpaceStatsURL(spaceId, start, end); try { HttpResponse response = restHelper.get(url); checkResponse(response, HttpStatus.SC_OK); String body = response.getResponseBody(); JaxbJsonSerializer<SpaceStatsDTOList> serializer = new JaxbJsonSerializer<>(SpaceStatsDTOList.class); return serializer.deserialize(body); } catch (NotFoundException e) { throw new NotFoundException("spaceId = " + spaceId); } catch (UnauthorizedException e) { throw new UnauthorizedException(spaceId, e); } catch (Exception e) { throw new ContentStoreException("failed to retrieve space stats for " + spaceId, 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 SpaceStatsDTOList getStorageProviderStats(Date start, Date end) throws ContentStoreException { String url = buildStorageProviderStatsURL(start, end); try { HttpResponse response = restHelper.get(url); checkResponse(response, HttpStatus.SC_OK); String body = response.getResponseBody(); JaxbJsonSerializer<SpaceStatsDTOList> serializer = new JaxbJsonSerializer<>(SpaceStatsDTOList.class); return serializer.deserialize(body); } catch (NotFoundException e) { throw new NotFoundException("storeId = " + getStoreId()); } catch (UnauthorizedException e) { throw new UnauthorizedException(getStoreId(), e); } catch (Exception e) { throw new ContentStoreException("failed to retrieve storage provider stats for " + getStoreId(), e); } }