Search in sources :

Example 1 with AssignToGlobalLoadBalancerRuleCmd

use of org.apache.cloudstack.api.command.user.region.ha.gslb.AssignToGlobalLoadBalancerRuleCmd in project cloudstack by apache.

the class GlobalLoadBalancingRulesServiceImplTest method runAssignToGlobalLoadBalancerRuleTestSameZoneLb.

void runAssignToGlobalLoadBalancerRuleTestSameZoneLb() throws Exception {
    TransactionLegacy txn = TransactionLegacy.open("runAssignToGlobalLoadBalancerRuleTestSameZoneLb");
    GlobalLoadBalancingRulesServiceImpl gslbServiceImpl = new GlobalLoadBalancingRulesServiceImpl();
    gslbServiceImpl._accountMgr = Mockito.mock(AccountManager.class);
    gslbServiceImpl._gslbRuleDao = Mockito.mock(GlobalLoadBalancerRuleDao.class);
    gslbServiceImpl._gslbLbMapDao = Mockito.mock(GlobalLoadBalancerLbRuleMapDao.class);
    gslbServiceImpl._regionDao = Mockito.mock(RegionDao.class);
    gslbServiceImpl._rulesMgr = Mockito.mock(RulesManager.class);
    gslbServiceImpl._lbDao = Mockito.mock(LoadBalancerDao.class);
    gslbServiceImpl._networkDao = Mockito.mock(NetworkDao.class);
    gslbServiceImpl._globalConfigDao = Mockito.mock(ConfigurationDao.class);
    gslbServiceImpl._ipAddressDao = Mockito.mock(IPAddressDao.class);
    gslbServiceImpl._agentMgr = Mockito.mock(AgentManager.class);
    AssignToGlobalLoadBalancerRuleCmd assignCmd = new AssignToGlobalLoadBalancerRuleCmdExtn();
    Class<?> _class = assignCmd.getClass().getSuperclass();
    Account account = new AccountVO("testaccount", 3, "networkdomain", (short) 0, UUID.randomUUID().toString());
    when(gslbServiceImpl._accountMgr.getAccount(anyLong())).thenReturn(account);
    Field gslbRuleId = _class.getDeclaredField("id");
    gslbRuleId.setAccessible(true);
    gslbRuleId.set(assignCmd, new Long(1));
    GlobalLoadBalancerRuleVO gslbRule = new GlobalLoadBalancerRuleVO("test-gslb-rule", "test-gslb-rule", "test-domain", "roundrobin", "sourceip", "tcp", 1, 3, 1, GlobalLoadBalancerRule.State.Active);
    when(gslbServiceImpl._gslbRuleDao.findById(new Long(1))).thenReturn(gslbRule);
    LoadBalancerVO lbRule1 = new LoadBalancerVO();
    lbRule1.setState(FirewallRule.State.Active);
    Field networkIdField1 = LoadBalancerVO.class.getSuperclass().getDeclaredField("networkId");
    Field accountIdField1 = LoadBalancerVO.class.getSuperclass().getDeclaredField("accountId");
    Field domainIdField1 = LoadBalancerVO.class.getSuperclass().getDeclaredField("domainId");
    networkIdField1.setAccessible(true);
    accountIdField1.setAccessible(true);
    domainIdField1.setAccessible(true);
    networkIdField1.set(lbRule1, new Long(1));
    accountIdField1.set(lbRule1, new Long(3));
    domainIdField1.set(lbRule1, new Long(1));
    Field idField1 = LoadBalancerVO.class.getSuperclass().getDeclaredField("id");
    idField1.setAccessible(true);
    idField1.set(lbRule1, new Long(1));
    LoadBalancerVO lbRule2 = new LoadBalancerVO();
    lbRule2.setState(FirewallRule.State.Active);
    Field networkIdField2 = LoadBalancerVO.class.getSuperclass().getDeclaredField("networkId");
    Field accountIdField2 = LoadBalancerVO.class.getSuperclass().getDeclaredField("accountId");
    Field domainIdField2 = LoadBalancerVO.class.getSuperclass().getDeclaredField("domainId");
    networkIdField2.setAccessible(true);
    accountIdField2.setAccessible(true);
    domainIdField2.setAccessible(true);
    networkIdField2.set(lbRule2, new Long(1));
    accountIdField2.set(lbRule2, new Long(3));
    domainIdField2.set(lbRule2, new Long(1));
    Field idField2 = LoadBalancerVO.class.getSuperclass().getDeclaredField("id");
    idField2.setAccessible(true);
    idField2.set(lbRule2, new Long(2));
    when(gslbServiceImpl._lbDao.findById(new Long(1))).thenReturn(lbRule1);
    when(gslbServiceImpl._lbDao.findById(new Long(2))).thenReturn(lbRule2);
    Field lbRules = _class.getDeclaredField("loadBalancerRulesIds");
    lbRules.setAccessible(true);
    List<Long> lbRuleIds = new ArrayList<Long>();
    lbRuleIds.add(new Long(1));
    lbRuleIds.add(new Long(2));
    lbRules.set(assignCmd, lbRuleIds);
    NetworkVO networkVo = new NetworkVO();
    Field dcID = NetworkVO.class.getDeclaredField("dataCenterId");
    dcID.setAccessible(true);
    dcID.set(networkVo, new Long(1));
    when(gslbServiceImpl._networkDao.findById(new Long(1))).thenReturn(networkVo);
    try {
        gslbServiceImpl.assignToGlobalLoadBalancerRule(assignCmd);
    } catch (InvalidParameterValueException e) {
        s_logger.info(e.getMessage());
        Assert.assertTrue(e.getMessage().contains("Load balancer rule specified should be in unique zone"));
    }
}
Also used : AssignToGlobalLoadBalancerRuleCmd(org.apache.cloudstack.api.command.user.region.ha.gslb.AssignToGlobalLoadBalancerRuleCmd) ConfigurationDao(org.apache.cloudstack.framework.config.dao.ConfigurationDao) Account(com.cloud.user.Account) LoadBalancerDao(com.cloud.network.dao.LoadBalancerDao) AgentManager(com.cloud.agent.AgentManager) RulesManager(com.cloud.network.rules.RulesManager) LoadBalancerVO(com.cloud.network.dao.LoadBalancerVO) ArrayList(java.util.ArrayList) AccountVO(com.cloud.user.AccountVO) Field(java.lang.reflect.Field) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) NetworkVO(com.cloud.network.dao.NetworkVO) IPAddressDao(com.cloud.network.dao.IPAddressDao) TransactionLegacy(com.cloud.utils.db.TransactionLegacy) NetworkDao(com.cloud.network.dao.NetworkDao) Matchers.anyLong(org.mockito.Matchers.anyLong) AccountManager(com.cloud.user.AccountManager) RegionDao(org.apache.cloudstack.region.dao.RegionDao)

