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);
}
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");
}
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())));
}
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);
}
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));
}
Aggregations