Search in sources :

Example 16 with AmbariClient

use of com.sequenceiq.ambari.client.AmbariClient in project cloudbreak by hortonworks.

the class AmbariClientFactoryTest method testGetAmbariClientWithUsernameAndPasswordWhenExceptionOccuredWhichIsCloudbreakSecuritySetupException.

@Test
public void testGetAmbariClientWithUsernameAndPasswordWhenExceptionOccuredWhichIsCloudbreakSecuritySetupException() throws CloudbreakSecuritySetupException {
    Stack stack = TestUtil.stack();
    Cluster cluster = TestUtil.cluster();
    String userName = "userName";
    String password = "password";
    stack.setCluster(cluster);
    HttpClientConfig httpClientConfig = new HttpClientConfig(stack.getAmbariIp());
    AmbariClient ambariClient = Mockito.mock(AmbariClient.class);
    when(tlsSecurityService.buildTLSClientConfigForPrimaryGateway(stack.getId(), stack.getAmbariIp())).thenThrow(new IllegalArgumentException("failed"));
    thrown.expect(IllegalArgumentException.class);
    thrown.expectMessage("failed");
    AmbariClient defaultAmbariClient = underTest.getAmbariClient(stack, userName, password);
    Assert.assertEquals(ambariClient, defaultAmbariClient);
    verify(tlsSecurityService, times(1)).buildTLSClientConfigForPrimaryGateway(stack.getId(), stack.getAmbariIp());
    verify(ambariClientProvider, times(0)).getAmbariClient(httpClientConfig, stack.getGatewayPort(), userName, password);
}
Also used : HttpClientConfig(com.sequenceiq.cloudbreak.client.HttpClientConfig) Cluster(com.sequenceiq.cloudbreak.domain.Cluster) Stack(com.sequenceiq.cloudbreak.domain.Stack) AmbariClient(com.sequenceiq.ambari.client.AmbariClient) Test(org.junit.Test)

Example 17 with AmbariClient

use of com.sequenceiq.ambari.client.AmbariClient in project cloudbreak by hortonworks.

the class AmbariClientFactoryTest method testGetDefaultAmbariClientWhenExceptionOccuredWhichIsCloudbreakSecuritySetupException.

@Test
public void testGetDefaultAmbariClientWhenExceptionOccuredWhichIsCloudbreakSecuritySetupException() throws CloudbreakSecuritySetupException {
    Stack stack = TestUtil.stack();
    HttpClientConfig httpClientConfig = new HttpClientConfig(stack.getAmbariIp());
    AmbariClient ambariClient = Mockito.mock(AmbariClient.class);
    when(tlsSecurityService.buildTLSClientConfigForPrimaryGateway(stack.getId(), stack.getAmbariIp())).thenThrow(new IllegalArgumentException("failed"));
    thrown.expect(IllegalArgumentException.class);
    thrown.expectMessage("failed");
    AmbariClient defaultAmbariClient = underTest.getDefaultAmbariClient(stack);
    Assert.assertEquals(ambariClient, defaultAmbariClient);
    verify(tlsSecurityService, times(1)).buildTLSClientConfigForPrimaryGateway(stack.getId(), stack.getAmbariIp());
    verify(ambariClientProvider, times(0)).getDefaultAmbariClient(httpClientConfig, stack.getGatewayPort());
}
Also used : HttpClientConfig(com.sequenceiq.cloudbreak.client.HttpClientConfig) Stack(com.sequenceiq.cloudbreak.domain.Stack) AmbariClient(com.sequenceiq.ambari.client.AmbariClient) Test(org.junit.Test)

Example 18 with AmbariClient

use of com.sequenceiq.ambari.client.AmbariClient in project cloudbreak by hortonworks.

the class AmbariClientFactoryTest method testGetAmbariClientWhenExceptionOccuredWhichIsCloudbreakSecuritySetupException.

