Search in sources :

Example 31 with VolumeSetAttributes

use of com.sequenceiq.cloudbreak.cloud.model.VolumeSetAttributes 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 32 with VolumeSetAttributes

use of com.sequenceiq.cloudbreak.cloud.model.VolumeSetAttributes 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 33 with VolumeSetAttributes

use of com.sequenceiq.cloudbreak.cloud.model.VolumeSetAttributes in project cloudbreak by hortonworks.

the class InstanceMetaDataServiceTest method testGetAzFromDiskOrNullIfRepairWhenRepairAndCloudPlatformSupportedButNoVolumeWithHostName.

@Test
public void testGetAzFromDiskOrNullIfRepairWhenRepairAndCloudPlatformSupportedButNoVolumeWithHostName() {
    Stack stack = new Stack();
    stack.setId(1L);
    stack.setCloudPlatform(CloudPlatform.AWS.name());
    VolumeSetAttributes volumeSetAttributes = new VolumeSetAttributes("az", false, "fstab", List.of(), 10, "type");
    volumeSetAttributes.setDiscoveryFQDN("any-hostname");
    CloudResource cloudResource = CloudResource.builder().type(ResourceType.AWS_VOLUMESET).status(CommonStatus.DETACHED).name("name").params(Map.of(CloudResource.ATTRIBUTES, volumeSetAttributes)).build();
    when(resourceRetriever.findAllByStatusAndTypeAndStackAndInstanceGroup(CommonStatus.DETACHED, ResourceType.AWS_VOLUMESET, 1L, "ig")).thenReturn(List.of(cloudResource));
    String actual = underTest.getAzFromDiskOrNullIfRepair(stack, true, "ig", "hostname");
    assertThat(actual).isNull();
    verify(resourceRetriever).findAllByStatusAndTypeAndStackAndInstanceGroup(CommonStatus.DETACHED, ResourceType.AWS_VOLUMESET, 1L, "ig");
}
Also used : CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) VolumeSetAttributes(com.sequenceiq.cloudbreak.cloud.model.VolumeSetAttributes) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 34 with VolumeSetAttributes

use of com.sequenceiq.cloudbreak.cloud.model.VolumeSetAttributes in project cloudbreak by hortonworks.

the class InstanceMetaDataService method getAzFromDiskOrNullIfRepair.

@VisibleForTesting
String getAzFromDiskOrNullIfRepair(Stack stack, boolean repair, String instanceGroup, String hostname) {
    String availabilityZone = null;
    if (repair) {
        ResourceType resourceType = getSupportedReattachableDiskType(stack);
        if (resourceType != null) {
            List<CloudResource> reattachableDiskResources = resourceRetriever.findAllByStatusAndTypeAndStackAndInstanceGroup(CommonStatus.DETACHED, resourceType, stack.getId(), instanceGroup);
            Optional<CloudResource> reattachableDiskResource = reattachableDiskResources.stream().filter(d -> d.getParameter(ATTRIBUTES, VolumeSetAttributes.class).getDiscoveryFQDN().equals(hostname)).findFirst();
            if (reattachableDiskResource.isPresent()) {
                VolumeSetAttributes volumeSetAttributes = reattachableDiskResource.get().getParameter(ATTRIBUTES, VolumeSetAttributes.class);
                availabilityZone = volumeSetAttributes.getAvailabilityZone();
                LOGGER.debug("Found AZ for the {}: {}", resourceType, availabilityZone);
            } else {
                LOGGER.debug("Cannot find {} for {} in instanceGroup of {}", resourceType, hostname, instanceGroup);
            }
        }
    }
    return availabilityZone;
}
Also used : Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) ATTRIBUTES(com.sequenceiq.cloudbreak.cloud.model.CloudResource.ATTRIBUTES) InstanceMetaDataRepository(com.sequenceiq.cloudbreak.repository.InstanceMetaDataRepository) Network(com.sequenceiq.cloudbreak.domain.Network) LoggerFactory(org.slf4j.LoggerFactory) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) ResourceRetriever(com.sequenceiq.cloudbreak.cloud.service.ResourceRetriever) CloudPlatform(com.sequenceiq.cloudbreak.common.mappable.CloudPlatform) Inject(javax.inject.Inject) Strings(com.google.common.base.Strings) ThreadBasedUserCrnProvider(com.sequenceiq.cloudbreak.auth.ThreadBasedUserCrnProvider) TransactionService(com.sequenceiq.cloudbreak.common.service.TransactionService) Service(org.springframework.stereotype.Service) Map(java.util.Map) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) InstanceTemplate(com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate) CommonStatus(com.sequenceiq.common.api.type.CommonStatus) ResourceType(com.sequenceiq.common.api.type.ResourceType) NetworkScaleDetails(com.sequenceiq.cloudbreak.core.flow2.dto.NetworkScaleDetails) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) Benchmark.measure(com.sequenceiq.cloudbreak.util.Benchmark.measure) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) Collection(java.util.Collection) Set(java.util.Set) PageRequest(org.springframework.data.domain.PageRequest) EnvironmentClientService(com.sequenceiq.cloudbreak.service.environment.EnvironmentClientService) AccessDeniedException(org.springframework.security.access.AccessDeniedException) Page(org.springframework.data.domain.Page) VolumeSetAttributes(com.sequenceiq.cloudbreak.cloud.model.VolumeSetAttributes) Collectors(java.util.stream.Collectors) RegionAwareInternalCrnGeneratorFactory(com.sequenceiq.cloudbreak.auth.crn.RegionAwareInternalCrnGeneratorFactory) Objects(java.util.Objects) Json(com.sequenceiq.cloudbreak.common.json.Json) List(java.util.List) MultiAzCalculatorService(com.sequenceiq.cloudbreak.service.multiaz.MultiAzCalculatorService) InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) Group(com.sequenceiq.cloudbreak.cloud.model.Group) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) Optional(java.util.Optional) StackType(com.sequenceiq.cloudbreak.api.endpoint.v4.common.StackType) VisibleForTesting(com.google.common.annotations.VisibleForTesting) StackInstanceCount(com.sequenceiq.cloudbreak.domain.projection.StackInstanceCount) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup) Collections(java.util.Collections) ResourceType(com.sequenceiq.common.api.type.ResourceType) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) VolumeSetAttributes(com.sequenceiq.cloudbreak.cloud.model.VolumeSetAttributes) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 35 with VolumeSetAttributes

