use of com.emc.storageos.volumecontroller.impl.plugins.metering.isilon.IsilonStatsRecorder in project coprhd-controller by CoprHD.
the class IsilonCommunicationInterface method collectStatisticsInformation.
@Override
public void collectStatisticsInformation(AccessProfile accessProfile) throws BaseCollectionException {
URI storageSystemId = null;
StorageSystem isilonCluster = null;
long statsCount = 0;
try {
_log.info("Metering for {} using ip {}", accessProfile.getSystemId(), accessProfile.getIpAddress());
IsilonApi api = getIsilonDevice(accessProfile);
long latestSampleTime = accessProfile.getLastSampleTime();
storageSystemId = accessProfile.getSystemId();
isilonCluster = _dbClient.queryObject(StorageSystem.class, storageSystemId);
String serialNumber = isilonCluster.getSerialNumber();
String deviceType = isilonCluster.getSystemType();
initializeKeyMap(accessProfile);
boolean fsChanged = false;
List<Stat> stats = new ArrayList<Stat>();
List<FileShare> modifiedFileSystems = new ArrayList<FileShare>();
ZeroRecordGenerator zeroRecordGenerator = new FileZeroRecordGenerator();
CassandraInsertion statsColumnInjector = new FileDBInsertion();
// get usage stats from quotas
IsilonStatsRecorder recorder = new IsilonStatsRecorder(zeroRecordGenerator, statsColumnInjector);
_keyMap.put(Constants._TimeCollected, System.currentTimeMillis());
// compute static load processor code
computeStaticLoadMetrics(storageSystemId);
Map<String, String> fileSystemsMap = getStorageSystemFileShares(storageSystemId);
if (fileSystemsMap.isEmpty()) {
// No file shares for the storage system,
// ignore stats collection for the system!!!
_log.info("No file systems found for storage device {}. Hence metering stats collection ignored.", storageSystemId);
return;
}
// Process IsilonQuotas page by page (MAX 1000) in a page...
String resumeToken = null;
do {
IsilonApi.IsilonList<IsilonSmartQuota> quotas = api.listQuotas(resumeToken);
resumeToken = quotas.getToken();
for (IsilonSmartQuota quota : quotas.getList()) {
String fsNativeId = quota.getPath();
String fsNativeGuid = NativeGUIDGenerator.generateNativeGuid(deviceType, serialNumber, fsNativeId);
String fsId = fileSystemsMap.get(fsNativeGuid);
if (fsId == null || fsId.isEmpty()) {
// No file shares found for the quota
// ignore stats collection for the file system!!!
_log.debug("File System does not exists with nativeid {}. Hence ignoring stats collection.", fsNativeGuid);
continue;
}
Stat stat = recorder.addUsageStat(quota, _keyMap, fsId, api);
fsChanged = false;
if (null != stat) {
stats.add(stat);
// Persists the file system, only if change in used capacity.
FileShare fileSystem = _dbClient.queryObject(FileShare.class, stat.getResourceId());
if (fileSystem != null) {
if (!fileSystem.getInactive()) {
if (null != fileSystem.getUsedCapacity() && null != stat.getAllocatedCapacity() && !fileSystem.getUsedCapacity().equals(stat.getAllocatedCapacity())) {
fileSystem.setUsedCapacity(stat.getAllocatedCapacity());
fsChanged = true;
}
if (null != fileSystem.getSoftLimit() && null != fileSystem.getSoftLimitExceeded() && null != quota.getThresholds() && null != quota.getThresholds().getsoftExceeded() && !fileSystem.getSoftLimitExceeded().equals(quota.getThresholds().getsoftExceeded())) {
// softLimitExceeded
fileSystem.setSoftLimitExceeded(quota.getThresholds().getsoftExceeded());
fsChanged = true;
}
if (fsChanged) {
modifiedFileSystems.add(fileSystem);
}
}
}
}
// Each batch with MAX_RECORDS_SIZE - 100 records!!!
if (modifiedFileSystems.size() >= MAX_RECORDS_SIZE) {
_dbClient.updateObject(modifiedFileSystems);
_log.info("Processed {} file systems stats ", modifiedFileSystems.size());
modifiedFileSystems.clear();
}
if (stats.size() >= MAX_RECORDS_SIZE) {
_log.info("Processed {} stats", stats.size());
persistStatsInDB(stats);
}
}
statsCount = statsCount + quotas.size();
_log.info("Processed {} file system stats for device {} ", quotas.size(), storageSystemId);
} while (resumeToken != null);
zeroRecordGenerator.identifyRecordstobeZeroed(_keyMap, stats, FileShare.class);
// write the remaining records!!
if (!modifiedFileSystems.isEmpty()) {
_dbClient.updateObject(modifiedFileSystems);
_log.info("Processed {} file systems stats ", modifiedFileSystems.size());
modifiedFileSystems.clear();
}
if (!stats.isEmpty()) {
_log.info("Processed {} stats", stats.size());
persistStatsInDB(stats);
}
latestSampleTime = System.currentTimeMillis();
accessProfile.setLastSampleTime(latestSampleTime);
_log.info("Done metering device {}, processed {} file system stats ", storageSystemId, statsCount);
} catch (Exception e) {
if (isilonCluster != null) {
cleanupDiscovery(isilonCluster);
}
_log.error("CollectStatisticsInformation failed. Storage system: " + storageSystemId, e);
throw (new IsilonCollectionException(e.getMessage()));
}
}
Aggregations