Search in sources :

Example 11 with ApiHostTemplateList

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

the class ClouderaManagerDecommisionerTest method testVerifyNodesAreRemovableWithoutRepairAndReplication.

@Test
public void testVerifyNodesAreRemovableWithoutRepairAndReplication() 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(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(2).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 12 with ApiHostTemplateList

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

the class ClouderaManagerDecommisionerTest method testCollectDownscaleCandidatesWhenEveryHostHasHostnameButNotEnoughNodesToDownscale.

@Test
public void testCollectDownscaleCandidatesWhenEveryHostHasHostnameButNotEnoughNodesToDownscale() 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);
    assertThrows(NotEnoughNodeException.class, () -> underTest.collectDownscaleCandidates(mock(ApiClient.class), stack, downscaledHostGroup, -8, downscaledHostGroup.getInstanceGroup().getAllInstanceMetaData()));
}
Also used : HostTemplatesResourceApi(com.cloudera.api.swagger.HostTemplatesResourceApi) HostsResourceApi(com.cloudera.api.swagger.HostsResourceApi) 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) Test(org.junit.Test)

Example 13 with ApiHostTemplateList

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

the class ClouderaManagerDecomissioner method verifyNodesAreRemovable.

public void verifyNodesAreRemovable(Stack stack, Collection<InstanceMetaData> removableInstances, ApiClient client) {
    try {
        HostTemplatesResourceApi hostTemplatesResourceApi = clouderaManagerApiFactory.getHostTemplatesResourceApi(client);
        ApiHostTemplateList hostTemplates = hostTemplatesResourceApi.readHostTemplates(stack.getName());
        for (HostGroup hostGroup : stack.getCluster().getHostGroups()) {
            Set<InstanceMetaData> removableHostsInHostGroup = removableInstances.stream().filter(instanceMetaData -> instanceMetaData.getInstanceGroup().getGroupName().equals(hostGroup.getName())).collect(Collectors.toSet());
            if (!removableHostsInHostGroup.isEmpty()) {
                String hostGroupName = hostGroup.getName();
                int replication = hostGroupNodesAreDataNodes(hostTemplates, hostGroupName) ? getReplicationFactor(client, stack.getName()) : 0;
                Set<InstanceMetaData> runningInstances = hostGroup.getInstanceGroup().getRunningInstanceMetaDataSet();
                int removableSizeFromTheRunning = Math.toIntExact(removableHostsInHostGroup.stream().filter(instance -> runningInstances.contains(instance)).count());
                verifyNodeCount(replication, removableSizeFromTheRunning, runningInstances.size(), 0, stack);
                Set<String> removableInstanceFqdn = removableInstances.stream().map(InstanceMetaData::getDiscoveryFQDN).filter(org.apache.commons.lang3.StringUtils::isNoneBlank).collect(Collectors.toSet());
                verifyNodeNotBusy(removableInstanceFqdn, client);
            }
        }
    } catch (ApiException ex) {
        throw new CloudbreakServiceException("Could not verify if nodes are removable or not", ex);
    }
}
Also used : LoggerFactory(org.slf4j.LoggerFactory) ApiService(com.cloudera.api.swagger.model.ApiService) ApiRole(com.cloudera.api.swagger.model.ApiRole) ApiException(com.cloudera.api.swagger.client.ApiException) ClustersResourceApi(com.cloudera.api.swagger.ClustersResourceApi) ApiRoleState(com.cloudera.api.swagger.model.ApiRoleState) FlowMessageService(com.sequenceiq.cloudbreak.message.FlowMessageService) Map(java.util.Map) ApiHostTemplate(com.cloudera.api.swagger.model.ApiHostTemplate) ClouderaManagerResourceApi(com.cloudera.api.swagger.ClouderaManagerResourceApi) 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) ApiHostsToRemoveArgs(com.cloudera.api.swagger.model.ApiHostsToRemoveArgs) ResourceAttributeUtil(com.sequenceiq.cloudbreak.cluster.util.ResourceAttributeUtil) Collection(java.util.Collection) HostsResourceApi(com.cloudera.api.swagger.HostsResourceApi) Set(java.util.Set) Status(com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status) ExtendedPollingResult(com.sequenceiq.cloudbreak.polling.ExtendedPollingResult) ApiHostNameList(com.cloudera.api.swagger.model.ApiHostNameList) VolumeSetAttributes(com.sequenceiq.cloudbreak.cloud.model.VolumeSetAttributes) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) List(java.util.List) ApiServiceConfig(com.cloudera.api.swagger.model.ApiServiceConfig) Stream(java.util.stream.Stream) ApiHealthSummary(com.cloudera.api.swagger.model.ApiHealthSummary) Optional(java.util.Optional) CancellationException(com.sequenceiq.cloudbreak.cloud.scheduler.CancellationException) Joiner(com.google.common.base.Joiner) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) ApiCommand(com.cloudera.api.swagger.model.ApiCommand) HostServiceStatuses(com.sequenceiq.cloudbreak.cluster.status.HostServiceStatuses) HostServiceStatus(com.sequenceiq.cloudbreak.cluster.status.HostServiceStatus) ApiClient(com.cloudera.api.swagger.client.ApiClient) ApiHostList(com.cloudera.api.swagger.model.ApiHostList) Function(java.util.function.Function) ServicesResourceApi(com.cloudera.api.swagger.ServicesResourceApi) ClouderaManagerPollingServiceProvider(com.sequenceiq.cloudbreak.cm.polling.ClouderaManagerPollingServiceProvider) HashSet(java.util.HashSet) Inject(javax.inject.Inject) ApiHost(com.cloudera.api.swagger.model.ApiHost) RolesResourceApi(com.cloudera.api.swagger.RolesResourceApi) NodeIsBusyException(com.sequenceiq.cloudbreak.cluster.service.NodeIsBusyException) Logger(org.slf4j.Logger) ResourceEvent(com.sequenceiq.cloudbreak.event.ResourceEvent) Consumer(java.util.function.Consumer) HostName.hostName(com.sequenceiq.cloudbreak.cloud.model.HostName.hostName) Component(org.springframework.stereotype.Component) HostGroup(com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup) InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) CommandsResourceApi(com.cloudera.api.swagger.CommandsResourceApi) HostName(com.sequenceiq.cloudbreak.cloud.model.HostName) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) MgmtServiceResourceApi(com.cloudera.api.swagger.MgmtServiceResourceApi) Comparator(java.util.Comparator) ApiRoleRef(com.cloudera.api.swagger.model.ApiRoleRef) ApiServiceList(com.cloudera.api.swagger.model.ApiServiceList) ClouderaManagerApiFactory(com.sequenceiq.cloudbreak.cm.client.retry.ClouderaManagerApiFactory) StringUtils(org.springframework.util.StringUtils) HostTemplatesResourceApi(com.cloudera.api.swagger.HostTemplatesResourceApi) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) HostGroup(com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup) InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) ApiHostTemplateList(com.cloudera.api.swagger.model.ApiHostTemplateList) ApiException(com.cloudera.api.swagger.client.ApiException)

