aboutsummaryrefslogtreecommitdiffstats
path: root/runtime-acm
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
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')
-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
-rw-r--r--runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/commissioning/CommissioningProviderTest.java19
-rw-r--r--runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/commissioning/rest/CommissioningControllerTest.java10
-rw-r--r--runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProviderTest.java26
-rw-r--r--runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/rest/InstantiationControllerTest.java9
-rw-r--r--runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/comm/SupervisionMessagesTest.java6
-rw-r--r--runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/util/CommonTestData.java2
12 files changed, 119 insertions, 25 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);
}
diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/commissioning/CommissioningProviderTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/commissioning/CommissioningProviderTest.java
index fbaa4fed5..08d20bacc 100644
--- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/commissioning/CommissioningProviderTest.java
+++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/commissioning/CommissioningProviderTest.java
@@ -24,6 +24,7 @@ package org.onap.policy.clamp.acm.runtime.commissioning;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.timeout;
import static org.mockito.Mockito.verify;
@@ -34,6 +35,7 @@ import java.util.List;
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.participants.AcmParticipantProvider;
import org.onap.policy.clamp.acm.runtime.supervision.comm.ParticipantPrimePublisher;
import org.onap.policy.clamp.acm.runtime.util.CommonTestData;
import org.onap.policy.clamp.models.acm.concepts.AcTypeState;
@@ -58,7 +60,7 @@ class CommissioningProviderTest {
var acProvider = mock(AutomationCompositionProvider.class);
var acDefinitionProvider = mock(AcDefinitionProvider.class);
- var provider = new CommissioningProvider(acDefinitionProvider, acProvider, null, null);
+ var provider = new CommissioningProvider(acDefinitionProvider, acProvider, null, null, null);
var serviceTemplates = provider.getAutomationCompositionDefinitions(null, null);
assertThat(serviceTemplates.getServiceTemplates()).isEmpty();
@@ -85,7 +87,7 @@ class CommissioningProviderTest {
when(acDefinitionProvider.createAutomationCompositionDefinition(serviceTemplate)).thenReturn(acmDefinition);
var acProvider = mock(AutomationCompositionProvider.class);
- var provider = new CommissioningProvider(acDefinitionProvider, acProvider, null, null);
+ var provider = new CommissioningProvider(acDefinitionProvider, acProvider, null, null, null);
var affectedDefinitions = provider.createAutomationCompositionDefinition(serviceTemplate)
.getAffectedAutomationCompositionDefinitions();
verify(acDefinitionProvider).createAutomationCompositionDefinition(serviceTemplate);
@@ -103,7 +105,7 @@ class CommissioningProviderTest {
var acDefinitionProvider = mock(AcDefinitionProvider.class);
var acProvider = mock(AutomationCompositionProvider.class);
- var provider = new CommissioningProvider(acDefinitionProvider, acProvider, null, null);
+ var provider = new CommissioningProvider(acDefinitionProvider, acProvider, null, null, null);
var serviceTemplate = InstantiationUtils.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML);
when(acDefinitionProvider.getServiceTemplateList(null, null)).thenReturn(List.of(serviceTemplate));
@@ -120,7 +122,7 @@ class CommissioningProviderTest {
var compositionId = UUID.randomUUID();
when(acProvider.getAcInstancesByCompositionId(compositionId)).thenReturn(List.of(new AutomationComposition()));
- var provider = new CommissioningProvider(acDefinitionProvider, acProvider, null, null);
+ var provider = new CommissioningProvider(acDefinitionProvider, acProvider, null, null, null);
assertThatThrownBy(() -> provider.deleteAutomationCompositionDefinition(compositionId))
.hasMessageMatching("Delete instances, to commission automation composition definitions");
@@ -140,7 +142,7 @@ class CommissioningProviderTest {
when(acDefinitionProvider.getAcDefinition(compositionId)).thenReturn(acmDefinition);
var acProvider = mock(AutomationCompositionProvider.class);
- var provider = new CommissioningProvider(acDefinitionProvider, acProvider, null, null);
+ var provider = new CommissioningProvider(acDefinitionProvider, acProvider, null, null, null);
provider.deleteAutomationCompositionDefinition(compositionId);
@@ -157,7 +159,7 @@ class CommissioningProviderTest {
var participantPrimePublisher = mock(ParticipantPrimePublisher.class);
var provider = new CommissioningProvider(acDefinitionProvider, mock(AutomationCompositionProvider.class),
- new AcTypeStateResolver(), participantPrimePublisher);
+ mock(AcmParticipantProvider.class), new AcTypeStateResolver(), participantPrimePublisher);
var acTypeStateUpdate = new AcTypeStateUpdate();
acTypeStateUpdate.setPrimeOrder(PrimeOrder.PRIME);
@@ -175,11 +177,14 @@ class CommissioningProviderTest {
when(acDefinitionProvider.getAcDefinition(compositionId)).thenReturn(acmDefinition);
var participantPrimePublisher = mock(ParticipantPrimePublisher.class);
+ var acmParticipantProvider = mock(AcmParticipantProvider.class);
var provider = new CommissioningProvider(acDefinitionProvider, mock(AutomationCompositionProvider.class),
- new AcTypeStateResolver(), participantPrimePublisher);
+ acmParticipantProvider, new AcTypeStateResolver(), participantPrimePublisher);
var acTypeStateUpdate = new AcTypeStateUpdate();
acTypeStateUpdate.setPrimeOrder(PrimeOrder.DEPRIME);
+
+ doNothing().when(acmParticipantProvider).verifyParticipantState(any());
provider.compositionDefinitionPriming(compositionId, acTypeStateUpdate);
verify(participantPrimePublisher, timeout(1000).times(1)).sendDepriming(compositionId);
}
diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/commissioning/rest/CommissioningControllerTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/commissioning/rest/CommissioningControllerTest.java
index fac4440a2..e8e595b4a 100644
--- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/commissioning/rest/CommissioningControllerTest.java
+++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/commissioning/rest/CommissioningControllerTest.java
@@ -40,10 +40,16 @@ import org.junit.jupiter.api.extension.ExtendWith;
import org.onap.policy.clamp.acm.runtime.instantiation.InstantiationUtils;
import org.onap.policy.clamp.acm.runtime.util.rest.CommonRestController;
import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionDefinition;
+import org.onap.policy.clamp.models.acm.concepts.Participant;
+import org.onap.policy.clamp.models.acm.concepts.ParticipantState;
+import org.onap.policy.clamp.models.acm.concepts.ParticipantSupportedElementType;
import org.onap.policy.clamp.models.acm.messages.rest.commissioning.AcTypeStateUpdate;
import org.onap.policy.clamp.models.acm.messages.rest.commissioning.CommissioningResponse;
import org.onap.policy.clamp.models.acm.messages.rest.commissioning.PrimeOrder;
import org.onap.policy.clamp.models.acm.persistence.provider.AcDefinitionProvider;
+import org.onap.policy.clamp.models.acm.persistence.provider.ParticipantProvider;
+import org.onap.policy.clamp.models.acm.utils.AcmUtils;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
import org.onap.policy.models.tosca.authorative.concepts.ToscaDataType;
import org.onap.policy.models.tosca.authorative.concepts.ToscaProperty;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
@@ -65,6 +71,8 @@ class CommissioningControllerTest extends CommonRestController {
@Autowired
private AcDefinitionProvider acDefinitionProvider;
+ @Autowired
+ private ParticipantProvider participantProvider;
@LocalServerPort
private int randomServerPort;
@@ -223,6 +231,8 @@ class CommissioningControllerTest extends CommonRestController {
var serviceTemplateCreate = new ToscaServiceTemplate(serviceTemplate);
serviceTemplateCreate.setName(name);
var acmDefinition = acDefinitionProvider.createAutomationCompositionDefinition(serviceTemplateCreate);
+
return acmDefinition.getCompositionId();
}
+
}
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 54a0c9613..13da979c8 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
@@ -24,6 +24,7 @@ package org.onap.policy.clamp.acm.runtime.instantiation;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -34,6 +35,7 @@ import java.util.Optional;
import java.util.UUID;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
+import org.onap.policy.clamp.acm.runtime.participants.AcmParticipantProvider;
import org.onap.policy.clamp.acm.runtime.supervision.SupervisionAcHandler;
import org.onap.policy.clamp.acm.runtime.util.CommonTestData;
import org.onap.policy.clamp.common.acm.exception.AutomationCompositionException;
@@ -96,8 +98,9 @@ class AutomationCompositionInstantiationProviderTest {
when(acDefinitionProvider.findAcDefinition(compositionId)).thenReturn(Optional.of(acDefinition));
var acProvider = mock(AutomationCompositionProvider.class);
var supervisionAcHandler = mock(SupervisionAcHandler.class);
+ var acmParticipantProvider = mock(AcmParticipantProvider.class);
var instantiationProvider = new AutomationCompositionInstantiationProvider(acProvider, acDefinitionProvider,
- null, supervisionAcHandler);
+ null, supervisionAcHandler, acmParticipantProvider);
var automationCompositionCreate =
InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_CREATE_JSON, "Crud");
automationCompositionCreate.setCompositionId(compositionId);
@@ -134,6 +137,7 @@ class AutomationCompositionInstantiationProviderTest {
when(acProvider.deleteAutomationComposition(automationCompositionUpdate.getInstanceId()))
.thenReturn(automationCompositionUpdate);
+ doNothing().when(acmParticipantProvider).verifyParticipantState(any());
instantiationProvider.deleteAutomationComposition(automationCompositionCreate.getCompositionId(),
automationCompositionCreate.getInstanceId());
@@ -148,9 +152,10 @@ class AutomationCompositionInstantiationProviderTest {
var acProvider = mock(AutomationCompositionProvider.class);
var acDefinitionProvider = mock(AcDefinitionProvider.class);
var supervisionAcHandler = mock(SupervisionAcHandler.class);
+ var acmParticipantProvider = mock(AcmParticipantProvider.class);
var instantiationProvider = new AutomationCompositionInstantiationProvider(acProvider,
- acDefinitionProvider, null, supervisionAcHandler);
+ acDefinitionProvider, null, supervisionAcHandler, acmParticipantProvider);
when(acProvider.getAutomationComposition(automationComposition.getInstanceId()))
.thenReturn(automationComposition);
@@ -181,7 +186,7 @@ class AutomationCompositionInstantiationProviderTest {
var acDefinitionProvider = mock(AcDefinitionProvider.class);
var instantiationProvider = new AutomationCompositionInstantiationProvider(acProvider,
- acDefinitionProvider, null, null);
+ acDefinitionProvider, null, null, null);
when(acProvider.getAutomationComposition(automationComposition.getInstanceId()))
.thenReturn(automationComposition);
@@ -207,9 +212,10 @@ class AutomationCompositionInstantiationProviderTest {
var acProvider = mock(AutomationCompositionProvider.class);
when(acProvider.createAutomationComposition(automationCompositionCreate))
.thenReturn(automationCompositionCreate);
+ var acmParticipantProvider = mock(AcmParticipantProvider.class);
var instantiationProvider = new AutomationCompositionInstantiationProvider(acProvider,
- acDefinitionProvider, null, null);
+ acDefinitionProvider, null, null, acmParticipantProvider);
var instantiationResponse = instantiationProvider.createAutomationComposition(
automationCompositionCreate.getCompositionId(), automationCompositionCreate);
@@ -226,6 +232,7 @@ class AutomationCompositionInstantiationProviderTest {
@Test
void testCreateAutomationCompositions_CommissionedAcElementNotFound() {
var acDefinitionProvider = mock(AcDefinitionProvider.class);
+ var acmParticipantProvider = mock(AcmParticipantProvider.class);
var acDefinition = CommonTestData.createAcDefinition(serviceTemplate, AcTypeState.PRIMED);
var compositionId = acDefinition.getCompositionId();
when(acDefinitionProvider.findAcDefinition(compositionId)).thenReturn(Optional.of(acDefinition));
@@ -235,7 +242,7 @@ class AutomationCompositionInstantiationProviderTest {
var acProvider = mock(AutomationCompositionProvider.class);
var provider = new AutomationCompositionInstantiationProvider(acProvider,
- acDefinitionProvider, null, null);
+ acDefinitionProvider, null, null, acmParticipantProvider);
assertThatThrownBy(() -> provider.createAutomationComposition(compositionId, automationComposition))
.hasMessageMatching(AC_ELEMENT_NAME_NOT_FOUND);
@@ -256,7 +263,7 @@ class AutomationCompositionInstantiationProviderTest {
when(acProvider.getAutomationComposition(automationComposition.getInstanceId()))
.thenReturn(automationComposition);
var provider = new AutomationCompositionInstantiationProvider(acProvider,
- mock(AcDefinitionProvider.class), null, null);
+ mock(AcDefinitionProvider.class), null, null, null);
var compositionId = automationComposition.getCompositionId();
assertThatThrownBy(() -> provider.createAutomationComposition(compositionId, automationComposition))
@@ -275,7 +282,7 @@ class AutomationCompositionInstantiationProviderTest {
when(acProvider.getAutomationComposition(automationComposition.getInstanceId()))
.thenReturn(automationComposition);
var provider = new AutomationCompositionInstantiationProvider(acProvider,
- mock(AcDefinitionProvider.class), null, null);
+ mock(AcDefinitionProvider.class), null, null, null);
var compositionId = automationComposition.getCompositionId();
var wrongCompositionId = UUID.randomUUID();
@@ -301,7 +308,7 @@ class AutomationCompositionInstantiationProviderTest {
when(acDefinitionProvider.findAcDefinition(compositionId)).thenReturn(Optional.of(acDefinition));
var acProvider = mock(AutomationCompositionProvider.class);
var provider =
- new AutomationCompositionInstantiationProvider(acProvider, acDefinitionProvider, null, null);
+ new AutomationCompositionInstantiationProvider(acProvider, acDefinitionProvider, null, null, null);
var automationComposition =
InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_CREATE_JSON, "Crud");
@@ -329,8 +336,9 @@ class AutomationCompositionInstantiationProviderTest {
.thenReturn(automationComposition);
var supervisionAcHandler = mock(SupervisionAcHandler.class);
+ var acmParticipantProvider = mock(AcmParticipantProvider.class);
var provider = new AutomationCompositionInstantiationProvider(acProvider, acDefinitionProvider,
- new AcInstanceStateResolver(), supervisionAcHandler);
+ new AcInstanceStateResolver(), supervisionAcHandler, acmParticipantProvider);
var acInstanceStateUpdate = new AcInstanceStateUpdate();
acInstanceStateUpdate.setDeployOrder(DeployOrder.DEPLOY);
diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/rest/InstantiationControllerTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/rest/InstantiationControllerTest.java
index 8948f5f53..d57d0f3b7 100644
--- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/rest/InstantiationControllerTest.java
+++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/rest/InstantiationControllerTest.java
@@ -47,6 +47,7 @@ import org.onap.policy.clamp.models.acm.messages.rest.instantiation.AcInstanceSt
import org.onap.policy.clamp.models.acm.messages.rest.instantiation.DeployOrder;
import org.onap.policy.clamp.models.acm.messages.rest.instantiation.InstantiationResponse;
import org.onap.policy.clamp.models.acm.persistence.provider.AcDefinitionProvider;
+import org.onap.policy.clamp.models.acm.persistence.provider.ParticipantProvider;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
@@ -77,6 +78,9 @@ class InstantiationControllerTest extends CommonRestController {
private AcDefinitionProvider acDefinitionProvider;
@Autowired
+ private ParticipantProvider participantProvider;
+
+ @Autowired
private AutomationCompositionInstantiationProvider instantiationProvider;
@LocalServerPort
@@ -335,6 +339,11 @@ class InstantiationControllerTest extends CommonRestController {
serviceTemplateCreate.setName(name);
var acmDefinition = CommonTestData.createAcDefinition(serviceTemplate, AcTypeState.PRIMED);
acDefinitionProvider.updateAcDefinition(acmDefinition);
+ saveDummyParticipantInDb();
return acmDefinition.getCompositionId();
}
+
+ private void saveDummyParticipantInDb() {
+ participantProvider.saveParticipant(CommonTestData.createParticipant(CommonTestData.getParticipantId()));
+ }
}
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 4ff759c13..8de5ccabe 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.participants.AcmParticipantProvider;
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;
@@ -144,7 +145,8 @@ class SupervisionMessagesTest {
@Test
void testParticipantPrimePublisherDecommissioning() {
- var publisher = new ParticipantPrimePublisher(mock(ParticipantProvider.class));
+ var publisher = new ParticipantPrimePublisher(mock(ParticipantProvider.class),
+ mock(AcmParticipantProvider.class));
var topicSink = mock(TopicSink.class);
publisher.active(List.of(topicSink));
publisher.sendDepriming(UUID.randomUUID());
@@ -165,7 +167,7 @@ class SupervisionMessagesTest {
participantId);
var participantProvider = mock(ParticipantProvider.class);
when(participantProvider.getSupportedElementMap()).thenReturn(supportedElementMap);
- var publisher = new ParticipantPrimePublisher(participantProvider);
+ var publisher = new ParticipantPrimePublisher(participantProvider, mock(AcmParticipantProvider.class));
var topicSink = mock(TopicSink.class);
publisher.active(List.of(topicSink));
var serviceTemplate = InstantiationUtils.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML);
diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/util/CommonTestData.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/util/CommonTestData.java
index 69c1302bc..5c82713b0 100644
--- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/util/CommonTestData.java
+++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/util/CommonTestData.java
@@ -28,6 +28,7 @@ import org.onap.policy.clamp.common.acm.exception.AutomationCompositionRuntimeEx
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.Participant;
+import org.onap.policy.clamp.models.acm.concepts.ParticipantState;
import org.onap.policy.clamp.models.acm.utils.AcmUtils;
import org.onap.policy.common.utils.coder.Coder;
import org.onap.policy.common.utils.coder.CoderException;
@@ -92,6 +93,7 @@ public class CommonTestData {
public static Participant createParticipant(UUID participantId) {
var participant = new Participant();
participant.setParticipantId(participantId);
+ participant.setParticipantState(ParticipantState.ON_LINE);
return participant;
}