Skip to content

Commit 12fb59c

Browse files
Handle storage pool disconnect in a host
1 parent 7d8cede commit 12fb59c

File tree

1 file changed

+37
-2
lines changed

1 file changed

+37
-2
lines changed

engine/storage/volume/src/main/java/org/apache/cloudstack/storage/datastore/provider/DefaultHostListener.java

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import com.cloud.agent.AgentManager;
2222
import com.cloud.agent.api.Answer;
2323
import com.cloud.agent.api.CleanupPersistentNetworkResourceCommand;
24+
import com.cloud.agent.api.DeleteStoragePoolCommand;
2425
import com.cloud.agent.api.ModifyStoragePoolAnswer;
2526
import com.cloud.agent.api.ModifyStoragePoolCommand;
2627
import com.cloud.agent.api.SetupPersistentNetworkCommand;
@@ -45,6 +46,7 @@
4546
import com.cloud.storage.dao.StoragePoolHostDao;
4647
import com.cloud.utils.exception.CloudRuntimeException;
4748

49+
import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
4850
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager;
4951
import org.apache.cloudstack.engine.subsystem.api.storage.HypervisorHostListener;
5052
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
@@ -207,8 +209,41 @@ private void updateStoragePoolHostVOAndDetails(StoragePool pool, long hostId, Mo
207209

208210
@Override
209211
public boolean hostDisconnected(long hostId, long poolId) {
210-
// TODO Auto-generated method stub
211-
return false;
212+
HostVO host = hostDao.findById(hostId);
213+
if (host == null) {
214+
logger.error("Failed to disconnect host by HostListener as host was not found with id : " + hostId);
215+
return false;
216+
}
217+
218+
DataStore dataStore = dataStoreMgr.getDataStore(poolId, DataStoreRole.Primary);
219+
StoragePool storagePool = (StoragePool) dataStore;
220+
DeleteStoragePoolCommand cmd = new DeleteStoragePoolCommand(storagePool);
221+
Answer answer = sendDeleteStoragePoolCommand(cmd, storagePool, host);
222+
if (!answer.getResult()) {
223+
logger.error("Failed to disconnect storage pool: " + storagePool + " and host: " + host);
224+
return false;
225+
}
226+
227+
StoragePoolHostVO storagePoolHost = storagePoolHostDao.findByPoolHost(poolId, hostId);
228+
if (storagePoolHost != null) {
229+
storagePoolHostDao.deleteStoragePoolHostDetails(hostId, poolId);
230+
}
231+
logger.info("Connection removed between storage pool: " + storagePool + " and host: " + host);
232+
return true;
233+
}
234+
235+
private Answer sendDeleteStoragePoolCommand(DeleteStoragePoolCommand cmd, StoragePool storagePool, HostVO host) {
236+
Answer answer = agentMgr.easySend(host.getId(), cmd);
237+
if (answer == null) {
238+
throw new CloudRuntimeException(String.format("Unable to get an answer to the delete storage pool command for storage pool %s, sent to host %s", storagePool, host));
239+
}
240+
241+
if (!answer.getResult()) {
242+
String msg = "Unable to detach storage pool " + storagePool + " from the host " + host;
243+
alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_HOST, storagePool.getDataCenterId(), storagePool.getPodId(), msg, msg);
244+
}
245+
246+
return answer;
212247
}
213248

214249
@Override

0 commit comments

Comments
 (0)