summaryrefslogtreecommitdiffstats
path: root/runtime-controlloop
diff options
context:
space:
mode:
authorsaul.gill <saul.gill@est.tech>2021-08-24 14:38:06 +0100
committersaul.gill <saul.gill@est.tech>2021-08-25 11:33:31 +0100
commit17f9123bf5d192412124535965393179ebe14cc8 (patch)
tree3a075197296916a6a8d0657b5fb4e509d9d2be13 /runtime-controlloop
parent0dfe7276a5a9448d1ab4ecd81b45ad7269eab1f0 (diff)
Added dmaap messages on commission/decommission
Added dmaap message trigger to commissioning endpoint Added dmapp message trigger to decommissioning endpoint Issue-ID: POLICY-3415 Change-Id: I37ab580c9713d1002becd3bc3af674c2ca17b3c9 Signed-off-by: saul.gill <saul.gill@est.tech>
Diffstat (limited to 'runtime-controlloop')
-rw-r--r--runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/commissioning/CommissioningProvider.java49
-rw-r--r--runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionHandler.java28
-rw-r--r--runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/ParticipantUpdatePublisher.java25
-rw-r--r--runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/commissioning/CommissioningProviderTest.java34
-rw-r--r--runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/instantiation/ControlLoopInstantiationProviderTest.java72
-rw-r--r--runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/instantiation/InstantiationUtils.java2
-rw-r--r--runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/instantiation/rest/InstantiationControllerTest.java65
-rw-r--r--runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/SupervisionMessagesTest.java14
-rw-r--r--runtime-controlloop/src/test/resources/META-INF/persistence.xml1
-rwxr-xr-x[-rw-r--r--]runtime-controlloop/src/test/resources/testscripts/listenOnTopic.sh0
10 files changed, 233 insertions, 57 deletions
diff --git a/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/commissioning/CommissioningProvider.java b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/commissioning/CommissioningProvider.java
index ba632f9cc..74b5394f4 100644
--- a/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/commissioning/CommissioningProvider.java
+++ b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/commissioning/CommissioningProvider.java
@@ -34,8 +34,12 @@ import javax.ws.rs.core.Response.Status;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.MapUtils;
import org.onap.policy.clamp.controlloop.common.exception.ControlLoopException;
+import org.onap.policy.clamp.controlloop.models.controlloop.concepts.Participant;
import org.onap.policy.clamp.controlloop.models.controlloop.persistence.provider.ControlLoopProvider;
+import org.onap.policy.clamp.controlloop.models.controlloop.persistence.provider.ParticipantProvider;
+import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantUpdate;
import org.onap.policy.clamp.controlloop.models.messages.rest.commissioning.CommissioningResponse;
+import org.onap.policy.clamp.controlloop.runtime.supervision.SupervisionHandler;
import org.onap.policy.models.base.PfModelException;
import org.onap.policy.models.provider.PolicyModelsProvider;
import org.onap.policy.models.tosca.authorative.concepts.ToscaCapabilityType;
@@ -63,6 +67,8 @@ public class CommissioningProvider {
private final PolicyModelsProvider modelsProvider;
private final ControlLoopProvider clProvider;
private final ObjectMapper mapper = new ObjectMapper();
+ private final ParticipantProvider participantProvider;
+ private final SupervisionHandler supervisionHandler;
private static final Object lockit = new Object();
@@ -72,9 +78,14 @@ public class CommissioningProvider {
* @param modelsProvider the PolicyModelsProvider
* @param clProvider the ControlLoopProvider
*/
- public CommissioningProvider(PolicyModelsProvider modelsProvider, ControlLoopProvider clProvider) {
+ public CommissioningProvider(PolicyModelsProvider modelsProvider,
+ ControlLoopProvider clProvider,
+ SupervisionHandler supervisionHandler,
+ ParticipantProvider participantProvider) {
this.modelsProvider = modelsProvider;
this.clProvider = clProvider;
+ this.supervisionHandler = supervisionHandler;
+ this.participantProvider = participantProvider;
mapper.setPropertyNamingStrategy(PropertyNamingStrategies.SNAKE_CASE);
}
@@ -95,6 +106,24 @@ public class CommissioningProvider {
synchronized (lockit) {
modelsProvider.createServiceTemplate(serviceTemplate);
+ List<Participant> participantList =
+ participantProvider.getParticipants(null,
+ null);
+
+ if (participantList != null) {
+ for (Participant participant: participantList) {
+ var participantType = new ToscaConceptIdentifier();
+ participantType.setName(participant.getType());
+ participantType.setVersion(participant.getTypeVersion());
+
+ var participantUpdate = new ParticipantUpdate();
+ participantUpdate.setParticipantId(participant.getDefinition());
+ participantUpdate.setParticipantType(participantType);
+
+ this.supervisionHandler.handleSendCommissionMessage(participantUpdate);
+ }
+ }
+
}
var response = new CommissioningResponse();
@@ -126,6 +155,24 @@ public class CommissioningProvider {
}
synchronized (lockit) {
+ List<Participant> participantList =
+ participantProvider.getParticipants(null,
+ null);
+
+ if (participantList != null) {
+ for (Participant participant : participantList) {
+ var participantType = new ToscaConceptIdentifier();
+ participantType.setName(participant.getType());
+ participantType.setVersion(participant.getTypeVersion());
+
+ var participantUpdate = new ParticipantUpdate();
+ participantUpdate.setParticipantId(participant.getDefinition());
+ participantUpdate.setParticipantType(participantType);
+
+ this.supervisionHandler.handleSendDeCommissionMessage(participantUpdate);
+ }
+ }
+
modelsProvider.deleteServiceTemplate(name, version);
}
diff --git a/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionHandler.java b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionHandler.java
index 0e2ff5ca9..7cc5d7fee 100644
--- a/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionHandler.java
+++ b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionHandler.java
@@ -21,7 +21,6 @@
package org.onap.policy.clamp.controlloop.runtime.supervision;
import java.util.List;
-import java.util.Map;
import javax.ws.rs.core.Response;
import lombok.AllArgsConstructor;
import org.apache.commons.collections4.CollectionUtils;
@@ -35,6 +34,7 @@ import org.onap.policy.clamp.controlloop.models.controlloop.persistence.provider
import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantDeregister;
import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantRegister;
import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantStatus;
+import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantUpdate;
import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantUpdateAck;
import org.onap.policy.clamp.controlloop.runtime.monitoring.MonitoringProvider;
import org.onap.policy.clamp.controlloop.runtime.supervision.comm.ControlLoopStateChangePublisher;
@@ -141,7 +141,7 @@ public class SupervisionHandler {
participantRegisterAckPublisher.send(participantRegisterMessage.getMessageId());
participantUpdatePublisher.send(participantRegisterMessage.getParticipantId(),
- participantRegisterMessage.getParticipantType());
+ participantRegisterMessage.getParticipantType(), true);
}
/**
@@ -166,6 +166,30 @@ public class SupervisionHandler {
}
/**
+ * Send commissioning update message to dmaap.
+ *
+ * @param participantUpdateMessage the ParticipantUpdate message to send
+ */
+ public void handleSendCommissionMessage(ParticipantUpdate participantUpdateMessage) {
+ LOGGER.debug("Participant update message being sent {}", participantUpdateMessage);
+
+ participantUpdatePublisher.send(participantUpdateMessage.getParticipantId(),
+ participantUpdateMessage.getParticipantType(), true);
+ }
+
+ /**
+ * Send decommissioning update message to dmaap.
+ *
+ * @param participantUpdateMessage the ParticipantUpdate message to send
+ */
+ public void handleSendDeCommissionMessage(ParticipantUpdate participantUpdateMessage) {
+ LOGGER.debug("Participant update message being sent {}", participantUpdateMessage);
+
+ participantUpdatePublisher.send(participantUpdateMessage.getParticipantId(),
+ participantUpdateMessage.getParticipantType(), false);
+ }
+
+ /**
* Supervise a control loop, performing whatever actions need to be performed on the control loop.
*
* @param controlLoop the control loop to supervises
diff --git a/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/ParticipantUpdatePublisher.java b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/ParticipantUpdatePublisher.java
index 5edf528b8..d5dc4a6d0 100644
--- a/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/ParticipantUpdatePublisher.java
+++ b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/ParticipantUpdatePublisher.java
@@ -22,22 +22,21 @@ package org.onap.policy.clamp.controlloop.runtime.supervision.comm;
import java.time.Instant;
import java.util.ArrayList;
-import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import lombok.AllArgsConstructor;
-import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopElement;
import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopElementDefinition;
import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantDefinition;
import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantUpdate;
-import org.onap.policy.clamp.controlloop.runtime.commissioning.CommissioningProvider;
import org.onap.policy.common.utils.coder.Coder;
import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.common.utils.coder.StandardCoder;
import org.onap.policy.models.base.PfModelException;
+import org.onap.policy.models.provider.PolicyModelsProvider;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplates;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
@@ -51,7 +50,7 @@ public class ParticipantUpdatePublisher extends AbstractParticipantPublisher<Par
private static final Logger LOGGER = LoggerFactory.getLogger(ParticipantUpdatePublisher.class);
private static final String CONTROL_LOOP_ELEMENT = "ControlLoopElement";
- private final CommissioningProvider commissioningProvider;
+ private final PolicyModelsProvider modelsProvider;
private static final Coder CODER = new StandardCoder();
/**
@@ -60,7 +59,8 @@ public class ParticipantUpdatePublisher extends AbstractParticipantPublisher<Par
* @param participantId the participant Id
* @param participantType the participant Type
*/
- public void send(ToscaConceptIdentifier participantId, ToscaConceptIdentifier participantType) {
+ public void send(ToscaConceptIdentifier participantId, ToscaConceptIdentifier participantType,
+ boolean commissionFlag) {
var message = new ParticipantUpdate();
message.setParticipantId(participantId);
message.setParticipantType(participantType);
@@ -68,7 +68,7 @@ public class ParticipantUpdatePublisher extends AbstractParticipantPublisher<Par
ToscaServiceTemplate toscaServiceTemplate;
try {
- toscaServiceTemplate = commissioningProvider.getToscaServiceTemplate(null, null);
+ toscaServiceTemplate = modelsProvider.getServiceTemplateList(null, null).get(0);
} catch (PfModelException pfme) {
LOGGER.warn("Get of tosca service template failed, cannot send participantupdate", pfme);
return;
@@ -91,8 +91,15 @@ public class ParticipantUpdatePublisher extends AbstractParticipantPublisher<Par
}
}
- message.setParticipantDefinitionUpdates(participantDefinitionUpdates);
- message.setToscaServiceTemplate(toscaServiceTemplate);
+ if (commissionFlag) {
+ // Commission the controlloop but sending participantdefinitions to participants
+ message.setParticipantDefinitionUpdates(participantDefinitionUpdates);
+ message.setToscaServiceTemplate(toscaServiceTemplate);
+ } else {
+ // DeCommission the controlloop but deleting participantdefinitions on participants
+ message.setParticipantDefinitionUpdates(null);
+ message.setToscaServiceTemplate(null);
+ }
LOGGER.debug("Participant Update sent {}", message);
super.send(message);
}
@@ -127,7 +134,7 @@ public class ParticipantUpdatePublisher extends AbstractParticipantPublisher<Par
private ParticipantDefinition getParticipantDefinition(ControlLoopElementDefinition clDefinition,
ToscaConceptIdentifier clParticipantId,
List<ControlLoopElementDefinition> controlLoopElementDefinitionList) {
- ParticipantDefinition participantDefinition = new ParticipantDefinition();
+ var participantDefinition = new ParticipantDefinition();
participantDefinition.setParticipantId(clParticipantId);
controlLoopElementDefinitionList.add(clDefinition);
participantDefinition.setControlLoopElementDefinitionList(controlLoopElementDefinitionList);
diff --git a/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/commissioning/CommissioningProviderTest.java b/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/commissioning/CommissioningProviderTest.java
index 232d6d83c..5c49b8523 100644
--- a/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/commissioning/CommissioningProviderTest.java
+++ b/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/commissioning/CommissioningProviderTest.java
@@ -33,6 +33,7 @@ import java.util.Map;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import org.onap.policy.clamp.controlloop.models.controlloop.persistence.provider.ControlLoopProvider;
+import org.onap.policy.clamp.controlloop.models.controlloop.persistence.provider.ParticipantProvider;
import org.onap.policy.clamp.controlloop.runtime.main.parameters.ClRuntimeParameterGroup;
import org.onap.policy.clamp.controlloop.runtime.util.CommonTestData;
import org.onap.policy.common.utils.coder.Coder;
@@ -62,7 +63,7 @@ class CommissioningProviderTest {
private ControlLoopProvider clProvider = null;
private static final Coder CODER = new StandardCoder();
private final ObjectMapper mapper = new ObjectMapper();
-
+ private ParticipantProvider participantProvider;
@AfterEach
void close() throws Exception {
@@ -72,6 +73,9 @@ class CommissioningProviderTest {
if (clProvider != null) {
clProvider.close();
}
+ if (participantProvider != null) {
+ participantProvider.close();
+ }
}
/**
@@ -85,8 +89,10 @@ class CommissioningProviderTest {
modelsProvider =
CommonTestData.getPolicyModelsProvider(clRuntimeParameterGroup.getDatabaseProviderParameters());
clProvider = new ControlLoopProvider(clRuntimeParameterGroup.getDatabaseProviderParameters());
+ participantProvider = new ParticipantProvider(clRuntimeParameterGroup.getDatabaseProviderParameters());
- CommissioningProvider provider = new CommissioningProvider(modelsProvider, clProvider);
+ CommissioningProvider provider = new CommissioningProvider(modelsProvider, clProvider,
+ null, participantProvider);
ToscaServiceTemplate serviceTemplate = yamlTranslator
.fromYaml(ResourceUtils.getResourceAsString(TOSCA_SERVICE_TEMPLATE_YAML), ToscaServiceTemplate.class);
@@ -122,8 +128,10 @@ class CommissioningProviderTest {
modelsProvider =
CommonTestData.getPolicyModelsProvider(clRuntimeParameterGroup.getDatabaseProviderParameters());
clProvider = new ControlLoopProvider(clRuntimeParameterGroup.getDatabaseProviderParameters());
+ participantProvider = new ParticipantProvider(clRuntimeParameterGroup.getDatabaseProviderParameters());
- CommissioningProvider provider = new CommissioningProvider(modelsProvider, clProvider);
+ CommissioningProvider provider = new CommissioningProvider(modelsProvider, clProvider,
+ null, participantProvider);
// Test Service template is null
assertThatThrownBy(() -> provider.createControlLoopDefinitions(null)).hasMessageMatching(TEMPLATE_IS_NULL);
List<ToscaNodeTemplate> listOfTemplates = provider.getControlLoopDefinitions(null, null);
@@ -151,8 +159,10 @@ class CommissioningProviderTest {
modelsProvider =
CommonTestData.getPolicyModelsProvider(clRuntimeParameterGroup.getDatabaseProviderParameters());
clProvider = new ControlLoopProvider(clRuntimeParameterGroup.getDatabaseProviderParameters());
+ participantProvider = new ParticipantProvider(clRuntimeParameterGroup.getDatabaseProviderParameters());
- CommissioningProvider provider = new CommissioningProvider(modelsProvider, clProvider);
+ CommissioningProvider provider = new CommissioningProvider(modelsProvider, clProvider,
+ null, participantProvider);
ToscaServiceTemplate serviceTemplate = yamlTranslator
.fromYaml(ResourceUtils
.getResourceAsString(COMMON_TOSCA_SERVICE_TEMPLATE_YAML), ToscaServiceTemplate.class);
@@ -179,8 +189,10 @@ class CommissioningProviderTest {
modelsProvider =
CommonTestData.getPolicyModelsProvider(clRuntimeParameterGroup.getDatabaseProviderParameters());
clProvider = new ControlLoopProvider(clRuntimeParameterGroup.getDatabaseProviderParameters());
+ participantProvider = new ParticipantProvider(clRuntimeParameterGroup.getDatabaseProviderParameters());
- CommissioningProvider provider = new CommissioningProvider(modelsProvider, clProvider);
+ CommissioningProvider provider = new CommissioningProvider(modelsProvider, clProvider,
+ null, participantProvider);
ToscaServiceTemplate serviceTemplate = yamlTranslator
.fromYaml(ResourceUtils
.getResourceAsString(COMMON_TOSCA_SERVICE_TEMPLATE_YAML), ToscaServiceTemplate.class);
@@ -207,8 +219,10 @@ class CommissioningProviderTest {
modelsProvider =
CommonTestData.getPolicyModelsProvider(clRuntimeParameterGroup.getDatabaseProviderParameters());
clProvider = new ControlLoopProvider(clRuntimeParameterGroup.getDatabaseProviderParameters());
+ participantProvider = new ParticipantProvider(clRuntimeParameterGroup.getDatabaseProviderParameters());
- CommissioningProvider provider = new CommissioningProvider(modelsProvider, clProvider);
+ CommissioningProvider provider = new CommissioningProvider(modelsProvider, clProvider,
+ null, participantProvider);
ToscaServiceTemplate serviceTemplate = yamlTranslator
.fromYaml(ResourceUtils
.getResourceAsString(COMMON_TOSCA_SERVICE_TEMPLATE_YAML), ToscaServiceTemplate.class);
@@ -258,8 +272,10 @@ class CommissioningProviderTest {
modelsProvider =
CommonTestData.getPolicyModelsProvider(clRuntimeParameterGroup.getDatabaseProviderParameters());
clProvider = new ControlLoopProvider(clRuntimeParameterGroup.getDatabaseProviderParameters());
+ participantProvider = new ParticipantProvider(clRuntimeParameterGroup.getDatabaseProviderParameters());
- CommissioningProvider provider = new CommissioningProvider(modelsProvider, clProvider);
+ CommissioningProvider provider = new CommissioningProvider(modelsProvider, clProvider,
+ null, participantProvider);
ToscaServiceTemplate serviceTemplate = yamlTranslator
.fromYaml(ResourceUtils.getResourceAsString(TOSCA_SERVICE_TEMPLATE_YAML), ToscaServiceTemplate.class);
@@ -286,8 +302,10 @@ class CommissioningProviderTest {
modelsProvider =
CommonTestData.getPolicyModelsProvider(clRuntimeParameterGroup.getDatabaseProviderParameters());
clProvider = new ControlLoopProvider(clRuntimeParameterGroup.getDatabaseProviderParameters());
+ participantProvider = new ParticipantProvider(clRuntimeParameterGroup.getDatabaseProviderParameters());
- CommissioningProvider provider = new CommissioningProvider(modelsProvider, clProvider);
+ CommissioningProvider provider = new CommissioningProvider(modelsProvider, clProvider,
+ null, participantProvider);
ToscaServiceTemplate serviceTemplate = yamlTranslator
.fromYaml(ResourceUtils.getResourceAsString(TOSCA_SERVICE_TEMPLATE_YAML), ToscaServiceTemplate.class);
diff --git a/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/instantiation/ControlLoopInstantiationProviderTest.java b/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/instantiation/ControlLoopInstantiationProviderTest.java
index c414ffa02..d1aaddc5a 100644
--- a/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/instantiation/ControlLoopInstantiationProviderTest.java
+++ b/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/instantiation/ControlLoopInstantiationProviderTest.java
@@ -26,7 +26,9 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy;
import java.io.IOException;
import java.util.ArrayList;
import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import org.onap.policy.clamp.controlloop.common.exception.ControlLoopRuntimeException;
@@ -49,9 +51,14 @@ import org.onap.policy.clamp.controlloop.runtime.supervision.comm.ParticipantDer
import org.onap.policy.clamp.controlloop.runtime.supervision.comm.ParticipantRegisterAckPublisher;
import org.onap.policy.clamp.controlloop.runtime.supervision.comm.ParticipantUpdatePublisher;
import org.onap.policy.clamp.controlloop.runtime.util.CommonTestData;
+import org.onap.policy.common.utils.coder.YamlJsonTranslator;
+import org.onap.policy.common.utils.resources.ResourceUtils;
import org.onap.policy.models.base.PfModelException;
import org.onap.policy.models.provider.PolicyModelsProvider;
+import org.onap.policy.models.provider.PolicyModelsProviderFactory;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
+import org.springframework.beans.factory.annotation.Autowired;
/**
* Class to perform unit test of {@link ControlLoopInstantiationProvider}}.
@@ -88,10 +95,21 @@ class ControlLoopInstantiationProviderTest {
+ " item \"ControlLoop\" value \"org.onap.domain.PMSHControlLoopDefinition\" INVALID,"
+ " Commissioned control loop definition not FOUND\n";
+ private static ToscaServiceTemplate serviceTemplate = new ToscaServiceTemplate();
+
+ private static final YamlJsonTranslator yamlTranslator = new YamlJsonTranslator();
+
private static SupervisionHandler supervisionHandler;
private static CommissioningProvider commissioningProvider;
private static ControlLoopProvider clProvider;
private static PolicyModelsProvider modelsProvider;
+ private static ParticipantProvider participantProvider;
+
+ @BeforeAll
+ public static void setUpBeforeClass() throws Exception {
+ serviceTemplate = yamlTranslator.fromYaml(ResourceUtils.getResourceAsString(TOSCA_TEMPLATE_YAML),
+ ToscaServiceTemplate.class);
+ }
/**
* setup Db Provider Parameters.
@@ -105,11 +123,13 @@ class ControlLoopInstantiationProviderTest {
modelsProvider =
CommonTestData.getPolicyModelsProvider(controlLoopParameters.getDatabaseProviderParameters());
clProvider = new ControlLoopProvider(controlLoopParameters.getDatabaseProviderParameters());
+ participantProvider = new ParticipantProvider(controlLoopParameters.getDatabaseProviderParameters());
+
var participantStatisticsProvider =
new ParticipantStatisticsProvider(controlLoopParameters.getDatabaseProviderParameters());
var clElementStatisticsProvider =
new ClElementStatisticsProvider(controlLoopParameters.getDatabaseProviderParameters());
- commissioningProvider = new CommissioningProvider(modelsProvider, clProvider);
+ commissioningProvider = new CommissioningProvider(modelsProvider, clProvider, null, participantProvider);
var monitoringProvider =
new MonitoringProvider(participantStatisticsProvider, clElementStatisticsProvider, clProvider);
var participantProvider = new ParticipantProvider(controlLoopParameters.getDatabaseProviderParameters());
@@ -123,24 +143,31 @@ class ControlLoopInstantiationProviderTest {
participantRegisterAckPublisher, participantDeregisterAckPublisher, participantUpdatePublisher);
}
+ @BeforeEach
+ public void populateDb() throws Exception {
+ createEntryInDB();
+ }
+
@AfterAll
public static void closeDbProvider() throws PfModelException {
clProvider.close();
modelsProvider.close();
}
+ @AfterEach
+ public void cleanDatabase() throws Exception {
+ deleteEntryInDB(serviceTemplate.getName(), serviceTemplate.getVersion());
+ }
+
@Test
void testInstantiationCrud() throws Exception {
+
ControlLoops controlLoopsCreate =
InstantiationUtils.getControlLoopsFromResource(CL_INSTANTIATION_CREATE_JSON, "Crud");
ControlLoops controlLoopsDb = getControlLoopsFromDb(controlLoopsCreate);
assertThat(controlLoopsDb.getControlLoopList()).isEmpty();
var instantiationProvider =
new ControlLoopInstantiationProvider(clProvider, commissioningProvider, supervisionHandler);
-
- // to validate control Loop, it needs to define ToscaServiceTemplate
- InstantiationUtils.storeToscaServiceTemplate(TOSCA_TEMPLATE_YAML, commissioningProvider);
-
InstantiationResponse instantiationResponse = instantiationProvider.createControlLoops(controlLoopsCreate);
InstantiationUtils.assertInstantiationResponse(instantiationResponse, controlLoopsCreate);
@@ -192,11 +219,12 @@ class ControlLoopInstantiationProviderTest {
}
private ControlLoops getControlLoopsFromDb(ControlLoops controlLoopsSource) throws Exception {
+
ControlLoops controlLoopsDb = new ControlLoops();
controlLoopsDb.setControlLoopList(new ArrayList<>());
- var instantiationProvider =
- new ControlLoopInstantiationProvider(clProvider, commissioningProvider, supervisionHandler);
+ var instantiationProvider = new ControlLoopInstantiationProvider(clProvider,
+ commissioningProvider, supervisionHandler);
for (ControlLoop controlLoop : controlLoopsSource.getControlLoopList()) {
ControlLoops controlLoopsFromDb =
@@ -208,6 +236,7 @@ class ControlLoopInstantiationProviderTest {
@Test
void testInstantiationDelete() throws Exception {
+
ControlLoops controlLoops =
InstantiationUtils.getControlLoopsFromResource(CL_INSTANTIATION_CREATE_JSON, "Delete");
assertThat(getControlLoopsFromDb(controlLoops).getControlLoopList()).isEmpty();
@@ -217,9 +246,6 @@ class ControlLoopInstantiationProviderTest {
var instantiationProvider =
new ControlLoopInstantiationProvider(clProvider, commissioningProvider, supervisionHandler);
- // to validate control Loop, it needs to define ToscaServiceTemplate
- InstantiationUtils.storeToscaServiceTemplate(TOSCA_TEMPLATE_YAML, commissioningProvider);
-
assertThatThrownBy(
() -> instantiationProvider.deleteControlLoop(controlLoop0.getName(), controlLoop0.getVersion()))
.hasMessageMatching(CONTROL_LOOP_NOT_FOUND);
@@ -263,6 +289,7 @@ class ControlLoopInstantiationProviderTest {
@Test
void testCreateControlLoops_NoDuplicates() throws Exception {
+
ControlLoops controlLoopsCreate =
InstantiationUtils.getControlLoopsFromResource(CL_INSTANTIATION_CREATE_JSON, "NoDuplicates");
@@ -272,9 +299,6 @@ class ControlLoopInstantiationProviderTest {
var instantiationProvider =
new ControlLoopInstantiationProvider(clProvider, commissioningProvider, supervisionHandler);
- // to validate control Loop, it needs to define ToscaServiceTemplate
- InstantiationUtils.storeToscaServiceTemplate(TOSCA_TEMPLATE_YAML, commissioningProvider);
-
InstantiationResponse instantiationResponse = instantiationProvider.createControlLoops(controlLoopsCreate);
InstantiationUtils.assertInstantiationResponse(instantiationResponse, controlLoopsCreate);
@@ -288,13 +312,14 @@ class ControlLoopInstantiationProviderTest {
@Test
void testCreateControlLoops_CommissionedClElementNotFound() throws Exception {
+
ControlLoops controlLoops = InstantiationUtils
.getControlLoopsFromResource(CL_INSTANTIATION_DEFINITION_NAME_NOT_FOUND_JSON, "ClElementNotFound");
var provider = new ControlLoopInstantiationProvider(clProvider, commissioningProvider, supervisionHandler);
// to validate control Loop, it needs to define ToscaServiceTemplate
- InstantiationUtils.storeToscaServiceTemplate(TOSCA_TEMPLATE_YAML, commissioningProvider);
+ // InstantiationUtils.storeToscaServiceTemplate(TOSCA_TEMPLATE_YAML, commissioningProvider);
assertThat(getControlLoopsFromDb(controlLoops).getControlLoopList()).isEmpty();
@@ -324,7 +349,6 @@ class ControlLoopInstantiationProviderTest {
@Test
void testInstantiationVersions() throws Exception {
-
// create controlLoops V1
ControlLoops controlLoopsV1 =
InstantiationUtils.getControlLoopsFromResource(CL_INSTANTIATION_CREATE_JSON, "V1");
@@ -333,9 +357,6 @@ class ControlLoopInstantiationProviderTest {
var instantiationProvider =
new ControlLoopInstantiationProvider(clProvider, commissioningProvider, supervisionHandler);
- // to validate control Loop, it needs to define ToscaServiceTemplate
- InstantiationUtils.storeToscaServiceTemplate(TOSCA_TEMPLATE_YAML, commissioningProvider);
-
InstantiationUtils.assertInstantiationResponse(instantiationProvider.createControlLoops(controlLoopsV1),
controlLoopsV1);
@@ -386,4 +407,19 @@ class ControlLoopInstantiationProviderTest {
assertThat(controlLoopsGet.getControlLoopList()).isEmpty();
}
}
+
+ private synchronized void deleteEntryInDB(String name, String version) throws Exception {
+ if (!modelsProvider.getServiceTemplateList(null, null).isEmpty()) {
+ modelsProvider.deleteServiceTemplate(name, version);
+ }
+ }
+
+ private synchronized void createEntryInDB() throws Exception {
+ try {
+ deleteEntryInDB(serviceTemplate.getName(), serviceTemplate.getVersion());
+ modelsProvider.createServiceTemplate(serviceTemplate);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
}
diff --git a/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/instantiation/InstantiationUtils.java b/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/instantiation/InstantiationUtils.java
index e98ad1380..8529c0c9b 100644
--- a/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/instantiation/InstantiationUtils.java
+++ b/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/instantiation/InstantiationUtils.java
@@ -140,6 +140,8 @@ public class InstantiationUtils {
ToscaServiceTemplate template =
yamlTranslator.fromYaml(ResourceUtils.getResourceAsString(path), ToscaServiceTemplate.class);
+ commissioningProvider.deleteControlLoopDefinition(null, null);
+
commissioningProvider.createControlLoopDefinitions(template);
}
diff --git a/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/instantiation/rest/InstantiationControllerTest.java b/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/instantiation/rest/InstantiationControllerTest.java
index 6c9674dec..41c55dd2d 100644
--- a/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/instantiation/rest/InstantiationControllerTest.java
+++ b/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/instantiation/rest/InstantiationControllerTest.java
@@ -28,6 +28,9 @@ import static org.junit.jupiter.api.Assertions.assertNull;
import javax.ws.rs.client.Entity;
import javax.ws.rs.client.Invocation;
import javax.ws.rs.core.Response;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
@@ -35,12 +38,17 @@ import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoop
import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoops;
import org.onap.policy.clamp.controlloop.models.messages.rest.instantiation.InstantiationCommand;
import org.onap.policy.clamp.controlloop.models.messages.rest.instantiation.InstantiationResponse;
-import org.onap.policy.clamp.controlloop.runtime.commissioning.CommissioningProvider;
import org.onap.policy.clamp.controlloop.runtime.instantiation.ControlLoopInstantiationProvider;
import org.onap.policy.clamp.controlloop.runtime.instantiation.InstantiationUtils;
+import org.onap.policy.clamp.controlloop.runtime.main.parameters.ClRuntimeParameterGroup;
import org.onap.policy.clamp.controlloop.runtime.main.rest.InstantiationController;
import org.onap.policy.clamp.controlloop.runtime.util.rest.CommonRestController;
+import org.onap.policy.common.utils.coder.YamlJsonTranslator;
+import org.onap.policy.common.utils.resources.ResourceUtils;
+import org.onap.policy.models.provider.PolicyModelsProvider;
+import org.onap.policy.models.provider.PolicyModelsProviderFactory;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
@@ -72,24 +80,29 @@ class InstantiationControllerTest extends CommonRestController {
private static final String INSTANTIATION_COMMAND_ENDPOINT = "instantiation/command";
+ private static ToscaServiceTemplate serviceTemplate = new ToscaServiceTemplate();
+
+ private static final YamlJsonTranslator yamlTranslator = new YamlJsonTranslator();
+
+
@Autowired
- private ControlLoopInstantiationProvider instantiationProvider;
+ private ClRuntimeParameterGroup clRuntimeParameterGroup;
@Autowired
- private CommissioningProvider commissioningProvider;
+ private ControlLoopInstantiationProvider instantiationProvider;
@LocalServerPort
private int randomServerPort;
- /**
- * starts Main and inserts a commissioning template.
- *
- * @throws Exception if an error occurs
- */
+ @BeforeAll
+ public static void setUpBeforeClass() throws Exception {
+ serviceTemplate = yamlTranslator.fromYaml(ResourceUtils.getResourceAsString(TOSCA_TEMPLATE_YAML),
+ ToscaServiceTemplate.class);
+ }
+
@BeforeEach
- public void setUpBeforeClass() throws Exception {
- // to validate control Loop, it needs to define ToscaServiceTemplate
- InstantiationUtils.storeToscaServiceTemplate(TOSCA_TEMPLATE_YAML, commissioningProvider);
+ public void populateDb() throws Exception {
+ createEntryInDB();
}
@BeforeEach
@@ -97,6 +110,11 @@ class InstantiationControllerTest extends CommonRestController {
super.setHttpPrefix(randomServerPort);
}
+ @AfterEach
+ public void cleanDatabase() throws Exception {
+ deleteEntryInDB(serviceTemplate.getName(), serviceTemplate.getVersion());
+ }
+
@Test
void testSwagger() throws Exception {
super.testSwagger(INSTANTIATION_ENDPOINT);
@@ -138,6 +156,7 @@ class InstantiationControllerTest extends CommonRestController {
@Test
void testCreate() throws Exception {
+
ControlLoops controlLoopsFromRsc =
InstantiationUtils.getControlLoopsFromResource(CL_INSTANTIATION_CREATE_JSON, "Create");
@@ -159,6 +178,7 @@ class InstantiationControllerTest extends CommonRestController {
@Test
void testCreateBadRequest() throws Exception {
+
ControlLoops controlLoopsFromRsc =
InstantiationUtils.getControlLoopsFromResource(CL_INSTANTIATION_CREATE_JSON, "CreateBadRequest");
@@ -185,7 +205,7 @@ class InstantiationControllerTest extends CommonRestController {
@Test
void testQuery() throws Exception {
- // inserts a ControlLoops to DB
+
var controlLoops = InstantiationUtils.getControlLoopsFromResource(CL_INSTANTIATION_CREATE_JSON, "Query");
instantiationProvider.createControlLoops(controlLoops);
@@ -203,6 +223,7 @@ class InstantiationControllerTest extends CommonRestController {
@Test
void testUpdate() throws Exception {
+
ControlLoops controlLoopsCreate =
InstantiationUtils.getControlLoopsFromResource(CL_INSTANTIATION_CREATE_JSON, "Update");
@@ -238,6 +259,7 @@ class InstantiationControllerTest extends CommonRestController {
@Test
void testDelete() throws Exception {
+
ControlLoops controlLoopsFromRsc =
InstantiationUtils.getControlLoopsFromResource(CL_INSTANTIATION_CREATE_JSON, "Delete");
@@ -259,6 +281,7 @@ class InstantiationControllerTest extends CommonRestController {
@Test
void testDeleteBadRequest() throws Exception {
+
ControlLoops controlLoopsFromRsc =
InstantiationUtils.getControlLoopsFromResource(CL_INSTANTIATION_CREATE_JSON, "DelBadRequest");
@@ -293,6 +316,7 @@ class InstantiationControllerTest extends CommonRestController {
@Test
void testCommand() throws Exception {
+
var controlLoops = InstantiationUtils.getControlLoopsFromResource(CL_INSTANTIATION_CREATE_JSON, "Command");
instantiationProvider.createControlLoops(controlLoops);
@@ -313,4 +337,21 @@ class InstantiationControllerTest extends CommonRestController {
assertEquals(command.getOrderedState(), controlLoopsGet.getControlLoopList().get(0).getOrderedState());
}
}
+
+ private synchronized void deleteEntryInDB(String name, String version) throws Exception {
+ try (PolicyModelsProvider modelsProvider = new PolicyModelsProviderFactory()
+ .createPolicyModelsProvider(clRuntimeParameterGroup.getDatabaseProviderParameters())) {
+ if (!modelsProvider.getServiceTemplateList(null, null).isEmpty()) {
+ modelsProvider.deleteServiceTemplate(name, version);
+ }
+ }
+ }
+
+ private synchronized void createEntryInDB() throws Exception {
+ try (PolicyModelsProvider modelsProvider = new PolicyModelsProviderFactory()
+ .createPolicyModelsProvider(clRuntimeParameterGroup.getDatabaseProviderParameters())) {
+ deleteEntryInDB(serviceTemplate.getName(), serviceTemplate.getVersion());
+ modelsProvider.createServiceTemplate(serviceTemplate);
+ }
+ }
}
diff --git a/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/SupervisionMessagesTest.java b/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/SupervisionMessagesTest.java
index 10116a240..73ec4e482 100644
--- a/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/SupervisionMessagesTest.java
+++ b/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/SupervisionMessagesTest.java
@@ -23,7 +23,6 @@ package org.onap.policy.clamp.controlloop.runtime.supervision.comm;
import java.time.Instant;
import java.util.ArrayList;
import java.util.Collections;
-import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
@@ -44,7 +43,6 @@ import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.Parti
import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantUpdate;
import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantUpdateAck;
import org.onap.policy.clamp.controlloop.runtime.commissioning.CommissioningProvider;
-import org.onap.policy.clamp.controlloop.runtime.instantiation.InstantiationUtils;
import org.onap.policy.clamp.controlloop.runtime.main.parameters.ClRuntimeParameterGroup;
import org.onap.policy.clamp.controlloop.runtime.monitoring.MonitoringProvider;
import org.onap.policy.clamp.controlloop.runtime.supervision.SupervisionHandler;
@@ -70,10 +68,12 @@ class SupervisionMessagesTest extends CommonRestController {
private static final Object lockit = new Object();
private static final CommInfrastructure INFRA = CommInfrastructure.NOOP;
private static final String TOPIC = "my-topic";
+ private static final long interval = 1000;
private static SupervisionHandler supervisionHandler;
private static CommissioningProvider commissioningProvider;
private static ControlLoopProvider clProvider;
private static PolicyModelsProvider modelsProvider;
+ private static ParticipantProvider participantProvider;
private static final YamlJsonTranslator yamlTranslator = new YamlJsonTranslator();
private static final String TOSCA_TEMPLATE_YAML =
"src/test/resources/rest/servicetemplates/pmsh_multiple_cl_tosca.yaml";
@@ -91,11 +91,13 @@ class SupervisionMessagesTest extends CommonRestController {
modelsProvider = CommonTestData.getPolicyModelsProvider(controlLoopParameters.getDatabaseProviderParameters());
clProvider = new ControlLoopProvider(controlLoopParameters.getDatabaseProviderParameters());
+ participantProvider = new ParticipantProvider(controlLoopParameters.getDatabaseProviderParameters());
+
var participantStatisticsProvider =
new ParticipantStatisticsProvider(controlLoopParameters.getDatabaseProviderParameters());
var clElementStatisticsProvider =
new ClElementStatisticsProvider(controlLoopParameters.getDatabaseProviderParameters());
- commissioningProvider = new CommissioningProvider(modelsProvider, clProvider);
+ commissioningProvider = new CommissioningProvider(modelsProvider, clProvider, null, participantProvider);
var monitoringProvider =
new MonitoringProvider(participantStatisticsProvider, clElementStatisticsProvider, clProvider);
var participantProvider = new ParticipantProvider(controlLoopParameters.getDatabaseProviderParameters());
@@ -128,6 +130,7 @@ class SupervisionMessagesTest extends CommonRestController {
ToscaServiceTemplate serviceTemplate = yamlTranslator.fromYaml(
ResourceUtils.getResourceAsString(TOSCA_SERVICE_TEMPLATE_YAML), ToscaServiceTemplate.class);
+ // List<ToscaNodeTemplate> listOfTemplates = commissioningProvider.getControlLoopDefinitions(null, null);
commissioningProvider.createControlLoopDefinitions(serviceTemplate);
participantRegisterListener.onTopicEvent(INFRA, TOPIC, null, participantRegisterMsg);
}
@@ -177,9 +180,6 @@ class SupervisionMessagesTest extends CommonRestController {
@Test
void testSendParticipantUpdate() throws Exception {
- InstantiationUtils.storeToscaServiceTemplate(TOSCA_TEMPLATE_YAML, commissioningProvider);
- commissioningProvider.getToscaServiceTemplate(null, null);
-
final ParticipantUpdate participantUpdateMsg = new ParticipantUpdate();
participantUpdateMsg.setParticipantId(getParticipantId());
participantUpdateMsg.setTimestamp(Instant.now());
@@ -209,7 +209,7 @@ class SupervisionMessagesTest extends CommonRestController {
participantUpdateMsg.setToscaServiceTemplate(toscaServiceTemplate);
synchronized (lockit) {
ParticipantUpdatePublisher participantUpdatePublisher =
- new ParticipantUpdatePublisher(commissioningProvider);
+ new ParticipantUpdatePublisher(modelsProvider);
participantUpdatePublisher.active(Collections.singletonList(Mockito.mock(TopicSink.class)));
participantUpdatePublisher.send(participantUpdateMsg);
}
diff --git a/runtime-controlloop/src/test/resources/META-INF/persistence.xml b/runtime-controlloop/src/test/resources/META-INF/persistence.xml
index 6e31cca47..c4e2e8d55 100644
--- a/runtime-controlloop/src/test/resources/META-INF/persistence.xml
+++ b/runtime-controlloop/src/test/resources/META-INF/persistence.xml
@@ -104,6 +104,7 @@
<class>org.onap.policy.models.tosca.simple.concepts.JpaToscaTopologyTemplate</class>
<class>org.onap.policy.clamp.controlloop.models.controlloop.persistence.concepts.JpaControlLoop</class>
<class>org.onap.policy.clamp.controlloop.models.controlloop.persistence.concepts.JpaControlLoopElement</class>
+ <class>org.onap.policy.clamp.controlloop.models.controlloop.persistence.concepts.JpaParticipant</class>
<class>org.onap.policy.clamp.controlloop.models.controlloop.persistence.concepts.JpaParticipantStatistics</class>
<class>org.onap.policy.clamp.controlloop.models.controlloop.persistence.concepts.JpaClElementStatistics</class>
diff --git a/runtime-controlloop/src/test/resources/testscripts/listenOnTopic.sh b/runtime-controlloop/src/test/resources/testscripts/listenOnTopic.sh
index 5e661777b..5e661777b 100644..100755
--- a/runtime-controlloop/src/test/resources/testscripts/listenOnTopic.sh
+++ b/runtime-controlloop/src/test/resources/testscripts/listenOnTopic.sh