summaryrefslogtreecommitdiffstats
path: root/asdctool/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'asdctool/src/main/java')
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/ValidationToolBL.java8
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/ServiceValidatorExecuter.java8
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/TopologyTemplateValidatorExecuter.java10
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/ValidatorExecuter.java7
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/VfValidatorExecuter.java8
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/report/Report.java100
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/tasks/TopologyTemplateValidationTask.java6
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/tasks/VfValidationTask.java3
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/tasks/artifacts/ArtifactValidationUtils.java9
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/tasks/artifacts/ServiceArtifactValidationTask.java8
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/tasks/artifacts/VfArtifactValidationTask.java5
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/tasks/moduleJson/ModuleJsonTask.java21
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/utils/ReportManager.java47
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/main/ValidationTool.java14
14 files changed, 159 insertions, 95 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);
}
}