Search in sources :

Example 36 with Stat

use of com.emc.storageos.db.client.model.Stat in project coprhd-controller by CoprHD.

the class JSONStatMarshallerTest method testJsonStatMarshallingForError.

@Test
public void testJsonStatMarshallingForError() throws URISyntaxException, IOException, MarshallingExcetion {
    deleteIfExists(JsonTestOutputFile);
    JSONStatMarshaller jm = new JSONStatMarshaller();
    Stat st = new Stat();
    st.setTenant(new URI("http://tenant.1"));
    st.setProject(new URI("http://project.1"));
    OutputStream output = new OutputStream() {

        private StringBuilder string = new StringBuilder();

        @Override
        public void write(int b) throws IOException {
            this.string.append((char) b);
        }

        public String toString() {
            return this.string.toString();
        }
    };
    PrintWriter writer = new PrintWriter(output);
    String error = "someerror";
    jm.error(writer, error);
    writer.close();
    Assert.assertTrue(output.toString().contains("{ \"error\": [" + "someerror" + "] }"));
    deleteIfExists(JsonTestOutputFile);
}
Also used : Stat(com.emc.storageos.db.client.model.Stat) OutputStream(java.io.OutputStream) JSONStatMarshaller(com.emc.storageos.api.service.impl.resource.utils.JSONStatMarshaller) URI(java.net.URI) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Example 37 with Stat

use of com.emc.storageos.db.client.model.Stat in project coprhd-controller by CoprHD.

the class XMLStatMarshallerTest method testXmlStatMarshalling.

@Test
public void testXmlStatMarshalling() throws MarshallingExcetion, IOException, JAXBException {
    deleteIfExists(XmlTestOutputFile);
    XMLStatMarshaller xmlMarshaller = new XMLStatMarshaller();
    Stat st = new Stat();
    String svcType = "block";
    st.setServiceType(svcType);
    OutputStream output = new OutputStream() {

        private StringBuilder string = new StringBuilder();

        @Override
        public void write(int b) throws IOException {
            this.string.append((char) b);
        }

        public String toString() {
            return this.string.toString();
        }
    };
    PrintWriter writer = new PrintWriter(output);
    xmlMarshaller.marshall(st, writer);
    writer.close();
    FileWriter fileWriter = new FileWriter(XmlTestOutputFile);
    fileWriter.write(output.toString());
    fileWriter.close();
    JAXBContext context = null;
    Unmarshaller unmarshaller = null;
    context = JAXBContext.newInstance(Stat.class);
    unmarshaller = context.createUnmarshaller();
    File f = new File(XmlTestOutputFile);
    Stat stat = (Stat) unmarshaller.unmarshal(f);
    Assert.assertEquals("block", stat.getServiceType().toString());
    deleteIfExists(XmlTestOutputFile);
}
Also used : Stat(com.emc.storageos.db.client.model.Stat) OutputStream(java.io.OutputStream) FileWriter(java.io.FileWriter) JAXBContext(javax.xml.bind.JAXBContext) Unmarshaller(javax.xml.bind.Unmarshaller) File(java.io.File) XMLStatMarshaller(com.emc.storageos.api.service.impl.resource.utils.XMLStatMarshaller) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Example 38 with Stat

use of com.emc.storageos.db.client.model.Stat 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)

Example 39 with Stat

use of com.emc.storageos.db.client.model.Stat 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)

Example 40 with Stat

use of com.emc.storageos.db.client.model.Stat in project coprhd-controller by CoprHD.

the class VPlexMeteringTest method testVPlexPerpetualCSVFileCollector.

