Search in sources :

Example 96 with HostGroup

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

the class HostGroupRequestToHostGroupConverterTest method testConvert.

@Test
public void testConvert() {
    // GIVEN
    // WHEN
    HostGroup result = underTest.convert(getRequest("host-group.json"));
    // THEN
    assertAllFieldsNotNull(result, Arrays.asList("cluster", "instanceGroup"));
}
Also used : HostGroup(com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup) AbstractJsonConverterTest(com.sequenceiq.cloudbreak.converter.AbstractJsonConverterTest) Test(org.junit.Test)

Example 97 with HostGroup

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

the class DatahubRestResourceAuditEventConverterTest method testRequestParametersWhenStackFoundAndScaling.

@Test
public void testRequestParametersWhenStackFoundAndScaling() {
    StructuredRestCallEvent event = new StructuredRestCallEvent();
    OperationDetails operation = new OperationDetails();
    operation.setResourceName("name");
    operation.setWorkspaceId(123L);
    operation.setResourceEvent("scaling");
    event.setOperation(operation);
    RestCallDetails restCall = new RestCallDetails();
    event.setRestCall(restCall);
    RestRequestDetails restRequest = new RestRequestDetails();
    restRequest.setMethod("PUT");
    restRequest.setBody(new Json(Map.of("group", "gr", "desiredCount", 2)).getValue());
    restCall.setRestRequest(restRequest);
    Stack stack = new Stack();
    Cluster cluster = new Cluster();
    cluster.setId(345L);
    stack.setCluster(cluster);
    HostGroup hostGroup = new HostGroup();
    InstanceGroup instanceGroup = new InstanceGroup();
    hostGroup.setInstanceGroup(instanceGroup);
    Map<String, Object> params = new HashMap<>();
    when(legacyRestCommonService.addClusterCrnAndNameIfPresent(event)).thenReturn(params);
    when(stackService.findStackByNameAndWorkspaceId(operation.getResourceName(), operation.getWorkspaceId())).thenReturn(Optional.of(stack));
    when(hostGroupService.getByClusterIdAndNameWithRecipes(345L, "gr")).thenReturn(hostGroup);
    Map<String, Object> actual = underTest.requestParameters(event);
    Assertions.assertEquals(3, actual.size());
    Assertions.assertEquals(2, actual.get("desiredCount"));
    Assertions.assertEquals(0, actual.get("originalCount"));
    Assertions.assertEquals("gr", actual.get("hostGroup"));
}
Also used : HashMap(java.util.HashMap) RestRequestDetails(com.sequenceiq.cloudbreak.structuredevent.event.rest.RestRequestDetails) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) HostGroup(com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup) Json(com.sequenceiq.cloudbreak.common.json.Json) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup) StructuredRestCallEvent(com.sequenceiq.cloudbreak.structuredevent.event.StructuredRestCallEvent) OperationDetails(com.sequenceiq.cloudbreak.structuredevent.event.legacy.OperationDetails) RestCallDetails(com.sequenceiq.cloudbreak.structuredevent.event.rest.RestCallDetails) Test(org.junit.jupiter.api.Test)

Example 98 with HostGroup

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

the class ClouderaManagerDecomissionerTest method testDecommissionForNodesNowKnownByCM.

@Test
public void testDecommissionForNodesNowKnownByCM() throws ApiException {
    HostTemplatesResourceApi hostTemplatesResourceApi = mock(HostTemplatesResourceApi.class);
    ApiHostTemplateList apiHostTemplateList = new ApiHostTemplateList();
    apiHostTemplateList.setItems(new ArrayList<>());
    when(hostTemplatesResourceApi.readHostTemplates(any())).thenReturn(apiHostTemplateList);
    when(clouderaManagerApiFactory.getHostTemplatesResourceApi(client)).thenReturn(hostTemplatesResourceApi);
    HostGroup compute = new HostGroup();
    compute.setName("compute");
    HostsResourceApi hostsResourceApi = mock(HostsResourceApi.class);
    when(clouderaManagerApiFactory.getHostsResourceApi(client)).thenReturn(hostsResourceApi);
    ApiHostList apiHostList = new ApiHostList();
    apiHostList.addItemsItem(createApiHostRef("host1.example.com"));
    apiHostList.addItemsItem(createApiHostRef("host2.example.com", ApiHealthSummary.BAD));
    apiHostList.addItemsItem(createApiHostRef("host5.example.com"));
    when(hostsResourceApi.readHosts(any(), any(), any())).thenReturn(apiHostList);
    InstanceMetaData healthy1 = createInstanceMetadata(InstanceStatus.SERVICES_HEALTHY, "host1.example.com", "compute");
    InstanceMetaData bad1 = createInstanceMetadata(InstanceStatus.SERVICES_HEALTHY, "host2.example.com", "compute");
    InstanceMetaData failed1 = createInstanceMetadata(InstanceStatus.ORCHESTRATION_FAILED, "host3.example.com", "compute");
    InstanceMetaData failed2 = createInstanceMetadata(InstanceStatus.ORCHESTRATION_FAILED, "host4.example.com", "compute");
    InstanceMetaData healthy2 = createInstanceMetadata(InstanceStatus.SERVICES_HEALTHY, "host5.example.com", "compute");
    Set<InstanceMetaData> instanceMetaDataSet = Set.of(failed1, failed2, healthy1, healthy2, bad1);
    Stack stack = getStack();
    stack.setPlatformVariant("AWS");
    Set<InstanceMetaData> removableInstances = underTest.collectDownscaleCandidates(client, stack, compute, 4, instanceMetaDataSet);
    assertEquals(4, removableInstances.size());
    assertTrue(removableInstances.contains(failed1));
    assertTrue(removableInstances.contains(failed2));
    assertTrue(removableInstances.contains(healthy2));
    assertTrue(removableInstances.contains(bad1));
}
Also used : ApiHostList(com.cloudera.api.swagger.model.ApiHostList) InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) HostTemplatesResourceApi(com.cloudera.api.swagger.HostTemplatesResourceApi) HostsResourceApi(com.cloudera.api.swagger.HostsResourceApi) HostGroup(com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup) ApiHostTemplateList(com.cloudera.api.swagger.model.ApiHostTemplateList) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Test(org.junit.jupiter.api.Test)

