use of org.apache.cloudstack.storage.command.SyncVolumePathCommand in project cloudstack by apache.
the class StorageManagerImpl method handleRemoveChildStoragePoolFromDatastoreCluster.
private void handleRemoveChildStoragePoolFromDatastoreCluster(Set<String> childDatastoreUUIDs) {
for (String childDatastoreUUID : childDatastoreUUIDs) {
StoragePoolVO dataStoreVO = _storagePoolDao.findPoolByUUID(childDatastoreUUID);
List<VolumeVO> allVolumes = _volumeDao.findByPoolId(dataStoreVO.getId());
allVolumes.removeIf(volumeVO -> volumeVO.getInstanceId() == null);
allVolumes.removeIf(volumeVO -> volumeVO.getState() != Volume.State.Ready);
for (VolumeVO volume : allVolumes) {
VMInstanceVO vmInstance = _vmInstanceDao.findById(volume.getInstanceId());
if (vmInstance == null) {
continue;
}
long volumeId = volume.getId();
Long hostId = vmInstance.getHostId();
if (hostId == null) {
hostId = vmInstance.getLastHostId();
}
HostVO hostVO = _hostDao.findById(hostId);
// Prepare for the syncvolumepath command
DataTO volTO = volFactory.getVolume(volume.getId()).getTO();
DiskTO disk = new DiskTO(volTO, volume.getDeviceId(), volume.getPath(), volume.getVolumeType());
Map<String, String> details = new HashMap<String, String>();
details.put(DiskTO.PROTOCOL_TYPE, Storage.StoragePoolType.DatastoreCluster.toString());
disk.setDetails(details);
s_logger.debug(String.format("Attempting to process SyncVolumePathCommand for the volume %d on the host %d with state %s", volumeId, hostId, hostVO.getResourceState()));
SyncVolumePathCommand cmd = new SyncVolumePathCommand(disk);
final Answer answer = _agentMgr.easySend(hostId, cmd);
// validate answer
if (answer == null) {
throw new CloudRuntimeException("Unable to get an answer to the SyncVolumePath command for volume " + volumeId);
}
if (!answer.getResult()) {
throw new CloudRuntimeException("Unable to process SyncVolumePathCommand for the volume" + volumeId + " to the host " + hostId + " due to " + answer.getDetails());
}
assert (answer instanceof SyncVolumePathAnswer) : "Well, now why won't you actually return the SyncVolumePathAnswer when it's SyncVolumePathCommand? volume=" + volume.getUuid() + "Host=" + hostId;
// check for the changed details of volume and update database
VolumeVO volumeVO = _volumeDao.findById(volumeId);
String datastoreName = answer.getContextParam("datastoreName");
if (datastoreName != null) {
StoragePoolVO storagePoolVO = _storagePoolDao.findByUuid(datastoreName);
if (storagePoolVO != null) {
volumeVO.setPoolId(storagePoolVO.getId());
} else {
s_logger.warn(String.format("Unable to find datastore %s while updating the new datastore of the volume %d", datastoreName, volumeId));
}
}
String volumePath = answer.getContextParam("volumePath");
if (volumePath != null) {
volumeVO.setPath(volumePath);
}
String chainInfo = answer.getContextParam("chainInfo");
if (chainInfo != null) {
volumeVO.setChainInfo(chainInfo);
}
_volumeDao.update(volumeVO.getId(), volumeVO);
}
dataStoreVO.setParent(0L);
_storagePoolDao.update(dataStoreVO.getId(), dataStoreVO);
}
}
Aggregations