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);
}
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);
}
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()));
}
}
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);
}
}
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);
}
Aggregations