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_r237244941
##########
File path:
traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/core/config/ConfigHandler.java
##########
@@ -320,16 +408,100 @@ private void parseTrafficOpsConfig(final JsonNode
config, final JsonNode stats)
/**
* Parses the cache information from the configuration and updates the
{@link CacheRegister}.
*
- * @param trConfig
- * the {@link TrafficRouterConfiguration}
+ * @param snap the {@link SnapshotEventsProcessor}
+ * @param cacheRegister the {@link CacheRegister}
+ */
+ @SuppressWarnings({"PMD.AvoidDeeplyNestedIfStmts" })
+ private void parseCacheConfig(final SnapshotEventsProcessor snap,
+ final CacheRegister cacheRegister) throws
+ ParseException {
+ final Map<String, Cache> existingCacheMap =
cacheRegister.getCacheMap();
+ // first Remove caches that have been deleted
+ existingCacheMap.entrySet().removeIf(exEntry-> {
+ if
(snap.getDeleteCacheEvents().contains(exEntry.getKey())){
+ LOGGER.info("Removed cache from map:
"+exEntry.getKey());
+ return true;
+ }
+ return false;
+ });
+ // remove deleted caches from locations
+ // this works because 'loc.getCaches()' makes a copy
+ final Set<CacheLocation> exLocations =
cacheRegister.getCacheLocations();
+ exLocations.forEach(loc->{
+ loc.getCaches().forEach(cacheEntry-> {
+ if
(snap.getDeleteCacheEvents().contains(cacheEntry.getId())) {
+ LOGGER.info("Removed cache from
location: "+cacheEntry.getId());
+ loc.removeCache(cacheEntry.getId());
+ }
+ });
+ });
+ cacheRegister.setConfiguredLocations(exLocations);
+ // scan remaining caches for ds link changes
+ final Iterator<String> cacheIter =
existingCacheMap.keySet().iterator();
+ while (cacheIter.hasNext()) {
+ final String cacheName = cacheIter.next();
Review comment:
Why an iterator vs the `for (final String cacheName :
existingCacheMap.KeySet())` syntax?
----------------------------------------------------------------
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