You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficcontrol.apache.org by oc...@apache.org on 2020/11/11 17:29:11 UTC
[trafficcontrol] 02/03: Dcz to crs stats (#5250)
This is an automated email from the ASF dual-hosted git repository.
ocket8888 pushed a commit to branch 5.0.x
in repository https://gitbox.apache.org/repos/asf/trafficcontrol.git
commit 0c53b32f07192d488b054cf93b44df854f4e9ea1
Author: mattjackson220 <33...@users.noreply.github.com>
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
(cherry picked from commit 4f539e71a8eb3379f3d99c19ff19338a92eecfe6)
---
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 c883cff..c0755f3 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -66,6 +66,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
- Added User-Agent string to Traffic Router log output.
- Added default sort logic to GET API calls using Read()
- Traffic Ops: added validation for assigning ORG servers to topology-based delivery services
+- 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;
}