You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by da...@apache.org on 2015/12/13 18:43:59 UTC
[1/2] git commit: updated refs/heads/4.6 to 5774b96
Repository: cloudstack
Updated Branches:
refs/heads/4.6 d7b717187 -> 5774b965f
CLOUDSTACK-9134: set device_id as the first device_id not in use instead of nic count
when we restart vpc tiers, the old nics will be removed, and create a new nic.
however, the device_id was set to the nic count, which may be already used.
this commit get the first device_id not in use as the device_id of new nic.
This issue also happen when we add multiple networks to a vm and remove them.
Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/acfc19dc
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/acfc19dc
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/acfc19dc
Branch: refs/heads/4.6
Commit: acfc19dc8285a07412ee0078fbc13d7319d5be8b
Parents: 3515f57
Author: Wei Zhou <w....@tech.leaseweb.com>
Authored: Thu Dec 10 13:26:02 2015 +0100
Committer: Wei Zhou <w....@tech.leaseweb.com>
Committed: Thu Dec 10 14:02:02 2015 +0100
----------------------------------------------------------------------
.../orchestration/NetworkOrchestrator.java | 2 +-
engine/schema/src/com/cloud/vm/dao/NicDao.java | 2 +-
.../schema/src/com/cloud/vm/dao/NicDaoImpl.java | 31 +++++++++++++-------
3 files changed, 22 insertions(+), 13 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/acfc19dc/engine/orchestration/src/org/apache/cloudstack/engine/orchestration/NetworkOrchestrator.java
----------------------------------------------------------------------
diff --git a/engine/orchestration/src/org/apache/cloudstack/engine/orchestration/NetworkOrchestrator.java b/engine/orchestration/src/org/apache/cloudstack/engine/orchestration/NetworkOrchestrator.java
index a3ae526..21699a3 100644
--- a/engine/orchestration/src/org/apache/cloudstack/engine/orchestration/NetworkOrchestrator.java
+++ b/engine/orchestration/src/org/apache/cloudstack/engine/orchestration/NetworkOrchestrator.java
@@ -3150,7 +3150,7 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra
//1) allocate nic (if needed) Always allocate if it is a user vm
if (nic == null || (vmProfile.getType() == VirtualMachine.Type.User)) {
- int deviceId = _nicDao.countNics(vm.getId());
+ int deviceId = _nicDao.getFreeDeviceId(vm.getId());
nic = allocateNic(requested, network, false, deviceId, vmProfile).first();
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/acfc19dc/engine/schema/src/com/cloud/vm/dao/NicDao.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/vm/dao/NicDao.java b/engine/schema/src/com/cloud/vm/dao/NicDao.java
index a7ad016..2c7895a 100644
--- a/engine/schema/src/com/cloud/vm/dao/NicDao.java
+++ b/engine/schema/src/com/cloud/vm/dao/NicDao.java
@@ -55,7 +55,7 @@ public interface NicDao extends GenericDao<NicVO, Long> {
String getIpAddress(long networkId, long instanceId);
- int countNics(long instanceId);
+ int getFreeDeviceId(long instanceId);
NicVO findByNetworkIdInstanceIdAndBroadcastUri(long networkId, long instanceId, String broadcastUri);
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/acfc19dc/engine/schema/src/com/cloud/vm/dao/NicDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/vm/dao/NicDaoImpl.java b/engine/schema/src/com/cloud/vm/dao/NicDaoImpl.java
index da89b2c..f1299b3 100644
--- a/engine/schema/src/com/cloud/vm/dao/NicDaoImpl.java
+++ b/engine/schema/src/com/cloud/vm/dao/NicDaoImpl.java
@@ -25,6 +25,7 @@ import javax.inject.Inject;
import org.springframework.stereotype.Component;
+import com.cloud.utils.db.Filter;
import com.cloud.utils.db.GenericDaoBase;
import com.cloud.utils.db.GenericSearchBuilder;
import com.cloud.utils.db.JoinBuilder;
@@ -44,7 +45,7 @@ public class NicDaoImpl extends GenericDaoBase<NicVO, Long> implements NicDao {
private SearchBuilder<NicVO> AllFieldsSearch;
private GenericSearchBuilder<NicVO, String> IpSearch;
private SearchBuilder<NicVO> NonReleasedSearch;
- private GenericSearchBuilder<NicVO, Integer> CountBy;
+ private GenericSearchBuilder<NicVO, Integer> deviceIdSearch;
private GenericSearchBuilder<NicVO, Integer> CountByForStartingVms;
@Inject
@@ -81,11 +82,10 @@ public class NicDaoImpl extends GenericDaoBase<NicVO, Long> implements NicDao {
NonReleasedSearch.and("state", NonReleasedSearch.entity().getState(), Op.NOTIN);
NonReleasedSearch.done();
- CountBy = createSearchBuilder(Integer.class);
- CountBy.select(null, Func.COUNT, CountBy.entity().getId());
- CountBy.and("vmId", CountBy.entity().getInstanceId(), Op.EQ);
- CountBy.and("removed", CountBy.entity().getRemoved(), Op.NULL);
- CountBy.done();
+ deviceIdSearch = createSearchBuilder(Integer.class);
+ deviceIdSearch.select(null, Func.DISTINCT, deviceIdSearch.entity().getDeviceId());
+ deviceIdSearch.and("instance", deviceIdSearch.entity().getInstanceId(), Op.EQ);
+ deviceIdSearch.done();
CountByForStartingVms = createSearchBuilder(Integer.class);
CountByForStartingVms.select(null, Func.COUNT, CountByForStartingVms.entity().getId());
@@ -222,11 +222,20 @@ public class NicDaoImpl extends GenericDaoBase<NicVO, Long> implements NicDao {
}
@Override
- public int countNics(long instanceId) {
- SearchCriteria<Integer> sc = CountBy.create();
- sc.setParameters("vmId", instanceId);
- List<Integer> results = customSearch(sc, null);
- return results.get(0);
+ public int getFreeDeviceId(long instanceId) {
+ Filter searchFilter = new Filter(NicVO.class, "deviceId", true, null, null);
+ SearchCriteria<Integer> sc = deviceIdSearch.create();
+ sc.setParameters("instance", instanceId);
+ List<Integer> deviceIds = customSearch(sc, searchFilter);
+
+ int freeDeviceId = 0;
+ for (int deviceId : deviceIds) {
+ if (deviceId > freeDeviceId)
+ break;
+ freeDeviceId ++;
+ }
+
+ return freeDeviceId;
}
@Override
[2/2] git commit: updated refs/heads/4.6 to 5774b96
Posted by da...@apache.org.
Merge pull request #1209 from ustcweizhou/free-deviceid
CLOUDSTACK-9134: set device_id as the first device_id not in use instead of nic count
when we restart vpc tiers, the old nics will be removed, and create a new nic.
however, the device_id was set to the nic count, which may be already used.
this commit get the first device_id not in use as the device_id of new nic.
This issue also happen when we add multiple networks to a vm and remove them.
* pr/1209:
CLOUDSTACK-9134: set device_id as the first device_id not in use instead of nic count
Signed-off-by: Daan Hoogland <da...@onecht.net>
Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/5774b965
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/5774b965
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/5774b965
Branch: refs/heads/4.6
Commit: 5774b965f35fcfea645c25a9cc0be9f3e603dfa1
Parents: d7b7171 acfc19d
Author: Daan Hoogland <da...@onecht.net>
Authored: Sun Dec 13 18:43:29 2015 +0100
Committer: Daan Hoogland <da...@onecht.net>
Committed: Sun Dec 13 18:43:30 2015 +0100
----------------------------------------------------------------------
.../orchestration/NetworkOrchestrator.java | 2 +-
engine/schema/src/com/cloud/vm/dao/NicDao.java | 2 +-
.../schema/src/com/cloud/vm/dao/NicDaoImpl.java | 31 +++++++++++++-------
3 files changed, 22 insertions(+), 13 deletions(-)
----------------------------------------------------------------------