ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From oleew...@apache.org
Subject ambari git commit: AMBARI-17625. Ambari server log flooded with error messages related to LogSearch service (Miklos Gergely via oleewere)
Date Tue, 12 Jul 2016 14:20:05 GMT
Repository: ambari
Updated Branches:
  refs/heads/branch-2.4 946df6343 -> 1198657d9


AMBARI-17625. Ambari server log flooded with error messages related to LogSearch service (Miklos
Gergely via oleewere)


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/1198657d
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/1198657d
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/1198657d

Branch: refs/heads/branch-2.4
Commit: 1198657d94b7dbe3326e473af3ef7a1f41e463d5
Parents: 946df63
Author: Miklos Gergely <mgergely@hortonworks.com>
Authored: Tue Jul 12 12:05:42 2016 +0200
Committer: oleewere <oleewere@gmail.com>
Committed: Tue Jul 12 16:19:36 2016 +0200

----------------------------------------------------------------------
 .../logging/LoggingSearchPropertyProvider.java  | 71 +++++++++++---------
 .../LoggingSearchPropertyProviderTest.java      | 27 ++++++--
 2 files changed, 60 insertions(+), 38 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/1198657d/ambari-server/src/main/java/org/apache/ambari/server/controller/logging/LoggingSearchPropertyProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/logging/LoggingSearchPropertyProvider.java
