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.executers;
23 import fj.data.Either;
24 import org.openecomp.sdc.asdctool.impl.validator.report.Report;
25 import org.openecomp.sdc.asdctool.impl.validator.tasks.TopologyTemplateValidationTask;
26 import org.openecomp.sdc.asdctool.impl.validator.utils.ReportManager;
27 import org.openecomp.sdc.asdctool.impl.validator.utils.VertexResult;
28 import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus;
29 import org.openecomp.sdc.be.dao.jsongraph.GraphVertex;
30 import org.openecomp.sdc.be.dao.jsongraph.JanusGraphDao;
31 import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum;
32 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
33 import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum;
34 import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
35 import org.openecomp.sdc.common.log.wrappers.Logger;
36 import org.springframework.beans.factory.annotation.Autowired;
38 import java.util.ArrayList;
39 import java.util.EnumMap;
40 import java.util.HashSet;
41 import java.util.List;
45 public class TopologyTemplateValidatorExecuter {
47 private static Logger log = Logger.getLogger(VfValidatorExecuter.class.getName());
49 protected JanusGraphDao janusGraphDao;
51 protected String name;
54 public TopologyTemplateValidatorExecuter(JanusGraphDao janusGraphDao) {
55 this.janusGraphDao = janusGraphDao;
58 public void setName(String name) {
62 public String getName() {
66 protected List<GraphVertex> getVerticesToValidate(ComponentTypeEnum type) {
67 Map<GraphPropertyEnum, Object> props = new EnumMap<>(GraphPropertyEnum.class);
68 props.put(GraphPropertyEnum.COMPONENT_TYPE, type.name());
69 if (type.equals(ComponentTypeEnum.RESOURCE)) {
70 props.put(GraphPropertyEnum.RESOURCE_TYPE, ResourceTypeEnum.VF);
73 Either<List<GraphVertex>, JanusGraphOperationStatus> results = janusGraphDao
74 .getByCriteria(VertexTypeEnum.TOPOLOGY_TEMPLATE, props);
75 if (results.isRight()) {
76 log.error("getVerticesToValidate failed " + results.right().value());
77 return new ArrayList<>();
79 log.info("getVerticesToValidate: " + results.left().value().size() + " vertices to scan");
80 return results.left().value();
83 protected boolean validate(Report report, List<? extends TopologyTemplateValidationTask> tasks, List<GraphVertex> vertices,
84 String outputFilePath) {
85 ReportManager.reportStartValidatorRun(getName(), vertices.size(), outputFilePath);
86 Set<String> failedTasks = new HashSet<>();
87 Set<String> successTasks = new HashSet<>();
88 boolean successAllVertices = true;
90 int verticesSize = vertices.size();
92 for (GraphVertex vertex : vertices) {
94 boolean successAllTasks = true;
95 for (TopologyTemplateValidationTask task : tasks) {
96 ReportManager.reportStartTaskRun(vertex, task.getTaskName(), outputFilePath);
97 VertexResult result = task.validate(report, vertex, outputFilePath);
98 if (!result.getStatus()) {
99 failedTasks.add(task.getTaskName());
100 successAllVertices = false;
101 successAllTasks = false;
102 } else if (successAllTasks && vertexNum == verticesSize) {
103 successTasks.add(task.getTaskName());
105 ReportManager.printValidationTaskStatus(vertex, task.getTaskName(), result.getStatus(), outputFilePath);
106 report.addSuccess(vertex.getUniqueId(), task.getTaskName(), result);
108 String componentScanStatus = successAllTasks ? "success" : "failed";
109 log.info("Topology Template " + vertex.getUniqueId() + " Validation finished with " + componentScanStatus);
111 ReportManager.reportValidatorTypeSummary(getName(), failedTasks, successTasks, outputFilePath);
112 return successAllVertices;