protected GetVmStatsAnswer execute( GetVmStatsCommand cmd) {
Connection conn = getConnection();
List<String> vmNames = cmd.getVmNames();
HashMap<String, VmStatsEntry> vmStatsNameMap = new HashMap<String, VmStatsEntry>();
if( vmNames.size() == 0 ) {
return new GetVmStatsAnswer(cmd, vmStatsNameMap);
}
try {
// Determine the UUIDs of the requested VMs
List<String> vmUUIDs = new ArrayList<String>();
for (String vmName : vmNames) {
VM vm = getVM(conn, vmName);
vmUUIDs.add(vm.getUuid(conn));
}
HashMap<String, VmStatsEntry> vmStatsUUIDMap = getVmStats(conn, cmd, vmUUIDs, cmd.getHostGuid());
if( vmStatsUUIDMap == null ) {
return new GetVmStatsAnswer(cmd, vmStatsNameMap);
}
for (String vmUUID : vmStatsUUIDMap.keySet()) {
vmStatsNameMap.put(vmNames.get(vmUUIDs.indexOf(vmUUID)), vmStatsUUIDMap.get(vmUUID));
}
return new GetVmStatsAnswer(cmd, vmStatsNameMap);
} catch (XenAPIException e) {
String msg = "Unable to get VM stats" + e.toString();
s_logger.warn(msg, e);
return new GetVmStatsAnswer(cmd, vmStatsNameMap);
} catch (XmlRpcException e) {
String msg = "Unable to get VM stats" + e.getMessage();
s_logger.warn(msg, e);
return new GetVmStatsAnswer(cmd, vmStatsNameMap);
}
}