ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rle...@apache.org
Subject ambari git commit: AMBARI-9439. Kerberos: regenerate keytabs not handled for all hosts (rlevas)
Date Mon, 23 Feb 2015 19:13:33 GMT
Repository: ambari
Updated Branches:
  refs/heads/trunk 46f1ffbec -> 575097117


AMBARI-9439. Kerberos: regenerate keytabs not handled for all hosts (rlevas)


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

Branch: refs/heads/trunk
Commit: 575097117230f5111dd9171efbf632eff3f58d1e
Parents: 46f1ffb
Author: Robert Levas <rlevas@hortonworks.com>
Authored: Mon Feb 23 14:13:24 2015 -0500
Committer: Robert Levas <rlevas@hortonworks.com>
Committed: Mon Feb 23 14:13:30 2015 -0500

----------------------------------------------------------------------
 .../server/controller/KerberosHelper.java       |  31 +++-
 .../org/apache/ambari/server/state/Service.java |   3 +-
 .../server/controller/KerberosHelperTest.java   | 150 +++++++++++++++++--
 3 files changed, 170 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/57509711/ambari-server/src/main/java/org/apache/ambari/server/controller/KerberosHelper.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/KerberosHelper.java
b/ambari-server/src/main/java/org/apache/ambari/server/controller/KerberosHelper.java
index 7a0a374..e562497 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/KerberosHelper.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/KerberosHelper.java
@@ -81,6 +81,7 @@ import org.apache.ambari.server.state.Service;
 import org.apache.ambari.server.state.ServiceComponent;
 import org.apache.ambari.server.state.ServiceComponentHost;
 import org.apache.ambari.server.state.StackId;
+import org.apache.ambari.server.state.State;
 import org.apache.ambari.server.state.kerberos.KerberosComponentDescriptor;
 import org.apache.ambari.server.state.kerberos.KerberosConfigurationDescriptor;
 import org.apache.ambari.server.state.kerberos.KerberosDescriptor;