Example 99 with HostGroup

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

the class ClouderaManagerDecommisionerTest method testVerifyNodesAreRemovableWithRepairAndReplication.

@Test
public void testVerifyNodesAreRemovableWithRepairAndReplication() 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(2, 5);
    cluster.setHostGroups(hostGroups);
    // Multimap<Long, InstanceMetaData> hostGroupWithInstances = createTestHostGroupWithInstances();
    ApiServiceConfig apiServiceConfig = createApiServiceConfigWithReplication("3", true);
    ApiHostTemplateList hostTemplates = createHostTemplatesWithDataNodes(hostGroups.stream().findFirst().get().getName());
    when(clouderaManagerApiFactory.getHostTemplatesResourceApi(Mockito.any(ApiClient.class))).thenReturn(hostTemplatesResourceApi);
    when(hostTemplatesResourceApi.readHostTemplates(stack.getName())).thenReturn(hostTemplates);
    when(resourceAttributeUtil.getTypedAttributes(stack.getDiskResources().get(0), VolumeSetAttributes.class)).thenReturn(Optional.of(volumeSetAttributes));
    when(clouderaManagerApiFactory.getServicesResourceApi(Mockito.any(ApiClient.class))).thenReturn(servicesResourceApi);
    when(servicesResourceApi.readServiceConfig(stack.getName(), "hdfs", "full")).thenReturn(apiServiceConfig);
    when(clouderaManagerApiFactory.getHostsResourceApi(Mockito.any(ApiClient.class))).thenReturn(hostsResourceApi);
    when(hostsResourceApi.readHosts(eq(null), eq(null), anyString())).thenReturn(apiHostList);
    when(apiHostList.getItems()).thenReturn(List.of());
    // WHEN
    HostGroup firstHostGroup = hostGroups.iterator().next();
    Set<InstanceMetaData> firstHostGroupInstances = firstHostGroup.getInstanceGroup().getInstanceMetaDataSet();
    Set<InstanceMetaData> removableInstances = firstHostGroupInstances.stream().limit(5).collect(Collectors.toSet());
    underTest.verifyNodesAreRemovable(stack, removableInstances, new ApiClient());
// THEN no exception
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) HostGroup(com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup) ApiClient(com.cloudera.api.swagger.client.ApiClient) ApiHostTemplateList(com.cloudera.api.swagger.model.ApiHostTemplateList) VolumeSetAttributes(com.sequenceiq.cloudbreak.cloud.model.VolumeSetAttributes) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) ApiServiceConfig(com.cloudera.api.swagger.model.ApiServiceConfig) Test(org.junit.Test)

Example 100 with HostGroup

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

the class ClouderaManagerDecommisionerTest method testVerifyNodesAreRemovableWithoutRepairWithReplicationAndTooMuchRemovableNodes.

@Test
public void testVerifyNodesAreRemovableWithoutRepairWithReplicationAndTooMuchRemovableNodes() throws ApiException {
    // GIVEN
    VolumeSetAttributes volumeSetAttributes = new VolumeSetAttributes("az", true, "fstab", List.of(), 50, "vt");
    Stack stack = createTestStack(volumeSetAttributes);
    Cluster cluster = new Cluster();
    stack.setCluster(cluster);
    Set<HostGroup> hostGroups = createTestHostGroups(2, 5);
    cluster.setHostGroups(hostGroups);
    ApiServiceConfig apiServiceConfig = createApiServiceConfigWithReplication("3", true);
    ApiHostTemplateList hostTemplates = createHostTemplatesWithDataNodes(hostGroups.stream().findFirst().get().getName());
    when(clouderaManagerApiFactory.getHostTemplatesResourceApi(Mockito.any(ApiClient.class))).thenReturn(hostTemplatesResourceApi);
    when(hostTemplatesResourceApi.readHostTemplates(stack.getName())).thenReturn(hostTemplates);
    when(resourceAttributeUtil.getTypedAttributes(stack.getDiskResources().get(0), VolumeSetAttributes.class)).thenReturn(Optional.of(volumeSetAttributes));
    when(clouderaManagerApiFactory.getServicesResourceApi(Mockito.any(ApiClient.class))).thenReturn(servicesResourceApi);
    when(servicesResourceApi.readServiceConfig(stack.getName(), "hdfs", "full")).thenReturn(apiServiceConfig);
    // WHEN
    HostGroup firstHostGroup = hostGroups.iterator().next();
    Set<InstanceMetaData> firstHostGroupInstances = firstHostGroup.getInstanceGroup().getInstanceMetaDataSet();
    Set<InstanceMetaData> removableInstances = firstHostGroupInstances.stream().limit(5).collect(Collectors.toSet());
    assertThrows(NotEnoughNodeException.class, () -> underTest.verifyNodesAreRemovable(stack, removableInstances, new ApiClient()));
// THEN no exception
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) HostGroup(com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup) ApiClient(com.cloudera.api.swagger.client.ApiClient) ApiHostTemplateList(com.cloudera.api.swagger.model.ApiHostTemplateList) VolumeSetAttributes(com.sequenceiq.cloudbreak.cloud.model.VolumeSetAttributes) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) ApiServiceConfig(com.cloudera.api.swagger.model.ApiServiceConfig) Test(org.junit.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