Search in sources :

Example 61 with HostGroup

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

the class AmbariClusterHostServiceTypeTest method testUpdateHostsForDownscaleSelectMultipleNodesWithLessData.

@Test
public void testUpdateHostsForDownscaleSelectMultipleNodesWithLessData() throws Exception {
    HostGroupAdjustmentJson json = new HostGroupAdjustmentJson();
    json.setHostGroup("slave_1");
    json.setScalingAdjustment(-2);
    AmbariClient ambariClient = mock(AmbariClient.class);
    HostMetadata metadata1 = mock(HostMetadata.class);
    InstanceMetaData instanceMetaData1 = mock(InstanceMetaData.class);
    HostMetadata metadata2 = mock(HostMetadata.class);
    InstanceMetaData instanceMetaData2 = mock(InstanceMetaData.class);
    HostMetadata metadata3 = mock(HostMetadata.class);
    InstanceMetaData instanceMetaData3 = mock(InstanceMetaData.class);
    HostMetadata metadata4 = mock(HostMetadata.class);
    InstanceMetaData instanceMetaData4 = mock(InstanceMetaData.class);
    Set<HostMetadata> hostsMetaData = new HashSet<>();
    List<HostMetadata> hostsMetadataList = asList(metadata1, metadata2, metadata3, metadata4);
    hostsMetaData.addAll(hostsMetadataList);
    HostGroup hostGroup = new HostGroup();
    hostGroup.setHostMetadata(hostsMetaData);
    hostGroup.setName("slave_1");
    Map<String, Map<Long, Long>> dfsSpace = new HashMap<>();
    dfsSpace.put("node2", singletonMap(85_000L, 15_000L));
    dfsSpace.put("node1", singletonMap(90_000L, 10_000L));
    dfsSpace.put("node3", singletonMap(80_000L, 20_000L));
    dfsSpace.put("node4", singletonMap(90_000L, 10_000L));
    when(metadata1.getHostName()).thenReturn("node1");
    when(metadata2.getHostName()).thenReturn("node2");
    when(metadata3.getHostName()).thenReturn("node3");
    when(metadata3.getHostName()).thenReturn("node4");
    when(instanceMetaData1.getAmbariServer()).thenReturn(false);
    when(instanceMetaData2.getAmbariServer()).thenReturn(false);
    when(instanceMetaData3.getAmbariServer()).thenReturn(false);
    when(instanceMetaData4.getAmbariServer()).thenReturn(false);
    when(ambariClientProvider.getAmbariClient(any(HttpClientConfig.class), anyInt(), any(Cluster.class))).thenReturn(ambariClient);
    when(ambariClient.getComponentsCategory("multi-node-yarn", "slave_1")).thenReturn(singletonMap("DATANODE", "SLAVE"));
    when(ambariClient.getBlueprintMap(cluster.getBlueprint().getAmbariName())).thenReturn(singletonMap("slave_1", singletonList("DATANODE")));
    when(ambariClient.getDFSSpace()).thenReturn(dfsSpace);
    when(instanceMetadataRepository.findHostInStack(stack.getId(), "node1")).thenReturn(instanceMetaData1);
    when(instanceMetadataRepository.findHostInStack(stack.getId(), "node2")).thenReturn(instanceMetaData2);
    when(instanceMetadataRepository.findHostInStack(stack.getId(), "node3")).thenReturn(instanceMetaData3);
    when(instanceMetadataRepository.findHostInStack(stack.getId(), "node4")).thenReturn(instanceMetaData3);
    when(hostGroupService.getByClusterIdAndName(anyLong(), anyString())).thenReturn(hostGroup);
    when(statusToPollGroupConverter.convert(any(Status.class))).thenReturn(PollGroup.POLLABLE);
    underTest.updateHosts(stack.getId(), json);
    verify(flowManager, times(1)).triggerClusterDownscale(stack.getId(), json);
    verify(blueprintValidator, times(1)).validateHostGroupScalingRequest(stack.getCluster().getBlueprint(), hostGroup, json.getScalingAdjustment());
}
Also used : Status(com.sequenceiq.cloudbreak.api.model.Status) HttpClientConfig(com.sequenceiq.cloudbreak.client.HttpClientConfig) HashMap(java.util.HashMap) HostGroup(com.sequenceiq.cloudbreak.domain.HostGroup) Cluster(com.sequenceiq.cloudbreak.domain.Cluster) HostGroupAdjustmentJson(com.sequenceiq.cloudbreak.api.model.HostGroupAdjustmentJson) Matchers.anyString(org.mockito.Matchers.anyString) InstanceMetaData(com.sequenceiq.cloudbreak.domain.InstanceMetaData) Map(java.util.Map) HashMap(java.util.HashMap) Collections.singletonMap(java.util.Collections.singletonMap) AmbariClient(com.sequenceiq.ambari.client.AmbariClient) HostMetadata(com.sequenceiq.cloudbreak.domain.HostMetadata) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 62 with HostGroup

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