@Test
public void testGetAmbariClientWhenExceptionOccuredWhichIsCloudbreakSecuritySetupException() throws CloudbreakSecuritySetupException {
    Stack stack = TestUtil.stack();
    Cluster cluster = TestUtil.cluster();
    stack.setCluster(cluster);
    HttpClientConfig httpClientConfig = new HttpClientConfig(stack.getAmbariIp());
    AmbariClient ambariClient = Mockito.mock(AmbariClient.class);
    when(tlsSecurityService.buildTLSClientConfigForPrimaryGateway(stack.getId(), stack.getAmbariIp())).thenThrow(new IllegalArgumentException("failed"));
    thrown.expect(IllegalArgumentException.class);
    thrown.expectMessage("failed");
    AmbariClient defaultAmbariClient = underTest.getAmbariClient(stack, cluster);
    Assert.assertEquals(ambariClient, defaultAmbariClient);
    verify(tlsSecurityService, times(1)).buildTLSClientConfigForPrimaryGateway(stack.getId(), stack.getAmbariIp());
    verify(ambariClientProvider, times(0)).getAmbariClient(httpClientConfig, stack.getGatewayPort(), cluster);
}
Also used : HttpClientConfig(com.sequenceiq.cloudbreak.client.HttpClientConfig) Cluster(com.sequenceiq.cloudbreak.domain.Cluster) Stack(com.sequenceiq.cloudbreak.domain.Stack) AmbariClient(com.sequenceiq.ambari.client.AmbariClient) Test(org.junit.Test)

Example 19 with AmbariClient

use of com.sequenceiq.ambari.client.AmbariClient in project cloudbreak by hortonworks.

the class AmbariClusterSecurityServiceTest method testApiUpdateUserNamePasswordWhenChangePasswordThrowExceptionAndAmbariVersionThrowExceptionThenShouldThrowCloudbreakException.

@Test
public void testApiUpdateUserNamePasswordWhenChangePasswordThrowExceptionAndAmbariVersionThrowExceptionThenShouldThrowCloudbreakException() throws CloudbreakException {
    Stack stack = TestUtil.stack();
    Cluster cluster = TestUtil.cluster();
    stack.setCluster(cluster);
    AmbariClient ambariClient = Mockito.mock(AmbariClient.class);
    String newPassword = "newadmin";
    when(clusterService.getById(stack.getCluster().getId())).thenReturn(cluster);
    when(clientFactory.getAmbariClient(stack, cluster.getUserName(), cluster.getPassword())).thenReturn(ambariClient);
    when(clientFactory.getAmbariClient(stack, cluster.getUserName(), newPassword)).thenReturn(ambariClient);
    when(ambariClient.changePassword(cluster.getUserName(), cluster.getPassword(), newPassword, true)).thenThrow(new AmbariConnectionException("test1"));
    when(ambariClient.ambariServerVersion()).thenThrow(new AmbariConnectionException("test1"));
    thrown.expect(CloudbreakException.class);
    thrown.expectMessage("test1");
    underTest.updateUserNamePassword(stack, newPassword);
    verify(clientFactory, times(1)).getAmbariClient(stack, cluster.getUserName(), cluster.getPassword());
    verify(clusterService, times(1)).getById(stack.getCluster().getId());
    verify(ambariClient, times(1)).changePassword(cluster.getUserName(), cluster.getPassword(), newPassword, true);
    verify(ambariClient, times(1)).ambariServerVersion();
}
Also used : Cluster(com.sequenceiq.cloudbreak.domain.Cluster) Matchers.anyString(org.mockito.Matchers.anyString) AmbariConnectionException(com.sequenceiq.ambari.client.AmbariConnectionException) Stack(com.sequenceiq.cloudbreak.domain.Stack) AmbariClient(com.sequenceiq.ambari.client.AmbariClient) Test(org.junit.Test)

Example 20 with AmbariClient

use of com.sequenceiq.ambari.client.AmbariClient in project cloudbreak by hortonworks.

the class AmbariClusterSecurityServiceTest method testPrepareSecurityWhenEverythingWorks.

