Skip to content

Commit 11e4ded

Browse files
author
kishan
committed
Bug 13619: Throw exception when not traffic sentinel host is not available. Update last_collection timestamp when atleast 1 IP has nonzero bytes
Status 13619: resolved fixed Reviewed-By: Nitin
1 parent 4dea695 commit 11e4ded

2 files changed

Lines changed: 12 additions & 4 deletions

File tree

‎core/src/com/cloud/network/resource/TrafficSentinelResource.java‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,11 +229,13 @@ private DirectNetworkUsageAnswer getPublicIpBytesSentAndReceived(DirectNetworkUs
229229
in.close();
230230
} catch (MalformedURLException e1) {
231231
s_logger.info("Invalid Traffic Sentinel URL",e1);
232+
throw new ExecutionException(e1.getMessage());
232233
} catch (IOException e) {
233234
s_logger.debug("Error in direct network usage accounting",e);
235+
throw new ExecutionException(e.getMessage());
234236
}
235237
} catch (Exception e) {
236-
s_logger.error(e);
238+
s_logger.debug(e);
237239
throw new ExecutionException(e.getMessage());
238240
}
239241
return answer;

‎server/src/com/cloud/network/NetworkUsageManagerImpl.java‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -372,15 +372,16 @@ private boolean collectDirectNetworkUsage(HostVO host){
372372
}
373373

374374
List<UserStatisticsVO> collectedStats = new ArrayList<UserStatisticsVO>();
375-
376-
//Get usage for Ips for which were assigned for the entire duration
375+
376+
//Get usage for Ips which were assigned for the entire duration
377377
if(fullDurationIpUsage.size() > 0){
378378
DirectNetworkUsageCommand cmd = new DirectNetworkUsageCommand(IpList, lastCollection, now);
379379
DirectNetworkUsageAnswer answer = (DirectNetworkUsageAnswer) _agentMgr.easySend(host.getId(), cmd);
380380
if (answer == null || !answer.getResult()) {
381381
String details = (answer != null) ? answer.getDetails() : "details unavailable";
382382
String msg = "Unable to get network usage stats from " + host.getId() + " due to: " + details + ".";
383383
s_logger.error(msg);
384+
return false;
384385
} else {
385386
for(UsageIPAddressVO usageIp : fullDurationIpUsage){
386387
String publicIp = usageIp.getAddress();
@@ -403,7 +404,7 @@ private boolean collectDirectNetworkUsage(HostVO host){
403404
}
404405
}
405406

406-
//Get usage for Ips for which were assigned for part of the duration period
407+
//Get usage for Ips which were assigned for part of the duration period
407408
for(UsageIPAddressVO usageIp : IpPartialUsage){
408409
IpList = new ArrayList<String>() ;
409410
IpList.add(usageIp.getAddress());
@@ -413,6 +414,7 @@ private boolean collectDirectNetworkUsage(HostVO host){
413414
String details = (answer != null) ? answer.getDetails() : "details unavailable";
414415
String msg = "Unable to get network usage stats from " + host.getId() + " due to: " + details + ".";
415416
s_logger.error(msg);
417+
return false;
416418
} else {
417419
String publicIp = usageIp.getAddress();
418420
long[] bytesSentRcvd = answer.get(publicIp);
@@ -434,6 +436,10 @@ private boolean collectDirectNetworkUsage(HostVO host){
434436
}
435437
}
436438

439+
if(collectedStats.size() == 0){
440+
s_logger.debug("No new direct network stats. No need to persist");
441+
return false;
442+
}
437443
//Persist all the stats and last_collection time in a single transaction
438444
Transaction txn = Transaction.open(Transaction.CLOUD_DB);
439445
try {

0 commit comments

Comments
 (0)