You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by jo...@apache.org on 2017/07/27 12:58:55 UTC

[1/6] ambari git commit: AMBARI-21561. NameNode Last Checkpoint alert: global name PERCENT_WARNING is not defined

Repository: ambari
Updated Branches:
  refs/heads/branch-2.6 ab05c5fec -> 41a1bc81b


AMBARI-21561. NameNode Last Checkpoint alert: global name PERCENT_WARNING is not defined


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

Branch: refs/heads/branch-2.6
Commit: 7fb0436969bff73bc5777d7ea28b3c4141a561f9
Parents: ab05c5f
Author: Attila Doroszlai <ad...@hortonworks.com>
Authored: Mon Jul 24 14:48:01 2017 +0200
Committer: Attila Doroszlai <ad...@hortonworks.com>
Committed: Wed Jul 26 08:41:12 2017 +0200

----------------------------------------------------------------------
 .../4.2/services/HDFS/package/alerts/alert_checkpoint_time.py      | 2 --
 1 file changed, 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/7fb04369/ambari-server/src/main/resources/stacks/BigInsights/4.2/services/HDFS/package/alerts/alert_checkpoint_time.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/stacks/BigInsights/4.2/services/HDFS/package/alerts/alert_checkpoint_time.py b/ambari-server/src/main/resources/stacks/BigInsights/4.2/services/HDFS/package/alerts/alert_checkpoint_time.py
index 2a29d1a..ef389cd 100755
--- a/ambari-server/src/main/resources/stacks/BigInsights/4.2/services/HDFS/package/alerts/alert_checkpoint_time.py
+++ b/ambari-server/src/main/resources/stacks/BigInsights/4.2/services/HDFS/package/alerts/alert_checkpoint_time.py
@@ -82,8 +82,6 @@ def execute(configurations={}, parameters={}, host_name=None):
   http_uri = None
   https_uri = None
   http_policy = 'HTTP_ONLY'
-  percent_warning = PERCENT_WARNING
-  percent_critical = PERCENT_CRITICAL
   checkpoint_tx = CHECKPOINT_TX_DEFAULT
   checkpoint_period = CHECKPOINT_PERIOD_DEFAULT
   


[5/6] ambari git commit: AMBARI-21583. Hive server configurations not applied to all the nodes for HS2 HA deployment. (swagle)

Posted by jo...@apache.org.
AMBARI-21583. Hive server configurations not applied to all the nodes for HS2 HA deployment. (swagle)


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

Branch: refs/heads/branch-2.6
Commit: fd8f801b1820f3fd0b2887322bec97c828118c9a
Parents: 84317d9
Author: Siddharth Wagle <sw...@hortonworks.com>
Authored: Wed Jul 26 15:42:10 2017 -0700
Committer: Siddharth Wagle <sw...@hortonworks.com>
Committed: Wed Jul 26 15:43:21 2017 -0700

----------------------------------------------------------------------
 .../HIVE/0.12.0.2.0/package/scripts/params_linux.py                | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/fd8f801b/ambari-server/src/main/resources/common-services/HIVE/0.12.0.2.0/package/scripts/params_linux.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/common-services/HIVE/0.12.0.2.0/package/scripts/params_linux.py b/ambari-server/src/main/resources/common-services/HIVE/0.12.0.2.0/package/scripts/params_linux.py
index b2bc34a..65ba140 100644
--- a/ambari-server/src/main/resources/common-services/HIVE/0.12.0.2.0/package/scripts/params_linux.py
+++ b/ambari-server/src/main/resources/common-services/HIVE/0.12.0.2.0/package/scripts/params_linux.py
@@ -399,7 +399,7 @@ hive_conf_dirs_list = [hive_client_conf_dir]
 ranger_hive_component = status_params.SERVER_ROLE_DIRECTORY_MAP['HIVE_SERVER']
 if status_params.role == "HIVE_METASTORE" and hive_metastore_hosts is not None and hostname in hive_metastore_hosts:
   hive_conf_dirs_list.append(hive_server_conf_dir)