@Test
public void testPrepareSecurityWhenEverythingWorks() throws CloudbreakException {
    Stack stack = TestUtil.stack();
    Cluster cluster = TestUtil.cluster();
    stack.setCluster(cluster);
    AmbariClient ambariClient = Mockito.mock(AmbariClient.class);
    when(clientFactory.getAmbariClient(stack, stack.getCluster())).thenReturn(ambariClient);
    when(ambariClient.startService(anyString())).thenReturn(1);
    when(ambariClient.stopService(anyString())).thenReturn(1);
    Map<String, Integer> operationRequests = new HashMap<>();
    operationRequests.put("ZOOKEEPER_SERVICE_STATE", 1);
    operationRequests.put("HDFS_SERVICE_STATE", 1);
    operationRequests.put("YARN_SERVICE_STATE", 1);
    operationRequests.put("MAPREDUCE2_SERVICE_STATE", 1);
    operationRequests.put("KERBEROS_SERVICE_STATE", 1);
    ImmutablePair<PollingResult, Exception> pair = new ImmutablePair<>(PollingResult.SUCCESS, null);
    String failed = "failed";
    when(ambariOperationService.waitForOperations(stack, ambariClient, operationRequests, PREPARE_DEKERBERIZING)).thenReturn(pair);
    when(cloudbreakMessagesService.getMessage(AMBARI_CLUSTER_PREPARE_DEKERBERIZING_FAILED.code())).thenReturn("failed");
    doNothing().when(ambariClusterConnectorPollingResultChecker).checkPollingResult(pair.getLeft(), failed);
    underTest.prepareSecurity(stack);
    verify(ambariOperationService, times(1)).waitForOperations(stack, ambariClient, operationRequests, PREPARE_DEKERBERIZING);
    verify(cloudbreakMessagesService, times(1)).getMessage(AMBARI_CLUSTER_PREPARE_DEKERBERIZING_FAILED.code());
    verify(ambariClusterConnectorPollingResultChecker, times(1)).checkPollingResult(pair.getLeft(), failed);
}
Also used : ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) HashMap(java.util.HashMap) PollingResult(com.sequenceiq.cloudbreak.service.PollingResult) Cluster(com.sequenceiq.cloudbreak.domain.Cluster) Matchers.anyString(org.mockito.Matchers.anyString) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) AmbariConnectionException(com.sequenceiq.ambari.client.AmbariConnectionException) ExpectedException(org.junit.rules.ExpectedException) CancellationException(com.sequenceiq.cloudbreak.cloud.scheduler.CancellationException) Stack(com.sequenceiq.cloudbreak.domain.Stack) AmbariClient(com.sequenceiq.ambari.client.AmbariClient) Test(org.junit.Test)

Aggregations

AmbariClient (com.sequenceiq.ambari.client.AmbariClient)78 Test (org.junit.Test)39 Cluster (com.sequenceiq.cloudbreak.domain.Cluster)37 Stack (com.sequenceiq.cloudbreak.domain.Stack)32 HttpClientConfig (com.sequenceiq.cloudbreak.client.HttpClientConfig)23 HostMetadata (com.sequenceiq.cloudbreak.domain.HostMetadata)16 CloudbreakException (com.sequenceiq.cloudbreak.service.CloudbreakException)16 HashMap (java.util.HashMap)16 PollingResult (com.sequenceiq.cloudbreak.service.PollingResult)15 CancellationException (com.sequenceiq.cloudbreak.cloud.scheduler.CancellationException)14 HostGroup (com.sequenceiq.cloudbreak.domain.HostGroup)14 Matchers.anyString (org.mockito.Matchers.anyString)14 Map (java.util.Map)13 AmbariConnectionException (com.sequenceiq.ambari.client.AmbariConnectionException)10 Collections.singletonMap (java.util.Collections.singletonMap)9 HashSet (java.util.HashSet)9 HostGroupAdjustmentJson (com.sequenceiq.cloudbreak.api.model.HostGroupAdjustmentJson)6 Status (com.sequenceiq.cloudbreak.api.model.Status)6 List (java.util.List)6 ImmutablePair (org.apache.commons.lang3.tuple.ImmutablePair)6