elsloo closed pull request #1944: Added TR endpoints to test deep caching
URL: https://github.com/apache/incubator-trafficcontrol/pull/1944
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git a/docs/source/development/traffic_router/traffic_router_api.rst
b/docs/source/development/traffic_router/traffic_router_api.rst
index d742276e6a..2ae902f63d 100644
--- a/docs/source/development/traffic_router/traffic_router_api.rst
+++ b/docs/source/development/traffic_router/traffic_router_api.rst
@@ -42,7 +42,49 @@ A mapping of caches to cache groups and their current health
state.
|
-/crs/locations/:location/caches
+**/crs/locations/:location/caches**
A list of caches for this cache group only.
+|
+
+**/crs/consistenthash/cache/coveragezone/?ip=:ip&deliveryServiceId=:deliveryServiceId&requestPath=:requestPath**
+
+The resulting cache of the consistent hash using coverage zone file for a
given client IP, delivery service, and request path.
+
+|
+
+**/crs/consistenthash/cache/deep/coveragezone/?ip=:ip&deliveryServiceId=:deliveryServiceId&requestPath=:requestPath**
+
+The resulting cache of the consistent hash using deep coverage zone file (deep
caching) for a given client IP, delivery service, and request path.
+
+|
+
+**/crs/consistenthash/cache/geolocation/?ip=:ip&deliveryServiceId=:deliveryServiceId&requestPath=:requestPath**
+
+The resulting cache of the consistent hash using geolocation for a given
client IP, delivery service, and request path.
+
+|
+
+**/crs/consistenthash/deliveryservice/?deliveryServiceId=:deliveryServiceId&requestPath=:requestPath**
+
+The resulting delivery service of the consistent hash for a given delivery
service and request path -- used to test steering delivery services.
+
+|
+
+**/crs/coveragezone/caches/?deliveryServiceId=:deliveryServiceId&cacheLocationId=:cacheLocationId**
+
+A list of caches for a given delivery service and cache location.
+
+|
+
+**/crs/coveragezone/cachelocation/?ip=:ip&deliveryServiceId=:deliveryServiceId**
+
+The resulting cache location for a given client IP and delivery service.
+
+|
+
+**/crs/deepcoveragezone/cachelocation/?ip=:ip&deliveryServiceId=:deliveryServiceId**
+
+The resulting cache location using deep coverage zone file (deep caching) for
a given client IP and delivery service.
+
diff --git
a/traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/api/controllers/ConsistentHashController.java
b/traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/api/controllers/ConsistentHashController.java
index 42e2108350..8704cd3650 100644
---
a/traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/api/controllers/ConsistentHashController.java
+++
b/traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/api/controllers/ConsistentHashController.java
@@ -47,6 +47,21 @@ ResponseEntity
hashCoverageZoneCache(@RequestParam(name="ip") final String ip,
return ResponseEntity.ok(cache);
}
+ @RequestMapping(value = "/cache/deep/coveragezone")
+ public @ResponseBody
+ ResponseEntity hashCoverageZoneDeepCache(@RequestParam(name="ip") final
String ip,
+
@RequestParam(name = "deliveryServiceId") final String deliveryServiceId,
+
@RequestParam(name = "requestPath") final String requestPath) {
+
+ final Cache cache =
trafficRouterManager.getTrafficRouter().consistentHashForCoverageZone(ip,
deliveryServiceId, requestPath, true);
+
+ if (cache == null) {
+ return
ResponseEntity.status(HttpStatus.NOT_FOUND).body("{}");
+ }
+
+ return ResponseEntity.ok(cache);
+ }
+
@RequestMapping(value = "/cache/geolocation")
public @ResponseBody
ResponseEntity hashGeolocatedCache(@RequestParam(name="ip") final
String ip,
diff --git
a/traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/api/controllers/DeepCoverageZoneController.java
b/traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/api/controllers/DeepCoverageZoneController.java
new file mode 100644
index 0000000000..6503bcb9c8
--- /dev/null
+++
b/traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/api/controllers/DeepCoverageZoneController.java
@@ -0,0 +1,45 @@
+/*
+ *
+ * Licensed 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.api.controllers;
+
+import com.comcast.cdn.traffic_control.traffic_router.core.cache.CacheLocation;
+import
com.comcast.cdn.traffic_control.traffic_router.core.router.TrafficRouterManager;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.ResponseBody;
+
+@Controller
+@RequestMapping("/deepcoveragezone")
+public class DeepCoverageZoneController {
+ @Autowired
+ TrafficRouterManager trafficRouterManager;
+
+ @RequestMapping(value = "/cachelocation")
+ public @ResponseBody
+ ResponseEntity<CacheLocation> getCacheLocationForIp(@RequestParam(name =
"ip") final String ip,
+ @RequestParam(name =
"deliveryServiceId") final String deliveryServiceId) {
+ final CacheLocation cacheLocation =
trafficRouterManager.getTrafficRouter().getCoverageZoneCacheLocation(ip,
deliveryServiceId, true);
+ if (cacheLocation == null) {
+ return ResponseEntity.status(HttpStatus.NOT_FOUND).body(null);
+ }
+
+ return ResponseEntity.ok(cacheLocation);
+ }
+}
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 da05a5cb10..9662fd8cae 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
@@ -713,13 +713,17 @@ protected CacheLocation
getCoverageZoneCacheLocation(final String ip, final Deli
}
public Cache consistentHashForCoverageZone(final String ip, final
String deliveryServiceId, final String requestPath) {
+ return consistentHashForCoverageZone(ip, deliveryServiceId,
requestPath, false);
+ }
+
+ public Cache consistentHashForCoverageZone(final String ip, final
String deliveryServiceId, final String requestPath, final boolean useDeep) {
final DeliveryService deliveryService =
cacheRegister.getDeliveryService(deliveryServiceId);
if (deliveryService == null) {
LOGGER.error("Failed getting delivery service from
cache register for id '" + deliveryServiceId + "'");
return null;
}
- final CacheLocation coverageZoneCacheLocation =
getCoverageZoneCacheLocation(ip, deliveryService);
+ final CacheLocation coverageZoneCacheLocation =
getCoverageZoneCacheLocation(ip, deliveryService, useDeep);
final List<Cache> caches = selectCachesByCZ(deliveryService,
coverageZoneCacheLocation);
if (caches == null || caches.isEmpty()) {
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services