* ============LICENSE_START=======================================================
* Copyright (C) 2019 Nordix Foundation.
* Modifications Copyright (C) 2019-2021 AT&T Intellectual Property.
- * Modifications Copyright (C) 2021 Bell Canada. All rights reserved.
+ * Modifications Copyright (C) 2021-2022 Bell Canada. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
import org.onap.policy.models.pdp.concepts.PdpStatus;
import org.onap.policy.models.pdp.enums.PdpMessageType;
import org.onap.policy.pap.main.PapConstants;
-import org.onap.policy.pap.main.PolicyModelsProviderFactoryWrapper;
import org.onap.policy.pap.main.PolicyPapRuntimeException;
import org.onap.policy.pap.main.comm.PdpHeartbeatListener;
import org.onap.policy.pap.main.comm.PdpModifyRequestMap;
import org.onap.policy.pap.main.parameters.PapParameterGroup;
import org.onap.policy.pap.main.parameters.PdpModifyRequestMapParams;
import org.onap.policy.pap.main.rest.PapStatisticsManager;
-import org.onap.policy.pap.main.rest.PolicyUndeployerImpl;
import org.springframework.context.event.ContextClosedEvent;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.context.event.EventListener;
private final RequestIdDispatcher<PdpStatus> responseReqIdDispatcher;
private final RequestIdDispatcher<PdpStatus> heartbeatReqIdDispatcher;
- /**
- * Listener for anonymous {@link PdpStatus} messages either for registration or heartbeat.
- */
- private final PdpHeartbeatListener pdpHeartbeatListener;
-
/**
* Instantiate the activator for policy pap as a complete service.
*
* @param papParameterGroup the parameters for the pap service
*/
- public PapActivator(PapParameterGroup papParameterGroup) {
+ public PapActivator(PapParameterGroup papParameterGroup, PolicyNotifier policyNotifier,
+ PdpHeartbeatListener pdpHeartbeatListener, PdpModifyRequestMap pdpModifyRequestMap) {
super("Policy PAP");
this.papParameterGroup = papParameterGroup;
TopicEndpointManager.getManager().addTopics(papParameterGroup.getTopicParameterGroup());
this.heartbeatMsgDispatcher = new MessageTypeDispatcher(MSG_TYPE_NAMES);
this.responseReqIdDispatcher = new RequestIdDispatcher<>(PdpStatus.class, REQ_ID_NAMES);
this.heartbeatReqIdDispatcher = new RequestIdDispatcher<>(PdpStatus.class, REQ_ID_NAMES);
- this.pdpHeartbeatListener = new PdpHeartbeatListener(papParameterGroup.getPdpParameters(),
- papParameterGroup.isSavePdpStatisticsInDb());
} catch (final RuntimeException e) {
throw new PolicyPapRuntimeException(e);
final AtomicReference<TimerManager> pdpUpdTimers = new AtomicReference<>();
final AtomicReference<TimerManager> pdpStChgTimers = new AtomicReference<>();
final AtomicReference<ScheduledExecutorService> pdpExpirationTimer = new AtomicReference<>();
- final AtomicReference<PolicyModelsProviderFactoryWrapper> daoFactory = new AtomicReference<>();
final AtomicReference<PdpModifyRequestMap> requestMap = new AtomicReference<>();
- final AtomicReference<PolicyNotifier> notifier = new AtomicReference<>();
// @formatter:off
addAction("PAP parameters",
() -> ParameterService.register(papParameterGroup),
() -> ParameterService.deregister(papParameterGroup.getName()));
- addAction("DAO Factory",
- () -> daoFactory.set(new PolicyModelsProviderFactoryWrapper(
- papParameterGroup.getDatabaseProviderParameters())),
- () -> daoFactory.get().close());
-
- addAction("DAO Factory registration",
- () -> Registry.register(PapConstants.REG_PAP_DAO_FACTORY, daoFactory.get()),
- () -> Registry.unregister(PapConstants.REG_PAP_DAO_FACTORY));
-
addAction("Pdp Heartbeat Listener",
() -> heartbeatReqIdDispatcher.register(pdpHeartbeatListener),
() -> heartbeatReqIdDispatcher.unregister(pdpHeartbeatListener));
() -> {
notifyPub.set(new Publisher<>(PapConstants.TOPIC_POLICY_NOTIFICATION));
startThread(notifyPub.get());
- notifier.set(new PolicyNotifier(notifyPub.get(), daoFactory.get()));
+ policyNotifier.setPublisher(notifyPub.get());
},
() -> notifyPub.get().stop());
- addAction("Policy Notifier",
- () -> Registry.register(PapConstants.REG_POLICY_NOTIFIER, notifier.get()),
- () -> Registry.unregister(PapConstants.REG_POLICY_NOTIFIER));
-
addAction("PDP update timers",
() -> {
pdpUpdTimers.set(new TimerManager("update", pdpParams.getUpdateParameters().getMaxWaitMs()));
addAction("PDP modification requests",
() -> {
- requestMap.set(new PdpModifyRequestMap(
- PdpModifyRequestMapParams.builder()
- .maxPdpAgeMs(MAX_MISSED_HEARTBEATS * pdpParams.getHeartBeatMs())
- .daoFactory(daoFactory.get())
- .modifyLock(pdpUpdateLock)
- .params(pdpParams)
- .policyNotifier(notifier.get())
- .pdpPublisher(pdpPub.get())
- .responseDispatcher(responseReqIdDispatcher)
- .stateChangeTimers(pdpStChgTimers.get())
- .updateTimers(pdpUpdTimers.get())
- .savePdpStatistics(papParameterGroup.isSavePdpStatisticsInDb())
- .build()));
+ pdpModifyRequestMap.initialize(
+ PdpModifyRequestMapParams.builder()
+ .maxPdpAgeMs(MAX_MISSED_HEARTBEATS * pdpParams.getHeartBeatMs())
+ .modifyLock(pdpUpdateLock)
+ .params(pdpParams)
+ .pdpPublisher(pdpPub.get())
+ .responseDispatcher(responseReqIdDispatcher)
+ .stateChangeTimers(pdpStChgTimers.get())
+ .updateTimers(pdpUpdTimers.get())
+ .savePdpStatistics(papParameterGroup.isSavePdpStatisticsInDb())
+ .build());
+ requestMap.set(pdpModifyRequestMap);
Registry.register(PapConstants.REG_PDP_MODIFY_MAP, requestMap.get());
-
- // now that it's registered, we can attach a "policy undeploy" provider
- requestMap.get().setPolicyUndeployer(new PolicyUndeployerImpl());
},
() -> Registry.unregister(PapConstants.REG_PDP_MODIFY_MAP));