Search in sources :

Example 1 with LoadBalancerDao

use of com.cloud.network.dao.LoadBalancerDao in project cosmic by MissionCriticalCloud.

the class AssignLoadBalancerTest method testNicIsNotInNw.

@Test(expected = InvalidParameterValueException.class)
public void testNicIsNotInNw() throws ResourceAllocationException, ResourceUnavailableException, InsufficientCapacityException {
    final Map<Long, List<String>> vmIdIpMap = new HashMap<>();
    final List<String> secIp = new ArrayList<>();
    secIp.add("10.1.1.175");
    vmIdIpMap.put(1L, secIp);
    final List<Long> vmIds = new ArrayList<>();
    vmIds.add(2L);
    final LoadBalancerDao lbDao = Mockito.mock(LoadBalancerDao.class);
    final LoadBalancerVMMapDao lb2VmMapDao = Mockito.mock(LoadBalancerVMMapDao.class);
    final UserVmDao userVmDao = Mockito.mock(UserVmDao.class);
    _lbMgr._lbDao = lbDao;
    _lbMgr._lb2VmMapDao = lb2VmMapDao;
    _lbMgr._vmDao = userVmDao;
    _lbvmMapList = new ArrayList<>();
    _lbMgr._rulesMgr = _rulesMgr;
    _lbMgr._networkModel = _networkModel;
    when(lbDao.findById(anyLong())).thenReturn(Mockito.mock(LoadBalancerVO.class));
    when(userVmDao.findById(anyLong())).thenReturn(Mockito.mock(UserVmVO.class));
    when(lb2VmMapDao.listByLoadBalancerId(anyLong(), anyBoolean())).thenReturn(_lbvmMapList);
    _lbMgr.assignToLoadBalancer(1L, null, vmIdIpMap);
}
Also used : LoadBalancerDao(com.cloud.network.dao.LoadBalancerDao) UserVmVO(com.cloud.vm.UserVmVO) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) LoadBalancerVO(com.cloud.network.dao.LoadBalancerVO) Matchers.anyString(org.mockito.Matchers.anyString) Matchers.anyLong(org.mockito.Matchers.anyLong) LoadBalancerVMMapDao(com.cloud.network.dao.LoadBalancerVMMapDao) ArrayList(java.util.ArrayList) List(java.util.List) UserVmDao(com.cloud.vm.dao.UserVmDao) Test(org.junit.Test)

Example 2 with LoadBalancerDao

use of com.cloud.network.dao.LoadBalancerDao in project cosmic by MissionCriticalCloud.

the class AssignLoadBalancerTest method tesSecIpNotSetToVm.

@Test(expected = InvalidParameterValueException.class)
public void tesSecIpNotSetToVm() throws ResourceAllocationException, ResourceUnavailableException, InsufficientCapacityException {
    final AssignToLoadBalancerRuleCmd assignLbRuleCmd = Mockito.mock(AssignToLoadBalancerRuleCmd.class);
    final Map<Long, List<String>> vmIdIpMap = new HashMap<>();
    final List<String> secIp = new ArrayList<>();
    secIp.add("10.1.1.175");
    vmIdIpMap.put(1L, secIp);
    final List<Long> vmIds = new ArrayList<>();
    vmIds.add(2L);
    final LoadBalancerVO lbVO = new LoadBalancerVO("1", "L1", "Lbrule", 1, 22, 22, "rb", 204, 0, 0, "tcp", 60000, 60000);
    final LoadBalancerDao lbDao = Mockito.mock(LoadBalancerDao.class);
    final LoadBalancerVMMapDao lb2VmMapDao = Mockito.mock(LoadBalancerVMMapDao.class);
    final UserVmDao userVmDao = Mockito.mock(UserVmDao.class);
    final NicSecondaryIpDao nicSecIpDao = Mockito.mock(NicSecondaryIpDao.class);
    _lbMgr._lbDao = lbDao;
    _lbMgr._lb2VmMapDao = lb2VmMapDao;
    _lbMgr._vmDao = userVmDao;
    _lbMgr._nicSecondaryIpDao = nicSecIpDao;
    _lbvmMapList = new ArrayList<>();
    _lbMgr._rulesMgr = _rulesMgr;
    _lbMgr._networkModel = _networkModel;
    when(lbDao.findById(anyLong())).thenReturn(lbVO);
    when(userVmDao.findById(anyLong())).thenReturn(Mockito.mock(UserVmVO.class));
    when(lb2VmMapDao.listByLoadBalancerId(anyLong(), anyBoolean())).thenReturn(_lbvmMapList);
    when(nicSecIpDao.findByIp4AddressAndNicId(anyString(), anyLong())).thenReturn(null);
    _lbMgr.assignToLoadBalancer(1L, null, vmIdIpMap);
}
Also used : LoadBalancerDao(com.cloud.network.dao.LoadBalancerDao) UserVmVO(com.cloud.vm.UserVmVO) NicSecondaryIpDao(com.cloud.vm.dao.NicSecondaryIpDao) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) LoadBalancerVO(com.cloud.network.dao.LoadBalancerVO) Matchers.anyString(org.mockito.Matchers.anyString) AssignToLoadBalancerRuleCmd(com.cloud.api.command.user.loadbalancer.AssignToLoadBalancerRuleCmd) Matchers.anyLong(org.mockito.Matchers.anyLong) LoadBalancerVMMapDao(com.cloud.network.dao.LoadBalancerVMMapDao) ArrayList(java.util.ArrayList) List(java.util.List) UserVmDao(com.cloud.vm.dao.UserVmDao) Test(org.junit.Test)

