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);
}
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);
}
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);
}
}
Aggregations