Search in sources :

Example 26 with LoadBalancingRule

use of com.cloud.network.lb.LoadBalancingRule in project cloudstack by apache.

the class InternalLBVMManagerTest method applyToVmInStartingState.

@Test(expected = ResourceUnavailableException.class)
public void applyToVmInStartingState() throws ResourceUnavailableException {
    boolean result = false;
    final List<DomainRouterVO> vms = new ArrayList<DomainRouterVO>();
    vm.setState(State.Starting);
    vms.add(vm);
    final List<LoadBalancingRule> rules = new ArrayList<LoadBalancingRule>();
    final LoadBalancingRule rule = new LoadBalancingRule(null, null, null, null, null, null, null);
    rules.add(rule);
    try {
        result = _lbVmMgr.applyLoadBalancingRules(new NetworkVO(), rules, vms);
    } finally {
        assertFalse("Rules were applied to vm in Starting state", result);
    }
}
Also used : NetworkVO(com.cloud.network.dao.NetworkVO) LoadBalancingRule(com.cloud.network.lb.LoadBalancingRule) ArrayList(java.util.ArrayList) DomainRouterVO(com.cloud.vm.DomainRouterVO) Test(org.junit.Test)

Example 27 with LoadBalancingRule

use of com.cloud.network.lb.LoadBalancingRule in project cloudstack by apache.

the class InternalLBVMManagerTest method applyToVmInStoppedState.

@Test
public void applyToVmInStoppedState() throws ResourceUnavailableException {
    boolean result = false;
    final List<DomainRouterVO> vms = new ArrayList<DomainRouterVO>();
    vm.setState(State.Stopped);
    vms.add(vm);
    final List<LoadBalancingRule> rules = new ArrayList<LoadBalancingRule>();
    final LoadBalancingRule rule = new LoadBalancingRule(null, null, null, null, null, null, null);
    rules.add(rule);
    try {
        result = _lbVmMgr.applyLoadBalancingRules(new NetworkVO(), rules, vms);
    } finally {
        assertTrue("Rules failed to apply to vm in Stopped state", result);
    }
}
Also used : NetworkVO(com.cloud.network.dao.NetworkVO) LoadBalancingRule(com.cloud.network.lb.LoadBalancingRule) ArrayList(java.util.ArrayList) DomainRouterVO(com.cloud.vm.DomainRouterVO) Test(org.junit.Test)

Example 28 with LoadBalancingRule

use of com.cloud.network.lb.LoadBalancingRule in project cloudstack by apache.

the class BasicNetworkVisitor method visit.

@Override
public boolean visit(final LoadBalancingRules loadbalancing) throws ResourceUnavailableException {
    final Network network = loadbalancing.getNetwork();
    final DomainRouterVO router = (DomainRouterVO) loadbalancing.getRouter();
    final List<LoadBalancingRule> rules = loadbalancing.getRules();
    final Commands cmds = new Commands(Command.OnError.Continue);
    _commandSetupHelper.createApplyLoadBalancingRulesCommands(rules, router, cmds, network.getId());
    return _networkGeneralHelper.sendCommandsToRouter(router, cmds);
}
Also used : LoadBalancingRule(com.cloud.network.lb.LoadBalancingRule) Network(com.cloud.network.Network) Commands(com.cloud.agent.manager.Commands) DomainRouterVO(com.cloud.vm.DomainRouterVO)

Example 29 with LoadBalancingRule

use of com.cloud.network.lb.LoadBalancingRule in project cloudstack by apache.

the class BasicNetworkVisitor method visit.

@SuppressWarnings("unchecked")
@Override
public boolean visit(final FirewallRules firewall) throws ResourceUnavailableException {
    final Network network = firewall.getNetwork();
    final VirtualRouter router = firewall.getRouter();
    final List<? extends FirewallRule> rules = firewall.getRules();
    final List<LoadBalancingRule> loadbalancingRules = firewall.getLoadbalancingRules();
    final Purpose purpose = firewall.getPurpose();
    final Commands cmds = new Commands(Command.OnError.Continue);
    if (purpose == Purpose.LoadBalancing) {
        _commandSetupHelper.createApplyLoadBalancingRulesCommands(loadbalancingRules, router, cmds, network.getId());
        return _networkGeneralHelper.sendCommandsToRouter(router, cmds);
    } else if (purpose == Purpose.PortForwarding) {
        _commandSetupHelper.createApplyPortForwardingRulesCommands((List<? extends PortForwardingRule>) rules, router, cmds, network.getId());
        return _networkGeneralHelper.sendCommandsToRouter(router, cmds);
    } else if (purpose == Purpose.StaticNat) {
        _commandSetupHelper.createApplyStaticNatRulesCommands((List<StaticNatRule>) rules, router, cmds, network.getId());
        return _networkGeneralHelper.sendCommandsToRouter(router, cmds);
    } else if (purpose == Purpose.Firewall) {
        _commandSetupHelper.createApplyFirewallRulesCommands(rules, router, cmds, network.getId());
        return _networkGeneralHelper.sendCommandsToRouter(router, cmds);
    }
    s_logger.warn("Unable to apply rules of purpose: " + rules.get(0).getPurpose());
    return false;
}
Also used : LoadBalancingRule(com.cloud.network.lb.LoadBalancingRule) Network(com.cloud.network.Network) Commands(com.cloud.agent.manager.Commands) Purpose(com.cloud.network.rules.FirewallRule.Purpose) List(java.util.List) ArrayList(java.util.ArrayList) StaticNatRule(com.cloud.network.rules.StaticNatRule) PortForwardingRule(com.cloud.network.rules.PortForwardingRule) VirtualRouter(com.cloud.network.router.VirtualRouter)

Aggregations

LoadBalancingRule (com.cloud.network.lb.LoadBalancingRule)29 LbDestination (com.cloud.network.lb.LoadBalancingRule.LbDestination)15 ArrayList (java.util.ArrayList)14 LbStickinessPolicy (com.cloud.network.lb.LoadBalancingRule.LbStickinessPolicy)11 Ip (com.cloud.utils.net.Ip)11 DomainRouterVO (com.cloud.vm.DomainRouterVO)10 LoadBalancerTO (com.cloud.agent.api.to.LoadBalancerTO)8 Network (com.cloud.network.Network)8 LbHealthCheckPolicy (com.cloud.network.lb.LoadBalancingRule.LbHealthCheckPolicy)8 Test (org.junit.Test)7 LoadBalancerVO (com.cloud.network.dao.LoadBalancerVO)6 NetworkVO (com.cloud.network.dao.NetworkVO)6 LbSslCert (com.cloud.network.lb.LoadBalancingRule.LbSslCert)6 LoadBalancerConfigCommand (com.cloud.agent.api.routing.LoadBalancerConfigCommand)5 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)5 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)5 Nic (com.cloud.vm.Nic)5 HealthCheckLBConfigAnswer (com.cloud.agent.api.routing.HealthCheckLBConfigAnswer)4 Commands (com.cloud.agent.manager.Commands)4 DataCenterVO (com.cloud.dc.DataCenterVO)4