@Test
public void testVPlexPerpetualCSVFileCollector() throws InstantiationException, IllegalAccessException {
    MockDbClient mockDbClient = new MockDbClient();
    mockStorageDriverManager();
    StorageSystem storageSystem = mockStorageSystem("vplex-1", "000123ABC000XYZ");
    mockDbClient.MOCK_DB.put(storageSystem.getId(), storageSystem);
    int directorIndex = 1;
    String[] directors = DIRECTORS.split(",");
    for (String directorName : directors) {
        int adapterIndex = (directorIndex % 2);
        String aOrB = directorName.substring(directorName.length() - 1);
        String adapterSerial = String.format("CF23K00000%d%d", directorIndex, adapterIndex);
        StorageHADomain director = mockVPlexAdapter(storageSystem, directorName, adapterSerial);
        mockDbClient.MOCK_DB.put(director.getId(), director);
        for (int cpuIndex = 0; cpuIndex < 2; cpuIndex++) {
            for (int portIndex = 0; portIndex < PORT_PER_DIRECTOR; portIndex++) {
                String portName = String.format("%s%d-FC%02d", aOrB, cpuIndex, portIndex);
                String wwn = String.format("5C:CC:DD:EE:FF:00:%02d:%02d", directorIndex, portIndex);
                StoragePort port = mockStoragePort(director, portName, wwn, adapterSerial);
                mockDbClient.MOCK_DB.put(port.getId(), port);
            }
        }
        directorIndex++;
    }
    AccessProfile accessProfile = new AccessProfile();
    accessProfile.setIpAddress(HOST);
    accessProfile.setUserName(USERNAME);
    accessProfile.setPassword(PASSWORD);
    accessProfile.setSystemId(storageSystem.getId());
    Map<String, Object> context = new HashMap<>();
    context.put(Constants.dbClient, mockDbClient);
    context.put(Constants._Stats, new LinkedList<Stat>());
    context.put(Constants._TimeCollected, System.currentTimeMillis());
    VPlexPerpetualCSVFileCollector collector = new VPlexPerpetualCSVFileCollector();
    PortMetricsProcessor portMetricsProcessor = mockPortMetricsProcessor(mockDbClient);
    collector.setPortMetricsProcessor(portMetricsProcessor);
    collector.collect(accessProfile, context);
}
Also used : HashMap(java.util.HashMap) StoragePort(com.emc.storageos.db.client.model.StoragePort) AccessProfile(com.emc.storageos.plugins.AccessProfile) Constraint(com.emc.storageos.db.client.constraint.Constraint) Stat(com.emc.storageos.db.client.model.Stat) PortMetricsProcessor(com.emc.storageos.volumecontroller.impl.plugins.metering.smis.processor.PortMetricsProcessor) DataObject(com.emc.storageos.db.client.model.DataObject) DiscoveredDataObject(com.emc.storageos.db.client.model.DiscoveredDataObject) StorageHADomain(com.emc.storageos.db.client.model.StorageHADomain) VPlexPerpetualCSVFileCollector(com.emc.storageos.volumecontroller.impl.plugins.metering.vplex.VPlexPerpetualCSVFileCollector) StorageSystem(com.emc.storageos.db.client.model.StorageSystem) Test(org.junit.Test)

Aggregations

Stat (com.emc.storageos.db.client.model.Stat)40 List (java.util.List)14 DbClient (com.emc.storageos.db.client.DbClient)13 BaseCollectionException (com.emc.storageos.plugins.BaseCollectionException)12 URI (java.net.URI)12 AccessProfile (com.emc.storageos.plugins.AccessProfile)8 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)7 ArrayList (java.util.ArrayList)7 Test (org.junit.Test)7 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)6 SMIPluginException (com.emc.storageos.plugins.metering.smis.SMIPluginException)6 PrintWriter (java.io.PrintWriter)6 FileShare (com.emc.storageos.db.client.model.FileShare)5 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)5 IOException (java.io.IOException)5 OutputStream (java.io.OutputStream)5 CIMInstance (javax.cim.CIMInstance)5 ResponsePacket (com.emc.nas.vnxfile.xmlapi.ResponsePacket)4 ContainmentConstraint (com.emc.storageos.db.client.constraint.ContainmentConstraint)4 File (java.io.File)4