Search in sources :

Example 11 with VolumeSetAttributes

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

the class ResourceUtilTest method getVolumeSetResource.

private Resource getVolumeSetResource(String instanceID, Long id) {
    Resource resource = new Resource();
    resource.setResourceType(ResourceType.AZURE_VOLUMESET);
    resource.setInstanceId(instanceID);
    resource.setId(id);
    VolumeSetAttributes volumeSetAttributes = new VolumeSetAttributes.Builder().build();
    resource.setAttributes(new Json(volumeSetAttributes));
    return resource;
}
Also used : Resource(com.sequenceiq.cloudbreak.domain.Resource) Json(com.sequenceiq.cloudbreak.common.json.Json) VolumeSetAttributes(com.sequenceiq.cloudbreak.cloud.model.VolumeSetAttributes)

Example 12 with VolumeSetAttributes

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

the class AwsRepairTest method assertVolumeResource.

private void assertVolumeResource(List<CloudResource> updatedCloudResources, String instanceId, int sizeDisk, String fstab) {
    updatedCloudResources.stream().filter(cloudResource -> instanceId.equals(cloudResource.getInstanceId())).findFirst().ifPresentOrElse(cloudResource -> {
        VolumeSetAttributes volumeSetAttributes = cloudResource.getParameter(CloudResource.ATTRIBUTES, VolumeSetAttributes.class);
        assertTrue(cloudResource.isPersistent());
        assertEquals(instanceId, cloudResource.getInstanceId());
        assertEquals(ResourceType.AWS_VOLUMESET, cloudResource.getType());
        assertEquals(WORKER_GROUP, cloudResource.getGroup());
        assertEquals(CommonStatus.CREATED, cloudResource.getStatus());
        assertEquals(AVAILABILITY_ZONE, volumeSetAttributes.getAvailabilityZone());
        assertEquals(Integer.valueOf(sizeDisk), volumeSetAttributes.getVolumes().get(0).getSize());
        assertEquals("standard", volumeSetAttributes.getVolumes().get(0).getType());
        assertEquals(fstab, volumeSetAttributes.getFstab());
    }, () -> fail("Volume resource was not saved for " + instanceId));
}
Also used : VolumeSetAttributes(com.sequenceiq.cloudbreak.cloud.model.VolumeSetAttributes)

Example 13 with VolumeSetAttributes

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

the class AzureVolumeResourceBuilderTest method deleteTestWhenDiskIsDeletedOnAzure.

@Test
public void deleteTestWhenDiskIsDeletedOnAzure() 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(VOLUME_ID, 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();
    PagedList<Disk> pagedList = mock(PagedList.class);
    when(azureClient.listDisksByResourceGroup(eq("resource-group"))).thenReturn(pagedList);
    underTest.delete(context, auth, volumeSetResource);
    verify(azureUtils, times(0)).deleteManagedDisks(any(), any());
}
Also used : Volume(com.sequenceiq.cloudbreak.cloud.model.Volume) ArrayList(java.util.ArrayList) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) Disk(com.microsoft.azure.management.compute.Disk) VolumeSetAttributes(com.sequenceiq.cloudbreak.cloud.model.VolumeSetAttributes) Test(org.junit.jupiter.api.Test)

Example 14 with VolumeSetAttributes

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

the class AzureVolumeResourceBuilderTest method verifyVolumeSetResource.

private void verifyVolumeSetResource(CloudResource resultVolumeSetResource, String diskIdExpected, String deviceExpected) {
    assertThat(resultVolumeSetResource.getType()).isEqualTo(ResourceType.AZURE_VOLUMESET);
    assertThat(resultVolumeSetResource.getStatus()).isEqualTo(CommonStatus.CREATED);
    assertThat(resultVolumeSetResource.getName()).isEqualTo(VOLUME_NAME);
    VolumeSetAttributes resultVolumeSetAttributes = resultVolumeSetResource.getParameter(CloudResource.ATTRIBUTES, VolumeSetAttributes.class);
    assertThat(resultVolumeSetAttributes).isNotNull();
    assertThat(resultVolumeSetAttributes.getAvailabilityZone()).isEqualTo(AVAILABILITY_ZONE);
    assertThat(resultVolumeSetAttributes.getDeleteOnTermination()).isEqualTo(true);
    assertThat(resultVolumeSetAttributes.getFstab()).isEqualTo(FSTAB);
    assertThat(resultVolumeSetAttributes.getVolumeSize()).isEqualTo(VOLUME_SIZE);
    assertThat(resultVolumeSetAttributes.getVolumeType()).isEqualTo(VOLUME_TYPE);
    List<VolumeSetAttributes.Volume> resultVolumes = resultVolumeSetAttributes.getVolumes();
    assertThat(resultVolumes).isNotNull();
    assertThat(resultVolumes).hasSize(1);
    VolumeSetAttributes.Volume resultVolume = resultVolumes.get(0);
    assertThat(resultVolume.getId()).isEqualTo(diskIdExpected);
    assertThat(resultVolume.getDevice()).isEqualTo(deviceExpected);
    assertThat(resultVolume.getSize()).isEqualTo(VOLUME_SIZE);
    assertThat(resultVolume.getType()).isEqualTo(VOLUME_TYPE);
    assertThat(resultVolume.getCloudVolumeUsageType()).isEqualTo(CloudVolumeUsageType.GENERAL);
}
Also used : Volume(com.sequenceiq.cloudbreak.cloud.model.Volume) VolumeSetAttributes(com.sequenceiq.cloudbreak.cloud.model.VolumeSetAttributes)

Example 15 with VolumeSetAttributes

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

the class AzureVolumeResourceBuilderTest method buildTestWhenVolumeSetExistsAndRequestedAndExistingDisk.

@Test
void buildTestWhenVolumeSetExistsAndRequestedAndExistingDisk() 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(azureClient.getDiskByName(RESOURCE_GROUP, VOLUME_ID)).thenReturn(disk);
    List<CloudResource> result = underTest.build(context, cloudInstance, PRIVATE_ID, auth, group, List.of(volumeSetResource), cloudStack);
    verify(azureClient, never()).createManagedDisk(anyString(), anyInt(), any(AzureDiskType.class), anyString(), anyString(), anyMap(), anyString());
    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) AzureDiskType(com.sequenceiq.cloudbreak.cloud.azure.AzureDiskType) 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