use of com.sequenceiq.cloudbreak.cloud.model.VolumeSetAttributes in project cloudbreak by hortonworks.

the class VolumeMatcherTest method addVolumeResourcesToContextThrowsException.

@Test
public void addVolumeResourcesToContextThrowsException() {
    List<CloudResource> workerInstanceResources = new ArrayList<>();
    workerInstanceResources.add(CloudResource.builder().type(ResourceType.AWS_INSTANCE).status(CommonStatus.REQUESTED).name("worker1").group("worker").params(Map.of("privateId", 1L)).build());
    workerInstanceResources.add(CloudResource.builder().type(ResourceType.AWS_INSTANCE).status(CommonStatus.REQUESTED).name("worker2").group("worker").params(Map.of("privateId", 10L)).build());
    workerInstanceResources.add(CloudResource.builder().type(ResourceType.AWS_INSTANCE).status(CommonStatus.REQUESTED).name("worker3").group("worker").params(Map.of("privateId", 11L)).build());
    List<CloudResource> workerVolumeResources = new ArrayList<>();
    VolumeSetAttributes volume1attributes = new VolumeSetAttributes("az1", false, "fstab", new ArrayList<>(), 100, "general");
    volume1attributes.setDiscoveryFQDN("worker3.example.com");
    workerVolumeResources.add(CloudResource.builder().type(ResourceType.AWS_VOLUMESET).status(CommonStatus.REQUESTED).name("volume1").group("worker").params(Map.of("attributes", volume1attributes)).build());
    List<CloudInstance> workerInstances = new ArrayList<>();
    workerInstances.add(new CloudInstance(null, getInstanceTemplate(2L, "worker"), mock(InstanceAuthentication.class), "subnet1", "az1", Map.of(CloudInstance.FQDN, "worker2.example.com")));
    workerInstances.add(new CloudInstance(null, getInstanceTemplate(3L, "worker"), mock(InstanceAuthentication.class), "subnet1", "az1", Map.of(CloudInstance.FQDN, "worker3.example.com")));
    ResourceBuilderContext context = new ResourceBuilderContext("context", Location.location(Region.region("us-west-1")), 0);
    CloudConnectorException cloudConnectorException = Assert.assertThrows(CloudConnectorException.class, () -> volumeMatcher.addVolumeResourcesToContext(workerInstances, workerInstanceResources, workerVolumeResources, context));
    assertEquals("Can't find cloud instance by private ID: 2", cloudConnectorException.getMessage());
}
Also used : CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) ArrayList(java.util.ArrayList) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) VolumeSetAttributes(com.sequenceiq.cloudbreak.cloud.model.VolumeSetAttributes) Test(org.junit.jupiter.api.Test)

Aggregations

VolumeSetAttributes (com.sequenceiq.cloudbreak.cloud.model.VolumeSetAttributes)49 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)27 ArrayList (java.util.ArrayList)26 Test (org.junit.jupiter.api.Test)18 CloudInstance (com.sequenceiq.cloudbreak.cloud.model.CloudInstance)16 List (java.util.List)16 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)14 ResourceType (com.sequenceiq.common.api.type.ResourceType)14 Group (com.sequenceiq.cloudbreak.cloud.model.Group)12 InstanceTemplate (com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate)12 Volume (com.sequenceiq.cloudbreak.cloud.model.Volume)12 CommonStatus (com.sequenceiq.common.api.type.CommonStatus)12 Collectors (java.util.stream.Collectors)12 Optional (java.util.Optional)11 AuthenticatedContext (com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext)10 CloudStack (com.sequenceiq.cloudbreak.cloud.model.CloudStack)10 Resource (com.sequenceiq.cloudbreak.domain.Resource)10 InstanceMetaData (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData)10 Inject (javax.inject.Inject)10 Logger (org.slf4j.Logger)10