From 39a4e0cb1b805470ad85ed4cf4fdeb69610ae98c Mon Sep 17 00:00:00 2001 From: Michael Lando Date: Tue, 18 Jul 2017 20:46:42 +0300 Subject: [SDC] rebase 1710 Change-Id: I07fced02f40a57700d9d35ed3ba498bca351fb13 Signed-off-by: Michael Lando --- .../asdctool/impl/validator/ValidationToolBL.java | 43 +++++++ .../validator/config/ValidationConfigManager.java | 39 ++++++ .../config/ValidationToolConfiguration.java | 133 +++++++++++++++++++++ .../executers/ServiceValidatorExecuter.java | 36 ++++++ .../TopologyTemplateValidatorExecuter.java | 92 ++++++++++++++ .../validator/executers/ValidatorExecuter.java | 15 +++ .../validator/executers/VfValidatorExecuter.java | 32 +++++ .../validator/tasks/ServiceValidationTask.java | 25 ++++ .../tasks/TopologyTemplateValidationTask.java | 13 ++ .../impl/validator/tasks/VfValidationTask.java | 25 ++++ .../tasks/artifacts/ArtifactValidationUtils.java | 106 ++++++++++++++++ .../artifacts/ServiceArtifactValidationTask.java | 26 ++++ .../tasks/artifacts/VfArtifactValidationTask.java | 28 +++++ .../impl/validator/utils/ElementTypeEnum.java | 59 +++++++++ .../impl/validator/utils/ReportManager.java | 93 ++++++++++++++ .../impl/validator/utils/ValidationTaskResult.java | 45 +++++++ .../sdc/asdctool/main/ValidationTool.java | 47 ++++++++ .../src/main/resources/scripts/validationTool.sh | 31 +++++ 18 files changed, 888 insertions(+) create mode 100644 asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/ValidationToolBL.java create mode 100644 asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/config/ValidationConfigManager.java create mode 100644 asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/config/ValidationToolConfiguration.java create mode 100644 asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/ServiceValidatorExecuter.java create mode 100644 asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/TopologyTemplateValidatorExecuter.java create mode 100644 asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/ValidatorExecuter.java create mode 100644 asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/VfValidatorExecuter.java create mode 100644 asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/tasks/ServiceValidationTask.java create mode 100644 asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/tasks/TopologyTemplateValidationTask.java create mode 100644 asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/tasks/VfValidationTask.java create mode 100644 asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/tasks/artifacts/ArtifactValidationUtils.java create mode 100644 asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/tasks/artifacts/ServiceArtifactValidationTask.java create mode 100644 asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/tasks/artifacts/VfArtifactValidationTask.java create mode 100644 asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/utils/ElementTypeEnum.java create mode 100644 asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/utils/ReportManager.java create mode 100644 asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/utils/ValidationTaskResult.java create mode 100644 asdctool/src/main/java/org/openecomp/sdc/asdctool/main/ValidationTool.java create mode 100644 asdctool/src/main/resources/scripts/validationTool.sh (limited to 'asdctool') 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 new file mode 100644 index 0000000000..a57a237e76 --- /dev/null +++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/ValidationToolBL.java @@ -0,0 +1,43 @@ +package org.openecomp.sdc.asdctool.impl.validator; + +import org.openecomp.sdc.asdctool.impl.validator.executers.ValidatorExecuter; +import org.openecomp.sdc.asdctool.impl.validator.utils.ReportManager; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import java.util.*; + +/** + * Created by chaya on 7/3/2017. + */ +@Component +public class ValidationToolBL { + + private static Logger log = LoggerFactory.getLogger(ValidationToolBL.class.getName()); + + @Autowired + protected List validators; + + @Autowired + protected ReportManager reportManager; + + private boolean allValid = true; + + + public boolean validateAll() { + for (ValidatorExecuter validatorExec: validators) { + System.out.println("ValidatorExecuter "+validatorExec.getName()+" started"); + if (!validatorExec.executeValidations()) { + allValid = false; + System.out.println("ValidatorExecuter "+validatorExec.getName()+" finished with warnings"); + } + else { + System.out.println("ValidatorExecuter "+validatorExec.getName()+" finished successfully"); + } + } + return allValid; + } + +} diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/config/ValidationConfigManager.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/config/ValidationConfigManager.java new file mode 100644 index 0000000000..facb9d70f2 --- /dev/null +++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/config/ValidationConfigManager.java @@ -0,0 +1,39 @@ +package org.openecomp.sdc.asdctool.impl.validator.config; + +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.Properties; + +/** + * Created by chaya on 7/4/2017. + */ +public class ValidationConfigManager { + + private static Properties prop = new Properties(); + + public static String getOutputFilePath() { + return outputFilePath; + } + + public static void setOutputFilePath(String outputFilePath) { + ValidationConfigManager.outputFilePath = outputFilePath; + } + + private static String outputFilePath; + + public static Properties setValidationConfiguration(String path){ + InputStream input = null; + try { + input = new FileInputStream(path); + prop.load(input); + } catch (IOException ex) { + ex.printStackTrace(); + } + return prop; + } + + public static Properties getValidationConfiguration() { + return prop; + } +} 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 new file mode 100644 index 0000000000..87b27c7369 --- /dev/null +++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/config/ValidationToolConfiguration.java @@ -0,0 +1,133 @@ +package org.openecomp.sdc.asdctool.impl.validator.config; + +import org.openecomp.sdc.asdctool.impl.migration.v1707.MigrationTitanStrategy; +import org.openecomp.sdc.asdctool.impl.validator.tasks.artifacts.ArtifactValidationUtils; +import org.openecomp.sdc.asdctool.impl.validator.tasks.artifacts.ServiceArtifactValidationTask; +import org.openecomp.sdc.asdctool.impl.validator.tasks.artifacts.VfArtifactValidationTask; +import org.openecomp.sdc.asdctool.impl.validator.executers.ServiceValidatorExecuter; +import org.openecomp.sdc.asdctool.impl.validator.executers.VfValidatorExecuter; +import org.openecomp.sdc.asdctool.impl.validator.ValidationToolBL; +import org.openecomp.sdc.asdctool.impl.validator.utils.ReportManager; +import org.openecomp.sdc.be.dao.DAOTitanStrategy; +import org.openecomp.sdc.be.dao.TitanClientStrategy; +import org.openecomp.sdc.be.dao.cassandra.ArtifactCassandraDao; +import org.openecomp.sdc.be.dao.cassandra.CassandraClient; +import org.openecomp.sdc.be.dao.jsongraph.TitanDao; +import org.openecomp.sdc.be.dao.titan.TitanGraphClient; +import org.openecomp.sdc.be.model.DerivedNodeTypeResolver; +import org.openecomp.sdc.be.model.jsontitan.operations.*; +import org.openecomp.sdc.be.model.operations.api.ToscaDefinitionPathCalculator; +import org.openecomp.sdc.be.model.operations.impl.ToscaDefinitionPathCalculatorImpl; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +/** + * Created by chaya on 7/3/2017. + */ +@Configuration +public class ValidationToolConfiguration { + + @Bean + public ServiceValidatorExecuter basicServiceValidator() { return new ServiceValidatorExecuter();} + + @Bean + public VfArtifactValidationTask vfArtifactValidationTask() { return new VfArtifactValidationTask(); } + + @Bean + public ServiceArtifactValidationTask serviceArtifactValidationTask() { return new ServiceArtifactValidationTask();} + + @Bean + public ValidationToolBL validationToolBL() { + return new ValidationToolBL(); + } + + @Bean + public VfValidatorExecuter basicVfValidator() { return new VfValidatorExecuter();} + + @Bean + public ReportManager reportManager() { return new ReportManager();} + + @Bean(name = "artifact-cassandra-dao") + public ArtifactCassandraDao artifactCassandraDao() { + return new ArtifactCassandraDao(); + } + + @Bean + public ArtifactValidationUtils artifactValidationUtils() { return new ArtifactValidationUtils();} + + @Bean(name = "groups-operation") + public GroupsOperation jsonGroupsOperation() { + return new GroupsOperation(); + } + + @Bean(name = "cassandra-client") + public CassandraClient cassandraClient() { + return new CassandraClient(); + } + + @Bean(name = "dao-titan-strategy") + public TitanClientStrategy daoStrategy() { + return new DAOTitanStrategy(); + } + + @Bean(name = "migration-titan-client", initMethod = "createGraph") + public TitanGraphClient titanMigrationClient(@Qualifier("dao-titan-strategy") TitanClientStrategy titanClientStrategy) { + return new TitanGraphClient(titanClientStrategy); + } + + @Bean(name = "tosca-operation-facade") + public ToscaOperationFacade toscaOperationFacade() { + return new ToscaOperationFacade(); + } + + @Bean(name = "node-type-operation") + public NodeTypeOperation nodeTypeOperation(@Qualifier("mig-derived-resolver") DerivedNodeTypeResolver migrationDerivedNodeTypeResolver) { + return new NodeTypeOperation(migrationDerivedNodeTypeResolver); + } + + @Bean(name = "topology-template-operation") + public TopologyTemplateOperation topologyTemplateOperation() { + return new TopologyTemplateOperation(); + } + + @Bean(name = "node-template-operation") + public NodeTemplateOperation nodeTemplateOperation() { + return new NodeTemplateOperation(); + } + + @Bean(name = "mig-derived-resolver") + public DerivedNodeTypeResolver migrationDerivedNodeTypeResolver() { + return new ByToscaNameDerivedNodeTypeResolver(); + } + + @Bean(name = "titan-dao") + public TitanDao titanDao(@Qualifier("migration-titan-client") TitanGraphClient titanGraphClient) { + return new TitanDao(titanGraphClient); + } + + @Bean(name = "category-operation") + public CategoryOperation categoryOperation() { + return new CategoryOperation(); + } + + @Bean(name = "tosca-path-calculator") + public ToscaDefinitionPathCalculator pathCalculator() { + return new ToscaDefinitionPathCalculatorImpl(); + } + + @Bean(name = "artifacts-operation") + public ArtifactsOperations artifactsOperation() { + return new ArtifactsOperations(); + } + + @Bean(name = "tosca-data-operation") + public ToscaDataOperation toscaDataOperation() { + return new ToscaDataOperation(); + } + + @Bean(name = "tosca-element-lifecycle-operation") + public ToscaElementLifecycleOperation toscaElementLifecycleOperation() { + return new ToscaElementLifecycleOperation(); + } +} 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 new file mode 100644 index 0000000000..817ab15418 --- /dev/null +++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/ServiceValidatorExecuter.java @@ -0,0 +1,36 @@ +package org.openecomp.sdc.asdctool.impl.validator.executers; + +import org.openecomp.sdc.asdctool.impl.validator.tasks.ServiceValidationTask; +import org.openecomp.sdc.be.dao.jsongraph.GraphVertex; +import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; + +import java.util.*; + +/** + * Created by chaya on 7/4/2017. + */ +public class ServiceValidatorExecuter extends TopologyTemplateValidatorExecuter implements ValidatorExecuter { + + @Autowired(required = false) + List tasks = new ArrayList<>(); + + private static Logger log = LoggerFactory.getLogger(VfValidatorExecuter.class.getName()); + + public ServiceValidatorExecuter() { + setName("SERVICE_VALIDATOR"); + } + + @Override + public boolean executeValidations() { + List vertices = getVerticesToValidate(ComponentTypeEnum.SERVICE); + return validate(tasks, vertices); + } + + @Override + public String getName() { + return super.getName(); + } +} 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 new file mode 100644 index 0000000000..16a479dc75 --- /dev/null +++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/TopologyTemplateValidatorExecuter.java @@ -0,0 +1,92 @@ +package org.openecomp.sdc.asdctool.impl.validator.executers; + +import fj.data.Either; +import org.openecomp.sdc.asdctool.impl.validator.tasks.TopologyTemplateValidationTask; +import org.openecomp.sdc.asdctool.impl.validator.utils.ReportManager; +import org.openecomp.sdc.be.dao.jsongraph.GraphVertex; +import org.openecomp.sdc.be.dao.jsongraph.TitanDao; +import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum; +import org.openecomp.sdc.be.dao.titan.TitanOperationStatus; +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.be.model.jsontitan.operations.TopologyTemplateOperation; +import org.openecomp.sdc.be.model.jsontitan.operations.ToscaOperationFacade; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; + +import java.util.*; + +/** + * Created by chaya on 7/3/2017. + */ +public class TopologyTemplateValidatorExecuter { + + private static Logger log = LoggerFactory.getLogger(VfValidatorExecuter.class.getName()); + + @Autowired + protected TitanDao titanDao; + + @Autowired + protected ToscaOperationFacade toscaOperationFacade; + + @Autowired + protected TopologyTemplateOperation topologyTemplateOperation; + + protected String name; + + public void setName(String name) { + this.name = name; + } + + public String getName() { + return name; + } + + public void reportValidateTaskStatus(TopologyTemplateValidationTask validationTask, boolean success, GraphVertex vertexScanned) { + ReportManager.reportValidationTaskStatus(vertexScanned, validationTask.getTaskName(), validationTask.getTaskResultStatus(), success); + } + + protected List getVerticesToValidate(ComponentTypeEnum type) { + Map 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, TitanOperationStatus> results = titanDao.getByCriteria(VertexTypeEnum.TOPOLOGY_TEMPLATE, props); + if (results.isRight()) { + System.out.println("getVerticesToValidate failed "+ results.right().value()); + return new ArrayList(); + } + System.out.println("getVerticesToValidate: "+results.left().value().size()+" vertices to scan"); + return results.left().value(); + } + + protected boolean validate(List tasks, List vertices) { + ReportManager.reportStartValidatorRun(getName(), vertices.size()); + Set failedTasks = new HashSet<>(); + Set successTasks = new HashSet<>(); + boolean successAllVertices = true; + for (GraphVertex vertex: vertices) { + boolean successAllTasks = true; + for (TopologyTemplateValidationTask task: tasks) { + ReportManager.reportStartTaskRun(vertex, task.getTaskName()); + boolean success = task.validate(vertex); + if (!success) { + failedTasks.add(task.getTaskName()); + successAllVertices = false; + successAllTasks = false; + } else { + successTasks.add(task.getTaskName()); + } + reportValidateTaskStatus(task, success, vertex); + } + String componentScanStatus = successAllTasks? "success" : "failed"; + System.out.println("Topology Template "+vertex.getUniqueId()+" Validation finished with "+componentScanStatus); + } + ReportManager.reportValidatorTypeSummary(getName(), failedTasks, successTasks); + return successAllVertices; + } +} 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 new file mode 100644 index 0000000000..8281d1f353 --- /dev/null +++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/ValidatorExecuter.java @@ -0,0 +1,15 @@ +package org.openecomp.sdc.asdctool.impl.validator.executers; + +import org.openecomp.sdc.asdctool.impl.validator.utils.ElementTypeEnum; +import org.openecomp.sdc.be.model.Component; + +import java.util.List; + +/** + * Created by chaya on 7/3/2017. + */ +public interface ValidatorExecuter { + + boolean executeValidations(); + 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 new file mode 100644 index 0000000000..913a36fbd4 --- /dev/null +++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/VfValidatorExecuter.java @@ -0,0 +1,32 @@ +package org.openecomp.sdc.asdctool.impl.validator.executers; + +import org.openecomp.sdc.asdctool.impl.validator.tasks.VfValidationTask; +import org.openecomp.sdc.be.dao.jsongraph.GraphVertex; +import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum; +import org.springframework.beans.factory.annotation.Autowired; + +import java.util.*; + +/** + * Created by chaya on 7/3/2017. + */ +public class VfValidatorExecuter extends TopologyTemplateValidatorExecuter implements ValidatorExecuter { + + @Autowired(required = false) + private List tasks = new ArrayList<>(); + + public VfValidatorExecuter() { + setName("BASIC_VF_VALIDATOR"); + } + + @Override + public boolean executeValidations() { + List vertices = getVerticesToValidate(ComponentTypeEnum.RESOURCE); + return validate(tasks, vertices); + } + + @Override + public String getName() { + return super.getName(); + } +} diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/tasks/ServiceValidationTask.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/tasks/ServiceValidationTask.java new file mode 100644 index 0000000000..89444768a4 --- /dev/null +++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/tasks/ServiceValidationTask.java @@ -0,0 +1,25 @@ +package org.openecomp.sdc.asdctool.impl.validator.tasks; + +/** + * Created by chaya on 7/5/2017. + */ +public abstract class ServiceValidationTask implements TopologyTemplateValidationTask { + protected String name = ""; + protected String taskStatus = "NOT_STARTED"; + + @Override + public String getTaskName() { + return this.name; + } + + @Override + public String getTaskResultStatus() { + return this.taskStatus; + } + + @Override + public void setTaskResultStatus(String status) { + this.taskStatus = status; + } + +} 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 new file mode 100644 index 0000000000..6ca012546b --- /dev/null +++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/tasks/TopologyTemplateValidationTask.java @@ -0,0 +1,13 @@ +package org.openecomp.sdc.asdctool.impl.validator.tasks; + +import org.openecomp.sdc.be.dao.jsongraph.GraphVertex; + +/** + * Created by chaya on 7/5/2017. + */ +public interface TopologyTemplateValidationTask { + boolean validate(GraphVertex vertex); + 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 new file mode 100644 index 0000000000..ec621b86ae --- /dev/null +++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/tasks/VfValidationTask.java @@ -0,0 +1,25 @@ +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 = ""; + + @Override + public String getTaskName() { + return this.name; + } + + @Override + public String getTaskResultStatus() { + return taskStatus; + } + + @Override + public void setTaskResultStatus(String status) { + this.taskStatus = status; + } + +} 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 new file mode 100644 index 0000000000..dfdeec8c67 --- /dev/null +++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/tasks/artifacts/ArtifactValidationUtils.java @@ -0,0 +1,106 @@ +package org.openecomp.sdc.asdctool.impl.validator.tasks.artifacts; + +import fj.data.Either; +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; +import org.openecomp.sdc.be.dao.jsongraph.GraphVertex; +import org.openecomp.sdc.be.datatypes.elements.ArtifactDataDefinition; +import org.openecomp.sdc.be.datatypes.elements.MapArtifactDataDefinition; +import org.openecomp.sdc.be.model.ComponentParametersView; +import org.openecomp.sdc.be.model.jsontitan.datamodel.TopologyTemplate; +import org.openecomp.sdc.be.model.jsontitan.datamodel.ToscaElement; +import org.openecomp.sdc.be.model.jsontitan.operations.TopologyTemplateOperation; +import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus; +import org.springframework.beans.factory.annotation.Autowired; + +import java.util.*; + +/** + * Created by chaya on 7/6/2017. + */ +public class ArtifactValidationUtils { + + @Autowired + private ArtifactCassandraDao artifactCassandraDao; + + @Autowired + private TopologyTemplateOperation topologyTemplateOperation; + + public boolean validateArtifactsAreInCassandra(GraphVertex vertex, String taskName, List artifacts) { + boolean allArtifactsExist = true; + for(ArtifactDataDefinition artifact:artifacts) { + boolean isArtifactExist = isArtifcatInCassandra(artifact.getEsId()); + String status = isArtifactExist ? "Artifact " + artifact.getEsId() + " is in Cassandra" : + "Artifact " + artifact.getEsId() + " doesn't exist in Cassandra"; + ReportManager.writeReportLineToFile(status); + if (!isArtifactExist) { + allArtifactsExist = false; + } + } + return allArtifactsExist; + } + + public boolean isArtifcatInCassandra(String uniueId) { + Either countOfArtifactsEither = + artifactCassandraDao.getCountOfArtifactById(uniueId); + if (countOfArtifactsEither.isRight()) { + // print to console + System.out.print("Failed to retrieve artifact with id: "+uniueId+" from Cassandra" ); + return false; + } + Long count = countOfArtifactsEither.left().value(); + if (count <1) { + //System.out.print("Artifact "+uniueId+" count is: "+count); + return false; + } + return true; + } + + public List addRelevantArtifacts(Map artifactsMap) { + List artifacts = new ArrayList<>(); + Optional.ofNullable(artifactsMap).orElse(Collections.emptyMap()).forEach( (key, dataDef) -> { + if (dataDef.getEsId() != null && !dataDef.getEsId().isEmpty()) { + artifacts.add(dataDef); + } + }); + return artifacts; + } + + public boolean validateTopologyTemplateArtifacts(GraphVertex vertex, String taskName) { + ComponentParametersView paramView = new ComponentParametersView(); + paramView.disableAll(); + paramView.setIgnoreArtifacts(false); + paramView.setIgnoreComponentInstances(false); + Either toscaElementEither = topologyTemplateOperation.getToscaElement(vertex.getUniqueId(), paramView); + if (toscaElementEither.isRight()) { + return false; + } + TopologyTemplate element = (TopologyTemplate) toscaElementEither.left().value(); + Map deploymentArtifacts = element.getDeploymentArtifacts(); + Map artifacts = element.getArtifacts(); + Map apiArtifacts = element.getServiceApiArtifacts(); + Map instanceArtifacts = element.getInstanceArtifacts(); + Map instanceDeploymentArtifacts = element.getInstDeploymentArtifacts(); + + List allArtifacts = new ArrayList<>(); + + allArtifacts.addAll(addRelevantArtifacts(deploymentArtifacts)); + allArtifacts.addAll(addRelevantArtifacts(artifacts)); + allArtifacts.addAll(addRelevantArtifacts(apiArtifacts)); + + if (instanceArtifacts != null) { + instanceArtifacts.forEach((key, artifactMap) -> { + allArtifacts.addAll(addRelevantArtifacts(artifactMap.getMapToscaDataDefinition())); + }); + } + + if (instanceDeploymentArtifacts != null) { + instanceDeploymentArtifacts.forEach((key, artifactMap) -> { + allArtifacts.addAll(addRelevantArtifacts(artifactMap.getMapToscaDataDefinition())); + }); + } + + return validateArtifactsAreInCassandra(vertex, taskName, allArtifacts); + } +} 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 new file mode 100644 index 0000000000..410691fb47 --- /dev/null +++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/tasks/artifacts/ServiceArtifactValidationTask.java @@ -0,0 +1,26 @@ +package org.openecomp.sdc.asdctool.impl.validator.tasks.artifacts; + +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 { + + @Autowired + private ArtifactValidationUtils artifactValidationUtils; + + + + public ServiceArtifactValidationTask() { + this.name = "Service Artifact Validation Task"; + } + + @Override + public boolean validate(GraphVertex vertex) { + return artifactValidationUtils.validateTopologyTemplateArtifacts(vertex, getTaskName()); + } +} 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 new file mode 100644 index 0000000000..01bc26fe2b --- /dev/null +++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/tasks/artifacts/VfArtifactValidationTask.java @@ -0,0 +1,28 @@ +package org.openecomp.sdc.asdctool.impl.validator.tasks.artifacts; + +import org.openecomp.sdc.asdctool.impl.validator.tasks.VfValidationTask; +import org.openecomp.sdc.be.dao.jsongraph.GraphVertex; +import org.openecomp.sdc.be.model.jsontitan.operations.TopologyTemplateOperation; +import org.springframework.beans.factory.annotation.Autowired; + + +/** + * Created by chaya on 7/4/2017. + */ +public class VfArtifactValidationTask extends VfValidationTask { + + @Autowired + ArtifactValidationUtils artifactValidationUtils; + + @Autowired + protected TopologyTemplateOperation topologyTemplateOperation; + + public VfArtifactValidationTask() { + this.name = "Artifact Validation Task"; + } + + @Override + public boolean validate(GraphVertex vertex) { + return artifactValidationUtils.validateTopologyTemplateArtifacts(vertex, getTaskName()); + } +} 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 new file mode 100644 index 0000000000..245d38c853 --- /dev/null +++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/utils/ElementTypeEnum.java @@ -0,0 +1,59 @@ +package org.openecomp.sdc.asdctool.impl.validator.utils; + +import org.openecomp.sdc.asdctool.impl.validator.executers.VfValidatorExecuter; + +import java.util.ArrayList; +import java.util.List; + +/** + * Created by chaya on 7/4/2017. + */ +public enum ElementTypeEnum { + + VF ("vf", VfValidatorExecuter.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 getAllTypes() { + + List arrayList = new ArrayList(); + + 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; + } +} 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 new file mode 100644 index 0000000000..1fdde7dd80 --- /dev/null +++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/utils/ReportManager.java @@ -0,0 +1,93 @@ +package org.openecomp.sdc.asdctool.impl.validator.utils; + +import org.apache.commons.lang.text.StrBuilder; +import org.openecomp.sdc.asdctool.impl.validator.tasks.TopologyTemplateValidationTask; +import org.openecomp.sdc.asdctool.impl.validator.config.ValidationConfigManager; +import org.openecomp.sdc.be.dao.jsongraph.GraphVertex; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.nio.file.StandardOpenOption; +import java.util.ArrayList; +import java.util.List; +import java.util.Set; + +/** + * Created by chaya on 7/5/2017. + */ +public class ReportManager { + + private static List taskResults; + private static String reportOutputFilePath; + + public ReportManager() { + try { + taskResults = new ArrayList<>(); + // open file for first time + reportOutputFilePath = ValidationConfigManager.getOutputFilePath(); + StrBuilder sb = new StrBuilder(); + sb.appendln("-----------------------Validation Tool Results:-------------------------"); + Files.write(Paths.get(reportOutputFilePath), sb.toString().getBytes()); + } catch (IOException e) { + e.printStackTrace(); + } + } + + public static void reportValidationTaskStatus(GraphVertex vertexScanned, String taskName, String taskResultMessage, boolean success) { + taskResults.add(new ValidationTaskResult(vertexScanned, taskName, taskResultMessage, success)); + printValidationTaskStatus(vertexScanned, taskName, success); + } + + private static void printValidationTaskStatus(GraphVertex vertexScanned, String taskName, boolean success) { + String successStatus = success ? "success" : "failed"; + String line = "-----------------------Vertex: "+vertexScanned.getUniqueId()+", Task " + taskName + " " +successStatus+"-----------------------"; + StrBuilder sb = new StrBuilder(); + writeReportLineToFile(sb.appendNewLine().toString()); + sb.appendln(line); + sb.appendNewLine(); + writeReportLineToFile(line); + } + + public static void reportValidationTaskSummary(TopologyTemplateValidationTask task, int numOfFailedComponents, int numOfSuccessComponents) { + StrBuilder sb = new StrBuilder(); + sb.appendNewLine(); + sb.appendln("-----------------------Task " + task.getTaskName() + " Validation Summary-----------------------"); + sb.appendln("Num of failed components: "+ numOfFailedComponents); + sb.appendln("Num of success components: "+ numOfSuccessComponents); + sb.appendln("Total components scanned: " + numOfFailedComponents+numOfSuccessComponents); + writeReportLineToFile(sb.toString()); + } + + public static void writeReportLineToFile(String message) { + try { + Files.write(Paths.get(reportOutputFilePath), new StrBuilder().appendNewLine().toString().getBytes(), StandardOpenOption.APPEND); + Files.write(Paths.get(reportOutputFilePath), message.getBytes(), StandardOpenOption.APPEND); + } catch (IOException e) { + e.printStackTrace(); + } + } + + public static void reportValidatorTypeSummary(String validatorName, Set failedTasksNames, Set successTasksNames){ + StrBuilder sb = new StrBuilder(); + sb.appendNewLine().appendNewLine(); + sb.appendln("-----------------------ValidatorExecuter " + validatorName + " Validation Summary-----------------------"); + sb.appendln("Failed tasks: "+ failedTasksNames); + sb.appendln("Success tasks: "+ successTasksNames); + writeReportLineToFile(sb.toString()); + } + + public static void reportStartValidatorRun(String validatorName, int componenentsNum) { + StrBuilder sb = new StrBuilder(); + sb.appendNewLine().appendNewLine(); + sb.appendln("------ValidatorExecuter " + validatorName + " Validation Started, on "+componenentsNum+" components---------"); + writeReportLineToFile(sb.toString()); + } + + public static void reportStartTaskRun(GraphVertex vertex, String taskName){ + StrBuilder sb = new StrBuilder(); + sb.appendNewLine().appendNewLine(); + sb.appendln("-----------------------Vertex: "+vertex.getUniqueId()+", Task " + taskName + " Started-----------------------"); + writeReportLineToFile(sb.toString()); + } +} diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/utils/ValidationTaskResult.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/utils/ValidationTaskResult.java new file mode 100644 index 0000000000..8fad932941 --- /dev/null +++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/utils/ValidationTaskResult.java @@ -0,0 +1,45 @@ +package org.openecomp.sdc.asdctool.impl.validator.utils; + +import org.openecomp.sdc.be.dao.jsongraph.GraphVertex; +import org.openecomp.sdc.be.model.Component; + +/** + * Created by chaya on 7/5/2017. + */ +public class ValidationTaskResult { + public ValidationTaskResult(GraphVertex vertex, String name, String resultMessage, boolean isSuccessful) { + this.vertexScanned = vertex; + this.name = name; + this.resultMessage = resultMessage; + this.isSuccessful = isSuccessful; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getResultMessage() { + return resultMessage; + } + + public void setResultMessage(String resultMessage) { + this.resultMessage = resultMessage; + } + + public boolean isSuccessful() { + return isSuccessful; + } + + public void setSuccessful(boolean successful) { + isSuccessful = successful; + } + + private String name; + private String resultMessage; + private boolean isSuccessful; + private GraphVertex vertexScanned; +} 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 new file mode 100644 index 0000000000..6b10615ad3 --- /dev/null +++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/main/ValidationTool.java @@ -0,0 +1,47 @@ +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.migration.v1604.AppConfig; +import org.openecomp.sdc.be.config.ConfigurationManager; +import org.openecomp.sdc.common.api.ConfigurationSource; +import org.openecomp.sdc.common.impl.ExternalConfiguration; +import org.openecomp.sdc.common.impl.FSConfigurationSource; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.context.annotation.AnnotationConfigApplicationContext; + +/** + * Created by chaya on 7/3/2017. + */ +public class ValidationTool { + + private static Logger log = LoggerFactory.getLogger(ValidationTool.class.getName()); + + public static void main(String[] args) throws Exception { + + String outputFilePath = args[0]; + ValidationConfigManager.setOutputFilePath(outputFilePath); + + String appConfigDir = args[1]; + AnnotationConfigApplicationContext context = initContext(appConfigDir); + ValidationToolBL validationToolBL = context.getBean(ValidationToolBL.class); + + System.out.println("Start Validation Tool"); + if (validationToolBL.validateAll()) { + System.out.println("Validation finished successfully"); + System.exit(0); + } else { + System.out.println("Validation finished with warnings"); + System.exit(2); + } + } + + 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; + } +} diff --git a/asdctool/src/main/resources/scripts/validationTool.sh b/asdctool/src/main/resources/scripts/validationTool.sh new file mode 100644 index 0000000000..fc82eee72d --- /dev/null +++ b/asdctool/src/main/resources/scripts/validationTool.sh @@ -0,0 +1,31 @@ +#!/bin/bash + +############################## +# Validation Tool # +############################## + +CURRENT_DIR=`pwd` +BASEDIR=$(dirname $0) + +if [ ${BASEDIR:0:1} = "/" ] +then + FULL_PATH=$BASEDIR +else + FULL_PATH=$CURRENT_DIR/$BASEDIR +fi + +source ${FULL_PATH}/baseOperation.sh + +mainClass="org.openecomp.sdc.asdctool.main.ValidationTool" + +command="java $JVM_LOG_FILE -cp $JARS $mainClass reportOutput.txt /apps/jetty/base/be/config/catalog-be/" +echo $command + +$command +result=$? + +echo "***********************************" +echo "***** $result *********************" +echo "***********************************" + +exit $result \ No newline at end of file -- cgit 1.2.3-korg