Search in sources :

Example 1 with Thresholds

use of com.emc.storageos.isilon.restapi.IsilonSmartQuota.Thresholds in project coprhd-controller by CoprHD.

the class IsilonStatsRecorder method addUsageStat.

/**
 * Adds a Stat for usage from the IsilonQuota.
 *
 * @param quota
 * @param keyMap
 * @param fsNativeGuid native Guid of the file share
 * @param isilonApi
 * @return the stat
 */
public Stat addUsageStat(IsilonSmartQuota quota, Map<String, Object> keyMap, String fsNativeGuid, IsilonApi isilonApi) {
    Stat stat = zeroRecordGenerator.injectattr(keyMap, fsNativeGuid, FileShare.class);
    if (stat != null) {
        try {
            DbClient dbClient = (DbClient) keyMap.get(Constants.dbClient);
            stat.setTimeInMillis((Long) keyMap.get(Constants._TimeCollected));
            stat.setTimeCollected((Long) keyMap.get(Constants._TimeCollected));
            statsColumnInjector.injectColumns(stat, dbClient);
            long provisionedCapacity = 0L;
            Thresholds threshold = quota.getThresholds();
            if (threshold != null && threshold.getHard() != null) {
                provisionedCapacity = threshold.getHard();
            }
            stat.setProvisionedCapacity(provisionedCapacity);
            long usedCapacity = quota.getUsagePhysical();
            stat.setAllocatedCapacity(usedCapacity);
            URIQueryResultList snapURIList = new URIQueryResultList();
            dbClient.queryByConstraint(ContainmentConstraint.Factory.getFileshareSnapshotConstraint(stat.getResourceId()), snapURIList);
            // Set snapshot count.
            // Set snapshot size. Get current data for snapshot size (snapshot size changes dynamically).
            int snapCount = 0;
            long fsSnapshotSize = 0;
            IsilonSnapshot isiSnap;
            for (URI snapURI : snapURIList) {
                Snapshot snap = dbClient.queryObject(Snapshot.class, snapURI);
                // Filter out deleted Snapshot
                if (snap != null && (!snap.getInactive())) {
                    String nativeId = snap.getNativeId();
                    try {
                        isiSnap = isilonApi.getSnapshot(nativeId);
                    } catch (IsilonException iex) {
                        _log.error(String.format("Stat: %s: can not get snapshot size for snapshot: %s", fsNativeGuid, nativeId), iex);
                        continue;
                    }
                    snapCount++;
                    fsSnapshotSize += Long.valueOf(isiSnap.getSize());
                }
            }
            stat.setSnapshotCount(snapCount);
            _log.debug(String.format("Stat: %s: snapshot count: %s", fsNativeGuid, snapCount));
            stat.setSnapshotCapacity(fsSnapshotSize);
            _log.debug(String.format("Stat: %s: snapshot size: %s", fsNativeGuid, fsSnapshotSize));
            _log.debug(String.format("Stat: %s: %s: provisioned capacity(%s): used capacity(%s)", stat.getResourceId(), fsNativeGuid, provisionedCapacity, usedCapacity));
        } catch (DatabaseException ex) {
            _log.error("Query to db failed for FileShare id {}, skipping recording usage stat.", stat.getResourceId(), ex);
        }
    }
    return stat;
}
Also used : Snapshot(com.emc.storageos.db.client.model.Snapshot) IsilonSnapshot(com.emc.storageos.isilon.restapi.IsilonSnapshot) Stat(com.emc.storageos.db.client.model.Stat) DbClient(com.emc.storageos.db.client.DbClient) Thresholds(com.emc.storageos.isilon.restapi.IsilonSmartQuota.Thresholds) IsilonSnapshot(com.emc.storageos.isilon.restapi.IsilonSnapshot) URI(java.net.URI) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) ContainmentConstraint(com.emc.storageos.db.client.constraint.ContainmentConstraint) IsilonException(com.emc.storageos.isilon.restapi.IsilonException)

Aggregations

DbClient (com.emc.storageos.db.client.DbClient)1 ContainmentConstraint (com.emc.storageos.db.client.constraint.ContainmentConstraint)1 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)1 Snapshot (com.emc.storageos.db.client.model.Snapshot)1 Stat (com.emc.storageos.db.client.model.Stat)1 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)1 IsilonException (com.emc.storageos.isilon.restapi.IsilonException)1 Thresholds (com.emc.storageos.isilon.restapi.IsilonSmartQuota.Thresholds)1 IsilonSnapshot (com.emc.storageos.isilon.restapi.IsilonSnapshot)1 URI (java.net.URI)1