Search in sources :

Example 86 with Cluster

use of com.sequenceiq.cloudbreak.domain.Cluster in project cloudbreak by hortonworks.

the class AmbariClientFactoryTest method testGetAmbariClientWhenEverythingWorksFine.

@Test
public void testGetAmbariClientWhenEverythingWorksFine() 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())).thenReturn(httpClientConfig);
    when(ambariClientProvider.getAmbariClient(httpClientConfig, stack.getGatewayPort(), cluster)).thenReturn(ambariClient);
    AmbariClient defaultAmbariClient = underTest.getAmbariClient(stack, cluster);
    Assert.assertEquals(ambariClient, defaultAmbariClient);
    verify(tlsSecurityService, times(1)).buildTLSClientConfigForPrimaryGateway(stack.getId(), stack.getAmbariIp());
    verify(ambariClientProvider, times(1)).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 87 with Cluster

use of com.sequenceiq.cloudbreak.domain.Cluster in project cloudbreak by hortonworks.

the class AmbariClusterCreationSuccessHandlerTest method testHandleClusterCreationSuccessWhenEverythingGoesFine.

@Test
public void testHandleClusterCreationSuccessWhenEverythingGoesFine() {
    Stack stack = TestUtil.stack();
    Cluster cluster = TestUtil.cluster();
    Set<HostMetadata> hostMetadataList = new HashSet<>();
    cluster.getHostGroups().forEach(hostGroup -> hostGroup.getHostMetadata().forEach(hostMetadataList::add));
    List<InstanceMetaData> instanceMetaDataList = new ArrayList<>();
    stack.getInstanceGroups().forEach(instanceGroup -> instanceGroup.getInstanceMetaData().forEach(instanceMetaDataList::add));
    when(clusterService.updateCluster(cluster)).thenReturn(cluster);
    when(instanceMetadataRepository.save(anyCollection())).thenReturn(instanceMetaDataList);
    when(hostMetadataRepository.findHostsInCluster(cluster.getId())).thenReturn(hostMetadataList);
    when(hostMetadataRepository.save(anyCollection())).thenReturn(hostMetadataList);
    underTest.handleClusterCreationSuccess(stack, cluster);
    ArgumentCaptor<Cluster> clusterCaptor = ArgumentCaptor.forClass(Cluster.class);
    verify(clusterService, times(1)).updateCluster(clusterCaptor.capture());
    assertNotNull(clusterCaptor.getValue().getCreationFinished());
    assertNotNull(clusterCaptor.getValue().getUpSince());
    ArgumentCaptor<List> instanceMetadataCaptor = ArgumentCaptor.forClass(List.class);
    verify(instanceMetadataRepository, times(1)).save(instanceMetadataCaptor.capture());
    for (InstanceMetaData instanceMetaData : (List<InstanceMetaData>) instanceMetadataCaptor.getValue()) {
        Assert.assertEquals(InstanceStatus.REGISTERED, instanceMetaData.getInstanceStatus());
    }
    ArgumentCaptor<List> hostMetadataCaptor = ArgumentCaptor.forClass(List.class);
    verify(hostMetadataRepository, times(1)).save(hostMetadataCaptor.capture());
    for (HostMetadata hostMetadata : (List<HostMetadata>) hostMetadataCaptor.getValue()) {
        Assert.assertEquals(HostMetadataState.HEALTHY, hostMetadata.getHostMetadataState());
    }
    verify(hostMetadataRepository, times(1)).findHostsInCluster(cluster.getId());
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.InstanceMetaData) ArrayList(java.util.ArrayList) Cluster(com.sequenceiq.cloudbreak.domain.Cluster) ArrayList(java.util.ArrayList) List(java.util.List) Stack(com.sequenceiq.cloudbreak.domain.Stack) HostMetadata(com.sequenceiq.cloudbreak.domain.HostMetadata) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 88 with Cluster

use of com.sequenceiq.cloudbreak.domain.Cluster 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 89 with Cluster

use of com.sequenceiq.cloudbreak.domain.Cluster in project cloudbreak by hortonworks.

the class AmbariClusterSecurityServiceTest method testApiUpdateUserNamePasswordWhenEverythingWorks.

@Test
public void testApiUpdateUserNamePasswordWhenEverythingWorks() 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(ambariClient.changePassword(cluster.getUserName(), cluster.getPassword(), newPassword, true)).thenReturn(ambariClient);
    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);
}
Also used : Cluster(com.sequenceiq.cloudbreak.domain.Cluster) Matchers.anyString(org.mockito.Matchers.anyString) Stack(com.sequenceiq.cloudbreak.domain.Stack) AmbariClient(com.sequenceiq.ambari.client.AmbariClient) Test(org.junit.Test)

Example 90 with Cluster

use of com.sequenceiq.cloudbreak.domain.Cluster in project cloudbreak by hortonworks.

the class AmbariClusterSecurityServiceTest method testDisableSecurityWhenCancellationExceptionOccursThenShouldThrowCancellationException.

@Test
public void testDisableSecurityWhenCancellationExceptionOccursThenShouldThrowCancellationException() 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 CancellationException("cancel"));
    when(cloudbreakMessagesService.getMessage(AMBARI_CLUSTER_DISABLE_KERBEROS_FAILED.code())).thenReturn("failed");
    doThrow(new CancellationException("cancel")).when(ambariClusterConnectorPollingResultChecker).checkPollingResult(pair.getLeft(), failed);
    thrown.expect(CancellationException.class);
    thrown.expectMessage("cancel");
    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) CancellationException(com.sequenceiq.cloudbreak.cloud.scheduler.CancellationException) 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

Cluster (com.sequenceiq.cloudbreak.domain.Cluster)144 Stack (com.sequenceiq.cloudbreak.domain.Stack)68 Test (org.junit.Test)64 AmbariClient (com.sequenceiq.ambari.client.AmbariClient)31 HostGroup (com.sequenceiq.cloudbreak.domain.HostGroup)26 Blueprint (com.sequenceiq.cloudbreak.domain.Blueprint)22 CloudbreakException (com.sequenceiq.cloudbreak.service.CloudbreakException)22 HashMap (java.util.HashMap)22 HashSet (java.util.HashSet)15 List (java.util.List)15 ArrayList (java.util.ArrayList)13 HttpClientConfig (com.sequenceiq.cloudbreak.client.HttpClientConfig)12 BadRequestException (com.sequenceiq.cloudbreak.controller.BadRequestException)12 BlueprintPreparationObject (com.sequenceiq.cloudbreak.blueprint.BlueprintPreparationObject)11 Matchers.anyString (org.mockito.Matchers.anyString)11 CancellationException (com.sequenceiq.cloudbreak.cloud.scheduler.CancellationException)10 InstanceMetaData (com.sequenceiq.cloudbreak.domain.InstanceMetaData)10 InstanceGroup (com.sequenceiq.cloudbreak.domain.InstanceGroup)9 Json (com.sequenceiq.cloudbreak.domain.json.Json)9 PollingResult (com.sequenceiq.cloudbreak.service.PollingResult)9