Skip to content

Commit db53556

Browse files
author
gitlab
committed
Merge branch 'fix_bug_10005_@@2' into 'master'
fix data volume bill bug (fix ZSTAC-10005) Closes ZSTAC-10005 See merge request zstackio/zstack!2378
2 parents cac4dcd + 26032ee commit db53556

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

header/src/main/java/org/zstack/header/volume/VolumeCanonicalEvents.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public static class VolumeStatusChangedData {
1717
private String newStatus;
1818
private VolumeInventory inventory;
1919
private Date date = new Date();
20+
private String accountUuid;
2021

2122
public String getVolumeUuid() {
2223
return volumeUuid;
@@ -57,5 +58,13 @@ public Date getDate() {
5758
public void setDate(Date date) {
5859
this.date = date;
5960
}
61+
62+
public String getAccountUuid() {
63+
return accountUuid;
64+
}
65+
66+
public void setAccountUuid(String accountUuid) {
67+
this.accountUuid = accountUuid;
68+
}
6069
}
6170
}

storage/src/main/java/org/zstack/storage/volume/FireVolumeCanonicalEvent.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44
import org.springframework.beans.factory.annotation.Autowired;
55
import org.springframework.beans.factory.annotation.Configurable;
66
import org.zstack.core.cloudbus.EventFacade;
7+
import org.zstack.core.db.Q;
8+
import org.zstack.header.identity.AccountResourceRefVO;
9+
import org.zstack.header.identity.AccountResourceRefVO_;
710
import org.zstack.header.volume.VolumeCanonicalEvents;
811
import org.zstack.header.volume.VolumeInventory;
912
import org.zstack.header.volume.VolumeStatus;
10-
1113
import java.util.Date;
1214

1315
/**
@@ -19,12 +21,23 @@ public class FireVolumeCanonicalEvent {
1921
private EventFacade evtf;
2022

2123
public void fireVolumeStatusChangedEvent(VolumeStatus oldStatus, VolumeInventory vol) {
24+
25+
String accountUuid = null;
26+
27+
boolean volumeAccountExists = Q.New(AccountResourceRefVO.class).gt(AccountResourceRefVO_.resourceUuid, vol.getUuid()).isExists();
28+
if (volumeAccountExists) {
29+
accountUuid = Q.New(AccountResourceRefVO.class)
30+
.select(AccountResourceRefVO_.ownerAccountUuid)
31+
.gt(AccountResourceRefVO_.resourceUuid, vol.getUuid()).limit(1).findValue();
32+
}
33+
2234
VolumeCanonicalEvents.VolumeStatusChangedData d = new VolumeCanonicalEvents.VolumeStatusChangedData();
2335
d.setInventory(vol);
2436
d.setDate(new Date());
2537
d.setNewStatus(vol.getStatus());
2638
d.setOldStatus(oldStatus == null ? null : oldStatus.toString());
2739
d.setVolumeUuid(vol.getUuid());
40+
d.setAccountUuid(accountUuid);
2841
evtf.fire(VolumeCanonicalEvents.VOLUME_STATUS_CHANGED_PATH, d);
2942
}
3043
}

storage/src/main/java/org/zstack/storage/volume/VolumeBase.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -780,7 +780,9 @@ public void handle(Map data) {
780780
self = dbf.updateAndRefresh(self);
781781
new FireVolumeCanonicalEvent().fireVolumeStatusChangedEvent(oldStatus, getSelfInventory());
782782
} else if (deletionPolicy == VolumeDeletionPolicy.DBOnly) {
783-
new FireVolumeCanonicalEvent().fireVolumeStatusChangedEvent(oldStatus, getSelfInventory());
783+
VolumeInventory inventory = getSelfInventory();
784+
inventory.setStatus(VolumeStatus.Deleted.toString());
785+
new FireVolumeCanonicalEvent().fireVolumeStatusChangedEvent(oldStatus, inventory);
784786
dbf.remove(self);
785787
} else {
786788
throw new CloudRuntimeException(String.format("Invalid deletionPolicy:%s", deletionPolicy));

0 commit comments

Comments
 (0)