/**
   * Flushes the rest of the UnManagedProtectionSet changes to the database and cleans up (i.e.,
   * removes) any UnManagedProtectionSets that no longer exist on the RecoverPoint device, but are
   * still in the database.
   *
   * @param protectionSystem the ProtectionSystem to clean up
   * @param dbClient a reference to the database client
   */
  private void cleanUp(ProtectionSystem protectionSystem, DbClient dbClient) {

    // flush all remaining changes to the database
    handlePersistence(dbClient, true);

    // remove any UnManagedProtectionSets found in the database
    // but no longer found on the RecoverPoint device
    Set<URI> umpsetsFoundInDbForProtectionSystem =
        DiscoveryUtils.getAllUnManagedProtectionSetsForSystem(
            dbClient, protectionSystem.getId().toString());

    SetView<URI> onlyFoundInDb =
        Sets.difference(umpsetsFoundInDbForProtectionSystem, unManagedCGsReturnedFromProvider);

    if (onlyFoundInDb != null && !onlyFoundInDb.isEmpty()) {
      Iterator<UnManagedProtectionSet> umpsesToDelete =
          dbClient.queryIterativeObjects(UnManagedProtectionSet.class, onlyFoundInDb, true);
      while (umpsesToDelete.hasNext()) {
        UnManagedProtectionSet umps = umpsesToDelete.next();
        log.info(
            "Deleting orphaned UnManagedProtectionSet {} no longer found on RecoverPoint device.",
            umps.getNativeGuid());
        dbClient.markForDeletion(umps);
      }
    }

    // reset all tracking collections
    unManagedCGsInsert = null;
    unManagedCGsUpdate = null;
    unManagedVolumesToDelete = null;
    unManagedVolumesToUpdateByWwn = null;
    unManagedCGsReturnedFromProvider = null;
  }
  /**
   * This method cleans up UnManaged Volumes in DB, which had been deleted manually from the Array
   * 1. Get All UnManagedVolumes from DB 2. Store URIs of unmanaged volumes returned from the
   * Provider in unManagedVolumesBookKeepingList. 3. If unmanaged volume is found only in DB, but
   * not in unManagedVolumesBookKeepingList, then set unmanaged volume to inactive.
   *
   * <p>DB | Provider
   *
   * <p>x,y,z | y,z.a [a --> new entry has been added but indexes didn't get added yet into DB]
   *
   * <p>x--> will be set to inactive
   *
   * @param storageSystem
   * @param discoveredUnManagedVolumes
   * @param dbClient
   * @param partitionManager
   */
  public static void markInActiveUnManagedVolumes(
      StorageSystem storageSystem,
      Set<URI> discoveredUnManagedVolumes,
      DbClient dbClient,
      PartitionManager partitionManager) {

    _log.info(
        " -- Processing {} discovered UnManaged Volumes Objects from -- {}",
        discoveredUnManagedVolumes.size(),
        storageSystem.getLabel());
    if (discoveredUnManagedVolumes.isEmpty()) {
      return;
    }
    // Get all available existing unmanaged Volume URIs for this array from DB
    URIQueryResultList allAvailableUnManagedVolumesInDB = new URIQueryResultList();
    dbClient.queryByConstraint(
        ContainmentConstraint.Factory.getStorageDeviceUnManagedVolumeConstraint(
            storageSystem.getId()),
        allAvailableUnManagedVolumesInDB);

    Set<URI> unManagedVolumesInDBSet = new HashSet<URI>();
    Iterator<URI> allAvailableUnManagedVolumesItr = allAvailableUnManagedVolumesInDB.iterator();
    while (allAvailableUnManagedVolumesItr.hasNext()) {
      unManagedVolumesInDBSet.add(allAvailableUnManagedVolumesItr.next());
    }

    SetView<URI> onlyAvailableinDB =
        Sets.difference(unManagedVolumesInDBSet, discoveredUnManagedVolumes);

    _log.info("Diff :" + Joiner.on("\t").join(onlyAvailableinDB));
    if (!onlyAvailableinDB.isEmpty()) {
      List<UnManagedVolume> unManagedVolumeTobeDeleted = new ArrayList<UnManagedVolume>();
      Iterator<UnManagedVolume> unManagedVolumes =
          dbClient.queryIterativeObjects(
              UnManagedVolume.class, new ArrayList<URI>(onlyAvailableinDB));

      while (unManagedVolumes.hasNext()) {
        UnManagedVolume volume = unManagedVolumes.next();
        if (null == volume || volume.getInactive()) {
          continue;
        }

        _log.info("Setting unManagedVolume {} inactive", volume.getId());
        volume.setStoragePoolUri(NullColumnValueGetter.getNullURI());
        volume.setStorageSystemUri(NullColumnValueGetter.getNullURI());
        volume.setInactive(true);
        unManagedVolumeTobeDeleted.add(volume);
      }
      if (!unManagedVolumeTobeDeleted.isEmpty()) {
        partitionManager.updateAndReIndexInBatches(
            unManagedVolumeTobeDeleted, 1000, dbClient, UNMANAGED_VOLUME);
      }
    }
  }
