diff options
Diffstat (limited to 'asdctool/src/main/java')
5 files changed, 55 insertions, 56 deletions
diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/config/ValidationConfigManager.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/config/ValidationConfigManager.java index ea0bbf33a9..3c09a54735 100644 --- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/config/ValidationConfigManager.java +++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/config/ValidationConfigManager.java @@ -24,14 +24,24 @@ package org.openecomp.sdc.asdctool.impl.validator.config; +import java.util.function.Supplier; + public class ValidationConfigManager { + private static final String CSV_FILE_PREFIX = "/csvSummary_"; + private static final String CSV_EXT = ".csv"; + public static final String DEFAULT_CSV_PATH = "summary.csv"; + private static String outputFullFilePath; private static String outputFilePath; private ValidationConfigManager() { } + public static String csvReportFilePath(String outputPath, Supplier<Long> getTime) { + return outputPath + CSV_FILE_PREFIX + getTime.get() + CSV_EXT; + } + public static String getOutputFullFilePath() { return outputFullFilePath; } @@ -44,15 +54,4 @@ public class ValidationConfigManager { ValidationConfigManager.outputFilePath = outputPath; ValidationConfigManager.outputFullFilePath = outputPath + "/reportOutput.txt"; } - - public static String getCsvReportFilePath() { - return csvReportFilePath; - } - - public static void setCsvReportFilePath(String outputPath) { - ValidationConfigManager.csvReportFilePath = - outputPath + "/csvSummary_" + System.currentTimeMillis() + ".csv"; - } - - private static String csvReportFilePath = "summary.csv"; } diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/config/ValidationToolConfiguration.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/config/ValidationToolConfiguration.java index b83417c6c1..7afb4ed001 100644 --- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/config/ValidationToolConfiguration.java +++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/config/ValidationToolConfiguration.java @@ -131,9 +131,6 @@ public class ValidationToolConfiguration { return new VfValidatorExecuter(tasks, janusGraphDao); } - @Bean - public ReportManager reportManager() { return new ReportManager();} - @Bean(name = "artifact-cassandra-dao") public ArtifactCassandraDao artifactCassandraDao(CassandraClient cassandraClient) { return new ArtifactCassandraDao(cassandraClient); diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/utils/ReportManager.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/utils/ReportManager.java index e575ffce24..feef9eaf01 100644 --- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/utils/ReportManager.java +++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/utils/ReportManager.java @@ -37,23 +37,22 @@ import java.util.Map; import java.util.Optional; import java.util.Set; -/** - * Created by chaya on 7/5/2017. - */ public class ReportManager { private static Logger log = LoggerFactory.getLogger(ReportManager.class); private static String reportOutputFilePath; - private static String csvReportFilePath; - private static Map<String, Set<String>> failedVerticesPerTask = new HashMap<>(); - private static Map<String, Map<String, VertexResult>> resultsPerVertex = new HashMap<>(); + private static final Map<String, Set<String>> failedVerticesPerTask = new HashMap<>(); + private static final Map<String, Map<String, VertexResult>> resultsPerVertex = new HashMap<>(); + + public static ReportManager make(String csvReportFilePath) { + return new ReportManager(csvReportFilePath); + } - public ReportManager() { + private ReportManager(String csvReportFilePath) { try { - initCsvFile(); + initCsvFile(csvReportFilePath); initReportFile(); } catch (IOException e) { - e.printStackTrace(); log.info("Init file failed - {}", e.getClass().getSimpleName(), e); } } @@ -65,8 +64,7 @@ public class ReportManager { Files.write(Paths.get(reportOutputFilePath), sb.toString().getBytes()); } - private void initCsvFile() throws IOException { - csvReportFilePath = ValidationConfigManager.getCsvReportFilePath(); + private void initCsvFile(String csvReportFilePath) throws IOException { StrBuilder sb = new StrBuilder(); sb.append("Vertex ID,Task Name,Success,Result Details,Result Description"); sb.appendNewLine(); @@ -75,12 +73,12 @@ public class ReportManager { public static void reportTaskEnd(String vertexId, String taskName, VertexResult result) { Map<String, VertexResult> vertexTasksResults = - Optional.ofNullable(resultsPerVertex.get(vertexId)).orElse(new HashMap<>()); + Optional.ofNullable(resultsPerVertex.get(vertexId)).orElse(new HashMap<>()); vertexTasksResults.put(taskName, result); resultsPerVertex.put(vertexId, vertexTasksResults); } - public static void addFailedVertex (String taskName, String vertexId) { + public static void addFailedVertex(String taskName, String vertexId) { Set<String> failedVertices = failedVerticesPerTask.get(taskName); if (failedVertices == null) { failedVertices = new HashSet<>(); @@ -91,7 +89,9 @@ public class ReportManager { public static void printValidationTaskStatus(GraphVertex vertexScanned, String taskName, boolean success) { String successStatus = success ? "success" : "failed"; - String line = "-----------------------Vertex: "+vertexScanned.getUniqueId()+", Task " + taskName + " " +successStatus+"-----------------------"; + String line = + "-----------------------Vertex: " + vertexScanned.getUniqueId() + ", Task " + taskName + " " + successStatus + + "-----------------------"; StrBuilder sb = new StrBuilder(); sb.appendln(line); writeReportLineToFile(line); @@ -99,35 +99,39 @@ public class ReportManager { public static void writeReportLineToFile(String message) { try { - Files.write(Paths.get(reportOutputFilePath), new StrBuilder().appendNewLine().toString().getBytes(), StandardOpenOption.APPEND); + Files.write(Paths.get(reportOutputFilePath), new StrBuilder().appendNewLine().toString().getBytes(), + StandardOpenOption.APPEND); Files.write(Paths.get(reportOutputFilePath), message.getBytes(), StandardOpenOption.APPEND); } catch (IOException e) { - e.printStackTrace(); log.info("write to file failed - {}", e.getClass().getSimpleName(), e); } } - public static void reportValidatorTypeSummary(String validatorName, Set<String> failedTasksNames, Set<String> successTasksNames){ + public static void reportValidatorTypeSummary(String validatorName, Set<String> failedTasksNames, + Set<String> successTasksNames) { StrBuilder sb = new StrBuilder(); - sb.appendln("-----------------------ValidatorExecuter " + validatorName + " Validation Summary-----------------------"); - sb.appendln("Failed tasks: "+ failedTasksNames); - sb.appendln("Success tasks: "+ successTasksNames); + sb.appendln( + "-----------------------ValidatorExecuter " + validatorName + " Validation Summary-----------------------"); + sb.appendln("Failed tasks: " + failedTasksNames); + sb.appendln("Success tasks: " + successTasksNames); writeReportLineToFile(sb.toString()); } public static void reportStartValidatorRun(String validatorName, int componenentsNum) { StrBuilder sb = new StrBuilder(); - sb.appendln("------ValidatorExecuter " + validatorName + " Validation Started, on "+componenentsNum+" components---------"); + sb.appendln("------ValidatorExecuter " + validatorName + " Validation Started, on " + componenentsNum + + " components---------"); writeReportLineToFile(sb.toString()); } - public static void reportStartTaskRun(GraphVertex vertex, String taskName){ + public static void reportStartTaskRun(GraphVertex vertex, String taskName) { StrBuilder sb = new StrBuilder(); - sb.appendln("-----------------------Vertex: "+vertex.getUniqueId()+", Task " + taskName + " Started-----------------------"); + sb.appendln("-----------------------Vertex: " + vertex.getUniqueId() + ", Task " + taskName + + " Started-----------------------"); writeReportLineToFile(sb.toString()); } - public static void reportEndOfToolRun() { + public static void reportEndOfToolRun(String csvReportFilePath) { StrBuilder sb = new StrBuilder(); sb.appendln("-----------------------------------Validator Tool Summary-----------------------------------"); failedVerticesPerTask.forEach((taskName, failedVertices) -> { @@ -137,10 +141,10 @@ public class ReportManager { sb.appendNewLine(); }); writeReportLineToFile(sb.toString()); - printAllResults(); + printAllResults(csvReportFilePath); } - public static void printAllResults() { + public static void printAllResults(String csvReportFilePath) { resultsPerVertex.forEach((vertex, tasksResults) -> tasksResults.forEach((task, result) -> { try { String resultLine = vertex + "," + task + "," + result.getStatus() + "," + result.getResult(); @@ -150,7 +154,6 @@ public class ReportManager { new StrBuilder().appendNewLine().toString().getBytes(), StandardOpenOption.APPEND); } catch (IOException e) { - e.printStackTrace(); log.info("write to file failed - {}", e.getClass().getSimpleName(), e); } })); diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/main/ArtifactValidatorTool.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/main/ArtifactValidatorTool.java index c85385b454..063f3f6a29 100644 --- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/main/ArtifactValidatorTool.java +++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/main/ArtifactValidatorTool.java @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -28,12 +28,11 @@ import org.springframework.context.annotation.AnnotationConfigApplicationContext public class ArtifactValidatorTool { - public static void main(String[] args) { + public static void main(String[] args) { String outputPath = args[0]; ValidationConfigManager.setOutputFullFilePath(outputPath); - ValidationConfigManager.setCsvReportFilePath(outputPath); - + String appConfigDir = args[1]; AnnotationConfigApplicationContext context = initContext(appConfigDir); ArtifactToolBL validationToolBL = context.getBean(ArtifactToolBL.class); @@ -47,12 +46,13 @@ public class ArtifactValidatorTool { System.out.println("ArtifactValidation finished with warnings"); System.exit(2); } - } - - private static AnnotationConfigApplicationContext initContext(String appConfigDir) { - ConfigurationUploader.uploadConfigurationFiles(appConfigDir); - AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(ValidationToolConfiguration.class); - return context; - } + } + + private static AnnotationConfigApplicationContext initContext(String appConfigDir) { + ConfigurationUploader.uploadConfigurationFiles(appConfigDir); + AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext( + ValidationToolConfiguration.class); + return context; + } } diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/main/ValidationTool.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/main/ValidationTool.java index 25efc9ac68..23b9c18d3f 100644 --- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/main/ValidationTool.java +++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/main/ValidationTool.java @@ -42,15 +42,15 @@ public class ValidationTool { String outputPath = args[0]; ValidationConfigManager.setOutputFullFilePath(outputPath); - ValidationConfigManager.setCsvReportFilePath(outputPath); + String csvReportFilePath = ValidationConfigManager.csvReportFilePath(outputPath, System::currentTimeMillis); String appConfigDir = args[1]; AnnotationConfigApplicationContext context = initContext(appConfigDir); ValidationToolBL validationToolBL = context.getBean(ValidationToolBL.class); log.info("Start Validation Tool"); - Boolean result = validationToolBL.validateAll(); - ReportManager.reportEndOfToolRun(); + boolean result = validationToolBL.validateAll(); + ReportManager.reportEndOfToolRun(csvReportFilePath); if (result) { log.info("Validation finished successfully"); System.exit(0); |