aboutsummaryrefslogtreecommitdiffstats
path: root/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/XACMLPapServlet.java
diff options
context:
space:
mode:
Diffstat (limited to 'ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/XACMLPapServlet.java')
-rw-r--r--ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/XACMLPapServlet.java442
1 files changed, 258 insertions, 184 deletions
diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/XACMLPapServlet.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/XACMLPapServlet.java
index 30d09edb5..889905eb6 100644
--- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/XACMLPapServlet.java
+++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/XACMLPapServlet.java
@@ -42,8 +42,6 @@ import java.util.Properties;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.CopyOnWriteArrayList;
-import javax.persistence.EntityManagerFactory;
-import javax.persistence.Persistence;
import javax.persistence.PersistenceException;
import javax.servlet.Servlet;
import javax.servlet.ServletConfig;
@@ -93,7 +91,8 @@ import org.onap.policy.xacml.std.pap.StdPDPStatus;
/**
* Servlet implementation class XacmlPapServlet
*/
-@WebServlet(description = "Implements the XACML PAP RESTful API.", urlPatterns = {"/"}, loadOnStartup = 1,
+@WebServlet(description = "Implements the XACML PAP RESTful API.", urlPatterns = {"/"},
+ loadOnStartup = 1,
initParams = {@WebInitParam(name = "XACML_PROPERTIES_NAME", value = "xacml.pap.properties",
description = "The location of the properties file holding configuration information.")})
public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeListener, Runnable {
@@ -114,23 +113,23 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
/*
* List of Admin Console URLs. Used to send notifications when configuration changes.
*
- * The CopyOnWriteArrayList *should* protect from concurrency errors. This list is seldom changed
- * but often read, so the costs of this approach make sense.
+ * The CopyOnWriteArrayList *should* protect from concurrency errors. This list is seldom
+ * changed but often read, so the costs of this approach make sense.
*/
- private static final CopyOnWriteArrayList<String> adminConsoleURLStringList = new CopyOnWriteArrayList<>();
+ private static final CopyOnWriteArrayList<String> adminConsoleURLStringList =
+ new CopyOnWriteArrayList<>();
private static String configHome;
private static String actionHome;
/*
- * This PAP instance's own URL. Need this when creating URLs to send to the PDPs so they can GET the
- * Policy files from this process.
+ * This PAP instance's own URL. Need this when creating URLs to send to the PDPs so they can GET
+ * the Policy files from this process.
*/
- public static String papURL = null;
+ private static String papUrl = null;
// The heartbeat thread.
private static Heartbeat heartbeat = null;
private static Thread heartbeatThread = null;
- private static EntityManagerFactory emf;
- public static PolicyDBDao policyDBDao;
+ private static PolicyDBDao policyDbDao;
/*
* papEngine - This is our engine workhorse that manages the PDP Groups and Nodes.
*/
@@ -182,7 +181,8 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
String hostname = InetAddress.getLocalHost().getCanonicalHostName();
baseLoggingContext.setServer(hostname);
} catch (UnknownHostException e) {
- LOGGER.warn(XACMLErrorConstants.ERROR_SYSTEM_ERROR + "Unable to get hostname for logging", e);
+ LOGGER.warn(XACMLErrorConstants.ERROR_SYSTEM_ERROR
+ + "Unable to get hostname for logging", e);
}
// Initialize
@@ -207,49 +207,56 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
}
// Integer will throw an exception of anything is missing or
// unrecognized
- int papTransWait = Integer.parseInt(XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_TRANS_WAIT));
- int papTransTimeout =
- Integer.parseInt(XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_TRANS_TIMEOUT));
- int papAuditTimeout =
- Integer.parseInt(XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_AUDIT_TIMEOUT));
+ int papTransWait = Integer
+ .parseInt(XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_TRANS_WAIT));
+ int papTransTimeout = Integer.parseInt(
+ XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_TRANS_TIMEOUT));
+ int papAuditTimeout = Integer.parseInt(
+ XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_AUDIT_TIMEOUT));
// Boolean will default to false if anything is missing or
// unrecognized
- boolean papAuditFlag =
- Boolean.parseBoolean(XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_RUN_AUDIT_FLAG));
- boolean papFileSystemAudit =
- Boolean.parseBoolean(XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_AUDIT_FLAG));
- String papDependencyGroups = XACMLProperties.getProperty(XACMLRestProperties.PAP_DEPENDENCY_GROUPS);
+ boolean papAuditFlag = Boolean.parseBoolean(
+ XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_RUN_AUDIT_FLAG));
+ boolean papFileSystemAudit = Boolean.parseBoolean(
+ XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_AUDIT_FLAG));
+ String papDependencyGroups =
+ XACMLProperties.getProperty(XACMLRestProperties.PAP_DEPENDENCY_GROUPS);
if (papDependencyGroups == null) {
throw new PAPException("papDependencyGroups is null");
}
setPAPDependencyGroups(papDependencyGroups);
// Integer will throw an exception of anything is missing or
// unrecognized
- int fpMonitorInterval =
- Integer.parseInt(XACMLProperties.getProperty(IntegrityMonitorProperties.FP_MONITOR_INTERVAL));
- int failedCounterThreshold =
- Integer.parseInt(XACMLProperties.getProperty(IntegrityMonitorProperties.FAILED_COUNTER_THRESHOLD));
- int testTransInterval =
- Integer.parseInt(XACMLProperties.getProperty(IntegrityMonitorProperties.TEST_TRANS_INTERVAL));
- int writeFpcInterval =
- Integer.parseInt(XACMLProperties.getProperty(IntegrityMonitorProperties.WRITE_FPC_INTERVAL));
- LOGGER.debug("\n\n\n**************************************" + "\n*************************************"
- + "\n" + "\n papDbDriver = " + papDbDriver + "\n papDbUrl = " + papDbUrl + "\n papDbUser = "
- + papDbUser + "\n papTransWait = " + papTransWait + "\n papTransTimeout = " + papTransTimeout
- + "\n papAuditTimeout = " + papAuditTimeout + "\n papAuditFlag = " + papAuditFlag
- + "\n papFileSystemAudit = " + papFileSystemAudit + "\n papResourceName = " + papResourceName
- + "\n fpMonitorInterval = " + fpMonitorInterval + "\n failedCounterThreshold = "
- + failedCounterThreshold + "\n testTransInterval = " + testTransInterval + "\n writeFpcInterval = "
- + writeFpcInterval + "\n papSiteName = " + papSiteName + "\n papNodeType = " + papNodeType
- + "\n papDependencyGroupsList = " + papDependencyGroups + "\n papIntegrityAuditPeriodSeconds = "
- + papIntegrityAuditPeriodSeconds + "\n\n*************************************"
+ int fpMonitorInterval = Integer.parseInt(
+ XACMLProperties.getProperty(IntegrityMonitorProperties.FP_MONITOR_INTERVAL));
+ int failedCounterThreshold = Integer.parseInt(XACMLProperties
+ .getProperty(IntegrityMonitorProperties.FAILED_COUNTER_THRESHOLD));
+ int testTransInterval = Integer.parseInt(
+ XACMLProperties.getProperty(IntegrityMonitorProperties.TEST_TRANS_INTERVAL));
+ int writeFpcInterval = Integer.parseInt(
+ XACMLProperties.getProperty(IntegrityMonitorProperties.WRITE_FPC_INTERVAL));
+ LOGGER.debug("\n\n\n**************************************"
+ + "\n*************************************" + "\n" + "\n papDbDriver = "
+ + papDbDriver + "\n papDbUrl = " + papDbUrl + "\n papDbUser = " + papDbUser
+ + "\n papTransWait = " + papTransWait + "\n papTransTimeout = "
+ + papTransTimeout + "\n papAuditTimeout = " + papAuditTimeout
+ + "\n papAuditFlag = " + papAuditFlag + "\n papFileSystemAudit = "
+ + papFileSystemAudit + "\n papResourceName = " + papResourceName
+ + "\n fpMonitorInterval = " + fpMonitorInterval
+ + "\n failedCounterThreshold = " + failedCounterThreshold
+ + "\n testTransInterval = " + testTransInterval + "\n writeFpcInterval = "
+ + writeFpcInterval + "\n papSiteName = " + papSiteName + "\n papNodeType = "
+ + papNodeType + "\n papDependencyGroupsList = " + papDependencyGroups
+ + "\n papIntegrityAuditPeriodSeconds = " + papIntegrityAuditPeriodSeconds
+ + "\n\n*************************************"
+ "\n**************************************");
// Pull custom persistence settings
Properties properties;
try {
properties = XACMLProperties.getProperties();
- LOGGER.debug("\n\n\n**************************************" + "\n**************************************"
- + "\n\n" + "properties = " + properties + "\n\n**************************************");
+ LOGGER.debug("\n\n\n**************************************"
+ + "\n**************************************" + "\n\n" + "properties = "
+ + properties + "\n\n**************************************");
} catch (IOException e) {
PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "XACMLPapServlet",
" Error loading properties with: " + "XACMLProperties.getProperties()");
@@ -257,8 +264,8 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
}
// Create an IntegrityMonitor
if (properties.getProperty(PERSISTENCE_JDBC_PWD) != null) {
- properties.setProperty(PERSISTENCE_JDBC_PWD,
- CryptoUtils.decryptTxtNoExStr(properties.getProperty(PERSISTENCE_JDBC_PWD, "")));
+ properties.setProperty(PERSISTENCE_JDBC_PWD, CryptoUtils
+ .decryptTxtNoExStr(properties.getProperty(PERSISTENCE_JDBC_PWD, "")));
}
im = IntegrityMonitor.getInstance(papResourceName, properties);
// Create an IntegrityAudit
@@ -268,39 +275,41 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
// we are about to call the PDPs and give them their configuration.
// To do that we need to have the URL of this PAP so we can
// construct the Policy file URLs
- setPAPURL(XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_URL));
+ setPapUrl(XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_URL));
// Create the policyDBDao
- setPolicyDBDao();
+ setPolicyDbDao();
// Load our PAP engine, first create a factory
- ONAPPapEngineFactory factory = ONAPPapEngineFactory
- .newInstance(XACMLProperties.getProperty(XACMLProperties.PROP_PAP_PAPENGINEFACTORY));
+ ONAPPapEngineFactory factory = ONAPPapEngineFactory.newInstance(
+ XACMLProperties.getProperty(XACMLProperties.PROP_PAP_PAPENGINEFACTORY));
// The factory knows how to go about creating a PAP Engine
setPAPEngine(factory.newEngine());
if (((org.onap.policy.xacml.std.pap.StdEngine) papEngine).wasDefaultGroupJustAdded) {
createDefaultGroupOnInit();
}
- policyDBDao.setPapEngine(XACMLPapServlet.papEngine);
- if (Boolean.parseBoolean(XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_RUN_AUDIT_FLAG))) {
+ policyDbDao.setPapEngine(XACMLPapServlet.papEngine);
+ if (Boolean.parseBoolean(
+ XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_RUN_AUDIT_FLAG))) {
/*
* Auditing the local File System groups to be in sync with the Database
*/
// get an AuditTransaction to lock out all other transactions
- PolicyDBDaoTransaction auditTrans = policyDBDao.getNewAuditTransaction();
+ PolicyDBDaoTransaction auditTrans = policyDbDao.getNewAuditTransaction();
LOGGER.info("PapServlet: calling auditLocalFileSystem for PDP group audit");
LOGGER.info("PapServlet: old group is " + papEngine.getDefaultGroup().toString());
// get the current filesystem group and update from the database if needed
StdPDPGroup group = (StdPDPGroup) papEngine.getDefaultGroup();
- StdPDPGroup updatedGroup = policyDBDao.auditLocalFileSystem(group);
+ StdPDPGroup updatedGroup = policyDbDao.auditLocalFileSystem(group);
if (updatedGroup != null) {
papEngine.updateGroup(updatedGroup);
}
- LOGGER.info("PapServlet: updated group is " + papEngine.getDefaultGroup().toString());
+ LOGGER.info(
+ "PapServlet: updated group is " + papEngine.getDefaultGroup().toString());
// sync up the config data from DB to file system
LOGGER.info("PapServlet: Sync config data from DB to file system");
- policyDBDao.synchronizeConfigDataInFileSystem();
+ policyDbDao.synchronizeConfigDataInFileSystem();
// release the transaction lock
auditTrans.close();
@@ -309,20 +318,23 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
// Configurable - have the PAP servlet initiate sending the latest
// PDP policy/pip configuration
// to all its known PDP nodes.
- if (Boolean.parseBoolean(XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_INITIATE_PDP_CONFIG))) {
+ if (Boolean.parseBoolean(XACMLProperties
+ .getProperty(XACMLRestProperties.PROP_PAP_INITIATE_PDP_CONFIG))) {
startInitiateThreadService(new Thread(this));
}
// After startup, the PAP does Heartbeat's to each of the PDPs
// periodically
startHeartBeatService(new Heartbeat(XACMLPapServlet.papEngine));
} catch (FactoryException | PAPException e) {
- PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, e, "XACMLPapServlet", " Failed to create engine");
- throw new ServletException(XACMLErrorConstants.ERROR_SYSTEM_ERROR + "PAP not initialized; error: " + e);
+ PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, e, "XACMLPapServlet",
+ " Failed to create engine");
+ throw new ServletException(
+ XACMLErrorConstants.ERROR_SYSTEM_ERROR + "PAP not initialized; error: " + e);
} catch (Exception e) {
PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, e, "XACMLPapServlet",
" Failed to create engine - unexpected error");
- throw new ServletException(
- XACMLErrorConstants.ERROR_SYSTEM_ERROR + "PAP not initialized; unexpected error: " + e);
+ throw new ServletException(XACMLErrorConstants.ERROR_SYSTEM_ERROR
+ + "PAP not initialized; unexpected error: " + e);
}
}
@@ -330,11 +342,12 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
private void createDefaultGroupOnInit() {
PolicyDBDaoTransaction addNewGroup = null;
try {
- addNewGroup = policyDBDao.getNewTransaction();
+ addNewGroup = policyDbDao.getNewTransaction();
OnapPDPGroup group = papEngine.getDefaultGroup();
- addNewGroup.createGroup(group.getId(), group.getName(), group.getDescription(), "automaticallyAdded");
+ addNewGroup.createGroup(group.getId(), group.getName(), group.getDescription(),
+ "automaticallyAdded");
addNewGroup.commitTransaction();
- addNewGroup = policyDBDao.getNewTransaction();
+ addNewGroup = policyDbDao.getNewTransaction();
addNewGroup.changeDefaultGroup(group, "automaticallyAdded");
addNewGroup.commitTransaction();
} catch (Exception e) {
@@ -351,7 +364,8 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
initiateThread.start();
}
- private static void mapperWriteValue(ObjectMapper mapper, HttpServletResponse response, Object value) {
+ private static void mapperWriteValue(ObjectMapper mapper, HttpServletResponse response,
+ Object value) {
try {
mapper.writeValue(response.getOutputStream(), value);
} catch (Exception e) {
@@ -365,25 +379,24 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
XACMLPapServlet.heartbeatThread.start();
}
- private static void setPolicyDBDao() throws ServletException {
+ private static void setPolicyDbDao() throws ServletException {
try {
- policyDBDao = PolicyDBDao.getPolicyDBDaoInstance();
+ policyDbDao = PolicyDBDao.getPolicyDBDaoInstance();
} catch (Exception e) {
throw new ServletException("Unable to Create Policy DBDao Instance", e);
}
}
- private static void setEMF(Properties properties) throws ServletException {
- emf = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT, properties);
- if (emf == null) {
- PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE
- + " Error creating entity manager factory with persistence unit: " + PERSISTENCE_UNIT);
- throw new ServletException("Unable to create Entity Manager Factory");
- }
+ public static PolicyDBDao getPolicyDbDao() {
+ return policyDbDao;
}
- private static void setPAPURL(String papURL) {
- XACMLPapServlet.papURL = papURL;
+ private static void setPapUrl(String papUrl) {
+ XACMLPapServlet.papUrl = papUrl;
+ }
+
+ public static String getPapUrl() {
+ return papUrl;
}
private static void setPAPEngine(PAPPolicyEngine newEngine) {
@@ -399,9 +412,11 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
papDependencyGroupsFlatArray[i] = papDependencyGroupsFlatArray[i].trim();
}
try {
- if (XACMLProperties.getProperty(XACMLRestProperties.PAP_INTEGRITY_AUDIT_PERIOD_SECONDS) != null) {
- papIntegrityAuditPeriodSeconds = Integer.parseInt(
- XACMLProperties.getProperty(XACMLRestProperties.PAP_INTEGRITY_AUDIT_PERIOD_SECONDS).trim());
+ if (XACMLProperties.getProperty(
+ XACMLRestProperties.PAP_INTEGRITY_AUDIT_PERIOD_SECONDS) != null) {
+ papIntegrityAuditPeriodSeconds = Integer.parseInt(XACMLProperties
+ .getProperty(XACMLRestProperties.PAP_INTEGRITY_AUDIT_PERIOD_SECONDS)
+ .trim());
}
} catch (Exception e) {
String msg = "integrity_audit_period_seconds ";
@@ -411,7 +426,8 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
throw e;
}
} catch (Exception e) {
- PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "XACMLPapServlet", " ERROR: Bad property entry");
+ PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "XACMLPapServlet",
+ " ERROR: Bad property entry");
throw new PAPException(e);
}
}
@@ -428,7 +444,8 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
setPapDbDriver(papDbDriver);
papDbUrl = XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_DB_URL);
if (papDbUrl == null) {
- PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, "XACMLPapServlet", " ERROR: Bad papDbUrl property entry");
+ PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, "XACMLPapServlet",
+ " ERROR: Bad papDbUrl property entry");
throw new PAPException("papDbUrl is null");
}
setPapDbUrl(papDbUrl);
@@ -439,8 +456,8 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
throw new PAPException("papDbUser is null");
}
setPapDbUser(papDbUser);
- papDbPd = CryptoUtils
- .decryptTxtNoExStr(XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_DB_PASSWORD, ""));
+ papDbPd = CryptoUtils.decryptTxtNoExStr(
+ XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_DB_PASSWORD, ""));
if (papDbPd == null) {
PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, "XACMLPapServlet",
" ERROR: Bad papDbPassword property entry");
@@ -462,16 +479,18 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
// PDPId File location
XACMLPapServlet.pdpFile = XACMLProperties.getProperty(XACMLRestProperties.PROP_PDP_IDFILE);
if (XACMLPapServlet.pdpFile == null) {
- PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE + " The PDP Id Authentication File Property is not valid: "
+ PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE
+ + " The PDP Id Authentication File Property is not valid: "
+ XACMLRestProperties.PROP_PDP_IDFILE);
- throw new PAPException("The PDP Id Authentication File Property :" + XACMLRestProperties.PROP_PDP_IDFILE
- + " is not Valid. ");
+ throw new PAPException("The PDP Id Authentication File Property :"
+ + XACMLRestProperties.PROP_PDP_IDFILE + " is not Valid. ");
}
}
/**
- * Thread used only during PAP startup to initiate change messages to all known PDPs. This must be
- * on a separate thread so that any GET requests from the PDPs during this update can be serviced.
+ * Thread used only during PAP startup to initiate change messages to all known PDPs. This must
+ * be on a separate thread so that any GET requests from the PDPs during this update can be
+ * serviced.
*/
@Override
public void run() {
@@ -498,7 +517,8 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
XACMLPapServlet.heartbeatThread.join();
} catch (InterruptedException e) {
XACMLPapServlet.heartbeatThread.interrupt();
- PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, e, "XACMLPapServlet", " Error stopping heartbeat");
+ PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, e, "XACMLPapServlet",
+ " Error stopping heartbeat");
}
}
if (initiateThread != null) {
@@ -507,7 +527,8 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
initiateThread.join();
} catch (InterruptedException e) {
initiateThread.interrupt();
- PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, e, "XACMLPapServlet", " Error stopping thread");
+ PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, e, "XACMLPapServlet",
+ " Error stopping thread");
}
}
}
@@ -517,15 +538,16 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
}
/**
- * Called by: - PDP nodes to register themselves with the PAP, and - Admin Console to make changes
- * in the PDP Groups.
+ * Called by: - PDP nodes to register themselves with the PAP, and - Admin Console to make
+ * changes in the PDP Groups.
*
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
- ONAPLoggingContext loggingContext = ONAPLoggingUtils.getLoggingContextForRequest(request, baseLoggingContext);
+ ONAPLoggingContext loggingContext =
+ ONAPLoggingUtils.getLoggingContextForRequest(request, baseLoggingContext);
setLoggingContext(loggingContext, "doPost", "PAP.post");
PolicyDBDaoTransaction pdpTransaction = null;
try {
@@ -534,8 +556,9 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
loggingContext.metricEnded();
PolicyLogger.metrics("XACMLPapServlet doPost im startTransaction");
} catch (AdministrativeStateException ae) {
- String message = "POST interface called for PAP " + papResourceName + " but it has an Administrative"
- + " state of " + im.getStateManager().getAdminState() + "\n Exception Message: "
+ String message = "POST interface called for PAP " + papResourceName
+ + " but it has an Administrative" + " state of "
+ + im.getStateManager().getAdminState() + "\n Exception Message: "
+ PolicyUtils.CATCH_EXCEPTION;
LOGGER.error(MessageCodes.ERROR_SYSTEM_ERROR + " " + message, ae);
loggingContext.metricEnded();
@@ -545,8 +568,10 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
setResponseError(response, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, message);
return;
} catch (StandbyStatusException se) {
- String message = "POST interface called for PAP " + papResourceName + " but it has a Standby Status"
- + " of " + im.getStateManager().getStandbyStatus() + "\n Exception Message: " + se.getMessage();
+ String message = "POST interface called for PAP " + papResourceName
+ + " but it has a Standby Status" + " of "
+ + im.getStateManager().getStandbyStatus() + "\n Exception Message: "
+ + se.getMessage();
LOGGER.error(MessageCodes.ERROR_SYSTEM_ERROR + " " + message, se);
loggingContext.metricEnded();
PolicyLogger.metrics("XACMLPapServlet doPost im startTransaction");
@@ -583,7 +608,8 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
}
}
loggingContext.metricStarted();
- getAcServiceInstance().doAcPost(request, response, groupId, loggingContext, papEngine);
+ getAcServiceInstance().doAcPost(request, response, groupId, loggingContext,
+ papEngine);
loggingContext.metricEnded();
PolicyLogger.metrics("XACMLPapServlet doPost doACPost");
loggingContext.transactionEnded();
@@ -604,20 +630,25 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
LOGGER.info("Unknown PDP: " + id);
// Check PDP ID
if (CheckPDP.validateID(id)) {
- pdpTransaction = policyDBDao.getNewTransaction();
+ pdpTransaction = policyDbDao.getNewTransaction();
try {
- pdpTransaction.addPdpToGroup(id, XACMLPapServlet.papEngine.getDefaultGroup().getId(), id,
- "Registered on first startup", Integer.parseInt(jmxport), "PDP autoregister");
- XACMLPapServlet.papEngine.newPDP(id, XACMLPapServlet.papEngine.getDefaultGroup(), id,
+ pdpTransaction.addPdpToGroup(id,
+ XACMLPapServlet.papEngine.getDefaultGroup().getId(), id,
+ "Registered on first startup", Integer.parseInt(jmxport),
+ "PDP autoregister");
+ XACMLPapServlet.papEngine.newPDP(id,
+ XACMLPapServlet.papEngine.getDefaultGroup(), id,
"Registered on first startup", Integer.parseInt(jmxport));
- } catch (NullPointerException | PAPException | IllegalArgumentException | IllegalStateException
- | PersistenceException | PolicyDBException e) {
+ } catch (NullPointerException | PAPException | IllegalArgumentException
+ | IllegalStateException | PersistenceException | PolicyDBException e) {
pdpTransaction.rollbackTransaction();
String message = "Failed to create new PDP for id: " + id;
- PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, "XACMLPapServlet", " " + message);
+ PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, "XACMLPapServlet",
+ " " + message);
loggingContext.transactionEnded();
PolicyLogger.audit("Transaction Failed - See Error.log");
- setResponseError(response, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage());
+ setResponseError(response, HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
+ e.getMessage());
im.endTransaction();
return;
}
@@ -635,7 +666,8 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW + " " + message);
loggingContext.transactionEnded();
PolicyLogger.audit("Transaction Failed - See Error.log");
- setResponseError(response, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, message);
+ setResponseError(response, HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
+ message);
im.endTransaction();
return;
}
@@ -674,8 +706,8 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
LOGGER.error(e);
}
if (group == null) {
- PolicyLogger.error(
- MessageCodes.ERROR_PROCESS_FLOW + " PDP not associated with any group, even the default");
+ PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW
+ + " PDP not associated with any group, even the default");
loggingContext.transactionEnded();
PolicyLogger.audit("Transaction Failed - See Error.log");
setResponseError(response, HttpServletResponse.SC_UNAUTHORIZED,
@@ -748,7 +780,8 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
LOGGER.debug(XACMLErrorConstants.ERROR_PROCESS_FLOW + "POST exception: " + e, e);
loggingContext.transactionEnded();
PolicyLogger.audit("Transaction Failed - See Error.log");
- setResponseError(response, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage());
+ setResponseError(response, HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
+ e.getMessage());
im.endTransaction();
return;
}
@@ -774,7 +807,8 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
- ONAPLoggingContext loggingContext = ONAPLoggingUtils.getLoggingContextForRequest(request, baseLoggingContext);
+ ONAPLoggingContext loggingContext =
+ ONAPLoggingUtils.getLoggingContextForRequest(request, baseLoggingContext);
setLoggingContext(loggingContext, "doGet", "PAP.get");
loggingContext.metricStarted();
XACMLRest.dumpRequest(request);
@@ -798,8 +832,10 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
loggingContext.metricEnded();
PolicyLogger.metrics("XACMLPapServlet doGet im startTransaction");
} catch (AdministrativeStateException ae) {
- String message = "GET interface called for PAP " + papResourceName + " but it has an Administrative"
- + " state of " + im.getStateManager().getAdminState() + "\n Exception Message: " + ae.getMessage();
+ String message = "GET interface called for PAP " + papResourceName
+ + " but it has an Administrative" + " state of "
+ + im.getStateManager().getAdminState() + "\n Exception Message: "
+ + ae.getMessage();
LOGGER.info(message, ae);
PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR + " " + message);
loggingContext.transactionEnded();
@@ -807,8 +843,10 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
setResponseError(response, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, message);
return;
} catch (StandbyStatusException se) {
- String message = "GET interface called for PAP " + papResourceName + " but it has a Standby Status" + " of "
- + im.getStateManager().getStandbyStatus() + "\n Exception Message: " + se.getMessage();
+ String message = "GET interface called for PAP " + papResourceName
+ + " but it has a Standby Status" + " of "
+ + im.getStateManager().getStandbyStatus() + "\n Exception Message: "
+ + se.getMessage();
LOGGER.info(message, se);
PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR + " " + message);
loggingContext.transactionEnded();
@@ -850,7 +888,8 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
// this is from the Admin Console, so handle separately
try {
loggingContext.metricStarted();
- getAcServiceInstance().doAcGet(request, response, groupId, loggingContext, papEngine);
+ getAcServiceInstance().doAcGet(request, response, groupId, loggingContext,
+ papEngine);
loggingContext.metricEnded();
PolicyLogger.metrics("XACMLPapServlet doGet doACGet");
} catch (IOException e) {
@@ -874,7 +913,8 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
// Is it known?
if (pdp == null) {
// Check if request came from localhost
- if ("localhost".equals(request.getRemoteHost()) || request.getRemoteHost().equals(request.getLocalAddr())) {
+ if ("localhost".equals(request.getRemoteHost())
+ || request.getRemoteHost().equals(request.getLocalAddr())) {
// Return status information - basically all the groups
loggingContext.setServiceName("PAP.getGroups");
Set<OnapPDPGroup> groups = null;
@@ -882,10 +922,12 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
groups = papEngine.getOnapPDPGroups();
} catch (PAPException e) {
LOGGER.debug(e);
- PolicyLogger.error(MessageCodes.ERROR_UNKNOWN, e, "XACMLPapServlet", " GET exception");
+ PolicyLogger.error(MessageCodes.ERROR_UNKNOWN, e, "XACMLPapServlet",
+ " GET exception");
loggingContext.transactionEnded();
PolicyLogger.audit("Transaction Failed - See Error.log");
- setResponseError(response, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage());
+ setResponseError(response, HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
+ e.getMessage());
im.endTransaction();
return;
}
@@ -898,8 +940,8 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
im.endTransaction();
return;
}
- String message =
- "Unknown PDP: " + id + " from " + request.getRemoteHost() + " us: " + request.getLocalAddr();
+ String message = "Unknown PDP: " + id + " from " + request.getRemoteHost() + " us: "
+ + request.getLocalAddr();
PolicyLogger.error(MessageCodes.ERROR_PERMISSIONS + " " + message);
loggingContext.transactionEnded();
PolicyLogger.audit("Transaction Failed - See Error.log");
@@ -946,13 +988,14 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
return;
}
try {
- LOGGER.warn("PolicyDebugging: Policy Validity: " + policy.isValid() + "\n " + "Policy Name : "
- + policy.getName() + "\n Policy URI: " + policy.getLocation().toString());
+ LOGGER.warn("PolicyDebugging: Policy Validity: " + policy.isValid() + "\n "
+ + "Policy Name : " + policy.getName() + "\n Policy URI: "
+ + policy.getLocation().toString());
} catch (PAPException | IOException e) {
LOGGER.error(e);
}
- try (InputStream is =
- new FileInputStream(((StdPDPGroup) group).getDirectory().toString() + File.separator + policyId);
+ try (InputStream is = new FileInputStream(
+ ((StdPDPGroup) group).getDirectory().toString() + File.separator + policyId);
OutputStream os = response.getOutputStream()) {
// Send the policy back
IOUtils.copy(is, os);
@@ -979,7 +1022,8 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
@Override
protected void doPut(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
- ONAPLoggingContext loggingContext = ONAPLoggingUtils.getLoggingContextForRequest(request, baseLoggingContext);
+ ONAPLoggingContext loggingContext =
+ ONAPLoggingUtils.getLoggingContextForRequest(request, baseLoggingContext);
setLoggingContext(loggingContext, "doPut", "PAP.put");
try {
loggingContext.metricStarted();
@@ -989,9 +1033,11 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
} catch (IntegrityMonitorException e) {
String message = "PUT interface called for PAP " + papResourceName;
if (e instanceof AdministrativeStateException) {
- message += " but it has an Administrative state of " + im.getStateManager().getAdminState();
+ message += " but it has an Administrative state of "
+ + im.getStateManager().getAdminState();
} else if (e instanceof StandbyStatusException) {
- message += " but it has a Standby Status of " + im.getStateManager().getStandbyStatus();
+ message += " but it has a Standby Status of "
+ + im.getStateManager().getStandbyStatus();
} else {
message += " but an exception occurred";
@@ -1032,9 +1078,11 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
}
loggingContext.metricStarted();
LOGGER.info("XACMLPapServlet: Calling PolicyDBDao to handlIncomingHttpNotification");
- HandleIncomingNotifications handleIncomingNotifications = new HandleIncomingNotifications();
+ HandleIncomingNotifications handleIncomingNotifications =
+ new HandleIncomingNotifications();
handleIncomingNotifications.handleIncomingHttpNotification(policyDBDaoRequestUrl,
- policyDBDaoRequestEntityId, policyDBDaoRequestEntityType, policyDBDaoRequestExtraData, this);
+ policyDBDaoRequestEntityId, policyDBDaoRequestEntityType,
+ policyDBDaoRequestExtraData, this);
loggingContext.metricEnded();
PolicyLogger.metrics("XACMLPapServlet doPut handle incoming http notification");
response.setStatus(200);
@@ -1091,9 +1139,9 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
return;
}
/*
- * This is to update the PDP Group with the policy/policies being pushed Part of a 2 step process to
- * push policies to the PDP that can now be done From both the Admin Console and the PolicyEngine
- * API
+ * This is to update the PDP Group with the policy/policies being pushed Part of a 2 step
+ * process to push policies to the PDP that can now be done From both the Admin Console and
+ * the PolicyEngine API
*/
String groupId = request.getParameter(GROUPID);
if (groupId != null) {
@@ -1122,7 +1170,8 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
// this is from the Admin Console, so handle separately
try {
loggingContext.metricEnded();
- getAcServiceInstance().doAcPut(request, response, groupId, loggingContext, papEngine);
+ getAcServiceInstance().doAcPut(request, response, groupId, loggingContext,
+ papEngine);
loggingContext.metricEnded();
PolicyLogger.metrics("XACMLPapServlet goPut doACPut");
} catch (IOException e) {
@@ -1179,10 +1228,12 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
}
// We do not expect anything from anywhere else.
// This method is here in case we ever need to support other operations.
- LOGGER.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "Request does not have groupId or apiflag");
+ LOGGER.error(
+ XACMLErrorConstants.ERROR_DATA_ISSUE + "Request does not have groupId or apiflag");
loggingContext.transactionEnded();
PolicyLogger.audit("Transaction Failed - See Error.log");
- setResponseError(response, HttpServletResponse.SC_BAD_REQUEST, "Request does not have groupId or apiflag");
+ setResponseError(response, HttpServletResponse.SC_BAD_REQUEST,
+ "Request does not have groupId or apiflag");
loggingContext.transactionEnded();
PolicyLogger.audit("Transaction Failed - See error.log");
im.endTransaction();
@@ -1194,7 +1245,8 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
@Override
protected void doDelete(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
- ONAPLoggingContext loggingContext = ONAPLoggingUtils.getLoggingContextForRequest(request, baseLoggingContext);
+ ONAPLoggingContext loggingContext =
+ ONAPLoggingUtils.getLoggingContextForRequest(request, baseLoggingContext);
setLoggingContext(loggingContext, "doDelete", "PAP.delete");
try {
loggingContext.metricStarted();
@@ -1202,8 +1254,10 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
loggingContext.metricEnded();
PolicyLogger.metrics("XACMLPapServlet doDelete im startTransaction");
} catch (AdministrativeStateException ae) {
- String message = "DELETE interface called for PAP " + papResourceName + " but it has an Administrative"
- + " state of " + im.getStateManager().getAdminState() + "\n Exception Message: " + ae.getMessage();
+ String message = "DELETE interface called for PAP " + papResourceName
+ + " but it has an Administrative" + " state of "
+ + im.getStateManager().getAdminState() + "\n Exception Message: "
+ + ae.getMessage();
LOGGER.info(message, ae);
PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR + " " + message);
loggingContext.transactionEnded();
@@ -1211,8 +1265,10 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
setResponseError(response, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, message);
return;
} catch (StandbyStatusException se) {
- String message = "PUT interface called for PAP " + papResourceName + " but it has a Standby Status" + " of "
- + im.getStateManager().getStandbyStatus() + "\n Exception Message: " + se.getMessage();
+ String message = "PUT interface called for PAP " + papResourceName
+ + " but it has a Standby Status" + " of "
+ + im.getStateManager().getStandbyStatus() + "\n Exception Message: "
+ + se.getMessage();
LOGGER.info(message, se);
PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR + " " + message);
loggingContext.transactionEnded();
@@ -1255,7 +1311,8 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
// this is from the Admin Console, so handle separately
try {
loggingContext.metricStarted();
- getAcServiceInstance().doAcDelete(request, response, groupId, loggingContext, papEngine);
+ getAcServiceInstance().doAcDelete(request, response, groupId, loggingContext,
+ papEngine);
loggingContext.metricEnded();
PolicyLogger.metrics("XACMLPapServlet doDelete doACDelete");
} catch (IOException e) {
@@ -1270,16 +1327,20 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE + " Request does not have groupId");
loggingContext.transactionEnded();
PolicyLogger.audit("Transaction Failed - See Error.log");
- setResponseError(response, HttpServletResponse.SC_BAD_REQUEST, "Request does not have groupId");
+ setResponseError(response, HttpServletResponse.SC_BAD_REQUEST,
+ "Request does not have groupId");
im.endTransaction();
}
- private boolean isPDPCurrent(Properties policies, Properties pipconfig, Properties pdpProperties) {
+ private boolean isPDPCurrent(Properties policies, Properties pipconfig,
+ Properties pdpProperties) {
String localRootPolicies = policies.getProperty(XACMLProperties.PROP_ROOTPOLICIES);
- String localReferencedPolicies = policies.getProperty(XACMLProperties.PROP_REFERENCEDPOLICIES);
+ String localReferencedPolicies =
+ policies.getProperty(XACMLProperties.PROP_REFERENCEDPOLICIES);
if (localRootPolicies == null || localReferencedPolicies == null) {
- LOGGER.warn(XACMLErrorConstants.ERROR_DATA_ISSUE + "Missing property on PAP server: RootPolicies="
- + localRootPolicies + " ReferencedPolicies=" + localReferencedPolicies);
+ LOGGER.warn(XACMLErrorConstants.ERROR_DATA_ISSUE
+ + "Missing property on PAP server: RootPolicies=" + localRootPolicies
+ + " ReferencedPolicies=" + localReferencedPolicies);
return false;
}
// Compare the policies and pipconfig properties to the pdpProperties
@@ -1289,7 +1350,8 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
Properties pdpPolicies = XACMLProperties.getPolicyProperties(pdpProperties, false);
Properties pdpPipConfig = XACMLProperties.getPipProperties(pdpProperties);
if (localRootPolicies.equals(pdpPolicies.getProperty(XACMLProperties.PROP_ROOTPOLICIES))
- && localReferencedPolicies.equals(pdpPolicies.getProperty(XACMLProperties.PROP_REFERENCEDPOLICIES))
+ && localReferencedPolicies.equals(
+ pdpPolicies.getProperty(XACMLProperties.PROP_REFERENCEDPOLICIES))
&& pdpPipConfig.equals(pipconfig)) {
// The PDP is current
return true;
@@ -1301,7 +1363,8 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
// property.
// Either of these cases means that the PDP is not up-to-date, so
// just drop-through to return false.
- PolicyLogger.error(MessageCodes.ERROR_SCHEMA_INVALID, e, "XACMLPapServlet", " PDP Error");
+ PolicyLogger.error(MessageCodes.ERROR_SCHEMA_INVALID, e, "XACMLPapServlet",
+ " PDP Error");
}
return false;
}
@@ -1352,9 +1415,9 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
* @throws ServletException
* @throws IOException
*/
- public void updateGroupsFromAPI(HttpServletRequest request, HttpServletResponse response, String groupId,
- ONAPLoggingContext loggingContext) throws IOException {
- PolicyDBDaoTransaction acPutTransaction = policyDBDao.getNewTransaction();
+ public void updateGroupsFromAPI(HttpServletRequest request, HttpServletResponse response,
+ String groupId, ONAPLoggingContext loggingContext) throws IOException {
+ PolicyDBDaoTransaction acPutTransaction = policyDbDao.getNewTransaction();
PolicyLogger.audit("PolicyDBDaoTransaction started for updateGroupsFromAPI");
try {
String userId = request.getParameter("userId");
@@ -1426,8 +1489,8 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
loggingContext.transactionEnded();
LOGGER.info("Success");
- if (policy != null
- && ((policy.getId().contains("Config_MS_")) || (policy.getId().contains("BRMS_Param")))) {
+ if (policy != null && ((policy.getId().contains("Config_MS_"))
+ || (policy.getId().contains("BRMS_Param")))) {
PushPolicyHandler pushPolicyHandler = PushPolicyHandler.getInstance();
if (pushPolicyHandler.preSafetyCheck(policy, configHome)) {
LOGGER.debug("Precheck Successful.");
@@ -1438,12 +1501,14 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
return;
} catch (PAPException e) {
acPutTransaction.rollbackTransaction();
- PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, "XACMLPapServlet", " API PUT exception");
+ PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, "XACMLPapServlet",
+ " API PUT exception");
loggingContext.transactionEnded();
PolicyLogger.audit("Transaction Failed - See Error.log");
String message = XACMLErrorConstants.ERROR_PROCESS_FLOW
+ "Exception in request to update group from API - See Error.log on on the PAP.";
- setResponseError(response, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage());
+ setResponseError(response, HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
+ e.getMessage());
response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
response.addHeader("error", ADD_GROUP_ERROR);
response.addHeader("message", message);
@@ -1452,8 +1517,8 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
}
/*
- * HELPER to change Group status when PDP status is changed (Must NOT be called from a method that
- * is synchronized on the papEngine or it may deadlock)
+ * HELPER to change Group status when PDP status is changed (Must NOT be called from a method
+ * that is synchronized on the papEngine or it may deadlock)
*/
public void setPDPSummaryStatus(OnapPDP pdp, PDPStatus.Status newStatus) throws PAPException {
setPDPSummaryStatus(pdp, newStatus.toString());
@@ -1475,8 +1540,8 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
}
/*
- * Callback methods telling this servlet to notify PDPs of changes made by the PAP StdEngine in the
- * PDP group directories
+ * Callback methods telling this servlet to notify PDPs of changes made by the PAP StdEngine in
+ * the PDP group directories
*/
@Override
public void changed() {
@@ -1485,8 +1550,10 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
try {
groups = papEngine.getOnapPDPGroups();
} catch (PAPException e) {
- PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, e, "XACMLPapServlet", " getPDPGroups failed");
- throw new IllegalAccessError(XACMLErrorConstants.ERROR_SYSTEM_ERROR + "Unable to get Groups: " + e);
+ PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, e, "XACMLPapServlet",
+ " getPDPGroups failed");
+ throw new IllegalAccessError(
+ XACMLErrorConstants.ERROR_SYSTEM_ERROR + "Unable to get Groups: " + e);
}
for (OnapPDPGroup group : groups) {
groupChanged(group);
@@ -1499,8 +1566,10 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
try {
groups = papEngine.getOnapPDPGroups();
} catch (PAPException e) {
- PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, e, "XACMLPapServlet", " getPDPGroups failed");
- throw new IllegalAccessError(XACMLErrorConstants.ERROR_SYSTEM_ERROR + "Unable to get Groups: " + e);
+ PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, e, "XACMLPapServlet",
+ " getPDPGroups failed");
+ throw new IllegalAccessError(
+ XACMLErrorConstants.ERROR_SYSTEM_ERROR + "Unable to get Groups: " + e);
}
for (OnapPDPGroup group : groups) {
groupChanged(group, loggingContext);
@@ -1554,7 +1623,8 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
}
}
- private void pdpChanged(OnapPDP pdp, ONAPLoggingContext loggingContext, List<Properties> pdpDataByGroup) {
+ private void pdpChanged(OnapPDP pdp, ONAPLoggingContext loggingContext,
+ List<Properties> pdpDataByGroup) {
Thread t = new Thread(new UpdatePdpThread(pdp, loggingContext, pdpDataByGroup));
if (CheckPDP.validateID(pdp.getId())) {
t.start();
@@ -1571,7 +1641,8 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
return dataToNotify.setPolicyConfigProperties(pdp, papEngine);
}
- private void testService(ONAPLoggingContext loggingContext, HttpServletResponse response) throws IOException {
+ private void testService(ONAPLoggingContext loggingContext, HttpServletResponse response)
+ throws IOException {
LOGGER.info("Test request received");
try {
im.evaluateSanity();
@@ -1582,7 +1653,8 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
PolicyLogger.audit("Transaction Failed - See Error.log");
response.setStatus(HttpServletResponse.SC_OK);
return;
- } catch (ForwardProgressException | AdministrativeStateException | StandbyStatusException e) {
+ } catch (ForwardProgressException | AdministrativeStateException
+ | StandbyStatusException e) {
String submsg;
if (e instanceof ForwardProgressException) {
submsg = " is not making forward progress.";
@@ -1592,8 +1664,8 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
submsg = " Standby Status is NOT PROVIDING SERVICE.";
}
- String message = "GET:/pap/test called and PAP " + papResourceName + submsg + " Exception Message: "
- + e.getMessage();
+ String message = "GET:/pap/test called and PAP " + papResourceName + submsg
+ + " Exception Message: " + e.getMessage();
LOGGER.info(message, e);
PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR + " " + message);
loggingContext.transactionEnded();
@@ -1607,8 +1679,8 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
if (eMsg == null) {
eMsg = "No Exception Message";
}
- String message = "GET:/pap/test called and PAP " + papResourceName + " has had a subsystem failure."
- + " Exception Message: " + eMsg;
+ String message = "GET:/pap/test called and PAP " + papResourceName
+ + " has had a subsystem failure." + " Exception Message: " + eMsg;
LOGGER.info(message, e);
PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR + " " + message);
loggingContext.transactionEnded();
@@ -1633,16 +1705,18 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
}
}
- private void setLoggingContext(ONAPLoggingContext loggingContext, String methodType, String serviceName) {
+ private void setLoggingContext(ONAPLoggingContext loggingContext, String methodType,
+ String serviceName) {
loggingContext.transactionStarted();
loggingContext.setServiceName(serviceName);
if (loggingContext.getRequestID() == null || "".equals(loggingContext.getRequestID())) {
UUID requestID = UUID.randomUUID();
loggingContext.setRequestID(requestID.toString());
- PolicyLogger.info(
- "requestID not provided in call to XACMLPapServlet ('" + methodType + "') so we generated one");
+ PolicyLogger.info("requestID not provided in call to XACMLPapServlet ('" + methodType
+ + "') so we generated one");
} else {
- PolicyLogger.info("requestID was provided in call to XACMLPapServlet ('" + methodType + "')");
+ PolicyLogger.info(
+ "requestID was provided in call to XACMLPapServlet ('" + methodType + "')");
}
}
@@ -1657,12 +1731,14 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
private static void loadWebapps() throws PAPException {
if (actionHome == null || configHome == null) {
- Path webappsPath = Paths.get(XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_WEBAPPS));
+ Path webappsPath =
+ Paths.get(XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_WEBAPPS));
// Sanity Check
if (webappsPath == null) {
- PolicyLogger.error("Invalid Webapps Path Location property : " + XACMLRestProperties.PROP_PAP_WEBAPPS);
- throw new PAPException(
- "Invalid Webapps Path Location property : " + XACMLRestProperties.PROP_PAP_WEBAPPS);
+ PolicyLogger.error("Invalid Webapps Path Location property : "
+ + XACMLRestProperties.PROP_PAP_WEBAPPS);
+ throw new PAPException("Invalid Webapps Path Location property : "
+ + XACMLRestProperties.PROP_PAP_WEBAPPS);
}
Path webappsPathConfig = Paths.get(webappsPath.toString() + File.separator + "Config");
Path webappsPathAction = Paths.get(webappsPath.toString() + File.separator + "Action");
@@ -1671,14 +1747,16 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
Files.createDirectories(webappsPathConfig);
} catch (IOException e) {
PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, "XACMLPapServlet",
- "Failed to create config directory: " + webappsPathConfig.toAbsolutePath().toString());
+ "Failed to create config directory: "
+ + webappsPathConfig.toAbsolutePath().toString());
}
}
if (Files.notExists(webappsPathAction)) {
try {
Files.createDirectories(webappsPathAction);
} catch (IOException e) {
- LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Failed to create action directory: "
+ LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW
+ + "Failed to create action directory: "
+ webappsPathAction.toAbsolutePath().toString(), e);
}
}
@@ -1715,10 +1793,6 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
actionHome = getActionHome();
}
- public static EntityManagerFactory getEmf() {
- return emf;
- }
-
public IntegrityAudit getIa() {
return ia;
}
@@ -1736,7 +1810,7 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
}
public static PolicyDBDaoTransaction getDbDaoTransaction() {
- return policyDBDao.getNewTransaction();
+ return policyDbDao.getNewTransaction();
}
public static String getPapDbDriver() {