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