Search in sources :

Example 6 with VolumeSetAttributes

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

the class StackDownscaleServiceTest method finishStackDownscaleAndSaveVolumeFQDNTest.

@Test
public void finishStackDownscaleAndSaveVolumeFQDNTest() throws TransactionService.TransactionExecutionException {
    StackScalingFlowContext stackScalingFlowContext = mock(StackScalingFlowContext.class);
    Stack stack = mock(Stack.class);
    when(stackScalingFlowContext.getStack()).thenReturn(stack);
    when(stackScalingFlowContext.isRepair()).thenReturn(true);
    InstanceGroup masterGroup = new InstanceGroup();
    masterGroup.setGroupName("master");
    when(stack.getInstanceGroups()).thenReturn(Set.of(masterGroup));
    InstanceMetaData master = new InstanceMetaData();
    master.setInstanceId("i-1111");
    master.setDiscoveryFQDN("master1.cloudera.site");
    master.setPrivateId(1L);
    masterGroup.setInstanceMetaData(Set.of(master));
    ArrayList<Resource> volumes = new ArrayList<>();
    Resource volume1 = new Resource();
    volumes.add(volume1);
    volume1.setInstanceId("i-1111");
    doReturn(Optional.of(new VolumeSetAttributes("az1", false, "", new ArrayList<>(), 50, "gp2"))).when(resourceAttributeUtil).getTypedAttributes(volume1, VolumeSetAttributes.class);
    when(resourceService.findByStackIdAndType(any(), any())).thenReturn(volumes);
    stackDownscaleService.finishStackDownscale(stackScalingFlowContext, Set.of(1L));
    verify(resourceService).saveAll(resourcesCaptor.capture());
    Iterable<Resource> resourcesCaptorValue = resourcesCaptor.getValue();
    Json attributes = resourcesCaptorValue.iterator().next().getAttributes();
    assertEquals("master1.cloudera.site", attributes.getValue("discoveryFQDN"));
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) Resource(com.sequenceiq.cloudbreak.domain.Resource) ArrayList(java.util.ArrayList) Json(com.sequenceiq.cloudbreak.common.json.Json) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup) VolumeSetAttributes(com.sequenceiq.cloudbreak.cloud.model.VolumeSetAttributes) Test(org.junit.jupiter.api.Test)

Example 7 with VolumeSetAttributes

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

the class InstanceMetaDataServiceTest method testGetAzFromDiskOrNullIfRepairWhenRepairAndCloudPlatformSupported.

@Test
public void testGetAzFromDiskOrNullIfRepairWhenRepairAndCloudPlatformSupported() {
    Stack stack = new Stack();
    stack.setId(1L);
    stack.setCloudPlatform(CloudPlatform.AWS.name());
    VolumeSetAttributes volumeSetAttributes = new VolumeSetAttributes("az", false, "fstab", List.of(), 10, "type");
    volumeSetAttributes.setDiscoveryFQDN("hostname");
    CloudResource cloudResource = CloudResource.builder().type(ResourceType.AWS_VOLUMESET).status(CommonStatus.DETACHED).name("name").params(Map.of(CloudResource.ATTRIBUTES, volumeSetAttributes)).build();
    when(resourceRetriever.findAllByStatusAndTypeAndStackAndInstanceGroup(CommonStatus.DETACHED, ResourceType.AWS_VOLUMESET, 1L, "ig")).thenReturn(List.of(cloudResource));
    String actual = underTest.getAzFromDiskOrNullIfRepair(stack, true, "ig", "hostname");
    assertThat(actual).isEqualTo("az");
    verify(resourceRetriever).findAllByStatusAndTypeAndStackAndInstanceGroup(CommonStatus.DETACHED, ResourceType.AWS_VOLUMESET, 1L, "ig");
}
Also used : CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) VolumeSetAttributes(com.sequenceiq.cloudbreak.cloud.model.VolumeSetAttributes) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 8 with VolumeSetAttributes

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

the class AwsVolumeResourceBuilderTest method verifyResultAndGetVolumes.

