* ============LICENSE_START=======================================================
* ONAP-PDP-REST
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2018 AT&T Intellectual Property. 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.
* 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.
import org.onap.policy.common.logging.flexlogger.FlexLogger;
import org.onap.policy.common.logging.flexlogger.Logger;
import org.onap.policy.pdp.rest.PapUrlResolver;
-import org.onap.policy.rest.XACMLRestProperties;
+import org.onap.policy.rest.XacmlRestProperties;
import org.onap.policy.xacml.api.XACMLErrorConstants;
import com.att.research.xacml.api.pap.PDPPolicy;
/**
* NotificationController Checks for the Updated and Removed policies. It notifies the Server to send Notifications to
* the Client.
- *
+ *
* @version 0.2
*
*/
private static Boolean notificationFlag = false;
public void check(PDPStatus newStatus, Map<String, PolicyDef> policyContainer) {
- boolean updated = false;
- boolean removed = false;
+
+ LOGGER.info("NotificationController: checking for updated and removed policies.");
+ boolean isUpdated = false;
+ boolean isRemoved = false;
Notification notification = new Notification();
HashSet<Removed> removedPolicies = new HashSet<>();
HashSet<Updated> updatedPolicies = new HashSet<>();
if (oldStatus == null) {
oldStatus = newStatus;
}
- // Debugging purpose only.
- LOGGER.debug("old config Status :" + oldStatus.getStatus());
- LOGGER.debug("new config Status :" + newStatus.getStatus());
+
+ LOGGER.info("old config Status :" + oldStatus.getStatus());
+ LOGGER.info("new config Status :" + newStatus.getStatus());
// Depending on the above condition taking the Change as an Update.
if (oldStatus.getStatus().toString() != newStatus.getStatus().toString()) {
LOGGER.info("There is an Update to the PDP");
LOGGER.debug(oldStatus.getLoadedPolicies());
LOGGER.debug(newStatus.getLoadedPolicies());
+
// Check if there is an Update/additions in the policy.
+ LOGGER.info("NotificationController: check for updated or new policies");
for (PDPPolicy newPolicy : newStatus.getLoadedPolicies()) {
boolean change = true;
for (PDPPolicy oldPolicy : oldStatus.getLoadedPolicies()) {
}
// if there is a change Send the notifications to the Client.
if (change) {
+ LOGGER.info("NotificationController: sending update/new policy notification");
sendUpdate(newPolicy, policyContainer);
- updated = true;
+ isUpdated = true;
updatedPolicies.add(this.updated);
}
}
// Check if there is any removal of policy.
+ LOGGER.info("NotificationController: check for removed policies");
for (PDPPolicy oldPolicy : oldStatus.getLoadedPolicies()) {
boolean change = true;
for (PDPPolicy newPolicy : newStatus.getLoadedPolicies()) {
}
// if there is a change Send the notifications to the Client.
if (change) {
+ LOGGER.info("NotificationController: sending removal notification");
sendremove(oldPolicy);
- removed = true;
+ isRemoved = true;
removedPolicies.add(this.removed);
}
}
// At the end the oldStatus must be updated with the newStatus.
oldStatus = newStatus;
// Sending Notification to the Server to pass over to the clients
- if (updated || removed) {
+ if (isUpdated || isRemoved) {
// Call the Notification Server..
notification.setRemovedPolicies(removedPolicies);
notification.setLoadedPolicies(updatedPolicies);
- notification = setUpdateTypes(updated, removed, notification);
+ notification = setUpdateTypes(isUpdated, isRemoved, notification);
ObjectWriter om = new ObjectMapper().writer();
try {
setNotificationJSON(om.writeValueAsString(notification));
- LOGGER.info(notificationJSON);
+ LOGGER.info("NotificationController notificationJson: " + notificationJSON);
// NotificationServer Method here.
setPropNotification();
if (("ueb".equals(propNotificationType) || "dmaap".equals(propNotificationType))
}
private static void setPropNotification() {
- propNotificationType = XACMLProperties.getProperty(XACMLRestProperties.PROP_NOTIFICATION_TYPE);
- pdpURL = XACMLProperties.getProperty(XACMLRestProperties.PROP_PDP_ID);
+ propNotificationType = XACMLProperties.getProperty(XacmlRestProperties.PROP_NOTIFICATION_TYPE);
+ pdpURL = XACMLProperties.getProperty(XacmlRestProperties.PROP_PDP_ID);
}
public static void sendNotification() {
if (notificationFlag) {
try {
+ LOGGER.info("NotificationController: calling NotificationServer to sendNotification");
NotificationServer.sendNotification(notificationJSON, propNotificationType, pdpURL);
} catch (Exception e) {
LOGGER.info(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error in sending the Event Notification: "
} else if (newPolicy.getName().contains(".Action_")) {
// Take Configuration copy to PDP Webapps.
// Action policies have .json as extension.
- String urlString = "$URL/Action/" + newPolicy.getId().substring(0, newPolicy.getId().lastIndexOf("."))
+ String urlString = "$URL/Action/" + newPolicy.getId().substring(0, newPolicy.getId().lastIndexOf('.'))
+ ".json";
callPap(urlString, "Action");
}
private void removeFile(PDPPolicy oldPolicy) {
try {
- Path removedPolicyFile = Paths.get(XACMLProperties.getProperty(XACMLRestProperties.PROP_PDP_CONFIG)
+ Path removedPolicyFile = Paths.get(XACMLProperties.getProperty(XacmlRestProperties.PROP_PDP_CONFIG)
+ File.separator + oldPolicy.getId());
Files.deleteIfExists(removedPolicyFile);
boolean delete = false;
if (oldPolicy.getName().contains(".Config_")) {
delete = true;
dir = new File(
- XACMLProperties.getProperty(XACMLRestProperties.PROP_PDP_WEBAPPS) + File.separator + "Config");
+ XACMLProperties.getProperty(XacmlRestProperties.PROP_PDP_WEBAPPS) + File.separator + "Config");
} else if (oldPolicy.getName().contains(".Action_")) {
delete = true;
dir = new File(
- XACMLProperties.getProperty(XACMLRestProperties.PROP_PDP_WEBAPPS) + File.separator + "Action");
+ XACMLProperties.getProperty(XacmlRestProperties.PROP_PDP_WEBAPPS) + File.separator + "Action");
}
if (delete) {
FileFilter fileFilter = new WildcardFileFilter(
- oldPolicy.getId().substring(0, oldPolicy.getId().lastIndexOf(".")) + ".*");
+ oldPolicy.getId().substring(0, oldPolicy.getId().lastIndexOf('.')) + ".*");
File[] configFile = dir.listFiles(fileFilter);
if (configFile.length == 1) {
Files.deleteIfExists(configFile[0].toPath());
private void callPap(String urlString, String type) {
Path configLocation = Paths
- .get(XACMLProperties.getProperty(XACMLRestProperties.PROP_PDP_WEBAPPS) + File.separator + type);
+ .get(XACMLProperties.getProperty(XacmlRestProperties.PROP_PDP_WEBAPPS) + File.separator + type);
if (Files.notExists(configLocation)) {
try {
Files.createDirectories(configLocation);
String papPath = papUrls.getUrl();
papPath = papPath.substring(0, papPath.lastIndexOf("/pap"));
String papAddress = urlString.replace("$URL", papPath);
- String fileName = papAddress.substring(papAddress.lastIndexOf("/") + 1);
+ String fileName = papAddress.substring(papAddress.lastIndexOf('/') + 1);
String fileLocation = configLocation.toString() + File.separator + fileName;
try {
URL papURL = new URL(papAddress);