private boolean updateStoragePortVirtualArrays(StoragePort storagePort,VirtualArrayAssignmentChanges varrayAssignmentChanges){
  boolean varraysForPortUpdated=false;
  Set<String> varraysAddedToPort=new HashSet<String>();
  Set<String> varraysRemovedFromPort=new HashSet<String>();
  if (varrayAssignmentChanges != null) {
    _log.info("Update request has virtual array assignment changes for storage port {}",storagePort.getId());
    verifyAssignmentChanges(storagePort,varrayAssignmentChanges);
    _log.info("Requested virtual array assignment changes verified.");
    VirtualArrayAssignments addAssignments=varrayAssignmentChanges.getAdd();
    if (addAssignments != null) {
      Set<String> addVArrays=addAssignments.getVarrays();
      if ((addVArrays != null) && (!addVArrays.isEmpty())) {
        _log.info("Request specifies virtual arrays to be added.");
        VirtualArrayService.checkVirtualArrayURIs(addVArrays,_dbClient);
        StringSet currentAssignments=storagePort.getAssignedVirtualArrays();
        Iterator<String> addVArraysIter=addVArrays.iterator();
        while (addVArraysIter.hasNext()) {
          String addVArrayId=addVArraysIter.next();
          if ((currentAssignments != null) && (currentAssignments.contains(addVArrayId))) {
            _log.info("Storage port already assigned to virtual array {}",addVArrayId);
            continue;
          }
          varraysAddedToPort.add(addVArrayId);
          varraysForPortUpdated=true;
          _log.info("Storage port will be assigned to virtual array {}",addVArrayId);
        }
      }
    }
    VirtualArrayAssignments removeAssignments=varrayAssignmentChanges.getRemove();
    if (removeAssignments != null) {
      Set<String> removeVArrays=removeAssignments.getVarrays();
      if ((removeVArrays != null) && (!removeVArrays.isEmpty())) {
        _log.info("Request specifies virtual arrays to be removed.");
        VirtualArrayService.checkVirtualArrayURIs(removeVArrays,_dbClient);
        StringSet currentAssignments=storagePort.getAssignedVirtualArrays();
        Iterator<String> removeVArraysIter=removeVArrays.iterator();
        while (removeVArraysIter.hasNext()) {
          String removeVArrayId=removeVArraysIter.next();
          if ((currentAssignments == null) || (!currentAssignments.contains(removeVArrayId))) {
            _log.info("Storage port is not assigned to virtual array {}",removeVArrayId);
            continue;
          }
          varraysRemovedFromPort.add(removeVArrayId);
          varraysForPortUpdated=true;
          _log.info("Storage port will be unassigned from virtual array {}",removeVArrayId);
        }
      }
    }
  }
  if (varraysForPortUpdated) {
    storagePort.addAssignedVirtualArrays(varraysAddedToPort);
    storagePort.removeAssignedVirtualArrays(varraysRemovedFromPort);
    verifyPortNoInUseInRemovedVarrays(storagePort);
    _dbClient.updateAndReindexObject(storagePort);
    URI storagePortNetworkURI=storagePort.getNetwork();
    if (storagePortNetworkURI != null) {
      Network storagePortNetwork=_dbClient.queryObject(Network.class,storagePortNetworkURI);
      if (storagePortNetwork != null) {
        if (!varraysRemovedFromPort.isEmpty()) {
          NetworkAssociationHelper.updateConnectedVirtualArrays(storagePortNetwork,Collections.singletonList(storagePort),false,_dbClient);
        }
 else         if (!varraysAddedToPort.isEmpty()) {
          NetworkAssociationHelper.updateConnectedVirtualArrays(storagePortNetwork,Collections.singletonList(storagePort),true,_dbClient);
        }
      }
    }
  }
  return varraysForPortUpdated;
}

