Repository: ambari
Updated Branches:
  refs/heads/branch-2.5 5e7a7b603 -> dedfb547a


AMBARI-19105. Ambari LogSearch REST Layer should use a configurable timeout for 
HTTP connections to LogSearch Server. (rnettleton)


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

Branch: refs/heads/branch-2.5
Commit: dedfb547a0fa1ea91d69c92eb48f0382710059db
Parents: 5e7a7b6
Author: Bob Nettleton <[email protected]>
Authored: Thu Dec 15 18:40:12 2016 -0500
Committer: Bob Nettleton <[email protected]>
Committed: Thu Dec 15 18:40:12 2016 -0500

----------------------------------------------------------------------
 .../server/api/services/ClusterService.java     |  2 +-
 .../server/api/services/LoggingService.java     | 48 ++++++-----
 .../server/configuration/Configuration.java     | 34 ++++++++
 .../controller/AmbariManagementController.java  | 12 +++
 .../AmbariManagementControllerImpl.java         |  8 ++
 .../internal/LoggingResourceProvider.java       | 24 ------
 .../logging/LogSearchDataRetrievalService.java  | 50 +++++++++---
 .../LoggingRequestHelperFactoryImpl.java        | 30 ++++++-
 .../logging/LoggingRequestHelperImpl.java       | 78 +++++++++++-------
 .../logging/LoggingSearchPropertyProvider.java  | 33 ++++----
 .../ambari/server/controller/logging/Utils.java |  4 +-
 .../server/api/services/LoggingServiceTest.java |  3 +-
 .../LogSearchDataRetrievalServiceTest.java      | 35 ++++++--
 .../LoggingRequestHelperFactoryImplTest.java    | 82 ++++++++++++++++---
 .../logging/LoggingRequestHelperImplTest.java   | 84 ++++++++++++++++++++
 .../server/controller/logging/UtilsTest.java    | 17 ++--
 16 files changed, 412 insertions(+), 132 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/dedfb547/ambari-server/src/main/java/org/apache/ambari/server/api/services/ClusterService.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/api/services/ClusterService.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/api/services/ClusterService.java