Example 2 with AssignToGlobalLoadBalancerRuleCmd

use of org.apache.cloudstack.api.command.user.region.ha.gslb.AssignToGlobalLoadBalancerRuleCmd in project cloudstack by apache.

the class GlobalLoadBalancingRulesServiceImplTest method runAssignToGlobalLoadBalancerRuleTest.

void runAssignToGlobalLoadBalancerRuleTest() throws Exception {
    TransactionLegacy txn = TransactionLegacy.open("runAssignToGlobalLoadBalancerRuleTest");
    GlobalLoadBalancingRulesServiceImpl gslbServiceImpl = new GlobalLoadBalancingRulesServiceImpl();
    gslbServiceImpl._accountMgr = Mockito.mock(AccountManager.class);
    gslbServiceImpl._gslbRuleDao = Mockito.mock(GlobalLoadBalancerRuleDao.class);
    gslbServiceImpl._gslbLbMapDao = Mockito.mock(GlobalLoadBalancerLbRuleMapDao.class);
    gslbServiceImpl._regionDao = Mockito.mock(RegionDao.class);
    gslbServiceImpl._rulesMgr = Mockito.mock(RulesManager.class);
    gslbServiceImpl._lbDao = Mockito.mock(LoadBalancerDao.class);
    gslbServiceImpl._networkDao = Mockito.mock(NetworkDao.class);
    gslbServiceImpl._globalConfigDao = Mockito.mock(ConfigurationDao.class);
    gslbServiceImpl._ipAddressDao = Mockito.mock(IPAddressDao.class);
    gslbServiceImpl._agentMgr = Mockito.mock(AgentManager.class);
    AssignToGlobalLoadBalancerRuleCmd assignCmd = new AssignToGlobalLoadBalancerRuleCmdExtn();
    Class<?> _class = assignCmd.getClass().getSuperclass();
    Account account = new AccountVO("testaccount", 1, "networkdomain", (short) 0, UUID.randomUUID().toString());
    when(gslbServiceImpl._accountMgr.getAccount(anyLong())).thenReturn(account);
    Field gslbRuleId = _class.getDeclaredField("id");
    gslbRuleId.setAccessible(true);
    gslbRuleId.set(assignCmd, new Long(1));
    GlobalLoadBalancerRuleVO gslbRule = new GlobalLoadBalancerRuleVO("test-gslb-rule", "test-gslb-rule", "test-domain", "roundrobin", "sourceip", "tcp", 1, 1, 1, GlobalLoadBalancerRule.State.Active);
    when(gslbServiceImpl._gslbRuleDao.findById(new Long(1))).thenReturn(gslbRule);
    LoadBalancerVO lbRule = new LoadBalancerVO();
    lbRule.setState(FirewallRule.State.Active);
    Field networkIdField = LoadBalancerVO.class.getSuperclass().getDeclaredField("networkId");
    networkIdField.setAccessible(true);
    networkIdField.set(lbRule, new Long(1));
    Field sourceIpAddressId = LoadBalancerVO.class.getSuperclass().getDeclaredField("sourceIpAddressId");
    sourceIpAddressId.setAccessible(true);
    sourceIpAddressId.set(lbRule, new Long(1));
    when(gslbServiceImpl._lbDao.findById(new Long(1))).thenReturn(lbRule);
    Field lbRules = _class.getDeclaredField("loadBalancerRulesIds");
    lbRules.setAccessible(true);
    List<Long> lbRuleIds = new ArrayList<Long>();
    lbRuleIds.add(new Long(1));
    lbRules.set(assignCmd, lbRuleIds);
    NetworkVO networkVo = new NetworkVO();
    Field dcID = NetworkVO.class.getDeclaredField("dataCenterId");
    dcID.setAccessible(true);
    dcID.set(networkVo, new Long(1));
    when(gslbServiceImpl._networkDao.findById(new Long(1))).thenReturn(networkVo);
    IPAddressVO ip = new IPAddressVO(new Ip("10.1.1.1"), 1, 1, 1, true);
    when(gslbServiceImpl._ipAddressDao.findById(new Long(1))).thenReturn(ip);
    try {
        gslbServiceImpl.assignToGlobalLoadBalancerRule(assignCmd);
    } catch (Exception e) {
        s_logger.info("exception in testing runAssignToGlobalLoadBalancerRuleTest message: " + e.toString());
    }
}
Also used : AssignToGlobalLoadBalancerRuleCmd(org.apache.cloudstack.api.command.user.region.ha.gslb.AssignToGlobalLoadBalancerRuleCmd) ConfigurationDao(org.apache.cloudstack.framework.config.dao.ConfigurationDao) Account(com.cloud.user.Account) LoadBalancerDao(com.cloud.network.dao.LoadBalancerDao) AgentManager(com.cloud.agent.AgentManager) RulesManager(com.cloud.network.rules.RulesManager) Ip(com.cloud.utils.net.Ip) LoadBalancerVO(com.cloud.network.dao.LoadBalancerVO) ArrayList(java.util.ArrayList) AccountVO(com.cloud.user.AccountVO) Field(java.lang.reflect.Field) NetworkVO(com.cloud.network.dao.NetworkVO) IPAddressDao(com.cloud.network.dao.IPAddressDao) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) TransactionLegacy(com.cloud.utils.db.TransactionLegacy) NetworkDao(com.cloud.network.dao.NetworkDao) Matchers.anyLong(org.mockito.Matchers.anyLong) AccountManager(com.cloud.user.AccountManager) IPAddressVO(com.cloud.network.dao.IPAddressVO) RegionDao(org.apache.cloudstack.region.dao.RegionDao)

