Search in sources :

Example 1 with CreateGlobalLoadBalancerRuleCmd

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

the class GlobalLoadBalancingRulesServiceImplTest method runCreateGlobalLoadBalancerRulePostiveTest.

void runCreateGlobalLoadBalancerRulePostiveTest() throws Exception {
    TransactionLegacy txn = TransactionLegacy.open("runCreateGlobalLoadBalancerRulePostiveTest");
    GlobalLoadBalancingRulesServiceImpl gslbServiceImpl = new GlobalLoadBalancingRulesServiceImpl();
    gslbServiceImpl._accountMgr = Mockito.mock(AccountManager.class);
    Account account = new AccountVO("testaccount", 1, "networkdomain", (short) 0, UUID.randomUUID().toString());
    when(gslbServiceImpl._accountMgr.getAccount(anyLong())).thenReturn(account);
    gslbServiceImpl._gslbRuleDao = Mockito.mock(GlobalLoadBalancerRuleDao.class);
    when(gslbServiceImpl._gslbRuleDao.persist(any(GlobalLoadBalancerRuleVO.class))).thenReturn(new GlobalLoadBalancerRuleVO());
    gslbServiceImpl._gslbLbMapDao = Mockito.mock(GlobalLoadBalancerLbRuleMapDao.class);
    gslbServiceImpl._regionDao = Mockito.mock(RegionDao.class);
    RegionVO region = new RegionVO();
    region.setGslbEnabled(true);
    when(gslbServiceImpl._regionDao.findById(anyInt())).thenReturn(region);
    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);
    CreateGlobalLoadBalancerRuleCmd createCmd = new CreateGlobalLoadBalancerRuleCmdExtn();
    Class<?> _class = createCmd.getClass().getSuperclass();
    Field regionIdField = _class.getDeclaredField("regionId");
    regionIdField.setAccessible(true);
    regionIdField.set(createCmd, new Integer(1));
    Field algoField = _class.getDeclaredField("algorithm");
    algoField.setAccessible(true);
    algoField.set(createCmd, "roundrobin");
    Field stickyField = _class.getDeclaredField("stickyMethod");
    stickyField.setAccessible(true);
    stickyField.set(createCmd, "sourceip");
    Field nameField = _class.getDeclaredField("globalLoadBalancerRuleName");
    nameField.setAccessible(true);
    nameField.set(createCmd, "gslb-rule");
    Field descriptionField = _class.getDeclaredField("description");
    descriptionField.setAccessible(true);
    descriptionField.set(createCmd, "testing create gslb-rule");
    Field serviceDomainField = _class.getDeclaredField("serviceDomainName");
    serviceDomainField.setAccessible(true);
    serviceDomainField.set(createCmd, "gslb-rule-domain");
    Field serviceTypeField = _class.getDeclaredField("serviceType");
    serviceTypeField.setAccessible(true);
    serviceTypeField.set(createCmd, "tcp");
    try {
        gslbServiceImpl.createGlobalLoadBalancerRule(createCmd);
    } catch (Exception e) {
        s_logger.info("exception in testing runCreateGlobalLoadBalancerRulePostiveTest message: " + e.toString());
    }
}
Also used : Account(com.cloud.user.Account) ConfigurationDao(org.apache.cloudstack.framework.config.dao.ConfigurationDao) LoadBalancerDao(com.cloud.network.dao.LoadBalancerDao) AgentManager(com.cloud.agent.AgentManager) IPAddressDao(com.cloud.network.dao.IPAddressDao) RulesManager(com.cloud.network.rules.RulesManager) AccountVO(com.cloud.user.AccountVO) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) TransactionLegacy(com.cloud.utils.db.TransactionLegacy) Field(java.lang.reflect.Field) NetworkDao(com.cloud.network.dao.NetworkDao) CreateGlobalLoadBalancerRuleCmd(org.apache.cloudstack.api.command.user.region.ha.gslb.CreateGlobalLoadBalancerRuleCmd) RegionVO(org.apache.cloudstack.region.RegionVO) AccountManager(com.cloud.user.AccountManager) RegionDao(org.apache.cloudstack.region.dao.RegionDao)

Example 2 with CreateGlobalLoadBalancerRuleCmd

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

the class GlobalLoadBalancingRulesServiceImplTest method runCreateGlobalLoadBalancerRuleInvalidServiceType.

