Search in sources :

Example 6 with ApplicationLoadBalancerRuleVO

use of org.apache.cloudstack.lb.ApplicationLoadBalancerRuleVO in project cloudstack by apache.

the class ApplicationLoadBalancerTest method setUp.

@Override
@Before
public void setUp() {
    ComponentContext.initComponentsLifeCycle();
    //mockito for .getApplicationLoadBalancer tests
    Mockito.when(_lbDao.findById(1L)).thenReturn(new ApplicationLoadBalancerRuleVO());
    Mockito.when(_lbDao.findById(2L)).thenReturn(null);
    //mockito for .deleteApplicationLoadBalancer tests
    Mockito.when(_lbService.deleteLoadBalancerRule(existingLbId, true)).thenReturn(true);
    Mockito.when(_lbService.deleteLoadBalancerRule(nonExistingLbId, true)).thenReturn(false);
    //mockito for .createApplicationLoadBalancer tests
    NetworkVO guestNetwork = new NetworkVO(TrafficType.Guest, null, null, 1, null, 1, 1L, false);
    setId(guestNetwork, validGuestNetworkId);
    guestNetwork.setCidr("10.1.1.1/24");
    NetworkVO publicNetwork = new NetworkVO(TrafficType.Public, null, null, 1, null, 1, 1L, false);
    Mockito.when(_ntwkModel.getNetwork(validGuestNetworkId)).thenReturn(guestNetwork);
    Mockito.when(_ntwkModel.getNetwork(invalidGuestNetworkId)).thenReturn(null);
    Mockito.when(_ntwkModel.getNetwork(validPublicNetworkId)).thenReturn(publicNetwork);
    Mockito.when(_accountMgr.getAccount(validAccountId)).thenReturn(new AccountVO());
    Mockito.when(_accountMgr.getAccount(invalidAccountId)).thenReturn(null);
    Mockito.when(_ntwkModel.areServicesSupportedInNetwork(validGuestNetworkId, Service.Lb)).thenReturn(true);
    Mockito.when(_ntwkModel.areServicesSupportedInNetwork(invalidGuestNetworkId, Service.Lb)).thenReturn(false);
    ApplicationLoadBalancerRuleVO lbRule = new ApplicationLoadBalancerRuleVO("new", "new", 22, 22, "roundrobin", validGuestNetworkId, validAccountId, 1L, new Ip(validRequestedIp), validGuestNetworkId, Scheme.Internal);
    Mockito.when(_lbDao.persist(Matchers.any(ApplicationLoadBalancerRuleVO.class))).thenReturn(lbRule);
    Mockito.when(_lbMgr.validateLbRule(Matchers.any(LoadBalancingRule.class))).thenReturn(true);
    Mockito.when(_firewallDao.setStateToAdd(Matchers.any(FirewallRuleVO.class))).thenReturn(true);
    Mockito.when(_accountMgr.getSystemUser()).thenReturn(new UserVO(1));
    Mockito.when(_accountMgr.getSystemAccount()).thenReturn(new AccountVO(2));
    CallContext.register(_accountMgr.getSystemUser(), _accountMgr.getSystemAccount());
    Mockito.when(_ntwkModel.areServicesSupportedInNetwork(Matchers.anyLong(), Matchers.any(Network.Service.class))).thenReturn(true);
    Map<Network.Capability, String> caps = new HashMap<Network.Capability, String>();
    caps.put(Capability.SupportedProtocols, NetUtils.TCP_PROTO);
    Mockito.when(_ntwkModel.getNetworkServiceCapabilities(Matchers.anyLong(), Matchers.any(Network.Service.class))).thenReturn(caps);
    Mockito.when(_lbDao.countBySourceIp(new Ip(validRequestedIp), validGuestNetworkId)).thenReturn(1L);
}
Also used : ApplicationLoadBalancerRuleVO(org.apache.cloudstack.lb.ApplicationLoadBalancerRuleVO) NetworkVO(com.cloud.network.dao.NetworkVO) LoadBalancingRule(com.cloud.network.lb.LoadBalancingRule) Capability(com.cloud.network.Network.Capability) HashMap(java.util.HashMap) Ip(com.cloud.utils.net.Ip) NetworkOrchestrationService(org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService) Service(com.cloud.network.Network.Service) LoadBalancingRulesService(com.cloud.network.lb.LoadBalancingRulesService) AccountVO(com.cloud.user.AccountVO) FirewallRuleVO(com.cloud.network.rules.FirewallRuleVO) UserVO(com.cloud.user.UserVO) Network(com.cloud.network.Network) Before(org.junit.Before)

