Repository: ambari Updated Branches: refs/heads/trunk bff239c08 -> 025b3446f
AMBARI-16129. LogSearch Integration using incorrect query parameters for LogSearch. (rnettleton) Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/025b3446 Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/025b3446 Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/025b3446 Branch: refs/heads/trunk Commit: 025b3446ffe4c3389654932e5b9b619432c25d36 Parents: bff239c Author: Bob Nettleton <rnettle...@hortonworks.com> Authored: Wed Apr 27 11:39:45 2016 -0400 Committer: Bob Nettleton <rnettle...@hortonworks.com> Committed: Wed Apr 27 11:40:14 2016 -0400 ---------------------------------------------------------------------- .../logging/LoggingRequestHelper.java | 42 +++++++++++++++++ .../logging/LoggingRequestHelperImpl.java | 34 ++++++++++++-- .../logging/LoggingSearchPropertyProvider.java | 17 +------ .../logging/LoggingRequestHelperImplTest.java | 48 ++++++++++++++++++-- .../LoggingSearchPropertyProviderTest.java | 3 +- 5 files changed, 118 insertions(+), 26 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/025b3446/ambari-server/src/main/java/org/apache/ambari/server/controller/logging/LoggingRequestHelper.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/logging/LoggingRequestHelper.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/logging/LoggingRequestHelper.java index eb45c9e..7833e01 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/controller/logging/LoggingRequestHelper.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/logging/LoggingRequestHelper.java @@ -22,10 +22,52 @@ import java.util.Set; */ public interface LoggingRequestHelper { + /** + * Sends a search query request to the LogSearch server + * + * @param queryParameters the query parameters to pass to LogSearch + * + * @return a LogQueryResponse, containing the results of the search + */ public LogQueryResponse sendQueryRequest(Map<String, String> queryParameters); + /** + * Sends a request to obtain the log file name for a given component, on + * a given host + * + * @param componentName the component name + * @param hostName the host name + * + * @return a Set of Strings that include the log file names associated + * with this component/host combination + */ public Set<String> sendGetLogFileNamesRequest(String componentName, String hostName); + /** + * Sends a request to obtain the log level counts for a given component on + * a given host + * + * @param componentName the component name + * @param hostName the host name + * + * @return a LogLevelQueryResponse, containing the log level counts for this + * component/host combination + */ public LogLevelQueryResponse sendLogLevelQueryRequest(String componentName, String hostName); + /** + * Appends the required LogSearch query parameters to a base URI + * + * @param baseURI the base URI for this request, typically the URI to the + * Ambari Integration searchEngine component + * + * @param componentName the component name + * @param hostName the host name + * + * @return a URI String that refers to the tail results of + * the log file associated with this component/host + * combination + */ + public String createLogFileTailURI(String baseURI, String componentName, String hostName); + } http://git-wip-us.apache.org/repos/asf/ambari/blob/025b3446/ambari-server/src/main/java/org/apache/ambari/server/controller/logging/LoggingRequestHelperImpl.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/logging/LoggingRequestHelperImpl.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/logging/LoggingRequestHelperImpl.java index c1afce0..d8c71e2 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/controller/logging/LoggingRequestHelperImpl.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/logging/LoggingRequestHelperImpl.java @@ -68,6 +68,14 @@ public class LoggingRequestHelperImpl implements LoggingRequestHelper { private static final String LOGSEARCH_ADMIN_CREDENTIAL_NAME = "logsearch.admin.credential"; + private static final String COMPONENT_QUERY_PARAMETER_NAME = "component_name"; + + private static final String HOST_QUERY_PARAMETER_NAME = "host_name"; + + private static final String DEFAULT_PAGE_SIZE = "50"; + + private static final String PAGE_SIZE_QUERY_PARAMETER_NAME = "pageSize"; + private static AtomicInteger errorLogCounterForLogSearchConnectionExceptions = new AtomicInteger(0); private final String hostName; @@ -180,8 +188,8 @@ public class LoggingRequestHelperImpl implements LoggingRequestHelper { // TODO, this current method will be a temporary workaround // TODO, until the new LogSearch API method is available to handle this request - queryParameters.put("host", hostName); - queryParameters.put("components_name",componentName); + queryParameters.put(HOST_QUERY_PARAMETER_NAME, hostName); + queryParameters.put(COMPONENT_QUERY_PARAMETER_NAME,componentName); // ask for page size of 1, since we really only want a single entry to // get the file path name queryParameters.put("pageSize", "1"); @@ -229,6 +237,24 @@ public class LoggingRequestHelperImpl implements LoggingRequestHelper { return null; } + /** + * Generates the log file tail URI, using the LogSearch server's + * query parameters. + * + * @param baseURI the base URI for this request, typically the URI to the + * Ambari Integration searchEngine component + * + * @param componentName the component name + * @param hostName the host name + * + * @return + */ + @Override + public String createLogFileTailURI(String baseURI, String componentName, String hostName) { + return baseURI + "?" + COMPONENT_QUERY_PARAMETER_NAME + "=" + componentName + "&" + HOST_QUERY_PARAMETER_NAME + "=" + hostName + + "&" + PAGE_SIZE_QUERY_PARAMETER_NAME + "=" + DEFAULT_PAGE_SIZE; + } + private static ObjectReader createObjectReader(Class type) { // setup the Jackson mapper/reader to read in the data structure ObjectMapper mapper = createJSONObjectMapper(); @@ -263,8 +289,8 @@ public class LoggingRequestHelperImpl implements LoggingRequestHelper { Map<String, String> queryParameters = new HashMap<String, String>(); // set the query parameters to limit this level count // request to the specific component on the specified host - queryParameters.put("host", hostName); - queryParameters.put("components_name",componentName); + queryParameters.put(HOST_QUERY_PARAMETER_NAME, hostName); + queryParameters.put(COMPONENT_QUERY_PARAMETER_NAME,componentName); // add any query strings specified for (String key : queryParameters.keySet()) { http://git-wip-us.apache.org/repos/asf/ambari/blob/025b3446/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 f80bc6d..ff7e7f5 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 @@ -46,14 +46,6 @@ public class LoggingSearchPropertyProvider implements PropertyProvider { private static final String PATH_TO_SEARCH_ENGINE = "/logging/searchEngine"; - private static final String DEFAULT_PAGE_SIZE = "50"; - - private static final String COMPONENT_QUERY_PARAMETER_NAME = "components_name"; - - private static final String HOST_QUERY_PARAMETER_NAME = "host"; - - private static final String PAGE_SIZE_QUERY_PARAMETER_NAME = "pageSize"; - private static AtomicInteger errorLogCounterForLogSearchConnectionExceptions = new AtomicInteger(0); private final LoggingRequestHelperFactory requestHelperFactory; @@ -69,8 +61,6 @@ public class LoggingSearchPropertyProvider implements PropertyProvider { this.controllerFactory = controllerFactory; } - - @Override public Set<Resource> populateResources(Set<Resource> resources, Request request, Predicate predicate) throws SystemException { @@ -113,7 +103,7 @@ public class LoggingSearchPropertyProvider implements PropertyProvider { for (String fileName : logFileNames) { // generate the URIs that can be used by clients to obtain search results/tail log results/etc final String searchEngineURI = controller.getAmbariServerURI(getFullPathToSearchEngine(clusterName)); - final String logFileTailURI = createLogFileTailURI(searchEngineURI, mappedComponentNameForLogSearch, hostName); + final String logFileTailURI = requestHelper.createLogFileTailURI(searchEngineURI, mappedComponentNameForLogSearch, hostName); // all log files are assumed to be service types for now listOfFileDefinitions.add(new LogFileDefinitionInfo(fileName, LogFileType.SERVICE, searchEngineURI, logFileTailURI)); } @@ -175,11 +165,6 @@ public class LoggingSearchPropertyProvider implements PropertyProvider { return CLUSTERS_PATH + "/" + clusterName + PATH_TO_SEARCH_ENGINE; } - protected static String createLogFileTailURI(String searchEngineURI, String componentName, String hostName) { - return searchEngineURI + "?" + COMPONENT_QUERY_PARAMETER_NAME + "=" + componentName + "&" + HOST_QUERY_PARAMETER_NAME + "=" + hostName - + "&" + PAGE_SIZE_QUERY_PARAMETER_NAME + "=" + DEFAULT_PAGE_SIZE; - } - @Override public Set<String> checkPropertyIds(Set<String> propertyIds) { return Collections.emptySet(); http://git-wip-us.apache.org/repos/asf/ambari/blob/025b3446/ambari-server/src/test/java/org/apache/ambari/server/controller/logging/LoggingRequestHelperImplTest.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/logging/LoggingRequestHelperImplTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/logging/LoggingRequestHelperImplTest.java index 0a7e8f2..b839b64 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/controller/logging/LoggingRequestHelperImplTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/logging/LoggingRequestHelperImplTest.java @@ -453,10 +453,10 @@ public class LoggingRequestHelperImplTest { httpURLConnection.getURL().getQuery(); // verify that the query contains the three required parameters - assertTrue("host parameter was not included in query", - resultQuery.contains("host=c6401.ambari.apache.org")); - assertTrue("components_name parameter was not included in the query", - resultQuery.contains("components_name=" + expectedComponentName)); + assertTrue("host_name parameter was not included in query", + resultQuery.contains("host_name=c6401.ambari.apache.org")); + assertTrue("component_name parameter was not included in the query", + resultQuery.contains("component_name=" + expectedComponentName)); assertTrue("pageSize parameter was not included in query", resultQuery.contains("pageSize=1")); @@ -654,6 +654,46 @@ public class LoggingRequestHelperImplTest { mockSupport.verifyAll(); } + @Test + public void testCreateLogFileTailURI() throws Exception { + final String expectedHostName = "c6401.ambari.apache.org"; + final String expectedPort = "61888"; + final String expectedComponentName = "hdfs_namenode"; + + final String expectedBaseURI = + "http://" + expectedHostName + ":" + expectedPort + "/api/v1/clusters/clusterone/logging/searchEngine"; + + final String expectedTailFileURI = expectedBaseURI + "?component_name=" + expectedComponentName + + "&host_name=" + expectedHostName + "&pageSize=50"; + + + EasyMockSupport mockSupport = + new EasyMockSupport(); + + CredentialStoreService credentialStoreServiceMock = + mockSupport.createMock(CredentialStoreService.class); + Cluster clusterMock = + mockSupport.createMock(Cluster.class); + LoggingRequestHelperImpl.NetworkConnection networkConnectionMock = + mockSupport.createMock(LoggingRequestHelperImpl.NetworkConnection.class); + + mockSupport.replayAll(); + + LoggingRequestHelper helper = + new LoggingRequestHelperImpl("c6401.ambari.apache.org", "61888", credentialStoreServiceMock, clusterMock, networkConnectionMock); + + String result = helper.createLogFileTailURI(expectedBaseURI, expectedComponentName, expectedHostName); + + // verify that the URI contains the expected LogSearch query parameters, + // including the correct default page size + assertEquals("LogFile Tail URI was not generated as expected", + expectedTailFileURI, + result); + + + mockSupport.verifyAll(); + } + /** * Convenience method for asserting on the values of NameValuePair instances http://git-wip-us.apache.org/repos/asf/ambari/blob/025b3446/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 0d61984..593f660 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 @@ -123,6 +123,7 @@ public class LoggingSearchPropertyProviderTest { expect(helperMock.sendGetLogFileNamesRequest(expectedLogSearchComponentName, "c6401.ambari.apache.org")).andReturn(Collections.singleton(expectedLogFilePath)); expect(helperMock.sendLogLevelQueryRequest(expectedLogSearchComponentName,"c6401.ambari.apache.org")).andReturn(levelQueryResponse).atLeastOnce(); + expect(helperMock.createLogFileTailURI(expectedAmbariURL + expectedSearchEnginePath, expectedLogSearchComponentName, "c6401.ambari.apache.org")).andReturn("").atLeastOnce(); Request requestMock = mockSupport.createMock(Request.class); @@ -208,8 +209,6 @@ public class LoggingSearchPropertyProviderTest { expectedLogFilePath, definitionInfo.getLogFileName()); assertEquals("Incorrect URL path to searchEngine", expectedAmbariURL + expectedSearchEnginePath, definitionInfo.getSearchEngineURL()); - assertEquals("Incorrect URL path to log file tail", - expectedAmbariURL + expectedSearchEnginePath + expectedTailFileQueryString, definitionInfo.getLogFileTailURL()); // verify that the log level count information