You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by ol...@apache.org on 2016/10/03 14:36:17 UTC
[14/16] ambari git commit: AMBARI-18372. Audit logs should not be
filtered by Log Feeder (Miklos Gergely via oleewere)
AMBARI-18372. Audit logs should not be filtered by Log Feeder (Miklos Gergely via oleewere)
Change-Id: I636b5619e365e9a9f1271a0da4df545d459900cf
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/fb600aab
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/fb600aab
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/fb600aab
Branch: refs/heads/logsearch-ga
Commit: fb600aab8095c85b685d90e9273db86c9d151ade
Parents: a83bf2b
Author: Miklos Gergely <mg...@hortonworks.com>
Authored: Mon Oct 3 16:13:42 2016 +0200
Committer: oleewere <ol...@gmail.com>
Committed: Mon Oct 3 16:33:56 2016 +0200
----------------------------------------------------------------------
.../logfeeder/logconfig/FilterLogData.java | 10 ++--
.../ambari/logfeeder/output/OutputManager.java | 4 +-
.../logconfig/LogConfigHandlerTest.java | 51 ++++++++++++++++----
.../logfeeder/output/OutputManagerTest.java | 2 +
4 files changed, 53 insertions(+), 14 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/fb600aab/ambari-logsearch/ambari-logsearch-logfeeder/src/main/java/org/apache/ambari/logfeeder/logconfig/FilterLogData.java
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-logfeeder/src/main/java/org/apache/ambari/logfeeder/logconfig/FilterLogData.java b/ambari-logsearch/ambari-logsearch-logfeeder/src/main/java/org/apache/ambari/logfeeder/logconfig/FilterLogData.java
index 801a289..a05a916 100644
--- a/ambari-logsearch/ambari-logsearch-logfeeder/src/main/java/org/apache/ambari/logfeeder/logconfig/FilterLogData.java
+++ b/ambari-logsearch/ambari-logsearch-logfeeder/src/main/java/org/apache/ambari/logfeeder/logconfig/FilterLogData.java
@@ -23,6 +23,7 @@ import java.util.List;
import java.util.Map;
import org.apache.ambari.logfeeder.common.LogFeederConstants;
+import org.apache.ambari.logfeeder.input.InputMarker;
import org.apache.ambari.logfeeder.util.LogFeederUtil;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
@@ -39,15 +40,18 @@ public enum FilterLogData {
private static final boolean DEFAULT_VALUE = true;
- public boolean isAllowed(String jsonBlock) {
+ public boolean isAllowed(String jsonBlock, InputMarker inputMarker) {
if (StringUtils.isEmpty(jsonBlock)) {
return DEFAULT_VALUE;
}
Map<String, Object> jsonObj = LogFeederUtil.toJSONObject(jsonBlock);
- return isAllowed(jsonObj);
+ return isAllowed(jsonObj, inputMarker);
}
- public boolean isAllowed(Map<String, Object> jsonObj) {
+ public boolean isAllowed(Map<String, Object> jsonObj, InputMarker inputMarker) {
+ if ("audit".equals(inputMarker.input.getConfigs().get(LogFeederConstants.ROW_TYPE)))
+ return true;
+
boolean isAllowed = applyFilter(jsonObj);
if (!isAllowed) {
LOG.trace("Filter block the content :" + LogFeederUtil.getGson().toJson(jsonObj));
http://git-wip-us.apache.org/repos/asf/ambari/blob/fb600aab/ambari-logsearch/ambari-logsearch-logfeeder/src/main/java/org/apache/ambari/logfeeder/output/OutputManager.java
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-logfeeder/src/main/java/org/apache/ambari/logfeeder/output/OutputManager.java b/ambari-logsearch/ambari-logsearch-logfeeder/src/main/java/org/apache/ambari/logfeeder/output/OutputManager.java
index 2c81c19..86b5c57 100644
--- a/ambari-logsearch/ambari-logsearch-logfeeder/src/main/java/org/apache/ambari/logfeeder/output/OutputManager.java
+++ b/ambari-logsearch/ambari-logsearch-logfeeder/src/main/java/org/apache/ambari/logfeeder/output/OutputManager.java
@@ -139,7 +139,7 @@ public class OutputManager {
}
}
- if (FilterLogData.INSTANCE.isAllowed(jsonObj)) {
+ if (FilterLogData.INSTANCE.isAllowed(jsonObj, inputMarker)) {
for (Output output : input.getOutputList()) {
try {
output.write(jsonObj, inputMarker);
@@ -171,7 +171,7 @@ public class OutputManager {
}
public void write(String jsonBlock, InputMarker inputMarker) {
- if (FilterLogData.INSTANCE.isAllowed(jsonBlock)) {
+ if (FilterLogData.INSTANCE.isAllowed(jsonBlock, inputMarker)) {
for (Output output : inputMarker.input.getOutputList()) {
try {
output.write(jsonBlock, inputMarker);
http://git-wip-us.apache.org/repos/asf/ambari/blob/fb600aab/ambari-logsearch/ambari-logsearch-logfeeder/src/test/java/org/apache/ambari/logfeeder/logconfig/LogConfigHandlerTest.java
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-logfeeder/src/test/java/org/apache/ambari/logfeeder/logconfig/LogConfigHandlerTest.java b/ambari-logsearch/ambari-logsearch-logfeeder/src/test/java/org/apache/ambari/logfeeder/logconfig/LogConfigHandlerTest.java
index 02ffd47..266108f 100644
--- a/ambari-logsearch/ambari-logsearch-logfeeder/src/test/java/org/apache/ambari/logfeeder/logconfig/LogConfigHandlerTest.java
+++ b/ambari-logsearch/ambari-logsearch-logfeeder/src/test/java/org/apache/ambari/logfeeder/logconfig/LogConfigHandlerTest.java
@@ -26,6 +26,9 @@ import java.util.Map;
import static org.easymock.EasyMock.*;
import static org.junit.Assert.*;
+import org.apache.ambari.logfeeder.common.LogFeederConstants;
+import org.apache.ambari.logfeeder.input.Input;
+import org.apache.ambari.logfeeder.input.InputMarker;
import org.apache.ambari.logfeeder.util.LogFeederUtil;
import org.junit.AfterClass;
import org.junit.BeforeClass;
@@ -35,6 +38,24 @@ public class LogConfigHandlerTest {
private static LogConfigFetcher mockFetcher;
+ private static InputMarker inputMarkerAudit;
+ private static InputMarker inputMarkerService;
+ static {
+ Map<String, Object> auditMap = new HashMap<String, Object>();
+ auditMap.put(LogFeederConstants.ROW_TYPE, "audit");
+ Input auditInput = strictMock(Input.class);
+ expect(auditInput.getConfigs()).andReturn(auditMap).anyTimes();
+ inputMarkerAudit = new InputMarker(auditInput, null, 0);
+
+ Map<String, Object> serviceMap = new HashMap<String, Object>();
+ serviceMap.put(LogFeederConstants.ROW_TYPE, "service");
+ Input serviceInput = strictMock(Input.class);
+ expect(serviceInput.getConfigs()).andReturn(serviceMap).anyTimes();
+ inputMarkerService = new InputMarker(serviceInput, null, 0);
+
+ replay(auditInput, serviceInput);
+ }
+
private static final Map<String, Object> CONFIG_MAP = new HashMap<>();
static {
CONFIG_MAP.put("jsons",
@@ -74,40 +95,52 @@ public class LogConfigHandlerTest {
}
@Test
+ public void testLogConfigHandler_auditAllowed() throws Exception {
+ assertTrue(FilterLogData.INSTANCE.isAllowed("{'host':'host1', 'type':'configured_log_file', 'level':'DEBUG'}",
+ inputMarkerAudit));
+ }
+
+ @Test
public void testLogConfigHandler_emptyDataAllowed() throws Exception {
- assertTrue(FilterLogData.INSTANCE.isAllowed((String)null));
- assertTrue(FilterLogData.INSTANCE.isAllowed(""));
- assertTrue(FilterLogData.INSTANCE.isAllowed(Collections.<String, Object> emptyMap()));
+ assertTrue(FilterLogData.INSTANCE.isAllowed((String)null, inputMarkerService));
+ assertTrue(FilterLogData.INSTANCE.isAllowed("", inputMarkerService));
+ assertTrue(FilterLogData.INSTANCE.isAllowed(Collections.<String, Object> emptyMap(), inputMarkerService));
}
@Test
public void testLogConfigHandler_notConfiguredLogAllowed() throws Exception {
- assertTrue(FilterLogData.INSTANCE.isAllowed("{'host':'host1', 'type':'not_configured_log_file', 'level':'INFO'}"));
+ assertTrue(FilterLogData.INSTANCE.isAllowed("{'host':'host1', 'type':'not_configured_log_file', 'level':'INFO'}",
+ inputMarkerService));
}
@Test
public void testLogConfigHandler_configuredDataAllow() throws Exception {
- assertTrue(FilterLogData.INSTANCE.isAllowed("{'host':'host1', 'type':'configured_log_file', 'level':'INFO'}"));
+ assertTrue(FilterLogData.INSTANCE.isAllowed("{'host':'host1', 'type':'configured_log_file', 'level':'INFO'}",
+ inputMarkerService));
}
@Test
public void testLogConfigHandler_configuredDataDontAllow() throws Exception {
- assertFalse(FilterLogData.INSTANCE.isAllowed("{'host':'host1', 'type':'configured_log_file', 'level':'DEBUG'}"));
+ assertFalse(FilterLogData.INSTANCE.isAllowed("{'host':'host1', 'type':'configured_log_file', 'level':'DEBUG'}",
+ inputMarkerService));
}
@Test
public void testLogConfigHandler_overridenConfiguredData() throws Exception {
- assertTrue(FilterLogData.INSTANCE.isAllowed("{'host':'host1', 'type':'configured_log_file2', 'level':'DEBUG'}"));
+ assertTrue(FilterLogData.INSTANCE.isAllowed("{'host':'host1', 'type':'configured_log_file2', 'level':'DEBUG'}",
+ inputMarkerService));
}
@Test
public void testLogConfigHandler_overridenConfiguredDataDifferentHost() throws Exception {
- assertFalse(FilterLogData.INSTANCE.isAllowed("{'host':'host2', 'type':'configured_log_file2', 'level':'DEBUG'}"));
+ assertFalse(FilterLogData.INSTANCE.isAllowed("{'host':'host2', 'type':'configured_log_file2', 'level':'DEBUG'}",
+ inputMarkerService));
}
@Test
public void testLogConfigHandler_overridenConfiguredDataExpired() throws Exception {
- assertFalse(FilterLogData.INSTANCE.isAllowed("{'host':'host1', 'type':'configured_log_file3', 'level':'DEBUG'}"));
+ assertFalse(FilterLogData.INSTANCE.isAllowed("{'host':'host1', 'type':'configured_log_file3', 'level':'DEBUG'}",
+ inputMarkerService));
}
@AfterClass
http://git-wip-us.apache.org/repos/asf/ambari/blob/fb600aab/ambari-logsearch/ambari-logsearch-logfeeder/src/test/java/org/apache/ambari/logfeeder/output/OutputManagerTest.java
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-logfeeder/src/test/java/org/apache/ambari/logfeeder/output/OutputManagerTest.java b/ambari-logsearch/ambari-logsearch-logfeeder/src/test/java/org/apache/ambari/logfeeder/output/OutputManagerTest.java
index e103346..a080fa8 100644
--- a/ambari-logsearch/ambari-logsearch-logfeeder/src/test/java/org/apache/ambari/logfeeder/output/OutputManagerTest.java
+++ b/ambari-logsearch/ambari-logsearch-logfeeder/src/test/java/org/apache/ambari/logfeeder/output/OutputManagerTest.java
@@ -102,6 +102,7 @@ public class OutputManagerTest {
expect(mockInput.getContextFields()).andReturn(Collections.<String, String> emptyMap());
expect(mockInput.isUseEventMD5()).andReturn(false);
expect(mockInput.isGenEventMD5()).andReturn(false);
+ expect(mockInput.getConfigs()).andReturn(Collections.<String, Object> emptyMap());
expect(mockInput.getOutputList()).andReturn(Arrays.asList(output1, output2, output3));
output1.write(jsonObj, inputMarker); expectLastCall();
@@ -131,6 +132,7 @@ public class OutputManagerTest {
Output output2 = strictMock(Output.class);
Output output3 = strictMock(Output.class);
+ expect(mockInput.getConfigs()).andReturn(Collections.<String, Object> emptyMap());
expect(mockInput.getOutputList()).andReturn(Arrays.asList(output1, output2, output3));
output1.write(jsonString, inputMarker); expectLastCall();