2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.sdc.asdctool.impl.validator.executor;
23 import fj.data.Either;
24 import java.util.ArrayList;
25 import java.util.EnumMap;
26 import java.util.HashSet;
27 import java.util.List;
31 import org.openecomp.sdc.asdctool.impl.validator.report.Report;
32 import org.openecomp.sdc.asdctool.impl.validator.report.ReportFile.TXTFile;
33 import org.openecomp.sdc.asdctool.impl.validator.tasks.TopologyTemplateValidationTask;
34 import org.openecomp.sdc.asdctool.impl.validator.utils.VertexResult;
35 import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus;
36 import org.openecomp.sdc.be.dao.jsongraph.GraphVertex;
37 import org.openecomp.sdc.be.dao.jsongraph.JanusGraphDao;
38 import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum;
39 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
40 import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum;
41 import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
42 import org.openecomp.sdc.common.log.wrappers.Logger;
44 public class TopologyTemplateValidatorExecutor {
46 private static final Logger log = Logger.getLogger(VfValidatorExecutor.class);
48 private final JanusGraphDao janusGraphDao;
51 private final String name;
53 public TopologyTemplateValidatorExecutor(JanusGraphDao janusGraphDao, String name) {
54 this.janusGraphDao = janusGraphDao;
58 protected List<GraphVertex> getVerticesToValidate(ComponentTypeEnum type) {
59 Map<GraphPropertyEnum, Object> props = new EnumMap<>(GraphPropertyEnum.class);
60 props.put(GraphPropertyEnum.COMPONENT_TYPE, type.name());
61 if (type.equals(ComponentTypeEnum.RESOURCE)) {
62 props.put(GraphPropertyEnum.RESOURCE_TYPE, ResourceTypeEnum.VF);
65 Either<List<GraphVertex>, JanusGraphOperationStatus> results = janusGraphDao
66 .getByCriteria(VertexTypeEnum.TOPOLOGY_TEMPLATE, props);
67 if (results.isRight()) {
68 log.error("getVerticesToValidate failed " + results.right().value());
69 return new ArrayList<>();
71 log.info("getVerticesToValidate: " + results.left().value().size() + " vertices to scan");
72 return results.left().value();
75 protected boolean validate(
77 List<? extends TopologyTemplateValidationTask> tasks,
78 List<GraphVertex> vertices,
81 reportFile.reportStartValidatorRun(getName(), vertices.size());
82 Set<String> failedTasks = new HashSet<>();
83 Set<String> successTasks = new HashSet<>();
84 boolean successAllVertices = true;
86 int verticesSize = vertices.size();
88 for (GraphVertex vertex : vertices) {
90 boolean successAllTasks = true;
91 for (TopologyTemplateValidationTask task : tasks) {
92 reportFile.reportStartTaskRun(vertex, task.getTaskName());
93 VertexResult result = task.validate(report, vertex, reportFile);
94 if (!result.getStatus()) {
95 failedTasks.add(task.getTaskName());
96 successAllVertices = false;
97 successAllTasks = false;
98 } else if (successAllTasks && vertexNum == verticesSize) {
99 successTasks.add(task.getTaskName());
101 reportFile.printValidationTaskStatus(vertex, task.getTaskName(), result.getStatus());
102 report.addSuccess(vertex.getUniqueId(), task.getTaskName(), result);
104 String componentScanStatus = successAllTasks ? "success" : "failed";
105 log.info("Topology Template " + vertex.getUniqueId() + " Validation finished with " + componentScanStatus);
107 reportFile.reportValidatorTypeSummary(getName(), failedTasks, successTasks);
108 return successAllVertices;