Example 14 with ApiHostTemplateList

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

the class ClouderaManagerDecomissioner method collectDownscaleCandidates.

public Set<InstanceMetaData> collectDownscaleCandidates(ApiClient client, Stack stack, HostGroup hostGroup, Integer scalingAdjustment, Set<InstanceMetaData> instanceMetaDatasInStack) {
    LOGGER.debug("Collecting downscale candidates");
    Set<InstanceMetaData> instancesForHostGroup = instanceMetaDatasInStack.stream().filter(instanceMetaData -> instanceMetaData.getInstanceGroup().getGroupName().equals(hostGroup.getName())).collect(Collectors.toSet());
    HostsResourceApi hostsResourceApi = clouderaManagerApiFactory.getHostsResourceApi(client);
    try {
        HostTemplatesResourceApi hostTemplatesResourceApi = clouderaManagerApiFactory.getHostTemplatesResourceApi(client);
        ApiHostTemplateList hostTemplates = hostTemplatesResourceApi.readHostTemplates(stack.getName());
        int replication = hostGroupNodesAreDataNodes(hostTemplates, hostGroup.getName()) ? getReplicationFactor(client, stack.getName()) : 0;
        verifyNodeCount(replication, scalingAdjustment, instancesForHostGroup.size(), 0, stack);
        ApiHostList hostRefList = hostsResourceApi.readHosts(null, null, SUMMARY_REQUEST_VIEW);
        Set<InstanceMetaData> instancesToRemove = getUnusedInstances(scalingAdjustment, instancesForHostGroup, hostRefList);
        List<ApiHost> apiHosts = hostRefList.getItems().stream().filter(host -> instancesForHostGroup.stream().filter(instanceMetaData -> instanceMetaData.getDiscoveryFQDN() != null).anyMatch(instanceMetaData -> instanceMetaData.getDiscoveryFQDN().equals(host.getHostname()))).collect(Collectors.toList());
        Set<String> hostsToRemove = apiHosts.stream().sorted(hostHealthComparator).limit(Math.abs(scalingAdjustment) - instancesToRemove.size()).map(ApiHost::getHostname).collect(Collectors.toSet());
        Set<InstanceMetaData> clouderaManagerNodesToRemove = instancesForHostGroup.stream().filter(instanceMetaData -> hostsToRemove.contains(instanceMetaData.getDiscoveryFQDN())).collect(Collectors.toSet());
        instancesToRemove.addAll(clouderaManagerNodesToRemove);
        LOGGER.debug("Downscale candidates: [{}]", instancesToRemove);
        return instancesToRemove;
    } catch (ApiException e) {
        LOGGER.error("Failed to get host list for cluster: {}", stack.getName(), e);
        throw new CloudbreakServiceException(e.getMessage(), e);
    }
}
Also used : LoggerFactory(org.slf4j.LoggerFactory) ApiService(com.cloudera.api.swagger.model.ApiService) ApiRole(com.cloudera.api.swagger.model.ApiRole) ApiException(com.cloudera.api.swagger.client.ApiException) ClustersResourceApi(com.cloudera.api.swagger.ClustersResourceApi) ApiRoleState(com.cloudera.api.swagger.model.ApiRoleState) FlowMessageService(com.sequenceiq.cloudbreak.message.FlowMessageService) Map(java.util.Map) ApiHostTemplate(com.cloudera.api.swagger.model.ApiHostTemplate) ClouderaManagerResourceApi(com.cloudera.api.swagger.ClouderaManagerResourceApi) 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) ApiHostsToRemoveArgs(com.cloudera.api.swagger.model.ApiHostsToRemoveArgs) ResourceAttributeUtil(com.sequenceiq.cloudbreak.cluster.util.ResourceAttributeUtil) Collection(java.util.Collection) HostsResourceApi(com.cloudera.api.swagger.HostsResourceApi) Set(java.util.Set) Status(com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status) ExtendedPollingResult(com.sequenceiq.cloudbreak.polling.ExtendedPollingResult) ApiHostNameList(com.cloudera.api.swagger.model.ApiHostNameList) VolumeSetAttributes(com.sequenceiq.cloudbreak.cloud.model.VolumeSetAttributes) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) List(java.util.List) ApiServiceConfig(com.cloudera.api.swagger.model.ApiServiceConfig) Stream(java.util.stream.Stream) ApiHealthSummary(com.cloudera.api.swagger.model.ApiHealthSummary) Optional(java.util.Optional) CancellationException(com.sequenceiq.cloudbreak.cloud.scheduler.CancellationException) Joiner(com.google.common.base.Joiner) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) ApiCommand(com.cloudera.api.swagger.model.ApiCommand) HostServiceStatuses(com.sequenceiq.cloudbreak.cluster.status.HostServiceStatuses) HostServiceStatus(com.sequenceiq.cloudbreak.cluster.status.HostServiceStatus) ApiClient(com.cloudera.api.swagger.client.ApiClient) ApiHostList(com.cloudera.api.swagger.model.ApiHostList) Function(java.util.function.Function) ServicesResourceApi(com.cloudera.api.swagger.ServicesResourceApi) ClouderaManagerPollingServiceProvider(com.sequenceiq.cloudbreak.cm.polling.ClouderaManagerPollingServiceProvider) HashSet(java.util.HashSet) Inject(javax.inject.Inject) ApiHost(com.cloudera.api.swagger.model.ApiHost) RolesResourceApi(com.cloudera.api.swagger.RolesResourceApi) NodeIsBusyException(com.sequenceiq.cloudbreak.cluster.service.NodeIsBusyException) Logger(org.slf4j.Logger) ResourceEvent(com.sequenceiq.cloudbreak.event.ResourceEvent) Consumer(java.util.function.Consumer) HostName.hostName(com.sequenceiq.cloudbreak.cloud.model.HostName.hostName) Component(org.springframework.stereotype.Component) HostGroup(com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup) InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) CommandsResourceApi(com.cloudera.api.swagger.CommandsResourceApi) HostName(com.sequenceiq.cloudbreak.cloud.model.HostName) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) MgmtServiceResourceApi(com.cloudera.api.swagger.MgmtServiceResourceApi) Comparator(java.util.Comparator) ApiRoleRef(com.cloudera.api.swagger.model.ApiRoleRef) ApiServiceList(com.cloudera.api.swagger.model.ApiServiceList) ClouderaManagerApiFactory(com.sequenceiq.cloudbreak.cm.client.retry.ClouderaManagerApiFactory) StringUtils(org.springframework.util.StringUtils) HostTemplatesResourceApi(com.cloudera.api.swagger.HostTemplatesResourceApi) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) 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) ApiException(com.cloudera.api.swagger.client.ApiException)

