summaryrefslogtreecommitdiffstats
path: root/runtime-acm/src
diff options
context:
space:
mode:
authorFrancescoFioraEst <francesco.fiora@est.tech>2023-02-13 11:08:42 +0000
committerFrancescoFioraEst <francesco.fiora@est.tech>2023-02-14 10:32:14 +0000
commit204be45b2c666a9261e287275ead362b8817f22c (patch)
tree4c21b8763a6570e920fb8901a33ecd07990def15 /runtime-acm/src
parent06339bee0cf891144ca781983ba99d170b10b2b7 (diff)
Implement recording of Operational State and Usage State on ACM-R
Issue-ID: POLICY-4511 Change-Id: I3a241bf602e6625d91cee2dc5242b76165bcd381 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/supervision/SupervisionAcHandler.java6
-rw-r--r--runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAspect.java10
-rw-r--r--runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionPartecipantScanner.java93
-rw-r--r--runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScanner.java113
-rw-r--r--runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/AutomationCompositionDeployPublisher.java43
-rw-r--r--runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/AutomationCompositionStateChangePublisher.java70
-rw-r--r--runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAcHandlerTest.java55
-rw-r--r--runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAspectTest.java12
-rw-r--r--runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionParticipantScannerTest.java58
-rw-r--r--runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScannerTest.java103
-rw-r--r--runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/comm/SupervisionMessagesTest.java16
11 files changed, 327 insertions, 252 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 3e79e78c1..5fcb3837f 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
@@ -79,7 +79,7 @@ public class SupervisionAcHandler {
AcmUtils.setCascadedState(automationComposition, DeployState.UNDEPLOYING, LockState.NONE);
automationCompositionProvider.updateAutomationComposition(automationComposition);
var startPhase = ParticipantUtils.getFirstStartPhase(automationComposition, acDefinition.getServiceTemplate());
- automationCompositionStateChangePublisher.undeploy(automationComposition, startPhase, true);
+ automationCompositionStateChangePublisher.send(automationComposition, startPhase, true);
}
/**
@@ -92,7 +92,7 @@ public class SupervisionAcHandler {
AcmUtils.setCascadedState(automationComposition, DeployState.DEPLOYED, LockState.UNLOCKING);
automationCompositionProvider.updateAutomationComposition(automationComposition);
var startPhase = ParticipantUtils.getFirstStartPhase(automationComposition, acDefinition.getServiceTemplate());
- automationCompositionStateChangePublisher.unlock(automationComposition, startPhase, true);
+ automationCompositionStateChangePublisher.send(automationComposition, startPhase, true);
}
/**
@@ -105,7 +105,7 @@ public class SupervisionAcHandler {
AcmUtils.setCascadedState(automationComposition, DeployState.DEPLOYED, LockState.LOCKING);
automationCompositionProvider.updateAutomationComposition(automationComposition);
var startPhase = ParticipantUtils.getFirstStartPhase(automationComposition, acDefinition.getServiceTemplate());
- automationCompositionStateChangePublisher.lock(automationComposition, startPhase, true);
+ automationCompositionStateChangePublisher.send(automationComposition, startPhase, true);
}
/**
diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAspect.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAspect.java
index 8d1f98388..ef50a633e 100644
--- a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAspect.java
+++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAspect.java
@@ -43,6 +43,7 @@ public class SupervisionAspect implements Closeable {
private static final Logger LOGGER = LoggerFactory.getLogger(SupervisionAspect.class);
private final SupervisionScanner supervisionScanner;
+ private final SupervisionPartecipantScanner partecipantScanner;
private ThreadPoolExecutor executor =
new ThreadPoolExecutor(1, 1, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>());
@@ -52,7 +53,12 @@ public class SupervisionAspect implements Closeable {
initialDelayString = "${runtime.participantParameters.heartBeatMs}")
public void schedule() {
LOGGER.info("Add scheduled scanning");
- executor.execute(() -> supervisionScanner.run(true));
+ executor.execute(this::executeScan);
+ }
+
+ private void executeScan() {
+ supervisionScanner.run(true);
+ partecipantScanner.run();
}
/**
@@ -68,7 +74,7 @@ public class SupervisionAspect implements Closeable {
@Before("@annotation(MessageIntercept) && args(participantStatusMessage,..)")
public void handleParticipantStatus(ParticipantStatus participantStatusMessage) {
- executor.execute(() -> supervisionScanner.handleParticipantStatus(participantStatusMessage.getParticipantId()));
+ executor.execute(() -> partecipantScanner.handleParticipantStatus(participantStatusMessage.getParticipantId()));
}
@Override
diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionPartecipantScanner.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionPartecipantScanner.java
new file mode 100644
index 000000000..b396e629c
--- /dev/null
+++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionPartecipantScanner.java
@@ -0,0 +1,93 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2023 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.clamp.acm.runtime.supervision;
+
+import java.util.UUID;
+import org.onap.policy.clamp.acm.runtime.main.parameters.AcRuntimeParameterGroup;
+import org.onap.policy.clamp.models.acm.concepts.Participant;
+import org.onap.policy.clamp.models.acm.concepts.ParticipantState;
+import org.onap.policy.clamp.models.acm.persistence.provider.ParticipantProvider;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Component;
+
+/**
+ * This class is used to scan the automation compositions in the database and check if they are in the correct state.
+ */
+@Component
+public class SupervisionPartecipantScanner {
+ private static final Logger LOGGER = LoggerFactory.getLogger(SupervisionPartecipantScanner.class);
+
+ private final HandleCounter<UUID> participantStatusCounter = new HandleCounter<>();
+
+ private final ParticipantProvider participantProvider;
+
+ /**
+ * Constructor for instantiating SupervisionPartecipantScanner.
+ *
+ * @param participantProvider the Participant Provider
+ * @param acRuntimeParameterGroup the parameters for the automation composition runtime
+ */
+ public SupervisionPartecipantScanner(
+ final ParticipantProvider participantProvider,
+ final AcRuntimeParameterGroup acRuntimeParameterGroup) {
+ this.participantProvider = participantProvider;
+
+ participantStatusCounter.setMaxRetryCount(
+ acRuntimeParameterGroup.getParticipantParameters().getUpdateParameters().getMaxRetryCount());
+ participantStatusCounter.setMaxWaitMs(acRuntimeParameterGroup.getParticipantParameters().getMaxStatusWaitMs());
+ }
+
+ /**
+ * Run Scanning.
+ */
+ public void run() {
+ LOGGER.debug("Scanning participans in the database . . .");
+
+ for (var participant : participantProvider.getParticipants()) {
+ scanParticipantStatus(participant);
+ }
+
+ LOGGER.debug("Participans scan complete . . .");
+ }
+
+ private void scanParticipantStatus(Participant participant) {
+ var id = participant.getParticipantId();
+ if (participantStatusCounter.isFault(id)) {
+ LOGGER.debug("report Participant fault");
+ return;
+ }
+ if (participantStatusCounter.getDuration(id) > participantStatusCounter.getMaxWaitMs()
+ && !participantStatusCounter.count(id)) {
+ LOGGER.debug("report Participant fault");
+ participantStatusCounter.setFault(id);
+ participant.setParticipantState(ParticipantState.OFF_LINE);
+ participantProvider.updateParticipant(participant);
+ }
+ }
+
+ /**
+ * handle participant Status message.
+ */
+ public void handleParticipantStatus(UUID id) {
+ participantStatusCounter.clear(id);
+ }
+}
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 68ec44dc0..7ee7267e2 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
@@ -29,13 +29,11 @@ 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;
import org.onap.policy.clamp.models.acm.concepts.AutomationComposition;
-import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionState;
-import org.onap.policy.clamp.models.acm.concepts.Participant;
-import org.onap.policy.clamp.models.acm.concepts.ParticipantState;
+import org.onap.policy.clamp.models.acm.concepts.DeployState;
import org.onap.policy.clamp.models.acm.concepts.ParticipantUtils;
import org.onap.policy.clamp.models.acm.persistence.provider.AcDefinitionProvider;
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.utils.AcmUtils;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -49,15 +47,12 @@ public class SupervisionScanner {
private static final Logger LOGGER = LoggerFactory.getLogger(SupervisionScanner.class);
private final HandleCounter<UUID> automationCompositionCounter = new HandleCounter<>();
- private final HandleCounter<UUID> participantStatusCounter = new HandleCounter<>();
-
private final Map<UUID, Integer> phaseMap = new HashMap<>();
private final AutomationCompositionProvider automationCompositionProvider;
private final AcDefinitionProvider acDefinitionProvider;
private final AutomationCompositionStateChangePublisher automationCompositionStateChangePublisher;
private final AutomationCompositionDeployPublisher automationCompositionDeployPublisher;
- private final ParticipantProvider participantProvider;
/**
* Constructor for instantiating SupervisionScanner.
@@ -66,29 +61,22 @@ public class SupervisionScanner {
* @param acDefinitionProvider the Policy Models Provider
* @param automationCompositionStateChangePublisher the AutomationComposition StateChange Publisher
* @param automationCompositionDeployPublisher the AutomationCompositionUpdate Publisher
- * @param participantProvider the Participant Provider
* @param acRuntimeParameterGroup the parameters for the automation composition runtime
*/
public SupervisionScanner(final AutomationCompositionProvider automationCompositionProvider,
- AcDefinitionProvider acDefinitionProvider,
- final AutomationCompositionStateChangePublisher automationCompositionStateChangePublisher,
- AutomationCompositionDeployPublisher automationCompositionDeployPublisher,
- ParticipantProvider participantProvider,
- final AcRuntimeParameterGroup acRuntimeParameterGroup) {
+ final AcDefinitionProvider acDefinitionProvider,
+ final AutomationCompositionStateChangePublisher automationCompositionStateChangePublisher,
+ final AutomationCompositionDeployPublisher automationCompositionDeployPublisher,
+ final AcRuntimeParameterGroup acRuntimeParameterGroup) {
this.automationCompositionProvider = automationCompositionProvider;
this.acDefinitionProvider = acDefinitionProvider;
this.automationCompositionStateChangePublisher = automationCompositionStateChangePublisher;
this.automationCompositionDeployPublisher = automationCompositionDeployPublisher;
- this.participantProvider = participantProvider;
automationCompositionCounter.setMaxRetryCount(
- acRuntimeParameterGroup.getParticipantParameters().getUpdateParameters().getMaxRetryCount());
+ acRuntimeParameterGroup.getParticipantParameters().getUpdateParameters().getMaxRetryCount());
automationCompositionCounter
- .setMaxWaitMs(acRuntimeParameterGroup.getParticipantParameters().getMaxStatusWaitMs());
-
- participantStatusCounter.setMaxRetryCount(
- acRuntimeParameterGroup.getParticipantParameters().getUpdateParameters().getMaxRetryCount());
- participantStatusCounter.setMaxWaitMs(acRuntimeParameterGroup.getParticipantParameters().getMaxStatusWaitMs());
+ .setMaxWaitMs(acRuntimeParameterGroup.getParticipantParameters().getMaxStatusWaitMs());
}
/**
@@ -99,12 +87,6 @@ public class SupervisionScanner {
public void run(boolean counterCheck) {
LOGGER.debug("Scanning automation compositions in the database . . .");
- if (counterCheck) {
- for (var participant : participantProvider.getParticipants()) {
- scanParticipantStatus(participant);
- }
- }
-
var list = acDefinitionProvider.getAllAcDefinitions();
for (var acDefinition : list) {
var acList = automationCompositionProvider.getAcInstancesByCompositionId(acDefinition.getCompositionId());
@@ -116,33 +98,12 @@ public class SupervisionScanner {
LOGGER.debug("Automation composition scan complete . . .");
}
- private void scanParticipantStatus(Participant participant) {
- var id = participant.getParticipantId();
- if (participantStatusCounter.isFault(id)) {
- LOGGER.debug("report Participant fault");
- return;
- }
- if (participantStatusCounter.getDuration(id) > participantStatusCounter.getMaxWaitMs()
- && !participantStatusCounter.count(id)) {
- LOGGER.debug("report Participant fault");
- participantStatusCounter.setFault(id);
- participant.setParticipantState(ParticipantState.OFF_LINE);
- participantProvider.updateParticipant(participant);
- }
- }
-
- /**
- * handle participant Status message.
- */
- public void handleParticipantStatus(UUID id) {
- participantStatusCounter.clear(id);
- }
-
private void scanAutomationComposition(final AutomationComposition automationComposition,
- ToscaServiceTemplate toscaServiceTemplate, boolean counterCheck) {
+ ToscaServiceTemplate serviceTemplate, boolean counterCheck) {
LOGGER.debug("scanning automation composition {} . . .", automationComposition.getInstanceId());
- if (automationComposition.getState().equals(automationComposition.getOrderedState().asState())) {
+ if (!AcmUtils.isInTransitionalState(automationComposition.getDeployState(),
+ automationComposition.getLockState())) {
LOGGER.debug("automation composition {} scanned, OK", automationComposition.getInstanceId());
// Clear missed report counter on automation composition
@@ -156,12 +117,12 @@ public class SupervisionScanner {
var defaultMin = 1000; // min startPhase
var defaultMax = 0; // max startPhase
for (var element : automationComposition.getElements().values()) {
- var toscaNodeTemplate = toscaServiceTemplate.getToscaTopologyTemplate().getNodeTemplates()
- .get(element.getDefinition().getName());
+ var toscaNodeTemplate = serviceTemplate.getToscaTopologyTemplate().getNodeTemplates()
+ .get(element.getDefinition().getName());
int startPhase = ParticipantUtils.findStartPhase(toscaNodeTemplate.getProperties());
defaultMin = Math.min(defaultMin, startPhase);
defaultMax = Math.max(defaultMax, startPhase);
- if (!element.getState().equals(element.getOrderedState().asState())) {
+ if (AcmUtils.isInTransitionalState(element.getDeployState(), element.getLockState())) {
completed = false;
minSpNotCompleted = Math.min(minSpNotCompleted, startPhase);
maxSpNotCompleted = Math.max(maxSpNotCompleted, startPhase);
@@ -169,36 +130,35 @@ public class SupervisionScanner {
}
if (completed) {
- LOGGER.debug("automation composition scan: transition from state {} to {} completed",
- automationComposition.getState(), automationComposition.getOrderedState());
+ LOGGER.debug("automation composition scan: transition state {} {} ", automationComposition.getDeployState(),
+ automationComposition.getLockState());
- automationComposition.setState(automationComposition.getOrderedState().asState());
+ var deployState = automationComposition.getDeployState();
+ automationComposition.setDeployState(AcmUtils.deployCompleted(deployState));
+ automationComposition
+ .setLockState(AcmUtils.lockCompleted(deployState, automationComposition.getLockState()));
automationCompositionProvider.updateAutomationComposition(automationComposition);
// Clear missed report counter on automation composition
clearFaultAndCounter(automationComposition);
} else {
LOGGER.debug("automation composition scan: transition from state {} to {} not completed",
- automationComposition.getState(), automationComposition.getOrderedState());
+ automationComposition.getDeployState(), automationComposition.getLockState());
- var nextSpNotCompleted =
- AutomationCompositionState.UNINITIALISED2PASSIVE.equals(automationComposition.getState())
- || AutomationCompositionState.PASSIVE2RUNNING.equals(automationComposition.getState())
- ? minSpNotCompleted
- : maxSpNotCompleted;
+ var isForward =
+ AcmUtils.isForward(automationComposition.getDeployState(), automationComposition.getLockState());
- var firstStartPhase =
- AutomationCompositionState.UNINITIALISED2PASSIVE.equals(automationComposition.getState())
- || AutomationCompositionState.PASSIVE2RUNNING.equals(automationComposition.getState())
- ? defaultMin
- : defaultMax;
+ var nextSpNotCompleted = isForward ? minSpNotCompleted : maxSpNotCompleted;
+ var firstStartPhase = isForward ? defaultMin : defaultMax;
if (nextSpNotCompleted != phaseMap.getOrDefault(automationComposition.getInstanceId(), firstStartPhase)) {
phaseMap.put(automationComposition.getInstanceId(), nextSpNotCompleted);
- sendAutomationCompositionMsg(automationComposition, nextSpNotCompleted);
+ sendAutomationCompositionMsg(automationComposition, serviceTemplate, nextSpNotCompleted,
+ firstStartPhase == nextSpNotCompleted);
} else if (counterCheck) {
phaseMap.put(automationComposition.getInstanceId(), nextSpNotCompleted);
- handleCounter(automationComposition, nextSpNotCompleted);
+ handleCounter(automationComposition, serviceTemplate, nextSpNotCompleted,
+ firstStartPhase == nextSpNotCompleted);
}
}
}
@@ -208,7 +168,8 @@ public class SupervisionScanner {
phaseMap.remove(automationComposition.getInstanceId());
}
- private void handleCounter(AutomationComposition automationComposition, int startPhase) {
+ private void handleCounter(AutomationComposition automationComposition, ToscaServiceTemplate serviceTemplate,
+ int startPhase, boolean firstStartPhase) {
var instanceId = automationComposition.getInstanceId();
if (automationCompositionCounter.isFault(instanceId)) {
LOGGER.debug("report AutomationComposition fault");
@@ -218,7 +179,7 @@ public class SupervisionScanner {
if (automationCompositionCounter.getDuration(instanceId) > automationCompositionCounter.getMaxWaitMs()) {
if (automationCompositionCounter.count(instanceId)) {
phaseMap.put(instanceId, startPhase);
- sendAutomationCompositionMsg(automationComposition, startPhase);
+ sendAutomationCompositionMsg(automationComposition, serviceTemplate, startPhase, firstStartPhase);
} else {
LOGGER.debug("report AutomationComposition fault");
automationCompositionCounter.setFault(instanceId);
@@ -226,13 +187,15 @@ public class SupervisionScanner {
}
}
- private void sendAutomationCompositionMsg(AutomationComposition automationComposition, int startPhase) {
- if (AutomationCompositionState.UNINITIALISED2PASSIVE.equals(automationComposition.getState())) {
+ private void sendAutomationCompositionMsg(AutomationComposition automationComposition,
+ ToscaServiceTemplate serviceTemplate, int startPhase, boolean firstStartPhase) {
+ if (DeployState.DEPLOYING.equals(automationComposition.getDeployState())) {
LOGGER.debug("retry message AutomationCompositionUpdate");
- automationCompositionDeployPublisher.send(automationComposition, startPhase);
+ automationCompositionDeployPublisher.send(automationComposition, serviceTemplate, startPhase,
+ firstStartPhase);
} else {
LOGGER.debug("retry message AutomationCompositionStateChange");
- automationCompositionStateChangePublisher.send(automationComposition, startPhase);
+ automationCompositionStateChangePublisher.send(automationComposition, startPhase, firstStartPhase);
}
}
}
diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/AutomationCompositionDeployPublisher.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/AutomationCompositionDeployPublisher.java
index cc4a05939..2628f030d 100644
--- a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/AutomationCompositionDeployPublisher.java
+++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/AutomationCompositionDeployPublisher.java
@@ -36,7 +36,6 @@ import org.onap.policy.clamp.models.acm.concepts.AutomationComposition;
import org.onap.policy.clamp.models.acm.concepts.ParticipantDeploy;
import org.onap.policy.clamp.models.acm.messages.dmaap.participant.AutomationCompositionDeploy;
import org.onap.policy.clamp.models.acm.messages.rest.instantiation.DeployOrder;
-import org.onap.policy.clamp.models.acm.persistence.provider.AcDefinitionProvider;
import org.onap.policy.clamp.models.acm.utils.AcmUtils;
import org.onap.policy.models.base.PfUtils;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
@@ -53,53 +52,13 @@ import org.springframework.stereotype.Component;
public class AutomationCompositionDeployPublisher extends AbstractParticipantPublisher<AutomationCompositionDeploy> {
private static final Logger LOGGER = LoggerFactory.getLogger(AutomationCompositionDeployPublisher.class);
- private final AcDefinitionProvider acDefinitionProvider;
-
- /**
- * Send AutomationCompositionDeploy to Participant.
- *
- * @param automationComposition the AutomationComposition
- */
- @Timed(value = "publisher.automation_composition_deploy",
- description = "AUTOMATION_COMPOSITION_DEPLOY messages published")
- public void send(AutomationComposition automationComposition) {
- send(automationComposition, 0);
- }
-
- /**
- * Send AutomationCompositionDeploy to Participant.
- *
- * @param automationComposition the AutomationComposition
- * @param startPhase the Start Phase
- */
- @Timed(value = "publisher.automation_composition_deploy",
- description = "AUTOMATION_COMPOSITION_DEPLOY messages published")
- public void send(AutomationComposition automationComposition, int startPhase) {
- var acDeployMsg = new AutomationCompositionDeploy();
- acDeployMsg.setCompositionId(automationComposition.getCompositionId());
- acDeployMsg.setStartPhase(startPhase);
- acDeployMsg.setAutomationCompositionId(automationComposition.getInstanceId());
- acDeployMsg.setMessageId(UUID.randomUUID());
- acDeployMsg.setTimestamp(Instant.now());
- var toscaServiceTemplate =
- acDefinitionProvider.getAcDefinition(automationComposition.getCompositionId()).getServiceTemplate();
-
- List<ParticipantDeploy> participantDeploys = new ArrayList<>();
- for (var element : automationComposition.getElements().values()) {
- element.setToscaServiceTemplateFragment(AcmUtils.getToscaServiceTemplateFragment(toscaServiceTemplate));
- AcmUtils.prepareParticipantUpdate(element, participantDeploys);
- }
- acDeployMsg.setParticipantUpdatesList(participantDeploys);
-
- LOGGER.debug("AutomationCompositionDeploy message sent {}", acDeployMsg);
- super.send(acDeployMsg);
- }
/**
* Send AutomationCompositionDeploy to Participant.
*
* @param automationComposition the AutomationComposition
* @param startPhase the Start Phase
+ * @param firstStartPhase true if the first StartPhase
*/
@Timed(value = "publisher.automation_composition_deploy",
description = "AUTOMATION_COMPOSITION_DEPLOY messages published")
diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/AutomationCompositionStateChangePublisher.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/AutomationCompositionStateChangePublisher.java
index 56a62e13b..e59c2ac18 100644
--- a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/AutomationCompositionStateChangePublisher.java
+++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/AutomationCompositionStateChangePublisher.java
@@ -24,8 +24,7 @@ import io.micrometer.core.annotation.Timed;
import java.util.UUID;
import org.onap.policy.clamp.models.acm.concepts.AutomationComposition;
import org.onap.policy.clamp.models.acm.messages.dmaap.participant.AutomationCompositionStateChange;
-import org.onap.policy.clamp.models.acm.messages.rest.instantiation.DeployOrder;
-import org.onap.policy.clamp.models.acm.messages.rest.instantiation.LockOrder;
+import org.onap.policy.clamp.models.acm.utils.AcmUtils;
import org.springframework.stereotype.Component;
/**
@@ -36,7 +35,7 @@ public class AutomationCompositionStateChangePublisher
extends AbstractParticipantPublisher<AutomationCompositionStateChange> {
/**
- * Send undeploy message to to Participant.
+ * Send AutomationCompositionStateChange message to to Participant.
*
* @param automationComposition the AutomationComposition
* @param startPhase the startPhase
@@ -44,75 +43,16 @@ public class AutomationCompositionStateChangePublisher
@Timed(
value = "publisher.automation_composition_state_change",
description = "AUTOMATION_COMPOSITION_STATE_CHANGE messages published")
- public void undeploy(AutomationComposition automationComposition, int startPhase, boolean firstStartPhase) {
- send(automationComposition, startPhase, firstStartPhase, DeployOrder.UNDEPLOY, LockOrder.NONE);
- }
-
- /**
- * Send unlock message to to Participant.
- *
- * @param automationComposition the AutomationComposition
- * @param startPhase the startPhase
- */
- @Timed(
- value = "publisher.automation_composition_state_change",
- description = "AUTOMATION_COMPOSITION_STATE_CHANGE messages published")
- public void unlock(AutomationComposition automationComposition, int startPhase, boolean firstStartPhase) {
- send(automationComposition, startPhase, firstStartPhase, DeployOrder.NONE, LockOrder.UNLOCK);
- }
-
- /**
- * Send lock message to to Participant.
- *
- * @param automationComposition the AutomationComposition
- * @param startPhase the startPhase
- */
- @Timed(
- value = "publisher.automation_composition_state_change",
- description = "AUTOMATION_COMPOSITION_STATE_CHANGE messages published")
- public void lock(AutomationComposition automationComposition, int startPhase, boolean firstStartPhase) {
- send(automationComposition, startPhase, firstStartPhase, DeployOrder.NONE, LockOrder.LOCK);
- }
-
- /**
- * Send undeploy message to to Participant.
- *
- * @param automationComposition the AutomationComposition
- * @param startPhase the startPhase
- * @param deployOrder the DeployOrder
- * @param lockOrder the LockOrder
- */
- private void send(AutomationComposition automationComposition, int startPhase, boolean firstStartPhase,
- DeployOrder deployOrder, LockOrder lockOrder) {
+ public void send(AutomationComposition automationComposition, int startPhase, boolean firstStartPhase) {
var acsc = new AutomationCompositionStateChange();
acsc.setCompositionId(automationComposition.getCompositionId());
acsc.setAutomationCompositionId(automationComposition.getInstanceId());
acsc.setMessageId(UUID.randomUUID());
- acsc.setDeployOrderedState(deployOrder);
- acsc.setLockOrderedState(lockOrder);
+ acsc.setDeployOrderedState(AcmUtils.stateDeployToOrder(automationComposition.getDeployState()));
+ acsc.setLockOrderedState(AcmUtils.stateLockToOrder(automationComposition.getLockState()));
acsc.setStartPhase(startPhase);
acsc.setFirstStartPhase(firstStartPhase);
super.send(acsc);
}
-
- /**
- * Send AutomationCompositionStateChange to Participant.
- *
- * @param automationComposition the AutomationComposition
- * @param startPhase the startPhase
- */
- @Timed(
- value = "publisher.automation_composition_state_change",
- description = "AUTOMATION_COMPOSITION_STATE_CHANGE messages published")
- public void send(AutomationComposition automationComposition, int startPhase) {
- var acsc = new AutomationCompositionStateChange();
- acsc.setCompositionId(automationComposition.getCompositionId());
- acsc.setAutomationCompositionId(automationComposition.getInstanceId());
- acsc.setMessageId(UUID.randomUUID());
- acsc.setOrderedState(automationComposition.getOrderedState());
- acsc.setStartPhase(startPhase);
-
- super.send(acsc);
- }
}
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 fb285a84c..153f7a0e0 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
@@ -21,9 +21,12 @@
package org.onap.policy.clamp.acm.runtime.supervision;
import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyBoolean;
+import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Mockito.mock;
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.Map;
import java.util.Optional;
@@ -34,6 +37,7 @@ import org.onap.policy.clamp.acm.runtime.supervision.comm.AutomationCompositionD
import org.onap.policy.clamp.acm.runtime.supervision.comm.AutomationCompositionStateChangePublisher;
import org.onap.policy.clamp.acm.runtime.util.CommonTestData;
import org.onap.policy.clamp.models.acm.concepts.AcElementDeployAck;
+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.DeployState;
import org.onap.policy.clamp.models.acm.concepts.LockState;
@@ -97,4 +101,55 @@ class SupervisionAcHandlerTest {
verify(automationCompositionProvider).updateAutomationComposition(any(AutomationComposition.class));
}
+
+ @Test
+ void testUndeploy() {
+ var automationCompositionProvider = mock(AutomationCompositionProvider.class);
+ var acStateChangePublisher = mock(AutomationCompositionStateChangePublisher.class);
+ var handler = new SupervisionAcHandler(automationCompositionProvider,
+ mock(AutomationCompositionDeployPublisher.class),
+ acStateChangePublisher);
+ var serviceTemplate = InstantiationUtils.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML);
+ var acDefinition = CommonTestData.createAcDefinition(serviceTemplate, AcTypeState.PRIMED);
+ var automationComposition =
+ InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_CREATE_JSON, "Undeploy");
+ handler.undeploy(automationComposition, acDefinition);
+
+ verify(automationCompositionProvider).updateAutomationComposition(any(AutomationComposition.class));
+ verify(acStateChangePublisher).send(any(AutomationComposition.class), anyInt(), anyBoolean());
+ }
+
+ @Test
+ void testUnlock() {
+ var automationCompositionProvider = mock(AutomationCompositionProvider.class);
+ var acStateChangePublisher = mock(AutomationCompositionStateChangePublisher.class);
+ var handler = new SupervisionAcHandler(automationCompositionProvider,
+ mock(AutomationCompositionDeployPublisher.class),
+ acStateChangePublisher);
+ var serviceTemplate = InstantiationUtils.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML);
+ var acDefinition = CommonTestData.createAcDefinition(serviceTemplate, AcTypeState.PRIMED);
+ var automationComposition =
+ InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_CREATE_JSON, "UnLock");
+ handler.unlock(automationComposition, acDefinition);
+
+ verify(automationCompositionProvider).updateAutomationComposition(any(AutomationComposition.class));
+ verify(acStateChangePublisher).send(any(AutomationComposition.class), anyInt(), anyBoolean());
+ }
+
+ @Test
+ void testLock() {
+ var automationCompositionProvider = mock(AutomationCompositionProvider.class);
+ var acStateChangePublisher = mock(AutomationCompositionStateChangePublisher.class);
+ var handler = new SupervisionAcHandler(automationCompositionProvider,
+ mock(AutomationCompositionDeployPublisher.class),
+ acStateChangePublisher);
+ var serviceTemplate = InstantiationUtils.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML);
+ var acDefinition = CommonTestData.createAcDefinition(serviceTemplate, AcTypeState.PRIMED);
+ var automationComposition =
+ InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_CREATE_JSON, "Lock");
+ handler.lock(automationComposition, acDefinition);
+
+ verify(automationCompositionProvider).updateAutomationComposition(any(AutomationComposition.class));
+ verify(acStateChangePublisher).send(any(AutomationComposition.class), anyInt(), anyBoolean());
+ }
}
diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAspectTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAspectTest.java
index b913cfac9..c9985e203 100644
--- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAspectTest.java
+++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAspectTest.java
@@ -34,16 +34,19 @@ class SupervisionAspectTest {
@Test
void testSchedule() throws Exception {
var supervisionScanner = mock(SupervisionScanner.class);
- try (var supervisionAspect = new SupervisionAspect(supervisionScanner)) {
+ var partecipantScanner = mock(SupervisionPartecipantScanner.class);
+ try (var supervisionAspect = new SupervisionAspect(supervisionScanner, partecipantScanner)) {
supervisionAspect.schedule();
verify(supervisionScanner, timeout(500)).run(true);
+ verify(partecipantScanner, timeout(500)).run();
}
}
@Test
void testDoCheck() throws Exception {
var supervisionScanner = mock(SupervisionScanner.class);
- try (var supervisionAspect = new SupervisionAspect(supervisionScanner)) {
+ var partecipantScanner = mock(SupervisionPartecipantScanner.class);
+ try (var supervisionAspect = new SupervisionAspect(supervisionScanner, partecipantScanner)) {
supervisionAspect.doCheck();
supervisionAspect.doCheck();
verify(supervisionScanner, timeout(500).times(2)).run(false);
@@ -56,9 +59,10 @@ class SupervisionAspectTest {
participantStatusMessage.setParticipantId(CommonTestData.getParticipantId());
var supervisionScanner = mock(SupervisionScanner.class);
- try (var supervisionAspect = new SupervisionAspect(supervisionScanner)) {
+ var partecipantScanner = mock(SupervisionPartecipantScanner.class);
+ try (var supervisionAspect = new SupervisionAspect(supervisionScanner, partecipantScanner)) {
supervisionAspect.handleParticipantStatus(participantStatusMessage);
- verify(supervisionScanner, timeout(500)).handleParticipantStatus(CommonTestData.getParticipantId());
+ verify(partecipantScanner, timeout(500)).handleParticipantStatus(CommonTestData.getParticipantId());
}
}
}
diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionParticipantScannerTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionParticipantScannerTest.java
new file mode 100644
index 000000000..3ad9f813c
--- /dev/null
+++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionParticipantScannerTest.java
@@ -0,0 +1,58 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2023 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+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 java.util.List;
+import org.junit.jupiter.api.Test;
+import org.onap.policy.clamp.acm.runtime.util.CommonTestData;
+import org.onap.policy.clamp.models.acm.concepts.ParticipantState;
+import org.onap.policy.clamp.models.acm.persistence.provider.ParticipantProvider;
+import org.onap.policy.models.base.PfModelException;
+
+class SupervisionParticipantScannerTest {
+
+ @Test
+ void testScanParticipant() throws PfModelException {
+ var acRuntimeParameterGroup = CommonTestData.geParameterGroup("dbScanParticipant");
+ acRuntimeParameterGroup.getParticipantParameters().getUpdateParameters().setMaxWaitMs(-1);
+ acRuntimeParameterGroup.getParticipantParameters().setMaxStatusWaitMs(-1);
+
+ var participant = CommonTestData.createParticipant(CommonTestData.getParticipantId());
+ participant.setParticipantState(ParticipantState.OFF_LINE);
+ var participantProvider = mock(ParticipantProvider.class);
+ when(participantProvider.getParticipants()).thenReturn(List.of(participant));
+
+ var supervisionScanner = new SupervisionPartecipantScanner(participantProvider, acRuntimeParameterGroup);
+
+ supervisionScanner.handleParticipantStatus(participant.getParticipantId());
+ supervisionScanner.run();
+ verify(participantProvider, times(0)).saveParticipant(any());
+
+ supervisionScanner.run();
+ verify(participantProvider, times(1)).updateParticipant(any());
+ }
+}
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 fe34c6b04..032468a56 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
@@ -21,6 +21,7 @@
package org.onap.policy.clamp.acm.runtime.supervision;
import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
@@ -39,13 +40,11 @@ import org.onap.policy.clamp.acm.runtime.supervision.comm.AutomationCompositionS
import org.onap.policy.clamp.acm.runtime.util.CommonTestData;
import org.onap.policy.clamp.models.acm.concepts.AutomationComposition;
import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionDefinition;
-import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionOrderedState;
-import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionState;
-import org.onap.policy.clamp.models.acm.concepts.ParticipantState;
+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.persistence.provider.AcDefinitionProvider;
import org.onap.policy.clamp.models.acm.persistence.provider.AutomationCompositionProvider;
-import org.onap.policy.clamp.models.acm.persistence.provider.ParticipantProvider;
-import org.onap.policy.models.base.PfModelException;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
class SupervisionScannerTest {
@@ -70,16 +69,15 @@ class SupervisionScannerTest {
var automationCompositionProvider = mock(AutomationCompositionProvider.class);
var automationCompositionStateChangePublisher = mock(AutomationCompositionStateChangePublisher.class);
var automationCompositionDeployPublisher = mock(AutomationCompositionDeployPublisher.class);
- var participantProvider = mock(ParticipantProvider.class);
var acRuntimeParameterGroup = CommonTestData.geParameterGroup("dbScanner");
var automationComposition = InstantiationUtils.getAutomationCompositionFromResource(AC_JSON, "Crud");
when(automationCompositionProvider.getAcInstancesByCompositionId(compositionId))
- .thenReturn(List.of(automationComposition));
+ .thenReturn(List.of(automationComposition));
var supervisionScanner = new SupervisionScanner(automationCompositionProvider, acDefinitionProvider,
- automationCompositionStateChangePublisher, automationCompositionDeployPublisher, participantProvider,
- acRuntimeParameterGroup);
+ automationCompositionStateChangePublisher, automationCompositionDeployPublisher,
+ acRuntimeParameterGroup);
supervisionScanner.run(false);
verify(automationCompositionProvider, times(0)).updateAutomationComposition(any(AutomationComposition.class));
@@ -88,20 +86,19 @@ class SupervisionScannerTest {
@Test
void testScannerOrderedStateDifferentToState() {
var automationComposition = InstantiationUtils.getAutomationCompositionFromResource(AC_JSON, "Crud");
- automationComposition.setState(AutomationCompositionState.UNINITIALISED2PASSIVE);
- automationComposition.setOrderedState(AutomationCompositionOrderedState.UNINITIALISED);
+ automationComposition.setDeployState(DeployState.UNDEPLOYING);
+ automationComposition.setLockState(LockState.NONE);
var automationCompositionProvider = mock(AutomationCompositionProvider.class);
when(automationCompositionProvider.getAcInstancesByCompositionId(compositionId))
- .thenReturn(List.of(automationComposition));
+ .thenReturn(List.of(automationComposition));
var automationCompositionDeployPublisher = mock(AutomationCompositionDeployPublisher.class);
var automationCompositionStateChangePublisher = mock(AutomationCompositionStateChangePublisher.class);
- var participantProvider = mock(ParticipantProvider.class);
var acRuntimeParameterGroup = CommonTestData.geParameterGroup("dbScanner");
var supervisionScanner = new SupervisionScanner(automationCompositionProvider, acDefinitionProvider,
- automationCompositionStateChangePublisher, automationCompositionDeployPublisher, participantProvider,
- acRuntimeParameterGroup);
+ automationCompositionStateChangePublisher, automationCompositionDeployPublisher,
+ acRuntimeParameterGroup);
supervisionScanner.run(false);
verify(automationCompositionProvider, times(1)).updateAutomationComposition(any(AutomationComposition.class));
@@ -112,21 +109,16 @@ class SupervisionScannerTest {
var automationCompositionProvider = mock(AutomationCompositionProvider.class);
var automationComposition = new AutomationComposition();
when(automationCompositionProvider.getAcInstancesByCompositionId(compositionId))
- .thenReturn(List.of(automationComposition));
-
- var participantProvider = mock(ParticipantProvider.class);
- var participant = CommonTestData.createParticipant(CommonTestData.getParticipantId());
- when(participantProvider.getParticipants()).thenReturn(List.of(participant));
+ .thenReturn(List.of(automationComposition));
var automationCompositionDeployPublisher = mock(AutomationCompositionDeployPublisher.class);
var automationCompositionStateChangePublisher = mock(AutomationCompositionStateChangePublisher.class);
var acRuntimeParameterGroup = CommonTestData.geParameterGroup("dbScanner");
var supervisionScanner = new SupervisionScanner(automationCompositionProvider, acDefinitionProvider,
- automationCompositionStateChangePublisher, automationCompositionDeployPublisher, participantProvider,
- acRuntimeParameterGroup);
+ automationCompositionStateChangePublisher, automationCompositionDeployPublisher,
+ acRuntimeParameterGroup);
- supervisionScanner.handleParticipantStatus(participant.getParticipantId());
supervisionScanner.run(true);
verify(automationCompositionProvider, times(0)).updateAutomationComposition(any(AutomationComposition.class));
}
@@ -134,65 +126,68 @@ class SupervisionScannerTest {
@Test
void testSendAutomationCompositionMsgUpdate() {
var automationComposition = InstantiationUtils.getAutomationCompositionFromResource(AC_JSON, "Crud");
- automationComposition.setState(AutomationCompositionState.UNINITIALISED2PASSIVE);
- automationComposition.setOrderedState(AutomationCompositionOrderedState.PASSIVE);
+ automationComposition.setDeployState(DeployState.DEPLOYING);
+ automationComposition.setLockState(LockState.NONE);
for (var element : automationComposition.getElements().values()) {
if ("org.onap.domain.database.Http_PMSHMicroserviceAutomationCompositionElement"
- .equals(element.getDefinition().getName())) {
- element.setOrderedState(AutomationCompositionOrderedState.PASSIVE);
- element.setState(AutomationCompositionState.UNINITIALISED);
+ .equals(element.getDefinition().getName())) {
+ element.setDeployState(DeployState.DEPLOYING);
+ element.setLockState(LockState.NONE);
} else {
- element.setOrderedState(AutomationCompositionOrderedState.PASSIVE);
- element.setState(AutomationCompositionState.PASSIVE);
+ element.setDeployState(DeployState.DEPLOYED);
+ element.setLockState(LockState.LOCKED);
}
}
var automationCompositionProvider = mock(AutomationCompositionProvider.class);
when(automationCompositionProvider.getAcInstancesByCompositionId(compositionId))
- .thenReturn(List.of(automationComposition));
+ .thenReturn(List.of(automationComposition));
- var participantProvider = mock(ParticipantProvider.class);
var automationCompositionDeployPublisher = mock(AutomationCompositionDeployPublisher.class);
var automationCompositionStateChangePublisher = mock(AutomationCompositionStateChangePublisher.class);
var acRuntimeParameterGroup = CommonTestData.geParameterGroup("dbScanner");
var supervisionScanner = new SupervisionScanner(automationCompositionProvider, acDefinitionProvider,
- automationCompositionStateChangePublisher, automationCompositionDeployPublisher, participantProvider,
- acRuntimeParameterGroup);
+ automationCompositionStateChangePublisher, automationCompositionDeployPublisher,
+ acRuntimeParameterGroup);
supervisionScanner.run(false);
- verify(automationCompositionDeployPublisher).send(any(AutomationComposition.class), anyInt());
+ verify(automationCompositionDeployPublisher).send(any(AutomationComposition.class),
+ any(ToscaServiceTemplate.class), anyInt(), anyBoolean());
}
@Test
- void testScanParticipant() throws PfModelException {
+ void testSendAutomationCompositionMsgUnlocking() {
+ var automationComposition = InstantiationUtils.getAutomationCompositionFromResource(AC_JSON, "Crud");
+ automationComposition.setDeployState(DeployState.DEPLOYED);
+ automationComposition.setLockState(LockState.UNLOCKING);
+ for (var element : automationComposition.getElements().values()) {
+ if ("org.onap.domain.database.Http_PMSHMicroserviceAutomationCompositionElement"
+ .equals(element.getDefinition().getName())) {
+ element.setDeployState(DeployState.DEPLOYED);
+ element.setLockState(LockState.UNLOCKING);
+ } else {
+ element.setDeployState(DeployState.DEPLOYED);
+ element.setLockState(LockState.UNLOCKED);
+ }
+ }
+
var automationCompositionProvider = mock(AutomationCompositionProvider.class);
- var automationComposition = new AutomationComposition();
when(automationCompositionProvider.getAcInstancesByCompositionId(compositionId))
- .thenReturn(List.of(automationComposition));
-
- var acRuntimeParameterGroup = CommonTestData.geParameterGroup("dbScanParticipant");
- acRuntimeParameterGroup.getParticipantParameters().getUpdateParameters().setMaxWaitMs(-1);
- acRuntimeParameterGroup.getParticipantParameters().setMaxStatusWaitMs(-1);
-
- var participant = CommonTestData.createParticipant(CommonTestData.getParticipantId());
- participant.setParticipantState(ParticipantState.OFF_LINE);
- var participantProvider = mock(ParticipantProvider.class);
- when(participantProvider.getParticipants()).thenReturn(List.of(participant));
+ .thenReturn(List.of(automationComposition));
var automationCompositionDeployPublisher = mock(AutomationCompositionDeployPublisher.class);
var automationCompositionStateChangePublisher = mock(AutomationCompositionStateChangePublisher.class);
+ var acRuntimeParameterGroup = CommonTestData.geParameterGroup("dbScanner");
var supervisionScanner = new SupervisionScanner(automationCompositionProvider, acDefinitionProvider,
- automationCompositionStateChangePublisher, automationCompositionDeployPublisher, participantProvider,
- acRuntimeParameterGroup);
+ automationCompositionStateChangePublisher, automationCompositionDeployPublisher,
+ acRuntimeParameterGroup);
- supervisionScanner.handleParticipantStatus(participant.getParticipantId());
- supervisionScanner.run(true);
- verify(participantProvider, times(0)).saveParticipant(any());
+ supervisionScanner.run(false);
- supervisionScanner.run(true);
- verify(participantProvider, times(1)).updateParticipant(any());
+ verify(automationCompositionStateChangePublisher).send(any(AutomationComposition.class), anyInt(),
+ anyBoolean());
}
}
diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/comm/SupervisionMessagesTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/comm/SupervisionMessagesTest.java
index 0072a1042..e0accc4a0 100644
--- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/comm/SupervisionMessagesTest.java
+++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/comm/SupervisionMessagesTest.java
@@ -42,7 +42,8 @@ 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.AutomationComposition;
import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionDefinition;
-import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionState;
+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.messages.dmaap.participant.AutomationCompositionDeployAck;
import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantDeregister;
import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantDeregisterAck;
@@ -117,14 +118,15 @@ class SupervisionMessagesTest {
@Test
void testSendAutomationCompositionStateChangePublisherNotActive() {
var publisher = new AutomationCompositionStateChangePublisher();
- assertThatThrownBy(() -> publisher.send(getAutomationComposition(), 0)).hasMessage(NOT_ACTIVE);
+ assertThatThrownBy(() -> publisher.send(getAutomationComposition(), 0, true)).hasMessage(NOT_ACTIVE);
}
private AutomationComposition getAutomationComposition() {
var automationComposition = new AutomationComposition();
automationComposition.setName("NAME");
automationComposition.setVersion("0.0.1");
- automationComposition.setState(AutomationCompositionState.UNINITIALISED);
+ automationComposition.setDeployState(DeployState.DEPLOYED);
+ automationComposition.setLockState(LockState.UNLOCKING);
return automationComposition;
}
@@ -133,7 +135,7 @@ class SupervisionMessagesTest {
var publisher = new AutomationCompositionStateChangePublisher();
var topicSink = mock(TopicSink.class);
publisher.active(List.of(topicSink));
- publisher.send(getAutomationComposition(), 0);
+ publisher.send(getAutomationComposition(), 0, true);
verify(topicSink).send(anyString());
publisher.stop();
}
@@ -152,12 +154,12 @@ class SupervisionMessagesTest {
var participantId = UUID.randomUUID();
Map<ToscaConceptIdentifier, UUID> supportedElementMap = new HashMap<>();
supportedElementMap.put(
- new ToscaConceptIdentifier("org.onap.policy.clamp.acm.PolicyAutomationCompositionElement", "1.0.1"),
+ new ToscaConceptIdentifier("org.onap.policy.clamp.acm.PolicyAutomationCompositionElement", "1.0.0"),
participantId);
supportedElementMap.put(new ToscaConceptIdentifier(
- "org.onap.policy.clamp.acm.K8SMicroserviceAutomationCompositionElement", "1.0.1"), participantId);
+ "org.onap.policy.clamp.acm.K8SMicroserviceAutomationCompositionElement", "1.0.0"), participantId);
supportedElementMap.put(
- new ToscaConceptIdentifier("org.onap.policy.clamp.acm.HttpAutomationCompositionElement", "1.0.1"),
+ new ToscaConceptIdentifier("org.onap.policy.clamp.acm.HttpAutomationCompositionElement", "1.0.0"),
participantId);
var participantProvider = mock(ParticipantProvider.class);
when(participantProvider.getSupportedElementMap()).thenReturn(supportedElementMap);