List<UserStatisticsVO> collectedStats = new ArrayList<UserStatisticsVO>();
//Get usage for Ips which were assigned for the entire duration
if(fullDurationIpUsage.size() > 0){
DirectNetworkUsageCommand cmd = new DirectNetworkUsageCommand(IpList, lastCollection, now, _TSinclZones, _TSexclZones);
DirectNetworkUsageAnswer answer = (DirectNetworkUsageAnswer) _agentMgr.easySend(host.getId(), cmd);
if (answer == null || !answer.getResult()) {
String details = (answer != null) ? answer.getDetails() : "details unavailable";
String msg = "Unable to get network usage stats from " + host.getId() + " due to: " + details + ".";
s_logger.error(msg);
return false;
} else {
for(UsageIPAddressVO usageIp : fullDurationIpUsage){
String publicIp = usageIp.getAddress();
long[] bytesSentRcvd = answer.get(publicIp);
Long bytesSent = bytesSentRcvd[0];
Long bytesRcvd = bytesSentRcvd[1];
if(bytesSent == null || bytesRcvd == null){
s_logger.debug("Incorrect bytes for IP: "+publicIp);
continue;
}
if(bytesSent == 0L && bytesRcvd == 0L){
s_logger.trace("Ignore zero bytes for IP: "+publicIp);
continue;
}
UserStatisticsVO stats = new UserStatisticsVO(usageIp.getAccountId(), zoneId, null, null, null, null);
stats.setCurrentBytesSent(bytesSent);
stats.setCurrentBytesReceived(bytesRcvd);
collectedStats.add(stats);
}
}
}
//Get usage for Ips which were assigned for part of the duration period
for(UsageIPAddressVO usageIp : IpPartialUsage){
IpList = new ArrayList<String>() ;
IpList.add(usageIp.getAddress());
DirectNetworkUsageCommand cmd = new DirectNetworkUsageCommand(IpList, usageIp.getAssigned(), usageIp.getReleased(), _TSinclZones, _TSexclZones);
DirectNetworkUsageAnswer answer = (DirectNetworkUsageAnswer) _agentMgr.easySend(host.getId(), cmd);
if (answer == null || !answer.getResult()) {
String details = (answer != null) ? answer.getDetails() : "details unavailable";
String msg = "Unable to get network usage stats from " + host.getId() + " due to: " + details + ".";
s_logger.error(msg);
return false;
} else {
String publicIp = usageIp.getAddress();
long[] bytesSentRcvd = answer.get(publicIp);
Long bytesSent = bytesSentRcvd[0];
Long bytesRcvd = bytesSentRcvd[1];
if(bytesSent == null || bytesRcvd == null){
s_logger.debug("Incorrect bytes for IP: "+publicIp);
continue;