Example 3 with LoadBalancerDao

use of com.cloud.network.dao.LoadBalancerDao in project cosmic by MissionCriticalCloud.

the class AssignLoadBalancerTest method testBothArgsEmpty.

@Test(expected = InvalidParameterValueException.class)
public void testBothArgsEmpty() throws ResourceAllocationException, ResourceUnavailableException, InsufficientCapacityException {
    final Map<Long, List<String>> emptyMap = new HashMap<>();
    final LoadBalancerDao lbdao = Mockito.mock(LoadBalancerDao.class);
    _lbMgr._lbDao = lbdao;
    when(lbdao.findById(anyLong())).thenReturn(Mockito.mock(LoadBalancerVO.class));
    _lbMgr.assignToLoadBalancer(1L, null, emptyMap);
}
Also used : LoadBalancerDao(com.cloud.network.dao.LoadBalancerDao) HashMap(java.util.HashMap) Matchers.anyLong(org.mockito.Matchers.anyLong) LoadBalancerVO(com.cloud.network.dao.LoadBalancerVO) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Example 4 with LoadBalancerDao

use of com.cloud.network.dao.LoadBalancerDao in project cloudstack by apache.

the class FirewallRules method accept.

@Override
public boolean accept(final NetworkTopologyVisitor visitor, final VirtualRouter router) throws ResourceUnavailableException {
    _router = router;
    _purpose = _rules.get(0).getPurpose();
    if (_purpose == Purpose.LoadBalancing) {
        LoadBalancerDao loadBalancerDao = visitor.getVirtualNetworkApplianceFactory().getLoadBalancerDao();
        // for load balancer we have to resend all lb rules for the network or vpc
        final List<LoadBalancerVO> lbs = loadBalancerDao.listByNetworkIdOrVpcIdAndScheme(_network.getId(), _network.getVpcId(), Scheme.Public);
        _loadbalancingRules = new ArrayList<LoadBalancingRule>();
        LoadBalancingRulesManager lbMgr = visitor.getVirtualNetworkApplianceFactory().getLbMgr();
        NetworkModel networkModel = visitor.getVirtualNetworkApplianceFactory().getNetworkModel();
        for (final LoadBalancerVO lb : lbs) {
            final List<LbDestination> dstList = lbMgr.getExistingDestinations(lb.getId());
            final List<LbStickinessPolicy> policyList = lbMgr.getStickinessPolicies(lb.getId());
            final List<LbHealthCheckPolicy> hcPolicyList = lbMgr.getHealthCheckPolicies(lb.getId());
            final LbSslCert sslCert = lbMgr.getLbSslCert(lb.getId());
            final Ip sourceIp = networkModel.getPublicIpAddress(lb.getSourceIpAddressId()).getAddress();
            final LoadBalancingRule loadBalancing = new LoadBalancingRule(lb, dstList, policyList, hcPolicyList, sourceIp, sslCert, lb.getLbProtocol());
            _loadbalancingRules.add(loadBalancing);
        }
    }
    return visitor.visit(this);
}
Also used : LoadBalancerDao(com.cloud.network.dao.LoadBalancerDao) LbSslCert(com.cloud.network.lb.LoadBalancingRule.LbSslCert) LoadBalancingRule(com.cloud.network.lb.LoadBalancingRule) LoadBalancingRulesManager(com.cloud.network.lb.LoadBalancingRulesManager) Ip(com.cloud.utils.net.Ip) LoadBalancerVO(com.cloud.network.dao.LoadBalancerVO) LbStickinessPolicy(com.cloud.network.lb.LoadBalancingRule.LbStickinessPolicy) LbDestination(com.cloud.network.lb.LoadBalancingRule.LbDestination) NetworkModel(com.cloud.network.NetworkModel) LbHealthCheckPolicy(com.cloud.network.lb.LoadBalancingRule.LbHealthCheckPolicy)

