use of com.sequenceiq.ambari.client.AmbariClient in project cloudbreak by hortonworks.
the class AmbariClusterSecurityServiceTest method testChangeOriginalAmbariCredentialsAndCreateCloudbreakUserWhenAdminIsTheDefinedUserAndPasswordIsNotAdminThenTryToChangeDefaultUser.
@Test
public void testChangeOriginalAmbariCredentialsAndCreateCloudbreakUserWhenAdminIsTheDefinedUserAndPasswordIsNotAdminThenTryToChangeDefaultUser() throws CloudbreakException {
Stack stack = TestUtil.stack();
Cluster cluster = TestUtil.cluster();
cluster.setUserName("admin");
cluster.setPassword("admin1");
stack.setCluster(cluster);
AmbariClient ambariClient = Mockito.mock(AmbariClient.class);
when(clientFactory.getDefaultAmbariClient(stack)).thenReturn(ambariClient);
when(ambariSecurityConfigProvider.getAmbariUserName(cluster)).thenReturn("cloudbreak");
when(ambariSecurityConfigProvider.getAmbariPassword(cluster)).thenReturn("cloudbreak123");
when(ambariUserHandler.createAmbariUser("cloudbreak", "cloudbreak123", stack, ambariClient)).thenReturn(ambariClient);
when(ambariUserHandler.createAmbariUser(cluster.getUserName(), cluster.getPassword(), stack, ambariClient)).thenReturn(ambariClient);
when(ambariClient.deleteUser("admin")).thenReturn(ambariClient);
when(ambariClient.changePassword("admin", "admin", cluster.getPassword(), true)).thenReturn(ambariClient);
underTest.changeOriginalAmbariCredentialsAndCreateCloudbreakUser(stack);
verify(clientFactory, times(1)).getDefaultAmbariClient(stack);
verify(ambariSecurityConfigProvider, times(1)).getAmbariUserName(stack.getCluster());
verify(ambariSecurityConfigProvider, times(1)).getAmbariPassword(stack.getCluster());
verify(ambariUserHandler, times(1)).createAmbariUser("cloudbreak", "cloudbreak123", stack, ambariClient);
verify(ambariClient, times(0)).deleteUser("admin");
verify(ambariClient, times(1)).changePassword("admin", "admin", cluster.getPassword(), true);
}
use of com.sequenceiq.ambari.client.AmbariClient in project cloudbreak by hortonworks.
the class AmbariClusterSecurityServiceTest method testChangeOriginalAmbariCredentialsAndCreateCloudbreakUserWhenEverythingworksFineThenChangeDefaultUserNameAndPassword.
@Test
public void testChangeOriginalAmbariCredentialsAndCreateCloudbreakUserWhenEverythingworksFineThenChangeDefaultUserNameAndPassword() throws CloudbreakException {
Stack stack = TestUtil.stack();
Cluster cluster = TestUtil.cluster();
cluster.setUserName("admin1");
stack.setCluster(cluster);
AmbariClient ambariClient = Mockito.mock(AmbariClient.class);
when(clientFactory.getDefaultAmbariClient(stack)).thenReturn(ambariClient);
when(ambariSecurityConfigProvider.getAmbariUserName(cluster)).thenReturn("cloudbreak");
when(ambariSecurityConfigProvider.getAmbariPassword(cluster)).thenReturn("cloudbreak123");
when(ambariUserHandler.createAmbariUser("cloudbreak", "cloudbreak123", stack, ambariClient)).thenReturn(ambariClient);
when(ambariUserHandler.createAmbariUser(cluster.getUserName(), cluster.getPassword(), stack, ambariClient)).thenReturn(ambariClient);
when(ambariClient.deleteUser("admin")).thenReturn(ambariClient);
underTest.changeOriginalAmbariCredentialsAndCreateCloudbreakUser(stack);
verify(clientFactory, times(1)).getDefaultAmbariClient(stack);
verify(ambariSecurityConfigProvider, times(1)).getAmbariUserName(stack.getCluster());
verify(ambariSecurityConfigProvider, times(1)).getAmbariPassword(stack.getCluster());
verify(ambariUserHandler, times(1)).createAmbariUser("cloudbreak", "cloudbreak123", stack, ambariClient);
verify(ambariUserHandler, times(1)).createAmbariUser(cluster.getUserName(), cluster.getPassword(), stack, ambariClient);
verify(ambariClient, times(1)).deleteUser("admin");
verify(ambariClient, times(0)).changePassword(anyString(), anyString(), anyString(), anyBoolean());
}
use of com.sequenceiq.ambari.client.AmbariClient in project cloudbreak by hortonworks.
the class AmbariClusterSecurityServiceTest method testApiReplaceUserNamePasswordWhenEverythingWorks.
@Test
public void testApiReplaceUserNamePasswordWhenEverythingWorks() throws CloudbreakException {
Stack stack = TestUtil.stack();
Cluster cluster = TestUtil.cluster();
stack.setCluster(cluster);
AmbariClient ambariClient = Mockito.mock(AmbariClient.class);
String newUserName = "admin";
String newPassword = "newadmin";
when(clientFactory.getAmbariClient(stack, cluster.getUserName(), cluster.getPassword())).thenReturn(ambariClient);
when(ambariUserHandler.createAmbariUser(newUserName, newPassword, stack, ambariClient)).thenReturn(ambariClient);
when(ambariClient.deleteUser(cluster.getUserName())).thenReturn(ambariClient);
underTest.replaceUserNamePassword(stack, newUserName, newPassword);
verify(clientFactory, times(1)).getAmbariClient(stack, cluster.getUserName(), cluster.getPassword());
verify(ambariUserHandler, times(1)).createAmbariUser(newUserName, newPassword, stack, ambariClient);
verify(ambariClient, times(1)).deleteUser(cluster.getUserName());
}
use of com.sequenceiq.ambari.client.AmbariClient in project cloudbreak by hortonworks.
the class AmbariClusterSecurityServiceTest method testPrepareSecurityWhenCancellationExceptionOccursThenShouldThrowCancellationException.
@Test
public void testPrepareSecurityWhenCancellationExceptionOccursThenShouldThrowCancellationException() 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 CancellationException("cancel"));
when(cloudbreakMessagesService.getMessage(AMBARI_CLUSTER_PREPARE_DEKERBERIZING_FAILED.code())).thenReturn("failed");
doThrow(new CancellationException("cancel")).when(ambariClusterConnectorPollingResultChecker).checkPollingResult(pair.getLeft(), failed);
thrown.expect(CancellationException.class);
thrown.expectMessage("cancel");
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.ambari.client.AmbariClient in project cloudbreak by hortonworks.
the class AmbariClusterSecurityServiceTest method testDisableSecurityWhenEverythingWorks.
@Test
public void testDisableSecurityWhenEverythingWorks() 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.SUCCESS, null);
String failed = "failed";
when(ambariOperationService.waitForOperations(stack, ambariClient, operationRequests, DISABLE_KERBEROS_STATE)).thenReturn(pair);
when(cloudbreakMessagesService.getMessage(AMBARI_CLUSTER_DISABLE_KERBEROS_FAILED.code())).thenReturn("failed");
doNothing().when(ambariClusterConnectorPollingResultChecker).checkPollingResult(pair.getLeft(), 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);
}
Aggregations