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.tasks.TopologyTemplateValidationTask;
25 import org.openecomp.sdc.asdctool.impl.validator.utils.ReportManager;
26 import org.openecomp.sdc.asdctool.impl.validator.utils.VertexResult;
27 import org.openecomp.sdc.be.dao.jsongraph.GraphVertex;
28 import org.openecomp.sdc.be.dao.jsongraph.JanusGraphDao;
29 import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum;
30 import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus;
31 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
32 import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum;
33 import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
34 import org.openecomp.sdc.common.log.wrappers.Logger;
35 import org.springframework.beans.factory.annotation.Autowired;
40 * Created by chaya on 7/3/2017.
42 public class TopologyTemplateValidatorExecuter {
44 private static Logger log = Logger.getLogger(VfValidatorExecuter.class.getName());
47 protected JanusGraphDao janusGraphDao;
49 protected String name;
51 public void setName(String name) {
55 public String getName() {
59 protected List<GraphVertex> getVerticesToValidate(ComponentTypeEnum type) {
60 Map<GraphPropertyEnum, Object> props = new EnumMap<>(GraphPropertyEnum.class);
61 props.put(GraphPropertyEnum.COMPONENT_TYPE, type.name());
62 if(type.equals(ComponentTypeEnum.RESOURCE)) {
63 props.put(GraphPropertyEnum.RESOURCE_TYPE, ResourceTypeEnum.VF);
66 Either<List<GraphVertex>, JanusGraphOperationStatus> results = janusGraphDao
67 .getByCriteria(VertexTypeEnum.TOPOLOGY_TEMPLATE, props);
68 if (results.isRight()) {
69 log.error("getVerticesToValidate failed "+ results.right().value());
70 return new ArrayList<>();
72 log.info("getVerticesToValidate: "+results.left().value().size()+" vertices to scan");
73 return results.left().value();
76 protected boolean validate(List<? extends TopologyTemplateValidationTask> tasks, List<GraphVertex> vertices) {
77 ReportManager.reportStartValidatorRun(getName(), vertices.size());
78 Set<String> failedTasks = new HashSet<>();
79 Set<String> successTasks = new HashSet<>();
80 boolean successAllVertices = true;
82 int verticesSize = vertices.size();
84 for (GraphVertex vertex: vertices) {
86 boolean successAllTasks = true;
87 for (TopologyTemplateValidationTask task: tasks) {
88 ReportManager.reportStartTaskRun(vertex, task.getTaskName());
89 VertexResult result = task.validate(vertex);
90 if (!result.getStatus()) {
91 failedTasks.add(task.getTaskName());
92 successAllVertices = false;
93 successAllTasks = false;
94 } else if (successAllTasks && vertexNum == verticesSize) {
95 successTasks.add(task.getTaskName());
97 ReportManager.printValidationTaskStatus(vertex, task.getTaskName(), result.getStatus());
98 ReportManager.reportTaskEnd(vertex.getUniqueId(), task.getTaskName(), result);
100 String componentScanStatus = successAllTasks? "success" : "failed";
101 log.info("Topology Template "+vertex.getUniqueId()+" Validation finished with "+componentScanStatus);
103 ReportManager.reportValidatorTypeSummary(getName(), failedTasks, successTasks);
104 return successAllVertices;