protected String callBridge(RestHttpHelper restHelper, String bridgeURL) { log.info("Making bridge call to restart snapshot. URL: {}", bridgeURL); try { RestHttpHelper.HttpResponse response = restHelper.post(bridgeURL, null, null); int statusCode = response.getStatusCode(); if (statusCode != HttpStatus.SC_ACCEPTED) { throw new RuntimeException("Unexpected response code: " + statusCode); } return response.getResponseBody(); } catch (Exception e) { throw new TaskException("Exception encountered attempting to " + "restart snapshot. " + "Error reported: " + e.getMessage(), e); } }
public HttpResponse initializeDurastore(String host, String port, String context) throws Exception { String baseURL = "http://" + host + ":" + port + "/" + context; String storesURL = baseURL + "/stores"; String xml = buildTestAccountXml(); RestHttpHelper restHelper = new RestHttpHelper(getRootCredential()); return restHelper.post(storesURL, xml, null); }
@Override public String startStorageReport() throws ReportException { String url = buildBaseStorageReportURL(); try { RestHttpHelper.HttpResponse response = getRestHelper() .post(url, null, null); checkResponse(response, HttpStatus.SC_OK); return response.getResponseBody(); } catch (Exception e) { String error = "Could not start storage report due to: " + e.getMessage(); throw new ReportException(error, e); } }
/** * This method initializes this application with the provided configuration. * * @param config * @return */ public RestHttpHelper.HttpResponse initialize(AppConfig config) { String xml = config.asXml(); String url = getInitUrl(config); try { Map<String, String> headers = null; return getRestHelper().post(url, xml, headers); } catch (Exception e) { log.error("error initializing app at: " + url, ExceptionUtil.getStackTraceAsString(e)); throw new DuraCloudRuntimeException(e); } }
/** * This method sets the security users of this application to the provided * users. * * @param users * @return */ public RestHttpHelper.HttpResponse setSecurityUsers(Collection<SecurityUserBean> users) { String xml = SecurityUsersDocumentBinding.createDocumentFrom(users); try { Map<String, String> headers = null; return getRestHelper().post(getSecurityUrl(), xml, headers); } catch (Exception e) { log.error("error initializing durastore security", ExceptionUtil.getStackTraceAsString(e)); throw new DuraCloudRuntimeException(e); } }
@Override public String scheduleStorageReport(Date startTime, long frequency) throws ReportException { if(null == startTime) { throw new ReportException("Start time may not be null"); } if(startTime.before(new Date())) { throw new ReportException("Start time must be in the future"); } if(frequency < 600000) { throw new ReportException("Frequency must be higher than " + "600000 milliseconds (10 minutes)"); } String url = buildScheduleStorageReportURL(startTime.getTime(), frequency); try { RestHttpHelper.HttpResponse response = getRestHelper() .post(url, null, null); checkResponse(response, HttpStatus.SC_OK); return response.getResponseBody(); } catch (Exception e) { String error = "Could not schedule storage report due to: " + e.getMessage(); throw new ReportException(error, e); } }
private String doPerformTask(String taskName, String taskParameters) throws ContentStoreException { String url = buildTaskURL(taskName); try { HttpResponse response = restHelper.post(url, taskParameters, null); checkResponse(response, HttpStatus.SC_OK); return response.getResponseBody(); } catch (InvalidIdException e) { throw new UnsupportedTaskException(taskName, e); } catch (UnauthorizedException e) { throw new UnauthorizedException("Not authorized to perform task: " + taskName, e); } catch (ContentStateException e) { throw e; } catch (Exception e) { throw new ContentStoreException("Error performing task (" + taskName + "): " + e.getMessage(), e); } }
private void doSetSpaceACLs(String spaceId, Map<String, AclType> spaceACLs) throws ContentStoreException { String task = "set space ACLs"; String url = buildAclURL(spaceId); Map<String, String> headers = convertAclsToHeaders(spaceACLs); try { HttpResponse response = restHelper.post(url, null, headers); checkResponse(response, HttpStatus.SC_OK); } 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); } }
private void doSetContentProperties(String spaceId, String contentId, Map<String, String> contentProperties) throws ContentStoreException { String task = "update content properties"; String url = buildContentURL(spaceId, contentId); Map<String, String> headers = convertPropertiesToHeaders(contentProperties); try { HttpResponse response = restHelper.post(url, null, headers); checkResponse(response, HttpStatus.SC_OK); } 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); } }