trafficcontrol-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From els...@apache.org
Subject [incubator-trafficcontrol] 29/36: Address DDC review comments
Date Wed, 24 Jan 2018 17:23:38 GMT
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 013909de88439c87e48b6af29642e7670896ec11
Author: Rawlin Peters <rawlin_peters@comcast.com>
AuthorDate: Fri Nov 10 15:57:43 2017 -0700

    Address DDC review comments
    
    Changed DCZF to use 'deepCoverageZones' key instead of 'coverageZones'
    for better separation.
    
    Created enum type DeepCachingType to use in DeliveryService struct in
    lib/go-tc.
---
 docs/source/admin/traffic_ops/using.rst            |  4 +-
 lib/go-tc/deliveryservices.go                      |  2 +-
 lib/go-tc/enum.go                                  | 48 ++++++++++++++++++++++
 .../traffic_router/core/ds/DeliveryService.java    |  2 +-
 .../traffic_router/core/loc/NetworkNode.java       |  3 +-
 .../traffic_router/core/loc/NetworkUpdater.java    |  2 +-
 .../traffic_router/core/loc/NetworkNodeTest.java   |  3 +-
 .../core/loc/NetworkNodeUnitTest.java              |  6 +--
 traffic_router/core/src/test/resources/dczmap.json |  2 +-
 9 files changed, 61 insertions(+), 11 deletions(-)

diff --git a/docs/source/admin/traffic_ops/using.rst b/docs/source/admin/traffic_ops/using.rst
index 5ac1a0d..6a6c130 100644
--- a/docs/source/admin/traffic_ops/using.rst
+++ b/docs/source/admin/traffic_ops/using.rst
@@ -895,10 +895,10 @@ The script that generates the CZF file is not part of Traffic Control,
since it
 
 The Deep Coverage Zone File
 +++++++++++++++++++++++++++
