diff options
author | sindre <sindre.grostad@icloud.com> | 2017-08-09 13:00:16 +0200 |
---|---|---|
committer | Ola Aunrønning <olaa@yahoo-inc.com> | 2017-08-15 12:29:39 +0200 |
commit | a5a59c808b733681d894cf001466fd711555f02b (patch) | |
tree | 51d3292bc69c3645564d9dc09df4d26fd23c1d39 /node-maintainer | |
parent | c2f9eea750352710b951456053a06d1c6f1c8b6e (diff) |
change of format for reporting
Diffstat (limited to 'node-maintainer')
9 files changed, 71 insertions, 102 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 1f57392d2e9..cd89a1524cf 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 @@ -21,7 +21,13 @@ public class ReportSender { private static void updateNodeRepository(ArrayList<URL> nodeInfoUrls, HardwareDivergenceReport hardwareDivergenceReport) throws IOException { ObjectMapper om = new ObjectMapper(); - String report = "{\"hardwareDivergence\": " + om.writeValueAsString(hardwareDivergenceReport) + "}"; + String report; + if (hardwareDivergenceReport.isHardwareDivergenceReportEmpty()){ + report = "{\"hardwareDivergence\": null}"; + } + else { + report = "{\"hardwareDivergence\": " + om.writeValueAsString(hardwareDivergenceReport) + "}"; + } System.out.println(report); /* //TODO: Update node repo diff --git a/node-maintainer/src/main/java/com/yahoo/vespa/hosted/node/verification/commons/report/BenchmarkReport.java b/node-maintainer/src/main/java/com/yahoo/vespa/hosted/node/verification/commons/report/BenchmarkReport.java index 50794af278d..0d21816e69b 100644 --- a/node-maintainer/src/main/java/com/yahoo/vespa/hosted/node/verification/commons/report/BenchmarkReport.java +++ b/node-maintainer/src/main/java/com/yahoo/vespa/hosted/node/verification/commons/report/BenchmarkReport.java @@ -1,7 +1,10 @@ package com.yahoo.vespa.hosted.node.verification.commons.report; +import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; /** * Created by sgrostad on 12/07/2017. @@ -52,4 +55,16 @@ public class BenchmarkReport { return memoryReadSpeedGBs; } + @JsonIgnore + public boolean isAllBenchmarksOK() { + ObjectMapper om = new ObjectMapper(); + try { + String jsonReport = om.writeValueAsString(this); + return jsonReport.length() == 2; + } catch (JsonProcessingException e){ + e.printStackTrace(); + return false; + } + } + } diff --git a/node-maintainer/src/main/java/com/yahoo/vespa/hosted/node/verification/commons/report/HardwareDivergenceReport.java b/node-maintainer/src/main/java/com/yahoo/vespa/hosted/node/verification/commons/report/HardwareDivergenceReport.java index af85b142141..20fc19082a4 100644 --- a/node-maintainer/src/main/java/com/yahoo/vespa/hosted/node/verification/commons/report/HardwareDivergenceReport.java +++ b/node-maintainer/src/main/java/com/yahoo/vespa/hosted/node/verification/commons/report/HardwareDivergenceReport.java @@ -1,5 +1,6 @@ package com.yahoo.vespa.hosted.node.verification.commons.report; +import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; @@ -13,11 +14,29 @@ public class HardwareDivergenceReport { BenchmarkReport benchmarkReport; public void setSpecVerificationReport(SpecVerificationReport specVerificationReport) { - this.specVerificationReport = specVerificationReport; + if (specVerificationReport.isValidSpec()){ + this.specVerificationReport = null; + } + else { + this.specVerificationReport = specVerificationReport; + } } public void setBenchmarkReport(BenchmarkReport benchmarkReport) { - this.benchmarkReport = benchmarkReport; + if (benchmarkReport.isAllBenchmarksOK()) { + this.benchmarkReport = null; + } + else { + this.benchmarkReport = benchmarkReport; + } + } + + @JsonIgnore + public boolean isHardwareDivergenceReportEmpty(){ + if (specVerificationReport == null && benchmarkReport == null){ + return true; + } + return false; } } diff --git a/node-maintainer/src/main/java/com/yahoo/vespa/hosted/node/verification/commons/report/SpecVerificationReport.java b/node-maintainer/src/main/java/com/yahoo/vespa/hosted/node/verification/commons/report/SpecVerificationReport.java index b6af61e4d20..e7ece6c4a7f 100644 --- a/node-maintainer/src/main/java/com/yahoo/vespa/hosted/node/verification/commons/report/SpecVerificationReport.java +++ b/node-maintainer/src/main/java/com/yahoo/vespa/hosted/node/verification/commons/report/SpecVerificationReport.java @@ -1,7 +1,10 @@ package com.yahoo.vespa.hosted.node.verification.commons.report; +import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; import com.yahoo.vespa.hosted.node.verification.spec.retrievers.HardwareInfo; @@ -55,4 +58,18 @@ public class SpecVerificationReport { public void setFaultyIpAddresses(String[] faultyIpAddresses) { this.faultyIpAddresses = faultyIpAddresses; } + + @JsonIgnore + public boolean isValidSpec() { + ObjectMapper om = new ObjectMapper(); + try { + String jsonReport = om.writeValueAsString(this); + return jsonReport.length() == 2; + } + catch (JsonProcessingException e){ + e.printStackTrace(); + return false; + } + } + } diff --git a/node-maintainer/src/main/java/com/yahoo/vespa/hosted/node/verification/hardware/HardwareBenchmarker.java b/node-maintainer/src/main/java/com/yahoo/vespa/hosted/node/verification/hardware/HardwareBenchmarker.java index 7e7d3c65dc0..a203bcced5a 100644 --- a/node-maintainer/src/main/java/com/yahoo/vespa/hosted/node/verification/hardware/HardwareBenchmarker.java +++ b/node-maintainer/src/main/java/com/yahoo/vespa/hosted/node/verification/hardware/HardwareBenchmarker.java @@ -32,23 +32,8 @@ public class HardwareBenchmarker { benchmark.doBenchmark(); } BenchmarkReport benchmarkReport = BenchmarkResultInspector.makeBenchmarkReport(benchmarkResults); - if (!isAllBenchmarksOK(benchmarkReport)) { - ReportSender.reportBenchmarkResults(benchmarkReport, nodeInfoUrls); - } - return isAllBenchmarksOK(benchmarkReport); - } - - - - private static boolean isAllBenchmarksOK(BenchmarkReport benchmarkReport) { - ObjectMapper om = new ObjectMapper(); - try { - String jsonReport = om.writeValueAsString(benchmarkReport); - return jsonReport.length() == 2; - } catch (JsonProcessingException e){ - e.printStackTrace(); - return false; - } + ReportSender.reportBenchmarkResults(benchmarkReport, nodeInfoUrls); + return benchmarkReport.isAllBenchmarksOK(); } public static void main(String[] args) throws IOException { diff --git a/node-maintainer/src/main/java/com/yahoo/vespa/hosted/node/verification/spec/SpecVerifier.java b/node-maintainer/src/main/java/com/yahoo/vespa/hosted/node/verification/spec/SpecVerifier.java index 2ef7668cc2d..ee9d7437075 100644 --- a/node-maintainer/src/main/java/com/yahoo/vespa/hosted/node/verification/spec/SpecVerifier.java +++ b/node-maintainer/src/main/java/com/yahoo/vespa/hosted/node/verification/spec/SpecVerifier.java @@ -38,15 +38,8 @@ public class SpecVerifier { VerifierSettings verifierSettings = new VerifierSettings(nodeRepoJsonModel); HardwareInfo actualHardware = HardwareInfoRetriever.retrieve(commandExecutor, verifierSettings); SpecVerificationReport specVerificationReport = makeVerificationReport(actualHardware, nodeRepoJsonModel); - if (!isValidSpec(specVerificationReport)) { - ReportSender.reportSpecVerificationResults(specVerificationReport, nodeInfoUrls); - } - return isValidSpec(specVerificationReport); - } - - private static boolean isValidSpec(SpecVerificationReport specVerificationReport) throws JsonProcessingException { - ObjectMapper om = new ObjectMapper(); - return om.writeValueAsString(specVerificationReport).length() == 2; + ReportSender.reportSpecVerificationResults(specVerificationReport, nodeInfoUrls); + return specVerificationReport.isValidSpec(); } protected static SpecVerificationReport makeVerificationReport(HardwareInfo actualHardware, NodeRepoJsonModel nodeRepoJsonModel) { diff --git a/node-maintainer/src/test/java/com/yahoo/vespa/hosted/node/verification/hardware/HardwareBenchmarkerTest.java b/node-maintainer/src/test/java/com/yahoo/vespa/hosted/node/verification/hardware/HardwareBenchmarkerTest.java index 1b1eafd8cd9..159cddb7640 100644 --- a/node-maintainer/src/test/java/com/yahoo/vespa/hosted/node/verification/hardware/HardwareBenchmarkerTest.java +++ b/node-maintainer/src/test/java/com/yahoo/vespa/hosted/node/verification/hardware/HardwareBenchmarkerTest.java @@ -4,7 +4,10 @@ import com.yahoo.vespa.hosted.node.verification.mock.MockCommandExecutor; import org.junit.Before; import org.junit.Test; +import java.net.URL; +import java.nio.file.Paths; import java.util.ArrayList; +import java.util.Arrays; import static org.junit.Assert.assertTrue; @@ -16,6 +19,9 @@ public class HardwareBenchmarkerTest { private static final String VALID_CPU_BENCHMARK_PATH = RESOURCE_PATH + "cpuCyclesWithCommasTimeWithDotTest.txt"; private static final String VALID_MEMORY_WRITE_BENCHMARK_PATH = RESOURCE_PATH + "validMemoryWriteSpeed"; private static final String VALID_MEMORY_READ_BENCHMARK_PATH = RESOURCE_PATH + "validMemoryReadSpeed"; + private static final String ABSOLUTE_PATH = Paths.get(".").toAbsolutePath().normalize().toString(); + private static final String VALID_NODE_REPO_JSON_WITHOUT_HARDWARE_DIVERGENCE = RESOURCE_PATH + "nodeRepoWithoutHardwareDivergence.json"; + private static final String URL_TO_NODE_REPO_JSON = "file://" + ABSOLUTE_PATH + "/" + VALID_NODE_REPO_JSON_WITHOUT_HARDWARE_DIVERGENCE; @Before public void setup() { @@ -33,7 +39,7 @@ public class HardwareBenchmarkerTest { mockCommandExecutor.addCommand("cat " + VALID_MEMORY_READ_BENCHMARK_PATH); mockCommandExecutor.addDummyCommand(); mockCommandExecutor.addDummyCommand(); - assertTrue(HardwareBenchmarker.hardwareBenchmarks(mockCommandExecutor, new ArrayList<>())); + assertTrue(HardwareBenchmarker.hardwareBenchmarks(mockCommandExecutor, new ArrayList<URL>(Arrays.asList(new URL(URL_TO_NODE_REPO_JSON))))); } diff --git a/node-maintainer/src/test/java/com/yahoo/vespa/hosted/node/verification/hardware/report/BenchmarkReportTest.java b/node-maintainer/src/test/java/com/yahoo/vespa/hosted/node/verification/hardware/report/BenchmarkReportTest.java deleted file mode 100644 index a9568ed4a3e..00000000000 --- a/node-maintainer/src/test/java/com/yahoo/vespa/hosted/node/verification/hardware/report/BenchmarkReportTest.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.yahoo.vespa.hosted.node.verification.hardware.report; - -import com.fasterxml.jackson.databind.ObjectMapper; -import com.yahoo.vespa.hosted.node.verification.commons.report.BenchmarkReport; -import org.junit.Test; - -import static org.junit.Assert.assertEquals; - -public class BenchmarkReportTest { - - private BenchmarkReport benchmarkReport = new BenchmarkReport(); - - @Test - public void createFromHardwareResults_should_create_correct_report() throws Exception { - double expectedCpuCyclesPerSec = 4; - double expectedDiskSpeedMbps = 120; - double expectedMemoryReadSpeedGBs = 7.1; - double expectedMemoryWriteSpeedGBs = 5.9; - benchmarkReport.setCpuCyclesPerSec(expectedCpuCyclesPerSec); - benchmarkReport.setDiskSpeedMbs(expectedDiskSpeedMbps); - benchmarkReport.setMemoryReadSpeedGBs(expectedMemoryReadSpeedGBs); - benchmarkReport.setMemoryWriteSpeedGBs(expectedMemoryWriteSpeedGBs); - ObjectMapper om = new ObjectMapper(); - String expectedResultJson = "{\"cpuCyclesPerSec\":4.0,\"diskSpeedMbs\":120.0,\"memoryWriteSpeedGBs\":5.9,\"memoryReadSpeedGBs\":7.1}"; - assertEquals(expectedResultJson, om.writeValueAsString(benchmarkReport)); - } - -}
\ No newline at end of file diff --git a/node-maintainer/src/test/java/com/yahoo/vespa/hosted/node/verification/spec/report/SpecVerificationReportTest.java b/node-maintainer/src/test/java/com/yahoo/vespa/hosted/node/verification/spec/report/SpecVerificationReportTest.java deleted file mode 100644 index 3c562cbaeda..00000000000 --- a/node-maintainer/src/test/java/com/yahoo/vespa/hosted/node/verification/spec/report/SpecVerificationReportTest.java +++ /dev/null @@ -1,44 +0,0 @@ -package com.yahoo.vespa.hosted.node.verification.spec.report; - -import com.fasterxml.jackson.databind.ObjectMapper; -import com.yahoo.vespa.hosted.node.verification.commons.report.SpecVerificationReport; -import com.yahoo.vespa.hosted.node.verification.mock.MockCommandExecutor; -import com.yahoo.vespa.hosted.node.verification.spec.retrievers.HardwareInfo; -import org.junit.Before; -import org.junit.Test; - -import static org.junit.Assert.*; - -public class SpecVerificationReportTest { - - private SpecVerificationReport specVerificationReport; - private static final String REPORT_PATH = "src/test/java/com/yahoo/vespa/hosted/node/verification/spec/resources/reportJSON"; - - @Before - public void setup() { - specVerificationReport = new SpecVerificationReport(); - } - - @Test - public void VerificationReport_returns_empty_string_when_all_specs_are_correct() throws Exception { - String expectedJson = "{}"; - ObjectMapper om = new ObjectMapper(); - String actualJson = om.writeValueAsString(specVerificationReport); - assertEquals(expectedJson, actualJson); - } - - @Test - public void Json_is_in_wanted_format_when_all_specs_are_wrong() throws Exception { - specVerificationReport.setActualInterfaceSpeed(100D); - specVerificationReport.setActualDiskSpaceAvailable(500D); - specVerificationReport.setActualDiskType(HardwareInfo.DiskType.FAST); - specVerificationReport.setActualMemoryAvailable(123D); - specVerificationReport.setActualcpuCores(4); - specVerificationReport.setFaultyIpAddresses(new String[]{"2001:db8:0:1234:0:567:8:1"}); - String expectedJson = MockCommandExecutor.readFromFile(REPORT_PATH).get(0); - ObjectMapper om = new ObjectMapper(); - String actualJson = om.writeValueAsString(specVerificationReport); - assertEquals(expectedJson, actualJson); - } - -}
\ No newline at end of file |