use of com.cloud.agent.api.GetStorageStatsAnswer in project cloudstack by apache.
the class CitrixGetStorageStatsCommandWrapper method execute.
@Override
public Answer execute(final GetStorageStatsCommand command, final CitrixResourceBase citrixResourceBase) {
final Connection conn = citrixResourceBase.getConnection();
try {
final Set<SR> srs = SR.getByNameLabel(conn, command.getStorageId());
if (srs.size() != 1) {
final String msg = "There are " + srs.size() + " storageid: " + command.getStorageId();
s_logger.warn(msg);
return new GetStorageStatsAnswer(command, msg);
}
final SR sr = srs.iterator().next();
sr.scan(conn);
final long capacity = sr.getPhysicalSize(conn);
final long used = sr.getPhysicalUtilisation(conn);
return new GetStorageStatsAnswer(command, capacity, used);
} catch (final XenAPIException e) {
final String msg = "GetStorageStats Exception:" + e.toString() + "host:" + citrixResourceBase.getHost().getUuid() + "storageid: " + command.getStorageId();
s_logger.warn(msg);
return new GetStorageStatsAnswer(command, msg);
} catch (final XmlRpcException e) {
final String msg = "GetStorageStats Exception:" + e.getMessage() + "host:" + citrixResourceBase.getHost().getUuid() + "storageid: " + command.getStorageId();
s_logger.warn(msg);
return new GetStorageStatsAnswer(command, msg);
} catch (final Exception e) {
final String msg = "GetStorageStats Exception:" + e.getMessage() + "host:" + citrixResourceBase.getHost().getUuid() + "storageid: " + command.getStorageId();
s_logger.warn(msg);
return new GetStorageStatsAnswer(command, msg);
}
}
use of com.cloud.agent.api.GetStorageStatsAnswer in project cloudstack by apache.
the class HypervDirectConnectResourceTest method testGetStorageStatsCommand.
@Test
public final void testGetStorageStatsCommand() {
// TODO: Update sample data to unsure it is using correct info.
String sample = "{\"id\":\"" + s_testLocalStoreUUID + "\",\"localPath\":" + s_testLocalStorePathJSON + "," + "\"pooltype\":\"Filesystem\"," + "\"contextMap\":{},\"wait\":0}";
s_logger.info("Sample JSON: " + sample);
GetStorageStatsCommand cmd = s_gson.fromJson(sample, GetStorageStatsCommand.class);
s_hypervresource.executeRequest(cmd);
GetStorageStatsAnswer ans = (GetStorageStatsAnswer) s_hypervresource.executeRequest(cmd);
Assert.assertTrue(ans.getDetails(), ans.getResult());
Assert.assertTrue(ans.getByteUsed() != ans.getCapacityBytes());
}
Aggregations