Search in sources :

Example 1 with NetAppStatsRecorder

use of com.emc.storageos.volumecontroller.impl.plugins.metering.netapp.NetAppStatsRecorder in project coprhd-controller by CoprHD.

the class NetAppFileCommunicationInterface method collectStatisticsInformation.

@Override
public void collectStatisticsInformation(AccessProfile accessProfile) throws BaseCollectionException {
    URI storageSystemId = null;
    String fsName = null;
    try {
        _logger.info("Metering for {} using ip {}", accessProfile.getSystemId(), accessProfile.getIpAddress());
        String arrayIp = accessProfile.getIpAddress();
        String arrayUser = accessProfile.getUserName();
        String arrayPassword = accessProfile.getPassword();
        int arrayPort = accessProfile.getPortNumber();
        NetAppApi netAppApi = new NetAppApi.Builder(arrayIp, arrayPort, arrayUser, arrayPassword).https(true).build();
        long latestSampleTime = accessProfile.getLastSampleTime();
        storageSystemId = accessProfile.getSystemId();
        StorageSystem NetAppArray = _dbClient.queryObject(StorageSystem.class, storageSystemId);
        String serialNumber = NetAppArray.getSerialNumber();
        String deviceType = NetAppArray.getSystemType();
        initializeKeyMap(accessProfile);
        List<Stat> stats = new ArrayList<Stat>();
        ZeroRecordGenerator zeroRecordGenerator = new FileZeroRecordGenerator();
        CassandraInsertion statsColumnInjector = new FileDBInsertion();
        /* Get Stats from the NTAP array */
        List<Map<String, String>> usageStats = new ArrayList<Map<String, String>>();
        NetAppStatsRecorder recorder = new NetAppStatsRecorder(zeroRecordGenerator, statsColumnInjector);
        _keyMap.put(Constants._TimeCollected, System.currentTimeMillis());
        Map<String, Number> metrics = new ConcurrentHashMap<String, Number>();
        List<URI> storageSystemIds = new ArrayList<URI>();
        storageSystemIds.add(storageSystemId);
        List<FileShare> fsObjs = _dbClient.queryObjectField(FileShare.class, Constants.STORAGE_DEVICE, storageSystemIds);
        List<URI> fsUris = zeroRecordGenerator.extractVolumesOrFileSharesFromDB(storageSystemId, _dbClient, FileShare.class);
        for (URI fsUri : fsUris) {
            FileShare fsObj = _dbClient.queryObject(FileShare.class, fsUri);
            if (fsObj.getInactive()) {
                continue;
            }
            fsName = fsObj.getName();
            String fsNativeGuid = NativeGUIDGenerator.generateNativeGuid(deviceType, serialNumber, fsObj.getPath());
            try {
                usageStats = netAppApi.listVolumeInfo(fsName, null);
                for (Map<String, String> map : usageStats) {
                    /*
                         * TODO: usageStats usually contains a single element. If
                         * the list consists of multiple elements, all but one
                         * element will get overwritten.
                         */
                    metrics.put(Constants.SIZE_TOTAL, 0);
                    if (map.get(Constants.SIZE_TOTAL) != null) {
                        metrics.put(Constants.SIZE_TOTAL, Long.valueOf(map.get(Constants.SIZE_TOTAL)));
                    }
                    metrics.put(Constants.SIZE_USED, 0);
                    if (map.get(Constants.SIZE_USED) != null) {
                        metrics.put(Constants.SIZE_USED, Long.valueOf(map.get(Constants.SIZE_USED)));
                    }
                    /*
                         * TODO: Bytes per block on NTAP is hard coded for now. If
                         * possible, we should to get this from the array.
                         */
                    Long snapshotBytesReserved = 0L;
                    if (map.get(Constants.SNAPSHOT_BLOCKS_RESERVED) != null) {
                        snapshotBytesReserved = Long.valueOf(map.get(Constants.SNAPSHOT_BLOCKS_RESERVED)) * Constants.NETAPP_BYTES_PER_BLOCK;
                    }
                    metrics.put(Constants.SNAPSHOT_BYTES_RESERVED, snapshotBytesReserved);
                    Integer snapshotCount = _dbClient.countObjects(Snapshot.class, Constants.PARENT, fsObj.getId());
                    metrics.put(Constants.SNAPSHOT_COUNT, snapshotCount);
                    Stat stat = recorder.addUsageStat(fsNativeGuid, _keyMap, metrics);
                    if (stat != null) {
                        stats.add(stat);
                        // Persists the file system, only if change in used capacity.
                        if (fsObj.getUsedCapacity() != stat.getAllocatedCapacity()) {
                            fsObj.setUsedCapacity(stat.getAllocatedCapacity());
                            _dbClient.persistObject(fsObj);
                        }
                    }
                }
            } catch (NetAppException ne) {
                String arg = fsName.toString() + ", " + accessProfile.getIpAddress().toString() + ", " + accessProfile.getSystemType().toString();
                _logger.info("Failed to retrieve stats for FileShare, Syste, Type: {}", arg);
            }
        }
        if (!stats.isEmpty()) {
            zeroRecordGenerator.identifyRecordstobeZeroed(_keyMap, stats, FileShare.class);
            persistStatsInDB(stats);
            latestSampleTime = System.currentTimeMillis();
            accessProfile.setLastSampleTime(latestSampleTime);
        }
        _logger.info("Done metering device {}", storageSystemId);
    } catch (Exception e) {
        String message = "collectStatisticsInformation failed. Storage system: " + storageSystemId;
        _logger.error(message, e);
        throw NetAppException.exceptions.collectStatsFailed(accessProfile.getIpAddress(), accessProfile.getSystemType(), message);
    }
}
Also used : ArrayList(java.util.ArrayList) FileZeroRecordGenerator(com.emc.storageos.volumecontroller.impl.plugins.metering.file.FileZeroRecordGenerator) URI(java.net.URI) NetAppException(com.emc.storageos.netapp.NetAppException) Stat(com.emc.storageos.db.client.model.Stat) NetAppApi(com.emc.storageos.netapp.NetAppApi) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) StorageSystem(com.emc.storageos.db.client.model.StorageSystem) NetAppStatsRecorder(com.emc.storageos.volumecontroller.impl.plugins.metering.netapp.NetAppStatsRecorder) FileShare(com.emc.storageos.db.client.model.FileShare) UnManagedSMBFileShare(com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedSMBFileShare) AlternateIdConstraint(com.emc.storageos.db.client.constraint.AlternateIdConstraint) ContainmentConstraint(com.emc.storageos.db.client.constraint.ContainmentConstraint) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) BaseCollectionException(com.emc.storageos.plugins.BaseCollectionException) NetAppException(com.emc.storageos.netapp.NetAppException) NetAppFileCollectionException(com.emc.storageos.plugins.metering.netapp.NetAppFileCollectionException) IOException(java.io.IOException) CassandraInsertion(com.emc.storageos.volumecontroller.impl.plugins.metering.CassandraInsertion) FileZeroRecordGenerator(com.emc.storageos.volumecontroller.impl.plugins.metering.file.FileZeroRecordGenerator) ZeroRecordGenerator(com.emc.storageos.volumecontroller.impl.plugins.metering.ZeroRecordGenerator) UnManagedFSExportMap(com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedFSExportMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) UnManagedSMBShareMap(com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedSMBShareMap) StringMap(com.emc.storageos.db.client.model.StringMap) FileDBInsertion(com.emc.storageos.volumecontroller.impl.plugins.metering.file.FileDBInsertion)

Aggregations

AlternateIdConstraint (com.emc.storageos.db.client.constraint.AlternateIdConstraint)1 ContainmentConstraint (com.emc.storageos.db.client.constraint.ContainmentConstraint)1 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 StringMap (com.emc.storageos.db.client.model.StringMap)1 UnManagedFSExportMap (com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedFSExportMap)1 UnManagedSMBFileShare (com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedSMBFileShare)1 UnManagedSMBShareMap (com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedSMBShareMap)1 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)1 NetAppApi (com.emc.storageos.netapp.NetAppApi)1 NetAppException (com.emc.storageos.netapp.NetAppException)1 BaseCollectionException (com.emc.storageos.plugins.BaseCollectionException)1 NetAppFileCollectionException (com.emc.storageos.plugins.metering.netapp.NetAppFileCollectionException)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 NetAppStatsRecorder (com.emc.storageos.volumecontroller.impl.plugins.metering.netapp.NetAppStatsRecorder)1 IOException (java.io.IOException)1