cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kelv...@apache.org
Subject [13/43] git commit: refs/heads/javelin - IPv6: move assignPublicIp6Address() from NetworkManager to new Ipv6AddressManager
Date Fri, 01 Feb 2013 01:29:17 GMT
IPv6: move assignPublicIp6Address() from NetworkManager to new Ipv6AddressManager

Don't want to involve IP address management code in NetworkManager.


Project: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/commit/cb9f2d01
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/tree/cb9f2d01
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/diff/cb9f2d01

Branch: refs/heads/javelin
Commit: cb9f2d018d3abb5a17a244a1071706592f75cdfc
Parents: 1f2147d
Author: Sheng Yang <sheng.yang@citrix.com>
Authored: Tue Jan 29 18:02:32 2013 -0800
Committer: Sheng Yang <sheng.yang@citrix.com>
Committed: Tue Jan 29 19:08:03 2013 -0800

----------------------------------------------------------------------
 .../configuration/DefaultComponentLibrary.java     |    2 +
 .../src/com/cloud/network/Ipv6AddressManager.java  |   28 +++
 .../com/cloud/network/Ipv6AddressManagerImpl.java  |  132 +++++++++++++++
 server/src/com/cloud/network/NetworkManager.java   |    4 -
 .../src/com/cloud/network/NetworkManagerImpl.java  |   55 +------
 .../cloud/network/dao/PublicIpv6AddressDao.java    |    2 +-
 .../network/dao/PublicIpv6AddressDaoImpl.java      |    4 +-
 .../com/cloud/network/guru/DirectNetworkGuru.java  |    8 +-
 .../com/cloud/network/MockNetworkManagerImpl.java  |    8 -
 .../test/com/cloud/vpc/MockNetworkManagerImpl.java |    8 -
 10 files changed, 172 insertions(+), 79 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/cb9f2d01/server/src/com/cloud/configuration/DefaultComponentLibrary.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/configuration/DefaultComponentLibrary.java b/server/src/com/cloud/configuration/DefaultComponentLibrary.java
index e2e800b..e8fcabe 100755
--- a/server/src/com/cloud/configuration/DefaultComponentLibrary.java
+++ b/server/src/com/cloud/configuration/DefaultComponentLibrary.java
@@ -91,6 +91,7 @@ import com.cloud.keystore.KeystoreManagerImpl;
 import com.cloud.maint.UpgradeManagerImpl;
 import com.cloud.maint.dao.AgentUpgradeDaoImpl;
 import com.cloud.network.ExternalLoadBalancerUsageManagerImpl;
+import com.cloud.network.Ipv6AddressManagerImpl;
 import com.cloud.network.NetworkManagerImpl;
 import com.cloud.network.NetworkModelImpl;
 import com.cloud.network.NetworkServiceImpl;
@@ -464,6 +465,7 @@ public class DefaultComponentLibrary extends ComponentLibraryBase implements
Com
         addManager("TaggedResourcesManager", TaggedResourceManagerImpl.class);
         addManager("Site2SiteVpnManager", Site2SiteVpnManagerImpl.class);
         addManager("QueryManager", QueryManagerImpl.class);
