From 35fab7f245e8755585ce4f5cb3115fdcc1971d5f Mon Sep 17 00:00:00 2001 From: Ola Aunrønning Date: Wed, 9 Aug 2017 15:03:02 +0200 Subject: Now sends HTTP Patch including benchmark/verification results to node repo --- .../node/verification/commons/ReportSender.java | 39 +++++++++++----------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/node-maintainer/src/main/java/com/yahoo/vespa/hosted/node/verification/commons/ReportSender.java b/node-maintainer/src/main/java/com/yahoo/vespa/hosted/node/verification/commons/ReportSender.java index cd89a1524cf..d058c4c263e 100644 --- a/node-maintainer/src/main/java/com/yahoo/vespa/hosted/node/verification/commons/ReportSender.java +++ b/node-maintainer/src/main/java/com/yahoo/vespa/hosted/node/verification/commons/ReportSender.java @@ -2,23 +2,28 @@ package com.yahoo.vespa.hosted.node.verification.commons; import com.fasterxml.jackson.databind.ObjectMapper; -import com.yahoo.application.Networking; -import com.yahoo.application.container.handler.Request; -import com.yahoo.application.container.JDisc; -import com.yahoo.application.container.handler.Response; -import com.yahoo.text.Utf8; import com.yahoo.vespa.hosted.node.verification.commons.noderepo.NodeRepoInfoRetriever; import com.yahoo.vespa.hosted.node.verification.commons.noderepo.NodeRepoJsonModel; import com.yahoo.vespa.hosted.node.verification.commons.report.BenchmarkReport; import com.yahoo.vespa.hosted.node.verification.commons.report.HardwareDivergenceReport; import com.yahoo.vespa.hosted.node.verification.commons.report.SpecVerificationReport; +import org.apache.http.client.ClientProtocolException; +import org.apache.http.client.methods.CloseableHttpResponse; +import org.apache.http.client.methods.HttpPatch; +import org.apache.http.entity.StringEntity; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClients; import java.io.IOException; import java.net.URL; import java.util.ArrayList; +import java.util.logging.Level; +import java.util.logging.Logger; public class ReportSender { + private static final Logger logger = Logger.getLogger(ReportSender.class.getName()); + private static void updateNodeRepository(ArrayList nodeInfoUrls, HardwareDivergenceReport hardwareDivergenceReport) throws IOException { ObjectMapper om = new ObjectMapper(); String report; @@ -28,21 +33,17 @@ public class ReportSender { else { report = "{\"hardwareDivergence\": " + om.writeValueAsString(hardwareDivergenceReport) + "}"; } - System.out.println(report); - /* - //TODO: Update node repo - String url = nodeInfoUrls.get(0).toString(); - Request request = new Request(url, Utf8.toBytes(report), Request.Method.PATCH); - JDisc container = JDisc.fromServicesXml("", Networking.disable); - Response response = container.handleRequest(request); - container.close(); - - for (URL nodeInfoUrl : nodeInfoUrls) { - new Request(nodeInfoUrl.toString(), - Utf8.toBytes(report), - Request.Method.PATCH); + HttpPatch httpPatch = new HttpPatch(nodeInfoUrls.get(0).toString()); + httpPatch.setEntity(new StringEntity(report)); + CloseableHttpClient httpClient = HttpClients.createDefault(); + try { + CloseableHttpResponse httpResponse = httpClient.execute(httpPatch); + logger.log(Level.INFO, "Response code: " + httpResponse.getStatusLine().getStatusCode()); - }*/ + } catch (ClientProtocolException e) { + System.out.println("Failed to patch node repo - Invalid URL"); + } + httpClient.close(); } public static void reportBenchmarkResults(BenchmarkReport benchmarkReport, ArrayList nodeInfoUrls) throws IOException { -- cgit v1.2.3