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 3 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
35 changes: 22 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 @@
pstmt.setObject(i++, value);
}
}

if (s_logger.isDebugEnabled() && lock != null) {
txn.registerLock(pstmt.toString());
}
Expand Down Expand Up @@ -1342,22 +1341,32 @@
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) {
onClause.append(joinedTableNames.getOrDefault(join.getSecondAttribute()[i].table, join.getFirstAttributes()[i].table))
.append(".")
.append(join.getSecondAttribute()[i].columnName);

Check warning on line 1347 in framework/db/src/main/java/com/cloud/utils/db/GenericDaoBase.java

View check run for this annotation

Codecov / codecov/patch

framework/db/src/main/java/com/cloud/utils/db/GenericDaoBase.java#L1345-L1347

Added lines #L1345 - L1347 were not covered by tests
} else {
onClause.append(joinedTableNames.getOrDefault(join.getFirstAttributes()[i].table, join.getFirstAttributes()[i].table))
.append(".")
.append(join.getFirstAttributes()[i].columnName);

Check warning on line 1351 in framework/db/src/main/java/com/cloud/utils/db/GenericDaoBase.java

View check run for this annotation

Codecov / codecov/patch

framework/db/src/main/java/com/cloud/utils/db/GenericDaoBase.java#L1349-L1351

Added lines #L1349 - L1351 were not covered by tests
}
}
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) {
vishesh92 marked this conversation as resolved.
Show resolved Hide resolved
onClause.append(" IS NULL");

Check warning on line 1355 in framework/db/src/main/java/com/cloud/utils/db/GenericDaoBase.java

View check run for this annotation

Codecov / codecov/patch

framework/db/src/main/java/com/cloud/utils/db/GenericDaoBase.java#L1355

Added line #L1355 was not covered by tests
} else {
if(!joinTableAlias.equals(joinTableName)) {
onClause.append(joinTableAlias);
onClause.append("=");

Check warning on line 1357 in framework/db/src/main/java/com/cloud/utils/db/GenericDaoBase.java

View check run for this annotation

Codecov / codecov/patch

framework/db/src/main/java/com/cloud/utils/db/GenericDaoBase.java#L1357

Added line #L1357 was not covered by tests
if (join.getSecondAttribute()[i].getValue() != null) {
onClause.append("?");
joinAttrList.add(join.getSecondAttribute()[i]);

Check warning on line 1360 in framework/db/src/main/java/com/cloud/utils/db/GenericDaoBase.java

View check run for this annotation

Codecov / codecov/patch

framework/db/src/main/java/com/cloud/utils/db/GenericDaoBase.java#L1359-L1360

Added lines #L1359 - L1360 were not covered by tests
} else {
onClause.append(joinTableName);
if (!joinTableAlias.equals(joinTableName)) {
onClause.append(joinTableAlias);

Check warning on line 1363 in framework/db/src/main/java/com/cloud/utils/db/GenericDaoBase.java

View check run for this annotation

Codecov / codecov/patch

framework/db/src/main/java/com/cloud/utils/db/GenericDaoBase.java#L1363

Added line #L1363 was not covered by tests
} else {
onClause.append(joinTableName);

Check warning on line 1365 in framework/db/src/main/java/com/cloud/utils/db/GenericDaoBase.java

View check run for this annotation

Codecov / codecov/patch

framework/db/src/main/java/com/cloud/utils/db/GenericDaoBase.java#L1365

Added line #L1365 was not covered by tests
}
onClause.append(".")
.append(join.getSecondAttribute()[i].columnName);

Check warning on line 1368 in framework/db/src/main/java/com/cloud/utils/db/GenericDaoBase.java

View check run for this annotation

Codecov / codecov/patch

framework/db/src/main/java/com/cloud/utils/db/GenericDaoBase.java#L1367-L1368

Added lines #L1367 - L1368 were not covered by tests
}
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 @@
@Inject
private NetworkDao networkDao;

@Inject
private IPAddressDao ipAddressDao;

@Inject
private NicDao nicDao;

Expand Down Expand Up @@ -1453,6 +1458,22 @@
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);

Check warning on line 1464 in server/src/main/java/com/cloud/api/query/QueryManagerImpl.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/com/cloud/api/query/QueryManagerImpl.java#L1462-L1464

Added lines #L1462 - L1464 were not covered by tests

SearchBuilder<NicVO> nicSearch = nicDao.createSearchBuilder();
userVmSearchBuilder.join("nicSearch", nicSearch, JoinBuilder.JoinType.LEFT,

Check warning on line 1467 in server/src/main/java/com/cloud/api/query/QueryManagerImpl.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/com/cloud/api/query/QueryManagerImpl.java#L1466-L1467

Added lines #L1466 - L1467 were not covered by tests
JoinBuilder.JoinCondition.AND,
nicSearch.entity().getInstanceId(), userVmSearchBuilder.entity().getId(),
nicSearch.entity().getRemoved(), userVmSearchBuilder.entity().setLong(null));

Check warning on line 1470 in server/src/main/java/com/cloud/api/query/QueryManagerImpl.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/com/cloud/api/query/QueryManagerImpl.java#L1469-L1470

Added lines #L1469 - L1470 were not covered by tests

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

Check warning on line 1472 in server/src/main/java/com/cloud/api/query/QueryManagerImpl.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/com/cloud/api/query/QueryManagerImpl.java#L1472

Added line #L1472 was not covered by tests

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

Check warning on line 1475 in server/src/main/java/com/cloud/api/query/QueryManagerImpl.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/com/cloud/api/query/QueryManagerImpl.java#L1474-L1475

Added lines #L1474 - L1475 were not covered by tests

userVmSearchBuilder.cp();
}

Expand Down Expand Up @@ -1546,6 +1567,9 @@
userVmSearchCriteria.setParameters("keywordDisplayName", keywordMatch);
userVmSearchCriteria.setParameters("keywordName", keywordMatch);
userVmSearchCriteria.setParameters("keywordState", keyword);
userVmSearchCriteria.setParameters("keywordIpAddress", keywordMatch);
userVmSearchCriteria.setParameters("keywordPublicIpAddress", keywordMatch);
userVmSearchCriteria.setParameters("keywordIp6Address", keywordMatch);

Check warning on line 1572 in server/src/main/java/com/cloud/api/query/QueryManagerImpl.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/com/cloud/api/query/QueryManagerImpl.java#L1570-L1572

Added lines #L1570 - L1572 were not covered by tests
if (isRootAdmin) {
userVmSearchCriteria.setParameters("keywordInstanceName", keywordMatch);
}
Expand Down
Loading