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()); } }
protected String generateHostname(SshMachineLocation machine) { String hostnameTemplate = config.get(HOSTNAME_TEMPLATE); if (Strings.isNonBlank(hostnameTemplate)) { return TemplateProcessor.processTemplateContents( hostnameTemplate, machine, ImmutableMap.<String, Object>of()); } else { return null; } }
public String getCassandraConfigTemplateUrl() { String templatedUrl = getConfig(CassandraNode.CASSANDRA_CONFIG_TEMPLATE_URL); return TemplateProcessor.processTemplateContents( templatedUrl, this, ImmutableMap.<String, Object>of()); }