Exemple #3
0
 static SkylarkClassObject concat(SkylarkClassObject lval, SkylarkClassObject rval, Location loc)
     throws EvalException {
   SetView<String> commonFields = Sets.intersection(lval.values.keySet(), rval.values.keySet());
   if (!commonFields.isEmpty()) {
     throw new EvalException(
         loc,
         "Cannot concat structs with common field(s): " + Joiner.on(",").join(commonFields));
   }
   return new SkylarkClassObject(
       ImmutableMap.<String, Object>builder().putAll(lval.values).putAll(rval.values).build(),
       loc);
 }
  public static void markInActiveUnManagedExportMask(
      URI storageSystemUri,
      Set<URI> discoveredUnManagedExportMasks,
      DbClient dbClient,
      PartitionManager partitionManager) {

    URIQueryResultList result = new URIQueryResultList();
    dbClient.queryByConstraint(
        ContainmentConstraint.Factory.getStorageSystemUnManagedExportMaskConstraint(
            storageSystemUri),
        result);
    Set<URI> allMasksInDatabase = new HashSet<URI>();
    Iterator<URI> it = result.iterator();
    while (it.hasNext()) {
      allMasksInDatabase.add(it.next());
    }

    SetView<URI> onlyAvailableinDB =
        Sets.difference(allMasksInDatabase, discoveredUnManagedExportMasks);

    if (!onlyAvailableinDB.isEmpty()) {
      _log.info(
          "these UnManagedExportMasks are orphaned and will be cleaned up:"
              + Joiner.on("\t").join(onlyAvailableinDB));

      List<UnManagedExportMask> unManagedExportMasksToBeDeleted =
          new ArrayList<UnManagedExportMask>();
      Iterator<UnManagedExportMask> unManagedExportMasks =
          dbClient.queryIterativeObjects(
              UnManagedExportMask.class, new ArrayList<URI>(onlyAvailableinDB));

      while (unManagedExportMasks.hasNext()) {

        UnManagedExportMask uem = unManagedExportMasks.next();
        if (null == uem || uem.getInactive()) {
          continue;
        }

        _log.info("Setting UnManagedExportMask {} inactive", uem.getMaskingViewPath());
        uem.setStorageSystemUri(NullColumnValueGetter.getNullURI());
        uem.setInactive(true);
        unManagedExportMasksToBeDeleted.add(uem);
      }
      if (!unManagedExportMasksToBeDeleted.isEmpty()) {
        partitionManager.updateAndReIndexInBatches(
            unManagedExportMasksToBeDeleted,
            Constants.DEFAULT_PARTITION_SIZE,
            dbClient,
            UNMANAGED_EXPORT_MASK);
      }
    }
  }
    private void syncListenedChannels() {
      if (m_channels.equals(m_currentListenedChannels)) {
        return;
      }

      final Set<NotificationChannel> channels = Sets.newHashSet(m_channels);
      final SetView<NotificationChannel> toUnlisten =
          Sets.difference(m_currentListenedChannels, channels);
      final SetView<NotificationChannel> toListen =
          Sets.difference(channels, m_currentListenedChannels);

      if (!toUnlisten.isEmpty()) {
        sendUnlistens(toUnlisten);
      }
      if (!toListen.isEmpty()) {
        sendListens(toListen);
      }
      if (!toUnlisten.isEmpty() || !toListen.isEmpty()) {
        m_currentListenedChannels.clear();
        m_currentListenedChannels.addAll(channels);
      }
    }
 static void validateRegions(
     Map<String, Collection<String>> regionsToAdd,
     Map<String, Collection<String>> supportedRegions) {
   MapDifference<String, Collection<String>> comparison =
       Maps.difference(regionsToAdd, supportedRegions);
   checkArgument(
       comparison.entriesOnlyOnLeft().isEmpty(),
       "unsupported regions: %s",
       comparison.entriesOnlyOnLeft().keySet());
   for (Entry<String, Collection<String>> entry : regionsToAdd.entrySet()) {
     ImmutableSet<String> toAdd = ImmutableSet.copyOf(entry.getValue());
     SetView<String> intersection =
         Sets.intersection(toAdd, ImmutableSet.copyOf(supportedRegions.get(entry.getKey())));
     SetView<String> unsupported = Sets.difference(toAdd, intersection);
     checkArgument(
         unsupported.isEmpty(), "unsupported territories in %s:", entry.getKey(), unsupported);
   }
 }