You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by pr...@apache.org on 2013/07/29 23:09:08 UTC

git commit: updated refs/heads/4.2 to 57099c8

Updated Branches:
  refs/heads/4.2 140dfaaa5 -> 57099c8f8


CLOUDSTACK-3904 listHosts API fails in VMware setup when virtualmachineid parameter is passed

Changes:
- Pod and Cluster can be null, modified the query to append these only if non-null


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

Branch: refs/heads/4.2
Commit: 57099c8f8fb0bbd808c91c40ae44bef593aafae2
Parents: 140dfaa
Author: Prachi Damle <pr...@cloud.com>
Authored: Mon Jul 29 14:07:53 2013 -0700
Committer: Prachi Damle <pr...@cloud.com>
Committed: Mon Jul 29 14:08:47 2013 -0700

----------------------------------------------------------------------
 .../src/com/cloud/vm/dao/VMInstanceDaoImpl.java | 30 ++++++++++++++------
 1 file changed, 22 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/57099c8f/engine/schema/src/com/cloud/vm/dao/VMInstanceDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/vm/dao/VMInstanceDaoImpl.java b/engine/schema/src/com/cloud/vm/dao/VMInstanceDaoImpl.java
index e8f98e9..bc3efbb 100644
--- a/engine/schema/src/com/cloud/vm/dao/VMInstanceDaoImpl.java
+++ b/engine/schema/src/com/cloud/vm/dao/VMInstanceDaoImpl.java
@@ -95,15 +95,15 @@ public class VMInstanceDaoImpl extends GenericDaoBase<VMInstanceVO, Long> implem
     private static final String ORDER_CLUSTERS_NUMBER_OF_VMS_FOR_ACCOUNT_PART1 =
             "SELECT host.cluster_id, SUM(IF(vm.state='Running' AND vm.account_id = ?, 1, 0)) FROM `cloud`.`host` host LEFT JOIN `cloud`.`vm_instance` vm ON host.id = vm.host_id WHERE ";
     private static final String ORDER_CLUSTERS_NUMBER_OF_VMS_FOR_ACCOUNT_PART2 =
-            " AND host.type = 'Routing' GROUP BY host.cluster_id ORDER BY 2 ASC ";
+            " AND host.type = 'Routing' AND host.removed is null GROUP BY host.cluster_id ORDER BY 2 ASC ";
 
-    private static final String ORDER_PODS_NUMBER_OF_VMS_FOR_ACCOUNT = "SELECT pod.id, SUM(IF(vm.state='Running' AND vm.account_id = ?, 1, 0)) FROM `cloud`.`host_pod_ref` pod LEFT JOIN `cloud`.`vm_instance` vm ON pod.id = vm.pod_id WHERE pod.data_center_id = ? " +
+    private static final String ORDER_PODS_NUMBER_OF_VMS_FOR_ACCOUNT = "SELECT pod.id, SUM(IF(vm.state='Running' AND vm.account_id = ?, 1, 0)) FROM `cloud`.`host_pod_ref` pod LEFT JOIN `cloud`.`vm_instance` vm ON pod.id = vm.pod_id WHERE pod.data_center_id = ? AND pod.removed is null " +
                                                                        " GROUP BY pod.id ORDER BY 2 ASC ";
 
-    private static final String ORDER_HOSTS_NUMBER_OF_VMS_FOR_ACCOUNT =
-            "SELECT host.id, SUM(IF(vm.state='Running' AND vm.account_id = ?, 1, 0)) FROM `cloud`.`host` host LEFT JOIN `cloud`.`vm_instance` vm ON host.id = vm.host_id WHERE host.data_center_id = ? " +
-    		                                                            " AND host.pod_id = ? AND host.cluster_id = ? AND host.type = 'Routing' " +
-    		                                                            " GROUP BY host.id ORDER BY 2 ASC ";
+    private static final String ORDER_HOSTS_NUMBER_OF_VMS_FOR_ACCOUNT = "SELECT host.id, SUM(IF(vm.state='Running' AND vm.account_id = ?, 1, 0)) FROM `cloud`.`host` host LEFT JOIN `cloud`.`vm_instance` vm ON host.id = vm.host_id WHERE host.data_center_id = ? "
+            + " AND host.type = 'Routing' AND host.removed is null ";
+
+    private static final String ORDER_HOSTS_NUMBER_OF_VMS_FOR_ACCOUNT_PART2 = " GROUP BY host.id ORDER BY 2 ASC ";
 
     @Inject protected HostDao _hostDao;
 
@@ -561,11 +561,25 @@ public class VMInstanceDaoImpl extends GenericDaoBase<VMInstanceVO, Long> implem
         List<Long> result = new ArrayList<Long>();
         try {
             String sql = ORDER_HOSTS_NUMBER_OF_VMS_FOR_ACCOUNT;
+            if (podId != null) {
+                sql = sql + " AND host.pod_id = ? ";
+            }
+
+            if (clusterId != null) {
+                sql = sql + " AND host.cluster_id = ? ";
+            }
+
+            sql = sql + ORDER_HOSTS_NUMBER_OF_VMS_FOR_ACCOUNT_PART2;
+
             pstmt = txn.prepareAutoCloseStatement(sql);
             pstmt.setLong(1, accountId);
             pstmt.setLong(2, dcId);
-            pstmt.setLong(3, podId);
-            pstmt.setLong(4, clusterId);
+            if (podId != null) {
+                pstmt.setLong(3, podId);
+            }
+            if (clusterId != null) {
+                pstmt.setLong(4, clusterId);
+            }
 
             ResultSet rs = pstmt.executeQuery();
             while (rs.next()) {