This is an automated email from the ASF dual-hosted git repository.

oleewere pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/ambari.git


The following commit(s) were added to refs/heads/trunk by this push:
     new 7a7ecdd  AMBARI-23566. Fix shipper config test entry mechanism (#996)
7a7ecdd is described below

commit 7a7ecdd901a9fae81d8c706ba37738743ae8f3fe
Author: Olivér Szabó <oleew...@gmail.com>
AuthorDate: Fri Apr 13 15:17:05 2018 +0200

    AMBARI-23566. Fix shipper config test entry mechanism (#996)
---
 .../apache/ambari/logfeeder/common/ConfigHandler.java    |  8 ++++++++
 .../ambari/logfeeder/common/LogEntryParseTester.java     |  9 +++++++++
 .../logfeeder/loglevelfilter/LogLevelFilterHandler.java  |  4 ++++
 .../ambari/logfeeder/output/OutputManagerImpl.java       |  1 -
 ambari-logsearch/ambari-logsearch-server/pom.xml         | 10 ++++++++++
 .../org/apache/ambari/logsearch/doc/DocConstants.java    |  4 ++++
 .../ambari/logsearch/manager/ShipperConfigManager.java   |  7 +++----
 .../logsearch/model/request/ShipperConfigTestParams.java | 16 ++++++++--------
 .../model/request/impl/ShipperConfigTestRequest.java     | 15 +++++++++++----
 .../ambari/logsearch/rest/ShipperConfigResource.java     |  4 +++-
 10 files changed, 60 insertions(+), 18 deletions(-)

diff --git 
a/ambari-logsearch/ambari-logsearch-logfeeder/src/main/java/org/apache/ambari/logfeeder/common/ConfigHandler.java
 
b/ambari-logsearch/ambari-logsearch-logfeeder/src/main/java/org/apache/ambari/logfeeder/common/ConfigHandler.java
index f138c13..b4c4f22 100644
--- 
a/ambari-logsearch/ambari-logsearch-logfeeder/src/main/java/org/apache/ambari/logfeeder/common/ConfigHandler.java
+++ 
b/ambari-logsearch/ambari-logsearch-logfeeder/src/main/java/org/apache/ambari/logfeeder/common/ConfigHandler.java
@@ -442,4 +442,12 @@ public class ConfigHandler implements InputConfigMonitor {
     outputManager.close();
     inputManager.checkInAll();
   }
+
+  public void setInputManager(InputManager inputManager) {
+    this.inputManager = inputManager;
+  }
+
+  public void setOutputManager(OutputManager outputManager) {
+    this.outputManager = outputManager;
+  }
 }
diff --git 
a/ambari-logsearch/ambari-logsearch-logfeeder/src/main/java/org/apache/ambari/logfeeder/common/LogEntryParseTester.java
 
b/ambari-logsearch/ambari-logsearch-logfeeder/src/main/java/org/apache/ambari/logfeeder/common/LogEntryParseTester.java
index 81f7317..14b6f83 100644
--- 
a/ambari-logsearch/ambari-logsearch-logfeeder/src/main/java/org/apache/ambari/logfeeder/common/LogEntryParseTester.java
+++ 
b/ambari-logsearch/ambari-logsearch-logfeeder/src/main/java/org/apache/ambari/logfeeder/common/LogEntryParseTester.java
@@ -27,6 +27,9 @@ import java.util.Map;
 
 import org.apache.ambari.logfeeder.conf.LogFeederProps;
 import org.apache.ambari.logfeeder.input.InputFileMarker;
+import org.apache.ambari.logfeeder.input.InputManagerImpl;
+import org.apache.ambari.logfeeder.loglevelfilter.LogLevelFilterHandler;
+import org.apache.ambari.logfeeder.output.OutputManagerImpl;
 import org.apache.ambari.logfeeder.plugin.input.Input;
 import org.apache.ambari.logfeeder.plugin.input.InputMarker;
 import org.apache.ambari.logfeeder.plugin.output.Output;
@@ -77,6 +80,12 @@ public class LogEntryParseTester {
   public Map<String, Object> parse() throws Exception {
     InputConfig inputConfig = getInputConfig();
     ConfigHandler configHandler = new ConfigHandler(null);
+    configHandler.setInputManager(new InputManagerImpl());
+    OutputManagerImpl outputManager = new OutputManagerImpl();
+    LogLevelFilterHandler logLevelFilterHandler = new 
LogLevelFilterHandler(null);
+    logLevelFilterHandler.setLogFeederProps(new LogFeederProps());
+    outputManager.setLogLevelFilterHandler(logLevelFilterHandler);
+    configHandler.setOutputManager(outputManager);
     Input input = configHandler.getTestInput(inputConfig, logId);
     final Map<String, Object> result = new HashMap<>();
     input.getFirstFilter().init(new LogFeederProps());
diff --git 
a/ambari-logsearch/ambari-logsearch-logfeeder/src/main/java/org/apache/ambari/logfeeder/loglevelfilter/LogLevelFilterHandler.java
 
b/ambari-logsearch/ambari-logsearch-logfeeder/src/main/java/org/apache/ambari/logfeeder/loglevelfilter/LogLevelFilterHandler.java
index 1874ee9..4eeb197 100644
--- 
a/ambari-logsearch/ambari-logsearch-logfeeder/src/main/java/org/apache/ambari/logfeeder/loglevelfilter/LogLevelFilterHandler.java
+++ 
b/ambari-logsearch/ambari-logsearch-logfeeder/src/main/java/org/apache/ambari/logfeeder/loglevelfilter/LogLevelFilterHandler.java
@@ -198,4 +198,8 @@ public class LogLevelFilterHandler implements 
LogLevelFilterMonitor {
       return false;
     }
   }
+
+  public void setLogFeederProps(LogFeederProps logFeederProps) {
+    this.logFeederProps = logFeederProps;
+  }
 }
diff --git 
a/ambari-logsearch/ambari-logsearch-logfeeder/src/main/java/org/apache/ambari/logfeeder/output/OutputManagerImpl.java
 
b/ambari-logsearch/ambari-logsearch-logfeeder/src/main/java/org/apache/ambari/logfeeder/output/OutputManagerImpl.java
index 834cf7e..612573b 100644
--- 
a/ambari-logsearch/ambari-logsearch-logfeeder/src/main/java/org/apache/ambari/logfeeder/output/OutputManagerImpl.java
+++ 
b/ambari-logsearch/ambari-logsearch-logfeeder/src/main/java/org/apache/ambari/logfeeder/output/OutputManagerImpl.java
@@ -264,7 +264,6 @@ public class OutputManagerImpl extends OutputManager {
     return logLevelFilterHandler;
   }
 
-  @VisibleForTesting
   public void setLogLevelFilterHandler(LogLevelFilterHandler 
logLevelFilterHandler) {
     this.logLevelFilterHandler = logLevelFilterHandler;
   }
diff --git a/ambari-logsearch/ambari-logsearch-server/pom.xml 
b/ambari-logsearch/ambari-logsearch-server/pom.xml
index 5730f80..64ddf3a 100755
--- a/ambari-logsearch/ambari-logsearch-server/pom.xml
+++ b/ambari-logsearch/ambari-logsearch-server/pom.xml
@@ -293,6 +293,16 @@
         <groupId>com.google.guava</groupId>
         <version>20.0</version>
     </dependency>
+    <dependency>
+      <groupId>org.codehaus.jackson</groupId>
+      <artifactId>jackson-core-asl</artifactId>
+      <version>1.9.13</version>
+    </dependency>
+    <dependency>
+      <groupId>org.codehaus.jackson</groupId>
+      <artifactId>jackson-mapper-asl</artifactId>
+      <version>1.9.13</version>
+    </dependency>
 
     <dependency>
       <groupId>javax.servlet</groupId>
diff --git 
a/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/doc/DocConstants.java
 
b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/doc/DocConstants.java
index b0fdeb4..1b58fb8 100644
--- 
a/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/doc/DocConstants.java
+++ 
b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/doc/DocConstants.java
@@ -46,6 +46,10 @@ public class DocConstants {
     public static final String FORMAT_D = "File Export format, can be 'txt' or 
'json'";
     public static final String TOP = "Number that defines how many top element 
you would like to see.";
     public static final String USER_D = "Filter for users (comma separated 
list)";
+    public static final String LOG_ID_D = "Id of the log component";
+    public static final String SHIPPER_CONFIG_D = "Input config json for 
logfeeder shipper";
+    public static final String TEST_ENTRY_D = "Log sample for testing";
+
   }
 
   public class AuditOperationDescriptions {
diff --git 
a/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/manager/ShipperConfigManager.java
 
b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/manager/ShipperConfigManager.java
index 5ca95e1..3c667c2 100644
--- 
a/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/manager/ShipperConfigManager.java
+++ 
b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/manager/ShipperConfigManager.java
@@ -92,17 +92,16 @@ public class ShipperConfigManager extends JsonManagerBase {
     }
   }
 
