[BugFix:
move AttachL2Network validate from L2NetworkApiInterceptor to VmVdpaNicApiInterceptor
package org.zstack.network.l2;
-import org.apache.commons.lang.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.zstack.core.cloudbus.CloudBus;
import org.zstack.core.db.DatabaseFacade;
+import org.zstack.core.db.Q;
import org.zstack.core.db.SimpleQuery;
import org.zstack.core.db.SimpleQuery.Op;
import org.zstack.core.errorcode.ErrorFacade;
@@ -31,8 +31,6 @@ public class L2NetworkApiInterceptor implements ApiMessageInterceptor {
private DatabaseFacade dbf;
@Autowired
private ErrorFacade errf;
- @Autowired
- private ResourceConfigFacade rcf;
private void setServiceId(APIMessage msg) {
if (msg instanceof L2NetworkMessage) {
@@ -64,23 +62,6 @@ public class L2NetworkApiInterceptor implements ApiMessageInterceptor {
if (q.isExists()) {
throw new ApiMessageInterceptionException(operr("l2Network[uuid:%s] has attached to cluster[uuid:%s], can't attach again", msg.getL2NetworkUuid(), msg.getClusterUuid()));
}
-
- SimpleQuery<L2NetworkVO> q2 = dbf.createQuery(L2NetworkVO.class);
- q2.add(L2NetworkVO_.uuid, Op.EQ, msg.getL2NetworkUuid());
- q2.add(L2NetworkVO_.vSwitchType, Op.EQ, "OvsDpdk");
- boolean isOvsDpdk = q2.isExists();
-
- ResourceConfig ovsDpdkSup = rcf.getResourceConfig("premiumCluster.network.ovsdpdk");
- if (ovsDpdkSup != null) {
- boolean isOvsDpdkSup = ovsDpdkSup.getResourceConfigValue(msg.getClusterUuid(), Boolean.class);
- if (isOvsDpdk && !isOvsDpdkSup) {
- throw new ApiMessageInterceptionException(operr("cluster[uuid:%s] do not support ovsdpdk", msg.getClusterUuid()));
- }
- } else {
- if (isOvsDpdk) {
- throw new ApiMessageInterceptionException(operr("cluster[uuid:%s] do not support ovsdpdk", msg.getClusterUuid()));
- }
- }
}
private void validate(APIDetachL2NetworkFromClusterMsg msg) {
@@ -106,10 +87,11 @@ public class L2NetworkApiInterceptor implements ApiMessageInterceptor {
}
// once we already created a linux bridge with a physical interface,
// we can not use it to create a OvsDpdk bridge
- SimpleQuery<L2NetworkVO> q = dbf.createQuery(L2NetworkVO.class);
- q.add(L2NetworkVO_.physicalInterface, Op.EQ, msg.getPhysicalInterface());
- q.add(L2NetworkVO_.vSwitchType, Op.NOT_EQ, msg.getvSwitchType());
- if (q.isExists()) {
+ boolean isConflict = Q.New(L2NetworkVO.class)
+ .eq(L2NetworkVO_.physicalInterface, msg.getPhysicalInterface())
+ .notEq(L2NetworkVO_.vSwitchType, msg.getvSwitchType())
+ .isExists();
+ if (isConflict) {
throw new ApiMessageInterceptionException(argerr("can not create %s L2Network with physicalInterface:[%s] which was already been used by another vSwitchType.", msg.getvSwitchType(), msg.getPhysicalInterface()));
}
}