void runCreateGlobalLoadBalancerRuleInvalidServiceType() throws Exception {
    TransactionLegacy txn = TransactionLegacy.open("runCreateGlobalLoadBalancerRulePostiveTest");
    GlobalLoadBalancingRulesServiceImpl gslbServiceImpl = new GlobalLoadBalancingRulesServiceImpl();
    gslbServiceImpl._accountMgr = Mockito.mock(AccountManager.class);
    Account account = new AccountVO("testaccount", 1, "networkdomain", (short) 0, UUID.randomUUID().toString());
    when(gslbServiceImpl._accountMgr.getAccount(anyLong())).thenReturn(account);
    gslbServiceImpl._gslbRuleDao = Mockito.mock(GlobalLoadBalancerRuleDao.class);
    when(gslbServiceImpl._gslbRuleDao.persist(any(GlobalLoadBalancerRuleVO.class))).thenReturn(new GlobalLoadBalancerRuleVO());
    gslbServiceImpl._gslbLbMapDao = Mockito.mock(GlobalLoadBalancerLbRuleMapDao.class);
    gslbServiceImpl._regionDao = Mockito.mock(RegionDao.class);
    RegionVO region = new RegionVO();
    region.setGslbEnabled(true);
    when(gslbServiceImpl._regionDao.findById(anyInt())).thenReturn(region);
    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);
    CreateGlobalLoadBalancerRuleCmd createCmd = new CreateGlobalLoadBalancerRuleCmdExtn();
    Class<?> _class = createCmd.getClass().getSuperclass();
    Field regionIdField = _class.getDeclaredField("regionId");
    regionIdField.setAccessible(true);
    regionIdField.set(createCmd, new Integer(1));
    Field algoField = _class.getDeclaredField("algorithm");
    algoField.setAccessible(true);
    algoField.set(createCmd, "roundrobin");
    Field stickyField = _class.getDeclaredField("stickyMethod");
    stickyField.setAccessible(true);
    stickyField.set(createCmd, "sourceip");
    Field nameField = _class.getDeclaredField("globalLoadBalancerRuleName");
    nameField.setAccessible(true);
    nameField.set(createCmd, "gslb-rule");
    Field descriptionField = _class.getDeclaredField("description");
    descriptionField.setAccessible(true);
    descriptionField.set(createCmd, "testing create gslb-rule");
    Field serviceDomainField = _class.getDeclaredField("serviceDomainName");
    serviceDomainField.setAccessible(true);
    serviceDomainField.set(createCmd, "gslb-rule-domain");
    Field serviceTypeField = _class.getDeclaredField("serviceType");
    serviceTypeField.setAccessible(true);
    serviceTypeField.set(createCmd, "invalidtcp");
    try {
        gslbServiceImpl.createGlobalLoadBalancerRule(createCmd);
    } catch (InvalidParameterValueException e) {
        Assert.assertTrue(e.getMessage().contains("Invalid service type"));
    }
}
Also used : Account(com.cloud.user.Account) ConfigurationDao(org.apache.cloudstack.framework.config.dao.ConfigurationDao) LoadBalancerDao(com.cloud.network.dao.LoadBalancerDao) AgentManager(com.cloud.agent.AgentManager) IPAddressDao(com.cloud.network.dao.IPAddressDao) RulesManager(com.cloud.network.rules.RulesManager) AccountVO(com.cloud.user.AccountVO) TransactionLegacy(com.cloud.utils.db.TransactionLegacy) Field(java.lang.reflect.Field) NetworkDao(com.cloud.network.dao.NetworkDao) CreateGlobalLoadBalancerRuleCmd(org.apache.cloudstack.api.command.user.region.ha.gslb.CreateGlobalLoadBalancerRuleCmd) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) RegionVO(org.apache.cloudstack.region.RegionVO) AccountManager(com.cloud.user.AccountManager) RegionDao(org.apache.cloudstack.region.dao.RegionDao)

Example 3 with CreateGlobalLoadBalancerRuleCmd

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

the class GlobalLoadBalancingRulesServiceImplTest method runCreateGlobalLoadBalancerRuleInvalidAlgorithm.

