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_r239947686
##########
File path:
traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/core/config/ConfigHandler.java
##########
@@ -320,16 +411,95 @@ 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> existingLocations =
cacheRegister.getCacheLocations();
+ existingLocations.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(existingLocations);
+ // scan remaining caches for ds link changes
+ for (final String cacheName : existingCacheMap.keySet()) {
+ // If its in the modified list then replace the
mappings in existing
+ if
(!snap.getMappingEvents().keySet().contains(cacheName)) {
+ LOGGER.info("No changes for cache
named: "+cacheName);
+ continue;
+ } else {
+ LOGGER.info("Found mapping change for cache:
"+cacheName);
+ final Cache cache =
existingCacheMap.get(cacheName);
+ final Cache newCache =
snap.getMappingEvents().get(cacheName);
+ final Collection<DeliveryServiceReference>
existingDsRefs = cache.getDeliveryServices();
+ for (final DeliveryServiceReference dsr :
existingDsRefs ) {
+ final String dsId =
dsr.getDeliveryServiceId();
+ DeliveryService theDs =
cacheRegister.getDeliveryService(dsId);
+ if (theDs != null) {
+ final DeliveryServiceReference
ndsr = newCache.getDeliveryService(dsId);
+ addNewStats(ndsr, theDs);
+ continue;
+ } else {
Review comment:
ditto the comment above
----------------------------------------------------------------
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