Traffic Router crs/stats endpoint now contains data about retrieving and 
checking https certificates


Project: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/repo
Commit: 
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/commit/2c59a49b
Tree: 
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/tree/2c59a49b
Diff: 
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/diff/2c59a49b

Branch: refs/heads/psql
Commit: 2c59a49b90eb15273df7da6cd9225cee25e55c57
Parents: 87dfd37
Author: Trevor Ackerman <trevorackerman.soft...@gmail.com>
Authored: Fri Oct 14 13:33:37 2016 -0600
Committer: Trevor Ackerman <trevorackerman.soft...@gmail.com>
Committed: Fri Oct 14 13:33:37 2016 -0600

----------------------------------------------------------------------
 .../core/secure/CertificatesClient.java              | 15 +++++++++++++++
 .../core/secure/CertificatesPoller.java              | 11 +++++++++++
 .../core/secure/CertificatesPublisher.java           |  9 +++++++--
 .../src/main/webapp/WEB-INF/applicationContext.xml   |  3 +++
 4 files changed, 36 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/2c59a49b/traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/core/secure/CertificatesClient.java
----------------------------------------------------------------------
diff --git 
a/traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/core/secure/CertificatesClient.java
 
b/traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/core/secure/CertificatesClient.java
index 00e16d9..c350046 100644
--- 
a/traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/core/secure/CertificatesClient.java
+++ 
b/traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/core/secure/CertificatesClient.java
@@ -16,6 +16,7 @@
 
 package com.comcast.cdn.traffic_control.traffic_router.core.secure;
 
+import 
com.comcast.cdn.traffic_control.traffic_router.core.router.TrafficRouterManager;
 import 
com.comcast.cdn.traffic_control.traffic_router.core.util.ProtectedFetcher;
 import 
com.comcast.cdn.traffic_control.traffic_router.core.util.TrafficOpsUtils;
 import com.comcast.cdn.traffic_control.traffic_router.shared.CertificateData;
