harikrishna-patnala commented on code in PR #6202:
URL: https://github.com/apache/cloudstack/pull/6202#discussion_r877782702
##########
server/src/main/java/com/cloud/server/ManagementServerImpl.java:
##########
@@ -4336,6 +4365,174 @@ public SSHKeyPair registerSSHKeyPair(final
RegisterSSHKeyPairCmd cmd) {
return createAndSaveSSHKeyPair(name, fingerprint, publicKey, null,
owner);
}
+ @Override
+ public boolean deleteUserData(final DeleteUserDataCmd cmd) {
+ final Account caller = getCaller();
+ final String accountName = cmd.getAccountName();
+ final Long domainId = cmd.getDomainId();
+ final Long projectId = cmd.getProjectId();
+
+ Account owner = null;
+ try {
+ owner = _accountMgr.finalizeOwner(caller, accountName, domainId,
projectId);
+ } catch (InvalidParameterValueException ex) {
+ if (caller.getType() == Account.Type.ADMIN && accountName != null
&& domainId != null) {
+ owner = _accountDao.findAccountIncludingRemoved(accountName,
domainId);
+ }
+ if (owner == null) {
+ throw ex;
+ }
+ }
+
+ final UserDataVO userData = _userDataDao.findById(cmd.getId());
+ if (userData == null) {
+ final InvalidParameterValueException ex = new
InvalidParameterValueException(
+ "A UserData with id '" + cmd.getId() + "' does not exist
for account " + owner.getAccountName() + " in specified domain id");
+ final DomainVO domain =
ApiDBUtils.findDomainById(owner.getDomainId());
+ String domainUuid = String.valueOf(owner.getDomainId());
+ if (domain != null) {
+ domainUuid = domain.getUuid();
+ }
+ ex.addProxyObject(domainUuid, "domainId");
+ throw ex;
+ }
+
+ List<VMTemplateVO> templatesLinkedToUserData =
_templateDao.findTemplatesLinkedToUserdata(userData.getId());
+ if (CollectionUtils.isNotEmpty(templatesLinkedToUserData)) {
+ throw new CloudRuntimeException(String.format("Userdata %s cannot
be removed as it is linked to active template/templates", userData.getName()));
+ }
+
+
annotationDao.removeByEntityType(AnnotationService.EntityType.USER_DATA.name(),
userData.getUuid());
+
+ return _userDataDao.expunge(userData.getId());
Review Comment:
Userdata vo does not have a removed column, so we are directly expunging it.
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]