private List<VolumeSetAttributes.Volume> verifyResultAndGetVolumes(List<CloudResource> result) {
    assertThat(result).hasSize(1);
    CloudResource cloudResource = result.get(0);
    assertThat(cloudResource.getStatus()).isEqualTo(CommonStatus.CREATED);
    VolumeSetAttributes volumeSet = cloudResource.getParameter(CloudResource.ATTRIBUTES, VolumeSetAttributes.class);
    assertThat(volumeSet).isNotNull();
    List<VolumeSetAttributes.Volume> volumes = volumeSet.getVolumes();
    assertThat(volumes).isNotNull();
    return volumes;
}
Also used : Volume(com.sequenceiq.cloudbreak.cloud.model.Volume) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) VolumeSetAttributes(com.sequenceiq.cloudbreak.cloud.model.VolumeSetAttributes)

Example 9 with VolumeSetAttributes

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

the class AzureVolumeResourceBuilder method build.

@Override
public List<CloudResource> build(AzureContext context, CloudInstance instance, long privateId, AuthenticatedContext auth, Group group, List<CloudResource> buildableResource, CloudStack cloudStack) throws Exception {
    LOGGER.info("Create volumes on provider");
    AzureClient client = getAzureClient(auth);
    Map<String, List<VolumeSetAttributes.Volume>> volumeSetMap = Collections.synchronizedMap(new HashMap<>());
    List<Future<?>> futures = new ArrayList<>();
    List<CloudResource> requestedResources = buildableResource.stream().filter(cloudResource -> CommonStatus.REQUESTED.equals(cloudResource.getStatus())).collect(toList());
    CloudContext cloudContext = auth.getCloudContext();
    String resourceGroupName = azureResourceGroupMetadataProvider.getResourceGroupName(cloudContext, cloudStack);
    String region = cloudContext.getLocation().getRegion().getRegionName();
    String diskEncryptionSetId = getDiskEncryptionSetId(group);
    for (CloudResource resource : requestedResources) {
        volumeSetMap.put(resource.getName(), Collections.synchronizedList(new ArrayList<>()));
        VolumeSetAttributes volumeSet = getVolumeSetAttributes(resource);
        DeviceNameGenerator generator = new DeviceNameGenerator(DEVICE_NAME_TEMPLATE, 1);
        futures.addAll(volumeSet.getVolumes().stream().map(volume -> intermediateBuilderExecutor.submit(() -> {
            Disk result = client.getDiskByName(resourceGroupName, volume.getId());
            if (result == null) {
                result = client.createManagedDisk(volume.getId(), volume.getSize(), AzureDiskType.getByValue(volume.getType()), region, resourceGroupName, cloudStack.getTags(), diskEncryptionSetId);
            } else {
                LOGGER.info("Managed disk for resource group: {}, name: {} already exists: {}", resourceGroupName, volume.getId(), result);
            }
            String volumeId = result.id();
            volumeSetMap.get(resource.getName()).add(new VolumeSetAttributes.Volume(volumeId, generator.next(), volume.getSize(), volume.getType(), volume.getCloudVolumeUsageType()));
        })).collect(toList()));
    }
    for (Future<?> future : futures) {
        future.get();
    }
    return buildableResource.stream().peek(resource -> {
        List<VolumeSetAttributes.Volume> volumes = volumeSetMap.get(resource.getName());
        if (!CollectionUtils.isEmpty(volumes)) {
            getVolumeSetAttributes(resource).setVolumes(volumes);
        }
    }).map(copyResourceWithNewStatus(CommonStatus.CREATED)).collect(toList());
}
Also used : AzureContext(com.sequenceiq.cloudbreak.cloud.azure.context.AzureContext) VirtualMachine(com.microsoft.azure.management.compute.VirtualMachine) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) AvailabilityZoneId(com.microsoft.azure.management.resources.fluentcore.arm.AvailabilityZoneId) AsyncTaskExecutor(org.springframework.core.task.AsyncTaskExecutor) LoggerFactory(org.slf4j.LoggerFactory) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) PlatformParametersConsts(com.sequenceiq.cloudbreak.cloud.PlatformParametersConsts) DeviceNameGenerator(com.sequenceiq.cloudbreak.util.DeviceNameGenerator) Future(java.util.concurrent.Future) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) Map(java.util.Map) AzureInstanceView(com.sequenceiq.cloudbreak.cloud.azure.view.AzureInstanceView) AzureUtils(com.sequenceiq.cloudbreak.cloud.azure.AzureUtils) CommonStatus(com.sequenceiq.common.api.type.CommonStatus) ResourceStatus(com.sequenceiq.cloudbreak.cloud.model.ResourceStatus) AzureResourceGroupMetadataProvider(com.sequenceiq.cloudbreak.cloud.azure.AzureResourceGroupMetadataProvider) CloudResourceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus) AzureDiskType(com.sequenceiq.cloudbreak.cloud.azure.AzureDiskType) VolumeSetAttributes(com.sequenceiq.cloudbreak.cloud.model.VolumeSetAttributes) Collectors(java.util.stream.Collectors) Backoff(org.springframework.retry.annotation.Backoff) Objects(java.util.Objects) Disk(com.microsoft.azure.management.compute.Disk) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) List(java.util.List) CollectionUtils(org.springframework.util.CollectionUtils) Group(com.sequenceiq.cloudbreak.cloud.model.Group) Optional(java.util.Optional) AzureClient(com.sequenceiq.cloudbreak.cloud.azure.client.AzureClient) HashMap(java.util.HashMap) Image(com.sequenceiq.cloudbreak.cloud.model.Image) Function(java.util.function.Function) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) AzureResourceNameService(com.sequenceiq.cloudbreak.cloud.azure.service.AzureResourceNameService) Builder(com.sequenceiq.cloudbreak.cloud.model.CloudResource.Builder) PagedList(com.microsoft.azure.PagedList) Qualifier(org.springframework.beans.factory.annotation.Qualifier) StreamSupport(java.util.stream.StreamSupport) InstanceTemplate(com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate) Retryable(org.springframework.retry.annotation.Retryable) ResourceType(com.sequenceiq.common.api.type.ResourceType) Logger(org.slf4j.Logger) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) PersistenceNotifier(com.sequenceiq.cloudbreak.cloud.notification.PersistenceNotifier) Collectors.toList(java.util.stream.Collectors.toList) Component(org.springframework.stereotype.Component) PreserveResourceException(com.sequenceiq.cloudbreak.cloud.template.compute.PreserveResourceException) Collections(java.util.Collections) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) ArrayList(java.util.ArrayList) VolumeSetAttributes(com.sequenceiq.cloudbreak.cloud.model.VolumeSetAttributes) AzureClient(com.sequenceiq.cloudbreak.cloud.azure.client.AzureClient) Future(java.util.concurrent.Future) List(java.util.List) ArrayList(java.util.ArrayList) PagedList(com.microsoft.azure.PagedList) Collectors.toList(java.util.stream.Collectors.toList) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) Disk(com.microsoft.azure.management.compute.Disk) DeviceNameGenerator(com.sequenceiq.cloudbreak.util.DeviceNameGenerator)

Example 10 with VolumeSetAttributes

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

the class AbstractResourceConnectorTest method testDiskReattachmentWhenResourceDetachedAndHostEquals.

@Test
public void testDiskReattachmentWhenResourceDetachedAndHostEquals() {
    CloudResource cloudResource = mock(CloudResource.class);
    CloudInstance cloudInstance = mock(CloudInstance.class);
    InstanceTemplate instanceTemplate = mock(InstanceTemplate.class);
    VolumeSetAttributes volumeSetAttributes = mock(VolumeSetAttributes.class);
    when(cloudResource.getGroup()).thenReturn("groupName");
    when(cloudResource.getType()).thenReturn(ResourceType.AWS_VOLUMESET);
    when(cloudResource.getInstanceId()).thenReturn("any");
    when(cloudResource.getStatus()).thenReturn(CommonStatus.DETACHED);
    when(cloudInstance.getStringParameter(CloudInstance.FQDN)).thenReturn("fqdn");
    when(cloudInstance.getTemplate()).thenReturn(instanceTemplate);
    when(instanceTemplate.getPrivateId()).thenReturn(1L);
    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).addComputeResources(1L, List.of(cloudResource));
}
Also used : CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) InstanceTemplate(com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate) 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