Exemplo n.º 1
0
 public static final Optional<String> httpPost(
     Entity framework, String subUrl, String dataUrl, Map<String, Object> substitutions) {
   String targetUrl =
       Urls.mergePaths(framework.sensors().get(MesosFramework.FRAMEWORK_URL), subUrl);
   String templateContents = ResourceUtils.create().getResourceAsString(dataUrl);
   String processedJson =
       TemplateProcessor.processTemplateContents(templateContents, substitutions);
   LOG.debug("Posting JSON to {}: {}", targetUrl, processedJson);
   URI postUri = URI.create(targetUrl);
   HttpToolResponse response =
       HttpTool.httpPost(
           MesosUtils.buildClient(framework),
           postUri,
           MutableMap.of(
               HttpHeaders.CONTENT_TYPE, "application/json",
               HttpHeaders.ACCEPT, "application/json"),
           processedJson.getBytes());
   LOG.debug("Response: " + response.getContentAsString());
   if (!HttpTool.isStatusCodeHealthy(response.getResponseCode())) {
     LOG.warn(
         "Invalid response code {}: {}", response.getResponseCode(), response.getReasonPhrase());
     return Optional.absent();
   } else {
     LOG.debug("Successfull call to {}: {}", targetUrl);
     return Optional.of(response.getContentAsString());
   }
 }
Exemplo n.º 2
0
 public static final Optional<String> httpDelete(Entity framework, String subUrl) {
   String targetUrl =
       Urls.mergePaths(framework.sensors().get(MesosFramework.FRAMEWORK_URL), subUrl);
   LOG.debug("Deleting {}", targetUrl);
   URI deleteUri = URI.create(targetUrl);
   HttpToolResponse response =
       HttpTool.httpDelete(
           buildClient(framework),
           deleteUri,
           MutableMap.of(HttpHeaders.ACCEPT, "application/json"));
   LOG.debug("Response: " + response.getContentAsString());
   if (!HttpTool.isStatusCodeHealthy(response.getResponseCode())) {
     LOG.warn(
         "Invalid response code {}: {}", response.getResponseCode(), response.getReasonPhrase());
     return Optional.absent();
   } else {
     LOG.debug("Successfull call to {}: {}", targetUrl);
     return Optional.of(response.getContentAsString());
   }
 }
 @Override
 public String apply(HttpToolResponse input) {
   return input.getContentAsString();
 }
 @Override
 public Integer apply(HttpToolResponse input) {
   return input.getResponseCode();
 }
 @Override
 public Boolean apply(HttpToolResponse input) {
   List<String> actual = input.getHeaderLists().get(header);
   return actual != null && actual.size() > 0;
 }
 public Long apply(HttpToolResponse input) {
   return input.getLatencyFullContent();
 }