Search in sources :

Example 1 with RegionVO

use of org.apache.cloudstack.region.RegionVO in project cloudstack by apache.

the class ConfigurationManagerImpl method createPortableIpRange.

@Override
@DB
@ActionEvent(eventType = EventTypes.EVENT_PORTABLE_IP_RANGE_CREATE, eventDescription = "creating portable ip range", async = false)
public PortableIpRange createPortableIpRange(final CreatePortableIpRangeCmd cmd) throws ConcurrentOperationException {
    final Integer regionId = cmd.getRegionId();
    final String startIP = cmd.getStartIp();
    final String endIP = cmd.getEndIp();
    final String gateway = cmd.getGateway();
    final String netmask = cmd.getNetmask();
    String vlanId = cmd.getVlan();
    final RegionVO region = _regionDao.findById(regionId);
    if (region == null) {
        throw new InvalidParameterValueException("Invalid region ID: " + regionId);
    }
    if (!NetUtils.isValidIp(startIP) || !NetUtils.isValidIp(endIP) || !NetUtils.validIpRange(startIP, endIP)) {
        throw new InvalidParameterValueException("Invalid portable ip  range: " + startIP + "-" + endIP);
    }
    if (!NetUtils.sameSubnet(startIP, gateway, netmask)) {
        throw new InvalidParameterValueException("Please ensure that your start IP is in the same subnet as " + "your portable IP range's gateway and as per the IP range's netmask.");
    }
    if (!NetUtils.sameSubnet(endIP, gateway, netmask)) {
        throw new InvalidParameterValueException("Please ensure that your end IP is in the same subnet as " + "your portable IP range's gateway and as per the IP range's netmask.");
    }
    if (checkOverlapPortableIpRange(regionId, startIP, endIP)) {
        throw new InvalidParameterValueException("Ip  range: " + startIP + "-" + endIP + " overlaps with a portable" + " IP range already configured in the region " + regionId);
    }
    if (vlanId == null) {
        vlanId = Vlan.UNTAGGED;
    } else {
        if (!NetUtils.isValidVlan(vlanId)) {
            throw new InvalidParameterValueException("Invalid vlan id " + vlanId);
        }
        final List<DataCenterVO> zones = _zoneDao.listAllZones();
        if (zones != null && !zones.isEmpty()) {
            for (final DataCenterVO zone : zones) {
                // check if there is zone vlan with same id
                if (_vlanDao.findByZoneAndVlanId(zone.getId(), vlanId) != null) {
                    throw new InvalidParameterValueException("Found a VLAN id " + vlanId + " already existing in" + " zone " + zone.getUuid() + " that conflicts with VLAN id of the portable ip range being configured");
                }
                //check if there is a public ip range that overlaps with portable ip range being created
                checkOverlapPublicIpRange(zone.getId(), startIP, endIP);
            }
        }
    }
    final GlobalLock portableIpLock = GlobalLock.getInternLock("PortablePublicIpRange");
    portableIpLock.lock(5);
    try {
        final String vlanIdFinal = vlanId;
        return Transaction.execute(new TransactionCallback<PortableIpRangeVO>() {

            @Override
            public PortableIpRangeVO doInTransaction(final TransactionStatus status) {
                PortableIpRangeVO portableIpRange = new PortableIpRangeVO(regionId, vlanIdFinal, gateway, netmask, startIP, endIP);
                portableIpRange = _portableIpRangeDao.persist(portableIpRange);
                long startIpLong = NetUtils.ip2Long(startIP);
                final long endIpLong = NetUtils.ip2Long(endIP);
                while (startIpLong <= endIpLong) {
                    final PortableIpVO portableIP = new PortableIpVO(regionId, portableIpRange.getId(), vlanIdFinal, gateway, netmask, NetUtils.long2Ip(startIpLong));
                    _portableIpDao.persist(portableIP);
                    startIpLong++;
                }
                // implicitly enable portable IP service for the region
                region.setPortableipEnabled(true);
                _regionDao.update(region.getId(), region);
                return portableIpRange;
            }
        });
    } finally {
        portableIpLock.unlock();
    }
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) GlobalLock(com.cloud.utils.db.GlobalLock) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) RegionVO(org.apache.cloudstack.region.RegionVO) TransactionStatus(com.cloud.utils.db.TransactionStatus) PortableIpRangeVO(org.apache.cloudstack.region.PortableIpRangeVO) PortableIpVO(org.apache.cloudstack.region.PortableIpVO) ActionEvent(com.cloud.event.ActionEvent) DB(com.cloud.utils.db.DB)

Example 2 with RegionVO

use of org.apache.cloudstack.region.RegionVO 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 RegionVO

use of org.apache.cloudstack.region.RegionVO 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 4 with RegionVO

use of org.apache.cloudstack.region.RegionVO 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 RegionVO

use of org.apache.cloudstack.region.RegionVO 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)

Aggregations

InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)7 RegionVO (org.apache.cloudstack.region.RegionVO)7 AgentManager (com.cloud.agent.AgentManager)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 RegionDao (org.apache.cloudstack.region.dao.RegionDao)5 ActionEvent (com.cloud.event.ActionEvent)2 DB (com.cloud.utils.db.DB)2 PortableIpRangeVO (org.apache.cloudstack.region.PortableIpRangeVO)2 PortableIpVO (org.apache.cloudstack.region.PortableIpVO)2 DataCenterVO (com.cloud.dc.DataCenterVO)1