diff options
author | JvD_Ericsson <jeff.van.dam@est.tech> | 2023-07-25 09:47:41 +0100 |
---|---|---|
committer | Michael Morris <michael.morris@est.tech> | 2023-09-22 07:43:02 +0000 |
commit | 27633293d6d45521ea985019ea7b99c2009b62c7 (patch) | |
tree | 1e3df4c1aa47c14c2cb5abeb19080056748353a3 | |
parent | 629837b3f7a282c74604987fd531ff4523f98a0c (diff) |
Backend support for operation milestones with activity inputs
Issue-ID: SDC-4582
Signed-off-by: JvD_Ericsson <jeff.van.dam@est.tech>
Change-Id: I625ec9bb05790bb5f9e78ed9d65abda8f8af5ec3
12 files changed, 201 insertions, 5 deletions
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 9f0adcf217..c8d7862306 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 @@ -31,6 +31,7 @@ import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.OPERATIONS; import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.REQUIRED; import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.STATUS; import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.TYPE; +import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.VALUE; import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.WORKFLOW; import com.google.gson.Gson; @@ -211,10 +212,13 @@ public class InterfaceDefinitionHandler { for (Object activityValue : milestoneActivities) { ActivityDataDefinition activity = new ActivityDataDefinition(); if (activityValue instanceof Map) { - Map<String, String> activityMap = (Map<String, String>) activityValue; + Map<String, Object> activityMap = (Map<String, Object>) activityValue; + if (activityMap.containsKey(INPUTS.getElementName())) { + activity.setInputs(handleInterfaceOperationInputs((Map<String, Object>) activityMap.get(INPUTS.getElementName()))); + } if (activityMap.containsKey(TYPE.getElementName()) && activityMap.containsKey(WORKFLOW.getElementName())) { - activity.setType(activityMap.get(TYPE.getElementName())); - activity.setWorkflow(activityMap.get(WORKFLOW.getElementName())); + activity.setType((String) activityMap.get(TYPE.getElementName())); + activity.setWorkflow((String) activityMap.get(WORKFLOW.getElementName())); activities.add(activity); } else { return new ListDataDefinition<>(); @@ -268,6 +272,11 @@ public class InterfaceDefinitionHandler { LOGGER.debug(WITH_ATTRIBUTE, DEFAULT.getElementName(), json); operationInput.setToscaDefaultValue(json); } + if (inputPropertyValue.get(VALUE.getElementName()) != null) { + final Gson gson = new Gson(); + final String json = gson.toJson(inputPropertyValue.get(VALUE.getElementName())); + operationInput.setValue(json); + } if (inputPropertyValue.get(STATUS.getElementName()) != null) { final String status = inputPropertyValue.get(STATUS.getElementName()).toString(); LOGGER.debug(WITH_ATTRIBUTE, STATUS.getElementName(), status); diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/InterfacesOperationsConverter.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/InterfacesOperationsConverter.java index e95f16eaac..52fdfcc4e5 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/InterfacesOperationsConverter.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/InterfacesOperationsConverter.java @@ -36,6 +36,7 @@ import java.util.Set; import java.util.stream.Collectors; import org.apache.commons.collections.MapUtils; import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.math.NumberUtils; import org.openecomp.sdc.be.datatypes.elements.ActivityDataDefinition; @@ -332,6 +333,10 @@ public class InterfacesOperationsConverter { Map<String, ToscaActivity> toscaActivityMap = new HashMap<>(); ToscaActivity toscaActivity = new ToscaActivity(); toscaActivity.setWorkflow(activity.getWorkflow()); + Map<String, Object> inputs = getToscaActivityInputs(activity.getInputs(), dataTypes); + if (!inputs.isEmpty()) { + toscaActivity.setInputs(inputs); + } toscaActivityMap.put(activity.getType(), toscaActivity); toscaActivities.add(toscaActivityMap); } @@ -342,6 +347,21 @@ public class InterfacesOperationsConverter { toscaOperation.setMilestones(toscaMilestones); } + private Map<String, Object> getToscaActivityInputs(ListDataDefinition<OperationInputDefinition> inputs, + Map<String, DataTypeDefinition> dataTypes) { + if (Objects.isNull(inputs) || inputs.isEmpty()) { + return null; + } + Map<String, Object> toscaInputs = new HashMap<>(); + for (OperationInputDefinition input : inputs.getListToscaDataDefinition()) { + Object value = propertyConvertor.convertToToscaObject(input, getInputValue(input), dataTypes, false); + if (ObjectUtils.isNotEmpty(value)) { + toscaInputs.put(input.getName(), value); + } + } + return toscaInputs; + } + private boolean operationHasAnImplementation(OperationDataDefinition operation) { return operation.getImplementation() != null && StringUtils.isNotEmpty(operation.getImplementation().getArtifactName()) && !operation.getImplementation().getArtifactName().equals("''"); diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaActivity.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaActivity.java index 736988e85e..3f33bc7ab3 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaActivity.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaActivity.java @@ -21,10 +21,12 @@ package org.openecomp.sdc.be.tosca.model; +import java.util.Map; import lombok.Data; @Data public class ToscaActivity { String workflow; + private Map<String, Object> inputs; } diff --git a/catalog-be/src/main/resources/import/tosca/data-types/dataTypes.yml b/catalog-be/src/main/resources/import/tosca/data-types/dataTypes.yml index 1b2c0402c1..24bed4d567 100644 --- a/catalog-be/src/main/resources/import/tosca/data-types/dataTypes.yml +++ b/catalog-be/src/main/resources/import/tosca/data-types/dataTypes.yml @@ -3478,3 +3478,21 @@ tosca.datatypes.asd.requiredPlugin: description: "the version of the required K8s plugin" type: string required: true + +tosca.dataTypes.tmf.milestoneJeopardyData: + derived_from: tosca.datatypes.Root + properties: + name: + type: string + required: true + message: + type: string + required: true + eventType: + type: string + required: true + valid_values: [milestone, jeopardy] + jeopardyType: + type: string + required: false + valid_values: [normal, critical, hazard] diff --git a/catalog-be/src/main/resources/import/tosca/models/init/acm/imports/acm.yaml b/catalog-be/src/main/resources/import/tosca/models/init/acm/imports/acm.yaml index c88d7235e9..9ef248232d 100644 --- a/catalog-be/src/main/resources/import/tosca/models/init/acm/imports/acm.yaml +++ b/catalog-be/src/main/resources/import/tosca/models/init/acm/imports/acm.yaml @@ -584,3 +584,20 @@ node_types: typeVersion: 1.0.0 description: The connfiguration entities the Automation Composition Element is managing and their associated REST requests + tosca.dataTypes.tmf.milestoneJeopardyData: + derived_from: tosca.datatypes.Root + properties: + name: + type: string + required: true + message: + type: string + required: true + eventType: + type: string + required: true + valid_values: [milestone, jeopardy] + jeopardyType: + type: string + required: false + valid_values: [normal, critical, hazard] diff --git a/catalog-be/src/main/resources/import/tosca/models/init/acm/tosca/data-types/dataTypes.yml b/catalog-be/src/main/resources/import/tosca/models/init/acm/tosca/data-types/dataTypes.yml index 48e514288a..7cc808bdb3 100644 --- a/catalog-be/src/main/resources/import/tosca/models/init/acm/tosca/data-types/dataTypes.yml +++ b/catalog-be/src/main/resources/import/tosca/models/init/acm/tosca/data-types/dataTypes.yml @@ -374,3 +374,21 @@ org.onap.datatypes.policy.clamp.acm.httpAutomationCompositionElement.Configurati type: org.onap.datatypes.policy.clamp.acm.httpAutomationCompositionElement.RestRequest typeVersion: 1.0.0 description: A sequence of REST commands to send to the REST endpoint + +tosca.dataTypes.tmf.milestoneJeopardyData: + derived_from: tosca.datatypes.Root + properties: + name: + type: string + required: true + message: + type: string + required: true + eventType: + type: string + required: true + valid_values: [milestone, jeopardy] + jeopardyType: + type: string + required: false + valid_values: [normal, critical, hazard] diff --git a/catalog-be/src/main/resources/import/tosca/models/init/etsi-SOL001-v2.5.1/imports/etsi_nfv_sol001_nsd_types.yaml b/catalog-be/src/main/resources/import/tosca/models/init/etsi-SOL001-v2.5.1/imports/etsi_nfv_sol001_nsd_types.yaml index 6462c3d66c..0b1a6217ee 100644 --- a/catalog-be/src/main/resources/import/tosca/models/init/etsi-SOL001-v2.5.1/imports/etsi_nfv_sol001_nsd_types.yaml +++ b/catalog-be/src/main/resources/import/tosca/models/init/etsi-SOL001-v2.5.1/imports/etsi_nfv_sol001_nsd_types.yaml @@ -525,3 +525,20 @@ policy_types: - less_or_equal: 65535 default: 65535 targets: [ tosca.nodes.nfv.Sap ] + tosca.dataTypes.tmf.milestoneJeopardyData: + derived_from: tosca.datatypes.Root + properties: + name: + type: string + required: true + message: + type: string + required: true + eventType: + type: string + required: true + valid_values: [milestone, jeopardy] + jeopardyType: + type: string + required: false + valid_values: [normal, critical, hazard] diff --git a/catalog-be/src/main/resources/import/tosca/models/init/etsi-SOL001-v2.5.1/imports/etsi_nfv_sol001_vnfd_types.yaml b/catalog-be/src/main/resources/import/tosca/models/init/etsi-SOL001-v2.5.1/imports/etsi_nfv_sol001_vnfd_types.yaml index 48f8e6478c..51b691f223 100644 --- a/catalog-be/src/main/resources/import/tosca/models/init/etsi-SOL001-v2.5.1/imports/etsi_nfv_sol001_vnfd_types.yaml +++ b/catalog-be/src/main/resources/import/tosca/models/init/etsi-SOL001-v2.5.1/imports/etsi_nfv_sol001_vnfd_types.yaml @@ -1607,3 +1607,20 @@ policy_types: description: Provide additional data to access the interface endpoint required: false targets: [ tosca.nodes.nfv.VnfExtCp, tosca.nodes.nfv.VduCp ] + tosca.dataTypes.tmf.milestoneJeopardyData: + derived_from: tosca.datatypes.Root + properties: + name: + type: string + required: true + message: + type: string + required: true + eventType: + type: string + required: true + valid_values: [milestone, jeopardy] + jeopardyType: + type: string + required: false + valid_values: [normal, critical, hazard] diff --git a/catalog-be/src/main/resources/import/tosca/models/init/etsi-SOL001-v2.5.1/tosca/data-types/dataTypes.yml b/catalog-be/src/main/resources/import/tosca/models/init/etsi-SOL001-v2.5.1/tosca/data-types/dataTypes.yml index 8d8b779d25..12bc82a33f 100644 --- a/catalog-be/src/main/resources/import/tosca/models/init/etsi-SOL001-v2.5.1/tosca/data-types/dataTypes.yml +++ b/catalog-be/src/main/resources/import/tosca/models/init/etsi-SOL001-v2.5.1/tosca/data-types/dataTypes.yml @@ -971,3 +971,21 @@ tosca.datatypes.nfv.VnfLcmOperationsConfiguration: type: tosca.datatypes.nfv.VnfChangeExtConnectivityOperationConfiguration description: Configuration parameters for the changeExtVnfConnectivityOpConfig operation required: false + +tosca.dataTypes.tmf.milestoneJeopardyData: + derived_from: tosca.datatypes.Root + properties: + name: + type: string + required: true + message: + type: string + required: true + eventType: + type: string + required: true + valid_values: [milestone, jeopardy] + jeopardyType: + type: string + required: false + valid_values: [normal, critical, hazard] diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/InterfacesOperationsConverterTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/InterfacesOperationsConverterTest.java index dfe4107b86..974d321c62 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/InterfacesOperationsConverterTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/InterfacesOperationsConverterTest.java @@ -427,9 +427,18 @@ class InterfacesOperationsConverterTest { private Map<String, MilestoneDataDefinition> createMilestones() { Map<String, MilestoneDataDefinition> toscaMilestones = new HashMap<>(); + OperationInputDefinition input1 = new OperationInputDefinition(); + input1.setValue("testString"); + input1.setType("string"); + input1.setName("stringName"); + OperationInputDefinition input2 = createMockComplexOperationInputDefinition("complex", "complex"); + ListDataDefinition<OperationInputDefinition> inputs = new ListDataDefinition<>(); + inputs.add(input1); + inputs.add(input2); ActivityDataDefinition activity = new ActivityDataDefinition(); activity.setType(ActivityTypeEnum.DELEGATE.getValue()); activity.setWorkflow("workflow1"); + activity.setInputs(inputs); ListDataDefinition<ActivityDataDefinition> activities = new ListDataDefinition<>(); activities.add(activity); MilestoneDataDefinition milestone = new MilestoneDataDefinition(); @@ -607,6 +616,7 @@ class InterfacesOperationsConverterTest { @Test void testGetInterfaceAsMapWithMilestones() { + addComplexTypeToDataTypes(); Component component = new Resource(); component.setNormalizedName("normalizedComponentName"); InterfaceDefinition addedInterface = new InterfaceDefinition(); @@ -637,9 +647,31 @@ class InterfacesOperationsConverterTest { Map<String, Object> activity = activities.get(0); assertEquals(1, activities.size()); assertTrue(activity.containsKey("delegate")); - Map<String, String> activityVariables = (Map<String, String>) activity.get("delegate"); + Map<String, Object> activityVariables = (Map<String, Object>) activity.get("delegate"); assertTrue(activityVariables.containsKey("workflow")); assertEquals("workflow1", activityVariables.get("workflow")); + assertTrue(activityVariables.containsKey("inputs")); + assertTrue(activityVariables.get("inputs") instanceof Map); + Map<String, Object> inputs = (Map<String, Object>) activityVariables.get("inputs"); + assertNotNull(inputs); + assertTrue(inputs.containsKey("stringName")); + assertTrue(inputs.get("stringName") instanceof String); + String input = (String) inputs.get("stringName"); + assertEquals("testString", input); + assertTrue(inputs.containsKey("complex")); + Map<String, Object> complexInput = (Map<String, Object>) inputs.get("complex"); + assertTrue(complexInput.containsKey("intProp")); + assertTrue(complexInput.get("intProp") instanceof Integer); + assertEquals(1, complexInput.get("intProp")); + assertTrue(complexInput.containsKey("stringProp")); + Map<String, Object> complexInputStringProp = (Map<String, Object>) complexInput.get("stringProp"); + assertTrue(complexInputStringProp.containsKey("type")); + assertTrue(ToscaFunctionType.findType((String) complexInputStringProp.get("type")).isPresent()); + assertTrue(complexInputStringProp.containsKey("propertyName")); + assertEquals("designer", complexInputStringProp.get("propertyName")); + assertTrue(complexInputStringProp.containsKey("propertySource")); + assertEquals("SELF", complexInputStringProp.get("propertySource")); + } private void addComplexTypeToDataTypes() { diff --git a/catalog-be/src/test/resources/interfaceDefinition/interfaceDefinition-legacy.yaml b/catalog-be/src/test/resources/interfaceDefinition/interfaceDefinition-legacy.yaml index 8f350edd54..7daba75d5e 100644 --- a/catalog-be/src/test/resources/interfaceDefinition/interfaceDefinition-legacy.yaml +++ b/catalog-be/src/test/resources/interfaceDefinition/interfaceDefinition-legacy.yaml @@ -59,6 +59,24 @@ start: workflow: workflow1 - type: delegate workflow: workflow2 + inputs: + string: + type: string + value: testString + complex: + type: tosca.datatypes.nfv.VirtualCpu + value: + virtual_cpu_oversubscription_policy: pol + cpu_architecture: cpu + virtual_cpu_clock: 27Hz + vdu_cpu_requirements: + 'k1': 'v1' + 'k2': 'v2' + virtual_cpu_pinning: + virtual_cpu_pinning_policy: pol + virtual_cpu_pinning_rule: + - 1 + - 2 on_timeout: activities: - type: delegate diff --git a/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/ActivityDataDefinition.java b/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/ActivityDataDefinition.java index 8d76f68a67..2f5eb303a3 100644 --- a/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/ActivityDataDefinition.java +++ b/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/ActivityDataDefinition.java @@ -31,7 +31,8 @@ public class ActivityDataDefinition extends ToscaDataDefinition implements Seria public ActivityDataDefinition(ActivityDataDefinition activity) { setType(activity.getType()); - setWorkflow(getWorkflow()); + setWorkflow(activity.getWorkflow()); + setInputs(activity.getInputs()); } public String getType() { @@ -50,4 +51,13 @@ public class ActivityDataDefinition extends ToscaDataDefinition implements Seria setToscaPresentationValue(JsonPresentationFields.OPERATION_ACTIVITIES_WORKFLOW, workflow); } + public ListDataDefinition<OperationInputDefinition> getInputs() { + return (ListDataDefinition<OperationInputDefinition>) getToscaPresentationValue( + JsonPresentationFields.INPUTS); + } + + public void setInputs(ListDataDefinition<OperationInputDefinition> inputs) { + setToscaPresentationValue(JsonPresentationFields.INPUTS, inputs); + } + } |