void runCreateGlobalLoadBalancerRuleInvalidAlgorithm() throws Exception {
    TransactionLegacy txn = TransactionLegacy.open("runCreateGlobalLoadBalancerRulePostiveTest");
    GlobalLoadBalancingRulesServiceImpl gslbServiceImpl = new GlobalLoadBalancingRulesServiceImpl();
    gslbServiceImpl._accountMgr = Mockito.mock(AccountManager.class);
    Account account = new AccountVO("testaccount", 1, "networkdomain", (short) 0, UUID.randomUUID().toString());
    when(gslbServiceImpl._accountMgr.getAccount(anyLong())).thenReturn(account);
    gslbServiceImpl._gslbRuleDao = Mockito.mock(GlobalLoadBalancerRuleDao.class);
    when(gslbServiceImpl._gslbRuleDao.persist(any(GlobalLoadBalancerRuleVO.class))).thenReturn(new GlobalLoadBalancerRuleVO());
    gslbServiceImpl._gslbLbMapDao = Mockito.mock(GlobalLoadBalancerLbRuleMapDao.class);
    gslbServiceImpl._regionDao = Mockito.mock(RegionDao.class);
    RegionVO region = new RegionVO();
    region.setGslbEnabled(true);
    when(gslbServiceImpl._regionDao.findById(anyInt())).thenReturn(region);
    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);
    CreateGlobalLoadBalancerRuleCmd createCmd = new CreateGlobalLoadBalancerRuleCmdExtn();
    Class<?> _class = createCmd.getClass().getSuperclass();
    Field regionIdField = _class.getDeclaredField("regionId");
    regionIdField.setAccessible(true);
    regionIdField.set(createCmd, new Integer(1));
    Field algoField = _class.getDeclaredField("algorithm");
    algoField.setAccessible(true);
    algoField.set(createCmd, "invalidalgo");
    Field stickyField = _class.getDeclaredField("stickyMethod");
    stickyField.setAccessible(true);
    stickyField.set(createCmd, "sourceip");
    Field nameField = _class.getDeclaredField("globalLoadBalancerRuleName");
    nameField.setAccessible(true);
    nameField.set(createCmd, "gslb-rule");
    Field descriptionField = _class.getDeclaredField("description");
    descriptionField.setAccessible(true);
    descriptionField.set(createCmd, "testing create gslb-rule");
    Field serviceDomainField = _class.getDeclaredField("serviceDomainName");
    serviceDomainField.setAccessible(true);
    serviceDomainField.set(createCmd, "gslb-rule-domain");
    Field serviceTypeField = _class.getDeclaredField("serviceType");
    serviceTypeField.setAccessible(true);
    serviceTypeField.set(createCmd, "tcp");
    try {
        gslbServiceImpl.createGlobalLoadBalancerRule(createCmd);
    } catch (InvalidParameterValueException e) {
        Assert.assertTrue(e.getMessage().contains("Invalid Algorithm"));
    }
}
Also used : Account(com.cloud.user.Account) ConfigurationDao(org.apache.cloudstack.framework.config.dao.ConfigurationDao) LoadBalancerDao(com.cloud.network.dao.LoadBalancerDao) AgentManager(com.cloud.agent.AgentManager) IPAddressDao(com.cloud.network.dao.IPAddressDao) RulesManager(com.cloud.network.rules.RulesManager) AccountVO(com.cloud.user.AccountVO) TransactionLegacy(com.cloud.utils.db.TransactionLegacy) Field(java.lang.reflect.Field) NetworkDao(com.cloud.network.dao.NetworkDao) CreateGlobalLoadBalancerRuleCmd(org.apache.cloudstack.api.command.user.region.ha.gslb.CreateGlobalLoadBalancerRuleCmd) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) RegionVO(org.apache.cloudstack.region.RegionVO) AccountManager(com.cloud.user.AccountManager) RegionDao(org.apache.cloudstack.region.dao.RegionDao)

Example 4 with CreateGlobalLoadBalancerRuleCmd

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

the class GlobalLoadBalancingRulesServiceImplTest method runCreateGlobalLoadBalancerRuleInvalidStickyMethod.