Example 3 with AssignToGlobalLoadBalancerRuleCmd

use of org.apache.cloudstack.api.command.user.region.ha.gslb.AssignToGlobalLoadBalancerRuleCmd in project cloudstack by apache.

the class GlobalLoadBalancingRulesServiceImplTest method runAssignToGlobalLoadBalancerRuleTestRevokedState.

void runAssignToGlobalLoadBalancerRuleTestRevokedState() throws Exception {
    TransactionLegacy txn = TransactionLegacy.open("runAssignToGlobalLoadBalancerRuleTestRevokedState");
    GlobalLoadBalancingRulesServiceImpl gslbServiceImpl = new GlobalLoadBalancingRulesServiceImpl();
    gslbServiceImpl._accountMgr = Mockito.mock(AccountManager.class);
    gslbServiceImpl._gslbRuleDao = Mockito.mock(GlobalLoadBalancerRuleDao.class);
    gslbServiceImpl._gslbLbMapDao = Mockito.mock(GlobalLoadBalancerLbRuleMapDao.class);
    gslbServiceImpl._regionDao = Mockito.mock(RegionDao.class);
    gslbServiceImpl._rulesMgr = Mockito.mock(RulesManager.class);
    gslbServiceImpl._lbDao = Mockito.mock(LoadBalancerDao.class);
    gslbServiceImpl._networkDao = Mockito.mock(NetworkDao.class);
    gslbServiceImpl._globalConfigDao = Mockito.mock(ConfigurationDao.class);
    gslbServiceImpl._ipAddressDao = Mockito.mock(IPAddressDao.class);
    gslbServiceImpl._agentMgr = Mockito.mock(AgentManager.class);
    AssignToGlobalLoadBalancerRuleCmd assignCmd = new AssignToGlobalLoadBalancerRuleCmdExtn();
    Class<?> _class = assignCmd.getClass().getSuperclass();
    Account account = new AccountVO("testaccount", 1, "networkdomain", (short) 0, UUID.randomUUID().toString());
    when(gslbServiceImpl._accountMgr.getAccount(anyLong())).thenReturn(account);
    Field gslbRuleId = _class.getDeclaredField("id");
    gslbRuleId.setAccessible(true);
    gslbRuleId.set(assignCmd, new Long(1));
    GlobalLoadBalancerRuleVO gslbRule = new GlobalLoadBalancerRuleVO("test-gslb-rule", "test-gslb-rule", "test-domain", "roundrobin", "sourceip", "tcp", 1, 1, 1, GlobalLoadBalancerRule.State.Revoke);
    when(gslbServiceImpl._gslbRuleDao.findById(new Long(1))).thenReturn(gslbRule);
    LoadBalancerVO lbRule = new LoadBalancerVO();
    lbRule.setState(FirewallRule.State.Active);
    Field networkIdField = LoadBalancerVO.class.getSuperclass().getDeclaredField("networkId");
    networkIdField.setAccessible(true);
    networkIdField.set(lbRule, new Long(1));
    when(gslbServiceImpl._lbDao.findById(new Long(1))).thenReturn(lbRule);
    Field lbRules = _class.getDeclaredField("loadBalancerRulesIds");
    lbRules.setAccessible(true);
    List<Long> lbRuleIds = new ArrayList<Long>();
    lbRuleIds.add(new Long(1));
    lbRules.set(assignCmd, lbRuleIds);
    NetworkVO networkVo = new NetworkVO();
    Field dcID = NetworkVO.class.getDeclaredField("dataCenterId");
    dcID.setAccessible(true);
    dcID.set(networkVo, new Long(1));
    when(gslbServiceImpl._networkDao.findById(new Long(1))).thenReturn(networkVo);
    try {
        gslbServiceImpl.assignToGlobalLoadBalancerRule(assignCmd);
    } catch (InvalidParameterValueException e) {
        Assert.assertTrue(e.getMessage().contains("revoked state"));
    }
}
Also used : AssignToGlobalLoadBalancerRuleCmd(org.apache.cloudstack.api.command.user.region.ha.gslb.AssignToGlobalLoadBalancerRuleCmd) ConfigurationDao(org.apache.cloudstack.framework.config.dao.ConfigurationDao) Account(com.cloud.user.Account) LoadBalancerDao(com.cloud.network.dao.LoadBalancerDao) AgentManager(com.cloud.agent.AgentManager) RulesManager(com.cloud.network.rules.RulesManager) LoadBalancerVO(com.cloud.network.dao.LoadBalancerVO) ArrayList(java.util.ArrayList) AccountVO(com.cloud.user.AccountVO) Field(java.lang.reflect.Field) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) NetworkVO(com.cloud.network.dao.NetworkVO) IPAddressDao(com.cloud.network.dao.IPAddressDao) TransactionLegacy(com.cloud.utils.db.TransactionLegacy) NetworkDao(com.cloud.network.dao.NetworkDao) Matchers.anyLong(org.mockito.Matchers.anyLong) AccountManager(com.cloud.user.AccountManager) RegionDao(org.apache.cloudstack.region.dao.RegionDao)

