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

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

commit 0577ddcfbcc6012b463e40539137c323c61404fd
Author: Jan van Doorn <jan_vando...@cable.comcast.com>
AuthorDate: Fri Nov 18 21:26:53 2016 +0000

    Add Dynamic Deep Caching
    
    (cherry picked from commit ef5734bbfa77d6088407604cfb5790a53f49691c)
---
 .../traffic_router/core/config/ConfigHandler.java  | 17 +++++
 .../traffic_router/core/ds/DeliveryService.java    | 14 ++++
 .../core/loc/AbstractServiceUpdater.java           | 12 +++-
 .../core/loc/DeepNetworkUpdater.java               | 49 ++++++++++++++
 .../traffic_router/core/loc/NetworkNode.java       | 78 ++++++++++++++++++++--
 .../traffic_router/core/router/StatTracker.java    | 22 +++++-
 .../traffic_router/core/router/TrafficRouter.java  | 69 +++++++++++++++++--
 .../src/main/webapp/WEB-INF/applicationContext.xml |  9 +++
 .../core/router/TrafficRouterTest.java             |  4 +-
 9 files changed, 259 insertions(+), 15 deletions(-)

diff --git 
a/traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/core/config/ConfigHandler.java
 
b/traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/core/config/ConfigHandler.java
index a657e23..e6bd2df 100644
--- 
a/traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/core/config/ConfigHandler.java
+++ 
b/traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/core/config/ConfigHandler.java
@@ -36,6 +36,7 @@ import 
com.comcast.cdn.traffic_control.traffic_router.core.loc.FederationsWatche
 import 
com.comcast.cdn.traffic_control.traffic_router.core.loc.GeolocationDatabaseUpdater;
 import com.comcast.cdn.traffic_control.traffic_router.core.loc.NetworkNode;
 import com.comcast.cdn.traffic_control.traffic_router.core.loc.NetworkUpdater;
+import 
com.comcast.cdn.traffic_control.traffic_router.core.loc.DeepNetworkUpdater;
 import 
com.comcast.cdn.traffic_control.traffic_router.core.loc.RegionalGeoUpdater;
 
 import 