-elif status_params.role == "HIVE_SERVER" and hive_server_hosts is not None and hostname in hive_server_host:
+elif status_params.role == "HIVE_SERVER" and hive_server_hosts is not None and hostname in hive_server_hosts:
   hive_conf_dirs_list.append(hive_server_conf_dir)
 elif status_params.role == "HIVE_SERVER_INTERACTIVE" and hive_server_interactive_hosts is not None and hostname in hive_server_interactive_hosts:
   hive_conf_dirs_list.append(status_params.hive_server_interactive_conf_dir)


[2/6] ambari git commit: AMBARI-21571 Making changes to a config group is forcing updates to other values which customer do not intend to change. (atkach)

Posted by jo...@apache.org.
AMBARI-21571 Making changes to a config group is forcing updates to other values which customer do not intend to change. (atkach)


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

Branch: refs/heads/branch-2.6
Commit: 7756f98d2f7997dc0ff968ffbe4032d7c2ee9e8a
Parents: 7fb0436
Author: Andrii Tkach <at...@apache.org>
Authored: Tue Jul 25 16:15:47 2017 +0300
Committer: Andrii Tkach <at...@apache.org>
Committed: Wed Jul 26 12:14:47 2017 +0300

----------------------------------------------------------------------
 .../mixins/common/configs/enhanced_configs.js   | 23 ++++++++--
 .../common/configs/enhanced_configs_test.js     | 44 ++++++++++++++++++++
 2 files changed, 64 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/7756f98d/ambari-web/app/mixins/common/configs/enhanced_configs.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/mixins/common/configs/enhanced_configs.js b/ambari-web/app/mixins/common/configs/enhanced_configs.js
index e86fb59..5668b8c 100644
--- a/ambari-web/app/mixins/common/configs/enhanced_configs.js
+++ b/ambari-web/app/mixins/common/configs/enhanced_configs.js
@@ -392,10 +392,10 @@ App.EnhancedConfigsMixin = Em.Mixin.create(App.ConfigWithOverrideRecommendationP
     var self = this;
     var recommendations = event ? this.get('changedProperties') : this.get('recommendations'),
       recommendedChanges = recommendations.filterProperty('isEditable'),
-      requiredChanges = recommendations.filterProperty('isEditable', false);
-    if (recommendations.length > 0) {
+      requiredChanges = this.filterRequiredChanges(recommendations);
+    if (recommendedChanges.length > 0 || requiredChanges.length > 0) {
       App.showDependentConfigsPopup(recommendedChanges, requiredChanges, function() {
-        self.onSaveRecommendedPopup(recommendations);
+        self.onSaveRecommendedPopup(recommendedChanges.concat(requiredChanges));
         if (callback) callback();
       }, secondary);
     } else {
@@ -404,6 +404,23 @@ App.EnhancedConfigsMixin = Em.Mixin.create(App.ConfigWithOverrideRecommendationP
   },
 
   /**
+   *
+   * @param {Array} recommendations
+   * @returns {Array}
+   */
+  filterRequiredChanges: function(recommendations) {
+    return recommendations.filter(function(recommendation) {
+      if (recommendation.isEditable === false) {
+        if (!this.get('selectedConfigGroup.isDefault')) {
+          return App.ServiceConfigGroup.defaultGroupName !== recommendation.configGroup
+        } else {
+          return true;
+        }
+      }
+    }, this);
+  },
+
+  /**
    * update configs when toggle checkbox on dependent configs popup
    */
   onSaveRecommendedPopup: function(recommendations) {

http://git-wip-us.apache.org/repos/asf/ambari/blob/7756f98d/ambari-web/test/mixins/common/configs/enhanced_configs_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/mixins/common/configs/enhanced_configs_test.js b/ambari-web/test/mixins/common/configs/enhanced_configs_test.js
index 880f4d2..3a41dc9 100644
--- a/ambari-web/test/mixins/common/configs/enhanced_configs_test.js
+++ b/ambari-web/test/mixins/common/configs/enhanced_configs_test.js
@@ -263,5 +263,49 @@ describe('App.EnhancedConfigsMixin', function() {
       )).to.be.true;
     });
   });
