Pearl1594 commented on a change in pull request #4617:
URL: https://github.com/apache/cloudstack/pull/4617#discussion_r565240438
##########
File path: server/src/main/java/com/cloud/projects/ProjectManagerImpl.java
##########
@@ -313,7 +338,29 @@ public boolean deleteProject(long projectId) {
CallContext.current().setProject(project);
_accountMgr.checkAccess(ctx.getCallingAccount(),
AccessType.ModifyProject, true,
_accountMgr.getAccount(project.getProjectAccountId()));
- return deleteProject(ctx.getCallingAccount(), ctx.getCallingUserId(),
project);
+ if (isCleanup != null && isCleanup) {
+ return deleteProject(ctx.getCallingAccount(),
ctx.getCallingUserId(), project);
+ } else {
+ List<VMTemplateVO> userTemplates =
_templateDao.listByAccountId(project.getProjectAccountId());
+ List<VMSnapshotVO> vmSnapshots =
_vmSnapshotDao.listByAccountId(project.getProjectAccountId());
+ List<UserVmVO> vms =
_userVmDao.listByAccountId(project.getProjectAccountId());
+ List<VolumeVO> volumes =
_volumeDao.findDetachedByAccount(project.getProjectAccountId());
+ List<NetworkVO> networks =
_networkDao.listByOwner(project.getProjectAccountId());
+ List<? extends Vpc> vpcs =
_vpcMgr.getVpcsForAccount(project.getProjectAccountId());
+
+ Optional<String> message = Stream.of(userTemplates, vmSnapshots,
vms, volumes, networks, vpcs)
Review comment:
Overall, LGTM. But would it be better, if we could inform the user about
all the resources that are tied to the project as opposed to the first one
that's found - by doing something like this:
```
List<String> message = Stream.of(userTemplates, vmSnapshots, vms, volumes,
networks, vpcs)
.filter(entity -> !entity.isEmpty())
.map(entity -> entity.size() + " " +
entity.get(0).getEntityType().getSimpleName())
.collect(Collectors.toList());
...
String msg = String.join(",", message) + " to clean up";
CloudRuntimeException e = new CloudRuntimeException("Can't delete the
project yet because it has " + msg);
...
```
Such that the end error would look like:

Or is this too much info??
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]