Example 7 with ApplicationLoadBalancerRuleVO

use of org.apache.cloudstack.lb.ApplicationLoadBalancerRuleVO in project cloudstack by apache.

the class ApplicationLoadBalancerManagerImpl method updateApplicationLoadBalancer.

@Override
@ActionEvent(eventType = EventTypes.EVENT_LOAD_BALANCER_UPDATE, eventDescription = "updating load balancer", async = true)
public ApplicationLoadBalancerRule updateApplicationLoadBalancer(Long id, String customId, Boolean forDisplay) {
    Account caller = CallContext.current().getCallingAccount();
    ApplicationLoadBalancerRuleVO rule = _lbDao.findById(id);
    if (rule == null) {
        throw new InvalidParameterValueException("Unable to find load balancer " + id);
    }
    _accountMgr.checkAccess(caller, null, true, rule);
    if (customId != null) {
        rule.setUuid(customId);
    }
    if (forDisplay != null) {
        rule.setDisplay(forDisplay);
    }
    _lbDao.update(id, rule);
    return _lbDao.findById(id);
}
Also used : Account(com.cloud.user.Account) ApplicationLoadBalancerRuleVO(org.apache.cloudstack.lb.ApplicationLoadBalancerRuleVO) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) ActionEvent(com.cloud.event.ActionEvent)

Example 8 with ApplicationLoadBalancerRuleVO

use of org.apache.cloudstack.lb.ApplicationLoadBalancerRuleVO in project cloudstack by apache.

the class InternalLBVMManagerTest method applyToVmInRunningState.

@Test
public void applyToVmInRunningState() throws ResourceUnavailableException {
    boolean result = false;
    final List<DomainRouterVO> vms = new ArrayList<DomainRouterVO>();
    vm.setState(State.Running);
    vms.add(vm);
    final List<LoadBalancingRule> rules = new ArrayList<LoadBalancingRule>();
    final ApplicationLoadBalancerRuleVO lb = new ApplicationLoadBalancerRuleVO(null, null, 22, 22, "roundrobin", 1L, 1L, 1L, new Ip(requestedIp), 1L, Scheme.Internal);
    lb.setState(FirewallRule.State.Add);
    final LoadBalancingRule rule = new LoadBalancingRule(lb, null, null, null, new Ip(requestedIp));
    rules.add(rule);
    ntwk.getId();
    try {
        result = _lbVmMgr.applyLoadBalancingRules(ntwk, rules, vms);
    } finally {
        assertTrue("Rules failed to apply to vm in Running state", result);
    }
}
Also used : ApplicationLoadBalancerRuleVO(org.apache.cloudstack.lb.ApplicationLoadBalancerRuleVO) LoadBalancingRule(com.cloud.network.lb.LoadBalancingRule) Ip(com.cloud.utils.net.Ip) ArrayList(java.util.ArrayList) DomainRouterVO(com.cloud.vm.DomainRouterVO) Test(org.junit.Test)

Aggregations

ApplicationLoadBalancerRuleVO (org.apache.cloudstack.lb.ApplicationLoadBalancerRuleVO)8 LoadBalancingRule (com.cloud.network.lb.LoadBalancingRule)6 Ip (com.cloud.utils.net.Ip)4 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)3 ArrayList (java.util.ArrayList)3 UnsupportedServiceException (com.cloud.exception.UnsupportedServiceException)2 Network (com.cloud.network.Network)2 NetworkVO (com.cloud.network.dao.NetworkVO)2 LbDestination (com.cloud.network.lb.LoadBalancingRule.LbDestination)2 LbHealthCheckPolicy (com.cloud.network.lb.LoadBalancingRule.LbHealthCheckPolicy)2 LbStickinessPolicy (com.cloud.network.lb.LoadBalancingRule.LbStickinessPolicy)2 Account (com.cloud.user.Account)2 Test (org.junit.Test)2 ActionEvent (com.cloud.event.ActionEvent)1 InsufficientAddressCapacityException (com.cloud.exception.InsufficientAddressCapacityException)1 InsufficientVirtualNetworkCapacityException (com.cloud.exception.InsufficientVirtualNetworkCapacityException)1 NetworkRuleConflictException (com.cloud.exception.NetworkRuleConflictException)1 Capability (com.cloud.network.Network.Capability)1 Service (com.cloud.network.Network.Service)1 PublicIp (com.cloud.network.addr.PublicIp)1