Search in sources :

Example 81 with Stack

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

the class AmbariDecommissionerTest method testVerifyNodeCountWithReplicationFactory.

@Test
public void testVerifyNodeCountWithReplicationFactory() throws CloudbreakSecuritySetupException {
    String hostGroupName = "hostGroupName";
    String hostname = "hostname";
    String ipAddress = "192.18.256.1";
    int gatewayPort = 1234;
    String ambariName = "ambari-name";
    Map<String, List<String>> blueprintMap = new HashMap<>();
    blueprintMap.put(hostGroupName, Collections.singletonList("DATANODE"));
    Blueprint blueprint = new Blueprint();
    blueprint.setName(ambariName);
    blueprint.setAmbariName(ambariName);
    Cluster cluster = new Cluster();
    cluster.setAmbariIp(ipAddress);
    cluster.setBlueprint(blueprint);
    Stack stack = new Stack();
    stack.setGatewayPort(gatewayPort);
    stack.setId(100L);
    HostGroup hostGroup = new HostGroup();
    hostGroup.setName(hostGroupName);
    hostGroup.setHostMetadata(Sets.newHashSet(getHostMetadata(0L), getHostMetadata(1L), getHostMetadata(2L), getHostMetadata(3L)));
    AmbariClient ambariClient = mock(AmbariClient.class);
    HttpClientConfig config = new HttpClientConfig(ipAddress);
    when(tlsSecurityService.buildTLSClientConfigForPrimaryGateway(stack.getId(), cluster.getAmbariIp())).thenReturn(config);
    when(ambariClientProvider.getAmbariClient(config, stack.getGatewayPort(), cluster)).thenReturn(ambariClient);
    when(hostGroupService.getByClusterAndHostName(cluster, hostname)).thenReturn(hostGroup);
    when(ambariClient.getBlueprintMap(ambariName)).thenReturn(blueprintMap);
    when(configurationService.getConfiguration(ambariClient, hostGroupName)).thenReturn(Collections.singletonMap(ConfigParam.DFS_REPLICATION.key(), "3"));
    underTest.verifyNodeCount(stack, cluster, hostname);
    verify(configurationService, times(1)).getConfiguration(ambariClient, hostGroupName);
}
Also used : HttpClientConfig(com.sequenceiq.cloudbreak.client.HttpClientConfig) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Blueprint(com.sequenceiq.cloudbreak.domain.Blueprint) Cluster(com.sequenceiq.cloudbreak.domain.Cluster) HostGroup(com.sequenceiq.cloudbreak.domain.HostGroup) List(java.util.List) Blueprint(com.sequenceiq.cloudbreak.domain.Blueprint) Stack(com.sequenceiq.cloudbreak.domain.Stack) AmbariClient(com.sequenceiq.ambari.client.AmbariClient) Test(org.junit.Test)

Example 82 with Stack

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

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

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

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

the class AmbariClientFactoryTest method testGetDefaultAmbariClientWhenExceptionOccuredWhichIsCloudbreakSecuritySetupException.

@Test
public void testGetDefaultAmbariClientWhenExceptionOccuredWhichIsCloudbreakSecuritySetupException() throws CloudbreakSecuritySetupException {
    Stack stack = TestUtil.stack();
    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.getDefaultAmbariClient(stack);
    Assert.assertEquals(ambariClient, defaultAmbariClient);
    verify(tlsSecurityService, times(1)).buildTLSClientConfigForPrimaryGateway(stack.getId(), stack.getAmbariIp());
    verify(ambariClientProvider, times(0)).getDefaultAmbariClient(httpClientConfig, stack.getGatewayPort());
}
Also used : HttpClientConfig(com.sequenceiq.cloudbreak.client.HttpClientConfig) Stack(com.sequenceiq.cloudbreak.domain.Stack) AmbariClient(com.sequenceiq.ambari.client.AmbariClient) Test(org.junit.Test)

Aggregations

Stack (com.sequenceiq.cloudbreak.domain.Stack)207 Cluster (com.sequenceiq.cloudbreak.domain.Cluster)74 Test (org.junit.Test)70 AmbariClient (com.sequenceiq.ambari.client.AmbariClient)32 InstanceMetaData (com.sequenceiq.cloudbreak.domain.InstanceMetaData)30 CloudbreakException (com.sequenceiq.cloudbreak.service.CloudbreakException)26 DetailedStackStatus (com.sequenceiq.cloudbreak.api.model.DetailedStackStatus)23 ArrayList (java.util.ArrayList)20 List (java.util.List)20 BadRequestException (com.sequenceiq.cloudbreak.controller.BadRequestException)18 HostGroup (com.sequenceiq.cloudbreak.domain.HostGroup)18 InstanceGroup (com.sequenceiq.cloudbreak.domain.InstanceGroup)18 HashMap (java.util.HashMap)18 HashSet (java.util.HashSet)18 Blueprint (com.sequenceiq.cloudbreak.domain.Blueprint)17 Map (java.util.Map)17 Matchers.anyString (org.mockito.Matchers.anyString)16 HostMetadata (com.sequenceiq.cloudbreak.domain.HostMetadata)15 Set (java.util.Set)15 CancellationException (com.sequenceiq.cloudbreak.cloud.scheduler.CancellationException)14