/**
  * injects the ProvisionedCapacity from provisioning capacity.
  *
  * @param stat
  * @param keyMap
  */
 private void injectProvisionedCapacity(final Stat stat, final Map<String, Object> keyMap) {
   final DbClient dbClient = (DbClient) keyMap.get(VNXFileConstants.DBCLIENT);
   try {
     final FileShare fileObj = dbClient.queryObject(FileShare.class, stat.getResourceId());
     _logger.info(
         "injectProvisioned Capacity existing {} from File System {}",
         stat.getProvisionedCapacity(),
         fileObj.getCapacity());
     stat.setProvisionedCapacity(fileObj.getCapacity());
   } catch (final Exception e) {
     _logger.error("No FileShare found using resource {}", stat.getResourceId());
   }
 }
Ejemplo n.º 2
0
 @Override
 public void injectColumnsDetails(Stat statObj, DbClient client) throws Exception {
   ProtectionSystem protectionObj =
       client.queryObject(ProtectionSystem.class, statObj.getResourceId());
   // Given a protection system, find a volume protected by this protection system,
   // and then extract the project and vpool
   Volume protectedVolume = null;
   URIQueryResultList resultList = new URIQueryResultList();
   client.queryByConstraint(
       ContainmentConstraint.Factory.getProtectionSystemVolumesConstraint(protectionObj.getId()),
       resultList);
   for (Iterator<URI> volumeItr = resultList.iterator(); volumeItr.hasNext(); ) {
     Volume volume = client.queryObject(Volume.class, volumeItr.next());
     if (volume.getProtectionController().equals(protectionObj.getId())) {
       protectedVolume = volume;
       break;
     }
   }
   if (protectedVolume != null) {
     _logger.info(
         "Found volume "
             + protectedVolume.getWWN()
             + " protected by this protection controller.  Get the Cos/Project/Tenant.");
     statObj.setProject(protectedVolume.getProject().getURI());
     statObj.setVirtualPool(protectedVolume.getVirtualPool());
     statObj.setTenant(protectedVolume.getTenant().getURI());
   } else {
     statObj.setProject(null);
     statObj.setVirtualPool(null);
     statObj.setTenant(null);
     throw new SMIPluginException(
         "Cassandra Database Insertion Error.  Cannot identify Project/CoS/Tenant for ProtectionSystem",
         -1);
   }
 }
  /**
   * process the FileShareUsage response of the VNX XML API Server.
   *
   * @param fsUsageList : fileShareUsage map.
   * @param keyMap : attribute map.
   * @param statList : list of stat objects.
   */
  @SuppressWarnings("rawtypes")
  private void processFileShareInfo(
      final List<Object> fsUsageList,
      final Map<String, Object> keyMap,
      final List<Stat> statList,
      DbClient dbClient)
      throws VNXFilePluginException {

    final String serialId = keyMap.get(Constants._serialID).toString();
    Iterator iterator = fsUsageList.iterator();
    keyMap.put(Constants._TimeCollected, System.currentTimeMillis());

    Map<String, Long> fsCapacityMap = new HashMap<String, Long>();

    while (iterator.hasNext()) {
      FileSystemSetUsageStats fsSetUsageStats = (FileSystemSetUsageStats) iterator.next();
      List<Item> fsUsageItems = fsSetUsageStats.getItem();
      _logger.info(
          "Received {} fileShareUsage records at server time {}",
          fsUsageItems.size(),
          fsSetUsageStats.getTime());
      for (Item item : fsUsageItems) {
        if (null == item.getFileSystem()) {
          continue;
        }
        final String nativeGuid =
            NativeGUIDGenerator.generateNativeGuid(
                Type.vnxfile.toString(), serialId, item.getFileSystem());
        Stat stat = _zeroRecordGenerator.injectattr(keyMap, nativeGuid, null);
        if (null != stat) {
          stat.setTimeInMillis((Long) keyMap.get(Constants._TimeCollected));
          stat.setTimeCollected((Long) keyMap.get(Constants._TimeCollected));
          injectProvisionedCapacity(stat, keyMap);
          // The data coming in is in KB. Converting to Bytes
          stat.setAllocatedCapacity(item.getSpaceUsed() * 1024);
          _statsColumnInjector.injectColumns(stat, dbClient);
          statList.add(stat);
          // Persists the file system, only if change in used capacity.
          DbClient client = (DbClient) keyMap.get(Constants.dbClient);
          if (client != null) {
            FileShare fileSystem = client.queryObject(FileShare.class, stat.getResourceId());
            if (fileSystem != null) {
              if (!fileSystem.getInactive()
                  && fileSystem.getUsedCapacity() != stat.getAllocatedCapacity()) {
                fileSystem.setUsedCapacity(stat.getAllocatedCapacity());
                client.persistObject(fileSystem);
              }
            }
          }
        }
        // filesystem and total capacity in Map
        long totalSpace = item.getSpaceTotal();
        String fsNativeId = item.getFileSystem();
        fsCapacityMap.put(fsNativeId, Long.valueOf(totalSpace));
        _logger.info(
            "processFileShareInfo - FileSystem native id  {}  and file system total size{}",
            fsNativeId,
            String.valueOf(totalSpace));
      }
      _logger.info("Filesystems found - {} ", fsCapacityMap.size());
      keyMap.put(VNXFileConstants.FILE_CAPACITY_MAP, fsCapacityMap);
    }
    _logger.info("No. of stat objects: {}", statList.size());
  }