diff options
Diffstat (limited to 'asdctool')
2 files changed, 80 insertions, 0 deletions
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; @@ -38,6 +39,9 @@ public class ValidationToolConfiguration { 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<ToscaElement, StorageOperationStatus> toscaElementEither = topologyTemplateOperation.getToscaElement(vertex.getUniqueId(), paramView); + if (toscaElementEither.isRight()) { + return false; + } + TopologyTemplate element = (TopologyTemplate) toscaElementEither.left().value(); + if (!isAfterSubmitForTesting(element)) { + return false; + } + Map<String, MapGroupsDataDefinition> instGroups = element.getInstGroups(); + Map<String, MapArtifactDataDefinition> instDeploymentArtifacts = element.getInstDeploymentArtifacts(); + + for (Map.Entry<String, MapGroupsDataDefinition> 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<ArtifactDataDefinition> 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()); + } +} |