+
+  describe('#filterRequiredChanges', function() {
+
+    it('all recommendations editable', function() {
+      var recommendations = [
+        {
+          isEditable: true
+        }
+      ];
+      expect(instanceObject.filterRequiredChanges(recommendations)).to.be.empty;
+    });
+
+    it('recommendations not editable when editing default config group', function() {
+      instanceObject.set('selectedConfigGroup', Em.Object.create({isDefault: true}));
+      var recommendations = [
+        {
+          isEditable: false
+        }
+      ];
+      expect(instanceObject.filterRequiredChanges(recommendations)).to.be.eql(recommendations);
+    });
+
+    it('recommendations not editable when editing non-default config group for default group', function() {
+      instanceObject.set('selectedConfigGroup', Em.Object.create({isDefault: false}));
+      var recommendations = [
+        {
+          isEditable: false,
+          configGroup: App.ServiceConfigGroup.defaultGroupName
+        }
+      ];
+      expect(instanceObject.filterRequiredChanges(recommendations)).to.be.empty;
+    });
+
+    it('recommendations not editable when editing non-default config group for non-default group', function() {
+      instanceObject.set('selectedConfigGroup', Em.Object.create({isDefault: false}));
+      var recommendations = [
+        {
+          isEditable: false,
+          configGroup: 'g1'
+        }
+      ];
+      expect(instanceObject.filterRequiredChanges(recommendations)).to.be.eql(recommendations);
+    });
+  });
 });
 


[3/6] ambari git commit: AMBARI-21576. Livy2 server startup failure if webhdfs not enabled (Ferenc Schneider via adoroszlai)

Posted by jo...@apache.org.
AMBARI-21576. Livy2 server startup failure if webhdfs not enabled (Ferenc Schneider via adoroszlai)


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

Branch: refs/heads/branch-2.6
Commit: 187c9151146bf0368c379e073ad63b093113d61b
Parents: 7756f98
Author: Ferenc Schneider <fs...@hortonworks.com>
Authored: Wed Jul 26 18:58:19 2017 +0200
Committer: Attila Doroszlai <ad...@hortonworks.com>
Committed: Wed Jul 26 18:58:19 2017 +0200

----------------------------------------------------------------------
 .../common-services/SPARK2/2.0.0/package/scripts/livy2_server.py   | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/187c9151/ambari-server/src/main/resources/common-services/SPARK2/2.0.0/package/scripts/livy2_server.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/common-services/SPARK2/2.0.0/package/scripts/livy2_server.py b/ambari-server/src/main/resources/common-services/SPARK2/2.0.0/package/scripts/livy2_server.py
index cb4f5ee..50b9cf1 100644
--- a/ambari-server/src/main/resources/common-services/SPARK2/2.0.0/package/scripts/livy2_server.py
+++ b/ambari-server/src/main/resources/common-services/SPARK2/2.0.0/package/scripts/livy2_server.py
@@ -117,7 +117,7 @@ class LivyServer(Script):
         dir_exists = ('FileStatus' in list_status)
       else:
         # have to do time expensive hdfs dfs -d check.
-        dfs_ret_code = shell.call(format("hdfs --config {hadoop_conf_dir} dfs -test -d " + dir_path), user=params.livy_user)[0]
+        dfs_ret_code = shell.call(format("hdfs --config {hadoop_conf_dir} dfs -test -d " + dir_path), user=params.livy2_user)[0]
         dir_exists = not dfs_ret_code #dfs -test -d returns 0 in case the dir exists
 
       if not dir_exists:


[4/6] ambari git commit: AMBARI-21582 - Stack Tools and Feature Should be Ignored in Blueprints (jonathanhurley)

Posted by jo...@apache.org.
AMBARI-21582 - Stack Tools and Feature Should be Ignored in Blueprints (jonathanhurley)


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

Branch: refs/heads/branch-2.6
Commit: 84317d92c989d17ae9bc179d859cf53a244ce78b
Parents: 187c915
Author: Jonathan Hurley <jh...@hortonworks.com>
Authored: Wed Jul 26 16:29:47 2017 -0400
Committer: Jonathan Hurley <jh...@hortonworks.com>
Committed: Wed Jul 26 16:35:54 2017 -0400