the class AmbariClusterHostServiceTypeTest method testUpdateHostsForDownscaleSelectNodesWithLessData.

@Test
public void testUpdateHostsForDownscaleSelectNodesWithLessData() throws CloudbreakSecuritySetupException {
    HostGroupAdjustmentJson json = new HostGroupAdjustmentJson();
    json.setHostGroup("slave_1");
    json.setScalingAdjustment(-1);
    AmbariClient ambariClient = mock(AmbariClient.class);
    HostMetadata metadata1 = mock(HostMetadata.class);
    InstanceMetaData instanceMetaData1 = mock(InstanceMetaData.class);
    HostMetadata metadata2 = mock(HostMetadata.class);
    InstanceMetaData instanceMetaData2 = mock(InstanceMetaData.class);
    HostMetadata metadata3 = mock(HostMetadata.class);
    InstanceMetaData instanceMetaData3 = mock(InstanceMetaData.class);
    Set<HostMetadata> hostsMetaData = new HashSet<>();
    List<HostMetadata> hostsMetadataList = asList(metadata1, metadata2, metadata3);
    hostsMetaData.addAll(hostsMetadataList);
    HostGroup hostGroup = new HostGroup();
    hostGroup.setHostMetadata(hostsMetaData);
    hostGroup.setName("slave_1");
    Map<String, Map<Long, Long>> dfsSpace = new HashMap<>();
    dfsSpace.put("node2", singletonMap(85_000L, 15_000L));
    dfsSpace.put("node1", singletonMap(90_000L, 10_000L));
    dfsSpace.put("node3", singletonMap(80_000L, 20_000L));
    when(metadata1.getHostName()).thenReturn("node1");
    when(metadata2.getHostName()).thenReturn("node2");
    when(metadata3.getHostName()).thenReturn("node3");
    when(instanceMetaData1.getAmbariServer()).thenReturn(false);
    when(instanceMetaData2.getAmbariServer()).thenReturn(false);
    when(instanceMetaData3.getAmbariServer()).thenReturn(false);
    when(ambariClientProvider.getAmbariClient(any(HttpClientConfig.class), anyInt(), any(Cluster.class))).thenReturn(ambariClient);
    when(ambariClient.getComponentsCategory("multi-node-yarn", "slave_1")).thenReturn(singletonMap("DATANODE", "SLAVE"));
    when(ambariClient.getBlueprintMap(cluster.getBlueprint().getAmbariName())).thenReturn(singletonMap("slave_1", singletonList("DATANODE")));
    when(ambariClient.getDFSSpace()).thenReturn(dfsSpace);
    when(instanceMetadataRepository.findHostInStack(stack.getId(), "node1")).thenReturn(instanceMetaData1);
    when(instanceMetadataRepository.findHostInStack(stack.getId(), "node2")).thenReturn(instanceMetaData2);
    when(instanceMetadataRepository.findHostInStack(stack.getId(), "node3")).thenReturn(instanceMetaData3);
    when(hostGroupService.getByClusterIdAndName(anyLong(), anyString())).thenReturn(hostGroup);
    when(statusToPollGroupConverter.convert(any(Status.class))).thenReturn(PollGroup.POLLABLE);
    underTest.updateHosts(stack.getId(), json);
    verify(flowManager, times(1)).triggerClusterDownscale(stack.getId(), json);
    verify(blueprintValidator, times(1)).validateHostGroupScalingRequest(stack.getCluster().getBlueprint(), hostGroup, json.getScalingAdjustment());
}
Also used : Status(com.sequenceiq.cloudbreak.api.model.Status) HttpClientConfig(com.sequenceiq.cloudbreak.client.HttpClientConfig) HashMap(java.util.HashMap) HostGroup(com.sequenceiq.cloudbreak.domain.HostGroup) Cluster(com.sequenceiq.cloudbreak.domain.Cluster) HostGroupAdjustmentJson(com.sequenceiq.cloudbreak.api.model.HostGroupAdjustmentJson) Matchers.anyString(org.mockito.Matchers.anyString) InstanceMetaData(com.sequenceiq.cloudbreak.domain.InstanceMetaData) Map(java.util.Map) HashMap(java.util.HashMap) Collections.singletonMap(java.util.Collections.singletonMap) AmbariClient(com.sequenceiq.ambari.client.AmbariClient) HostMetadata(com.sequenceiq.cloudbreak.domain.HostMetadata) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 63 with HostGroup

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