@@ -103,6 +104,7 @@ import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
+import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -509,6 +511,11 @@ public class KerberosHelper {
         Map<String, String> kerberosDescriptorProperties = kerberosDescriptor.getProperties();
         Map<String, Map<String, String>> kerberosConfigurations = new HashMap<String,
Map<String, String>>();
 
+        // While iterating over all the ServiceComponentHosts find hosts that have KERBEROS_CLIENT
+        // components in the INSTALLED state and add them to the hostsWithValidKerberosClient
Set.
+        // This is needed to help determine which hosts to perform actions for and create
tasks for.
+        Set<String> hostsWithValidKerberosClient = new HashSet<String>();
+
         // Create a temporary directory to store metadata needed to complete this task. 
Information
         // such as which principals and keytabs files to create as well as what configurations
need
         // to be update are stored in data files in this directory. Any keytab files are
stored in
@@ -545,6 +552,16 @@ public class KerberosHelper {
               // keytab files, and configurations need to be created or updated.
               for (ServiceComponentHost sch : serviceComponentHosts) {
                 String serviceName = sch.getServiceName();
+                String componentName = sch.getServiceComponentName();
+
+                // If the current ServiceComponentHost represents the KERBEROS/KERBEROS_CLIENT
and
+                // indicates that the KERBEROS_CLIENT component is in the INSTALLED state,
add the
+                // current host to the set of hosts that should be handled...
+                if(Service.Type.KERBEROS.name().equals(serviceName) &&
+                    Role.KERBEROS_CLIENT.name().equals(componentName) &&
+                    (sch.getState() == State.INSTALLED)) {
+                  hostsWithValidKerberosClient.add(hostname);
+                }
 
                 // If there is no filter or the filter contains the current service name...
                 if ((serviceComponentFilter == null) || serviceComponentFilter.containsKey(serviceName))
{
@@ -552,7 +569,6 @@ public class KerberosHelper {
                   KerberosServiceDescriptor serviceDescriptor = kerberosDescriptor.getService(serviceName);
 
                   if (serviceDescriptor != null) {
-                    String componentName = sch.getServiceComponentName();
                     int identitiesAdded = 0;
                     List<KerberosIdentityDescriptor> serviceIdentities = serviceDescriptor.getIdentities(true);
 
@@ -607,6 +623,17 @@ public class KerberosHelper {
           }
         }
 
+        // Filter out ServiceComponentHosts not ready for processing from serviceComponentHostsToProcess
+        // by pruning off the ones that on hosts that are not in hostsWithValidKerberosClient
+        Iterator<ServiceComponentHost> iterator = serviceComponentHostsToProcess.iterator();
+        while(iterator.hasNext()) {
+          ServiceComponentHost sch = iterator.next();
+
+          if(!hostsWithValidKerberosClient.contains(sch.getHostName())) {
+            iterator.remove();
+          }
+        }
+
         // If there are ServiceComponentHosts to process, make sure the administrator credentials
         // are available
         if (!serviceComponentHostsToProcess.isEmpty()) {
@@ -1650,7 +1677,7 @@ public class KerberosHelper {
         List<String> hostsToUpdate = createUniqueHostList(serviceComponentHosts, Collections.singleton(HostState.HEALTHY));
         Map<String, String> requestParams = new HashMap<String, String>();
         List<RequestResourceFilter> requestResourceFilters = new ArrayList<RequestResourceFilter>();
-        RequestResourceFilter reqResFilter = new RequestResourceFilter("KERBEROS", "KERBEROS_CLIENT",
hostsToUpdate);
+        RequestResourceFilter reqResFilter = new RequestResourceFilter(Service.Type.KERBEROS.name(),
Role.KERBEROS_CLIENT.name(), hostsToUpdate);
         requestResourceFilters.add(reqResFilter);
 
         ActionExecutionContext actionExecContext = new ActionExecutionContext(

http://git-wip-us.apache.org/repos/asf/ambari/blob/57509711/ambari-server/src/main/java/org/apache/ambari/server/state/Service.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/Service.java b/ambari-server/src/main/java/org/apache/ambari/server/state/Service.java
index d05f209..1137cba 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/state/Service.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/state/Service.java
@@ -133,6 +133,7 @@ public interface Service {
     FLUME,
     YARN,
     MAPREDUCE2,
-    AMBARI_METRICS
+    AMBARI_METRICS,
+    KERBEROS
   }
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/57509711/ambari-server/src/test/java/org/apache/ambari/server/controller/KerberosHelperTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/KerberosHelperTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/controller/KerberosHelperTest.java
index 7db2653..c80970a 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/KerberosHelperTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/KerberosHelperTest.java
@@ -23,6 +23,7 @@ import com.google.inject.Guice;
 import com.google.inject.Injector;
 import junit.framework.Assert;
 import org.apache.ambari.server.AmbariException;
+import org.apache.ambari.server.Role;
 import org.apache.ambari.server.actionmanager.ActionManager;
 import org.apache.ambari.server.actionmanager.HostRoleCommand;
 import org.apache.ambari.server.actionmanager.RequestFactory;
@@ -56,6 +57,7 @@ import org.apache.ambari.server.state.Service;
 import org.apache.ambari.server.state.ServiceComponent;
 import org.apache.ambari.server.state.ServiceComponentHost;
 import org.apache.ambari.server.state.StackId;
+import org.apache.ambari.server.state.State;
 import org.apache.ambari.server.state.cluster.ClusterFactory;
 import org.apache.ambari.server.state.cluster.ClustersImpl;
 import org.apache.ambari.server.state.host.HostFactory;
@@ -87,14 +89,8 @@ import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
-import static org.easymock.EasyMock.anyLong;
-import static org.easymock.EasyMock.anyObject;
-import static org.easymock.EasyMock.capture;
-import static org.easymock.EasyMock.expect;
-import static org.easymock.EasyMock.expectLastCall;
-import static org.easymock.EasyMock.reset;
-import static org.easymock.EasyMock.replay;
-import static org.easymock.EasyMock.verify;
+import static org.easymock.EasyMock.*;
+import static org.easymock.EasyMock.createNiceMock;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
 
@@ -320,12 +316,17 @@ public class KerberosHelperTest extends EasyMockSupport {
 
   @Test
   public void testRegenerateKeytabsValidateRequestStageContainer() throws Exception {
-    testRegenerateKeytabs(new KerberosCredential("principal", "password", "keytab"), false);
+    testRegenerateKeytabs(new KerberosCredential("principal", "password", "keytab"), true,
false);
+  }
+
+  @Test
+  public void testRegenerateKeytabsValidateSkipInvalidHost() throws Exception {
+    testRegenerateKeytabs(new KerberosCredential("principal", "password", "keytab"), true,
true);
   }
 
   @Test
   public void testRegenerateKeytabs() throws Exception {
-    testRegenerateKeytabs(new KerberosCredential("principal", "password", "keytab"), false);
+    testRegenerateKeytabs(new KerberosCredential("principal", "password", "keytab"), false,
false);
   }
 
   @Test
@@ -341,6 +342,15 @@ public class KerberosHelperTest extends EasyMockSupport {
 
     final StackId stackVersion = createNiceMock(StackId.class);
 
+    final ServiceComponentHost schKerberosClient = createMock(ServiceComponentHost.class);
+    expect(schKerberosClient.getServiceName()).andReturn(Service.Type.KERBEROS.name()).anyTimes();
+    expect(schKerberosClient.getServiceComponentName()).andReturn(Role.KERBEROS_CLIENT.name()).anyTimes();
+    expect(schKerberosClient.getSecurityState()).andReturn(SecurityState.UNSECURED).anyTimes();
+    expect(schKerberosClient.getDesiredSecurityState()).andReturn(SecurityState.UNSECURED).anyTimes();
+    expect(schKerberosClient.getStackVersion()).andReturn(stackVersion).anyTimes();
+    expect(schKerberosClient.getHostName()).andReturn("host1").anyTimes();
+    expect(schKerberosClient.getState()).andReturn(State.INSTALLED).anyTimes();
+
     final ServiceComponentHost sch1 = createMock(ServiceComponentHost.class);
     expect(sch1.getServiceName()).andReturn("SERVICE1").anyTimes();
     expect(sch1.getServiceComponentName()).andReturn("COMPONENT1").anyTimes();
@@ -348,6 +358,7 @@ public class KerberosHelperTest extends EasyMockSupport {
     expect(sch1.getDesiredSecurityState()).andReturn(SecurityState.UNSECURED).anyTimes();
     expect(sch1.getStackVersion()).andReturn(stackVersion).anyTimes();
     expect(sch1.getHostName()).andReturn("host1").anyTimes();
+    expect(sch1.getState()).andReturn(State.INSTALLED).anyTimes();
 
     sch1.setDesiredSecurityState(SecurityState.SECURED_KERBEROS);
     expect(expectLastCall()).once();
@@ -361,6 +372,7 @@ public class KerberosHelperTest extends EasyMockSupport {
     expect(sch2.getDesiredSecurityState()).andReturn(SecurityState.UNSECURED).anyTimes();
     expect(sch2.getStackVersion()).andReturn(stackVersion).anyTimes();
     expect(sch2.getHostName()).andReturn("host1").anyTimes();
+    expect(sch2.getState()).andReturn(State.INSTALLED).anyTimes();
 
     sch2.setDesiredSecurityState(SecurityState.SECURED_KERBEROS);
     expect(expectLastCall()).once();
@@ -371,6 +383,18 @@ public class KerberosHelperTest extends EasyMockSupport {
     expect(host.getHostName()).andReturn("host1").anyTimes();
     expect(host.getState()).andReturn(HostState.HEALTHY).anyTimes();
 
+    final ServiceComponent serviceComponentKerberosClient = createNiceMock(ServiceComponent.class);
+    expect(serviceComponentKerberosClient.getName()).andReturn(Role.KERBEROS_CLIENT.name()).anyTimes();
+    expect(serviceComponentKerberosClient.getServiceComponentHosts()).andReturn(Collections.singletonMap("host1",
schKerberosClient)).anyTimes();
+
+    final Service serviceKerberos = createStrictMock(Service.class);
+    expect(serviceKerberos.getName()).andReturn(Service.Type.KERBEROS.name()).anyTimes();
+    expect(serviceKerberos.getServiceComponents())
+        .andReturn(Collections.singletonMap(Role.KERBEROS_CLIENT.name(), serviceComponentKerberosClient))
+            .times(3);
+    serviceKerberos.setSecurityState(SecurityState.SECURED_KERBEROS);
+    expectLastCall().once();
+
     final Service service1 = createStrictMock(Service.class);
     expect(service1.getName()).andReturn("SERVICE1").anyTimes();
     expect(service1.getServiceComponents())
@@ -408,6 +432,7 @@ public class KerberosHelperTest extends EasyMockSupport {
     expect(cluster.getServices())
         .andReturn(new HashMap<String, Service>() {
           {
+            put(Service.Type.KERBEROS.name(), serviceKerberos);
             put("SERVICE1", service1);
             put("SERVICE2", service2);
           }
@@ -416,6 +441,7 @@ public class KerberosHelperTest extends EasyMockSupport {
     expect(cluster.getServiceComponentHosts("host1"))
         .andReturn(new ArrayList<ServiceComponentHost>() {
           {
+            add(schKerberosClient);
             add(sch1);
             add(sch2);
           }
@@ -593,6 +619,14 @@ public class KerberosHelperTest extends EasyMockSupport {
 
     final StackId stackVersion = createNiceMock(StackId.class);
 
+    final ServiceComponentHost schKerberosClient = createMock(ServiceComponentHost.class);
+    expect(schKerberosClient.getServiceName()).andReturn(Service.Type.KERBEROS.name()).anyTimes();
+    expect(schKerberosClient.getServiceComponentName()).andReturn(Role.KERBEROS_CLIENT.name()).anyTimes();
+    expect(schKerberosClient.getSecurityState()).andReturn(SecurityState.UNSECURED).anyTimes();
+    expect(schKerberosClient.getDesiredSecurityState()).andReturn(SecurityState.UNSECURED).anyTimes();
+    expect(schKerberosClient.getStackVersion()).andReturn(stackVersion).anyTimes();
+    expect(schKerberosClient.getHostName()).andReturn("host1").anyTimes();
+    expect(schKerberosClient.getState()).andReturn(State.INSTALLED).anyTimes();
 
     final ServiceComponentHost sch1 = createMock(ServiceComponentHost.class);
     expect(sch1.getServiceName()).andReturn("SERVICE1").times(2);
@@ -600,6 +634,8 @@ public class KerberosHelperTest extends EasyMockSupport {
     expect(sch1.getSecurityState()).andReturn(SecurityState.SECURED_KERBEROS).anyTimes();
     expect(sch1.getDesiredSecurityState()).andReturn(SecurityState.SECURED_KERBEROS).anyTimes();
     expect(sch1.getStackVersion()).andReturn(stackVersion).anyTimes();
+    expect(sch1.getHostName()).andReturn("host1").anyTimes();
+    expect(sch1.getState()).andReturn(State.INSTALLED).anyTimes();
 
     sch1.setDesiredSecurityState(SecurityState.UNSECURED);
     expect(expectLastCall()).once();
@@ -612,6 +648,8 @@ public class KerberosHelperTest extends EasyMockSupport {
     expect(sch2.getSecurityState()).andReturn(SecurityState.SECURED_KERBEROS).anyTimes();
     expect(sch2.getDesiredSecurityState()).andReturn(SecurityState.SECURED_KERBEROS).anyTimes();
     expect(sch2.getStackVersion()).andReturn(stackVersion).anyTimes();
+    expect(sch2.getHostName()).andReturn("host1").anyTimes();
+    expect(sch2.getState()).andReturn(State.INSTALLED).anyTimes();
 
     sch2.setDesiredSecurityState(SecurityState.UNSECURED);
     expect(expectLastCall()).once();
@@ -621,6 +659,18 @@ public class KerberosHelperTest extends EasyMockSupport {
     final Host host = createNiceMock(Host.class);
     expect(host.getHostName()).andReturn("host1").anyTimes();
 
+    final ServiceComponent serviceComponentKerberosClient = createNiceMock(ServiceComponent.class);
+    expect(serviceComponentKerberosClient.getName()).andReturn(Role.KERBEROS_CLIENT.name()).anyTimes();
+    expect(serviceComponentKerberosClient.getServiceComponentHosts()).andReturn(Collections.singletonMap("host1",
schKerberosClient)).anyTimes();
+
+    final Service serviceKerberos = createStrictMock(Service.class);
+    expect(serviceKerberos.getName()).andReturn(Service.Type.KERBEROS.name()).anyTimes();
+    expect(serviceKerberos.getServiceComponents())
+        .andReturn(Collections.singletonMap(Role.KERBEROS_CLIENT.name(), serviceComponentKerberosClient))
+        .times(3);
+    serviceKerberos.setSecurityState(SecurityState.UNSECURED);
+    expectLastCall().once();
+
     final Service service1 = createStrictMock(Service.class);
     expect(service1.getName()).andReturn("SERVICE1").anyTimes();
     expect(service1.getServiceComponents())
@@ -657,6 +707,7 @@ public class KerberosHelperTest extends EasyMockSupport {
     expect(cluster.getServices())
         .andReturn(new HashMap<String, Service>() {
           {
+            put(Service.Type.KERBEROS.name(), serviceKerberos);
             put("SERVICE1", service1);
             put("SERVICE2", service2);
           }
@@ -665,6 +716,7 @@ public class KerberosHelperTest extends EasyMockSupport {
     expect(cluster.getServiceComponentHosts("host1"))
         .andReturn(new ArrayList<ServiceComponentHost>() {
           {
+            add(schKerberosClient);
             add(sch1);
             add(sch2);
           }
@@ -822,12 +874,18 @@ public class KerberosHelperTest extends EasyMockSupport {
     verifyAll();
   }
 
-  private void testRegenerateKeytabs(final KerberosCredential kerberosCredential, boolean
mockRequestStageContainer) throws Exception {
+  private void testRegenerateKeytabs(final KerberosCredential kerberosCredential, boolean
mockRequestStageContainer, final boolean testInvalidHost) throws Exception {
 
     KerberosHelper kerberosHelper = injector.getInstance(KerberosHelper.class);
 
     final StackId stackVersion = createNiceMock(StackId.class);
 
+    final ServiceComponentHost schKerberosClient = createMock(ServiceComponentHost.class);
+    expect(schKerberosClient.getServiceName()).andReturn(Service.Type.KERBEROS.name()).anyTimes();
+    expect(schKerberosClient.getServiceComponentName()).andReturn(Role.KERBEROS_CLIENT.name()).anyTimes();
+    expect(schKerberosClient.getHostName()).andReturn("host1").anyTimes();
+    expect(schKerberosClient.getState()).andReturn(State.INSTALLED).anyTimes();
+
     final ServiceComponentHost sch1 = createMock(ServiceComponentHost.class);
     expect(sch1.getServiceName()).andReturn("SERVICE1").anyTimes();
     expect(sch1.getServiceComponentName()).andReturn("COMPONENT1").anyTimes();
@@ -848,6 +906,51 @@ public class KerberosHelperTest extends EasyMockSupport {
     expect(host.getHostName()).andReturn("host1").anyTimes();
     expect(host.getState()).andReturn(HostState.HEALTHY).anyTimes();
 
+    final ServiceComponentHost schKerberosClientInvalid;
+    final ServiceComponentHost sch1a;
+    final Host hostInvalid;
+    if(testInvalidHost) {
+      schKerberosClientInvalid = createMock(ServiceComponentHost.class);
+      expect(schKerberosClientInvalid.getServiceName()).andReturn(Service.Type.KERBEROS.name()).anyTimes();
+      expect(schKerberosClientInvalid.getServiceComponentName()).andReturn(Role.KERBEROS_CLIENT.name()).anyTimes();
+      expect(schKerberosClientInvalid.getHostName()).andReturn("host2").anyTimes();
+      expect(schKerberosClientInvalid.getState()).andReturn(State.INIT).anyTimes();
+
+      sch1a = createMock(ServiceComponentHost.class);
+      expect(sch1a.getServiceName()).andReturn("SERVICE1").anyTimes();
+      expect(sch1a.getServiceComponentName()).andReturn("COMPONENT1").anyTimes();
+      expect(sch1a.getSecurityState()).andReturn(SecurityState.UNSECURED).anyTimes();
+      expect(sch1a.getDesiredSecurityState()).andReturn(SecurityState.UNSECURED).anyTimes();
+      expect(sch1a.getStackVersion()).andReturn(stackVersion).anyTimes();
+      expect(sch1a.getHostName()).andReturn("host2").anyTimes();
+
+      hostInvalid = createNiceMock(Host.class);
+      expect(hostInvalid.getHostName()).andReturn("host1").anyTimes();
+      expect(hostInvalid.getState()).andReturn(HostState.HEALTHY).anyTimes();
+    }
+    else {
+      schKerberosClientInvalid = null;
+      sch1a = null;
+      hostInvalid = null;
+    }
+
+    Map<String, ServiceComponentHost> map = new HashMap<String, ServiceComponentHost>();
+    final ServiceComponent serviceComponentKerberosClient = createNiceMock(ServiceComponent.class);
+    map.put("host1", schKerberosClient);
+    expect(serviceComponentKerberosClient.getName()).andReturn(Role.KERBEROS_CLIENT.name()).anyTimes();
+
+    if(testInvalidHost) {
+      map.put("host2", schKerberosClientInvalid);
+    }
+
+    expect(serviceComponentKerberosClient.getServiceComponentHosts()).andReturn(map).anyTimes();
+
+    final Service serviceKerberos = createStrictMock(Service.class);
+    expect(serviceKerberos.getName()).andReturn(Service.Type.KERBEROS.name()).anyTimes();
+    expect(serviceKerberos.getServiceComponents())
+        .andReturn(Collections.singletonMap(Role.KERBEROS_CLIENT.name(), serviceComponentKerberosClient))
+        .times(3);
+
     final Service service1 = createStrictMock(Service.class);
     expect(service1.getName()).andReturn("SERVICE1").anyTimes();
     expect(service1.getServiceComponents())
@@ -880,6 +983,7 @@ public class KerberosHelperTest extends EasyMockSupport {
     expect(cluster.getServices())
         .andReturn(new HashMap<String, Service>() {
           {
+            put(Service.Type.KERBEROS.name(), serviceKerberos);
             put("SERVICE1", service1);
             put("SERVICE2", service2);
           }
@@ -888,6 +992,7 @@ public class KerberosHelperTest extends EasyMockSupport {
     expect(cluster.getServiceComponentHosts("host1"))
         .andReturn(new ArrayList<ServiceComponentHost>() {
           {
+            add(schKerberosClient);
             add(sch1);
             add(sch2);
           }
@@ -909,6 +1014,10 @@ public class KerberosHelperTest extends EasyMockSupport {
         .andReturn(new HashMap<String, Host>() {
           {
             put("host1", host);
+
+            if (testInvalidHost) {
+              put("host2", hostInvalid);
+            }
           }
         })
         .once();
@@ -1109,6 +1218,12 @@ public class KerberosHelperTest extends EasyMockSupport {
   private void testEnsureIdentities(final KerberosCredential kerberosCredential) throws Exception
{
     KerberosHelper kerberosHelper = injector.getInstance(KerberosHelper.class);
 
+    final ServiceComponentHost schKerberosClient = createMock(ServiceComponentHost.class);
+    expect(schKerberosClient.getServiceName()).andReturn(Service.Type.KERBEROS.name()).anyTimes();
+    expect(schKerberosClient.getServiceComponentName()).andReturn(Role.KERBEROS_CLIENT.name()).anyTimes();
+    expect(schKerberosClient.getHostName()).andReturn("host1").anyTimes();
+    expect(schKerberosClient.getState()).andReturn(State.INSTALLED).anyTimes();
+
     final ServiceComponentHost sch1 = createMock(ServiceComponentHost.class);
     expect(sch1.getServiceName()).andReturn("SERVICE1").anyTimes();
     expect(sch1.getServiceComponentName()).andReturn("COMPONENT1").anyTimes();
@@ -1116,6 +1231,7 @@ public class KerberosHelperTest extends EasyMockSupport {
 
     final ServiceComponentHost sch2 = createStrictMock(ServiceComponentHost.class);
     expect(sch2.getServiceName()).andReturn("SERVICE2").anyTimes();
+    expect(sch2.getServiceComponentName()).andReturn("COMPONENT3").anyTimes();
 
     final ServiceComponentHost sch3 = createStrictMock(ServiceComponentHost.class);
     expect(sch3.getServiceName()).andReturn("SERVICE3").anyTimes();
@@ -1126,6 +1242,16 @@ public class KerberosHelperTest extends EasyMockSupport {
     expect(host.getHostName()).andReturn("host1").anyTimes();
     expect(host.getState()).andReturn(HostState.HEALTHY).anyTimes();
 
+    final ServiceComponent serviceComponentKerberosClient = createNiceMock(ServiceComponent.class);
+    expect(serviceComponentKerberosClient.getName()).andReturn(Role.KERBEROS_CLIENT.name()).anyTimes();
+    expect(serviceComponentKerberosClient.getServiceComponentHosts()).andReturn(Collections.singletonMap("host1",
schKerberosClient)).anyTimes();
+
+    final Service serviceKerberos = createStrictMock(Service.class);
+    expect(serviceKerberos.getName()).andReturn(Service.Type.KERBEROS.name()).anyTimes();
+    expect(serviceKerberos.getServiceComponents())
+        .andReturn(Collections.singletonMap(Role.KERBEROS_CLIENT.name(), serviceComponentKerberosClient))
+        .times(3);
+
     final Service service1 = createStrictMock(Service.class);
     expect(service1.getName()).andReturn("SERVICE1").anyTimes();
     expect(service1.getServiceComponents())
@@ -1157,6 +1283,7 @@ public class KerberosHelperTest extends EasyMockSupport {
     expect(cluster.getServices())
         .andReturn(new HashMap<String, Service>() {
           {
+            put(Service.Type.KERBEROS.name(), serviceKerberos);
             put("SERVICE1", service1);
             put("SERVICE2", service2);
           }
@@ -1168,6 +1295,7 @@ public class KerberosHelperTest extends EasyMockSupport {
             add(sch1);
             add(sch2);
             add(sch3);
+            add(schKerberosClient);
           }
         })
         .once();


Mime
View raw message