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);
}
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());
}
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);
}
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);
}
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);
}
Aggregations