aboutsummaryrefslogtreecommitdiffstats
path: root/participant
diff options
context:
space:
mode:
authorFrancescoFioraEst <francesco.fiora@est.tech>2023-05-16 15:24:54 +0100
committerFrancesco Fiora <francesco.fiora@est.tech>2023-05-17 09:32:57 +0000
commitdb6eb3fc07398e31dfa664992117f33fa8489cec (patch)
treef492919cd5b1c2973e91b4866e49e1deb36f524b /participant
parent722523f568a682f1e48f6998c24c945802fec782 (diff)
Add extend instance deletion support in ACM
Extend the functionality of deletion step to also inform the participant of instance deletion. This allow the participant to take any necessary steps that might result from instance deletion. Issue-ID: POLICY-4686 Change-Id: Ibeb44d472da20ad98dafa9ddd7ded28398f4ed10 Signed-off-by: FrancescoFioraEst <francesco.fiora@est.tech>
Diffstat (limited to 'participant')
-rw-r--r--participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/AutomationCompositionElementListener.java5
-rw-r--r--participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/ParticipantIntermediaryApi.java8
-rw-r--r--participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/impl/ParticipantIntermediaryApiImpl.java7
-rw-r--r--participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/handler/AutomationCompositionHandler.java76
4 files changed, 64 insertions, 32 deletions
diff --git a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/AutomationCompositionElementListener.java b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/AutomationCompositionElementListener.java
index 23390699a..d6ef80fbe 100644
--- a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/AutomationCompositionElementListener.java
+++ b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/AutomationCompositionElementListener.java
@@ -57,4 +57,9 @@ public interface AutomationCompositionElementListener {
throws PfModelException {
// default Unlock Operation
}
+
+ public default void delete(UUID automationCompositionId, UUID automationCompositionElementId)
+ throws PfModelException {
+ // default Delete Operation
+ }
}
diff --git a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/ParticipantIntermediaryApi.java b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/ParticipantIntermediaryApi.java
index 509b6ed6e..f35572769 100644
--- a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/ParticipantIntermediaryApi.java
+++ b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/ParticipantIntermediaryApi.java
@@ -23,6 +23,7 @@ package org.onap.policy.clamp.acm.participant.intermediary.api;
import java.util.Map;
import java.util.UUID;
+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;
@@ -52,6 +53,13 @@ public interface ParticipantIntermediaryApi {
LockState lockState, String message);
/**
+ * Get AutomationCompositions.
+ *
+ * @return get all AutomationCompositions
+ */
+ Map<UUID, AutomationComposition> getAutomationCompositions();
+
+ /**
* Send Automation Composition Element update Info to AC-runtime.
*
* @param automationCompositionId the ID of the automation composition to update the states
diff --git a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/impl/ParticipantIntermediaryApiImpl.java b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/impl/ParticipantIntermediaryApiImpl.java
index 20f222ab3..69fd9f3e8 100644
--- a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/impl/ParticipantIntermediaryApiImpl.java
+++ b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/impl/ParticipantIntermediaryApiImpl.java
@@ -26,8 +26,10 @@ import java.util.UUID;
import org.onap.policy.clamp.acm.participant.intermediary.api.AutomationCompositionElementListener;
import org.onap.policy.clamp.acm.participant.intermediary.api.ParticipantIntermediaryApi;
import org.onap.policy.clamp.acm.participant.intermediary.handler.AutomationCompositionHandler;
+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.models.base.PfUtils;
import org.springframework.stereotype.Component;
/**
@@ -67,4 +69,9 @@ public class ParticipantIntermediaryApiImpl implements ParticipantIntermediaryAp
automationCompositionHandler.sendAcElementInfo(automationCompositionId, elementId, useState, operationalState,
statusProperties);
}
+
+ @Override
+ public Map<UUID, AutomationComposition> getAutomationCompositions() {
+ return PfUtils.mapMap(automationCompositionHandler.getAutomationCompositionMap(), AutomationComposition::new);
+ }
}
diff --git a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/handler/AutomationCompositionHandler.java b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/handler/AutomationCompositionHandler.java
index e35582058..26ec1462c 100644
--- a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/handler/AutomationCompositionHandler.java
+++ b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/handler/AutomationCompositionHandler.java
@@ -129,13 +129,14 @@ public class AutomationCompositionHandler {
if (deployState != null) {
element.setDeployState(deployState);
+ element.setLockState(
+ DeployState.DEPLOYED.equals(element.getDeployState()) ? LockState.LOCKED : LockState.NONE);
var checkOpt = automationComposition.getElements().values().stream()
.filter(acElement -> !deployState.equals(acElement.getDeployState())).findAny();
if (checkOpt.isEmpty()) {
automationComposition.setDeployState(deployState);
+ automationComposition.setLockState(element.getLockState());
}
- element.setLockState(
- DeployState.DEPLOYED.equals(element.getDeployState()) ? LockState.LOCKED : LockState.NONE);
}
if (lockState != null) {
element.setLockState(lockState);
@@ -191,14 +192,8 @@ public class AutomationCompositionHandler {
if (!checkConsistantOrderState(automationComposition, stateChangeMsg.getDeployOrderedState(),
stateChangeMsg.getLockOrderedState())) {
- var automationCompositionAck =
- new AutomationCompositionDeployAck(ParticipantMessageType.AUTOMATION_COMPOSITION_STATECHANGE_ACK);
- automationCompositionAck.setParticipantId(participantId);
- automationCompositionAck.setMessage("Automation composition is already in state "
- + stateChangeMsg.getDeployOrderedState() + " and " + stateChangeMsg.getLockOrderedState());
- automationCompositionAck.setResult(false);
- automationCompositionAck.setAutomationCompositionId(automationComposition.getInstanceId());
- publisher.sendAutomationCompositionAck(automationCompositionAck);
+ LOGGER.warn("Not Consistant OrderState Automation composition {}",
+ stateChangeMsg.getAutomationCompositionId());
return;
}
@@ -228,10 +223,17 @@ public class AutomationCompositionHandler {
private void handleDeployOrderState(final AutomationComposition automationComposition, DeployOrder orderedState,
Integer startPhaseMsg, List<AutomationCompositionElementDefinition> acElementDefinitions) {
- if (DeployOrder.UNDEPLOY.equals(orderedState)) {
- handleUndeployState(automationComposition, startPhaseMsg, acElementDefinitions);
- } else {
- LOGGER.debug("StateChange message has no state, state is null {}", automationComposition.getKey());
+ switch (orderedState) {
+ case UNDEPLOY:
+ handleUndeployState(automationComposition, startPhaseMsg, acElementDefinitions);
+ break;
+ case DELETE:
+ handleDeleteState(automationComposition, startPhaseMsg, acElementDefinitions);
+ break;
+
+ default:
+ LOGGER.debug("StateChange message has no state, state is null {}", automationComposition.getKey());
+ break;
}
}
@@ -287,23 +289,7 @@ public class AutomationCompositionHandler {
}
private void initializeDeploy(UUID messageId, UUID instanceId, ParticipantDeploy participantDeploy) {
- var automationComposition = automationCompositionMap.get(instanceId);
-
- if (automationComposition != null) {
- var automationCompositionUpdateAck =
- new AutomationCompositionDeployAck(ParticipantMessageType.AUTOMATION_COMPOSITION_DEPLOY_ACK);
- automationCompositionUpdateAck.setParticipantId(participantId);
-
- automationCompositionUpdateAck.setMessage(
- "Automation composition " + instanceId + " already defined on participant " + participantId);
- automationCompositionUpdateAck.setResult(false);
- automationCompositionUpdateAck.setResponseTo(messageId);
- automationCompositionUpdateAck.setAutomationCompositionId(instanceId);
- publisher.sendAutomationCompositionAck(automationCompositionUpdateAck);
- return;
- }
-
- automationComposition = new AutomationComposition();
+ var automationComposition = new AutomationComposition();
automationComposition.setInstanceId(instanceId);
var acElements = storeElementsOnThisParticipant(participantDeploy);
automationComposition.setElements(prepareAcElementMap(acElements));
@@ -379,9 +365,17 @@ public class AutomationCompositionHandler {
automationComposition.getElements().values().stream()
.forEach(acElement -> automationCompositionElementUndeploy(automationComposition.getInstanceId(),
acElement, startPhaseMsg, acElementDefinitions));
+ }
+
+ private void handleDeleteState(final AutomationComposition automationComposition, Integer startPhaseMsg,
+ List<AutomationCompositionElementDefinition> acElementDefinitions) {
+
+ automationComposition.getElements().values().stream()
+ .forEach(acElement -> automationCompositionElementDelete(automationComposition.getInstanceId(),
+ acElement, startPhaseMsg, acElementDefinitions));
boolean isAllUninitialised = automationComposition.getElements().values().stream()
- .filter(element -> !DeployState.UNDEPLOYED.equals(element.getDeployState())).findAny().isEmpty();
+ .filter(element -> !DeployState.DELETED.equals(element.getDeployState())).findAny().isEmpty();
if (isAllUninitialised) {
automationCompositionMap.remove(automationComposition.getInstanceId());
}
@@ -464,6 +458,24 @@ public class AutomationCompositionHandler {
}
}
+ private void automationCompositionElementDelete(UUID instanceId, AutomationCompositionElement acElement,
+ Integer startPhaseMsg, List<AutomationCompositionElementDefinition> acElementDefinitions) {
+ var acElementNodeTemplate = getAcElementNodeTemplate(acElementDefinitions, acElement.getDefinition());
+ if (acElementNodeTemplate != null) {
+ int startPhase = ParticipantUtils.findStartPhase(acElementNodeTemplate.getProperties());
+ if (startPhaseMsg.equals(startPhase)) {
+ for (var acElementListener : listeners) {
+ try {
+ acElementListener.delete(instanceId, acElement.getId());
+ updateAutomationCompositionElementState(instanceId, acElement.getId(), DeployState.DELETED,
+ null, "Deleted");
+ } catch (PfModelException e) {
+ LOGGER.error("Automation composition element unlock failed {}", instanceId);
+ }
+ }
+ }
+ }
+ }
/**
* Undeploy Instance Elements On Participant.