private void determineUnManagedExportMasksForExportInfo(com.emc.storageos.db.client.model.StorageSystem storageSystem,Map<String,List<HostExportInfo>> hostToVolumeExportInfoMap,Set<String> invalidExportHosts,DbClient dbClient,Map<URI,HostExportInfo> masksToUpdateForVolumes,List<HostExportInfo> masksToCreateForVolumes){
  for (  Map.Entry<String,List<HostExportInfo>> entry : hostToVolumeExportInfoMap.entrySet()) {
    String hostName=entry.getKey();
    log.info("Processing export info for host {} .",hostName);
    if (invalidExportHosts.contains(hostName)) {
      log.info("Found host {} in invalid hosts list. We will not process this host export data.",hostName);
      continue;
    }
    List<HostExportInfo> volumeToHostExportInfoList=entry.getValue();
    log.info("Processing export info list {} .",volumeToHostExportInfoList);
    String maskName=getUnManagedMaskName(hostName,storageSystem.getNativeGuid());
    HostExportInfo hostExportInfo=verifyHostExports(volumeToHostExportInfoList);
    if (hostExportInfo == null) {
      invalidExportHosts.add(hostName);
      log.info("Found export info for host {} invalid. We will not process this host export data.",hostName);
      UnManagedExportMask unManagedMask=getUnManagedExportMask(maskName,dbClient,storageSystem.getId());
      if (unManagedMask != null) {
        log.info("Found existing unmanaged export mask for host {} and array {} --- {} . We will deactivate this mask.",hostName,storageSystem.getNativeId(),unManagedMask);
        removeInvalidMaskDataFromVolumes(unManagedMask,dbClient);
        unManagedMask.setInactive(true);
        dbClient.updateObject(unManagedMask);
      }
      continue;
    }
    log.info("The result export info for host {} and array {} : {} .",hostName,storageSystem.getNativeId(),hostExportInfo);
    UnManagedExportMask unManagedMask=getUnManagedExportMask(maskName,dbClient,storageSystem.getId());
    boolean isValid=true;
    if (unManagedMask != null) {
      log.info("Found existing unmanaged export mask for host {} and array {} --- {} .",hostName,storageSystem.getNativeId(),unManagedMask);
      StringSet storagePortsUris=unManagedMask.getKnownStoragePortUris();
      Set<String> storagePortsNativeIds=new HashSet<>();
      Set<String> initiatorsNativeIds=new HashSet<>();
      for (      String portUriString : storagePortsUris) {
        URI portUri=URI.create(portUriString);
        com.emc.storageos.db.client.model.StoragePort port=dbClient.queryObject(com.emc.storageos.db.client.model.StoragePort.class,portUri);
        storagePortsNativeIds.add(port.getNativeId());
      }
      storagePortsNativeIds.addAll(unManagedMask.getUnmanagedStoragePortNetworkIds());
      initiatorsNativeIds.addAll(unManagedMask.getKnownInitiatorNetworkIds());
      initiatorsNativeIds.addAll(unManagedMask.getUnmanagedInitiatorNetworkIds());
      isValid=verifyHostExports(initiatorsNativeIds,storagePortsNativeIds,hostExportInfo);
      if (!isValid) {
        log.info("The result export info for host {} and storage array {} does not comply with existing mask.",hostName,storageSystem.getNativeId());
        removeInvalidMaskDataFromVolumes(unManagedMask,dbClient);
        unManagedMask.setInactive(true);
        dbClient.updateObject(unManagedMask);
      }
    }
 else {
      log.info("There is no existing unmanaged export mask for host {} and array {} .",hostName,storageSystem.getNativeId());
      List<String> initiatorPorts=new ArrayList<>();
      for (      Initiator initiator : hostExportInfo.getInitiators()) {
        initiatorPorts.add(initiator.getPort());
      }
      Map<URI,ExportMask> uriToExportMask=ExportMaskUtils.getExportMasksWithInitiatorPorts(dbClient,initiatorPorts);
      for (      ExportMask mask : uriToExportMask.values()) {
        if (URIUtil.identical(mask.getStorageDevice(),storageSystem.getId())) {
          isValid=false;
          log.info("Found managed export mask for host {} and array {} --- {}." + " We will not process this host export data.",hostName,storageSystem.getNativeId(),mask.getId());
          break;
        }
      }
    }
    if (!isValid) {
      log.info("Found export info for host {} invalid. Export info: {}." + " We will not process this host export data.",hostName,hostExportInfo);
      invalidExportHosts.add(hostName);
      continue;
    }
    if (unManagedMask != null) {
      URI maskId=unManagedMask.getId();
      masksToUpdateForVolumes.put(maskId,hostExportInfo);
    }
 else {
      masksToCreateForVolumes.add(hostExportInfo);
    }
  }
}

