cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From prachida...@apache.org
Subject [05/34] Changes to add AffinityGroupprocessor, deployVM changes
Date Thu, 11 Apr 2013 20:24:44 GMT
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/fe2a8687/server/src/org/apache/cloudstack/affinity/dao/AffinityGroupVMMapDaoImpl.java
----------------------------------------------------------------------
diff --git a/server/src/org/apache/cloudstack/affinity/dao/AffinityGroupVMMapDaoImpl.java
b/server/src/org/apache/cloudstack/affinity/dao/AffinityGroupVMMapDaoImpl.java
index e9286db..0fb4e79 100644
--- a/server/src/org/apache/cloudstack/affinity/dao/AffinityGroupVMMapDaoImpl.java
+++ b/server/src/org/apache/cloudstack/affinity/dao/AffinityGroupVMMapDaoImpl.java
@@ -19,17 +19,22 @@ package org.apache.cloudstack.affinity.dao;
 import java.util.List;
 
 import javax.ejb.Local;
+import javax.inject.Inject;
 
 import org.apache.cloudstack.affinity.AffinityGroupVMMapVO;
+import org.apache.cloudstack.affinity.AffinityGroupVO;
 import org.springframework.stereotype.Component;
 
+import com.cloud.host.HostTagVO;
 import com.cloud.utils.Pair;
 import com.cloud.utils.db.Filter;
 import com.cloud.utils.db.GenericDaoBase;
 import com.cloud.utils.db.GenericSearchBuilder;
+import com.cloud.utils.db.JoinBuilder.JoinType;
 import com.cloud.utils.db.SearchBuilder;
 import com.cloud.utils.db.SearchCriteria;
 import com.cloud.utils.db.SearchCriteria.Func;
+import com.cloud.utils.db.Transaction;
 
 @Component
 @Local(value = { AffinityGroupVMMapDao.class })
@@ -40,6 +45,10 @@ public class AffinityGroupVMMapDaoImpl extends GenericDaoBase<AffinityGroupVMMap
     protected GenericSearchBuilder<AffinityGroupVMMapVO, Long> CountSGForVm;
     private GenericSearchBuilder<AffinityGroupVMMapVO, Long> ListVmIdByAffinityGroup;
     private SearchBuilder<AffinityGroupVMMapVO> ListByAffinityGroup;
+    private SearchBuilder<AffinityGroupVMMapVO> ListByVmIdType;
+
+    @Inject
+    protected AffinityGroupDao _affinityGroupDao;
 
     protected AffinityGroupVMMapDaoImpl() {
         ListVmIdByAffinityGroup = createSearchBuilder(Long.class);
@@ -62,6 +71,14 @@ public class AffinityGroupVMMapDaoImpl extends GenericDaoBase<AffinityGroupVMMap
         ListByVmIdGroupId.and("affinityGroupId", ListByVmIdGroupId.entity().getAffinityGroupId(),
SearchCriteria.Op.EQ);
         ListByVmIdGroupId.done();
 
+        ListByVmIdType = createSearchBuilder();
+        ListByVmIdType.and("instanceId", ListByVmIdType.entity().getInstanceId(), SearchCriteria.Op.EQ);
+        SearchBuilder<AffinityGroupVO> groupSearch = _affinityGroupDao.createSearchBuilder();
+        groupSearch.and("type", groupSearch.entity().getType(), SearchCriteria.Op.EQ);
+        ListByVmIdType.join("groupSearch", groupSearch, ListByVmIdType.entity().getAffinityGroupId(),
groupSearch
+                .entity().getId(), JoinType.INNER);
+        ListByVmIdType.done();
+
         CountSGForVm = createSearchBuilder(Long.class);
         CountSGForVm.select(null, Func.COUNT, null);
         CountSGForVm.and("vmId", CountSGForVm.entity().getInstanceId(), SearchCriteria.Op.EQ);
@@ -117,4 +134,30 @@ public class AffinityGroupVMMapDaoImpl extends GenericDaoBase<AffinityGroupVMMap
     	sc.setParameters("vmId", instanceId);
         return customSearch(sc, null).get(0);
 	}
+
+    @Override
+    public AffinityGroupVMMapVO findByVmIdType(long instanceId, String type) {
+        SearchCriteria<AffinityGroupVMMapVO> sc = ListByVmIdType.create();
+        sc.setParameters("instanceId", instanceId);
+        sc.setJoinParameters("groupSearch", "type", type);
+        return customSearch(sc, null).get(0);
+    }
+
+    @Override
+    public void updateMap(Long vmId, List<Long> affinityGroupIds) {
+        Transaction txn = Transaction.currentTxn();
+        txn.start();
+
+        SearchCriteria<AffinityGroupVMMapVO> sc = createSearchCriteria();
+        sc.addAnd("instanceId", SearchCriteria.Op.EQ, vmId);
+        expunge(sc);
+
+        for (Long groupId : affinityGroupIds) {
+            AffinityGroupVMMapVO vo = new AffinityGroupVMMapVO(groupId, vmId);
+            persist(vo);
+        }
+
+        txn.commit();
+
+    }
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/fe2a8687/server/test/com/cloud/vm/MockUserVmManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/test/com/cloud/vm/MockUserVmManagerImpl.java b/server/test/com/cloud/vm/MockUserVmManagerImpl.java
index dd8dd83..fd826d9 100644
--- a/server/test/com/cloud/vm/MockUserVmManagerImpl.java
+++ b/server/test/com/cloud/vm/MockUserVmManagerImpl.java
@@ -253,13 +253,13 @@ public class MockUserVmManagerImpl extends ManagerBase implements UserVmManager,
         // TODO Auto-generated method stub
         return null;
     }
