Skip to content

Commit

Permalink
Merge branch 'shixin-41032@@2' into 'feature-L7lb'
Browse files Browse the repository at this point in the history
[BugFix: ZSTACK-41032] reconnect vpc will not sync slb info only shared lb

See merge request zstackio/zstack!1092
  • Loading branch information
gitlab committed Jun 10, 2021
2 parents aba63f8 + 3d82477 commit 7b40bcb
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 5 deletions.
Expand Up @@ -12,6 +12,8 @@ public interface LoadBalancerFactory {

String getNetworkServiceType();

String getApplianceVmType();

LoadBalancerBackend getLoadBalancerBackend(LoadBalancerVO vo);

String getProviderTypeByVmNicUuid(String nicUuid);
Expand Down
Expand Up @@ -13,4 +13,5 @@ public interface LoadBalancerManager {
LoadBalancerServerGroupVO getDefaultServerGroup(LoadBalancerListenerVO vo);
List<String> getLoadBalancerListenterByVmNics(List<String> vmNicUuids);
void upgradeLoadBalancerServerGroup();
LoadBalancerFactory getLoadBalancerFactoryByApplianceVmType(String type);
}
Expand Up @@ -82,6 +82,7 @@ public class LoadBalancerManagerImpl extends AbstractService implements LoadBala

private Map<String, LoadBalancerBackend> backends = new HashMap<String, LoadBalancerBackend>();
private Map<String, LoadBalancerFactory> lbFactories = new HashMap<String, LoadBalancerFactory>();
private Map<String, LoadBalancerFactory> lbFactoriesByApplianceVmType = new HashMap<String, LoadBalancerFactory>();

@Override
@MessageSafe
Expand Down Expand Up @@ -442,6 +443,15 @@ public boolean start() {
lbFactories.put(f.getType(), f);
}

for (LoadBalancerFactory f : pluginRgty.getExtensionList(LoadBalancerFactory.class)) {
LoadBalancerFactory old = lbFactoriesByApplianceVmType.get(f.getApplianceVmType());
if (old != null) {
throw new CloudRuntimeException(String.format("duplicate LoadBalancerFactory[%s, %s]", old.getClass(), f.getType()));
}

lbFactoriesByApplianceVmType.put(f.getApplianceVmType(), f);
}

installConfigValidateExtension();
prepareSystemTags();

Expand Down Expand Up @@ -735,6 +745,12 @@ public LoadBalancerFactory getLoadBalancerFactory(String type) {
return f;
}

@Override
public LoadBalancerFactory getLoadBalancerFactoryByApplianceVmType(String applianceVmType) {
LoadBalancerFactory f = lbFactories.get(applianceVmType);
return f;
}

@Override
public List<ExpandedQueryStruct> getExpandedQueryStructs() {
List<ExpandedQueryStruct> structs = new ArrayList<ExpandedQueryStruct>();
Expand Down
Expand Up @@ -91,4 +91,9 @@ public List<VmNicVO> getAttachableVmNicsForServerGroup(LoadBalancerVO lbVO, Load
LoadBalancerBackend backend = lbMgr.getBackend(providerType);
return backend.getAttachableVmNicsForServerGroup(lbVO, groupVO);
}

@Override
public String getApplianceVmType() {
return VyosConstants.VYOS_VM_TYPE;
}
}
Expand Up @@ -5,6 +5,7 @@
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.transaction.annotation.Transactional;
import org.zstack.compute.vm.VmInstanceManager;
import org.zstack.core.db.DatabaseFacade;
import org.zstack.core.db.SimpleQuery;
import org.zstack.core.db.SimpleQuery.Op;
Expand All @@ -15,9 +16,7 @@
import org.zstack.header.errorcode.ErrorCode;
import org.zstack.header.tag.SystemTagVO;
import org.zstack.header.tag.SystemTagVO_;
import org.zstack.header.vm.VmNicInventory;
import org.zstack.header.vm.VmNicVO;
import org.zstack.header.vm.VmNicVO_;
import org.zstack.header.vm.*;
import org.zstack.network.service.lb.*;
import org.zstack.network.service.vip.VipInventory;
import org.zstack.network.service.vip.VipVO;
Expand Down Expand Up @@ -74,6 +73,13 @@ public void run(final FlowTrigger outterTrigger, final Map data) {

new VirtualRouterRoleManager().makeLoadBalancerRole(vr.getUuid());

LoadBalancerType lbType = LoadBalancerType.Shared;
LoadBalancerFactory factory = lbMgr.getLoadBalancerFactoryByApplianceVmType(vr.getApplianceVmType());
if (factory != null) {
lbType = LoadBalancerType.valueOf(factory.getType());
}

LoadBalancerType finalLbType = lbType;
Collection<LoadBalancerVO> lbs = new Callable<List<LoadBalancerVO>>() {
@Override
@Transactional(readOnly = true)
Expand All @@ -84,7 +90,7 @@ public List<LoadBalancerVO> call() {
" and lgref.serverGroupUuid = g.uuid and nicRef.serverGroupUuid= g.uuid " +
" and nicRef.vmNicUuid = nic.uuid and nic.l3NetworkUuid = l3.uuid" +
" and l3.uuid in (:l3uuids) and lb.state = :state and lb.uuid not in (select t.resourceUuid from SystemTagVO t" +
" where t.tag = :tag and t.resourceType = :rtype)";
" where t.tag = :tag and t.resourceType = :rtype) and lb.type = :lbType";

TypedQuery<LoadBalancerVO> vq = dbf.getEntityManager().createQuery(sql, LoadBalancerVO.class);

Expand All @@ -99,7 +105,7 @@ public List<LoadBalancerVO> call() {
" and lgref.serverGroupUuid = g.uuid and nicRef.serverGroupUuid= g.uuid " +
" and nicRef.vmNicUuid = nic.uuid and nic.l3NetworkUuid = l3.uuid" +
" and l3.uuid in (:l3uuids) and lb.state = :state and lb.uuid not in (select t.resourceUuid from SystemTagVO t" +
" where t.tag = :tag and t.resourceType = :rtype and t.resourceUuid not in (:mylbs))";
" where t.tag = :tag and t.resourceType = :rtype and t.resourceUuid not in (:mylbs)) and lb.type = :lbType";
vq = dbf.getEntityManager().createQuery(sql, LoadBalancerVO.class);
vq.setParameter("mylbs", lbuuids);
}
Expand All @@ -109,6 +115,7 @@ public List<LoadBalancerVO> call() {
vq.setParameter("rtype", LoadBalancerVO.class.getSimpleName());
vq.setParameter("state", LoadBalancerState.Enabled);
vq.setParameter("l3uuids", l3Uuids);
vq.setParameter("lbType", finalLbType);
return vq.getResultList();
}
}.call();
Expand Down

0 comments on commit 7b40bcb

Please sign in to comment.