cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From alena1...@apache.org
Subject git commit: updated refs/heads/master to beabf59
Date Mon, 05 Aug 2013 21:26:06 GMT
Updated Branches:
  refs/heads/master 4c89be144 -> beabf596b


CLOUDSTACK-4080: don't GC the network when it has vms in Starting state even when the nics
are not allocated for them yet (can happen when vm is being created)


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

Branch: refs/heads/master
Commit: beabf596ba0d26dcd23edb555a2b20e63d32d70b
Parents: 4c89be1
Author: Alena Prokharchyk <alena.prokharchyk@citrix.com>
Authored: Mon Aug 5 14:12:25 2013 -0700
Committer: Alena Prokharchyk <alena.prokharchyk@citrix.com>
Committed: Mon Aug 5 14:15:04 2013 -0700

----------------------------------------------------------------------
 engine/schema/src/com/cloud/vm/dao/NicDao.java  |  2 +
 .../schema/src/com/cloud/vm/dao/NicDaoImpl.java | 52 +++++++++++++++-----
 .../src/com/cloud/network/NetworkModelImpl.java |  7 +++
 3 files changed, 50 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/beabf596/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 37249dd..79bd4d2 100644
--- a/engine/schema/src/com/cloud/vm/dao/NicDao.java
+++ b/engine/schema/src/com/cloud/vm/dao/NicDao.java
@@ -71,4 +71,6 @@ public interface NicDao extends GenericDao<NicVO, Long> {
     NicVO findByInstanceIdAndIpAddressAndVmtype(long instanceId, String ipaddress, VirtualMachine.Type
type);
 
     List<NicVO> listByNetworkIdTypeAndGatewayAndBroadcastUri(long networkId, VirtualMachine.Type
vmType, String gateway, URI broadcastUri);
+    
+    int countNicsForStartingVms(long networkId);
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/beabf596/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 d6433a4..8e9f7fa 100644
--- a/engine/schema/src/com/cloud/vm/dao/NicDaoImpl.java
+++ b/engine/schema/src/com/cloud/vm/dao/NicDaoImpl.java
@@ -16,8 +16,18 @@
 // under the License.
 package com.cloud.vm.dao;
 
+import java.net.URI;
+import java.util.List;
+
+import javax.annotation.PostConstruct;
+import javax.ejb.Local;
+import javax.inject.Inject;
+
+import org.springframework.stereotype.Component;
+
 import com.cloud.utils.db.GenericDaoBase;
 import com.cloud.utils.db.GenericSearchBuilder;
+import com.cloud.utils.db.JoinBuilder;
 import com.cloud.utils.db.SearchBuilder;
 import com.cloud.utils.db.SearchCriteria;
 import com.cloud.utils.db.SearchCriteria.Func;
@@ -25,25 +35,27 @@ import com.cloud.utils.db.SearchCriteria.Op;
 import com.cloud.vm.Nic;
 import com.cloud.vm.Nic.State;
 import com.cloud.vm.NicVO;
+import com.cloud.vm.VMInstanceVO;
 import com.cloud.vm.VirtualMachine;
-import org.springframework.stereotype.Component;
-
-import javax.ejb.Local;
-import java.net.URI;
-import java.util.List;
 
 @Component
 @Local(value=NicDao.class)
 public class NicDaoImpl extends GenericDaoBase<NicVO, Long> implements NicDao {
-    private final SearchBuilder<NicVO> AllFieldsSearch;
-    private final GenericSearchBuilder<NicVO, String> IpSearch;
-    private final SearchBuilder<NicVO> NonReleasedSearch;
-    final GenericSearchBuilder<NicVO, Integer> CountBy;
+    private  SearchBuilder<NicVO> AllFieldsSearch;
+    private GenericSearchBuilder<NicVO, String> IpSearch;
+    private SearchBuilder<NicVO> NonReleasedSearch;
+    private GenericSearchBuilder<NicVO, Integer> CountBy;
+    private GenericSearchBuilder<NicVO, Integer> CountByForStartingVms;
 
+    @Inject
+    VMInstanceDao _vmDao;
     
-    public NicDaoImpl() {
-        super();
+    public NicDaoImpl() {  
         
+    }
+    
+    @PostConstruct
+    protected void init() {
         AllFieldsSearch = createSearchBuilder();
         AllFieldsSearch.and("instance", AllFieldsSearch.entity().getInstanceId(), Op.EQ);
         AllFieldsSearch.and("network", AllFieldsSearch.entity().getNetworkId(), Op.EQ);
@@ -73,6 +85,15 @@ public class NicDaoImpl extends GenericDaoBase<NicVO, Long> implements
NicDao {
         CountBy.and("vmId", CountBy.entity().getInstanceId(), Op.EQ);
         CountBy.and("removed", CountBy.entity().getRemoved(), Op.NULL);
         CountBy.done();
+        
+        CountByForStartingVms = createSearchBuilder(Integer.class);
+        CountByForStartingVms.select(null, Func.COUNT, CountByForStartingVms.entity().getId());
+        CountByForStartingVms.and("networkId", CountByForStartingVms.entity().getNetworkId(),
Op.EQ);
+        CountByForStartingVms.and("removed", CountByForStartingVms.entity().getRemoved(),
Op.NULL);
+        SearchBuilder<VMInstanceVO> join1 = _vmDao.createSearchBuilder();
+        join1.and("state", join1.entity().getState(), Op.EQ);
+        CountByForStartingVms.join("vm", join1, CountByForStartingVms.entity().getInstanceId(),
join1.entity().getId(), JoinBuilder.JoinType.INNER);
+        CountByForStartingVms.done();
     }
     
     @Override
@@ -256,4 +277,13 @@ public class NicDaoImpl extends GenericDaoBase<NicVO, Long> implements
NicDao {
         return listBy(sc);
     }
 
+    @Override
+    public int countNicsForStartingVms(long networkId) {
+        SearchCriteria<Integer> sc = CountByForStartingVms.create();
+        sc.setParameters("networkId", networkId);
+        sc.setJoinParameters("vm", "state", VirtualMachine.State.Starting);
+        List<Integer> results = customSearch(sc, null);
+        return results.get(0);
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/beabf596/server/src/com/cloud/network/NetworkModelImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/NetworkModelImpl.java b/server/src/com/cloud/network/NetworkModelImpl.java
index 849884d..7665f15 100755
--- a/server/src/com/cloud/network/NetworkModelImpl.java
+++ b/server/src/com/cloud/network/NetworkModelImpl.java
@@ -2169,6 +2169,13 @@ public class NetworkModelImpl extends ManagerBase implements NetworkModel
{
                 networkIsConfiguredForExternalNetworking(network.getDataCenterId(), networkId))
{
             return false;
         }
+        
+        //if the network has vms in Starting state (nics for those might not be allocated
yet as Starting state also used when vm is being Created)
+        //don't GC
+        if (_nicDao.countNicsForStartingVms(networkId) > 0) {
+            s_logger.debug("Network id=" + networkId + " is not ready for GC as it has vms
that are Starting at the moment");
+            return false;
+        }
 
         return true;
     }


Mime
View raw message