Search in sources :

Example 1 with AmbariConnectionException

use of com.sequenceiq.ambari.client.AmbariConnectionException 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 2 with AmbariConnectionException

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

the class AmbariClusterSecurityServiceTest method testDisableSecurityWhenExceptionOccursWhichNotCancellationThenShouldThrowAmbariOperationFailedException.

@Test
public void testDisableSecurityWhenExceptionOccursWhichNotCancellationThenShouldThrowAmbariOperationFailedException() 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.disableKerberos()).thenReturn(1);
    Map<String, Integer> operationRequests = singletonMap("DISABLE_KERBEROS_REQUEST", 1);
    ImmutablePair<PollingResult, Exception> pair = new ImmutablePair<>(PollingResult.EXIT, null);
    String failed = "failed";
    when(ambariOperationService.waitForOperations(stack, ambariClient, operationRequests, DISABLE_KERBEROS_STATE)).thenThrow(new AmbariConnectionException("failed"));
    when(cloudbreakMessagesService.getMessage(AMBARI_CLUSTER_DISABLE_KERBEROS_FAILED.code())).thenReturn("failed");
    doThrow(new AmbariOperationFailedException("cancel")).when(ambariClusterConnectorPollingResultChecker).checkPollingResult(pair.getLeft(), failed);
    thrown.expect(AmbariOperationFailedException.class);
    thrown.expectMessage("failed");
    underTest.disableSecurity(stack);
    verify(ambariOperationService, times(1)).waitForOperations(stack, ambariClient, operationRequests, DISABLE_KERBEROS_STATE);
    verify(cloudbreakMessagesService, times(1)).getMessage(AMBARI_CLUSTER_DISABLE_KERBEROS_FAILED.code());
    verify(ambariClusterConnectorPollingResultChecker, times(1)).checkPollingResult(pair.getLeft(), failed);
}
Also used : ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) PollingResult(com.sequenceiq.cloudbreak.service.PollingResult) Cluster(com.sequenceiq.cloudbreak.domain.Cluster) Matchers.anyString(org.mockito.Matchers.anyString) AmbariConnectionException(com.sequenceiq.ambari.client.AmbariConnectionException) 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)

Example 3 with AmbariConnectionException

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

the class AmbariClusterSecurityServiceTest method testPrepareSecurityWhenExceptionOccursWhichNotCancellationThenShouldThrowAmbariOperationFailedException.

@Test
public void testPrepareSecurityWhenExceptionOccursWhichNotCancellationThenShouldThrowAmbariOperationFailedException() 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.EXIT, null);
    String failed = "failed";
    when(ambariOperationService.waitForOperations(stack, ambariClient, operationRequests, PREPARE_DEKERBERIZING)).thenThrow(new AmbariConnectionException("failed"));
    when(cloudbreakMessagesService.getMessage(AMBARI_CLUSTER_PREPARE_DEKERBERIZING_FAILED.code())).thenReturn("failed");
    doThrow(new AmbariOperationFailedException("cancel")).when(ambariClusterConnectorPollingResultChecker).checkPollingResult(pair.getLeft(), failed);
    thrown.expect(AmbariOperationFailedException.class);
    thrown.expectMessage("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 : HashMap(java.util.HashMap) Cluster(com.sequenceiq.cloudbreak.domain.Cluster) Matchers.anyString(org.mockito.Matchers.anyString) AmbariConnectionException(com.sequenceiq.ambari.client.AmbariConnectionException) 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) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) PollingResult(com.sequenceiq.cloudbreak.service.PollingResult) AmbariClient(com.sequenceiq.ambari.client.AmbariClient) Test(org.junit.Test)

Example 4 with AmbariConnectionException

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

the class AmbariClusterSecurityServiceTest method testApiUpdateUserNamePasswordWhenChangePasswordThrowException.

@Test
public void testApiUpdateUserNamePasswordWhenChangePasswordThrowException() 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()).thenReturn("1.1");
    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 5 with AmbariConnectionException

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

the class AmbariClusterModificationService method stopCluster.

@Override
public void stopCluster(Stack stack) throws CloudbreakException {
    AmbariClient ambariClient = clientFactory.getAmbariClient(stack, stack.getCluster());
    try {
        boolean stopped = true;
        Collection<Map<String, String>> values = ambariClient.getHostComponentsStates().values();
        for (Map<String, String> value : values) {
            for (String state : value.values()) {
                if (!"INSTALLED".equals(state)) {
                    stopped = false;
                }
            }
        }
        if (!stopped) {
            LOGGER.info("Stop all Hadoop services");
            eventService.fireCloudbreakEvent(stack.getId(), UPDATE_IN_PROGRESS.name(), cloudbreakMessagesService.getMessage(AMBARI_CLUSTER_SERVICES_STOPPING.code()));
            int requestId = ambariClient.stopAllServices();
            if (requestId != -1) {
                LOGGER.info("Waiting for Hadoop services to stop on stack");
                PollingResult servicesStopResult = ambariOperationService.waitForOperations(stack, ambariClient, singletonMap("stop services", requestId), STOP_AMBARI_PROGRESS_STATE).getLeft();
                if (isExited(servicesStopResult)) {
                    throw new CancellationException("Cluster was terminated while waiting for Hadoop services to start");
                } else if (isTimeout(servicesStopResult)) {
                    throw new CloudbreakException("Timeout while stopping Ambari services.");
                }
            } else {
                LOGGER.warn("Failed to stop Hadoop services.");
                throw new CloudbreakException("Failed to stop Hadoop services.");
            }
            eventService.fireCloudbreakEvent(stack.getId(), UPDATE_IN_PROGRESS.name(), cloudbreakMessagesService.getMessage(AMBARI_CLUSTER_SERVICES_STOPPED.code()));
        }
    } catch (AmbariConnectionException ignored) {
        LOGGER.debug("Ambari not running on the gateway machine, no need to stop it.");
    }
}
Also used : CancellationException(com.sequenceiq.cloudbreak.cloud.scheduler.CancellationException) PollingResult(com.sequenceiq.cloudbreak.service.PollingResult) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) AmbariConnectionException(com.sequenceiq.ambari.client.AmbariConnectionException) Map(java.util.Map) Collections.singletonMap(java.util.Collections.singletonMap) AmbariClient(com.sequenceiq.ambari.client.AmbariClient)

Aggregations

AmbariClient (com.sequenceiq.ambari.client.AmbariClient)5 AmbariConnectionException (com.sequenceiq.ambari.client.AmbariConnectionException)5 Cluster (com.sequenceiq.cloudbreak.domain.Cluster)4 Stack (com.sequenceiq.cloudbreak.domain.Stack)4 Test (org.junit.Test)4 Matchers.anyString (org.mockito.Matchers.anyString)4 CancellationException (com.sequenceiq.cloudbreak.cloud.scheduler.CancellationException)3 CloudbreakException (com.sequenceiq.cloudbreak.service.CloudbreakException)3 PollingResult (com.sequenceiq.cloudbreak.service.PollingResult)3 ImmutablePair (org.apache.commons.lang3.tuple.ImmutablePair)2 ExpectedException (org.junit.rules.ExpectedException)2 Collections.singletonMap (java.util.Collections.singletonMap)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1