Now sends HTTP Patch including benchmark/verification results to node repo
@@ -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<URL> 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("<jdisc version=\"1.0\"/>", 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<URL> nodeInfoUrls) throws IOException {
