Search in sources :

Example 36 with VolumeSetAttributes

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())));
}
Also used : InjectMocks(org.mockito.InjectMocks) ResourceType(com.sequenceiq.common.api.type.ResourceType) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) Region(com.sequenceiq.cloudbreak.cloud.model.Region) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) VolumeSetAttributes(com.sequenceiq.cloudbreak.cloud.model.VolumeSetAttributes) TemporaryStorage(com.sequenceiq.cloudbreak.common.type.TemporaryStorage) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) List(java.util.List) InstanceStatus(com.sequenceiq.cloudbreak.cloud.model.InstanceStatus) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Map(java.util.Map) Assertions(org.junit.jupiter.api.Assertions) Location(com.sequenceiq.cloudbreak.cloud.model.Location) InstanceAuthentication(com.sequenceiq.cloudbreak.cloud.model.InstanceAuthentication) InstanceTemplate(com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Assert(org.junit.Assert) Mockito.mock(org.mockito.Mockito.mock) CommonStatus(com.sequenceiq.common.api.type.CommonStatus) 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)

Example 37 with VolumeSetAttributes

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());
}
Also used : 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)

Example 38 with VolumeSetAttributes

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)));
        }
    }
}
Also used : Variant(com.sequenceiq.cloudbreak.cloud.model.Variant) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) LoadBalancerResourceService(com.sequenceiq.cloudbreak.cloud.template.loadbalancer.LoadBalancerResourceService) DatabaseServerCheckerService(com.sequenceiq.cloudbreak.cloud.template.compute.DatabaseServerCheckerService) LoggerFactory(org.slf4j.LoggerFactory) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) DatabaseServerTerminateService(com.sequenceiq.cloudbreak.cloud.template.compute.DatabaseServerTerminateService) ContextBuilders(com.sequenceiq.cloudbreak.cloud.template.init.ContextBuilders) DatabaseServerLaunchService(com.sequenceiq.cloudbreak.cloud.template.compute.DatabaseServerLaunchService) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Inject(javax.inject.Inject) GroupResourceService(com.sequenceiq.cloudbreak.cloud.template.group.GroupResourceService) Lists(com.google.common.collect.Lists) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) NetworkResourceService(com.sequenceiq.cloudbreak.cloud.template.network.NetworkResourceService) InstanceTemplate(com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate) DatabaseServerStopService(com.sequenceiq.cloudbreak.cloud.template.compute.DatabaseServerStopService) CommonStatus(com.sequenceiq.common.api.type.CommonStatus) ResourceStatus(com.sequenceiq.cloudbreak.cloud.model.ResourceStatus) ResourceType(com.sequenceiq.common.api.type.ResourceType) ResourceConnector(com.sequenceiq.cloudbreak.cloud.ResourceConnector) Logger(org.slf4j.Logger) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) ExternalDatabaseStatus(com.sequenceiq.cloudbreak.cloud.model.ExternalDatabaseStatus) AdjustmentTypeWithThreshold(com.sequenceiq.common.api.adjustment.AdjustmentTypeWithThreshold) Collection(java.util.Collection) CloudResourceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus) Platform(com.sequenceiq.cloudbreak.cloud.model.Platform) ResourceBuilderContext(com.sequenceiq.cloudbreak.cloud.template.context.ResourceBuilderContext) Set(java.util.Set) PersistenceNotifier(com.sequenceiq.cloudbreak.cloud.notification.PersistenceNotifier) VolumeSetAttributes(com.sequenceiq.cloudbreak.cloud.model.VolumeSetAttributes) DatabaseServerStartService(com.sequenceiq.cloudbreak.cloud.template.compute.DatabaseServerStartService) Collectors(java.util.stream.Collectors) QuotaExceededException(com.sequenceiq.cloudbreak.cloud.exception.QuotaExceededException) DatabaseStack(com.sequenceiq.cloudbreak.cloud.model.DatabaseStack) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) List(java.util.List) InstanceStatus(com.sequenceiq.cloudbreak.cloud.model.InstanceStatus) Group(com.sequenceiq.cloudbreak.cloud.model.Group) ComputeResourceService(com.sequenceiq.cloudbreak.cloud.template.compute.ComputeResourceService) StringUtils(org.springframework.util.StringUtils) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) VolumeSetAttributes(com.sequenceiq.cloudbreak.cloud.model.VolumeSetAttributes)

Example 39 with VolumeSetAttributes

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");
}
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) VirtualMachine(com.microsoft.azure.management.compute.VirtualMachine) Test(org.junit.jupiter.api.Test)

Example 40 with VolumeSetAttributes

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);
}
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)

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