Search in sources :

Example 61 with Cluster

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

the class AmbariClusterServiceTest method setup.

@Before
public void setup() throws CloudbreakException {
    Cluster cluster = new Cluster();
    cluster.setId(1L);
    cluster.setBlueprint(new Blueprint());
    cluster.getBlueprint().setId(1L);
    Stack stack = new Stack();
    stack.setOrchestrator(new Orchestrator());
    stack.setCluster(cluster);
    when(clusterRepository.findById(any(Long.class))).thenReturn(cluster);
    when(stackService.getByIdWithLists(any(Long.class))).thenReturn(stack);
    when(orchestratorTypeResolver.resolveType(any(Orchestrator.class))).thenReturn(OrchestratorType.HOST);
    when(orchestratorTypeResolver.resolveType(anyString())).thenReturn(OrchestratorType.HOST);
    when(clusterComponentConfigProvider.getHDPRepo(any(Long.class))).thenReturn(new StackRepoDetails());
    when(clusterComponentConfigProvider.store(any(ClusterComponent.class))).thenAnswer(invocation -> invocation.getArgumentAt(0, ClusterComponent.class));
    when(clusterComponentConfigProvider.getComponent(any(Long.class), any(ComponentType.class))).thenReturn(new ClusterComponent());
    when(blueprintService.get(any(Long.class))).thenReturn(cluster.getBlueprint());
}
Also used : ComponentType(com.sequenceiq.cloudbreak.common.type.ComponentType) StackRepoDetails(com.sequenceiq.cloudbreak.cloud.model.component.StackRepoDetails) ClusterComponent(com.sequenceiq.cloudbreak.domain.ClusterComponent) Blueprint(com.sequenceiq.cloudbreak.domain.Blueprint) Cluster(com.sequenceiq.cloudbreak.domain.Cluster) Orchestrator(com.sequenceiq.cloudbreak.domain.Orchestrator) Stack(com.sequenceiq.cloudbreak.domain.Stack) Before(org.junit.Before)

Example 62 with Cluster

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

the class AmbariClientFactoryTest method testGetAmbariClientWithUsernameAndPasswordWhenEverythingWorksFine.

@Test
public void testGetAmbariClientWithUsernameAndPasswordWhenEverythingWorksFine() throws CloudbreakSecuritySetupException {
    Stack stack = TestUtil.stack();
    Cluster cluster = TestUtil.cluster();
    stack.setCluster(cluster);
    String userName = "userName";
    String password = "password";
    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(), userName, password)).thenReturn(ambariClient);
    AmbariClient defaultAmbariClient = underTest.getAmbariClient(stack, userName, password);
    Assert.assertEquals(ambariClient, defaultAmbariClient);
    verify(tlsSecurityService, times(1)).buildTLSClientConfigForPrimaryGateway(stack.getId(), stack.getAmbariIp());
    verify(ambariClientProvider, times(1)).getAmbariClient(httpClientConfig, stack.getGatewayPort(), userName, password);
}
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 63 with Cluster

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

the class AmbariClientFactoryTest method testGetAmbariClientWithUsernameAndPasswordWhenExceptionOccuredWhichIsCloudbreakSecuritySetupException.

@Test
public void testGetAmbariClientWithUsernameAndPasswordWhenExceptionOccuredWhichIsCloudbreakSecuritySetupException() throws CloudbreakSecuritySetupException {
    Stack stack = TestUtil.stack();
    Cluster cluster = TestUtil.cluster();
    String userName = "userName";
    String password = "password";
    stack.setCluster(cluster);
    HttpClientConfig httpClientConfig = new HttpClientConfig(stack.getAmbariIp());
    AmbariClient ambariClient = Mockito.mock(AmbariClient.class);
    when(tlsSecurityService.buildTLSClientConfigForPrimaryGateway(stack.getId(), stack.getAmbariIp())).thenThrow(new IllegalArgumentException("failed"));
    thrown.expect(IllegalArgumentException.class);
    thrown.expectMessage("failed");
    AmbariClient defaultAmbariClient = underTest.getAmbariClient(stack, userName, password);
    Assert.assertEquals(ambariClient, defaultAmbariClient);
    verify(tlsSecurityService, times(1)).buildTLSClientConfigForPrimaryGateway(stack.getId(), stack.getAmbariIp());
    verify(ambariClientProvider, times(0)).getAmbariClient(httpClientConfig, stack.getGatewayPort(), userName, password);
}
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 64 with Cluster

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

the class AmbariClientFactoryTest method testGetAmbariClientWhenExceptionOccuredWhichIsCloudbreakSecuritySetupException.

@Test
public void testGetAmbariClientWhenExceptionOccuredWhichIsCloudbreakSecuritySetupException() 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())).thenThrow(new IllegalArgumentException("failed"));
    thrown.expect(IllegalArgumentException.class);
    thrown.expectMessage("failed");
    AmbariClient defaultAmbariClient = underTest.getAmbariClient(stack, cluster);
    Assert.assertEquals(ambariClient, defaultAmbariClient);
    verify(tlsSecurityService, times(1)).buildTLSClientConfigForPrimaryGateway(stack.getId(), stack.getAmbariIp());
    verify(ambariClientProvider, times(0)).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 65 with Cluster

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

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