summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFrancescoFioraEst <francesco.fiora@est.tech>2023-12-13 14:12:25 +0000
committerFrancescoFioraEst <francesco.fiora@est.tech>2024-01-02 09:43:57 +0000
commit664af40d4c073404d6c067731e25fc44dab3f2c2 (patch)
treea37c1821e6e200d79f036398d06d1c37bd58c594
parent7189a95de7687a8c37a05d40306e743df5fdf5b3 (diff)
Add validation in AC instance elements Id in update
Issue-ID: POLICY-4905 Change-Id: If49a7829fa8acfe375cf7bb1d7ed6859f8a3f190 Signed-off-by: FrancescoFioraEst <francesco.fiora@est.tech>
-rwxr-xr-xruntime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProvider.java18
-rwxr-xr-xruntime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProviderTest.java32
2 files changed, 30 insertions, 20 deletions
diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProvider.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProvider.java
index 9f126406b..84920dd03 100755
--- a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProvider.java
+++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProvider.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2021-2023 Nordix Foundation.
+ * Copyright (C) 2021-2024 Nordix Foundation.
* Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -134,7 +134,7 @@ public class AutomationCompositionInstantiationProvider {
} else if ((DeployState.DEPLOYED.equals(acToUpdate.getDeployState())
|| DeployState.UPDATING.equals(acToUpdate.getDeployState()))
&& LockState.LOCKED.equals(acToUpdate.getLockState())) {
- return updateDeployedAutomationComposition(compositionId, automationComposition, acToUpdate);
+ return updateDeployedAutomationComposition(automationComposition, acToUpdate);
}
throw new PfModelRuntimeException(Response.Status.BAD_REQUEST,
"Not allowed to update in the state " + acToUpdate.getDeployState());
@@ -143,12 +143,11 @@ public class AutomationCompositionInstantiationProvider {
/**
* Update deployed AC Element properties.
*
- * @param compositionId The UUID of the automation composition definition
* @param automationComposition the automation composition
* @param acToBeUpdated the composition to be updated
* @return the result of the update
*/
- public InstantiationResponse updateDeployedAutomationComposition(UUID compositionId,
+ public InstantiationResponse updateDeployedAutomationComposition(
AutomationComposition automationComposition, AutomationComposition acToBeUpdated) {
if (automationComposition.getCompositionTargetId() != null
@@ -158,12 +157,13 @@ public class AutomationCompositionInstantiationProvider {
}
// Iterate and update the element property values
- for (var dbAcElement : acToBeUpdated.getElements().entrySet()) {
- var elementId = dbAcElement.getKey();
- if (automationComposition.getElements().containsKey(elementId)) {
- dbAcElement.getValue().getProperties()
- .putAll(automationComposition.getElements().get(elementId).getProperties());
+ for (var element : automationComposition.getElements().entrySet()) {
+ var elementId = element.getKey();
+ var dbAcElement = acToBeUpdated.getElements().get(elementId);
+ if (dbAcElement == null) {
+ throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, "Element id not present " + elementId);
}
+ dbAcElement.getProperties().putAll(element.getValue().getProperties());
}
if (automationComposition.getRestarting() != null) {
throw new PfModelRuntimeException(Status.BAD_REQUEST, "There is a restarting process, Update not allowed");
diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProviderTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProviderTest.java
index 8dca6693c..87bfe1b38 100755
--- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProviderTest.java
+++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProviderTest.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2021-2023 Nordix Foundation.
+ * Copyright (C) 2021-2024 Nordix Foundation.
* Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -30,6 +30,7 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.onap.policy.clamp.acm.runtime.util.CommonTestData.TOSCA_SERVICE_TEMPLATE_YAML;
+import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
@@ -39,7 +40,6 @@ import org.onap.policy.clamp.acm.runtime.main.parameters.AcRuntimeParameterGroup
import org.onap.policy.clamp.acm.runtime.participants.AcmParticipantProvider;
import org.onap.policy.clamp.acm.runtime.supervision.SupervisionAcHandler;
import org.onap.policy.clamp.acm.runtime.util.CommonTestData;
-import org.onap.policy.clamp.common.acm.exception.AutomationCompositionException;
import org.onap.policy.clamp.models.acm.concepts.AcTypeState;
import org.onap.policy.clamp.models.acm.concepts.AutomationComposition;
import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionDefinition;
@@ -149,7 +149,7 @@ class AutomationCompositionInstantiationProviderTest {
}
@Test
- void testInstantiationUpdate() throws AutomationCompositionException {
+ void testInstantiationUpdate() {
var acDefinitionProvider = mock(AcDefinitionProvider.class);
var acDefinition = CommonTestData.createAcDefinition(serviceTemplate, AcTypeState.PRIMED);
var compositionId = acDefinition.getCompositionId();
@@ -158,13 +158,13 @@ class AutomationCompositionInstantiationProviderTest {
var automationCompositionUpdate =
InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_UPDATE_JSON, "Crud");
automationCompositionUpdate.setCompositionId(compositionId);
+ automationCompositionUpdate.setInstanceId(UUID.randomUUID());
automationCompositionUpdate.setDeployState(DeployState.DEPLOYED);
automationCompositionUpdate.setLockState(LockState.LOCKED);
var acProvider = mock(AutomationCompositionProvider.class);
- when(acProvider.getAutomationComposition(automationCompositionUpdate.getInstanceId()))
- .thenReturn(automationCompositionUpdate);
- when(acProvider.updateAutomationComposition(automationCompositionUpdate))
- .thenReturn(automationCompositionUpdate);
+ var acmFromDb = new AutomationComposition(automationCompositionUpdate);
+ when(acProvider.getAutomationComposition(automationCompositionUpdate.getInstanceId())).thenReturn(acmFromDb);
+ when(acProvider.updateAutomationComposition(acmFromDb)).thenReturn(acmFromDb);
var supervisionAcHandler = mock(SupervisionAcHandler.class);
var acmParticipantProvider = mock(AcmParticipantProvider.class);
@@ -175,12 +175,22 @@ class AutomationCompositionInstantiationProviderTest {
automationCompositionUpdate.getCompositionId(), automationCompositionUpdate);
verify(supervisionAcHandler).update(any());
- verify(acProvider).updateAutomationComposition(automationCompositionUpdate);
+ verify(acProvider).updateAutomationComposition(acmFromDb);
InstantiationUtils.assertInstantiationResponse(instantiationResponse, automationCompositionUpdate);
+
+ var elements = new ArrayList<>(automationCompositionUpdate.getElements().values());
+ automationCompositionUpdate.getElements().clear();
+ for (var element : elements) {
+ element.setId(UUID.randomUUID());
+ automationCompositionUpdate.getElements().put(element.getId(), element);
+ }
+ assertThatThrownBy(
+ () -> instantiationProvider.updateAutomationComposition(compositionId, automationCompositionUpdate))
+ .hasMessageStartingWith("Element id not present ");
}
@Test
- void testUpdateBadRequest() throws AutomationCompositionException {
+ void testUpdateBadRequest() {
var automationCompositionUpdate =
InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_UPDATE_JSON, "Crud");
automationCompositionUpdate.setDeployState(DeployState.DEPLOYING);
@@ -210,7 +220,7 @@ class AutomationCompositionInstantiationProviderTest {
}
@Test
- void testUpdateRestartedBadRequest() throws AutomationCompositionException {
+ void testUpdateRestartedBadRequest() {
var automationCompositionUpdate =
InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_UPDATE_JSON, "Crud");
automationCompositionUpdate.setDeployState(DeployState.DEPLOYED);
@@ -239,7 +249,7 @@ class AutomationCompositionInstantiationProviderTest {
}
@Test
- void testUpdateCompositionRestartedBadRequest() throws AutomationCompositionException {
+ void testUpdateCompositionRestartedBadRequest() {
var acDefinitionProvider = mock(AcDefinitionProvider.class);
var acDefinition = CommonTestData.createAcDefinition(serviceTemplate, AcTypeState.PRIMED);
acDefinition.setRestarting(true);