Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filter list VMs by IP address #9547

Merged
merged 5 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
42 changes: 29 additions & 13 deletions framework/db/src/main/java/com/cloud/utils/db/GenericDaoBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,6 @@ public List<T> searchIncludingRemoved(SearchCriteria<T> sc, final Filter filter,
pstmt.setObject(i++, value);
}
}

if (s_logger.isDebugEnabled() && lock != null) {
txn.registerLock(pstmt.toString());
}
Expand Down Expand Up @@ -1342,22 +1341,39 @@ protected List<Attribute> addJoins(StringBuilder str, Collection<JoinBuilder<Sea
onClause.append("?");
joinAttrList.add(join.getFirstAttributes()[i]);
} else {
onClause.append(joinedTableNames.getOrDefault(join.getFirstAttributes()[i].table, join.getFirstAttributes()[i].table))
.append(".")
.append(join.getFirstAttributes()[i].columnName);
if (join.getFirstAttributes()[i].table == null && join.getFirstAttributes()[i].value == null ||
join.getSecondAttribute()[i].table == null && join.getSecondAttribute()[i].value == null) {
vishesh92 marked this conversation as resolved.
Show resolved Hide resolved
onClause.append(joinedTableNames.getOrDefault(join.getSecondAttribute()[i].table, join.getFirstAttributes()[i].table))
.append(".");
if (join.getFirstAttributes()[i].table == null && join.getFirstAttributes()[i].value == null) {
onClause.append(join.getSecondAttribute()[i].columnName);
} else {
onClause.append(join.getFirstAttributes()[i].columnName);
}

} else {
onClause.append(joinedTableNames.getOrDefault(join.getFirstAttributes()[i].table, join.getFirstAttributes()[i].table))
.append(".")
.append(join.getFirstAttributes()[i].columnName);
}
}
onClause.append("=");
if (join.getSecondAttribute()[i].getValue() != null) {
onClause.append("?");
joinAttrList.add(join.getSecondAttribute()[i]);
if (join.getFirstAttributes()[i].table == null && join.getFirstAttributes()[i].value == null ||
join.getSecondAttribute()[i].table == null && join.getSecondAttribute()[i].value == null) {
vishesh92 marked this conversation as resolved.
Show resolved Hide resolved
onClause.append(" IS NULL");
} else {
if(!joinTableAlias.equals(joinTableName)) {
onClause.append(joinTableAlias);
onClause.append("=");
if (join.getSecondAttribute()[i].getValue() != null) {
onClause.append("?");
joinAttrList.add(join.getSecondAttribute()[i]);
} else {
onClause.append(joinTableName);
if (!joinTableAlias.equals(joinTableName)) {
onClause.append(joinTableAlias);
} else {
onClause.append(joinTableName);
}
onClause.append(".")
.append(join.getSecondAttribute()[i].columnName);
}
onClause.append(".")
.append(join.getSecondAttribute()[i].columnName);
}
}
onClause.append(" ");
Expand Down
24 changes: 24 additions & 0 deletions server/src/main/java/com/cloud/api/query/QueryManagerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@

import javax.inject.Inject;

import com.cloud.network.dao.IPAddressDao;
import com.cloud.network.dao.IPAddressVO;
import com.cloud.storage.StoragePool;
import com.cloud.storage.StoragePoolHostVO;
import com.cloud.event.EventVO;
Expand Down Expand Up @@ -549,6 +551,9 @@ public class QueryManagerImpl extends MutualExclusiveIdsManagerBase implements Q
@Inject
private NetworkDao networkDao;

@Inject
private IPAddressDao ipAddressDao;

@Inject
private NicDao nicDao;

Expand Down Expand Up @@ -1453,6 +1458,22 @@ private Pair<List<Long>, Integer> searchForUserVMIdsAndCount(ListVMsCmd cmd) {
if (isRootAdmin) {
userVmSearchBuilder.or("keywordInstanceName", userVmSearchBuilder.entity().getInstanceName(), Op.LIKE );
}

SearchBuilder<IPAddressVO> ipAddressSearch = ipAddressDao.createSearchBuilder();
userVmSearchBuilder.join("ipAddressSearch", ipAddressSearch,
ipAddressSearch.entity().getAssociatedWithVmId(), userVmSearchBuilder.entity().getId(), JoinBuilder.JoinType.LEFT);

SearchBuilder<NicVO> nicSearch = nicDao.createSearchBuilder();
userVmSearchBuilder.join("nicSearch", nicSearch, JoinBuilder.JoinType.LEFT,
JoinBuilder.JoinCondition.AND,
nicSearch.entity().getInstanceId(), userVmSearchBuilder.entity().getId(),
nicSearch.entity().getRemoved(), userVmSearchBuilder.entity().setLong(null));

userVmSearchBuilder.or("ipAddressSearch", "keywordPublicIpAddress", ipAddressSearch.entity().getAddress(), Op.LIKE);

userVmSearchBuilder.or("nicSearch", "keywordIpAddress", nicSearch.entity().getIPv4Address(), Op.LIKE);
userVmSearchBuilder.or("nicSearch", "keywordIp6Address", nicSearch.entity().getIPv6Address(), Op.LIKE);

userVmSearchBuilder.cp();
}

Expand Down Expand Up @@ -1546,6 +1567,9 @@ private Pair<List<Long>, Integer> searchForUserVMIdsAndCount(ListVMsCmd cmd) {
userVmSearchCriteria.setParameters("keywordDisplayName", keywordMatch);
userVmSearchCriteria.setParameters("keywordName", keywordMatch);
userVmSearchCriteria.setParameters("keywordState", keyword);
userVmSearchCriteria.setParameters("keywordIpAddress", keywordMatch);
userVmSearchCriteria.setParameters("keywordPublicIpAddress", keywordMatch);
userVmSearchCriteria.setParameters("keywordIp6Address", keywordMatch);
if (isRootAdmin) {
userVmSearchCriteria.setParameters("keywordInstanceName", keywordMatch);
}
Expand Down
Loading