Search in sources :

Example 36 with ApiHost

use of com.cloudera.api.swagger.model.ApiHost in project cloudbreak by hortonworks.

the class ClouderaManagerHostStatusCheckerTest method shouldBeTrueWhenOneInstanceIsFailed.

@Test
public void shouldBeTrueWhenOneInstanceIsFailed() throws ApiException {
    InstanceMetaData instanceMetaData = validInstanceMetadata();
    InstanceMetaData instanceMetaData2 = validInstanceMetadata();
    instanceMetaData2.setPrivateIp("2.2.2.2");
    instanceMetaData2.setInstanceStatus(InstanceStatus.FAILED);
    ApiHost apiHost = getValidApiHost(instanceMetaData);
    when(hostsResourceApi.readHosts(null, null, VIEWTYPE)).thenReturn(new ApiHostList().items(List.of(apiHost)));
    boolean result = underTest.doStatusCheck(getPollerObject(instanceMetaData, instanceMetaData2));
    assertTrue(result);
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) ApiHostList(com.cloudera.api.swagger.model.ApiHostList) ApiHost(com.cloudera.api.swagger.model.ApiHost) Test(org.junit.Test)

Example 37 with ApiHost

use of com.cloudera.api.swagger.model.ApiHost in project cloudbreak by hortonworks.

the class ClouderaManagerHostStatusCheckerTest method shouldBeFalseWhenHostsReturnedHasNoHeartbeat.

@Test
public void shouldBeFalseWhenHostsReturnedHasNoHeartbeat() throws ApiException {
    InstanceMetaData instanceMetaData = validInstanceMetadata();
    ApiHost apiHost = new ApiHost().ipAddress(instanceMetaData.getPrivateIp());
    when(hostsResourceApi.readHosts(null, null, VIEWTYPE)).thenReturn(new ApiHostList().items(List.of(apiHost)));
    boolean result = underTest.doStatusCheck(getPollerObject(instanceMetaData));
    assertFalse(result);
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) ApiHostList(com.cloudera.api.swagger.model.ApiHostList) ApiHost(com.cloudera.api.swagger.model.ApiHost) Test(org.junit.Test)

Example 38 with ApiHost

use of com.cloudera.api.swagger.model.ApiHost in project cloudbreak by hortonworks.

the class ClouderaManagerDecomissionerTest method createApiHostRef.

private ApiHost createApiHostRef(String instanceFqd, ApiHealthSummary healthSummary) {
    ApiHost instanceHostRef = new ApiHost();
    instanceHostRef.setHostname(instanceFqd);
    instanceHostRef.setHostId(instanceFqd);
    instanceHostRef.setHealthSummary(healthSummary);
    return instanceHostRef;
}
Also used : ApiHost(com.cloudera.api.swagger.model.ApiHost)

Example 39 with ApiHost

use of com.cloudera.api.swagger.model.ApiHost in project cloudbreak by hortonworks.

the class ClouderaManagerDecommisionerTest method getBusyHost.

private ApiHost getBusyHost() {
    ApiHost apihost = new ApiHost();
    apihost.setHostname("hg0-host-1");
    ApiRoleRef apiroleref = new ApiRoleRef();
    apiroleref.setRoleStatus(ApiRoleState.BUSY);
    apihost.addRoleRefsItem(apiroleref);
    return apihost;
}
Also used : ApiRoleRef(com.cloudera.api.swagger.model.ApiRoleRef) ApiHost(com.cloudera.api.swagger.model.ApiHost)

Example 40 with ApiHost

use of com.cloudera.api.swagger.model.ApiHost in project cloudbreak by hortonworks.

the class ClouderaManagerDecommisionerTest method testCollectDownscaleCandidatesWhenEveryHostHasHostname.

@Test
public void testCollectDownscaleCandidatesWhenEveryHostHasHostname() 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();
    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-instanceid-4", downscaleCandidates.stream().anyMatch(instanceMetaData -> "hg0-instanceid-4".equals(instanceMetaData.getInstanceId())));
    assertTrue("Assert if downscaleCandidates contains hg0-instanceid-4", downscaleCandidates.stream().anyMatch(instanceMetaData -> "hg0-instanceid-5".equals(instanceMetaData.getInstanceId())));
}
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) ApiHostList(com.cloudera.api.swagger.model.ApiHostList) InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) HostsResourceApi(com.cloudera.api.swagger.HostsResourceApi) ApiHostTemplateList(com.cloudera.api.swagger.model.ApiHostTemplateList) ApiHost(com.cloudera.api.swagger.model.ApiHost) Test(org.junit.Test)

Aggregations

ApiHost (com.cloudera.api.swagger.model.ApiHost)49 ApiHostList (com.cloudera.api.swagger.model.ApiHostList)30 InstanceMetaData (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData)26 Test (org.junit.Test)23 HostsResourceApi (com.cloudera.api.swagger.HostsResourceApi)16 ApiException (com.cloudera.api.swagger.client.ApiException)16 List (java.util.List)14 ApiClient (com.cloudera.api.swagger.client.ApiClient)13 Set (java.util.Set)13 Collectors (java.util.stream.Collectors)13 ClouderaManagerApiFactory (com.sequenceiq.cloudbreak.cm.client.retry.ClouderaManagerApiFactory)12 ApiCommand (com.cloudera.api.swagger.model.ApiCommand)11 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)11 HostGroup (com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup)11 ApiHealthSummary (com.cloudera.api.swagger.model.ApiHealthSummary)10 ApiRoleRef (com.cloudera.api.swagger.model.ApiRoleRef)10 ClouderaManagerPollingServiceProvider (com.sequenceiq.cloudbreak.cm.polling.ClouderaManagerPollingServiceProvider)10 Logger (org.slf4j.Logger)10 LoggerFactory (org.slf4j.LoggerFactory)10 ClouderaManagerResourceApi (com.cloudera.api.swagger.ClouderaManagerResourceApi)9