private Map<URI,Map<URI,Map<String,List<URI>>>> createDeviceToCGMapFromDescriptors(List<VolumeDescriptor> addDescriptors,List<VolumeDescriptor> removeDescriptors){
  Map<URI,Map<URI,Map<String,List<URI>>>> deviceToCGMap=new HashMap<URI,Map<URI,Map<String,List<URI>>>>();
  for (  VolumeDescriptor descr : addDescriptors) {
    URI deviceURI=descr.getDeviceURI();
    Map<URI,Map<String,List<URI>>> volumesToUpdateByCG=deviceToCGMap.get(deviceURI);
    if (volumesToUpdateByCG == null) {
      volumesToUpdateByCG=new HashMap<URI,Map<String,List<URI>>>();
      deviceToCGMap.put(deviceURI,volumesToUpdateByCG);
    }
    URI consistencyGroupURI=descr.getConsistencyGroupURI();
    Map<String,List<URI>> volumesToUpdate=volumesToUpdateByCG.get(consistencyGroupURI);
    if (volumesToUpdate == null) {
      volumesToUpdate=new HashMap<String,List<URI>>();
      volumesToUpdateByCG.put(consistencyGroupURI,volumesToUpdate);
    }
    List<URI> volumesToAdd=volumesToUpdate.get(ADD_VOLUMES_TO_CG_KEY);
    if (volumesToAdd == null) {
      volumesToAdd=new ArrayList<URI>();
      volumesToUpdate.put(ADD_VOLUMES_TO_CG_KEY,volumesToAdd);
    }
    volumesToAdd.add(descr.getVolumeURI());
  }
  for (  VolumeDescriptor descr : removeDescriptors) {
    URI deviceURI=descr.getDeviceURI();
    Map<URI,Map<String,List<URI>>> volumesToUpdateByCG=deviceToCGMap.get(deviceURI);
    if (volumesToUpdateByCG == null) {
      volumesToUpdateByCG=new HashMap<URI,Map<String,List<URI>>>();
      deviceToCGMap.put(deviceURI,volumesToUpdateByCG);
    }
    URI consistencyGroupURI=descr.getConsistencyGroupURI();
    Map<String,List<URI>> volumesToUpdate=volumesToUpdateByCG.get(consistencyGroupURI);
    if (volumesToUpdate == null) {
      volumesToUpdate=new HashMap<String,List<URI>>();
      volumesToUpdateByCG.put(consistencyGroupURI,volumesToUpdate);
    }
    List<URI> volumesToRemove=volumesToUpdate.get(REMOVE_VOLUMES_FROM_CG_KEY);
    if (volumesToRemove == null) {
      volumesToRemove=new ArrayList<URI>();
      volumesToUpdate.put(REMOVE_VOLUMES_FROM_CG_KEY,volumesToRemove);
    }
    volumesToRemove.add(descr.getVolumeURI());
  }
  return deviceToCGMap;
}

private Map < URI , Map < URI , Map < String , List < URI > > > > createDeviceToCGMapFromDescriptors ( List < VolumeDescriptor > addDescriptors , List < VolumeDescriptor > removeDescriptors ) { Map < URI , Map < URI , Map < String , List < URI > > > > deviceToCGMap = new HashMap < URI , Map < URI , Map < String , List < URI > > > > ( ) ; for ( VolumeDescriptor descr : addDescriptors ) { URI deviceURI = descr . getDeviceURI ( ) ; Map < URI , Map < String , List < URI > > > volumesToUpdateByCG = deviceToCGMap . get ( deviceURI ) ; if ( volumesToUpdateByCG == null ) { volumesToUpdateByCG = new HashMap < URI , Map < String , List < URI > > > ( ) ; deviceToCGMap . put ( deviceURI , volumesToUpdateByCG ) ; } URI consistencyGroupURI = descr . getConsistencyGroupURI ( ) ; Map < String , List < URI > > volumesToUpdate = volumesToUpdateByCG . get ( consistencyGroupURI ) ; if ( volumesToUpdate == null ) { volumesToUpdate = new HashMap < String , List < URI > > ( ) ; volumesToUpdateByCG . put ( consistencyGroupURI , volumesToUpdate ) ; } List < URI > volumesToAdd = volumesToUpdate . get ( ADD_VOLUMES_TO_CG_KEY ) ; if ( volumesToAdd == null ) { volumesToAdd = new ArrayList < URI > ( ) ; volumesToUpdate . put ( ADD_VOLUMES_TO_CG_KEY , volumesToAdd ) ; } volumesToAdd . add ( descr . getVolumeURI ( ) ) ; } for ( VolumeDescriptor descr : removeDescriptors ) { URI deviceURI = descr . getDeviceURI ( ) ; Map < URI , Map < String , List < URI > > > volumesToUpdateByCG = deviceToCGMap . get ( deviceURI ) ; if ( volumesToUpdateByCG == null ) { volumesToUpdateByCG = new HashMap < URI , Map < String , List < URI > > > ( ) ; deviceToCGMap . put ( deviceURI , volumesToUpdateByCG ) ; } URI consistencyGroupURI = descr . getConsistencyGroupURI ( ) ; Map < String , List < URI > > volumesToUpdate = volumesToUpdateByCG . get ( consistencyGroupURI ) ; if ( volumesToUpdate == null ) { volumesToUpdate = new HashMap < String , List < URI > > ( ) ; volumesToUpdateByCG . put ( consistencyGroupURI , volumesToUpdate ) ; } List < URI > volumesToRemove = volumesToUpdate . get ( REMOVE_VOLUMES_FROM_CG_KEY ) ; if ( volumesToRemove == null ) { volumesToRemove = new ArrayList < URI > ( ) ; volumesToUpdate . put ( REMOVE_VOLUMES_FROM_CG_KEY , volumesToRemove ) ; } volumesToRemove . add ( descr . getVolumeURI ( ) ) ; } return deviceToCGMap ; }
convenience method to create a map device to cg to volume to add and remove . we want the map to contain both the volumes to add and remove segregated by device and also by cg . the map will look like the below : device uri - - > cg uri - - - - > add - > list of volumes to add from this cg for this device - - - - > remove - > list of volumes to remove from this cg for this device