----------------------------------------------------------------------
 .../controller/internal/BlueprintConfigurationProcessor.java      | 2 +-
 .../controller/internal/BlueprintConfigurationProcessorTest.java  | 3 +++
 2 files changed, 4 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/84317d92/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/BlueprintConfigurationProcessor.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/BlueprintConfigurationProcessor.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/BlueprintConfigurationProcessor.java
index 50cea9e..b0a605b 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/BlueprintConfigurationProcessor.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/BlueprintConfigurationProcessor.java
@@ -2960,7 +2960,7 @@ public class BlueprintConfigurationProcessor {
       Map<String,String> clusterEnvDefaultProperties = defaultStackProperties.get(CLUSTER_ENV_CONFIG_TYPE_NAME);
 
       for( String property : properties ){
-        if (defaultStackProperties.containsKey(property)) {
+        if (clusterEnvDefaultProperties.containsKey(property)) {
           configuration.setProperty(CLUSTER_ENV_CONFIG_TYPE_NAME, property,
               clusterEnvDefaultProperties.get(property));
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/84317d92/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/BlueprintConfigurationProcessorTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/BlueprintConfigurationProcessorTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/BlueprintConfigurationProcessorTest.java
index 3562c96..c5af0d9 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/BlueprintConfigurationProcessorTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/BlueprintConfigurationProcessorTest.java
@@ -87,6 +87,7 @@ public class BlueprintConfigurationProcessorTest extends EasyMockSupport {
   private static final Configuration EMPTY_CONFIG = new Configuration(Collections.<String, Map<String, String>>emptyMap(), Collections.<String, Map<String, Map<String, String>>>emptyMap());
   private final Map<String, Collection<String>> serviceComponents = new HashMap<>();
   private final Map<String, Map<String, String>> stackProperties = new HashMap<>();
+  private final Map<String, String> defaultClusterEnvProperties = new HashMap<>();
 
   private final String STACK_NAME = "testStack";
   private final String STACK_VERSION = "1";
@@ -212,6 +213,8 @@ public class BlueprintConfigurationProcessorTest extends EasyMockSupport {
     expect(ambariContext.getConfigHelper()).andReturn(configHelper).anyTimes();
     expect(configHelper.getDefaultStackProperties(
         EasyMock.eq(new StackId(STACK_NAME, STACK_VERSION)))).andReturn(stackProperties).anyTimes();
+
+    stackProperties.put(ConfigHelper.CLUSTER_ENV, defaultClusterEnvProperties);
   }
 
   @After


[6/6] ambari git commit: AMBARI-21578. testBadCredential UT fails (rlevas)

Posted by jo...@apache.org.
AMBARI-21578. testBadCredential UT fails (rlevas)


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

Branch: refs/heads/branch-2.6
Commit: 41a1bc81b7e05be9d3293cd7cab3076579bcad5c
Parents: fd8f801
Author: Robert Levas <rl...@hortonworks.com>
Authored: Thu Jul 27 07:29:35 2017 -0400
Committer: Robert Levas <rl...@hortonworks.com>
Committed: Thu Jul 27 07:29:35 2017 -0400

----------------------------------------------------------------------
 ambari-server/pom.xml                           |   2 +-
 .../pam/PamAuthenticationFactory.java           |  35 +++++
 .../AmbariPamAuthenticationProvider.java        |   5 +-
 .../AmbariPamAuthenticationProviderTest.java    | 147 +++++++++++--------
 4 files changed, 123 insertions(+), 66 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/41a1bc81/ambari-server/pom.xml
----------------------------------------------------------------------
diff --git a/ambari-server/pom.xml b/ambari-server/pom.xml
index b3e1e9f..3ff8218 100644
--- a/ambari-server/pom.xml
+++ b/ambari-server/pom.xml
@@ -1520,7 +1520,7 @@
     <dependency>
       <groupId>net.java.dev.jna</groupId>
       <artifactId>jna</artifactId>
-      <version>4.3.0</version>
+      <version>4.2.2</version>
     </dependency>
     <dependency>
       <groupId>io.dropwizard.metrics</groupId>

http://git-wip-us.apache.org/repos/asf/ambari/blob/41a1bc81/ambari-server/src/main/java/org/apache/ambari/server/security/authentication/pam/PamAuthenticationFactory.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/security/authentication/pam/PamAuthenticationFactory.java b/ambari-server/src/main/java/org/apache/ambari/server/security/authentication/pam/PamAuthenticationFactory.java
new file mode 100644
index 0000000..6f423c1
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/security/authentication/pam/PamAuthenticationFactory.java
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ambari.server.security.authentication.pam;
+
+import javax.inject.Singleton;
+
+import org.jvnet.libpam.PAM;
+import org.jvnet.libpam.PAMException;
+
+/**
+ * PamAuthenticationFactory returns Pam library instances.
+ */
+@Singleton
+public class PamAuthenticationFactory {
+
+  public PAM createInstance(String pamConfig) throws PAMException {
+    return new PAM(pamConfig);
+  }
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/41a1bc81/ambari-server/src/main/java/org/apache/ambari/server/security/authorization/AmbariPamAuthenticationProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/security/authorization/AmbariPamAuthenticationProvider.java b/ambari-server/src/main/java/org/apache/ambari/server/security/authorization/AmbariPamAuthenticationProvider.java
index 1626cd8..18bb510 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/security/authorization/AmbariPamAuthenticationProvider.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/security/authorization/AmbariPamAuthenticationProvider.java
@@ -29,6 +29,7 @@ import org.apache.ambari.server.orm.entities.GroupEntity;
 import org.apache.ambari.server.orm.entities.MemberEntity;
 import org.apache.ambari.server.orm.entities.UserEntity;
 import org.apache.ambari.server.security.ClientSecurityType;
+import org.apache.ambari.server.security.authentication.pam.PamAuthenticationFactory;
 import org.jvnet.libpam.PAM;
 import org.jvnet.libpam.PAMException;
 import org.jvnet.libpam.UnixUser;
@@ -54,6 +55,8 @@ public class AmbariPamAuthenticationProvider implements AuthenticationProvider {
   protected UserDAO userDAO;
   @Inject
   protected GroupDAO groupDAO;
+  @Inject
+  private PamAuthenticationFactory pamAuthenticationFactory;
 
   private static Logger LOG = LoggerFactory.getLogger(AmbariPamAuthenticationProvider.class);
 
@@ -85,7 +88,7 @@ public class AmbariPamAuthenticationProvider implements AuthenticationProvider {
         try{
           //Set PAM configuration file (found under /etc/pam.d)
           String pamConfig = configuration.getPamConfigurationFile();
-          pam = new PAM(pamConfig);
+          pam = pamAuthenticationFactory.createInstance(pamConfig);
 
         } catch(PAMException ex) {
           LOG.error("Unable to Initialize PAM." + ex.getMessage());

http://git-wip-us.apache.org/repos/asf/ambari/blob/41a1bc81/ambari-server/src/test/java/org/apache/ambari/server/security/authorization/AmbariPamAuthenticationProviderTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/security/authorization/AmbariPamAuthenticationProviderTest.java b/ambari-server/src/test/java/org/apache/ambari/server/security/authorization/AmbariPamAuthenticationProviderTest.java
index 59a0c7a..9cfd148 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/security/authorization/AmbariPamAuthenticationProviderTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/security/authorization/AmbariPamAuthenticationProviderTest.java
@@ -1,4 +1,4 @@
-/**
+/*
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
  * distributed with this work for additional information
@@ -17,91 +17,120 @@
  */
 package org.apache.ambari.server.security.authorization;
 
-import static org.easymock.EasyMock.createNiceMock;
+import static org.easymock.EasyMock.anyObject;
+import static org.easymock.EasyMock.eq;
 import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.expectLastCall;
 
-import java.util.Arrays;
-import java.util.Collection;
 import java.util.Collections;
-import java.util.HashSet;
 
-import org.apache.ambari.server.H2DatabaseCleaner;
-import org.apache.ambari.server.audit.AuditLoggerModule;
+import javax.persistence.EntityManager;
+
 import org.apache.ambari.server.configuration.Configuration;
-import org.apache.ambari.server.orm.GuiceJpaInitializer;
+import org.apache.ambari.server.hooks.HookContextFactory;
+import org.apache.ambari.server.hooks.HookService;
+import org.apache.ambari.server.orm.DBAccessor;
 import org.apache.ambari.server.orm.dao.UserDAO;
-import org.apache.ambari.server.orm.entities.PrincipalEntity;
-import org.apache.ambari.server.orm.entities.UserEntity;
 import org.apache.ambari.server.security.ClientSecurityType;
-import org.easymock.EasyMock;
-import org.junit.After;
+import org.apache.ambari.server.security.authentication.pam.PamAuthenticationFactory;
+import org.apache.ambari.server.state.stack.OsFamily;
+import org.easymock.EasyMockSupport;
 import org.junit.Before;
 import org.junit.Test;
 import org.jvnet.libpam.PAM;
+import org.jvnet.libpam.PAMException;
 import org.jvnet.libpam.UnixUser;
+import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
 import org.springframework.security.core.Authentication;
 import org.springframework.security.core.AuthenticationException;
 import org.springframework.security.crypto.password.PasswordEncoder;
+import org.springframework.security.crypto.password.StandardPasswordEncoder;
 
+import com.google.inject.AbstractModule;
 import com.google.inject.Guice;
-import com.google.inject.Inject;
 import com.google.inject.Injector;
 
 import junit.framework.Assert;
 
-public class AmbariPamAuthenticationProviderTest {
-
-  private static Injector injector;
-
-  @Inject
-  private AmbariPamAuthenticationProvider authenticationProvider;
-  @Inject
-  PasswordEncoder passwordEncoder;
-  @Inject
-  Configuration configuration;
+public class AmbariPamAuthenticationProviderTest extends EasyMockSupport {
 
   private static final String TEST_USER_NAME = "userName";
   private static final String TEST_USER_PASS = "userPass";
   private static final String TEST_USER_INCORRECT_PASS = "userIncorrectPass";
 
+  private Injector injector;
+
   @Before
-  public void setUp() {
-    injector = Guice.createInjector(new AuditLoggerModule(), new AuthorizationTestModule());
-    injector.injectMembers(this);
-    injector.getInstance(GuiceJpaInitializer.class);
+  public void setup() {
+    injector = Guice.createInjector(new AbstractModule() {
+
+      @Override
+      protected void configure() {
+        bind(EntityManager.class).toInstance(createNiceMock(EntityManager.class));
+        bind(DBAccessor.class).toInstance(createNiceMock(DBAccessor.class));
+        bind(HookContextFactory.class).toInstance(createNiceMock(HookContextFactory.class));
+        bind(HookService.class).toInstance(createNiceMock(HookService.class));
+        bind(OsFamily.class).toInstance(createNiceMock(OsFamily.class));
+        bind(UserDAO.class).toInstance(createNiceMock(UserDAO.class));
+        bind(PamAuthenticationFactory.class).toInstance(createMock(PamAuthenticationFactory.class));
+        bind(PasswordEncoder.class).toInstance(new StandardPasswordEncoder());
+      }
+    });
+
+    Configuration configuration = injector.getInstance(Configuration.class);
     configuration.setClientSecurityType(ClientSecurityType.PAM);
     configuration.setProperty(Configuration.PAM_CONFIGURATION_FILE, "ambari-pam");
   }
 
-  @After
-  public void tearDown() throws Exception {
-    H2DatabaseCleaner.clearDatabaseAndStopPersistenceService(injector);
-  }
-
   @Test(expected = AuthenticationException.class)
   public void testBadCredential() throws Exception {
-    UserEntity userEntity = combineUserEntity();
-    User user = new User(userEntity);
-    Collection<AmbariGrantedAuthority> userAuthorities = Collections.singletonList(createNiceMock(AmbariGrantedAuthority.class));
-    Authentication authentication = new AmbariUserAuthentication("wrong", user, userAuthorities);
+
+    PAM pam = createMock(PAM.class);
+    expect(pam.authenticate(eq(TEST_USER_NAME), eq(TEST_USER_INCORRECT_PASS)))
+        .andThrow(new PAMException())
+        .once();
+    pam.dispose();
+    expectLastCall().once();
+
+    PamAuthenticationFactory pamAuthenticationFactory = injector.getInstance(PamAuthenticationFactory.class);
+    expect(pamAuthenticationFactory.createInstance(anyObject(String.class))).andReturn(pam).once();
+
+    replayAll();
+
+    Authentication authentication = new UsernamePasswordAuthenticationToken(TEST_USER_NAME, TEST_USER_INCORRECT_PASS);
+
+    AmbariPamAuthenticationProvider authenticationProvider = injector.getInstance(AmbariPamAuthenticationProvider.class);
     authenticationProvider.authenticate(authentication);
+
+    verifyAll();
   }
 
   @Test
   public void testAuthenticate() throws Exception {
-    PAM pam = createNiceMock(PAM.class);
+
     UnixUser unixUser = createNiceMock(UnixUser.class);
-    UserEntity userEntity = combineUserEntity();
-    User user = new User(userEntity);
-    UserDAO userDAO = createNiceMock(UserDAO.class);
-    Collection<AmbariGrantedAuthority> userAuthorities = Collections.singletonList(createNiceMock(AmbariGrantedAuthority.class));
-    expect(pam.authenticate(EasyMock.anyObject(String.class), EasyMock.anyObject(String.class))).andReturn(unixUser).atLeastOnce();
-    expect(unixUser.getGroups()).andReturn(new HashSet<String>(Arrays.asList("group"))).atLeastOnce();
-    EasyMock.replay(unixUser);
-    EasyMock.replay(pam);
-    Authentication authentication = new AmbariUserAuthentication("userPass", user, userAuthorities);
-    Authentication result = authenticationProvider.authenticateViaPam(pam,authentication);
-    expect(userDAO.findUserByName("userName")).andReturn(null).once();
+    expect(unixUser.getGroups()).andReturn(Collections.singleton("group")).atLeastOnce();
+
+    PAM pam = createMock(PAM.class);
+    expect(pam.authenticate(eq(TEST_USER_NAME), eq(TEST_USER_PASS)))
+        .andReturn(unixUser)
+        .once();
+    pam.dispose();
+    expectLastCall().once();
+
+    PamAuthenticationFactory pamAuthenticationFactory = injector.getInstance(PamAuthenticationFactory.class);
+    expect(pamAuthenticationFactory.createInstance(anyObject(String.class))).andReturn(pam).once();
+
+    replayAll();
+
+    Authentication authentication = new UsernamePasswordAuthenticationToken(TEST_USER_NAME, TEST_USER_PASS);
+
+    AmbariPamAuthenticationProvider authenticationProvider = injector.getInstance(AmbariPamAuthenticationProvider.class);
+
+    Authentication result = authenticationProvider.authenticate(authentication);
+
+    verifyAll();
+
     Assert.assertNotNull(result);
     Assert.assertEquals(true, result.isAuthenticated());
     Assert.assertTrue(result instanceof AmbariUserAuthentication);
@@ -109,24 +138,14 @@ public class AmbariPamAuthenticationProviderTest {
 
   @Test
   public void testDisabled() throws Exception {
-    UserEntity userEntity = combineUserEntity();
-    User user = new User(userEntity);
-    Collection<AmbariGrantedAuthority> userAuthorities = Collections.singletonList(createNiceMock(AmbariGrantedAuthority.class));
+
+    Configuration configuration = injector.getInstance(Configuration.class);
     configuration.setClientSecurityType(ClientSecurityType.LOCAL);
-    Authentication authentication = new AmbariUserAuthentication("userPass", user, userAuthorities);
+
+    Authentication authentication = new UsernamePasswordAuthenticationToken(TEST_USER_NAME, TEST_USER_PASS);
+
+    AmbariPamAuthenticationProvider authenticationProvider = injector.getInstance(AmbariPamAuthenticationProvider.class);
     Authentication auth = authenticationProvider.authenticate(authentication);
     Assert.assertTrue(auth == null);
   }
-
-  private UserEntity combineUserEntity() {
-    PrincipalEntity principalEntity = new PrincipalEntity();
-    UserEntity userEntity = new UserEntity();
-    userEntity.setUserId(1);
-    userEntity.setUserName(UserName.fromString(TEST_USER_NAME));
-    userEntity.setUserPassword(passwordEncoder.encode(TEST_USER_PASS));
-    userEntity.setUserType(UserType.PAM);
-    userEntity.setPrincipal(principalEntity);
-    return userEntity;
-  }
-
 }