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_r237247306
##########
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();
+ // If its in the modified list then replace the
mappings in existing
+ if
(snap.getMappingEvents().keySet().contains(cacheName)) {
+ 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) {
+ // This means the delivery
service has been deleted, so we can only find it in the deleted list
+ theDs =
snap.getDeleteEvents().get(dsId);
+ if (theDs == null) {
+ // this means there is
a bug somewhere
+ // allow
NullPointerException
+
LOGGER.error("parseCacheConfig: This DeliveryService has been deleted from the
Cache " +
Review comment:
Can you move this message into a variable and reuse that in both places?
----------------------------------------------------------------
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