summaryrefslogtreecommitdiffstats
path: root/runtime-acm/src
diff options
context:
space:
mode:
authorFrancescoFioraEst <francesco.fiora@est.tech>2023-02-07 11:06:01 +0000
committerFrancescoFioraEst <francesco.fiora@est.tech>2023-02-08 11:43:43 +0000
commitc1fce9211058bf91b40415022a819d3b410f711e (patch)
tree17dfdfd8e6f3df63c886c406b091becd727f29e0 /runtime-acm/src
parentf15329432ee82d48d7ead388ba1866ebbba8efd8 (diff)
Implement AC Element Instance Locking and Unlocking on ACM-R
Issue-ID: POLICY-4509 Change-Id: I8bca27cfa2a417314a27e2bec3938b538f05e346 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/instantiation/AutomationCompositionInstantiationProvider.java10
-rw-r--r--runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAcHandler.java171
-rw-r--r--runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionHandler.java224
-rw-r--r--runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/AutomationCompositionDeployPublisher.java52
-rw-r--r--runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/AutomationCompositionStateChangeAckListener.java8
-rw-r--r--runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/AutomationCompositionStateChangePublisher.java68
-rw-r--r--runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/AutomationCompositionUpdateAckListener.java8
-rw-r--r--runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProviderTest.java12
-rw-r--r--runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/InstantiationUtils.java18
-rw-r--r--runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAcHandlerTest.java100
-rw-r--r--runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionHandlerTest.java260
-rw-r--r--runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/comm/SupervisionMessagesTest.java5
12 files changed, 417 insertions, 519 deletions
diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProvider.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProvider.java
index 5281cb537..62a769fdb 100644
--- a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProvider.java
+++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProvider.java
@@ -26,6 +26,7 @@ import javax.validation.Valid;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
import lombok.AllArgsConstructor;
+import org.onap.policy.clamp.acm.runtime.supervision.SupervisionAcHandler;
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.AutomationCompositionState;
@@ -55,6 +56,7 @@ public class AutomationCompositionInstantiationProvider {
private final AutomationCompositionProvider automationCompositionProvider;
private final AcDefinitionProvider acDefinitionProvider;
private final AcInstanceStateResolver acInstanceStateResolver;
+ private final SupervisionAcHandler supervisionAcHandler;
/**
* Create automation composition.
@@ -233,19 +235,19 @@ public class AutomationCompositionInstantiationProvider {
automationComposition.getLockState());
switch (result) {
case "DEPLOY":
- //
+ supervisionAcHandler.deploy(automationComposition, acDefinition);
break;
case "UNDEPLOY":
- //
+ supervisionAcHandler.undeploy(automationComposition, acDefinition);
break;
case "LOCK":
- //
+ supervisionAcHandler.lock(automationComposition, acDefinition);
break;
case "UNLOCK":
- //
+ supervisionAcHandler.unlock(automationComposition, acDefinition);
break;
default:
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
new file mode 100644
index 000000000..3e79e78c1
--- /dev/null
+++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAcHandler.java
@@ -0,0 +1,171 @@
+/*-
+ * ============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 io.micrometer.core.annotation.Timed;
+import java.util.Map;
+import java.util.Set;
+import java.util.UUID;
+import lombok.AllArgsConstructor;
+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.AcElementDeployAck;
+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.DeployState;
+import org.onap.policy.clamp.models.acm.concepts.LockState;
+import org.onap.policy.clamp.models.acm.concepts.ParticipantUtils;
+import org.onap.policy.clamp.models.acm.messages.dmaap.participant.AutomationCompositionDeployAck;
+import org.onap.policy.clamp.models.acm.persistence.provider.AutomationCompositionProvider;
+import org.onap.policy.clamp.models.acm.utils.AcmUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Component;
+
+/**
+ * This class handles supervision of automation composition instances, so only one object of this type should be built
+ * at a time.
+ */
+@Component
+@AllArgsConstructor
+public class SupervisionAcHandler {
+ private static final Logger LOGGER = LoggerFactory.getLogger(SupervisionAcHandler.class);
+
+ private final AutomationCompositionProvider automationCompositionProvider;
+
+ // Publishers for participant communication
+ private final AutomationCompositionDeployPublisher automationCompositionDeployPublisher;
+ private final AutomationCompositionStateChangePublisher automationCompositionStateChangePublisher;
+
+ /**
+ * Handle Deploy an AutomationComposition instance.
+ *
+ * @param automationComposition the AutomationComposition
+ * @param acDefinition the AutomationCompositionDefinition
+ */
+ public void deploy(AutomationComposition automationComposition, AutomationCompositionDefinition acDefinition) {
+ AcmUtils.setCascadedState(automationComposition, DeployState.DEPLOYING, LockState.NONE);
+ automationCompositionProvider.updateAutomationComposition(automationComposition);
+ var startPhase = ParticipantUtils.getFirstStartPhase(automationComposition, acDefinition.getServiceTemplate());
+ automationCompositionDeployPublisher.send(automationComposition, acDefinition.getServiceTemplate(), startPhase,
+ true);
+ }
+
+ /**
+ * Handle Undeploy an AutomationComposition instance.
+ *
+ * @param automationComposition the AutomationComposition
+ * @param acDefinition the AutomationCompositionDefinition
+ */
+ public void undeploy(AutomationComposition automationComposition, AutomationCompositionDefinition acDefinition) {
+ AcmUtils.setCascadedState(automationComposition, DeployState.UNDEPLOYING, LockState.NONE);
+ automationCompositionProvider.updateAutomationComposition(automationComposition);
+ var startPhase = ParticipantUtils.getFirstStartPhase(automationComposition, acDefinition.getServiceTemplate());
+ automationCompositionStateChangePublisher.undeploy(automationComposition, startPhase, true);
+ }
+
+ /**
+ * Handle Unlock an AutomationComposition instance.
+ *
+ * @param automationComposition the AutomationComposition
+ * @param acDefinition the AutomationCompositionDefinition
+ */
+ public void unlock(AutomationComposition automationComposition, AutomationCompositionDefinition acDefinition) {
+ AcmUtils.setCascadedState(automationComposition, DeployState.DEPLOYED, LockState.UNLOCKING);
+ automationCompositionProvider.updateAutomationComposition(automationComposition);
+ var startPhase = ParticipantUtils.getFirstStartPhase(automationComposition, acDefinition.getServiceTemplate());
+ automationCompositionStateChangePublisher.unlock(automationComposition, startPhase, true);
+ }
+
+ /**
+ * Handle Lock an AutomationComposition instance.
+ *
+ * @param automationComposition the AutomationComposition
+ * @param acDefinition the AutomationCompositionDefinition
+ */
+ public void lock(AutomationComposition automationComposition, AutomationCompositionDefinition acDefinition) {
+ AcmUtils.setCascadedState(automationComposition, DeployState.DEPLOYED, LockState.LOCKING);
+ automationCompositionProvider.updateAutomationComposition(automationComposition);
+ var startPhase = ParticipantUtils.getFirstStartPhase(automationComposition, acDefinition.getServiceTemplate());
+ automationCompositionStateChangePublisher.lock(automationComposition, startPhase, true);
+ }
+
+ /**
+ * Handle a AutomationComposition deploy acknowledge message from a participant.
+ *
+ * @param automationCompositionAckMessage the AutomationCompositionAck message received from a participant
+ */
+ @MessageIntercept
+ @Timed(
+ value = "listener.automation_composition_deploy_ack",
+ description = "AUTOMATION_COMPOSITION_DEPLOY_ACK messages received")
+ public void handleAutomationCompositionUpdateAckMessage(
+ AutomationCompositionDeployAck automationCompositionAckMessage) {
+ LOGGER.debug("AutomationComposition Update Ack message received {}", automationCompositionAckMessage);
+ setAcElementStateInDb(automationCompositionAckMessage);
+ }
+
+ /**
+ * Handle a AutomationComposition statechange acknowledge message from a participant.
+ *
+ * @param automationCompositionAckMessage the AutomationCompositionAck message received from a participant
+ */
+ @MessageIntercept
+ @Timed(
+ value = "listener.automation_composition_statechange_ack",
+ description = "AUTOMATION_COMPOSITION_STATECHANGE_ACK messages received")
+ public void handleAutomationCompositionStateChangeAckMessage(
+ AutomationCompositionDeployAck automationCompositionAckMessage) {
+ LOGGER.debug("AutomationComposition StateChange Ack message received {}", automationCompositionAckMessage);
+ setAcElementStateInDb(automationCompositionAckMessage);
+ }
+
+ private void setAcElementStateInDb(AutomationCompositionDeployAck automationCompositionAckMessage) {
+ if (automationCompositionAckMessage.getAutomationCompositionResultMap() != null) {
+ var automationComposition = automationCompositionProvider
+ .findAutomationComposition(automationCompositionAckMessage.getAutomationCompositionId());
+ if (automationComposition.isPresent()) {
+ var updated = updateState(automationComposition.get(),
+ automationCompositionAckMessage.getAutomationCompositionResultMap().entrySet());
+ if (updated) {
+ automationCompositionProvider.updateAutomationComposition(automationComposition.get());
+ }
+ } else {
+ LOGGER.warn("AutomationComposition not found in database {}",
+ automationCompositionAckMessage.getAutomationCompositionId());
+ }
+ }
+ }
+
+ private boolean updateState(AutomationComposition automationComposition,
+ Set<Map.Entry<UUID, AcElementDeployAck>> automationCompositionResultSet) {
+ var updated = false;
+ for (var acElementAck : automationCompositionResultSet) {
+ var element = automationComposition.getElements().get(acElementAck.getKey());
+ if (element != null) {
+ element.setDeployState(acElementAck.getValue().getDeployState());
+ element.setLockState(acElementAck.getValue().getLockState());
+ updated = true;
+ }
+ }
+ 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 db726e09d..d6bae3b5b 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
@@ -22,68 +22,25 @@
package org.onap.policy.clamp.acm.runtime.supervision;
import io.micrometer.core.annotation.Timed;
-import java.util.Map;
-import java.util.Set;
-import java.util.UUID;
-import javax.ws.rs.core.Response;
import lombok.AllArgsConstructor;
-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.common.acm.exception.AutomationCompositionException;
-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.AutomationCompositionState;
-import org.onap.policy.clamp.models.acm.concepts.ParticipantUtils;
-import org.onap.policy.clamp.models.acm.messages.dmaap.participant.AutomationCompositionDeployAck;
import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantPrimeAck;
import org.onap.policy.clamp.models.acm.persistence.provider.AcDefinitionProvider;
-import org.onap.policy.clamp.models.acm.persistence.provider.AutomationCompositionProvider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
/**
- * This class handles supervision of automation composition instances, so only one object of this type should be built
+ * This class handles supervision of automation composition definition, so only one object of this type should be built
* at a time.
- *
- * <p/>
- * It is effectively a singleton that is started at system start.
*/
@Component
@AllArgsConstructor
public class SupervisionHandler {
private static final Logger LOGGER = LoggerFactory.getLogger(SupervisionHandler.class);
- private static final String AUTOMATION_COMPOSITION_CANNOT_TRANSITION_FROM_STATE =
- "Automation composition can't transition from state ";
- private static final String AUTOMATION_COMPOSITION_IS_ALREADY_IN_STATE =
- "Automation composition is already in state ";
- private static final String TO_STATE = " to state ";
- private static final String AND_TRANSITIONING_TO_STATE = " and transitioning to state ";
-
- private final AutomationCompositionProvider automationCompositionProvider;
private final AcDefinitionProvider acDefinitionProvider;
- // Publishers for participant communication
- private final AutomationCompositionDeployPublisher automationCompositionDeployPublisher;
- private final AutomationCompositionStateChangePublisher automationCompositionStateChangePublisher;
-
- /**
- * Handle a AutomationComposition update acknowledge message from a participant.
- *
- * @param automationCompositionAckMessage the AutomationCompositionAck message received from a participant
- */
- @MessageIntercept
- @Timed(
- value = "listener.automation_composition_deploy_ack",
- description = "AUTOMATION_COMPOSITION_DEPLOY_ACK messages received")
- public void handleAutomationCompositionUpdateAckMessage(
- AutomationCompositionDeployAck automationCompositionAckMessage) {
- LOGGER.debug("AutomationComposition Update Ack message received {}", automationCompositionAckMessage);
- setAcElementStateInDb(automationCompositionAckMessage);
- }
-
/**
* Handle a ParticipantPrimeAck message from a participant.
*
@@ -118,183 +75,4 @@ public class SupervisionHandler {
}
acDefinitionProvider.updateAcDefinition(acDefinition);
}
-
- /**
- * Handle a AutomationComposition statechange acknowledge message from a participant.
- *
- * @param automationCompositionAckMessage the AutomationCompositionAck message received from a participant
- */
- @MessageIntercept
- @Timed(
- value = "listener.automation_composition_statechange_ack",
- description = "AUTOMATION_COMPOSITION_STATECHANGE_ACK messages received")
- public void handleAutomationCompositionStateChangeAckMessage(
- AutomationCompositionDeployAck automationCompositionAckMessage) {
- LOGGER.debug("AutomationComposition StateChange Ack message received {}", automationCompositionAckMessage);
- setAcElementStateInDb(automationCompositionAckMessage);
- }
-
- private void setAcElementStateInDb(AutomationCompositionDeployAck automationCompositionAckMessage) {
- if (automationCompositionAckMessage.getAutomationCompositionResultMap() != null) {
- var automationComposition = automationCompositionProvider
- .findAutomationComposition(automationCompositionAckMessage.getAutomationCompositionId());
- if (automationComposition.isPresent()) {
- var updated = updateState(automationComposition.get(),
- automationCompositionAckMessage.getAutomationCompositionResultMap().entrySet());
- if (updated) {
- automationCompositionProvider.updateAutomationComposition(automationComposition.get());
- }
- } else {
- LOGGER.warn("AutomationComposition not found in database {}",
- automationCompositionAckMessage.getAutomationCompositionId());
- }
- }
- }
-
- private boolean updateState(AutomationComposition automationComposition,
- Set<Map.Entry<UUID, AcElementDeployAck>> automationCompositionResultSet) {
- var updated = false;
- for (var acElementAck : automationCompositionResultSet) {
- var element = automationComposition.getElements().get(acElementAck.getKey());
- if (element != null) {
- element.setState(acElementAck.getValue().getState());
- updated = true;
- }
- }
- return updated;
- }
-
- /**
- * Supervise a automation composition, performing whatever actions need to be performed on the automation
- * composition.
- *
- * @param automationComposition the automation composition to supervises
- * @throws AutomationCompositionException on supervision errors
- */
- public void triggerAutomationCompositionSupervision(AutomationComposition automationComposition)
- throws AutomationCompositionException {
- switch (automationComposition.getOrderedState()) {
- case UNINITIALISED:
- superviseAutomationCompositionUninitialization(automationComposition);
- break;
-
- case PASSIVE:
- superviseAutomationCompositionPassivation(automationComposition);
- break;
-
- case RUNNING:
- superviseAutomationCompositionActivation(automationComposition);
- break;
-
- default:
- exceptionOccured(Response.Status.NOT_ACCEPTABLE,
- "A automation composition cannot be commanded to go into state "
- + automationComposition.getOrderedState().name());
- }
- }
-
- /**
- * Supervise a automation composition uninitialisation, performing whatever actions need to be performed on the
- * automation composition,
- * automation composition ordered state is UNINITIALIZED.
- *
- * @param automationComposition the automation composition to supervises
- * @throws AutomationCompositionException on supervision errors
- */
- private void superviseAutomationCompositionUninitialization(AutomationComposition automationComposition)
- throws AutomationCompositionException {
- switch (automationComposition.getState()) {
- case UNINITIALISED:
- exceptionOccured(Response.Status.NOT_ACCEPTABLE,
- AUTOMATION_COMPOSITION_IS_ALREADY_IN_STATE + automationComposition.getState().name());
- break;
-
- case UNINITIALISED2PASSIVE:
- case PASSIVE:
- automationComposition.setState(AutomationCompositionState.PASSIVE2UNINITIALISED);
- automationCompositionStateChangePublisher.send(automationComposition,
- getFirstStartPhase(automationComposition));
- break;
-
- case PASSIVE2UNINITIALISED:
- exceptionOccured(Response.Status.NOT_ACCEPTABLE,
- AUTOMATION_COMPOSITION_IS_ALREADY_IN_STATE + automationComposition.getState().name()
- + AND_TRANSITIONING_TO_STATE + automationComposition.getOrderedState());
- break;
-
- default:
- exceptionOccured(Response.Status.NOT_ACCEPTABLE, AUTOMATION_COMPOSITION_CANNOT_TRANSITION_FROM_STATE
- + automationComposition.getState().name() + TO_STATE + automationComposition.getOrderedState());
- break;
- }
- }
-
- private void superviseAutomationCompositionPassivation(AutomationComposition automationComposition)
- throws AutomationCompositionException {
- switch (automationComposition.getState()) {
- case PASSIVE:
- exceptionOccured(Response.Status.NOT_ACCEPTABLE,
- AUTOMATION_COMPOSITION_IS_ALREADY_IN_STATE + automationComposition.getState().name());
- break;
- case UNINITIALISED:
- automationComposition.setState(AutomationCompositionState.UNINITIALISED2PASSIVE);
- automationCompositionDeployPublisher.send(automationComposition);
- break;
-
- case UNINITIALISED2PASSIVE:
- case RUNNING2PASSIVE:
- exceptionOccured(Response.Status.NOT_ACCEPTABLE,
- AUTOMATION_COMPOSITION_IS_ALREADY_IN_STATE + automationComposition.getState().name()
- + AND_TRANSITIONING_TO_STATE + automationComposition.getOrderedState());
- break;
-
- case RUNNING:
- automationComposition.setState(AutomationCompositionState.RUNNING2PASSIVE);
- automationCompositionStateChangePublisher.send(automationComposition,
- getFirstStartPhase(automationComposition));
- break;
-
- default:
- exceptionOccured(Response.Status.NOT_ACCEPTABLE, AUTOMATION_COMPOSITION_CANNOT_TRANSITION_FROM_STATE
- + automationComposition.getState().name() + TO_STATE + automationComposition.getOrderedState());
- break;
- }
- }
-
- private void superviseAutomationCompositionActivation(AutomationComposition automationComposition)
- throws AutomationCompositionException {
- switch (automationComposition.getState()) {
- case RUNNING:
- exceptionOccured(Response.Status.NOT_ACCEPTABLE,
- AUTOMATION_COMPOSITION_IS_ALREADY_IN_STATE + automationComposition.getState().name());
- break;
-
- case PASSIVE2RUNNING:
- exceptionOccured(Response.Status.NOT_ACCEPTABLE,
- AUTOMATION_COMPOSITION_IS_ALREADY_IN_STATE + automationComposition.getState().name()
- + AND_TRANSITIONING_TO_STATE + automationComposition.getOrderedState());
- break;
-
- case PASSIVE:
- automationComposition.setState(AutomationCompositionState.PASSIVE2RUNNING);
- automationCompositionStateChangePublisher.send(automationComposition,
- getFirstStartPhase(automationComposition));
- break;
-
- default:
- exceptionOccured(Response.Status.NOT_ACCEPTABLE, AUTOMATION_COMPOSITION_CANNOT_TRANSITION_FROM_STATE
- + automationComposition.getState().name() + TO_STATE + automationComposition.getOrderedState());
- break;
- }
- }
-
- private int getFirstStartPhase(AutomationComposition automationComposition) {
- var toscaServiceTemplate =
- acDefinitionProvider.getAcDefinition(automationComposition.getCompositionId()).getServiceTemplate();
- return ParticipantUtils.getFirstStartPhase(automationComposition, toscaServiceTemplate);
- }
-
- private void exceptionOccured(Response.Status status, String reason) throws AutomationCompositionException {
- throw new AutomationCompositionException(status, reason);
- }
}
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 0811a5a44..cc4a05939 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
@@ -25,14 +25,22 @@ package org.onap.policy.clamp.acm.runtime.supervision.comm;
import io.micrometer.core.annotation.Timed;
import java.time.Instant;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import java.util.UUID;
+import java.util.function.UnaryOperator;
import lombok.AllArgsConstructor;
+import org.onap.policy.clamp.models.acm.concepts.AcElementDeploy;
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;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
@@ -86,4 +94,48 @@ public class AutomationCompositionDeployPublisher extends AbstractParticipantPub
LOGGER.debug("AutomationCompositionDeploy message sent {}", acDeployMsg);
super.send(acDeployMsg);
}
+
+ /**
+ * 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, ToscaServiceTemplate toscaServiceTemplate,
+ int startPhase, boolean firstStartPhase) {
+ var toscaServiceTemplateFragment = AcmUtils.getToscaServiceTemplateFragment(toscaServiceTemplate);
+ Map<UUID, List<AcElementDeploy>> map = new HashMap<>();
+ for (var element : automationComposition.getElements().values()) {
+ var acElementDeploy = new AcElementDeploy();
+ acElementDeploy.setId(element.getId());
+ acElementDeploy.setDefinition(new ToscaConceptIdentifier(element.getDefinition()));
+ acElementDeploy.setOrderedState(DeployOrder.DEPLOY);
+ acElementDeploy.setProperties(PfUtils.mapMap(element.getProperties(), UnaryOperator.identity()));
+ acElementDeploy.setToscaServiceTemplateFragment(toscaServiceTemplateFragment);
+
+ map.putIfAbsent(element.getParticipantId(), new ArrayList<>());
+ map.get(element.getParticipantId()).add(acElementDeploy);
+ }
+ List<ParticipantDeploy> participantDeploys = new ArrayList<>();
+ for (var entry : map.entrySet()) {
+ var participantDeploy = new ParticipantDeploy();
+ participantDeploy.setParticipantId(entry.getKey());
+ participantDeploy.setAcElementList(entry.getValue());
+ participantDeploys.add(participantDeploy);
+ }
+
+ var acDeployMsg = new AutomationCompositionDeploy();
+ acDeployMsg.setCompositionId(automationComposition.getCompositionId());
+ acDeployMsg.setStartPhase(startPhase);
+ acDeployMsg.setFirstStartPhase(firstStartPhase);
+ acDeployMsg.setAutomationCompositionId(automationComposition.getInstanceId());
+ acDeployMsg.setMessageId(UUID.randomUUID());
+ acDeployMsg.setTimestamp(Instant.now());
+ acDeployMsg.setParticipantUpdatesList(participantDeploys);
+
+ LOGGER.debug("AutomationCompositionDeploy message sent {}", acDeployMsg);
+ super.send(acDeployMsg);
+ }
}
diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/AutomationCompositionStateChangeAckListener.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/AutomationCompositionStateChangeAckListener.java
index ed1662a95..df8e60cac 100644
--- a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/AutomationCompositionStateChangeAckListener.java
+++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/AutomationCompositionStateChangeAckListener.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2021 Nordix Foundation.
+ * Copyright (C) 2021,2023 Nordix Foundation.
* Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -22,7 +22,7 @@
package org.onap.policy.clamp.acm.runtime.supervision.comm;
import org.onap.policy.clamp.acm.runtime.config.messaging.Listener;
-import org.onap.policy.clamp.acm.runtime.supervision.SupervisionHandler;
+import org.onap.policy.clamp.acm.runtime.supervision.SupervisionAcHandler;
import org.onap.policy.clamp.models.acm.messages.dmaap.participant.AutomationCompositionDeployAck;
import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantMessageType;
import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
@@ -40,12 +40,12 @@ public class AutomationCompositionStateChangeAckListener extends ScoListener<Aut
implements Listener<AutomationCompositionDeployAck> {
private static final Logger LOGGER = LoggerFactory.getLogger(AutomationCompositionStateChangeAckListener.class);
- private final SupervisionHandler supervisionHandler;
+ private final SupervisionAcHandler supervisionHandler;
/**
* Constructs the object.
*/
- public AutomationCompositionStateChangeAckListener(SupervisionHandler supervisionHandler) {
+ public AutomationCompositionStateChangeAckListener(SupervisionAcHandler supervisionHandler) {
super(AutomationCompositionDeployAck.class);
this.supervisionHandler = supervisionHandler;
}
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 8d6378e3f..56a62e13b 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
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2021,2022 Nordix Foundation.
+ * Copyright (C) 2021-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.
@@ -24,6 +24,8 @@ 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.springframework.stereotype.Component;
/**
@@ -34,12 +36,74 @@ public class AutomationCompositionStateChangePublisher
extends AbstractParticipantPublisher<AutomationCompositionStateChange> {
/**
+ * Send undeploy 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 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) {
+ var acsc = new AutomationCompositionStateChange();
+ acsc.setCompositionId(automationComposition.getCompositionId());
+ acsc.setAutomationCompositionId(automationComposition.getInstanceId());
+ acsc.setMessageId(UUID.randomUUID());
+ acsc.setDeployOrderedState(deployOrder);
+ acsc.setLockOrderedState(lockOrder);
+ 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",
+ @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();
diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/AutomationCompositionUpdateAckListener.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/AutomationCompositionUpdateAckListener.java
index 64d1fbef1..81ecf93b4 100644
--- a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/AutomationCompositionUpdateAckListener.java
+++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/AutomationCompositionUpdateAckListener.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2021 Nordix Foundation.
+ * Copyright (C) 2021,2023 Nordix Foundation.
* Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -22,7 +22,7 @@
package org.onap.policy.clamp.acm.runtime.supervision.comm;
import org.onap.policy.clamp.acm.runtime.config.messaging.Listener;
-import org.onap.policy.clamp.acm.runtime.supervision.SupervisionHandler;
+import org.onap.policy.clamp.acm.runtime.supervision.SupervisionAcHandler;
import org.onap.policy.clamp.models.acm.messages.dmaap.participant.AutomationCompositionDeployAck;
import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantMessageType;
import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
@@ -40,12 +40,12 @@ public class AutomationCompositionUpdateAckListener extends ScoListener<Automati
implements Listener<AutomationCompositionDeployAck> {
private static final Logger LOGGER = LoggerFactory.getLogger(AutomationCompositionUpdateAckListener.class);
- private final SupervisionHandler supervisionHandler;
+ private final SupervisionAcHandler supervisionHandler;
/**
* Constructs the object.
*/
- public AutomationCompositionUpdateAckListener(SupervisionHandler supervisionHandler) {
+ public AutomationCompositionUpdateAckListener(SupervisionAcHandler supervisionHandler) {
super(AutomationCompositionDeployAck.class);
this.supervisionHandler = supervisionHandler;
}
diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProviderTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProviderTest.java
index 019d53c0b..1acaebea6 100644
--- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProviderTest.java
+++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProviderTest.java
@@ -88,7 +88,7 @@ class AutomationCompositionInstantiationProviderTest {
when(acDefinitionProvider.findAcDefinition(compositionId)).thenReturn(Optional.of(acDefinition));
var acProvider = mock(AutomationCompositionProvider.class);
var instantiationProvider =
- new AutomationCompositionInstantiationProvider(acProvider, acDefinitionProvider, null);
+ new AutomationCompositionInstantiationProvider(acProvider, acDefinitionProvider, null, null);
var automationCompositionCreate =
InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_CREATE_JSON, "Crud");
automationCompositionCreate.setCompositionId(compositionId);
@@ -140,7 +140,7 @@ class AutomationCompositionInstantiationProviderTest {
var acDefinitionProvider = mock(AcDefinitionProvider.class);
var instantiationProvider = new AutomationCompositionInstantiationProvider(acProvider,
- acDefinitionProvider, null);
+ acDefinitionProvider, null, null);
when(acProvider.getAutomationComposition(automationComposition.getInstanceId()))
.thenReturn(automationComposition);
@@ -169,7 +169,7 @@ class AutomationCompositionInstantiationProviderTest {
var acDefinitionProvider = mock(AcDefinitionProvider.class);
var instantiationProvider = new AutomationCompositionInstantiationProvider(acProvider,
- acDefinitionProvider, null);
+ acDefinitionProvider, null, null);
when(acProvider.getAutomationComposition(automationComposition.getInstanceId()))
.thenReturn(automationComposition);
@@ -197,7 +197,7 @@ class AutomationCompositionInstantiationProviderTest {
.thenReturn(automationCompositionCreate);
var instantiationProvider = new AutomationCompositionInstantiationProvider(acProvider,
- acDefinitionProvider, null);
+ acDefinitionProvider, null, null);
var instantiationResponse = instantiationProvider.createAutomationComposition(
automationCompositionCreate.getCompositionId(), automationCompositionCreate);
@@ -223,7 +223,7 @@ class AutomationCompositionInstantiationProviderTest {
var acProvider = mock(AutomationCompositionProvider.class);
var provider = new AutomationCompositionInstantiationProvider(acProvider,
- acDefinitionProvider, null);
+ acDefinitionProvider, null, null);
assertThatThrownBy(() -> provider.createAutomationComposition(compositionId, automationComposition))
.hasMessageMatching(AC_ELEMENT_NAME_NOT_FOUND);
@@ -245,7 +245,7 @@ class AutomationCompositionInstantiationProviderTest {
.thenReturn(automationComposition);
var acDefinitionProvider = mock(AcDefinitionProvider.class);
var provider = new AutomationCompositionInstantiationProvider(acProvider,
- acDefinitionProvider, null);
+ acDefinitionProvider, null, null);
var compositionId = automationComposition.getCompositionId();
assertThatThrownBy(() -> provider.createAutomationComposition(compositionId, automationComposition))
diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/InstantiationUtils.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/InstantiationUtils.java
index a5ffacc6a..534762299 100644
--- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/InstantiationUtils.java
+++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/InstantiationUtils.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2021-2022 Nordix Foundation.
+ * Copyright (C) 2021-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.
@@ -26,7 +26,6 @@ import static org.junit.jupiter.api.Assertions.fail;
import java.io.File;
import org.onap.policy.clamp.models.acm.concepts.AutomationComposition;
-import org.onap.policy.clamp.models.acm.messages.rest.instantiation.InstantiationCommand;
import org.onap.policy.clamp.models.acm.messages.rest.instantiation.InstantiationResponse;
import org.onap.policy.common.utils.coder.Coder;
import org.onap.policy.common.utils.coder.CoderException;
@@ -65,21 +64,6 @@ public class InstantiationUtils {
}
/**
- * Gets InstantiationCommand from Resource.
- *
- * @param path path of the resource
- * @return the InstantiationCommand
- */
- public static InstantiationCommand getInstantiationCommandFromResource(final String path) {
- try {
- return CODER.decode(new File(path), InstantiationCommand.class);
- } catch (CoderException e) {
- fail("Cannot read or decode " + path);
- return null;
- }
- }
-
- /**
* Assert that Instantiation Response contains proper AutomationCompositions.
*
* @param response InstantiationResponse
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
new file mode 100644
index 000000000..e16672d14
--- /dev/null
+++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAcHandlerTest.java
@@ -0,0 +1,100 @@
+/*-
+ * ============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.verify;
+import static org.mockito.Mockito.when;
+
+import java.util.Map;
+import java.util.Optional;
+import java.util.UUID;
+import org.junit.jupiter.api.Test;
+import org.onap.policy.clamp.acm.runtime.instantiation.InstantiationUtils;
+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.acm.runtime.util.CommonTestData;
+import org.onap.policy.clamp.models.acm.concepts.AcElementDeployAck;
+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;
+import org.onap.policy.clamp.models.acm.messages.dmaap.participant.AutomationCompositionDeployAck;
+import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantMessageType;
+import org.onap.policy.clamp.models.acm.persistence.provider.AutomationCompositionProvider;
+
+class SupervisionAcHandlerTest {
+ private static final String AC_INSTANTIATION_CREATE_JSON = "src/test/resources/rest/acm/AutomationComposition.json";
+ private static final UUID IDENTIFIER = UUID.randomUUID();
+
+ @Test
+ void testHandleAutomationCompositionStateChangeAckMessage() {
+ var automationCompositionProvider = mock(AutomationCompositionProvider.class);
+ var automationComposition =
+ InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_CREATE_JSON, "Crud");
+ when(automationCompositionProvider.findAutomationComposition(IDENTIFIER))
+ .thenReturn(Optional.of(automationComposition));
+
+ var handler = new SupervisionAcHandler(automationCompositionProvider,
+ mock(AutomationCompositionDeployPublisher.class),
+ mock(AutomationCompositionStateChangePublisher.class));
+
+ var automationCompositionAckMessage =
+ new AutomationCompositionDeployAck(ParticipantMessageType.AUTOMATION_COMPOSITION_STATECHANGE_ACK);
+ for (var elementEntry : automationComposition.getElements().entrySet()) {
+ var acElementDeployAck = new AcElementDeployAck(null, DeployState.DEPLOYED, LockState.UNLOCKED, true, "");
+ automationCompositionAckMessage.getAutomationCompositionResultMap().put(elementEntry.getKey(),
+ acElementDeployAck);
+ }
+ automationCompositionAckMessage.setAutomationCompositionId(IDENTIFIER);
+
+ handler.handleAutomationCompositionStateChangeAckMessage(automationCompositionAckMessage);
+
+ verify(automationCompositionProvider).updateAutomationComposition(any(AutomationComposition.class));
+ }
+
+ @Test
+ void testHandleAutomationCompositionUpdateAckMessage() {
+ var automationCompositionProvider = mock(AutomationCompositionProvider.class);
+ var automationComposition =
+ InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_CREATE_JSON, "Crud");
+ 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(null, DeployState.DEPLOYED, LockState.LOCKED, true, "");
+ automationCompositionAckMessage
+ .setAutomationCompositionResultMap(Map.of(elementEntry.getKey(), acElementDeployAck));
+ }
+ automationCompositionAckMessage.setParticipantId(CommonTestData.getParticipantId());
+ automationCompositionAckMessage.setAutomationCompositionId(IDENTIFIER);
+
+ var handler = new SupervisionAcHandler(automationCompositionProvider,
+ mock(AutomationCompositionDeployPublisher.class),
+ mock(AutomationCompositionStateChangePublisher.class));
+
+ handler.handleAutomationCompositionUpdateAckMessage(automationCompositionAckMessage);
+
+ verify(automationCompositionProvider).updateAutomationComposition(any(AutomationComposition.class));
+ }
+}
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 0fa15b62d..d4cc5e310 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
@@ -20,232 +20,22 @@
package org.onap.policy.clamp.acm.runtime.supervision;
-import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.ArgumentMatchers.eq;
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.List;
-import java.util.Map;
-import java.util.Objects;
import java.util.Optional;
-import java.util.UUID;
import org.junit.jupiter.api.Test;
-import org.mockito.Mockito;
import org.onap.policy.clamp.acm.runtime.instantiation.InstantiationUtils;
-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.acm.runtime.util.CommonTestData;
-import org.onap.policy.clamp.common.acm.exception.AutomationCompositionException;
-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.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.DeployState;
import org.onap.policy.clamp.models.acm.concepts.ParticipantState;
-import org.onap.policy.clamp.models.acm.messages.dmaap.participant.AutomationCompositionDeployAck;
-import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantMessageType;
import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantPrimeAck;
import org.onap.policy.clamp.models.acm.persistence.provider.AcDefinitionProvider;
-import org.onap.policy.clamp.models.acm.persistence.provider.AutomationCompositionProvider;
-
class SupervisionHandlerTest {
- private static final String AC_INSTANTIATION_CREATE_JSON = "src/test/resources/rest/acm/AutomationComposition.json";
- private static final UUID IDENTIFIER = UUID.randomUUID();
-
- @Test
- void testTriggerAutomationCompositionSupervision() throws AutomationCompositionException {
- var automationCompositionDeployPublisher = mock(AutomationCompositionDeployPublisher.class);
- var handler = createSupervisionHandlerForTrigger(automationCompositionDeployPublisher);
-
- var automationComposition =
- InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_CREATE_JSON, "Crud");
- automationComposition.setOrderedState(AutomationCompositionOrderedState.PASSIVE);
- automationComposition.setState(AutomationCompositionState.UNINITIALISED);
- handler.triggerAutomationCompositionSupervision(automationComposition);
-
- verify(automationCompositionDeployPublisher).send(automationComposition);
- }
-
- @Test
- void testAcUninitialisedToUninitialised() {
- var handler = createSupervisionHandlerForTrigger();
- var automationComposition =
- InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_CREATE_JSON, "Crud");
- automationComposition.setOrderedState(AutomationCompositionOrderedState.UNINITIALISED);
- automationComposition.setState(AutomationCompositionState.UNINITIALISED);
-
- assertThatThrownBy(() -> handler.triggerAutomationCompositionSupervision(automationComposition))
- .hasMessageMatching("Automation composition is already in state UNINITIALISED");
- }
-
- @Test
- void testAcUninitialisedToPassive() throws AutomationCompositionException {
- var automationComposition =
- InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_CREATE_JSON, "Crud");
- automationComposition.setOrderedState(AutomationCompositionOrderedState.UNINITIALISED);
- automationComposition.setState(AutomationCompositionState.PASSIVE);
- automationComposition.setCompositionId(UUID.randomUUID());
-
- var acDefinitionProvider = Mockito.mock(AcDefinitionProvider.class);
- var acDefinition = new AutomationCompositionDefinition();
- acDefinition.setCompositionId(automationComposition.getCompositionId());
- acDefinition.setServiceTemplate(InstantiationUtils.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML));
- when(acDefinitionProvider.getAcDefinition(automationComposition.getCompositionId())).thenReturn(acDefinition);
-
- var automationCompositionStateChangePublisher = mock(AutomationCompositionStateChangePublisher.class);
-
- var automationCompositionProvider = mock(AutomationCompositionProvider.class);
- var handler = new SupervisionHandler(automationCompositionProvider, acDefinitionProvider,
- mock(AutomationCompositionDeployPublisher.class), automationCompositionStateChangePublisher);
-
- handler.triggerAutomationCompositionSupervision(automationComposition);
-
- verify(automationCompositionStateChangePublisher).send(any(AutomationComposition.class), eq(1));
- }
-
- @Test
- void testAcPassiveToPassive() {
- var handler = createSupervisionHandlerForTrigger();
- var automationComposition =
- InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_CREATE_JSON, "Crud");
- automationComposition.setOrderedState(AutomationCompositionOrderedState.PASSIVE);
- automationComposition.setState(AutomationCompositionState.PASSIVE);
-
- assertThatThrownBy(() -> handler.triggerAutomationCompositionSupervision(automationComposition))
- .hasMessageMatching("Automation composition is already in state PASSIVE");
- }
-
- @Test
- void testAcTransitioning() {
- var handler = createSupervisionHandlerForTrigger();
- var automationComposition =
- InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_CREATE_JSON, "Crud");
- automationComposition.setOrderedState(AutomationCompositionOrderedState.UNINITIALISED);
- automationComposition.setState(AutomationCompositionState.PASSIVE2UNINITIALISED);
-
- assertThatThrownBy(() -> handler.triggerAutomationCompositionSupervision(automationComposition))
- .hasMessageMatching("Automation composition is already in state "
- + "PASSIVE2UNINITIALISED and transitioning to state UNINITIALISED");
-
- automationComposition.setOrderedState(AutomationCompositionOrderedState.PASSIVE);
- automationComposition.setState(AutomationCompositionState.UNINITIALISED2PASSIVE);
- assertThatThrownBy(() -> handler.triggerAutomationCompositionSupervision(automationComposition))
- .hasMessageMatching("Automation composition is already in state "
- + "UNINITIALISED2PASSIVE and transitioning to state PASSIVE");
-
- automationComposition.setOrderedState(AutomationCompositionOrderedState.RUNNING);
- automationComposition.setState(AutomationCompositionState.PASSIVE2RUNNING);
- assertThatThrownBy(() -> handler.triggerAutomationCompositionSupervision(automationComposition))
- .hasMessageMatching("Automation composition is already in state "
- + "PASSIVE2RUNNING and transitioning to state RUNNING");
- }
-
- @Test
- void testAcRunningToPassive() throws AutomationCompositionException {
- var automationCompositionStateChangePublisher = mock(AutomationCompositionStateChangePublisher.class);
- var handler = createSupervisionHandler(mock(AutomationCompositionProvider.class),
- mock(AutomationCompositionDeployPublisher.class), automationCompositionStateChangePublisher,
- AutomationCompositionOrderedState.PASSIVE, AutomationCompositionState.UNINITIALISED);
-
- var automationComposition =
- InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_CREATE_JSON, "Crud");
- automationComposition.setOrderedState(AutomationCompositionOrderedState.PASSIVE);
- automationComposition.setState(AutomationCompositionState.RUNNING);
-
- handler.triggerAutomationCompositionSupervision(automationComposition);
-
- verify(automationCompositionStateChangePublisher).send(any(AutomationComposition.class), eq(1));
- }
-
- @Test
- void testAcRunningToRunning() {
- var handler = createSupervisionHandlerForTrigger();
-
- var automationComposition =
- InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_CREATE_JSON, "Crud");
- automationComposition.setOrderedState(AutomationCompositionOrderedState.RUNNING);
- automationComposition.setState(AutomationCompositionState.RUNNING);
-
- assertThatThrownBy(() -> handler.triggerAutomationCompositionSupervision(automationComposition))
- .hasMessageMatching("Automation composition is already in state RUNNING");
- }
-
- @Test
- void testAcRunningToUninitialised() {
- var handler = createSupervisionHandlerForTrigger();
-
- var automationComposition =
- InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_CREATE_JSON, "Crud");
- automationComposition.setOrderedState(AutomationCompositionOrderedState.RUNNING);
- automationComposition.setState(AutomationCompositionState.UNINITIALISED);
-
- assertThatThrownBy(() -> handler.triggerAutomationCompositionSupervision(automationComposition))
- .hasMessageMatching(
- "Automation composition can't transition from state UNINITIALISED to state RUNNING");
- }
-
- @Test
- void testAcPassiveToRunning() throws AutomationCompositionException {
- var automationCompositionStateChangePublisher = mock(AutomationCompositionStateChangePublisher.class);
- var handler = createSupervisionHandler(mock(AutomationCompositionProvider.class),
- mock(AutomationCompositionDeployPublisher.class), automationCompositionStateChangePublisher,
- AutomationCompositionOrderedState.PASSIVE, AutomationCompositionState.UNINITIALISED);
-
- var automationComposition =
- InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_CREATE_JSON, "Crud");
- automationComposition.setOrderedState(AutomationCompositionOrderedState.RUNNING);
- automationComposition.setState(AutomationCompositionState.PASSIVE);
-
- handler.triggerAutomationCompositionSupervision(automationComposition);
-
- verify(automationCompositionStateChangePublisher).send(any(AutomationComposition.class), eq(0));
- }
-
- @Test
- void testHandleAutomationCompositionStateChangeAckMessage() {
- var automationCompositionProvider = mock(AutomationCompositionProvider.class);
- var handler = createSupervisionHandler(automationCompositionProvider,
- mock(AutomationCompositionDeployPublisher.class), mock(AutomationCompositionStateChangePublisher.class),
- AutomationCompositionOrderedState.PASSIVE, AutomationCompositionState.UNINITIALISED);
- var automationCompositionAckMessage =
- new AutomationCompositionDeployAck(ParticipantMessageType.AUTOMATION_COMPOSITION_STATECHANGE_ACK);
- var acElementDeployAck =
- new AcElementDeployAck(AutomationCompositionState.PASSIVE, DeployState.DEPLOYED, true, "");
- automationCompositionAckMessage.setAutomationCompositionResultMap(
- Map.of(UUID.fromString("709c62b3-8918-41b9-a747-d21eb79c6c20"), acElementDeployAck));
- automationCompositionAckMessage.setAutomationCompositionId(IDENTIFIER);
-
- handler.handleAutomationCompositionStateChangeAckMessage(automationCompositionAckMessage);
-
- verify(automationCompositionProvider).updateAutomationComposition(any(AutomationComposition.class));
- }
-
- @Test
- void testHandleAutomationCompositionUpdateAckMessage() {
- var automationCompositionAckMessage =
- new AutomationCompositionDeployAck(ParticipantMessageType.AUTOMATION_COMPOSITION_DEPLOY_ACK);
- automationCompositionAckMessage.setParticipantId(CommonTestData.getParticipantId());
- var acElementDeployAck =
- new AcElementDeployAck(AutomationCompositionState.PASSIVE, DeployState.DEPLOYED, true, "");
- automationCompositionAckMessage.setAutomationCompositionResultMap(
- Map.of(UUID.fromString("709c62b3-8918-41b9-a747-d21eb79c6c20"), acElementDeployAck));
- automationCompositionAckMessage.setAutomationCompositionId(IDENTIFIER);
- var automationCompositionProvider = mock(AutomationCompositionProvider.class);
- var handler = createSupervisionHandler(automationCompositionProvider,
- mock(AutomationCompositionDeployPublisher.class), mock(AutomationCompositionStateChangePublisher.class),
- AutomationCompositionOrderedState.PASSIVE, AutomationCompositionState.UNINITIALISED);
-
- handler.handleAutomationCompositionUpdateAckMessage(automationCompositionAckMessage);
-
- verify(automationCompositionProvider).updateAutomationComposition(any(AutomationComposition.class));
- }
@Test
void testParticipantPrimeAckNotFound() {
@@ -253,9 +43,7 @@ class SupervisionHandlerTest {
participantPrimeAckMessage.setParticipantId(CommonTestData.getParticipantId());
participantPrimeAckMessage.setState(ParticipantState.ON_LINE);
var acDefinitionProvider = mock(AcDefinitionProvider.class);
- var handler = new SupervisionHandler(mock(AutomationCompositionProvider.class), acDefinitionProvider,
- mock(AutomationCompositionDeployPublisher.class),
- mock(AutomationCompositionStateChangePublisher.class));
+ var handler = new SupervisionHandler(acDefinitionProvider);
handler.handleParticipantMessage(participantPrimeAckMessage);
verify(acDefinitionProvider).findAcDefinition(any());
@@ -275,9 +63,7 @@ class SupervisionHandlerTest {
when(acDefinitionProvider.findAcDefinition(acDefinition.getCompositionId()))
.thenReturn(Optional.of(acDefinition));
- var handler = new SupervisionHandler(mock(AutomationCompositionProvider.class), acDefinitionProvider,
- mock(AutomationCompositionDeployPublisher.class),
- mock(AutomationCompositionStateChangePublisher.class));
+ var handler = new SupervisionHandler(acDefinitionProvider);
handler.handleParticipantMessage(participantPrimeAckMessage);
verify(acDefinitionProvider).findAcDefinition(any());
@@ -297,50 +83,10 @@ class SupervisionHandlerTest {
when(acDefinitionProvider.findAcDefinition(acDefinition.getCompositionId()))
.thenReturn(Optional.of(acDefinition));
- var handler = new SupervisionHandler(mock(AutomationCompositionProvider.class), acDefinitionProvider,
- mock(AutomationCompositionDeployPublisher.class),
- mock(AutomationCompositionStateChangePublisher.class));
+ var handler = new SupervisionHandler(acDefinitionProvider);
handler.handleParticipantMessage(participantPrimeAckMessage);
verify(acDefinitionProvider).findAcDefinition(any());
verify(acDefinitionProvider).updateAcDefinition(any());
}
-
- private SupervisionHandler createSupervisionHandler(AutomationCompositionProvider automationCompositionProvider,
- AutomationCompositionDeployPublisher automationCompositionDeployPublisher,
- AutomationCompositionStateChangePublisher automationCompositionStateChangePublisher,
- AutomationCompositionOrderedState orderedState, AutomationCompositionState state) {
- var automationComposition =
- InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_CREATE_JSON, "Crud");
-
- automationComposition.setOrderedState(orderedState);
- automationComposition.setState(state);
- when(automationCompositionProvider.findAutomationComposition(IDENTIFIER))
- .thenReturn(Optional.of(automationComposition));
-
- var acDefinitionProvider = Mockito.mock(AcDefinitionProvider.class);
- when(acDefinitionProvider.getServiceTemplateList(any(), any())).thenReturn(List
- .of(Objects.requireNonNull(InstantiationUtils.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML))));
-
- var acDefinition = new AutomationCompositionDefinition();
- acDefinition.setCompositionId(automationComposition.getCompositionId());
- acDefinition.setServiceTemplate(InstantiationUtils.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML));
- when(acDefinitionProvider.getAcDefinition(automationComposition.getCompositionId())).thenReturn(acDefinition);
-
- return new SupervisionHandler(automationCompositionProvider, acDefinitionProvider,
- automationCompositionDeployPublisher, automationCompositionStateChangePublisher);
- }
-
- private SupervisionHandler createSupervisionHandlerForTrigger() {
- return new SupervisionHandler(mock(AutomationCompositionProvider.class), mock(AcDefinitionProvider.class),
- mock(AutomationCompositionDeployPublisher.class),
- mock(AutomationCompositionStateChangePublisher.class));
- }
-
- private SupervisionHandler createSupervisionHandlerForTrigger(
- AutomationCompositionDeployPublisher automationCompositionDeployPublisher) {
-
- return new SupervisionHandler(mock(AutomationCompositionProvider.class), mock(AcDefinitionProvider.class),
- automationCompositionDeployPublisher, mock(AutomationCompositionStateChangePublisher.class));
- }
}
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 c2d4e0ff7..0072a1042 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
@@ -35,6 +35,7 @@ import java.util.Map;
import java.util.UUID;
import org.junit.jupiter.api.Test;
import org.onap.policy.clamp.acm.runtime.instantiation.InstantiationUtils;
+import org.onap.policy.clamp.acm.runtime.supervision.SupervisionAcHandler;
import org.onap.policy.clamp.acm.runtime.supervision.SupervisionHandler;
import org.onap.policy.clamp.acm.runtime.supervision.SupervisionParticipantHandler;
import org.onap.policy.clamp.acm.runtime.util.CommonTestData;
@@ -225,7 +226,7 @@ class SupervisionMessagesTest {
void testAutomationCompositionUpdateAckListener() {
final var automationCompositionAck =
new AutomationCompositionDeployAck(ParticipantMessageType.AUTOMATION_COMPOSITION_DEPLOY);
- var supervisionHandler = mock(SupervisionHandler.class);
+ var supervisionHandler = mock(SupervisionAcHandler.class);
var acUpdateAckListener = new AutomationCompositionUpdateAckListener(supervisionHandler);
acUpdateAckListener.onTopicEvent(INFRA, TOPIC, null, automationCompositionAck);
verify(supervisionHandler).handleAutomationCompositionUpdateAckMessage(automationCompositionAck);
@@ -235,7 +236,7 @@ class SupervisionMessagesTest {
void testAutomationCompositionStateChangeAckListener() {
final var automationCompositionAck =
new AutomationCompositionDeployAck(ParticipantMessageType.AUTOMATION_COMPOSITION_STATE_CHANGE);
- var supervisionHandler = mock(SupervisionHandler.class);
+ var supervisionHandler = mock(SupervisionAcHandler.class);
var acStateChangeAckListener = new AutomationCompositionStateChangeAckListener(supervisionHandler);
acStateChangeAckListener.onTopicEvent(INFRA, TOPIC, null, automationCompositionAck);
verify(supervisionHandler).handleAutomationCompositionStateChangeAckMessage(automationCompositionAck);