@@ -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