summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--participant/participant-impl/participant-impl-dcae/src/main/java/org/onap/policy/clamp/controlloop/participant/dcae/config/ParticipantConfig.java16
-rw-r--r--participant/participant-impl/participant-impl-dcae/src/main/java/org/onap/policy/clamp/controlloop/participant/dcae/main/parameters/ParticipantDcaeParameters.java3
-rw-r--r--participant/participant-impl/participant-impl-dcae/src/test/java/org/onap/policy/clamp/controlloop/participant/dcae/endtoend/PartecipantDcaeTest.java30
-rw-r--r--participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/controlloop/participant/kubernetes/configurations/ParticipantIntermediaryConfig.java19
-rw-r--r--participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/controlloop/participant/kubernetes/handler/ControlLoopElementHandler.java3
-rw-r--r--participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/controlloop/participant/kubernetes/parameters/ParticipantK8sParameters.java3
-rw-r--r--participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/controlloop/participant/policy/config/ParticipantConfig.java24
-rw-r--r--participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/controlloop/participant/policy/main/parameters/ParticipantPolicyParameters.java4
-rw-r--r--participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/controlloop/participant/policy/endtoend/ParticipantPolicyTest.java28
-rw-r--r--participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/ParticipantSimulatorApplication.java3
-rw-r--r--participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/config/ParticipantConfig.java16
-rw-r--r--participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/main/parameters/ParticipantSimulatorParameters.java11
-rw-r--r--participant/participant-impl/participant-impl-simulator/src/main/resources/config/application.yaml8
-rw-r--r--participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/controlloop/participant/simulator/endtoend/ParticipantSimulatorTest.java6
-rw-r--r--participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/controlloop/participant/simulator/main/parameters/CommonTestData.java23
-rw-r--r--participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/controlloop/participant/simulator/main/parameters/TestParticipantSimulatorParameters.java7
-rw-r--r--participant/participant-impl/participant-impl-simulator/src/test/resources/application_test.properties7
-rw-r--r--participant/participant-intermediary/pom.xml7
-rw-r--r--participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/api/ParticipantIntermediaryApi.java21
-rw-r--r--participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/api/impl/ParticipantIntermediaryApiImpl.java53
-rw-r--r--participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/comm/ControlLoopStateChangeListener.java36
-rw-r--r--participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/comm/ControlLoopUpdateListener.java34
-rw-r--r--participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/comm/ParticipantHealthCheckListener.java36
-rw-r--r--participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/comm/ParticipantListener.java57
-rw-r--r--participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/comm/ParticipantStateChangeListener.java34
-rw-r--r--participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/comm/ParticipantStatusPublisher.java8
-rw-r--r--participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/config/BeanFactory.java55
-rw-r--r--participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/ControlLoopHandler.java8
-rw-r--r--participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/IntermediaryActivator.java139
-rw-r--r--participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/ParticipantHandler.java46
-rw-r--r--participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/parameters/ParticipantParameters.java (renamed from participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/api/ParticipantIntermediaryFactory.java)18
31 files changed, 318 insertions, 445 deletions
diff --git a/participant/participant-impl/participant-impl-dcae/src/main/java/org/onap/policy/clamp/controlloop/participant/dcae/config/ParticipantConfig.java b/participant/participant-impl/participant-impl-dcae/src/main/java/org/onap/policy/clamp/controlloop/participant/dcae/config/ParticipantConfig.java
index ff828abab..965c3f143 100644
--- a/participant/participant-impl/participant-impl-dcae/src/main/java/org/onap/policy/clamp/controlloop/participant/dcae/config/ParticipantConfig.java
+++ b/participant/participant-impl/participant-impl-dcae/src/main/java/org/onap/policy/clamp/controlloop/participant/dcae/config/ParticipantConfig.java
@@ -21,29 +21,23 @@
package org.onap.policy.clamp.controlloop.participant.dcae.config;
import org.onap.policy.clamp.controlloop.participant.dcae.main.handler.ControlLoopElementHandler;
-import org.onap.policy.clamp.controlloop.participant.dcae.main.parameters.ParticipantDcaeParameters;
import org.onap.policy.clamp.controlloop.participant.intermediary.api.ParticipantIntermediaryApi;
-import org.onap.policy.clamp.controlloop.participant.intermediary.api.ParticipantIntermediaryFactory;
-import org.springframework.context.annotation.Bean;
+import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
@Configuration
public class ParticipantConfig {
/**
- * Create ParticipantIntermediaryApi.
+ * Register ControlLoopElementListener.
*
- * @param parameters the Participant Dcae Parameters
+ * @param intermediaryApi the ParticipantIntermediaryApi
* @param clElementHandler the ControlLoop Element Handler
- * @return ParticipantIntermediaryApi
*/
- @Bean
- public ParticipantIntermediaryApi participantIntermediaryApi(ParticipantDcaeParameters parameters,
+ @Autowired
+ public void registerControlLoopElementListener(ParticipantIntermediaryApi intermediaryApi,
ControlLoopElementHandler clElementHandler) {
- ParticipantIntermediaryApi intermediaryApi = new ParticipantIntermediaryFactory().createApiImplementation();
- intermediaryApi.init(parameters.getIntermediaryParameters());
intermediaryApi.registerControlLoopElementListener(clElementHandler);
clElementHandler.setIntermediaryApi(intermediaryApi);
- return intermediaryApi;
}
}
diff --git a/participant/participant-impl/participant-impl-dcae/src/main/java/org/onap/policy/clamp/controlloop/participant/dcae/main/parameters/ParticipantDcaeParameters.java b/participant/participant-impl/participant-impl-dcae/src/main/java/org/onap/policy/clamp/controlloop/participant/dcae/main/parameters/ParticipantDcaeParameters.java
index 798781177..1ef9e2fdd 100644
--- a/participant/participant-impl/participant-impl-dcae/src/main/java/org/onap/policy/clamp/controlloop/participant/dcae/main/parameters/ParticipantDcaeParameters.java
+++ b/participant/participant-impl/participant-impl-dcae/src/main/java/org/onap/policy/clamp/controlloop/participant/dcae/main/parameters/ParticipantDcaeParameters.java
@@ -27,6 +27,7 @@ import javax.validation.constraints.NotNull;
import lombok.Getter;
import lombok.Setter;
import org.onap.policy.clamp.controlloop.participant.intermediary.parameters.ParticipantIntermediaryParameters;
+import org.onap.policy.clamp.controlloop.participant.intermediary.parameters.ParticipantParameters;
import org.onap.policy.common.endpoints.parameters.RestClientParameters;
import org.onap.policy.common.parameters.validation.ParameterGroupConstraint;
import org.springframework.boot.context.properties.ConfigurationProperties;
@@ -40,7 +41,7 @@ import org.springframework.validation.annotation.Validated;
@Getter
@Setter
@ConfigurationProperties(prefix = "participant")
-public class ParticipantDcaeParameters {
+public class ParticipantDcaeParameters implements ParticipantParameters {
@NotNull
@Min(10)
diff --git a/participant/participant-impl/participant-impl-dcae/src/test/java/org/onap/policy/clamp/controlloop/participant/dcae/endtoend/PartecipantDcaeTest.java b/participant/participant-impl/participant-impl-dcae/src/test/java/org/onap/policy/clamp/controlloop/participant/dcae/endtoend/PartecipantDcaeTest.java
index 46317729a..a96581e6c 100644
--- a/participant/participant-impl/participant-impl-dcae/src/test/java/org/onap/policy/clamp/controlloop/participant/dcae/endtoend/PartecipantDcaeTest.java
+++ b/participant/participant-impl/participant-impl-dcae/src/test/java/org/onap/policy/clamp/controlloop/participant/dcae/endtoend/PartecipantDcaeTest.java
@@ -35,9 +35,9 @@ import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.Parti
import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantControlLoopUpdate;
import org.onap.policy.clamp.controlloop.participant.dcae.main.parameters.CommonTestData;
import org.onap.policy.clamp.controlloop.participant.dcae.main.rest.TestListenerUtils;
-import org.onap.policy.clamp.controlloop.participant.intermediary.api.ParticipantIntermediaryApi;
import org.onap.policy.clamp.controlloop.participant.intermediary.comm.ControlLoopStateChangeListener;
import org.onap.policy.clamp.controlloop.participant.intermediary.comm.ControlLoopUpdateListener;
+import org.onap.policy.clamp.controlloop.participant.intermediary.handler.ParticipantHandler;
import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
import org.onap.policy.common.utils.coder.CoderException;
import org.springframework.beans.factory.annotation.Autowired;
@@ -61,7 +61,7 @@ class PartecipantDcaeTest {
private static ClientAndServer mockConsulServer;
@Autowired
- private ParticipantIntermediaryApi participantIntermediaryApi;
+ private ParticipantHandler participantHandler;
/**
* start Servers.
@@ -107,8 +107,7 @@ class PartecipantDcaeTest {
TestListenerUtils.createControlLoopStateChangeMsg(ControlLoopOrderedState.UNINITIALISED);
participantControlLoopStateChangeMsg.setOrderedState(ControlLoopOrderedState.PASSIVE);
- ControlLoopStateChangeListener clStateChangeListener =
- new ControlLoopStateChangeListener(participantIntermediaryApi.getParticipantHandler());
+ ControlLoopStateChangeListener clStateChangeListener = new ControlLoopStateChangeListener(participantHandler);
clStateChangeListener.onTopicEvent(INFRA, TOPIC, null, participantControlLoopStateChangeMsg);
assertEquals(ControlLoopOrderedState.PASSIVE, participantControlLoopStateChangeMsg.getOrderedState());
@@ -128,13 +127,12 @@ class PartecipantDcaeTest {
participantControlLoopUpdateMsg.getParticipantId().setName("DummyName");
participantControlLoopUpdateMsg.getControlLoop().setOrderedState(ControlLoopOrderedState.PASSIVE);
- ControlLoopUpdateListener clUpdateListener =
- new ControlLoopUpdateListener(participantIntermediaryApi.getParticipantHandler());
+ ControlLoopUpdateListener clUpdateListener = new ControlLoopUpdateListener(participantHandler);
clUpdateListener.onTopicEvent(INFRA, TOPIC, null, participantControlLoopUpdateMsg);
// Verify the content in participantHandler
assertNotEquals(participantControlLoopUpdateMsg.getParticipantId().getName(),
- participantIntermediaryApi.getParticipantHandler().getParticipantId().getName());
+ participantHandler.getParticipantId().getName());
}
@Test
@@ -142,15 +140,12 @@ class PartecipantDcaeTest {
ParticipantControlLoopUpdate participantControlLoopUpdateMsg = TestListenerUtils.createControlLoopUpdateMsg();
participantControlLoopUpdateMsg.getControlLoop().setOrderedState(ControlLoopOrderedState.PASSIVE);
- ControlLoopUpdateListener clUpdateListener =
- new ControlLoopUpdateListener(participantIntermediaryApi.getParticipantHandler());
+ ControlLoopUpdateListener clUpdateListener = new ControlLoopUpdateListener(participantHandler);
clUpdateListener.onTopicEvent(INFRA, TOPIC, null, participantControlLoopUpdateMsg);
// Verify the content in participantHandler
- assertEquals(participantIntermediaryApi.getParticipantHandler().getParticipantId(),
- participantControlLoopUpdateMsg.getParticipantId());
- assertEquals(1, participantIntermediaryApi.getParticipantHandler().getControlLoopHandler().getControlLoops()
- .getControlLoopList().size());
+ assertEquals(participantHandler.getParticipantId(), participantControlLoopUpdateMsg.getParticipantId());
+ assertEquals(1, participantHandler.getControlLoopHandler().getControlLoops().getControlLoopList().size());
}
@Test
@@ -158,14 +153,11 @@ class PartecipantDcaeTest {
ParticipantControlLoopUpdate participantControlLoopUpdateMsg = TestListenerUtils.createControlLoopUpdateMsg();
participantControlLoopUpdateMsg.getControlLoop().setOrderedState(ControlLoopOrderedState.UNINITIALISED);
- ControlLoopUpdateListener clUpdateListener =
- new ControlLoopUpdateListener(participantIntermediaryApi.getParticipantHandler());
+ ControlLoopUpdateListener clUpdateListener = new ControlLoopUpdateListener(participantHandler);
clUpdateListener.onTopicEvent(INFRA, TOPIC, null, participantControlLoopUpdateMsg);
// Verify the content in participantHandler
- assertEquals(participantIntermediaryApi.getParticipantHandler().getParticipantId(),
- participantControlLoopUpdateMsg.getParticipantId());
- assertEquals(1, participantIntermediaryApi.getParticipantHandler().getControlLoopHandler().getControlLoops()
- .getControlLoopList().size());
+ assertEquals(participantHandler.getParticipantId(), participantControlLoopUpdateMsg.getParticipantId());
+ assertEquals(1, participantHandler.getControlLoopHandler().getControlLoops().getControlLoopList().size());
}
}
diff --git a/participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/controlloop/participant/kubernetes/configurations/ParticipantIntermediaryConfig.java b/participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/controlloop/participant/kubernetes/configurations/ParticipantIntermediaryConfig.java
index d8c39925b..bfbed66b7 100644
--- a/participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/controlloop/participant/kubernetes/configurations/ParticipantIntermediaryConfig.java
+++ b/participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/controlloop/participant/kubernetes/configurations/ParticipantIntermediaryConfig.java
@@ -21,28 +21,23 @@
package org.onap.policy.clamp.controlloop.participant.kubernetes.configurations;
import org.onap.policy.clamp.controlloop.participant.intermediary.api.ParticipantIntermediaryApi;
-import org.onap.policy.clamp.controlloop.participant.intermediary.api.ParticipantIntermediaryFactory;
import org.onap.policy.clamp.controlloop.participant.kubernetes.handler.ControlLoopElementHandler;
-import org.onap.policy.clamp.controlloop.participant.kubernetes.parameters.ParticipantK8sParameters;
-import org.springframework.context.annotation.Bean;
+import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
@Configuration
public class ParticipantIntermediaryConfig {
/**
- * Create ParticipantIntermediaryApi.
+ * Register ControlLoopElementListener.
*
- * @param parameters the K8s Participant Parameters
+ * @param intermediaryApi the ParticipantIntermediaryApi
* @param clElementHandler the ControlLoop Element Handler
- * @return ParticipantIntermediaryApi
*/
- @Bean
- public ParticipantIntermediaryApi participantIntermediaryApi(ParticipantK8sParameters parameters,
- ControlLoopElementHandler clElementHandler) {
- ParticipantIntermediaryApi intermediaryApi = new ParticipantIntermediaryFactory().createApiImplementation();
- intermediaryApi.init(parameters.getIntermediaryParameters());
+ @Autowired
+ public void registerControlLoopElementListener(ParticipantIntermediaryApi intermediaryApi,
+ ControlLoopElementHandler clElementHandler) {
intermediaryApi.registerControlLoopElementListener(clElementHandler);
- return intermediaryApi;
+ clElementHandler.setIntermediaryApi(intermediaryApi);
}
}
diff --git a/participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/controlloop/participant/kubernetes/handler/ControlLoopElementHandler.java b/participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/controlloop/participant/kubernetes/handler/ControlLoopElementHandler.java
index 5f1dcb8d4..6257c3d19 100644
--- a/participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/controlloop/participant/kubernetes/handler/ControlLoopElementHandler.java
+++ b/participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/controlloop/participant/kubernetes/handler/ControlLoopElementHandler.java
@@ -26,6 +26,7 @@ import java.lang.invoke.MethodHandles;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
+import lombok.Setter;
import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopElement;
import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopOrderedState;
import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopState;
@@ -52,7 +53,7 @@ public class ControlLoopElementHandler implements ControlLoopElementListener {
@Autowired
private ChartService chartService;
- @Autowired
+ @Setter
private ParticipantIntermediaryApi intermediaryApi;
// Map of CLElement Id and installed Helm charts
diff --git a/participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/controlloop/participant/kubernetes/parameters/ParticipantK8sParameters.java b/participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/controlloop/participant/kubernetes/parameters/ParticipantK8sParameters.java
index 54eb3b225..a5731da74 100644
--- a/participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/controlloop/participant/kubernetes/parameters/ParticipantK8sParameters.java
+++ b/participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/controlloop/participant/kubernetes/parameters/ParticipantK8sParameters.java
@@ -25,6 +25,7 @@ import javax.validation.constraints.NotNull;
import lombok.Getter;
import lombok.Setter;
import org.onap.policy.clamp.controlloop.participant.intermediary.parameters.ParticipantIntermediaryParameters;
+import org.onap.policy.clamp.controlloop.participant.intermediary.parameters.ParticipantParameters;
import org.onap.policy.common.parameters.annotations.Valid;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.validation.annotation.Validated;
@@ -37,7 +38,7 @@ import org.springframework.validation.annotation.Validated;
@Getter
@Setter
@ConfigurationProperties(prefix = "participant")
-public class ParticipantK8sParameters {
+public class ParticipantK8sParameters implements ParticipantParameters {
@NotNull
@Valid
diff --git a/participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/controlloop/participant/policy/config/ParticipantConfig.java b/participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/controlloop/participant/policy/config/ParticipantConfig.java
index 3b8324151..7b49a9a6b 100644
--- a/participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/controlloop/participant/policy/config/ParticipantConfig.java
+++ b/participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/controlloop/participant/policy/config/ParticipantConfig.java
@@ -21,29 +21,23 @@
package org.onap.policy.clamp.controlloop.participant.policy.config;
import org.onap.policy.clamp.controlloop.participant.intermediary.api.ParticipantIntermediaryApi;
-import org.onap.policy.clamp.controlloop.participant.intermediary.api.ParticipantIntermediaryFactory;
import org.onap.policy.clamp.controlloop.participant.policy.main.handler.ControlLoopElementHandler;
-import org.onap.policy.clamp.controlloop.participant.policy.main.parameters.ParticipantPolicyParameters;
-import org.springframework.context.annotation.Bean;
+import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
@Configuration
public class ParticipantConfig {
/**
- * Create ParticipantIntermediaryApi.
+ * Register ControlLoopElementListener.
*
- * @param parameters the Participant Policy Parameters
- * @param controlLoopElementHandler the ControlLoop Element Handler
- * @return ParticipantIntermediaryApi
+ * @param intermediaryApi the ParticipantIntermediaryApi
+ * @param clElementHandler the ControlLoop Element Handler
*/
- @Bean
- public ParticipantIntermediaryApi participantIntermediaryApi(ParticipantPolicyParameters parameters,
- ControlLoopElementHandler controlLoopElementHandler) {
- ParticipantIntermediaryApi intermediaryApi = new ParticipantIntermediaryFactory().createApiImplementation();
- intermediaryApi.init(parameters.getIntermediaryParameters());
- intermediaryApi.registerControlLoopElementListener(controlLoopElementHandler);
- controlLoopElementHandler.setIntermediaryApi(intermediaryApi);
- return intermediaryApi;
+ @Autowired
+ public void registerControlLoopElementListener(ParticipantIntermediaryApi intermediaryApi,
+ ControlLoopElementHandler clElementHandler) {
+ intermediaryApi.registerControlLoopElementListener(clElementHandler);
+ clElementHandler.setIntermediaryApi(intermediaryApi);
}
}
diff --git a/participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/controlloop/participant/policy/main/parameters/ParticipantPolicyParameters.java b/participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/controlloop/participant/policy/main/parameters/ParticipantPolicyParameters.java
index 91f7ae47f..ced9d1bd0 100644
--- a/participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/controlloop/participant/policy/main/parameters/ParticipantPolicyParameters.java
+++ b/participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/controlloop/participant/policy/main/parameters/ParticipantPolicyParameters.java
@@ -25,12 +25,12 @@ import javax.validation.constraints.NotNull;
import lombok.Getter;
import lombok.Setter;
import org.onap.policy.clamp.controlloop.participant.intermediary.parameters.ParticipantIntermediaryParameters;
+import org.onap.policy.clamp.controlloop.participant.intermediary.parameters.ParticipantParameters;
import org.onap.policy.common.endpoints.parameters.RestClientParameters;
import org.onap.policy.common.parameters.validation.ParameterGroupConstraint;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.validation.annotation.Validated;
-
/**
* Class to hold all parameters needed for the policy participant.
*
@@ -39,7 +39,7 @@ import org.springframework.validation.annotation.Validated;
@Getter
@Setter
@ConfigurationProperties(prefix = "participant")
-public class ParticipantPolicyParameters {
+public class ParticipantPolicyParameters implements ParticipantParameters {
@NotNull
@Valid
diff --git a/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/controlloop/participant/policy/endtoend/ParticipantPolicyTest.java b/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/controlloop/participant/policy/endtoend/ParticipantPolicyTest.java
index d34a38103..6b8323971 100644
--- a/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/controlloop/participant/policy/endtoend/ParticipantPolicyTest.java
+++ b/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/controlloop/participant/policy/endtoend/ParticipantPolicyTest.java
@@ -28,9 +28,9 @@ import org.junit.jupiter.api.extension.ExtendWith;
import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopOrderedState;
import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantControlLoopStateChange;
import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantControlLoopUpdate;
-import org.onap.policy.clamp.controlloop.participant.intermediary.api.ParticipantIntermediaryApi;
import org.onap.policy.clamp.controlloop.participant.intermediary.comm.ControlLoopStateChangeListener;
import org.onap.policy.clamp.controlloop.participant.intermediary.comm.ControlLoopUpdateListener;
+import org.onap.policy.clamp.controlloop.participant.intermediary.handler.ParticipantHandler;
import org.onap.policy.clamp.controlloop.participant.policy.main.utils.TestListenerUtils;
import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
import org.springframework.beans.factory.annotation.Autowired;
@@ -49,7 +49,7 @@ class ParticipantPolicyTest {
private static final String TOPIC = "my-topic";
@Autowired
- private ParticipantIntermediaryApi participantIntermediaryApi;
+ private ParticipantHandler participantHandler;
@Test
void testUpdatePolicyTypes() {
@@ -60,14 +60,12 @@ class ParticipantPolicyTest {
assertNotNull(participantControlLoopUpdateMsg.getControlLoopDefinition().getPolicyTypes());
synchronized (lockit) {
- ControlLoopUpdateListener clUpdateListener =
- new ControlLoopUpdateListener(participantIntermediaryApi.getParticipantHandler());
+ ControlLoopUpdateListener clUpdateListener = new ControlLoopUpdateListener(participantHandler);
clUpdateListener.onTopicEvent(INFRA, TOPIC, null, participantControlLoopUpdateMsg);
}
// Verify the result of GET participants with what is stored
- assertEquals("org.onap.PM_Policy",
- participantIntermediaryApi.getParticipantHandler().getParticipantId().getName());
+ assertEquals("org.onap.PM_Policy", participantHandler.getParticipantId().getName());
}
@Test
@@ -83,14 +81,12 @@ class ParticipantPolicyTest {
participantControlLoopUpdateMsg.getControlLoopDefinition().getToscaTopologyTemplate().getPolicies());
synchronized (lockit) {
- ControlLoopUpdateListener clUpdateListener =
- new ControlLoopUpdateListener(participantIntermediaryApi.getParticipantHandler());
+ ControlLoopUpdateListener clUpdateListener = new ControlLoopUpdateListener(participantHandler);
clUpdateListener.onTopicEvent(INFRA, TOPIC, null, participantControlLoopUpdateMsg);
}
// Verify the result of GET participants with what is stored
- assertEquals("org.onap.PM_Policy",
- participantIntermediaryApi.getParticipantHandler().getParticipantId().getName());
+ assertEquals("org.onap.PM_Policy", participantHandler.getParticipantId().getName());
}
@Test
@@ -106,24 +102,20 @@ class ParticipantPolicyTest {
participantControlLoopUpdateMsg.getControlLoopDefinition().getToscaTopologyTemplate().getPolicies());
synchronized (lockit) {
- ControlLoopUpdateListener clUpdateListener =
- new ControlLoopUpdateListener(participantIntermediaryApi.getParticipantHandler());
+ ControlLoopUpdateListener clUpdateListener = new ControlLoopUpdateListener(participantHandler);
clUpdateListener.onTopicEvent(INFRA, TOPIC, null, participantControlLoopUpdateMsg);
}
// Verify the result of GET participants with what is stored
- assertEquals("org.onap.PM_Policy",
- participantIntermediaryApi.getParticipantHandler().getParticipantId().getName());
+ assertEquals("org.onap.PM_Policy", participantHandler.getParticipantId().getName());
- ControlLoopStateChangeListener clStateChangeListener =
- new ControlLoopStateChangeListener(participantIntermediaryApi.getParticipantHandler());
+ ControlLoopStateChangeListener clStateChangeListener = new ControlLoopStateChangeListener(participantHandler);
ParticipantControlLoopStateChange participantControlLoopStateChangeMsg =
TestListenerUtils.createControlLoopStateChangeMsg(ControlLoopOrderedState.UNINITIALISED);
participantControlLoopStateChangeMsg.setOrderedState(ControlLoopOrderedState.UNINITIALISED);
clStateChangeListener.onTopicEvent(INFRA, TOPIC, null, participantControlLoopStateChangeMsg);
// Verify the result of GET participants with what is stored
- assertEquals("org.onap.PM_Policy",
- participantIntermediaryApi.getParticipantHandler().getParticipantId().getName());
+ assertEquals("org.onap.PM_Policy", participantHandler.getParticipantId().getName());
}
}
diff --git a/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/ParticipantSimulatorApplication.java b/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/ParticipantSimulatorApplication.java
index 9f6e4aa4b..8267df477 100644
--- a/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/ParticipantSimulatorApplication.java
+++ b/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/ParticipantSimulatorApplication.java
@@ -23,6 +23,7 @@ package org.onap.policy.clamp.controlloop.participant.simulator;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.ConfigurationPropertiesScan;
+import org.springframework.context.annotation.ComponentScan;
/**
* Starter.
@@ -30,6 +31,8 @@ import org.springframework.boot.context.properties.ConfigurationPropertiesScan;
*/
@SpringBootApplication
@ConfigurationPropertiesScan("org.onap.policy.clamp.controlloop.participant.simulator.main.parameters")
+@ComponentScan({"org.onap.policy.clamp.controlloop.participant.simulator",
+ "org.onap.policy.clamp.controlloop.participant.intermediary"})
public class ParticipantSimulatorApplication {
public static void main(String[] args) {
diff --git a/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/config/ParticipantConfig.java b/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/config/ParticipantConfig.java
index f4e6791ec..c890ec247 100644
--- a/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/config/ParticipantConfig.java
+++ b/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/config/ParticipantConfig.java
@@ -20,9 +20,6 @@
package org.onap.policy.clamp.controlloop.participant.simulator.config;
-import org.onap.policy.clamp.controlloop.participant.intermediary.api.ParticipantIntermediaryApi;
-import org.onap.policy.clamp.controlloop.participant.intermediary.api.ParticipantIntermediaryFactory;
-import org.onap.policy.clamp.controlloop.participant.simulator.main.parameters.ParticipantSimulatorParameters;
import org.onap.policy.clamp.controlloop.participant.simulator.main.rest.RequestResponseLoggingFilter;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
@@ -32,19 +29,6 @@ import org.springframework.context.annotation.Configuration;
public class ParticipantConfig {
/**
- * Create ParticipantIntermediaryApi.
- *
- * @param parameters the Participant Dcae Parameters
- * @return ParticipantIntermediaryApi
- */
- @Bean
- public ParticipantIntermediaryApi participantIntermediaryApi(ParticipantSimulatorParameters parameters) {
- ParticipantIntermediaryApi intermediaryApi = new ParticipantIntermediaryFactory().createApiImplementation();
- intermediaryApi.init(parameters.getIntermediaryParameters());
- return intermediaryApi;
- }
-
- /**
* logging Filter configuration.
*
* @return FilterRegistrationBean
diff --git a/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/main/parameters/ParticipantSimulatorParameters.java b/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/main/parameters/ParticipantSimulatorParameters.java
index 5110ac6a6..99579006c 100644
--- a/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/main/parameters/ParticipantSimulatorParameters.java
+++ b/participant/participant-impl/participant-impl-simulator/src/main/java/org/onap/policy/clamp/controlloop/participant/simulator/main/parameters/ParticipantSimulatorParameters.java
@@ -25,8 +25,7 @@ import javax.validation.constraints.NotNull;
import lombok.Getter;
import lombok.Setter;
import org.onap.policy.clamp.controlloop.participant.intermediary.parameters.ParticipantIntermediaryParameters;
-import org.onap.policy.common.parameters.validation.ParameterGroupConstraint;
-import org.onap.policy.models.provider.PolicyModelsProviderParameters;
+import org.onap.policy.clamp.controlloop.participant.intermediary.parameters.ParticipantParameters;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.validation.annotation.Validated;
@@ -38,13 +37,9 @@ import org.springframework.validation.annotation.Validated;
@Getter
@Setter
@ConfigurationProperties(prefix = "participant")
-public class ParticipantSimulatorParameters {
+public class ParticipantSimulatorParameters implements ParticipantParameters {
- @NotNull
@Valid
- private ParticipantIntermediaryParameters intermediaryParameters;
-
@NotNull
- @ParameterGroupConstraint
- private PolicyModelsProviderParameters databaseProviderParameters;
+ private ParticipantIntermediaryParameters intermediaryParameters;
}
diff --git a/participant/participant-impl/participant-impl-simulator/src/main/resources/config/application.yaml b/participant/participant-impl/participant-impl-simulator/src/main/resources/config/application.yaml
index a45636b34..82e3b89f1 100644
--- a/participant/participant-impl/participant-impl-simulator/src/main/resources/config/application.yaml
+++ b/participant/participant-impl/participant-impl-simulator/src/main/resources/config/application.yaml
@@ -35,11 +35,3 @@ participant:
topic: POLICY-NOTIFICATION
servers[0]: ${topicServer:message-router}
topicCommInfrastructure: dmaap
- databaseProviderParameters:
- name: PolicyProviderParameterGroup
- implementation: org.onap.policy.models.provider.impl.DatabasePolicyModelsProviderImpl
- databaseDriver: org.mariadb.jdbc.Driver
- databaseUrl: jdbc:mariadb://mariadb:3306/cdsparticipantsim
- databaseUser: policy
- databasePassword: P01icY
- persistenceUnit: ToscaConceptTest
diff --git a/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/controlloop/participant/simulator/endtoend/ParticipantSimulatorTest.java b/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/controlloop/participant/simulator/endtoend/ParticipantSimulatorTest.java
index 46495f7c3..0b63c395a 100644
--- a/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/controlloop/participant/simulator/endtoend/ParticipantSimulatorTest.java
+++ b/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/controlloop/participant/simulator/endtoend/ParticipantSimulatorTest.java
@@ -40,6 +40,7 @@ import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.Parti
import org.onap.policy.clamp.controlloop.models.messages.rest.TypedSimpleResponse;
import org.onap.policy.clamp.controlloop.participant.intermediary.api.ParticipantIntermediaryApi;
import org.onap.policy.clamp.controlloop.participant.intermediary.comm.ControlLoopUpdateListener;
+import org.onap.policy.clamp.controlloop.participant.intermediary.handler.ParticipantHandler;
import org.onap.policy.clamp.controlloop.participant.simulator.main.parameters.CommonTestData;
import org.onap.policy.clamp.controlloop.participant.simulator.main.rest.AbstractRestController;
import org.onap.policy.clamp.controlloop.participant.simulator.main.rest.TestListenerUtils;
@@ -89,6 +90,9 @@ class ParticipantSimulatorTest {
@Autowired
private ParticipantIntermediaryApi participantIntermediaryApi;
+ @Autowired
+ private ParticipantHandler participantHandler;
+
private static final Object lockit = new Object();
private boolean check = false;
@@ -97,7 +101,7 @@ class ParticipantSimulatorTest {
if (!check) {
check = true;
ControlLoopUpdateListener clUpdateListener =
- new ControlLoopUpdateListener(participantIntermediaryApi.getParticipantHandler());
+ new ControlLoopUpdateListener(participantHandler);
ParticipantControlLoopUpdate participantControlLoopUpdateMsg =
TestListenerUtils.createControlLoopUpdateMsg();
diff --git a/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/controlloop/participant/simulator/main/parameters/CommonTestData.java b/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/controlloop/participant/simulator/main/parameters/CommonTestData.java
index c53410b28..e85b3ebbe 100644
--- a/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/controlloop/participant/simulator/main/parameters/CommonTestData.java
+++ b/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/controlloop/participant/simulator/main/parameters/CommonTestData.java
@@ -65,30 +65,7 @@ public class CommonTestData {
public Map<String, Object> getParticipantParameterGroupMap(final String name) {
final Map<String, Object> map = new TreeMap<>();
- map.put("name", name);
map.put("intermediaryParameters", getIntermediaryParametersMap(false));
- map.put("databaseProviderParameters", getDatabaseProviderParametersMap(false));
- return map;
- }
-
- /**
- * Returns a property map for a databaseProviderParameters map for test cases.
- *
- * @param isEmpty boolean value to represent that object created should be empty or not
- * @return a property map suitable for constructing an object
- */
- public Map<String, Object> getDatabaseProviderParametersMap(final boolean isEmpty) {
- final Map<String, Object> map = new TreeMap<>();
- if (!isEmpty) {
- map.put("name", "PolicyProviderParameterGroup");
- map.put("implementation", "org.onap.policy.models.provider.impl.DatabasePolicyModelsProviderImpl");
- map.put("databaseDriver", "org.h2.Driver");
- map.put("databaseUrl", "jdbc:h2:mem:testdb");
- map.put("databaseUser", "policy");
- map.put("databasePassword", "P01icY");
- map.put("persistenceUnit", "ToscaConceptTest");
- }
-
return map;
}
diff --git a/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/controlloop/participant/simulator/main/parameters/TestParticipantSimulatorParameters.java b/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/controlloop/participant/simulator/main/parameters/TestParticipantSimulatorParameters.java
index e5c7b5e30..3c1d1c2a3 100644
--- a/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/controlloop/participant/simulator/main/parameters/TestParticipantSimulatorParameters.java
+++ b/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/controlloop/participant/simulator/main/parameters/TestParticipantSimulatorParameters.java
@@ -47,13 +47,6 @@ class TestParticipantSimulatorParameters {
}
@Test
- void testParticipantParameterGroup_EmptyDatabaseProviderParameters() {
- final ParticipantSimulatorParameters participantParameters = commonTestData.getParticipantSimulatorParameters();
- participantParameters.setDatabaseProviderParameters(null);
- assertThat(validatorFactory.getValidator().validate(participantParameters)).isNotEmpty();
- }
-
- @Test
void testParticipantPolicyParameters_NullTopicSinks() {
final ParticipantSimulatorParameters participantParameters = commonTestData.getParticipantSimulatorParameters();
participantParameters.getIntermediaryParameters().getClampControlLoopTopics().setTopicSinks(null);
diff --git a/participant/participant-impl/participant-impl-simulator/src/test/resources/application_test.properties b/participant/participant-impl/participant-impl-simulator/src/test/resources/application_test.properties
index 89c57bb12..2b30c4ffd 100644
--- a/participant/participant-impl/participant-impl-simulator/src/test/resources/application_test.properties
+++ b/participant/participant-impl/participant-impl-simulator/src/test/resources/application_test.properties
@@ -26,10 +26,3 @@ participant.intermediaryParameters.clampControlLoopTopics.topicSinks[0].topicCom
participant.intermediaryParameters.clampControlLoopTopics.topicSinks[1].topic=POLICY-NOTIFICATION
participant.intermediaryParameters.clampControlLoopTopics.topicSinks[1].servers[0]=localhost
participant.intermediaryParameters.clampControlLoopTopics.topicSinks[1].topicCommInfrastructure=dmaap
-participant.databaseProviderParameters.name=PolicyProviderParameterGroup
-participant.databaseProviderParameters.implementation=org.onap.policy.models.provider.impl.DatabasePolicyModelsProviderImpl
-participant.databaseProviderParameters.databaseDriver=org.h2.Driver
-participant.databaseProviderParameters.databaseUrl=jdbc:h2:mem:testdb
-participant.databaseProviderParameters.databaseUser=policy
-participant.databaseProviderParameters.databasePassword=P01icY
-participant.databaseProviderParameters.persistenceUnit=ToscaConceptTest
diff --git a/participant/participant-intermediary/pom.xml b/participant/participant-intermediary/pom.xml
index aac80a4a2..9f754148e 100644
--- a/participant/participant-intermediary/pom.xml
+++ b/participant/participant-intermediary/pom.xml
@@ -33,4 +33,11 @@
<description>Common intermediary library for managing DMaaP participant messaging and holding participant and control
loop state</description>
+ <dependencies>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-webmvc</artifactId>
+ </dependency>
+ </dependencies>
+
</project>
diff --git a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/api/ParticipantIntermediaryApi.java b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/api/ParticipantIntermediaryApi.java
index adc9c2393..a87299bdc 100644
--- a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/api/ParticipantIntermediaryApi.java
+++ b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/api/ParticipantIntermediaryApi.java
@@ -31,25 +31,12 @@ import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoop
import org.onap.policy.clamp.controlloop.models.controlloop.concepts.Participant;
import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantState;
import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantStatistics;
-import org.onap.policy.clamp.controlloop.participant.intermediary.handler.ParticipantHandler;
-import org.onap.policy.clamp.controlloop.participant.intermediary.parameters.ParticipantIntermediaryParameters;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
/**
* This interface is used by participant implementations to use the participant intermediary.
*/
public interface ParticipantIntermediaryApi {
- /**
- * Initialise the participant intermediary.
- *
- * @param parameters the parameters for the intermediary
- */
- void init(ParticipantIntermediaryParameters parameters);
-
- /**
- * Close the intermediary.
- */
- void close();
/**
* Register a listener for control loop elements that are mediated by the intermediary.
@@ -128,12 +115,4 @@ public interface ParticipantIntermediaryApi {
*/
void updateControlLoopElementStatistics(UUID id, ClElementStatistics elementStatistics);
- /**
- * Return participantHandler, This will not be used in real world, but for junits,
- * if participantHandler is not returned, there is no way to test state change messages
- * without dmaap simulator.
- *
- * @return the participant handler
- */
- ParticipantHandler getParticipantHandler();
}
diff --git a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/api/impl/ParticipantIntermediaryApiImpl.java b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/api/impl/ParticipantIntermediaryApiImpl.java
index 839088d72..838f47544 100644
--- a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/api/impl/ParticipantIntermediaryApiImpl.java
+++ b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/api/impl/ParticipantIntermediaryApiImpl.java
@@ -35,45 +35,41 @@ import org.onap.policy.clamp.controlloop.models.controlloop.concepts.Participant
import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantStatistics;
import org.onap.policy.clamp.controlloop.participant.intermediary.api.ControlLoopElementListener;
import org.onap.policy.clamp.controlloop.participant.intermediary.api.ParticipantIntermediaryApi;
-import org.onap.policy.clamp.controlloop.participant.intermediary.handler.IntermediaryActivator;
import org.onap.policy.clamp.controlloop.participant.intermediary.handler.ParticipantHandler;
-import org.onap.policy.clamp.controlloop.participant.intermediary.parameters.ParticipantIntermediaryParameters;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
+import org.springframework.stereotype.Component;
/**
* This class is api implementation used by participant intermediary.
*/
+@Component
public class ParticipantIntermediaryApiImpl implements ParticipantIntermediaryApi {
- // The activator for the participant intermediary
- private IntermediaryActivator activator;
+ // The handler for the participant intermediary
+ private ParticipantHandler participantHandler;
- @Override
- public void init(ParticipantIntermediaryParameters parameters) {
- activator = new IntermediaryActivator(parameters);
-
- activator.start();
- }
-
- @Override
- public void close() {
- activator.shutdown();
+ /**
+ * Constructor.
+ *
+ * @param participantHandler ParticipantHandler
+ */
+ public ParticipantIntermediaryApiImpl(ParticipantHandler participantHandler) {
+ this.participantHandler = participantHandler;
}
@Override
public void registerControlLoopElementListener(ControlLoopElementListener controlLoopElementListener) {
- activator.getParticipantHandler().getControlLoopHandler()
- .registerControlLoopElementListener(controlLoopElementListener);
+ participantHandler.getControlLoopHandler().registerControlLoopElementListener(controlLoopElementListener);
}
@Override
public List<Participant> getParticipants(String name, String version) {
- return List.of(activator.getParticipantHandler().getParticipant(name, version));
+ return List.of(participantHandler.getParticipant(name, version));
}
@Override
public Participant updateParticipantState(ToscaConceptIdentifier definition, ParticipantState state) {
- return activator.getParticipantHandler().updateParticipantState(definition, state);
+ return participantHandler.updateParticipantState(definition, state);
}
@Override
@@ -83,13 +79,13 @@ public class ParticipantIntermediaryApiImpl implements ParticipantIntermediaryAp
@Override
public ControlLoops getControlLoops(String name, String version) {
- return activator.getParticipantHandler().getControlLoopHandler().getControlLoops();
+ return participantHandler.getControlLoopHandler().getControlLoops();
}
@Override
public Map<UUID, ControlLoopElement> getControlLoopElements(String name, String version) {
- List<ControlLoop> controlLoops = activator.getParticipantHandler()
- .getControlLoopHandler().getControlLoops().getControlLoopList();
+ List<ControlLoop> controlLoops =
+ participantHandler.getControlLoopHandler().getControlLoops().getControlLoopList();
for (ControlLoop controlLoop : controlLoops) {
if (name.equals(controlLoop.getDefinition().getName())) {
@@ -101,8 +97,8 @@ public class ParticipantIntermediaryApiImpl implements ParticipantIntermediaryAp
@Override
public ControlLoopElement getControlLoopElement(UUID id) {
- List<ControlLoop> controlLoops = activator.getParticipantHandler()
- .getControlLoopHandler().getControlLoops().getControlLoopList();
+ List<ControlLoop> controlLoops =
+ participantHandler.getControlLoopHandler().getControlLoops().getControlLoopList();
for (ControlLoop controlLoop : controlLoops) {
ControlLoopElement clElement = controlLoop.getElements().get(id);
@@ -116,18 +112,11 @@ public class ParticipantIntermediaryApiImpl implements ParticipantIntermediaryAp
@Override
public ControlLoopElement updateControlLoopElementState(UUID id, ControlLoopOrderedState currentState,
ControlLoopState newState) {
- return activator.getParticipantHandler().getControlLoopHandler()
- .updateControlLoopElementState(id, currentState, newState);
+ return participantHandler.getControlLoopHandler().updateControlLoopElementState(id, currentState, newState);
}
@Override
public void updateControlLoopElementStatistics(UUID id, ClElementStatistics elementStatistics) {
- activator.getParticipantHandler().getControlLoopHandler()
- .updateControlLoopElementStatistics(id, elementStatistics);
- }
-
- @Override
- public ParticipantHandler getParticipantHandler() {
- return activator.getParticipantHandler();
+ participantHandler.getControlLoopHandler().updateControlLoopElementStatistics(id, elementStatistics);
}
}
diff --git a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/comm/ControlLoopStateChangeListener.java b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/comm/ControlLoopStateChangeListener.java
index 50b8b9cdc..e46c6db1b 100644
--- a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/comm/ControlLoopStateChangeListener.java
+++ b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/comm/ControlLoopStateChangeListener.java
@@ -20,23 +20,15 @@
package org.onap.policy.clamp.controlloop.participant.intermediary.comm;
-import java.io.Closeable;
import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantControlLoopStateChange;
import org.onap.policy.clamp.controlloop.participant.intermediary.handler.ParticipantHandler;
-import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
-import org.onap.policy.common.endpoints.listeners.ScoListener;
-import org.onap.policy.common.utils.coder.StandardCoderObject;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Component;
/**
* Listener for Participant State Change messages sent by CLAMP.
*/
-public class ControlLoopStateChangeListener extends ScoListener<ParticipantControlLoopStateChange>
- implements Closeable {
- private static final Logger LOGGER = LoggerFactory.getLogger(ControlLoopStateChangeListener.class);
-
- private final ParticipantHandler participantHandler;
+@Component
+public class ControlLoopStateChangeListener extends ParticipantListener<ParticipantControlLoopStateChange> {
/**
* Constructs the object.
@@ -44,25 +36,7 @@ public class ControlLoopStateChangeListener extends ScoListener<ParticipantContr
* @param participantHandler the handler for managing the state of the participant
*/
public ControlLoopStateChangeListener(final ParticipantHandler participantHandler) {
- super(ParticipantControlLoopStateChange.class);
- this.participantHandler = participantHandler;
- }
-
- @Override
- public void onTopicEvent(final CommInfrastructure infra, final String topic, final StandardCoderObject sco,
- final ParticipantControlLoopStateChange controlLoopStateChangeMsg) {
- LOGGER.debug("Control Loop State Change received from CLAMP - {}", controlLoopStateChangeMsg);
-
- if (participantHandler.canHandle(controlLoopStateChangeMsg)) {
- LOGGER.debug("Message for this participant");
- participantHandler.getControlLoopHandler().handleControlLoopStateChange(controlLoopStateChangeMsg);
- } else {
- LOGGER.debug("Message not for this participant");
- }
- }
-
- @Override
- public void close() {
- // No explicit action on this class
+ super(ParticipantControlLoopStateChange.class, participantHandler,
+ participantHandler::handleControlLoopStateChange);
}
}
diff --git a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/comm/ControlLoopUpdateListener.java b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/comm/ControlLoopUpdateListener.java
index ab2437c1c..d15643e0f 100644
--- a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/comm/ControlLoopUpdateListener.java
+++ b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/comm/ControlLoopUpdateListener.java
@@ -20,22 +20,15 @@
package org.onap.policy.clamp.controlloop.participant.intermediary.comm;
-import java.io.Closeable;
import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantControlLoopUpdate;
import org.onap.policy.clamp.controlloop.participant.intermediary.handler.ParticipantHandler;
-import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
-import org.onap.policy.common.endpoints.listeners.ScoListener;
-import org.onap.policy.common.utils.coder.StandardCoderObject;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Component;
/**
* Listener for Control Loop Update messages sent by CLAMP.
*/
-public class ControlLoopUpdateListener extends ScoListener<ParticipantControlLoopUpdate> implements Closeable {
- private static final Logger LOGGER = LoggerFactory.getLogger(ControlLoopUpdateListener.class);
-
- private final ParticipantHandler participantHandler;
+@Component
+public class ControlLoopUpdateListener extends ParticipantListener<ParticipantControlLoopUpdate> {
/**
* Constructs the object.
@@ -43,25 +36,6 @@ public class ControlLoopUpdateListener extends ScoListener<ParticipantControlLoo
* @param participantHandler the handler for managing the state of the participant
*/
public ControlLoopUpdateListener(final ParticipantHandler participantHandler) {
- super(ParticipantControlLoopUpdate.class);
- this.participantHandler = participantHandler;
- }
-
- @Override
- public void onTopicEvent(final CommInfrastructure infra, final String topic, final StandardCoderObject sco,
- final ParticipantControlLoopUpdate participantControlLoopUpdateMsg) {
- LOGGER.debug("Control Loop update received from CLAMP - {}", participantControlLoopUpdateMsg);
-
- if (participantHandler.canHandle(participantControlLoopUpdateMsg)) {
- LOGGER.debug("Message for this participant");
- participantHandler.getControlLoopHandler().handleControlLoopUpdate(participantControlLoopUpdateMsg);
- } else {
- LOGGER.debug("Message not for this participant");
- }
- }
-
- @Override
- public void close() {
- // No explicit action on this class
+ super(ParticipantControlLoopUpdate.class, participantHandler, participantHandler::handleControlLoopUpdate);
}
}
diff --git a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/comm/ParticipantHealthCheckListener.java b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/comm/ParticipantHealthCheckListener.java
index e0e6be329..15f5140eb 100644
--- a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/comm/ParticipantHealthCheckListener.java
+++ b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/comm/ParticipantHealthCheckListener.java
@@ -20,22 +20,15 @@
package org.onap.policy.clamp.controlloop.participant.intermediary.comm;
-import java.io.Closeable;
import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantHealthCheck;
import org.onap.policy.clamp.controlloop.participant.intermediary.handler.ParticipantHandler;
-import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
-import org.onap.policy.common.endpoints.listeners.ScoListener;
-import org.onap.policy.common.utils.coder.StandardCoderObject;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Component;
/**
* Listener for Participant health status messages sent by CLAMP.
*/
-public class ParticipantHealthCheckListener extends ScoListener<ParticipantHealthCheck> implements Closeable {
- private static final Logger LOGGER = LoggerFactory.getLogger(ParticipantHealthCheckListener.class);
-
- private final ParticipantHandler participantHandler;
+@Component
+public class ParticipantHealthCheckListener extends ParticipantListener<ParticipantHealthCheck> {
/**
* Constructs the object.
@@ -43,27 +36,6 @@ public class ParticipantHealthCheckListener extends ScoListener<ParticipantHealt
* @param participantHandler the handler for managing the state and health of the participant
*/
public ParticipantHealthCheckListener(final ParticipantHandler participantHandler) {
- super(ParticipantHealthCheck.class);
- this.participantHandler = participantHandler;
- }
-
- @Override
- public void onTopicEvent(final CommInfrastructure infra, final String topic, final StandardCoderObject sco,
- final ParticipantHealthCheck participantHealthCheckMsg) {
- LOGGER.debug("Participant Health Check message received from CLAMP - {}", participantHealthCheckMsg);
-
-
- if (participantHandler.canHandle(participantHealthCheckMsg)) {
- LOGGER.debug("Message for this participant");
- participantHandler.handleParticipantHealthCheck(participantHealthCheckMsg);
- } else {
- LOGGER.debug("Message not for this participant");
- }
-
- }
-
- @Override
- public void close() {
- // No explicit action on this class
+ super(ParticipantHealthCheck.class, participantHandler, participantHandler::handleParticipantHealthCheck);
}
}
diff --git a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/comm/ParticipantListener.java b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/comm/ParticipantListener.java
new file mode 100644
index 000000000..c6ad900b3
--- /dev/null
+++ b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/comm/ParticipantListener.java
@@ -0,0 +1,57 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2021 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.clamp.controlloop.participant.intermediary.comm;
+
+import java.util.function.Consumer;
+import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantMessage;
+import org.onap.policy.clamp.controlloop.participant.intermediary.handler.ParticipantHandler;
+import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
+import org.onap.policy.common.endpoints.listeners.ScoListener;
+import org.onap.policy.common.utils.coder.StandardCoderObject;
+
+/**
+ * Abstract Listener for Participant messages sent by CLAMP.
+ */
+public abstract class ParticipantListener<T extends ParticipantMessage> extends ScoListener<T> {
+
+ private final ParticipantHandler participantHandler;
+ private final Consumer<T> consumer;
+
+ /**
+ * Constructs the object.
+ *
+ * @param clazz class of message this handles
+ * @param participantHandler ParticipantHandler
+ * @param consumer function that handles the message
+ */
+ protected ParticipantListener(Class<T> clazz, ParticipantHandler participantHandler, Consumer<T> consumer) {
+ super(clazz);
+ this.participantHandler = participantHandler;
+ this.consumer = consumer;
+ }
+
+ @Override
+ public void onTopicEvent(CommInfrastructure infra, String topic, StandardCoderObject sco, T message) {
+ if (participantHandler.appliesTo(message)) {
+ consumer.accept(message);
+ }
+ }
+}
diff --git a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/comm/ParticipantStateChangeListener.java b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/comm/ParticipantStateChangeListener.java
index c1a8b5b4a..ec6548a7c 100644
--- a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/comm/ParticipantStateChangeListener.java
+++ b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/comm/ParticipantStateChangeListener.java
@@ -20,23 +20,16 @@
package org.onap.policy.clamp.controlloop.participant.intermediary.comm;
-import java.io.Closeable;
import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantStateChange;
import org.onap.policy.clamp.controlloop.participant.intermediary.handler.ParticipantHandler;
-import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
-import org.onap.policy.common.endpoints.listeners.ScoListener;
-import org.onap.policy.common.utils.coder.StandardCoderObject;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Component;
/**
* Listener for Participant State Change messages sent by CLAMP.
*
*/
-public class ParticipantStateChangeListener extends ScoListener<ParticipantStateChange> implements Closeable {
- private static final Logger LOGGER = LoggerFactory.getLogger(ParticipantStateChangeListener.class);
-
- private final ParticipantHandler participantHandler;
+@Component
+public class ParticipantStateChangeListener extends ParticipantListener<ParticipantStateChange> {
/**
* Constructs the object.
@@ -44,25 +37,6 @@ public class ParticipantStateChangeListener extends ScoListener<ParticipantState
* @param participantHandler the handler for managing the state of the participant
*/
public ParticipantStateChangeListener(final ParticipantHandler participantHandler) {
- super(ParticipantStateChange.class);
- this.participantHandler = participantHandler;
- }
-
- @Override
- public void onTopicEvent(final CommInfrastructure infra, final String topic, final StandardCoderObject sco,
- final ParticipantStateChange participantStateChangeMsg) {
- LOGGER.debug("Participant State Change received from CLAMP - {}", participantStateChangeMsg);
-
- if (participantHandler.canHandle(participantStateChangeMsg)) {
- LOGGER.debug("Message for this participant");
- participantHandler.handleParticipantStateChange(participantStateChangeMsg);
- } else {
- LOGGER.debug("Message not for this participant");
- }
- }
-
- @Override
- public void close() {
- // No explicit action on this class
+ super(ParticipantStateChange.class, participantHandler, participantHandler::handleParticipantStateChange);
}
}
diff --git a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/comm/ParticipantStatusPublisher.java b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/comm/ParticipantStatusPublisher.java
index bc53b4e9d..78b998453 100644
--- a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/comm/ParticipantStatusPublisher.java
+++ b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/comm/ParticipantStatusPublisher.java
@@ -20,7 +20,6 @@
package org.onap.policy.clamp.controlloop.participant.intermediary.comm;
-import java.io.Closeable;
import java.util.List;
import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantStatus;
import org.onap.policy.common.endpoints.event.comm.TopicSink;
@@ -32,7 +31,7 @@ import org.slf4j.LoggerFactory;
* This class is used to send Participant Status messages to clamp using TopicSinkClient.
*
*/
-public class ParticipantStatusPublisher implements Closeable {
+public class ParticipantStatusPublisher {
private static final Logger LOGGER = LoggerFactory.getLogger(ParticipantStatusPublisher.class);
private final TopicSinkClient topicSinkClient;
@@ -55,9 +54,4 @@ public class ParticipantStatusPublisher implements Closeable {
topicSinkClient.send(participantStatus);
LOGGER.debug("Sent Participant Status message to CLAMP - {}", participantStatus);
}
-
- @Override
- public void close() {
- // No explicit action on this class
- }
}
diff --git a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/config/BeanFactory.java b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/config/BeanFactory.java
new file mode 100644
index 000000000..dc7d87eec
--- /dev/null
+++ b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/config/BeanFactory.java
@@ -0,0 +1,55 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2021 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.clamp.controlloop.participant.intermediary.config;
+
+import java.util.List;
+import org.onap.policy.clamp.controlloop.participant.intermediary.comm.ParticipantStatusPublisher;
+import org.onap.policy.clamp.controlloop.participant.intermediary.parameters.ParticipantParameters;
+import org.onap.policy.common.endpoints.event.comm.TopicEndpointManager;
+import org.onap.policy.common.endpoints.event.comm.TopicSink;
+import org.onap.policy.common.endpoints.listeners.MessageTypeDispatcher;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+@Configuration
+public class BeanFactory {
+
+ // Name of the message type for messages on topics
+ private static final String[] MSG_TYPE_NAMES = {"messageType"};
+
+ /**
+ * create ParticipantStatusPublisher.
+ *
+ * @param parameters the ParticipantParameters
+ * @return ParticipantStatusPublisher
+ */
+ @Bean
+ public ParticipantStatusPublisher publisher(final ParticipantParameters parameters) {
+ List<TopicSink> topicSinks = TopicEndpointManager.getManager()
+ .addTopicSinks(parameters.getIntermediaryParameters().getClampControlLoopTopics().getTopicSinks());
+ return new ParticipantStatusPublisher(topicSinks);
+ }
+
+ @Bean
+ public MessageTypeDispatcher msgDispatcher() {
+ return new MessageTypeDispatcher(MSG_TYPE_NAMES);
+ }
+}
diff --git a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/ControlLoopHandler.java b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/ControlLoopHandler.java
index 3eebd177f..50048ffc2 100644
--- a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/ControlLoopHandler.java
+++ b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/ControlLoopHandler.java
@@ -20,7 +20,6 @@
package org.onap.policy.clamp.controlloop.participant.intermediary.handler;
-import java.io.Closeable;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
@@ -51,7 +50,7 @@ import org.slf4j.LoggerFactory;
* This class is responsible for managing the state of all control loops in the participant.
*/
@NoArgsConstructor
-public class ControlLoopHandler implements Closeable {
+public class ControlLoopHandler {
private static final Logger LOGGER = LoggerFactory.getLogger(ControlLoopHandler.class);
private ToscaConceptIdentifier participantType = null;
@@ -77,11 +76,6 @@ public class ControlLoopHandler implements Closeable {
this.messageSender = messageSender;
}
- @Override
- public void close() {
- // No explicit action on this class
- }
-
public void registerControlLoopElementListener(ControlLoopElementListener listener) {
listeners.add(listener);
}
diff --git a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/IntermediaryActivator.java b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/IntermediaryActivator.java
index 3eae27267..2d789d40d 100644
--- a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/IntermediaryActivator.java
+++ b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/IntermediaryActivator.java
@@ -20,125 +20,100 @@
package org.onap.policy.clamp.controlloop.participant.intermediary.handler;
+import java.io.Closeable;
+import java.io.IOException;
import java.util.List;
-import java.util.concurrent.atomic.AtomicReference;
-import javax.ws.rs.core.Response.Status;
-import lombok.Getter;
-import org.onap.policy.clamp.controlloop.common.exception.ControlLoopRuntimeException;
-import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantControlLoopStateChange;
-import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantControlLoopUpdate;
-import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantHealthCheck;
import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantMessageType;
-import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantStateChange;
import org.onap.policy.clamp.controlloop.participant.intermediary.comm.ControlLoopStateChangeListener;
import org.onap.policy.clamp.controlloop.participant.intermediary.comm.ControlLoopUpdateListener;
import org.onap.policy.clamp.controlloop.participant.intermediary.comm.ParticipantHealthCheckListener;
import org.onap.policy.clamp.controlloop.participant.intermediary.comm.ParticipantStateChangeListener;
-import org.onap.policy.clamp.controlloop.participant.intermediary.comm.ParticipantStatusPublisher;
-import org.onap.policy.clamp.controlloop.participant.intermediary.parameters.ParticipantIntermediaryParameters;
+import org.onap.policy.clamp.controlloop.participant.intermediary.parameters.ParticipantParameters;
import org.onap.policy.common.endpoints.event.comm.TopicEndpointManager;
-import org.onap.policy.common.endpoints.event.comm.TopicSink;
import org.onap.policy.common.endpoints.event.comm.TopicSource;
import org.onap.policy.common.endpoints.listeners.MessageTypeDispatcher;
-import org.onap.policy.common.endpoints.listeners.ScoListener;
import org.onap.policy.common.utils.services.ServiceManagerContainer;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.event.ContextClosedEvent;
+import org.springframework.context.event.ContextRefreshedEvent;
+import org.springframework.context.event.EventListener;
+import org.springframework.stereotype.Component;
/**
* This class activates the Participant Intermediary together with all its handlers.
*/
-public class IntermediaryActivator extends ServiceManagerContainer {
- // Name of the message type for messages on topics
- private static final String[] MSG_TYPE_NAMES = {"messageType"};
+@Component
+public class IntermediaryActivator extends ServiceManagerContainer implements Closeable {
- @Getter
- private final ParticipantIntermediaryParameters parameters;
+ private final ApplicationContext applicationContext;
// Topics from which the participant receives and to which the participant sends messages
- private List<TopicSink> topicSinks;
private List<TopicSource> topicSources;
- // The participant handler for this intermediary
- final AtomicReference<ParticipantHandler> participantHandler = new AtomicReference<>();
-
- /**
- * Listens for messages on the topic, decodes them into a message, and then dispatches them.
- */
- private final MessageTypeDispatcher msgDispatcher;
-
/**
* Instantiate the activator for participant.
*
- * @param parameters the parameters for the participant intermediary
- * @throws ControlLoopRuntimeException when the activation fails
+ * @param applicationContext ApplicationContext
+ * @param parameters the ParticipantParameters
*/
- public IntermediaryActivator(final ParticipantIntermediaryParameters parameters) {
- this.parameters = parameters;
-
- topicSinks =
- TopicEndpointManager.getManager().addTopicSinks(parameters.getClampControlLoopTopics().getTopicSinks());
+ public IntermediaryActivator(final ApplicationContext applicationContext, final ParticipantParameters parameters) {
+ this.applicationContext = applicationContext;
- topicSources =
- TopicEndpointManager.getManager().addTopicSources(parameters.getClampControlLoopTopics().getTopicSources());
-
- try {
- this.msgDispatcher = new MessageTypeDispatcher(MSG_TYPE_NAMES);
- } catch (final RuntimeException e) {
- throw new ControlLoopRuntimeException(Status.INTERNAL_SERVER_ERROR,
- "topic message dispatcher failed to start", e);
- }
+ topicSources = TopicEndpointManager.getManager()
+ .addTopicSources(parameters.getIntermediaryParameters().getClampControlLoopTopics().getTopicSources());
// @formatter:off
- final AtomicReference<ParticipantStatusPublisher> statusPublisher = new AtomicReference<>();
- final AtomicReference<ParticipantStateChangeListener> participantStateChangeListener = new AtomicReference<>();
- final AtomicReference<ParticipantHealthCheckListener> participantHealthCheckListener = new AtomicReference<>();
- final AtomicReference<ControlLoopStateChangeListener> controlLoopStateChangeListener = new AtomicReference<>();
- final AtomicReference<ControlLoopUpdateListener> controlLoopUpdateListener = new AtomicReference<>();
addAction("Topic endpoint management",
() -> TopicEndpointManager.getManager().start(),
() -> TopicEndpointManager.getManager().shutdown());
- addAction("Participant Status Publisher",
- () -> statusPublisher.set(new ParticipantStatusPublisher(topicSinks)),
- () -> statusPublisher.get().close());
-
- addAction("Participant Handler",
- () -> participantHandler.set(new ParticipantHandler(parameters, statusPublisher.get())),
- () -> participantHandler.get().close());
-
- addAction("Participant State Change Listener",
- () -> participantStateChangeListener.set(new ParticipantStateChangeListener(participantHandler.get())),
- () -> participantStateChangeListener.get().close());
-
- addAction("Participant Health Check Listener",
- () -> participantHealthCheckListener.set(new ParticipantHealthCheckListener(participantHandler.get())),
- () -> participantHealthCheckListener.get().close());
-
- addAction("Control Loop State Change Listener",
- () -> controlLoopStateChangeListener.set(new ControlLoopStateChangeListener(participantHandler.get())),
- () -> controlLoopStateChangeListener.get().close());
-
- addAction("Control Loop Update Listener",
- () -> controlLoopUpdateListener.set(new ControlLoopUpdateListener(participantHandler.get())),
- () -> controlLoopUpdateListener.get().close());
-
addAction("Topic Message Dispatcher", this::registerMsgDispatcher, this::unregisterMsgDispatcher);
// @formatter:on
}
/**
+ * Handle ContextRefreshEvent.
+ *
+ * @param ctxRefreshedEvent ContextRefreshedEvent
+ */
+ @EventListener
+ public void handleContextRefreshEvent(ContextRefreshedEvent ctxRefreshedEvent) {
+ if (!isAlive()) {
+ start();
+ }
+ }
+
+ /**
+ * Handle ContextClosedEvent.
+ *
+ * @param ctxClosedEvent ContextClosedEvent
+ */
+ @EventListener
+ public void handleContextClosedEvent(ContextClosedEvent ctxClosedEvent) {
+ if (isAlive()) {
+ stop();
+ }
+ }
+
+ /**
* Registers the dispatcher with the topic source(s).
*/
private void registerMsgDispatcher() {
+ MessageTypeDispatcher msgDispatcher = applicationContext.getBean(MessageTypeDispatcher.class);
+
msgDispatcher.register(ParticipantMessageType.PARTICIPANT_STATE_CHANGE.name(),
- (ScoListener<ParticipantStateChange>) new ParticipantStateChangeListener(participantHandler.get()));
+ applicationContext.getBean(ParticipantStateChangeListener.class));
+
msgDispatcher.register(ParticipantMessageType.PARTICIPANT_HEALTH_CHECK.name(),
- (ScoListener<ParticipantHealthCheck>) new ParticipantHealthCheckListener(participantHandler.get()));
+ applicationContext.getBean(ParticipantHealthCheckListener.class));
+
msgDispatcher.register(ParticipantMessageType.PARTICIPANT_CONTROL_LOOP_STATE_CHANGE.name(),
- (ScoListener<ParticipantControlLoopStateChange>) new ControlLoopStateChangeListener(
- participantHandler.get()));
+ applicationContext.getBean(ControlLoopStateChangeListener.class));
+
msgDispatcher.register(ParticipantMessageType.PARTICIPANT_CONTROL_LOOP_UPDATE.name(),
- (ScoListener<ParticipantControlLoopUpdate>) new ControlLoopUpdateListener(participantHandler.get()));
+ applicationContext.getBean(ControlLoopUpdateListener.class));
+
for (final TopicSource source : topicSources) {
source.register(msgDispatcher);
}
@@ -148,17 +123,15 @@ public class IntermediaryActivator extends ServiceManagerContainer {
* Unregisters the dispatcher from the topic source(s).
*/
private void unregisterMsgDispatcher() {
+ MessageTypeDispatcher msgDispatcher = applicationContext.getBean(MessageTypeDispatcher.class);
+
for (final TopicSource source : topicSources) {
source.unregister(msgDispatcher);
}
}
- /**
- * Return the participant handler.
- *
- * @return the participant handler
- */
- public ParticipantHandler getParticipantHandler() {
- return participantHandler.get();
+ @Override
+ public void close() throws IOException {
+ super.shutdown();
}
}
diff --git a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/ParticipantHandler.java b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/ParticipantHandler.java
index 5e414b175..1c54658fa 100644
--- a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/ParticipantHandler.java
+++ b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/ParticipantHandler.java
@@ -28,6 +28,8 @@ import org.onap.policy.clamp.controlloop.models.controlloop.concepts.Participant
import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantHealthStatus;
import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantState;
import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantStatistics;
+import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantControlLoopStateChange;
+import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantControlLoopUpdate;
import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantHealthCheck;
import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantMessage;
import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantResponseDetails;
@@ -35,15 +37,17 @@ import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.Parti
import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantStateChange;
import org.onap.policy.clamp.controlloop.participant.intermediary.comm.MessageSender;
import org.onap.policy.clamp.controlloop.participant.intermediary.comm.ParticipantStatusPublisher;
-import org.onap.policy.clamp.controlloop.participant.intermediary.parameters.ParticipantIntermediaryParameters;
+import org.onap.policy.clamp.controlloop.participant.intermediary.parameters.ParticipantParameters;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Component;
/**
* This class is responsible for managing the state of a participant.
*/
@Getter
+@Component
public class ParticipantHandler implements Closeable {
private static final Logger LOGGER = LoggerFactory.getLogger(ParticipantHandler.class);
@@ -65,18 +69,18 @@ public class ParticipantHandler implements Closeable {
* @param parameters the parameters of the participant
* @param publisher the publisher for sending responses to messages
*/
- public ParticipantHandler(ParticipantIntermediaryParameters parameters, ParticipantStatusPublisher publisher) {
- this.participantType = parameters.getParticipantType();
- this.participantId = parameters.getParticipantId();
- this.sender = new MessageSender(this, publisher, parameters.getReportingTimeInterval());
- this.controlLoopHandler = new ControlLoopHandler(parameters, sender);
+ public ParticipantHandler(ParticipantParameters parameters, ParticipantStatusPublisher publisher) {
+ this.participantType = parameters.getIntermediaryParameters().getParticipantType();
+ this.participantId = parameters.getIntermediaryParameters().getParticipantId();
+ this.sender =
+ new MessageSender(this, publisher, parameters.getIntermediaryParameters().getReportingTimeInterval());
+ this.controlLoopHandler = new ControlLoopHandler(parameters.getIntermediaryParameters(), sender);
this.participantStatistics = new ParticipantStatistics();
}
@Override
public void close() {
sender.close();
- controlLoopHandler.close();
}
/**
@@ -133,6 +137,24 @@ public class ParticipantHandler implements Closeable {
}
/**
+ * Handle a control loop update message.
+ *
+ * @param updateMsg the update message
+ */
+ public void handleControlLoopUpdate(ParticipantControlLoopUpdate updateMsg) {
+ controlLoopHandler.handleControlLoopUpdate(updateMsg);
+ }
+
+ /**
+ * Handle a control loop state change message.
+ *
+ * @param stateChangeMsg the state change message
+ */
+ public void handleControlLoopStateChange(ParticipantControlLoopStateChange stateChangeMsg) {
+ controlLoopHandler.handleControlLoopStateChange(stateChangeMsg);
+ }
+
+ /**
* Method to handle when the new state from participant is active.
*
* @param response participant response
@@ -233,4 +255,14 @@ public class ParticipantHandler implements Closeable {
public boolean canHandle(ParticipantMessage partipantMsg) {
return partipantMsg.appliesTo(participantType, participantId);
}
+
+ /**
+ * Check if a participant message applies to this participant handler.
+ *
+ * @param partipantMsg the message to check
+ * @return true if it applies, false otherwise
+ */
+ public boolean appliesTo(ParticipantMessage partipantMsg) {
+ return partipantMsg.appliesTo(participantType, participantId);
+ }
}
diff --git a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/api/ParticipantIntermediaryFactory.java b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/parameters/ParticipantParameters.java
index d7cc4b2ed..c350b1b95 100644
--- a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/api/ParticipantIntermediaryFactory.java
+++ b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/parameters/ParticipantParameters.java
@@ -18,21 +18,9 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.clamp.controlloop.participant.intermediary.api;
+package org.onap.policy.clamp.controlloop.participant.intermediary.parameters;
-import org.onap.policy.clamp.controlloop.participant.intermediary.api.impl.ParticipantIntermediaryApiImpl;
+public interface ParticipantParameters {
-/**
- * Factory class for creating {@link ParticipantIntermediaryApi} instances.
- */
-public class ParticipantIntermediaryFactory {
-
- /**
- * Create an implementation of the {@link ParticipantIntermediaryApi} interface.
- *
- * @return the implementation of the API
- */
- public ParticipantIntermediaryApi createApiImplementation() {
- return new ParticipantIntermediaryApiImpl();
- }
+ ParticipantIntermediaryParameters getIntermediaryParameters();
}