@Test public void testRun() { OnapPDP pdp = new StdPDP("http: OnapLoggingContext loggingContext = new OnapLoggingContext(); loggingContext.setRequestId("id"); List<Properties> properties = new ArrayList<Properties>(); UpdatePdpThread thread = new UpdatePdpThread(pdp, loggingContext, properties); assertThatCode(thread::run).doesNotThrowAnyException(); }
@Override public void run() { HttpURLConnection connection = null; try { if (this.loggingContext == null) { loggingContext = new OnapLoggingContext(baseLoggingContext); } } catch (Exception e) { PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, e, XACMLPAPSERVLET, " Failed to send property file to " + pdp.getId()); return; } try { loggingContext.setServiceName("PAP:PDP.putConfig"); if (requestId == null || "".equals(requestId)) { UUID requestId = UUID.randomUUID(); loggingContext.setRequestId(requestId.toString()); PolicyLogger .info("requestID not provided in call to XACMLPapSrvlet (UpdatePDPThread) so we generated one: " + loggingContext.getRequestId()); } else { loggingContext.setRequestId(requestId); PolicyLogger.info("requestID was provided in call to XACMLPapSrvlet (UpdatePDPThread): " + loggingContext.getRequestId()); } loggingContext.transactionStarted(); if (LOGGER.isDebugEnabled()) { LOGGER.debug("creating url for id '" + pdp.getId() + "'"); } URL url = new URL(pdp.getId() + "?cache=all"); connection = (HttpURLConnection) url.openConnection(); connection.setRequestMethod("PUT"); String encoding = CheckPDP.getEncoding(pdp.getId()); if (encoding != null) { connection.setRequestProperty("Authorization", "Basic " + encoding); } connection.setRequestProperty("Content-Type", "text/x-java-properties"); connection.setRequestProperty("X-ECOMP-RequestID", loggingContext.getRequestId()); connection.setInstanceFollowRedirects(true); connection.setDoOutput(true); if (!writePropertiesToStream(connection)) { return; } loggingContext.metricStarted(); connection.connect(); loggingContext.metricEnded(); PolicyLogger.metrics("XACMLPapServlet UpdatePDPThread connection connect"); if (connection.getResponseCode() == 204) { LOGGER.info("Success. We are configured correctly - " + pdp.getId()); loggingContext.transactionEnded(); auditLogger.info("Success. PDP is configured correctly."); PolicyLogger.audit("Transaction Success. PDP is configured correctly."); getPapInstance().setPDPSummaryStatus(pdp, PDPStatus.Status.UP_TO_DATE); } else if (connection.getResponseCode() == 200) { LOGGER.info("Success. PDP needs to update its configuration - " + pdp.getId()); loggingContext.transactionEnded(); auditLogger.info("Success. PDP needs to update its configuration."); PolicyLogger.audit("Transaction Success. PDP is configured correctly."); getPapInstance().setPDPSummaryStatus(pdp, PDPStatus.Status.OUT_OF_SYNCH); } else { LOGGER.warn("Failed: " + connection.getResponseCode() + MESSAGE + connection.getResponseMessage() + pdp.getId()); loggingContext.transactionEnded(); auditLogger.warn("Failed: " + connection.getResponseCode() + MESSAGE + connection.getResponseMessage()); PolicyLogger.audit("Transaction Failed: " + connection.getResponseCode() + MESSAGE + connection.getResponseMessage()); getPapInstance().setPDPSummaryStatus(pdp, PDPStatus.Status.UNKNOWN); } } catch (Exception e) { LOGGER.debug(e); PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, e, XACMLPAPSERVLET, " Unable to sync config with PDP '" + pdp.getId() + "'"); loggingContext.transactionEnded(); PolicyLogger.audit("Transaction Failed: Unable to sync config with PDP '" + pdp.getId() + "': " + e); LOGGER.info("Transaction Failed: Unable to sync config with PDP '" + pdp.getId() + "': " + e); try { getPapInstance().setPDPSummaryStatus(pdp, PDPStatus.Status.UNKNOWN); } catch (PAPException e1) { LOGGER.debug(e1); PolicyLogger .audit("Transaction Failed: Unable to set status of PDP " + pdp.getId() + " to UNKNOWN: " + e); PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, e, XACMLPAPSERVLET, " Unable to set status of PDP '" + pdp.getId() + "' to UNKNOWN"); } } finally { if (connection != null) { connection.disconnect(); } } }
UpdatePdpThread implements Runnable { @Override public void run() { HttpURLConnection connection = null; try { if (this.loggingContext == null) { loggingContext = new OnapLoggingContext(baseLoggingContext); } } catch (Exception e) { PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, e, XACMLPAPSERVLET, " Failed to send property file to " + pdp.getId()); return; } try { loggingContext.setServiceName("PAP:PDP.putConfig"); if (requestId == null || "".equals(requestId)) { UUID requestId = UUID.randomUUID(); loggingContext.setRequestId(requestId.toString()); PolicyLogger .info("requestID not provided in call to XACMLPapSrvlet (UpdatePDPThread) so we generated one: " + loggingContext.getRequestId()); } else { loggingContext.setRequestId(requestId); PolicyLogger.info("requestID was provided in call to XACMLPapSrvlet (UpdatePDPThread): " + loggingContext.getRequestId()); } loggingContext.transactionStarted(); if (LOGGER.isDebugEnabled()) { LOGGER.debug("creating url for id '" + pdp.getId() + "'"); } URL url = new URL(pdp.getId() + "?cache=all"); connection = (HttpURLConnection) url.openConnection(); connection.setRequestMethod("PUT"); String encoding = CheckPDP.getEncoding(pdp.getId()); if (encoding != null) { connection.setRequestProperty("Authorization", "Basic " + encoding); } connection.setRequestProperty("Content-Type", "text/x-java-properties"); connection.setRequestProperty("X-ECOMP-RequestID", loggingContext.getRequestId()); connection.setInstanceFollowRedirects(true); connection.setDoOutput(true); if (!writePropertiesToStream(connection)) { return; } loggingContext.metricStarted(); connection.connect(); loggingContext.metricEnded(); PolicyLogger.metrics("XACMLPapServlet UpdatePDPThread connection connect"); if (connection.getResponseCode() == 204) { LOGGER.info("Success. We are configured correctly - " + pdp.getId()); loggingContext.transactionEnded(); auditLogger.info("Success. PDP is configured correctly."); PolicyLogger.audit("Transaction Success. PDP is configured correctly."); getPapInstance().setPDPSummaryStatus(pdp, PDPStatus.Status.UP_TO_DATE); } else if (connection.getResponseCode() == 200) { LOGGER.info("Success. PDP needs to update its configuration - " + pdp.getId()); loggingContext.transactionEnded(); auditLogger.info("Success. PDP needs to update its configuration."); PolicyLogger.audit("Transaction Success. PDP is configured correctly."); getPapInstance().setPDPSummaryStatus(pdp, PDPStatus.Status.OUT_OF_SYNCH); } else { LOGGER.warn("Failed: " + connection.getResponseCode() + MESSAGE + connection.getResponseMessage() + pdp.getId()); loggingContext.transactionEnded(); auditLogger.warn("Failed: " + connection.getResponseCode() + MESSAGE + connection.getResponseMessage()); PolicyLogger.audit("Transaction Failed: " + connection.getResponseCode() + MESSAGE + connection.getResponseMessage()); getPapInstance().setPDPSummaryStatus(pdp, PDPStatus.Status.UNKNOWN); } } catch (Exception e) { LOGGER.debug(e); PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, e, XACMLPAPSERVLET, " Unable to sync config with PDP '" + pdp.getId() + "'"); loggingContext.transactionEnded(); PolicyLogger.audit("Transaction Failed: Unable to sync config with PDP '" + pdp.getId() + "': " + e); LOGGER.info("Transaction Failed: Unable to sync config with PDP '" + pdp.getId() + "': " + e); try { getPapInstance().setPDPSummaryStatus(pdp, PDPStatus.Status.UNKNOWN); } catch (PAPException e1) { LOGGER.debug(e1); PolicyLogger .audit("Transaction Failed: Unable to set status of PDP " + pdp.getId() + " to UNKNOWN: " + e); PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, e, XACMLPAPSERVLET, " Unable to set status of PDP '" + pdp.getId() + "' to UNKNOWN"); } } finally { if (connection != null) { connection.disconnect(); } } } }
UpdatePdpThread implements Runnable { @Override public void run() { HttpURLConnection connection = null; try { if (this.loggingContext == null) { loggingContext = new OnapLoggingContext(baseLoggingContext); } } catch (Exception e) { PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, e, XACMLPAPSERVLET, " Failed to send property file to " + pdp.getId()); return; } try { loggingContext.setServiceName("PAP:PDP.putConfig"); if (requestId == null || "".equals(requestId)) { UUID requestId = UUID.randomUUID(); loggingContext.setRequestId(requestId.toString()); PolicyLogger .info("requestID not provided in call to XACMLPapSrvlet (UpdatePDPThread) so we generated one: " + loggingContext.getRequestId()); } else { loggingContext.setRequestId(requestId); PolicyLogger.info("requestID was provided in call to XACMLPapSrvlet (UpdatePDPThread): " + loggingContext.getRequestId()); } loggingContext.transactionStarted(); if (LOGGER.isDebugEnabled()) { LOGGER.debug("creating url for id '" + pdp.getId() + "'"); } URL url = new URL(pdp.getId() + "?cache=all"); connection = (HttpURLConnection) url.openConnection(); connection.setRequestMethod("PUT"); String encoding = CheckPDP.getEncoding(pdp.getId()); if (encoding != null) { connection.setRequestProperty("Authorization", "Basic " + encoding); } connection.setRequestProperty("Content-Type", "text/x-java-properties"); connection.setRequestProperty("X-ECOMP-RequestID", loggingContext.getRequestId()); connection.setInstanceFollowRedirects(true); connection.setDoOutput(true); if (!writePropertiesToStream(connection)) { return; } loggingContext.metricStarted(); connection.connect(); loggingContext.metricEnded(); PolicyLogger.metrics("XACMLPapServlet UpdatePDPThread connection connect"); if (connection.getResponseCode() == 204) { LOGGER.info("Success. We are configured correctly - " + pdp.getId()); loggingContext.transactionEnded(); auditLogger.info("Success. PDP is configured correctly."); PolicyLogger.audit("Transaction Success. PDP is configured correctly."); getPapInstance().setPDPSummaryStatus(pdp, PDPStatus.Status.UP_TO_DATE); } else if (connection.getResponseCode() == 200) { LOGGER.info("Success. PDP needs to update its configuration - " + pdp.getId()); loggingContext.transactionEnded(); auditLogger.info("Success. PDP needs to update its configuration."); PolicyLogger.audit("Transaction Success. PDP is configured correctly."); getPapInstance().setPDPSummaryStatus(pdp, PDPStatus.Status.OUT_OF_SYNCH); } else { LOGGER.warn("Failed: " + connection.getResponseCode() + MESSAGE + connection.getResponseMessage() + pdp.getId()); loggingContext.transactionEnded(); auditLogger.warn("Failed: " + connection.getResponseCode() + MESSAGE + connection.getResponseMessage()); PolicyLogger.audit("Transaction Failed: " + connection.getResponseCode() + MESSAGE + connection.getResponseMessage()); getPapInstance().setPDPSummaryStatus(pdp, PDPStatus.Status.UNKNOWN); } } catch (Exception e) { LOGGER.debug(e); PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, e, XACMLPAPSERVLET, " Unable to sync config with PDP '" + pdp.getId() + "'"); loggingContext.transactionEnded(); PolicyLogger.audit("Transaction Failed: Unable to sync config with PDP '" + pdp.getId() + "': " + e); LOGGER.info("Transaction Failed: Unable to sync config with PDP '" + pdp.getId() + "': " + e); try { getPapInstance().setPDPSummaryStatus(pdp, PDPStatus.Status.UNKNOWN); } catch (PAPException e1) { LOGGER.debug(e1); PolicyLogger .audit("Transaction Failed: Unable to set status of PDP " + pdp.getId() + " to UNKNOWN: " + e); PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, e, XACMLPAPSERVLET, " Unable to set status of PDP '" + pdp.getId() + "' to UNKNOWN"); } } finally { if (connection != null) { connection.disconnect(); } } } UpdatePdpThread(OnapPDP pdp, List<Properties> properties);  UpdatePdpThread(OnapPDP pdp, OnapLoggingContext loggingContext, List<Properties> properties); }
UpdatePdpThread implements Runnable { @Override public void run() { HttpURLConnection connection = null; try { if (this.loggingContext == null) { loggingContext = new OnapLoggingContext(baseLoggingContext); } } catch (Exception e) { PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, e, XACMLPAPSERVLET, " Failed to send property file to " + pdp.getId()); return; } try { loggingContext.setServiceName("PAP:PDP.putConfig"); if (requestId == null || "".equals(requestId)) { UUID requestId = UUID.randomUUID(); loggingContext.setRequestId(requestId.toString()); PolicyLogger .info("requestID not provided in call to XACMLPapSrvlet (UpdatePDPThread) so we generated one: " + loggingContext.getRequestId()); } else { loggingContext.setRequestId(requestId); PolicyLogger.info("requestID was provided in call to XACMLPapSrvlet (UpdatePDPThread): " + loggingContext.getRequestId()); } loggingContext.transactionStarted(); if (LOGGER.isDebugEnabled()) { LOGGER.debug("creating url for id '" + pdp.getId() + "'"); } URL url = new URL(pdp.getId() + "?cache=all"); connection = (HttpURLConnection) url.openConnection(); connection.setRequestMethod("PUT"); String encoding = CheckPDP.getEncoding(pdp.getId()); if (encoding != null) { connection.setRequestProperty("Authorization", "Basic " + encoding); } connection.setRequestProperty("Content-Type", "text/x-java-properties"); connection.setRequestProperty("X-ECOMP-RequestID", loggingContext.getRequestId()); connection.setInstanceFollowRedirects(true); connection.setDoOutput(true); if (!writePropertiesToStream(connection)) { return; } loggingContext.metricStarted(); connection.connect(); loggingContext.metricEnded(); PolicyLogger.metrics("XACMLPapServlet UpdatePDPThread connection connect"); if (connection.getResponseCode() == 204) { LOGGER.info("Success. We are configured correctly - " + pdp.getId()); loggingContext.transactionEnded(); auditLogger.info("Success. PDP is configured correctly."); PolicyLogger.audit("Transaction Success. PDP is configured correctly."); getPapInstance().setPDPSummaryStatus(pdp, PDPStatus.Status.UP_TO_DATE); } else if (connection.getResponseCode() == 200) { LOGGER.info("Success. PDP needs to update its configuration - " + pdp.getId()); loggingContext.transactionEnded(); auditLogger.info("Success. PDP needs to update its configuration."); PolicyLogger.audit("Transaction Success. PDP is configured correctly."); getPapInstance().setPDPSummaryStatus(pdp, PDPStatus.Status.OUT_OF_SYNCH); } else { LOGGER.warn("Failed: " + connection.getResponseCode() + MESSAGE + connection.getResponseMessage() + pdp.getId()); loggingContext.transactionEnded(); auditLogger.warn("Failed: " + connection.getResponseCode() + MESSAGE + connection.getResponseMessage()); PolicyLogger.audit("Transaction Failed: " + connection.getResponseCode() + MESSAGE + connection.getResponseMessage()); getPapInstance().setPDPSummaryStatus(pdp, PDPStatus.Status.UNKNOWN); } } catch (Exception e) { LOGGER.debug(e); PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, e, XACMLPAPSERVLET, " Unable to sync config with PDP '" + pdp.getId() + "'"); loggingContext.transactionEnded(); PolicyLogger.audit("Transaction Failed: Unable to sync config with PDP '" + pdp.getId() + "': " + e); LOGGER.info("Transaction Failed: Unable to sync config with PDP '" + pdp.getId() + "': " + e); try { getPapInstance().setPDPSummaryStatus(pdp, PDPStatus.Status.UNKNOWN); } catch (PAPException e1) { LOGGER.debug(e1); PolicyLogger .audit("Transaction Failed: Unable to set status of PDP " + pdp.getId() + " to UNKNOWN: " + e); PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, e, XACMLPAPSERVLET, " Unable to set status of PDP '" + pdp.getId() + "' to UNKNOWN"); } } finally { if (connection != null) { connection.disconnect(); } } } UpdatePdpThread(OnapPDP pdp, List<Properties> properties);  UpdatePdpThread(OnapPDP pdp, OnapLoggingContext loggingContext, List<Properties> properties); @Override void run(); }
UpdatePdpThread implements Runnable { @Override public void run() { HttpURLConnection connection = null; try { if (this.loggingContext == null) { loggingContext = new OnapLoggingContext(baseLoggingContext); } } catch (Exception e) { PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, e, XACMLPAPSERVLET, " Failed to send property file to " + pdp.getId()); return; } try { loggingContext.setServiceName("PAP:PDP.putConfig"); if (requestId == null || "".equals(requestId)) { UUID requestId = UUID.randomUUID(); loggingContext.setRequestId(requestId.toString()); PolicyLogger .info("requestID not provided in call to XACMLPapSrvlet (UpdatePDPThread) so we generated one: " + loggingContext.getRequestId()); } else { loggingContext.setRequestId(requestId); PolicyLogger.info("requestID was provided in call to XACMLPapSrvlet (UpdatePDPThread): " + loggingContext.getRequestId()); } loggingContext.transactionStarted(); if (LOGGER.isDebugEnabled()) { LOGGER.debug("creating url for id '" + pdp.getId() + "'"); } URL url = new URL(pdp.getId() + "?cache=all"); connection = (HttpURLConnection) url.openConnection(); connection.setRequestMethod("PUT"); String encoding = CheckPDP.getEncoding(pdp.getId()); if (encoding != null) { connection.setRequestProperty("Authorization", "Basic " + encoding); } connection.setRequestProperty("Content-Type", "text/x-java-properties"); connection.setRequestProperty("X-ECOMP-RequestID", loggingContext.getRequestId()); connection.setInstanceFollowRedirects(true); connection.setDoOutput(true); if (!writePropertiesToStream(connection)) { return; } loggingContext.metricStarted(); connection.connect(); loggingContext.metricEnded(); PolicyLogger.metrics("XACMLPapServlet UpdatePDPThread connection connect"); if (connection.getResponseCode() == 204) { LOGGER.info("Success. We are configured correctly - " + pdp.getId()); loggingContext.transactionEnded(); auditLogger.info("Success. PDP is configured correctly."); PolicyLogger.audit("Transaction Success. PDP is configured correctly."); getPapInstance().setPDPSummaryStatus(pdp, PDPStatus.Status.UP_TO_DATE); } else if (connection.getResponseCode() == 200) { LOGGER.info("Success. PDP needs to update its configuration - " + pdp.getId()); loggingContext.transactionEnded(); auditLogger.info("Success. PDP needs to update its configuration."); PolicyLogger.audit("Transaction Success. PDP is configured correctly."); getPapInstance().setPDPSummaryStatus(pdp, PDPStatus.Status.OUT_OF_SYNCH); } else { LOGGER.warn("Failed: " + connection.getResponseCode() + MESSAGE + connection.getResponseMessage() + pdp.getId()); loggingContext.transactionEnded(); auditLogger.warn("Failed: " + connection.getResponseCode() + MESSAGE + connection.getResponseMessage()); PolicyLogger.audit("Transaction Failed: " + connection.getResponseCode() + MESSAGE + connection.getResponseMessage()); getPapInstance().setPDPSummaryStatus(pdp, PDPStatus.Status.UNKNOWN); } } catch (Exception e) { LOGGER.debug(e); PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, e, XACMLPAPSERVLET, " Unable to sync config with PDP '" + pdp.getId() + "'"); loggingContext.transactionEnded(); PolicyLogger.audit("Transaction Failed: Unable to sync config with PDP '" + pdp.getId() + "': " + e); LOGGER.info("Transaction Failed: Unable to sync config with PDP '" + pdp.getId() + "': " + e); try { getPapInstance().setPDPSummaryStatus(pdp, PDPStatus.Status.UNKNOWN); } catch (PAPException e1) { LOGGER.debug(e1); PolicyLogger .audit("Transaction Failed: Unable to set status of PDP " + pdp.getId() + " to UNKNOWN: " + e); PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, e, XACMLPAPSERVLET, " Unable to set status of PDP '" + pdp.getId() + "' to UNKNOWN"); } } finally { if (connection != null) { connection.disconnect(); } } } UpdatePdpThread(OnapPDP pdp, List<Properties> properties);  UpdatePdpThread(OnapPDP pdp, OnapLoggingContext loggingContext, List<Properties> properties); @Override void run();  }