@@ -34,12 +35,15 @@ public class CertificatesClient {
        private static final String PEM_FOOTER_PREFIX = "-----END";
        private long lastValidfetchTimestamp = 0L;
        private boolean shutdown = false;
+       private TrafficRouterManager trafficRouterManager;
 
        public List<CertificateData> refreshData() {
                final StringBuilder stringBuilder = new StringBuilder();
+               
trafficRouterManager.trackEvent("lastHttpsCertificatesFetchAttempt");
                int status = fetchRawData(stringBuilder);
 
                while (status != HttpURLConnection.HTTP_NOT_MODIFIED && status 
!= HttpURLConnection.HTTP_OK) {
+                       
trafficRouterManager.trackEvent("lastHttpsCertificatesFetchFail");
                        try {
                                
Thread.sleep(trafficOpsUtils.getConfigLongValue("certificates.retry.interval", 
30 * 1000L));
                        } catch (InterruptedException e) {
@@ -49,6 +53,8 @@ public class CertificatesClient {
                                        return null;
                                }
                        }
+
+                       
trafficRouterManager.trackEvent("lastHttpsCertificatesFetchAttempt");
                        status = fetchRawData(stringBuilder);
                }
 
@@ -57,6 +63,7 @@ public class CertificatesClient {
                }
 
                lastValidfetchTimestamp = System.currentTimeMillis();
+               
trafficRouterManager.trackEvent("lastHttpsCertificatesFetchSuccess");
                return getCertificateData(stringBuilder.toString());
        }
 
@@ -127,4 +134,12 @@ public class CertificatesClient {
        public void setShutdown(final boolean shutdown) {
                this.shutdown = true;
        }
+
+       public TrafficRouterManager getTrafficRouterManager() {
+               return trafficRouterManager;
+       }
+
+       public void setTrafficRouterManager(final TrafficRouterManager 
trafficRouterManager) {
+               this.trafficRouterManager = trafficRouterManager;
+       }
 }

http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/2c59a49b/traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/core/secure/CertificatesPoller.java
----------------------------------------------------------------------
diff --git 
a/traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/core/secure/CertificatesPoller.java
 
b/traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/core/secure/CertificatesPoller.java
index 8672c3c..5291709 100644
--- 
a/traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/core/secure/CertificatesPoller.java
+++ 
b/traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/core/secure/CertificatesPoller.java
@@ -17,6 +17,7 @@
 package com.comcast.cdn.traffic_control.traffic_router.core.secure;
 
 import 
com.comcast.cdn.traffic_control.traffic_router.configuration.ConfigurationListener;
+import 
com.comcast.cdn.traffic_control.traffic_router.core.router.TrafficRouterManager;
 import com.comcast.cdn.traffic_control.traffic_router.shared.CertificateData;
 import org.apache.log4j.Logger;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -41,6 +42,7 @@ public class CertificatesPoller implements 
ConfigurationListener {
        private long pollingInterval = defaultFixedRate;
        private BlockingQueue<List<CertificateData>> certificatesQueue;
        private List<CertificateData> lastFetchedData = new ArrayList<>();
+       private TrafficRouterManager trafficRouterManager;
 
        @Autowired
        private Environment environment;
@@ -71,6 +73,7 @@ public class CertificatesPoller implements 
ConfigurationListener {
        public void start() {
                final Runnable runnable = () -> {
                        try {
+                               
trafficRouterManager.trackEvent("lastHttpsCertificatesCheck");
                                List<CertificateData> certificateDataList = 
certificatesClient.refreshData();
                                if (certificateDataList == null) {
                                        return;
@@ -148,4 +151,12 @@ public class CertificatesPoller implements 
ConfigurationListener {
        public void setCertificatesQueue(final 
BlockingQueue<List<CertificateData>> certificatesQueue) {
                this.certificatesQueue = certificatesQueue;
        }
+
+       public TrafficRouterManager getTrafficRouterManager() {
+               return trafficRouterManager;
+       }
+
+       public void setTrafficRouterManager(final TrafficRouterManager 
trafficRouterManager) {
+               this.trafficRouterManager = trafficRouterManager;
+       }
 }

http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/2c59a49b/traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/core/secure/CertificatesPublisher.java
----------------------------------------------------------------------
diff --git 
a/traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/core/secure/CertificatesPublisher.java
 
b/traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/core/secure/CertificatesPublisher.java
index 5ab11ea..df36059 100644
--- 
a/traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/core/secure/CertificatesPublisher.java
+++ 
b/traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/core/secure/CertificatesPublisher.java
@@ -2,6 +2,7 @@ package 
com.comcast.cdn.traffic_control.traffic_router.core.secure;
 
 import 
com.comcast.cdn.traffic_control.traffic_router.core.config.CertificateChecker;
 import com.comcast.cdn.traffic_control.traffic_router.core.ds.DeliveryService;
+import 
com.comcast.cdn.traffic_control.traffic_router.core.router.TrafficRouterManager;
 import com.comcast.cdn.traffic_control.traffic_router.shared.CertificateData;
 import 
com.comcast.cdn.traffic_control.traffic_router.shared.DeliveryServiceCertificatesMBean;
 import com.fasterxml.jackson.databind.ObjectMapper;
@@ -23,9 +24,10 @@ public class CertificatesPublisher {
        private boolean running = true;
        final Thread worker;
 
-       @SuppressWarnings("PMD.AvoidCatchingThrowable")
-       public CertificatesPublisher(final BlockingQueue<List<CertificateData>> 
certificatesQueue, final BlockingQueue<Boolean> publishStatusQueue, final 
CertificateChecker certificateChecker) {
 
+       @SuppressWarnings("PMD.AvoidCatchingThrowable")
+       public CertificatesPublisher(final BlockingQueue<List<CertificateData>> 
certificatesQueue, final BlockingQueue<Boolean> publishStatusQueue,
+                                    final CertificateChecker 
certificateChecker, final TrafficRouterManager trafficRouterManager) {
                worker = new Thread(() -> {
                        while (running) {
                                try {
@@ -41,6 +43,9 @@ public class CertificatesPublisher {
                                                });
                                                
publishCertificateList(certificateDataList);
                                                publishStatusQueue.poll(2, 
TimeUnit.SECONDS);
+                                               
trafficRouterManager.trackEvent("lastHttpsCertificatesUpdate");
+                                       } else {
+                                               
trafficRouterManager.trackEvent("lastInvalidHttpsCertificates");
                                        }
                                } catch (Throwable e) {
                                        if (!running) {

http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/2c59a49b/traffic_router/core/src/main/webapp/WEB-INF/applicationContext.xml
----------------------------------------------------------------------
diff --git a/traffic_router/core/src/main/webapp/WEB-INF/applicationContext.xml 
b/traffic_router/core/src/main/webapp/WEB-INF/applicationContext.xml
index 9a433aa..6374bc1 100644
--- a/traffic_router/core/src/main/webapp/WEB-INF/applicationContext.xml
+++ b/traffic_router/core/src/main/webapp/WEB-INF/applicationContext.xml
@@ -120,6 +120,7 @@
                <constructor-arg name="certificatesQueue" 
ref="certificatesQueue"/>
                <constructor-arg name="publishStatusQueue" 
ref="publishStatusQueue"/>
                <constructor-arg name="certificateChecker" 
ref="certificateChecker"/>
+               <constructor-arg name="trafficRouterManager" 
ref="trafficRouterManager"/>
        </bean>
 
        <bean id="ConfigHandler" 
class="com.comcast.cdn.traffic_control.traffic_router.core.config.ConfigHandler">
@@ -296,11 +297,13 @@
 
        <bean name="certificatesClient" 
class="com.comcast.cdn.traffic_control.traffic_router.core.secure.CertificatesClient">
                <property name="trafficOpsUtils" ref="trafficOpsUtils"/>
+               <property name="trafficRouterManager" 
ref="trafficRouterManager"/>
        </bean>
 
        <bean name="certificatesPoller" 
class="com.comcast.cdn.traffic_control.traffic_router.core.secure.CertificatesPoller"
 init-method="start">
                <property name="certificatesClient" ref="certificatesClient"/>
                <property name="certificatesQueue" ref="certificatesQueue"/>
+               <property name="trafficRouterManager" 
ref="trafficRouterManager"/>
        </bean>
 
 </beans>

Reply via email to