aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichaelMorris <michael.morris@est.tech>2023-10-08 12:41:06 +0100
committerMichaelMorris <michael.morris@est.tech>2023-10-09 14:46:53 +0100
commit38a997dfc171ab2e8eb3e6a2fd27342a65bda8db (patch)
treeddbb8d81cc7509cdbd2144c6698075e68f3d5906
parentd3bf58392f2a1c98b8d2289b70844ce39fb62e64 (diff)
Import service with milestones
Signed-off-by: MichaelMorris <michael.morris@est.tech> Issue-ID: SDC-4647 Change-Id: I23ceb41a90a887774396d5caf8fb6eac8aa318a6
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/YamlTemplateParsingHandler.java17
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InterfaceDefinitionHandler.java39
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogic.java1
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/csar/YamlTemplateParsingHandlerTest.java5
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogicTest.java2
5 files changed, 44 insertions, 20 deletions
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/YamlTemplateParsingHandler.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/YamlTemplateParsingHandler.java
index 7970dd2680..a5927a5b45 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/YamlTemplateParsingHandler.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/YamlTemplateParsingHandler.java
@@ -45,6 +45,7 @@ import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.INPUTS;
import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.INTERFACES;
import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.IS_PASSWORD;
import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.MEMBERS;
+import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.MILESTONES;
import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.NODE;
import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.NODE_TEMPLATES;
import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.NODE_TYPE;
@@ -88,6 +89,7 @@ import org.apache.commons.lang3.StringUtils;
import org.openecomp.sdc.be.components.impl.AnnotationBusinessLogic;
import org.openecomp.sdc.be.components.impl.GroupTypeBusinessLogic;
import org.openecomp.sdc.be.components.impl.ImportUtils;
+import org.openecomp.sdc.be.components.impl.InterfaceDefinitionHandler;
import org.openecomp.sdc.be.components.impl.NodeFilterUploadCreator;
import org.openecomp.sdc.be.components.impl.PolicyTypeBusinessLogic;
import org.openecomp.sdc.be.components.impl.ServiceBusinessLogic;
@@ -96,10 +98,13 @@ import org.openecomp.sdc.be.components.utils.PropertiesUtils;
import org.openecomp.sdc.be.config.BeEcompErrorManager;
import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.dao.janusgraph.JanusGraphDao;
+import org.openecomp.sdc.be.datatypes.elements.ActivityDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.ArtifactDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.CapabilityDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.FilterDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.GetInputValueDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.ListDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.MilestoneDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.OperationDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.OperationInputDefinition;
import org.openecomp.sdc.be.datatypes.elements.PolicyTargetType;
@@ -108,8 +113,8 @@ import org.openecomp.sdc.be.datatypes.elements.PropertyFilterConstraintDataDefin
import org.openecomp.sdc.be.datatypes.elements.SubPropertyToscaFunction;
import org.openecomp.sdc.be.datatypes.elements.SubstitutionFilterPropertyDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.ToscaFunction;
-import org.openecomp.sdc.be.datatypes.elements.ToscaGetFunctionDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.ToscaFunctionType;
+import org.openecomp.sdc.be.datatypes.enums.ActivityTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.ConstraintType;
import org.openecomp.sdc.be.datatypes.enums.FilterValueType;
import org.openecomp.sdc.be.datatypes.enums.PropertyFilterTargetType;
@@ -125,7 +130,6 @@ import org.openecomp.sdc.be.model.ParsedToscaYamlInfo;
import org.openecomp.sdc.be.model.PolicyDefinition;
import org.openecomp.sdc.be.model.PolicyTypeDefinition;
import org.openecomp.sdc.be.model.PropertyDefinition;
-import org.openecomp.sdc.be.model.Resource;
import org.openecomp.sdc.be.model.UploadArtifactInfo;
import org.openecomp.sdc.be.model.UploadAttributeInfo;
import org.openecomp.sdc.be.model.UploadCapInfo;
@@ -159,13 +163,15 @@ public class YamlTemplateParsingHandler {
private final PolicyTypeBusinessLogic policyTypeBusinessLogic;
private final ServiceBusinessLogic serviceBusinessLogic;
private final ToscaFunctionYamlParsingHandler toscaFunctionYamlParsingHandler;
+ private final InterfaceDefinitionHandler interfaceDefinitionHandler;
public YamlTemplateParsingHandler(JanusGraphDao janusGraphDao,
GroupTypeBusinessLogic groupTypeBusinessLogic,
AnnotationBusinessLogic annotationBusinessLogic,
PolicyTypeBusinessLogic policyTypeBusinessLogic,
ServiceBusinessLogic serviceBusinessLogic,
- final ToscaFunctionYamlParsingHandler toscaFunctionYamlParsingHandler
+ final ToscaFunctionYamlParsingHandler toscaFunctionYamlParsingHandler,
+ final InterfaceDefinitionHandler interfaceDefinitionHandler
) {
this.janusGraphDao = janusGraphDao;
this.groupTypeBusinessLogic = groupTypeBusinessLogic;
@@ -173,6 +179,7 @@ public class YamlTemplateParsingHandler {
this.policyTypeBusinessLogic = policyTypeBusinessLogic;
this.serviceBusinessLogic = serviceBusinessLogic;
this.toscaFunctionYamlParsingHandler = toscaFunctionYamlParsingHandler;
+ this.interfaceDefinitionHandler = interfaceDefinitionHandler;
}
public ParsedToscaYamlInfo parseResourceInfoFromYAML(String fileName, String resourceYml, Map<String, String> createdNodesToscaResourceNames,
@@ -1296,6 +1303,10 @@ public class YamlTemplateParsingHandler {
final Map<String, Object> interfaceInputs = (Map<String, Object>) operationValue.get(INPUTS.getElementName());
operationDef.setInputs(handleInterfaceOperationInputs(interfaceInputs));
}
+ if (operationValue.containsKey(MILESTONES.getElementName())) {
+ final Map<String, Object> interfaceMilestones = (Map<String, Object>) operationValue.get(MILESTONES.getElementName());
+ operationDef.setMilestones(interfaceDefinitionHandler.handleInterfaceOperationMilestones(interfaceMilestones));
+ }
operations.put(operationEntry.getKey(), operationDef);
}
interfaceDef.setOperations(operations);
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InterfaceDefinitionHandler.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InterfaceDefinitionHandler.java
index 3eb8d786b9..8d713c48b0 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InterfaceDefinitionHandler.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InterfaceDefinitionHandler.java
@@ -42,12 +42,14 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;
import java.util.Optional;
+import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors;
import org.apache.commons.collections.MapUtils;
@@ -197,7 +199,7 @@ public class InterfaceDefinitionHandler {
return operation;
}
- private Map<String, MilestoneDataDefinition> handleInterfaceOperationMilestones(final Map<String, Object> interfaceMilestones) {
+ public Map<String, MilestoneDataDefinition> handleInterfaceOperationMilestones(final Map<String, Object> interfaceMilestones) {
final Map<String, MilestoneDataDefinition> milestones = new HashMap<>();
for (final Entry<String, Object> interfaceInput : interfaceMilestones.entrySet()) {
final MilestoneDataDefinition operationMilestone = new MilestoneDataDefinition();
@@ -311,24 +313,31 @@ public class InterfaceDefinitionHandler {
final ListDataDefinition<OperationInputDefinition> inputs = new ListDataDefinition<>();
final String defaultType = "tosca.dataTypes.tmf.milestoneJeopardyData";
for (final Entry<String, Object> interfaceInput : activityInputs.entrySet()) {
- final OperationInputDefinition operationInput = new OperationInputDefinition();
- operationInput.setUniqueId(UUID.randomUUID().toString());
- operationInput.setInputId(operationInput.getUniqueId());
- operationInput.setName(interfaceInput.getKey());
- operationInput.setType(defaultType);
- if (Objects.nonNull(interfaceInput.getValue())) {
- if (interfaceInput.getValue() instanceof Map) {
- Map<String, Object> valueMap = (Map<String, Object>) interfaceInput.getValue();
- if (valueMap.containsKey("jeopardyType") && valueMap.containsKey("name") &&
- valueMap.containsKey("eventType") && valueMap.containsKey("message")) {
- operationInput.setValue(new Gson().toJson(interfaceInput.getValue()));
- }
- }
+ if (isMilestoneJeopardyData(interfaceInput.getValue())) {
+ final OperationInputDefinition operationInput = new OperationInputDefinition();
+ operationInput.setUniqueId(UUID.randomUUID().toString());
+ operationInput.setInputId(operationInput.getUniqueId());
+ operationInput.setName(interfaceInput.getKey());
+ operationInput.setType(defaultType);
+ operationInput.setValue(new Gson().toJson(interfaceInput.getValue()));
+ inputs.add(operationInput);
}
- inputs.add(operationInput);
}
return inputs;
+ }
+
+ private boolean isMilestoneJeopardyData(Object value) {
+ if (value instanceof Map) {
+ Set<String> allowedKeys = new HashSet<>();
+ allowedKeys.add("jeopardyType");
+ allowedKeys.add("name");
+ allowedKeys.add("eventType");
+ allowedKeys.add("message");
+ Map<String, Object> valueMap = (Map<String, Object>) value;
+ return allowedKeys.containsAll(valueMap.keySet());
+ }
+ return false;
}
private ListDataDefinition<OperationInputDefinition> handleInterfaceOperationInputs(final Map<String, Object> interfaceInputs) {
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogic.java
index 6301929ce3..d4f67ec13d 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogic.java
@@ -2511,6 +2511,7 @@ public class ServiceImportBusinessLogic {
templateOperation.setImplementation(instanceOperation.getImplementation());
//Description
templateOperation.setDescription(instanceOperation.getDescription());
+ templateOperation.setMilestones(instanceOperation.getMilestones());
operationsToAdd.put(operation.getKey(), templateOperation);
}
InterfaceDefinition interfaceDef = new InterfaceDefinition();
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/csar/YamlTemplateParsingHandlerTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/csar/YamlTemplateParsingHandlerTest.java
index 218e0267d2..f5ffb8af81 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/csar/YamlTemplateParsingHandlerTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/csar/YamlTemplateParsingHandlerTest.java
@@ -33,6 +33,7 @@ import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.openecomp.sdc.be.components.impl.AnnotationBusinessLogic;
import org.openecomp.sdc.be.components.impl.GroupTypeBusinessLogic;
+import org.openecomp.sdc.be.components.impl.InterfaceDefinitionHandler;
import org.openecomp.sdc.be.components.impl.PolicyTypeBusinessLogic;
import org.openecomp.sdc.be.components.impl.ServiceBusinessLogic;
import org.openecomp.sdc.be.components.validation.AnnotationValidator;
@@ -95,6 +96,8 @@ public class YamlTemplateParsingHandlerTest {
private ServiceBusinessLogic serviceBusinessLogic;
@Mock
private ToscaFunctionYamlParsingHandler toscaFunctionYamlParsingHandler;
+ @Mock
+ private InterfaceDefinitionHandler interfaceDefinitionHandler;
private YamlTemplateParsingHandler handler;
@@ -142,7 +145,7 @@ public class YamlTemplateParsingHandlerTest {
public void setup() {
final var annotationBusinessLogic = new AnnotationBusinessLogic(annotationTypeOperations, annotationValidator);
handler = new YamlTemplateParsingHandler(janusGraphDao, groupTypeBusinessLogic, annotationBusinessLogic, policyTypeBusinessLogic,
- serviceBusinessLogic, toscaFunctionYamlParsingHandler);
+ serviceBusinessLogic, toscaFunctionYamlParsingHandler, interfaceDefinitionHandler);
ReflectionTestUtils.setField(handler, "policyTypeBusinessLogic", policyTypeBusinessLogic);
}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogicTest.java
index e4ebd78cce..88cd464279 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogicTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogicTest.java
@@ -1490,7 +1490,7 @@ class ResourceBusinessLogicTest {
String resourceYml = new String(csar.get("Definitions/my_vnf.yaml"));
YamlTemplateParsingHandler yamlTemplateParser = new YamlTemplateParsingHandler(mockJanusGraphDao, null,
- Mockito.mock(AnnotationBusinessLogic.class), null, null, null);
+ Mockito.mock(AnnotationBusinessLogic.class), null, null, null, null);
final ParsedToscaYamlInfo parsedToscaYamlInfo = yamlTemplateParser.parseResourceInfoFromYAML("Definitions/my_vnf.yml", resourceYml,
Collections.EMPTY_MAP, Collections.EMPTY_MAP, "myVnf", resourceResponse, "");