public static void sanitizeExportMaskContainers(DbClient dbClient,ExportMask exportMask){
  if (exportMask != null) {
    List<URI> initiatorURIs=StringSetUtil.stringSetToUriList(exportMask.getInitiators());
    List<URI> initiatorsToRemove=new ArrayList<>();
    for (    URI initiatorURI : initiatorURIs) {
      DataObject initiator=dbClient.queryObject(initiatorURI);
      if (initiator == null || initiator.getInactive()) {
        initiatorsToRemove.add(initiatorURI);
      }
    }
    if (!initiatorsToRemove.isEmpty()) {
      _log.info(String.format("sanitizeExportMaskContainers - Removing non-existent/inactive Initiators from ExportMask %s (%s): %s",exportMask.getMaskName(),exportMask.getId(),CommonTransformerFunctions.collectionToString(initiatorsToRemove)));
      exportMask.removeInitiatorURIs(initiatorsToRemove);
      exportMask.removeFromUserAddedInitiatorsByURI(initiatorsToRemove);
    }
    Map<URI,Integer> volumeMap=StringMapUtil.stringMapToVolumeMap(exportMask.getVolumes());
    List<URI> volumesToRemove=new ArrayList<>();
    for (    URI volumeURI : volumeMap.keySet()) {
      DataObject volume=dbClient.queryObject(volumeURI);
      if (volume == null || volume.getInactive()) {
        volumesToRemove.add(volumeURI);
      }
    }
    if (!volumesToRemove.isEmpty()) {
      _log.info(String.format("sanitizeExportMaskContainers - Removing non-existent/inactive BlockObjects from ExportMask %s (%s): %s",exportMask.getMaskName(),exportMask.getId(),CommonTransformerFunctions.collectionToString(volumesToRemove)));
      exportMask.removeVolumes(volumesToRemove);
      exportMask.removeFromUserAddedVolumesByURI(volumesToRemove);
    }
    List<URI> storagePorts=StringSetUtil.stringSetToUriList(exportMask.getStoragePorts());
    List<URI> storagePortsToRemove=new ArrayList<>();
    for (    URI storagePortURI : storagePorts) {
      DataObject storagePort=dbClient.queryObject(storagePortURI);
      if (storagePort == null || storagePort.getInactive()) {
        storagePortsToRemove.add(storagePortURI);
      }
    }
    if (!storagePortsToRemove.isEmpty()) {
      _log.info(String.format("sanitizeExportMaskContainers - Removing non-existent/inactive StoragePorts from ExportMask %s (%s): %s",exportMask.getMaskName(),exportMask.getId(),CommonTransformerFunctions.collectionToString(storagePortsToRemove)));
      exportMask.removeTargets(storagePortsToRemove);
    }
  }
}

public static void sanitizeExportMaskContainers ( DbClient dbClient , ExportMask exportMask ) { if ( exportMask != null ) { List < URI > initiatorURIs = StringSetUtil . stringSetToUriList ( exportMask . getInitiators ( ) ) ; List < URI > initiatorsToRemove = new ArrayList < > ( ) ; for ( URI initiatorURI : initiatorURIs ) { DataObject initiator = dbClient . queryObject ( initiatorURI ) ; if ( initiator == null || initiator . getInactive ( ) ) { initiatorsToRemove . add ( initiatorURI ) ; } } if ( ! initiatorsToRemove . isEmpty ( ) ) { _log . info ( String . format ( "sanitizeExportMaskContainers - Removing non-existent/inactive Initiators from ExportMask %s (%s): %s" , exportMask . getMaskName ( ) , exportMask . getId ( ) , CommonTransformerFunctions . collectionToString ( initiatorsToRemove ) ) ) ; exportMask . removeInitiatorURIs ( initiatorsToRemove ) ; exportMask . removeFromUserAddedInitiatorsByURI ( initiatorsToRemove ) ; } Map < URI , Integer > volumeMap = StringMapUtil . stringMapToVolumeMap ( exportMask . getVolumes ( ) ) ; List < URI > volumesToRemove = new ArrayList < > ( ) ; for ( URI volumeURI : volumeMap . keySet ( ) ) { DataObject volume = dbClient . queryObject ( volumeURI ) ; if ( volume == null || volume . getInactive ( ) ) { volumesToRemove . add ( volumeURI ) ; } } if ( ! volumesToRemove . isEmpty ( ) ) { _log . info ( String . format ( "sanitizeExportMaskContainers - Removing non-existent/inactive BlockObjects from ExportMask %s (%s): %s" , exportMask . getMaskName ( ) , exportMask . getId ( ) , CommonTransformerFunctions . collectionToString ( volumesToRemove ) ) ) ; exportMask . removeVolumes ( volumesToRemove ) ; exportMask . removeFromUserAddedVolumesByURI ( volumesToRemove ) ; } List < URI > storagePorts = StringSetUtil . stringSetToUriList ( exportMask . getStoragePorts ( ) ) ; List < URI > storagePortsToRemove = new ArrayList < > ( ) ; for ( URI storagePortURI : storagePorts ) { DataObject storagePort = dbClient . queryObject ( storagePortURI ) ; if ( storagePort == null || storagePort . getInactive ( ) ) { storagePortsToRemove . add ( storagePortURI ) ; } } if ( ! storagePortsToRemove . isEmpty ( ) ) { _log . info ( String . format ( "sanitizeExportMaskContainers - Removing non-existent/inactive StoragePorts from ExportMask %s (%s): %s" , exportMask . getMaskName ( ) , exportMask . getId ( ) , CommonTransformerFunctions . collectionToString ( storagePortsToRemove ) ) ) ; exportMask . removeTargets ( storagePortsToRemove ) ; } } }
routine will examine the exportmask and determine if any of its initiators or volumes no longer exist in the database or are marked as inactive . if so , they will get removed from the list .
