ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aonis...@apache.org
Subject [49/53] [abbrv] ambari git commit: AMBARI-22639. Log Feeder refactor: integrate with spring boot (oleewere)
Date Fri, 15 Dec 2017 12:52:49 GMT
http://git-wip-us.apache.org/repos/asf/ambari/blob/31e8e55a/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
deleted file mode 100644
index 46abc63..0000000
--- a/ambari-logsearch/ambari-logsearch-logfeeder/src/test/java/org/apache/ambari/logfeeder/logconfig/LogConfigHandlerTest.java
+++ /dev/null
@@ -1,148 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ambari.logfeeder.logconfig;
-
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.Date;
-
-import static org.easymock.EasyMock.*;
-import static org.junit.Assert.*;
-
-import org.apache.ambari.logfeeder.input.Input;
-import org.apache.ambari.logfeeder.input.InputMarker;
-import org.apache.ambari.logfeeder.loglevelfilter.FilterLogData;
-import org.apache.ambari.logfeeder.loglevelfilter.LogLevelFilterHandler;
-import org.apache.ambari.logfeeder.util.LogFeederPropertiesUtil;
-import org.apache.ambari.logsearch.config.api.LogSearchConfig;
-import org.apache.ambari.logsearch.config.api.model.loglevelfilter.LogLevelFilter;
-import org.apache.commons.lang.time.DateUtils;
-import org.apache.ambari.logsearch.config.zookeeper.model.inputconfig.impl.InputDescriptorImpl;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-public class LogConfigHandlerTest {
-  
-  private static InputMarker inputMarkerAudit;
-  private static InputMarker inputMarkerService;
-  static {
-    InputDescriptorImpl auditInputDescriptor = new InputDescriptorImpl() {};
-    auditInputDescriptor.setRowtype("audit");
-    
-    Input auditInput = strictMock(Input.class);
-    expect(auditInput.getInputDescriptor()).andReturn(auditInputDescriptor).anyTimes();
-    inputMarkerAudit = new InputMarker(auditInput, null, 0);
-    
-    InputDescriptorImpl serviceInputDescriptor = new InputDescriptorImpl() {};
-    serviceInputDescriptor.setRowtype("service");
-    
-    Input serviceInput = strictMock(Input.class);
-    expect(serviceInput.getInputDescriptor()).andReturn(serviceInputDescriptor).anyTimes();
-    inputMarkerService = new InputMarker(serviceInput, null, 0);
-    
-    replay(auditInput, serviceInput);
-  }
-  
-  @BeforeClass
-  public static void init() throws Exception {
-    LogFeederPropertiesUtil.loadProperties("logfeeder.properties");
-    
-    LogSearchConfig config = strictMock(LogSearchConfig.class);
-    config.createLogLevelFilter(anyString(), anyString(), anyObject(LogLevelFilter.class));
-    expectLastCall().anyTimes();
-    LogLevelFilterHandler.init(config);
-    
-    LogLevelFilter logLevelFilter1 = new LogLevelFilter();
-    logLevelFilter1.setHosts(Collections.<String> emptyList());
-    logLevelFilter1.setDefaultLevels(Arrays.asList("FATAL", "ERROR", "WARN", "INFO"));
-    logLevelFilter1.setOverrideLevels(Collections.<String> emptyList());
-    
-    LogLevelFilter logLevelFilter2 = new LogLevelFilter();
-    logLevelFilter2.setHosts(Arrays.asList("host1"));
-    logLevelFilter2.setDefaultLevels(Arrays.asList("FATAL", "ERROR", "WARN", "INFO"));
-    logLevelFilter2.setOverrideLevels(Arrays.asList("FATAL", "ERROR", "WARN", "INFO", "DEBUG",
"TRACE"));
-    logLevelFilter2.setExpiryTime(DateUtils.addDays(new Date(), 1));
-    
-    LogLevelFilter logLevelFilter3 = new LogLevelFilter();
-    logLevelFilter3.setHosts(Arrays.asList("host1"));
-    logLevelFilter3.setDefaultLevels(Arrays.asList("FATAL", "ERROR", "WARN", "INFO"));
-    logLevelFilter3.setOverrideLevels(Arrays.asList("FATAL", "ERROR", "WARN", "INFO", "DEBUG",
"TRACE"));
-    logLevelFilter3.setExpiryTime(DateUtils.addDays(new Date(), -1));
-    
-    LogLevelFilterHandler h = new LogLevelFilterHandler();
-    h.setLogLevelFilter("configured_log_file1", logLevelFilter1);
-    h.setLogLevelFilter("configured_log_file2", logLevelFilter2);
-    h.setLogLevelFilter("configured_log_file3", logLevelFilter3);
-  }
-  
-  @Test
-  public void testLogConfigHandler_auditAllowed() throws Exception {
-    assertTrue(FilterLogData.INSTANCE.isAllowed("{'host':'host1', 'type':'configured_log_file1',
'level':'DEBUG'}",
-        inputMarkerAudit));
-  }
-  
-  @Test
-  public void testLogConfigHandler_emptyDataAllowed() throws Exception {
-    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_file1',
'level':'WARN'}",
-        inputMarkerService));
-  }
-  
-  @Test
-  public void testLogConfigHandler_notConfiguredLogNotAllowed() throws Exception {
-    assertFalse(FilterLogData.INSTANCE.isAllowed("{'host':'host1', 'type':'not_configured_log_file1',
'level':'TRACE'}",
-        inputMarkerService));
-  }
-  
-  @Test
-  public void testLogConfigHandler_configuredDataAllow() throws Exception {
-    assertTrue(FilterLogData.INSTANCE.isAllowed("{'host':'host1', 'type':'configured_log_file1',
'level':'INFO'}",
-        inputMarkerService));
-  }
-  
-  @Test
-  public void testLogConfigHandler_configuredDataDontAllow() throws Exception {
-    assertFalse(FilterLogData.INSTANCE.isAllowed("{'host':'host1', 'type':'configured_log_file1',
'level':'DEBUG'}",
-        inputMarkerService));
-  }
-  
-  @Test
-  public void testLogConfigHandler_overridenConfiguredData() throws Exception {
-    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'}",
-        inputMarkerService));
-  }
-  
-  @Test
-  public void testLogConfigHandler_overridenConfiguredDataExpired() throws Exception {
-    assertFalse(FilterLogData.INSTANCE.isAllowed("{'host':'host1', 'type':'configured_log_file3',
'level':'DEBUG'}",
-        inputMarkerService));
-  }
-}

