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_r236471214
##########
File path:
traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/core/config/ConfigHandler.java
##########
@@ -128,136 +139,213 @@ 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) {
+ LOGGER.debug("Entered processConfig");
+ if (snapJson == null) {
trafficRouterManager.setCacheRegister(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) {
+ synchronized (configSync) {
final ObjectMapper mapper = new ObjectMapper();
- final JsonNode jo = mapper.readTree(jsonStr);
- final JsonNode config = JsonUtils.getJsonNode(jo,
"config");
+ 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()) {
+ if (sts < getLastSnapshotTimestamp()) {
cancelled.set(false);
isProcessing.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");
+ LOGGER.info("Exiting processConfig: Incoming
CrConfig snapshot timestamp (" + sts + ") is older than " +
+ "the loaded timestamp (" +
getLastSnapshotTimestamp() + "); unable to process");
return false;
}
-
try {
- parseGeolocationConfig(config);
- parseCoverageZoneNetworkConfig(config);
- parseDeepCoverageZoneNetworkConfig(config);
- parseRegionalGeoConfig(jo);
- parseAnonymousIpConfig(jo);
-
- final CacheRegister cacheRegister = new
CacheRegister();
- final JsonNode deliveryServicesJson =
JsonUtils.getJsonNode(jo, "deliveryServices");
-
cacheRegister.setTrafficRouters(JsonUtils.getJsonNode(jo, "contentRouters"));
- cacheRegister.setConfig(config);
- cacheRegister.setStats(stats);
- parseTrafficOpsConfig(config, stats);
-
- final Map<String, DeliveryService>
deliveryServiceMap = parseDeliveryServiceConfig(JsonUtils.getJsonNode(jo,
deliveryServicesKey));
-
- parseCertificatesConfig(config);
-
certificatesPublisher.setDeliveryServicesJson(deliveryServicesJson);
- final ArrayList<DeliveryService>
deliveryServices = new ArrayList<>();
-
- if (deliveryServiceMap != null &&
!deliveryServiceMap.values().isEmpty()) {
-
deliveryServices.addAll(deliveryServiceMap.values());
+ // Search for updates, adds and deletes to
delivery services
+ final SnapshotEventsProcessor
snapshotEventsProcessor = SnapshotEventsProcessor
+ .diffCrConfigs(jo, cjo);
+
+ if (snapshotEventsProcessor.shouldLoadAll()) {
+ if (loadEntireSnapshot(jo,
snapshotEventsProcessor)) {
+
ConfigHandler.setLastSnapshotTimestamp(sts);
+ return true;
+ }
+ } else if(processChangeEvents(jo,
snapshotEventsProcessor)) {
+
ConfigHandler.setLastSnapshotTimestamp(sts);
Review comment:
Can you fix the formatting here?
----------------------------------------------------------------
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