summaryrefslogtreecommitdiffstats
path: root/runtime-acm/src
diff options
context:
space:
mode:
authorFrancescoFioraEst <francesco.fiora@est.tech>2023-06-16 10:42:14 +0100
committerFrancesco Fiora <francesco.fiora@est.tech>2023-06-16 09:51:29 +0000
commit0f24f33b124bf326e4b7dbaa2a55cab72696b9ee (patch)
tree6fcf5bc915bd52d1e0071401293ebe0fdc4d9495 /runtime-acm/src
parenta2320d29b9373041db88395d9fdda7ea84d38807 (diff)
Add support for Prime Deprime Failure Handling in ACM-Runtime
Issue-ID: POLICY-4714 Change-Id: I1f3cf8f0fcebc7c48b3632ad10aa8907c41cdb5a Signed-off-by: FrancescoFioraEst <francesco.fiora@est.tech>
Diffstat (limited to 'runtime-acm/src')
-rw-r--r--runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/commissioning/CommissioningProvider.java19
-rw-r--r--runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAcHandler.java33
-rw-r--r--runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionHandler.java28
-rw-r--r--runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAcHandlerTest.java40
-rw-r--r--runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionHandlerTest.java27
5 files changed, 99 insertions, 48 deletions
diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/commissioning/CommissioningProvider.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/commissioning/CommissioningProvider.java
index d8eddf558..141207651 100644
--- a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/commissioning/CommissioningProvider.java
+++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/commissioning/CommissioningProvider.java
@@ -30,6 +30,7 @@ import lombok.RequiredArgsConstructor;
import org.onap.policy.clamp.acm.runtime.supervision.comm.ParticipantPrimePublisher;
import org.onap.policy.clamp.models.acm.concepts.AcTypeState;
import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionDefinition;
+import org.onap.policy.clamp.models.acm.concepts.StateChangeResult;
import org.onap.policy.clamp.models.acm.messages.rest.commissioning.AcTypeStateUpdate;
import org.onap.policy.clamp.models.acm.messages.rest.commissioning.CommissioningResponse;
import org.onap.policy.clamp.models.acm.persistence.provider.AcDefinitionProvider;
@@ -180,7 +181,8 @@ public class CommissioningProvider {
throw new PfModelRuntimeException(Status.BAD_REQUEST, "There are instances, Priming/Depriming not allowed");
}
var acmDefinition = acDefinitionProvider.getAcDefinition(compositionId);
- var stateOrdered = acTypeStateResolver.resolve(acTypeStateUpdate.getPrimeOrder(), acmDefinition.getState());
+ var stateOrdered = acTypeStateResolver.resolve(acTypeStateUpdate.getPrimeOrder(), acmDefinition.getState(),
+ acmDefinition.getStateChangeResult());
switch (stateOrdered) {
case PRIME:
prime(acmDefinition);
@@ -197,21 +199,24 @@ public class CommissioningProvider {
}
private void prime(AutomationCompositionDefinition acmDefinition) {
- var prearation = participantPrimePublisher.prepareParticipantPriming(acmDefinition);
+ acmDefinition.setStateChangeResult(StateChangeResult.NO_ERROR);
+ var preparation = participantPrimePublisher.prepareParticipantPriming(acmDefinition);
acDefinitionProvider.updateAcDefinition(acmDefinition);
executor.execute(
- () -> participantPrimePublisher.sendPriming(prearation, acmDefinition.getCompositionId(), null));
+ () -> participantPrimePublisher.sendPriming(preparation, acmDefinition.getCompositionId(), null));
}
private void deprime(AutomationCompositionDefinition acmDefinition) {
- if (!AcTypeState.COMMISSIONED.equals(acmDefinition.getState())) {
- for (var elementState : acmDefinition.getElementStateMap().values()) {
+ acmDefinition.setStateChangeResult(StateChangeResult.NO_ERROR);
+ for (var elementState : acmDefinition.getElementStateMap().values()) {
+ if (elementState.getParticipantId() != null) {
elementState.setState(AcTypeState.DEPRIMING);
}
- acmDefinition.setState(AcTypeState.DEPRIMING);
- acDefinitionProvider.updateAcDefinition(acmDefinition);
}
+ acmDefinition.setState(AcTypeState.DEPRIMING);
+ acDefinitionProvider.updateAcDefinition(acmDefinition);
+
executor.execute(() -> participantPrimePublisher.sendDepriming(acmDefinition.getCompositionId()));
}
diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAcHandler.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAcHandler.java
index e9f8d6ce5..536e3e246 100644
--- a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAcHandler.java
+++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAcHandler.java
@@ -78,8 +78,8 @@ public class SupervisionAcHandler {
automationComposition.setStateChangeResult(StateChangeResult.NO_ERROR);
automationCompositionProvider.updateAutomationComposition(automationComposition);
var startPhase = ParticipantUtils.getFirstStartPhase(automationComposition, acDefinition.getServiceTemplate());
- automationCompositionDeployPublisher.send(automationComposition, acDefinition.getServiceTemplate(), startPhase,
- true);
+ automationCompositionDeployPublisher.send(automationComposition, acDefinition.getServiceTemplate(),
+ startPhase, true);
}
/**
@@ -207,24 +207,25 @@ public class SupervisionAcHandler {
}
private void setAcElementStateInDb(AutomationCompositionDeployAck automationCompositionAckMessage) {
- var automationComposition = automationCompositionProvider
+ var automationCompositionOpt = automationCompositionProvider
.findAutomationComposition(automationCompositionAckMessage.getAutomationCompositionId());
- if (automationComposition.isEmpty()) {
+ if (automationCompositionOpt.isEmpty()) {
LOGGER.warn("AutomationComposition not found in database {}",
automationCompositionAckMessage.getAutomationCompositionId());
return;
}
+ var automationComposition = automationCompositionOpt.get();
if (automationCompositionAckMessage.getAutomationCompositionResultMap() == null
|| automationCompositionAckMessage.getAutomationCompositionResultMap().isEmpty()) {
- if (DeployState.DELETING.equals(automationComposition.get().getDeployState())) {
+ if (DeployState.DELETING.equals(automationComposition.getDeployState())) {
// scenario when Automation Composition instance has never been deployed
- for (var element : automationComposition.get().getElements().values()) {
+ for (var element : automationComposition.getElements().values()) {
if (element.getParticipantId().equals(automationCompositionAckMessage.getParticipantId())) {
element.setDeployState(DeployState.DELETED);
}
}
- automationCompositionProvider.updateAutomationComposition(automationComposition.get());
+ automationCompositionProvider.updateAutomationComposition(automationComposition);
} else {
LOGGER.warn("Empty AutomationCompositionResultMap {} {}",
automationCompositionAckMessage.getAutomationCompositionId(),
@@ -233,11 +234,11 @@ public class SupervisionAcHandler {
return;
}
- var updated = updateState(automationComposition.get(),
+ var updated = updateState(automationComposition,
automationCompositionAckMessage.getAutomationCompositionResultMap().entrySet(),
automationCompositionAckMessage.getStateChangeResult());
if (updated) {
- automationCompositionProvider.updateAutomationComposition(automationComposition.get());
+ automationCompositionProvider.updateAutomationComposition(automationComposition);
}
}
@@ -246,7 +247,10 @@ public class SupervisionAcHandler {
StateChangeResult stateChangeResult) {
var updated = false;
var elementInErrors = StateChangeResult.FAILED.equals(stateChangeResult);
- boolean inProgress = StateChangeResult.NO_ERROR.equals(automationComposition.getStateChangeResult());
+ boolean inProgress = !StateChangeResult.FAILED.equals(automationComposition.getStateChangeResult());
+ if (elementInErrors && inProgress) {
+ automationComposition.setStateChangeResult(StateChangeResult.FAILED);
+ }
for (var acElementAck : automationCompositionResultSet) {
var element = automationComposition.getElements().get(acElementAck.getKey());
@@ -255,16 +259,11 @@ public class SupervisionAcHandler {
element.setOutProperties(acElementAck.getValue().getOutProperties());
element.setOperationalState(acElementAck.getValue().getOperationalState());
element.setUseState(acElementAck.getValue().getUseState());
+ element.setDeployState(acElementAck.getValue().getDeployState());
+ element.setLockState(acElementAck.getValue().getLockState());
updated = true;
- if (!elementInErrors || inProgress) {
- element.setDeployState(acElementAck.getValue().getDeployState());
- element.setLockState(acElementAck.getValue().getLockState());
- }
}
}
- if (elementInErrors && inProgress) {
- automationComposition.setStateChangeResult(stateChangeResult.FAILED);
- }
return updated;
}
}
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 6a1e12f70..862672f3b 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
@@ -24,6 +24,8 @@ package org.onap.policy.clamp.acm.runtime.supervision;
import io.micrometer.core.annotation.Timed;
import lombok.AllArgsConstructor;
import org.onap.policy.clamp.models.acm.concepts.AcTypeState;
+import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionDefinition;
+import org.onap.policy.clamp.models.acm.concepts.StateChangeResult;
import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantPrimeAck;
import org.onap.policy.clamp.models.acm.persistence.provider.AcDefinitionProvider;
import org.slf4j.Logger;
@@ -61,18 +63,34 @@ public class SupervisionHandler {
participantPrimeAckMessage.getCompositionId(), participantPrimeAckMessage.getParticipantId());
return;
}
- var state = AcTypeState.PRIMING.equals(acDefinition.getState()) ? AcTypeState.PRIMED : AcTypeState.COMMISSIONED;
+ handleParticipantPrimeAck(participantPrimeAckMessage, acDefinition);
+ }
+
+ private void handleParticipantPrimeAck(ParticipantPrimeAck participantPrimeAckMessage,
+ AutomationCompositionDefinition acDefinition) {
+ var finalState =
+ AcTypeState.PRIMING.equals(acDefinition.getState()) ? AcTypeState.PRIMED : AcTypeState.COMMISSIONED;
+ var msgInErrors = StateChangeResult.FAILED.equals(participantPrimeAckMessage.getStateChangeResult());
+ boolean inProgress = !StateChangeResult.FAILED.equals(acDefinition.getStateChangeResult());
+ if (inProgress && msgInErrors) {
+ acDefinition.setStateChangeResult(StateChangeResult.FAILED);
+ }
+
boolean completed = true;
for (var element : acDefinition.getElementStateMap().values()) {
if (participantPrimeAckMessage.getParticipantId().equals(element.getParticipantId())) {
- element.setState(state);
- } else if (!state.equals(element.getState())) {
+ element.setMessage(participantPrimeAckMessage.getMessage());
+ element.setState(participantPrimeAckMessage.getCompositionState());
+ }
+ if (!finalState.equals(element.getState())) {
completed = false;
}
}
- if (completed) {
- acDefinition.setState(state);
+
+ if (inProgress && !msgInErrors && completed) {
+ acDefinition.setState(finalState);
}
acDefinitionProvider.updateAcDefinition(acDefinition);
}
+
}
diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAcHandlerTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAcHandlerTest.java
index 6988cd3c4..1f63c3da8 100644
--- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAcHandlerTest.java
+++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAcHandlerTest.java
@@ -53,9 +53,10 @@ class SupervisionAcHandlerTest {
@Test
void testHandleAutomationCompositionStateChangeAckMessage() {
- var automationCompositionProvider = mock(AutomationCompositionProvider.class);
var automationComposition =
InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_CREATE_JSON, "Crud");
+ automationComposition.setInstanceId(IDENTIFIER);
+ var automationCompositionProvider = mock(AutomationCompositionProvider.class);
when(automationCompositionProvider.findAutomationComposition(IDENTIFIER))
.thenReturn(Optional.of(automationComposition));
@@ -64,38 +65,39 @@ class SupervisionAcHandlerTest {
mock(AcElementPropertiesPublisher.class));
var automationCompositionAckMessage =
- new AutomationCompositionDeployAck(ParticipantMessageType.AUTOMATION_COMPOSITION_STATECHANGE_ACK);
+ getAutomationCompositionDeployAck(ParticipantMessageType.AUTOMATION_COMPOSITION_STATECHANGE_ACK,
+ automationComposition, DeployState.DEPLOYED, LockState.UNLOCKED);
+ handler.handleAutomationCompositionStateChangeAckMessage(automationCompositionAckMessage);
+
+ verify(automationCompositionProvider).updateAutomationComposition(any(AutomationComposition.class));
+ }
+
+ private AutomationCompositionDeployAck getAutomationCompositionDeployAck(ParticipantMessageType messageType,
+ AutomationComposition automationComposition, DeployState deployState, LockState lockState) {
+ var automationCompositionAckMessage = new AutomationCompositionDeployAck(messageType);
for (var elementEntry : automationComposition.getElements().entrySet()) {
- var acElementDeployAck =
- new AcElementDeployAck(DeployState.DEPLOYED, LockState.UNLOCKED, "", "", Map.of(), true, "");
+ var acElementDeployAck = new AcElementDeployAck(deployState, lockState, "", "", Map.of(), true, "");
automationCompositionAckMessage.getAutomationCompositionResultMap().put(elementEntry.getKey(),
acElementDeployAck);
}
- automationCompositionAckMessage.setAutomationCompositionId(IDENTIFIER);
-
- handler.handleAutomationCompositionStateChangeAckMessage(automationCompositionAckMessage);
-
- verify(automationCompositionProvider).updateAutomationComposition(any(AutomationComposition.class));
+ automationCompositionAckMessage.setAutomationCompositionId(automationComposition.getInstanceId());
+ automationCompositionAckMessage.setParticipantId(CommonTestData.getParticipantId());
+ return automationCompositionAckMessage;
}
@Test
void testHandleAutomationCompositionUpdateAckMessage() {
- var automationCompositionProvider = mock(AutomationCompositionProvider.class);
var automationComposition =
InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_CREATE_JSON, "Crud");
+ automationComposition.setInstanceId(IDENTIFIER);
+ var automationCompositionProvider = mock(AutomationCompositionProvider.class);
when(automationCompositionProvider.findAutomationComposition(IDENTIFIER))
.thenReturn(Optional.of(automationComposition));
var automationCompositionAckMessage =
- new AutomationCompositionDeployAck(ParticipantMessageType.AUTOMATION_COMPOSITION_DEPLOY_ACK);
- for (var elementEntry : automationComposition.getElements().entrySet()) {
- var acElementDeployAck =
- new AcElementDeployAck(DeployState.DEPLOYED, LockState.LOCKED, "", "", Map.of(), true, "");
- automationCompositionAckMessage
- .setAutomationCompositionResultMap(Map.of(elementEntry.getKey(), acElementDeployAck));
- }
+ getAutomationCompositionDeployAck(ParticipantMessageType.AUTOMATION_COMPOSITION_DEPLOY_ACK,
+ automationComposition, DeployState.DEPLOYED, LockState.LOCKED);
automationCompositionAckMessage.setParticipantId(CommonTestData.getParticipantId());
- automationCompositionAckMessage.setAutomationCompositionId(IDENTIFIER);
var handler = new SupervisionAcHandler(automationCompositionProvider,
mock(AutomationCompositionDeployPublisher.class), mock(AutomationCompositionStateChangePublisher.class),
@@ -108,11 +110,11 @@ class SupervisionAcHandlerTest {
@Test
void testHandleAcUpdateAckFailedMessage() {
- var automationCompositionProvider = mock(AutomationCompositionProvider.class);
var automationComposition =
InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_CREATE_JSON, "Crud");
automationComposition.setDeployState(DeployState.DEPLOYING);
automationComposition.setStateChangeResult(StateChangeResult.NO_ERROR);
+ var automationCompositionProvider = mock(AutomationCompositionProvider.class);
when(automationCompositionProvider.findAutomationComposition(IDENTIFIER))
.thenReturn(Optional.of(automationComposition));
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 d4cc5e310..9ce63b005 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
@@ -32,6 +32,7 @@ import org.onap.policy.clamp.acm.runtime.instantiation.InstantiationUtils;
import org.onap.policy.clamp.acm.runtime.util.CommonTestData;
import org.onap.policy.clamp.models.acm.concepts.AcTypeState;
import org.onap.policy.clamp.models.acm.concepts.ParticipantState;
+import org.onap.policy.clamp.models.acm.concepts.StateChangeResult;
import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantPrimeAck;
import org.onap.policy.clamp.models.acm.persistence.provider.AcDefinitionProvider;
@@ -78,6 +79,32 @@ class SupervisionHandlerTest {
var acDefinition = CommonTestData.createAcDefinition(
InstantiationUtils.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML), AcTypeState.PRIMING);
participantPrimeAckMessage.setCompositionId(acDefinition.getCompositionId());
+ acDefinition.getElementStateMap().values().iterator().next()
+ .setParticipantId(CommonTestData.getParticipantId());
+
+ var acDefinitionProvider = mock(AcDefinitionProvider.class);
+ when(acDefinitionProvider.findAcDefinition(acDefinition.getCompositionId()))
+ .thenReturn(Optional.of(acDefinition));
+
+ var handler = new SupervisionHandler(acDefinitionProvider);
+
+ handler.handleParticipantMessage(participantPrimeAckMessage);
+ verify(acDefinitionProvider).findAcDefinition(any());
+ verify(acDefinitionProvider).updateAcDefinition(any());
+ }
+
+ @Test
+ void testParticipantPrimeAckFailed() {
+ var participantPrimeAckMessage = new ParticipantPrimeAck();
+ participantPrimeAckMessage.setParticipantId(CommonTestData.getParticipantId());
+ participantPrimeAckMessage.setState(ParticipantState.ON_LINE);
+ participantPrimeAckMessage.setStateChangeResult(StateChangeResult.FAILED);
+
+ var acDefinition = CommonTestData.createAcDefinition(
+ InstantiationUtils.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML), AcTypeState.PRIMING);
+ participantPrimeAckMessage.setCompositionId(acDefinition.getCompositionId());
+ acDefinition.getElementStateMap().values().iterator().next()
+ .setParticipantId(CommonTestData.getParticipantId());
var acDefinitionProvider = mock(AcDefinitionProvider.class);
when(acDefinitionProvider.findAcDefinition(acDefinition.getCompositionId()))