the class AmbariClusterHostServiceTypeTest method testUpdateHostsForDownscaleWhenRemainingSpaceIsNotEnough.

@Test
public void testUpdateHostsForDownscaleWhenRemainingSpaceIsNotEnough() throws Exception {
    HostGroupAdjustmentJson json = new HostGroupAdjustmentJson();
    json.setHostGroup("slave_1");
    json.setScalingAdjustment(-1);
    AmbariClient ambariClient = mock(AmbariClient.class);
    HostMetadata metadata1 = mock(HostMetadata.class);
    InstanceMetaData instanceMetaData1 = mock(InstanceMetaData.class);
    HostMetadata metadata2 = mock(HostMetadata.class);
    InstanceMetaData instanceMetaData2 = mock(InstanceMetaData.class);
    HostMetadata metadata3 = mock(HostMetadata.class);
    InstanceMetaData instanceMetaData3 = mock(InstanceMetaData.class);
    Set<HostMetadata> hostsMetaData = new HashSet<>();
    List<HostMetadata> hostsMetadataList = asList(metadata1, metadata2, metadata3);
    hostsMetaData.addAll(hostsMetadataList);
    HostGroup hostGroup = new HostGroup();
    hostGroup.setHostMetadata(hostsMetaData);
    hostGroup.setName("slave_1");
    Map<String, Map<Long, Long>> dfsSpace = new HashMap<>();
    dfsSpace.put("node2", singletonMap(5_000L, 15_000L));
    dfsSpace.put("node1", singletonMap(10_000L, 10_000L));
    dfsSpace.put("node3", singletonMap(6_000L, 20_000L));
    when(metadata1.getHostName()).thenReturn("node1");
    when(metadata2.getHostName()).thenReturn("node2");
    when(metadata3.getHostName()).thenReturn("node3");
    when(instanceMetaData1.getAmbariServer()).thenReturn(false);
    when(instanceMetaData2.getAmbariServer()).thenReturn(false);
    when(instanceMetaData3.getAmbariServer()).thenReturn(false);
    when(ambariClientProvider.getAmbariClient(any(HttpClientConfig.class), anyInt(), any(Cluster.class))).thenReturn(ambariClient);
    when(ambariClient.getComponentsCategory("multi-node-yarn", "slave_1")).thenReturn(singletonMap("DATANODE", "SLAVE"));
    when(ambariClient.getBlueprintMap(cluster.getBlueprint().getAmbariName())).thenReturn(singletonMap("slave_1", singletonList("DATANODE")));
    when(ambariClient.getDFSSpace()).thenReturn(dfsSpace);
    when(hostGroupService.getByClusterIdAndName(anyLong(), anyString())).thenReturn(hostGroup);
    when(instanceMetadataRepository.findHostInStack(stack.getId(), "node1")).thenReturn(instanceMetaData1);
    when(instanceMetadataRepository.findHostInStack(stack.getId(), "node2")).thenReturn(instanceMetaData2);
    when(instanceMetadataRepository.findHostInStack(stack.getId(), "node3")).thenReturn(instanceMetaData3);
    when(statusToPollGroupConverter.convert(any(Status.class))).thenReturn(PollGroup.POLLABLE);
    underTest.updateHosts(stack.getId(), json);
    verify(flowManager, times(1)).triggerClusterDownscale(stack.getId(), json);
    verify(blueprintValidator, times(1)).validateHostGroupScalingRequest(stack.getCluster().getBlueprint(), hostGroup, json.getScalingAdjustment());
}
Also used : Status(com.sequenceiq.cloudbreak.api.model.Status) HttpClientConfig(com.sequenceiq.cloudbreak.client.HttpClientConfig) HashMap(java.util.HashMap) HostGroup(com.sequenceiq.cloudbreak.domain.HostGroup) Cluster(com.sequenceiq.cloudbreak.domain.Cluster) HostGroupAdjustmentJson(com.sequenceiq.cloudbreak.api.model.HostGroupAdjustmentJson) Matchers.anyString(org.mockito.Matchers.anyString) InstanceMetaData(com.sequenceiq.cloudbreak.domain.InstanceMetaData) Map(java.util.Map) HashMap(java.util.HashMap) Collections.singletonMap(java.util.Collections.singletonMap) AmbariClient(com.sequenceiq.ambari.client.AmbariClient) HostMetadata(com.sequenceiq.cloudbreak.domain.HostMetadata) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 64 with HostGroup

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