Example 5 with LoadBalancerDao

use of com.cloud.network.dao.LoadBalancerDao in project cloudstack by apache.

the class LoadBalancingRules method accept.

@Override
public boolean accept(final NetworkTopologyVisitor visitor, final VirtualRouter router) throws ResourceUnavailableException {
    _router = router;
    LoadBalancerDao loadBalancerDao = visitor.getVirtualNetworkApplianceFactory().getLoadBalancerDao();
    // For load balancer we have to resend all lb rules for the network or vpc
    final List<LoadBalancerVO> lbs = loadBalancerDao.listByNetworkIdOrVpcIdAndScheme(_network.getId(), _network.getVpcId(), Scheme.Public);
    // We are cleaning it before because all the rules have to be sent to the router.
    _rules.clear();
    LoadBalancingRulesManager lbMgr = visitor.getVirtualNetworkApplianceFactory().getLbMgr();
    NetworkModel networkModel = visitor.getVirtualNetworkApplianceFactory().getNetworkModel();
    for (final LoadBalancerVO lb : lbs) {
        final List<LbDestination> dstList = lbMgr.getExistingDestinations(lb.getId());
        final List<LbStickinessPolicy> policyList = lbMgr.getStickinessPolicies(lb.getId());
        final List<LbHealthCheckPolicy> hcPolicyList = lbMgr.getHealthCheckPolicies(lb.getId());
        final LbSslCert sslCert = lbMgr.getLbSslCert(lb.getId());
        final Ip sourceIp = networkModel.getPublicIpAddress(lb.getSourceIpAddressId()).getAddress();
        final LoadBalancingRule loadBalancing = new LoadBalancingRule(lb, dstList, policyList, hcPolicyList, sourceIp, sslCert, lb.getLbProtocol());
        _rules.add(loadBalancing);
    }
    return visitor.visit(this);
}
Also used : LoadBalancerDao(com.cloud.network.dao.LoadBalancerDao) LbSslCert(com.cloud.network.lb.LoadBalancingRule.LbSslCert) LoadBalancingRule(com.cloud.network.lb.LoadBalancingRule) LoadBalancingRulesManager(com.cloud.network.lb.LoadBalancingRulesManager) Ip(com.cloud.utils.net.Ip) LoadBalancerVO(com.cloud.network.dao.LoadBalancerVO) LbStickinessPolicy(com.cloud.network.lb.LoadBalancingRule.LbStickinessPolicy) LbDestination(com.cloud.network.lb.LoadBalancingRule.LbDestination) NetworkModel(com.cloud.network.NetworkModel) LbHealthCheckPolicy(com.cloud.network.lb.LoadBalancingRule.LbHealthCheckPolicy)

Aggregations

LoadBalancerDao (com.cloud.network.dao.LoadBalancerDao)12 LoadBalancerVO (com.cloud.network.dao.LoadBalancerVO)12 ArrayList (java.util.ArrayList)8 HashMap (java.util.HashMap)8 List (java.util.List)8 Test (org.junit.Test)8 Matchers.anyLong (org.mockito.Matchers.anyLong)8 Matchers.anyString (org.mockito.Matchers.anyString)7 LoadBalancerVMMapDao (com.cloud.network.dao.LoadBalancerVMMapDao)6 UserVmVO (com.cloud.vm.UserVmVO)6 UserVmDao (com.cloud.vm.dao.UserVmDao)6 NetworkModel (com.cloud.network.NetworkModel)4 LoadBalancingRule (com.cloud.network.lb.LoadBalancingRule)4 LbDestination (com.cloud.network.lb.LoadBalancingRule.LbDestination)4 LbHealthCheckPolicy (com.cloud.network.lb.LoadBalancingRule.LbHealthCheckPolicy)4 LbSslCert (com.cloud.network.lb.LoadBalancingRule.LbSslCert)4 LbStickinessPolicy (com.cloud.network.lb.LoadBalancingRule.LbStickinessPolicy)4 LoadBalancingRulesManager (com.cloud.network.lb.LoadBalancingRulesManager)4 Ip (com.cloud.utils.net.Ip)4 NicSecondaryIpDao (com.cloud.vm.dao.NicSecondaryIpDao)4