summaryrefslogtreecommitdiffstats
path: root/runtime-acm/src/main
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/main
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/main')
-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
7 files changed, 304 insertions, 237 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;
}