1 package org.openecomp.sdc.asdctool.impl.validator.tasks.moduleJson;
4 import org.apache.cassandra.cql3.CQL3Type;
5 import org.openecomp.sdc.asdctool.impl.validator.tasks.ServiceValidationTask;
6 import org.openecomp.sdc.asdctool.impl.validator.utils.ReportManager;
7 import org.openecomp.sdc.be.dao.jsongraph.GraphVertex;
8 import org.openecomp.sdc.be.datatypes.elements.ArtifactDataDefinition;
9 import org.openecomp.sdc.be.datatypes.elements.MapArtifactDataDefinition;
10 import org.openecomp.sdc.be.datatypes.elements.MapGroupsDataDefinition;
11 import org.openecomp.sdc.be.model.ComponentParametersView;
12 import org.openecomp.sdc.be.model.LifecycleStateEnum;
13 import org.openecomp.sdc.be.model.jsontitan.datamodel.TopologyTemplate;
14 import org.openecomp.sdc.be.model.jsontitan.datamodel.ToscaElement;
15 import org.openecomp.sdc.be.model.jsontitan.operations.TopologyTemplateOperation;
16 import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
17 import org.springframework.beans.factory.annotation.Autowired;
20 import java.util.stream.Collectors;
23 * Created by chaya on 7/18/2017.
25 public class ModuleJsonTask extends ServiceValidationTask {
28 private TopologyTemplateOperation topologyTemplateOperation;
30 public ModuleJsonTask() {
31 this.name = "Service Module json Validation Task";
35 public boolean validate(GraphVertex vertex) {
36 ComponentParametersView paramView = new ComponentParametersView();
37 paramView.disableAll();
38 paramView.setIgnoreArtifacts(false);
39 paramView.setIgnoreGroups(false);
40 paramView.setIgnoreComponentInstances(false);
41 Either<ToscaElement, StorageOperationStatus> toscaElementEither = topologyTemplateOperation.getToscaElement(vertex.getUniqueId(), paramView);
42 if (toscaElementEither.isRight()) {
45 TopologyTemplate element = (TopologyTemplate) toscaElementEither.left().value();
46 if (!isAfterSubmitForTesting(element)) {
49 Map<String, MapGroupsDataDefinition> instGroups = element.getInstGroups();
50 Map<String, MapArtifactDataDefinition> instDeploymentArtifacts = element.getInstDeploymentArtifacts();
52 for (Map.Entry<String, MapGroupsDataDefinition> pair : Optional.ofNullable(instGroups).orElse(Collections.emptyMap()).entrySet()) {
53 MapGroupsDataDefinition groups = pair.getValue();
54 if (groups != null && !groups.getMapToscaDataDefinition().isEmpty()) {
55 return findCoordinateModuleJson(pair, instDeploymentArtifacts, vertex);
62 private boolean findCoordinateModuleJson(Map.Entry<String, MapGroupsDataDefinition> pair, Map<String, MapArtifactDataDefinition> instDeploymentArtifacts, GraphVertex vertex) {
63 String groupKey = pair.getKey();
64 String[] split = groupKey.split("\\.");
65 String instanceName = split[split.length-1];
66 MapArtifactDataDefinition deploymentsArtifacts = instDeploymentArtifacts.get(groupKey);
67 if (deploymentsArtifacts != null && !deploymentsArtifacts.getMapToscaDataDefinition().isEmpty()) {
68 List<ArtifactDataDefinition> moduleJsonArtifacts = deploymentsArtifacts.getMapToscaDataDefinition().values().stream().filter(artifact -> {
69 String artifactName = artifact.getArtifactName();
70 if (artifactName.startsWith(instanceName) && artifactName.endsWith("modules.json")) {
74 }).collect(Collectors.toList());
75 if (moduleJsonArtifacts.size() > 0) {
76 String status = "Instance "+instanceName+" has a corresponding modules.json file: "+moduleJsonArtifacts.get(0).getArtifactName();
77 ReportManager.writeReportLineToFile(status);
81 String status = "Instance "+instanceName+" doesn't have a corresponding modules.json file";
82 ReportManager.writeReportLineToFile(status);
83 ReportManager.addFailedVertex(getTaskName(), vertex.getUniqueId());
87 private boolean isAfterSubmitForTesting(TopologyTemplate element){
88 List allowedStates = new ArrayList<>(Arrays.asList(LifecycleStateEnum.READY_FOR_CERTIFICATION,
89 LifecycleStateEnum.CERTIFICATION_IN_PROGRESS, LifecycleStateEnum.CERTIFIED));
90 return allowedStates.contains(element.getLifecycleState());