Search in sources :

Example 1 with IsilonStatsRecorder

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()));
    }
}
Also used : IsilonSmartQuota(com.emc.storageos.isilon.restapi.IsilonSmartQuota) ArrayList(java.util.ArrayList) IsilonCollectionException(com.emc.storageos.plugins.metering.isilon.IsilonCollectionException) FileZeroRecordGenerator(com.emc.storageos.volumecontroller.impl.plugins.metering.file.FileZeroRecordGenerator) URI(java.net.URI) FileShare(com.emc.storageos.db.client.model.FileShare) UnManagedSMBFileShare(com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedSMBFileShare) IsilonException(com.emc.storageos.isilon.restapi.IsilonException) BaseCollectionException(com.emc.storageos.plugins.BaseCollectionException) IOException(java.io.IOException) JSONException(org.codehaus.jettison.json.JSONException) URISyntaxException(java.net.URISyntaxException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) IsilonCollectionException(com.emc.storageos.plugins.metering.isilon.IsilonCollectionException) IsilonStatsRecorder(com.emc.storageos.volumecontroller.impl.plugins.metering.isilon.IsilonStatsRecorder) Stat(com.emc.storageos.db.client.model.Stat) CassandraInsertion(com.emc.storageos.volumecontroller.impl.plugins.metering.CassandraInsertion) IsilonApi(com.emc.storageos.isilon.restapi.IsilonApi) FileZeroRecordGenerator(com.emc.storageos.volumecontroller.impl.plugins.metering.file.FileZeroRecordGenerator) ZeroRecordGenerator(com.emc.storageos.volumecontroller.impl.plugins.metering.ZeroRecordGenerator) StorageSystem(com.emc.storageos.db.client.model.StorageSystem) FileDBInsertion(com.emc.storageos.volumecontroller.impl.plugins.metering.file.FileDBInsertion)

Aggregations

FileShare (com.emc.storageos.db.client.model.FileShare)1 Stat (com.emc.storageos.db.client.model.Stat)1 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)1 UnManagedSMBFileShare (com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedSMBFileShare)1 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)1 IsilonApi (com.emc.storageos.isilon.restapi.IsilonApi)1 IsilonException (com.emc.storageos.isilon.restapi.IsilonException)1 IsilonSmartQuota (com.emc.storageos.isilon.restapi.IsilonSmartQuota)1 BaseCollectionException (com.emc.storageos.plugins.BaseCollectionException)1 IsilonCollectionException (com.emc.storageos.plugins.metering.isilon.IsilonCollectionException)1 CassandraInsertion (com.emc.storageos.volumecontroller.impl.plugins.metering.CassandraInsertion)1 ZeroRecordGenerator (com.emc.storageos.volumecontroller.impl.plugins.metering.ZeroRecordGenerator)1 FileDBInsertion (com.emc.storageos.volumecontroller.impl.plugins.metering.file.FileDBInsertion)1 FileZeroRecordGenerator (com.emc.storageos.volumecontroller.impl.plugins.metering.file.FileZeroRecordGenerator)1 IsilonStatsRecorder (com.emc.storageos.volumecontroller.impl.plugins.metering.isilon.IsilonStatsRecorder)1 IOException (java.io.IOException)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 ArrayList (java.util.ArrayList)1 JSONException (org.codehaus.jettison.json.JSONException)1