com.comcast.cdn.traffic_control.traffic_router.core.secure.CertificatesPoller;
@@ -76,6 +77,7 @@ public class ConfigHandler {
        private TrafficOpsUtils trafficOpsUtils;
 
        private NetworkUpdater networkUpdater;
+       private DeepNetworkUpdater deepNetworkUpdater;
        private FederationsWatcher federationsWatcher;
        private RegionalGeoUpdater regionalGeoUpdater;
        private SteeringWatcher steeringWatcher;
@@ -102,6 +104,9 @@ public class ConfigHandler {
        public NetworkUpdater getNetworkUpdater () {
                return networkUpdater;
        }
+       public DeepNetworkUpdater getDeepNetworkUpdater () {
+               return deepNetworkUpdater;
+       }
 
        public RegionalGeoUpdater getRegionalGeoUpdater() {
                return regionalGeoUpdater;
@@ -141,6 +146,7 @@ public class ConfigHandler {
                        try {
                                parseGeolocationConfig(config);
                                parseCoverageZoneNetworkConfig(config);
+                               parseDeepCoverageZoneNetworkConfig(config);
                                parseRegionalGeoConfig(jo);
 
                                final CacheRegister cacheRegister = new 
CacheRegister();
@@ -199,6 +205,7 @@ public class ConfigHandler {
                                parseCacheConfig(JsonUtils.getJsonNode(jo, 
"contentServers"), cacheRegister);
                                parseMonitorConfig(JsonUtils.getJsonNode(jo, 
"monitors"));
 
+                               NetworkNode.setCacheRegister(cacheRegister);
                                federationsWatcher.configure(config);
                                steeringWatcher.configure(config);
                                steeringWatcher.setCacheRegister(cacheRegister);
@@ -251,6 +258,9 @@ public class ConfigHandler {
        public void setNetworkUpdater(final NetworkUpdater nu) {
                this.networkUpdater = nu;
        }
+       public void setDeepNetworkUpdater(final DeepNetworkUpdater dnu) {
+               this.deepNetworkUpdater = dnu;
+       }
 
        public void setRegionalGeoUpdater(final RegionalGeoUpdater 
regionalGeoUpdater) {
                this.regionalGeoUpdater = regionalGeoUpdater;
@@ -541,6 +551,13 @@ public class ConfigHandler {
                        );
        }
 
+       private void parseDeepCoverageZoneNetworkConfig(final JsonNode config) 
throws JsonUtilsException {
+               getDeepNetworkUpdater().setDataBaseURL(
+                               JsonUtils.getString(config, 
"deepcoveragezone.polling.url"),
+                               JsonUtils.optLong(config, 
"deepcoveragezone.polling.interval")
+               );
+       }
+
        private void parseRegionalGeoConfig(final JsonNode jo) throws 
JsonUtilsException {
                final JsonNode config = JsonUtils.getJsonNode(jo, "config");
                final String url = JsonUtils.optString(config, 
"regional_geoblock.polling.url", null);
diff --git 
a/traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/core/ds/DeliveryService.java
 
b/traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/core/ds/DeliveryService.java
index 33cd406..e124fb4 100644
--- 
a/traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/core/ds/DeliveryService.java
+++ 
b/traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/core/ds/DeliveryService.java
@@ -93,6 +93,11 @@ public class DeliveryService {
        private final boolean acceptHttp;
        private final boolean acceptHttps;
        private final boolean redirectToHttps;
+       private int deepCache; // should this be final or should it be settable?
+
+       // enums are hard in Java.
+       public static final int DC_NEVER   = 0;
+       public static final int DC_ALWAYS  = 1;
 
        public DeliveryService(final String id, final JsonNode dsJo) throws 
JsonUtilsException {
                this.id = id;
@@ -145,6 +150,7 @@ public class DeliveryService {
                acceptHttps = JsonUtils.optBoolean(protocol, "acceptHttps");
                redirectToHttps = JsonUtils.optBoolean(protocol, 
"redirectToHttps");
 
+               this.deepCache = JsonUtils.optInt(dsJo, "deepCachingType", 
DC_NEVER);
        }
 
        public String getId() {
@@ -389,6 +395,14 @@ public class DeliveryService {
                this.isDns = isDns;
        }
 
+       public int getDeepCache() {
+               return deepCache;
+       }
+       public void setDeepCache(final int deepCache) {
+               this.deepCache = deepCache;
+       }
+
+
        public boolean appendQueryString() {
                return shouldAppendQueryString;
        }
diff --git 
a/traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/core/loc/AbstractServiceUpdater.java
 
b/traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/core/loc/AbstractServiceUpdater.java
index 3304119..650bdea 100644
--- 
a/traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/core/loc/AbstractServiceUpdater.java
+++ 
b/traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/core/loc/AbstractServiceUpdater.java
@@ -48,6 +48,7 @@ public abstract class AbstractServiceUpdater {
        protected String databaseName;
        protected ScheduledExecutorService executorService;
        private long pollingInterval;
+       private long initialDelay = -1;
        protected boolean loaded = false;
        protected ScheduledFuture<?> scheduledService;
        private TrafficRouterManager trafficRouterManager;
@@ -92,9 +93,13 @@ public abstract class AbstractServiceUpdater {
 
        public void init() {
                final long pollingInterval = getPollingInterval();
+        if (initialDelay == -1) {
+             initialDelay = pollingInterval;
+        }
+
                final Date nextFetchDate = new Date(System.currentTimeMillis() 
+ pollingInterval);
                LOGGER.info("[" + getClass().getSimpleName() + "] Fetching 
external resource " + dataBaseURL + " at interval: " + pollingInterval + " : " 
+ TimeUnit.MILLISECONDS + " next update occurrs at " + nextFetchDate);
-               scheduledService = 
executorService.scheduleWithFixedDelay(updater, pollingInterval, 
pollingInterval, TimeUnit.MILLISECONDS);
+               scheduledService = 
executorService.scheduleWithFixedDelay(updater, initialDelay, pollingInterval, 
TimeUnit.MILLISECONDS);
        }
 
        @SuppressWarnings({"PMD.CyclomaticComplexity", "PMD.NPathComplexity"})
@@ -194,6 +199,11 @@ public abstract class AbstractServiceUpdater {
                dataBaseURL = null;
        }
 
+    public void setDataBaseURL(final String url, final long refresh, final 
long iDelay) {
+        this.initialDelay = iDelay;
+        this.setDataBaseURL(url, refresh);
+    }
+
        public void setDataBaseURL(final String url, final long refresh) {
                if (refresh !=0 && refresh != pollingInterval) {
 
diff --git 
a/traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/core/loc/DeepNetworkUpdater.java
 
b/traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/core/loc/DeepNetworkUpdater.java
new file mode 100644
index 0000000..b4df7b8
--- /dev/null
+++ 
b/traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/core/loc/DeepNetworkUpdater.java
@@ -0,0 +1,49 @@
+/*
+ *
+ * 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.core.loc;
+
+import java.io.File;
+import java.io.IOException;
+
+public class DeepNetworkUpdater extends AbstractServiceUpdater {
+
+       public DeepNetworkUpdater() {
+               sourceCompressed = false;
+               tmpPrefix = "deepczf";
+               tmpSuffix = ".json";
+       }
+
+       @Override
+       public boolean loadDatabase() throws IOException {
+               final File existingDB = 
databasesDirectory.resolve(databaseName).toFile();
+
+               if (!existingDB.exists() || !existingDB.canRead()) {
+                       return false;
+               }
+
+               return NetworkNode.generateTree(existingDB, false, true) != 
null;
+       }
+
+       @Override
+       public boolean verifyDatabase(final File dbFile) throws IOException {
+               if (!dbFile.exists() || !dbFile.canRead()) {
+                       return false;
+               }
+
+               return NetworkNode.generateTree(dbFile, true, true) != null;
+       }
+
+}
diff --git 
a/traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/core/loc/NetworkNode.java
 
b/traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/core/loc/NetworkNode.java
index 77dc22b..e4e32dd 100644
--- 
a/traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/core/loc/NetworkNode.java
+++ 
b/traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/core/loc/NetworkNode.java
@@ -35,13 +35,18 @@ import com.fasterxml.jackson.databind.JsonNode;
 import com.fasterxml.jackson.databind.ObjectMapper;
 import org.apache.log4j.Logger;
 
+import com.comcast.cdn.traffic_control.traffic_router.core.cache.Cache;
 import com.comcast.cdn.traffic_control.traffic_router.core.cache.CacheLocation;
+import com.comcast.cdn.traffic_control.traffic_router.core.cache.CacheRegister;
 
 public class NetworkNode implements Comparable<NetworkNode> {
     private static final Logger LOGGER = Logger.getLogger(NetworkNode.class);
     private static final String DEFAULT_SUB_STR = "0.0.0.0/0";
 
     private static NetworkNode instance;
+    private static NetworkNode deepInstance;
+
+    private static CacheRegister cacheRegister;
 
     private CidrAddress cidrAddress;
     private String loc;
@@ -63,13 +68,39 @@ public class NetworkNode implements Comparable<NetworkNode> 
{
         return instance;
     }
 
-    public static NetworkNode generateTree(final File f, final boolean 
verifyOnly) throws IOException {
+    public static NetworkNode getDeepInstance() {
+        if (deepInstance != null) {
+            return deepInstance;
+        }
+
+        try {
+            deepInstance = new NetworkNode(DEFAULT_SUB_STR);
+        } catch (NetworkNodeException e) {
+            LOGGER.warn(e);
+        }
+
+        return deepInstance;
+    }
+
+    public static void setCacheRegister(final CacheRegister cr) {
+        cacheRegister = cr;
+    }
+
+    public static NetworkNode generateTree(final File f, final boolean 
verifyOnly, final boolean useDeep) throws IOException  {
         final ObjectMapper mapper = new ObjectMapper();
-        return generateTree(mapper.readTree(f), verifyOnly);
+        return generateTree(mapper.readTree(f), verifyOnly, useDeep);
+    }
+
+    public static NetworkNode generateTree(final File f, final boolean 
verifyOnly) throws IOException  {
+        return generateTree(f, verifyOnly, false);
     }
 
-    @SuppressWarnings("PMD.CyclomaticComplexity")
     public static NetworkNode generateTree(final JsonNode json, final boolean 
verifyOnly) {
+        return generateTree(json, verifyOnly, false);
+    }
+
+    @SuppressWarnings({"PMD.CyclomaticComplexity", "PMD.NPathComplexity"})
+    public static NetworkNode generateTree(final JsonNode json, final boolean 
verifyOnly, final boolean useDeep) {
         try {
             final JsonNode coverageZones = JsonUtils.getJsonNode(json, 
"coverageZones");
 
@@ -87,13 +118,40 @@ public class NetworkNode implements 
Comparable<NetworkNode> {
                     final double longitude = 
coordinates.get("longitude").asDouble();
                     geolocation = new Geolocation(latitude, longitude);
                 }
+                CacheLocation deepLoc = null;
+                if (useDeep) {
+                    try {
+                        final JsonNode caches = JsonUtils.getJsonNode(locData, 
"caches");
+                        for (final JsonNode cacheJson : caches) {
+                            final String cacheHostname = cacheJson.asText();
+                            if (deepLoc == null) {
+                                deepLoc = new CacheLocation( "deep." + loc, 
new Geolocation(0.0, 0.0));  // TODO JvD
+                            }
+                            // Get the cache from the cacheregister here - 
don't create a new cache due to the deep file, only reuse the
+                            // ones we already know about.
+                            final Cache cache = 
cacheRegister.getCacheMap().get(cacheHostname);
+                            if (cache == null) {
+                                LOGGER.error("DDC: deep cache entry " + 
cacheHostname + " not found in crconfig server list!");
+                            } else {
+                                LOGGER.info("DDC: Adding " + cacheHostname + " 
to " + deepLoc.getId() + ".");
+                                deepLoc.addCache(cache);
+                            }
+                        }
+                    } catch (JsonUtilsException ex) {
+                        LOGGER.warn("An exception was caught while accessing 
the caches key of " + loc + " in the incoming coverage zone file: " + 
ex.getMessage());
+                    }
+                }
 
                 try {
                     for (final JsonNode network6 : 
JsonUtils.getJsonNode(locData, "network6")) {
                         final String ip = network6.asText();
 
                         try {
-                            root.add6(new NetworkNode(ip, loc, geolocation));
+                            final NetworkNode nn = new NetworkNode(ip, loc, 
geolocation);
+                            if (useDeep && deepLoc != null) { // for deepLoc, 
we add the location here; normally it gets added by setLocation.
+                                nn.setCacheLocation(deepLoc);
+                            }
+                            root.add6(nn);
                         } catch (NetworkNodeException ex) {
                             LOGGER.error(ex, ex);
                             return null;
@@ -108,7 +166,11 @@ public class NetworkNode implements 
Comparable<NetworkNode> {
                         final String ip = network.asText();
 
                         try {
-                            root.add(new NetworkNode(ip, loc, geolocation));
+                            final NetworkNode nn = new NetworkNode(ip, loc, 
geolocation);
+                            if (useDeep && deepLoc != null) {
+                                nn.setCacheLocation(deepLoc);
+                            }
+                            root.add(nn);
                         } catch (NetworkNodeException ex) {
                             LOGGER.error(ex, ex);
                             return null;
@@ -120,7 +182,11 @@ public class NetworkNode implements 
Comparable<NetworkNode> {
             }
 
             if (!verifyOnly) {
-                instance = root;
+                if (useDeep) {
+                    deepInstance = root;
+                } else {
+                    instance = root;
+                }
             }
 
             return root;
diff --git 
a/traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/core/router/StatTracker.java
 
b/traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/core/router/StatTracker.java
index f628afd..78e1772 100644
--- 
a/traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/core/router/StatTracker.java
+++ 
b/traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/core/router/StatTracker.java
@@ -44,6 +44,18 @@ public class StatTracker {
                public void setGeoCount(final int geoCount) {
                        this.geoCount = geoCount;
                }
+               public int getDeepCzCount() {
+                       return deepCzCount;
+               }
+               public void setDeepCzCount(final int deepCzCount) {
+                       this.deepCzCount = deepCzCount;
+               }
+               public int getDeepCzMissCount() {
+                       return deepCzMissCount;
+               }
+               public void setDeepCzMissCount(final int deepCzMissCount) {
+                       this.deepCzMissCount = deepCzMissCount;
+               }
                public int getDsrCount() {
                        return dsrCount;
                }
@@ -89,6 +101,8 @@ public class StatTracker {
 
                public int czCount;
                public int geoCount;
+               public int deepCzCount;
+               public int deepCzMissCount;
                public int missCount;
                public int dsrCount;
                public int errCount;
@@ -104,7 +118,7 @@ public class StatTracker {
                }
 
                public static enum ResultType {
-                       ERROR, CZ, GEO, MISS, STATIC_ROUTE, DS_REDIRECT, 
DS_MISS, INIT, FED, RGDENY, RGALT, GEO_REDIRECT
+                       ERROR, CZ, GEO, MISS, STATIC_ROUTE, DS_REDIRECT, 
DS_MISS, INIT, FED, RGDENY, RGALT, GEO_REDIRECT, DEEP_CZ, DEEP_CZ_MISS
                }
 
                public enum ResultDetails {
@@ -274,6 +288,12 @@ public class StatTracker {
                case GEO:
                        tallies.geoCount++;
                        break;
+               case DEEP_CZ:
+                       tallies.deepCzCount++;
+                       break;
+               case DEEP_CZ_MISS:
+                       tallies.deepCzMissCount++;
+                       break;
                case MISS:
                        tallies.missCount++;
                        break;
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 7db9ab2..b1b2623 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
@@ -243,9 +243,42 @@ public class TrafficRouter {
 
                return null;
        }
-       protected List<Cache> selectCaches(final Request request, final 
DeliveryService ds, final Track track) throws GeolocationException {
-               final CacheLocation cacheLocation = 
getCoverageZoneCacheLocation(request.getClientIP(), ds);
-               List<Cache> caches = selectCachesByCZ(ds, cacheLocation, track);
+
+       @SuppressWarnings("PMD.CyclomaticComplexity")
+       protected List<Cache> selectCaches(final HTTPRequest request, final 
DeliveryService ds, final Track track) throws GeolocationException {
+               // DDC - Dynamic Deep Caching
+               // cacheLocation has a list of caches that we can hash this 
request to.
+               // Make this list different for content that should be cached 
deep.
+               //boolean useDeepCZ = false;
+               // first get the cachegroup, because the popularity is by 
cachegroup...
+               // this is expensive, but i see no other option.
+               final CacheLocation cacheGroup = 
getCoverageZoneCacheLocation(request.getClientIP(), ds, false);
+               CacheLocation cacheLocation = null;
+               ResultType result = ResultType.CZ;
+               if (cacheGroup != null) {
+                       // change true to a function that returns yes if the 
request.getPath is popular
+                       //boolean isPop = isPopular(request.getPath(), 
ds.getId(), cacheGroup.getId());
+                       if (ds.getDeepCache() == DeliveryService.DC_ALWAYS) {
+                               // Deep caching is enabled and wanted for the 
requested URL. See if there are deep caches available
+                               cacheLocation = 
getCoverageZoneCacheLocation(request.getClientIP(), ds, true);
+                               if (cacheLocation != null && 
cacheLocation.getCaches().size() != 0) {
+                                       // Found deep caches for this client, 
and there are caches available there.
+                                       // Use the cacheLocation, and set 
result to DEEP_CZ
+                                       result = ResultType.DEEP_CZ;
+                               } else {
+                                       // No deep caches for this client, 
would have used them if there were any...
+                                       // set the cacheLocation to the 
cacheGroup found earlier.
+                                       result = ResultType.DEEP_CZ_MISS;
+                                       cacheLocation = cacheGroup;
+                               }
+                       } else {
+                               // Deep caching not enabled or not for this 
URL. Back to cachegroup.
+                               cacheLocation = cacheGroup;
+                       }
+
+               }
+
+               List<Cache>caches = selectCachesByCZ(ds, cacheLocation, track, 
result);
 
                if (caches != null) {
                        return caches;
@@ -434,6 +467,10 @@ public class TrafficRouter {
        }
 
        private List<Cache> selectCachesByCZ(final DeliveryService ds, final 
CacheLocation cacheLocation, final Track track) {
+               return selectCachesByCZ(ds, cacheLocation, track, 
ResultType.CZ); // RestultType.CZ was the original default before DDC
+       }
+
+       private List<Cache> selectCachesByCZ(final DeliveryService ds, final 
CacheLocation cacheLocation, final Track track, final ResultType result) {
                if (cacheLocation == null || ds == null || 
!ds.isLocationAvailable(cacheLocation)) {
                        return null;
                }
@@ -441,7 +478,7 @@ public class TrafficRouter {
                final List<Cache> caches = selectCaches(cacheLocation, ds);
 
                if (caches != null && track != null) {
-                       track.setResult(ResultType.CZ);
+                       track.setResult(result);
                        track.setResultLocation(cacheLocation.getGeolocation());
                }
 
@@ -592,6 +629,15 @@ public class TrafficRouter {
                return false;
        }
 
+       protected NetworkNode getDeepNetworkNode(final String ip) {
+               try {
+                       return NetworkNode.getDeepInstance().getNetwork(ip);
+               } catch (NetworkNodeException e) {
+                       LOGGER.warn(e);
+               }
+               return null;
+       }
+
        protected NetworkNode getNetworkNode(final String ip) {
                try {
                        return NetworkNode.getInstance().getNetwork(ip);
@@ -602,7 +648,16 @@ public class TrafficRouter {
        }
 
        public CacheLocation getCoverageZoneCacheLocation(final String ip, 
final String deliveryServiceId) {
-               final NetworkNode networkNode = getNetworkNode(ip);
+               return getCoverageZoneCacheLocation(ip, deliveryServiceId, 
false); // default is not deep
+       }
+
+       public CacheLocation getCoverageZoneCacheLocation(final String ip, 
final String deliveryServiceId, final boolean useDeep) {
+               NetworkNode networkNode;
+               if (useDeep) {
+                       networkNode = getDeepNetworkNode(ip);
+               } else {
+                       networkNode = getNetworkNode(ip);
+               }
 
                if (networkNode == null) {
                        return null;
@@ -632,6 +687,10 @@ public class TrafficRouter {
                return 
getClosestCacheLocation(cacheRegister.filterAvailableLocations(deliveryServiceId),
 networkNode.getGeolocation(), 
cacheRegister.getDeliveryService(deliveryServiceId));
        }
 
+       protected CacheLocation getCoverageZoneCacheLocation(final String ip, 
final DeliveryService deliveryService, final boolean useDeep) {
+               return getCoverageZoneCacheLocation(ip, 
deliveryService.getId(), useDeep);
+       }
+
        protected CacheLocation getCoverageZoneCacheLocation(final String ip, 
final DeliveryService deliveryService) {
                return getCoverageZoneCacheLocation(ip, 
deliveryService.getId());
        }
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 4e3f869..d416a3f 100644
--- a/traffic_router/core/src/main/webapp/WEB-INF/applicationContext.xml
+++ b/traffic_router/core/src/main/webapp/WEB-INF/applicationContext.xml
@@ -109,6 +109,7 @@
                <property name="trafficRouterManager" 
ref="trafficRouterManager" />
                <property name="geolocationDatabaseUpdater" 
ref="geolocationDatabaseUpdater" />
                <property name="networkUpdater" ref="networkUpdater" />
+               <property name="deepNetworkUpdater" ref="deepNetworkUpdater" />
                <property name="regionalGeoUpdater" ref="regionalGeoUpdater" />
                <property name="statTracker" ref="statTracker" />
                <property name="configDir" value="/opt/traffic_router/conf" />
@@ -144,6 +145,14 @@
                <property name="trafficRouterManager" 
ref="trafficRouterManager" />
        </bean>
 
+       <bean id="deepNetworkUpdater" 
class="com.comcast.cdn.traffic_control.traffic_router.core.loc.DeepNetworkUpdater"
 init-method="init">
+               <property name="executorService" ref="ScheduledExecutorService" 
/>
+               <property name="databasesDirectory" ref="databasesDir" />
+               <property name="databaseName" 
value="$[cache.dczmap.database:dczmap.json]" />
+               <property name="pollingInterval" 
value="$[cache.dczmap.database.refresh.period:10800000]" />
+               <property name="trafficRouterManager" 
ref="trafficRouterManager" />
+       </bean>
+
        <bean id="regionalGeoUpdater" 
class="com.comcast.cdn.traffic_control.traffic_router.core.loc.RegionalGeoUpdater"
                init-method="init">
                <property name="executorService" ref="ScheduledExecutorService" 
/>
diff --git 
a/traffic_router/core/src/test/java/com/comcast/cdn/traffic_control/traffic_router/core/router/TrafficRouterTest.java
 
b/traffic_router/core/src/test/java/com/comcast/cdn/traffic_control/traffic_router/core/router/TrafficRouterTest.java
index 1c6e971..2e7a54a 100644
--- 
a/traffic_router/core/src/test/java/com/comcast/cdn/traffic_control/traffic_router/core/router/TrafficRouterTest.java
+++ 
b/traffic_router/core/src/test/java/com/comcast/cdn/traffic_control/traffic_router/core/router/TrafficRouterTest.java
@@ -138,7 +138,7 @@ public class TrafficRouterTest {
 
         List<Cache> caches = new ArrayList<Cache>();
         caches.add(cache);
-        when(trafficRouter.selectCaches(any(Request.class), 
any(DeliveryService.class), any(Track.class))).thenReturn(caches);
+        when(trafficRouter.selectCaches(any(HTTPRequest.class), 
any(DeliveryService.class), any(Track.class))).thenReturn(caches);
         when(trafficRouter.selectCachesByGeo(anyString(), 
any(DeliveryService.class), any(CacheLocation.class), 
any(Track.class))).thenCallRealMethod();
         when(trafficRouter.getClientLocation(anyString(), 
any(DeliveryService.class), any(CacheLocation.class), 
any(Track.class))).thenReturn(new Geolocation(40, -100));
         when(trafficRouter.getCachesByGeo(any(DeliveryService.class), 
any(Geolocation.class), any(Track.class))).thenCallRealMethod();
@@ -168,7 +168,7 @@ public class TrafficRouterTest {
         
when(deliveryService.isLocationAvailable(cacheLocation)).thenReturn(true);
         
when(deliveryService.filterAvailableLocations(any(Collection.class))).thenCallRealMethod();
 
-        when(trafficRouter.selectCaches(any(Request.class), 
any(DeliveryService.class), any(Track.class))).thenCallRealMethod();
+        when(trafficRouter.selectCaches(any(HTTPRequest.class), 
any(DeliveryService.class), any(Track.class))).thenCallRealMethod();
         when(trafficRouter.selectCachesByGeo(anyString(), 
any(DeliveryService.class), any(CacheLocation.class), 
any(Track.class))).thenCallRealMethod();
 
         Geolocation clientLocation = new Geolocation(40, -100);

-- 
To stop receiving notification emails like this one, please contact
els...@apache.org.

Reply via email to