@@ -89,65 +89,71 @@ protected void runHeartBeat() {
8989 Set <String > removedPools = new HashSet <>();
9090 for (String uuid : storagePool .keySet ()) {
9191 HAStoragePool primaryStoragePool = storagePool .get (uuid );
92- StoragePool storage ;
9392 if (primaryStoragePool .getPool ().getType () == StoragePoolType .NetworkFilesystem ) {
94- try {
95- Connect conn = LibvirtConnection .getConnection ();
96- storage = conn .storagePoolLookupByUUIDString (uuid );
97- if (storage == null || storage .getInfo ().state != StoragePoolState .VIR_STORAGE_POOL_RUNNING ) {
98- if (storage == null ) {
99- s_logger .debug (String .format ("Libvirt storage pool [%s] not found, removing from HA list." , uuid ));
100- } else {
101- s_logger .debug (String .format ("Libvirt storage pool [%s] found, but not running, removing from HA list." , uuid ));
102- }
103-
104- removedPools .add (uuid );
105- continue ;
106- }
107-
108- s_logger .debug (String .format ("Found NFS storage pool [%s] in libvirt, continuing." , uuid ));
109-
110- } catch (LibvirtException e ) {
111- s_logger .debug (String .format ("Failed to lookup libvirt storage pool [%s]." , uuid ), e );
112-
113- if (e .toString ().contains ("pool not found" )) {
114- s_logger .debug (String .format ("Removing pool [%s] from HA monitor since it was deleted." , uuid ));
115- removedPools .add (uuid );
116- continue ;
117- }
93+ checkForNotExistingPools (removedPools , uuid );
94+ if (removedPools .contains (uuid )) {
95+ continue ;
11896 }
11997 }
120-
12198 String result = null ;
122- for (int i = 1 ; i <= _heartBeatUpdateMaxTries ; i ++) {
123- result = primaryStoragePool .getPool ().createHeartBeatCommand (primaryStoragePool , hostPrivateIp , true );
124-
125- if (result != null ) {
126- s_logger .warn (String .format ("Write heartbeat for pool [%s] failed: %s; try: %s of %s." , uuid , result , i , _heartBeatUpdateMaxTries ));
127- try {
128- Thread .sleep (_heartBeatUpdateRetrySleep );
129- } catch (InterruptedException e ) {
130- s_logger .debug ("[IGNORED] Interrupted between heartbeat retries." , e );
131- }
132- } else {
133- break ;
134- }
135-
136- }
99+ result = executePoolHeartBeatCommand (uuid , primaryStoragePool , result );
137100
138101 if (result != null && rebootHostAndAlertManagementOnHeartbeatTimeout ) {
139102 s_logger .warn (String .format ("Write heartbeat for pool [%s] failed: %s; stopping cloudstack-agent." , uuid , result ));
140103 primaryStoragePool .getPool ().createHeartBeatCommand (primaryStoragePool , null , false );;
141104 }
142105 }
143-
144106 if (!removedPools .isEmpty ()) {
145107 for (String uuid : removedPools ) {
146108 removeStoragePool (uuid );
147109 }
148110 }
149111 }
112+ }
150113
114+ private String executePoolHeartBeatCommand (String uuid , HAStoragePool primaryStoragePool , String result ) {
115+ for (int i = 1 ; i <= _heartBeatUpdateMaxTries ; i ++) {
116+ result = primaryStoragePool .getPool ().createHeartBeatCommand (primaryStoragePool , hostPrivateIp , true );
117+
118+ if (result != null ) {
119+ s_logger .warn (String .format ("Write heartbeat for pool [%s] failed: %s; try: %s of %s." , uuid , result , i , _heartBeatUpdateMaxTries ));
120+ try {
121+ Thread .sleep (_heartBeatUpdateRetrySleep );
122+ } catch (InterruptedException e ) {
123+ s_logger .debug ("[IGNORED] Interrupted between heartbeat retries." , e );
124+ }
125+ } else {
126+ break ;
127+ }
128+
129+ }
130+ return result ;
131+ }
132+
133+ private void checkForNotExistingPools (Set <String > removedPools , String uuid ) {
134+ try {
135+ Connect conn = LibvirtConnection .getConnection ();
136+ StoragePool storage = conn .storagePoolLookupByUUIDString (uuid );
137+ if (storage == null || storage .getInfo ().state != StoragePoolState .VIR_STORAGE_POOL_RUNNING ) {
138+ if (storage == null ) {
139+ s_logger .debug (String .format ("Libvirt storage pool [%s] not found, removing from HA list." , uuid ));
140+ } else {
141+ s_logger .debug (String .format ("Libvirt storage pool [%s] found, but not running, removing from HA list." , uuid ));
142+ }
143+
144+ removedPools .add (uuid );
145+ }
146+
147+ s_logger .debug (String .format ("Found NFS storage pool [%s] in libvirt, continuing." , uuid ));
148+
149+ } catch (LibvirtException e ) {
150+ s_logger .debug (String .format ("Failed to lookup libvirt storage pool [%s]." , uuid ), e );
151+
152+ if (e .toString ().contains ("pool not found" )) {
153+ s_logger .debug (String .format ("Removing pool [%s] from HA monitor since it was deleted." , uuid ));
154+ removedPools .add (uuid );
155+ }
156+ }
151157 }
152158
153159 @ Override
0 commit comments