aboutsummaryrefslogtreecommitdiffstats
path: root/participant/participant-impl
diff options
context:
space:
mode:
authorFrancescoFioraEst <francesco.fiora@est.tech>2024-09-18 17:27:04 +0100
committerFrancescoFioraEst <francesco.fiora@est.tech>2024-12-11 17:16:19 +0000
commit2df59bcd84c52b013ac5f607acd0ae50fdbff8bf (patch)
tree8cfc384cea63c97808bd2b01c0acee3acaba976a /participant/participant-impl
parent4e99849bef97bdc98f96fd62668ab4f83aa25c7a (diff)
Move policy definition data under instance propertiesHEADmaster
Move policy definition data under instance properties for policy-participant. Issue-ID: POLICY-4938 Change-Id: I60c6536554ce3750f03e42e397f000b35b5d6e07 Signed-off-by: FrancescoFioraEst <francesco.fiora@est.tech>
Diffstat (limited to 'participant/participant-impl')
-rw-r--r--participant/participant-impl/participant-impl-kubernetes/src/test/java/org/onap/policy/clamp/acm/participant/kubernetes/parameters/CommonTestData.java5
-rw-r--r--participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/acm/participant/policy/main/handler/AutomationCompositionElementHandler.java16
-rw-r--r--participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/acm/participant/policy/main/handler/AutomationCompositionElementHandlerTest.java42
-rw-r--r--participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/acm/participant/sim/main/handler/AutomationCompositionElementHandlerV2Test.java15
-rw-r--r--participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/acm/participant/sim/main/handler/AutomationCompositionElementHandlerV3Test.java16
5 files changed, 70 insertions, 24 deletions
diff --git a/participant/participant-impl/participant-impl-kubernetes/src/test/java/org/onap/policy/clamp/acm/participant/kubernetes/parameters/CommonTestData.java b/participant/participant-impl/participant-impl-kubernetes/src/test/java/org/onap/policy/clamp/acm/participant/kubernetes/parameters/CommonTestData.java
index 42939b813..ae7f98d8d 100644
--- a/participant/participant-impl/participant-impl-kubernetes/src/test/java/org/onap/policy/clamp/acm/participant/kubernetes/parameters/CommonTestData.java
+++ b/participant/participant-impl/participant-impl-kubernetes/src/test/java/org/onap/policy/clamp/acm/participant/kubernetes/parameters/CommonTestData.java
@@ -37,7 +37,6 @@ 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.ToscaServiceTemplate;
public class CommonTestData {
@@ -199,11 +198,9 @@ public class CommonTestData {
* @return an InstanceElementDto
*/
public InstanceElementDto createInstanceElementDto(Map<String, Object> inProperties) {
- return new InstanceElementDto(getAutomationCompositionId(), UUID.randomUUID(),
- new ToscaServiceTemplate(), inProperties, new HashMap<>());
+ return new InstanceElementDto(getAutomationCompositionId(), UUID.randomUUID(), inProperties, new HashMap<>());
}
-
/**
* Create an compositionElementDto.
*
diff --git a/participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/acm/participant/policy/main/handler/AutomationCompositionElementHandler.java b/participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/acm/participant/policy/main/handler/AutomationCompositionElementHandler.java
index 5a3bc6328..5cf79acf8 100644
--- a/participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/acm/participant/policy/main/handler/AutomationCompositionElementHandler.java
+++ b/participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/acm/participant/policy/main/handler/AutomationCompositionElementHandler.java
@@ -36,6 +36,9 @@ import org.onap.policy.clamp.acm.participant.policy.client.PolicyApiHttpClient;
import org.onap.policy.clamp.acm.participant.policy.client.PolicyPapHttpClient;
import org.onap.policy.clamp.models.acm.concepts.DeployState;
import org.onap.policy.clamp.models.acm.concepts.StateChangeResult;
+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.base.PfModelException;
import org.onap.policy.models.pdp.concepts.DeploymentSubGroup;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
@@ -51,6 +54,7 @@ import org.springframework.stereotype.Component;
public class AutomationCompositionElementHandler extends AcElementListenerV2 {
private static final Logger LOGGER = LoggerFactory.getLogger(AutomationCompositionElementHandler.class);
+ private static final Coder CODER = new StandardCoder();
private final PolicyApiHttpClient apiHttpClient;
private final PolicyPapHttpClient papHttpClient;
@@ -79,7 +83,7 @@ public class AutomationCompositionElementHandler extends AcElementListenerV2 {
@Override
public void undeploy(CompositionElementDto compositionElement, InstanceElementDto instanceElement)
throws PfModelException {
- var automationCompositionDefinition = instanceElement.toscaServiceTemplateFragment();
+ var automationCompositionDefinition = getToscaServiceTemplate(instanceElement.inProperties());
if (automationCompositionDefinition.getToscaTopologyTemplate() == null) {
LOGGER.debug("No policies to undeploy to {}", instanceElement.elementId());
intermediaryApi.updateAutomationCompositionElementState(instanceElement.instanceId(),
@@ -161,7 +165,7 @@ public class AutomationCompositionElementHandler extends AcElementListenerV2 {
var createPolicyTypeResp = HttpStatus.SC_OK;
var createPolicyResp = HttpStatus.SC_OK;
- var automationCompositionDefinition = instanceElement.toscaServiceTemplateFragment();
+ var automationCompositionDefinition = getToscaServiceTemplate(instanceElement.inProperties());
if (automationCompositionDefinition.getToscaTopologyTemplate() == null) {
intermediaryApi.updateAutomationCompositionElementState(instanceElement.instanceId(),
instanceElement.elementId(), DeployState.UNDEPLOYED, null, StateChangeResult.FAILED,
@@ -222,4 +226,12 @@ public class AutomationCompositionElementHandler extends AcElementListenerV2 {
return policyList;
}
+
+ private ToscaServiceTemplate getToscaServiceTemplate(Map<String, Object> properties) throws PfModelException {
+ try {
+ return CODER.convert(properties, ToscaServiceTemplate.class);
+ } catch (CoderException e) {
+ throw new PfModelException(Status.BAD_REQUEST, e.getMessage());
+ }
+ }
}
diff --git a/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/acm/participant/policy/main/handler/AutomationCompositionElementHandlerTest.java b/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/acm/participant/policy/main/handler/AutomationCompositionElementHandlerTest.java
index 39f35e6df..cc8bb0ac1 100644
--- a/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/acm/participant/policy/main/handler/AutomationCompositionElementHandlerTest.java
+++ b/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/acm/participant/policy/main/handler/AutomationCompositionElementHandlerTest.java
@@ -22,6 +22,7 @@ package org.onap.policy.clamp.acm.participant.policy.main.handler;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.clearInvocations;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
@@ -38,6 +39,9 @@ import org.onap.policy.clamp.acm.participant.policy.client.PolicyApiHttpClient;
import org.onap.policy.clamp.acm.participant.policy.client.PolicyPapHttpClient;
import org.onap.policy.clamp.models.acm.concepts.DeployState;
import org.onap.policy.clamp.models.acm.concepts.StateChangeResult;
+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.base.PfModelException;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
@@ -47,6 +51,8 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaTopologyTemplate;
class AutomationCompositionElementHandlerTest {
+ private static final Coder CODER = new StandardCoder();
+
private static final ToscaConceptIdentifier DEFINITION =
new ToscaConceptIdentifier("1.0.1", "org.onap.PM_CDS_Blueprint");
@@ -74,7 +80,17 @@ class AutomationCompositionElementHandlerTest {
template.setToscaTopologyTemplate(new ToscaTopologyTemplate());
template.getToscaTopologyTemplate().setPolicies(List.of(Map.of("DummyPolicy", new ToscaPolicy())));
template.setPolicyTypes(Map.of("dummy policy type", new ToscaPolicyType()));
- return new InstanceElementDto(UUID.randomUUID(), UUID.randomUUID(), template, Map.of(), Map.of());
+ var inProperties = getProperties(template);
+ return new InstanceElementDto(UUID.randomUUID(), UUID.randomUUID(), inProperties, Map.of());
+ }
+
+ private Map<String, Object> getProperties(ToscaServiceTemplate template) {
+ try {
+ var json = CODER.encode(template);
+ return CODER.decode(json, Map.class);
+ } catch (CoderException e) {
+ throw new RuntimeException(e);
+ }
}
@Test
@@ -98,6 +114,7 @@ class AutomationCompositionElementHandlerTest {
instanceElement.elementId(), DeployState.DEPLOYED, null, StateChangeResult.NO_ERROR,
"Deployed");
+ clearInvocations(intermediaryApi);
handler.undeploy(compositionElement, instanceElement);
verify(intermediaryApi).updateAutomationCompositionElementState(instanceElement.instanceId(),
instanceElement.elementId(), DeployState.UNDEPLOYED, null, StateChangeResult.NO_ERROR,
@@ -116,12 +133,33 @@ class AutomationCompositionElementHandlerTest {
verify(intermediaryApi).updateAutomationCompositionElementState(instanceElement.instanceId(),
instanceElement.elementId(), DeployState.UNDEPLOYED, null, StateChangeResult.FAILED,
"ToscaTopologyTemplate not defined");
+
+ clearInvocations(intermediaryApi);
+ instanceElement = getInstanceElementWithNoPolicy();
+ handler.deploy(compositionElement, instanceElement);
+ verify(intermediaryApi).updateAutomationCompositionElementState(instanceElement.instanceId(),
+ instanceElement.elementId(), DeployState.DEPLOYED, null, StateChangeResult.NO_ERROR,
+ "Deployed");
+
+ clearInvocations(intermediaryApi);
+ handler.undeploy(compositionElement, instanceElement);
+ verify(intermediaryApi).updateAutomationCompositionElementState(instanceElement.instanceId(),
+ instanceElement.elementId(), DeployState.UNDEPLOYED, null, StateChangeResult.NO_ERROR,
+ "Undeployed");
}
private InstanceElementDto getInstanceElementWithNullTopology() {
var template = new ToscaServiceTemplate();
template.setToscaTopologyTemplate(null);
- return new InstanceElementDto(UUID.randomUUID(), UUID.randomUUID(), template, Map.of(), Map.of());
+ var inProperties = getProperties(template);
+ return new InstanceElementDto(UUID.randomUUID(), UUID.randomUUID(), inProperties, Map.of());
+ }
+
+ private InstanceElementDto getInstanceElementWithNoPolicy() {
+ var template = new ToscaServiceTemplate();
+ template.setToscaTopologyTemplate(new ToscaTopologyTemplate());
+ var inProperties = getProperties(template);
+ return new InstanceElementDto(UUID.randomUUID(), UUID.randomUUID(), inProperties, Map.of());
}
@Test
diff --git a/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/acm/participant/sim/main/handler/AutomationCompositionElementHandlerV2Test.java b/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/acm/participant/sim/main/handler/AutomationCompositionElementHandlerV2Test.java
index e89a82696..2f1e9dc9d 100644
--- a/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/acm/participant/sim/main/handler/AutomationCompositionElementHandlerV2Test.java
+++ b/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/acm/participant/sim/main/handler/AutomationCompositionElementHandlerV2Test.java
@@ -44,7 +44,7 @@ class AutomationCompositionElementHandlerV2Test {
private static final CompositionElementDto COMPOSITION_ELEMENT =
new CompositionElementDto(UUID.randomUUID(), new ToscaConceptIdentifier(), Map.of(), Map.of());
private static final InstanceElementDto INSTANCE_ELEMENT =
- new InstanceElementDto(UUID.randomUUID(), UUID.randomUUID(), null, Map.of(), Map.of());
+ new InstanceElementDto(UUID.randomUUID(), UUID.randomUUID(), Map.of(), Map.of());
private static final CompositionDto COMPOSITION = new CompositionDto(UUID.randomUUID(), Map.of(), Map.of());
@Test
@@ -131,7 +131,7 @@ class AutomationCompositionElementHandlerV2Test {
var acElementHandler = new AutomationCompositionElementHandlerV2(intermediaryApi, simulatorService);
simulatorService.setConfig(config);
var instanceElementUpdated = new InstanceElementDto(
- INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(), null,
+ INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(),
Map.of("key", "value"), Map.of());
acElementHandler.update(COMPOSITION_ELEMENT, INSTANCE_ELEMENT, instanceElementUpdated);
verify(intermediaryApi).updateAutomationCompositionElementState(
@@ -209,7 +209,7 @@ class AutomationCompositionElementHandlerV2Test {
Map.of(), Map.of());
var instanceElementMigrated = new InstanceElementDto(
INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(),
- null, Map.of("key", "value"), new HashMap<>());
+ Map.of("key", "value"), new HashMap<>());
acElementHandler
.migrate(COMPOSITION_ELEMENT, compositionElementTarget, INSTANCE_ELEMENT, instanceElementMigrated);
verify(intermediaryApi).updateAutomationCompositionElementState(
@@ -236,13 +236,12 @@ class AutomationCompositionElementHandlerV2Test {
UUID.randomUUID(), new ToscaConceptIdentifier(), Map.of(), Map.of(), ElementState.NOT_PRESENT);
var instanceElement = new InstanceElementDto(
- UUID.randomUUID(), UUID.randomUUID(), null, Map.of(), Map.of(), ElementState.NOT_PRESENT);
+ UUID.randomUUID(), UUID.randomUUID(), Map.of(), Map.of(), ElementState.NOT_PRESENT);
var compoElTargetAdd = new CompositionElementDto(
UUID.randomUUID(), new ToscaConceptIdentifier(), Map.of(), Map.of(), ElementState.NEW);
var inElMigratedAdd = new InstanceElementDto(
- instanceElement.instanceId(), instanceElement.elementId(), null,
- Map.of(), new HashMap<>(), ElementState.NEW);
+ instanceElement.instanceId(), instanceElement.elementId(), Map.of(), new HashMap<>(), ElementState.NEW);
acElementHandler
.migrate(compositionElement, compoElTargetAdd, instanceElement, inElMigratedAdd);
verify(intermediaryApi).updateAutomationCompositionElementState(
@@ -262,7 +261,7 @@ class AutomationCompositionElementHandlerV2Test {
Map.of(), Map.of(), ElementState.REMOVED);
var inElMigratedRemove = new InstanceElementDto(
INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(),
- null, Map.of("key", "value"), Map.of(), ElementState.REMOVED);
+ Map.of("key", "value"), Map.of(), ElementState.REMOVED);
acElementHandler
.migrate(COMPOSITION_ELEMENT, compoElTargetRemove, INSTANCE_ELEMENT, inElMigratedRemove);
verify(intermediaryApi).updateAutomationCompositionElementState(
@@ -284,7 +283,7 @@ class AutomationCompositionElementHandlerV2Test {
Map.of(), Map.of());
var instanceElementMigrated = new InstanceElementDto(
INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(),
- null, Map.of("key", "value"), Map.of());
+ Map.of("key", "value"), Map.of());
acElementHandler.migratePrecheck(COMPOSITION_ELEMENT, compositionElementTarget,
INSTANCE_ELEMENT, instanceElementMigrated);
verify(intermediaryApi).updateAutomationCompositionElementState(
diff --git a/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/acm/participant/sim/main/handler/AutomationCompositionElementHandlerV3Test.java b/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/acm/participant/sim/main/handler/AutomationCompositionElementHandlerV3Test.java
index d2d3d5c7e..41b3f2001 100644
--- a/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/acm/participant/sim/main/handler/AutomationCompositionElementHandlerV3Test.java
+++ b/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/acm/participant/sim/main/handler/AutomationCompositionElementHandlerV3Test.java
@@ -45,7 +45,7 @@ class AutomationCompositionElementHandlerV3Test {
private static final CompositionElementDto COMPOSITION_ELEMENT =
new CompositionElementDto(UUID.randomUUID(), new ToscaConceptIdentifier(), Map.of(), Map.of());
private static final InstanceElementDto INSTANCE_ELEMENT =
- new InstanceElementDto(UUID.randomUUID(), UUID.randomUUID(), null, Map.of(), Map.of());
+ new InstanceElementDto(UUID.randomUUID(), UUID.randomUUID(), Map.of(), Map.of());
private static final CompositionDto COMPOSITION = new CompositionDto(UUID.randomUUID(), Map.of(), Map.of());
@Test
@@ -132,7 +132,7 @@ class AutomationCompositionElementHandlerV3Test {
var acElementHandler = new AutomationCompositionElementHandlerV3(intermediaryApi, simulatorService);
simulatorService.setConfig(config);
var instanceElementUpdated = new InstanceElementDto(
- INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(), null,
+ INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(),
Map.of("key", "value"), Map.of());
acElementHandler.update(COMPOSITION_ELEMENT, INSTANCE_ELEMENT, instanceElementUpdated);
verify(intermediaryApi).updateAutomationCompositionElementState(
@@ -210,7 +210,7 @@ class AutomationCompositionElementHandlerV3Test {
Map.of(), Map.of());
var instanceElementMigrated = new InstanceElementDto(
INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(),
- null, Map.of("key", "value"), new HashMap<>());
+ Map.of("key", "value"), new HashMap<>());
acElementHandler
.migrate(COMPOSITION_ELEMENT, compositionElementTarget, INSTANCE_ELEMENT, instanceElementMigrated, 0);
verify(intermediaryApi).updateAutomationCompositionElementState(
@@ -235,7 +235,7 @@ class AutomationCompositionElementHandlerV3Test {
var compositionElementTarget = new CompositionElementDto(UUID.randomUUID(), new ToscaConceptIdentifier(),
Map.of("stage", List.of(1, 2)), Map.of());
var instanceElementMigrated = new InstanceElementDto(INSTANCE_ELEMENT.instanceId(),
- INSTANCE_ELEMENT.elementId(), null, Map.of(), new HashMap<>());
+ INSTANCE_ELEMENT.elementId(), Map.of(), new HashMap<>());
acElementHandler
.migrate(COMPOSITION_ELEMENT, compositionElementTarget, INSTANCE_ELEMENT, instanceElementMigrated, 1);
verify(intermediaryApi).updateAutomationCompositionElementStage(
@@ -254,12 +254,12 @@ class AutomationCompositionElementHandlerV3Test {
UUID.randomUUID(), new ToscaConceptIdentifier(), Map.of(), Map.of(), ElementState.NOT_PRESENT);
var instanceElement = new InstanceElementDto(
- UUID.randomUUID(), UUID.randomUUID(), null, Map.of(), Map.of(), ElementState.NOT_PRESENT);
+ UUID.randomUUID(), UUID.randomUUID(), Map.of(), Map.of(), ElementState.NOT_PRESENT);
var compoElTargetAdd = new CompositionElementDto(
UUID.randomUUID(), new ToscaConceptIdentifier(), Map.of(), Map.of(), ElementState.NEW);
var inElMigratedAdd = new InstanceElementDto(instanceElement.instanceId(), instanceElement.elementId(),
- null, Map.of(), new HashMap<>(), ElementState.NEW);
+ Map.of(), new HashMap<>(), ElementState.NEW);
acElementHandler
.migrate(compositionElement, compoElTargetAdd, instanceElement, inElMigratedAdd, 0);
verify(intermediaryApi).updateAutomationCompositionElementState(
@@ -279,7 +279,7 @@ class AutomationCompositionElementHandlerV3Test {
Map.of(), Map.of(), ElementState.REMOVED);
var inElMigratedRemove = new InstanceElementDto(
INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(),
- null, Map.of("key", "value"), Map.of(), ElementState.REMOVED);
+ Map.of("key", "value"), Map.of(), ElementState.REMOVED);
acElementHandler
.migrate(COMPOSITION_ELEMENT, compoElTargetRemove, INSTANCE_ELEMENT, inElMigratedRemove, 0);
verify(intermediaryApi).updateAutomationCompositionElementState(
@@ -301,7 +301,7 @@ class AutomationCompositionElementHandlerV3Test {
Map.of(), Map.of());
var instanceElementMigrated = new InstanceElementDto(
INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(),
- null, Map.of("key", "value"), Map.of());
+ Map.of("key", "value"), Map.of());
acElementHandler.migratePrecheck(COMPOSITION_ELEMENT, compositionElementTarget,
INSTANCE_ELEMENT, instanceElementMigrated);
verify(intermediaryApi).updateAutomationCompositionElementState(