http://git-wip-us.apache.org/repos/asf/ambari/blob/31e8e55a/ambari-logsearch/ambari-logsearch-logfeeder/src/test/java/org/apache/ambari/logfeeder/metrics/MetricsManagerTest.java
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-logfeeder/src/test/java/org/apache/ambari/logfeeder/metrics/MetricsManagerTest.java
b/ambari-logsearch/ambari-logsearch-logfeeder/src/test/java/org/apache/ambari/logfeeder/metrics/MetricsManagerTest.java
index f74a80e..da8fff7 100644
--- a/ambari-logsearch/ambari-logsearch-logfeeder/src/test/java/org/apache/ambari/logfeeder/metrics/MetricsManagerTest.java
+++ b/ambari-logsearch/ambari-logsearch-logfeeder/src/test/java/org/apache/ambari/logfeeder/metrics/MetricsManagerTest.java
@@ -29,11 +29,9 @@ import java.util.Arrays;
 import java.util.List;
 import java.util.TreeMap;
 
-import org.apache.ambari.logfeeder.util.LogFeederPropertiesUtil;
 import org.apache.hadoop.metrics2.sink.timeline.TimelineMetric;
 import org.apache.hadoop.metrics2.sink.timeline.TimelineMetrics;
 import org.junit.Before;
