private void placeVolumeToMaskWithLeastNumberOfVolumes(URI volumeURI,Map<URI,ExportMask> placedMasks){
  log.info("These exportMasks are pointing to the same cluster: {}",placedMasks.keySet());
  int leastNumberOfVolumes=Integer.MAX_VALUE;
  Set<URI> exportMaskWithMoreVolumes=new HashSet<>();
  ExportMask currMaskWithLeastVolumes=null;
  for (  ExportMask mask : placedMasks.values()) {
    int totalVolumeCount=mask.returnTotalVolumeCount();
    if (totalVolumeCount < leastNumberOfVolumes) {
      if (currMaskWithLeastVolumes != null) {
        exportMaskWithMoreVolumes.add(currMaskWithLeastVolumes.getId());
      }
      leastNumberOfVolumes=totalVolumeCount;
      currMaskWithLeastVolumes=mask;
    }
 else {
      exportMaskWithMoreVolumes.add(mask.getId());
    }
  }
  if (currMaskWithLeastVolumes != null) {
    log.info(String.format("ExportMask %s was selected for volume %s, as it has %d total volumes",currMaskWithLeastVolumes.getId(),volumeURI,currMaskWithLeastVolumes.returnTotalVolumeCount()));
  }
  log.info("Determined that this volume {} can be unplaced from these ExportMasks: {}",volumeURI,exportMaskWithMoreVolumes);
  log.info("placeVolumeToMaskWithLeastNumberOfVolumes - PlacementDescriptor before:\n{}",placementDescriptor.toString());
  for (  URI exportMaskURI : exportMaskWithMoreVolumes) {
    placementDescriptor.unplaceVolumeFromMask(volumeURI,exportMaskURI);
  }
  log.info("placeVolumeToMaskWithLeastNumberOfVolumes - PlacementDescriptor after:\n{}",placementDescriptor.toString());
}

private void placeVolumeToMaskWithLeastNumberOfVolumes ( URI volumeURI , Map < URI , ExportMask > placedMasks ) { log . info ( "These exportMasks are pointing to the same cluster: {}" , placedMasks . keySet ( ) ) ; int leastNumberOfVolumes = Integer . MAX_VALUE ; Set < URI > exportMaskWithMoreVolumes = new HashSet < > ( ) ; ExportMask currMaskWithLeastVolumes = null ; for ( ExportMask mask : placedMasks . values ( ) ) { int totalVolumeCount = mask . returnTotalVolumeCount ( ) ; if ( totalVolumeCount < leastNumberOfVolumes ) { if ( currMaskWithLeastVolumes != null ) { exportMaskWithMoreVolumes . add ( currMaskWithLeastVolumes . getId ( ) ) ; } leastNumberOfVolumes = totalVolumeCount ; currMaskWithLeastVolumes = mask ; } else { exportMaskWithMoreVolumes . add ( mask . getId ( ) ) ; } } if ( currMaskWithLeastVolumes != null ) { log . info ( String . format ( "ExportMask %s was selected for volume %s, as it has %d total volumes" , currMaskWithLeastVolumes . getId ( ) , volumeURI , currMaskWithLeastVolumes . returnTotalVolumeCount ( ) ) ) ; } log . info ( "Determined that this volume {} can be unplaced from these ExportMasks: {}" , volumeURI , exportMaskWithMoreVolumes ) ; log . info ( "placeVolumeToMaskWithLeastNumberOfVolumes - PlacementDescriptor before:\n{}" , placementDescriptor . toString ( ) ) ; for ( URI exportMaskURI : exportMaskWithMoreVolumes ) { placementDescriptor . unplaceVolumeFromMask ( volumeURI , exportMaskURI ) ; } log . info ( "placeVolumeToMaskWithLeastNumberOfVolumes - PlacementDescriptor after:\n{}" , placementDescriptor . toString ( ) ) ; }
routine will adjust the placementdescriptor . placedvolumes , such that the volume will be placed only to one exportmask ( the one with least number of volumes ) . nb : this routine is to be run in the context of determining volumes that are placed against multiple exportmasks . the exportmasks would be pointing to the same cluster , so only a single exportmask would be required . so , the placedmasks map should contain exportmasks that point to the same vplex cluster .
