Search in sources :

Example 56 with HostGroup

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

the class ClouderaManagerDecommisionerTest method testCollectDownscaleCandidatesWhenOneHostDoesNotHaveFQDN.

@Test
public void testCollectDownscaleCandidatesWhenOneHostDoesNotHaveFQDN() throws ApiException {
    // GIVEN
    VolumeSetAttributes volumeSetAttributes = new VolumeSetAttributes("az", false, "fstab", List.of(), 50, "vt");
    Stack stack = createTestStack(volumeSetAttributes);
    Cluster cluster = new Cluster();
    stack.setCluster(cluster);
    Set<HostGroup> hostGroups = createTestHostGroups(1, 6);
    cluster.setHostGroups(hostGroups);
    HostGroup downscaledHostGroup = hostGroups.iterator().next();
    Optional<InstanceMetaData> hgHost2 = downscaledHostGroup.getInstanceGroup().getAllInstanceMetaData().stream().filter(instanceMetaData -> instanceMetaData.getDiscoveryFQDN().equals("hg0-host-2")).findFirst();
    hgHost2.ifPresent(instanceMetaData -> instanceMetaData.setDiscoveryFQDN(null));
    HostsResourceApi hostsResourceApi = mock(HostsResourceApi.class);
    when(clouderaManagerApiFactory.getHostsResourceApi(any(ApiClient.class))).thenReturn(hostsResourceApi);
    HostTemplatesResourceApi hostTemplatesResourceApi = mock(HostTemplatesResourceApi.class);
    when(clouderaManagerApiFactory.getHostTemplatesResourceApi(any(ApiClient.class))).thenReturn(hostTemplatesResourceApi);
    ApiHostTemplateList hostTemplates = createEmptyHostTemplates();
    when(hostTemplatesResourceApi.readHostTemplates(stack.getName())).thenReturn(hostTemplates);
    ApiHostList apiHostRefList = new ApiHostList();
    List<ApiHost> apiHosts = new ArrayList<>();
    hostGroups.stream().flatMap(hostGroup -> hostGroup.getInstanceGroup().getAllInstanceMetaData().stream()).map(InstanceMetaData::getDiscoveryFQDN).forEach(hostName -> {
        ApiHost apiHostRef = new ApiHost();
        apiHostRef.setHostname(hostName);
        apiHostRef.setHostId(hostName);
        apiHostRef.setHealthSummary(ApiHealthSummary.GOOD);
        apiHosts.add(apiHostRef);
    });
    apiHostRefList.setItems(apiHosts);
    when(hostsResourceApi.readHosts(any(), any(), any())).thenReturn(apiHostRefList);
    Set<InstanceMetaData> downscaleCandidates = underTest.collectDownscaleCandidates(mock(ApiClient.class), stack, downscaledHostGroup, -2, downscaledHostGroup.getInstanceGroup().getAllInstanceMetaData());
    assertEquals(2, downscaleCandidates.size());
    assertTrue("Assert if downscaleCandidates contains hg0-host-2, because FQDN is missing", downscaleCandidates.stream().anyMatch(instanceMetaData -> "hg0-instanceid-2".equals(instanceMetaData.getInstanceId())));
    assertTrue("Assert if downscaleCandidates contains hg0-host-5", downscaleCandidates.stream().anyMatch(instanceMetaData -> "hg0-host-5".equals(instanceMetaData.getDiscoveryFQDN())));
}
Also used : Resource(com.sequenceiq.cloudbreak.domain.Resource) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) ApiException(com.cloudera.api.swagger.client.ApiException) ApiRoleState(com.cloudera.api.swagger.model.ApiRoleState) ApiHostTemplate(com.cloudera.api.swagger.model.ApiHostTemplate) HostTemplatesResourceApi(com.cloudera.api.swagger.HostTemplatesResourceApi) ApiHostTemplateList(com.cloudera.api.swagger.model.ApiHostTemplateList) NotEnoughNodeException(com.sequenceiq.cloudbreak.cluster.service.NotEnoughNodeException) ApiConfig(com.cloudera.api.swagger.model.ApiConfig) ResourceAttributeUtil(com.sequenceiq.cloudbreak.cluster.util.ResourceAttributeUtil) HostsResourceApi(com.cloudera.api.swagger.HostsResourceApi) InstanceStatus(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus) Set(java.util.Set) VolumeSetAttributes(com.sequenceiq.cloudbreak.cloud.model.VolumeSetAttributes) Collectors(java.util.stream.Collectors) Json(com.sequenceiq.cloudbreak.common.json.Json) List(java.util.List) ApiServiceConfig(com.cloudera.api.swagger.model.ApiServiceConfig) ApiHealthSummary(com.cloudera.api.swagger.model.ApiHealthSummary) Optional(java.util.Optional) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) Mockito.mock(org.mockito.Mockito.mock) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) Mock(org.mockito.Mock) ApiClient(com.cloudera.api.swagger.client.ApiClient) RunWith(org.junit.runner.RunWith) ApiHostList(com.cloudera.api.swagger.model.ApiHostList) ServicesResourceApi(com.cloudera.api.swagger.ServicesResourceApi) ClouderaManagerPollingServiceProvider(com.sequenceiq.cloudbreak.cm.polling.ClouderaManagerPollingServiceProvider) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) ApiHost(com.cloudera.api.swagger.model.ApiHost) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) NodeIsBusyException(com.sequenceiq.cloudbreak.cluster.service.NodeIsBusyException) CloudConstants(com.sequenceiq.cloudbreak.common.type.CloudConstants) InjectMocks(org.mockito.InjectMocks) ApiRoleConfigGroupRef(com.cloudera.api.swagger.model.ApiRoleConfigGroupRef) ResourceType(com.sequenceiq.common.api.type.ResourceType) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Mockito(org.mockito.Mockito) HostGroup(com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup) InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) Assertions(org.junit.jupiter.api.Assertions) ApiRoleRef(com.cloudera.api.swagger.model.ApiRoleRef) ClouderaManagerApiFactory(com.sequenceiq.cloudbreak.cm.client.retry.ClouderaManagerApiFactory) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) HostTemplatesResourceApi(com.cloudera.api.swagger.HostTemplatesResourceApi) ArrayList(java.util.ArrayList) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) HostGroup(com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup) ApiClient(com.cloudera.api.swagger.client.ApiClient) VolumeSetAttributes(com.sequenceiq.cloudbreak.cloud.model.VolumeSetAttributes) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) ApiHostList(com.cloudera.api.swagger.model.ApiHostList) HostsResourceApi(com.cloudera.api.swagger.HostsResourceApi) ApiHostTemplateList(com.cloudera.api.swagger.model.ApiHostTemplateList) ApiHost(com.cloudera.api.swagger.model.ApiHost) Test(org.junit.Test)

