forked from zstackio/zstack
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
<fix>[trash]: fix storage trash capacity calculation
1、when calculating the primary storage capacity, it is necessary to calculate the trash size. 2、When creating a volume trash, the size should be the actual size and necessary to reduce capacity. Resolves/Related: ZSTAC-68260 Change-Id: I62656562636d7777646e6f6b787769727a716f6d
- Loading branch information
shan.wu
committed
Dec 13, 2024
1 parent
f1720a7
commit 11c6284
Showing
19 changed files
with
444 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 0 additions & 10 deletions
10
core/src/main/java/org/zstack/core/trash/CreateRecycleExtensionPoint.java
This file was deleted.
Oops, something went wrong.
85 changes: 85 additions & 0 deletions
85
core/src/main/java/org/zstack/core/trash/DefaultPrimaryStorageTrashLifeCycleExtension.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package org.zstack.core.trash; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.zstack.core.cloudbus.CloudBus; | ||
import org.zstack.core.db.DatabaseFacade; | ||
import org.zstack.header.core.trash.InstallPathRecycleInventory; | ||
import org.zstack.header.core.trash.InstallPathRecycleVO; | ||
import org.zstack.header.storage.primary.AllocatePrimaryStorageSpaceMsg; | ||
import org.zstack.header.storage.primary.PrimaryStorageConstant; | ||
import org.zstack.header.storage.primary.PrimaryStorageVO; | ||
import org.zstack.header.storage.primary.ReleasePrimaryStorageSpaceMsg; | ||
import org.zstack.utils.Utils; | ||
import org.zstack.utils.logging.CLogger; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
|
||
public class DefaultPrimaryStorageTrashLifeCycleExtension implements StorageTrashLifeCycleExtensionPoint { | ||
@Autowired | ||
private DatabaseFacade dbf; | ||
|
||
@Autowired | ||
private CloudBus bus; | ||
|
||
private final static CLogger logger = Utils.getLogger(DefaultPrimaryStorageTrashLifeCycleExtension.class); | ||
|
||
protected boolean isPrimaryStorage(String storageType) { | ||
return PrimaryStorageVO.class.getSimpleName().equals(storageType); | ||
} | ||
|
||
@Override | ||
public void beforeCreateTrash(InstallPathRecycleVO vo) { | ||
} | ||
|
||
@Override | ||
public List<Long> afterCreateTrash(List<InstallPathRecycleInventory> inventoryList) { | ||
if (inventoryList.isEmpty()) { | ||
return Collections.EMPTY_LIST; | ||
} | ||
Map<String, Long> storageTrashMap = inventoryList.stream().filter(i -> isPrimaryStorage(i.getStorageType())) | ||
.collect(Collectors.groupingBy(InstallPathRecycleInventory::getStorageUuid, | ||
Collectors.summingLong(InstallPathRecycleInventory::getSize))); | ||
List<AllocatePrimaryStorageSpaceMsg> amsgs = storageTrashMap.entrySet().stream().map(e -> { | ||
String storageUuid = e.getKey(); | ||
Long totalTrashSize = e.getValue(); | ||
AllocatePrimaryStorageSpaceMsg amsg = new AllocatePrimaryStorageSpaceMsg(); | ||
amsg.setForce(true); | ||
amsg.setRequiredPrimaryStorageUuid(storageUuid); | ||
amsg.setNoOverProvisioning(true); | ||
amsg.setRequiredInstallUri(inventoryList.get(0).getInstallPath()); | ||
amsg.setSize(totalTrashSize); | ||
bus.makeTargetServiceIdByResourceUuid(amsg, PrimaryStorageConstant.SERVICE_ID, amsg.getRequiredPrimaryStorageUuid()); | ||
return amsg; | ||
}).collect(Collectors.toList()); | ||
bus.send(amsgs); | ||
return inventoryList.stream().map(InstallPathRecycleInventory::getTrashId).collect(Collectors.toList()); | ||
} | ||
|
||
@Override | ||
public List<Long> beforeRemoveTrash(List<InstallPathRecycleInventory> inventoryList) { | ||
if (inventoryList.isEmpty()) { | ||
return Collections.EMPTY_LIST; | ||
} | ||
Map<String, Long> storageTrashMap = inventoryList.stream().filter(i -> isPrimaryStorage(i.getStorageType())) | ||
.collect(Collectors.groupingBy(InstallPathRecycleInventory::getStorageUuid, | ||
Collectors.summingLong(InstallPathRecycleInventory::getSize))); | ||
List<ReleasePrimaryStorageSpaceMsg> rmsgs = storageTrashMap.entrySet().stream().map(e -> { | ||
String storageUuid = e.getKey(); | ||
Long totalTrashSize = e.getValue(); | ||
ReleasePrimaryStorageSpaceMsg amsg = new ReleasePrimaryStorageSpaceMsg(); | ||
amsg.setPrimaryStorageUuid(storageUuid); | ||
amsg.setNoOverProvisioning(true); | ||
amsg.setAllocatedInstallUrl(inventoryList.get(0).getInstallPath()); | ||
amsg.setDiskSize(totalTrashSize); | ||
bus.makeTargetServiceIdByResourceUuid(amsg, PrimaryStorageConstant.SERVICE_ID, amsg.getPrimaryStorageUuid()); | ||
return amsg; | ||
}).collect(Collectors.toList()); | ||
bus.send(rmsgs); | ||
return inventoryList.stream().map(InstallPathRecycleInventory::getTrashId).collect(Collectors.toList()); | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
core/src/main/java/org/zstack/core/trash/StorageTrashLifeCycleExtensionPoint.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package org.zstack.core.trash; | ||
|
||
import org.zstack.header.core.trash.InstallPathRecycleInventory; | ||
import org.zstack.header.core.trash.InstallPathRecycleVO; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* Created by mingjian.deng on 2019/10/29. | ||
*/ | ||
public interface StorageTrashLifeCycleExtensionPoint { | ||
void beforeCreateTrash(InstallPathRecycleVO vo); | ||
|
||
List<Long> afterCreateTrash(List<InstallPathRecycleInventory> inventoryList); | ||
|
||
List<Long> beforeRemoveTrash(List<InstallPathRecycleInventory> inventoryList); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.