aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFrancescoFioraEst <francesco.fiora@est.tech>2024-01-04 11:15:14 +0000
committerFrancesco Fiora <francesco.fiora@est.tech>2024-01-04 13:06:41 +0000
commit2064e725f74edf8fc7873c9ebef1d8bf7f65c5a8 (patch)
treecf068355e05e72fa16154744316763546a751cec
parent664af40d4c073404d6c067731e25fc44dab3f2c2 (diff)
Add support for OutProperties instance in deploy scenario
Add support for OutProperties instance, operationalState and useState in deploy scenario. Issue-ID: POLICY-4911 Change-Id: I47b5e63b21e4fedd625413de8e80797138fb8d8a Signed-off-by: FrancescoFioraEst <francesco.fiora@est.tech>
-rw-r--r--participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/handler/CacheProvider.java12
-rw-r--r--participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/CacheProviderTest.java73
-rw-r--r--participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/main/parameters/CommonTestData.java50
3 files changed, 100 insertions, 35 deletions
diff --git a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/handler/CacheProvider.java b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/handler/CacheProvider.java
index 08d5ccd32..dc1bb051a 100644
--- a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/handler/CacheProvider.java
+++ b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/handler/CacheProvider.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2023 Nordix Foundation.
+ * Copyright (C) 2023-2024 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -133,6 +133,7 @@ public class CacheProvider {
*/
public void initializeAutomationComposition(@NonNull UUID compositionId, @NonNull UUID instanceId,
ParticipantDeploy participantDeploy) {
+ var acLast = automationCompositions.get(instanceId);
Map<UUID, AutomationCompositionElement> acElementMap = new LinkedHashMap<>();
for (var element : participantDeploy.getAcElementList()) {
var acElement = new AutomationCompositionElement();
@@ -142,14 +143,19 @@ public class CacheProvider {
acElement.setDeployState(DeployState.DEPLOYING);
acElement.setLockState(LockState.NONE);
acElement.setProperties(element.getProperties());
+ var acElementLast = acLast != null ? acLast.getElements().get(element.getId()) : null;
+ if (acElementLast != null) {
+ acElement.setOutProperties(acElementLast.getOutProperties());
+ acElement.setOperationalState(acElementLast.getOperationalState());
+ acElement.setUseState(acElementLast.getUseState());
+ }
acElementMap.put(element.getId(), acElement);
}
-
var automationComposition = new AutomationComposition();
automationComposition.setCompositionId(compositionId);
automationComposition.setInstanceId(instanceId);
automationComposition.setElements(acElementMap);
- automationCompositions.put(automationComposition.getInstanceId(), automationComposition);
+ automationCompositions.put(instanceId, automationComposition);
}
/**
diff --git a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/CacheProviderTest.java b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/CacheProviderTest.java
index f207dc511..e55de0192 100644
--- a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/CacheProviderTest.java
+++ b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/CacheProviderTest.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2023 Nordix Foundation.
+ * Copyright (C) 2023-2024 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -24,17 +24,10 @@ import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.jupiter.api.Assertions.assertEquals;
-import java.util.ArrayList;
-import java.util.List;
import java.util.Map;
import java.util.UUID;
import org.junit.jupiter.api.Test;
import org.onap.policy.clamp.acm.participant.intermediary.main.parameters.CommonTestData;
-import org.onap.policy.clamp.common.acm.exception.AutomationCompositionException;
-import org.onap.policy.clamp.models.acm.concepts.AcElementDeploy;
-import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElementDefinition;
-import org.onap.policy.clamp.models.acm.concepts.ParticipantDeploy;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate;
class CacheProviderTest {
@@ -81,34 +74,19 @@ class CacheProviderTest {
}
@Test
- void testinitCommonProperties() throws AutomationCompositionException {
- var parameter = CommonTestData.getParticipantParameters();
- var cacheProvider = new CacheProvider(parameter);
- var participantDeploy = new ParticipantDeploy();
- participantDeploy.setParticipantId(cacheProvider.getParticipantId());
-
- var compositionId = UUID.randomUUID();
-
- List<AutomationCompositionElementDefinition> definitions = new ArrayList<>();
+ void testinitCommonProperties() {
var automationComposition =
CommonTestData.getTestAutomationCompositions().getAutomationCompositionList().get(0);
automationComposition.setInstanceId(UUID.randomUUID());
+ var compositionId = UUID.randomUUID();
automationComposition.setCompositionId(compositionId);
- for (var element : automationComposition.getElements().values()) {
- var acElementDefinition = new AutomationCompositionElementDefinition();
- acElementDefinition.setAcElementDefinitionId(element.getDefinition());
- var nodeTemplate = new ToscaNodeTemplate();
- nodeTemplate.setProperties(Map.of("key", "value"));
- acElementDefinition.setAutomationCompositionElementToscaNodeTemplate(nodeTemplate);
- definitions.add(acElementDefinition);
-
- var acElement = new AcElementDeploy();
- acElement.setId(element.getId());
- acElement.setDefinition(element.getDefinition());
- participantDeploy.getAcElementList().add(acElement);
- }
+ var definitions =
+ CommonTestData.createAutomationCompositionElementDefinitionList(automationComposition);
+ var cacheProvider = new CacheProvider(CommonTestData.getParticipantParameters());
cacheProvider.addElementDefinition(compositionId, definitions);
+ var participantDeploy =
+ CommonTestData.createparticipantDeploy(cacheProvider.getParticipantId(), automationComposition);
cacheProvider.initializeAutomationComposition(compositionId, automationComposition.getInstanceId(),
participantDeploy);
@@ -130,6 +108,41 @@ class CacheProviderTest {
}
@Test
+ void testDeply() {
+ var automationComposition =
+ CommonTestData.getTestAutomationCompositions().getAutomationCompositionList().get(0);
+ automationComposition.setInstanceId(UUID.randomUUID());
+ var compositionId = UUID.randomUUID();
+ automationComposition.setCompositionId(compositionId);
+ var parameter = CommonTestData.getParticipantParameters();
+ var cacheProvider = new CacheProvider(parameter);
+
+ var participantDeploy =
+ CommonTestData.createparticipantDeploy(cacheProvider.getParticipantId(), automationComposition);
+ cacheProvider.initializeAutomationComposition(compositionId, automationComposition.getInstanceId(),
+ participantDeploy);
+
+ var ac = cacheProvider.getAutomationComposition(automationComposition.getInstanceId());
+ for (var element : ac.getElements().values()) {
+ element.setOperationalState("OperationalState");
+ element.setUseState("UseState");
+ element.setOutProperties(Map.of("key", "value"));
+ }
+
+ // deploy again
+ cacheProvider.initializeAutomationComposition(compositionId, automationComposition.getInstanceId(),
+ participantDeploy);
+
+ // check UseState, OperationalState and OutProperties have not changed
+ ac = cacheProvider.getAutomationComposition(automationComposition.getInstanceId());
+ for (var element : ac.getElements().values()) {
+ assertEquals("OperationalState", element.getOperationalState());
+ assertEquals("UseState", element.getUseState());
+ assertEquals("value", element.getOutProperties().get("key"));
+ }
+ }
+
+ @Test
void testInitializeAutomationComposition() {
var parameter = CommonTestData.getParticipantParameters();
var cacheProvider = new CacheProvider(parameter);
diff --git a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/main/parameters/CommonTestData.java b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/main/parameters/CommonTestData.java
index acff103a2..46894fb43 100644
--- a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/main/parameters/CommonTestData.java
+++ b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/main/parameters/CommonTestData.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2021-2023 Nordix Foundation.
+ * Copyright (C) 2021-2024 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,6 +22,7 @@ package org.onap.policy.clamp.acm.participant.intermediary.main.parameters;
import java.io.File;
import java.time.Instant;
+import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
@@ -29,11 +30,14 @@ import java.util.TreeMap;
import java.util.UUID;
import org.onap.policy.clamp.acm.participant.intermediary.handler.DummyParticipantParameters;
import org.onap.policy.clamp.acm.participant.intermediary.parameters.ParticipantIntermediaryParameters;
+import org.onap.policy.clamp.models.acm.concepts.AcElementDeploy;
import org.onap.policy.clamp.models.acm.concepts.AcElementRestart;
import org.onap.policy.clamp.models.acm.concepts.AutomationComposition;
+import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElementDefinition;
import org.onap.policy.clamp.models.acm.concepts.AutomationCompositions;
import org.onap.policy.clamp.models.acm.concepts.DeployState;
import org.onap.policy.clamp.models.acm.concepts.LockState;
+import org.onap.policy.clamp.models.acm.concepts.ParticipantDeploy;
import org.onap.policy.clamp.models.acm.concepts.ParticipantRestartAc;
import org.onap.policy.clamp.models.acm.concepts.ParticipantSupportedElementType;
import org.onap.policy.clamp.models.acm.messages.dmaap.participant.AutomationCompositionStateChange;
@@ -44,6 +48,7 @@ import org.onap.policy.common.utils.coder.Coder;
import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.common.utils.coder.StandardCoder;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate;
/**
* Class to hold/create all parameters for test cases.
@@ -202,7 +207,7 @@ public class CommonTestData {
* Return a AutomationCompositionStateChange.
*
* @param participantId the participantId
- * @param instanceId th AutomationComposition Id
+ * @param instanceId the AutomationComposition Id
* @param deployOrder a DeployOrder
* @param lockOrder a LockOrder
* @return a AutomationCompositionStateChange
@@ -236,4 +241,45 @@ public class CommonTestData {
participantRestartAc.getAcElementList().add(acElementRestart);
return participantRestartAc;
}
+
+ /**
+ * Create a ParticipantDeploy from an AutomationComposition.
+ *
+ * @param participantId the participantId
+ * @param automationComposition the AutomationComposition
+ * @return the ParticipantDeploy
+ */
+ public static ParticipantDeploy createparticipantDeploy(UUID participantId,
+ AutomationComposition automationComposition) {
+ var participantDeploy = new ParticipantDeploy();
+ participantDeploy.setParticipantId(participantId);
+ for (var element : automationComposition.getElements().values()) {
+ var acElement = new AcElementDeploy();
+ acElement.setId(element.getId());
+ acElement.setDefinition(element.getDefinition());
+ acElement.setProperties(element.getProperties());
+ participantDeploy.getAcElementList().add(acElement);
+ }
+ return participantDeploy;
+ }
+
+ /**
+ * create a List of AutomationCompositionElementDefinition from an AutomationComposition.
+ *
+ * @param automationComposition the AutomationComposition
+ * @return the List of AutomationCompositionElementDefinition
+ */
+ public static List<AutomationCompositionElementDefinition>
+ createAutomationCompositionElementDefinitionList(AutomationComposition automationComposition) {
+ List<AutomationCompositionElementDefinition> definitions = new ArrayList<>();
+ for (var element : automationComposition.getElements().values()) {
+ var acElementDefinition = new AutomationCompositionElementDefinition();
+ acElementDefinition.setAcElementDefinitionId(element.getDefinition());
+ var nodeTemplate = new ToscaNodeTemplate();
+ nodeTemplate.setProperties(Map.of("key", "value"));
+ acElementDefinition.setAutomationCompositionElementToscaNodeTemplate(nodeTemplate);
+ definitions.add(acElementDefinition);
+ }
+ return definitions;
+ }
}