Search in sources :

Example 16 with VolumeSetAttributes

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

the class AzureVolumeResourceBuilderTest method buildTestWhenVolumeSetExistsAndRequestedAndNewDiskAndDiskEncryptionSetIdGivenButIneffective.

@Test
void buildTestWhenVolumeSetExistsAndRequestedAndNewDiskAndDiskEncryptionSetIdGivenButIneffective() throws Exception {
    initAsyncTaskExecutor();
    ArrayList<VolumeSetAttributes.Volume> volumes = new ArrayList<>();
    volumes.add(new VolumeSetAttributes.Volume(VOLUME_ID, DEVICE, VOLUME_SIZE, VOLUME_TYPE, CloudVolumeUsageType.GENERAL));
    CloudResource volumeSetResource = CloudResource.builder().type(ResourceType.AZURE_VOLUMESET).status(CommonStatus.REQUESTED).params(Map.of(CloudResource.ATTRIBUTES, new VolumeSetAttributes(AVAILABILITY_ZONE, true, FSTAB, volumes, VOLUME_SIZE, VOLUME_TYPE))).name(VOLUME_NAME).build();
    when(instanceTemplate.getStringParameter(AzureInstanceTemplate.DISK_ENCRYPTION_SET_ID)).thenReturn(DISK_ENCRYPTION_SET_ID);
    when(azureClient.createManagedDisk(VOLUME_ID, VOLUME_SIZE, AzureDiskType.STANDARD_SSD_LRS, REGION, RESOURCE_GROUP, Map.of(), null)).thenReturn(disk);
    List<CloudResource> result = underTest.build(context, cloudInstance, PRIVATE_ID, auth, group, List.of(volumeSetResource), cloudStack);
    assertThat(result).isNotNull();
    assertThat(result).hasSize(1);
    verifyVolumeSetResource(result.get(0), DISK_ID, DEVICE_DEV_SDC);
}
Also used : Volume(com.sequenceiq.cloudbreak.cloud.model.Volume) ArrayList(java.util.ArrayList) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) VolumeSetAttributes(com.sequenceiq.cloudbreak.cloud.model.VolumeSetAttributes) Test(org.junit.jupiter.api.Test)

Example 17 with VolumeSetAttributes

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

the class AzureVolumeResourceBuilderTest method deleteTestWhenDiskIsOnAzureAndNotAttached.

@Test
public void deleteTestWhenDiskIsOnAzureAndNotAttached() throws PreserveResourceException {
    CloudResource mock = CloudResource.builder().type(ResourceType.AZURE_RESOURCE_GROUP).name("resource-group").build();
    when(context.getNetworkResources()).thenReturn(List.of(mock));
    ArrayList<VolumeSetAttributes.Volume> volumes = new ArrayList<>();
    volumes.add(new VolumeSetAttributes.Volume("vol1", DEVICE, VOLUME_SIZE, "ssd", CloudVolumeUsageType.GENERAL));
    CloudResource volumeSetResource = CloudResource.builder().type(ResourceType.AZURE_VOLUMESET).status(CommonStatus.CREATED).params(Map.of(CloudResource.ATTRIBUTES, new VolumeSetAttributes(AVAILABILITY_ZONE, true, "", volumes, VOLUME_SIZE, "ssd"))).name(VOLUME_NAME).build();
    List<Disk> diskList = new ArrayList<>();
    Disk disk1 = mock(Disk.class);
    when(disk1.id()).thenReturn("vol1");
    Disk disk2 = mock(Disk.class);
    when(disk2.id()).thenReturn("vol2");
    Disk disk3 = mock(Disk.class);
    when(disk3.id()).thenReturn("vol3");
    PagedList<Disk> pagedList = mock(PagedList.class);
    diskList.add(disk1);
    diskList.add(disk2);
    diskList.add(disk3);
    Disk disk = mock(Disk.class);
    when(disk.isAttachedToVirtualMachine()).thenReturn(false);
    when(azureClient.getDiskById(any())).thenReturn(disk);
    when(pagedList.stream()).thenAnswer(invocation -> diskList.stream());
    when(azureClient.listDisksByResourceGroup(eq("resource-group"))).thenReturn(pagedList);
    underTest.delete(context, auth, volumeSetResource);
    verify(azureUtils, times(1)).deleteManagedDisks(any(), collectionCaptor.capture());
    verify(azureClient, times(0)).getVirtualMachine(any());
    verify(azureClient, times(0)).detachDiskFromVm(any(), any());
    Collection<String> deletedAzureManagedDisks = collectionCaptor.getValue();
    assertThat(deletedAzureManagedDisks).contains("vol1");
}
Also used : Volume(com.sequenceiq.cloudbreak.cloud.model.Volume) ArrayList(java.util.ArrayList) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Disk(com.microsoft.azure.management.compute.Disk) VolumeSetAttributes(com.sequenceiq.cloudbreak.cloud.model.VolumeSetAttributes) Test(org.junit.jupiter.api.Test)

