use of com.sequenceiq.cloudbreak.cloud.model.VolumeSetAttributes in project cloudbreak by hortonworks.
the class VolumeMatcherTest method addVolumeResourcesToContextTest.
@Test
public void addVolumeResourcesToContextTest() {
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", 2L)).build());
workerInstanceResources.add(CloudResource.builder().type(ResourceType.AWS_INSTANCE).status(CommonStatus.REQUESTED).name("worker3").group("worker").params(Map.of("privateId", 3L)).build());
List<CloudResource> computeInstanceResources = new ArrayList<>();
computeInstanceResources.add(CloudResource.builder().type(ResourceType.AWS_INSTANCE).status(CommonStatus.REQUESTED).name("compute2").group("compute").params(Map.of("privateId", 5L)).build());
computeInstanceResources.add(CloudResource.builder().type(ResourceType.AWS_INSTANCE).status(CommonStatus.REQUESTED).name("compute3").group("compute").params(Map.of("privateId", 6L)).build());
computeInstanceResources.add(CloudResource.builder().type(ResourceType.AWS_INSTANCE).status(CommonStatus.REQUESTED).name("compute4").group("compute").params(Map.of("privateId", 7L)).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<CloudResource> computeVolumeResources = new ArrayList<>();
VolumeSetAttributes volume2attributes = new VolumeSetAttributes("az1", false, "fstab", new ArrayList<>(), 100, "general");
volume2attributes.setDiscoveryFQDN("compute2.example.com");
computeVolumeResources.add(CloudResource.builder().type(ResourceType.AWS_VOLUMESET).status(CommonStatus.REQUESTED).name("volume3").group("compute").params(Map.of("attributes", volume2attributes)).build());
VolumeSetAttributes volume3attributes = new VolumeSetAttributes("az1", false, "fstab", new ArrayList<>(), 100, "general");
volume3attributes.setDiscoveryFQDN("compute3.example.com");
computeVolumeResources.add(CloudResource.builder().type(ResourceType.AWS_VOLUMESET).status(CommonStatus.REQUESTED).name("volume4").group("compute").params(Map.of("attributes", volume3attributes)).build());
VolumeSetAttributes volume4attributes = new VolumeSetAttributes("az1", false, "fstab", new ArrayList<>(), 100, "general");
computeVolumeResources.add(CloudResource.builder().type(ResourceType.AWS_VOLUMESET).status(CommonStatus.REQUESTED).name("volume5").group("compute").params(Map.of("attributes", volume4attributes)).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")));
List<CloudInstance> computeInstances = new ArrayList<>();
computeInstances.add(new CloudInstance(null, getInstanceTemplate(5L, "compute"), mock(InstanceAuthentication.class), "subnet1", "az1", Map.of(CloudInstance.FQDN, "compute2.example.com")));
computeInstances.add(new CloudInstance(null, getInstanceTemplate(6L, "compute"), mock(InstanceAuthentication.class), "subnet1", "az1", Map.of(CloudInstance.FQDN, "compute3.example.com")));
computeInstances.add(new CloudInstance(null, getInstanceTemplate(7L, "compute"), mock(InstanceAuthentication.class), "subnet1", "az1"));
ResourceBuilderContext context = new ResourceBuilderContext("context", Location.location(Region.region("us-west-1")), 0);
volumeMatcher.addVolumeResourcesToContext(workerInstances, workerInstanceResources, workerVolumeResources, context);
Assertions.assertNull(context.getComputeResources(1L));
List<CloudResource> worker2 = context.getComputeResources(2L);
assertEquals(1, worker2.size());
Assertions.assertTrue(worker2.stream().anyMatch(cloudResource -> "worker2".equals(cloudResource.getName())));
List<CloudResource> worker3 = context.getComputeResources(3L);
assertEquals(2, worker3.size());
Assertions.assertTrue(worker3.stream().anyMatch(cloudResource -> "worker3".equals(cloudResource.getName())));
Assertions.assertTrue(worker3.stream().anyMatch(cloudResource -> "volume1".equals(cloudResource.getName())));
volumeMatcher.addVolumeResourcesToContext(computeInstances, computeInstanceResources, computeVolumeResources, context);
Assertions.assertNull(context.getComputeResources(4L));
List<CloudResource> compute2 = context.getComputeResources(5L);
assertEquals(2, compute2.size());
Assertions.assertTrue(compute2.stream().anyMatch(cloudResource -> "compute2".equals(cloudResource.getName())));
Assertions.assertTrue(compute2.stream().anyMatch(cloudResource -> "volume3".equals(cloudResource.getName())));
List<CloudResource> compute3 = context.getComputeResources(6L);
assertEquals(2, compute3.size());
Assertions.assertTrue(compute3.stream().anyMatch(cloudResource -> "compute3".equals(cloudResource.getName())));
Assertions.assertTrue(compute3.stream().anyMatch(cloudResource -> "volume4".equals(cloudResource.getName())));
}
use of com.sequenceiq.cloudbreak.cloud.model.VolumeSetAttributes in project cloudbreak by hortonworks.
the class AbstractResourceConnectorTest method testDiskReattachmentWhenInstanceEmptyButNoInstanceWithHostGroup.
@Test
public void testDiskReattachmentWhenInstanceEmptyButNoInstanceWithHostGroup() {
CloudResource cloudResource = mock(CloudResource.class);
CloudInstance cloudInstance = mock(CloudInstance.class);
VolumeSetAttributes volumeSetAttributes = mock(VolumeSetAttributes.class);
when(cloudResource.getGroup()).thenReturn("groupName");
when(cloudResource.getType()).thenReturn(ResourceType.AWS_VOLUMESET);
when(cloudResource.getInstanceId()).thenReturn(null);
when(cloudInstance.getStringParameter(CloudInstance.FQDN)).thenReturn("any-fqdn");
when(group.getName()).thenReturn("groupName");
when(group.getInstances()).thenReturn(List.of(cloudInstance));
when(cloudResource.getParameter(CloudResource.ATTRIBUTES, VolumeSetAttributes.class)).thenReturn(volumeSetAttributes);
when(volumeSetAttributes.getDiscoveryFQDN()).thenReturn("fqdn");
underTest.diskReattachment(List.of(cloudResource), group, context);
verify(context, never()).addComputeResources(any(), any());
}
use of com.sequenceiq.cloudbreak.cloud.model.VolumeSetAttributes in project cloudbreak by hortonworks.
the class AbstractResourceConnector method diskReattachment.
protected void diskReattachment(List<CloudResource> resources, Group scalingGroup, ResourceBuilderContext context) {
LOGGER.info("Disk reattachment with resources: {} for group: {}", resources, scalingGroup);
List<CloudResource> diskSets = resources.stream().filter(cloudResource -> scalingGroup.getName().equalsIgnoreCase(cloudResource.getGroup())).filter(cloudResource -> getDiskResourceType().equals(cloudResource.getType())).filter(cloudResource -> StringUtils.isEmpty(cloudResource.getInstanceId()) || CommonStatus.DETACHED.equals(cloudResource.getStatus())).collect(Collectors.toList());
for (CloudResource cloudResource : diskSets) {
VolumeSetAttributes volumeSetAttributes = cloudResource.getParameter(CloudResource.ATTRIBUTES, VolumeSetAttributes.class);
if (volumeSetAttributes != null) {
String discoveryFQDN = volumeSetAttributes.getDiscoveryFQDN();
scalingGroup.getInstances().stream().filter(cloudInstance -> discoveryFQDN.equals(cloudInstance.getStringParameter(CloudInstance.FQDN))).findFirst().map(CloudInstance::getTemplate).map(InstanceTemplate::getPrivateId).ifPresent(privateId -> context.addComputeResources(privateId, List.of(cloudResource)));
}
}
}
use of com.sequenceiq.cloudbreak.cloud.model.VolumeSetAttributes in project cloudbreak by hortonworks.
the class AzureVolumeResourceBuilderTest method deleteTestWhenDiskIsOnAzureAndAttached.
@Test
public void deleteTestWhenDiskIsOnAzureAndAttached() 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"))).instanceId("instance1").name(VOLUME_NAME).build();
List<Disk> diskList = new ArrayList<>();
Disk disk1 = mock(Disk.class);
when(disk1.id()).thenReturn("vol1");
when(disk1.isAttachedToVirtualMachine()).thenReturn(true);
Disk disk2 = mock(Disk.class);
when(disk2.id()).thenReturn("vol2");
when(disk2.isAttachedToVirtualMachine()).thenReturn(true);
Disk disk3 = mock(Disk.class);
when(disk3.id()).thenReturn("vol3");
when(disk3.isAttachedToVirtualMachine()).thenReturn(true);
PagedList<Disk> pagedList = mock(PagedList.class);
diskList.add(disk1);
diskList.add(disk2);
diskList.add(disk3);
Disk disk = mock(Disk.class);
when(disk.isAttachedToVirtualMachine()).thenReturn(true);
when(disk.virtualMachineId()).thenReturn("instance1");
when(azureClient.getDiskById(any())).thenReturn(disk);
when(pagedList.stream()).thenAnswer(invocation -> diskList.stream());
when(azureClient.listDisksByResourceGroup(eq("resource-group"))).thenReturn(pagedList);
VirtualMachine virtualMachine = mock(VirtualMachine.class);
when(azureClient.getVirtualMachine(eq("instance1"))).thenReturn(virtualMachine);
underTest.delete(context, auth, volumeSetResource);
verify(azureClient, times(1)).getVirtualMachine(eq("instance1"));
verify(azureClient, times(1)).detachDiskFromVm(eq("vol1"), eq(virtualMachine));
verify(azureUtils, times(1)).deleteManagedDisks(any(), collectionCaptor.capture());
Collection<String> deletedAzureManagedDisks = collectionCaptor.getValue();
assertThat(deletedAzureManagedDisks).contains("vol1");
}
use of com.sequenceiq.cloudbreak.cloud.model.VolumeSetAttributes in project cloudbreak by hortonworks.
the class AzureVolumeResourceBuilderTest method buildTestWhenVolumeSetExistsAndRequestedAndNewDiskAndDiskEncryptionSetIdGivenAndEffective.
@Test
void buildTestWhenVolumeSetExistsAndRequestedAndNewDiskAndDiskEncryptionSetIdGivenAndEffective() 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.getParameter(AzureInstanceTemplate.MANAGED_DISK_ENCRYPTION_WITH_CUSTOM_KEY_ENABLED, Object.class)).thenReturn(true);
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(), DISK_ENCRYPTION_SET_ID)).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);
}
Aggregations