void runCreateGlobalLoadBalancerRuleInvalidStickyMethod() throws Exception {
    TransactionLegacy txn = TransactionLegacy.open("runCreateGlobalLoadBalancerRulePostiveTest");
    GlobalLoadBalancingRulesServiceImpl gslbServiceImpl = new GlobalLoadBalancingRulesServiceImpl();
    gslbServiceImpl._accountMgr = Mockito.mock(AccountManager.class);
    Account account = new AccountVO("testaccount", 1, "networkdomain", (short) 0, UUID.randomUUID().toString());
    when(gslbServiceImpl._accountMgr.getAccount(anyLong())).thenReturn(account);
    gslbServiceImpl._gslbRuleDao = Mockito.mock(GlobalLoadBalancerRuleDao.class);
    when(gslbServiceImpl._gslbRuleDao.persist(any(GlobalLoadBalancerRuleVO.class))).thenReturn(new GlobalLoadBalancerRuleVO());
    gslbServiceImpl._gslbLbMapDao = Mockito.mock(GlobalLoadBalancerLbRuleMapDao.class);
    gslbServiceImpl._regionDao = Mockito.mock(RegionDao.class);
    RegionVO region = new RegionVO();
    region.setGslbEnabled(true);
    when(gslbServiceImpl._regionDao.findById(anyInt())).thenReturn(region);
    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);
    CreateGlobalLoadBalancerRuleCmd createCmd = new CreateGlobalLoadBalancerRuleCmdExtn();
    Class<?> _class = createCmd.getClass().getSuperclass();
    Field regionIdField = _class.getDeclaredField("regionId");
    regionIdField.setAccessible(true);
    regionIdField.set(createCmd, new Integer(1));
    Field algoField = _class.getDeclaredField("algorithm");
    algoField.setAccessible(true);
    algoField.set(createCmd, "roundrobin");
    Field stickyField = _class.getDeclaredField("stickyMethod");
    stickyField.setAccessible(true);
    stickyField.set(createCmd, "ivalidstickymethod");
    Field nameField = _class.getDeclaredField("globalLoadBalancerRuleName");
    nameField.setAccessible(true);
    nameField.set(createCmd, "gslb-rule");
    Field descriptionField = _class.getDeclaredField("description");
    descriptionField.setAccessible(true);
    descriptionField.set(createCmd, "testing create gslb-rule");
    Field serviceDomainField = _class.getDeclaredField("serviceDomainName");
    serviceDomainField.setAccessible(true);
    serviceDomainField.set(createCmd, "gslb-rule-domain");
    Field serviceTypeField = _class.getDeclaredField("serviceType");
    serviceTypeField.setAccessible(true);
    serviceTypeField.set(createCmd, "tcp");
    try {
        gslbServiceImpl.createGlobalLoadBalancerRule(createCmd);
    } catch (InvalidParameterValueException e) {
        Assert.assertTrue(e.getMessage().contains("Invalid persistence"));
    }
}
Also used : Account(com.cloud.user.Account) ConfigurationDao(org.apache.cloudstack.framework.config.dao.ConfigurationDao) LoadBalancerDao(com.cloud.network.dao.LoadBalancerDao) AgentManager(com.cloud.agent.AgentManager) IPAddressDao(com.cloud.network.dao.IPAddressDao) RulesManager(com.cloud.network.rules.RulesManager) AccountVO(com.cloud.user.AccountVO) TransactionLegacy(com.cloud.utils.db.TransactionLegacy) Field(java.lang.reflect.Field) NetworkDao(com.cloud.network.dao.NetworkDao) CreateGlobalLoadBalancerRuleCmd(org.apache.cloudstack.api.command.user.region.ha.gslb.CreateGlobalLoadBalancerRuleCmd) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) RegionVO(org.apache.cloudstack.region.RegionVO) AccountManager(com.cloud.user.AccountManager) RegionDao(org.apache.cloudstack.region.dao.RegionDao)

Example 5 with CreateGlobalLoadBalancerRuleCmd

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

the class GlobalLoadBalancingRulesServiceImplTest method runCreateGlobalLoadBalancerRuleInvalidDomainName.