b/ambari-server/src/main/java/org/apache/ambari/server/controller/logging/LoggingSearchPropertyProvider.java
index a28e04a..32690e8 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/logging/LoggingSearchPropertyProvider.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/logging/LoggingSearchPropertyProvider.java
@@ -54,7 +54,10 @@ public class LoggingSearchPropertyProvider implements PropertyProvider
{
   @Inject
   private LogSearchDataRetrievalService logSearchDataRetrievalService;
 
+  private LoggingRequestHelperFactory loggingRequestHelperFactory;
+  
   public LoggingSearchPropertyProvider() {
+    loggingRequestHelperFactory = new LoggingRequestHelperFactoryImpl();
   }
 
   @Override
@@ -66,43 +69,41 @@ public class LoggingSearchPropertyProvider implements PropertyProvider
{
       final String hostName = (String) resource.getPropertyValue(PropertyHelper.getPropertyId("HostRoles",
"host_name"));
       final String clusterName = (String) resource.getPropertyValue(PropertyHelper.getPropertyId("HostRoles",
"cluster_name"));
 
+      if (!logSearchServerRunning(clusterName)) {
+        continue;
+      }
+
       // query the stack definitions to find the correct component name (stack name mapped
to LogSearch-defined name)
       final String mappedComponentNameForLogSearch =
         getMappedComponentNameForSearch(clusterName, componentName, ambariManagementController);
 
       if (mappedComponentNameForLogSearch != null) {
-        HostComponentLoggingInfo loggingInfo =
-          new HostComponentLoggingInfo();
-
-
-        // if LogSearch service is available
-        if (logSearchDataRetrievalService != null) {
-          // send query to obtain logging metadata
-          Set<String> logFileNames =
-            logSearchDataRetrievalService.getLogFileNames(mappedComponentNameForLogSearch,
hostName, clusterName);
-
-          if ((logFileNames != null) && (!logFileNames.isEmpty())) {
-            loggingInfo.setComponentName(mappedComponentNameForLogSearch);
-            List<LogFileDefinitionInfo> listOfFileDefinitions =
-              new LinkedList<LogFileDefinitionInfo>();
-
-            for (String fileName : logFileNames) {
-              // generate the URIs that can be used by clients to obtain search results/tail
log results/etc
-              final String searchEngineURI = ambariManagementController.getAmbariServerURI(getFullPathToSearchEngine(clusterName));
-              final String logFileTailURI = logSearchDataRetrievalService.getLogFileTailURI(searchEngineURI,
mappedComponentNameForLogSearch, hostName, clusterName);
-              // all log files are assumed to be service types for now
-              listOfFileDefinitions.add(new LogFileDefinitionInfo(fileName, LogFileType.SERVICE,
searchEngineURI, logFileTailURI));
-            }
-
-            loggingInfo.setListOfLogFileDefinitions(listOfFileDefinitions);
-
-            LOG.debug("Adding logging info for component name = " + componentName + " on
host name = " + hostName);
-            // add the logging metadata for this host component
-            resource.setProperty("logging", loggingInfo);
-          } else {
-            Utils.logErrorMessageWithCounter(LOG, errorLogCounterForLogSearchConnectionExceptions,
-              "Error occurred while making request to LogSearch service, unable to populate
logging properties on this resource");
+        // send query to obtain logging metadata
+        Set<String> logFileNames =
+          logSearchDataRetrievalService.getLogFileNames(mappedComponentNameForLogSearch,
hostName, clusterName);
+
+        if ((logFileNames != null) && (!logFileNames.isEmpty())) {
+          HostComponentLoggingInfo loggingInfo = new HostComponentLoggingInfo();
+          loggingInfo.setComponentName(mappedComponentNameForLogSearch);
+          List<LogFileDefinitionInfo> listOfFileDefinitions =
+            new LinkedList<LogFileDefinitionInfo>();
+
+          for (String fileName : logFileNames) {
+            // generate the URIs that can be used by clients to obtain search results/tail
log results/etc
+            final String searchEngineURI = ambariManagementController.getAmbariServerURI(getFullPathToSearchEngine(clusterName));
+            final String logFileTailURI = logSearchDataRetrievalService.getLogFileTailURI(searchEngineURI,
mappedComponentNameForLogSearch, hostName, clusterName);
+            // all log files are assumed to be service types for now
+            listOfFileDefinitions.add(new LogFileDefinitionInfo(fileName, LogFileType.SERVICE,
searchEngineURI, logFileTailURI));
           }
+
+          loggingInfo.setListOfLogFileDefinitions(listOfFileDefinitions);
+
+          LOG.debug("Adding logging info for component name = " + componentName + " on host
name = " + hostName);
+          // add the logging metadata for this host component
+          resource.setProperty("logging", loggingInfo);
+        } else {
+          Utils.logErrorMessageWithCounter(LOG, errorLogCounterForLogSearchConnectionExceptions,
+            "Error occurred while making request to LogSearch service, unable to populate
logging properties on this resource");
         }
       }
 
@@ -111,6 +112,10 @@ public class LoggingSearchPropertyProvider implements PropertyProvider
{
     return resources;
   }
 
+  private boolean logSearchServerRunning(String clusterName) {
+    return loggingRequestHelperFactory.getHelper(ambariManagementController, clusterName)
!= null;
+  }
+
   private String getMappedComponentNameForSearch(String clusterName, String componentName,
AmbariManagementController controller) {
     try {
       AmbariMetaInfo metaInfo = controller.getAmbariMetaInfo();
@@ -159,4 +164,8 @@ public class LoggingSearchPropertyProvider implements PropertyProvider
{
     this.logSearchDataRetrievalService = logSearchDataRetrievalService;
   }
 
+  protected void setLoggingRequestHelperFactory(LoggingRequestHelperFactory loggingRequestHelperFactory)
{
+    this.loggingRequestHelperFactory = loggingRequestHelperFactory;
+  }
+
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/1198657d/ambari-server/src/test/java/org/apache/ambari/server/controller/logging/LoggingSearchPropertyProviderTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/logging/LoggingSearchPropertyProviderTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/controller/logging/LoggingSearchPropertyProviderTest.java
index 8b71b65..30b32d8 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/logging/LoggingSearchPropertyProviderTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/logging/LoggingSearchPropertyProviderTest.java
@@ -37,6 +37,7 @@ import java.util.LinkedList;
 import java.util.List;
 import java.util.Set;
 
+import static org.easymock.EasyMock.anyObject;
 import static org.easymock.EasyMock.capture;
 import static org.easymock.EasyMock.eq;
 import static org.easymock.EasyMock.expect;
@@ -81,8 +82,6 @@ public class LoggingSearchPropertyProviderTest {
 
     final String expectedAmbariURL = "http://c6401.ambari.apache.org:8080";
 
-    final String expectedTailFileQueryString = "?components_name=hdfs_namenode&host=c6401.ambari.apache.org&pageSize=50";
-
     final String expectedStackName = "HDP";
     final String expectedStackVersion = "2.4";
     final String expectedComponentName = "NAMENODE";
@@ -97,7 +96,7 @@ public class LoggingSearchPropertyProviderTest {
     expect(resourceMock.getPropertyValue(PropertyHelper.getPropertyId("HostRoles", "host_name"))).andReturn("c6401.ambari.apache.org").atLeastOnce();
     expect(resourceMock.getPropertyValue(PropertyHelper.getPropertyId("HostRoles", "cluster_name"))).andReturn("clusterone").atLeastOnce();
 
-    Capture<HostComponentLoggingInfo> captureLogInfo = new Capture<HostComponentLoggingInfo>();
+    Capture<HostComponentLoggingInfo> captureLogInfo = Capture.newInstance();
     // expect set method to be called
     resourceMock.setProperty(eq("logging"), capture(captureLogInfo));
 
@@ -144,6 +143,12 @@ public class LoggingSearchPropertyProviderTest {
     LogSearchDataRetrievalService dataRetrievalServiceMock =
       mockSupport.createMock(LogSearchDataRetrievalService.class);
 
+    LoggingRequestHelperFactory loggingRequestHelperFactoryMock =
+        mockSupport.createMock(LoggingRequestHelperFactory.class);
+    
+    LoggingRequestHelper loggingRequestHelperMock =
+        mockSupport.createMock(LoggingRequestHelper.class);
+    
     expect(dataRetrievalServiceMock.getLogFileNames(expectedLogSearchComponentName, "c6401.ambari.apache.org",
"clusterone")).andReturn(Collections.singleton(expectedLogFilePath)).atLeastOnce();
     expect(dataRetrievalServiceMock.getLogFileTailURI(expectedAmbariURL + expectedSearchEnginePath,
expectedLogSearchComponentName, "c6401.ambari.apache.org", "clusterone")).andReturn("").atLeastOnce();
 
@@ -156,6 +161,8 @@ public class LoggingSearchPropertyProviderTest {
     expect(stackIdMock.getStackName()).andReturn(expectedStackName).atLeastOnce();
     expect(stackIdMock.getStackVersion()).andReturn(expectedStackVersion).atLeastOnce();
     expect(clusterMock.getCurrentStackVersion()).andReturn(stackIdMock).atLeastOnce();
+    expect(loggingRequestHelperFactoryMock.getHelper(anyObject(AmbariManagementController.class),
anyObject(String.class)))
+        .andReturn(loggingRequestHelperMock).atLeastOnce();
 
     expect(metaInfoMock.getComponentToService(expectedStackName, expectedStackVersion, expectedComponentName)).andReturn(expectedServiceName).atLeastOnce();
     expect(metaInfoMock.getComponent(expectedStackName, expectedStackVersion, expectedServiceName,
expectedComponentName)).andReturn(componentInfoMock).atLeastOnce();
@@ -170,7 +177,7 @@ public class LoggingSearchPropertyProviderTest {
 
     propertyProvider.setAmbariManagementController(controllerMock);
     propertyProvider.setLogSearchDataRetrievalService(dataRetrievalServiceMock);
-
+    propertyProvider.setLoggingRequestHelperFactory(loggingRequestHelperFactoryMock);
 
     Set<Resource> returnedResources =
       propertyProvider.populateResources(Collections.singleton(resourceMock), requestMock,
predicateMock);
@@ -234,9 +241,6 @@ public class LoggingSearchPropertyProviderTest {
     expect(resourceMock.getPropertyValue(PropertyHelper.getPropertyId("HostRoles", "host_name"))).andReturn("c6401.ambari.apache.org").atLeastOnce();
     expect(resourceMock.getPropertyValue(PropertyHelper.getPropertyId("HostRoles", "cluster_name"))).andReturn("clusterone").atLeastOnce();
 
-    LoggingRequestHelperFactory helperFactoryMock =
-      mockSupport.createMock(LoggingRequestHelperFactory.class);
-
     Request requestMock =
       mockSupport.createMock(Request.class);
 
@@ -267,12 +271,20 @@ public class LoggingSearchPropertyProviderTest {
     LogSearchDataRetrievalService dataRetrievalServiceMock =
       mockSupport.createMock(LogSearchDataRetrievalService.class);
 
+    LoggingRequestHelperFactory loggingRequestHelperFactoryMock =
+        mockSupport.createMock(LoggingRequestHelperFactory.class);
+
+    LoggingRequestHelper loggingRequestHelperMock =
+        mockSupport.createMock(LoggingRequestHelper.class);
+
     expect(controllerMock.getAmbariMetaInfo()).andReturn(metaInfoMock).atLeastOnce();
     expect(controllerMock.getClusters()).andReturn(clustersMock).atLeastOnce();
     expect(clustersMock.getCluster("clusterone")).andReturn(clusterMock).atLeastOnce();
     expect(stackIdMock.getStackName()).andReturn(expectedStackName).atLeastOnce();
     expect(stackIdMock.getStackVersion()).andReturn(expectedStackVersion).atLeastOnce();
     expect(clusterMock.getCurrentStackVersion()).andReturn(stackIdMock).atLeastOnce();
+    expect(loggingRequestHelperFactoryMock.getHelper(anyObject(AmbariManagementController.class),
anyObject(String.class)))
+        .andReturn(loggingRequestHelperMock).atLeastOnce();
 
     expect(metaInfoMock.getComponentToService(expectedStackName, expectedStackVersion, expectedComponentName)).andReturn(expectedServiceName).atLeastOnce();
     expect(metaInfoMock.getComponent(expectedStackName, expectedStackVersion, expectedServiceName,
expectedComponentName)).andReturn(componentInfoMock).atLeastOnce();
@@ -292,6 +304,7 @@ public class LoggingSearchPropertyProviderTest {
 
     propertyProvider.setAmbariManagementController(controllerMock);
     propertyProvider.setLogSearchDataRetrievalService(dataRetrievalServiceMock);
+    propertyProvider.setLoggingRequestHelperFactory(loggingRequestHelperFactoryMock);
 
 
     // execute the populate resources method, verify that no exceptions occur, due to


Mime
View raw message