aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'main/src/main')
-rw-r--r--main/src/main/java/org/onap/policy/pap/main/PapConstants.java8
-rw-r--r--main/src/main/java/org/onap/policy/pap/main/comm/PdpMessageGenerator.java17
-rw-r--r--main/src/main/java/org/onap/policy/pap/main/config/WebConfig.java4
-rw-r--r--main/src/main/java/org/onap/policy/pap/main/rest/PolicyComponentsHealthCheckProvider.java9
-rw-r--r--main/src/main/java/org/onap/policy/pap/main/rest/SessionData.java19
-rw-r--r--main/src/main/java/org/onap/policy/pap/main/startstop/PapActivator.java34
-rw-r--r--main/src/main/resources/application.yaml14
7 files changed, 62 insertions, 43 deletions
diff --git a/main/src/main/java/org/onap/policy/pap/main/PapConstants.java b/main/src/main/java/org/onap/policy/pap/main/PapConstants.java
index 36d5eeb2..98859f10 100644
--- a/main/src/main/java/org/onap/policy/pap/main/PapConstants.java
+++ b/main/src/main/java/org/onap/policy/pap/main/PapConstants.java
@@ -4,6 +4,7 @@
* ================================================================================
* Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2022 Bell Canada. All rights reserved.
+ * Modifications Copyright (C) 2022 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -35,14 +36,7 @@ public final class PapConstants {
public static final String REG_PDP_MODIFY_MAP = "object:pdp/modify/map";
public static final String REG_METER_REGISTRY = "object:meter/registry";
- // topic names
- public static final String TOPIC_POLICY_PDP_PAP = "POLICY-PDP-PAP";
- public static final String TOPIC_POLICY_NOTIFICATION = "POLICY-NOTIFICATION";
- public static final String TOPIC_POLICY_HEARTBEAT = "POLICY-HEARTBEAT";
-
// policy components names
- public static final String POLICY_API = "api";
- public static final String POLICY_DISTRIBUTION = "distribution";
public static final String POLICY_PAP = "pap";
public static final String POLICY_PDPS = "pdps";
diff --git a/main/src/main/java/org/onap/policy/pap/main/comm/PdpMessageGenerator.java b/main/src/main/java/org/onap/policy/pap/main/comm/PdpMessageGenerator.java
index 255b93e0..7bf6b803 100644
--- a/main/src/main/java/org/onap/policy/pap/main/comm/PdpMessageGenerator.java
+++ b/main/src/main/java/org/onap/policy/pap/main/comm/PdpMessageGenerator.java
@@ -3,7 +3,7 @@
* ONAP PAP
* ================================================================================
* Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2021 Nordix Foundation.
+ * Modifications Copyright (C) 2021-2022 Nordix Foundation.
* Modifications Copyright (C) 2021-2022 Bell Canada. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -24,6 +24,7 @@ package org.onap.policy.pap.main.comm;
import java.util.LinkedList;
import java.util.List;
+import lombok.Getter;
import org.onap.policy.common.parameters.ParameterService;
import org.onap.policy.common.utils.services.Registry;
import org.onap.policy.models.base.PfModelException;
@@ -43,6 +44,7 @@ import org.onap.policy.pap.main.service.ToscaServiceTemplateService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.event.EventListener;
@@ -53,9 +55,7 @@ import org.springframework.context.event.EventListener;
public class PdpMessageGenerator {
private static final Logger LOGGER = LoggerFactory.getLogger(PdpMessageGenerator.class);
- private static final String PAP_GROUP_PARAMS_NAME = "PapGroup";
-
- private boolean includeHeartBeat;
+ private final boolean includeHeartBeat;
/**
* Lock used when updating PDPs.
*/
@@ -80,6 +80,10 @@ public class PdpMessageGenerator {
@Autowired
private PolicyNotifier policyNotifier;
+ @Getter
+ @Value("${pap.name}")
+ private String papGroupParamName = "PapGroup";
+
/**
* Constructs the object.
*
@@ -99,7 +103,7 @@ public class PdpMessageGenerator {
requestMap = Registry.get(PapConstants.REG_PDP_MODIFY_MAP, PdpModifyRequestMap.class);
if (includeHeartBeat) {
- PapParameterGroup params = ParameterService.get(PAP_GROUP_PARAMS_NAME);
+ PapParameterGroup params = ParameterService.get(papGroupParamName);
heartBeatMs = params.getPdpParameters().getHeartBeatMs();
} else {
@@ -130,8 +134,8 @@ public class PdpMessageGenerator {
* Method to return a list of policies.
*
* @param subGroup PdpSubGroup to retrieve policies from
+ * @return a list of ToscaPolicy
* @throws PfModelException the exception
- * @returns a list of ToscaPolicy
**/
public List<ToscaPolicy> getToscaPolicies(final PdpSubGroup subGroup) throws PfModelException {
@@ -167,7 +171,6 @@ public class PdpMessageGenerator {
* @param pdpInstanceId the pdp instance
* @param pdpState the new state as per the PDP_STATE_CHANGE change message
* @param policies list of policies as per the PDP_UPDATE message
- * @throws PfModelException the exception
*/
protected void updateDeploymentStatus(final String pdpGroupName, final String pdpType, final String pdpInstanceId,
PdpState pdpState, List<ToscaPolicy> policies) {
diff --git a/main/src/main/java/org/onap/policy/pap/main/config/WebConfig.java b/main/src/main/java/org/onap/policy/pap/main/config/WebConfig.java
index d8aee3a7..a6cfdf67 100644
--- a/main/src/main/java/org/onap/policy/pap/main/config/WebConfig.java
+++ b/main/src/main/java/org/onap/policy/pap/main/config/WebConfig.java
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2022 Bell Canada. All rights reserved.
+ * Modifications Copyright (C) 2022 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,7 +21,6 @@
package org.onap.policy.pap.main.config;
-import java.util.Arrays;
import java.util.List;
import org.onap.policy.common.spring.utils.YamlHttpMessageConverter;
import org.springframework.context.annotation.Configuration;
@@ -37,7 +37,7 @@ public class WebConfig implements WebMvcConfigurer {
@Override
public void extendMessageConverters(List<HttpMessageConverter<?>> converters) {
var yamlConverter = new YamlHttpMessageConverter();
- yamlConverter.setSupportedMediaTypes(Arrays.asList(MediaType.parseMediaType("application/yaml")));
+ yamlConverter.setSupportedMediaTypes(List.of(MediaType.parseMediaType("application/yaml")));
converters.add(yamlConverter);
}
} \ No newline at end of file
diff --git a/main/src/main/java/org/onap/policy/pap/main/rest/PolicyComponentsHealthCheckProvider.java b/main/src/main/java/org/onap/policy/pap/main/rest/PolicyComponentsHealthCheckProvider.java
index 53f05a15..4da802df 100644
--- a/main/src/main/java/org/onap/policy/pap/main/rest/PolicyComponentsHealthCheckProvider.java
+++ b/main/src/main/java/org/onap/policy/pap/main/rest/PolicyComponentsHealthCheckProvider.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019-2020 Nordix Foundation.
+ * Copyright (C) 2019-2020, 2022 Nordix Foundation.
* Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2020-2022 Bell Canada. All rights reserved.
* ================================================================================
@@ -88,6 +88,9 @@ public class PolicyComponentsHealthCheckProvider {
@Value("${server.port}")
private int port;
+ @Value("${pap.topic.pdp-pap.name:POLICY-PDP-PAP}")
+ private String topicPolicyPdpPap;
+
/**
* This method is used to initialize clients and executor.
*/
@@ -244,8 +247,8 @@ public class PolicyComponentsHealthCheckProvider {
private HealthCheckReport verifyDmaapClient(HttpClient httpClient, Response resp) {
DmaapGetTopicResponse dmaapResponse = resp.readEntity(DmaapGetTopicResponse.class);
var topicVerificationStatus = (dmaapResponse.getTopics() != null
- && dmaapResponse.getTopics().contains(PapConstants.TOPIC_POLICY_PDP_PAP));
- String message = (topicVerificationStatus ? "PAP to DMaaP connection check is successfull"
+ && dmaapResponse.getTopics().contains(topicPolicyPdpPap));
+ String message = (topicVerificationStatus ? "PAP to DMaaP connection check is successful"
: "PAP to DMaaP connection check failed");
int code = (topicVerificationStatus ? resp.getStatus() : 503);
return createHealthCheckReport(httpClient.getName(), httpClient.getBaseUrl(), code,
diff --git a/main/src/main/java/org/onap/policy/pap/main/rest/SessionData.java b/main/src/main/java/org/onap/policy/pap/main/rest/SessionData.java
index 2abce9b1..4cea257f 100644
--- a/main/src/main/java/org/onap/policy/pap/main/rest/SessionData.java
+++ b/main/src/main/java/org/onap/policy/pap/main/rest/SessionData.java
@@ -3,7 +3,7 @@
* ONAP PAP
* ================================================================================
* Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2021 Nordix Foundation.
+ * Modifications Copyright (C) 2021-2022 Nordix Foundation.
* Modifications Copyright (C) 2022 Bell Canada. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -96,12 +96,12 @@ public class SessionData {
/**
* Map's a policy's identifier to the policies for deployment.
*/
- private Map<ToscaConceptIdentifier, ToscaPolicy> policiesToBeDeployed = new HashMap<>();
+ private final Map<ToscaConceptIdentifier, ToscaPolicy> policiesToBeDeployed = new HashMap<>();
/**
* Set of policies to be undeployed.
*/
- private Set<ToscaConceptIdentifier> policiesToBeUndeployed = new HashSet<>();
+ private final Set<ToscaConceptIdentifier> policiesToBeUndeployed = new HashSet<>();
/**
* User starting requests.
@@ -114,11 +114,11 @@ public class SessionData {
*/
private final DeploymentStatus deployStatus;
- private PolicyAuditManager auditManager;
+ private final PolicyAuditManager auditManager;
- private ToscaServiceTemplateService toscaService;
+ private final ToscaServiceTemplateService toscaService;
- private PdpGroupService pdpGroupService;
+ private final PdpGroupService pdpGroupService;
/**
* Constructs the object.
@@ -368,9 +368,8 @@ public class SessionData {
*
* @param type desired policy type
* @return the active groups supporting the given policy
- * @throws PfModelException if an error occurred
*/
- public List<PdpGroup> getActivePdpGroupsByPolicyType(ToscaConceptIdentifier type) throws PfModelException {
+ public List<PdpGroup> getActivePdpGroupsByPolicyType(ToscaConceptIdentifier type) {
/*
* Cannot use computeIfAbsent() because the enclosed code throws an unchecked exception and handling that would
* obfuscate the code too much, thus disabling the sonar.
@@ -392,7 +391,7 @@ public class SessionData {
/**
* Gets the list of policies to be deployed to the PDPs.
*
- * @returns a list of policies to be deployed
+ * @return a list of policies to be deployed
*/
public List<ToscaPolicy> getPoliciesToBeDeployed() {
return new LinkedList<>(this.policiesToBeDeployed.values());
@@ -401,7 +400,7 @@ public class SessionData {
/**
* Gets the list of policies to be undeployed from the PDPs.
*
- * @returns a list of policies to be undeployed
+ * @return a list of policies to be undeployed
*/
public List<ToscaConceptIdentifier> getPoliciesToBeUndeployed() {
return new LinkedList<>(this.policiesToBeUndeployed);
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 f8c4fb32..19b3c672 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
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019 Nordix Foundation.
+ * Copyright (C) 2019, 2022 Nordix Foundation.
* Modifications Copyright (C) 2019-2021 AT&T Intellectual Property.
* Modifications Copyright (C) 2021-2022 Bell Canada. All rights reserved.
* ================================================================================
@@ -28,6 +28,7 @@ import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
+import lombok.Getter;
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;
@@ -50,6 +51,7 @@ 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.PapStatisticsManager;
+import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.event.ContextClosedEvent;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.context.event.EventListener;
@@ -63,15 +65,29 @@ import org.springframework.stereotype.Component;
*/
@Component
public class PapActivator extends ServiceManagerContainer {
+
+ // topic names
+ @Getter
+ @Value("${pap.topic.pdp-pap.name}")
+ private String topicPolicyPdpPap = "POLICY-PDP-PAP";
+
+ @Getter
+ @Value("${pap.topic.notification.name}")
+ private String topicPolicyNotification = "POLICY-NOTIFICATION";
+
+ @Getter
+ @Value("${pap.topic.heartbeat.name}")
+ private String topicPolicyHeartbeat = "POLICY-HEARTBEAT";
+
private static final String[] MSG_TYPE_NAMES = { "messageName" };
private static final String[] REQ_ID_NAMES = { "response", "responseTo" };
/**
- * Max number of heat beats that can be missed before PAP removes a PDP.
+ * Max number of heart beats that can be missed before PAP removes a PDP.
*/
private static final int MAX_MISSED_HEARTBEATS = 3;
- private PapParameterGroup papParameterGroup;
+ private final PapParameterGroup papParameterGroup;
/**
* Listens for messages on the topic, decodes them into a {@link PdpStatus} message, and then dispatches them to
@@ -142,12 +158,12 @@ public class PapActivator extends ServiceManagerContainer {
() -> heartbeatMsgDispatcher.unregister(PdpMessageType.PDP_STATUS.name()));
addAction("Response Message Dispatcher",
- () -> registerMsgDispatcher(responseMsgDispatcher, PapConstants.TOPIC_POLICY_PDP_PAP),
- () -> unregisterMsgDispatcher(responseMsgDispatcher, PapConstants.TOPIC_POLICY_PDP_PAP));
+ () -> registerMsgDispatcher(responseMsgDispatcher, topicPolicyPdpPap),
+ () -> unregisterMsgDispatcher(responseMsgDispatcher, topicPolicyPdpPap));
addAction("Heartbeat Message Dispatcher",
- () -> registerMsgDispatcher(heartbeatMsgDispatcher, PapConstants.TOPIC_POLICY_HEARTBEAT),
- () -> unregisterMsgDispatcher(heartbeatMsgDispatcher, PapConstants.TOPIC_POLICY_HEARTBEAT));
+ () -> registerMsgDispatcher(heartbeatMsgDispatcher, topicPolicyHeartbeat),
+ () -> unregisterMsgDispatcher(heartbeatMsgDispatcher, topicPolicyHeartbeat));
addAction("topics",
TopicEndpointManager.getManager()::start,
@@ -163,14 +179,14 @@ public class PapActivator extends ServiceManagerContainer {
addAction("PDP publisher",
() -> {
- pdpPub.set(new Publisher<>(PapConstants.TOPIC_POLICY_PDP_PAP));
+ pdpPub.set(new Publisher<>(topicPolicyPdpPap));
startThread(pdpPub.get());
},
() -> pdpPub.get().stop());
addAction("Policy Notification publisher",
() -> {
- notifyPub.set(new Publisher<>(PapConstants.TOPIC_POLICY_NOTIFICATION));
+ notifyPub.set(new Publisher<>(topicPolicyNotification));
startThread(notifyPub.get());
policyNotifier.setPublisher(notifyPub.get());
},
diff --git a/main/src/main/resources/application.yaml b/main/src/main/resources/application.yaml
index ebe94b89..2711e2d1 100644
--- a/main/src/main/resources/application.yaml
+++ b/main/src/main/resources/application.yaml
@@ -27,6 +27,10 @@ server:
pap:
name: PapGroup
aaf: false
+ topic:
+ pdp-pap.name: POLICY-PDP-PAP
+ notification.name: POLICY-NOTIFICATION
+ heartbeat.name: POLICY-HEARTBEAT
pdpParameters:
heartBeatMs: 120000
updateParameters:
@@ -38,24 +42,24 @@ pap:
savePdpStatisticsInDb: true
topicParameterGroup:
topicSources:
- - topic: POLICY-PDP-PAP
+ - topic: ${pap.topic.pdp-pap.name}
servers:
- message-router
topicCommInfrastructure: dmaap
fetchTimeout: 15000
- - topic: POLICY-HEARTBEAT
- effectiveTopic: POLICY-PDP-PAP
+ - topic: ${pap.topic.heartbeat.name}
+ effectiveTopic: ${pap.topic.pdp-pap.name}
consumerGroup: policy-pap
servers:
- message-router
topicCommInfrastructure: dmaap
fetchTimeout: 15000
topicSinks:
- - topic: POLICY-PDP-PAP
+ - topic: ${pap.topic.pdp-pap.name}
servers:
- message-router
topicCommInfrastructure: dmaap
- - topic: POLICY-NOTIFICATION
+ - topic: ${pap.topic.notification.name}
servers:
- message-router
topicCommInfrastructure: dmaap