the class ComponentLocatorServiceTest method createHostGroup.

private HostGroup createHostGroup(String name, String hostname) {
    HostGroup hg = new HostGroup();
    hg.setName(name);
    Constraint constraint = new Constraint();
    hg.setConstraint(constraint);
    InstanceGroup ig = new InstanceGroup();
    constraint.setInstanceGroup(ig);
    InstanceMetaData im = new InstanceMetaData();
    im.setDiscoveryFQDN(hostname);
    ig.setInstanceMetaData(ImmutableSet.of(im));
    return hg;
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.InstanceMetaData) Constraint(com.sequenceiq.cloudbreak.domain.Constraint) HostGroup(com.sequenceiq.cloudbreak.domain.HostGroup) InstanceGroup(com.sequenceiq.cloudbreak.domain.InstanceGroup)

Example 65 with HostGroup

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

the class AmbariDecommissionerTest method testVerifyNodeCountWithValidationException.

@Test
public void testVerifyNodeCountWithValidationException() throws CloudbreakSecuritySetupException {
    thrown.expect(NotEnoughNodeException.class);
    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(Collections.singleton(getHostMetadata(0L)));
    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"));
    thrown.expect(NotEnoughNodeException.class);
    thrown.expectMessage("There is not enough node to downscale. Check the replication factor and the ApplicationMaster occupation.");
    underTest.verifyNodeCount(stack, cluster, hostname);
}
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)

Aggregations

HostGroup (com.sequenceiq.cloudbreak.domain.HostGroup)94 Cluster (com.sequenceiq.cloudbreak.domain.Cluster)33 Test (org.junit.Test)33 InstanceGroup (com.sequenceiq.cloudbreak.domain.InstanceGroup)31 Blueprint (com.sequenceiq.cloudbreak.domain.Blueprint)29 HashSet (java.util.HashSet)22 JsonNode (com.fasterxml.jackson.databind.JsonNode)20 HostMetadata (com.sequenceiq.cloudbreak.domain.HostMetadata)20 List (java.util.List)20 HashMap (java.util.HashMap)19 Stack (com.sequenceiq.cloudbreak.domain.Stack)18 InstanceMetaData (com.sequenceiq.cloudbreak.domain.InstanceMetaData)16 AmbariClient (com.sequenceiq.ambari.client.AmbariClient)15 Map (java.util.Map)14 HttpClientConfig (com.sequenceiq.cloudbreak.client.HttpClientConfig)13 BadRequestException (com.sequenceiq.cloudbreak.controller.BadRequestException)12 Constraint (com.sequenceiq.cloudbreak.domain.Constraint)11 ArrayList (java.util.ArrayList)11 Set (java.util.Set)11 Inject (javax.inject.Inject)11