Skip to content

Commit d0ce8c6

Browse files
committed
<fix>[network]: fix query nic rely on usedIp
accord old design pattern, query nic will rely on usedIp, now nic include l3NetworkUuid, remove dependency will release nic query which has empty ip Resolves: ZSTAC-56072 Change-Id: I6868776c7fa668bac51c4f739fc054f71190e908
1 parent 9d63411 commit d0ce8c6

File tree

3 files changed

+22
-22
lines changed

3 files changed

+22
-22
lines changed

compute/src/main/java/org/zstack/compute/vm/VmCascadeExtension.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,10 @@ private VmNicDetachResult getVmNicDetachMsgs(List<L2NetworkDetachStruct> structs
146146
List<DetachNicFromVmMsg> dmsgs = new ArrayList<>();
147147

148148
for (L2NetworkDetachStruct s : structs) {
149-
String sql = "select vm.uuid, nic.uuid from VmInstanceVO vm, VmNicVO nic, L3NetworkVO l3, UsedIpVO ip"
149+
String sql = "select vm.uuid, nic.uuid from VmInstanceVO vm, VmNicVO nic, L3NetworkVO l3"
150150
+ " where vm.clusterUuid = :clusterUuid"
151151
+ " and l3.l2NetworkUuid = :l2NetworkUuid"
152-
+ " and nic.uuid = ip.vmNicUuid and ip.l3NetworkUuid = l3.uuid "
152+
+ " and nic.l3NetworkUuid = l3.uuid"
153153
+ " and nic.vmInstanceUuid = vm.uuid";
154154
TypedQuery<Tuple> q = dbf.getEntityManager().createQuery(sql, Tuple.class);
155155
q.setParameter("clusterUuid", s.getClusterUuid());
@@ -654,11 +654,11 @@ public String call(L3NetworkInventory arg) {
654654
@Override
655655
@Transactional(readOnly = true)
656656
public List<VmInstanceVO> call() {
657-
String sql = "select vm from VmInstanceVO vm, L3NetworkVO l3, VmNicVO nic, UsedIpVO ip" +
657+
String sql = "select vm from VmInstanceVO vm, L3NetworkVO l3, VmNicVO nic" +
658658
" where vm.type = :vmType" +
659659
" and vm.uuid = nic.vmInstanceUuid" +
660660
" and vm.state in (:vmStates)" +
661-
" and nic.uuid = ip.vmNicUuid and ip.l3NetworkUuid = l3.uuid" +
661+
" and nic.l3NetworkUuid = l3.uuid" +
662662
" and l3.uuid in (:uuids)" +
663663
" group by vm.uuid";
664664
TypedQuery<VmInstanceVO> q = dbf.getEntityManager().createQuery(sql, VmInstanceVO.class);

network/src/main/java/org/zstack/network/service/NetworkServiceFilter.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ public class NetworkServiceFilter {
2121
@Transactional(readOnly = true)
2222
public List<String> filterNicByServiceTypeAndProviderType(Collection<String> nicUuids, String serviceType, String providerType) {
2323
String sql = "select nic.uuid from VmNicVO nic, NetworkServiceL3NetworkRefVO l3ref, NetworkServiceProviderVO provider," +
24-
" NetworkServiceProviderL2NetworkRefVO l2ref, L3NetworkVO l3, UsedIpVO ip where nic.uuid = ip.vmNicUuid and " +
25-
" ip.l3NetworkUuid = l3.uuid and nic.uuid in (:uuids)" +
24+
" NetworkServiceProviderL2NetworkRefVO l2ref, L3NetworkVO l3 where nic.l3NetworkUuid = l3.uuid" +
25+
" and nic.uuid in (:uuids)" +
2626
" and l3.uuid = l3ref.l3NetworkUuid and l3ref.networkServiceType = :serviceType and l3ref.networkServiceProviderUuid = provider.uuid" +
2727
" and provider.uuid = l2ref.networkServiceProviderUuid and l2ref.l2NetworkUuid = l3.l2NetworkUuid" +
2828
" and provider.type = :providerType";
@@ -37,8 +37,8 @@ public List<String> filterNicByServiceTypeAndProviderType(Collection<String> nic
3737
@Transactional(readOnly = true)
3838
public List<String> filterVmByServiceTypeAndProviderType(Collection<String> vmUuids, String serviceType, String providerType) {
3939
String sql = "select distinct vm.uuid from VmNicVO nic, VmInstanceVO vm, NetworkServiceL3NetworkRefVO l3ref, NetworkServiceProviderVO provider," +
40-
" NetworkServiceProviderL2NetworkRefVO l2ref, L3NetworkVO l3, UsedIpVO ip " +
41-
" where nic.uuid = ip.vmNicUuid and ip.l3NetworkUuid = l3.uuid and ip.l3NetworkUuid = vm.defaultL3NetworkUuid" +
40+
" NetworkServiceProviderL2NetworkRefVO l2ref, L3NetworkVO l3 " +
41+
" where nic.l3NetworkUuid = l3.uuid and nic.l3NetworkUuid = vm.defaultL3NetworkUuid" +
4242
" and nic.vmInstanceUuid = vm.uuid and vm.uuid in (:uuids)" +
4343
" and l3.uuid = l3ref.l3NetworkUuid and l3ref.networkServiceType = :serviceType and l3ref.networkServiceProviderUuid = provider.uuid" +
4444
" and provider.uuid = l2ref.networkServiceProviderUuid and l2ref.l2NetworkUuid = l3.l2NetworkUuid" +

plugin/securityGroup/src/main/java/org/zstack/network/securitygroup/SecurityGroupManagerImpl.java

+14-14
Original file line numberDiff line numberDiff line change
@@ -258,8 +258,8 @@ List<HostRuleTO> mergeMultiHostRuleTO(Collection<HostRuleTO>... htos) {
258258
}
259259

260260
private List<HostRuleTO> calculateByL3NetworkAndSecurityGroup() {
261-
String sql = "select ref.vmNicUuid from VmNicSecurityGroupRefVO ref, SecurityGroupL3NetworkRefVO l3ref, VmNicVO nic, UsedIpVO ip, SecurityGroupVO sg" +
262-
" where l3ref.securityGroupUuid = ref.securityGroupUuid and nic.uuid = ip.vmNicUuid and ip.l3NetworkUuid = l3ref.l3NetworkUuid" +
261+
String sql = "select ref.vmNicUuid from VmNicSecurityGroupRefVO ref, SecurityGroupL3NetworkRefVO l3ref, VmNicVO nic, SecurityGroupVO sg" +
262+
" where l3ref.securityGroupUuid = ref.securityGroupUuid and nic.l3NetworkUuid = l3ref.l3NetworkUuid" +
263263
" and ref.securityGroupUuid in (:sgUuids) and l3ref.l3NetworkUuid in (:l3Uuids)" +
264264
" and ref.securityGroupUuid = sg.uuid and sg.state in (:sgStates)";
265265
TypedQuery<String> q = dbf.getEntityManager().createQuery(sql, String.class);
@@ -798,28 +798,28 @@ private List<VmNicVO> getCandidateVmNic(String sgId, String accountUuid) {
798798
if (nicUuidsToInclude == null) {
799799
// accessed by an admin
800800
if (nicUuidsToExclued.isEmpty()) {
801-
sql = "select nic from VmNicVO nic, VmInstanceVO vm, SecurityGroupVO sg, SecurityGroupL3NetworkRefVO ref, UsedIpVO ip " +
802-
"where nic.vmInstanceUuid = vm.uuid and nic.uuid = ip.vmNicUuid and ip.l3NetworkUuid = ref.l3NetworkUuid and ref.securityGroupUuid = sg.uuid " +
801+
sql = "select nic from VmNicVO nic, VmInstanceVO vm, SecurityGroupVO sg, SecurityGroupL3NetworkRefVO ref " +
802+
"where nic.vmInstanceUuid = vm.uuid and nic.l3NetworkUuid = ref.l3NetworkUuid and ref.securityGroupUuid = sg.uuid " +
803803
" and sg.uuid = :sgUuid and vm.type = :vmType and vm.state in (:vmStates) group by nic.uuid";
804804
q = dbf.getEntityManager().createQuery(sql, VmNicVO.class);
805805
} else {
806-
sql = "select nic from VmNicVO nic, VmInstanceVO vm, SecurityGroupVO sg, SecurityGroupL3NetworkRefVO ref, UsedIpVO ip" +
807-
" where nic.vmInstanceUuid = vm.uuid and nic.uuid = ip.vmNicUuid and ip.l3NetworkUuid = ref.l3NetworkUuid and ref.securityGroupUuid = sg.uuid " +
806+
sql = "select nic from VmNicVO nic, VmInstanceVO vm, SecurityGroupVO sg, SecurityGroupL3NetworkRefVO ref" +
807+
" where nic.vmInstanceUuid = vm.uuid and nic.l3NetworkUuid = ref.l3NetworkUuid and ref.securityGroupUuid = sg.uuid " +
808808
" and sg.uuid = :sgUuid and vm.type = :vmType and vm.state in (:vmStates) and nic.uuid not in (:nicUuids) group by nic.uuid";
809809
q = dbf.getEntityManager().createQuery(sql, VmNicVO.class);
810810
q.setParameter("nicUuids", nicUuidsToExclued);
811811
}
812812
} else {
813813
// accessed by a normal account
814814
if (nicUuidsToExclued.isEmpty()) {
815-
sql = "select nic from VmNicVO nic, VmInstanceVO vm, SecurityGroupVO sg, SecurityGroupL3NetworkRefVO ref, UsedIpVO ip " +
816-
" where nic.vmInstanceUuid = vm.uuid and nic.uuid = ip.vmNicUuid and ip.l3NetworkUuid = ref.l3NetworkUuid and ref.securityGroupUuid = sg.uuid " +
815+
sql = "select nic from VmNicVO nic, VmInstanceVO vm, SecurityGroupVO sg, SecurityGroupL3NetworkRefVO ref" +
816+
" where nic.vmInstanceUuid = vm.uuid and nic.l3NetworkUuid = ref.l3NetworkUuid and ref.securityGroupUuid = sg.uuid " +
817817
" and sg.uuid = :sgUuid and vm.type = :vmType and vm.state in (:vmStates) and nic.uuid in (:iuuids) group by nic.uuid";
818818
q = dbf.getEntityManager().createQuery(sql, VmNicVO.class);
819819
q.setParameter("iuuids", nicUuidsToInclude);
820820
} else {
821-
sql = "select nic from VmNicVO nic, VmInstanceVO vm, SecurityGroupVO sg, SecurityGroupL3NetworkRefVO ref, UsedIpVO ip " +
822-
" where nic.vmInstanceUuid = vm.uuid and nic.uuid = ip.vmNicUuid and ip.l3NetworkUuid = ref.l3NetworkUuid and ref.securityGroupUuid = sg.uuid " +
821+
sql = "select nic from VmNicVO nic, VmInstanceVO vm, SecurityGroupVO sg, SecurityGroupL3NetworkRefVO ref" +
822+
" where nic.vmInstanceUuid = vm.uuid and nic.l3NetworkUuid = ref.l3NetworkUuid and ref.securityGroupUuid = sg.uuid " +
823823
" and sg.uuid = :sgUuid and vm.type = :vmType and vm.state in (:vmStates) and nic.uuid not in (:nicUuids) and nic.uuid in (:iuuids) group by nic.uuid";
824824
q = dbf.getEntityManager().createQuery(sql, VmNicVO.class);
825825
q.setParameter("nicUuids", nicUuidsToExclued);
@@ -842,8 +842,8 @@ private void handle(APIGetCandidateVmNicForSecurityGroupMsg msg) {
842842

843843
@Transactional
844844
private void detachSecurityGroupFromL3Network(String sgUuid, String l3Uuid) {
845-
String sql = "select distinct ref.uuid from VmNicSecurityGroupRefVO ref, VmNicVO nic, UsedIpVO ip, SecurityGroupVO sg" +
846-
" where nic.uuid = ref.vmNicUuid and nic.uuid = ip.vmNicUuid and ip.l3NetworkUuid = :l3Uuid and ref.securityGroupUuid = :sgUuid";
845+
String sql = "select distinct ref.uuid from VmNicSecurityGroupRefVO ref, VmNicVO nic, SecurityGroupVO sg" +
846+
" where nic.uuid = ref.vmNicUuid and nic.l3NetworkUuid = :l3Uuid and ref.securityGroupUuid = :sgUuid";
847847
TypedQuery<String> tq = dbf.getEntityManager().createQuery(sql, String.class);
848848
tq.setParameter("l3Uuid", l3Uuid);
849849
tq.setParameter("sgUuid", sgUuid);
@@ -864,8 +864,8 @@ private void detachSecurityGroupFromL3Network(String sgUuid, String l3Uuid) {
864864

865865
@Transactional(readOnly = true)
866866
private List<String> getVmNicUuidsToRemoveForDetachSecurityGroup(String sgUuid, String l3Uuid) {
867-
String sql = "select distinct nic.uuid from VmNicVO nic, VmNicSecurityGroupRefVO ref, UsedIpVO ip, SecurityGroupVO sg" +
868-
" where ref.vmNicUuid = nic.uuid and nic.uuid = ip.vmNicUuid and ip.l3NetworkUuid = :l3Uuid and ref.securityGroupUuid = :sgUuid";
867+
String sql = "select distinct nic.uuid from VmNicVO nic, VmNicSecurityGroupRefVO ref, SecurityGroupVO sg" +
868+
" where ref.vmNicUuid = nic.uuid and nic.l3NetworkUuid = :l3Uuid and ref.securityGroupUuid = :sgUuid";
869869
TypedQuery<String> tq = dbf.getEntityManager().createQuery(sql, String.class);
870870
tq.setParameter("l3Uuid", l3Uuid);
871871
tq.setParameter("sgUuid", sgUuid);

0 commit comments

Comments
 (0)