diff options
author | a.sreekumar <ajith.sreekumar@bell.ca> | 2021-12-03 11:27:32 +0000 |
---|---|---|
committer | a.sreekumar <ajith.sreekumar@bell.ca> | 2021-12-14 17:58:20 +0000 |
commit | 4694c152f69380f4d3d64bde0a13d15fb59a71f3 (patch) | |
tree | 38c9e0b1117323c58536706a66830109225d6200 /main/src/main/java/org/onap/policy/pap/main/startstop/PapActivator.java | |
parent | c51fa0d4e953518571a115af4afdea80a17ed605 (diff) |
Migrate pap startup & controllers to spring boot
This commit migrates pap config, startup and controllers to spring boot.
Change-Id: Icf91d728160a23db614dfba6b40ddccd2f6163a5
Issue-ID: POLICY-3754
Signed-off-by: a.sreekumar <ajith.sreekumar@bell.ca>
Diffstat (limited to 'main/src/main/java/org/onap/policy/pap/main/startstop/PapActivator.java')
-rw-r--r-- | main/src/main/java/org/onap/policy/pap/main/startstop/PapActivator.java | 81 |
1 files changed, 36 insertions, 45 deletions
diff --git a/main/src/main/java/org/onap/policy/pap/main/startstop/PapActivator.java b/main/src/main/java/org/onap/policy/pap/main/startstop/PapActivator.java index ad78fc7c..94943706 100644 --- a/main/src/main/java/org/onap/policy/pap/main/startstop/PapActivator.java +++ b/main/src/main/java/org/onap/policy/pap/main/startstop/PapActivator.java @@ -30,8 +30,6 @@ import java.util.concurrent.atomic.AtomicReference; import org.onap.policy.common.endpoints.event.comm.TopicEndpointManager; import org.onap.policy.common.endpoints.event.comm.TopicListener; import org.onap.policy.common.endpoints.event.comm.TopicSource; -import org.onap.policy.common.endpoints.http.client.HttpClientFactoryInstance; -import org.onap.policy.common.endpoints.http.server.RestServer; import org.onap.policy.common.endpoints.listeners.MessageTypeDispatcher; import org.onap.policy.common.endpoints.listeners.RequestIdDispatcher; import org.onap.policy.common.parameters.ParameterService; @@ -51,21 +49,12 @@ import org.onap.policy.pap.main.comm.TimerManager; import org.onap.policy.pap.main.notification.PolicyNotifier; import org.onap.policy.pap.main.parameters.PapParameterGroup; import org.onap.policy.pap.main.parameters.PdpModifyRequestMapParams; -import org.onap.policy.pap.main.rest.HealthCheckRestControllerV1; -import org.onap.policy.pap.main.rest.PapAafFilter; import org.onap.policy.pap.main.rest.PapStatisticsManager; -import org.onap.policy.pap.main.rest.PdpGroupCreateOrUpdateControllerV1; -import org.onap.policy.pap.main.rest.PdpGroupDeleteControllerV1; -import org.onap.policy.pap.main.rest.PdpGroupDeployControllerV1; -import org.onap.policy.pap.main.rest.PdpGroupHealthCheckControllerV1; -import org.onap.policy.pap.main.rest.PdpGroupQueryControllerV1; -import org.onap.policy.pap.main.rest.PdpGroupStateChangeControllerV1; -import org.onap.policy.pap.main.rest.PolicyAuditControllerV1; -import org.onap.policy.pap.main.rest.PolicyComponentsHealthCheckControllerV1; -import org.onap.policy.pap.main.rest.PolicyComponentsHealthCheckProvider; -import org.onap.policy.pap.main.rest.PolicyStatusControllerV1; import org.onap.policy.pap.main.rest.PolicyUndeployerImpl; -import org.onap.policy.pap.main.rest.StatisticsRestControllerV1; +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 Policy Administration (PAP) as a complete service together with all its controllers, listeners & @@ -73,6 +62,7 @@ import org.onap.policy.pap.main.rest.StatisticsRestControllerV1; * * @author Ram Krishna Verma (ram.krishna.verma@est.tech) */ +@Component public class PapActivator extends ServiceManagerContainer { private static final String[] MSG_TYPE_NAMES = { "messageName" }; private static final String[] REQ_ID_NAMES = { "response", "responseTo" }; @@ -82,7 +72,7 @@ public class PapActivator extends ServiceManagerContainer { */ private static final int MAX_MISSED_HEARTBEATS = 3; - private final PapParameterGroup papParameterGroup; + private PapParameterGroup papParameterGroup; /** * Listens for messages on the topic, decodes them into a {@link PdpStatus} message, and then dispatches them to @@ -108,13 +98,12 @@ public class PapActivator extends ServiceManagerContainer { * * @param papParameterGroup the parameters for the pap service */ - public PapActivator(final PapParameterGroup papParameterGroup) { + public PapActivator(PapParameterGroup papParameterGroup) { super("Policy PAP"); - + this.papParameterGroup = papParameterGroup; TopicEndpointManager.getManager().addTopics(papParameterGroup.getTopicParameterGroup()); try { - this.papParameterGroup = papParameterGroup; this.responseMsgDispatcher = new MessageTypeDispatcher(MSG_TYPE_NAMES); this.heartbeatMsgDispatcher = new MessageTypeDispatcher(MSG_TYPE_NAMES); this.responseReqIdDispatcher = new RequestIdDispatcher<>(PdpStatus.class, REQ_ID_NAMES); @@ -126,7 +115,6 @@ public class PapActivator extends ServiceManagerContainer { throw new PolicyPapRuntimeException(e); } - papParameterGroup.getRestServerParameters().setName(papParameterGroup.getName()); final var pdpUpdateLock = new Object(); final var pdpParams = papParameterGroup.getPdpParameters(); @@ -137,7 +125,6 @@ public class PapActivator extends ServiceManagerContainer { final AtomicReference<ScheduledExecutorService> pdpExpirationTimer = new AtomicReference<>(); final AtomicReference<PolicyModelsProviderFactoryWrapper> daoFactory = new AtomicReference<>(); final AtomicReference<PdpModifyRequestMap> requestMap = new AtomicReference<>(); - final AtomicReference<RestServer> restServer = new AtomicReference<>(); final AtomicReference<PolicyNotifier> notifier = new AtomicReference<>(); // @formatter:off @@ -182,6 +169,10 @@ public class PapActivator extends ServiceManagerContainer { () -> Registry.register(PapConstants.REG_STATISTICS_MANAGER, new PapStatisticsManager()), () -> Registry.unregister(PapConstants.REG_STATISTICS_MANAGER)); + addAction("PAP Activator", + () -> Registry.register(PapConstants.REG_PAP_ACTIVATOR, this), + () -> Registry.unregister(PapConstants.REG_PAP_ACTIVATOR)); + addAction("PDP publisher", () -> { pdpPub.set(new Publisher<>(PapConstants.TOPIC_POLICY_PDP_PAP)); @@ -253,30 +244,6 @@ public class PapActivator extends ServiceManagerContainer { }, () -> pdpExpirationTimer.get().shutdown()); - addAction("PAP client executor", - () -> - PolicyComponentsHealthCheckProvider.initializeClientHealthCheckExecutorService(papParameterGroup, - HttpClientFactoryInstance.getClientFactory()), - PolicyComponentsHealthCheckProvider::cleanup); - - addAction("REST server", - () -> { - var server = new RestServer(papParameterGroup.getRestServerParameters(), PapAafFilter.class, - HealthCheckRestControllerV1.class, - StatisticsRestControllerV1.class, - PdpGroupCreateOrUpdateControllerV1.class, - PdpGroupDeployControllerV1.class, - PdpGroupDeleteControllerV1.class, - PdpGroupStateChangeControllerV1.class, - PdpGroupQueryControllerV1.class, - PdpGroupHealthCheckControllerV1.class, - PolicyStatusControllerV1.class, - PolicyComponentsHealthCheckControllerV1.class, - PolicyAuditControllerV1.class); - restServer.set(server); - restServer.get().start(); - }, - () -> restServer.get().stop()); // @formatter:on } @@ -322,4 +289,28 @@ public class PapActivator extends ServiceManagerContainer { source.unregister(dispatcher); } } + + /** + * Handle ContextRefreshEvent. + * + * @param ctxRefreshedEvent the ContextRefreshedEvent + */ + @EventListener + public void handleContextRefreshEvent(ContextRefreshedEvent ctxRefreshedEvent) { + if (!isAlive()) { + start(); + } + } + + /** + * Handle ContextClosedEvent. + * + * @param ctxClosedEvent the ContextClosedEvent + */ + @EventListener + public void handleContextClosedEvent(ContextClosedEvent ctxClosedEvent) { + if (isAlive()) { + stop(); + } + } } |