+        addManager("Ipv6AddressManager", Ipv6AddressManagerImpl.class);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/cb9f2d01/server/src/com/cloud/network/Ipv6AddressManager.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/Ipv6AddressManager.java b/server/src/com/cloud/network/Ipv6AddressManager.java
new file mode 100644
index 0000000..21c65a9
--- /dev/null
+++ b/server/src/com/cloud/network/Ipv6AddressManager.java
@@ -0,0 +1,28 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package com.cloud.network;
+
+import com.cloud.exception.InsufficientAddressCapacityException;
+import com.cloud.user.Account;
+import com.cloud.utils.component.Manager;
+
+public interface Ipv6AddressManager extends Manager {
+    public PublicIpv6Address assignDirectIp6Address(long dcId, Account owner, Long networkId,
String requestedIp6) throws InsufficientAddressCapacityException;
+
+	public void revokeDirectIpv6Address(long networkId, String ip6Address);
+}

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/cb9f2d01/server/src/com/cloud/network/Ipv6AddressManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/Ipv6AddressManagerImpl.java b/server/src/com/cloud/network/Ipv6AddressManagerImpl.java
new file mode 100644
index 0000000..d794ff7
--- /dev/null
+++ b/server/src/com/cloud/network/Ipv6AddressManagerImpl.java
@@ -0,0 +1,132 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package com.cloud.network;
+
+import java.util.Map;
+
+import javax.ejb.Local;
+import javax.naming.ConfigurationException;
+
+import org.apache.log4j.Logger;
+
+import com.cloud.dc.DataCenterVO;
+import com.cloud.dc.Vlan;
+import com.cloud.dc.dao.DataCenterDao;
+import com.cloud.dc.dao.VlanDao;
+import com.cloud.exception.InsufficientAddressCapacityException;
+import com.cloud.network.dao.PublicIpv6AddressDao;
+import com.cloud.user.Account;
+import com.cloud.utils.component.Inject;
+import com.cloud.utils.exception.CloudRuntimeException;
+import com.cloud.utils.net.NetUtils;
+
+@Local(value = { Ipv6AddressManager.class } )
+public class Ipv6AddressManagerImpl implements Ipv6AddressManager {
+    public static final Logger s_logger = Logger.getLogger(Ipv6AddressManagerImpl.class.getName());
+
+	String _name = null;
+			
+    @Inject
+    DataCenterDao _dcDao;
+    @Inject
+    VlanDao _vlanDao;
+    @Inject
+    NetworkModel _networkModel;
+    @Inject
+    PublicIpv6AddressDao _ipv6Dao;
+    
+	@Override
+	public boolean configure(String name, Map<String, Object> params)
+			throws ConfigurationException {
+		_name = name;
+		return true;
+	}
+
+	@Override
+	public boolean start() {
+		return true;
+	}
+
+	@Override
+	public boolean stop() {
+		return true;
+	}
+
+	@Override
+	public String getName() {
+		return _name;
+	}
+
+	@Override
+	public PublicIpv6Address assignDirectIp6Address(long dcId, Account owner, Long networkId,
String requestedIp6)
+			throws InsufficientAddressCapacityException {
+    	Vlan vlan = _networkModel.getVlanForNetwork(networkId);
+    	if (vlan == null) {
+    		s_logger.debug("Cannot find related vlan or too many vlan attached to network " + networkId);
+    		return null;
+    	}
+    	String ip = null;
+    	if (requestedIp6 == null) {
+    		int count = 0;
+    		while (ip == null || count >= 10) {
+    			ip = NetUtils.getIp6FromRange(vlan.getIp6Range());
+    			//Check for duplicate IP
+    			if (_ipv6Dao.findByNetworkIdAndIp(networkId, ip) == null) {
+    				break;
+    			} else {
+    				ip = null;
+    			}
+    			count ++;
+    		}
+    		if (ip == null) {
+    			throw new CloudRuntimeException("Fail to get unique ipv6 address after 10 times trying!");
+    		}
+    	} else {
+    		if (!NetUtils.isIp6InRange(requestedIp6, vlan.getIp6Range())) {
+    			throw new CloudRuntimeException("Requested IPv6 is not in the predefined range!");
+    		}
+    		ip = requestedIp6;
+    		if (_ipv6Dao.findByNetworkIdAndIp(networkId, ip) != null) {
+    			throw new CloudRuntimeException("The requested IP is already taken!");
+    		}
+    	}
+    	DataCenterVO dc = _dcDao.findById(dcId);
+        Long mac = dc.getMacAddress();
+        Long nextMac = mac + 1;
+        dc.setMacAddress(nextMac);
+        _dcDao.update(dc.getId(), dc);
+        
+    	String macAddress = NetUtils.long2Mac(NetUtils.createSequenceBasedMacAddress(mac));
+    	PublicIpv6AddressVO ipVO = new PublicIpv6AddressVO(ip, dcId, macAddress, vlan.getId());
+    	ipVO.setPhysicalNetworkId(vlan.getPhysicalNetworkId());
+    	ipVO.setSourceNetworkId(vlan.getNetworkId());
+    	ipVO.setState(PublicIpv6Address.State.Allocated);
+    	ipVO.setDomainId(owner.getDomainId());
+    	ipVO.setAccountId(owner.getAccountId());
+    	_ipv6Dao.persist(ipVO);
+    	return ipVO;
+	}
+
+	@Override
+	public void revokeDirectIpv6Address(long networkId, String ip6Address) {
+		PublicIpv6AddressVO ip = _ipv6Dao.findByNetworkIdAndIp(networkId, ip6Address);
+		if (ip != null) {
+			_ipv6Dao.remove(ip.getId());
+		}
+	}
+}

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/cb9f2d01/server/src/com/cloud/network/NetworkManager.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/NetworkManager.java b/server/src/com/cloud/network/NetworkManager.java
index 71ad72a..149d134 100755
--- a/server/src/com/cloud/network/NetworkManager.java
+++ b/server/src/com/cloud/network/NetworkManager.java
@@ -327,8 +327,4 @@ public interface NetworkManager  {
     int getRuleCountForIp(Long addressId, FirewallRule.Purpose purpose, FirewallRule.State
state);
 
     LoadBalancingServiceProvider getLoadBalancingProviderForNetwork(Network network);
-
-	PublicIpv6Address assignPublicIp6Address(long dcId, Long podId, Account owner,
-			VlanType type, Long networkId, String requestedIp6, boolean isSystem)
-			throws InsufficientAddressCapacityException;
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/cb9f2d01/server/src/com/cloud/network/NetworkManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/NetworkManagerImpl.java b/server/src/com/cloud/network/NetworkManagerImpl.java
index cea935e..e06a59b 100755
--- a/server/src/com/cloud/network/NetworkManagerImpl.java
+++ b/server/src/com/cloud/network/NetworkManagerImpl.java
@@ -276,6 +276,8 @@ public class NetworkManagerImpl implements NetworkManager, Manager, Listener
{
     NetworkModel _networkModel;
     @Inject
     PublicIpv6AddressDao _ipv6Dao;
+    @Inject
+    Ipv6AddressManager _ipv6Mgr;
 
     ScheduledExecutorService _executor;
 
@@ -297,57 +299,6 @@ public class NetworkManagerImpl implements NetworkManager, Manager, Listener
{
         return fetchNewPublicIp(dcId, podId, null, owner, type, networkId, false, true, requestedIp,
isSystem, null);
     }
 
-    @Override
-    public PublicIpv6Address assignPublicIp6Address(long dcId, Long podId, Account owner,
VlanType type, Long networkId, String requestedIp6, boolean isSystem) throws InsufficientAddressCapacityException
{
-    	Vlan vlan = _networkModel.getVlanForNetwork(networkId);
-    	if (vlan == null) {
-    		s_logger.debug("Cannot find related vlan or too many vlan attached to network " + networkId);
-    		return null;
-    	}
-    	//TODO should check before this point
-    	if (!NetUtils.isIp6InRange(requestedIp6, vlan.getIp6Range())) {
-    		throw new CloudRuntimeException("Requested IPv6 is not in the predefined range!");
-    	}
-    	String ip = null;
-    	if (requestedIp6 == null) {
-    		int count = 0;
-    		while (ip == null || count >= 10) {
-    			ip = NetUtils.getIp6FromRange(vlan.getIp6Range());
-    			//Check for duplicate IP
-    			if (_ipv6Dao.findByDcIdAndIp(dcId, ip) == null) {
-    				break;
-    			} else {
-    				ip = null;
-    			}
-    			count ++;
-    		}
-    		if (ip == null) {
-    			throw new CloudRuntimeException("Fail to get unique ipv6 address after 10 times trying!");
-    		}
-    	} else {
-    		ip = requestedIp6;
-    		//TODO should check before this point
-    		if (_ipv6Dao.findByDcIdAndIp(dcId, ip) != null) {
-    			throw new CloudRuntimeException("The requested IP is already taken!");
-    		}
-    	}
-    	DataCenterVO dc = _dcDao.findById(dcId);
-        Long mac = dc.getMacAddress();
-        Long nextMac = mac + 1;
-        dc.setMacAddress(nextMac);
-        _dcDao.update(dc.getId(), dc);
-        
-    	String macAddress = NetUtils.long2Mac(NetUtils.createSequenceBasedMacAddress(mac));
-    	PublicIpv6AddressVO ipVO = new PublicIpv6AddressVO(ip, dcId, macAddress, vlan.getId());
-    	ipVO.setPhysicalNetworkId(vlan.getPhysicalNetworkId());
-    	ipVO.setSourceNetworkId(vlan.getNetworkId());
-    	ipVO.setState(PublicIpv6Address.State.Allocated);
-    	ipVO.setDomainId(owner.getDomainId());
-    	ipVO.setAccountId(owner.getAccountId());
-    	_ipv6Dao.persist(ipVO);
-    	return ipVO;
-    }
-    
     @DB
     public PublicIp fetchNewPublicIp(long dcId, Long podId, Long vlanDbId, Account owner,
VlanType vlanUse,
             Long guestNetworkId, boolean sourceNat, boolean assign, String requestedIp, boolean
isSystem, Long vpcId)
@@ -3411,7 +3362,7 @@ public class NetworkManagerImpl implements NetworkManager, Manager,
Listener {
     	if (network.getIp6Gateway() != null) {
     		if (nic.getIp6Address() == null) {
     			ipv6 = true;
-    			PublicIpv6Address ip = assignPublicIp6Address(dc.getId(), null, vm.getOwner(), VlanType.DirectAttached,
network.getId(), requestedIpv6, false);
+    			PublicIpv6Address ip = _ipv6Mgr.assignDirectIp6Address(dc.getId(), vm.getOwner(),
network.getId(), requestedIpv6);
     			Vlan vlan = _networkModel.getVlanForNetwork(network.getId());
     			if (vlan == null) {
     				s_logger.debug("Cannot find related vlan or too many vlan attached to network " +
network.getId());

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/cb9f2d01/server/src/com/cloud/network/dao/PublicIpv6AddressDao.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/dao/PublicIpv6AddressDao.java b/server/src/com/cloud/network/dao/PublicIpv6AddressDao.java
index b8de08a..c347052 100644
--- a/server/src/com/cloud/network/dao/PublicIpv6AddressDao.java
+++ b/server/src/com/cloud/network/dao/PublicIpv6AddressDao.java
@@ -15,7 +15,7 @@ public interface PublicIpv6AddressDao extends GenericDao<PublicIpv6AddressVO,
Lo
 	
 	List<PublicIpv6AddressVO> listByNetwork(long networkId);
 	
-	public PublicIpv6AddressVO findByDcIdAndIp(long dcId, String ipAddress);
+	public PublicIpv6AddressVO findByNetworkIdAndIp(long networkId, String ipAddress);
 
 	List<PublicIpv6AddressVO> listByPhysicalNetworkId(long physicalNetworkId);
 

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/cb9f2d01/server/src/com/cloud/network/dao/PublicIpv6AddressDaoImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/dao/PublicIpv6AddressDaoImpl.java b/server/src/com/cloud/network/dao/PublicIpv6AddressDaoImpl.java
index 6883d4e..8a6bfcc 100644
--- a/server/src/com/cloud/network/dao/PublicIpv6AddressDaoImpl.java
+++ b/server/src/com/cloud/network/dao/PublicIpv6AddressDaoImpl.java
@@ -73,9 +73,9 @@ public class PublicIpv6AddressDaoImpl extends GenericDaoBase<PublicIpv6AddressVO
 	}
 
 	@Override
-	public PublicIpv6AddressVO findByDcIdAndIp(long dcId, String ipAddress) {
+	public PublicIpv6AddressVO findByNetworkIdAndIp(long networkId, String ipAddress) {
         SearchCriteria<PublicIpv6AddressVO> sc = AllFieldsSearch.create();
-        sc.setParameters("dataCenterId", dcId);
+        sc.setParameters("networkId", networkId);
         sc.setParameters("ipAddress", ipAddress);
         return findOneBy(sc);
 	}

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/cb9f2d01/server/src/com/cloud/network/guru/DirectNetworkGuru.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/guru/DirectNetworkGuru.java b/server/src/com/cloud/network/guru/DirectNetworkGuru.java
index d6a8812..ef286bd 100755
--- a/server/src/com/cloud/network/guru/DirectNetworkGuru.java
+++ b/server/src/com/cloud/network/guru/DirectNetworkGuru.java
@@ -31,6 +31,7 @@ import com.cloud.exception.InsufficientAddressCapacityException;
 import com.cloud.exception.InsufficientVirtualNetworkCapcityException;
 import com.cloud.exception.InvalidParameterValueException;
 import com.cloud.network.IPAddressVO;
+import com.cloud.network.Ipv6AddressManager;
 import com.cloud.network.Network;
 import com.cloud.network.Network.GuestType;
 import com.cloud.network.Network.Service;
@@ -76,6 +77,8 @@ public class DirectNetworkGuru extends AdapterBase implements NetworkGuru
{
     NetworkOfferingDao _networkOfferingDao;
     @Inject
     PublicIpv6AddressDao _ipv6Dao;
+    @Inject
+    Ipv6AddressManager _ipv6Mgr;
     
     private static final TrafficType[] _trafficTypes = {TrafficType.Guest};
     
@@ -230,10 +233,7 @@ public class DirectNetworkGuru extends AdapterBase implements NetworkGuru
{
     	}
     	
     	if (nic.getIp6Address() != null) {
-    		PublicIpv6AddressVO ip = _ipv6Dao.findByDcIdAndIp(network.getDataCenterId(), nic.getIp6Address());
-    		if (ip != null) {
-    			_ipv6Dao.remove(ip.getId());
-    		}
+    		_ipv6Mgr.revokeDirectIpv6Address(nic.getNetworkId(), nic.getIp6Address());
     	}
         nic.deallocate();
     }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/cb9f2d01/server/test/com/cloud/network/MockNetworkManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/test/com/cloud/network/MockNetworkManagerImpl.java b/server/test/com/cloud/network/MockNetworkManagerImpl.java
index df409a8..122d75a 100755
--- a/server/test/com/cloud/network/MockNetworkManagerImpl.java
+++ b/server/test/com/cloud/network/MockNetworkManagerImpl.java
@@ -818,12 +818,4 @@ public class MockNetworkManagerImpl implements NetworkManager, Manager,
NetworkS
         // TODO Auto-generated method stub
         return null;
     }
-
-	@Override
-	public PublicIpv6Address assignPublicIp6Address(long dcId, Long podId,
-			Account owner, VlanType type, Long networkId, String requestedIpv6,
-			boolean isSystem) throws InsufficientAddressCapacityException {
-		// TODO Auto-generated method stub
-		return null;
-	}
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/cb9f2d01/server/test/com/cloud/vpc/MockNetworkManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/test/com/cloud/vpc/MockNetworkManagerImpl.java b/server/test/com/cloud/vpc/MockNetworkManagerImpl.java
index 13426e6..970f5ad 100644
--- a/server/test/com/cloud/vpc/MockNetworkManagerImpl.java
+++ b/server/test/com/cloud/vpc/MockNetworkManagerImpl.java
@@ -1321,12 +1321,4 @@ public class MockNetworkManagerImpl implements NetworkManager, NetworkService,
M
         // TODO Auto-generated method stub
         return null;
     }
-
-	@Override
-	public PublicIpv6Address assignPublicIp6Address(long dcId, Long podId,
-			Account owner, VlanType type, Long networkId, String requestedIpv6,
-			boolean isSystem) throws InsufficientAddressCapacityException {
-		// TODO Auto-generated method stub
-		return null;
-	}
 }


Mime
View raw message