index 072c4a2..9f6feaa 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/api/services/ClusterService.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/api/services/ClusterService.java
@@ -662,7 +662,7 @@ public class ClusterService extends BaseService {
   @Path("{clusterName}/logging")
   public LoggingService getLogging(@Context javax.ws.rs.core.Request request,
                                    @PathParam("clusterName") String 
clusterName) {
-    return new LoggingService(clusterName);
+    return AmbariServer.getController().getLoggingService(clusterName);
   }
 
   // ----- helper methods ----------------------------------------------------

http://git-wip-us.apache.org/repos/asf/ambari/blob/dedfb547/ambari-server/src/main/java/org/apache/ambari/server/api/services/LoggingService.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/api/services/LoggingService.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/api/services/LoggingService.java
index bfa6975..d83aa25 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/api/services/LoggingService.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/api/services/LoggingService.java
@@ -18,6 +18,22 @@
 
 package org.apache.ambari.server.api.services;
 
+import java.util.EnumSet;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.HttpHeaders;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.UriInfo;
+
 import org.apache.ambari.server.AmbariException;
 import org.apache.ambari.server.api.services.serializers.ResultSerializer;
 import org.apache.ambari.server.controller.AmbariManagementController;
@@ -26,7 +42,6 @@ import 
org.apache.ambari.server.controller.internal.ResourceImpl;
 import org.apache.ambari.server.controller.logging.LogQueryResponse;
 import org.apache.ambari.server.controller.logging.LoggingRequestHelper;
 import org.apache.ambari.server.controller.logging.LoggingRequestHelperFactory;
-import 
org.apache.ambari.server.controller.logging.LoggingRequestHelperFactoryImpl;
 import org.apache.ambari.server.controller.spi.Resource;
 import org.apache.ambari.server.security.authorization.AuthorizationException;
 import org.apache.ambari.server.security.authorization.AuthorizationHelper;
@@ -36,20 +51,7 @@ import org.apache.ambari.server.state.Cluster;
 import org.apache.ambari.server.utils.RetryHelper;
 import org.apache.commons.lang.StringUtils;
 
-import javax.ws.rs.GET;
-import javax.ws.rs.Path;
-import javax.ws.rs.Produces;
-import javax.ws.rs.core.Context;
-import javax.ws.rs.core.HttpHeaders;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.MultivaluedMap;
-import javax.ws.rs.core.Response;
-import javax.ws.rs.core.UriInfo;
-import java.util.EnumSet;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
+import com.google.inject.Inject;
 
 /**
  * This Service provides access to the LogSearch query services, including:
@@ -67,19 +69,19 @@ public class LoggingService extends BaseService {
 
   private final ControllerFactory controllerFactory;
 
-  private final LoggingRequestHelperFactory helperFactory;
+  @Inject
+  private LoggingRequestHelperFactory helperFactory;
 
 
   private final String clusterName;
 
   public LoggingService(String clusterName) {
-    this(clusterName, new DefaultControllerFactory(), new 
LoggingRequestHelperFactoryImpl());
+    this(clusterName, new DefaultControllerFactory());
   }
 
-  public LoggingService(String clusterName, ControllerFactory 
controllerFactory, LoggingRequestHelperFactory helperFactory) {
+  public LoggingService(String clusterName, ControllerFactory 
controllerFactory) {
     this.clusterName = clusterName;
     this.controllerFactory = controllerFactory;
-    this.helperFactory = helperFactory;
   }
 
   @GET
@@ -206,6 +208,14 @@ public class LoggingService extends BaseService {
     return responseBuilder.build();
   }
 
+  /**
+   * Package-level setter that facilitates simpler unit testing
+   *
+   * @param helperFactory
+   */
+  void setLoggingRequestHelperFactory(LoggingRequestHelperFactory 
helperFactory) {
+    this.helperFactory = helperFactory;
+  }
 
   /**
    * Internal interface that defines an access factory for the

http://git-wip-us.apache.org/repos/asf/ambari/blob/dedfb547/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java
index 7ae4353..792c369 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java
@@ -2479,6 +2479,22 @@ public class Configuration {
   public static final ConfigurationProperty<Integer> 
SRVR_API_ACCEPTOR_THREAD_COUNT = new ConfigurationProperty<>(
       "client.api.acceptor.count", null);
 
+  /**
+   * The time, in milliseconds, that the Ambari Server will wait while 
attempting to connect to the
+   * LogSearch Portal service.
+   */
+  @Markdown(description = "The time, in milliseconds, that the Ambari Server 
will wait while attempting to connect to the LogSearch Portal service.")
+  public static final ConfigurationProperty<Integer> 
LOGSEARCH_PORTAL_CONNECT_TIMEOUT = new ConfigurationProperty<>(
+          "logsearch.portal.connect.timeout", 5000);
+
+  /**
+   * The time, in milliseconds, that the Ambari Server will wait while 
attempting to read a response from the
+   * LogSearch Portal service.
+   */
+  @Markdown(description = "The time, in milliseconds, that the Ambari Server 
will wait while attempting to read a response from the LogSearch Portal 
service.")
+  public static final ConfigurationProperty<Integer> 
LOGSEARCH_PORTAL_READ_TIMEOUT = new ConfigurationProperty<>(
+    "logsearch.portal.read.timeout", 5000);
+
   private static final Logger LOG = LoggerFactory.getLogger(
     Configuration.class);
 
@@ -5113,6 +5129,24 @@ public class Configuration {
   }
 
   /**
+   * Get the connect timeout used for connecting to the LogSearch Portal 
Service
+   *
+   * @return
+   */
+  public int getLogSearchPortalConnectTimeout() {
+    return NumberUtils.toInt(getProperty(LOGSEARCH_PORTAL_CONNECT_TIMEOUT));
+  }
+
+  /**
+   * Get the read timeout used for connecting to the LogSearch Portal Service
+   *
+   * @return
+   */
+  public int getLogSearchPortalReadTimeout() {
+    return NumberUtils.toInt(getProperty(LOGSEARCH_PORTAL_READ_TIMEOUT));
+  }
+
+  /**
    * Generates a markdown table which includes:
    * <ul>
    * <li>Property key name</li>

http://git-wip-us.apache.org/repos/asf/ambari/blob/dedfb547/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementController.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementController.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementController.java
index 389f973..cc20324 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementController.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementController.java
@@ -28,6 +28,7 @@ import org.apache.ambari.server.RoleCommand;
 import org.apache.ambari.server.actionmanager.ActionManager;
 import org.apache.ambari.server.agent.ExecutionCommand;
 import org.apache.ambari.server.api.services.AmbariMetaInfo;
+import org.apache.ambari.server.api.services.LoggingService;
 import org.apache.ambari.server.controller.internal.DeleteStatusMetaData;
 import org.apache.ambari.server.controller.internal.RequestStageContainer;
 import 
org.apache.ambari.server.controller.logging.LoggingSearchPropertyProvider;
@@ -872,6 +873,17 @@ public interface AmbariManagementController {
    */
   LoggingSearchPropertyProvider getLoggingSearchPropertyProvider();
 
+
+  /**
+   * Gets the LoggingService instance from the dependency injection framework.
+   *
+   * @param clusterName the cluster name associated with this LoggingService 
instance
+   *
+   * @return an instance of LoggingService associated with the specified 
cluster.
+   */
+  LoggingService getLoggingService(String clusterName);
+
+
   /**
    * Returns KerberosHelper instance
    * @return

http://git-wip-us.apache.org/repos/asf/ambari/blob/dedfb547/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
index b19a46c..1a6c5fa 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
@@ -87,6 +87,7 @@ import org.apache.ambari.server.actionmanager.StageFactory;
 import org.apache.ambari.server.agent.ExecutionCommand;
 import org.apache.ambari.server.agent.ExecutionCommand.KeyNames;
 import org.apache.ambari.server.api.services.AmbariMetaInfo;
+import org.apache.ambari.server.api.services.LoggingService;
 import org.apache.ambari.server.configuration.Configuration;
 import org.apache.ambari.server.configuration.Configuration.DatabaseType;
 import org.apache.ambari.server.controller.internal.DeleteStatusMetaData;
@@ -5078,6 +5079,13 @@ public class AmbariManagementControllerImpl implements 
AmbariManagementControlle
     return injector.getInstance(LoggingSearchPropertyProvider.class);
   }
 
+  @Override
+  public LoggingService getLoggingService(String clusterName) {
+    LoggingService loggingService = new LoggingService(clusterName);
+    injector.injectMembers(loggingService);
+    return loggingService;
+  }
+
   /**
    * {@inheritDoc}
    */

http://git-wip-us.apache.org/repos/asf/ambari/blob/dedfb547/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/LoggingResourceProvider.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/LoggingResourceProvider.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/LoggingResourceProvider.java
index d479f89..3df3f44 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/LoggingResourceProvider.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/LoggingResourceProvider.java
@@ -38,8 +38,6 @@ import 
org.apache.ambari.server.controller.utilities.PropertyHelper;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
-import java.util.LinkedList;
-import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
@@ -115,28 +113,6 @@ public class LoggingResourceProvider extends 
AbstractControllerResourceProvider
     return Collections.singleton(resource);
   }
 
-  private static List<Map<String, String>> createTestData(Resource resource) {
-    // just create some test data for verifying basic resource code, not an 
actual result
-    Map<String, String> levelCounts = new HashMap<String, String>();
-    levelCounts.put("INFO", "100");
-    levelCounts.put("WARN", "250");
-    levelCounts.put("DEBUG", "300");
-
-    resource.setProperty("logLevels", levelCounts);
-
-    List<Map <String, String>> listOfResults = new LinkedList<Map<String, 
String>>();
-    Map<String, String> resultOne = new HashMap<String, String>();
-    resultOne.put("data", "This is a test sentence.");
-    resultOne.put("score", "100");
-    resultOne.put("level", "INFO");
-    resultOne.put("type", "hdfs_namenode");
-    resultOne.put("host", "c6401.ambari.apache.org");
-    resultOne.put("LoggerName", "NameNodeLogger");
-
-    listOfResults.add(resultOne);
-    return listOfResults;
-  }
-
   @Override
   public Set<String> checkPropertyIds(Set<String> propertyIds) {
     Set<String> unSupportedProperties =

http://git-wip-us.apache.org/repos/asf/ambari/blob/dedfb547/ambari-server/src/main/java/org/apache/ambari/server/controller/logging/LogSearchDataRetrievalService.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/controller/logging/LogSearchDataRetrievalService.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/controller/logging/LogSearchDataRetrievalService.java
index 5c0bdb1..5ae47cb 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/controller/logging/LogSearchDataRetrievalService.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/controller/logging/LogSearchDataRetrievalService.java
@@ -17,11 +17,11 @@
  */
 package org.apache.ambari.server.controller.logging;
 
-import com.google.common.cache.Cache;
-import com.google.common.cache.CacheBuilder;
-import com.google.common.collect.Sets;
-import com.google.common.util.concurrent.AbstractService;
-import com.google.inject.Inject;
+import java.util.Set;
+import java.util.concurrent.Executor;
+import java.util.concurrent.Executors;
+import java.util.concurrent.TimeUnit;
+
 import org.apache.ambari.server.AmbariService;
 import org.apache.ambari.server.controller.AmbariManagementController;
 import org.apache.ambari.server.controller.AmbariServer;
@@ -29,10 +29,13 @@ import org.apache.commons.collections.CollectionUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import java.util.Set;
-import java.util.concurrent.Executor;
-import java.util.concurrent.Executors;
-import java.util.concurrent.TimeUnit;
+
+import com.google.common.cache.Cache;
+import com.google.common.cache.CacheBuilder;
+import com.google.common.collect.Sets;
+import com.google.common.util.concurrent.AbstractService;
+import com.google.inject.Inject;
+import com.google.inject.Injector;
 
 /**
  * The {@link LogSearchDataRetrievalService} is an Ambari Service that
@@ -63,9 +66,16 @@ public class LogSearchDataRetrievalService extends 
AbstractService {
 
   private static Logger LOG = 
LoggerFactory.getLogger(LogSearchDataRetrievalService.class);
 
+  /**
+   * Factory instance used to handle URL string generation requests on the
+   *   main request thread.
+   */
   @Inject
   private LoggingRequestHelperFactory loggingRequestHelperFactory;
 
+  @Inject
+  private Injector injector;
+
   /**
    * A Cache of host+component names to a set of log files associated with
    *  that Host/Component combination.  This data is retrieved from the
@@ -200,6 +210,15 @@ public class LogSearchDataRetrievalService extends 
AbstractService {
   }
 
   /**
+   * Package-level setter to facilitate simpler unit testing
+   *
+   * @param injector
+   */
+  void setInjector(Injector injector) {
+    this.injector = injector;
+  }
+
+  /**
    * This protected method provides a way for unit-tests to insert a
    * mock executor for simpler unit-testing.
    *
@@ -219,7 +238,14 @@ public class LogSearchDataRetrievalService extends 
AbstractService {
   }
 
   private void startLogSearchFileNameRequest(String host, String component, 
String cluster) {
-    executor.execute(new LogSearchFileNameRequestRunnable(host, component, 
cluster, logFileNameCache, currentRequests));
+    // Create a separate instance of LoggingRequestHelperFactory for
+    // each task launched, since these tasks will occur on a separate thread
+    // TODO: In a future patch, this should be refactored, to either remove 
the need
+    // TODO: for the separate factory instance at the level of this class, or 
to make
+    // TODO: the LoggingRequestHelperFactory implementation thread-safe, so 
that
+    // TODO: a single factory instance can be shared across multiple threads 
safely
+    executor.execute(new LogSearchFileNameRequestRunnable(host, component, 
cluster, logFileNameCache, currentRequests,
+                                                          
injector.getInstance(LoggingRequestHelperFactory.class)));
   }
 
   private AmbariManagementController getController() {
@@ -257,8 +283,8 @@ public class LogSearchDataRetrievalService extends 
AbstractService {
 
     private AmbariManagementController controller;
 
-    LogSearchFileNameRequestRunnable(String host, String component, String 
cluster, Cache<String, Set<String>> logFileNameCache, Set<String> 
currentRequests) {
-      this(host, component, cluster, logFileNameCache, currentRequests, new 
LoggingRequestHelperFactoryImpl(), AmbariServer.getController());
+    LogSearchFileNameRequestRunnable(String host, String component, String 
cluster, Cache<String, Set<String>> logFileNameCache, Set<String> 
currentRequests, LoggingRequestHelperFactory loggingRequestHelperFactory) {
+      this(host, component, cluster, logFileNameCache, currentRequests, 
loggingRequestHelperFactory, AmbariServer.getController());
     }
 
     LogSearchFileNameRequestRunnable(String host, String component, String 
cluster, Cache<String, Set<String>> logFileNameCache, Set<String> 
currentRequests,

http://git-wip-us.apache.org/repos/asf/ambari/blob/dedfb547/ambari-server/src/main/java/org/apache/ambari/server/controller/logging/LoggingRequestHelperFactoryImpl.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/controller/logging/LoggingRequestHelperFactoryImpl.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/controller/logging/LoggingRequestHelperFactoryImpl.java
index 0fc5cd9..947f7b1 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/controller/logging/LoggingRequestHelperFactoryImpl.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/controller/logging/LoggingRequestHelperFactoryImpl.java
@@ -17,7 +17,12 @@
  */
 package org.apache.ambari.server.controller.logging;
 
+import java.util.List;
+
+import javax.inject.Inject;
+
 import org.apache.ambari.server.AmbariException;
+import org.apache.ambari.server.configuration.Configuration;
 import org.apache.ambari.server.controller.AmbariManagementController;
 import org.apache.ambari.server.state.Cluster;
 import org.apache.ambari.server.state.Clusters;
@@ -26,8 +31,6 @@ import org.apache.ambari.server.state.ServiceComponentHost;
 import org.apache.ambari.server.state.State;
 import org.apache.log4j.Logger;
 
-import java.util.List;
-
 public class LoggingRequestHelperFactoryImpl implements 
LoggingRequestHelperFactory {
 
   private static final Logger LOG = 
Logger.getLogger(LoggingRequestHelperFactoryImpl.class);
@@ -42,9 +45,17 @@ public class LoggingRequestHelperFactoryImpl implements 
LoggingRequestHelperFact
 
   private static final String LOGSEARCH_UI_PROTOCOL = "logsearch_ui_protocol";
 
+  @Inject
+  private Configuration ambariServerConfiguration;
 
   @Override
   public LoggingRequestHelper getHelper(AmbariManagementController 
ambariManagementController, String clusterName) {
+
+    if (ambariServerConfiguration == null) {
+      LOG.error("Ambari Server configuration object not available, cannot 
create request helper");
+      return null;
+    }
+
     Clusters clusters =
       ambariManagementController.getClusters();
 
@@ -90,7 +101,11 @@ public class LoggingRequestHelperFactoryImpl implements 
LoggingRequestHelperFact
         final String logSearchProtocol =
           logSearchEnvConfig.getProperties().get(LOGSEARCH_UI_PROTOCOL);
 
-        return new LoggingRequestHelperImpl(logSearchHostName, 
logSearchPortNumber, logSearchProtocol, 
ambariManagementController.getCredentialStoreService(), cluster);
+        final LoggingRequestHelperImpl loggingRequestHelper = new 
LoggingRequestHelperImpl(logSearchHostName, logSearchPortNumber, 
logSearchProtocol, ambariManagementController.getCredentialStoreService(), 
cluster);
+        // set configured timeouts for the Ambari connection to the LogSearch 
Portal service
+        
loggingRequestHelper.setLogSearchConnectTimeoutInMilliseconds(ambariServerConfiguration.getLogSearchPortalConnectTimeout());
+        
loggingRequestHelper.setLogSearchReadTimeoutInMilliseconds(ambariServerConfiguration.getLogSearchPortalReadTimeout());
+        return loggingRequestHelper;
       }
     } catch (AmbariException ambariException) {
       LOG.error("Error occurred while trying to obtain the cluster, cluster 
name = " + clusterName, ambariException);
@@ -99,4 +114,13 @@ public class LoggingRequestHelperFactoryImpl implements 
LoggingRequestHelperFact
 
     return null;
   }
+
+  /**
+   * Package-level setter to facilitate simpler unit testing
+   *
+   * @param ambariServerConfiguration the Ambari Server configuration 
properties
+   */
+  void setAmbariServerConfiguration(Configuration ambariServerConfiguration) {
+    this.ambariServerConfiguration = ambariServerConfiguration;
+  }
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/dedfb547/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 ee87cd8..0c47fc5 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
@@ -18,29 +18,6 @@
 
 package org.apache.ambari.server.controller.logging;
 
-
-import org.apache.ambari.server.AmbariException;
-import org.apache.ambari.server.configuration.ComponentSSLConfiguration;
-import org.apache.ambari.server.security.credential.Credential;
-import org.apache.ambari.server.security.credential.PrincipalKeyCredential;
-import org.apache.ambari.server.security.encryption.CredentialStoreService;
-import org.apache.ambari.server.state.Cluster;
-import org.apache.ambari.server.state.Config;
-import org.apache.commons.codec.binary.Base64;
-import org.apache.commons.lang.StringUtils;
-import org.apache.http.client.utils.URIBuilder;
-import org.apache.log4j.Logger;
-import org.codehaus.jackson.map.AnnotationIntrospector;
-import org.codehaus.jackson.map.ObjectMapper;
-import org.codehaus.jackson.map.ObjectReader;
-import org.codehaus.jackson.map.annotate.JsonSerialize;
-import org.codehaus.jackson.map.introspect.JacksonAnnotationIntrospector;
-
-import javax.net.ssl.HttpsURLConnection;
-import javax.net.ssl.KeyManager;
-import javax.net.ssl.SSLContext;
-import javax.net.ssl.SSLSocketFactory;
-import javax.net.ssl.TrustManagerFactory;
 import java.io.BufferedReader;
 import java.io.File;
 import java.io.FileInputStream;
@@ -62,13 +39,37 @@ import java.util.Map;
 import java.util.Set;
 import java.util.concurrent.atomic.AtomicInteger;
 
+import javax.net.ssl.HttpsURLConnection;
+import javax.net.ssl.KeyManager;
+import javax.net.ssl.SSLContext;
+import javax.net.ssl.SSLSocketFactory;
+import javax.net.ssl.TrustManagerFactory;
+
+import org.apache.ambari.server.AmbariException;
+import org.apache.ambari.server.configuration.ComponentSSLConfiguration;
+import org.apache.ambari.server.security.credential.Credential;
+import org.apache.ambari.server.security.credential.PrincipalKeyCredential;
+import org.apache.ambari.server.security.encryption.CredentialStoreService;
+import org.apache.ambari.server.state.Cluster;
+import org.apache.ambari.server.state.Config;
+import org.apache.commons.codec.binary.Base64;
+import org.apache.commons.lang.StringUtils;
+import org.apache.http.client.utils.URIBuilder;
+import org.codehaus.jackson.map.AnnotationIntrospector;
+import org.codehaus.jackson.map.ObjectMapper;
+import org.codehaus.jackson.map.ObjectReader;
+import org.codehaus.jackson.map.annotate.JsonSerialize;
+import org.codehaus.jackson.map.introspect.JacksonAnnotationIntrospector;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
 /**
  * Convenience class to handle the connection details of a LogSearch query 
request.
  *
  */
 public class LoggingRequestHelperImpl implements LoggingRequestHelper {
 
-  private static Logger LOG = Logger.getLogger(LoggingRequestHelperImpl.class);
+  private static Logger LOG = 
LoggerFactory.getLogger(LoggingRequestHelperImpl.class);
 
   private static final String LOGSEARCH_ADMIN_JSON_CONFIG_TYPE_NAME = 
"logsearch-admin-json";
 
@@ -114,6 +115,11 @@ public class LoggingRequestHelperImpl implements 
LoggingRequestHelper {
 
   private SSLSocketFactory sslSocketFactory;
 
+  private int logSearchConnectTimeoutInMilliseconds = 
DEFAULT_LOGSEARCH_CONNECT_TIMEOUT_IN_MILLISECONDS;
+
+  private int logSearchReadTimeoutInMilliseconds = 
DEFAULT_LOGSEARCH_READ_TIMEOUT_IN_MILLISECONDS;
+
+
   public LoggingRequestHelperImpl(String hostName, String portNumber, String 
protocol, CredentialStoreService credentialStoreService, Cluster cluster) {
     this(hostName, portNumber, protocol, credentialStoreService, cluster, new 
DefaultNetworkConnection());
   }
@@ -127,6 +133,22 @@ public class LoggingRequestHelperImpl implements 
LoggingRequestHelper {
     this.networkConnection = networkConnection;
   }
 
+  public int getLogSearchConnectTimeoutInMilliseconds() {
+    return this.logSearchConnectTimeoutInMilliseconds;
+  }
+
+  public void setLogSearchConnectTimeoutInMilliseconds(int 
logSearchConnectTimeoutInMilliseconds) {
+    this.logSearchConnectTimeoutInMilliseconds = 
logSearchConnectTimeoutInMilliseconds;
+  }
+
+  public int getLogSearchReadTimeoutInMilliseconds() {
+    return this.logSearchReadTimeoutInMilliseconds;
+  }
+
+  public void setLogSearchReadTimeoutInMilliseconds(int 
logSearchReadTimeoutInMilliseconds) {
+    this.logSearchReadTimeoutInMilliseconds = 
logSearchReadTimeoutInMilliseconds;
+  }
+
   public LogQueryResponse sendQueryRequest(Map<String, String> 
queryParameters) {
     try {
       // use the Apache builder to create the correct URI
@@ -135,10 +157,12 @@ public class LoggingRequestHelperImpl implements 
LoggingRequestHelper {
       HttpURLConnection httpURLConnection  = (HttpURLConnection) 
logSearchURI.toURL().openConnection();
       secure(httpURLConnection, protocol);
       httpURLConnection.setRequestMethod("GET");
-      
httpURLConnection.setConnectTimeout(DEFAULT_LOGSEARCH_CONNECT_TIMEOUT_IN_MILLISECONDS);
-      
httpURLConnection.setReadTimeout(DEFAULT_LOGSEARCH_READ_TIMEOUT_IN_MILLISECONDS);
+      
httpURLConnection.setConnectTimeout(logSearchConnectTimeoutInMilliseconds);
+      httpURLConnection.setReadTimeout(logSearchReadTimeoutInMilliseconds);
 
       addCookiesFromCookieStore(httpURLConnection);
+      LOG.debug("Attempting request to LogSearch Portal Server, with connect 
timeout = {} milliseconds and read timeout = {} milliseconds",
+        logSearchConnectTimeoutInMilliseconds, 
logSearchReadTimeoutInMilliseconds);
 
       setupCredentials(httpURLConnection);
 
@@ -282,7 +306,7 @@ public class LoggingRequestHelperImpl implements 
LoggingRequestHelper {
     queryParameters.put("pageSize", "1");
 
     LogQueryResponse response = sendQueryRequest(queryParameters);
-    if ((response != null) && (!response.getListOfResults().isEmpty())) {
+    if ((response != null) && (response.getListOfResults() != null) && 
(!response.getListOfResults().isEmpty())) {
       LogLineResult lineOne = response.getListOfResults().get(0);
       // this assumes that each component has only one associated log file,
       // which may not always hold true

http://git-wip-us.apache.org/repos/asf/ambari/blob/dedfb547/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 16788ed..36c485a 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
@@ -17,7 +17,15 @@
  */
 package org.apache.ambari.server.controller.logging;
 
-import com.google.inject.Inject;
+import java.util.Collections;
+import java.util.EnumSet;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.atomic.AtomicInteger;
+
 import org.apache.ambari.server.AmbariException;
 import org.apache.ambari.server.api.services.AmbariMetaInfo;
 import org.apache.ambari.server.controller.AmbariManagementController;
@@ -35,20 +43,14 @@ import org.apache.ambari.server.state.ComponentInfo;
 import org.apache.ambari.server.state.LogDefinition;
 import org.apache.ambari.server.state.StackId;
 import org.apache.commons.lang.StringUtils;
-import org.apache.log4j.Logger;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
-import java.util.Collections;
-import java.util.EnumSet;
-import java.util.HashMap;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.atomic.AtomicInteger;
+import com.google.inject.Inject;
 
 public class LoggingSearchPropertyProvider implements PropertyProvider {
 
-  private static final Logger LOG = 
Logger.getLogger(LoggingSearchPropertyProvider.class);
+  private static final Logger LOG = 
LoggerFactory.getLogger(LoggingSearchPropertyProvider.class);
 
   private static final String CLUSTERS_PATH = "/api/v1/clusters";
 
@@ -67,12 +69,9 @@ public class LoggingSearchPropertyProvider implements 
PropertyProvider {
   @Inject
   private LogSearchDataRetrievalService logSearchDataRetrievalService;
 
+  @Inject
   private LoggingRequestHelperFactory loggingRequestHelperFactory;
   
-  public LoggingSearchPropertyProvider() {
-    loggingRequestHelperFactory = new LoggingRequestHelperFactoryImpl();
-  }
-
   @Override
   public Set<Resource> populateResources(Set<Resource> resources, Request 
request, Predicate predicate) throws SystemException {
     Map<String, Boolean> isLogSearchRunning = new HashMap<>();
@@ -222,11 +221,11 @@ public class LoggingSearchPropertyProvider implements 
PropertyProvider {
     this.ambariManagementController = ambariManagementController;
   }
 
-  protected void 
setLogSearchDataRetrievalService(LogSearchDataRetrievalService 
logSearchDataRetrievalService) {
+  void setLogSearchDataRetrievalService(LogSearchDataRetrievalService 
logSearchDataRetrievalService) {
     this.logSearchDataRetrievalService = logSearchDataRetrievalService;
   }
 
-  protected void setLoggingRequestHelperFactory(LoggingRequestHelperFactory 
loggingRequestHelperFactory) {
+  void setLoggingRequestHelperFactory(LoggingRequestHelperFactory 
loggingRequestHelperFactory) {
     this.loggingRequestHelperFactory = loggingRequestHelperFactory;
   }
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/dedfb547/ambari-server/src/main/java/org/apache/ambari/server/controller/logging/Utils.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/controller/logging/Utils.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/controller/logging/Utils.java
index 2de7388..969d442 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/controller/logging/Utils.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/controller/logging/Utils.java
@@ -17,10 +17,10 @@
  */
 package org.apache.ambari.server.controller.logging;
 
-import org.apache.log4j.Logger;
-
 import java.util.concurrent.atomic.AtomicInteger;
 
+import org.slf4j.Logger;
+
 /**
  * Utility class to hold static convenience methods for
  * the LogSearch integration layer

http://git-wip-us.apache.org/repos/asf/ambari/blob/dedfb547/ambari-server/src/test/java/org/apache/ambari/server/api/services/LoggingServiceTest.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/test/java/org/apache/ambari/server/api/services/LoggingServiceTest.java
 
b/ambari-server/src/test/java/org/apache/ambari/server/api/services/LoggingServiceTest.java
index 2a1f9ac..1a7bbbd 100644
--- 
a/ambari-server/src/test/java/org/apache/ambari/server/api/services/LoggingServiceTest.java
+++ 
b/ambari-server/src/test/java/org/apache/ambari/server/api/services/LoggingServiceTest.java
@@ -123,7 +123,8 @@ public class LoggingServiceTest {
     SecurityContextHolder.getContext().setAuthentication(authentication);
 
     LoggingService loggingService =
-      new LoggingService(expectedClusterName, controllerFactoryMock, 
helperFactoryMock);
+      new LoggingService(expectedClusterName, controllerFactoryMock);
+    loggingService.setLoggingRequestHelperFactory(helperFactoryMock);
 
     Response resource = loggingService.getSearchEngine("", null, uriInfoMock);
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/dedfb547/ambari-server/src/test/java/org/apache/ambari/server/controller/logging/LogSearchDataRetrievalServiceTest.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/test/java/org/apache/ambari/server/controller/logging/LogSearchDataRetrievalServiceTest.java
 
b/ambari-server/src/test/java/org/apache/ambari/server/controller/logging/LogSearchDataRetrievalServiceTest.java
index a36ce0d..7d4f049 100644
--- 
a/ambari-server/src/test/java/org/apache/ambari/server/controller/logging/LogSearchDataRetrievalServiceTest.java
+++ 
b/ambari-server/src/test/java/org/apache/ambari/server/controller/logging/LogSearchDataRetrievalServiceTest.java
@@ -17,19 +17,33 @@
  */
 package org.apache.ambari.server.controller.logging;
 
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.expectLastCall;
+import static org.easymock.EasyMock.isA;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Collections;
+import java.util.Set;
+import java.util.concurrent.Executor;
+
+
+import org.apache.ambari.server.controller.AmbariManagementController;
+import org.easymock.EasyMockSupport;
+import org.junit.Test;
+
 import com.google.common.cache.Cache;
+import com.google.inject.Injector;
+
+
+
 import org.apache.ambari.server.controller.AmbariManagementController;
 import org.easymock.EasyMockSupport;
 import org.junit.Test;
 
-import java.util.Collections;
-import java.util.Set;
-import java.util.concurrent.Executor;
+import com.google.common.cache.Cache;
 
-import static org.easymock.EasyMock.expect;
-import static org.easymock.EasyMock.expectLastCall;
-import static org.easymock.EasyMock.isA;
-import static org.junit.Assert.*;
 
 /**
  * This test verifies the basic behavior of the
@@ -114,15 +128,21 @@ public class LogSearchDataRetrievalServiceTest {
 
     Executor executorMock = mockSupport.createMock(Executor.class);
 
+    Injector injectorMock =
+      mockSupport.createMock(Injector.class);
+
     // expect the executor to be called to execute the LogSearch request
     
executorMock.execute(isA(LogSearchDataRetrievalService.LogSearchFileNameRequestRunnable.class));
     // executor should only be called once
     expectLastCall().once();
 
+    
expect(injectorMock.getInstance(LoggingRequestHelperFactory.class)).andReturn(helperFactoryMock);
+
     mockSupport.replayAll();
 
     LogSearchDataRetrievalService retrievalService = new 
LogSearchDataRetrievalService();
     retrievalService.setLoggingRequestHelperFactory(helperFactoryMock);
+    retrievalService.setInjector(injectorMock);
     // call the initialization routine called by the Google framework
     retrievalService.doStart();
     retrievalService.setExecutor(executorMock);
@@ -134,6 +154,7 @@ public class LogSearchDataRetrievalServiceTest {
 
     assertNull("Inital query on the retrieval service should be null, since 
cache is empty by default", resultSet);
     assertEquals("Incorrect number of entries in the current request set", 1, 
retrievalService.getCurrentRequests().size());
+
     assertTrue("Incorrect HostComponent set on request set",
                 
retrievalService.getCurrentRequests().contains(expectedComponentName + "+" + 
expectedHostName));
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/dedfb547/ambari-server/src/test/java/org/apache/ambari/server/controller/logging/LoggingRequestHelperFactoryImplTest.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/test/java/org/apache/ambari/server/controller/logging/LoggingRequestHelperFactoryImplTest.java
 
b/ambari-server/src/test/java/org/apache/ambari/server/controller/logging/LoggingRequestHelperFactoryImplTest.java
index 3ca978c..1606bf2 100644
--- 
a/ambari-server/src/test/java/org/apache/ambari/server/controller/logging/LoggingRequestHelperFactoryImplTest.java
+++ 
b/ambari-server/src/test/java/org/apache/ambari/server/controller/logging/LoggingRequestHelperFactoryImplTest.java
@@ -18,6 +18,17 @@
 
 package org.apache.ambari.server.controller.logging;
 
+import static org.easymock.EasyMock.expect;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.ambari.server.configuration.Configuration;
 import org.apache.ambari.server.controller.AmbariManagementController;
 import org.apache.ambari.server.security.encryption.CredentialStoreService;
 import org.apache.ambari.server.state.Cluster;
@@ -29,15 +40,6 @@ import org.apache.ambari.server.state.State;
 import org.easymock.EasyMockSupport;
 import org.junit.Test;
 
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-
-import static org.easymock.EasyMock.expect;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-
 public class LoggingRequestHelperFactoryImplTest {
 
   @Test
@@ -45,6 +47,8 @@ public class LoggingRequestHelperFactoryImplTest {
     final String expectedClusterName = "testclusterone";
     final String expectedHostName = "c6410.ambari.apache.org";
     final String expectedPortNumber = "61889";
+    final int expectedConnectTimeout = 3000;
+    final int expectedReadTimeout = 3000;
 
     EasyMockSupport mockSupport = new EasyMockSupport();
 
@@ -66,6 +70,9 @@ public class LoggingRequestHelperFactoryImplTest {
     CredentialStoreService credentialStoreServiceMock =
       mockSupport.createMock(CredentialStoreService.class);
 
+    Configuration serverConfigMock =
+      mockSupport.createMock(Configuration.class);
+
     Map<String, String> testProperties =
       new HashMap<String, String>();
     testProperties.put("logsearch_ui_port", expectedPortNumber);
@@ -79,13 +86,17 @@ public class LoggingRequestHelperFactoryImplTest {
     
expect(logSearchEnvConfig.getProperties()).andReturn(testProperties).atLeastOnce();
     
expect(serviceComponentHostMock.getHostName()).andReturn(expectedHostName).atLeastOnce();
     
expect(serviceComponentHostMock.getState()).andReturn(State.STARTED).atLeastOnce();
-
+    
expect(serverConfigMock.getLogSearchPortalConnectTimeout()).andReturn(expectedConnectTimeout);
+    
expect(serverConfigMock.getLogSearchPortalReadTimeout()).andReturn(expectedReadTimeout);
 
     mockSupport.replayAll();
 
     LoggingRequestHelperFactory helperFactory =
       new LoggingRequestHelperFactoryImpl();
 
+    // set the configuration mock using the concrete type
+    
((LoggingRequestHelperFactoryImpl)helperFactory).setAmbariServerConfiguration(serverConfigMock);
+
     LoggingRequestHelper helper =
       helperFactory.getHelper(controllerMock, expectedClusterName);
 
@@ -95,6 +106,12 @@ public class LoggingRequestHelperFactoryImplTest {
     assertTrue("Helper created was not of the expected type",
       helper instanceof LoggingRequestHelperImpl);
 
+    assertEquals("Helper factory did not set the expected connect timeout on 
the helper instance",
+      expectedConnectTimeout, 
((LoggingRequestHelperImpl)helper).getLogSearchConnectTimeoutInMilliseconds());
+
+    assertEquals("Helper factory did not set the expected read timeout on the 
helper instance",
+      expectedReadTimeout, 
((LoggingRequestHelperImpl)helper).getLogSearchReadTimeoutInMilliseconds());
+
     mockSupport.verifyAll();
   }
 
@@ -121,6 +138,9 @@ public class LoggingRequestHelperFactoryImplTest {
     ServiceComponentHost serviceComponentHostMock =
       mockSupport.createMock(ServiceComponentHost.class);
 
+    Configuration serverConfigMock =
+      mockSupport.createMock(Configuration.class);
+
     Map<String, String> testProperties =
       new HashMap<String, String>();
     testProperties.put("logsearch_ui_port", expectedPortNumber);
@@ -141,6 +161,9 @@ public class LoggingRequestHelperFactoryImplTest {
     LoggingRequestHelperFactory helperFactory =
       new LoggingRequestHelperFactoryImpl();
 
+    // set the configuration mock using the concrete type
+    
((LoggingRequestHelperFactoryImpl)helperFactory).setAmbariServerConfiguration(serverConfigMock);
+
     LoggingRequestHelper helper =
       helperFactory.getHelper(controllerMock, expectedClusterName);
 
@@ -168,6 +191,9 @@ public class LoggingRequestHelperFactoryImplTest {
     Config logSearchEnvConfig =
       mockSupport.createMock(Config.class);
 
+    Configuration serverConfigMock =
+      mockSupport.createMock(Configuration.class);
+
     expect(controllerMock.getClusters()).andReturn(clustersMock).atLeastOnce();
     
expect(clustersMock.getCluster(expectedClusterName)).andReturn(clusterMock).atLeastOnce();
     
expect(clusterMock.getDesiredConfigByType("logsearch-env")).andReturn(logSearchEnvConfig).atLeastOnce();
@@ -179,6 +205,9 @@ public class LoggingRequestHelperFactoryImplTest {
     LoggingRequestHelperFactory helperFactory =
       new LoggingRequestHelperFactoryImpl();
 
+    // set the configuration mock using the concrete type
+    
((LoggingRequestHelperFactoryImpl)helperFactory).setAmbariServerConfiguration(serverConfigMock);
+
     LoggingRequestHelper helper =
       helperFactory.getHelper(controllerMock, expectedClusterName);
 
@@ -203,6 +232,9 @@ public class LoggingRequestHelperFactoryImplTest {
     Cluster clusterMock =
       mockSupport.createMock(Cluster.class);
 
+    Configuration serverConfigMock =
+      mockSupport.createMock(Configuration.class);
+
     expect(controllerMock.getClusters()).andReturn(clustersMock).atLeastOnce();
     
expect(clustersMock.getCluster(expectedClusterName)).andReturn(clusterMock).atLeastOnce();
     // do not include LOGSEARCH in this map, to simulate the case when 
LogSearch is not deployed
@@ -213,6 +245,36 @@ public class LoggingRequestHelperFactoryImplTest {
     LoggingRequestHelperFactory helperFactory =
       new LoggingRequestHelperFactoryImpl();
 
+    // set the configuration mock using the concrete type
+    
((LoggingRequestHelperFactoryImpl)helperFactory).setAmbariServerConfiguration(serverConfigMock);
+
+    LoggingRequestHelper helper =
+      helperFactory.getHelper(controllerMock, expectedClusterName);
+
+    assertNull("LoggingRequestHelper object returned by the factory should 
have been null",
+      helper);
+
+    mockSupport.verifyAll();
+  }
+
+  @Test
+  public void testHelperCreationWithNoAmbariServerConfiguration() throws 
Exception {
+    final String expectedClusterName = "testclusterone";
+
+    EasyMockSupport mockSupport = new EasyMockSupport();
+
+    AmbariManagementController controllerMock =
+      mockSupport.createMock(AmbariManagementController.class);
+
+    mockSupport.replayAll();
+
+    LoggingRequestHelperFactory helperFactory =
+      new LoggingRequestHelperFactoryImpl();
+
+    // set the configuration mock using the concrete type
+    // set the configuration object to null, to simulate an error in 
dependency injection
+    
((LoggingRequestHelperFactoryImpl)helperFactory).setAmbariServerConfiguration(null);
+
     LoggingRequestHelper helper =
       helperFactory.getHelper(controllerMock, expectedClusterName);
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/dedfb547/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 c3530b7..2e7020f 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
@@ -106,6 +106,9 @@ public class LoggingRequestHelperImplTest {
       
"{\"name\":\"WARN\",\"value\":\"41\"},{\"name\":\"INFO\",\"value\":\"186\"},{\"name\":\"DEBUG\",\"value\":\"0\"},"
 +
       "{\"name\":\"TRACE\",\"value\":\"0\"}]}";
 
+  private static final String TEST_JSON_INPUT_NULL_LOG_LIST =
+    
"{\"startIndex\":0,\"pageSize\":0,\"totalCount\":0,\"resultSize\":0,\"sortType\":null,\"sortBy\":null,\"queryTimeMS\":1479850014987,\"logList\":null,\"listSize\":0}";
+
 
   private final String EXPECTED_HOST_NAME = "c6401.ambari.apache.org";
 
@@ -472,6 +475,87 @@ public class LoggingRequestHelperImplTest {
     assertEquals("Response did not include the expected file name",
       "/var/log/hadoop/hdfs/hadoop-hdfs-namenode-c6401.ambari.apache.org.log",
       result.iterator().next());
+
+    mockSupport.verifyAll();
+  }
+
+  @Test
+  public void testLogFileNameRequestWithNullLogList() throws Exception {
+    final String expectedComponentName = "hdfs_namenode";
+
+    EasyMockSupport mockSupport =
+      new EasyMockSupport();
+
+    CredentialStoreService credentialStoreServiceMock =
+      mockSupport.createMock(CredentialStoreService.class);
+
+    Cluster clusterMock =
+      mockSupport.createMock(Cluster.class);
+
+    LoggingRequestHelperImpl.NetworkConnection networkConnectionMock =
+      mockSupport.createMock(LoggingRequestHelperImpl.NetworkConnection.class);
+
+    Config adminPropertiesConfigMock =
+      mockSupport.createMock(Config.class);
+
+    Map<String, String> testConfigProperties =
+      new HashMap<String, String>();
+    testConfigProperties.put("logsearch_admin_username", "admin-user");
+    testConfigProperties.put("logsearch_admin_password", "admin-pwd");
+    testConfigProperties = Collections.unmodifiableMap(testConfigProperties);
+
+    Capture<HttpURLConnection> captureURLConnection = new 
Capture<HttpURLConnection>();
+    Capture<HttpURLConnection> captureURLConnectionForAuthentication = new 
Capture<HttpURLConnection>();
+
+    
expect(clusterMock.getDesiredConfigByType("logsearch-admin-json")).andReturn(adminPropertiesConfigMock).atLeastOnce();
+    
expect(adminPropertiesConfigMock.getProperties()).andReturn(testConfigProperties).atLeastOnce();
+    
expect(networkConnectionMock.readQueryResponseFromServer(capture(captureURLConnection))).andReturn(new
 StringBuffer(TEST_JSON_INPUT_NULL_LOG_LIST)).atLeastOnce();
+
+    // expect that basic authentication is setup, with the expected encoded 
credentials
+    
networkConnectionMock.setupBasicAuthentication(capture(captureURLConnectionForAuthentication),
 eq(EXPECTED_ENCODED_CREDENTIALS));
+
+    mockSupport.replayAll();
+
+    LoggingRequestHelper helper =
+      new LoggingRequestHelperImpl(EXPECTED_HOST_NAME, EXPECTED_PORT_NUMBER, 
EXPECTED_PROTOCOL, credentialStoreServiceMock, clusterMock, 
networkConnectionMock);
+
+    // invoke query request
+    Set<String> result =
+      helper.sendGetLogFileNamesRequest(expectedComponentName, 
EXPECTED_HOST_NAME);
+
+    // verify that the HttpURLConnection was created with the propert values
+    HttpURLConnection httpURLConnection =
+      captureURLConnection.getValue();
+
+    assertEquals("URLConnection did not have the correct hostname information",
+      EXPECTED_HOST_NAME, httpURLConnection.getURL().getHost());
+    assertEquals("URLConnection did not have the correct port information",
+      EXPECTED_PORT_NUMBER, httpURLConnection.getURL().getPort() + "");
+    assertEquals("URLConnection did not have the expected http protocol 
scheme",
+      "http", httpURLConnection.getURL().getProtocol());
+    assertEquals("URLConnection did not have the expected method set",
+      "GET", httpURLConnection.getRequestMethod());
+
+    assertSame("HttpUrlConnection instances passed into NetworkConnection mock 
should have been the same instance",
+      httpURLConnection, captureURLConnectionForAuthentication.getValue());
+
+    final String resultQuery =
+      httpURLConnection.getURL().getQuery();
+
+    // verify that the query contains the three required parameters
+    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"));
+
+    assertNotNull("Response object should not be null",
+      result);
+    assertEquals("Response Set was not of the expected size, expected an empty 
set",
+      0, result.size());
+
+    mockSupport.verifyAll();
   }
 
   /**

http://git-wip-us.apache.org/repos/asf/ambari/blob/dedfb547/ambari-server/src/test/java/org/apache/ambari/server/controller/logging/UtilsTest.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/test/java/org/apache/ambari/server/controller/logging/UtilsTest.java
 
b/ambari-server/src/test/java/org/apache/ambari/server/controller/logging/UtilsTest.java
index 12267f6..60f4725 100644
--- 
a/ambari-server/src/test/java/org/apache/ambari/server/controller/logging/UtilsTest.java
+++ 
b/ambari-server/src/test/java/org/apache/ambari/server/controller/logging/UtilsTest.java
@@ -17,19 +17,18 @@
  */
 package org.apache.ambari.server.controller.logging;
 
-import org.apache.log4j.Logger;
-import org.easymock.Capture;
-import org.easymock.EasyMockSupport;
-import org.junit.Test;
-
-import java.util.concurrent.atomic.AtomicInteger;
-
 import static org.easymock.EasyMock.capture;
-import static org.easymock.EasyMock.expectLastCall;
 import static org.easymock.EasyMock.eq;
-
+import static org.easymock.EasyMock.expectLastCall;
 import static org.junit.Assert.assertSame;
 
+import java.util.concurrent.atomic.AtomicInteger;
+
+import org.easymock.Capture;
+import org.easymock.EasyMockSupport;
+import org.junit.Test;
+import org.slf4j.Logger;
+
 public class UtilsTest {
 
   @Test

Reply via email to