Skip to content

Commit e3f1ccb

Browse files
author
Pearl Dsilva
committed
update existing clvm get stats method
1 parent 7caa9b5 commit e3f1ccb

1 file changed

Lines changed: 30 additions & 10 deletions

File tree

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/ClvmStorageAdaptor.java

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -326,25 +326,45 @@ private long[] getVgStats(String vgName) {
326326
String result = getVgStats.execute(parser);
327327

328328
if (result != null) {
329-
throw new CloudRuntimeException("Failed to get VG stats for " + vgName + ": " + result);
329+
String errorMsg = "Failed to get statistics for volume group " + vgName + ": " + result;
330+
logger.error(errorMsg);
331+
throw new CloudRuntimeException(errorMsg);
330332
}
331333

332-
String output = parser.getLines();
333-
if (output == null || output.trim().isEmpty()) {
334-
throw new CloudRuntimeException("Empty output from vgs for VG: " + vgName);
334+
String output = parser.getLines().trim();
335+
String[] lines = output.split("\\n");
336+
String dataLine = null;
337+
338+
for (String line : lines) {
339+
line = line.trim();
340+
if (!line.isEmpty() && Character.isDigit(line.charAt(0))) {
341+
dataLine = line;
342+
break;
343+
}
335344
}
336345

337-
String[] parts = output.trim().split("\\s+");
338-
if (parts.length < 2) {
339-
throw new CloudRuntimeException("Unexpected vgs output format for VG " + vgName + ": " + output);
346+
if (dataLine == null) {
347+
String errorMsg = "No valid data line found in vgs output for " + vgName + ": " + output;
348+
logger.error(errorMsg);
349+
throw new CloudRuntimeException(errorMsg);
350+
}
351+
352+
String[] stats = dataLine.split("\\s+");
353+
354+
if (stats.length < 2) {
355+
String errorMsg = "Unexpected output from vgs command for " + vgName + ": " + dataLine;
356+
logger.error(errorMsg);
357+
throw new CloudRuntimeException(errorMsg);
340358
}
341359

342360
try {
343-
long capacity = Long.parseLong(parts[0].trim());
344-
long available = Long.parseLong(parts[1].trim());
361+
long capacity = Long.parseLong(stats[0].trim());
362+
long available = Long.parseLong(stats[1].trim());
345363
return new long[]{capacity, available};
346364
} catch (NumberFormatException e) {
347-
throw new CloudRuntimeException("Failed to parse VG stats for " + vgName + ": " + output, e);
365+
String errorMsg = "Failed to parse VG statistics for " + vgName + ": " + e.getMessage();
366+
logger.error(errorMsg);
367+
throw new CloudRuntimeException(errorMsg, e);
348368
}
349369
}
350370

0 commit comments

Comments
 (0)