diff options
Diffstat (limited to 'asdctool/src/main/java')
9 files changed, 65 insertions, 33 deletions
diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/ValidationToolBL.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/ValidationToolBL.java index 6347e34558..61b3640d7d 100644 --- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/ValidationToolBL.java +++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/ValidationToolBL.java @@ -22,6 +22,7 @@ package org.openecomp.sdc.asdctool.impl.validator; import org.openecomp.sdc.asdctool.impl.validator.executers.ValidatorExecuter; import org.openecomp.sdc.asdctool.impl.validator.report.Report; +import org.openecomp.sdc.asdctool.impl.validator.report.ReportFile; import org.openecomp.sdc.common.log.wrappers.Logger; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @@ -31,7 +32,7 @@ import java.util.List; @Component public class ValidationToolBL { - private static Logger log = Logger.getLogger(ValidationToolBL.class.getName()); + private static final Logger log = Logger.getLogger(ValidationToolBL.class); protected List<ValidatorExecuter> validators; @@ -43,10 +44,10 @@ public class ValidationToolBL { this.validators = validators; } - public boolean validateAll(Report report, String outputFilePath) { + public boolean validateAll(Report report, ReportFile.TXTFile textFile, String outputFilePath) { for (ValidatorExecuter validatorExec: validators) { log.debug("ValidatorExecuter "+validatorExec.getName()+" started"); - if (!validatorExec.executeValidations(report, outputFilePath)) { + if (!validatorExec.executeValidations(report, textFile, outputFilePath)) { allValid = false; log.debug("ValidatorExecuter "+validatorExec.getName()+" finished with warnings"); } diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/ServiceValidatorExecuter.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/ServiceValidatorExecuter.java index 4bcdeaf1d7..af9cb3634c 100644 --- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/ServiceValidatorExecuter.java +++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/ServiceValidatorExecuter.java @@ -21,6 +21,7 @@ package org.openecomp.sdc.asdctool.impl.validator.executers; import org.openecomp.sdc.asdctool.impl.validator.report.Report; +import org.openecomp.sdc.asdctool.impl.validator.report.ReportFile.TXTFile; import org.openecomp.sdc.asdctool.impl.validator.tasks.ServiceValidationTask; import org.openecomp.sdc.be.dao.jsongraph.GraphVertex; import org.openecomp.sdc.be.dao.jsongraph.JanusGraphDao; @@ -43,13 +44,8 @@ public class ServiceValidatorExecuter extends TopologyTemplateValidatorExecuter } @Override - public boolean executeValidations(Report report, String outputFilePath) { + public boolean executeValidations(Report report, TXTFile reportFile, String outputFilePath) { List<GraphVertex> vertices = getVerticesToValidate(ComponentTypeEnum.SERVICE); - return validate(report, tasks, vertices, outputFilePath); - } - - @Override - public String getName() { - return super.getName(); + return validate(report, tasks, vertices, reportFile, outputFilePath); } } diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/TopologyTemplateValidatorExecuter.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/TopologyTemplateValidatorExecuter.java index 0c1e3bec5a..d6a5d12a25 100644 --- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/TopologyTemplateValidatorExecuter.java +++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/TopologyTemplateValidatorExecuter.java @@ -22,6 +22,7 @@ package org.openecomp.sdc.asdctool.impl.validator.executers; import fj.data.Either; import org.openecomp.sdc.asdctool.impl.validator.report.Report; +import org.openecomp.sdc.asdctool.impl.validator.report.ReportFile.TXTFile; import org.openecomp.sdc.asdctool.impl.validator.tasks.TopologyTemplateValidationTask; import org.openecomp.sdc.asdctool.impl.validator.utils.ReportManager; import org.openecomp.sdc.asdctool.impl.validator.utils.VertexResult; @@ -44,7 +45,7 @@ import java.util.Set; public class TopologyTemplateValidatorExecuter { - private static Logger log = Logger.getLogger(VfValidatorExecuter.class.getName()); + private static final Logger log = Logger.getLogger(VfValidatorExecuter.class); protected JanusGraphDao janusGraphDao; @@ -80,8 +81,13 @@ public class TopologyTemplateValidatorExecuter { return results.left().value(); } - protected boolean validate(Report report, List<? extends TopologyTemplateValidationTask> tasks, List<GraphVertex> vertices, - String outputFilePath) { + protected boolean validate( + Report report, + List<? extends TopologyTemplateValidationTask> tasks, + List<GraphVertex> vertices, + TXTFile reportFile, + String outputFilePath + ) { ReportManager.reportStartValidatorRun(getName(), vertices.size(), outputFilePath); Set<String> failedTasks = new HashSet<>(); Set<String> successTasks = new HashSet<>(); @@ -93,7 +99,7 @@ public class TopologyTemplateValidatorExecuter { vertexNum++; boolean successAllTasks = true; for (TopologyTemplateValidationTask task : tasks) { - ReportManager.reportStartTaskRun(vertex, task.getTaskName(), outputFilePath); + reportFile.reportStartTaskRun(vertex, task.getTaskName()); VertexResult result = task.validate(report, vertex, outputFilePath); if (!result.getStatus()) { failedTasks.add(task.getTaskName()); diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/ValidatorExecuter.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/ValidatorExecuter.java index 7d5314c1c5..88b7c0c64a 100644 --- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/ValidatorExecuter.java +++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/ValidatorExecuter.java @@ -21,9 +21,10 @@ package org.openecomp.sdc.asdctool.impl.validator.executers; import org.openecomp.sdc.asdctool.impl.validator.report.Report; +import org.openecomp.sdc.asdctool.impl.validator.report.ReportFile.TXTFile; public interface ValidatorExecuter { - boolean executeValidations(Report report, String outputFilePath); + boolean executeValidations(Report report, TXTFile textFile, String outputFilePath); String getName(); } diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/VfValidatorExecuter.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/VfValidatorExecuter.java index 5c42637d52..3484bbf8dc 100644 --- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/VfValidatorExecuter.java +++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/VfValidatorExecuter.java @@ -21,6 +21,7 @@ package org.openecomp.sdc.asdctool.impl.validator.executers; import org.openecomp.sdc.asdctool.impl.validator.report.Report; +import org.openecomp.sdc.asdctool.impl.validator.report.ReportFile.TXTFile; import org.openecomp.sdc.asdctool.impl.validator.tasks.VfValidationTask; import org.openecomp.sdc.be.dao.jsongraph.GraphVertex; import org.openecomp.sdc.be.dao.jsongraph.JanusGraphDao; @@ -41,13 +42,8 @@ public class VfValidatorExecuter extends TopologyTemplateValidatorExecuter imple } @Override - public boolean executeValidations(Report report, String outputFilePath) { + public boolean executeValidations(Report report, TXTFile reportFile, String outputFilePath) { List<GraphVertex> vertices = getVerticesToValidate(ComponentTypeEnum.RESOURCE); - return validate(report, tasks, vertices, outputFilePath); - } - - @Override - public String getName() { - return super.getName(); + return validate(report, tasks, vertices, reportFile, outputFilePath); } } diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/report/FileType.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/report/FileType.java index 7598ae1bb8..6ce07912dd 100644 --- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/report/FileType.java +++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/report/FileType.java @@ -25,5 +25,7 @@ package org.openecomp.sdc.asdctool.impl.validator.report; * a {@link org.openecomp.sdc.asdctool.impl.validator.report.ReportFileWriter }. */ public interface FileType { + interface TXT extends FileType { } + interface CSV extends FileType { } } diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/report/ReportFile.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/report/ReportFile.java index a0703f47e7..8b767662ee 100644 --- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/report/ReportFile.java +++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/report/ReportFile.java @@ -20,11 +20,23 @@ package org.openecomp.sdc.asdctool.impl.validator.report; +import org.openecomp.sdc.be.dao.jsongraph.GraphVertex; + /** * Provides business logic in regards to file writing required by the validation tools */ public class ReportFile { + // TODO: Delete this function once all the report file business logic has been moved to ReportFile + static public TXTFile makeAppendableTxtFile(ReportFileWriter<FileType.TXT> writer) { + return new TXTFile(writer); + } + + static public TXTFile makeTxtFile(ReportFileWriter<FileType.TXT> writer) { + writer.writeln("-----------------------Validation Tool Results:-------------------------"); + return new TXTFile(writer); + } + static public CSVFile makeCsvFile(ReportFileWriter<FileType.CSV> writer) { writer.writeln("Vertex ID,Task Name,Success,Result Details,Result Description"); return new CSVFile(writer); @@ -33,6 +45,24 @@ public class ReportFile { /** * Provides csv writing business logic related to {@link org.openecomp.sdc.asdctool.main.ValidationTool} */ + public static final class TXTFile extends ReportFile { + + private final ReportFileWriter<FileType.TXT> writer; + + private TXTFile(ReportFileWriter<FileType.TXT> writer) { + this.writer = writer; + } + + public void reportStartTaskRun(GraphVertex vertex, String taskName) { + writer.writeln(""); + writer.writeln("-----------------------Vertex: " + vertex.getUniqueId() + + ", Task " + taskName + " Started-----------------------"); + } + } + + /** + * Provides csv writing business logic related to {@link org.openecomp.sdc.asdctool.main.ValidationTool} + */ public static final class CSVFile extends ReportFile { private final ReportFileWriter<FileType.CSV> writer; 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 5b78df8c73..6e8e2de64a 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 @@ -23,6 +23,7 @@ package org.openecomp.sdc.asdctool.impl.validator.utils; import java.io.IOException; import java.nio.file.Files; +import java.nio.file.Path; import java.nio.file.Paths; import java.nio.file.StandardOpenOption; import java.util.Set; @@ -49,9 +50,13 @@ public class ReportManager { } private void initReportFile(String txtReportFilePath) throws IOException { - StrBuilder sb = new StrBuilder(); - sb.appendln("-----------------------Validation Tool Results:-------------------------"); - Files.write(Paths.get(txtReportFilePath), sb.toString().getBytes()); + Path path = Paths.get(txtReportFilePath); + // TODO: Remove this once all the report file business logic has been moved to ReportFile + if(Files.notExists(path)) { + StrBuilder sb = new StrBuilder(); + sb.appendln("-----------------------Validation Tool Results:-------------------------"); + Files.write(path, sb.toString().getBytes()); + } } public static void printValidationTaskStatus(GraphVertex vertexScanned, String taskName, boolean success, @@ -92,13 +97,6 @@ public class ReportManager { writeReportLineToFile(sb.toString(), outputFilePath); } - public static void reportStartTaskRun(GraphVertex vertex, String taskName, String outputFilePath) { - StrBuilder sb = new StrBuilder(); - sb.appendln("-----------------------Vertex: " + vertex.getUniqueId() + ", Task " + taskName - + " Started-----------------------"); - writeReportLineToFile(sb.toString(), outputFilePath); - } - public static void reportEndOfToolRun(Report report, String outputFilePath) { StrBuilder sb = new StrBuilder(); sb.appendln("-----------------------------------Validator Tool Summary-----------------------------------"); 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 754d163e77..d84f0a5d69 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 @@ -29,6 +29,7 @@ import org.openecomp.sdc.asdctool.impl.validator.report.FileType; import org.openecomp.sdc.asdctool.impl.validator.report.Report; import org.openecomp.sdc.asdctool.impl.validator.report.ReportFile; import org.openecomp.sdc.asdctool.impl.validator.report.ReportFile.CSVFile; +import org.openecomp.sdc.asdctool.impl.validator.report.ReportFile.TXTFile; import org.openecomp.sdc.asdctool.impl.validator.report.ReportFileWriter; import org.openecomp.sdc.asdctool.impl.validator.utils.ReportManager; import org.openecomp.sdc.be.config.ConfigurationManager; @@ -49,6 +50,7 @@ public class ValidationTool { String csvReportFilePath = ValidationConfigManager.csvReportFilePath(outputPath, System::currentTimeMillis); CSVFile csvFile = ReportFile.makeCsvFile(makeNioWriter(Paths.get(csvReportFilePath))); + TXTFile textFile = ReportFile.makeTxtFile(makeNioWriter(Paths.get(txtReportFilePath))); String appConfigDir = args[1]; AnnotationConfigApplicationContext context = initContext(appConfigDir); @@ -56,7 +58,7 @@ public class ValidationTool { log.info("Start Validation Tool"); Report report = Report.make(); - boolean result = validationToolBL.validateAll(report, txtReportFilePath); + boolean result = validationToolBL.validateAll(report, textFile, txtReportFilePath); ReportManager.reportEndOfToolRun(report, txtReportFilePath); csvFile.printAllResults(report); if (result) { |