Aggregations

AgentManager (com.cloud.agent.AgentManager)3 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)3 IPAddressDao (com.cloud.network.dao.IPAddressDao)3 LoadBalancerDao (com.cloud.network.dao.LoadBalancerDao)3 LoadBalancerVO (com.cloud.network.dao.LoadBalancerVO)3 NetworkDao (com.cloud.network.dao.NetworkDao)3 NetworkVO (com.cloud.network.dao.NetworkVO)3 RulesManager (com.cloud.network.rules.RulesManager)3 Account (com.cloud.user.Account)3 AccountManager (com.cloud.user.AccountManager)3 AccountVO (com.cloud.user.AccountVO)3 TransactionLegacy (com.cloud.utils.db.TransactionLegacy)3 Field (java.lang.reflect.Field)3 ArrayList (java.util.ArrayList)3 AssignToGlobalLoadBalancerRuleCmd (org.apache.cloudstack.api.command.user.region.ha.gslb.AssignToGlobalLoadBalancerRuleCmd)3 ConfigurationDao (org.apache.cloudstack.framework.config.dao.ConfigurationDao)3 RegionDao (org.apache.cloudstack.region.dao.RegionDao)3 Matchers.anyLong (org.mockito.Matchers.anyLong)3 IPAddressVO (com.cloud.network.dao.IPAddressVO)1 Ip (com.cloud.utils.net.Ip)1