private void determineUnManagedExportMasksForExportInfo ( com . emc . storageos . db . client . model . StorageSystem storageSystem , Map < String , List < HostExportInfo > > hostToVolumeExportInfoMap , Set < String > invalidExportHosts , DbClient dbClient , Map < URI , HostExportInfo > masksToUpdateForVolumes , List < HostExportInfo > masksToCreateForVolumes ) { for ( Map . Entry < String , List < HostExportInfo > > entry : hostToVolumeExportInfoMap . entrySet ( ) ) { String hostName = entry . getKey ( ) ; log . info ( "Processing export info for host {} ." , hostName ) ; if ( invalidExportHosts . contains ( hostName ) ) { log . info ( "Found host {} in invalid hosts list. We will not process this host export data." , hostName ) ; continue ; } List < HostExportInfo > volumeToHostExportInfoList = entry . getValue ( ) ; log . info ( "Processing export info list {} ." , volumeToHostExportInfoList ) ; String maskName = getUnManagedMaskName ( hostName , storageSystem . getNativeGuid ( ) ) ; HostExportInfo hostExportInfo = verifyHostExports ( volumeToHostExportInfoList ) ; if ( hostExportInfo == null ) { invalidExportHosts . add ( hostName ) ; log . info ( "Found export info for host {} invalid. We will not process this host export data." , hostName ) ; UnManagedExportMask unManagedMask = getUnManagedExportMask ( maskName , dbClient , storageSystem . getId ( ) ) ; if ( unManagedMask != null ) { log . info ( "Found existing unmanaged export mask for host {} and array {} --- {} . We will deactivate this mask." , hostName , storageSystem . getNativeId ( ) , unManagedMask ) ; removeInvalidMaskDataFromVolumes ( unManagedMask , dbClient ) ; unManagedMask . setInactive ( true ) ; dbClient . updateObject ( unManagedMask ) ; } continue ; } log . info ( "The result export info for host {} and array {} : {} ." , hostName , storageSystem . getNativeId ( ) , hostExportInfo ) ; UnManagedExportMask unManagedMask = getUnManagedExportMask ( maskName , dbClient , storageSystem . getId ( ) ) ; boolean isValid = true ; if ( unManagedMask != null ) { log . info ( "Found existing unmanaged export mask for host {} and array {} --- {} ." , hostName , storageSystem . getNativeId ( ) , unManagedMask ) ; StringSet storagePortsUris = unManagedMask . getKnownStoragePortUris ( ) ; Set < String > storagePortsNativeIds = new HashSet < > ( ) ; Set < String > initiatorsNativeIds = new HashSet < > ( ) ; for ( String portUriString : storagePortsUris ) { URI portUri = URI . create ( portUriString ) ; com . emc . storageos . db . client . model . StoragePort port = dbClient . queryObject ( com . emc . storageos . db . client . model . StoragePort . class , portUri ) ; storagePortsNativeIds . add ( port . getNativeId ( ) ) ; } storagePortsNativeIds . addAll ( unManagedMask . getUnmanagedStoragePortNetworkIds ( ) ) ; initiatorsNativeIds . addAll ( unManagedMask . getKnownInitiatorNetworkIds ( ) ) ; initiatorsNativeIds . addAll ( unManagedMask . getUnmanagedInitiatorNetworkIds ( ) ) ; isValid = verifyHostExports ( initiatorsNativeIds , storagePortsNativeIds , hostExportInfo ) ; if ( ! isValid ) { log . info ( "The result export info for host {} and storage array {} does not comply with existing mask." , hostName , storageSystem . getNativeId ( ) ) ; removeInvalidMaskDataFromVolumes ( unManagedMask , dbClient ) ; unManagedMask . setInactive ( true ) ; dbClient . updateObject ( unManagedMask ) ; } } else { log . info ( "There is no existing unmanaged export mask for host {} and array {} ." , hostName , storageSystem . getNativeId ( ) ) ; List < String > initiatorPorts = new ArrayList < > ( ) ; for ( Initiator initiator : hostExportInfo . getInitiators ( ) ) { initiatorPorts . add ( initiator . getPort ( ) ) ; } Map < URI , ExportMask > uriToExportMask = ExportMaskUtils . getExportMasksWithInitiatorPorts ( dbClient , initiatorPorts ) ; for ( ExportMask mask : uriToExportMask . values ( ) ) { if ( URIUtil . identical ( mask . getStorageDevice ( ) , storageSystem . getId ( ) ) ) { isValid = false ; log . info ( "Found managed export mask for host {} and array {} --- {}." + " We will not process this host export data." , hostName , storageSystem . getNativeId ( ) , mask . getId ( ) ) ; break ; } } } if ( ! isValid ) { log . info ( "Found export info for host {} invalid. Export info: {}." + " We will not process this host export data." , hostName , hostExportInfo ) ; invalidExportHosts . add ( hostName ) ; continue ; } if ( unManagedMask != null ) { URI maskId = unManagedMask . getId ( ) ; masksToUpdateForVolumes . put ( maskId , hostExportInfo ) ; } else { masksToCreateForVolumes . add ( hostExportInfo ) ; } } }
this method processes hosttovolumeexportinfomap to find out which existing unmanaged masks has to be updated , and which unmanaged masks have to be created new for this export info . it also identifies hosts with unsupported export info data ( exported host volumes are not seen through the same set of initiators and the same set of storage ports - - - which require more than one mask per host ) and adds these hosts to invalidexporthosts set .
