aboutsummaryrefslogtreecommitdiffstats
path: root/participant/participant-impl/participant-impl-http
diff options
context:
space:
mode:
authorSirisha_Manchikanti <sirisha.manchikanti@est.tech>2021-08-10 21:51:48 +0100
committerSirisha_Manchikanti <sirisha.manchikanti@est.tech>2021-08-18 14:58:42 +0100
commitd0a1bcee60c43a736a0526d49c07c564632c4f02 (patch)
tree32d46f33307a9bb65215a1f52eb626ae7db3d1ee /participant/participant-impl/participant-impl-http
parenta37bd982693785af5fc791df0baaa49dda039846 (diff)
Updated ControlLoop component messages
Updated controlloop messages (ParticipantUpdate, ControlLoopUpdate, ParticipantStatus) according to the following Wiki and added implementation for the corresponding updates in runtime-controlloop and participant components https://wiki.onap.org/display/DW/The+CLAMP+Control+Loop+Participant+Protocol Issue-ID: POLICY-3417 Signed-off-by: Sirisha_Manchikanti <sirisha.manchikanti@est.tech> Change-Id: I80d96a7553a89ca47de2aa35e09df5a5c792acfa
Diffstat (limited to 'participant/participant-impl/participant-impl-http')
-rw-r--r--participant/participant-impl/participant-impl-http/src/main/java/org/onap/policy/clamp/controlloop/participant/http/main/handler/ControlLoopElementHandler.java35
-rw-r--r--participant/participant-impl/participant-impl-http/src/test/java/handler/ClElementHandlerTest.java10
2 files changed, 22 insertions, 23 deletions
diff --git a/participant/participant-impl/participant-impl-http/src/main/java/org/onap/policy/clamp/controlloop/participant/http/main/handler/ControlLoopElementHandler.java b/participant/participant-impl/participant-impl-http/src/main/java/org/onap/policy/clamp/controlloop/participant/http/main/handler/ControlLoopElementHandler.java
index 67948a95c..f18885f0f 100644
--- a/participant/participant-impl/participant-impl-http/src/main/java/org/onap/policy/clamp/controlloop/participant/http/main/handler/ControlLoopElementHandler.java
+++ b/participant/participant-impl/participant-impl-http/src/main/java/org/onap/policy/clamp/controlloop/participant/http/main/handler/ControlLoopElementHandler.java
@@ -32,7 +32,6 @@ import java.util.concurrent.Executors;
import javax.validation.ConstraintViolation;
import javax.validation.Validation;
import javax.validation.ValidationException;
-import lombok.Getter;
import lombok.Setter;
import org.apache.commons.lang3.tuple.Pair;
import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopElement;
@@ -48,7 +47,6 @@ import org.onap.policy.common.utils.coder.StandardCoder;
import org.onap.policy.models.base.PfModelException;
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.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
@@ -99,29 +97,22 @@ public class ControlLoopElementHandler implements ControlLoopElementListener, Cl
* Callback method to handle an update on a control loop element.
*
* @param element the information on the control loop element
- * @param controlLoopDefinition toscaServiceTemplate
+ * @param nodeTemplate toscaNodeTemplate
*/
@Override
- public void controlLoopElementUpdate(ControlLoopElement element, ToscaServiceTemplate controlLoopDefinition) {
-
- for (Map.Entry<String, ToscaNodeTemplate> nodeTemplate : controlLoopDefinition.getToscaTopologyTemplate()
- .getNodeTemplates().entrySet()) {
- // Fetching the node template of corresponding CL element
- if (element.getDefinition().getName().equals(nodeTemplate.getKey())) {
- try {
- var configRequest = CODER.convert(nodeTemplate.getValue().getProperties(), ConfigRequest.class);
- Set<ConstraintViolation<ConfigRequest>> violations = Validation.buildDefaultValidatorFactory()
- .getValidator().validate(configRequest);
- if (violations.isEmpty()) {
- invokeHttpClient(configRequest);
- } else {
- LOGGER.error("Violations found in the config request parameters: {}", violations);
- throw new ValidationException("Constraint violations in the config request");
- }
- } catch (CoderException | ValidationException e) {
- LOGGER.error("Error invoking the http request for the config ", e);
- }
+ public void controlLoopElementUpdate(ControlLoopElement element, ToscaNodeTemplate nodeTemplate) {
+ try {
+ var configRequest = CODER.convert(nodeTemplate.getProperties(), ConfigRequest.class);
+ Set<ConstraintViolation<ConfigRequest>> violations = Validation.buildDefaultValidatorFactory()
+ .getValidator().validate(configRequest);
+ if (violations.isEmpty()) {
+ invokeHttpClient(configRequest);
+ } else {
+ LOGGER.error("Violations found in the config request parameters: {}", violations);
+ throw new ValidationException("Constraint violations in the config request");
}
+ } catch (CoderException | ValidationException e) {
+ LOGGER.error("Error invoking the http request for the config ", e);
}
}
diff --git a/participant/participant-impl/participant-impl-http/src/test/java/handler/ClElementHandlerTest.java b/participant/participant-impl/participant-impl-http/src/test/java/handler/ClElementHandlerTest.java
index 10b8103cb..46ed355de 100644
--- a/participant/participant-impl/participant-impl-http/src/test/java/handler/ClElementHandlerTest.java
+++ b/participant/participant-impl/participant-impl-http/src/test/java/handler/ClElementHandlerTest.java
@@ -24,6 +24,7 @@ import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doNothing;
+import java.util.Map;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
@@ -32,6 +33,7 @@ import org.mockito.Spy;
import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopElement;
import org.onap.policy.clamp.controlloop.participant.http.main.handler.ControlLoopElementHandler;
import org.onap.policy.common.utils.coder.CoderException;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import utils.CommonTestData;
@@ -47,6 +49,8 @@ class ClElementHandlerTest {
private CommonTestData commonTestData = new CommonTestData();
private static ToscaServiceTemplate serviceTemplate;
+ private static final String HTTP_CONTROL_LOOP_ELEMENT =
+ "org.onap.domain.database.Http_PMSHMicroserviceControlLoopElement";
@BeforeAll
static void init() throws CoderException {
@@ -57,7 +61,11 @@ class ClElementHandlerTest {
void test_ControlLoopElementUpdate() {
doNothing().when(controlLoopElementHandler).invokeHttpClient(any());
ControlLoopElement element = commonTestData.getControlLoopElement();
+
+ Map<String, ToscaNodeTemplate> nodeTemplatesMap =
+ serviceTemplate.getToscaTopologyTemplate().getNodeTemplates();
+
assertDoesNotThrow(() -> controlLoopElementHandler
- .controlLoopElementUpdate(element, serviceTemplate));
+ .controlLoopElementUpdate(element, nodeTemplatesMap.get(HTTP_CONTROL_LOOP_ELEMENT)));
}
}