This is an automated email from the ASF dual-hosted git repository.

rawlin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficcontrol.git


The following commit(s) were added to refs/heads/master by this push:
     new 4f539e7  Dcz to crs stats (#5250)
4f539e7 is described below

commit 4f539e71a8eb3379f3d99c19ff19338a92eecfe6
Author: mattjackson220 <[email protected]>
AuthorDate: Mon Nov 9 16:45:04 2020 -0700

    Dcz to crs stats (#5250)
    
    * updated /crs/stats/ip/{ip} to include deep coverage zone
    
    * updated /crs/stats/ip/{ip} to include deep coverage zone
    
    * added license and docs
    
    * fixed PMD failures
---
 CHANGELOG.md                                       |  1 +
 .../traffic_router/traffic_router_api.rst          |  3 +-
 .../core/edge/PropertiesAndCaches.java             | 60 ++++++++++++++++++++++
 .../traffic_router/core/router/TrafficRouter.java  | 21 ++++++++
 .../traffic_router/core/util/DataExporter.java     | 10 +++-
 5 files changed, 93 insertions(+), 2 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 04a04d3..f84144e 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -69,6 +69,7 @@ The format is based on [Keep a 
Changelog](http://keepachangelog.com/en/1.0.0/).
 - Added `--traffic_ops_insecure=<0|1>` optional option to traffic_ops_ort.pl
 - Added User-Agent string to Traffic Router log output.
 - Added default sort logic to GET API calls using Read()
+- Added locationByDeepCoverageZone to the `crs/stats/ip/{ip}` endpoint in the 
Traffic Router API
 
 ### Fixed
 - Fixed #5188 - DSR (delivery service request) incorrectly marked as complete 
and error message not displaying when DSR fulfilled and DS update fails in 
Traffic Portal. [Related Github 
issue](https://github.com/apache/trafficcontrol/issues/5188)
diff --git a/docs/source/development/traffic_router/traffic_router_api.rst 
b/docs/source/development/traffic_router/traffic_router_api.rst
index 67b44f9..b6047d1 100644
--- a/docs/source/development/traffic_router/traffic_router_api.rst
+++ b/docs/source/development/traffic_router/traffic_router_api.rst
@@ -150,7 +150,8 @@ Response Structure
        },
        "locationByFederation": "not found",
        "requestIp": "69.241.118.34",
-       "locationByCoverageZone": "not found"
+       "locationByCoverageZone": "not found",
+       "locationByDeepCoverageZone": "not found"
        }
 
 .. _tr-api-crs-locations:
diff --git 
a/traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/core/edge/PropertiesAndCaches.java
 
b/traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/core/edge/PropertiesAndCaches.java
new file mode 100644
index 0000000..7823ebe
--- /dev/null
+++ 
b/traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/core/edge/PropertiesAndCaches.java
@@ -0,0 +1,60 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package com.comcast.cdn.traffic_control.traffic_router.core.edge;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+
+/**
+ * An abbreviated version of CacheLocation to show only properties and a list 
of cache names
+ */
+public class PropertiesAndCaches {
+    final public Map<String, String> properties;
+    final public List<String> caches;
+
+    public PropertiesAndCaches(final CacheLocation cacheLocation) {
+        properties = cacheLocation.getProperties();
+        caches = new ArrayList<>();
+        for (final Cache cache : cacheLocation.getCaches()) {
+            caches.add(cache.getId());
+        }
+    }
+
+    /**
+     * Gets properties.
+     *
+     * @return the properties
+     */
+    public Map<String, String> getProperties() {
+        return properties;
+    }
+
+    /**
+     * Gets caches.
+     *
+     * @return the caches
+     */
+    public List<String> getCaches() {
+        return caches;
+    }
+
+}
diff --git 
a/traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/core/router/TrafficRouter.java
 
b/traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/core/router/TrafficRouter.java
index 67cb266..7a45d1f 100644
--- 
a/traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/core/router/TrafficRouter.java
+++ 
b/traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/core/router/TrafficRouter.java
@@ -1349,6 +1349,27 @@ public class TrafficRouter {
                return getCoverageZoneCacheLocation(ip, deliveryServiceId, 
false, null, requestVersion); // default is not deep
        }
 
+       /**
+        * Finds the deep coverage zone location information for a give IP 
address.
+        * @param ip
+        * @return deep coverage zone location
+        */
+       public CacheLocation getDeepCoverageZoneLocationByIP(final String ip) {
+               final NetworkNode networkNode = getDeepNetworkNode(ip);
+
+               if (networkNode == null) {
+                       return null;
+               }
+
+               final CacheLocation cacheLocation = (CacheLocation) 
networkNode.getLocation();
+
+               if (cacheLocation != null) {
+                       
cacheLocation.loadDeepCaches(networkNode.getDeepCacheNames(), cacheRegister);
+               }
+
+               return cacheLocation;
+       }
+
        @SuppressWarnings({"PMD.CyclomaticComplexity", "PMD.NPathComplexity"})
        public CacheLocation getCoverageZoneCacheLocation(final String ip, 
final String deliveryServiceId, final boolean useDeep, final Track track, final 
IPVersions requestVersion) {
                final NetworkNode networkNode = useDeep ? 
getDeepNetworkNode(ip) : getNetworkNode(ip);
diff --git 
a/traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/core/util/DataExporter.java
 
b/traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/core/util/DataExporter.java
index 0b2bb3a..be64e44 100644
--- 
a/traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/core/util/DataExporter.java
+++ 
b/traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/core/util/DataExporter.java
@@ -35,6 +35,7 @@ import 
com.comcast.cdn.traffic_control.traffic_router.core.edge.CacheLocation;
 import com.comcast.cdn.traffic_control.traffic_router.core.edge.CacheRegister;
 import com.comcast.cdn.traffic_control.traffic_router.core.edge.InetRecord;
 import com.comcast.cdn.traffic_control.traffic_router.core.edge.Location;
+import 
com.comcast.cdn.traffic_control.traffic_router.core.edge.PropertiesAndCaches;
 import com.comcast.cdn.traffic_control.traffic_router.geolocation.Geolocation;
 import 
com.comcast.cdn.traffic_control.traffic_router.geolocation.GeolocationException;
 import com.comcast.cdn.traffic_control.traffic_router.core.loc.NetworkNode;
@@ -117,7 +118,7 @@ public class DataExporter {
                        final List<Object> federationsList = 
federationExporter.getMatchingFederations(cidrAddress);
 
                        if (federationsList.isEmpty()) {
-                               map.put("locationByFederation", "not found");
+                               map.put("locationByFederation", 
NOT_FOUND_MESSAGE);
                        } else {
                                map.put("locationByFederation", 
federationsList);
                        }
@@ -125,6 +126,13 @@ public class DataExporter {
                        map.put("locationByFederation", NOT_FOUND_MESSAGE);
                }
 
+               final CacheLocation clFromDCZ = 
trafficRouterManager.getTrafficRouter().getDeepCoverageZoneLocationByIP(ip);
+               if (clFromDCZ != null) {
+                       map.put("locationByDeepCoverageZone", new 
PropertiesAndCaches(clFromDCZ));
+               } else {
+                       map.put("locationByDeepCoverageZone", 
NOT_FOUND_MESSAGE);
+               }
+
                return map;
        }
 

Reply via email to