You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@knox.apache.org by sm...@apache.org on 2020/04/22 11:35:08 UTC
[knox] branch v1.4.0 updated: KNOX-2350 - Handling event types w/o
COMMAND and/or COMMAND_STATUS attributes when polling CM events (#318)
(#319)
This is an automated email from the ASF dual-hosted git repository.
smolnar pushed a commit to branch v1.4.0
in repository https://gitbox.apache.org/repos/asf/knox.git
The following commit(s) were added to refs/heads/v1.4.0 by this push:
new 48b6e84 KNOX-2350 - Handling event types w/o COMMAND and/or COMMAND_STATUS attributes when polling CM events (#318) (#319)
48b6e84 is described below
commit 48b6e84f7edbfdd5838a4e28762bd5f8471534ae
Author: Sandor Molnar <sm...@apache.org>
AuthorDate: Wed Apr 22 13:35:00 2020 +0200
KNOX-2350 - Handling event types w/o COMMAND and/or COMMAND_STATUS attributes when polling CM events (#318) (#319)
---
.../cm/monitor/PollingConfigurationAnalyzer.java | 23 +++++++++-------------
.../monitor/PollingConfigurationAnalyzerTest.java | 10 ++++++++++
2 files changed, 19 insertions(+), 14 deletions(-)
diff --git a/gateway-discovery-cm/src/main/java/org/apache/knox/gateway/topology/discovery/cm/monitor/PollingConfigurationAnalyzer.java b/gateway-discovery-cm/src/main/java/org/apache/knox/gateway/topology/discovery/cm/monitor/PollingConfigurationAnalyzer.java
index 380962a..fb8d73c 100644
--- a/gateway-discovery-cm/src/main/java/org/apache/knox/gateway/topology/discovery/cm/monitor/PollingConfigurationAnalyzer.java
+++ b/gateway-discovery-cm/src/main/java/org/apache/knox/gateway/topology/discovery/cm/monitor/PollingConfigurationAnalyzer.java
@@ -48,12 +48,14 @@ import java.io.IOException;
import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
+import java.util.stream.Collectors;
import static org.apache.knox.gateway.topology.discovery.ClusterConfigurationMonitor.ConfigurationChangeListener;
@@ -385,24 +387,17 @@ public class PollingConfigurationAnalyzer implements Runnable {
@SuppressWarnings("unchecked")
private boolean isRelevantEvent(ApiEvent event) {
- boolean rc = false;
- String command = null;
- String status = null;
- List<ApiEventAttribute> attributes = event.getAttributes();
- Map<String,Object> map = getAttributeMap(attributes);
- 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)) {
- rc = true;
+ final Map<String, Object> attributeMap = getAttributeMap(event.getAttributes());
+ final String command = attributeMap.containsKey(COMMAND) ? (String) ((List<String>) attributeMap.get(COMMAND)).get(0) : "";
+ final String status = attributeMap.containsKey(COMMAND_STATUS) ? (String) ((List<String>) attributeMap.get(COMMAND_STATUS)).get(0) : "";
+ if ((START_COMMAND.equals(command) || RESTART_COMMAND.equals(command)) && (SUCCEEDED_STATUS.equals(status) || STARTED_STATUS.equals(status))) {
+ return true;
}
- return rc;
+ return false;
}
private Map<String, Object> getAttributeMap(List<ApiEventAttribute> attributes) {
- Map<String,Object> map = new HashMap<>();
- attributes.forEach(attr -> { map.put(attr.getName(), attr.getValues());});
- return map;
+ return attributes == null ? Collections.emptyMap() : attributes.stream().collect(Collectors.toMap(ApiEventAttribute::getName, ApiEventAttribute::getValues));
}
/**
diff --git a/gateway-discovery-cm/src/test/java/org/apache/knox/gateway/topology/discovery/cm/monitor/PollingConfigurationAnalyzerTest.java b/gateway-discovery-cm/src/test/java/org/apache/knox/gateway/topology/discovery/cm/monitor/PollingConfigurationAnalyzerTest.java
index cb2066e..49e339c 100644
--- a/gateway-discovery-cm/src/test/java/org/apache/knox/gateway/topology/discovery/cm/monitor/PollingConfigurationAnalyzerTest.java
+++ b/gateway-discovery-cm/src/test/java/org/apache/knox/gateway/topology/discovery/cm/monitor/PollingConfigurationAnalyzerTest.java
@@ -172,6 +172,16 @@ public class PollingConfigurationAnalyzerTest {
ApiEvent failedStartEvent = createApiEvent(ApiEventCategory.AUDIT_EVENT, startEventAttrs);
pca.addRestartEvent(clusterName, failedStartEvent);
+ // Simulate an event w/o COMMAND and/or COMMAND_STATUS attributes
+ final List<ApiEventAttribute> revisionEventAttrs = new ArrayList<>();
+ revisionEventAttrs.add(createEventAttribute("CLUSTER", clusterName));
+ revisionEventAttrs.add(createEventAttribute("SERVICE_TYPE", HiveOnTezServiceModelGenerator.SERVICE_TYPE));
+ revisionEventAttrs.add(createEventAttribute("SERVICE", HiveOnTezServiceModelGenerator.SERVICE));
+ revisionEventAttrs.add(createEventAttribute("REVISION", "215"));
+ revisionEventAttrs.add(createEventAttribute("EVENTCODE", "EV_REVISION_CREATED"));
+ final ApiEvent revisionEvent = createApiEvent(ApiEventCategory.AUDIT_EVENT, revisionEventAttrs);
+ pca.addRestartEvent(clusterName, revisionEvent);
+
try {
pollingThreadExecutor.awaitTermination(10, TimeUnit.SECONDS);
} catch (InterruptedException e) {