Source:
public List<CloudResource> build(AzureContext context, 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(Collectors.toList()); CloudContext cloudContext = auth.getCloudContext(); String resourceGroupName = azureResourceGroupMetadataProvider.getResourceGroupName(cloudContext, cloudStack); String region = cloudContext.getLocation().getRegion().getRegionName(); for (CloudResource resource : requestedResources) { volumeSetMap.put(resource.getName(), Collections.synchronizedList(new ArrayList<>())); VolumeSetAttributes volumeSet = getVolumeSetAttributes(resource); DeviceNameGenerator generator = new DeviceNameGenerator(); 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()); } String volumeId = result.id(); volumeSetMap.get(resource.getName()).add(new VolumeSetAttributes.Volume(volumeId, generator.next(), volume.getSize(), volume.getType())); })) .collect(Collectors.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(Collectors.toList()); }

Target:
public List<CloudResource> build(AzureContext context, 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(Collectors.toList()); CloudContext cloudContext = auth.getCloudContext(); String resourceGroupName = azureResourceGroupMetadataProvider.getResourceGroupName(cloudContext, cloudStack); String region = cloudContext.getLocation().getRegion().getRegionName(); for (CloudResource resource : requestedResources) { volumeSetMap.put(resource.getName(), Collections.synchronizedList(new ArrayList<>())); VolumeSetAttributes volumeSet = getVolumeSetAttributes(resource); DeviceNameGenerator generator = new DeviceNameGenerator(); 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()); } else { LOGGER.debug("Managed disk for resourcegroup: {}, 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())); })) .collect(Collectors.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(Collectors.toList()); }