Example 57 with HostGroup

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

the class ClouderaManagerClusterDecommissionServiceTest method testCollectHostsToRemove.

@Test
public void testCollectHostsToRemove() {
    HostGroup hostGroup = new HostGroup();
    Set<String> hostNames = Collections.emptySet();
    Map<String, InstanceMetaData> hosts = new HashMap<>();
    when(clouderaManagerDecomissioner.collectHostsToRemove(stack, hostGroup, hostNames, v31Client)).thenReturn(hosts);
    Map<String, InstanceMetaData> actual = underTest.collectHostsToRemove(hostGroup, hostNames);
    assertEquals(hosts, actual);
    verify(clouderaManagerDecomissioner).collectHostsToRemove(stack, hostGroup, hostNames, v31Client);
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) HashMap(java.util.HashMap) HostGroup(com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup) Test(org.junit.Test)

Example 58 with HostGroup

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

the class ClouderaManagerCommissionerTest method createHostGroup.

private HostGroup createHostGroup(Set<String> runningHostNames) {
    HostGroup hostGroup = new HostGroup();
    InstanceGroup instanceGroup = new InstanceGroup();
    Set<InstanceMetaData> instanceMetaData = createRunningInstanceMetadata(runningHostNames);
    instanceGroup.setInstanceMetaData(instanceMetaData);
    instanceGroup.setGroupName(HOSTGROUP_NAME_COMPUTE);
    hostGroup.setInstanceGroup(instanceGroup);
    hostGroup.setName(HOSTGROUP_NAME_COMPUTE);
    return hostGroup;
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) HostGroup(com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup)

Example 59 with HostGroup

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

the class ClouderaManagerCommissionerTest method testCollectHostsToCommissionMissingInCM.

@Test
public void testCollectHostsToCommissionMissingInCM() throws ApiException {
    Set<String> hostNames = createHostnames(3);
    Set<String> hostnamesKnownToCm = new HashSet<>(hostNames);
    hostnamesKnownToCm.remove(hostNames.iterator().next());
    ApiHostList apiHostList = createGoodHealthApiHostList(hostnamesKnownToCm);
    mockListClusterHosts(apiHostList);
    HostGroup hostGroup = createHostGroup(hostNames);
    Map<String, InstanceMetaData> result = underTest.collectHostsToCommission(getStack(), hostGroup, hostNames, client);
    assertEquals(2, result.size());
    assertEquals(hostnamesKnownToCm, result.keySet());
}
Also used : ApiHostList(com.cloudera.api.swagger.model.ApiHostList) InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) HostGroup(com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 60 with HostGroup

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

the class ClouderaManagerCommissionerTest method testCollectHostsToCommissionMissingInCB.

@Test
public void testCollectHostsToCommissionMissingInCB() throws ApiException {
    Set<String> hostNames = createHostnames(3);
    ApiHostList apiHostList = createGoodHealthApiHostList(hostNames);
    mockListClusterHosts(apiHostList);
    Set<String> hostnamesKnownToCb = new HashSet<>(hostNames);
    hostnamesKnownToCb.remove(hostNames.iterator().next());
    HostGroup hostGroup = createHostGroup(hostnamesKnownToCb);
    Map<String, InstanceMetaData> result = underTest.collectHostsToCommission(getStack(), hostGroup, hostNames, client);
    assertEquals(2, result.size());
    assertEquals(hostnamesKnownToCb, result.keySet());
}
Also used : ApiHostList(com.cloudera.api.swagger.model.ApiHostList) InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) HostGroup(com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Aggregations

HostGroup (com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup)132 InstanceMetaData (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData)66 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)60 HashSet (java.util.HashSet)55 Test (org.junit.jupiter.api.Test)52 List (java.util.List)50 InstanceGroup (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup)43 Cluster (com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster)37 Map (java.util.Map)37 Set (java.util.Set)37 Collectors (java.util.stream.Collectors)35 HostGroupService (com.sequenceiq.cloudbreak.service.hostgroup.HostGroupService)25 Optional (java.util.Optional)25 ArrayList (java.util.ArrayList)24 StackService (com.sequenceiq.cloudbreak.service.stack.StackService)22 InstanceStatus (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus)21 ClusterApiConnectors (com.sequenceiq.cloudbreak.service.cluster.ClusterApiConnectors)21 HashMap (java.util.HashMap)19 Logger (org.slf4j.Logger)19 LoggerFactory (org.slf4j.LoggerFactory)19