aboutsummaryrefslogtreecommitdiffstats
path: root/runtime-acm
diff options
context:
space:
mode:
Diffstat (limited to 'runtime-acm')
-rw-r--r--runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAcHandler.java2
-rw-r--r--runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionHandler.java15
-rw-r--r--runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionParticipantHandler.java3
-rw-r--r--runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScanner.java69
-rw-r--r--runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/TimeoutHandler.java18
-rw-r--r--runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionHandlerTest.java48
-rw-r--r--runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScannerTest.java115
7 files changed, 200 insertions, 70 deletions
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 a5dc0e78e..d6fa5d8d7 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
@@ -204,7 +204,6 @@ public class SupervisionAcHandler {
description = "AUTOMATION_COMPOSITION_DEPLOY_ACK messages received")
public void handleAutomationCompositionUpdateAckMessage(
AutomationCompositionDeployAck automationCompositionAckMessage) {
- LOGGER.debug("AutomationComposition Update Ack message received {}", automationCompositionAckMessage);
setAcElementStateInDb(automationCompositionAckMessage);
}
@@ -219,7 +218,6 @@ public class SupervisionAcHandler {
description = "AUTOMATION_COMPOSITION_STATECHANGE_ACK messages received")
public void handleAutomationCompositionStateChangeAckMessage(
AutomationCompositionDeployAck automationCompositionAckMessage) {
- LOGGER.debug("AutomationComposition StateChange Ack message received {}", automationCompositionAckMessage);
setAcElementStateInDb(automationCompositionAckMessage);
}
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 660cb28a5..963e4830e 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
@@ -52,7 +52,6 @@ public class SupervisionHandler {
*/
@Timed(value = "listener.participant_prime_ack", description = "PARTICIPANT_PRIME_ACK messages received")
public void handleParticipantMessage(ParticipantPrimeAck participantPrimeAckMessage) {
- LOGGER.debug("Participant Prime Ack message received {}", participantPrimeAckMessage);
var acDefinitionOpt = acDefinitionProvider.findAcDefinition(participantPrimeAckMessage.getCompositionId());
if (acDefinitionOpt.isEmpty()) {
LOGGER.warn("AC Definition not found in database {}", participantPrimeAckMessage.getCompositionId());
@@ -74,8 +73,10 @@ public class SupervisionHandler {
|| AcTypeState.PRIMED.equals(acDefinition.getState()) ? AcTypeState.PRIMED : AcTypeState.COMMISSIONED;
var msgInErrors = StateChangeResult.FAILED.equals(participantPrimeAckMessage.getStateChangeResult());
boolean inProgress = !StateChangeResult.FAILED.equals(acDefinition.getStateChangeResult());
+ boolean toUpdate = false;
if (inProgress && msgInErrors) {
acDefinition.setStateChangeResult(StateChangeResult.FAILED);
+ toUpdate = true;
}
boolean completed = true;
@@ -85,6 +86,7 @@ public class SupervisionHandler {
element.setMessage(participantPrimeAckMessage.getMessage());
element.setState(participantPrimeAckMessage.getCompositionState());
element.setRestarting(null);
+ acDefinitionProvider.updateAcDefinitionElement(element, acDefinition.getCompositionId());
}
if (!finalState.equals(element.getState())) {
completed = false;
@@ -95,16 +97,19 @@ public class SupervisionHandler {
}
if (inProgress && !msgInErrors && completed) {
+ toUpdate = true;
acDefinition.setState(finalState);
if (StateChangeResult.TIMEOUT.equals(acDefinition.getStateChangeResult())) {
acDefinition.setStateChangeResult(StateChangeResult.NO_ERROR);
}
}
- if (!restarting) {
+ if (!restarting && acDefinition.getRestarting() != null) {
+ toUpdate = true;
acDefinition.setRestarting(null);
}
- acDefinitionProvider.updateAcDefinition(acDefinition,
- acRuntimeParameterGroup.getAcmParameters().getToscaCompositionName());
+ if (toUpdate) {
+ acDefinitionProvider.updateAcDefinitionState(acDefinition.getCompositionId(), acDefinition.getState(),
+ acDefinition.getStateChangeResult(), acDefinition.getRestarting());
+ }
}
-
}
diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionParticipantHandler.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionParticipantHandler.java
index 7a2c58d50..24c256fa4 100644
--- a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionParticipantHandler.java
+++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionParticipantHandler.java
@@ -74,7 +74,6 @@ public class SupervisionParticipantHandler {
@MessageIntercept
@Timed(value = "listener.participant_register", description = "PARTICIPANT_REGISTER messages received")
public void handleParticipantMessage(ParticipantRegister participantRegisterMsg) {
- LOGGER.debug("Participant Register received {}", participantRegisterMsg);
var participantOpt = participantProvider.findParticipant(participantRegisterMsg.getParticipantId());
if (participantOpt.isPresent()) {
@@ -100,7 +99,6 @@ public class SupervisionParticipantHandler {
@MessageIntercept
@Timed(value = "listener.participant_deregister", description = "PARTICIPANT_DEREGISTER messages received")
public void handleParticipantMessage(ParticipantDeregister participantDeregisterMsg) {
- LOGGER.debug("Participant Deregister received {}", participantDeregisterMsg);
var participantOpt = participantProvider.findParticipant(participantDeregisterMsg.getParticipantId());
if (participantOpt.isPresent()) {
@@ -120,7 +118,6 @@ public class SupervisionParticipantHandler {
@MessageIntercept
@Timed(value = "listener.participant_status", description = "PARTICIPANT_STATUS messages received")
public void handleParticipantMessage(ParticipantStatus participantStatusMsg) {
- LOGGER.debug("Participant Status received {}", participantStatusMsg);
var participantOpt = participantProvider.findParticipant(participantStatusMsg.getParticipantId());
if (participantOpt.isEmpty()) {
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 33118fab7..881969a90 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
@@ -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.
* ================================================================================
@@ -23,8 +23,11 @@
package org.onap.policy.clamp.acm.runtime.supervision;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.Map;
+import java.util.Set;
import java.util.UUID;
+import java.util.stream.Collectors;
import org.onap.policy.clamp.acm.runtime.main.parameters.AcRuntimeParameterGroup;
import org.onap.policy.clamp.acm.runtime.supervision.comm.AutomationCompositionDeployPublisher;
import org.onap.policy.clamp.acm.runtime.supervision.comm.AutomationCompositionStateChangePublisher;
@@ -56,7 +59,6 @@ public class SupervisionScanner {
private final AcDefinitionProvider acDefinitionProvider;
private final AutomationCompositionStateChangePublisher automationCompositionStateChangePublisher;
private final AutomationCompositionDeployPublisher automationCompositionDeployPublisher;
- private final AcRuntimeParameterGroup acRuntimeParameterGroup;
/**
* Constructor for instantiating SupervisionScanner.
@@ -76,7 +78,6 @@ public class SupervisionScanner {
this.acDefinitionProvider = acDefinitionProvider;
this.automationCompositionStateChangePublisher = automationCompositionStateChangePublisher;
this.automationCompositionDeployPublisher = automationCompositionDeployPublisher;
- this.acRuntimeParameterGroup = acRuntimeParameterGroup;
acTimeout.setMaxWaitMs(acRuntimeParameterGroup.getParticipantParameters().getMaxStatusWaitMs());
}
@@ -87,20 +88,27 @@ public class SupervisionScanner {
public void run() {
LOGGER.debug("Scanning automation compositions in the database . . .");
- var list = acDefinitionProvider.getAllAcDefinitions();
- for (var acDefinition : list) {
- if (AcTypeState.PRIMING.equals(acDefinition.getState())
- || AcTypeState.DEPRIMING.equals(acDefinition.getState())) {
- scanAutomationCompositionDefinition(acDefinition);
- } else {
- acTimeout.clear(acDefinition.getCompositionId());
- var acList =
- automationCompositionProvider.getAcInstancesByCompositionId(acDefinition.getCompositionId());
- for (var automationComposition : acList) {
- scanAutomationComposition(automationComposition, acDefinition.getServiceTemplate());
- }
+ var acDefinitionList = acDefinitionProvider.getAllAcDefinitionsInTransition();
+ for (var acDefinition : acDefinitionList) {
+ scanAutomationCompositionDefinition(acDefinition);
+ }
+ Set<UUID> set = new HashSet<>();
+ set.addAll(acDefinitionList
+ .stream().map(AutomationCompositionDefinition::getCompositionId).collect(Collectors.toSet()));
+
+ var acList = automationCompositionProvider.getAcInstancesInTransition();
+ HashMap<UUID, AutomationCompositionDefinition> acDefinitionMap = new HashMap<>();
+ for (var automationComposition : acList) {
+ var acDefinition = acDefinitionMap.get(automationComposition.getCompositionId());
+ if (acDefinition == null) {
+ acDefinition = acDefinitionProvider.getAcDefinition(automationComposition.getCompositionId());
+ acDefinitionMap.put(acDefinition.getCompositionId(), acDefinition);
}
+ scanAutomationComposition(automationComposition, acDefinition.getServiceTemplate());
}
+ set.addAll(
+ acList.stream().map(AutomationComposition::getInstanceId).collect(Collectors.toSet()));
+ acTimeout.removeIfNotPresent(set);
LOGGER.debug("Automation composition scan complete . . .");
}
@@ -110,7 +118,7 @@ public class SupervisionScanner {
LOGGER.debug("automation definition {} scanned, OK", acDefinition.getCompositionId());
// Clear Timeout on ac Definition
- acTimeout.clear(acDefinition.getCompositionId());
+ acTimeout.remove(acDefinition.getCompositionId());
return;
}
@@ -121,7 +129,21 @@ public class SupervisionScanner {
acTimeout.clear(acDefinition.getCompositionId());
}
- handleTimeout(acDefinition);
+ boolean completed = true;
+ var finalState = AcTypeState.PRIMING.equals(acDefinition.getState())
+ || AcTypeState.PRIMED.equals(acDefinition.getState()) ? AcTypeState.PRIMED : AcTypeState.COMMISSIONED;
+ for (var element : acDefinition.getElementStateMap().values()) {
+ if (!finalState.equals(element.getState())) {
+ completed = false;
+ }
+ }
+ if (completed) {
+ acDefinitionProvider.updateAcDefinitionState(acDefinition.getCompositionId(), finalState,
+ StateChangeResult.NO_ERROR, null);
+ acTimeout.remove(acDefinition.getCompositionId());
+ } else {
+ handleTimeout(acDefinition);
+ }
}
private void scanAutomationComposition(final AutomationComposition automationComposition,
@@ -134,7 +156,7 @@ public class SupervisionScanner {
LOGGER.debug("automation composition {} scanned, OK", automationComposition.getInstanceId());
// Clear Timeout on automation composition
- clearTimeout(automationComposition, true);
+ removeTimeout(automationComposition);
return;
}
@@ -214,7 +236,7 @@ public class SupervisionScanner {
}
// Clear timeout on automation composition
- clearTimeout(automationComposition, true);
+ removeTimeout(automationComposition);
}
private void clearTimeout(AutomationComposition automationComposition, boolean cleanPhase) {
@@ -224,6 +246,11 @@ public class SupervisionScanner {
}
}
+ private void removeTimeout(AutomationComposition automationComposition) {
+ acTimeout.remove(automationComposition.getInstanceId());
+ phaseMap.remove(automationComposition.getInstanceId());
+ }
+
private void handleTimeout(AutomationCompositionDefinition acDefinition) {
var compositionId = acDefinition.getCompositionId();
if (acTimeout.isTimeout(compositionId)) {
@@ -235,8 +262,8 @@ public class SupervisionScanner {
LOGGER.debug("Report timeout for the ac definition {}", acDefinition.getCompositionId());
acTimeout.setTimeout(compositionId);
acDefinition.setStateChangeResult(StateChangeResult.TIMEOUT);
- acDefinitionProvider.updateAcDefinition(acDefinition,
- acRuntimeParameterGroup.getAcmParameters().getToscaCompositionName());
+ acDefinitionProvider.updateAcDefinitionState(acDefinition.getCompositionId(),
+ acDefinition.getState(), acDefinition.getStateChangeResult(), acDefinition.getRestarting());
}
}
diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/TimeoutHandler.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/TimeoutHandler.java
index 976c91438..3b34252bf 100644
--- a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/TimeoutHandler.java
+++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/TimeoutHandler.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.
@@ -33,8 +33,8 @@ public class TimeoutHandler<K> {
@Setter
private long maxWaitMs;
- private Set<K> mapTimeout = new HashSet<>();
- private Map<K, Long> mapTimer = new HashMap<>();
+ private final Set<K> mapTimeout = new HashSet<>();
+ private final Map<K, Long> mapTimer = new HashMap<>();
public long getDuration(K id) {
mapTimer.putIfAbsent(id, getEpochMilli());
@@ -61,6 +61,18 @@ public class TimeoutHandler<K> {
mapTimer.remove(id);
}
+ /**
+ * Remove elements that are not present in set.
+ *
+ * @param set the elements that should be present
+ */
+ public void removeIfNotPresent(final Set<K> set) {
+ var res = mapTimeout.stream().filter(el -> !set.contains(el)).toList();
+ if (!res.isEmpty()) {
+ res.forEach(this::remove);
+ }
+ }
+
public void setTimeout(K id) {
mapTimeout.add(id);
}
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 4028f57f6..448666f8f 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
@@ -22,6 +22,7 @@ package org.onap.policy.clamp.acm.runtime.supervision;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
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;
@@ -77,13 +78,16 @@ class SupervisionHandlerTest {
void testParticipantPrimeAck() {
var participantPrimeAckMessage = new ParticipantPrimeAck();
participantPrimeAckMessage.setParticipantId(CommonTestData.getParticipantId());
+ participantPrimeAckMessage.setCompositionState(AcTypeState.PRIMED);
participantPrimeAckMessage.setState(ParticipantState.ON_LINE);
var acDefinition = CommonTestData.createAcDefinition(
InstantiationUtils.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML), AcTypeState.PRIMING);
+ acDefinition.setStateChangeResult(StateChangeResult.NO_ERROR);
participantPrimeAckMessage.setCompositionId(acDefinition.getCompositionId());
- acDefinition.getElementStateMap().values().iterator().next()
- .setParticipantId(CommonTestData.getParticipantId());
+ for (var element : acDefinition.getElementStateMap().values()) {
+ element.setParticipantId(CommonTestData.getParticipantId());
+ }
var acDefinitionProvider = mock(AcDefinitionProvider.class);
when(acDefinitionProvider.findAcDefinition(acDefinition.getCompositionId()))
@@ -93,7 +97,10 @@ class SupervisionHandlerTest {
handler.handleParticipantMessage(participantPrimeAckMessage);
verify(acDefinitionProvider).findAcDefinition(any());
- verify(acDefinitionProvider).updateAcDefinition(any(), any());
+ verify(acDefinitionProvider, times(acDefinition.getElementStateMap().size()))
+ .updateAcDefinitionElement(any(), any());
+ verify(acDefinitionProvider).updateAcDefinitionState(acDefinition.getCompositionId(), AcTypeState.PRIMED,
+ StateChangeResult.NO_ERROR, null);
}
@Test
@@ -117,6 +124,39 @@ class SupervisionHandlerTest {
handler.handleParticipantMessage(participantPrimeAckMessage);
verify(acDefinitionProvider).findAcDefinition(any());
- verify(acDefinitionProvider).updateAcDefinition(any(), any());
+ verify(acDefinitionProvider).updateAcDefinitionElement(any(), any());
+ verify(acDefinitionProvider).updateAcDefinitionState(acDefinition.getCompositionId(), AcTypeState.PRIMING,
+ StateChangeResult.FAILED, null);
+ }
+
+ @Test
+ void testParticipantPrimeAckRestarted() {
+ var participantPrimeAckMessage = new ParticipantPrimeAck();
+ participantPrimeAckMessage.setParticipantId(CommonTestData.getParticipantId());
+ participantPrimeAckMessage.setCompositionState(AcTypeState.PRIMED);
+ participantPrimeAckMessage.setState(ParticipantState.ON_LINE);
+
+ var acDefinition = CommonTestData.createAcDefinition(
+ InstantiationUtils.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML), AcTypeState.PRIMED);
+ acDefinition.setStateChangeResult(StateChangeResult.TIMEOUT);
+ acDefinition.setRestarting(true);
+ participantPrimeAckMessage.setCompositionId(acDefinition.getCompositionId());
+ for (var element : acDefinition.getElementStateMap().values()) {
+ element.setParticipantId(CommonTestData.getParticipantId());
+ element.setRestarting(true);
+ }
+
+ var acDefinitionProvider = mock(AcDefinitionProvider.class);
+ when(acDefinitionProvider.findAcDefinition(acDefinition.getCompositionId()))
+ .thenReturn(Optional.of(acDefinition));
+
+ var handler = new SupervisionHandler(acDefinitionProvider, CommonTestData.getTestParamaterGroup());
+
+ handler.handleParticipantMessage(participantPrimeAckMessage);
+ verify(acDefinitionProvider).findAcDefinition(any());
+ verify(acDefinitionProvider, times(acDefinition.getElementStateMap().size()))
+ .updateAcDefinitionElement(any(), any());
+ verify(acDefinitionProvider).updateAcDefinitionState(acDefinition.getCompositionId(), AcTypeState.PRIMED,
+ StateChangeResult.NO_ERROR, null);
}
}
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 a1fad46b1..7d0b4252a 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
@@ -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.
@@ -25,6 +25,7 @@ import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.clearInvocations;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
@@ -46,6 +47,7 @@ import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionDefinition
import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElement;
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.NodeTemplateState;
import org.onap.policy.clamp.models.acm.concepts.StateChangeResult;
import org.onap.policy.clamp.models.acm.persistence.provider.AcDefinitionProvider;
import org.onap.policy.clamp.models.acm.persistence.provider.AutomationCompositionProvider;
@@ -57,82 +59,131 @@ class SupervisionScannerTest {
private static final UUID compositionId = UUID.randomUUID();
- private AcDefinitionProvider createAcDefinitionProvider(AcTypeState acTypeState,
- StateChangeResult stateChangeResult) {
+ private AutomationCompositionDefinition createAutomationCompositionDefinition(AcTypeState acTypeState,
+ StateChangeResult stateChangeResult) {
var serviceTemplate = InstantiationUtils.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML);
var acDefinition = new AutomationCompositionDefinition();
acDefinition.setState(acTypeState);
acDefinition.setStateChangeResult(stateChangeResult);
acDefinition.setCompositionId(compositionId);
acDefinition.setServiceTemplate(serviceTemplate);
+ var node = new NodeTemplateState();
+ node.setState(AcTypeState.PRIMING);
+ node.setNodeTemplateStateId(UUID.randomUUID());
+ acDefinition.setElementStateMap(Map.of(node.getNodeTemplateStateId().toString(), node));
+ return acDefinition;
+ }
+
+ private AcDefinitionProvider createAcDefinitionProvider(AutomationCompositionDefinition acDefinition) {
var acDefinitionProvider = mock(AcDefinitionProvider.class);
- when(acDefinitionProvider.getAllAcDefinitions()).thenReturn(List.of(Objects.requireNonNull(acDefinition)));
+ var acTypeState = acDefinition.getState();
+ if (AcTypeState.PRIMING.equals(acTypeState) || AcTypeState.DEPRIMING.equals(acTypeState)) {
+ when(acDefinitionProvider.getAllAcDefinitionsInTransition())
+ .thenReturn(List.of(Objects.requireNonNull(acDefinition)));
+ }
+ when(acDefinitionProvider.getAcDefinition(compositionId)).thenReturn(acDefinition);
return acDefinitionProvider;
}
+ private AcDefinitionProvider createAcDefinitionProvider(AcTypeState acTypeState,
+ StateChangeResult stateChangeResult) {
+ return createAcDefinitionProvider(createAutomationCompositionDefinition(acTypeState, stateChangeResult));
+ }
+
private AcDefinitionProvider createAcDefinitionProvider() {
return createAcDefinitionProvider(AcTypeState.PRIMED, StateChangeResult.NO_ERROR);
}
@Test
- void testScannerOrderedFailed() {
+ void testAcDefinitionPrimeFailed() {
var acDefinitionProvider = createAcDefinitionProvider(AcTypeState.PRIMING, StateChangeResult.FAILED);
var acRuntimeParameterGroup = CommonTestData.geParameterGroup("dbScanner");
var supervisionScanner = new SupervisionScanner(mock(AutomationCompositionProvider.class), acDefinitionProvider,
mock(AutomationCompositionStateChangePublisher.class), mock(AutomationCompositionDeployPublisher.class),
acRuntimeParameterGroup);
supervisionScanner.run();
- verify(acDefinitionProvider, times(0)).updateAcDefinition(any(AutomationCompositionDefinition.class),
- eq(CommonTestData.TOSCA_COMP_NAME));
+ verify(acDefinitionProvider, times(0)).updateAcDefinitionState(any(), any(), any(), any());
}
@Test
- void testScannerOrderedPriming() {
- var acDefinitionProvider = createAcDefinitionProvider(AcTypeState.PRIMING, StateChangeResult.NO_ERROR);
+ void testAcDefinitionPrimeTimeout() {
+ var acDefinition = createAutomationCompositionDefinition(AcTypeState.PRIMING, StateChangeResult.NO_ERROR);
+ var acDefinitionProvider = createAcDefinitionProvider(acDefinition);
var acRuntimeParameterGroup = CommonTestData.geParameterGroup("dbScanner");
var supervisionScanner = new SupervisionScanner(mock(AutomationCompositionProvider.class), acDefinitionProvider,
mock(AutomationCompositionStateChangePublisher.class), mock(AutomationCompositionDeployPublisher.class),
acRuntimeParameterGroup);
supervisionScanner.run();
- verify(acDefinitionProvider, times(0)).updateAcDefinition(any(AutomationCompositionDefinition.class),
- eq(CommonTestData.TOSCA_COMP_NAME));
+ // Ac Definition in Priming state
+ verify(acDefinitionProvider, times(0)).updateAcDefinitionState(any(), any(), any(), any());
acRuntimeParameterGroup.getParticipantParameters().setMaxStatusWaitMs(-1);
supervisionScanner = new SupervisionScanner(mock(AutomationCompositionProvider.class), acDefinitionProvider,
mock(AutomationCompositionStateChangePublisher.class), mock(AutomationCompositionDeployPublisher.class),
acRuntimeParameterGroup);
supervisionScanner.run();
- verify(acDefinitionProvider).updateAcDefinition(any(AutomationCompositionDefinition.class),
- eq(CommonTestData.TOSCA_COMP_NAME));
+ // set Timeout
+ verify(acDefinitionProvider).updateAcDefinitionState(acDefinition.getCompositionId(), acDefinition.getState(),
+ StateChangeResult.TIMEOUT, null);
+
+ clearInvocations(acDefinitionProvider);
+ acDefinition.setStateChangeResult(StateChangeResult.TIMEOUT);
+ supervisionScanner.run();
+ // already in Timeout
+ verify(acDefinitionProvider, times(0)).updateAcDefinitionState(any(), any(), any(), any());
+
+ clearInvocations(acDefinitionProvider);
+ // retry by the user
+ acDefinition.setStateChangeResult(StateChangeResult.NO_ERROR);
+ supervisionScanner.run();
+ // set Timeout
+ verify(acDefinitionProvider).updateAcDefinitionState(acDefinition.getCompositionId(), acDefinition.getState(),
+ StateChangeResult.TIMEOUT, null);
+
+ clearInvocations(acDefinitionProvider);
+ for (var element : acDefinition.getElementStateMap().values()) {
+ element.setState(AcTypeState.PRIMED);
+ }
+ supervisionScanner.run();
+ // completed
+ verify(acDefinitionProvider).updateAcDefinitionState(acDefinition.getCompositionId(), AcTypeState.PRIMED,
+ StateChangeResult.NO_ERROR, null);
}
@Test
- void testScannerOrderedStateEqualsToState() {
+ void testAcNotInTransitionOrFailed() {
var automationCompositionProvider = mock(AutomationCompositionProvider.class);
var automationCompositionStateChangePublisher = mock(AutomationCompositionStateChangePublisher.class);
var automationCompositionDeployPublisher = mock(AutomationCompositionDeployPublisher.class);
var acRuntimeParameterGroup = CommonTestData.geParameterGroup("dbScanner");
var automationComposition = InstantiationUtils.getAutomationCompositionFromResource(AC_JSON, "Crud");
- when(automationCompositionProvider.getAcInstancesByCompositionId(compositionId))
- .thenReturn(List.of(automationComposition));
+ automationComposition.setCompositionId(compositionId);
+ when(automationCompositionProvider.getAcInstancesInTransition()).thenReturn(List.of(automationComposition));
var supervisionScanner = new SupervisionScanner(automationCompositionProvider, createAcDefinitionProvider(),
automationCompositionStateChangePublisher, automationCompositionDeployPublisher,
acRuntimeParameterGroup);
+
+ // not in transition
supervisionScanner.run();
+ verify(automationCompositionProvider, times(0)).updateAutomationComposition(any(AutomationComposition.class));
+ automationComposition.setDeployState(DeployState.DEPLOYING);
+ automationComposition.setStateChangeResult(StateChangeResult.FAILED);
+ supervisionScanner.run();
+ // failed
verify(automationCompositionProvider, times(0)).updateAutomationComposition(any(AutomationComposition.class));
}
@Test
- void testScannerOrderedStateDifferentToState() {
+ void testAcUndeployCompleted() {
var automationComposition = InstantiationUtils.getAutomationCompositionFromResource(AC_JSON, "Crud");
automationComposition.setDeployState(DeployState.UNDEPLOYING);
automationComposition.setLockState(LockState.NONE);
+ automationComposition.setCompositionId(compositionId);
var automationCompositionProvider = mock(AutomationCompositionProvider.class);
- when(automationCompositionProvider.getAcInstancesByCompositionId(compositionId))
- .thenReturn(List.of(automationComposition));
+ when(automationCompositionProvider.getAcInstancesInTransition()).thenReturn(List.of(automationComposition));
var automationCompositionDeployPublisher = mock(AutomationCompositionDeployPublisher.class);
var automationCompositionStateChangePublisher = mock(AutomationCompositionStateChangePublisher.class);
@@ -147,13 +198,13 @@ class SupervisionScannerTest {
}
@Test
- void testScannerDelete() {
+ void testAcDeleted() {
var automationComposition = InstantiationUtils.getAutomationCompositionFromResource(AC_JSON, "Crud");
automationComposition.setDeployState(DeployState.DELETING);
automationComposition.setLockState(LockState.NONE);
+ automationComposition.setCompositionId(compositionId);
var automationCompositionProvider = mock(AutomationCompositionProvider.class);
- when(automationCompositionProvider.getAcInstancesByCompositionId(compositionId))
- .thenReturn(List.of(automationComposition));
+ when(automationCompositionProvider.getAcInstancesInTransition()).thenReturn(List.of(automationComposition));
var automationCompositionDeployPublisher = mock(AutomationCompositionDeployPublisher.class);
var automationCompositionStateChangePublisher = mock(AutomationCompositionStateChangePublisher.class);
@@ -171,8 +222,8 @@ class SupervisionScannerTest {
void testScanner() {
var automationCompositionProvider = mock(AutomationCompositionProvider.class);
var automationComposition = new AutomationComposition();
- when(automationCompositionProvider.getAcInstancesByCompositionId(compositionId))
- .thenReturn(List.of(automationComposition));
+ automationComposition.setCompositionId(compositionId);
+ when(automationCompositionProvider.getAcInstancesInTransition()).thenReturn(List.of(automationComposition));
var automationCompositionDeployPublisher = mock(AutomationCompositionDeployPublisher.class);
var automationCompositionStateChangePublisher = mock(AutomationCompositionStateChangePublisher.class);
@@ -191,12 +242,12 @@ class SupervisionScannerTest {
var automationComposition = InstantiationUtils.getAutomationCompositionFromResource(AC_JSON, "Crud");
automationComposition.setDeployState(DeployState.DEPLOYING);
automationComposition.setLockState(LockState.NONE);
+ automationComposition.setCompositionId(compositionId);
for (Map.Entry<UUID, AutomationCompositionElement> entry : automationComposition.getElements().entrySet()) {
entry.getValue().setDeployState(DeployState.DEPLOYING);
}
var automationCompositionProvider = mock(AutomationCompositionProvider.class);
- when(automationCompositionProvider.getAcInstancesByCompositionId(compositionId))
- .thenReturn(List.of(automationComposition));
+ when(automationCompositionProvider.getAcInstancesInTransition()).thenReturn(List.of(automationComposition));
var automationCompositionDeployPublisher = mock(AutomationCompositionDeployPublisher.class);
var automationCompositionStateChangePublisher = mock(AutomationCompositionStateChangePublisher.class);
@@ -225,6 +276,7 @@ class SupervisionScannerTest {
var automationComposition = InstantiationUtils.getAutomationCompositionFromResource(AC_JSON, "Crud");
automationComposition.setDeployState(DeployState.DEPLOYING);
automationComposition.setLockState(LockState.NONE);
+ automationComposition.setCompositionId(compositionId);
for (var element : automationComposition.getElements().values()) {
if ("org.onap.domain.database.Http_PMSHMicroserviceAutomationCompositionElement"
.equals(element.getDefinition().getName())) {
@@ -237,8 +289,7 @@ class SupervisionScannerTest {
}
var automationCompositionProvider = mock(AutomationCompositionProvider.class);
- when(automationCompositionProvider.getAcInstancesByCompositionId(compositionId))
- .thenReturn(List.of(automationComposition));
+ when(automationCompositionProvider.getAcInstancesInTransition()).thenReturn(List.of(automationComposition));
var automationCompositionDeployPublisher = mock(AutomationCompositionDeployPublisher.class);
var automationCompositionStateChangePublisher = mock(AutomationCompositionStateChangePublisher.class);
@@ -258,6 +309,7 @@ class SupervisionScannerTest {
void testSendAutomationCompositionMigrate() {
var automationComposition = InstantiationUtils.getAutomationCompositionFromResource(AC_JSON, "Crud");
automationComposition.setDeployState(DeployState.MIGRATING);
+ automationComposition.setCompositionId(compositionId);
var compositionTargetId = UUID.randomUUID();
automationComposition.setCompositionTargetId(compositionTargetId);
automationComposition.setLockState(LockState.LOCKED);
@@ -267,8 +319,7 @@ class SupervisionScannerTest {
}
var automationCompositionProvider = mock(AutomationCompositionProvider.class);
- when(automationCompositionProvider.getAcInstancesByCompositionId(compositionId))
- .thenReturn(List.of(automationComposition));
+ when(automationCompositionProvider.getAcInstancesInTransition()).thenReturn(List.of(automationComposition));
var automationCompositionDeployPublisher = mock(AutomationCompositionDeployPublisher.class);
var automationCompositionStateChangePublisher = mock(AutomationCompositionStateChangePublisher.class);
@@ -289,6 +340,7 @@ class SupervisionScannerTest {
var automationComposition = InstantiationUtils.getAutomationCompositionFromResource(AC_JSON, "Crud");
automationComposition.setDeployState(DeployState.DEPLOYED);
automationComposition.setLockState(LockState.UNLOCKING);
+ automationComposition.setCompositionId(compositionId);
for (var element : automationComposition.getElements().values()) {
if ("org.onap.domain.database.Http_PMSHMicroserviceAutomationCompositionElement"
.equals(element.getDefinition().getName())) {
@@ -301,8 +353,7 @@ class SupervisionScannerTest {
}
var automationCompositionProvider = mock(AutomationCompositionProvider.class);
- when(automationCompositionProvider.getAcInstancesByCompositionId(compositionId))
- .thenReturn(List.of(automationComposition));
+ when(automationCompositionProvider.getAcInstancesInTransition()).thenReturn(List.of(automationComposition));
var automationCompositionDeployPublisher = mock(AutomationCompositionDeployPublisher.class);
var automationCompositionStateChangePublisher = mock(AutomationCompositionStateChangePublisher.class);