-  public Response testShipperConfig(Map<String, Object> shipperConfig, String 
logId, String testEntry, String clusterName) {
+  public Response testShipperConfig(String shipperConfig, String logId, String 
testEntry, String clusterName) {
     try {
-      String shipperConfigJsonStr = new 
ObjectMapper().writeValueAsString(shipperConfig);
-      LSServerInputConfig inputConfigValidate = new 
ObjectMapper().readValue(shipperConfigJsonStr, LSServerInputConfig.class);
+      LSServerInputConfig inputConfigValidate = new 
ObjectMapper().readValue(shipperConfig, LSServerInputConfig.class);
       Validator validator = 
Validation.buildDefaultValidatorFactory().getValidator();
       Set<ConstraintViolation<LSServerInputConfig>> violations = 
validator.validate(inputConfigValidate);
       if (!violations.isEmpty()) {
         throw new IllegalArgumentException("Error validating shipper 
config:\n" + violations);
       }
       String globalConfigs = 
logSearchConfigConfigurer.getConfig().getGlobalConfigs(clusterName);
-      LogEntryParseTester tester = new LogEntryParseTester(testEntry, 
shipperConfigJsonStr, globalConfigs, logId);
+      LogEntryParseTester tester = new LogEntryParseTester(testEntry, 
shipperConfig, globalConfigs, logId);
       Map<String, Object> resultEntrty = tester.parse();
       return Response.ok().entity(resultEntrty).build();
     } catch (Exception e) {
diff --git 
a/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/model/request/ShipperConfigTestParams.java
 
b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/model/request/ShipperConfigTestParams.java
index cb54607..28e40df 100644
--- 
a/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/model/request/ShipperConfigTestParams.java
+++ 
b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/model/request/ShipperConfigTestParams.java
@@ -21,25 +21,25 @@ package org.apache.ambari.logsearch.model.request;
 import io.swagger.annotations.ApiParam;
 import org.apache.ambari.logsearch.common.LogSearchConstants;
 
-import java.util.Map;
-
-import static 
org.apache.ambari.logsearch.doc.DocConstants.CommonDescriptions.TOP;
+import static 
org.apache.ambari.logsearch.doc.DocConstants.CommonDescriptions.LOG_ID_D;
+import static 
org.apache.ambari.logsearch.doc.DocConstants.CommonDescriptions.SHIPPER_CONFIG_D;
+import static 
org.apache.ambari.logsearch.doc.DocConstants.CommonDescriptions.TEST_ENTRY_D;
 
 public interface ShipperConfigTestParams {
 
-  Map<String, Object> getShipperConfig();
+  String getShipperConfig();
 
-  @ApiParam(value = TOP, name = 
LogSearchConstants.REQUEST_PARAM_SHIPPER_CONFIG, required = true)
-  void setShipperConfig(Map<String, Object> shipperConfig);
+  @ApiParam(value = SHIPPER_CONFIG_D, name = 
LogSearchConstants.REQUEST_PARAM_SHIPPER_CONFIG, required = true)
+  void setShipperConfig(String shipperConfig);
 
   String getLogId();
 
-  @ApiParam(value = TOP, name = LogSearchConstants.REQUEST_PARAM_LOG_ID, 
required = true)
+  @ApiParam(value = LOG_ID_D, name = LogSearchConstants.REQUEST_PARAM_LOG_ID, 
required = true)
   void setLogId(String logId);
 
   String getTestEntry();
 
-  @ApiParam(value = TOP, name = LogSearchConstants.REQUEST_PARAM_TEST_ENTRY, 
required = true)
+  @ApiParam(value = TEST_ENTRY_D, name = 
LogSearchConstants.REQUEST_PARAM_TEST_ENTRY, required = true)
   void setTestEntry(String testEntry);
 
 }
diff --git 
a/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/model/request/impl/ShipperConfigTestRequest.java
 
b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/model/request/impl/ShipperConfigTestRequest.java
index 5d37c54..0e3baee 100644
--- 
a/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/model/request/impl/ShipperConfigTestRequest.java
+++ 
b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/model/request/impl/ShipperConfigTestRequest.java
@@ -22,18 +22,25 @@ import 
org.apache.ambari.logsearch.model.request.ShipperConfigTestParams;
 import org.hibernate.validator.constraints.NotBlank;
 import org.hibernate.validator.constraints.NotEmpty;
 
-import java.util.Map;
+import javax.ws.rs.FormParam;
+
+import static 
org.apache.ambari.logsearch.common.LogSearchConstants.REQUEST_PARAM_LOG_ID;
+import static 
org.apache.ambari.logsearch.common.LogSearchConstants.REQUEST_PARAM_SHIPPER_CONFIG;
+import static 
org.apache.ambari.logsearch.common.LogSearchConstants.REQUEST_PARAM_TEST_ENTRY;
 
 public class ShipperConfigTestRequest implements ShipperConfigTestParams {
 
   @NotBlank
+  @FormParam(REQUEST_PARAM_LOG_ID)
   private String logId;
 
   @NotBlank
+  @FormParam(REQUEST_PARAM_TEST_ENTRY)
   private String testEntry;
 
   @NotEmpty
-  private Map<String, Object> shipperConfig;
+  @FormParam(REQUEST_PARAM_SHIPPER_CONFIG)
+  private String shipperConfig;
 
   @Override
   public String getLogId() {
@@ -46,12 +53,12 @@ public class ShipperConfigTestRequest implements 
ShipperConfigTestParams {
   }
 
   @Override
-  public Map<String, Object> getShipperConfig() {
+  public String getShipperConfig() {
     return shipperConfig;
   }
 
   @Override
-  public void setShipperConfig(Map<String, Object> shipperConfig) {
+  public void setShipperConfig(String shipperConfig) {
     this.shipperConfig = shipperConfig;
   }
 
diff --git 
a/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/rest/ShipperConfigResource.java
 
b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/rest/ShipperConfigResource.java
index 5cd2d3c..dbf1ae0 100644
--- 
a/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/rest/ShipperConfigResource.java
+++ 
b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/rest/ShipperConfigResource.java
@@ -23,6 +23,7 @@ import javax.inject.Inject;
 import javax.inject.Named;
 import javax.validation.Valid;
 import javax.validation.executable.ValidateOnExecution;
+import javax.ws.rs.BeanParam;
 import javax.ws.rs.GET;
 import javax.ws.rs.POST;
 import javax.ws.rs.PUT;
@@ -41,6 +42,7 @@ import 
org.apache.ambari.logsearch.model.request.impl.ShipperConfigTestRequest;
 import org.springframework.context.annotation.Scope;
 
 import java.util.List;
+import java.util.Map;
 
 import static 
org.apache.ambari.logsearch.doc.DocConstants.ShipperConfigOperationDescriptions.GET_LOG_LEVEL_FILTER_OD;
 import static 
org.apache.ambari.logsearch.doc.DocConstants.ShipperConfigOperationDescriptions.GET_SERVICE_NAMES_OD;
@@ -99,7 +101,7 @@ public class ShipperConfigResource {
   @Path("/input/{clusterName}/test")
   @Produces({"application/json"})
   @ApiOperation(TEST_SHIPPER_CONFIG_OD)
-  public Response testShipperConfig(@Valid ShipperConfigTestRequest request, 
@PathParam("clusterName") String clusterName) {
+  public Response testShipperConfig(@Valid @BeanParam ShipperConfigTestRequest 
request, @PathParam("clusterName") String clusterName) {
     return shipperConfigManager.testShipperConfig(request.getShipperConfig(), 
request.getLogId(), request.getTestEntry(), clusterName);
   }
 

-- 
To stop receiving notification emails like this one, please contact
oleew...@apache.org.

Reply via email to