Search in sources :

Example 91 with Cluster

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

the class AmbariClusterSecurityServiceTest method testChangeOriginalAmbariCredentialsAndCreateCloudbreakUserWhenAdminIsTheDefinedUserThenDefaultUserDoesNotChange.

@Test
public void testChangeOriginalAmbariCredentialsAndCreateCloudbreakUserWhenAdminIsTheDefinedUserThenDefaultUserDoesNotChange() throws CloudbreakException {
    Stack stack = TestUtil.stack();
    Cluster cluster = TestUtil.cluster();
    cluster.setUserName("admin");
    cluster.setPassword("admin");
    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(ambariClient, times(0)).deleteUser("admin");
    verify(ambariClient, times(0)).changePassword(anyString(), anyString(), anyString(), anyBoolean());
}
Also used : Cluster(com.sequenceiq.cloudbreak.domain.Cluster) Stack(com.sequenceiq.cloudbreak.domain.Stack) AmbariClient(com.sequenceiq.ambari.client.AmbariClient) Test(org.junit.Test)

Example 92 with Cluster

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

use of com.sequenceiq.cloudbreak.domain.Cluster 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);
}
Also used : Cluster(com.sequenceiq.cloudbreak.domain.Cluster) Stack(com.sequenceiq.cloudbreak.domain.Stack) AmbariClient(com.sequenceiq.ambari.client.AmbariClient) Test(org.junit.Test)

Example 94 with Cluster

use of com.sequenceiq.cloudbreak.domain.Cluster 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());
}
Also used : Cluster(com.sequenceiq.cloudbreak.domain.Cluster) Stack(com.sequenceiq.cloudbreak.domain.Stack) AmbariClient(com.sequenceiq.ambari.client.AmbariClient) Test(org.junit.Test)

Example 95 with Cluster

use of com.sequenceiq.cloudbreak.domain.Cluster 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());
}
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)

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