You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by al...@apache.org on 2013/12/24 02:06:20 UTC
[2/3] CLOUDSTACK-5390: when calculate index (page #) in
NetworkManager, rely on fact that getStartIndex() returned by API,
returns pageSize*(page-1). So to get index(page),
you need to do the reverse calculation
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/632346d6/server/src/com/cloud/network/NetworkServiceImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/NetworkServiceImpl.java b/server/src/com/cloud/network/NetworkServiceImpl.java
index 7684a8a..5bbb1ca 100755
--- a/server/src/com/cloud/network/NetworkServiceImpl.java
+++ b/server/src/com/cloud/network/NetworkServiceImpl.java
@@ -40,7 +40,6 @@ import javax.ejb.Local;
import javax.inject.Inject;
import javax.naming.ConfigurationException;
-import org.apache.log4j.Logger;
import org.apache.cloudstack.acl.ControlledEntity.ACLType;
import org.apache.cloudstack.acl.SecurityChecker.AccessType;
import org.apache.cloudstack.api.command.admin.network.DedicateGuestVlanRangeCmd;
@@ -54,6 +53,7 @@ import org.apache.cloudstack.context.CallContext;
import org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService;
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
import org.apache.cloudstack.network.element.InternalLoadBalancerElementService;
+import org.apache.log4j.Logger;
import com.cloud.api.ApiDBUtils;
import com.cloud.configuration.Config;
@@ -158,13 +158,13 @@ import com.cloud.utils.db.Filter;
import com.cloud.utils.db.JoinBuilder;
import com.cloud.utils.db.SearchBuilder;
import com.cloud.utils.db.SearchCriteria;
+import com.cloud.utils.db.SearchCriteria.Op;
+import com.cloud.utils.db.Transaction;
import com.cloud.utils.db.TransactionCallback;
import com.cloud.utils.db.TransactionCallbackNoReturn;
import com.cloud.utils.db.TransactionCallbackWithException;
import com.cloud.utils.db.TransactionLegacy;
import com.cloud.utils.db.TransactionStatus;
-import com.cloud.utils.db.SearchCriteria.Op;
-import com.cloud.utils.db.Transaction;
import com.cloud.utils.exception.CloudRuntimeException;
import com.cloud.utils.exception.ExceptionUtil;
import com.cloud.utils.net.NetUtils;
@@ -183,12 +183,11 @@ import com.cloud.vm.dao.NicSecondaryIpVO;
import com.cloud.vm.dao.UserVmDao;
import com.cloud.vm.dao.VMInstanceDao;
-
/**
* NetworkServiceImpl implements NetworkService.
*/
-@Local(value = { NetworkService.class })
-public class NetworkServiceImpl extends ManagerBase implements NetworkService {
+@Local(value = {NetworkService.class})
+public class NetworkServiceImpl extends ManagerBase implements NetworkService {
private static final Logger s_logger = Logger.getLogger(NetworkServiceImpl.class);
private static final long MIN_VLAN_ID = 0L;
@@ -328,7 +327,7 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
// see the IPAddressVO.java class.
IPAddressVO ipAddr = ApiDBUtils.findIpAddressById(ip.getAssociatedWithNetworkId());
String ipAddrUuid = ip.getAssociatedWithNetworkId().toString();
- if ( ipAddr != null ){
+ if (ipAddr != null) {
ipAddrUuid = ipAddr.getUuid();
}
ex.addProxyObject(ipAddrUuid, "networkId");
@@ -419,8 +418,9 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
if (services.size() != 1) {
throw new InvalidParameterException("There are multiple services used ip " + ip.getAddress() + ".");
}
- if (service != null && !((Service) services.toArray()[0] == service || service.equals(Service.Firewall))) {
- throw new InvalidParameterException("The IP " + ip.getAddress() + " is already used as " + ((Service) services.toArray()[0]).getName() + " rather than " + service.getName());
+ if (service != null && !((Service)services.toArray()[0] == service || service.equals(Service.Firewall))) {
+ throw new InvalidParameterException("The IP " + ip.getAddress() + " is already used as " + ((Service)services.toArray()[0]).getName() + " rather than "
+ + service.getName());
}
return true;
}
@@ -459,7 +459,7 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
if (curProviders == null || curProviders.isEmpty()) {
continue;
}
- Provider curProvider = (Provider) curProviders.toArray()[0];
+ Provider curProvider = (Provider)curProviders.toArray()[0];
if (provider == null) {
provider = curProvider;
continue;
@@ -473,9 +473,6 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
return true;
}
-
-
-
private Set<Purpose> getPublicIpPurposeInRules(PublicIp ip, boolean includeRevoked, boolean includingFirewall) {
Set<Purpose> result = new HashSet<Purpose>();
List<FirewallRuleVO> rules = null;
@@ -510,13 +507,10 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
return _networksDao.listSourceNATEnabledNetworks(owner.getId(), zoneId, Network.GuestType.Isolated);
}
-
-
-
@Override
@ActionEvent(eventType = EventTypes.EVENT_NET_IP_ASSIGN, eventDescription = "allocating Ip", create = true)
- public IpAddress allocateIP(Account ipOwner, long zoneId, Long networkId)
- throws ResourceAllocationException, InsufficientAddressCapacityException, ConcurrentOperationException {
+ public IpAddress allocateIP(Account ipOwner, long zoneId, Long networkId) throws ResourceAllocationException, InsufficientAddressCapacityException,
+ ConcurrentOperationException {
Account caller = CallContext.current().getCallingAccount();
long callerUserId = CallContext.current().getCallingUserId();
@@ -541,8 +535,8 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
}
return _ipAddrMgr.allocateIp(ipOwner, false, caller, callerUserId, zone);
} else {
- throw new InvalidParameterValueException("Associate IP address can only be called on the shared networks in the advanced zone" +
- " with Firewall/Source Nat/Static Nat/Port Forwarding/Load balancing services enabled");
+ throw new InvalidParameterValueException("Associate IP address can only be called on the shared networks in the advanced zone"
+ + " with Firewall/Source Nat/Static Nat/Port Forwarding/Load balancing services enabled");
}
}
}
@@ -555,8 +549,8 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
@Override
@ActionEvent(eventType = EventTypes.EVENT_PORTABLE_IP_ASSIGN, eventDescription = "allocating portable public Ip", create = true)
- public IpAddress allocatePortableIP(Account ipOwner, int regionId, Long zoneId, Long networkId, Long vpcId)
- throws ResourceAllocationException, InsufficientAddressCapacityException, ConcurrentOperationException {
+ public IpAddress allocatePortableIP(Account ipOwner, int regionId, Long zoneId, Long networkId, Long vpcId) throws ResourceAllocationException,
+ InsufficientAddressCapacityException, ConcurrentOperationException {
Account caller = CallContext.current().getCallingAccount();
long callerUserId = CallContext.current().getCallingUserId();
DataCenter zone = _entityMgr.findById(DataCenter.class, zoneId);
@@ -584,8 +578,8 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
}
return _ipAddrMgr.allocatePortableIp(ipOwner, caller, zoneId, networkId, null);
} else {
- throw new InvalidParameterValueException("Associate IP address can only be called on the shared networks in the advanced zone" +
- " with Firewall/Source Nat/Static Nat/Port Forwarding/Load balancing services enabled");
+ throw new InvalidParameterValueException("Associate IP address can only be called on the shared networks in the advanced zone"
+ + " with Firewall/Source Nat/Static Nat/Port Forwarding/Load balancing services enabled");
}
}
}
@@ -609,7 +603,7 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
try {
return releaseIpAddressInternal(ipAddressId);
} catch (Exception e) {
- return false;
+ return false;
}
}
@@ -640,9 +634,9 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
protected NetworkServiceImpl() {
}
-
@Override
- public NicSecondaryIp allocateSecondaryGuestIP (Account ipOwner, long zoneId, final Long nicId, final Long networkId, String requestedIp) throws InsufficientAddressCapacityException {
+ public NicSecondaryIp allocateSecondaryGuestIP(Account ipOwner, long zoneId, final Long nicId, final Long networkId, String requestedIp)
+ throws InsufficientAddressCapacityException {
String ipaddr = null;
@@ -669,7 +663,6 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
// verify permissions
_accountMgr.checkAccess(ipOwner, null, true, vm);
-
Network network = _networksDao.findById(networkId);
if (network == null) {
throw new InvalidParameterValueException("Invalid network id is given");
@@ -694,7 +687,7 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
} catch (InsufficientAddressCapacityException e) {
throw new InvalidParameterValueException("Allocating guest ip for nic failed");
}
- } else if (dc.getNetworkType() == NetworkType.Basic || ntwkOff.getGuestType() == Network.GuestType.Shared) {
+ } else if (dc.getNetworkType() == NetworkType.Basic || ntwkOff.getGuestType() == Network.GuestType.Shared) {
//handle the basic networks here
VMInstanceVO vmi = (VMInstanceVO)vm;
Long podId = vmi.getPodIdToDeployIn();
@@ -733,7 +726,7 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
s_logger.debug("Setting nics table ...");
_nicDao.update(nicId, nicVO);
}
-
+
s_logger.debug("Setting nic_secondary_ip table ...");
Long vmId = nicVO.getInstanceId();
NicSecondaryIpVO secondaryIpVO = new NicSecondaryIpVO(nicId, addrFinal, vmId, accountId, domainId, networkId);
@@ -742,7 +735,7 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
}
});
- return getNicSecondaryIp(id);
+ return getNicSecondaryIp(id);
} else {
return null;
}
@@ -750,12 +743,12 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
@Override
@DB
- public boolean releaseSecondaryIpFromNic (long ipAddressId) {
+ public boolean releaseSecondaryIpFromNic(long ipAddressId) {
Account caller = CallContext.current().getCallingAccount();
boolean success = false;
// Verify input parameters
- NicSecondaryIpVO secIpVO= _nicSecondaryIpDao.findById(ipAddressId);
+ NicSecondaryIpVO secIpVO = _nicSecondaryIpDao.findById(ipAddressId);
if (secIpVO == null) {
throw new InvalidParameterValueException("Unable to find secondary ip address by id");
}
@@ -791,14 +784,14 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
throw new InvalidParameterValueException("Invalid zone Id is given");
}
- s_logger.debug("Calling secondary ip "+ secIpVO.getIp4Address() + " release ");
+ s_logger.debug("Calling secondary ip " + secIpVO.getIp4Address() + " release ");
if (dc.getNetworkType() == NetworkType.Advanced && network.getGuestType() == Network.GuestType.Isolated) {
//check PF or static NAT is configured on this ip address
String secondaryIp = secIpVO.getIp4Address();
- List<FirewallRuleVO> fwRulesList = _firewallDao.listByNetworkAndPurpose(network.getId(), Purpose.PortForwarding);
+ List<FirewallRuleVO> fwRulesList = _firewallDao.listByNetworkAndPurpose(network.getId(), Purpose.PortForwarding);
if (fwRulesList.size() != 0) {
- for (FirewallRuleVO rule: fwRulesList) {
+ for (FirewallRuleVO rule : fwRulesList) {
if (_portForwardingDao.findByIdAndIp(rule.getId(), secondaryIp) != null) {
s_logger.debug("VM nic IP " + secondaryIp + " is associated with the port forwarding rule");
throw new InvalidParameterValueException("Can't remove the secondary ip " + secondaryIp + " is associate with the port forwarding rule");
@@ -811,7 +804,7 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
s_logger.debug("VM nic IP " + secondaryIp + " is associated with the static NAT rule public IP address id " + publicIpVO.getId());
throw new InvalidParameterValueException("Can' remove the ip " + secondaryIp + "is associate with static NAT rule public IP address id " + publicIpVO.getId());
}
- } else if (dc.getNetworkType() == NetworkType.Basic || ntwkOff.getGuestType() == Network.GuestType.Shared) {
+ } else if (dc.getNetworkType() == NetworkType.Basic || ntwkOff.getGuestType() == Network.GuestType.Shared) {
final IPAddressVO ip = _ipAddressDao.findByIpAndSourceNetworkId(secIpVO.getNetworkId(), secIpVO.getIp4Address());
if (ip != null) {
Transaction.execute(new TransactionCallbackNoReturn() {
@@ -851,7 +844,7 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
return true;
}
- NicSecondaryIp getNicSecondaryIp (long id) {
+ NicSecondaryIp getNicSecondaryIp(long id) {
NicSecondaryIp nicSecIp = _nicSecondaryIpDao.findById(id);
if (nicSecIp == null) {
return null;
@@ -927,7 +920,6 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
return _networksDao.findById(id);
}
-
private void checkSharedNetworkCidrOverlap(Long zoneId, long physicalNetworkId, String cidr) {
if (zoneId == null || cidr == null) {
return;
@@ -941,11 +933,11 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
// in the zone when using external networking
PhysicalNetworkVO pNetwork = _physicalNetworkDao.findById(physicalNetworkId);
if (pNetwork.getVnet() != null) {
- List <Pair<Integer,Integer>> vlanList = pNetwork.getVnet();
- for (Pair<Integer,Integer> vlanRange : vlanList){
+ List<Pair<Integer, Integer>> vlanList = pNetwork.getVnet();
+ for (Pair<Integer, Integer> vlanRange : vlanList) {
Integer lowestVlanTag = vlanRange.first();
Integer highestVlanTag = vlanRange.second();
- for (int vlan=lowestVlanTag; vlan <= highestVlanTag; ++vlan) {
+ for (int vlan = lowestVlanTag; vlan <= highestVlanTag; ++vlan) {
int offset = vlan - lowestVlanTag;
String globalVlanBits = _configDao.getValue(Config.GuestVlanBits.key());
int cidrSize = 8 + Integer.parseInt(globalVlanBits);
@@ -1030,11 +1022,11 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
zoneId = pNtwk.getDataCenterId();
}
- if(displayNetwork != null){
- if(!_accountMgr.isRootAdmin(caller.getType())){
+ if (displayNetwork != null) {
+ if (!_accountMgr.isRootAdmin(caller.getType())) {
throw new PermissionDeniedException("Only admin allowed to update displaynetwork parameter");
}
- }else{
+ } else {
displayNetwork = true;
}
@@ -1067,8 +1059,7 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
}
} else if (ntwkOff.getGuestType() == GuestType.Shared) {
if (!(aclType == ACLType.Domain || aclType == ACLType.Account)) {
- throw new InvalidParameterValueException("AclType should be " + ACLType.Domain + " or " +
- ACLType.Account + " for network of type " + Network.GuestType.Shared);
+ throw new InvalidParameterValueException("AclType should be " + ACLType.Domain + " or " + ACLType.Account + " for network of type " + Network.GuestType.Shared);
}
}
} else {
@@ -1098,8 +1089,8 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
if (domainId != null) {
if (ntwkOff.getTrafficType() != TrafficType.Guest || ntwkOff.getGuestType() != Network.GuestType.Shared) {
- throw new InvalidParameterValueException("Domain level networks are supported just for traffic type "
- + TrafficType.Guest + " and guest type " + Network.GuestType.Shared);
+ throw new InvalidParameterValueException("Domain level networks are supported just for traffic type " + TrafficType.Guest + " and guest type "
+ + Network.GuestType.Shared);
}
DomainVO domain = _domainDao.findById(domainId);
@@ -1122,88 +1113,86 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
boolean ipv4 = true, ipv6 = false;
if (startIP != null) {
- ipv4 = true;
+ ipv4 = true;
}
if (startIPv6 != null) {
- ipv6 = true;
+ ipv6 = true;
}
if (gateway != null) {
- try {
- // getByName on a literal representation will only check validity of the address
- // http://docs.oracle.com/javase/6/docs/api/java/net/InetAddress.html#getByName(java.lang.String)
- InetAddress gatewayAddress = InetAddress.getByName(gateway);
- if (gatewayAddress instanceof Inet6Address) {
- ipv6 = true;
- } else {
- ipv4 = true;
- }
+ try {
+ // getByName on a literal representation will only check validity of the address
+ // http://docs.oracle.com/javase/6/docs/api/java/net/InetAddress.html#getByName(java.lang.String)
+ InetAddress gatewayAddress = InetAddress.getByName(gateway);
+ if (gatewayAddress instanceof Inet6Address) {
+ ipv6 = true;
+ } else {
+ ipv4 = true;
+ }
} catch (UnknownHostException e) {
- s_logger.error("Unable to convert gateway IP to a InetAddress", e);
- throw new InvalidParameterValueException("Gateway parameter is invalid");
- }
+ s_logger.error("Unable to convert gateway IP to a InetAddress", e);
+ throw new InvalidParameterValueException("Gateway parameter is invalid");
+ }
}
-
String cidr = null;
if (ipv4) {
- // if end ip is not specified, default it to startIp
- if (startIP != null) {
- if (!NetUtils.isValidIp(startIP)) {
- throw new InvalidParameterValueException("Invalid format for the startIp parameter");
- }
- if (endIP == null) {
- endIP = startIP;
- } else if (!NetUtils.isValidIp(endIP)) {
- throw new InvalidParameterValueException("Invalid format for the endIp parameter");
- }
- }
-
- if (startIP != null && endIP != null) {
- if (!(gateway != null && netmask != null)) {
- throw new InvalidParameterValueException("gateway and netmask should be defined when startIP/endIP are passed in");
- }
- }
-
- if (gateway != null && netmask != null) {
- if (!NetUtils.isValidIp(gateway)) {
- throw new InvalidParameterValueException("Invalid gateway");
- }
- if (!NetUtils.isValidNetmask(netmask)) {
- throw new InvalidParameterValueException("Invalid netmask");
- }
-
- cidr = NetUtils.ipAndNetMaskToCidr(gateway, netmask);
- }
+ // if end ip is not specified, default it to startIp
+ if (startIP != null) {
+ if (!NetUtils.isValidIp(startIP)) {
+ throw new InvalidParameterValueException("Invalid format for the startIp parameter");
+ }
+ if (endIP == null) {
+ endIP = startIP;
+ } else if (!NetUtils.isValidIp(endIP)) {
+ throw new InvalidParameterValueException("Invalid format for the endIp parameter");
+ }
+ }
+
+ if (startIP != null && endIP != null) {
+ if (!(gateway != null && netmask != null)) {
+ throw new InvalidParameterValueException("gateway and netmask should be defined when startIP/endIP are passed in");
+ }
+ }
+
+ if (gateway != null && netmask != null) {
+ if (!NetUtils.isValidIp(gateway)) {
+ throw new InvalidParameterValueException("Invalid gateway");
+ }
+ if (!NetUtils.isValidNetmask(netmask)) {
+ throw new InvalidParameterValueException("Invalid netmask");
+ }
+
+ cidr = NetUtils.ipAndNetMaskToCidr(gateway, netmask);
+ }
}
if (ipv6) {
- if (endIPv6 == null) {
- endIPv6 = startIPv6;
- }
- _networkModel.checkIp6Parameters(startIPv6, endIPv6, ip6Gateway, ip6Cidr);
+ if (endIPv6 == null) {
+ endIPv6 = startIPv6;
+ }
+ _networkModel.checkIp6Parameters(startIPv6, endIPv6, ip6Gateway, ip6Cidr);
- if (zone.getNetworkType() != NetworkType.Advanced || ntwkOff.getGuestType() != Network.GuestType.Shared) {
- throw new InvalidParameterValueException("Can only support create IPv6 network with advance shared network!");
- }
+ if (zone.getNetworkType() != NetworkType.Advanced || ntwkOff.getGuestType() != Network.GuestType.Shared) {
+ throw new InvalidParameterValueException("Can only support create IPv6 network with advance shared network!");
+ }
}
if (isolatedPvlan != null && (zone.getNetworkType() != NetworkType.Advanced || ntwkOff.getGuestType() != Network.GuestType.Shared)) {
- throw new InvalidParameterValueException("Can only support create Private VLAN network with advance shared network!");
+ throw new InvalidParameterValueException("Can only support create Private VLAN network with advance shared network!");
}
if (isolatedPvlan != null && ipv6) {
- throw new InvalidParameterValueException("Can only support create Private VLAN network with IPv4!");
+ throw new InvalidParameterValueException("Can only support create Private VLAN network with IPv4!");
}
// Regular user can create Guest Isolated Source Nat enabled network only
if (caller.getType() == Account.ACCOUNT_TYPE_NORMAL
&& (ntwkOff.getTrafficType() != TrafficType.Guest || ntwkOff.getGuestType() != Network.GuestType.Isolated
&& areServicesSupportedByNetworkOffering(ntwkOff.getId(), Service.SourceNat))) {
- throw new InvalidParameterValueException("Regular user can create a network only from the network" +
- " offering having traffic type " + TrafficType.Guest + " and network type "
- + Network.GuestType.Isolated + " with a service " + Service.SourceNat.getName() + " enabled");
+ throw new InvalidParameterValueException("Regular user can create a network only from the network" + " offering having traffic type " + TrafficType.Guest
+ + " and network type " + Network.GuestType.Isolated + " with a service " + Service.SourceNat.getName() + " enabled");
}
// Don't allow to specify vlan if the caller is not ROOT admin
@@ -1212,30 +1201,29 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
}
if (ipv4) {
- // For non-root admins check cidr limit - if it's allowed by global config value
- if (caller.getType() != Account.ACCOUNT_TYPE_ADMIN && cidr != null) {
+ // For non-root admins check cidr limit - if it's allowed by global config value
+ if (caller.getType() != Account.ACCOUNT_TYPE_ADMIN && cidr != null) {
- String[] cidrPair = cidr.split("\\/");
- int cidrSize = Integer.valueOf(cidrPair[1]);
+ String[] cidrPair = cidr.split("\\/");
+ int cidrSize = Integer.valueOf(cidrPair[1]);
- if (cidrSize < _cidrLimit) {
- throw new InvalidParameterValueException("Cidr size can't be less than " + _cidrLimit);
- }
- }
+ if (cidrSize < _cidrLimit) {
+ throw new InvalidParameterValueException("Cidr size can't be less than " + _cidrLimit);
+ }
+ }
}
Collection<String> ntwkProviders = _networkMgr.finalizeServicesAndProvidersForNetwork(ntwkOff, physicalNetworkId).values();
if (ipv6 && providersConfiguredForExternalNetworking(ntwkProviders)) {
- throw new InvalidParameterValueException("Cannot support IPv6 on network offering with external devices!");
+ throw new InvalidParameterValueException("Cannot support IPv6 on network offering with external devices!");
}
if (isolatedPvlan != null && providersConfiguredForExternalNetworking(ntwkProviders)) {
- throw new InvalidParameterValueException("Cannot support private vlan on network offering with external devices!");
+ throw new InvalidParameterValueException("Cannot support private vlan on network offering with external devices!");
}
if (cidr != null && providersConfiguredForExternalNetworking(ntwkProviders)) {
- if (ntwkOff.getGuestType() == GuestType.Shared && (zone.getNetworkType() == NetworkType.Advanced) &&
- isSharedNetworkOfferingWithServices(networkOfferingId)) {
+ if (ntwkOff.getGuestType() == GuestType.Shared && (zone.getNetworkType() == NetworkType.Advanced) && isSharedNetworkOfferingWithServices(networkOfferingId)) {
// validate if CIDR specified overlaps with any of the CIDR's allocated for isolated networks and shared networks in the zone
checkSharedNetworkCidrOverlap(zoneId, pNtwk.getId(), cidr);
} else {
@@ -1249,14 +1237,13 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
// Vlan is created in 1 cases - works in Advance zone only:
// 1) GuestType is Shared
- boolean createVlan = (startIP != null && endIP != null && zone.getNetworkType() == NetworkType.Advanced
- && (ntwkOff.getGuestType() == Network.GuestType.Shared));
+ boolean createVlan = (startIP != null && endIP != null && zone.getNetworkType() == NetworkType.Advanced && (ntwkOff.getGuestType() == Network.GuestType.Shared));
if (!createVlan) {
- // Only support advance shared network in IPv6, which means createVlan is a must
- if (ipv6) {
- createVlan = true;
- }
+ // Only support advance shared network in IPv6, which means createVlan is a must
+ if (ipv6) {
+ createVlan = true;
+ }
}
// Can add vlan range only to the network which allows it
@@ -1266,15 +1253,14 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
throw ex;
}
- Network network = commitNetwork(networkOfferingId, gateway, startIP, endIP, netmask, networkDomain, vlanId,
- name, displayText, caller, physicalNetworkId, zoneId, domainId, isDomainSpecific, subdomainAccess,
- vpcId, startIPv6, endIPv6, ip6Gateway, ip6Cidr, displayNetwork, aclId, isolatedPvlan, ntwkOff, pNtwk,
- aclType, owner, cidr, createVlan);
+ Network network = commitNetwork(networkOfferingId, gateway, startIP, endIP, netmask, networkDomain, vlanId, name, displayText, caller, physicalNetworkId, zoneId, domainId,
+ isDomainSpecific, subdomainAccess, vpcId, startIPv6, endIPv6, ip6Gateway, ip6Cidr, displayNetwork, aclId, isolatedPvlan, ntwkOff, pNtwk, aclType, owner, cidr,
+ createVlan);
// if the network offering has persistent set to true, implement the network
- if ( ntwkOff.getIsPersistent() ) {
+ if (ntwkOff.getIsPersistent()) {
try {
- if ( network.getState() == Network.State.Setup ) {
+ if (network.getState() == Network.State.Setup) {
s_logger.debug("Network id=" + network.getId() + " is already provisioned");
return network;
}
@@ -1298,20 +1284,18 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
return network;
}
- private Network commitNetwork(final Long networkOfferingId, final String gateway, final String startIP, final String endIP, final String netmask,
- final String networkDomain, final String vlanId, final String name, final String displayText, final Account caller,
- final Long physicalNetworkId, final Long zoneId, final Long domainId, final boolean isDomainSpecific, final Boolean subdomainAccessFinal,
- final Long vpcId, final String startIPv6, final String endIPv6, final String ip6Gateway, final String ip6Cidr, final Boolean displayNetwork,
- final Long aclId, final String isolatedPvlan, final NetworkOfferingVO ntwkOff, final PhysicalNetwork pNtwk, final ACLType aclType,
- final Account ownerFinal, final String cidr, final boolean createVlan) throws InsufficientCapacityException,
- ResourceAllocationException {
+ private Network commitNetwork(final Long networkOfferingId, final String gateway, final String startIP, final String endIP, final String netmask, final String networkDomain,
+ final String vlanId, final String name, final String displayText, final Account caller, final Long physicalNetworkId, final Long zoneId, final Long domainId,
+ final boolean isDomainSpecific, final Boolean subdomainAccessFinal, final Long vpcId, final String startIPv6, final String endIPv6, final String ip6Gateway,
+ final String ip6Cidr, final Boolean displayNetwork, final Long aclId, final String isolatedPvlan, final NetworkOfferingVO ntwkOff, final PhysicalNetwork pNtwk,
+ final ACLType aclType, final Account ownerFinal, final String cidr, final boolean createVlan) throws InsufficientCapacityException, ResourceAllocationException {
try {
- return Transaction.execute(new TransactionCallbackWithException<Network,Exception>() {
+ return Transaction.execute(new TransactionCallbackWithException<Network, Exception>() {
@Override
public Network doInTransaction(TransactionStatus status) throws InsufficientCapacityException, ResourceAllocationException {
Account owner = ownerFinal;
Boolean subdomainAccess = subdomainAccessFinal;
-
+
Long sharedDomainId = null;
if (isDomainSpecific) {
if (domainId != null) {
@@ -1321,52 +1305,51 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
subdomainAccess = true;
}
}
-
+
// default owner to system if network has aclType=Domain
if (aclType == ACLType.Domain) {
owner = _accountMgr.getAccount(Account.ACCOUNT_ID_SYSTEM);
}
-
+
//Create guest network
Network network = null;
if (vpcId != null) {
- if (!_configMgr.isOfferingForVpc(ntwkOff)){
+ if (!_configMgr.isOfferingForVpc(ntwkOff)) {
throw new InvalidParameterValueException("Network offering can't be used for VPC networks");
}
-
- if(aclId != null){
+
+ if (aclId != null) {
NetworkACL acl = _networkACLDao.findById(aclId);
- if(acl == null){
+ if (acl == null) {
throw new InvalidParameterValueException("Unable to find specified NetworkACL");
}
-
- if(aclId != NetworkACL.DEFAULT_DENY && aclId != NetworkACL.DEFAULT_ALLOW) {
+
+ if (aclId != NetworkACL.DEFAULT_DENY && aclId != NetworkACL.DEFAULT_ALLOW) {
//ACL is not default DENY/ALLOW
// ACL should be associated with a VPC
- if(!vpcId.equals(acl.getVpcId())){
- throw new InvalidParameterValueException("ACL: "+aclId+" do not belong to the VPC");
+ if (!vpcId.equals(acl.getVpcId())) {
+ throw new InvalidParameterValueException("ACL: " + aclId + " do not belong to the VPC");
}
}
}
- network = _vpcMgr.createVpcGuestNetwork(networkOfferingId, name, displayText, gateway, cidr, vlanId,
- networkDomain, owner, sharedDomainId, pNtwk, zoneId, aclType, subdomainAccess, vpcId, aclId, caller, displayNetwork);
+ network = _vpcMgr.createVpcGuestNetwork(networkOfferingId, name, displayText, gateway, cidr, vlanId, networkDomain, owner, sharedDomainId, pNtwk, zoneId,
+ aclType, subdomainAccess, vpcId, aclId, caller, displayNetwork);
} else {
- if (_configMgr.isOfferingForVpc(ntwkOff)){
+ if (_configMgr.isOfferingForVpc(ntwkOff)) {
throw new InvalidParameterValueException("Network offering can be used for VPC networks only");
}
if (ntwkOff.getInternalLb()) {
throw new InvalidParameterValueException("Internal Lb can be enabled on vpc networks only");
}
-
- network = _networkMgr.createGuestNetwork(networkOfferingId, name, displayText, gateway, cidr, vlanId,
- networkDomain, owner, sharedDomainId, pNtwk, zoneId, aclType, subdomainAccess, vpcId,
- ip6Gateway, ip6Cidr, displayNetwork, isolatedPvlan);
+
+ network = _networkMgr.createGuestNetwork(networkOfferingId, name, displayText, gateway, cidr, vlanId, networkDomain, owner, sharedDomainId, pNtwk, zoneId,
+ aclType, subdomainAccess, vpcId, ip6Gateway, ip6Cidr, displayNetwork, isolatedPvlan);
}
-
+
if (caller.getType() == Account.ACCOUNT_TYPE_ADMIN && createVlan) {
// Create vlan ip range
- _configMgr.createVlanAndPublicIpRange(pNtwk.getDataCenterId(), network.getId(), physicalNetworkId,
- false, null, startIP, endIP, gateway, netmask, vlanId, null, startIPv6, endIPv6, ip6Gateway, ip6Cidr);
+ _configMgr.createVlanAndPublicIpRange(pNtwk.getDataCenterId(), network.getId(), physicalNetworkId, false, null, startIP, endIP, gateway, netmask, vlanId,
+ null, startIPv6, endIPv6, ip6Gateway, ip6Cidr);
}
return network;
}
@@ -1380,7 +1363,7 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
}
@Override
- public List<? extends Network> searchForNetworks(ListNetworksCmd cmd) {
+ public Pair<List<? extends Network>, Integer> searchForNetworks(ListNetworksCmd cmd) {
Long id = cmd.getId();
String keyword = cmd.getKeyword();
Long zoneId = cmd.getZoneId();
@@ -1460,7 +1443,7 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
ex.addProxyObject(project.getUuid(), "projectId");
throw ex;
}
-
+
//add project account
permittedAccounts.add(project.getProjectAccountId());
//add caller account (if admin)
@@ -1474,7 +1457,7 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
if (domainId != null) {
path = _domainDao.findById(domainId).getPath();
} else {
- path = _domainDao.findById(caller.getDomainId()).getPath();
+ path = _domainDao.findById(caller.getDomainId()).getPath();
}
if (listAll && domainId == null) {
@@ -1507,7 +1490,7 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
if (tags != null && !tags.isEmpty()) {
SearchBuilder<ResourceTagVO> tagSearch = _resourceTagDao.createSearchBuilder();
- for (int count=0; count < tags.size(); count++) {
+ for (int count = 0; count < tags.size(); count++) {
tagSearch.or().op("key" + String.valueOf(count), tagSearch.entity().getKey(), SearchCriteria.Op.EQ);
tagSearch.and("value" + String.valueOf(count), tagSearch.entity().getValue(), SearchCriteria.Op.EQ);
tagSearch.cp();
@@ -1523,13 +1506,11 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
sb.join("domainSearch", domainSearch, sb.entity().getDomainId(), domainSearch.entity().getId(), JoinBuilder.JoinType.INNER);
}
-
- SearchBuilder<AccountVO> accountSearch = _accountDao.createSearchBuilder();
+ SearchBuilder<AccountVO> accountSearch = _accountDao.createSearchBuilder();
accountSearch.and("typeNEQ", accountSearch.entity().getType(), SearchCriteria.Op.NEQ);
accountSearch.and("typeEQ", accountSearch.entity().getType(), SearchCriteria.Op.EQ);
-
- sb.join("accountSearch", accountSearch, sb.entity().getAccountId(), accountSearch.entity().getId(), JoinBuilder.JoinType.INNER);
+ sb.join("accountSearch", accountSearch, sb.entity().getAccountId(), accountSearch.entity().getId(), JoinBuilder.JoinType.INNER);
List<NetworkVO> networksToReturn = new ArrayList<NetworkVO>();
@@ -1537,41 +1518,34 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
if (!permittedAccounts.isEmpty()) {
//get account level networks
networksToReturn.addAll(listAccountSpecificNetworks(
- buildNetworkSearchCriteria(sb, keyword, id, isSystem, zoneId, guestIpType, trafficType,
- physicalNetworkId, aclType, skipProjectNetworks, restartRequired, specifyIpRanges, vpcId, tags), searchFilter,
- permittedAccounts));
+ buildNetworkSearchCriteria(sb, keyword, id, isSystem, zoneId, guestIpType, trafficType, physicalNetworkId, aclType, skipProjectNetworks, restartRequired,
+ specifyIpRanges, vpcId, tags), searchFilter, permittedAccounts));
//get domain level networks
if (domainId != null) {
- networksToReturn
- .addAll(listDomainLevelNetworks(
- buildNetworkSearchCriteria(sb, keyword, id, isSystem, zoneId, guestIpType, trafficType,
- physicalNetworkId, aclType, true, restartRequired, specifyIpRanges, vpcId, tags), searchFilter,
- domainId, false));
+ networksToReturn.addAll(listDomainLevelNetworks(
+ buildNetworkSearchCriteria(sb, keyword, id, isSystem, zoneId, guestIpType, trafficType, physicalNetworkId, aclType, true, restartRequired,
+ specifyIpRanges, vpcId, tags), searchFilter, domainId, false));
}
} else {
//add account specific networks
networksToReturn.addAll(listAccountSpecificNetworksByDomainPath(
- buildNetworkSearchCriteria(sb, keyword, id, isSystem, zoneId, guestIpType, trafficType,
- physicalNetworkId, aclType, skipProjectNetworks, restartRequired, specifyIpRanges, vpcId, tags), searchFilter, path,
- isRecursive));
+ buildNetworkSearchCriteria(sb, keyword, id, isSystem, zoneId, guestIpType, trafficType, physicalNetworkId, aclType, skipProjectNetworks, restartRequired,
+ specifyIpRanges, vpcId, tags), searchFilter, path, isRecursive));
//add domain specific networks of domain + parent domains
networksToReturn.addAll(listDomainSpecificNetworksByDomainPath(
- buildNetworkSearchCriteria(sb, keyword, id, isSystem, zoneId, guestIpType, trafficType,
- physicalNetworkId, aclType, skipProjectNetworks, restartRequired, specifyIpRanges, vpcId, tags), searchFilter, path,
- isRecursive));
+ buildNetworkSearchCriteria(sb, keyword, id, isSystem, zoneId, guestIpType, trafficType, physicalNetworkId, aclType, skipProjectNetworks, restartRequired,
+ specifyIpRanges, vpcId, tags), searchFilter, path, isRecursive));
//add networks of subdomains
if (domainId == null) {
- networksToReturn
- .addAll(listDomainLevelNetworks(
- buildNetworkSearchCriteria(sb, keyword, id, isSystem, zoneId, guestIpType, trafficType,
- physicalNetworkId, aclType, true, restartRequired, specifyIpRanges, vpcId, tags), searchFilter,
- caller.getDomainId(), true));
+ networksToReturn.addAll(listDomainLevelNetworks(
+ buildNetworkSearchCriteria(sb, keyword, id, isSystem, zoneId, guestIpType, trafficType, physicalNetworkId, aclType, true, restartRequired,
+ specifyIpRanges, vpcId, tags), searchFilter, caller.getDomainId(), true));
}
}
} else {
- networksToReturn = _networksDao.search(buildNetworkSearchCriteria(sb, keyword, id, isSystem, zoneId,
- guestIpType, trafficType, physicalNetworkId, null, skipProjectNetworks, restartRequired, specifyIpRanges, vpcId, tags),
- searchFilter);
+ networksToReturn = _networksDao.search(
+ buildNetworkSearchCriteria(sb, keyword, id, isSystem, zoneId, guestIpType, trafficType, physicalNetworkId, null, skipProjectNetworks, restartRequired,
+ specifyIpRanges, vpcId, tags), searchFilter);
}
if (supportedServicesStr != null && !supportedServicesStr.isEmpty() && !networksToReturn.isEmpty()) {
@@ -1594,7 +1568,7 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
}
}
- networksToReturn=supportedNetworks;
+ networksToReturn = supportedNetworks;
}
if (canUseForDeploy != null) {
@@ -1605,43 +1579,40 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
}
}
- networksToReturn=networksForDeploy;
+ networksToReturn = networksForDeploy;
}
//Now apply pagination
//Most likely pageSize will never exceed int value, and we need integer to partition the listToReturn
boolean notNull = cmd.getStartIndex() != null && cmd.getPageSizeVal() != null;
- if (notNull && cmd.getStartIndex() <= Integer.MAX_VALUE && cmd.getStartIndex() >= Integer.MIN_VALUE &&
- cmd.getPageSizeVal() <= Integer.MAX_VALUE && cmd.getPageSizeVal() >= Integer.MIN_VALUE) {
- int startIndex = cmd.getStartIndex().intValue() == 0 ? 0 : cmd.getStartIndex().intValue() - 1;
+ if (notNull && cmd.getStartIndex() <= Integer.MAX_VALUE && cmd.getStartIndex() >= Integer.MIN_VALUE && cmd.getPageSizeVal() <= Integer.MAX_VALUE
+ && cmd.getPageSizeVal() >= Integer.MIN_VALUE) {
+ int startIndex = cmd.getStartIndex().intValue() == 0 ? 0 : cmd.getStartIndex().intValue() / cmd.getPageSizeVal().intValue();
List<NetworkVO> wPagination = new ArrayList<NetworkVO>();
List<List<NetworkVO>> partitions = partitionNetworks(networksToReturn, cmd.getPageSizeVal().intValue());
- if (startIndex< partitions.size()) {
+ if (startIndex < partitions.size()) {
wPagination = partitions.get(startIndex);
}
- return wPagination;
+ return new Pair<List<? extends Network>, Integer>(wPagination, networksToReturn.size());
}
- return networksToReturn;
+ return new Pair<List<? extends Network>, Integer>(networksToReturn, networksToReturn.size());
}
- private static List<List<NetworkVO>> partitionNetworks(List<NetworkVO> originalList,
- int chunkSize) {
+ private static List<List<NetworkVO>> partitionNetworks(List<NetworkVO> originalList, int chunkSize) {
List<List<NetworkVO>> listOfChunks = new ArrayList<List<NetworkVO>>();
for (int i = 0; i < originalList.size() / chunkSize; i++) {
- listOfChunks.add(originalList.subList(i * chunkSize, i * chunkSize
- + chunkSize));
+ listOfChunks.add(originalList.subList(i * chunkSize, i * chunkSize + chunkSize));
}
if (originalList.size() % chunkSize != 0) {
- listOfChunks.add(originalList.subList(originalList.size()
- - originalList.size() % chunkSize, originalList.size()));
+ listOfChunks.add(originalList.subList(originalList.size() - originalList.size() % chunkSize, originalList.size()));
}
return listOfChunks;
}
private SearchCriteria<NetworkVO> buildNetworkSearchCriteria(SearchBuilder<NetworkVO> sb, String keyword, Long id, Boolean isSystem, Long zoneId, String guestIpType,
- String trafficType, Long physicalNetworkId, String aclType, boolean skipProjectNetworks, Boolean restartRequired, Boolean specifyIpRanges, Long vpcId,
- Map<String, String> tags) {
+ String trafficType, Long physicalNetworkId, String aclType, boolean skipProjectNetworks, Boolean restartRequired, Boolean specifyIpRanges, Long vpcId,
+ Map<String, String> tags) {
SearchCriteria<NetworkVO> sc = sb.create();
@@ -1765,8 +1736,7 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
return _networksDao.search(sc, searchFilter);
}
- private List<NetworkVO> listDomainSpecificNetworksByDomainPath(SearchCriteria<NetworkVO> sc, Filter searchFilter,
- String path, boolean isRecursive) {
+ private List<NetworkVO> listDomainSpecificNetworksByDomainPath(SearchCriteria<NetworkVO> sc, Filter searchFilter, String path, boolean isRecursive) {
Set<Long> allowedDomains = new HashSet<Long>();
if (path != null) {
@@ -1792,7 +1762,7 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
domainSC.addAnd("aclType", SearchCriteria.Op.EQ, ACLType.Domain.toString());
sc.addAnd("id", SearchCriteria.Op.SC, domainSC);
- return _networksDao.search(sc, searchFilter);
+ return _networksDao.search(sc, searchFilter);
} else {
return new ArrayList<NetworkVO>();
}
@@ -1832,7 +1802,6 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
return _networkMgr.destroyNetwork(networkId, context);
}
-
@Override
@ActionEvent(eventType = EventTypes.EVENT_NETWORK_RESTART, eventDescription = "restarting network", async = true)
public boolean restartNetwork(RestartNetworkCmd cmd, boolean cleanup) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException {
@@ -1852,16 +1821,17 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
// Don't allow to restart network if it's not in Implemented/Setup state
if (!(network.getState() == Network.State.Implemented || network.getState() == Network.State.Setup)) {
- throw new InvalidParameterValueException("Network is not in the right state to be restarted. Correct states are: " + Network.State.Implemented + ", " + Network.State.Setup);
+ throw new InvalidParameterValueException("Network is not in the right state to be restarted. Correct states are: " + Network.State.Implemented + ", "
+ + Network.State.Setup);
}
- if (network.getBroadcastDomainType() == BroadcastDomainType.Lswitch ) {
- /**
- * Unable to restart these networks now.
- * TODO Restarting a SDN based network requires updating the nics and the configuration
- * in the controller. This requires a non-trivial rewrite of the restart procedure.
- */
- throw new InvalidParameterException("Unable to restart a running SDN network.");
+ if (network.getBroadcastDomainType() == BroadcastDomainType.Lswitch) {
+ /**
+ * Unable to restart these networks now.
+ * TODO Restarting a SDN based network requires updating the nics and the configuration
+ * in the controller. This requires a non-trivial rewrite of the restart procedure.
+ */
+ throw new InvalidParameterException("Unable to restart a running SDN network.");
}
_accountMgr.checkAccess(callerAccount, null, true, network);
@@ -1882,7 +1852,6 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
return _networksDao.getActiveNicsIn(networkId);
}
-
@Override
public Map<Capability, String> getNetworkOfferingServiceCapabilities(NetworkOffering offering, Service service) {
@@ -1913,7 +1882,8 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
if (elementCapabilities == null || !elementCapabilities.containsKey(service)) {
// TBD: We should be sending providerId and not the offering object itself.
- throw new UnsupportedServiceException("Service " + service.getName() + " is not supported by the element=" + element.getName() + " implementing Provider=" + provider);
+ throw new UnsupportedServiceException("Service " + service.getName() + " is not supported by the element=" + element.getName() + " implementing Provider="
+ + provider);
}
serviceCapabilities = elementCapabilities.get(service);
}
@@ -1921,17 +1891,15 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
return serviceCapabilities;
}
-
@Override
public IpAddress getIp(long ipAddressId) {
return _ipAddressDao.findById(ipAddressId);
}
-
protected boolean providersConfiguredForExternalNetworking(Collection<String> providers) {
- for(String providerStr : providers){
+ for (String providerStr : providers) {
Provider provider = Network.Provider.getProvider(providerStr);
- if(provider.isExternal()){
+ if (provider.isExternal()) {
return true;
}
}
@@ -1940,44 +1908,34 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
protected boolean isSharedNetworkOfferingWithServices(long networkOfferingId) {
NetworkOfferingVO networkOffering = _networkOfferingDao.findById(networkOfferingId);
- if ( (networkOffering.getGuestType() == Network.GuestType.Shared) && (
- areServicesSupportedByNetworkOffering(networkOfferingId, Service.SourceNat) ||
- areServicesSupportedByNetworkOffering(networkOfferingId, Service.StaticNat) ||
- areServicesSupportedByNetworkOffering(networkOfferingId, Service.Firewall) ||
- areServicesSupportedByNetworkOffering(networkOfferingId, Service.PortForwarding) ||
- areServicesSupportedByNetworkOffering(networkOfferingId, Service.Lb))) {
+ if ((networkOffering.getGuestType() == Network.GuestType.Shared)
+ && (areServicesSupportedByNetworkOffering(networkOfferingId, Service.SourceNat) || areServicesSupportedByNetworkOffering(networkOfferingId, Service.StaticNat)
+ || areServicesSupportedByNetworkOffering(networkOfferingId, Service.Firewall)
+ || areServicesSupportedByNetworkOffering(networkOfferingId, Service.PortForwarding) || areServicesSupportedByNetworkOffering(networkOfferingId, Service.Lb))) {
return true;
}
return false;
}
-
protected boolean areServicesSupportedByNetworkOffering(long networkOfferingId, Service... services) {
return (_ntwkOfferingSrvcDao.areServicesSupportedByNetworkOffering(networkOfferingId, services));
}
-
protected boolean areServicesSupportedInNetwork(long networkId, Service... services) {
return (_ntwkSrvcDao.areServicesSupportedInNetwork(networkId, services));
}
-
-
-
-
-
-
private boolean checkForNonStoppedVmInNetwork(long networkId) {
- List<UserVmVO> vms = _userVmDao.listByNetworkIdAndStates(networkId, VirtualMachine.State.Starting,
- VirtualMachine.State.Running, VirtualMachine.State.Migrating, VirtualMachine.State.Stopping);
+ List<UserVmVO> vms = _userVmDao.listByNetworkIdAndStates(networkId, VirtualMachine.State.Starting, VirtualMachine.State.Running, VirtualMachine.State.Migrating,
+ VirtualMachine.State.Stopping);
return vms.isEmpty();
}
@Override
@DB
@ActionEvent(eventType = EventTypes.EVENT_NETWORK_UPDATE, eventDescription = "updating network", async = true)
- public Network updateGuestNetwork(final long networkId, String name, String displayText, Account callerAccount,
- User callerUser, String domainSuffix, final Long networkOfferingId, Boolean changeCidr, String guestVmCidr, Boolean displayNetwork) {
+ public Network updateGuestNetwork(final long networkId, String name, String displayText, Account callerAccount, User callerUser, String domainSuffix,
+ final Long networkOfferingId, Boolean changeCidr, String guestVmCidr, Boolean displayNetwork) {
boolean restartNetwork = false;
@@ -2022,8 +1980,8 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
network.setDisplayText(displayText);
}
- if(displayNetwork != null){
- if(!_accountMgr.isRootAdmin(callerAccount.getType())){
+ if (displayNetwork != null) {
+ if (!_accountMgr.isRootAdmin(callerAccount.getType())) {
throw new PermissionDeniedException("Only admin allowed to update displaynetwork parameter");
}
network.setDisplayNetwork(displayNetwork);
@@ -2048,7 +2006,8 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
// network offering should be in Enabled state
if (networkOffering.getState() != NetworkOffering.State.Enabled) {
- InvalidParameterValueException ex = new InvalidParameterValueException("Network offering with specified id is not in " + NetworkOffering.State.Enabled + " state, can't upgrade to it");
+ InvalidParameterValueException ex = new InvalidParameterValueException("Network offering with specified id is not in " + NetworkOffering.State.Enabled
+ + " state, can't upgrade to it");
ex.addProxyObject(networkOffering.getUuid(), "networkOfferingId");
throw ex;
}
@@ -2064,8 +2023,7 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
Collection<String> newProviders = _networkMgr.finalizeServicesAndProvidersForNetwork(networkOffering, network.getPhysicalNetworkId()).values();
Collection<String> oldProviders = _networkMgr.finalizeServicesAndProvidersForNetwork(oldNtwkOff, network.getPhysicalNetworkId()).values();
- if (providersConfiguredForExternalNetworking(newProviders) != providersConfiguredForExternalNetworking(oldProviders)
- && !changeCidr) {
+ if (providersConfiguredForExternalNetworking(newProviders) != providersConfiguredForExternalNetworking(oldProviders) && !changeCidr) {
throw new InvalidParameterValueException("Updating network failed since guest CIDR needs to be changed!");
}
if (changeCidr) {
@@ -2077,16 +2035,16 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
}
// check if the network is upgradable
if (!canUpgrade(network, oldNetworkOfferingId, networkOfferingId)) {
- throw new InvalidParameterValueException("Can't upgrade from network offering " + oldNtwkOff.getUuid() +
- " to " + networkOffering.getUuid() + "; check logs for more information");
+ throw new InvalidParameterValueException("Can't upgrade from network offering " + oldNtwkOff.getUuid() + " to " + networkOffering.getUuid()
+ + "; check logs for more information");
}
restartNetwork = true;
networkOfferingChanged = true;
}
}
- final Map<String, String> newSvcProviders = networkOfferingChanged ? _networkMgr.finalizeServicesAndProvidersForNetwork(_entityMgr.findById(NetworkOffering.class, networkOfferingId), network.getPhysicalNetworkId())
- : new HashMap<String, String>();
+ final Map<String, String> newSvcProviders = networkOfferingChanged ? _networkMgr.finalizeServicesAndProvidersForNetwork(
+ _entityMgr.findById(NetworkOffering.class, networkOfferingId), network.getPhysicalNetworkId()) : new HashMap<String, String>();
// don't allow to modify network domain if the service is not supported
if (domainSuffix != null) {
@@ -2119,9 +2077,9 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
DataCenter dc = _dcDao.findById(network.getDataCenterId());
String networkCidr = network.getNetworkCidr();
- if (guestVmCidr!= null ) {
- if(dc.getNetworkType() == NetworkType.Basic) {
- throw new InvalidParameterValueException("Guest VM CIDR can't be specified for zone with " + NetworkType.Basic + " networking");
+ if (guestVmCidr != null) {
+ if (dc.getNetworkType() == NetworkType.Basic) {
+ throw new InvalidParameterValueException("Guest VM CIDR can't be specified for zone with " + NetworkType.Basic + " networking");
}
if (network.getGuestType() != GuestType.Isolated) {
throw new InvalidParameterValueException("Can only allow IP Reservation in networks with guest type " + GuestType.Isolated);
@@ -2130,82 +2088,86 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
throw new InvalidParameterValueException("Cannot specify this nework offering change and guestVmCidr at same time. Specify only one.");
}
if (!(network.getState() == Network.State.Implemented)) {
- throw new InvalidParameterValueException ("The network must be in " + Network.State.Implemented + " state. IP Reservation cannot be applied in " + network.getState() + " state");
+ throw new InvalidParameterValueException("The network must be in " + Network.State.Implemented + " state. IP Reservation cannot be applied in "
+ + network.getState() + " state");
}
if (!NetUtils.isValidCIDR(guestVmCidr)) {
- throw new InvalidParameterValueException ("Invalid format of Guest VM CIDR.");
+ throw new InvalidParameterValueException("Invalid format of Guest VM CIDR.");
}
if (!NetUtils.validateGuestCidr(guestVmCidr)) {
- throw new InvalidParameterValueException ("Invalid format of Guest VM CIDR. Make sure it is RFC1918 compliant. ");
+ throw new InvalidParameterValueException("Invalid format of Guest VM CIDR. Make sure it is RFC1918 compliant. ");
}
// If networkCidr is null it implies that there was no prior IP reservation, so the network cidr is network.getCidr()
// But in case networkCidr is a non null value (IP reservation already exists), it implies network cidr is networkCidr
if (networkCidr != null) {
- if(! NetUtils.isNetworkAWithinNetworkB(guestVmCidr, networkCidr)) {
- throw new InvalidParameterValueException ("Invalid value of Guest VM CIDR. For IP Reservation, Guest VM CIDR should be a subset of network CIDR : " + networkCidr);
+ if (!NetUtils.isNetworkAWithinNetworkB(guestVmCidr, networkCidr)) {
+ throw new InvalidParameterValueException("Invalid value of Guest VM CIDR. For IP Reservation, Guest VM CIDR should be a subset of network CIDR : "
+ + networkCidr);
}
} else {
- if (! NetUtils.isNetworkAWithinNetworkB(guestVmCidr, network.getCidr())) {
- throw new InvalidParameterValueException ("Invalid value of Guest VM CIDR. For IP Reservation, Guest VM CIDR should be a subset of network CIDR : " + network.getCidr());
+ if (!NetUtils.isNetworkAWithinNetworkB(guestVmCidr, network.getCidr())) {
+ throw new InvalidParameterValueException("Invalid value of Guest VM CIDR. For IP Reservation, Guest VM CIDR should be a subset of network CIDR : "
+ + network.getCidr());
}
}
// This check makes sure there are no active IPs existing outside the guestVmCidr in the network
- String[] guestVmCidrPair = guestVmCidr.split("\\/");
- Long size = Long.valueOf(guestVmCidrPair[1]);
- List<NicVO> nicsPresent = _nicDao.listByNetworkId(networkId);
-
- String cidrIpRange[] = NetUtils.getIpRangeFromCidr(guestVmCidrPair[0], size);
- s_logger.info("The start IP of the specified guest vm cidr is: " + cidrIpRange[0] +" and end IP is: " + cidrIpRange[1]);
- long startIp = NetUtils.ip2Long(cidrIpRange[0]);
- long endIp = NetUtils.ip2Long(cidrIpRange[1]);
- long range = endIp - startIp + 1;
- s_logger.info("The specified guest vm cidr has " + range + " IPs");
-
- for (NicVO nic : nicsPresent) {
- long nicIp = NetUtils.ip2Long(nic.getIp4Address());
- //check if nic IP is outside the guest vm cidr
- if (nicIp < startIp || nicIp > endIp) {
- if(!(nic.getState() == Nic.State.Deallocating)) {
- throw new InvalidParameterValueException("Active IPs like " + nic.getIp4Address() + " exist outside the Guest VM CIDR. Cannot apply reservation ");
- }
- }
- }
-
- // In some scenarios even though guesVmCidr and network CIDR do not appear similar but
- // the IP ranges exactly matches, in these special cases make sure no Reservation gets applied
- if (network.getNetworkCidr() == null) {
- if (NetUtils.isSameIpRange(guestVmCidr, network.getCidr()) && !guestVmCidr.equals(network.getCidr())) {
- throw new InvalidParameterValueException("The Start IP and End IP of guestvmcidr: "+ guestVmCidr + " and CIDR: " + network.getCidr() + " are same, " +
- "even though both the cidrs appear to be different. As a precaution no IP Reservation will be applied.");
- }
- } else {
- if(NetUtils.isSameIpRange(guestVmCidr, network.getNetworkCidr()) && !guestVmCidr.equals(network.getNetworkCidr())) {
- throw new InvalidParameterValueException("The Start IP and End IP of guestvmcidr: "+ guestVmCidr + " and Network CIDR: " + network.getNetworkCidr() + " are same, " +
- "even though both the cidrs appear to be different. As a precaution IP Reservation will not be affected. If you want to reset IP Reservation, " +
- "specify guestVmCidr to be: " + network.getNetworkCidr());
+ String[] guestVmCidrPair = guestVmCidr.split("\\/");
+ Long size = Long.valueOf(guestVmCidrPair[1]);
+ List<NicVO> nicsPresent = _nicDao.listByNetworkId(networkId);
+
+ String cidrIpRange[] = NetUtils.getIpRangeFromCidr(guestVmCidrPair[0], size);
+ s_logger.info("The start IP of the specified guest vm cidr is: " + cidrIpRange[0] + " and end IP is: " + cidrIpRange[1]);
+ long startIp = NetUtils.ip2Long(cidrIpRange[0]);
+ long endIp = NetUtils.ip2Long(cidrIpRange[1]);
+ long range = endIp - startIp + 1;
+ s_logger.info("The specified guest vm cidr has " + range + " IPs");
+
+ for (NicVO nic : nicsPresent) {
+ long nicIp = NetUtils.ip2Long(nic.getIp4Address());
+ //check if nic IP is outside the guest vm cidr
+ if (nicIp < startIp || nicIp > endIp) {
+ if (!(nic.getState() == Nic.State.Deallocating)) {
+ throw new InvalidParameterValueException("Active IPs like " + nic.getIp4Address() + " exist outside the Guest VM CIDR. Cannot apply reservation ");
}
}
+ }
- // When reservation is applied for the first time, network_cidr will be null
- // Populate it with the actual network cidr
- if (network.getNetworkCidr() == null) {
- network.setNetworkCidr(network.getCidr());
+ // In some scenarios even though guesVmCidr and network CIDR do not appear similar but
+ // the IP ranges exactly matches, in these special cases make sure no Reservation gets applied
+ if (network.getNetworkCidr() == null) {
+ if (NetUtils.isSameIpRange(guestVmCidr, network.getCidr()) && !guestVmCidr.equals(network.getCidr())) {
+ throw new InvalidParameterValueException("The Start IP and End IP of guestvmcidr: " + guestVmCidr + " and CIDR: " + network.getCidr() + " are same, "
+ + "even though both the cidrs appear to be different. As a precaution no IP Reservation will be applied.");
}
-
- // Condition for IP Reservation reset : guestVmCidr and network CIDR are same
- if (network.getNetworkCidr().equals(guestVmCidr)) {
- s_logger.warn("Guest VM CIDR and Network CIDR both are same, reservation will reset.");
- network.setNetworkCidr(null);
+ } else {
+ if (NetUtils.isSameIpRange(guestVmCidr, network.getNetworkCidr()) && !guestVmCidr.equals(network.getNetworkCidr())) {
+ throw new InvalidParameterValueException("The Start IP and End IP of guestvmcidr: " + guestVmCidr + " and Network CIDR: " + network.getNetworkCidr()
+ + " are same, "
+ + "even though both the cidrs appear to be different. As a precaution IP Reservation will not be affected. If you want to reset IP Reservation, "
+ + "specify guestVmCidr to be: " + network.getNetworkCidr());
}
- // Finally update "cidr" with the guestVmCidr
- // which becomes the effective address space for CloudStack guest VMs
- network.setCidr(guestVmCidr);
- _networksDao.update(networkId, network);
- s_logger.info("IP Reservation has been applied. The new CIDR for Guests Vms is " + guestVmCidr);
}
+ // When reservation is applied for the first time, network_cidr will be null
+ // Populate it with the actual network cidr
+ if (network.getNetworkCidr() == null) {
+ network.setNetworkCidr(network.getCidr());
+ }
+
+ // Condition for IP Reservation reset : guestVmCidr and network CIDR are same
+ if (network.getNetworkCidr().equals(guestVmCidr)) {
+ s_logger.warn("Guest VM CIDR and Network CIDR both are same, reservation will reset.");
+ network.setNetworkCidr(null);
+ }
+ // Finally update "cidr" with the guestVmCidr
+ // which becomes the effective address space for CloudStack guest VMs
+ network.setCidr(guestVmCidr);
+ _networksDao.update(networkId, network);
+ s_logger.info("IP Reservation has been applied. The new CIDR for Guests Vms is " + guestVmCidr);
+ }
+
ReservationContext context = new ReservationContextImpl(null, null, callerUser, callerAccount);
// 1) Shutdown all the elements and cleanup all the rules. Don't allow to shutdown network in intermediate
// states - Shutdown and Implementing
@@ -2226,8 +2188,9 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
s_logger.debug("Shutting down network id=" + networkId + " as a part of network update");
//check if network has reservation
- if(NetUtils.isNetworkAWithinNetworkB(network.getCidr(), network.getNetworkCidr())) {
- s_logger.warn ("Existing IP reservation will become ineffective for the network with id = " + networkId + " You need to reapply reservation after network reimplementation.");
+ if (NetUtils.isNetworkAWithinNetworkB(network.getCidr(), network.getNetworkCidr())) {
+ s_logger.warn("Existing IP reservation will become ineffective for the network with id = " + networkId
+ + " You need to reapply reservation after network reimplementation.");
//set cidr to the newtork cidr
network.setCidr(network.getNetworkCidr());
//set networkCidr to null to bring network back to no IP reservation state
@@ -2242,7 +2205,8 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
}
}
} else {
- CloudRuntimeException ex = new CloudRuntimeException("Failed to shutdown the network elements and resources as a part of update to network with specified id; network is in wrong state: " + network.getState());
+ CloudRuntimeException ex = new CloudRuntimeException(
+ "Failed to shutdown the network elements and resources as a part of update to network with specified id; network is in wrong state: " + network.getState());
ex.addProxyObject(network.getUuid(), "networkId");
throw ex;
}
@@ -2253,7 +2217,8 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
Network.State networkState = _networksDao.findById(networkId).getState();
boolean validStateToImplement = (networkState == Network.State.Implemented || networkState == Network.State.Setup || networkState == Network.State.Allocated);
if (restartNetwork && !validStateToImplement) {
- CloudRuntimeException ex = new CloudRuntimeException("Failed to implement the network elements and resources as a part of update to network with specified id; network is in wrong state: " + networkState);
+ CloudRuntimeException ex = new CloudRuntimeException(
+ "Failed to implement the network elements and resources as a part of update to network with specified id; network is in wrong state: " + networkState);
ex.addProxyObject(network.getUuid(), "networkId");
throw ex;
}
@@ -2278,18 +2243,19 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
}
long isDefault = (nic.isDefaultNic()) ? 1 : 0;
String nicIdString = Long.toString(nic.getId());
- UsageEventUtils.publishUsageEvent(EventTypes.EVENT_NETWORK_OFFERING_REMOVE, vm.getAccountId(), vm.getDataCenterId(),
- vm.getId(), nicIdString, oldNetworkOfferingId, null, isDefault, VirtualMachine.class.getName(), vm.getUuid());
- UsageEventUtils.publishUsageEvent(EventTypes.EVENT_NETWORK_OFFERING_ASSIGN, vm.getAccountId(), vm.getDataCenterId(),
- vm.getId(), nicIdString, networkOfferingId, null, isDefault, VirtualMachine.class.getName(), vm.getUuid());
+ UsageEventUtils.publishUsageEvent(EventTypes.EVENT_NETWORK_OFFERING_REMOVE, vm.getAccountId(), vm.getDataCenterId(), vm.getId(), nicIdString,
+ oldNetworkOfferingId, null, isDefault, VirtualMachine.class.getName(), vm.getUuid());
+ UsageEventUtils.publishUsageEvent(EventTypes.EVENT_NETWORK_OFFERING_ASSIGN, vm.getAccountId(), vm.getDataCenterId(), vm.getId(), nicIdString,
+ networkOfferingId, null, isDefault, VirtualMachine.class.getName(), vm.getUuid());
}
}
});
- } else {
+ } else {
network.setNetworkOfferingId(networkOfferingId);
- _networksDao.update(networkId, network, _networkMgr.finalizeServicesAndProvidersForNetwork(_entityMgr.findById(NetworkOffering.class, networkOfferingId), network.getPhysicalNetworkId()));
+ _networksDao.update(networkId, network,
+ _networkMgr.finalizeServicesAndProvidersForNetwork(_entityMgr.findById(NetworkOffering.class, networkOfferingId), network.getPhysicalNetworkId()));
}
- } else {
+ } else {
_networksDao.update(networkId, network);
}
@@ -2315,16 +2281,14 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
// 4) if network has been upgraded from a non persistent ntwk offering to a persistent ntwk offering,
// implement the network if its not already
- if ( networkOfferingChanged && !oldNtwkOff.getIsPersistent() && networkOffering.getIsPersistent()) {
- if( network.getState() == Network.State.Allocated) {
+ if (networkOfferingChanged && !oldNtwkOff.getIsPersistent() && networkOffering.getIsPersistent()) {
+ if (network.getState() == Network.State.Allocated) {
try {
DeployDestination dest = new DeployDestination(_dcDao.findById(network.getDataCenterId()), null, null, null);
_networkMgr.implementNetwork(network.getId(), dest, context);
} catch (Exception ex) {
- s_logger.warn("Failed to implement network " + network + " elements and resources as a part o" +
- "f network update due to ", ex);
- CloudRuntimeException e = new CloudRuntimeException("Failed to implement network (with specified" +
- " id) elements and resources as a part of network update");
+ s_logger.warn("Failed to implement network " + network + " elements and resources as a part o" + "f network update due to ", ex);
+ CloudRuntimeException e = new CloudRuntimeException("Failed to implement network (with specified" + " id) elements and resources as a part of network update");
e.addProxyObject(network.getUuid(), "networkId");
throw e;
}
@@ -2334,7 +2298,6 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
return getNetwork(network.getId());
}
-
protected Set<Long> getAvailableIps(Network network, String requestedIp) {
String[] cidr = network.getCidr().split("/");
List<String> ips = _nicDao.listIpAddressInNetwork(network.getId());
@@ -2357,7 +2320,6 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
return allPossibleIps;
}
-
protected boolean canUpgrade(Network network, long oldNetworkOfferingId, long newNetworkOfferingId) {
NetworkOffering oldNetworkOffering = _networkOfferingDao.findByIdIncludingRemoved(oldNetworkOfferingId);
NetworkOffering newNetworkOffering = _networkOfferingDao.findById(newNetworkOfferingId);
@@ -2423,25 +2385,22 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
return false;
}
}
-
+
//can't update from internal LB to public LB
if (areServicesSupportedByNetworkOffering(oldNetworkOfferingId, Service.Lb) && areServicesSupportedByNetworkOffering(newNetworkOfferingId, Service.Lb)) {
if (oldNetworkOffering.getPublicLb() != newNetworkOffering.getPublicLb() || oldNetworkOffering.getInternalLb() != newNetworkOffering.getInternalLb()) {
- throw new InvalidParameterValueException("Original and new offerings support different types of LB - Internal vs Public," +
- " can't upgrade");
+ throw new InvalidParameterValueException("Original and new offerings support different types of LB - Internal vs Public," + " can't upgrade");
}
}
return canIpsUseOffering(publicIps, newNetworkOfferingId);
}
-
-
@Override
@DB
@ActionEvent(eventType = EventTypes.EVENT_PHYSICAL_NETWORK_CREATE, eventDescription = "Creating Physical Network", create = true)
- public PhysicalNetwork createPhysicalNetwork(final Long zoneId, final String vnetRange, final String networkSpeed, final List<String>
- isolationMethods, String broadcastDomainRangeStr, final Long domainId, final List<String> tags, final String name) {
+ public PhysicalNetwork createPhysicalNetwork(final Long zoneId, final String vnetRange, final String networkSpeed, final List<String> isolationMethods,
+ String broadcastDomainRangeStr, final Long domainId, final List<String> tags, final String name) {
// Check if zone exists
if (zoneId == null) {
@@ -2476,9 +2435,9 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
if (vnetRange != null) {
// Verify zone type
- if (zoneType == NetworkType.Basic
- || (zoneType == NetworkType.Advanced && zone.isSecurityGroupEnabled())) {
- throw new InvalidParameterValueException("Can't add vnet range to the physical network in the zone that supports " + zoneType + " network, Security Group enabled: " + zone.isSecurityGroupEnabled());
+ if (zoneType == NetworkType.Basic || (zoneType == NetworkType.Advanced && zone.isSecurityGroupEnabled())) {
+ throw new InvalidParameterValueException("Can't add vnet range to the physical network in the zone that supports " + zoneType
+ + " network, Security Group enabled: " + zone.isSecurityGroupEnabled());
}
}
@@ -2538,7 +2497,7 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
//Add Internal Load Balancer element as a default network service provider
addDefaultInternalLbProviderToPhysicalNetwork(pNetwork.getId());
-
+
return pNetwork;
}
});
@@ -2565,7 +2524,7 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
sc.addAnd("name", SearchCriteria.Op.LIKE, "%" + name + "%");
}
- Pair<List<PhysicalNetworkVO>, Integer> result = _physicalNetworkDao.searchAndCount(sc, searchFilter);
+ Pair<List<PhysicalNetworkVO>, Integer> result = _physicalNetworkDao.searchAndCount(sc, searchFilter);
return new Pair<List<? extends PhysicalNetwork>, Integer>(result.first(), result.second());
}
@@ -2589,11 +2548,10 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
ex.addProxyObject(String.valueOf(network.getDataCenterId()), "dataCenterId");
throw ex;
}
- if (newVnetRange!= null) {
- if (zone.getNetworkType() == NetworkType.Basic
- || (zone.getNetworkType() == NetworkType.Advanced && zone.isSecurityGroupEnabled())) {
- throw new InvalidParameterValueException("Can't add vnet range to the physical network in the zone that supports " + zone.getNetworkType() + " network, Security Group enabled: "
- + zone.isSecurityGroupEnabled());
+ if (newVnetRange != null) {
+ if (zone.getNetworkType() == NetworkType.Basic || (zone.getNetworkType() == NetworkType.Advanced && zone.isSecurityGroupEnabled())) {
+ throw new InvalidParameterValueException("Can't add vnet range to the physical network in the zone that supports " + zone.getNetworkType()
+ + " network, Security Group enabled: " + zone.isSecurityGroupEnabled());
}
}
@@ -2623,7 +2581,7 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
}
if (newVnetRange != null) {
- String [] listOfRanges = newVnetRange.split(",");
+ String[] listOfRanges = newVnetRange.split(",");
addOrRemoveVnets(listOfRanges, network);
}
_physicalNetworkDao.update(id, network);
@@ -2632,16 +2590,16 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
}
@DB
- public void addOrRemoveVnets(String [] listOfRanges, final PhysicalNetworkVO network) {
- List<String> addVnets = null;
- List<String> removeVnets =null;
+ public void addOrRemoveVnets(String[] listOfRanges, final PhysicalNetworkVO network) {
+ List<String> addVnets = null;
+ List<String> removeVnets = null;
HashSet<String> tempVnets = new HashSet<String>();
HashSet<String> vnetsInDb = new HashSet<String>();
List<Pair<Integer, Integer>> vnetranges = null;
String comaSeperatedStingOfVnetRanges = null;
- int i =0;
- if (listOfRanges.length !=0) {
- _physicalNetworkDao.acquireInLockTable(network.getId(),10);
+ int i = 0;
+ if (listOfRanges.length != 0) {
+ _physicalNetworkDao.acquireInLockTable(network.getId(), 10);
vnetranges = validateVlanRange(network, listOfRanges);
//computing vnets to be removed.
@@ -2650,8 +2608,8 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
//computing vnets to add
vnetsInDb.addAll(_datacneter_vnet.listVnetsByPhysicalNetworkAndDataCenter(network.getDataCenterId(), network.getId()));
tempVnets.addAll(vnetsInDb);
- for (Pair<Integer, Integer>vlan : vnetranges) {
- for (i= vlan.first(); i<= vlan.second(); i++) {
+ for (Pair<Integer, Integer> vlan : vnetranges) {
+ for (i = vlan.first(); i <= vlan.second(); i++) {
tempVnets.add(Integer.toString(i));
}
}
@@ -2659,7 +2617,7 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
//vnets to add in tempVnets.
//adding and removing vnets from vnetsInDb
- if (removeVnets != null && removeVnets.size() !=0 ) {
+ if (removeVnets != null && removeVnets.size() != 0) {
vnetsInDb.removeAll(removeVnets);
}
@@ -2670,8 +2628,8 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
}
//sorting the vnets in Db to generate a coma seperated list of the vnet string.
- if (vnetsInDb.size() !=0 ) {
- comaSeperatedStingOfVnetRanges = generateVnetString( new ArrayList<String>(vnetsInDb));
+ if (vnetsInDb.size() != 0) {
+ comaSeperatedStingOfVnetRanges = generateVnetString(new ArrayList<String>(vnetsInDb));
}
network.setVnet(comaSeperatedStingOfVnetRanges);
@@ -2681,14 +2639,14 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
@Override
public void doInTransactionWithoutResult(TransactionStatus status) {
if (addVnetsFinal != null) {
- s_logger.debug("Adding vnet range " + addVnetsFinal.toString()+ " for the physicalNetwork id= " + network.getId() + " and zone id=" + network.getDataCenterId()
- + " as a part of updatePhysicalNetwork call");
+ s_logger.debug("Adding vnet range " + addVnetsFinal.toString() + " for the physicalNetwork id= " + network.getId() + " and zone id="
+ + network.getDataCenterId() + " as a part of updatePhysicalNetwork call");
//add vnet takes a list of strings to be added. each string is a vnet.
_dcDao.addVnet(network.getDataCenterId(), network.getId(), addVnetsFinal);
}
if (removeVnetsFinal != null) {
- s_logger.debug("removing vnet range " + removeVnetsFinal.toString()+ " for the physicalNetwork id= " + network.getId() + " and zone id=" + network.getDataCenterId()
- + " as a part of updatePhysicalNetwork call");
+ s_logger.debug("removing vnet range " + removeVnetsFinal.toString() + " for the physicalNetwork id= " + network.getId() + " and zone id="
+ + network.getDataCenterId() + " as a part of updatePhysicalNetwork call");
//deleteVnets takes a list of strings to be removed. each string is a vnet.
_datacneter_vnet.deleteVnets(TransactionLegacy.currentTxn(), network.getDataCenterId(), network.getId(), removeVnetsFinal);
}
@@ -2703,7 +2661,7 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkSer
<TRUNCATED>