-The Deep Coverage Zone File (DCZF) format is similar to the CZF format but adds a ``caches``
list under each ``coverageZone``: ::
+The Deep Coverage Zone File (DCZF) format is similar to the CZF format but adds a ``caches``
list under each ``deepCoverageZone``: ::
 
   {
-    "coverageZones": {
+    "deepCoverageZones": {
       "location-01": {
         "coordinates": {
           "latitude":  5.5,
diff --git a/lib/go-tc/deliveryservices.go b/lib/go-tc/deliveryservices.go
index b27b655..9d621a8 100644
--- a/lib/go-tc/deliveryservices.go
+++ b/lib/go-tc/deliveryservices.go
@@ -56,7 +56,7 @@ type DeliveryService struct {
 	Active               bool                   `json:"active"`
 	DSCP                 int                    `json:"dscp"`
 	RoutingName          string                 `json:"routingName"`
-	DeepCachingType      string                 `json:"deepCachingType"`
+	DeepCachingType      DeepCachingType        `json:"deepCachingType"`
 	Signed               bool                   `json:"signed"`
 	QStringIgnore        int                    `json:"qstringIgnore"`
 	GeoLimit             int                    `json:"geoLimit"`
diff --git a/lib/go-tc/enum.go b/lib/go-tc/enum.go
index 46aa9d0..f8f3a66 100644
--- a/lib/go-tc/enum.go
+++ b/lib/go-tc/enum.go
@@ -29,6 +29,8 @@ package tc
  */
 
 import (
+	"errors"
+	"strconv"
 	"strings"
 )
 
@@ -182,3 +184,49 @@ func CacheStatusFromString(s string) CacheStatus {
 		return CacheStatusInvalid
 	}
 }
+
+// DeepCachingType represents a Delivery Service's deep caching type. The string values of
this type should match the Traffic Ops values.
+type DeepCachingType string
+
+const (
+	DeepCachingTypeAlways  = DeepCachingType("ALWAYS")
+	DeepCachingTypeNever   = DeepCachingType("NEVER")
+	DeepCachingTypeInvalid = DeepCachingType("")
+)
+
+// String returns a string representation of this deep caching type
+func (t DeepCachingType) String() string {
+	switch t {
+	case DeepCachingTypeAlways:
+		return string(t)
+	case DeepCachingTypeNever:
+		return string(t)
+	default:
+		return "INVALID"
+	}
+}
+
+// DeepCachingTypeFromString returns a DeepCachingType from its string representation, or
DeepCachingTypeInvalid if the string is not a valid type.
+func DeepCachingTypeFromString(s string) DeepCachingType {
+	switch strings.ToLower(s) {
+	case "always":
+		return DeepCachingTypeAlways
+	case "never":
+		return DeepCachingTypeNever
+	default:
+		return DeepCachingTypeInvalid
+	}
+}
+
+// UnmarshalJSON unmarshals a JSON representation of a DeepCachingType (i.e. a string) or
returns an error if the DeepCachingType is invalid
+func (t *DeepCachingType) UnmarshalJSON(data []byte) error {
+	s, err := strconv.Unquote(string(data))
+	if err != nil {
+		return errors.New(string(data) + " JSON not quoted")
+	}
+	*t = DeepCachingTypeFromString(s)
+	if *t == DeepCachingTypeInvalid {
+		return errors.New(string(data) + " is not a DeepCachingType")
+	}
+	return nil
+}
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 3ac4ac9..6305e12 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
@@ -150,7 +150,7 @@ public class DeliveryService {
 		acceptHttp = JsonUtils.optBoolean(protocol, "acceptHttp", true);
 		acceptHttps = JsonUtils.optBoolean(protocol, "acceptHttps");
 		redirectToHttps = JsonUtils.optBoolean(protocol, "redirectToHttps");
-		final String dctString = JsonUtils.optString(dsJo, "deepCachingType", "NEVER");
+		final String dctString = JsonUtils.optString(dsJo, "deepCachingType", "NEVER").toUpperCase();
 		DeepCachingType dct = DeepCachingType.NEVER;
 		try {
 			dct = DeepCachingType.valueOf(dctString);
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 c098320..9d292ae 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
@@ -96,7 +96,8 @@ public class NetworkNode implements Comparable<NetworkNode> {
     @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");
+            final String czKey = useDeep ? "deepCoverageZones" : "coverageZones";
+            final JsonNode coverageZones = JsonUtils.getJsonNode(json, czKey);
 
             final SuperNode root = new SuperNode();
 
diff --git a/traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/core/loc/NetworkUpdater.java
b/traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/core/loc/NetworkUpdater.java
index d1dc4c5..2ae2938 100644
--- a/traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/core/loc/NetworkUpdater.java
+++ b/traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/core/loc/NetworkUpdater.java
@@ -47,7 +47,7 @@ public class NetworkUpdater extends AbstractServiceUpdater {
 		return generateTree(dbFile, true) != null;
 	}
 
-	public NetworkNode generateTree(final File dbFile, final boolean verifyOnly) throws IOException,
JSONException {
+	public NetworkNode generateTree(final File dbFile, final boolean verifyOnly) throws IOException
{
 		return NetworkNode.generateTree(dbFile, verifyOnly);
 	}
 
diff --git a/traffic_router/core/src/test/java/com/comcast/cdn/traffic_control/traffic_router/core/loc/NetworkNodeTest.java
b/traffic_router/core/src/test/java/com/comcast/cdn/traffic_control/traffic_router/core/loc/NetworkNodeTest.java
index 3517751..e4301af 100644
--- a/traffic_router/core/src/test/java/com/comcast/cdn/traffic_control/traffic_router/core/loc/NetworkNodeTest.java
+++ b/traffic_router/core/src/test/java/com/comcast/cdn/traffic_control/traffic_router/core/loc/NetworkNodeTest.java
@@ -58,7 +58,8 @@ public class NetworkNodeTest {
 		final NetworkNode nn = NetworkNode.generateTree(file, false, useDeep);
 		final ObjectMapper mapper = new ObjectMapper();
 		final JsonNode jsonNode = mapper.readTree(file);
-		final JsonNode coverageZones = jsonNode.get("coverageZones");
+		final String czKey = useDeep ? "deepCoverageZones" : "coverageZones";
+		final JsonNode coverageZones = jsonNode.get(czKey);
 
 		final Iterator<String> networkIter = coverageZones.fieldNames();
 		while (networkIter.hasNext()) {
diff --git a/traffic_router/core/src/test/java/com/comcast/cdn/traffic_control/traffic_router/core/loc/NetworkNodeUnitTest.java
b/traffic_router/core/src/test/java/com/comcast/cdn/traffic_control/traffic_router/core/loc/NetworkNodeUnitTest.java
index f4dd55a..3ebb10e 100644
--- a/traffic_router/core/src/test/java/com/comcast/cdn/traffic_control/traffic_router/core/loc/NetworkNodeUnitTest.java
+++ b/traffic_router/core/src/test/java/com/comcast/cdn/traffic_control/traffic_router/core/loc/NetworkNodeUnitTest.java
@@ -93,7 +93,7 @@ public class NetworkNodeUnitTest {
         String czmapString = "{" +
                 "\"revision\": \"Mon Dec 21 15:04:01 2015\"," +
                 "\"customerName\": \"Kabletown\"," +
-                "\"coverageZones\": {" +
+                "\"deepCoverageZones\": {" +
                 "\"us-co-denver\": {" +
                 "\"network\": [\"192.168.55.0/24\",\"192.168.6.0/24\",\"192.168.0.0/16\"],"
+
                 "\"network6\": [\"1234:5678::/64\",\"1234:5679::/64\"]," +
@@ -102,8 +102,8 @@ public class NetworkNodeUnitTest {
                 "}" +
                 "}";
 
-        JSONTokener jsonTokener = new JSONTokener(czmapString);
-        final JSONObject json = new JSONObject(jsonTokener);
+        final ObjectMapper mapper = new ObjectMapper();
+        final JsonNode json = mapper.readTree(czmapString);
         NetworkNode networkNode = NetworkNode.generateTree(json, false, true);
         NetworkNode foundNetworkNode = networkNode.getNetwork("192.168.55.100");
 
diff --git a/traffic_router/core/src/test/resources/dczmap.json b/traffic_router/core/src/test/resources/dczmap.json
index 39185c1..bfc5c5b 100644
--- a/traffic_router/core/src/test/resources/dczmap.json
+++ b/traffic_router/core/src/test/resources/dczmap.json
@@ -1,5 +1,5 @@
 {
-	"coverageZones":
+	"deepCoverageZones":
 	{
 		"cache-group-01":
 		{

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

Mime
View raw message