Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import com.cloud.user.UserDataVO;
import com.cloud.utils.db.GenericDao;

import java.util.List;

public interface UserDataDao extends GenericDao<UserDataVO, Long> {

public UserDataVO findByUserData(long accountId, long domainId, String userData);
Expand All @@ -27,4 +29,6 @@ public interface UserDataDao extends GenericDao<UserDataVO, Long> {

int removeByAccountId(long accountId);

List<UserDataVO> listByAccountId(long accountId);

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import com.cloud.utils.db.SearchCriteria;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class UserDataDaoImpl extends GenericDaoBase<UserDataVO, Long> implements UserDataDao {

Expand Down Expand Up @@ -70,4 +72,11 @@ public int removeByAccountId(long accountId) {
sc.setParameters("accountId", accountId);
return remove(sc);
}

@Override
public List<UserDataVO> listByAccountId(long accountId) {
SearchCriteria<UserDataVO> sc = userdataSearch.create();
sc.setParameters("accountId", accountId);
return listBy(sc);
}
}
26 changes: 25 additions & 1 deletion server/src/main/java/com/cloud/user/AccountManagerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -1200,7 +1200,7 @@ public int compare(NetworkVO network1, NetworkVO network2) {
}

// Delete registered UserData
userDataDao.removeByAccountId(accountId);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe this change causes the unnecessary stubbing error from mockito?

cleanupAccountUserData(account);

// Delete Webhooks
deleteWebhooksForAccount(accountId);
Expand All @@ -1221,6 +1221,30 @@ public int compare(NetworkVO network1, NetworkVO network2) {
}
}

private void cleanupAccountUserData(AccountVO account) {
long accountId = account.getId();
List<UserDataVO> userData = userDataDao.listByAccountId(accountId);
if (CollectionUtils.isEmpty(userData)) {
return;
}
logger.info("Deleting {} registered UserData for Account {}", userData.size(), account);
for (UserDataVO userdata : userData) {
List<VMTemplateVO> templatesLinkedToUserdata = _templateDao.findTemplatesLinkedToUserdata(userdata.getId());
if (CollectionUtils.isEmpty(templatesLinkedToUserdata)) {
continue;
}
for (VMTemplateVO template : templatesLinkedToUserdata) {
logger.debug("Unregistering UserData {} from Template {}", userdata, template);
template.setUserDataId(null);
template.setUserDataLinkPolicy(null);
_templateDao.update(template.getId(), template);
}
userDataDao.remove(userdata.getId());
}
int userDataRemoved = userDataDao.removeByAccountId(accountId);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think that the userDataDao.remove(..) performed on L1242 will affect the result of userDataDao.removeByAccountId(..) in other words, do we need it being done twice?

logger.info("Deleted {} registered UserData for Account {}", userDataRemoved, account);
}

@Override
public boolean disableAccount(long accountId) throws ConcurrentOperationException, ResourceUnavailableException {
boolean success = false;
Expand Down
Loading