Skip to content

Commit 23b19a9

Browse files
abh1sarDaan Hoogland
authored andcommitted
review comments
1 parent dc7068a commit 23b19a9

File tree

4 files changed

+33
-31
lines changed

4 files changed

+33
-31
lines changed

server/src/main/java/com/cloud/projects/ProjectManagerImpl.java

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -604,16 +604,16 @@ public boolean addUserToProject(Long projectId, String username, String email, L
604604

605605
boolean shouldIncrementResourceCount = projectRole != null && Role.Admin == projectRole;
606606
try (CheckedReservation cr = new CheckedReservation(userAccount, ResourceType.project, shouldIncrementResourceCount ? 1L : 0L, reservationDao, _resourceLimitMgr)) {
607-
if (assignUserToProject(project, user.getId(), user.getAccountId(), projectRole,
608-
Optional.ofNullable(role).map(ProjectRole::getId).orElse(null)) != null) {
609-
if (shouldIncrementResourceCount) {
610-
_resourceLimitMgr.incrementResourceCount(userAccount.getId(), ResourceType.project);
607+
if (assignUserToProject(project, user.getId(), user.getAccountId(), projectRole,
608+
Optional.ofNullable(role).map(ProjectRole::getId).orElse(null)) != null) {
609+
if (shouldIncrementResourceCount) {
610+
_resourceLimitMgr.incrementResourceCount(userAccount.getId(), ResourceType.project);
611+
}
612+
return true;
613+
} else {
614+
logger.warn("Failed to add user to project: {}", project);
615+
return false;
611616
}
612-
return true;
613-
} else {
614-
logger.warn("Failed to add user to project: {}", project);
615-
return false;
616-
}
617617
}
618618
}
619619
}
@@ -721,19 +721,16 @@ public void doInTransactionWithoutResult(TransactionStatus status) throws Resour
721721
}
722722