private boolean updateStoragePortVirtualArrays ( StoragePort storagePort , VirtualArrayAssignmentChanges varrayAssignmentChanges ) { boolean varraysForPortUpdated = false ; Set < String > varraysAddedToPort = new HashSet < String > ( ) ; Set < String > varraysRemovedFromPort = new HashSet < String > ( ) ; if ( varrayAssignmentChanges != null ) { _log . info ( "Update request has virtual array assignment changes for storage port {}" , storagePort . getId ( ) ) ; verifyAssignmentChanges ( storagePort , varrayAssignmentChanges ) ; _log . info ( "Requested virtual array assignment changes verified." ) ; VirtualArrayAssignments addAssignments = varrayAssignmentChanges . getAdd ( ) ; if ( addAssignments != null ) { Set < String > addVArrays = addAssignments . getVarrays ( ) ; if ( ( addVArrays != null ) && ( ! addVArrays . isEmpty ( ) ) ) { _log . info ( "Request specifies virtual arrays to be added." ) ; VirtualArrayService . checkVirtualArrayURIs ( addVArrays , _dbClient ) ; StringSet currentAssignments = storagePort . getAssignedVirtualArrays ( ) ; Iterator < String > addVArraysIter = addVArrays . iterator ( ) ; while ( addVArraysIter . hasNext ( ) ) { String addVArrayId = addVArraysIter . next ( ) ; if ( ( currentAssignments != null ) && ( currentAssignments . contains ( addVArrayId ) ) ) { _log . info ( "Storage port already assigned to virtual array {}" , addVArrayId ) ; continue ; } varraysAddedToPort . add ( addVArrayId ) ; varraysForPortUpdated = true ; _log . info ( "Storage port will be assigned to virtual array {}" , addVArrayId ) ; } } } VirtualArrayAssignments removeAssignments = varrayAssignmentChanges . getRemove ( ) ; if ( removeAssignments != null ) { Set < String > removeVArrays = removeAssignments . getVarrays ( ) ; if ( ( removeVArrays != null ) && ( ! removeVArrays . isEmpty ( ) ) ) { _log . info ( "Request specifies virtual arrays to be removed." ) ; VirtualArrayService . checkVirtualArrayURIs ( removeVArrays , _dbClient ) ; StringSet currentAssignments = storagePort . getAssignedVirtualArrays ( ) ; Iterator < String > removeVArraysIter = removeVArrays . iterator ( ) ; while ( removeVArraysIter . hasNext ( ) ) { String removeVArrayId = removeVArraysIter . next ( ) ; if ( ( currentAssignments == null ) || ( ! currentAssignments . contains ( removeVArrayId ) ) ) { _log . info ( "Storage port is not assigned to virtual array {}" , removeVArrayId ) ; continue ; } varraysRemovedFromPort . add ( removeVArrayId ) ; varraysForPortUpdated = true ; _log . info ( "Storage port will be unassigned from virtual array {}" , removeVArrayId ) ; } } } } if ( varraysForPortUpdated ) { storagePort . addAssignedVirtualArrays ( varraysAddedToPort ) ; storagePort . removeAssignedVirtualArrays ( varraysRemovedFromPort ) ; verifyPortNoInUseInRemovedVarrays ( storagePort ) ; _dbClient . updateAndReindexObject ( storagePort ) ; URI storagePortNetworkURI = storagePort . getNetwork ( ) ; if ( storagePortNetworkURI != null ) { Network storagePortNetwork = _dbClient . queryObject ( Network . class , storagePortNetworkURI ) ; if ( storagePortNetwork != null ) { if ( ! varraysRemovedFromPort . isEmpty ( ) ) { NetworkAssociationHelper . updateConnectedVirtualArrays ( storagePortNetwork , Collections . singletonList ( storagePort ) , false , _dbClient ) ; } else if ( ! varraysAddedToPort . isEmpty ( ) ) { NetworkAssociationHelper . updateConnectedVirtualArrays ( storagePortNetwork , Collections . singletonList ( storagePort ) , true , _dbClient ) ; } } } } return varraysForPortUpdated ; }
updates the virtual arrays to which the port is assigned .