void runCreateGlobalLoadBalancerRuleInvalidDomainName() throws Exception {
    TransactionLegacy txn = TransactionLegacy.open("runCreateGlobalLoadBalancerRulePostiveTest");
    GlobalLoadBalancingRulesServiceImpl gslbServiceImpl = new GlobalLoadBalancingRulesServiceImpl();
    gslbServiceImpl._accountMgr = Mockito.mock(AccountManager.class);
    Account account = new AccountVO("testaccount", 1, "networkdomain", (short) 0, UUID.randomUUID().toString());
    when(gslbServiceImpl._accountMgr.getAccount(anyLong())).thenReturn(account);
    gslbServiceImpl._gslbRuleDao = Mockito.mock(GlobalLoadBalancerRuleDao.class);
    gslbServiceImpl._gslbLbMapDao = Mockito.mock(GlobalLoadBalancerLbRuleMapDao.class);
    gslbServiceImpl._regionDao = Mockito.mock(RegionDao.class);
    RegionVO region = new RegionVO();
    region.setGslbEnabled(true);
    when(gslbServiceImpl._regionDao.findById(anyInt())).thenReturn(region);
    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);
    CreateGlobalLoadBalancerRuleCmd createCmd = new CreateGlobalLoadBalancerRuleCmdExtn();
    Class<?> _class = createCmd.getClass().getSuperclass();
    Field regionIdField = _class.getDeclaredField("regionId");
    regionIdField.setAccessible(true);
    regionIdField.set(createCmd, new Integer(1));
    Field algoField = _class.getDeclaredField("algorithm");
    algoField.setAccessible(true);
    algoField.set(createCmd, "roundrobin");
    Field stickyField = _class.getDeclaredField("stickyMethod");
    stickyField.setAccessible(true);
    stickyField.set(createCmd, "sourceip");
    Field nameField = _class.getDeclaredField("globalLoadBalancerRuleName");
    nameField.setAccessible(true);
    nameField.set(createCmd, "gslb-rule");
    Field descriptionField = _class.getDeclaredField("description");
    descriptionField.setAccessible(true);
    descriptionField.set(createCmd, "testing create gslb-rule");
    Field serviceDomainField = _class.getDeclaredField("serviceDomainName");
    serviceDomainField.setAccessible(true);
    serviceDomainField.set(createCmd, "gslb-rule-domain");
    GlobalLoadBalancerRuleVO gslbRule = new GlobalLoadBalancerRuleVO();
    when(gslbServiceImpl._gslbRuleDao.findByDomainName("gslb-rule-domain")).thenReturn(gslbRule);
    Field serviceTypeField = _class.getDeclaredField("serviceType");
    serviceTypeField.setAccessible(true);
    serviceTypeField.set(createCmd, "tcp");
    try {
        gslbServiceImpl.createGlobalLoadBalancerRule(createCmd);
    } catch (InvalidParameterValueException e) {
        Assert.assertTrue(e.getMessage().contains("Domain name " + "gslb-rule-domain" + "is in use"));
    }
}
Also used : Account(com.cloud.user.Account) ConfigurationDao(org.apache.cloudstack.framework.config.dao.ConfigurationDao) LoadBalancerDao(com.cloud.network.dao.LoadBalancerDao) AgentManager(com.cloud.agent.AgentManager) IPAddressDao(com.cloud.network.dao.IPAddressDao) RulesManager(com.cloud.network.rules.RulesManager) AccountVO(com.cloud.user.AccountVO) TransactionLegacy(com.cloud.utils.db.TransactionLegacy) Field(java.lang.reflect.Field) NetworkDao(com.cloud.network.dao.NetworkDao) CreateGlobalLoadBalancerRuleCmd(org.apache.cloudstack.api.command.user.region.ha.gslb.CreateGlobalLoadBalancerRuleCmd) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) RegionVO(org.apache.cloudstack.region.RegionVO) AccountManager(com.cloud.user.AccountManager) RegionDao(org.apache.cloudstack.region.dao.RegionDao)

Aggregations

AgentManager (com.cloud.agent.AgentManager)5 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)5 IPAddressDao (com.cloud.network.dao.IPAddressDao)5 LoadBalancerDao (com.cloud.network.dao.LoadBalancerDao)5 NetworkDao (com.cloud.network.dao.NetworkDao)5 RulesManager (com.cloud.network.rules.RulesManager)5 Account (com.cloud.user.Account)5 AccountManager (com.cloud.user.AccountManager)5 AccountVO (com.cloud.user.AccountVO)5 TransactionLegacy (com.cloud.utils.db.TransactionLegacy)5 Field (java.lang.reflect.Field)5 CreateGlobalLoadBalancerRuleCmd (org.apache.cloudstack.api.command.user.region.ha.gslb.CreateGlobalLoadBalancerRuleCmd)5 ConfigurationDao (org.apache.cloudstack.framework.config.dao.ConfigurationDao)5 RegionVO (org.apache.cloudstack.region.RegionVO)5 RegionDao (org.apache.cloudstack.region.dao.RegionDao)5