From a521335db6949fb0fdd846a4f1faa0c26336b0a9 Mon Sep 17 00:00:00 2001 From: cb478c Date: Wed, 19 Jul 2017 13:22:23 +0300 Subject: [SDC]first draft of module json validation task Change-Id: I551560e79ccd284ab852e8c1f1fec6cc9bf958d0 Signed-off-by: Michael Lando --- .../config/ValidationToolConfiguration.java | 4 ++ .../validator/tasks/moduleJson/ModuleJsonTask.java | 76 ++++++++++++++++++++++ 2 files changed, 80 insertions(+) create mode 100644 asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/tasks/moduleJson/ModuleJsonTask.java 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 87b27c7369..038134bbfe 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 @@ -7,6 +7,7 @@ import org.openecomp.sdc.asdctool.impl.validator.tasks.artifacts.VfArtifactValid 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.tasks.moduleJson.ModuleJsonTask; import org.openecomp.sdc.asdctool.impl.validator.utils.ReportManager; import org.openecomp.sdc.be.dao.DAOTitanStrategy; import org.openecomp.sdc.be.dao.TitanClientStrategy; @@ -37,6 +38,9 @@ public class ValidationToolConfiguration { @Bean public ServiceArtifactValidationTask serviceArtifactValidationTask() { return new ServiceArtifactValidationTask();} + @Bean + public ModuleJsonTask moduleJsonTask() { return new ModuleJsonTask();} + @Bean public ValidationToolBL validationToolBL() { return new ValidationToolBL(); diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/tasks/moduleJson/ModuleJsonTask.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/tasks/moduleJson/ModuleJsonTask.java new file mode 100644 index 0000000000..675ac1f25d --- /dev/null +++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/tasks/moduleJson/ModuleJsonTask.java @@ -0,0 +1,76 @@ +package org.openecomp.sdc.asdctool.impl.validator.tasks.moduleJson; + +import fj.data.Either; +import org.openecomp.sdc.asdctool.impl.validator.tasks.ServiceValidationTask; +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.datatypes.elements.MapGroupsDataDefinition; +import org.openecomp.sdc.be.model.ComponentParametersView; +import org.openecomp.sdc.be.model.LifecycleStateEnum; +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.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +/** + * Created by chaya on 7/18/2017. + */ +public class ModuleJsonTask extends ServiceValidationTask { + + @Autowired + private TopologyTemplateOperation topologyTemplateOperation; + + @Override + public boolean validate(GraphVertex vertex) { + ComponentParametersView paramView = new ComponentParametersView(); + paramView.disableAll(); + paramView.setIgnoreArtifacts(false); + paramView.setIgnoreGroups(false); + paramView.setIgnoreComponentInstances(false); + Either toscaElementEither = topologyTemplateOperation.getToscaElement(vertex.getUniqueId(), paramView); + if (toscaElementEither.isRight()) { + return false; + } + TopologyTemplate element = (TopologyTemplate) toscaElementEither.left().value(); + if (!isAfterSubmitForTesting(element)) { + return false; + } + Map instGroups = element.getInstGroups(); + Map instDeploymentArtifacts = element.getInstDeploymentArtifacts(); + + for (Map.Entry pair : instGroups.entrySet()) { + String groupKey = pair.getKey(); + MapGroupsDataDefinition groups = pair.getValue(); + if (groups != null && !groups.getMapToscaDataDefinition().isEmpty()) { + MapArtifactDataDefinition deploymentsArtifacts = instDeploymentArtifacts.get(groupKey); + if (deploymentsArtifacts != null && !deploymentsArtifacts.getMapToscaDataDefinition().isEmpty()) { + List moduleJsonArtifacts = deploymentsArtifacts.getMapToscaDataDefinition().values().stream().filter(artifact -> { + String artifactName = artifact.getArtifactName(); + if (artifactName.startsWith(groupKey) && artifactName.endsWith("module.json")) { + return true; + } + return false; + }).collect(Collectors.toList()); + if (moduleJsonArtifacts.size() > 0) { + return true; + } + } + } + } + return true; + } + + private boolean isAfterSubmitForTesting(TopologyTemplate element){ + List allowedStates = new ArrayList<>(Arrays.asList(LifecycleStateEnum.READY_FOR_CERTIFICATION, + LifecycleStateEnum.CERTIFICATION_IN_PROGRESS, LifecycleStateEnum.CERTIFIED)); + return allowedStates.contains(element.getLifecycleState()); + } +} -- cgit 1.2.3-korg