Aggregations

ApiHostTemplateList (com.cloudera.api.swagger.model.ApiHostTemplateList)14 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)12 HostGroup (com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup)12 ApiClient (com.cloudera.api.swagger.client.ApiClient)11 VolumeSetAttributes (com.sequenceiq.cloudbreak.cloud.model.VolumeSetAttributes)11 Cluster (com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster)9 InstanceMetaData (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData)9 Test (org.junit.Test)9 ApiServiceConfig (com.cloudera.api.swagger.model.ApiServiceConfig)8 HostTemplatesResourceApi (com.cloudera.api.swagger.HostTemplatesResourceApi)6 HostsResourceApi (com.cloudera.api.swagger.HostsResourceApi)6 ApiHostList (com.cloudera.api.swagger.model.ApiHostList)5 ApiHostTemplate (com.cloudera.api.swagger.model.ApiHostTemplate)5 NodeIsBusyException (com.sequenceiq.cloudbreak.cluster.service.NodeIsBusyException)5 ServicesResourceApi (com.cloudera.api.swagger.ServicesResourceApi)4 ApiException (com.cloudera.api.swagger.client.ApiException)4 ApiConfig (com.cloudera.api.swagger.model.ApiConfig)4 ApiHealthSummary (com.cloudera.api.swagger.model.ApiHealthSummary)4 ApiHost (com.cloudera.api.swagger.model.ApiHost)4 ApiRoleRef (com.cloudera.api.swagger.model.ApiRoleRef)4