summaryrefslogtreecommitdiffstats
path: root/asdctool/src/main
diff options
context:
space:
mode:
authorFrancis Toth <francis.toth@yoppworks.com>2020-07-07 09:10:33 -0400
committerOfir Sonsino <ofir.sonsino@intl.att.com>2020-07-09 09:34:59 +0000
commit20903a7051c3ee2e938cd02e408021ea34e78d0c (patch)
treefd274d884f6e2f13dcb141c80a4ac541c5459686 /asdctool/src/main
parentbdeb28f273da2494d7eeabbb5329222dfd168e3b (diff)
Clean ValidatorExecutor hierarchy
Signed-off-by: Francis Toth <francis.toth@yoppworks.com> Change-Id: I9d919b1d57eac1d25c8b3874366c2cb9e906923a Issue-ID: SDC-2499
Diffstat (limited to 'asdctool/src/main')
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/ArtifactToolBL.java10
-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/config/ValidationToolConfiguration.java11
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executor/ServiceValidatorExecutor.java50
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executor/TopologyTemplateValidatorExecutor.java100
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executor/VfValidatorExecutor.java48
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/utils/ElementTypeEnum.java79
7 files changed, 76 insertions, 230 deletions
diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/ArtifactToolBL.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/ArtifactToolBL.java
index d53cadf362..92af43e3e8 100644
--- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/ArtifactToolBL.java
+++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/ArtifactToolBL.java
@@ -28,19 +28,17 @@ import java.util.List;
public class ArtifactToolBL {
- private static final Logger log = Logger.getLogger(ValidationToolBL.class.getName());
+ private static final Logger log = Logger.getLogger(ArtifactToolBL.class);
- protected List<IArtifactValidatorExecutor> validators;
-
- private boolean allValid = true;
+ private final List<IArtifactValidatorExecutor> validators;
@Autowired
- public ArtifactToolBL(
- List<IArtifactValidatorExecutor> validators) {
+ public ArtifactToolBL(List<IArtifactValidatorExecutor> validators) {
this.validators = validators;
}
public boolean validateAll(String outputFilePath) {
+ boolean allValid = true;
for (IArtifactValidatorExecutor validatorExec : validators) {
log.debug("ValidatorExecuter " + validatorExec.getName() + " started");
if (!validatorExec.executeValidations(outputFilePath)) {
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 e9121f184c..8f9202fcb2 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
@@ -34,17 +34,15 @@ public class ValidationToolBL {
private static final Logger log = Logger.getLogger(ValidationToolBL.class);
- protected List<ValidatorExecutor> validators;
-
- private boolean allValid = true;
+ private final List<ValidatorExecutor> validators;
@Autowired
- public ValidationToolBL(
- List<ValidatorExecutor> validators) {
+ public ValidationToolBL(List<ValidatorExecutor> validators) {
this.validators = validators;
}
public boolean validateAll(Report report, ReportFile.TXTFile textFile) {
+ boolean allValid = true;
for (ValidatorExecutor validatorExec: validators) {
log.debug("ValidatorExecuter "+validatorExec.getName()+" started");
if (!validatorExec.executeValidations(report, textFile)) {
diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/config/ValidationToolConfiguration.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/config/ValidationToolConfiguration.java
index 1c02ac685a..5fbed89ac1 100644
--- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/config/ValidationToolConfiguration.java
+++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/config/ValidationToolConfiguration.java
@@ -26,10 +26,9 @@ import org.openecomp.sdc.asdctool.impl.validator.ValidationToolBL;
import org.openecomp.sdc.asdctool.impl.validator.executor.IArtifactValidatorExecutor;
import org.openecomp.sdc.asdctool.impl.validator.executor.NodeToscaArtifactsValidatorExecutor;
import org.openecomp.sdc.asdctool.impl.validator.executor.ServiceToscaArtifactsValidatorExecutor;
-import org.openecomp.sdc.asdctool.impl.validator.executor.ServiceValidatorExecutor;
+import org.openecomp.sdc.asdctool.impl.validator.executor.TopologyTemplateValidatorExecutor;
import org.openecomp.sdc.asdctool.impl.validator.executor.VFToscaArtifactValidatorExecutor;
import org.openecomp.sdc.asdctool.impl.validator.executor.ValidatorExecutor;
-import org.openecomp.sdc.asdctool.impl.validator.executor.VfValidatorExecutor;
import org.openecomp.sdc.asdctool.impl.validator.tasks.VfValidationTask;
import org.openecomp.sdc.asdctool.impl.validator.tasks.artifacts.ArtifactValidationUtils;
import org.openecomp.sdc.asdctool.impl.validator.tasks.artifacts.ServiceArtifactValidationTask;
@@ -78,8 +77,8 @@ import java.util.List;
public class ValidationToolConfiguration {
@Bean
- public ServiceValidatorExecutor basicServiceValidator(JanusGraphDao janusGraphDao) {
- return new ServiceValidatorExecutor(janusGraphDao);
+ public ValidatorExecutor basicServiceValidator(JanusGraphDao janusGraphDao) {
+ return TopologyTemplateValidatorExecutor.serviceValidatorExecutor(janusGraphDao);
}
@Bean
@@ -126,8 +125,8 @@ public class ValidationToolConfiguration {
}
@Bean
- public VfValidatorExecutor basicVfValidator(List<VfValidationTask> tasks, JanusGraphDao janusGraphDao) {
- return new VfValidatorExecutor(tasks, janusGraphDao);
+ public ValidatorExecutor basicVfValidator(List<VfValidationTask> tasks, JanusGraphDao janusGraphDao) {
+ return TopologyTemplateValidatorExecutor.vfValidatorExecutor(tasks, janusGraphDao);
}
@Bean(name = "artifact-cassandra-dao")
diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executor/ServiceValidatorExecutor.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executor/ServiceValidatorExecutor.java
deleted file mode 100644
index 27bcd1f60d..0000000000
--- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executor/ServiceValidatorExecutor.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2019 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.executor;
-
-import org.openecomp.sdc.asdctool.impl.validator.report.Report;
-import org.openecomp.sdc.asdctool.impl.validator.report.ReportFile.TXTFile;
-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;
-import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Component;
-
-import java.util.ArrayList;
-import java.util.List;
-
-@Component
-public class ServiceValidatorExecutor extends TopologyTemplateValidatorExecutor implements ValidatorExecutor {
-
- List<ServiceValidationTask> tasks = new ArrayList<>();
-
- @Autowired(required = false)
- public ServiceValidatorExecutor(JanusGraphDao janusGraphDao) {
- super(janusGraphDao, "SERVICE_VALIDATOR");
- }
-
- @Override
- public boolean executeValidations(Report report, TXTFile reportFile) {
- List<GraphVertex> vertices = getVerticesToValidate(ComponentTypeEnum.SERVICE);
- return validate(report, tasks, vertices, reportFile);
- }
-}
diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executor/TopologyTemplateValidatorExecutor.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executor/TopologyTemplateValidatorExecutor.java
index 95a9fce9af..36feb3b607 100644
--- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executor/TopologyTemplateValidatorExecutor.java
+++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executor/TopologyTemplateValidatorExecutor.java
@@ -20,19 +20,12 @@
package org.openecomp.sdc.asdctool.impl.validator.executor;
-import fj.data.Either;
-import java.util.ArrayList;
-import java.util.EnumMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
import lombok.Getter;
import org.openecomp.sdc.asdctool.impl.validator.report.Report;
import org.openecomp.sdc.asdctool.impl.validator.report.ReportFile.TXTFile;
import org.openecomp.sdc.asdctool.impl.validator.tasks.TopologyTemplateValidationTask;
+import org.openecomp.sdc.asdctool.impl.validator.tasks.VfValidationTask;
import org.openecomp.sdc.asdctool.impl.validator.utils.VertexResult;
-import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus;
import org.openecomp.sdc.be.dao.jsongraph.GraphVertex;
import org.openecomp.sdc.be.dao.jsongraph.JanusGraphDao;
import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum;
@@ -40,45 +33,56 @@ import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum;
import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
import org.openecomp.sdc.common.log.wrappers.Logger;
+import org.springframework.beans.factory.annotation.Autowired;
+
+import java.util.ArrayList;
+import java.util.EnumMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
-public class TopologyTemplateValidatorExecutor {
+public class TopologyTemplateValidatorExecutor implements ValidatorExecutor {
- private static final Logger log = Logger.getLogger(VfValidatorExecutor.class);
+ private static final Logger log = Logger.getLogger(TopologyTemplateValidatorExecutor.class);
private final JanusGraphDao janusGraphDao;
+ private final ComponentTypeEnum componentType;
+ private final List<? extends TopologyTemplateValidationTask> tasks;
@Getter
private final String name;
- public TopologyTemplateValidatorExecutor(JanusGraphDao janusGraphDao, String name) {
- this.janusGraphDao = janusGraphDao;
- this.name = name;
+ @Autowired(required = false)
+ public static ValidatorExecutor serviceValidatorExecutor(JanusGraphDao janusGraphDao) {
+ return new TopologyTemplateValidatorExecutor(
+ janusGraphDao, "SERVICE_VALIDATOR", ComponentTypeEnum.SERVICE, new ArrayList<>()
+ );
}
- protected List<GraphVertex> getVerticesToValidate(ComponentTypeEnum type) {
- Map<GraphPropertyEnum, Object> props = new EnumMap<>(GraphPropertyEnum.class);
- props.put(GraphPropertyEnum.COMPONENT_TYPE, type.name());
- if (type.equals(ComponentTypeEnum.RESOURCE)) {
- props.put(GraphPropertyEnum.RESOURCE_TYPE, ResourceTypeEnum.VF);
- }
-
- Either<List<GraphVertex>, JanusGraphOperationStatus> results = janusGraphDao
- .getByCriteria(VertexTypeEnum.TOPOLOGY_TEMPLATE, props);
- if (results.isRight()) {
- log.error("getVerticesToValidate failed " + results.right().value());
- return new ArrayList<>();
- }
- log.info("getVerticesToValidate: " + results.left().value().size() + " vertices to scan");
- return results.left().value();
+ @Autowired(required = false)
+ public static ValidatorExecutor vfValidatorExecutor(List<VfValidationTask> tasks, JanusGraphDao janusGraphDao) {
+ return new TopologyTemplateValidatorExecutor(
+ janusGraphDao, "BASIC_VF_VALIDATOR", ComponentTypeEnum.RESOURCE, tasks
+ );
}
- protected boolean validate(
- Report report,
- List<? extends TopologyTemplateValidationTask> tasks,
- List<GraphVertex> vertices,
- TXTFile reportFile
+ private TopologyTemplateValidatorExecutor(
+ JanusGraphDao janusGraphDao,
+ String name,
+ ComponentTypeEnum componentType,
+ List<? extends TopologyTemplateValidationTask> tasks
) {
- reportFile.reportStartValidatorRun(getName(), vertices.size());
+ this.janusGraphDao = janusGraphDao;
+ this.name = name;
+ this.componentType = componentType;
+ this.tasks = tasks;
+ }
+
+ @Override
+ public boolean executeValidations(Report report, TXTFile reportFile) {
+ List<GraphVertex> vertices = getVerticesToValidate();
+ reportFile.reportStartValidatorRun(name, vertices.size());
Set<String> failedTasks = new HashSet<>();
Set<String> successTasks = new HashSet<>();
boolean successAllVertices = true;
@@ -102,9 +106,33 @@ public class TopologyTemplateValidatorExecutor {
report.addSuccess(vertex.getUniqueId(), task.getTaskName(), result);
}
String componentScanStatus = successAllTasks ? "success" : "failed";
- log.info("Topology Template " + vertex.getUniqueId() + " Validation finished with " + componentScanStatus);
+ log.info("Topology Template {} Validation finished with {}", vertex.getUniqueId(), componentScanStatus);
}
- reportFile.reportValidatorTypeSummary(getName(), failedTasks, successTasks);
+ reportFile.reportValidatorTypeSummary(name, failedTasks, successTasks);
return successAllVertices;
}
+
+ private List<GraphVertex> getVerticesToValidate() {
+ return janusGraphDao
+ .getByCriteria(VertexTypeEnum.TOPOLOGY_TEMPLATE, buildProps())
+ .either(
+ vs -> {
+ log.info("getVerticesToValidate: {} vertices to scan", vs.size());
+ return vs;
+ },
+ sos -> {
+ log.error("getVerticesToValidate failed {}", sos);
+ return new ArrayList<>();
+ }
+ );
+ }
+
+ private Map<GraphPropertyEnum, Object> buildProps() {
+ Map<GraphPropertyEnum, Object> props = new EnumMap<>(GraphPropertyEnum.class);
+ props.put(GraphPropertyEnum.COMPONENT_TYPE, componentType.name());
+ if (componentType.equals(ComponentTypeEnum.RESOURCE)) {
+ props.put(GraphPropertyEnum.RESOURCE_TYPE, ResourceTypeEnum.VF);
+ }
+ return props;
+ }
}
diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executor/VfValidatorExecutor.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executor/VfValidatorExecutor.java
deleted file mode 100644
index f8aaf5480d..0000000000
--- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executor/VfValidatorExecutor.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2019 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.executor;
-
-import org.openecomp.sdc.asdctool.impl.validator.report.Report;
-import org.openecomp.sdc.asdctool.impl.validator.report.ReportFile.TXTFile;
-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;
-import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
-import org.springframework.beans.factory.annotation.Autowired;
-
-import java.util.List;
-
-public class VfValidatorExecutor extends TopologyTemplateValidatorExecutor implements ValidatorExecutor {
-
- private final List<VfValidationTask> tasks;
-
- @Autowired(required = false)
- public VfValidatorExecutor(List<VfValidationTask> tasks, JanusGraphDao janusGraphDao) {
- super(janusGraphDao, "BASIC_VF_VALIDATOR");
- this.tasks = tasks;
- }
-
- @Override
- public boolean executeValidations(Report report, TXTFile reportFile) {
- List<GraphVertex> vertices = getVerticesToValidate(ComponentTypeEnum.RESOURCE);
- return validate(report, tasks, vertices, reportFile);
- }
-}
diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/utils/ElementTypeEnum.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/utils/ElementTypeEnum.java
deleted file mode 100644
index 3424641491..0000000000
--- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/utils/ElementTypeEnum.java
+++ /dev/null
@@ -1,79 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2019 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.utils;
-
-import org.openecomp.sdc.asdctool.impl.validator.executor.VfValidatorExecutor;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * Created by chaya on 7/4/2017.
- */
-public enum ElementTypeEnum {
-
- VF ("vf", VfValidatorExecutor.class);
- //SERVICE("service", ServiceValidatorExecuter.class)
-
- private String elementType;
- private Class clazz;
-
- ElementTypeEnum(String elementType, Class clazz) {
- this. elementType = elementType;
- this.clazz = clazz;
- }
-
- public static ElementTypeEnum getByType(String elementType){
- for(ElementTypeEnum currType :ElementTypeEnum.values()){
- if(currType.getElementType().equals(elementType)){
- return currType;
- }
- }
- return null;
- }
-
- public static List<String> getAllTypes() {
-
- List<String> arrayList = new ArrayList<String>();
-
- for (ElementTypeEnum graphType : ElementTypeEnum.values()) {
- arrayList.add(graphType.getElementType());
- }
- return arrayList;
- }
-
-
- public String getElementType() {
- return elementType;
- }
-
- public void setElementType(String elementType) {
- this.elementType = elementType;
- }
-
- public Class getClazz() {
- return clazz;
- }
-
- public void setClazz(Class clazz) {
- this.clazz = clazz;
- }
-}