-import org.junit.BeforeClass;
 import org.junit.Test;
 
 public class MetricsManagerTest {
@@ -42,11 +40,6 @@ public class MetricsManagerTest {
   private LogFeederAMSClient mockClient;
   private Capture<TimelineMetrics> capture;
   
-  @BeforeClass
-  public static void loadProperties() throws Exception {
-    LogFeederPropertiesUtil.loadProperties("logfeeder.properties");
-  }
-  
   @Before
   public void init() throws Exception {
     manager = new MetricsManager();

http://git-wip-us.apache.org/repos/asf/ambari/blob/31e8e55a/ambari-logsearch/ambari-logsearch-logfeeder/src/test/java/org/apache/ambari/logfeeder/output/OutputKafkaTest.java
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-logfeeder/src/test/java/org/apache/ambari/logfeeder/output/OutputKafkaTest.java
b/ambari-logsearch/ambari-logsearch-logfeeder/src/test/java/org/apache/ambari/logfeeder/output/OutputKafkaTest.java
index 38d4b8b..c0babc4 100644
--- a/ambari-logsearch/ambari-logsearch-logfeeder/src/test/java/org/apache/ambari/logfeeder/output/OutputKafkaTest.java
+++ b/ambari-logsearch/ambari-logsearch-logfeeder/src/test/java/org/apache/ambari/logfeeder/output/OutputKafkaTest.java
@@ -23,6 +23,7 @@ import java.util.Map;
 import java.util.Properties;
 import java.util.concurrent.Future;
 
+import org.apache.ambari.logfeeder.conf.LogFeederProps;
 import org.apache.ambari.logfeeder.input.Input;
 import org.apache.ambari.logfeeder.input.InputMarker;
 import org.apache.ambari.logfeeder.output.OutputKafka.KafkaCallBack;
@@ -69,7 +70,7 @@ public class OutputKafkaTest {
     config.put("topic", TEST_TOPIC);
 
     outputKafka.loadConfig(config);
-    outputKafka.init();
+    outputKafka.init(new LogFeederProps());
 
     @SuppressWarnings("unchecked")
     Future<RecordMetadata> mockFuture = EasyMock.mock(Future.class);
@@ -103,7 +104,7 @@ public class OutputKafkaTest {
     config.put("topic", TEST_TOPIC);
 
     outputKafka.loadConfig(config);
-    outputKafka.init();
+    outputKafka.init(new LogFeederProps());
   }
 
   @Test
@@ -117,7 +118,7 @@ public class OutputKafkaTest {
     config.put("broker_list", "some broker list");
 
     outputKafka.loadConfig(config);
-    outputKafka.init();
+    outputKafka.init(new LogFeederProps());
   }
 
   @After

http://git-wip-us.apache.org/repos/asf/ambari/blob/31e8e55a/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 5abb720..49f5a11 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
@@ -29,8 +29,10 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
+import org.apache.ambari.logfeeder.conf.LogFeederProps;
 import org.apache.ambari.logfeeder.input.Input;
 import org.apache.ambari.logfeeder.input.InputMarker;
+import org.apache.ambari.logfeeder.loglevelfilter.LogLevelFilterHandler;
 import org.apache.ambari.logfeeder.metrics.MetricData;
 import org.apache.ambari.logsearch.config.zookeeper.model.inputconfig.impl.InputDescriptorImpl;
 import org.junit.Test;
@@ -63,10 +65,11 @@ public class OutputManagerTest {
     Output output1 = strictMock(Output.class);
     Output output2 = strictMock(Output.class);
     Output output3 = strictMock(Output.class);
-    
-    output1.init(); expectLastCall();
-    output2.init(); expectLastCall();
-    output3.init(); expectLastCall();
+
+    LogFeederProps logFeederProps = new LogFeederProps();
+    output1.init(logFeederProps); expectLastCall();
+    output2.init(logFeederProps); expectLastCall();
+    output3.init(logFeederProps); expectLastCall();
     
     replay(output1, output2, output3);
     
@@ -74,6 +77,7 @@ public class OutputManagerTest {
     manager.add(output1);
     manager.add(output2);
     manager.add(output3);
+    manager.setLogFeederProps(logFeederProps);
     
     manager.init();
     
@@ -98,11 +102,14 @@ public class OutputManagerTest {
     Output output1 = strictMock(Output.class);
     Output output2 = strictMock(Output.class);
     Output output3 = strictMock(Output.class);
+
+    LogLevelFilterHandler mockFilter = strictMock(LogLevelFilterHandler.class);
     
     expect(mockInput.getInputDescriptor()).andReturn(inputDescriptor);
-    expect(mockInput.isUseEventMD5()).andReturn(false);
-    expect(mockInput.isGenEventMD5()).andReturn(false);
-    expect(mockInput.getInputDescriptor()).andReturn(inputDescriptor);
+    expect(mockInput.isUseEventMD5()).andReturn(false).anyTimes();
+    expect(mockInput.isGenEventMD5()).andReturn(false).anyTimes();
+    expect(mockInput.getInputDescriptor()).andReturn(inputDescriptor).anyTimes();
+    expect(mockFilter.isAllowed(jsonObj, inputMarker)).andReturn(true).anyTimes();
     expect(mockInput.getCache()).andReturn(null);
     expect(mockInput.getOutputList()).andReturn(Arrays.asList(output1, output2, output3));
 
@@ -110,9 +117,10 @@ public class OutputManagerTest {
     output2.write(jsonObj, inputMarker); expectLastCall();
     output3.write(jsonObj, inputMarker); expectLastCall();
     
-    replay(output1, output2, output3, mockInput);
+    replay(output1, output2, output3, mockFilter, mockInput);
     
     OutputManager manager = new OutputManager();
+    manager.setLogLevelFilterHandler(mockFilter);
     manager.add(output1);
     manager.add(output2);
     manager.add(output3);
@@ -133,17 +141,21 @@ public class OutputManagerTest {
     Output output1 = strictMock(Output.class);
     Output output2 = strictMock(Output.class);
     Output output3 = strictMock(Output.class);
+
+    LogLevelFilterHandler mockFilter = strictMock(LogLevelFilterHandler.class);
     
-    expect(mockInput.getInputDescriptor()).andReturn(inputDescriptor);
+    expect(mockInput.getInputDescriptor()).andReturn(inputDescriptor).anyTimes();
+    expect(mockFilter.isAllowed(jsonString, inputMarker)).andReturn(true).anyTimes();
     expect(mockInput.getOutputList()).andReturn(Arrays.asList(output1, output2, output3));
     
     output1.write(jsonString, inputMarker); expectLastCall();
     output2.write(jsonString, inputMarker); expectLastCall();
     output3.write(jsonString, inputMarker); expectLastCall();
     
-    replay(output1, output2, output3, mockInput);
+    replay(output1, output2, output3, mockInput, mockFilter);
     
     OutputManager manager = new OutputManager();
+    manager.setLogLevelFilterHandler(mockFilter);
     manager.add(output1);
     manager.add(output2);
     manager.add(output3);

http://git-wip-us.apache.org/repos/asf/ambari/blob/31e8e55a/ambari-logsearch/ambari-logsearch-logfeeder/src/test/java/org/apache/ambari/logfeeder/output/OutputS3FileTest.java
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-logfeeder/src/test/java/org/apache/ambari/logfeeder/output/OutputS3FileTest.java
b/ambari-logsearch/ambari-logsearch-logfeeder/src/test/java/org/apache/ambari/logfeeder/output/OutputS3FileTest.java
index 7c6aca2..78cf014 100644
--- a/ambari-logsearch/ambari-logsearch-logfeeder/src/test/java/org/apache/ambari/logfeeder/output/OutputS3FileTest.java
+++ b/ambari-logsearch/ambari-logsearch-logfeeder/src/test/java/org/apache/ambari/logfeeder/output/OutputS3FileTest.java
@@ -18,6 +18,7 @@
 
 package org.apache.ambari.logfeeder.output;
 
+import org.apache.ambari.logfeeder.conf.LogFeederProps;
 import org.apache.ambari.logfeeder.input.Input;
 import org.apache.ambari.logfeeder.input.InputMarker;
 import org.apache.ambari.logfeeder.output.spool.LogSpooler;
@@ -93,7 +94,7 @@ public class OutputS3FileTest {
       }
     };
     outputS3File.loadConfig(configMap);
-    outputS3File.init();
+    outputS3File.init(new LogFeederProps());
     outputS3File.write("log event block", inputMarker);
     verify(spooler);
   }
@@ -130,7 +131,7 @@ public class OutputS3FileTest {
       }
     };
     outputS3File.loadConfig(configMap);
-    outputS3File.init();
+    outputS3File.init(new LogFeederProps());
     outputS3File.write("log event block1", inputMarker);
     outputS3File.write("log event block2", inputMarker);
     verify(spooler);
@@ -149,7 +150,7 @@ public class OutputS3FileTest {
     OutputS3File outputS3File = new OutputS3File();
     configMap.put(S3OutputConfiguration.ROLLOVER_SIZE_THRESHOLD_BYTES_KEY, thresholdSize);
     outputS3File.loadConfig(configMap);
-    outputS3File.init();
+    outputS3File.init(new LogFeederProps());
 
     assertTrue(outputS3File.shouldRollover(logSpoolerContext));
   }
@@ -166,7 +167,7 @@ public class OutputS3FileTest {
     OutputS3File outputS3File = new OutputS3File();
     configMap.put(S3OutputConfiguration.ROLLOVER_SIZE_THRESHOLD_BYTES_KEY, thresholdSize);
     outputS3File.loadConfig(configMap);
-    outputS3File.init();
+    outputS3File.init(new LogFeederProps());
 
     assertFalse(outputS3File.shouldRollover(logSpoolerContext));
   }

http://git-wip-us.apache.org/repos/asf/ambari/blob/31e8e55a/ambari-logsearch/ambari-logsearch-logfeeder/src/test/java/org/apache/ambari/logfeeder/output/OutputSolrTest.java
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-logfeeder/src/test/java/org/apache/ambari/logfeeder/output/OutputSolrTest.java
b/ambari-logsearch/ambari-logsearch-logfeeder/src/test/java/org/apache/ambari/logfeeder/output/OutputSolrTest.java
index 5ab271a..70d5c8f 100644
--- a/ambari-logsearch/ambari-logsearch-logfeeder/src/test/java/org/apache/ambari/logfeeder/output/OutputSolrTest.java
+++ b/ambari-logsearch/ambari-logsearch-logfeeder/src/test/java/org/apache/ambari/logfeeder/output/OutputSolrTest.java
@@ -26,6 +26,8 @@ import java.util.Map;
 import java.util.Set;
 import java.util.concurrent.ConcurrentHashMap;
 
+import org.apache.ambari.logfeeder.conf.LogFeederProps;
+import org.apache.ambari.logfeeder.conf.LogFeederSecurityConfig;
 import org.apache.ambari.logfeeder.input.Input;
 import org.apache.ambari.logfeeder.input.InputMarker;
 import org.apache.ambari.logsearch.config.api.LogSearchConfigLogFeeder;
@@ -52,12 +54,16 @@ public class OutputSolrTest {
   private OutputSolr outputSolr;
   private LogSearchConfigLogFeeder logSearchConfigMock;
   private Map<Integer, SolrInputDocument> receivedDocs = new ConcurrentHashMap<>();
+  private LogFeederProps logFeederProps = new LogFeederProps();
 
   @Rule
   public ExpectedException expectedException = ExpectedException.none();
 
   @Before
   public void init() throws Exception {
+    LogFeederSecurityConfig logFeederSecurityConfig = new LogFeederSecurityConfig();
+    logFeederSecurityConfig.setSolrKerberosEnabled(false);
+    logFeederProps.setLogFeederSecurityConfig(logFeederSecurityConfig);
     outputSolr = new OutputSolr() {
       @SuppressWarnings("deprecation")
       @Override
@@ -97,7 +103,7 @@ public class OutputSolrTest {
     config.put("type", "service");
 
     outputSolr.loadConfig(config);
-    outputSolr.init();
+    outputSolr.init(logFeederProps);
 
     Map<Integer, SolrInputDocument> expectedDocs = new HashMap<>();
 
@@ -166,7 +172,7 @@ public class OutputSolrTest {
     config.put("type", "service");
 
     outputSolr.loadConfig(config);
-    outputSolr.init();
+    outputSolr.init(logFeederProps);
   }
 
   @After


Mime
View raw message