Skip to content

Commit 81dbc3c

Browse files
committed
Fix of publish event for deleted snapshot
1 parent 0b0a065 commit 81dbc3c

File tree

4 files changed

+7
-4
lines changed

4 files changed

+7
-4
lines changed

engine/schema/src/main/java/org/apache/cloudstack/storage/datastore/db/SnapshotDataStoreDaoImpl.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ public boolean configure(String name, Map<String, Object> params) throws Configu
191191

192192
searchBySnapshotId = createSearchBuilder();
193193
searchBySnapshotId.and(SNAPSHOT_ID, searchBySnapshotId.entity().getSnapshotId(), SearchCriteria.Op.EQ);
194+
searchBySnapshotId.and(STATE, searchBySnapshotId.entity().getState(), SearchCriteria.Op.EQ);
194195
searchBySnapshotId.done();
195196

196197
return true;
@@ -426,6 +427,7 @@ public List<SnapshotDataStoreVO> listReadyBySnapshot(long snapshotId, DataStoreR
426427
@Override
427428
public List<SnapshotDataStoreVO> listReadyBySnapshotId(long snapshotId) {
428429
SearchCriteria<SnapshotDataStoreVO> sc = searchBySnapshotId.create();
430+
sc.setParameters(SNAPSHOT_ID, snapshotId);
429431
sc.setParameters(STATE, State.Ready);
430432
return listBy(sc);
431433
}

plugins/storage/volume/storpool/src/main/java/org/apache/cloudstack/storage/snapshot/StorPoolSnapshotStrategy.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,8 @@ private boolean deleteSnapshotFromDbIfNeeded(SnapshotVO snapshotVO, Long zoneId)
367367
List<SnapshotDataStoreVO> storeRefs = _snapshotStoreDao.listBySnapshotAndDataStoreRole(snapshotId, DataStoreRole.Image);
368368
if (zoneId != null) {
369369
storeRefs.removeIf(ref -> !zoneId.equals(dataStoreMgr.getStoreZoneId(ref.getDataStoreId(), ref.getRole())));
370+
} else {
371+
storeRefs.removeIf(ref -> !ref.getState().equals(State.Ready));
370372
}
371373
for (SnapshotDataStoreVO ref : storeRefs) {
372374
if (!deleteSnapshotOnImageAndPrimary(snapshotId, dataStoreMgr.getDataStore(ref.getDataStoreId(), ref.getRole()))) {

server/src/main/java/com/cloud/storage/snapshot/SnapshotManagerImpl.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -904,8 +904,7 @@ public boolean deleteSnapshot(long snapshotId, Long zoneId) {
904904
boolean result = snapshotStrategy.deleteSnapshot(snapshotId, zoneId);
905905
if (result) {
906906
for (Long zId : zoneIds) {
907-
List<SnapshotDataStoreVO> listActiveSnapshots = _snapshotStoreDao.listReadyBySnapshotId(snapshotId);
908-
if (snapshotCheck.getState() == Snapshot.State.BackedUp && CollectionUtils.isEmpty(listActiveSnapshots)) {
907+
if (snapshotCheck.getState() == Snapshot.State.BackedUp) {
909908
UsageEventUtils.publishUsageEvent(EventTypes.EVENT_SNAPSHOT_DELETE, snapshotCheck.getAccountId(), zId, snapshotId,
910909
snapshotCheck.getName(), null, null, 0L, snapshotCheck.getClass().getName(), snapshotCheck.getUuid());
911910
}
@@ -1738,7 +1737,7 @@ private boolean copySnapshotOnPool(SnapshotInfo snapshot, SnapshotStrategy snaps
17381737
_resourceLimitMgr.incrementResourceCount(CallContext.current().getCallingUserId(), ResourceType.primary_storage, snapshot.getSize());
17391738
if (CallContext.current().getCallingUserId() != Account.ACCOUNT_ID_SYSTEM) {
17401739
SnapshotVO snapshotVO = _snapshotDao.findByIdIncludingRemoved(snapshot.getSnapshotId());
1741-
UsageEventUtils.publishUsageEvent(EventTypes.EVENT_SNAPSHOT_COPY, CallContext.current().getCallingUserId(), snapshotOnStore.getDataCenterId(), snapshotVO.getId(), null, null, null, snapshotVO.getSize(),
1740+
UsageEventUtils.publishUsageEvent(EventTypes.EVENT_SNAPSHOT_COPY, CallContext.current().getCallingAccountId(), snapshotOnStore.getDataCenterId(), snapshotVO.getId(), null, null, null, snapshotVO.getSize(),
17421741
snapshotVO.getSize(), snapshotVO.getClass().getName(), snapshotVO.getUuid());
17431742
}
17441743
} catch (InterruptedException | ExecutionException e) {

server/src/main/java/org/apache/cloudstack/snapshot/SnapshotHelper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ public List<Long> addStoragePoolsForCopyToPrimary(VolumeInfo volume, List<Long>
345345
if (volume == null) {
346346
throw new InvalidParameterValueException("Could not find volume of a snapshot");
347347
}
348-
if (CollectionUtils.isEmpty(destZoneIds) && CollectionUtils.isEmpty(storagePoolIds)) {
348+
if (CollectionUtils.isEmpty(destZoneIds)) {
349349
throw new InvalidParameterValueException("There is no destination zone provided");
350350
}
351351
if (CollectionUtils.isEmpty(storagePoolIds)) {

0 commit comments

Comments
 (0)