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