-    
+
     @Override
     public UserVm removeNicFromVirtualMachine(RemoveNicFromVMCmd cmd) throws InvalidParameterValueException,
PermissionDeniedException, CloudRuntimeException {
         // TODO Auto-generated method stub
         return null;
     }
-    
+
     @Override
     public UserVm updateDefaultNicForVirtualMachine(UpdateDefaultNicForVMCmd cmd) throws
InvalidParameterValueException, CloudRuntimeException {
         // TODO Auto-generated method stub
@@ -330,7 +330,9 @@ public class MockUserVmManagerImpl extends ManagerBase implements UserVmManager,
     @Override
     public UserVm createBasicSecurityGroupVirtualMachine(DataCenter zone, ServiceOffering
serviceOffering, VirtualMachineTemplate template, List<Long> securityGroupIdList, Account
owner,
             String hostName, String displayName, Long diskOfferingId, Long diskSize, String
group, HypervisorType hypervisor, String userData, String sshKeyPair, Map<Long, IpAddresses>
requestedIps,
-            IpAddresses defaultIp, String keyboard) throws InsufficientCapacityException,
ConcurrentOperationException, ResourceUnavailableException, StorageUnavailableException,
+ IpAddresses defaultIp,
+            String keyboard, List<Long> affinityGroupIdList) throws InsufficientCapacityException,
+            ConcurrentOperationException, ResourceUnavailableException, StorageUnavailableException,
             ResourceAllocationException {
         // TODO Auto-generated method stub
         return null;
@@ -339,7 +341,9 @@ public class MockUserVmManagerImpl extends ManagerBase implements UserVmManager,
     @Override
     public UserVm createAdvancedSecurityGroupVirtualMachine(DataCenter zone, ServiceOffering
serviceOffering, VirtualMachineTemplate template, List<Long> networkIdList,
             List<Long> securityGroupIdList, Account owner, String hostName, String
displayName, Long diskOfferingId, Long diskSize, String group, HypervisorType hypervisor,
String userData,
-            String sshKeyPair, Map<Long, IpAddresses> requestedIps, IpAddresses defaultIps,
String keyboard) throws InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException,
+ String sshKeyPair, Map<Long, IpAddresses> requestedIps,
+            IpAddresses defaultIps, String keyboard, List<Long> affinityGroupIdList)
+            throws InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException,
             StorageUnavailableException, ResourceAllocationException {
         // TODO Auto-generated method stub
         return null;
@@ -348,7 +352,9 @@ public class MockUserVmManagerImpl extends ManagerBase implements UserVmManager,
     @Override
     public UserVm createAdvancedVirtualMachine(DataCenter zone, ServiceOffering serviceOffering,
VirtualMachineTemplate template, List<Long> networkIdList, Account owner, String hostName,
             String displayName, Long diskOfferingId, Long diskSize, String group, HypervisorType
hypervisor, String userData, String sshKeyPair, Map<Long, IpAddresses> requestedIps,
IpAddresses defaultIps,
-            String keyboard) throws InsufficientCapacityException, ConcurrentOperationException,
ResourceUnavailableException, StorageUnavailableException, ResourceAllocationException {
+            String keyboard, List<Long> affinityGroupIdList) throws InsufficientCapacityException,
+            ConcurrentOperationException, ResourceUnavailableException, StorageUnavailableException,
+            ResourceAllocationException {
         // TODO Auto-generated method stub
         return null;
     }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/fe2a8687/utils/src/com/cloud/utils/SerialVersionUID.java
----------------------------------------------------------------------
diff --git a/utils/src/com/cloud/utils/SerialVersionUID.java b/utils/src/com/cloud/utils/SerialVersionUID.java
index 35e9446..856d563 100755
--- a/utils/src/com/cloud/utils/SerialVersionUID.java
+++ b/utils/src/com/cloud/utils/SerialVersionUID.java
@@ -61,4 +61,5 @@ public interface SerialVersionUID {
     public static final long CloudExecutionException = Base | 0x27;
     public static final long CallFailedException = Base | 0x28;
     public static final long UnableDeleteHostException = Base | 0x29;
+    public static final long AffinityConflictException = Base | 0x2a;
 }


Mime
View raw message