aboutsummaryrefslogtreecommitdiffstats
path: root/runtime-acm/src/main
diff options
context:
space:
mode:
authorrameshiyer27 <ramesh.murugan.iyer@est.tech>2023-06-28 10:57:33 +0100
committerAdheli Tavares <adheli.tavares@est.tech>2023-07-05 09:18:01 +0000
commitfdd9179e8713e68916a16ea949b1125a358b560e (patch)
tree9c37560677ae9689b5b207d32c46a067a2d49f88 /runtime-acm/src/main
parent85751a7d52cc6efbea69c08f71f550ae32c61043 (diff)
Add validation for Participant availability
Validation added to check if the participant is online before executing all the ACM operations Issue-ID: POLICY-4746 Signed-off-by: zrrmmua <ramesh.murugan.iyer@est.tech> Change-Id: Ibbdb299822e5fc6462db9688a3ec853076b1e7e9
Diffstat (limited to 'runtime-acm/src/main')
-rw-r--r--runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/commissioning/CommissioningProvider.java11
-rw-r--r--runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProvider.java24
-rw-r--r--runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/rest/InstantiationController.java2
-rw-r--r--runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/participants/AcmParticipantProvider.java19
-rw-r--r--runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/AutomationCompositionStateChangePublisher.java2
-rw-r--r--runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/ParticipantPrimePublisher.java14
6 files changed, 65 insertions, 7 deletions
diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/commissioning/CommissioningProvider.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/commissioning/CommissioningProvider.java
index 141207651..c79e31726 100644
--- a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/commissioning/CommissioningProvider.java
+++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/commissioning/CommissioningProvider.java
@@ -21,12 +21,14 @@
package org.onap.policy.clamp.acm.runtime.commissioning;
+import java.util.HashSet;
import java.util.UUID;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.stream.Collectors;
import javax.ws.rs.core.Response.Status;
import lombok.RequiredArgsConstructor;
+import org.onap.policy.clamp.acm.runtime.participants.AcmParticipantProvider;
import org.onap.policy.clamp.acm.runtime.supervision.comm.ParticipantPrimePublisher;
import org.onap.policy.clamp.models.acm.concepts.AcTypeState;
import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionDefinition;
@@ -54,6 +56,7 @@ public class CommissioningProvider {
private final AcDefinitionProvider acDefinitionProvider;
private final AutomationCompositionProvider acProvider;
+ private final AcmParticipantProvider acmParticipantProvider;
private final AcTypeStateResolver acTypeStateResolver;
private final ParticipantPrimePublisher participantPrimePublisher;
@@ -209,11 +212,17 @@ public class CommissioningProvider {
private void deprime(AutomationCompositionDefinition acmDefinition) {
acmDefinition.setStateChangeResult(StateChangeResult.NO_ERROR);
+ var participantIds = new HashSet<UUID>();
for (var elementState : acmDefinition.getElementStateMap().values()) {
- if (elementState.getParticipantId() != null) {
+ var participantId = elementState.getParticipantId();
+ if (participantId != null) {
elementState.setState(AcTypeState.DEPRIMING);
+ participantIds.add(participantId);
}
}
+ if (! participantIds.isEmpty()) {
+ acmParticipantProvider.verifyParticipantState(participantIds);
+ }
acmDefinition.setState(AcTypeState.DEPRIMING);
acDefinitionProvider.updateAcDefinition(acmDefinition);
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 eb0c9b7d2..ab3b00d6d 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
@@ -22,16 +22,19 @@
package org.onap.policy.clamp.acm.runtime.instantiation;
import java.util.UUID;
+import java.util.stream.Collectors;
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.participants.AcmParticipantProvider;
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.AutomationCompositions;
import org.onap.policy.clamp.models.acm.concepts.DeployState;
import org.onap.policy.clamp.models.acm.concepts.LockState;
+import org.onap.policy.clamp.models.acm.concepts.NodeTemplateState;
import org.onap.policy.clamp.models.acm.messages.rest.instantiation.AcInstanceStateUpdate;
import org.onap.policy.clamp.models.acm.messages.rest.instantiation.InstantiationResponse;
import org.onap.policy.clamp.models.acm.persistence.provider.AcDefinitionProvider;
@@ -58,6 +61,7 @@ public class AutomationCompositionInstantiationProvider {
private final AcDefinitionProvider acDefinitionProvider;
private final AcInstanceStateResolver acInstanceStateResolver;
private final SupervisionAcHandler supervisionAcHandler;
+ private final AcmParticipantProvider acmParticipantProvider;
/**
* Create automation composition.
@@ -187,6 +191,11 @@ public class AutomationCompositionInstantiationProvider {
ValidationStatus.INVALID, "Commissioned automation composition definition not primed"));
return result;
}
+ var participantIds = acDefinitionOpt.get().getElementStateMap().values().stream()
+ .map(NodeTemplateState::getParticipantId).collect(Collectors.toSet());
+
+ acmParticipantProvider.verifyParticipantState(participantIds);
+
result.addResult(AcmUtils.validateAutomationComposition(automationComposition,
acDefinitionOpt.get().getServiceTemplate()));
@@ -236,9 +245,15 @@ public class AutomationCompositionInstantiationProvider {
throw new PfModelRuntimeException(Response.Status.BAD_REQUEST,
"Automation composition state is still " + automationComposition.getDeployState());
}
- var response = new InstantiationResponse();
- var acDefinition = acDefinitionProvider.getAcDefinition(automationComposition.getCompositionId());
+ var acDefinition = acDefinitionProvider
+ .getAcDefinition(automationComposition.getCompositionId());
+ if (acDefinition != null) {
+ var participantIds = acDefinition.getElementStateMap().values().stream()
+ .map(NodeTemplateState::getParticipantId).collect(Collectors.toSet());
+ acmParticipantProvider.verifyParticipantState(participantIds);
+ }
supervisionAcHandler.delete(automationComposition, acDefinition);
+ var response = new InstantiationResponse();
response.setInstanceId(automationComposition.getInstanceId());
response.setAffectedAutomationComposition(automationComposition.getKey().asIdentifier());
return response;
@@ -275,6 +290,11 @@ public class AutomationCompositionInstantiationProvider {
automationComposition.getCompositionId() + DO_NOT_MATCH + compositionId);
}
var acDefinition = acDefinitionProvider.getAcDefinition(automationComposition.getCompositionId());
+
+ var participantIds = acDefinition.getElementStateMap().values().stream()
+ .map(NodeTemplateState::getParticipantId).collect(Collectors.toSet());
+
+ acmParticipantProvider.verifyParticipantState(participantIds);
var result = acInstanceStateResolver.resolve(acInstanceStateUpdate.getDeployOrder(),
acInstanceStateUpdate.getLockOrder(), automationComposition.getDeployState(),
automationComposition.getLockState(), automationComposition.getStateChangeResult());
diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/rest/InstantiationController.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/rest/InstantiationController.java
index 1a34b37e8..931b47517 100644
--- a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/rest/InstantiationController.java
+++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/rest/InstantiationController.java
@@ -99,7 +99,7 @@ public class InstantiationController extends AbstractRestController implements A
}
/**
- * Deletes a automation composition definition.
+ * Deletes an automation composition.
*
* @param compositionId The UUID of the automation composition definition
* @param instanceId The UUID of the automation composition instance
diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/participants/AcmParticipantProvider.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/participants/AcmParticipantProvider.java
index d0fcdd936..670ae5301 100644
--- a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/participants/AcmParticipantProvider.java
+++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/participants/AcmParticipantProvider.java
@@ -24,7 +24,9 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.Set;
import java.util.UUID;
+import javax.ws.rs.core.Response;
import lombok.RequiredArgsConstructor;
import org.apache.commons.collections4.MapUtils;
import org.onap.policy.clamp.acm.runtime.supervision.comm.ParticipantStatusReqPublisher;
@@ -33,6 +35,7 @@ import org.onap.policy.clamp.models.acm.concepts.NodeTemplateState;
import org.onap.policy.clamp.models.acm.concepts.ParticipantInformation;
import org.onap.policy.clamp.models.acm.concepts.ParticipantState;
import org.onap.policy.clamp.models.acm.persistence.provider.ParticipantProvider;
+import org.onap.policy.models.base.PfModelRuntimeException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
@@ -107,6 +110,22 @@ public class AcmParticipantProvider {
this.participantStatusReqPublisher.send((UUID) null);
}
+ /**
+ * Verify Participant state.
+ *
+ * @param participantIds The list of UUIDs of the participants to get
+ * @throws PfModelRuntimeException in case the participant is offline
+ */
+ public void verifyParticipantState(Set<UUID> participantIds) {
+ for (UUID participantId : participantIds) {
+ var participant = this.participantProvider.getParticipantById(participantId);
+ if (! participant.getParticipantState().equals(ParticipantState.ON_LINE)) {
+ throw new PfModelRuntimeException(Response.Status.CONFLICT,
+ "Participant: " + participantId + " is OFFLINE");
+ }
+ }
+ }
+
private Map<UUID, AutomationCompositionElement> getAutomationCompositionElementsForParticipant(UUID participantId) {
var automationCompositionElements = participantProvider
.getAutomationCompositionElements(participantId);
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 e59c2ac18..86b9d47c2 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
@@ -35,7 +35,7 @@ public class AutomationCompositionStateChangePublisher
extends AbstractParticipantPublisher<AutomationCompositionStateChange> {
/**
- * Send AutomationCompositionStateChange message to to Participant.
+ * Send AutomationCompositionStateChange message to Participant.
*
* @param automationComposition the AutomationComposition
* @param startPhase the startPhase
diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/ParticipantPrimePublisher.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/ParticipantPrimePublisher.java
index 24dcc2382..539a992ff 100644
--- a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/ParticipantPrimePublisher.java
+++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/ParticipantPrimePublisher.java
@@ -25,10 +25,12 @@ package org.onap.policy.clamp.acm.runtime.supervision.comm;
import io.micrometer.core.annotation.Timed;
import java.time.Instant;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import lombok.AllArgsConstructor;
+import org.onap.policy.clamp.acm.runtime.participants.AcmParticipantProvider;
import org.onap.policy.clamp.models.acm.concepts.AcTypeState;
import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionDefinition;
import org.onap.policy.clamp.models.acm.concepts.ParticipantDefinition;
@@ -50,6 +52,7 @@ public class ParticipantPrimePublisher extends AbstractParticipantPublisher<Part
private static final Logger LOGGER = LoggerFactory.getLogger(ParticipantPrimePublisher.class);
private final ParticipantProvider participantProvider;
+ private final AcmParticipantProvider acmParticipantProvider;
/**
* Send ParticipantPrime to Participant
@@ -72,7 +75,7 @@ public class ParticipantPrimePublisher extends AbstractParticipantPublisher<Part
}
/**
- * Pepare the Priming message creating the list of ParticipantDefinition to send
+ * Prepare the Priming message creating the list of ParticipantDefinition to send
* and fill the ElementState map of the AC Definition.
*
* @param acmDefinition the AutomationComposition Definition
@@ -82,11 +85,13 @@ public class ParticipantPrimePublisher extends AbstractParticipantPublisher<Part
acmDefinition.setState(AcTypeState.PRIMING);
var acElements = AcmUtils.extractAcElementsFromServiceTemplate(acmDefinition.getServiceTemplate());
Map<ToscaConceptIdentifier, UUID> supportedElementMap = new HashMap<>();
+ var participantIds = new HashSet<UUID>();
if (AcTypeState.PRIMED.equals(acmDefinition.getState())) {
// scenario Prime again, participants already assigned
for (var elementEntry : acElements) {
var elementState = acmDefinition.getElementStateMap().get(elementEntry.getKey());
elementState.setState(AcTypeState.PRIMING);
+ participantIds.add(elementState.getParticipantId());
var type = new ToscaConceptIdentifier(elementEntry.getValue().getType(),
elementEntry.getValue().getTypeVersion());
supportedElementMap.put(type, elementState.getParticipantId());
@@ -99,9 +104,14 @@ public class ParticipantPrimePublisher extends AbstractParticipantPublisher<Part
elementState.setState(AcTypeState.PRIMING);
var type = new ToscaConceptIdentifier(elementEntry.getValue().getType(),
elementEntry.getValue().getTypeVersion());
- elementState.setParticipantId(supportedElementMap.get(type));
+ var participantId = supportedElementMap.get(type);
+ if (participantId != null) {
+ elementState.setParticipantId(participantId);
+ participantIds.add(participantId);
+ }
}
}
+ acmParticipantProvider.verifyParticipantState(participantIds);
return AcmUtils.prepareParticipantPriming(acElements, supportedElementMap);
}