summaryrefslogtreecommitdiffstats
path: root/runtime-acm
diff options
context:
space:
mode:
authorLiam Fallon <liam.fallon@est.tech>2022-12-09 10:41:23 +0000
committerGerrit Code Review <gerrit@onap.org>2022-12-09 10:41:23 +0000
commit7da3227a9090ece82343eee6f8133dbefbeee30a (patch)
tree9811a33895415e646ff84db75ce588fb175b5b66 /runtime-acm
parent2d3c8c987001ac176acb2feaadd885ceb1f7d234 (diff)
parenta50038a6ed673819b45e9af35eb203e6e24dec99 (diff)
Merge "Add instanceId support in AutomationCompositionProvider"
Diffstat (limited to 'runtime-acm')
-rw-r--r--runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProvider.java18
-rw-r--r--runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionHandler.java2
-rw-r--r--runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScanner.java2
-rw-r--r--runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProviderTest.java50
-rw-r--r--runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/rest/InstantiationControllerTest.java4
-rw-r--r--runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionHandlerTest.java4
-rw-r--r--runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScannerTest.java6
7 files changed, 48 insertions, 38 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 29b337edd..03a2f4e25 100644
--- 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
@@ -43,6 +43,7 @@ import org.onap.policy.common.parameters.BeanValidationResult;
import org.onap.policy.common.parameters.ObjectValidationResult;
import org.onap.policy.common.parameters.ValidationStatus;
import org.onap.policy.models.base.PfModelRuntimeException;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -80,9 +81,10 @@ public class AutomationCompositionInstantiationProvider {
if (!validationResult.isValid()) {
throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, validationResult.getResult());
}
- automationComposition = automationCompositionProvider.saveAutomationComposition(automationComposition);
+ automationComposition = automationCompositionProvider.createAutomationComposition(automationComposition);
var response = new InstantiationResponse();
+ response.setInstanceId(automationComposition.getInstanceId());
response.setAffectedAutomationComposition(automationComposition.getKey().asIdentifier());
return response;
@@ -99,9 +101,10 @@ public class AutomationCompositionInstantiationProvider {
if (!validationResult.isValid()) {
throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, validationResult.getResult());
}
- automationCompositionProvider.saveAutomationComposition(automationComposition);
+ automationCompositionProvider.updateAutomationComposition(automationComposition);
var response = new InstantiationResponse();
+ response.setInstanceId(automationComposition.getInstanceId());
response.setAffectedAutomationComposition(automationComposition.getKey().asIdentifier());
return response;
@@ -134,7 +137,8 @@ public class AutomationCompositionInstantiationProvider {
* @return the result of the deletion
*/
public InstantiationResponse deleteAutomationComposition(String name, String version) {
- var automationCompositionOpt = automationCompositionProvider.findAutomationComposition(name, version);
+ var automationCompositionOpt =
+ automationCompositionProvider.findAutomationComposition(new ToscaConceptIdentifier(name, version));
if (automationCompositionOpt.isEmpty()) {
throw new PfModelRuntimeException(Response.Status.NOT_FOUND, "Automation composition not found");
}
@@ -144,8 +148,10 @@ public class AutomationCompositionInstantiationProvider {
"Automation composition state is still " + automationComposition.getState());
}
var response = new InstantiationResponse();
- response.setAffectedAutomationComposition(
- automationCompositionProvider.deleteAutomationComposition(name, version).getKey().asIdentifier());
+ automationComposition =
+ automationCompositionProvider.deleteAutomationComposition(automationComposition.getInstanceId());
+ response.setInstanceId(automationComposition.getInstanceId());
+ response.setAffectedAutomationComposition(automationComposition.getKey().asIdentifier());
return response;
}
@@ -199,7 +205,7 @@ public class AutomationCompositionInstantiationProvider {
automationComposition.setCascadedOrderedState(command.getOrderedState());
supervisionHandler.triggerAutomationCompositionSupervision(automationComposition);
- automationCompositionProvider.saveAutomationComposition(automationComposition);
+ automationCompositionProvider.updateAutomationComposition(automationComposition);
var response = new InstantiationResponse();
response.setAffectedAutomationComposition(command.getAutomationCompositionIdentifier());
diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionHandler.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionHandler.java
index b5d7645da..de67360f8 100644
--- a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionHandler.java
+++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionHandler.java
@@ -235,7 +235,7 @@ public class SupervisionHandler {
automationCompositionAckMessage.getAutomationCompositionResultMap().entrySet());
updated |= setPrimed(automationComposition.get());
if (updated) {
- automationCompositionProvider.saveAutomationComposition(automationComposition.get());
+ automationCompositionProvider.updateAutomationComposition(automationComposition.get());
}
} else {
LOGGER.warn("AutomationComposition not found in database {}",
diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScanner.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScanner.java
index e2f8b6777..129569b6b 100644
--- a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScanner.java
+++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScanner.java
@@ -242,7 +242,7 @@ public class SupervisionScanner {
automationComposition.getState(), automationComposition.getOrderedState());
automationComposition.setState(automationComposition.getOrderedState().asState());
- automationCompositionProvider.saveAutomationComposition(automationComposition);
+ automationCompositionProvider.updateAutomationComposition(automationComposition);
// Clear missed report counter on automation composition
clearFaultAndCounter(automationComposition);
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 864179844..115adcb50 100644
--- 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
@@ -45,6 +45,7 @@ import org.onap.policy.clamp.models.acm.persistence.provider.AcDefinitionProvide
import org.onap.policy.clamp.models.acm.persistence.provider.AutomationCompositionProvider;
import org.onap.policy.clamp.models.acm.persistence.provider.ParticipantProvider;
import org.onap.policy.clamp.models.acm.persistence.provider.ProviderUtils;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate;
@@ -66,14 +67,13 @@ class AutomationCompositionInstantiationProviderTest {
private static final String ORDERED_STATE_INVALID = "ordered state invalid or not specified on command";
private static final String AC_ELEMENT_NAME_NOT_FOUND =
"\"AutomationComposition\" INVALID, item has status INVALID\n"
- + " \"entry PMSHInstance0AcElementNotFound\" INVALID, item has status INVALID\n"
- + " \"entry org.onap.domain.pmsh.DCAEMicroservice\" INVALID, Not found\n"
- + " \"entry org.onap.domain.pmsh.PMSH_MonitoringPolicyAutomationCompositionElement\""
- + " INVALID, Not found\n";
- private static final String AC_DEFINITION_NOT_FOUND =
- "\"AutomationComposition\" INVALID, item has status INVALID\n"
- + " item \"ServiceTemplate\" value \"\" INVALID,"
- + " Commissioned automation composition definition not found\n";
+ + " \"entry PMSHInstance0AcElementNotFound\" INVALID, item has status INVALID\n"
+ + " \"entry org.onap.domain.pmsh.DCAEMicroservice\" INVALID, Not found\n"
+ + " \"entry org.onap.domain.pmsh.PMSH_MonitoringPolicyAutomationCompositionElement\""
+ + " INVALID, Not found\n";
+ private static final String AC_DEFINITION_NOT_FOUND = "\"AutomationComposition\" INVALID, item has status INVALID\n"
+ + " item \"ServiceTemplate\" value \"\" INVALID,"
+ + " Commissioned automation composition definition not found\n";
private static ToscaServiceTemplate serviceTemplate = new ToscaServiceTemplate();
@@ -101,12 +101,13 @@ class AutomationCompositionInstantiationProviderTest {
var automationCompositionCreate =
InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_CREATE_JSON, "Crud");
automationCompositionCreate.setCompositionId(compositionId);
- when(acProvider.saveAutomationComposition(automationCompositionCreate)).thenReturn(automationCompositionCreate);
+ when(acProvider.createAutomationComposition(automationCompositionCreate))
+ .thenReturn(automationCompositionCreate);
var instantiationResponse = instantiationProvider.createAutomationComposition(automationCompositionCreate);
InstantiationUtils.assertInstantiationResponse(instantiationResponse, automationCompositionCreate);
- verify(acProvider).saveAutomationComposition(automationCompositionCreate);
+ verify(acProvider).createAutomationComposition(automationCompositionCreate);
when(acProvider.getAutomationCompositions(automationCompositionCreate.getName(),
automationCompositionCreate.getVersion())).thenReturn(List.of(automationCompositionCreate));
@@ -123,14 +124,12 @@ class AutomationCompositionInstantiationProviderTest {
instantiationResponse = instantiationProvider.updateAutomationComposition(automationCompositionUpdate);
InstantiationUtils.assertInstantiationResponse(instantiationResponse, automationCompositionUpdate);
- verify(acProvider).saveAutomationComposition(automationCompositionUpdate);
+ verify(acProvider).updateAutomationComposition(automationCompositionUpdate);
when(acProvider.findAutomationComposition(automationCompositionUpdate.getKey().asIdentifier()))
.thenReturn(Optional.of(automationCompositionUpdate));
- when(acProvider.findAutomationComposition(automationCompositionUpdate.getName(),
- automationCompositionUpdate.getVersion())).thenReturn(Optional.of(automationCompositionUpdate));
- when(acProvider.deleteAutomationComposition(automationCompositionUpdate.getName(),
- automationCompositionUpdate.getVersion())).thenReturn(automationCompositionUpdate);
+ when(acProvider.deleteAutomationComposition(automationCompositionUpdate.getInstanceId()))
+ .thenReturn(automationCompositionUpdate);
var instantiationCommand =
InstantiationUtils.getInstantiationCommandFromResource(AC_INSTANTIATION_CHANGE_STATE_JSON, "Crud");
@@ -146,8 +145,7 @@ class AutomationCompositionInstantiationProviderTest {
instantiationProvider.deleteAutomationComposition(automationCompositionCreate.getName(),
automationCompositionCreate.getVersion());
- verify(acProvider).deleteAutomationComposition(automationCompositionCreate.getName(),
- automationCompositionCreate.getVersion());
+ verify(acProvider).deleteAutomationComposition(automationCompositionCreate.getInstanceId());
}
@Test
@@ -172,11 +170,13 @@ class AutomationCompositionInstantiationProviderTest {
}
}
automationComposition.setState(AutomationCompositionState.UNINITIALISED);
+ automationComposition.setInstanceId(UUID.randomUUID());
- when(acProvider.findAutomationComposition(automationComposition.getName(), automationComposition.getVersion()))
- .thenReturn(Optional.of(automationComposition));
- when(acProvider.deleteAutomationComposition(automationComposition.getName(),
- automationComposition.getVersion())).thenReturn(automationComposition);
+ when(acProvider.findAutomationComposition(
+ new ToscaConceptIdentifier(automationComposition.getName(), automationComposition.getVersion())))
+ .thenReturn(Optional.of(automationComposition));
+ when(acProvider.deleteAutomationComposition(automationComposition.getInstanceId()))
+ .thenReturn(automationComposition);
instantiationProvider.deleteAutomationComposition(automationComposition.getName(),
automationComposition.getVersion());
@@ -193,8 +193,8 @@ class AutomationCompositionInstantiationProviderTest {
var instantiationProvider = new AutomationCompositionInstantiationProvider(acProvider, supervisionHandler,
participantProvider, acDefinitionProvider);
- when(acProvider.findAutomationComposition(automationComposition.getName(), automationComposition.getVersion()))
- .thenReturn(Optional.of(automationComposition));
+ var key = new ToscaConceptIdentifier(automationComposition.getName(), automationComposition.getVersion());
+ when(acProvider.findAutomationComposition(key)).thenReturn(Optional.of(automationComposition));
assertThatThrownBy(() -> instantiationProvider.deleteAutomationComposition(automationComposition.getName(),
automationComposition.getVersion())).hasMessageMatching(String.format(DELETE_BAD_REQUEST, state));
@@ -209,9 +209,11 @@ class AutomationCompositionInstantiationProviderTest {
var automationCompositionCreate =
InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_CREATE_JSON, "NoDuplicates");
automationCompositionCreate.setCompositionId(compositionId);
+ automationCompositionCreate.setInstanceId(UUID.randomUUID());
var acProvider = mock(AutomationCompositionProvider.class);
- when(acProvider.saveAutomationComposition(automationCompositionCreate)).thenReturn(automationCompositionCreate);
+ when(acProvider.createAutomationComposition(automationCompositionCreate))
+ .thenReturn(automationCompositionCreate);
var participantProvider = Mockito.mock(ParticipantProvider.class);
var supervisionHandler = mock(SupervisionHandler.class);
diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/rest/InstantiationControllerTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/rest/InstantiationControllerTest.java
index dd6e8f3fc..9c364b2db 100644
--- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/rest/InstantiationControllerTest.java
+++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/rest/InstantiationControllerTest.java
@@ -166,6 +166,7 @@ class InstantiationControllerTest extends CommonRestController {
assertEquals(Response.Status.OK.getStatusCode(), resp.getStatus());
var instResponse = resp.readEntity(InstantiationResponse.class);
InstantiationUtils.assertInstantiationResponse(instResponse, automationCompositionFromRsc);
+ automationCompositionFromRsc.setInstanceId(instResponse.getInstanceId());
var automationCompositionsFromDb = instantiationProvider.getAutomationCompositions(
automationCompositionFromRsc.getKey().getName(), automationCompositionFromRsc.getKey().getVersion());
@@ -227,12 +228,13 @@ class InstantiationControllerTest extends CommonRestController {
InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_CREATE_JSON, "Update");
automationCompositionCreate.setCompositionId(compositionId);
- instantiationProvider.createAutomationComposition(automationCompositionCreate);
+ var response = instantiationProvider.createAutomationComposition(automationCompositionCreate);
var invocationBuilder = super.sendRequest(INSTANTIATION_ENDPOINT);
var automationComposition =
InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_UPDATE_JSON, "Update");
automationComposition.setCompositionId(compositionId);
+ automationComposition.setInstanceId(response.getInstanceId());
var resp = invocationBuilder.put(Entity.json(automationComposition));
assertEquals(Response.Status.OK.getStatusCode(), resp.getStatus());
diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionHandlerTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionHandlerTest.java
index cc915003d..3a707cd52 100644
--- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionHandlerTest.java
+++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionHandlerTest.java
@@ -235,7 +235,7 @@ class SupervisionHandlerTest {
handler.handleAutomationCompositionStateChangeAckMessage(automationCompositionAckMessage);
- verify(automationCompositionProvider).saveAutomationComposition(any(AutomationComposition.class));
+ verify(automationCompositionProvider).updateAutomationComposition(any(AutomationComposition.class));
}
@Test
@@ -255,7 +255,7 @@ class SupervisionHandlerTest {
handler.handleAutomationCompositionUpdateAckMessage(automationCompositionAckMessage);
- verify(automationCompositionProvider).saveAutomationComposition(any(AutomationComposition.class));
+ verify(automationCompositionProvider).updateAutomationComposition(any(AutomationComposition.class));
}
@Test
diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScannerTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScannerTest.java
index 03a0ec59e..1455e9246 100644
--- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScannerTest.java
+++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScannerTest.java
@@ -96,7 +96,7 @@ class SupervisionScannerTest {
participantStatusReqPublisher, participantUpdatePublisher, acRuntimeParameterGroup);
supervisionScanner.run(false);
- verify(automationCompositionProvider, times(0)).saveAutomationComposition(any(AutomationComposition.class));
+ verify(automationCompositionProvider, times(0)).updateAutomationComposition(any(AutomationComposition.class));
}
@Test
@@ -120,7 +120,7 @@ class SupervisionScannerTest {
participantStatusReqPublisher, participantUpdatePublisher, acRuntimeParameterGroup);
supervisionScanner.run(false);
- verify(automationCompositionProvider, times(1)).saveAutomationComposition(any(AutomationComposition.class));
+ verify(automationCompositionProvider, times(1)).updateAutomationComposition(any(AutomationComposition.class));
}
@Test
@@ -148,7 +148,7 @@ class SupervisionScannerTest {
supervisionScanner.handleParticipantStatus(participant.getKey().asIdentifier());
supervisionScanner.run(true);
- verify(automationCompositionProvider, times(0)).saveAutomationComposition(any(AutomationComposition.class));
+ verify(automationCompositionProvider, times(0)).updateAutomationComposition(any(AutomationComposition.class));
verify(participantStatusReqPublisher, times(0)).send(any(ToscaConceptIdentifier.class));
}