From a45d6c0631aca1bc662998332683b59a8f55e544 Mon Sep 17 00:00:00 2001 From: Andrius Kausinis Date: Tue, 8 Mar 2022 09:17:41 +0200 Subject: [PATCH] Terminating benchmarking, when project metadata is missing. --- .../cybench/launcher/BenchmarkRunner.java | 488 +++++++++--------- 1 file changed, 248 insertions(+), 240 deletions(-) diff --git a/gocypher-cybench-client/gocypher-cybench-runner/src/main/java/com/gocypher/cybench/launcher/BenchmarkRunner.java b/gocypher-cybench-client/gocypher-cybench-runner/src/main/java/com/gocypher/cybench/launcher/BenchmarkRunner.java index 2043b661..31a9354f 100644 --- a/gocypher-cybench-client/gocypher-cybench-runner/src/main/java/com/gocypher/cybench/launcher/BenchmarkRunner.java +++ b/gocypher-cybench-client/gocypher-cybench-runner/src/main/java/com/gocypher/cybench/launcher/BenchmarkRunner.java @@ -105,254 +105,258 @@ public void run() { Map> defaultBenchmarksMetadata = ComputationUtils .parseBenchmarkMetadata(getProperty(Constants.BENCHMARK_METADATA)); - PROJECT_METADATA_MAP.put("artifactId", getMetadataFromBuildFile("artifactId")); - PROJECT_METADATA_MAP.put("version", getMetadataFromBuildFile("version")); - // make sure gradle metadata can be parsed BEFORE benchmarks are run - if (StringUtils.isEmpty(PROJECT_METADATA_MAP.get("artifactId"))) { - failBuildFromMissingMetadata("Project"); - } - if (StringUtils.isEmpty(PROJECT_METADATA_MAP.get("version"))) { - failBuildFromMissingMetadata("Version"); - } - LOG.info("Executing benchmarks..."); - - LOG.info("_______________________ BENCHMARK TESTS FOUND _________________________________"); - OptionsBuilder optBuild = new OptionsBuilder(); - // Number of separate full executions of a benchmark (warm up+measurement), this - // is returned still as one primary score item - int forks = setExecutionIntProperty(getProperty(Constants.NUMBER_OF_FORKS)); - // Number of measurements per benchmark operation, this is returned still as one - // primary score item - int measurementIterations = setExecutionIntProperty(getProperty(Constants.MEASUREMENT_ITERATIONS)); - - int measurementSeconds = setExecutionIntProperty(getProperty(Constants.MEASUREMENT_SECONDS)); - // number of iterations executed for warm up - int warmUpIterations = setExecutionIntProperty(getProperty(Constants.WARM_UP_ITERATIONS)); - // number of seconds dedicated for each warm up iteration - int warmUpSeconds = setExecutionIntProperty(getProperty(Constants.WARM_UP_SECONDS)); - // number of threads for benchmark test execution - int threads = setExecutionIntProperty(getProperty(Constants.RUN_THREAD_COUNT)); - // benchmarks run mode - Set modes = setExecutionModes(getProperty(Constants.BENCHMARK_MODES)); - String jmhArguments = setExecutionStringProperty(getProperty(Constants.JMH_ARGUMENTS)); - - String tempBenchmark; - SecurityBuilder securityBuilder = new SecurityBuilder(); - Map benchmarkSetting = new HashMap<>(); - Map generatedFingerprints = new HashMap<>(); - Map manualFingerprints = new HashMap<>(); - Map classFingerprints = new HashMap<>(); - boolean foundBenchmarks = false; - - if (checkIfConfigurationPropertyIsSet(getProperty(Constants.BENCHMARK_RUN_CLASSES))) { - LOG.info("Execute benchmarks found in configuration {}", getProperty(Constants.BENCHMARK_RUN_CLASSES)); - List benchmarkNames = Arrays.stream(getProperty(Constants.BENCHMARK_RUN_CLASSES).split(",")) - .map(String::trim).collect(Collectors.toList()); - - // ********************************************************* - - for (String benchmarkClass : benchmarkNames) { - try { - Class classObj = Class.forName(benchmarkClass); - SecurityUtils.generateMethodFingerprints(classObj, manualFingerprints, classFingerprints); - SecurityUtils.computeClassHashForMethods(classObj, generatedFingerprints); - tempBenchmark = classObj.getName(); - - if (!tempBenchmark.isEmpty()) { - optBuild.include(classObj.getName()); - foundBenchmarks = true; - if (classObj.getName().startsWith("com.gocypher.cybench.")) { - securityBuilder.generateSecurityHashForClasses(classObj); + try { + PROJECT_METADATA_MAP.put("artifactId", getMetadataFromBuildFile("artifactId")); + PROJECT_METADATA_MAP.put("version", getMetadataFromBuildFile("version")); + // make sure gradle metadata can be parsed BEFORE benchmarks are run + if (StringUtils.isEmpty(PROJECT_METADATA_MAP.get("artifactId"))) { + failBuildFromMissingMetadata("Project"); + } + if (StringUtils.isEmpty(PROJECT_METADATA_MAP.get("version"))) { + failBuildFromMissingMetadata("Version"); + } + LOG.info("Executing benchmarks..."); + + LOG.info("_______________________ BENCHMARK TESTS FOUND _________________________________"); + OptionsBuilder optBuild = new OptionsBuilder(); + // Number of separate full executions of a benchmark (warm up+measurement), this + // is returned still as one primary score item + int forks = setExecutionIntProperty(getProperty(Constants.NUMBER_OF_FORKS)); + // Number of measurements per benchmark operation, this is returned still as one + // primary score item + int measurementIterations = setExecutionIntProperty(getProperty(Constants.MEASUREMENT_ITERATIONS)); + + int measurementSeconds = setExecutionIntProperty(getProperty(Constants.MEASUREMENT_SECONDS)); + // number of iterations executed for warm up + int warmUpIterations = setExecutionIntProperty(getProperty(Constants.WARM_UP_ITERATIONS)); + // number of seconds dedicated for each warm up iteration + int warmUpSeconds = setExecutionIntProperty(getProperty(Constants.WARM_UP_SECONDS)); + // number of threads for benchmark test execution + int threads = setExecutionIntProperty(getProperty(Constants.RUN_THREAD_COUNT)); + // benchmarks run mode + Set modes = setExecutionModes(getProperty(Constants.BENCHMARK_MODES)); + String jmhArguments = setExecutionStringProperty(getProperty(Constants.JMH_ARGUMENTS)); + + String tempBenchmark; + SecurityBuilder securityBuilder = new SecurityBuilder(); + Map benchmarkSetting = new HashMap<>(); + Map generatedFingerprints = new HashMap<>(); + Map manualFingerprints = new HashMap<>(); + Map classFingerprints = new HashMap<>(); + boolean foundBenchmarks = false; + + if (checkIfConfigurationPropertyIsSet(getProperty(Constants.BENCHMARK_RUN_CLASSES))) { + LOG.info("Execute benchmarks found in configuration {}", getProperty(Constants.BENCHMARK_RUN_CLASSES)); + List benchmarkNames = Arrays.stream(getProperty(Constants.BENCHMARK_RUN_CLASSES).split(",")) + .map(String::trim).collect(Collectors.toList()); + + // ********************************************************* + + for (String benchmarkClass : benchmarkNames) { + try { + Class classObj = Class.forName(benchmarkClass); + SecurityUtils.generateMethodFingerprints(classObj, manualFingerprints, classFingerprints); + SecurityUtils.computeClassHashForMethods(classObj, generatedFingerprints); + tempBenchmark = classObj.getName(); + + if (!tempBenchmark.isEmpty()) { + optBuild.include(classObj.getName()); + foundBenchmarks = true; + if (classObj.getName().startsWith("com.gocypher.cybench.")) { + securityBuilder.generateSecurityHashForClasses(classObj); + } } + } catch (ClassNotFoundException exc) { + LOG.error("Class not found in the classpath for execution", exc); } - } catch (ClassNotFoundException exc) { - LOG.error("Class not found in the classpath for execution", exc); } - } - // ********************************************************* + // ********************************************************* - LOG.info("Custom classes found and registered for execution: {}", foundBenchmarks); - } else { - LOG.info("Execute all benchmarks found on the classpath and configure default ones...."); - List benchmarkClasses = JMHUtils.getAllBenchmarkClasses(); - - for (String benchmarkClass : benchmarkClasses) { - try { - Class classObj = Class.forName(benchmarkClass); - SecurityUtils.generateMethodFingerprints(classObj, manualFingerprints, classFingerprints); - SecurityUtils.computeClassHashForMethods(classObj, generatedFingerprints); - foundBenchmarks = true; - tempBenchmark = classObj.getName(); - securityBuilder.generateSecurityHashForClasses(classObj); - } catch (ClassNotFoundException exc) { - LOG.error("Class not found in the classpath for execution", exc); + LOG.info("Custom classes found and registered for execution: {}", foundBenchmarks); + } else { + LOG.info("Execute all benchmarks found on the classpath and configure default ones...."); + List benchmarkClasses = JMHUtils.getAllBenchmarkClasses(); + + for (String benchmarkClass : benchmarkClasses) { + try { + Class classObj = Class.forName(benchmarkClass); + SecurityUtils.generateMethodFingerprints(classObj, manualFingerprints, classFingerprints); + SecurityUtils.computeClassHashForMethods(classObj, generatedFingerprints); + foundBenchmarks = true; + tempBenchmark = classObj.getName(); + securityBuilder.generateSecurityHashForClasses(classObj); + } catch (ClassNotFoundException exc) { + LOG.error("Class not found in the classpath for execution", exc); + } } + + // Reflections reflections = new Reflections("com.gocypher.cybench.", new + // SubTypesScanner(false)); + // Set> allDefaultClasses = + // reflections.getSubTypesOf(Object.class); + // foundBenchmarks = true; + // for (Class classObj : allDefaultClasses) { + // if (!classObj.getName().isEmpty() && + // classObj.getSimpleName().contains("Benchmarks") + // && !classObj.getSimpleName().contains("_")) { + // We do not include any class, because then JMH will discover all benchmarks + // automatically including user defined + // optBuild.include(classObj.getName()); + // tempBenchmark = classObj.getName(); + // LOG.info("tempBenchmark... {}", tempBenchmark); + // securityBuilder.generateSecurityHashForClasses(classObj); + // } + // } + } + + ChainedOptionsBuilder optionBuilder = optBuild.shouldDoGC(true) // + // .addProfiler(HotspotThreadProfiler.class) // obsolete + // .addProfiler(HotspotRuntimeProfiler.class) // obsolete + .addProfiler(GCProfiler.class) // + .addProfiler(SafepointsProfiler.class) // + .detectJvmArgs(); + + optionBuilder = setMeasurementProperties(optionBuilder, forks, measurementIterations, measurementSeconds, + warmUpIterations, warmUpSeconds, threads, modes); + + if (StringUtils.isNotEmpty(jmhArguments)) { + CommandLineOptions cliOptions = new CommandLineOptions(jmhArguments.split("\\s")); + optionBuilder.parent(cliOptions); } - // Reflections reflections = new Reflections("com.gocypher.cybench.", new - // SubTypesScanner(false)); - // Set> allDefaultClasses = - // reflections.getSubTypesOf(Object.class); - // foundBenchmarks = true; - // for (Class classObj : allDefaultClasses) { - // if (!classObj.getName().isEmpty() && - // classObj.getSimpleName().contains("Benchmarks") - // && !classObj.getSimpleName().contains("_")) { - // We do not include any class, because then JMH will discover all benchmarks - // automatically including user defined - // optBuild.include(classObj.getName()); - // tempBenchmark = classObj.getName(); - // LOG.info("tempBenchmark... {}", tempBenchmark); - // securityBuilder.generateSecurityHashForClasses(classObj); - // } - // } - } - - ChainedOptionsBuilder optionBuilder = optBuild.shouldDoGC(true) // - // .addProfiler(HotspotThreadProfiler.class) // obsolete - // .addProfiler(HotspotRuntimeProfiler.class) // obsolete - .addProfiler(GCProfiler.class) // - .addProfiler(SafepointsProfiler.class) // - .detectJvmArgs(); - - optionBuilder = setMeasurementProperties(optionBuilder, forks, measurementIterations, measurementSeconds, - warmUpIterations, warmUpSeconds, threads, modes); - - if (StringUtils.isNotEmpty(jmhArguments)) { - CommandLineOptions cliOptions = new CommandLineOptions(jmhArguments.split("\\s")); - optionBuilder.parent(cliOptions); - } - - Options opt = optionBuilder.build(); - - Runner runner = new Runner(opt); - Collection results = Collections.emptyList(); - if (foundBenchmarks) { - results = runner.run(); - } - - LOG.info("Benchmark finished, executed tests count: {}", results.size()); - - BenchmarkOverviewReport report = ReportingService.getInstance().createBenchmarkReport(results, - defaultBenchmarksMetadata); - // BenchmarkOverviewReport report = - // ReportingService.getInstance().createBenchmarkReport(results); - report.getEnvironmentSettings().put("environment", hwProperties); - report.getEnvironmentSettings().put("jvmEnvironment", jvmProperties); - report.getEnvironmentSettings().put("unclassifiedProperties", - CollectSystemInformation.getUnclassifiedProperties()); - report.getEnvironmentSettings().put("userDefinedProperties", getUserDefinedProperties()); - - if (foundBenchmarks) { - if (System.getProperty(Constants.REPORT_SOURCE) != null) { - benchSource = System.getProperty(Constants.REPORT_SOURCE); + Options opt = optionBuilder.build(); + + Runner runner = new Runner(opt); + Collection results = Collections.emptyList(); + if (foundBenchmarks) { + results = runner.run(); } - benchmarkSetting.put(Constants.REPORT_SOURCE, benchSource); - } - if (getProperty(Constants.BENCHMARK_REPORT_NAME) != null) { - benchmarkSetting.put("benchReportName", getProperty(Constants.BENCHMARK_REPORT_NAME)); - } - - LOG.info("---> benchmarkSetting: {}", benchmarkSetting); - - for (Map.Entry> benchmarksEntry : report.getBenchmarks().entrySet()) { - List benchmarks = benchmarksEntry.getValue(); - benchmarks.forEach(benchmarkReport -> { - String name = benchmarkReport.getName(); - benchmarkReport.setClassFingerprint(classFingerprints.get(name)); - benchmarkReport.setGeneratedFingerprint(generatedFingerprints.get(name)); - benchmarkReport.setManualFingerprint(manualFingerprints.get(name)); - try { - JMHUtils.ClassAndMethod classAndMethod = new JMHUtils.ClassAndMethod(name).invoke(); - String clazz = classAndMethod.getClazz(); - String method = classAndMethod.getMethod(); - LOG.info("Adding metadata for benchmark: " + clazz + " test: " + method); - Class aClass = Class.forName(clazz); - Optional benchmarkMethod = JMHUtils.getBenchmarkMethod(method, aClass); - appendMetadataFromClass(aClass, benchmarkReport); - appendMetadataFromAnnotated(benchmarkMethod, benchmarkReport); - appendMetadataFromJavaDoc(aClass, benchmarkMethod, benchmarkReport); - syncReportsMetadata(report, benchmarkReport); - benchmarkSetting.put(Constants.REPORT_VERSION, getRunnerVersion()); - } catch (ClassNotFoundException e) { - LOG.error("Failed to load class: {}", name); + + LOG.info("Benchmark finished, executed tests count: {}", results.size()); + + BenchmarkOverviewReport report = ReportingService.getInstance().createBenchmarkReport(results, + defaultBenchmarksMetadata); + // BenchmarkOverviewReport report = + // ReportingService.getInstance().createBenchmarkReport(results); + report.getEnvironmentSettings().put("environment", hwProperties); + report.getEnvironmentSettings().put("jvmEnvironment", jvmProperties); + report.getEnvironmentSettings().put("unclassifiedProperties", + CollectSystemInformation.getUnclassifiedProperties()); + report.getEnvironmentSettings().put("userDefinedProperties", getUserDefinedProperties()); + + if (foundBenchmarks) { + if (System.getProperty(Constants.REPORT_SOURCE) != null) { + benchSource = System.getProperty(Constants.REPORT_SOURCE); } - report.setBenchmarkSettings(benchmarkSetting); - }); - } - if (report.getBenchmarks() != null && !report.getBenchmarks().isEmpty()) { - List customBenchmarksCategoryCheck = report.getBenchmarks().get("CUSTOM"); - report.getBenchmarks().remove("CUSTOM"); - if (customBenchmarksCategoryCheck != null) { - for (BenchmarkReport benchReport : customBenchmarksCategoryCheck) { - report.addToBenchmarks(benchReport); + benchmarkSetting.put(Constants.REPORT_SOURCE, benchSource); + } + if (getProperty(Constants.BENCHMARK_REPORT_NAME) != null) { + benchmarkSetting.put("benchReportName", getProperty(Constants.BENCHMARK_REPORT_NAME)); + } + + LOG.info("---> benchmarkSetting: {}", benchmarkSetting); + + for (Map.Entry> benchmarksEntry : report.getBenchmarks().entrySet()) { + List benchmarks = benchmarksEntry.getValue(); + benchmarks.forEach(benchmarkReport -> { + String name = benchmarkReport.getName(); + benchmarkReport.setClassFingerprint(classFingerprints.get(name)); + benchmarkReport.setGeneratedFingerprint(generatedFingerprints.get(name)); + benchmarkReport.setManualFingerprint(manualFingerprints.get(name)); + try { + JMHUtils.ClassAndMethod classAndMethod = new JMHUtils.ClassAndMethod(name).invoke(); + String clazz = classAndMethod.getClazz(); + String method = classAndMethod.getMethod(); + LOG.info("Adding metadata for benchmark: " + clazz + " test: " + method); + Class aClass = Class.forName(clazz); + Optional benchmarkMethod = JMHUtils.getBenchmarkMethod(method, aClass); + appendMetadataFromClass(aClass, benchmarkReport); + appendMetadataFromAnnotated(benchmarkMethod, benchmarkReport); + appendMetadataFromJavaDoc(aClass, benchmarkMethod, benchmarkReport); + syncReportsMetadata(report, benchmarkReport); + benchmarkSetting.put(Constants.REPORT_VERSION, getRunnerVersion()); + } catch (ClassNotFoundException e) { + LOG.error("Failed to load class: {}", name); + } + report.setBenchmarkSettings(benchmarkSetting); + }); + } + if (report.getBenchmarks() != null && !report.getBenchmarks().isEmpty()) { + List customBenchmarksCategoryCheck = report.getBenchmarks().get("CUSTOM"); + report.getBenchmarks().remove("CUSTOM"); + if (customBenchmarksCategoryCheck != null) { + for (BenchmarkReport benchReport : customBenchmarksCategoryCheck) { + report.addToBenchmarks(benchReport); + } } + report.computeScores(); + getReportUploadStatus(report); } - report.computeScores(); - getReportUploadStatus(report); - } - try { - LOG.info("Generating JSON report..."); - String reportJSON; - String reportEncrypted = ReportingService.getInstance().prepareReportForDelivery(securityBuilder, report); - String deviceReports = null; - String resultURL = null; - Map response = new HashMap<>(); - if (shouldSendReport(report)) { - String reportUploadToken = getProperty(Constants.USER_REPORT_TOKEN); - String emailAddress = getProperty(Constants.USER_EMAIL_ADDRESS); - - String tokenAndEmail = ComputationUtils.getRequestHeader(reportUploadToken, emailAddress); - String responseWithUrl = DeliveryService.getInstance().sendReportForStoring(reportEncrypted, - tokenAndEmail); - if (StringUtils.isNotEmpty(responseWithUrl)) { - response = JSONUtils.parseJsonIntoMap(responseWithUrl); + try { + LOG.info("Generating JSON report..."); + String reportJSON; + String reportEncrypted = ReportingService.getInstance().prepareReportForDelivery(securityBuilder, + report); + String deviceReports = null; + String resultURL = null; + Map response = new HashMap<>(); + if (shouldSendReport(report)) { + String reportUploadToken = getProperty(Constants.USER_REPORT_TOKEN); + String emailAddress = getProperty(Constants.USER_EMAIL_ADDRESS); + + String tokenAndEmail = ComputationUtils.getRequestHeader(reportUploadToken, emailAddress); + String responseWithUrl = DeliveryService.getInstance().sendReportForStoring(reportEncrypted, + tokenAndEmail); + if (StringUtils.isNotEmpty(responseWithUrl)) { + response = JSONUtils.parseJsonIntoMap(responseWithUrl); + } + if (!response.isEmpty() && !isErrorResponse(response)) { + deviceReports = String.valueOf(response.get(Constants.REPORT_USER_URL)); + resultURL = String.valueOf(response.get(Constants.REPORT_URL)); + report.setDeviceReportsURL(deviceReports); + report.setReportURL(resultURL); + } + } else { + // LOG.info(REPORT_NOT_SENT, CYB_REPORT_CYB_FILE, Constants.CYB_UPLOAD_URL); } - if (!response.isEmpty() && !isErrorResponse(response)) { - deviceReports = String.valueOf(response.get(Constants.REPORT_USER_URL)); - resultURL = String.valueOf(response.get(Constants.REPORT_URL)); - report.setDeviceReportsURL(deviceReports); - report.setReportURL(resultURL); + // LOG.info("-----------------------------------------------------------------------------------------"); + // LOG.info("REPORT '{}'", report); + // LOG.info("-----------------------------------------------------------------------------------------"); + reportJSON = JSONUtils.marshalToPrettyJson(report); + String cybReportJsonFile = getCybReportFileName(report, CYB_REPORT_JSON_FILE); + String cybReportFile = getCybReportFileName(report, CYB_REPORT_CYB_FILE); + if (cybReportJsonFile.equals(CYB_REPORT_JSON_FILE) && cybReportFile.equals(CYB_REPORT_CYB_FILE)) { + cybReportJsonFile = IOUtils.getReportsPath("", + ComputationUtils.createFileNameForReport("report", start, report.getTotalScore(), false)); + cybReportFile = IOUtils.getReportsPath("", + ComputationUtils.createFileNameForReport("report", start, report.getTotalScore(), true)); } - } else { - // LOG.info(REPORT_NOT_SENT, CYB_REPORT_CYB_FILE, Constants.CYB_UPLOAD_URL); - } - // LOG.info("-----------------------------------------------------------------------------------------"); - // LOG.info("REPORT '{}'", report); - // LOG.info("-----------------------------------------------------------------------------------------"); - reportJSON = JSONUtils.marshalToPrettyJson(report); - String cybReportJsonFile = getCybReportFileName(report, CYB_REPORT_JSON_FILE); - String cybReportFile = getCybReportFileName(report, CYB_REPORT_CYB_FILE); - if (cybReportJsonFile.equals(CYB_REPORT_JSON_FILE) && cybReportFile.equals(CYB_REPORT_CYB_FILE)) { - cybReportJsonFile = IOUtils.getReportsPath("", - ComputationUtils.createFileNameForReport("report", start, report.getTotalScore(), false)); - cybReportFile = IOUtils.getReportsPath("", - ComputationUtils.createFileNameForReport("report", start, report.getTotalScore(), true)); - } - LOG.info("Saving test results to '{}'", cybReportJsonFile); - IOUtils.storeResultsToFile(cybReportJsonFile, reportJSON); - LOG.info("Saving encrypted test results to '{}'", cybReportFile); - IOUtils.storeResultsToFile(cybReportFile, reportEncrypted); - - LOG.info("Removing all temporary auto-generated files...."); - IOUtils.removeTestDataFiles(); - LOG.info("Removed all temporary auto-generated files!!!"); - if (!response.isEmpty() && !isErrorResponse(response)) { - LOG.info("Benchmark report submitted successfully to {}", Constants.REPORT_URL); - LOG.info("You can find all device benchmarks on {}", deviceReports); - LOG.info("Your report is available at {}", resultURL); - LOG.info("NOTE: It may take a few minutes for your report to appear online"); - } else { - String errMsg = getErrorResponseMessage(response); - if (errMsg != null) { - LOG.error("CyBench backend service sent error response: {}", errMsg); + LOG.info("Saving test results to '{}'", cybReportJsonFile); + IOUtils.storeResultsToFile(cybReportJsonFile, reportJSON); + LOG.info("Saving encrypted test results to '{}'", cybReportFile); + IOUtils.storeResultsToFile(cybReportFile, reportEncrypted); + + LOG.info("Removing all temporary auto-generated files...."); + IOUtils.removeTestDataFiles(); + LOG.info("Removed all temporary auto-generated files!!!"); + if (!response.isEmpty() && !isErrorResponse(response)) { + LOG.info("Benchmark report submitted successfully to {}", Constants.REPORT_URL); + LOG.info("You can find all device benchmarks on {}", deviceReports); + LOG.info("Your report is available at {}", resultURL); + LOG.info("NOTE: It may take a few minutes for your report to appear online"); + } else { + String errMsg = getErrorResponseMessage(response); + if (errMsg != null) { + LOG.error("CyBench backend service sent error response: {}", errMsg); + } + LOG.info(REPORT_NOT_SENT, CYB_REPORT_CYB_FILE, Constants.CYB_UPLOAD_URL); } + } catch (Throwable e) { + LOG.error("Failed to save test results", e); LOG.info(REPORT_NOT_SENT, CYB_REPORT_CYB_FILE, Constants.CYB_UPLOAD_URL); } - } catch (Throwable e) { - LOG.error("Failed to save test results", e); - LOG.info(REPORT_NOT_SENT, CYB_REPORT_CYB_FILE, Constants.CYB_UPLOAD_URL); + } catch (MissingResourceException exc) { } LOG.info("-----------------------------------------------------------------------------------------"); @@ -743,7 +747,7 @@ public static void printGCStats() { * metadata property name * @return metadata property value */ - public static String getMetadataFromBuildFile(String prop) { + public static String getMetadataFromBuildFile(String prop) throws MissingResourceException { String property = ""; String userDir = System.getProperty("user.dir"); File gradle = new File(userDir + "/build.gradle"); @@ -764,7 +768,7 @@ public static String getMetadataFromBuildFile(String prop) { return property; } - private static String getMetadataFromMaven(String prop) { + private static String getMetadataFromMaven(String prop) throws MissingResourceException { String property = ""; String userDir = System.getProperty("user.dir"); File pom = new File(userDir + "/pom.xml"); @@ -796,7 +800,7 @@ private static String getMetadataFromMaven(String prop) { return property; } - private static String getMetadataFromGradle(String prop) { + private static String getMetadataFromGradle(String prop) throws MissingResourceException { // LOG.info("* Gradle project detected, grabbing missing metadata from gradle build files"); // LOG.info("* Checking for Groovy or Kotlin style build instructions"); String property = ""; @@ -827,7 +831,8 @@ private static String getMetadataFromGradle(String prop) { return property; } - private static String getGradleProperty(String prop, String dir, String... cfgFiles) { + private static String getGradleProperty(String prop, String dir, String... cfgFiles) + throws MissingResourceException { if (prop == "artifactId") { prop = "PROJECT_ARTIFACT"; } else { @@ -896,7 +901,7 @@ private static boolean isPropUnspecified(String prop) { return StringUtils.isBlank(prop) || "unspecified".equals(prop); } - public static void failBuildFromMissingMetadata(String metadata) { + public static void failBuildFromMissingMetadata(String metadata) throws MissingResourceException { LOG.error("* ===[Build failed from lack of metadata: (" + metadata + ")]==="); LOG.error("* CyBench runner is unable to continue due to missing crucial metadata."); if (metadata.contains("Version")) { @@ -919,7 +924,8 @@ public static void failBuildFromMissingMetadata(String metadata) { LOG.info("* 'class.version='\n"); LOG.warn("* For more information and instructions on this process, please visit the CyBench wiki at " + "https://github.com/K2NIO/gocypher-cybench-java/wiki/Getting-started-with-CyBench-annotations"); - // System.exit(1); + + throw new MissingResourceException("Missing project metadata configuration", null, null); } else if (metadata.contains("Project")) { LOG.error("* Project name metadata was unable to be processed."); LOG.warn("* Project name can be set or parsed dynamically a few different ways: \n"); @@ -940,11 +946,12 @@ public static void failBuildFromMissingMetadata(String metadata) { LOG.info("*** 'class.project='\n"); LOG.warn("* For more information and instructions on this process, please visit the CyBench wiki at " + "https://github.com/K2NIO/gocypher-cybench-java/wiki/Getting-started-with-CyBench-annotations"); - // System.exit(1); + + throw new MissingResourceException("Missing project metadata configuration", null, null); } } - public static void failBuildFromMissingMavenMetadata() { + public static void failBuildFromMissingMavenMetadata() throws MissingResourceException { LOG.error("* ===[Build failed from lack of metadata]==="); LOG.error("* CyBench runner is unable to continue due to missing crucial metadata."); LOG.error("* Error while parsing Maven project's 'pom.xml' file."); @@ -952,6 +959,7 @@ public static void failBuildFromMissingMavenMetadata() { LOG.error("* Refer to the exception thrown for reasons why the .xml file was unable to be parsed."); LOG.warn("* For more information on CyBench metadata (setting it, how it is used, etc.), please visit the CyBench wiki at " + "https://github.com/K2NIO/gocypher-cybench-java/wiki/Getting-started-with-CyBench-annotations"); - // System.exit(1); + + throw new MissingResourceException("Missing project metadata configuration", null, null); } }