723723
try (CheckedReservation checkedReservation = new CheckedReservation(futureOwnerAccount, ResourceType.project, null, null, 1L, reservationDao, _resourceLimitMgr)) {
724-
725-
_resourceLimitMgr.checkResourceLimit(_accountMgr.getAccount(futureOwnerAccount.getId()), ResourceType.project);
726-
727-
//unset the role for the old owner
728-
ProjectAccountVO currentOwner = _projectAccountDao.findByProjectIdAccountId(projectId, currentOwnerAccount.getId());
729-
currentOwner.setAccountRole(Role.Regular);
730-
_projectAccountDao.update(currentOwner.getId(), currentOwner);
731-
_resourceLimitMgr.decrementResourceCount(currentOwnerAccount.getId(), ResourceType.project);
732-
733-
//set new owner
734-
futureOwner.setAccountRole(Role.Admin);
735-
_projectAccountDao.update(futureOwner.getId(), futureOwner);
736-
_resourceLimitMgr.incrementResourceCount(futureOwnerAccount.getId(), ResourceType.project);
724+
//unset the role for the old owner
725+
ProjectAccountVO currentOwner = _projectAccountDao.findByProjectIdAccountId(projectId, currentOwnerAccount.getId());
726+
currentOwner.setAccountRole(Role.Regular);
727+
_projectAccountDao.update(currentOwner.getId(), currentOwner);
728+
_resourceLimitMgr.decrementResourceCount(currentOwnerAccount.getId(), ResourceType.project);
729+
730+
//set new owner
731+
futureOwner.setAccountRole(Role.Admin);
732+
_projectAccountDao.update(futureOwner.getId(), futureOwner);
733+
_resourceLimitMgr.incrementResourceCount(futureOwnerAccount.getId(), ResourceType.project);
737734
}
738735
} else {
739736
logger.trace("Future owner {}is already the owner of the project {}", newOwnerName, project);

server/src/main/java/com/cloud/storage/ImageStoreUploadMonitorImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ private Boolean checkAndUpdateVolumeResourceLimit(VolumeVO volume, VolumeDataSto
360360
boolean success = true;
361361
Long currentSize = answer.getVirtualSize() != 0 ? answer.getVirtualSize() : answer.getPhysicalSize();
362362
Long lastSize = volume.getSize() != null ? volume.getSize() : 0L;
363-
if (!checkAndUpdateSecondaryStorageResourceLimit(volume.getAccountId(), volume.getSize(), currentSize)) {
363+
if (!checkAndUpdateSecondaryStorageResourceLimit(volume.getAccountId(), lastSize, currentSize)) {
364364
volumeDataStore.setDownloadState(VMTemplateStorageResourceAssoc.Status.DOWNLOAD_ERROR);
365365
volumeDataStore.setState(State.Failed);
366366
volumeDataStore.setErrorString("Storage Limit Reached");

server/src/main/java/com/cloud/storage/download/DownloadListener.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,15 +280,15 @@ private Long getAccountIdForDataObject() {
280280
}
281281

282282
private Long getSizeFromDB() {
283-
Long lastSize = 0L;
283+
Long lastSize = null;
284284
if (DataObjectType.TEMPLATE.equals(object.getType())) {
285285
TemplateDataStoreVO t = _templateDataStoreDao.findByStoreTemplate(object.getDataStore().getId(), object.getId());
286286
lastSize = t.getSize();
287287
} else if (DataObjectType.VOLUME.equals(object.getType())) {
288288
VolumeVO v = _volumeDao.findById(object.getId());
289289
lastSize = v.getSize();
290290
}
291-
return lastSize;
291+
return lastSize == null ? 0L : lastSize;
292292
}
293293

294294
private Boolean checkAndUpdateResourceLimits(DownloadAnswer answer) {
@@ -297,6 +297,9 @@ private Boolean checkAndUpdateResourceLimits(DownloadAnswer answer) {
297297

298298
if (currentSize > lastSize) {
299299
Long accountId = getAccountIdForDataObject();
300+
if (accountId == null) {
301+
return true;
302+
}
300303
Account account = _accountMgr.getAccount(accountId);
301304
Long usage = currentSize - lastSize;
302305
try (CheckedReservation secStorageReservation = new CheckedReservation(account, Resource.ResourceType.secondary_storage, usage, _reservationDao, _resourceLimitMgr)) {

server/src/main/java/com/cloud/template/TemplateManagerImpl.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,12 +1035,14 @@ public VirtualMachineTemplate copyTemplate(CopyTemplateCmd cmd) throws StorageUn
10351035
logger.debug("There is Template {} in secondary storage {} in zone {} , don't need to copy", template, dstSecStore, dataCenterVOs.get(destZoneId));
10361036
continue;
10371037
}
1038-
try (CheckedReservation secondaryStorageReservation = new CheckedReservation(templateOwner, ResourceType.secondary_storage, null, null, template.getSize(), reservationDao, _resourceLimitMgr)) {
1039-
if (!copy(userId, template, srcSecStore, dataCenterVOs.get(destZoneId))) {
1040-
failedZones.add(dataCenterVOs.get(destZoneId).getName());
1041-
continue;
1042-
}
1043-
_resourceLimitMgr.incrementResourceCount(templateOwner.getId(), ResourceType.secondary_storage, template.getSize());
1038+
if (template.getSize() != null) {
1039+
try (CheckedReservation secondaryStorageReservation = new CheckedReservation(templateOwner, ResourceType.secondary_storage, null, null, template.getSize(), reservationDao, _resourceLimitMgr)) {
1040+
if (!copy(userId, template, srcSecStore, dataCenterVOs.get(destZoneId))) {
1041+
failedZones.add(dataCenterVOs.get(destZoneId).getName());
1042+
continue;
1043+
}
1044+
_resourceLimitMgr.incrementResourceCount(templateOwner.getId(), ResourceType.secondary_storage, template.getSize());
1045+
}
10441046
}
10451047
}
10461048
}

0 commit comments

Comments
 (0)