risdenk commented on a change in pull request #307: KNOX-2304 - CM discovery
cluster config monitor needs to be aware of …
URL: https://github.com/apache/knox/pull/307#discussion_r405579448
##########
File path:
gateway-discovery-cm/src/main/java/org/apache/knox/gateway/topology/discovery/cm/monitor/PollingConfigurationAnalyzer.java
##########
@@ -365,12 +375,32 @@ private DiscoveryApiClient getApiClient(final
ServiceDiscoveryConfig discoveryCo
clusterName,
lastTimestamp);
for (ApiEvent event : events) {
- restartEvents.add(new RestartEvent(event));
+ List<ApiEventAttribute> attributes = event.getAttributes();
+ Map<String,Object> map = getAttributeMap(attributes);
+ addIfRelevantEvent(restartEvents, event, map);
}
return restartEvents;
}
+ @SuppressWarnings("unchecked")
+ private void addIfRelevantEvent(List<RestartEvent> restartEvents, ApiEvent
event, Map<String, Object> map) {
+ String command = null;
+ String status = null;
+ command = (String) ((List<String>) map.get(COMMAND)).get(0);
+ status = (String) ((List<String>) map.get(COMMAND_STATUS)).get(0);
+ if (START_COMMAND.equals(command) || RESTART_COMMAND.equals(command) &&
+ SUCCEEDED_STATUS.equals(status) || STARTED_STATUS.equals(status)) {
+ restartEvents.add(new RestartEvent(event));
+ }
+ }
+
+ private Map<String, Object> getAttributeMap(List<ApiEventAttribute>
attributes) {
+ Map<String,Object> map = new HashMap<>();
+ attributes.forEach(attr -> { map.put(attr.getName(), attr.getValues());});
Review comment:
This will overwrite in the map correct? The attribute get name - is that
unique? I think this is by COMMAND or COMMAND_STATUS based on the logic for
eventually checking the map. If there are duplicate commands won't they get
overwritten in the map? So its last write wins?
If you do a Start of SERVICEA and then Start of SERVICEB - will you see both
events or just collapse it down to one?
Another example is doing start of same service twice with different results.
start success then (implicit stop) then start failure. Will that get picked up?
I think the map is totally breaking the uniqueness and ordering of the
events.
----------------------------------------------------------------
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