@@ -687,18 +687,17 @@ protected void runInContext() {
687687 return ;
688688 }
689689 // collect the vm disk statistics(total) from hypervisor. added by weizhou, 2013.03.
690- s_logger .trace ("Running VM disk stats ..." );
691- try {
692- Transaction .execute (new TransactionCallbackNoReturn () {
693- @ Override
694- public void doInTransactionWithoutResult (TransactionStatus status ) {
695- s_logger .debug ("VmDiskStatsTask is running..." );
690+ s_logger .debug ("VmDiskStatsTask is running..." );
696691
697- SearchCriteria <HostVO > sc = createSearchCriteriaForHostTypeRoutingStateUpAndNotInMaintenance ();
698- sc .addAnd ("hypervisorType" , SearchCriteria .Op .IN , HypervisorType .KVM , HypervisorType .VMware );
699- List <HostVO > hosts = _hostDao .search (sc , null );
692+ SearchCriteria <HostVO > sc = createSearchCriteriaForHostTypeRoutingStateUpAndNotInMaintenance ();
693+ sc .addAnd ("hypervisorType" , SearchCriteria .Op .IN , HypervisorType .KVM , HypervisorType .VMware );
694+ List <HostVO > hosts = _hostDao .search (sc , null );
700695
701- for (HostVO host : hosts ) {
696+ for (HostVO host : hosts ) {
697+ try {
698+ Transaction .execute (new TransactionCallbackNoReturn () {
699+ @ Override
700+ public void doInTransactionWithoutResult (TransactionStatus status ) {
702701 List <UserVmVO > vms = _userVmDao .listRunningByHostId (host .getId ());
703702 List <Long > vmIds = new ArrayList <Long >();
704703
@@ -709,7 +708,7 @@ public void doInTransactionWithoutResult(TransactionStatus status) {
709708
710709 HashMap <Long , List <VmDiskStatsEntry >> vmDiskStatsById = _userVmMgr .getVmDiskStatistics (host .getId (), host .getName (), vmIds );
711710 if (vmDiskStatsById == null )
712- continue ;
711+ return ;
713712
714713 Set <Long > vmIdSet = vmDiskStatsById .keySet ();
715714 for (Long vmId : vmIdSet ) {
@@ -796,10 +795,10 @@ public void doInTransactionWithoutResult(TransactionStatus status) {
796795 }
797796 }
798797 }
799- }
800- });
801- } catch ( Exception e ) {
802- s_logger . warn ( "Error while collecting vm disk stats from hosts" , e );
798+ });
799+ } catch ( Exception e ) {
800+ s_logger . warn ( String . format ( "Error while collecting vm disk stats from host %s : " , host . getName ()), e );
801+ }
803802 }
804803 }
805804 }
@@ -815,16 +814,16 @@ protected void runInContext() {
815814 return ;
816815 }
817816 // collect the vm network statistics(total) from hypervisor
818- try {
819- Transaction .execute (new TransactionCallbackNoReturn () {
820- @ Override
821- public void doInTransactionWithoutResult (TransactionStatus status ) {
822- s_logger .debug ("VmNetworkStatsTask is running..." );
817+ s_logger .debug ("VmNetworkStatsTask is running..." );
823818
824- SearchCriteria <HostVO > sc = createSearchCriteriaForHostTypeRoutingStateUpAndNotInMaintenance ();
825- List <HostVO > hosts = _hostDao .search (sc , null );
819+ SearchCriteria <HostVO > sc = createSearchCriteriaForHostTypeRoutingStateUpAndNotInMaintenance ();
820+ List <HostVO > hosts = _hostDao .search (sc , null );
826821
827- for (HostVO host : hosts ) {
822+ for (HostVO host : hosts ) {
823+ try {
824+ Transaction .execute (new TransactionCallbackNoReturn () {
825+ @ Override
826+ public void doInTransactionWithoutResult (TransactionStatus status ) {
828827 List <UserVmVO > vms = _userVmDao .listRunningByHostId (host .getId ());
829828 List <Long > vmIds = new ArrayList <Long >();
830829
@@ -835,7 +834,7 @@ public void doInTransactionWithoutResult(TransactionStatus status) {
835834
836835 HashMap <Long , List <VmNetworkStatsEntry >> vmNetworkStatsById = _userVmMgr .getVmNetworkStatistics (host .getId (), host .getName (), vmIds );
837836 if (vmNetworkStatsById == null )
838- continue ;
837+ return ;
839838
840839 Set <Long > vmIdSet = vmNetworkStatsById .keySet ();
841840 for (Long vmId : vmIdSet ) {
@@ -915,10 +914,10 @@ public void doInTransactionWithoutResult(TransactionStatus status) {
915914 }
916915 }
917916 }
918- }
919- });
920- } catch ( Exception e ) {
921- s_logger . warn ( "Error while collecting vm network stats from hosts" , e );
917+ });
918+ } catch ( Exception e ) {
919+ s_logger . warn ( String . format ( "Error while collecting vm network stats from host %s : " , host . getName ()), e );
920+ }
922921 }
923922 }
924923 }
0 commit comments