rawlinp commented on a change in pull request #2785: In Traffic Router Support 
Snapshots which only update Delivery Services
URL: https://github.com/apache/trafficcontrol/pull/2785#discussion_r239953358
 
 

 ##########
 File path: 
traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/core/config/ConfigHandler.java
 ##########
 @@ -560,115 +792,122 @@ private void parseCertificatesConfig(final JsonNode 
config) {
                        try {
                                System.setProperty(pollingInterval, 
JsonUtils.getString(config, pollingInterval));
                        } catch (Exception e) {
-                               LOGGER.warn("Failed to set system property " + 
pollingInterval + " from configuration object: " + e.getMessage());
+                               LOGGER.warn("Failed to set system property " + 
pollingInterval + " from configuration object: " + e
+                                               .getMessage());
                        }
                }
        }
 
-       private void parseAnonymousIpConfig(final JsonNode jo) throws 
JsonUtilsException {
+       private void parseAnonymousIpConfig(final JsonNode config, final 
SnapshotEventsProcessor dsep) {
                final String anonymousPollingUrl = "anonymousip.polling.url";
                final String anonymousPollingInterval = 
"anonymousip.polling.interval";
                final String anonymousPolicyConfiguration = 
"anonymousip.policy.configuration";
-
-               final JsonNode config = JsonUtils.getJsonNode(jo,"config");
+               final long interval = JsonUtils.optLong(config, 
anonymousPollingInterval);
                final String configUrl = JsonUtils.optString(config, 
anonymousPolicyConfiguration, null);
                final String databaseUrl = JsonUtils.optString(config, 
anonymousPollingUrl, null);
 
                if (configUrl == null) {
-                       LOGGER.info(anonymousPolicyConfiguration + " not 
configured; stopping service updater and disabling feature");
+                       LOGGER.info(anonymousPolicyConfiguration + " policy not 
configured; stopping service updater and disabling feature");
                        getAnonymousIpConfigUpdater().stopServiceUpdater();
                        AnonymousIp.getCurrentConfig().enabled = false;
                        return;
                }
-               
+
                if (databaseUrl == null) {
-                       LOGGER.info(anonymousPollingUrl + " not configured; 
stopping service updater and disabling feature");
+                       LOGGER.info(anonymousPollingUrl + " DB url not 
configured; stopping service updater and disabling feature");
                        getAnonymousIpDatabaseUpdater().stopServiceUpdater();
                        AnonymousIp.getCurrentConfig().enabled = false;
                        return;
                }
 
-               if (jo.has(deliveryServicesKey)) {
-                       final JsonNode dss = JsonUtils.getJsonNode(jo, 
deliveryServicesKey);
-                       final Iterator<String> dsNames = dss.fieldNames();
-                       while (dsNames.hasNext()) {
-                               final String ds = dsNames.next();
-                               final JsonNode dsNode = 
JsonUtils.getJsonNode(dss, ds);
-                               if (JsonUtils.optString(dsNode, 
"anonymousBlockingEnabled").equals("true")) {
-                                       final long interval = 
JsonUtils.optLong(config, anonymousPollingInterval);
-                                       
getAnonymousIpConfigUpdater().setDataBaseURL(configUrl, interval);
-                                       
getAnonymousIpDatabaseUpdater().setDataBaseURL(databaseUrl, interval);
-                                       AnonymousIp.getCurrentConfig().enabled 
= true;
-                                       LOGGER.debug("Anonymous Blocking in 
use, scheduling service updaters and enabling feature");
-                                       return;
-                               }
+               Collection<DeliveryService> deliveryServices = 
dsep.getCreationEvents().values();
+               if (findFirst(deliveryServices, ds -> 
ds.isAnonymousIpEnabled()).isPresent()) {
+                       getAnonymousIpConfigUpdater().setDataBaseURL(configUrl, 
interval);
+                       
getAnonymousIpDatabaseUpdater().setDataBaseURL(databaseUrl, interval);
+                       AnonymousIp.getCurrentConfig().enabled = true;
+                       LOGGER.debug("new Anonymous Blocking in use, scheduling 
service updaters and enabling feature");
+               } else {
+                       deliveryServices = dsep.getUpdateEvents().values();
+                       if (findFirst(deliveryServices, ds -> 
ds.isAnonymousIpEnabled()).isPresent()) {
+                               
getAnonymousIpConfigUpdater().setDataBaseURL(configUrl, interval);
+                               
getAnonymousIpDatabaseUpdater().setDataBaseURL(databaseUrl, interval);
+                               AnonymousIp.getCurrentConfig().enabled = true;
+                               LOGGER.debug("added Anonymous Blocking in use, 
scheduling service updaters and enabling feature");
+                       } else {
+                               LOGGER.debug("No DS using anonymous ip blocking 
- disabling feature");
+                               
getAnonymousIpConfigUpdater().cancelServiceUpdater();
+                               
getAnonymousIpDatabaseUpdater().cancelServiceUpdater();
+                               AnonymousIp.getCurrentConfig().enabled = false;
+
                        }
                }
-
-               LOGGER.debug("No DS using anonymous ip blocking - disabling 
feature");
-               getAnonymousIpConfigUpdater().cancelServiceUpdater();
-               getAnonymousIpDatabaseUpdater().cancelServiceUpdater();
-               AnonymousIp.getCurrentConfig().enabled = false;
        }
 
        /**
         * Parses the ConverageZoneNetwork database configuration and updates 
the database if the URL has
         * changed.
         *
-        * @param trConfig
-        *            the {@link TrafficRouterConfiguration}
+        * @param config
         * @throws JsonUtilsException
         */
        private void parseCoverageZoneNetworkConfig(final JsonNode config) 
throws JsonUtilsException {
                getNetworkUpdater().setDataBaseURL(
                                JsonUtils.getString(config, 
"coveragezone.polling.url"),
                                JsonUtils.optLong(config, 
"coveragezone.polling.interval")
-                       );
+               );
        }
 
-       private void parseDeepCoverageZoneNetworkConfig(final JsonNode config) 
throws JsonUtilsException {
+       private void parseDeepCoverageZoneNetworkConfig(final JsonNode config) {
                getDeepNetworkUpdater().setDataBaseURL(
-                       JsonUtils.optString(config, 
"deepcoveragezone.polling.url", null),
-                       JsonUtils.optLong(config, 
"deepcoveragezone.polling.interval")
+                               JsonUtils.optString(config, 
"deepcoveragezone.polling.url", null),
 
 Review comment:
   ditto the earlier comment above about indentation

----------------------------------------------------------------
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

Reply via email to