Example 18 with VolumeSetAttributes

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

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

the class StackDownscaleService method fillDiscoveryFQDNForRepair.

private void fillDiscoveryFQDNForRepair(Stack stack, List<InstanceMetaData> removableInstances) {
    List<Resource> diskResources = resourceService.findByStackIdAndType(stack.getId(), stack.getDiskResourceType());
    List<String> removeableInstanceIds = removableInstances.stream().map(InstanceMetaData::getInstanceId).collect(Collectors.toList());
    for (Resource volumeSet : diskResources) {
        Optional<VolumeSetAttributes> attributes = resourceAttributeUtil.getTypedAttributes(volumeSet, VolumeSetAttributes.class);
        attributes.ifPresent(volumeSetAttributes -> fillDiscoveryFQDNInVolumeSetIfEmpty(removableInstances, removeableInstanceIds, volumeSet, volumeSetAttributes));
    }
    resourceService.saveAll(diskResources);
}
Also used : Resource(com.sequenceiq.cloudbreak.domain.Resource) VolumeSetAttributes(com.sequenceiq.cloudbreak.cloud.model.VolumeSetAttributes)

Example 20 with VolumeSetAttributes

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

the class ClusterRepairServiceTest method testRepairByNodeIds.

@Test
public void testRepairByNodeIds() {
    InstanceGroup instanceGroup = new InstanceGroup();
    instanceGroup.setInstanceGroupType(InstanceGroupType.CORE);
    HostGroup hostGroup1 = new HostGroup();
    hostGroup1.setName("hostGroup1");
    hostGroup1.setRecoveryMode(RecoveryMode.MANUAL);
    hostGroup1.setInstanceGroup(instanceGroup);
    when(hostGroupService.getByCluster(eq(1L))).thenReturn(Set.of(hostGroup1));
    when(freeipaService.checkFreeipaRunning(stack.getEnvironmentCrn())).thenReturn(true);
    when(environmentService.environmentStatusInDesiredState(stack, Set.of(EnvironmentStatus.AVAILABLE))).thenReturn(true);
    InstanceMetaData instance1md = new InstanceMetaData();
    instance1md.setInstanceId("instanceId1");
    instance1md.setDiscoveryFQDN("host1Name.healthy");
    instance1md.setInstanceGroup(instanceGroup);
    instanceGroup.setInstanceMetaData(Collections.singleton(instance1md));
    Resource volumeSet = new Resource();
    VolumeSetAttributes attributes = new VolumeSetAttributes("eu-west-1", Boolean.TRUE, "", List.of(), 100, "standard");
    attributes.setDeleteOnTermination(null);
    volumeSet.setAttributes(new Json(attributes));
    volumeSet.setInstanceId("instanceId1");
    volumeSet.setResourceType(ResourceType.AWS_VOLUMESET);
    FlowLog flowLog = new FlowLog();
    flowLog.setStateStatus(StateStatus.SUCCESSFUL);
    when(stackUpdater.updateStackStatus(1L, DetailedStackStatus.REPAIR_IN_PROGRESS)).thenReturn(stack);
    when(stackService.getByIdWithListsInTransaction(1L)).thenReturn(stack);
    when(stack.getInstanceMetaDataAsList()).thenReturn(List.of(instance1md));
    when(resourceService.findByStackIdAndType(stack.getId(), volumeSet.getResourceType())).thenReturn(List.of(volumeSet));
    when(stackStopRestrictionService.isInfrastructureStoppable(stack)).thenReturn(StopRestrictionReason.NONE);
    ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.repairNodes(1L, Set.of("instanceId1"), false, false));
    verify(resourceService).findByStackIdAndType(stack.getId(), volumeSet.getResourceType());
    @SuppressWarnings("unchecked") ArgumentCaptor<List<Resource>> saveCaptor = ArgumentCaptor.forClass(List.class);
    verify(resourceService).saveAll(saveCaptor.capture());
    assertFalse(resourceAttributeUtil.getTypedAttributes(saveCaptor.getValue().get(0), VolumeSetAttributes.class).get().getDeleteOnTermination());
    verify(flowManager).triggerClusterRepairFlow(eq(1L), eq(Map.of("hostGroup1", List.of("host1Name.healthy"))), eq(false), eq(false));
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) FlowLog(com.sequenceiq.flow.domain.FlowLog) Resource(com.sequenceiq.cloudbreak.domain.Resource) HostGroup(com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup) List(java.util.List) ArrayList(java.util.ArrayList) Json(com.sequenceiq.cloudbreak.common.json.Json) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup) 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