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_r286259923
 
 

 ##########
 File path: 
traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/core/config/ConfigHandler.java
 ##########
 @@ -128,136 +135,218 @@ public AnonymousIpDatabaseUpdater 
getAnonymousIpDatabaseUpdater() {
                return anonymousIpDatabaseUpdater;
        }
 
-       @SuppressWarnings({"PMD.CyclomaticComplexity", "PMD.NPathComplexity", 
"PMD.AvoidCatchingThrowable"})
-       public boolean processConfig(final String jsonStr) throws 
JsonUtilsException, IOException  {
+       @SuppressWarnings({"PMD.AvoidCatchingThrowable"})
+       public boolean processConfig(final String snapJson, final String 
compJson) throws JsonUtilsException, IOException {
                isProcessing.set(true);
-               LOGGER.info("Entered processConfig");
-               if (jsonStr == null) {
-                       trafficRouterManager.setCacheRegister(null);
+               LOGGER.debug("Entered processConfig");
+               if (snapJson == null) {
                        cancelled.set(false);
                        isProcessing.set(false);
                        publishStatusQueue.clear();
-                       LOGGER.info("Exiting processConfig: No json data to 
process");
+                       LOGGER.info("Exiting processConfig: No json data to 
process because snapshot was NULL.");
                        return false;
                }
 
                Date date;
-               synchronized(configSync) {
-                       final ObjectMapper mapper = new ObjectMapper();
-                       final JsonNode jo = mapper.readTree(jsonStr);
-                       final JsonNode config = JsonUtils.getJsonNode(jo, 
"config");
-                       final JsonNode stats = JsonUtils.getJsonNode(jo, 
"stats");
-
-                       final long sts = getSnapshotTimestamp(stats);
-                       date = new Date(sts * 1000L);
-
-                       if (sts <= getLastSnapshotTimestamp()) {
-                               cancelled.set(false);
+               final ObjectMapper mapper = new ObjectMapper();
+               final JsonNode jo = mapper.readTree(snapJson);
+               final JsonNode stats = JsonUtils.getJsonNode(jo, "stats");
+               final ObjectMapper compMapper = new ObjectMapper();
+               JsonNode cjo = null;
+               if (compJson != null) {
+                       cjo = compMapper.readTree(compJson);
+               }
+               // Check to see if this is a new Snapshot
+               final long sts = getSnapshotTimestamp(stats);
+               date = new Date(sts * 1000L);
+               if (sts <= getLastSnapshotTimestamp()) {
+                       cancelled.set(false);
+                       isProcessing.set(false);
+                       publishStatusQueue.clear();
+                       LOGGER.info("Exiting processConfig: Incoming CrConfig 
snapshot timestamp (" + sts + ") is older than " +
+                                       "the loaded timestamp (" + 
getLastSnapshotTimestamp() + "); unable to process");
+                       return false;
+               }
+               synchronized (configSync) {
+                       try {
+                               // Search for updates, adds and deletes to 
delivery services
+                               final SnapshotEventsProcessor 
snapshotEventsProcessor = SnapshotEventsProcessor
+                                               .diffCrConfigs(jo, cjo);
+
+                               if 
(snapshotEventsProcessor.shouldReloadConfig()) {
+                                       if (initializeAll(jo, 
snapshotEventsProcessor)) {
+                                               
ConfigHandler.setLastSnapshotTimestamp(sts);
+                                               return true;
+                                       }
+                               } else if (processChangeEvents(jo, 
snapshotEventsProcessor)) {
+                                       
ConfigHandler.setLastSnapshotTimestamp(sts);
+                                       return true;
+                               }
+                       } catch (ParseException e) {
+                               LOGGER.error("Exiting processConfig: Failed to 
process config for snapshot from " + date, e);
+                               return false;
+                       } finally {
                                isProcessing.set(false);
+                               cancelled.set(false);
                                publishStatusQueue.clear();
-                               LOGGER.info("Exiting processConfig: Incoming 
TrConfig snapshot timestamp (" + sts + ") is older or equal to the loaded 
timestamp (" + getLastSnapshotTimestamp() + "); unable to process");
-                               return false;
                        }
+               }
+               return false;
+       }
+
+
+       @SuppressWarnings({"PMD.AvoidCatchingThrowable"})
+       private boolean processChangeEvents(final JsonNode jo,
+                                           final SnapshotEventsProcessor 
snapshotEventsProcessor)
+                       throws ParseException, JsonUtilsException, IOException {
+               LOGGER.debug("In processChangeEvents");
+               final CacheRegister cacheRegister = new CacheRegister();
+               if (trafficRouterManager.getTrafficRouter() != null) {
+                       final CacheRegister prevCr = 
trafficRouterManager.getTrafficRouter().getCacheRegister();
+                       cacheRegister.shallowCopy(prevCr);
+               }
+               final JsonNode config = JsonUtils.getJsonNode(jo, CONFIG_KEY);
+               cacheRegister.setConfig(config);
+               parseRegionalGeoConfig(config, snapshotEventsProcessor);
+               parseAnonymousIpConfig(config, snapshotEventsProcessor);
+               updateCertsPublisher(snapshotEventsProcessor);
+               final List<DeliveryService> httpsDeliveryServices = 
snapshotEventsProcessor.getSSLEnabledChangeEvents();
+               httpsDeliveryServices.forEach(ds -> LOGGER.info("Checking for 
certificate for " + ds.getId()));
+               if (!httpsDeliveryServices.isEmpty() && !waitForSslCerts()) {
+                       return false;
+               }
+               // updates, creates and removes the DeliveryServices in 
cacheRegister
+               parseDeliveryServiceMatchSets(snapshotEventsProcessor, 
cacheRegister);
+               parseCacheConfig(snapshotEventsProcessor, cacheRegister);
+
+               synchronized (this) {
 
 Review comment:
   Why does this need to be sync'd? I don't see anything else syncing on `this` 
(in this file), and this method seems to already be within the `synchronized 
(configSync)` of its caller.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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