diff options
22 files changed, 197 insertions, 113 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 c73e4d4c03..6347e34558 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 @@ -21,15 +21,13 @@ 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.common.log.wrappers.Logger; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import java.util.List; -/** - * Created by chaya on 7/3/2017. - */ @Component public class ValidationToolBL { @@ -45,10 +43,10 @@ public class ValidationToolBL { this.validators = validators; } - public boolean validateAll(String outputFilePath) { + public boolean validateAll(Report report, String outputFilePath) { for (ValidatorExecuter validatorExec: validators) { log.debug("ValidatorExecuter "+validatorExec.getName()+" started"); - if (!validatorExec.executeValidations(outputFilePath)) { + if (!validatorExec.executeValidations(report, 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 6d580d0bb4..4bcdeaf1d7 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 @@ -20,6 +20,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.tasks.ServiceValidationTask; import org.openecomp.sdc.be.dao.jsongraph.GraphVertex; import org.openecomp.sdc.be.dao.jsongraph.JanusGraphDao; @@ -30,9 +31,6 @@ import org.springframework.stereotype.Component; import java.util.ArrayList; import java.util.List; -/** - * Created by chaya on 7/4/2017. - */ @Component public class ServiceValidatorExecuter extends TopologyTemplateValidatorExecuter implements ValidatorExecuter { @@ -45,9 +43,9 @@ public class ServiceValidatorExecuter extends TopologyTemplateValidatorExecuter } @Override - public boolean executeValidations(String outputFilePath) { + public boolean executeValidations(Report report, String outputFilePath) { List<GraphVertex> vertices = getVerticesToValidate(ComponentTypeEnum.SERVICE); - return validate(tasks, vertices, outputFilePath); + return validate(report, tasks, vertices, outputFilePath); } @Override 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 b7195dec09..0c1e3bec5a 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 @@ -21,6 +21,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.tasks.TopologyTemplateValidationTask; import org.openecomp.sdc.asdctool.impl.validator.utils.ReportManager; import org.openecomp.sdc.asdctool.impl.validator.utils.VertexResult; @@ -41,9 +42,6 @@ import java.util.List; import java.util.Map; import java.util.Set; -/** - * Created by chaya on 7/3/2017. - */ public class TopologyTemplateValidatorExecuter { private static Logger log = Logger.getLogger(VfValidatorExecuter.class.getName()); @@ -82,7 +80,7 @@ public class TopologyTemplateValidatorExecuter { return results.left().value(); } - protected boolean validate(List<? extends TopologyTemplateValidationTask> tasks, List<GraphVertex> vertices, + protected boolean validate(Report report, List<? extends TopologyTemplateValidationTask> tasks, List<GraphVertex> vertices, String outputFilePath) { ReportManager.reportStartValidatorRun(getName(), vertices.size(), outputFilePath); Set<String> failedTasks = new HashSet<>(); @@ -96,7 +94,7 @@ public class TopologyTemplateValidatorExecuter { boolean successAllTasks = true; for (TopologyTemplateValidationTask task : tasks) { ReportManager.reportStartTaskRun(vertex, task.getTaskName(), outputFilePath); - VertexResult result = task.validate(vertex, outputFilePath); + VertexResult result = task.validate(report, vertex, outputFilePath); if (!result.getStatus()) { failedTasks.add(task.getTaskName()); successAllVertices = false; @@ -105,7 +103,7 @@ public class TopologyTemplateValidatorExecuter { successTasks.add(task.getTaskName()); } ReportManager.printValidationTaskStatus(vertex, task.getTaskName(), result.getStatus(), outputFilePath); - ReportManager.reportTaskEnd(vertex.getUniqueId(), task.getTaskName(), result); + report.addSuccess(vertex.getUniqueId(), task.getTaskName(), result); } String componentScanStatus = successAllTasks ? "success" : "failed"; log.info("Topology Template " + vertex.getUniqueId() + " Validation finished with " + componentScanStatus); 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 db41cb57a8..7d5314c1c5 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 @@ -20,11 +20,10 @@ package org.openecomp.sdc.asdctool.impl.validator.executers; -/** - * Created by chaya on 7/3/2017. - */ +import org.openecomp.sdc.asdctool.impl.validator.report.Report; + public interface ValidatorExecuter { - boolean executeValidations(String outputFilePath); + boolean executeValidations(Report report, 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 dc4ebabf5c..5c42637d52 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 @@ -20,6 +20,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.tasks.VfValidationTask; import org.openecomp.sdc.be.dao.jsongraph.GraphVertex; import org.openecomp.sdc.be.dao.jsongraph.JanusGraphDao; @@ -28,9 +29,6 @@ import org.springframework.beans.factory.annotation.Autowired; import java.util.List; -/** - * Created by chaya on 7/3/2017. - */ public class VfValidatorExecuter extends TopologyTemplateValidatorExecuter implements ValidatorExecuter { private List<VfValidationTask> tasks; @@ -43,9 +41,9 @@ public class VfValidatorExecuter extends TopologyTemplateValidatorExecuter imple } @Override - public boolean executeValidations(String outputFilePath) { + public boolean executeValidations(Report report, String outputFilePath) { List<GraphVertex> vertices = getVerticesToValidate(ComponentTypeEnum.RESOURCE); - return validate(tasks, vertices, outputFilePath); + return validate(report, tasks, vertices, outputFilePath); } @Override diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/report/Report.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/report/Report.java new file mode 100644 index 0000000000..68d7210e81 --- /dev/null +++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/report/Report.java @@ -0,0 +1,100 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdc.asdctool.impl.validator.report; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Optional; +import java.util.Set; +import java.util.function.BiFunction; +import java.util.function.Function; +import java.util.function.Supplier; +import org.openecomp.sdc.asdctool.impl.validator.utils.VertexResult; + +public final class Report { + + private final Map<String, Set<String>> failedVerticesPerTask = new HashMap<>(); + private final Map<String, Map<String, VertexResult>> resultsPerVertex = new HashMap<>(); + + public static Report make() { + return new Report(); + } + + private Report() { + } + + public void addFailure(String taskName, String vertexId) { + Set<String> failedVertices = + get(failedVerticesPerTask, HashSet::new).apply(taskName); + + put(failedVerticesPerTask).apply(taskName, + add(failedVertices).apply(vertexId)); + } + + public void addSuccess(String vertexId, String taskName, VertexResult result) { + Map<String, VertexResult> vertexTasksResults = + get(resultsPerVertex, HashMap::new).apply(vertexId); + + put(resultsPerVertex).apply(vertexId, + put(vertexTasksResults).apply(taskName, result)); + } + + public void forEachFailure(FailureConsumer c) { + failedVerticesPerTask.forEach(c::traverse); + } + + @FunctionalInterface + public interface FailureConsumer { + + void traverse(String taskName, Set<String> failedVertices); + } + + public void forEachSuccess(SuccessConsumer p) { + resultsPerVertex.forEach((vertex, tasksResults) -> + tasksResults.forEach((task, result) -> + p.traverse(vertex, task, result))); + } + + @FunctionalInterface + public interface SuccessConsumer { + + void traverse(String vertex, String task, VertexResult result); + } + + <K, V> Function<K, V> get(Map<K, V> kvs, Supplier<V> fallback) { + return k -> Optional.ofNullable(kvs.get(k)).orElseGet(fallback); + } + + <V> Function<V, Set<V>> add(Set<V> vs) { + return v -> { + vs.add(v); + return vs; + }; + } + + <K, V> BiFunction<K, V, Map<K, V>> put(Map<K, V> kvs) { + return (k, v) -> { + kvs.put(k, v); + return kvs; + }; + } +} diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/tasks/TopologyTemplateValidationTask.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/tasks/TopologyTemplateValidationTask.java index 576848dcdc..f50e552970 100644 --- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/tasks/TopologyTemplateValidationTask.java +++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/tasks/TopologyTemplateValidationTask.java @@ -20,14 +20,12 @@ package org.openecomp.sdc.asdctool.impl.validator.tasks; +import org.openecomp.sdc.asdctool.impl.validator.report.Report; import org.openecomp.sdc.asdctool.impl.validator.utils.VertexResult; import org.openecomp.sdc.be.dao.jsongraph.GraphVertex; -/** - * Created by chaya on 7/5/2017. - */ public interface TopologyTemplateValidationTask { - VertexResult validate(GraphVertex vertex, String outputFilePath); + VertexResult validate(Report report, GraphVertex vertex, String outputFilePath); String getTaskName(); String getTaskResultStatus(); void setTaskResultStatus(String status); diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/tasks/VfValidationTask.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/tasks/VfValidationTask.java index 0434704e8e..76e5952cc7 100644 --- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/tasks/VfValidationTask.java +++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/tasks/VfValidationTask.java @@ -20,9 +20,6 @@ package org.openecomp.sdc.asdctool.impl.validator.tasks; -/** - * Created by chaya on 7/5/2017. - */ public abstract class VfValidationTask implements TopologyTemplateValidationTask { protected String taskStatus = "NOT_STARTED"; protected String name = ""; diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/tasks/artifacts/ArtifactValidationUtils.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/tasks/artifacts/ArtifactValidationUtils.java index 6da79cf681..428b6606a6 100644 --- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/tasks/artifacts/ArtifactValidationUtils.java +++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/tasks/artifacts/ArtifactValidationUtils.java @@ -22,6 +22,7 @@ package org.openecomp.sdc.asdctool.impl.validator.tasks.artifacts; import fj.data.Either; +import org.openecomp.sdc.asdctool.impl.validator.report.Report; import org.openecomp.sdc.asdctool.impl.validator.utils.ReportManager; import org.openecomp.sdc.be.dao.cassandra.ArtifactCassandraDao; import org.openecomp.sdc.be.dao.cassandra.CassandraOperationStatus; @@ -60,7 +61,7 @@ public class ArtifactValidationUtils { this.topologyTemplateOperation = topologyTemplateOperation; } - public ArtifactsVertexResult validateArtifactsAreInCassandra(GraphVertex vertex, String taskName, + public ArtifactsVertexResult validateArtifactsAreInCassandra(Report report, GraphVertex vertex, String taskName, List<ArtifactDataDefinition> artifacts, String outputFilePath) { ArtifactsVertexResult result = new ArtifactsVertexResult(true); for (ArtifactDataDefinition artifact : artifacts) { @@ -69,7 +70,7 @@ public class ArtifactValidationUtils { "Artifact " + artifact.getEsId() + " doesn't exist in Cassandra"; ReportManager.writeReportLineToFile(status, outputFilePath); if (!isArtifactExist) { - ReportManager.addFailedVertex(taskName, vertex.getUniqueId()); + report.addFailure(taskName, vertex.getUniqueId()); result.setStatus(false); result.addNotFoundArtifact(artifact.getUniqueId()); } @@ -98,7 +99,7 @@ public class ArtifactValidationUtils { return artifacts; } - public ArtifactsVertexResult validateTopologyTemplateArtifacts(GraphVertex vertex, String taskName, + public ArtifactsVertexResult validateTopologyTemplateArtifacts(Report report, GraphVertex vertex, String taskName, String outputFilePath) { ArtifactsVertexResult result = new ArtifactsVertexResult(); ComponentParametersView paramView = new ComponentParametersView(); @@ -134,6 +135,6 @@ public class ArtifactValidationUtils { allArtifacts.addAll(addRelevantArtifacts(artifactMap.getMapToscaDataDefinition()))); } - return validateArtifactsAreInCassandra(vertex, taskName, allArtifacts, outputFilePath); + return validateArtifactsAreInCassandra(report, vertex, taskName, allArtifacts, outputFilePath); } } diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/tasks/artifacts/ServiceArtifactValidationTask.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/tasks/artifacts/ServiceArtifactValidationTask.java index 7caaa3cfa4..e3f547485a 100644 --- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/tasks/artifacts/ServiceArtifactValidationTask.java +++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/tasks/artifacts/ServiceArtifactValidationTask.java @@ -20,14 +20,12 @@ package org.openecomp.sdc.asdctool.impl.validator.tasks.artifacts; +import org.openecomp.sdc.asdctool.impl.validator.report.Report; import org.openecomp.sdc.asdctool.impl.validator.tasks.ServiceValidationTask; import org.openecomp.sdc.be.dao.jsongraph.GraphVertex; import org.springframework.beans.factory.annotation.Autowired; -/** - * Created by chaya on 7/6/2017. - */ public class ServiceArtifactValidationTask extends ServiceValidationTask { private ArtifactValidationUtils artifactValidationUtils; @@ -39,7 +37,7 @@ public class ServiceArtifactValidationTask extends ServiceValidationTask { } @Override - public ArtifactsVertexResult validate(GraphVertex vertex, String outputFilePath) { - return artifactValidationUtils.validateTopologyTemplateArtifacts(vertex, getTaskName(), outputFilePath); + public ArtifactsVertexResult validate(Report report, GraphVertex vertex, String outputFilePath) { + return artifactValidationUtils.validateTopologyTemplateArtifacts(report, vertex, getTaskName(), outputFilePath); } } diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/tasks/artifacts/VfArtifactValidationTask.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/tasks/artifacts/VfArtifactValidationTask.java index eb65b0c04c..f48088304f 100644 --- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/tasks/artifacts/VfArtifactValidationTask.java +++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/tasks/artifacts/VfArtifactValidationTask.java @@ -20,6 +20,7 @@ package org.openecomp.sdc.asdctool.impl.validator.tasks.artifacts; +import org.openecomp.sdc.asdctool.impl.validator.report.Report; import org.openecomp.sdc.asdctool.impl.validator.tasks.VfValidationTask; import org.openecomp.sdc.asdctool.impl.validator.utils.VertexResult; import org.openecomp.sdc.be.dao.jsongraph.GraphVertex; @@ -40,7 +41,7 @@ public class VfArtifactValidationTask extends VfValidationTask { } @Override - public VertexResult validate(GraphVertex vertex, String outputFilePath) { - return artifactValidationUtils.validateTopologyTemplateArtifacts(vertex, getTaskName(), outputFilePath); + public VertexResult validate(Report report, GraphVertex vertex, String outputFilePath) { + return artifactValidationUtils.validateTopologyTemplateArtifacts(report, vertex, getTaskName(), outputFilePath); } } diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/tasks/moduleJson/ModuleJsonTask.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/tasks/moduleJson/ModuleJsonTask.java index 47f00dc421..af4c6dfd55 100644 --- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/tasks/moduleJson/ModuleJsonTask.java +++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/tasks/moduleJson/ModuleJsonTask.java @@ -21,6 +21,7 @@ package org.openecomp.sdc.asdctool.impl.validator.tasks.moduleJson; import fj.data.Either; +import org.openecomp.sdc.asdctool.impl.validator.report.Report; import org.openecomp.sdc.asdctool.impl.validator.tasks.ServiceValidationTask; import org.openecomp.sdc.asdctool.impl.validator.utils.ReportManager; import org.openecomp.sdc.asdctool.impl.validator.utils.VertexResult; @@ -45,9 +46,6 @@ import java.util.Map; import java.util.Optional; import java.util.stream.Collectors; -/** - * Created by chaya on 7/18/2017. - */ public class ModuleJsonTask extends ServiceValidationTask { private TopologyTemplateOperation topologyTemplateOperation; @@ -59,7 +57,7 @@ public class ModuleJsonTask extends ServiceValidationTask { } @Override - public VertexResult validate(GraphVertex vertex, String outputFilePath) { + public VertexResult validate(Report report, GraphVertex vertex, String outputFilePath) { if (!isAfterSubmitForTesting(vertex)) { return new VertexResult(true); } @@ -82,15 +80,20 @@ public class ModuleJsonTask extends ServiceValidationTask { .orElse(Collections.emptyMap()).entrySet()) { MapGroupsDataDefinition groups = pair.getValue(); if (groups != null && !groups.getMapToscaDataDefinition().isEmpty()) { - return new VertexResult(findCoordinateModuleJson(pair, instDeploymentArtifacts, vertex, outputFilePath)); + return new VertexResult( + findCoordinateModuleJson(report, pair, instDeploymentArtifacts, vertex, outputFilePath)); } return new VertexResult(true); } return new VertexResult(true); } - private boolean findCoordinateModuleJson(Map.Entry<String, MapGroupsDataDefinition> pair, - Map<String, MapArtifactDataDefinition> instDeploymentArtifacts, GraphVertex vertex, String outputFilePath) { + private boolean findCoordinateModuleJson( + Report report, + Map.Entry<String, MapGroupsDataDefinition> pair, + Map<String, MapArtifactDataDefinition> instDeploymentArtifacts, + GraphVertex vertex, String outputFilePath + ) { String groupKey = pair.getKey(); String[] split = groupKey.split("\\."); String instanceName = split[split.length - 1]; @@ -114,12 +117,12 @@ public class ModuleJsonTask extends ServiceValidationTask { } String status = "Instance " + instanceName + " doesn't have a corresponding modules.json file"; ReportManager.writeReportLineToFile(status, outputFilePath); - ReportManager.addFailedVertex(getTaskName(), vertex.getUniqueId()); + report.addFailure(getTaskName(), vertex.getUniqueId()); return false; } private boolean isAfterSubmitForTesting(GraphVertex vertex) { - List allowedStates = new ArrayList<>(Arrays.asList(LifecycleStateEnum.CERTIFIED.name())); + List<String> allowedStates = new ArrayList<>(Arrays.asList(LifecycleStateEnum.CERTIFIED.name())); return allowedStates.contains(vertex.getMetadataProperty(GraphPropertyEnum.STATE)); } } 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 78910df439..a1300cb70c 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 @@ -21,27 +21,20 @@ package org.openecomp.sdc.asdctool.impl.validator.utils; -import org.apache.commons.lang.text.StrBuilder; -import org.openecomp.sdc.be.dao.jsongraph.GraphVertex; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import java.io.IOException; import java.nio.file.Files; import java.nio.file.Paths; import java.nio.file.StandardOpenOption; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Optional; import java.util.Set; +import org.apache.commons.lang.text.StrBuilder; +import org.openecomp.sdc.asdctool.impl.validator.report.Report; +import org.openecomp.sdc.be.dao.jsongraph.GraphVertex; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class ReportManager { - private static Logger log = LoggerFactory.getLogger(ReportManager.class); - - private static final Map<String, Set<String>> failedVerticesPerTask = new HashMap<>(); - private static final Map<String, Map<String, VertexResult>> resultsPerVertex = new HashMap<>(); + private static final Logger log = LoggerFactory.getLogger(ReportManager.class); public static ReportManager make(String csvReportFilePath, String txtReportFilePath) { return new ReportManager(csvReportFilePath, txtReportFilePath); @@ -69,22 +62,6 @@ public class ReportManager { Files.write(Paths.get(csvReportFilePath), sb.toString().getBytes()); } - public static void reportTaskEnd(String vertexId, String taskName, VertexResult result) { - Map<String, VertexResult> vertexTasksResults = - Optional.ofNullable(resultsPerVertex.get(vertexId)).orElse(new HashMap<>()); - vertexTasksResults.put(taskName, result); - resultsPerVertex.put(vertexId, vertexTasksResults); - } - - public static void addFailedVertex(String taskName, String vertexId) { - Set<String> failedVertices = failedVerticesPerTask.get(taskName); - if (failedVertices == null) { - failedVertices = new HashSet<>(); - } - failedVertices.add(vertexId); - failedVerticesPerTask.put(taskName, failedVertices); - } - public static void printValidationTaskStatus(GraphVertex vertexScanned, String taskName, boolean success, String outputFilePath) { String successStatus = success ? "success" : "failed"; @@ -130,21 +107,21 @@ public class ReportManager { writeReportLineToFile(sb.toString(), outputFilePath); } - public static void reportEndOfToolRun(String csvReportFilePath, String outputFilePath) { + public static void reportEndOfToolRun(Report report, String csvReportFilePath, String outputFilePath) { StrBuilder sb = new StrBuilder(); sb.appendln("-----------------------------------Validator Tool Summary-----------------------------------"); - failedVerticesPerTask.forEach((taskName, failedVertices) -> { + report.forEachFailure((taskName, failedVertices) -> { sb.append("Task: " + taskName); sb.appendNewLine(); sb.append("FailedVertices: " + failedVertices); sb.appendNewLine(); }); writeReportLineToFile(sb.toString(), outputFilePath); - printAllResults(csvReportFilePath); + printAllResults(report, csvReportFilePath); } - public static void printAllResults(String csvReportFilePath) { - resultsPerVertex.forEach((vertex, tasksResults) -> tasksResults.forEach((task, result) -> { + public static void printAllResults(Report report, String csvReportFilePath) { + report.forEachSuccess((vertex, task, result) -> { try { String resultLine = vertex + "," + task + "," + result.getStatus() + "," + result.getResult(); Files.write(Paths.get(csvReportFilePath), resultLine.getBytes(), @@ -155,6 +132,6 @@ public class ReportManager { } catch (IOException e) { log.info("write to file failed - {}", e.getClass().getSimpleName(), e); } - })); + }); } } 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 d98a26b7ed..f37a82d09b 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 @@ -23,6 +23,7 @@ package org.openecomp.sdc.asdctool.main; import org.openecomp.sdc.asdctool.impl.validator.ValidationToolBL; import org.openecomp.sdc.asdctool.impl.validator.config.ValidationConfigManager; import org.openecomp.sdc.asdctool.impl.validator.config.ValidationToolConfiguration; +import org.openecomp.sdc.asdctool.impl.validator.report.Report; import org.openecomp.sdc.asdctool.impl.validator.utils.ReportManager; import org.openecomp.sdc.be.config.ConfigurationManager; import org.openecomp.sdc.common.api.ConfigurationSource; @@ -31,12 +32,9 @@ import org.openecomp.sdc.common.impl.FSConfigurationSource; import org.openecomp.sdc.common.log.wrappers.Logger; import org.springframework.context.annotation.AnnotationConfigApplicationContext; -/** - * Created by chaya on 7/3/2017. - */ public class ValidationTool { - private static Logger log = Logger.getLogger(ValidationTool.class.getName()); + private static final Logger log = Logger.getLogger(ValidationTool.class.getName()); public static void main(String[] args) { @@ -49,8 +47,9 @@ public class ValidationTool { ValidationToolBL validationToolBL = context.getBean(ValidationToolBL.class); log.info("Start Validation Tool"); - boolean result = validationToolBL.validateAll(txtReportFilePath); - ReportManager.reportEndOfToolRun(csvReportFilePath, txtReportFilePath); + Report report = Report.make(); + boolean result = validationToolBL.validateAll(report, txtReportFilePath); + ReportManager.reportEndOfToolRun(report, csvReportFilePath, txtReportFilePath); if (result) { log.info("Validation finished successfully"); System.exit(0); @@ -63,7 +62,6 @@ public class ValidationTool { private static AnnotationConfigApplicationContext initContext(String appConfigDir) { ConfigurationSource configurationSource = new FSConfigurationSource(ExternalConfiguration.getChangeListener(), appConfigDir); ConfigurationManager configurationManager = new ConfigurationManager(configurationSource); - AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(ValidationToolConfiguration.class); - return context; + return new AnnotationConfigApplicationContext(ValidationToolConfiguration.class); } } diff --git a/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/ValidationToolBLTest.java b/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/ValidationToolBLTest.java index b412d7bc92..3db011bae5 100644 --- a/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/ValidationToolBLTest.java +++ b/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/ValidationToolBLTest.java @@ -22,6 +22,7 @@ package org.openecomp.sdc.asdctool.impl.validator; import org.junit.Test; import org.openecomp.sdc.asdctool.impl.validator.executers.ServiceValidatorExecuter; +import org.openecomp.sdc.asdctool.impl.validator.report.Report; import org.openecomp.sdc.be.dao.jsongraph.JanusGraphDao; import java.util.ArrayList; @@ -41,8 +42,9 @@ public class ValidationToolBLTest { ValidationToolBL testSubject = createTestSubject(); testSubject.validators = new LinkedList<>(); testSubject.validators.add(new ServiceValidatorExecuter(janusGraphDaoMock)); + Report report = Report.make(); // Initially no outputFilePath was passed to this function (hence it is set to null) // TODO: Fix this null and see if the argument is used by this function - testSubject.validateAll(null); + testSubject.validateAll(report, null); } } diff --git a/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/executers/ServiceValidatorExecuterTest.java b/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/executers/ServiceValidatorExecuterTest.java index a1728d8a94..98b8b250c3 100644 --- a/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/executers/ServiceValidatorExecuterTest.java +++ b/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/executers/ServiceValidatorExecuterTest.java @@ -21,6 +21,7 @@ package org.openecomp.sdc.asdctool.impl.validator.executers; import org.junit.Test; +import org.openecomp.sdc.asdctool.impl.validator.report.Report; import org.openecomp.sdc.be.dao.jsongraph.JanusGraphDao; import static org.mockito.Mockito.mock; @@ -39,8 +40,9 @@ public class ServiceValidatorExecuterTest { @Test(expected = NullPointerException.class) public void testExecuteValidations() { + Report report = Report.make(); // Initially no outputFilePath was passed to this function (hence it is set to null) // TODO: Fix this null and see if the argument is used by this function - createTestSubject().executeValidations(null); + createTestSubject().executeValidations(report, null); } } diff --git a/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/executers/VfValidatorExecuterTest.java b/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/executers/VfValidatorExecuterTest.java index c9bc5debd6..8ea87b1241 100644 --- a/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/executers/VfValidatorExecuterTest.java +++ b/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/executers/VfValidatorExecuterTest.java @@ -21,6 +21,7 @@ package org.openecomp.sdc.asdctool.impl.validator.executers; import org.junit.Test; +import org.openecomp.sdc.asdctool.impl.validator.report.Report; import org.openecomp.sdc.asdctool.impl.validator.tasks.VfValidationTask; import org.openecomp.sdc.be.dao.jsongraph.JanusGraphDao; @@ -45,8 +46,9 @@ public class VfValidatorExecuterTest { @Test(expected = NullPointerException.class) public void testExecuteValidations() { + Report report = Report.make(); // Initially no outputFilePath was passed to this function (hence it is set to null) // TODO: Fix this null and see if the argument is used by this function - createTestSubject().executeValidations(null); + createTestSubject().executeValidations(report, null); } } diff --git a/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/tasks/artifacts/ArtifactValidationUtilsTest.java b/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/tasks/artifacts/ArtifactValidationUtilsTest.java index 0399dbed38..354714b0c2 100644 --- a/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/tasks/artifacts/ArtifactValidationUtilsTest.java +++ b/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/tasks/artifacts/ArtifactValidationUtilsTest.java @@ -30,6 +30,7 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.MockitoAnnotations; import org.openecomp.sdc.asdctool.impl.validator.config.ValidationConfigManager; +import org.openecomp.sdc.asdctool.impl.validator.report.Report; import org.openecomp.sdc.asdctool.impl.validator.utils.ReportManager; import org.openecomp.sdc.asdctool.impl.validator.utils.ReportManagerHelper; import org.openecomp.sdc.be.dao.cassandra.ArtifactCassandraDao; @@ -113,12 +114,13 @@ public class ArtifactValidationUtilsTest { @Test public void testValidateArtifactsAreInCassandra() { // given + Report report = Report.make(); List<ArtifactDataDefinition> artifacts = new ArrayList<>(); artifacts.add(artifactDataDefinition); // when ArtifactsVertexResult result = - testSubject.validateArtifactsAreInCassandra(vertex, TASK_NAME, artifacts, txtReportFilePath); + testSubject.validateArtifactsAreInCassandra(report, vertex, TASK_NAME, artifacts, txtReportFilePath); List<String> reportOutputFile = ReportManagerHelper.getReportOutputFileAsList(txtReportFilePath); @@ -131,14 +133,15 @@ public class ArtifactValidationUtilsTest { @Test public void testValidateArtifactsNotInCassandra() { // given + Report report = Report.make(); List<ArtifactDataDefinition> artifacts = new ArrayList<>(); artifacts.add(artifactDataDefinition); artifacts.add(artifactDataDefinitionNotInCassandra); // when ArtifactsVertexResult result = - testSubject.validateArtifactsAreInCassandra(vertex, TASK_NAME, artifacts, txtReportFilePath); - ReportManager.reportEndOfToolRun(csvReportFilePath, txtReportFilePath); + testSubject.validateArtifactsAreInCassandra(report, vertex, TASK_NAME, artifacts, txtReportFilePath); + ReportManager.reportEndOfToolRun(report, csvReportFilePath, txtReportFilePath); List<String> reportOutputFile = ReportManagerHelper.getReportOutputFileAsList(txtReportFilePath); @@ -195,6 +198,7 @@ public class ArtifactValidationUtilsTest { @Test public void testValidateTopologyTemplateArtifacts() { // given + Report report = Report.make(); Map<String, ArtifactDataDefinition> artifacts = new HashMap<>(); artifacts.put(ES_ID, artifactDataDefinition); @@ -214,7 +218,7 @@ public class ArtifactValidationUtilsTest { // when ArtifactsVertexResult result = - testSubject.validateTopologyTemplateArtifacts(vertex, TASK_NAME, txtReportFilePath); + testSubject.validateTopologyTemplateArtifacts(report, vertex, TASK_NAME, txtReportFilePath); List<String> reportOutputFile = ReportManagerHelper.getReportOutputFileAsList(txtReportFilePath); @@ -229,12 +233,13 @@ public class ArtifactValidationUtilsTest { @Test public void testValidateTopologyTemplateArtifactsNotFoundToscaElement() { // given + Report report = Report.make(); when(topologyTemplateOperation.getToscaElement(eq(vertex.getUniqueId()), any())) .thenReturn(Either.right(StorageOperationStatus.NOT_FOUND)); // when ArtifactsVertexResult result = - testSubject.validateTopologyTemplateArtifacts(vertex, TASK_NAME, txtReportFilePath); + testSubject.validateTopologyTemplateArtifacts(report, vertex, TASK_NAME, txtReportFilePath); // then assertFalse(result.getStatus()); diff --git a/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/tasks/artifacts/ServiceArtifactValidationTaskTest.java b/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/tasks/artifacts/ServiceArtifactValidationTaskTest.java index cf28d74803..b45b589752 100644 --- a/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/tasks/artifacts/ServiceArtifactValidationTaskTest.java +++ b/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/tasks/artifacts/ServiceArtifactValidationTaskTest.java @@ -21,6 +21,7 @@ package org.openecomp.sdc.asdctool.impl.validator.tasks.artifacts; import org.junit.Test; +import org.openecomp.sdc.asdctool.impl.validator.report.Report; import org.openecomp.sdc.asdctool.impl.validator.utils.VertexResult; import org.openecomp.sdc.be.dao.jsongraph.GraphVertex; @@ -38,11 +39,12 @@ public class ServiceArtifactValidationTaskTest { @Test public void testValidate() { + Report report = Report.make(); GraphVertex vertex = null; ServiceArtifactValidationTask testSubject = createTestSubject(); // Initially no outputFilePath was passed to this function (hence it is set to null) // TODO: Fix this null and see if the argument is used by this function - VertexResult actual = testSubject.validate(vertex, null); + VertexResult actual = testSubject.validate(report, vertex, null); assertThat(actual, is(nullValue())); } } diff --git a/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/tasks/artifacts/VfArtifactValidationTaskTest.java b/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/tasks/artifacts/VfArtifactValidationTaskTest.java index 5302f4f23e..60e41abf4f 100644 --- a/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/tasks/artifacts/VfArtifactValidationTaskTest.java +++ b/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/tasks/artifacts/VfArtifactValidationTaskTest.java @@ -21,6 +21,7 @@ package org.openecomp.sdc.asdctool.impl.validator.tasks.artifacts; import org.junit.Test; +import org.openecomp.sdc.asdctool.impl.validator.report.Report; import org.openecomp.sdc.asdctool.impl.validator.utils.VertexResult; import org.openecomp.sdc.be.dao.jsongraph.GraphVertex; @@ -38,11 +39,12 @@ public class VfArtifactValidationTaskTest { @Test public void testValidate() { + Report report = Report.make(); GraphVertex vertex = null; VfArtifactValidationTask testSubject = createTestSubject(); // Initially no outputFilePath was passed to this function (hence it is set to null) // TODO: Fix this null and see if the argument is used by this function - VertexResult actual = testSubject.validate(vertex, null); + VertexResult actual = testSubject.validate(report, vertex, null); assertThat(actual, is(nullValue())); } } diff --git a/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/tasks/moduleJson/ModuleJsonTaskTest.java b/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/tasks/moduleJson/ModuleJsonTaskTest.java index 9a9f20bcc7..4ea31386e4 100644 --- a/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/tasks/moduleJson/ModuleJsonTaskTest.java +++ b/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/tasks/moduleJson/ModuleJsonTaskTest.java @@ -27,6 +27,7 @@ import org.mockito.ArgumentMatchers; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; +import org.openecomp.sdc.asdctool.impl.validator.report.Report; import org.openecomp.sdc.asdctool.impl.validator.utils.VertexResult; import org.openecomp.sdc.be.dao.jsongraph.GraphVertex; import org.openecomp.sdc.be.datatypes.elements.ArtifactDataDefinition; @@ -89,7 +90,8 @@ public class ModuleJsonTaskTest { // Initially no outputFilePath was passed to this function (hence it is set to null) // TODO: Fix this null and see if the argument is used by this function try { - VertexResult actual = test.validate(vertex, null); + Report report = Report.make(); + VertexResult actual = test.validate(report, vertex, null); assertThat(actual.getStatus(), is(true)); } catch (Exception e) { // TODO: Fix this test, as currently, any exception is ignored diff --git a/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/utils/ReportManagerTest.java b/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/utils/ReportManagerTest.java index e87347269c..c231ca3677 100644 --- a/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/utils/ReportManagerTest.java +++ b/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/utils/ReportManagerTest.java @@ -26,6 +26,7 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.Mockito; import org.openecomp.sdc.asdctool.impl.validator.config.ValidationConfigManager; +import org.openecomp.sdc.asdctool.impl.validator.report.Report; import org.openecomp.sdc.be.dao.jsongraph.GraphVertex; import java.io.File; @@ -63,7 +64,7 @@ public class ReportManagerTest { private final SortedSet<String> successTasksNames = new TreeSet<>(Arrays.asList(TASK_1_NAME, TASK_2_NAME)); - private VertexResult successResult = new VertexResult(); + private final VertexResult successResult = new VertexResult(); private final static String resourcePath = new File("src/test/resources").getAbsolutePath(); private final static String csvReportFilePath = ValidationConfigManager @@ -86,9 +87,10 @@ public class ReportManagerTest { @Test public void testReportTaskEnd() { // when - ReportManager.reportTaskEnd(VERTEX_1_ID, TASK_1_NAME, successResult); - ReportManager.reportTaskEnd(VERTEX_2_ID, TASK_2_NAME, successResult); - ReportManager.printAllResults(csvReportFilePath); + Report report = Report.make(); + report.addSuccess(VERTEX_1_ID, TASK_1_NAME, successResult); + report.addSuccess(VERTEX_2_ID, TASK_2_NAME, successResult); + ReportManager.printAllResults(report, csvReportFilePath); List<String> reportCsvFile = ReportManagerHelper.getReportCsvFileAsList(csvReportFilePath); @@ -102,10 +104,11 @@ public class ReportManagerTest { @Test public void testAddFailedVertex() { // when - ReportManager.addFailedVertex(TASK_1_NAME, VERTEX_1_ID); - ReportManager.reportEndOfToolRun(csvReportFilePath, txtReportFilePath); + Report report = Report.make(); + report.addFailure(TASK_1_NAME, VERTEX_1_ID); + ReportManager.reportEndOfToolRun(report, csvReportFilePath, txtReportFilePath); - List reportOutputFile = ReportManagerHelper.getReportOutputFileAsList(txtReportFilePath); + List<String> reportOutputFile = ReportManagerHelper.getReportOutputFileAsList(txtReportFilePath); // then assertNotNull(reportOutputFile); |