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 b3cf0071d62d3630899e2790287f8a64bd2aad64
Author: Jesse Rivas <jesse_ri...@comcast.com>
AuthorDate: Wed Feb 7 14:39:18 2018 -0700

    added geolocationOverrides to CRConfig and TR
    
    added documentation for geolocation.default.override profile parameter
---
 docs/source/admin/traffic_ops/configuration.rst      |  3 +++
 traffic_ops/app/lib/UI/Topology.pm                   | 13 +++++++++++++
 .../core/loc/MaxmindGeolocationService.java          |  4 ++++
 .../traffic_router/core/router/TrafficRouter.java    | 20 ++++++++++++++++++++
 .../traffic_router/geolocation/Geolocation.java      |  9 +++++++++
 5 files changed, 49 insertions(+)

diff --git a/docs/source/admin/traffic_ops/configuration.rst 
b/docs/source/admin/traffic_ops/configuration.rst
index 89bb726..720999e 100644
--- a/docs/source/admin/traffic_ops/configuration.rst
+++ b/docs/source/admin/traffic_ops/configuration.rst
@@ -158,6 +158,9 @@ Many of the settings for the different servers in a Traffic 
Control CDN are cont
 
+--------------------------+---------------+---------------------------------------------------------------------------------------------------------------------------------------+
 | geolocation6.polling.url | CRConfig.json | The location to get the IPv6 
GeoLiteCity database from.                                                      
                         |
 
+--------------------------+---------------+---------------------------------------------------------------------------------------------------------------------------------------+
+| geolocation.default /    | CRConfig.json | The country code and destination 
geo coordinates to use when the geo database service returns a default 
location.                     |
+| override                 |               | Format: 
<CountryCode>;<Lat>,<Long>   Ex: US;37.751,-97.822                              
                                              |
++--------------------------+---------------+---------------------------------------------------------------------------------------------------------------------------------------+
 
 These parameters should be set to reflect the local environment.
 
diff --git a/traffic_ops/app/lib/UI/Topology.pm 
b/traffic_ops/app/lib/UI/Topology.pm
index 6480e13..c659abc 100644
--- a/traffic_ops/app/lib/UI/Topology.pm
+++ b/traffic_ops/app/lib/UI/Topology.pm
@@ -153,6 +153,19 @@ sub gen_crconfig_json {
             }
             $data_obj->{'config'}->{'requestHeaders'} = $headers;
         }
+        elsif ( $param eq 'geolocation.default.override' ) {
+            ( my $country_code, my $coordinates ) = split( /\;/, 
$row->parameter->value );
+            ( my $lat, my $long ) = split( /\,/, $coordinates );
+            my $geolocation = {
+                'CountryCode' => "$country_code",
+                'Lat' => "$lat",
+                'Long' => "$long"
+            };
+            if ( !$data_obj->{'config'}->{'geolocationOverride'} ) {
+                $data_obj->{'config'}->{'geolocationOverride'} = [];
+            }
+            push ( $data_obj->{'config'}->{'geolocationOverride'}, 
$geolocation );
+        }
         elsif ( !exists $requested_param_names{$param} ) {
             $data_obj->{'config'}->{$param} = $row->parameter->value;
         }
diff --git 
a/traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/core/loc/MaxmindGeolocationService.java
 
b/traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/core/loc/MaxmindGeolocationService.java
index b9150d2..b7e4567 100644
--- 
a/traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/core/loc/MaxmindGeolocationService.java
+++ 
b/traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/core/loc/MaxmindGeolocationService.java
@@ -150,6 +150,10 @@ public class MaxmindGeolocationService implements 
GeolocationService {
                        
geolocation.setCountryName(response.getCountry().getName());
                }
 
+               if (geolocation.getCity() == null && 
geolocation.getPostalCode() == null && response.getSubdivisions().isEmpty()) {
+                       geolocation.setIsDefault(true);
+               }
+
                return geolocation;
        }
 }
\ No newline at end of file
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 49be6d4..2d29fa2 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
@@ -22,6 +22,7 @@ import java.net.URL;
 import java.net.UnknownHostException;
 import java.util.ArrayList;
 import java.util.Collections;
+import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
@@ -86,6 +87,8 @@ public class TrafficRouter {
        private final ConsistentHasher consistentHasher = new 
ConsistentHasher();
        private SteeringRegistry steeringRegistry;
 
+       private final Map<String, Geolocation> defaultGeolocations = new 
HashMap<String, Geolocation>();
+
        public TrafficRouter(final CacheRegister cr, 
                        final GeolocationService geolocationService, 
                        final GeolocationService geolocationService6, 
@@ -99,6 +102,19 @@ public class TrafficRouter {
                this.federationRegistry = federationRegistry;
                this.consistentDNSRouting = 
JsonUtils.optBoolean(cr.getConfig(), "consistent.dns.routing");
                this.zoneManager = new ZoneManager(this, statTracker, 
trafficOpsUtils, trafficRouterManager);
+
+               if (cr.getConfig() != null) {
+                       // geolocationOverride: {CountryCode: , Lat: , Long: }
+                       final JsonNode geolocations = 
cr.getConfig().get("geolocationOverride");
+                       if (geolocations != null) {
+                               for (final JsonNode geolocation : geolocations) 
{
+                                       final String countryCode = 
JsonUtils.optString(geolocation, "CountryCode");
+                                       final double lat = 
JsonUtils.optDouble(geolocation, "Lat");
+                                       final double longitude = 
JsonUtils.optDouble(geolocation, "Long");
+                                       defaultGeolocations.put(countryCode, 
new Geolocation(lat, longitude));
+                               }
+                       }
+               }
        }
 
        public ZoneManager getZoneManager() {
@@ -309,6 +325,10 @@ public class TrafficRouter {
                        }
                }
 
+               if (clientLocation.isDefault() == true && 
defaultGeolocations.containsKey(clientLocation.getCountryCode())) {
+                       clientLocation = 
defaultGeolocations.get(clientLocation.getCountryCode());
+               }
+
                final List<Cache> caches = getCachesByGeo(deliveryService, 
clientLocation, track);
 
                if (caches == null || caches.isEmpty()) {
diff --git 
a/traffic_router/geolocation/src/main/java/com/comcast/cdn/traffic_control/traffic_router/geolocation/Geolocation.java
 
b/traffic_router/geolocation/src/main/java/com/comcast/cdn/traffic_control/traffic_router/geolocation/Geolocation.java
index a2f5ffa..fed07af 100644
--- 
a/traffic_router/geolocation/src/main/java/com/comcast/cdn/traffic_control/traffic_router/geolocation/Geolocation.java
+++ 
b/traffic_router/geolocation/src/main/java/com/comcast/cdn/traffic_control/traffic_router/geolocation/Geolocation.java
@@ -31,6 +31,7 @@ public class Geolocation {
        private String city;
        private String countryCode;
        private String countryName;
+       private boolean isDefault;
 
        /**
         * Creates an immutable {@link Geolocation}.
@@ -145,6 +146,14 @@ public class Geolocation {
                this.countryName = countryName;
        }
 
+       public boolean isDefault() {
+               return isDefault;
+       }
+
+       public void setIsDefault(boolean isDefault) {
+               this.isDefault = isDefault;
+       }
+
        @Override
        public int hashCode() {
                return new HashCodeBuilder(1, 31)

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

Reply via email to