/**
   * 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 storagePoolUri
   * @throws IOException
   */
  private void performStorageUnManagedVolumeBookKeeping(URI storagePoolUri) throws IOException {
    @SuppressWarnings("deprecation")
    List<URI> unManagedVolumesInDB =
        _dbClient.queryByConstraint(
            ContainmentConstraint.Factory.getPoolUnManagedVolumeConstraint(storagePoolUri));

    Set<URI> unManagedVolumesInDBSet = new HashSet<URI>(unManagedVolumesInDB);
    SetView<URI> onlyAvailableinDB =
        Sets.difference(unManagedVolumesInDBSet, unManagedVolumesReturnedFromProvider);

    _logger.info("Diff :" + Joiner.on("\t").join(onlyAvailableinDB));
    if (onlyAvailableinDB.size() > 0) {
      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;
        }

        _logger.info("Setting unManagedVolume {} inactive", volume.getId());
        volume.setStoragePoolUri(NullColumnValueGetter.getNullURI());
        volume.setStorageSystemUri(NullColumnValueGetter.getNullURI());
        volume.setInactive(true);
        unManagedVolumeTobeDeleted.add(volume);
      }
      if (unManagedVolumeTobeDeleted.size() > 0) {
        _partitionManager.updateAndReIndexInBatches(
            unManagedVolumeTobeDeleted, 1000, _dbClient, "UnManagedVolume");
      }
    }
  }
Esempio n. 3
0
 private void removeTags(Set<Tag> newTags, Set<Tag> orginalTags) {
   SetView<Tag> removedTags = Sets.difference(orginalTags, newTags);
   logger.debug("removedTags size : {}", removedTags.size());
   for (Tag tag : removedTags) {
     tag.deTagged();
   }
 }
Esempio n. 4
0
 private void addNewTags(Set<Tag> newTags, Set<Tag> orginalTags) {
   SetView<Tag> addedTags = Sets.difference(newTags, orginalTags);
   logger.debug("addedTags size : {}", addedTags.size());
   for (Tag tag : addedTags) {
     tag.tagged();
   }
 }
  /**
   * 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);
      }
    }
  }
Esempio n. 6
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 String getLastCommitSha1(Set<String> prevBranches) throws Exception {
    Set<String> newBranches = stringifyBranches(testGitClient.getBranches());

    SetView<String> difference = Sets.difference(newBranches, prevBranches);

    assertEquals(1, difference.size());

    String result = difference.iterator().next();

    prevBranches.clear();
    prevBranches.addAll(newBranches);

    return result;
  }
 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);
   }
 }
  private Map<String, Location> setParentOfZoneToRegionOrProvider(
      Set<String> zoneIds, Set<? extends Location> locations) {
    // mutable, so that we can query current state when adding. safe as its temporary
    Map<String, Location> zoneIdToParent = Maps.newLinkedHashMap();

    Location provider = Iterables.find(locations, LocationPredicates.isProvider(), null);
    if (locations.size() == 1 && provider != null) {
      for (String zone : zoneIds) zoneIdToParent.put(zone, provider);
    } else {
      // note that we only call regionIdToZoneIdsSupplier if there are region locations present
      // they cannot be, if the above is true
      Map<String, Supplier<Set<String>>> regionIdToZoneIds = regionIdToZoneIdsSupplier.get();
      for (Location region : Iterables.filter(locations, LocationPredicates.isRegion())) {
        provider = region.getParent();
        if (regionIdToZoneIds.containsKey(region.getId())) {
          for (String zoneId : regionIdToZoneIds.get(region.getId()).get())
            zoneIdToParent.put(zoneId, region);
        } else {
          logger.debug("no zones configured for region: %s", region);
        }
      }
    }

    SetView<String> orphans = Sets.difference(zoneIds, zoneIdToParent.keySet());
    if (orphans.size() > 0) {
      // any unmatched zones should have their parents set to the provider
      checkState(
          provider != null,
          "cannot configure zones %s as we need a parent, and the only available location [%s] is not a provider",
          zoneIds,
          locations);
      for (String orphanedZoneId : orphans) zoneIdToParent.put(orphanedZoneId, provider);
    }

    checkState(
        zoneIdToParent.keySet().containsAll(zoneIds),
        "orphaned zones: %s ",
        Sets.difference(zoneIds, zoneIdToParent.keySet()));
    return zoneIdToParent;
  }
    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);
      }
    }