Github user GabrielBrascher commented on a diff in the pull request: https://github.com/apache/cloudstack/pull/1559#discussion_r83628876 --- Diff: engine/storage/volume/src/org/apache/cloudstack/storage/volume/VolumeDataFactoryImpl.java --- @@ -77,22 +80,51 @@ public VolumeInfo getVolume(long volumeId, DataStoreRole storeRole) { @Override public VolumeInfo getVolume(long volumeId) { + return getVolume(volumeId, false); + } + + @Override + public VolumeInfo getVolumeForExpunge(long volumeId) { + return getVolume(volumeId, true); + } + + protected VolumeInfo getVolume(long volumeId, boolean forExpunge) { VolumeVO volumeVO = volumeDao.findByIdIncludingRemoved(volumeId); if (volumeVO == null) { return null; } + + String dataStoreRole = ""; VolumeObject vol = null; if (volumeVO.getPoolId() == null) { + dataStoreRole = DataStoreRole.Image.toString(); DataStore store = null; VolumeDataStoreVO volumeStore = volumeStoreDao.findByVolume(volumeId); if (volumeStore != null) { - store = storeMgr.getDataStore(volumeStore.getDataStoreId(), DataStoreRole.Image); + if (forExpunge) { + store = storeMgr.getDataStoreForExpunge(volumeStore.getDataStoreId(), DataStoreRole.Image); + } else { + store = storeMgr.getDataStore(volumeStore.getDataStoreId(), DataStoreRole.Image); + } } + vol = VolumeObject.getVolumeObject(store, volumeVO); } else { - DataStore store = storeMgr.getDataStore(volumeVO.getPoolId(), DataStoreRole.Primary); + DataStore store = null; + dataStoreRole = DataStoreRole.Primary.toString(); + if (forExpunge) { + store = storeMgr.getDataStoreForExpunge(volumeVO.getPoolId(), DataStoreRole.Primary); + } else { + store = storeMgr.getDataStore(volumeVO.getPoolId(), DataStoreRole.Primary); + } + vol = VolumeObject.getVolumeObject(store, volumeVO); } + + if (vol.getDataStore() == null && forExpunge) { + logger.warn("Was unable to find a DataStore (role = " + dataStoreRole + ") for expunged volume " + volumeId); --- End diff -- Just a tip here. The [String format](https://docs.oracle.com/javase/7/docs/api/java/util/Formatter.html) can be very handy in cases like this.
--- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---