cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mc...@apache.org
Subject [03/57] [abbrv] Removing ^M's from code.
Date Sat, 06 Apr 2013 00:34:36 GMT
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/469c4dd1/server/src/com/cloud/network/as/dao/AutoScaleVmGroupPolicyMapDaoImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/as/dao/AutoScaleVmGroupPolicyMapDaoImpl.java b/server/src/com/cloud/network/as/dao/AutoScaleVmGroupPolicyMapDaoImpl.java
index b0d064e..ffb3dbc 100644
--- a/server/src/com/cloud/network/as/dao/AutoScaleVmGroupPolicyMapDaoImpl.java
+++ b/server/src/com/cloud/network/as/dao/AutoScaleVmGroupPolicyMapDaoImpl.java
@@ -1,33 +1,33 @@
-// 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.
+// 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.as.dao;
 
 import java.util.List;
 
 import javax.ejb.Local;
-
-import org.springframework.stereotype.Component;
+
+import org.springframework.stereotype.Component;
 
 import com.cloud.network.as.AutoScaleVmGroupPolicyMapVO;
 import com.cloud.utils.db.GenericDaoBase;
 import com.cloud.utils.db.SearchBuilder;
 import com.cloud.utils.db.SearchCriteria;
 import com.cloud.utils.db.SearchCriteria.Op;
-
+
 @Component
 @Local(value={AutoScaleVmGroupPolicyMapDao.class})
 public class AutoScaleVmGroupPolicyMapDaoImpl extends GenericDaoBase<AutoScaleVmGroupPolicyMapVO, Long> implements AutoScaleVmGroupPolicyMapDao {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/469c4dd1/server/src/com/cloud/network/as/dao/AutoScaleVmProfileDao.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/as/dao/AutoScaleVmProfileDao.java b/server/src/com/cloud/network/as/dao/AutoScaleVmProfileDao.java
index d97e848..0855bf7 100644
--- a/server/src/com/cloud/network/as/dao/AutoScaleVmProfileDao.java
+++ b/server/src/com/cloud/network/as/dao/AutoScaleVmProfileDao.java
@@ -1,19 +1,19 @@
-// 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.
+// 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.as.dao;
 
 import com.cloud.network.as.AutoScaleVmProfileVO;

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/469c4dd1/server/src/com/cloud/network/as/dao/AutoScaleVmProfileDaoImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/as/dao/AutoScaleVmProfileDaoImpl.java b/server/src/com/cloud/network/as/dao/AutoScaleVmProfileDaoImpl.java
index 99c3cc2..5d08491 100644
--- a/server/src/com/cloud/network/as/dao/AutoScaleVmProfileDaoImpl.java
+++ b/server/src/com/cloud/network/as/dao/AutoScaleVmProfileDaoImpl.java
@@ -1,29 +1,29 @@
-// 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.
+// 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.as.dao;
 
 import javax.ejb.Local;
-
-import org.springframework.stereotype.Component;
+
+import org.springframework.stereotype.Component;
 
 import com.cloud.network.as.AutoScaleVmProfileVO;
 import com.cloud.utils.db.GenericDaoBase;
 import com.cloud.utils.db.SearchCriteria;
-
+
 @Component
 @Local(value = { AutoScaleVmProfileDao.class })
 public class AutoScaleVmProfileDaoImpl extends GenericDaoBase<AutoScaleVmProfileVO, Long>  implements AutoScaleVmProfileDao {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/469c4dd1/server/src/com/cloud/network/security/dao/SecurityGroupDaoImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/security/dao/SecurityGroupDaoImpl.java b/server/src/com/cloud/network/security/dao/SecurityGroupDaoImpl.java
index dfa6a2e..d82cc4a 100644
--- a/server/src/com/cloud/network/security/dao/SecurityGroupDaoImpl.java
+++ b/server/src/com/cloud/network/security/dao/SecurityGroupDaoImpl.java
@@ -34,20 +34,20 @@ import com.cloud.utils.db.SearchBuilder;
 import com.cloud.utils.db.SearchCriteria;
 import com.cloud.utils.db.Transaction;
 
-@Component
-@Local(value={SecurityGroupDao.class})
-public class SecurityGroupDaoImpl extends GenericDaoBase<SecurityGroupVO, Long> implements SecurityGroupDao {
+@Component
+@Local(value={SecurityGroupDao.class})
+public class SecurityGroupDaoImpl extends GenericDaoBase<SecurityGroupVO, Long> implements SecurityGroupDao {
     private SearchBuilder<SecurityGroupVO> AccountIdSearch;
     private SearchBuilder<SecurityGroupVO> AccountIdNameSearch;
     private SearchBuilder<SecurityGroupVO> AccountIdNamesSearch;
     @Inject ResourceTagDao _tagsDao;
-
-
-    protected SecurityGroupDaoImpl() {
-        AccountIdSearch = createSearchBuilder();
-        AccountIdSearch.and("accountId", AccountIdSearch.entity().getAccountId(), SearchCriteria.Op.EQ);
+
+
+    protected SecurityGroupDaoImpl() {
+        AccountIdSearch = createSearchBuilder();
+        AccountIdSearch.and("accountId", AccountIdSearch.entity().getAccountId(), SearchCriteria.Op.EQ);
         AccountIdSearch.done();
-        
+
         AccountIdNameSearch = createSearchBuilder();
         AccountIdNameSearch.and("accountId", AccountIdNameSearch.entity().getAccountId(), SearchCriteria.Op.EQ);
         AccountIdNameSearch.and("name", AccountIdNameSearch.entity().getName(), SearchCriteria.Op.EQ);
@@ -132,5 +132,5 @@ public class SecurityGroupDaoImpl extends GenericDaoBase<SecurityGroupVO, Long>
         boolean result = super.expunge(id);
         txn.commit();
         return result;
-    }
-}
+    }
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/469c4dd1/server/src/com/cloud/storage/StorageManager.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/storage/StorageManager.java b/server/src/com/cloud/storage/StorageManager.java
index 9213b4b..6026cd9 100755
--- a/server/src/com/cloud/storage/StorageManager.java
+++ b/server/src/com/cloud/storage/StorageManager.java
@@ -120,4 +120,4 @@ public interface StorageManager extends StorageService {
 
     DataStore createLocalStorage(Host host, StoragePoolInfo poolInfo) throws ConnectionException;
 
-}
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/469c4dd1/server/src/com/cloud/storage/dao/VMTemplateDao.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/storage/dao/VMTemplateDao.java b/server/src/com/cloud/storage/dao/VMTemplateDao.java
index c39626f..7263371 100755
--- a/server/src/com/cloud/storage/dao/VMTemplateDao.java
+++ b/server/src/com/cloud/storage/dao/VMTemplateDao.java
@@ -48,11 +48,11 @@ public interface VMTemplateDao extends GenericDao<VMTemplateVO, Long>, StateDao<
 
 	public List<VMTemplateVO> listAllSystemVMTemplates();
 
-	public List<VMTemplateVO> listDefaultBuiltinTemplates();
-	public String getRoutingTemplateUniqueName();
-	public List<VMTemplateVO> findIsosByIdAndPath(Long domainId, Long accountId, String path);
-	public List<VMTemplateVO> listReadyTemplates();
-	public List<VMTemplateVO> listByAccountId(long accountId);
+	public List<VMTemplateVO> listDefaultBuiltinTemplates();
+	public String getRoutingTemplateUniqueName();
+	public List<VMTemplateVO> findIsosByIdAndPath(Long domainId, Long accountId, String path);
+	public List<VMTemplateVO> listReadyTemplates();
+	public List<VMTemplateVO> listByAccountId(long accountId);
 	public Set<Pair<Long, Long>> searchTemplates(String name, String keyword, TemplateFilter templateFilter, boolean isIso,
 	        List<HypervisorType> hypers, Boolean bootable, DomainVO domain, Long pageSize, Long startIndex, Long zoneId,
 	        HypervisorType hyperType, boolean onlyReady, boolean showDomr, List<Account> permittedAccounts, Account caller,

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/469c4dd1/server/src/com/cloud/storage/dao/VMTemplateDaoImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/storage/dao/VMTemplateDaoImpl.java b/server/src/com/cloud/storage/dao/VMTemplateDaoImpl.java
index b51b216..d9a26d3 100755
--- a/server/src/com/cloud/storage/dao/VMTemplateDaoImpl.java
+++ b/server/src/com/cloud/storage/dao/VMTemplateDaoImpl.java
@@ -129,16 +129,16 @@ public class VMTemplateDaoImpl extends GenericDaoBase<VMTemplateVO, Long> implem
 
     @Inject ResourceTagDao _tagsDao;
 
-
-    private String routerTmpltName;
-    private String consoleProxyTmpltName;
-
-    public VMTemplateDaoImpl() {
-    }
-
+
+    private String routerTmpltName;
+    private String consoleProxyTmpltName;
+
+    public VMTemplateDaoImpl() {
+    }
+
     @Override
     public List<VMTemplateVO> listByPublic() {
-    	SearchCriteria<VMTemplateVO> sc = PublicSearch.create();
+	SearchCriteria<VMTemplateVO> sc = PublicSearch.create();
     	sc.setParameters("public", 1);
 	    return listBy(sc);
 	}
@@ -515,8 +515,8 @@ public class VMTemplateDaoImpl extends GenericDaoBase<VMTemplateVO, Long> implem
         return templateZonePairList;
     }
 
-
-	@Override
+
+	@Override
 	public Set<Pair<Long, Long>> searchTemplates(String name, String keyword, TemplateFilter templateFilter,
 	        boolean isIso, List<HypervisorType> hypers, Boolean bootable, DomainVO domain, Long pageSize, Long startIndex,
 	        Long zoneId, HypervisorType hyperType, boolean onlyReady, boolean showDomr,List<Account> permittedAccounts,

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/469c4dd1/server/src/com/cloud/upgrade/dao/Upgrade30xBase.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/upgrade/dao/Upgrade30xBase.java b/server/src/com/cloud/upgrade/dao/Upgrade30xBase.java
index 36ae3c5..723089e 100644
--- a/server/src/com/cloud/upgrade/dao/Upgrade30xBase.java
+++ b/server/src/com/cloud/upgrade/dao/Upgrade30xBase.java
@@ -1,311 +1,311 @@
-// 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.upgrade.dao;
-
-import java.sql.Connection;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.util.UUID;
-
-import org.apache.log4j.Logger;
-
-import com.cloud.utils.exception.CloudRuntimeException;
-
-public abstract class Upgrade30xBase implements DbUpgrade{
-
-    final static Logger s_logger = Logger.getLogger(Upgrade30xBase.class);
-    
-    protected String getNetworkLabelFromConfig(Connection conn, String name){
-        String sql = "SELECT value FROM `cloud`.`configuration` where name = '"+name+"'";
-        String networkLabel = null;
-        PreparedStatement pstmt = null; 
-        ResultSet rs = null;
-        try{
-            pstmt = conn.prepareStatement(sql);
-            rs = pstmt.executeQuery();
-            if (rs.next()) {
-                networkLabel = rs.getString(1);
-            }
-        }catch (SQLException e) {
-            throw new CloudRuntimeException("Unable to fetch network label from configuration", e);
-        }finally{
-            if (rs != null) {
-                try {
-                    rs.close();
-                } catch (SQLException e) {
-                }
-            }
-            if (pstmt != null) {
-                try {
-                    pstmt.close();
-                } catch (SQLException e) {
-                }
-            }
-        }
-        return networkLabel;
-    }
-    
-    
-    protected long addPhysicalNetworkToZone(Connection conn, long zoneId, String zoneName, String networkType, String vnet, Long domainId){
-
-        String getNextNetworkSequenceSql = "SELECT value from `cloud`.`sequence` where name='physical_networks_seq'";
-        String advanceNetworkSequenceSql = "UPDATE `cloud`.`sequence` set value=value+1 where name='physical_networks_seq'";
-        PreparedStatement pstmtUpdate = null, pstmt2 = null;
-        // add p.network
-        try{
-            pstmt2 = conn.prepareStatement(getNextNetworkSequenceSql);
-        
-            ResultSet rsSeq = pstmt2.executeQuery();
-            rsSeq.next();
-    
-            long physicalNetworkId = rsSeq.getLong(1);
-            rsSeq.close();
-            pstmt2.close();
-            pstmt2 = conn.prepareStatement(advanceNetworkSequenceSql);
-            pstmt2.executeUpdate();
-            pstmt2.close();
-    
-            String uuid = UUID.randomUUID().toString();
-            String broadcastDomainRange = "POD";
-            if ("Advanced".equals(networkType)) {
-                broadcastDomainRange = "ZONE";
-            }
-    
-            s_logger.debug("Adding PhysicalNetwork " + physicalNetworkId + " for Zone id " + zoneId);
-            String sql = "INSERT INTO `cloud`.`physical_network` (id, uuid, data_center_id, vnet, broadcast_domain_range, state, name) VALUES (?,?,?,?,?,?,?)";
-            
-            pstmtUpdate = conn.prepareStatement(sql);
-            pstmtUpdate.setLong(1, physicalNetworkId);
-            pstmtUpdate.setString(2, uuid);
-            pstmtUpdate.setLong(3, zoneId);
-            pstmtUpdate.setString(4, vnet);
-            pstmtUpdate.setString(5, broadcastDomainRange);
-            pstmtUpdate.setString(6, "Enabled");
-            zoneName = zoneName + "-pNtwk" +physicalNetworkId;
-            pstmtUpdate.setString(7, zoneName);
-            s_logger.warn("Statement is " + pstmtUpdate.toString());
-            pstmtUpdate.executeUpdate();
-            pstmtUpdate.close();
-            
-            if (domainId != null && domainId.longValue() != 0) {
-                s_logger.debug("Updating domain_id for physical network id=" + physicalNetworkId);
-                sql = "UPDATE `cloud`.`physical_network` set domain_id=? where id=?";
-                pstmtUpdate = conn.prepareStatement(sql);
-                pstmtUpdate.setLong(1, domainId);
-                pstmtUpdate.setLong(2, physicalNetworkId);
-                pstmtUpdate.executeUpdate();
-                pstmtUpdate.close();
-            }
-    
-            return physicalNetworkId;
-        } catch (SQLException e) {
-            throw new CloudRuntimeException("Exception while adding PhysicalNetworks", e);
-        } finally {
-            if (pstmtUpdate != null) {
-                try {
-                    pstmtUpdate.close();
-                } catch (SQLException e) {
-                }
-            }
-            if (pstmt2 != null) {
-                try {
-                    pstmt2.close();
-                } catch (SQLException e) {
-                }
-            }
-
-        }
-    }
-    
-    protected void addTrafficType(Connection conn, long physicalNetworkId, String trafficType, String xenPublicLabel, String kvmPublicLabel, String vmwarePublicLabel){
-        // add traffic types
-        PreparedStatement pstmtUpdate = null;
-        try{
-            s_logger.debug("Adding PhysicalNetwork traffic types");
-            String insertTraficType = "INSERT INTO `cloud`.`physical_network_traffic_types` (physical_network_id, traffic_type, xen_network_label, kvm_network_label, vmware_network_label, uuid) VALUES ( ?, ?, ?, ?, ?, ?)";
-            pstmtUpdate = conn.prepareStatement(insertTraficType);
-            pstmtUpdate.setLong(1, physicalNetworkId);
-            pstmtUpdate.setString(2, trafficType);
-            pstmtUpdate.setString(3, xenPublicLabel);
-            pstmtUpdate.setString(4, kvmPublicLabel);
-            pstmtUpdate.setString(5, vmwarePublicLabel);
-            pstmtUpdate.setString(6, UUID.randomUUID().toString());
-            pstmtUpdate.executeUpdate();
-            pstmtUpdate.close();
-        }catch (SQLException e) {
-            throw new CloudRuntimeException("Exception while adding PhysicalNetworks", e);
-        } finally {
-            if (pstmtUpdate != null) {
-                try {
-                    pstmtUpdate.close();
-                } catch (SQLException e) {
-                }
-            }
-        }
-    }
-    
-    
-    protected void addDefaultSGProvider(Connection conn, long physicalNetworkId, long zoneId, String networkType, boolean is304){
-        PreparedStatement pstmtUpdate = null, pstmt2 = null;
-        try{
-            //add security group service provider (if security group service is enabled for at least one guest network)
-            boolean isSGServiceEnabled = false;
-            String selectSG = "";
-
-            if(is304){
-                 selectSG = "SELECT nm.* FROM `cloud`.`ntwk_service_map` nm JOIN `cloud`.`networks` n ON nm.network_id = n.id where n.data_center_id = ? and nm.service='SecurityGroup'";
-            }else{
-                 selectSG = "SELECT * from `cloud`.`networks` where is_security_group_enabled=1 and data_center_id=?";
-            }
-
-            pstmt2 = conn.prepareStatement(selectSG);
-            pstmt2.setLong(1, zoneId);
-            ResultSet sgDcSet = pstmt2.executeQuery(); 
-            if (sgDcSet.next()) {
-                isSGServiceEnabled = true;
-            }
-            sgDcSet.close();
-            pstmt2.close();
-            
-            if(isSGServiceEnabled){
-                s_logger.debug("Adding PhysicalNetworkServiceProvider SecurityGroupProvider to the physical network id=" + physicalNetworkId);
-                String insertPNSP = "INSERT INTO `cloud`.`physical_network_service_providers` (`uuid`, `physical_network_id` , `provider_name`, `state` ," +
-                        "`destination_physical_network_id`, `vpn_service_provided`, `dhcp_service_provided`, `dns_service_provided`, `gateway_service_provided`," +
-                        "`firewall_service_provided`, `source_nat_service_provided`, `load_balance_service_provided`, `static_nat_service_provided`," +
-                        "`port_forwarding_service_provided`, `user_data_service_provided`, `security_group_service_provided`) VALUES (?,?,?,?,0,0,0,0,0,0,0,0,0,0,0,1)";
-                pstmtUpdate = conn.prepareStatement(insertPNSP);
-                pstmtUpdate.setString(1, UUID.randomUUID().toString());
-                pstmtUpdate.setLong(2, physicalNetworkId);
-                pstmtUpdate.setString(3, "SecurityGroupProvider");
-                pstmtUpdate.setString(4, "Enabled");
-                
-                pstmtUpdate.executeUpdate();
-                pstmtUpdate.close();
-            }
-
-        }catch (SQLException e) {
-            throw new CloudRuntimeException("Exception while adding default Security Group Provider", e);
-        } finally {
-            if (pstmtUpdate != null) {
-                try {
-                    pstmtUpdate.close();
-                } catch (SQLException e) {
-                }
-            }
-            if (pstmt2 != null) {
-                try {
-                    pstmt2.close();
-                } catch (SQLException e) {
-                }
-            }
-        }
-    }
-    
-    protected void addDefaultVRProvider(Connection conn, long physicalNetworkId, long zoneId){
-        PreparedStatement pstmtUpdate = null, pstmt2 = null;
-        try{
-            // add physical network service provider - VirtualRouter
-            s_logger.debug("Adding PhysicalNetworkServiceProvider VirtualRouter");
-            String insertPNSP = "INSERT INTO `cloud`.`physical_network_service_providers` (`uuid`, `physical_network_id` , `provider_name`, `state` ," +
-                    "`destination_physical_network_id`, `vpn_service_provided`, `dhcp_service_provided`, `dns_service_provided`, `gateway_service_provided`," +
-                    "`firewall_service_provided`, `source_nat_service_provided`, `load_balance_service_provided`, `static_nat_service_provided`," +
-                    "`port_forwarding_service_provided`, `user_data_service_provided`, `security_group_service_provided`) VALUES (?,?,?,?,0,1,1,1,1,1,1,1,1,1,1,0)";
-
-            String routerUUID = UUID.randomUUID().toString();
-            pstmtUpdate = conn.prepareStatement(insertPNSP);
-            pstmtUpdate.setString(1, routerUUID );
-            pstmtUpdate.setLong(2, physicalNetworkId);
-            pstmtUpdate.setString(3, "VirtualRouter");
-            pstmtUpdate.setString(4, "Enabled");
-            pstmtUpdate.executeUpdate();
-            pstmtUpdate.close();
-            
-            // add virtual_router_element
-            String fetchNSPid = "SELECT id from `cloud`.`physical_network_service_providers` where physical_network_id=" + physicalNetworkId + " AND provider_name = 'VirtualRouter' AND uuid = ?";
-            pstmt2 = conn.prepareStatement(fetchNSPid);
-            pstmt2.setString(1, routerUUID);
-            ResultSet rsNSPid = pstmt2.executeQuery();
-            rsNSPid.next();
-            long nspId = rsNSPid.getLong(1);
-            pstmt2.close();
-
-            String insertRouter = "INSERT INTO `cloud`.`virtual_router_providers` (`nsp_id`, `uuid` , `type` , `enabled`) " +
-                    "VALUES (?,?,?,?)";
-            pstmtUpdate = conn.prepareStatement(insertRouter);
-            pstmtUpdate.setLong(1, nspId);
-            pstmtUpdate.setString(2, UUID.randomUUID().toString());
-            pstmtUpdate.setString(3, "VirtualRouter");
-            pstmtUpdate.setInt(4, 1);
-            pstmtUpdate.executeUpdate();
-            pstmtUpdate.close();
-        }catch (SQLException e) {
-            throw new CloudRuntimeException("Exception while adding PhysicalNetworks", e);
-        } finally {
-            if (pstmtUpdate != null) {
-                try {
-                    pstmtUpdate.close();
-                } catch (SQLException e) {
-                }
-            }
-            if (pstmt2 != null) {
-                try {
-                    pstmt2.close();
-                } catch (SQLException e) {
-                }
-            }
-        }
-    }
-    
-    protected void addPhysicalNtwk_To_Ntwk_IP_Vlan(Connection conn, long physicalNetworkId, long networkId){
-        PreparedStatement pstmtUpdate = null; 
-        try{
-            // add physicalNetworkId to vlan for this zone
-            String updateVLAN = "UPDATE `cloud`.`vlan` SET physical_network_id = " + physicalNetworkId + " WHERE network_id = " + networkId;
-            pstmtUpdate = conn.prepareStatement(updateVLAN);
-            pstmtUpdate.executeUpdate();
-            pstmtUpdate.close();
-
-            // add physicalNetworkId to user_ip_address for this zone
-            String updateUsrIp = "UPDATE `cloud`.`user_ip_address` SET physical_network_id = " + physicalNetworkId + " WHERE source_network_id = " + networkId;
-            pstmtUpdate = conn.prepareStatement(updateUsrIp);
-            pstmtUpdate.executeUpdate();
-            pstmtUpdate.close();
-
-            // add physicalNetworkId to guest networks for this zone
-            String updateNet = "UPDATE `cloud`.`networks` SET physical_network_id = " + physicalNetworkId + " WHERE id = " + networkId + " AND traffic_type = 'Guest'";
-            pstmtUpdate = conn.prepareStatement(updateNet);
-            pstmtUpdate.executeUpdate();
-            pstmtUpdate.close();
-        }catch (SQLException e) {
-            throw new CloudRuntimeException("Exception while adding PhysicalNetworks", e);
-        } finally {
-            if (pstmtUpdate != null) {
-                try {
-                    pstmtUpdate.close();
-                } catch (SQLException e) {
-                }
-            }
-        }
-            
-    }
-    
-    
-    
-    
-}
+// 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.upgrade.dao;
+
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.UUID;
+
+import org.apache.log4j.Logger;
+
+import com.cloud.utils.exception.CloudRuntimeException;
+
+public abstract class Upgrade30xBase implements DbUpgrade{
+
+    final static Logger s_logger = Logger.getLogger(Upgrade30xBase.class);
+
+    protected String getNetworkLabelFromConfig(Connection conn, String name){
+        String sql = "SELECT value FROM `cloud`.`configuration` where name = '"+name+"'";
+        String networkLabel = null;
+        PreparedStatement pstmt = null;
+        ResultSet rs = null;
+        try{
+            pstmt = conn.prepareStatement(sql);
+            rs = pstmt.executeQuery();
+            if (rs.next()) {
+                networkLabel = rs.getString(1);
+            }
+        }catch (SQLException e) {
+            throw new CloudRuntimeException("Unable to fetch network label from configuration", e);
+        }finally{
+            if (rs != null) {
+                try {
+                    rs.close();
+                } catch (SQLException e) {
+                }
+            }
+            if (pstmt != null) {
+                try {
+                    pstmt.close();
+                } catch (SQLException e) {
+                }
+            }
+        }
+        return networkLabel;
+    }
+
+
+    protected long addPhysicalNetworkToZone(Connection conn, long zoneId, String zoneName, String networkType, String vnet, Long domainId){
+
+        String getNextNetworkSequenceSql = "SELECT value from `cloud`.`sequence` where name='physical_networks_seq'";
+        String advanceNetworkSequenceSql = "UPDATE `cloud`.`sequence` set value=value+1 where name='physical_networks_seq'";
+        PreparedStatement pstmtUpdate = null, pstmt2 = null;
+        // add p.network
+        try{
+            pstmt2 = conn.prepareStatement(getNextNetworkSequenceSql);
+
+            ResultSet rsSeq = pstmt2.executeQuery();
+            rsSeq.next();
+
+            long physicalNetworkId = rsSeq.getLong(1);
+            rsSeq.close();
+            pstmt2.close();
+            pstmt2 = conn.prepareStatement(advanceNetworkSequenceSql);
+            pstmt2.executeUpdate();
+            pstmt2.close();
+
+            String uuid = UUID.randomUUID().toString();
+            String broadcastDomainRange = "POD";
+            if ("Advanced".equals(networkType)) {
+                broadcastDomainRange = "ZONE";
+            }
+
+            s_logger.debug("Adding PhysicalNetwork " + physicalNetworkId + " for Zone id " + zoneId);
+            String sql = "INSERT INTO `cloud`.`physical_network` (id, uuid, data_center_id, vnet, broadcast_domain_range, state, name) VALUES (?,?,?,?,?,?,?)";
+
+            pstmtUpdate = conn.prepareStatement(sql);
+            pstmtUpdate.setLong(1, physicalNetworkId);
+            pstmtUpdate.setString(2, uuid);
+            pstmtUpdate.setLong(3, zoneId);
+            pstmtUpdate.setString(4, vnet);
+            pstmtUpdate.setString(5, broadcastDomainRange);
+            pstmtUpdate.setString(6, "Enabled");
+            zoneName = zoneName + "-pNtwk" +physicalNetworkId;
+            pstmtUpdate.setString(7, zoneName);
+            s_logger.warn("Statement is " + pstmtUpdate.toString());
+            pstmtUpdate.executeUpdate();
+            pstmtUpdate.close();
+
+            if (domainId != null && domainId.longValue() != 0) {
+                s_logger.debug("Updating domain_id for physical network id=" + physicalNetworkId);
+                sql = "UPDATE `cloud`.`physical_network` set domain_id=? where id=?";
+                pstmtUpdate = conn.prepareStatement(sql);
+                pstmtUpdate.setLong(1, domainId);
+                pstmtUpdate.setLong(2, physicalNetworkId);
+                pstmtUpdate.executeUpdate();
+                pstmtUpdate.close();
+            }
+
+            return physicalNetworkId;
+        } catch (SQLException e) {
+            throw new CloudRuntimeException("Exception while adding PhysicalNetworks", e);
+        } finally {
+            if (pstmtUpdate != null) {
+                try {
+                    pstmtUpdate.close();
+                } catch (SQLException e) {
+                }
+            }
+            if (pstmt2 != null) {
+                try {
+                    pstmt2.close();
+                } catch (SQLException e) {
+                }
+            }
+
+        }
+    }
+
+    protected void addTrafficType(Connection conn, long physicalNetworkId, String trafficType, String xenPublicLabel, String kvmPublicLabel, String vmwarePublicLabel){
+        // add traffic types
+        PreparedStatement pstmtUpdate = null;
+        try{
+            s_logger.debug("Adding PhysicalNetwork traffic types");
+            String insertTraficType = "INSERT INTO `cloud`.`physical_network_traffic_types` (physical_network_id, traffic_type, xen_network_label, kvm_network_label, vmware_network_label, uuid) VALUES ( ?, ?, ?, ?, ?, ?)";
+            pstmtUpdate = conn.prepareStatement(insertTraficType);
+            pstmtUpdate.setLong(1, physicalNetworkId);
+            pstmtUpdate.setString(2, trafficType);
+            pstmtUpdate.setString(3, xenPublicLabel);
+            pstmtUpdate.setString(4, kvmPublicLabel);
+            pstmtUpdate.setString(5, vmwarePublicLabel);
+            pstmtUpdate.setString(6, UUID.randomUUID().toString());
+            pstmtUpdate.executeUpdate();
+            pstmtUpdate.close();
+        }catch (SQLException e) {
+            throw new CloudRuntimeException("Exception while adding PhysicalNetworks", e);
+        } finally {
+            if (pstmtUpdate != null) {
+                try {
+                    pstmtUpdate.close();
+                } catch (SQLException e) {
+                }
+            }
+        }
+    }
+
+
+    protected void addDefaultSGProvider(Connection conn, long physicalNetworkId, long zoneId, String networkType, boolean is304){
+        PreparedStatement pstmtUpdate = null, pstmt2 = null;
+        try{
+            //add security group service provider (if security group service is enabled for at least one guest network)
+            boolean isSGServiceEnabled = false;
+            String selectSG = "";
+
+            if(is304){
+                 selectSG = "SELECT nm.* FROM `cloud`.`ntwk_service_map` nm JOIN `cloud`.`networks` n ON nm.network_id = n.id where n.data_center_id = ? and nm.service='SecurityGroup'";
+            }else{
+                 selectSG = "SELECT * from `cloud`.`networks` where is_security_group_enabled=1 and data_center_id=?";
+            }
+
+            pstmt2 = conn.prepareStatement(selectSG);
+            pstmt2.setLong(1, zoneId);
+            ResultSet sgDcSet = pstmt2.executeQuery();
+            if (sgDcSet.next()) {
+                isSGServiceEnabled = true;
+            }
+            sgDcSet.close();
+            pstmt2.close();
+
+            if(isSGServiceEnabled){
+                s_logger.debug("Adding PhysicalNetworkServiceProvider SecurityGroupProvider to the physical network id=" + physicalNetworkId);
+                String insertPNSP = "INSERT INTO `cloud`.`physical_network_service_providers` (`uuid`, `physical_network_id` , `provider_name`, `state` ," +
+                        "`destination_physical_network_id`, `vpn_service_provided`, `dhcp_service_provided`, `dns_service_provided`, `gateway_service_provided`," +
+                        "`firewall_service_provided`, `source_nat_service_provided`, `load_balance_service_provided`, `static_nat_service_provided`," +
+                        "`port_forwarding_service_provided`, `user_data_service_provided`, `security_group_service_provided`) VALUES (?,?,?,?,0,0,0,0,0,0,0,0,0,0,0,1)";
+                pstmtUpdate = conn.prepareStatement(insertPNSP);
+                pstmtUpdate.setString(1, UUID.randomUUID().toString());
+                pstmtUpdate.setLong(2, physicalNetworkId);
+                pstmtUpdate.setString(3, "SecurityGroupProvider");
+                pstmtUpdate.setString(4, "Enabled");
+
+                pstmtUpdate.executeUpdate();
+                pstmtUpdate.close();
+            }
+
+        }catch (SQLException e) {
+            throw new CloudRuntimeException("Exception while adding default Security Group Provider", e);
+        } finally {
+            if (pstmtUpdate != null) {
+                try {
+                    pstmtUpdate.close();
+                } catch (SQLException e) {
+                }
+            }
+            if (pstmt2 != null) {
+                try {
+                    pstmt2.close();
+                } catch (SQLException e) {
+                }
+            }
+        }
+    }
+
+    protected void addDefaultVRProvider(Connection conn, long physicalNetworkId, long zoneId){
+        PreparedStatement pstmtUpdate = null, pstmt2 = null;
+        try{
+            // add physical network service provider - VirtualRouter
+            s_logger.debug("Adding PhysicalNetworkServiceProvider VirtualRouter");
+            String insertPNSP = "INSERT INTO `cloud`.`physical_network_service_providers` (`uuid`, `physical_network_id` , `provider_name`, `state` ," +
+                    "`destination_physical_network_id`, `vpn_service_provided`, `dhcp_service_provided`, `dns_service_provided`, `gateway_service_provided`," +
+                    "`firewall_service_provided`, `source_nat_service_provided`, `load_balance_service_provided`, `static_nat_service_provided`," +
+                    "`port_forwarding_service_provided`, `user_data_service_provided`, `security_group_service_provided`) VALUES (?,?,?,?,0,1,1,1,1,1,1,1,1,1,1,0)";
+
+            String routerUUID = UUID.randomUUID().toString();
+            pstmtUpdate = conn.prepareStatement(insertPNSP);
+            pstmtUpdate.setString(1, routerUUID );
+            pstmtUpdate.setLong(2, physicalNetworkId);
+            pstmtUpdate.setString(3, "VirtualRouter");
+            pstmtUpdate.setString(4, "Enabled");
+            pstmtUpdate.executeUpdate();
+            pstmtUpdate.close();
+
+            // add virtual_router_element
+            String fetchNSPid = "SELECT id from `cloud`.`physical_network_service_providers` where physical_network_id=" + physicalNetworkId + " AND provider_name = 'VirtualRouter' AND uuid = ?";
+            pstmt2 = conn.prepareStatement(fetchNSPid);
+            pstmt2.setString(1, routerUUID);
+            ResultSet rsNSPid = pstmt2.executeQuery();
+            rsNSPid.next();
+            long nspId = rsNSPid.getLong(1);
+            pstmt2.close();
+
+            String insertRouter = "INSERT INTO `cloud`.`virtual_router_providers` (`nsp_id`, `uuid` , `type` , `enabled`) " +
+                    "VALUES (?,?,?,?)";
+            pstmtUpdate = conn.prepareStatement(insertRouter);
+            pstmtUpdate.setLong(1, nspId);
+            pstmtUpdate.setString(2, UUID.randomUUID().toString());
+            pstmtUpdate.setString(3, "VirtualRouter");
+            pstmtUpdate.setInt(4, 1);
+            pstmtUpdate.executeUpdate();
+            pstmtUpdate.close();
+        }catch (SQLException e) {
+            throw new CloudRuntimeException("Exception while adding PhysicalNetworks", e);
+        } finally {
+            if (pstmtUpdate != null) {
+                try {
+                    pstmtUpdate.close();
+                } catch (SQLException e) {
+                }
+            }
+            if (pstmt2 != null) {
+                try {
+                    pstmt2.close();
+                } catch (SQLException e) {
+                }
+            }
+        }
+    }
+
+    protected void addPhysicalNtwk_To_Ntwk_IP_Vlan(Connection conn, long physicalNetworkId, long networkId){
+        PreparedStatement pstmtUpdate = null;
+        try{
+            // add physicalNetworkId to vlan for this zone
+            String updateVLAN = "UPDATE `cloud`.`vlan` SET physical_network_id = " + physicalNetworkId + " WHERE network_id = " + networkId;
+            pstmtUpdate = conn.prepareStatement(updateVLAN);
+            pstmtUpdate.executeUpdate();
+            pstmtUpdate.close();
+
+            // add physicalNetworkId to user_ip_address for this zone
+            String updateUsrIp = "UPDATE `cloud`.`user_ip_address` SET physical_network_id = " + physicalNetworkId + " WHERE source_network_id = " + networkId;
+            pstmtUpdate = conn.prepareStatement(updateUsrIp);
+            pstmtUpdate.executeUpdate();
+            pstmtUpdate.close();
+
+            // add physicalNetworkId to guest networks for this zone
+            String updateNet = "UPDATE `cloud`.`networks` SET physical_network_id = " + physicalNetworkId + " WHERE id = " + networkId + " AND traffic_type = 'Guest'";
+            pstmtUpdate = conn.prepareStatement(updateNet);
+            pstmtUpdate.executeUpdate();
+            pstmtUpdate.close();
+        }catch (SQLException e) {
+            throw new CloudRuntimeException("Exception while adding PhysicalNetworks", e);
+        } finally {
+            if (pstmtUpdate != null) {
+                try {
+                    pstmtUpdate.close();
+                } catch (SQLException e) {
+                }
+            }
+        }
+
+    }
+
+
+
+
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/469c4dd1/server/src/com/cloud/vm/dao/UserVmDaoImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/vm/dao/UserVmDaoImpl.java b/server/src/com/cloud/vm/dao/UserVmDaoImpl.java
index 4922828..c2fd648 100755
--- a/server/src/com/cloud/vm/dao/UserVmDaoImpl.java
+++ b/server/src/com/cloud/vm/dao/UserVmDaoImpl.java
@@ -55,24 +55,24 @@ import com.cloud.vm.VirtualMachine.State;
 import com.cloud.vm.dao.UserVmData.NicData;
 import com.cloud.vm.dao.UserVmData.SecurityGroupData;
 
-
-@Local(value={UserVmDao.class})
-public class UserVmDaoImpl extends GenericDaoBase<UserVmVO, Long> implements UserVmDao {
-    public static final Logger s_logger = Logger.getLogger(UserVmDaoImpl.class);
-    
-    protected SearchBuilder<UserVmVO> AccountPodSearch;
-    protected SearchBuilder<UserVmVO> AccountDataCenterSearch;
-    protected SearchBuilder<UserVmVO> AccountSearch;
-    protected SearchBuilder<UserVmVO> HostSearch;
-    protected SearchBuilder<UserVmVO> LastHostSearch;
-    protected SearchBuilder<UserVmVO> HostUpSearch;
-    protected SearchBuilder<UserVmVO> HostRunningSearch;
-    protected SearchBuilder<UserVmVO> StateChangeSearch;
-    protected SearchBuilder<UserVmVO> AccountHostSearch;
-
-    protected SearchBuilder<UserVmVO> DestroySearch;
-    protected SearchBuilder<UserVmVO> AccountDataCenterVirtualSearch;
-    protected GenericSearchBuilder<UserVmVO, Long> CountByAccountPod;
+
+@Local(value={UserVmDao.class})
+public class UserVmDaoImpl extends GenericDaoBase<UserVmVO, Long> implements UserVmDao {
+    public static final Logger s_logger = Logger.getLogger(UserVmDaoImpl.class);
+
+    protected SearchBuilder<UserVmVO> AccountPodSearch;
+    protected SearchBuilder<UserVmVO> AccountDataCenterSearch;
+    protected SearchBuilder<UserVmVO> AccountSearch;
+    protected SearchBuilder<UserVmVO> HostSearch;
+    protected SearchBuilder<UserVmVO> LastHostSearch;
+    protected SearchBuilder<UserVmVO> HostUpSearch;
+    protected SearchBuilder<UserVmVO> HostRunningSearch;
+    protected SearchBuilder<UserVmVO> StateChangeSearch;
+    protected SearchBuilder<UserVmVO> AccountHostSearch;
+
+    protected SearchBuilder<UserVmVO> DestroySearch;
+    protected SearchBuilder<UserVmVO> AccountDataCenterVirtualSearch;
+    protected GenericSearchBuilder<UserVmVO, Long> CountByAccountPod;
     protected GenericSearchBuilder<UserVmVO, Long> CountByAccount;
     protected GenericSearchBuilder<UserVmVO, Long> PodsHavingVmsForAccount;
 
@@ -81,46 +81,46 @@ public class UserVmDaoImpl extends GenericDaoBase<UserVmVO, Long> implements Use
     protected Attribute _updateTimeAttr;
     // ResourceTagsDaoImpl _tagsDao = ComponentLocator.inject(ResourceTagsDaoImpl.class);
     @Inject ResourceTagDao _tagsDao;
-   
-    private static final String LIST_PODS_HAVING_VMS_FOR_ACCOUNT = "SELECT pod_id FROM cloud.vm_instance WHERE data_center_id = ? AND account_id = ? AND pod_id IS NOT NULL AND (state = 'Running' OR state = 'Stopped') " +
-    		"GROUP BY pod_id HAVING count(id) > 0 ORDER BY count(id) DESC";
-    
-    private static String VM_DETAILS = "select vm_instance.id, " +
-            "account.id, account.account_name, account.type, domain.name, instance_group.id, instance_group.name," +
-            "data_center.id, data_center.name, data_center.is_security_group_enabled, host.id, host.name, " + 
-            "vm_template.id, vm_template.name, vm_template.display_text, iso.id, iso.name, " +
-            "vm_template.enable_password, service_offering.id, disk_offering.name, storage_pool.id, storage_pool.pool_type, " +
-            "service_offering.cpu, service_offering.speed, service_offering.ram_size, volumes.id, volumes.device_id, volumes.volume_type, security_group.id, security_group.name, " +
-            "security_group.description, nics.id, nics.ip4_address, nics.default_nic, nics.gateway, nics.network_id, nics.netmask, nics.mac_address, nics.broadcast_uri, nics.isolation_uri, " +
-            "networks.traffic_type, networks.guest_type, user_ip_address.id, user_ip_address.public_ip_address from vm_instance " +
-            "left join account on vm_instance.account_id=account.id  " +
-            "left join domain on vm_instance.domain_id=domain.id " +
-            "left join instance_group_vm_map on vm_instance.id=instance_group_vm_map.instance_id " +
-            "left join instance_group on instance_group_vm_map.group_id=instance_group.id " + 
-            "left join data_center on vm_instance.data_center_id=data_center.id " +
-            "left join host on vm_instance.host_id=host.id " + 
-            "left join vm_template on vm_instance.vm_template_id=vm_template.id " +
-            "left join user_vm on vm_instance.id=user_vm.id " +
-            "left join vm_template iso on iso.id=user_vm.iso_id " +  
-            "left join service_offering on vm_instance.service_offering_id=service_offering.id " +
-            "left join disk_offering  on vm_instance.service_offering_id=disk_offering.id " +
-            "left join volumes on vm_instance.id=volumes.instance_id " +
-            "left join storage_pool on volumes.pool_id=storage_pool.id " +
-            "left join security_group_vm_map on vm_instance.id=security_group_vm_map.instance_id " +
-            "left join security_group on security_group_vm_map.security_group_id=security_group.id " +
-            "left join nics on vm_instance.id=nics.instance_id " +
-            "left join networks on nics.network_id=networks.id " +
-            "left join user_ip_address on user_ip_address.vm_id=vm_instance.id " +
-            "where vm_instance.id in (";
-            
-    private static final int VM_DETAILS_BATCH_SIZE=100;
-   
-    @Inject protected UserVmDetailsDao _detailsDao;
-    @Inject protected NicDao _nicDao;
-    
-    public UserVmDaoImpl() {
+
+    private static final String LIST_PODS_HAVING_VMS_FOR_ACCOUNT = "SELECT pod_id FROM cloud.vm_instance WHERE data_center_id = ? AND account_id = ? AND pod_id IS NOT NULL AND (state = 'Running' OR state = 'Stopped') " +
+		"GROUP BY pod_id HAVING count(id) > 0 ORDER BY count(id) DESC";
+
+    private static String VM_DETAILS = "select vm_instance.id, " +
+            "account.id, account.account_name, account.type, domain.name, instance_group.id, instance_group.name," +
+            "data_center.id, data_center.name, data_center.is_security_group_enabled, host.id, host.name, " +
+            "vm_template.id, vm_template.name, vm_template.display_text, iso.id, iso.name, " +
+            "vm_template.enable_password, service_offering.id, disk_offering.name, storage_pool.id, storage_pool.pool_type, " +
+            "service_offering.cpu, service_offering.speed, service_offering.ram_size, volumes.id, volumes.device_id, volumes.volume_type, security_group.id, security_group.name, " +
+            "security_group.description, nics.id, nics.ip4_address, nics.default_nic, nics.gateway, nics.network_id, nics.netmask, nics.mac_address, nics.broadcast_uri, nics.isolation_uri, " +
+            "networks.traffic_type, networks.guest_type, user_ip_address.id, user_ip_address.public_ip_address from vm_instance " +
+            "left join account on vm_instance.account_id=account.id  " +
+            "left join domain on vm_instance.domain_id=domain.id " +
+            "left join instance_group_vm_map on vm_instance.id=instance_group_vm_map.instance_id " +
+            "left join instance_group on instance_group_vm_map.group_id=instance_group.id " +
+            "left join data_center on vm_instance.data_center_id=data_center.id " +
+            "left join host on vm_instance.host_id=host.id " +
+            "left join vm_template on vm_instance.vm_template_id=vm_template.id " +
+            "left join user_vm on vm_instance.id=user_vm.id " +
+            "left join vm_template iso on iso.id=user_vm.iso_id " +
+            "left join service_offering on vm_instance.service_offering_id=service_offering.id " +
+            "left join disk_offering  on vm_instance.service_offering_id=disk_offering.id " +
+            "left join volumes on vm_instance.id=volumes.instance_id " +
+            "left join storage_pool on volumes.pool_id=storage_pool.id " +
+            "left join security_group_vm_map on vm_instance.id=security_group_vm_map.instance_id " +
+            "left join security_group on security_group_vm_map.security_group_id=security_group.id " +
+            "left join nics on vm_instance.id=nics.instance_id " +
+            "left join networks on nics.network_id=networks.id " +
+            "left join user_ip_address on user_ip_address.vm_id=vm_instance.id " +
+            "where vm_instance.id in (";
+
+    private static final int VM_DETAILS_BATCH_SIZE=100;
+
+    @Inject protected UserVmDetailsDao _detailsDao;
+    @Inject protected NicDao _nicDao;
+
+    public UserVmDaoImpl() {
     }
-    
+
     @PostConstruct
     void init() {
         AccountSearch = createSearchBuilder();
@@ -203,56 +203,56 @@ public class UserVmDaoImpl extends GenericDaoBase<UserVmVO, Long> implements Use
 
         _updateTimeAttr = _allAttributes.get("updateTime");
         assert _updateTimeAttr != null : "Couldn't get this updateTime attribute";
-    }
-    
-    @Override
-    public List<UserVmVO> listByAccountAndPod(long accountId, long podId) {
-    	SearchCriteria<UserVmVO> sc = AccountPodSearch.create();
-    	sc.setParameters("account", accountId);
-    	sc.setParameters("pod", podId);
-    	
-    	return listIncludingRemovedBy(sc);
-    }
-    
-    @Override
-    public List<UserVmVO> listByAccountAndDataCenter(long accountId, long dcId) {
-        SearchCriteria<UserVmVO> sc = AccountDataCenterSearch.create();
-        sc.setParameters("account", accountId);
-        sc.setParameters("dc", dcId);
-        
-        return listIncludingRemovedBy(sc);
-    }
-    
-    @Override
-    public void updateVM(long id, String displayName, boolean enable, Long osTypeId, String userData) {
-        UserVmVO vo = createForUpdate();
-        vo.setDisplayName(displayName);
-        vo.setHaEnabled(enable);
-        vo.setGuestOSId(osTypeId);
-        vo.setUserData(userData);
-        update(id, vo);
-    }
-    
-    @Override
-    public List<UserVmVO> findDestroyedVms(Date date) {
-    	SearchCriteria<UserVmVO> sc = DestroySearch.create();
-    	sc.setParameters("state", State.Destroyed, State.Expunging, State.Error);
-    	sc.setParameters("updateTime", date);
-    	
-    	return listBy(sc);
-    }
-    
-    @Override
-    public List<UserVmVO> listByAccountId(long id) {
-        SearchCriteria<UserVmVO> sc = AccountSearch.create();
-        sc.setParameters("account", id);
-        return listBy(sc);
-    }
-    
-    @Override
-    public List<UserVmVO> listByHostId(Long id) {
-        SearchCriteria<UserVmVO> sc = HostSearch.create();
-        sc.setParameters("host", id);
+    }
+
+    @Override
+    public List<UserVmVO> listByAccountAndPod(long accountId, long podId) {
+	SearchCriteria<UserVmVO> sc = AccountPodSearch.create();
+	sc.setParameters("account", accountId);
+	sc.setParameters("pod", podId);
+
+	return listIncludingRemovedBy(sc);
+    }
+
+    @Override
+    public List<UserVmVO> listByAccountAndDataCenter(long accountId, long dcId) {
+        SearchCriteria<UserVmVO> sc = AccountDataCenterSearch.create();
+        sc.setParameters("account", accountId);
+        sc.setParameters("dc", dcId);
+
+        return listIncludingRemovedBy(sc);
+    }
+
+    @Override
+    public void updateVM(long id, String displayName, boolean enable, Long osTypeId, String userData) {
+        UserVmVO vo = createForUpdate();
+        vo.setDisplayName(displayName);
+        vo.setHaEnabled(enable);
+        vo.setGuestOSId(osTypeId);
+        vo.setUserData(userData);
+        update(id, vo);
+    }
+
+    @Override
+    public List<UserVmVO> findDestroyedVms(Date date) {
+	SearchCriteria<UserVmVO> sc = DestroySearch.create();
+	sc.setParameters("state", State.Destroyed, State.Expunging, State.Error);
+	sc.setParameters("updateTime", date);
+
+	return listBy(sc);
+    }
+
+    @Override
+    public List<UserVmVO> listByAccountId(long id) {
+        SearchCriteria<UserVmVO> sc = AccountSearch.create();
+        sc.setParameters("account", id);
+        return listBy(sc);
+    }
+
+    @Override
+    public List<UserVmVO> listByHostId(Long id) {
+        SearchCriteria<UserVmVO> sc = HostSearch.create();
+        sc.setParameters("host", id);
 
         return listBy(sc);
     }
@@ -267,311 +267,311 @@ public class UserVmDaoImpl extends GenericDaoBase<UserVmVO, Long> implements Use
     @Override
     public List<UserVmVO> listUpByHostId(Long hostId) {
         SearchCriteria<UserVmVO> sc = HostUpSearch.create();
-        sc.setParameters("host", hostId);
-        sc.setParameters("states", new Object[] {State.Destroyed, State.Stopped, State.Expunging});
-        return listBy(sc);
-    }
-    
-    @Override
-    public List<UserVmVO> listRunningByHostId(long hostId) {
-        SearchCriteria<UserVmVO> sc = HostRunningSearch.create();
-        sc.setParameters("host", hostId);
-        sc.setParameters("state", State.Running);
-        
-        return listBy(sc);
-    }
-
-    @Override
-    public List<UserVmVO> listVirtualNetworkInstancesByAcctAndZone(long accountId, long dcId, long networkId) {
-
-        SearchCriteria<UserVmVO> sc = AccountDataCenterVirtualSearch.create();
-        sc.setParameters("account", accountId);
-        sc.setParameters("dc", dcId);
-        sc.setJoinParameters("nicSearch", "networkId", networkId);
-
-        return listBy(sc);
-    }
-    
-    @Override
-    public List<UserVmVO> listByNetworkIdAndStates(long networkId, State... states) {
-        if (UserVmSearch == null) {
-            SearchBuilder<NicVO> nicSearch = _nicDao.createSearchBuilder();
-            nicSearch.and("networkId", nicSearch.entity().getNetworkId(), SearchCriteria.Op.EQ);
+        sc.setParameters("host", hostId);
+        sc.setParameters("states", new Object[] {State.Destroyed, State.Stopped, State.Expunging});
+        return listBy(sc);
+    }
+
+    @Override
+    public List<UserVmVO> listRunningByHostId(long hostId) {
+        SearchCriteria<UserVmVO> sc = HostRunningSearch.create();
+        sc.setParameters("host", hostId);
+        sc.setParameters("state", State.Running);
+
+        return listBy(sc);
+    }
+
+    @Override
+    public List<UserVmVO> listVirtualNetworkInstancesByAcctAndZone(long accountId, long dcId, long networkId) {
+
+        SearchCriteria<UserVmVO> sc = AccountDataCenterVirtualSearch.create();
+        sc.setParameters("account", accountId);
+        sc.setParameters("dc", dcId);
+        sc.setJoinParameters("nicSearch", "networkId", networkId);
+
+        return listBy(sc);
+    }
+
+    @Override
+    public List<UserVmVO> listByNetworkIdAndStates(long networkId, State... states) {
+        if (UserVmSearch == null) {
+            SearchBuilder<NicVO> nicSearch = _nicDao.createSearchBuilder();
+            nicSearch.and("networkId", nicSearch.entity().getNetworkId(), SearchCriteria.Op.EQ);
             nicSearch.and().op("ip4Address", nicSearch.entity().getIp4Address(), SearchCriteria.Op.NNULL);
             nicSearch.or("ip6Address", nicSearch.entity().getIp6Address(), SearchCriteria.Op.NNULL);
             nicSearch.cp();
-
-            UserVmSearch = createSearchBuilder();
-            UserVmSearch.and("states", UserVmSearch.entity().getState(), SearchCriteria.Op.IN);
-            UserVmSearch.join("nicSearch", nicSearch, UserVmSearch.entity().getId(), nicSearch.entity().getInstanceId(), JoinBuilder.JoinType.INNER);
-            UserVmSearch.done();
-        }
-
-        SearchCriteria<UserVmVO> sc = UserVmSearch.create();
-        if (states != null && states.length != 0) {
-            sc.setParameters("states", (Object[]) states);
-        }
-        sc.setJoinParameters("nicSearch", "networkId", networkId);
-
-        return listBy(sc);
-    }
-
-	@Override
-	public List<UserVmVO> listByLastHostId(Long hostId) {
-		SearchCriteria<UserVmVO> sc = LastHostSearch.create();
-		sc.setParameters("lastHost", hostId);
-		sc.setParameters("state", State.Stopped);
-		return listBy(sc);
-	}
-	
-	@Override
-	public List<UserVmVO> listByAccountIdAndHostId(long accountId, long hostId) {
-		SearchCriteria<UserVmVO> sc = AccountHostSearch.create();
-		sc.setParameters("hostId", hostId);
-		sc.setParameters("accountId", accountId);
-		return listBy(sc);
-	}
-
-	@Override
-	public void loadDetails(UserVmVO vm) {
-        Map<String, String> details = _detailsDao.findDetails(vm.getId());
-        vm.setDetails(details);
-	}
-	
-	@Override
-    public void saveDetails(UserVmVO vm) {
-        Map<String, String> details = vm.getDetails();
-        if (details == null) {
-            return;
-        }
-        _detailsDao.persist(vm.getId(), details);
-    }
-	
-    @Override
-    public List<Long> listPodIdsHavingVmsforAccount(long zoneId, long accountId){
-    	Transaction txn = Transaction.currentTxn();
-        PreparedStatement pstmt = null;
-        List<Long> result = new ArrayList<Long>();
-
-        try {
-            String sql = LIST_PODS_HAVING_VMS_FOR_ACCOUNT;
-            pstmt = txn.prepareAutoCloseStatement(sql);
-            pstmt.setLong(1, zoneId);
-            pstmt.setLong(2, accountId);
-            
-            ResultSet rs = pstmt.executeQuery();
-            while (rs.next()) {
-                result.add(rs.getLong(1));
-            }
-            return result;
-        } catch (SQLException e) {
-            throw new CloudRuntimeException("DB Exception on: " + LIST_PODS_HAVING_VMS_FOR_ACCOUNT, e);
-        } catch (Throwable e) {
-            throw new CloudRuntimeException("Caught: " + LIST_PODS_HAVING_VMS_FOR_ACCOUNT, e);
-        }
-    }
-    
-    @Override
-    public Hashtable<Long, UserVmData> listVmDetails(Hashtable<Long, UserVmData> userVmDataHash){
-        Transaction txn = Transaction.currentTxn();
-        PreparedStatement pstmt = null;      
-        
-        try {
-            int curr_index=0;
-            
-            List<UserVmData> userVmDataList = new ArrayList(userVmDataHash.values()); 
-            
-            if (userVmDataList.size() > VM_DETAILS_BATCH_SIZE){
-                pstmt = txn.prepareStatement(VM_DETAILS + getQueryBatchAppender(VM_DETAILS_BATCH_SIZE));
-                while ( (curr_index + VM_DETAILS_BATCH_SIZE) <= userVmDataList.size()){
-                    // set the vars value
-                    for (int k=1,j=curr_index;j<curr_index+VM_DETAILS_BATCH_SIZE;j++,k++){
-                        pstmt.setLong(k, userVmDataList.get(j).getId());
-                    }
-                    ResultSet rs = pstmt.executeQuery();
-                    while(rs.next()){
-                        long vm_id=rs.getLong("vm_instance.id");
-                        //check if the entry is already there
-                        UserVmData uvm=userVmDataHash.get(vm_id);
-                        if (uvm == null){
-                            uvm = new UserVmData();
-                            uvm.setId(vm_id);
-                        }
-                        // initialize the data with this row
-                        setUserVmData(uvm, rs);
-                    }
-                    rs.close();
-                    curr_index+=VM_DETAILS_BATCH_SIZE;
-                }
-            }
-            
-            
-            if (curr_index < userVmDataList.size()){
-                int batch_size = (userVmDataList.size() - curr_index);
-                pstmt = txn.prepareStatement(VM_DETAILS + getQueryBatchAppender(batch_size));
-                // set the vars value
-                for (int k=1,j=curr_index;j<curr_index+batch_size;j++,k++){
-                    pstmt.setLong(k, userVmDataList.get(j).getId());
-                }
-                ResultSet rs = pstmt.executeQuery();
-                while(rs.next()){
-                    long vm_id=rs.getLong("vm_instance.id");
-                    //check if the entry is already there
-                    UserVmData uvm=userVmDataHash.get(vm_id);
-                    if (uvm == null){
-                        uvm = new UserVmData();
-                        uvm.setId(vm_id);
-                    }
-                    // initialize the data with this row
-                    setUserVmData(uvm, rs);
-                }
-                rs.close();
-            }
-            
-            if (pstmt!=null)pstmt.close();
-            return userVmDataHash;
-        } catch (SQLException e) {
-            throw new CloudRuntimeException("DB Exception on: " + VM_DETAILS, e);
-        } catch (Throwable e) {
-            throw new CloudRuntimeException("Caught: " + VM_DETAILS, e);
-        }
-    }
-    
-    
-
-    public static UserVmData setUserVmData(UserVmData userVmData, ResultSet rs)
-        throws SQLException
-    {
-        
-        if (!userVmData.isInitialized()){
-        
-            //account.account_name, account.type, domain.name,  instance_group.id, instance_group.name,"
-            userVmData.setAccountId(rs.getLong("account.id"));
-            userVmData.setAccountName(rs.getString("account.account_name"));
-            userVmData.setDomainName(rs.getString("domain.name"));
-            
-            long grp_id = rs.getLong("instance_group.id");
-            if (grp_id > 0){
-                userVmData.setGroupId(grp_id);
-                userVmData.setGroup(rs.getString("instance_group.name"));
-            }
-            
-            //"data_center.id, data_center.name, host.id, host.name, vm_template.id, vm_template.name, vm_template.display_text, vm_template.enable_password, 
-            userVmData.setZoneId(rs.getLong("data_center.id"));
-            userVmData.setZoneName(rs.getString("data_center.name"));
-            
-            userVmData.setHostId(rs.getLong("host.id"));
-            userVmData.setHostName(rs.getString("host.name"));
-            
-            long template_id = rs.getLong("vm_template.id");
-            if (template_id > 0){
-                userVmData.setTemplateId(template_id);
-                userVmData.setTemplateName(rs.getString("vm_template.name"));
-                userVmData.setTemplateDisplayText(rs.getString("vm_template.display_text"));
-                userVmData.setPasswordEnabled(rs.getBoolean("vm_template.enable_password"));
-            }
-            else {
-                userVmData.setTemplateId(-1L);
-                userVmData.setTemplateName("ISO Boot");
-                userVmData.setTemplateDisplayText("ISO Boot");
-                userVmData.setPasswordEnabled(false);
-            }
-            
-            long iso_id = rs.getLong("iso.id");
-            if (iso_id > 0){
-                userVmData.setIsoId(iso_id);
-                userVmData.setIsoName(rs.getString("iso.name"));
-            }
-    
-    
-            //service_offering.id, disk_offering.name, " 
-            //"service_offering.cpu, service_offering.speed, service_offering.ram_size,
-            userVmData.setServiceOfferingId(rs.getLong("service_offering.id"));
-            userVmData.setServiceOfferingName(rs.getString("disk_offering.name"));
-            userVmData.setCpuNumber(rs.getInt("service_offering.cpu"));
-            userVmData.setCpuSpeed(rs.getInt("service_offering.speed"));
-            userVmData.setMemory(rs.getInt("service_offering.ram_size"));
-    
-            // volumes.device_id, volumes.volume_type, 
-            long vol_id = rs.getLong("volumes.id");
-            if (vol_id > 0){
-                userVmData.setRootDeviceId(rs.getLong("volumes.device_id"));
-                userVmData.setRootDeviceType(rs.getString("volumes.volume_type"));
-                // storage pool
-                long pool_id = rs.getLong("storage_pool.id");
-                if (pool_id > 0){
-                    userVmData.setRootDeviceType(rs.getString("storage_pool.pool_type"));
-                }
-                else {
-                    userVmData.setRootDeviceType("Not created");
-                }
-            }
-            userVmData.setInitialized();
-        }
-        
-        
-        Long securityGroupId = rs.getLong("security_group.id");
-        if (securityGroupId != null && securityGroupId.longValue() != 0){
-            SecurityGroupData resp = userVmData.newSecurityGroupData();
-            resp.setId(rs.getLong("security_group.id"));
-            resp.setName(rs.getString("security_group.name"));
-            resp.setDescription(rs.getString("security_group.description"));
-            resp.setObjectName("securitygroup");
-            userVmData.addSecurityGroup(resp);
-        }
-        
-        long nic_id = rs.getLong("nics.id");
-        if (nic_id > 0){
-            NicData nicResponse = userVmData.newNicData();
-            nicResponse.setId(nic_id);
-            nicResponse.setIpaddress(rs.getString("nics.ip4_address"));
-            nicResponse.setGateway(rs.getString("nics.gateway"));
-            nicResponse.setNetmask(rs.getString("nics.netmask"));
-            nicResponse.setNetworkid(rs.getLong("nics.network_id"));
-            nicResponse.setMacAddress(rs.getString("nics.mac_address"));
-            
-            int account_type = rs.getInt("account.type");
-            if (account_type == Account.ACCOUNT_TYPE_ADMIN) {
-                nicResponse.setBroadcastUri(rs.getString("nics.broadcast_uri"));
-                nicResponse.setIsolationUri(rs.getString("nics.isolation_uri"));
-            }
-
-
-            nicResponse.setTrafficType(rs.getString("networks.traffic_type"));
-            nicResponse.setType(rs.getString("networks.guest_type"));
-            nicResponse.setIsDefault(rs.getBoolean("nics.default_nic"));
-            nicResponse.setObjectName("nic");
-            userVmData.addNic(nicResponse);
-        }
-        
-        long publicIpId = rs.getLong("user_ip_address.id");
-        if (publicIpId > 0){
-            userVmData.setPublicIpId(publicIpId);
-            userVmData.setPublicIp(rs.getString("user_ip_address.public_ip_address"));
-        }
-        
-        return userVmData;
-    }
-    
-    public String getQueryBatchAppender(int count){
-        StringBuilder sb = new StringBuilder();
-        for (int i=0;i<count;i++){
-            sb.append(" ?,");
-        }
-        sb.deleteCharAt(sb.length()-1).append(")");
-        return sb.toString();
-    }
-
-
-    @Override
-    public Long countAllocatedVMsForAccount(long accountId) {
-    	SearchCriteria<Long> sc = CountByAccount.create();
-        sc.setParameters("account", accountId);
-        sc.setParameters("type", VirtualMachine.Type.User);
-		sc.setParameters("state", new Object[] {State.Destroyed, State.Error, State.Expunging});
-        return customSearch(sc, null).get(0);
-    }
-    
+
+            UserVmSearch = createSearchBuilder();
+            UserVmSearch.and("states", UserVmSearch.entity().getState(), SearchCriteria.Op.IN);
+            UserVmSearch.join("nicSearch", nicSearch, UserVmSearch.entity().getId(), nicSearch.entity().getInstanceId(), JoinBuilder.JoinType.INNER);
+            UserVmSearch.done();
+        }
+
+        SearchCriteria<UserVmVO> sc = UserVmSearch.create();
+        if (states != null && states.length != 0) {
+            sc.setParameters("states", (Object[]) states);
+        }
+        sc.setJoinParameters("nicSearch", "networkId", networkId);
+
+        return listBy(sc);
+    }
+
+	@Override
+	public List<UserVmVO> listByLastHostId(Long hostId) {
+		SearchCriteria<UserVmVO> sc = LastHostSearch.create();
+		sc.setParameters("lastHost", hostId);
+		sc.setParameters("state", State.Stopped);
+		return listBy(sc);
+	}
+
+	@Override
+	public List<UserVmVO> listByAccountIdAndHostId(long accountId, long hostId) {
+		SearchCriteria<UserVmVO> sc = AccountHostSearch.create();
+		sc.setParameters("hostId", hostId);
+		sc.setParameters("accountId", accountId);
+		return listBy(sc);
+	}
+
+	@Override
+	public void loadDetails(UserVmVO vm) {
+        Map<String, String> details = _detailsDao.findDetails(vm.getId());
+        vm.setDetails(details);
+	}
+
+	@Override
+    public void saveDetails(UserVmVO vm) {
+        Map<String, String> details = vm.getDetails();
+        if (details == null) {
+            return;
+        }
+        _detailsDao.persist(vm.getId(), details);
+    }
+
+    @Override
+    public List<Long> listPodIdsHavingVmsforAccount(long zoneId, long accountId){
+	Transaction txn = Transaction.currentTxn();
+        PreparedStatement pstmt = null;
+        List<Long> result = new ArrayList<Long>();
+
+        try {
+            String sql = LIST_PODS_HAVING_VMS_FOR_ACCOUNT;
+            pstmt = txn.prepareAutoCloseStatement(sql);
+            pstmt.setLong(1, zoneId);
+            pstmt.setLong(2, accountId);
+
+            ResultSet rs = pstmt.executeQuery();
+            while (rs.next()) {
+                result.add(rs.getLong(1));
+            }
+            return result;
+        } catch (SQLException e) {
+            throw new CloudRuntimeException("DB Exception on: " + LIST_PODS_HAVING_VMS_FOR_ACCOUNT, e);
+        } catch (Throwable e) {
+            throw new CloudRuntimeException("Caught: " + LIST_PODS_HAVING_VMS_FOR_ACCOUNT, e);
+        }
+    }
+
+    @Override
+    public Hashtable<Long, UserVmData> listVmDetails(Hashtable<Long, UserVmData> userVmDataHash){
+        Transaction txn = Transaction.currentTxn();
+        PreparedStatement pstmt = null;
+
+        try {
+            int curr_index=0;
+
+            List<UserVmData> userVmDataList = new ArrayList(userVmDataHash.values());
+
+            if (userVmDataList.size() > VM_DETAILS_BATCH_SIZE){
+                pstmt = txn.prepareStatement(VM_DETAILS + getQueryBatchAppender(VM_DETAILS_BATCH_SIZE));
+                while ( (curr_index + VM_DETAILS_BATCH_SIZE) <= userVmDataList.size()){
+                    // set the vars value
+                    for (int k=1,j=curr_index;j<curr_index+VM_DETAILS_BATCH_SIZE;j++,k++){
+                        pstmt.setLong(k, userVmDataList.get(j).getId());
+                    }
+                    ResultSet rs = pstmt.executeQuery();
+                    while(rs.next()){
+                        long vm_id=rs.getLong("vm_instance.id");
+                        //check if the entry is already there
+                        UserVmData uvm=userVmDataHash.get(vm_id);
+                        if (uvm == null){
+                            uvm = new UserVmData();
+                            uvm.setId(vm_id);
+                        }
+                        // initialize the data with this row
+                        setUserVmData(uvm, rs);
+                    }
+                    rs.close();
+                    curr_index+=VM_DETAILS_BATCH_SIZE;
+                }
+            }
+
+
+            if (curr_index < userVmDataList.size()){
+                int batch_size = (userVmDataList.size() - curr_index);
+                pstmt = txn.prepareStatement(VM_DETAILS + getQueryBatchAppender(batch_size));
+                // set the vars value
+                for (int k=1,j=curr_index;j<curr_index+batch_size;j++,k++){
+                    pstmt.setLong(k, userVmDataList.get(j).getId());
+                }
+                ResultSet rs = pstmt.executeQuery();
+                while(rs.next()){
+                    long vm_id=rs.getLong("vm_instance.id");
+                    //check if the entry is already there
+                    UserVmData uvm=userVmDataHash.get(vm_id);
+                    if (uvm == null){
+                        uvm = new UserVmData();
+                        uvm.setId(vm_id);
+                    }
+                    // initialize the data with this row
+                    setUserVmData(uvm, rs);
+                }
+                rs.close();
+            }
+
+            if (pstmt!=null)pstmt.close();
+            return userVmDataHash;
+        } catch (SQLException e) {
+            throw new CloudRuntimeException("DB Exception on: " + VM_DETAILS, e);
+        } catch (Throwable e) {
+            throw new CloudRuntimeException("Caught: " + VM_DETAILS, e);
+        }
+    }
+
+
+
+    public static UserVmData setUserVmData(UserVmData userVmData, ResultSet rs)
+        throws SQLException
+    {
+
+        if (!userVmData.isInitialized()){
+
+            //account.account_name, account.type, domain.name,  instance_group.id, instance_group.name,"
+            userVmData.setAccountId(rs.getLong("account.id"));
+            userVmData.setAccountName(rs.getString("account.account_name"));
+            userVmData.setDomainName(rs.getString("domain.name"));
+
+            long grp_id = rs.getLong("instance_group.id");
+            if (grp_id > 0){
+                userVmData.setGroupId(grp_id);
+                userVmData.setGroup(rs.getString("instance_group.name"));
+            }
+
+            //"data_center.id, data_center.name, host.id, host.name, vm_template.id, vm_template.name, vm_template.display_text, vm_template.enable_password,
+            userVmData.setZoneId(rs.getLong("data_center.id"));
+            userVmData.setZoneName(rs.getString("data_center.name"));
+
+            userVmData.setHostId(rs.getLong("host.id"));
+            userVmData.setHostName(rs.getString("host.name"));
+
+            long template_id = rs.getLong("vm_template.id");
+            if (template_id > 0){
+                userVmData.setTemplateId(template_id);
+                userVmData.setTemplateName(rs.getString("vm_template.name"));
+                userVmData.setTemplateDisplayText(rs.getString("vm_template.display_text"));
+                userVmData.setPasswordEnabled(rs.getBoolean("vm_template.enable_password"));
+            }
+            else {
+                userVmData.setTemplateId(-1L);
+                userVmData.setTemplateName("ISO Boot");
+                userVmData.setTemplateDisplayText("ISO Boot");
+                userVmData.setPasswordEnabled(false);
+            }
+
+            long iso_id = rs.getLong("iso.id");
+            if (iso_id > 0){
+                userVmData.setIsoId(iso_id);
+                userVmData.setIsoName(rs.getString("iso.name"));
+            }
+
+
+            //service_offering.id, disk_offering.name, "
+            //"service_offering.cpu, service_offering.speed, service_offering.ram_size,
+            userVmData.setServiceOfferingId(rs.getLong("service_offering.id"));
+            userVmData.setServiceOfferingName(rs.getString("disk_offering.name"));
+            userVmData.setCpuNumber(rs.getInt("service_offering.cpu"));
+            userVmData.setCpuSpeed(rs.getInt("service_offering.speed"));
+            userVmData.setMemory(rs.getInt("service_offering.ram_size"));
+
+            // volumes.device_id, volumes.volume_type,
+            long vol_id = rs.getLong("volumes.id");
+            if (vol_id > 0){
+                userVmData.setRootDeviceId(rs.getLong("volumes.device_id"));
+                userVmData.setRootDeviceType(rs.getString("volumes.volume_type"));
+                // storage pool
+                long pool_id = rs.getLong("storage_pool.id");
+                if (pool_id > 0){
+                    userVmData.setRootDeviceType(rs.getString("storage_pool.pool_type"));
+                }
+                else {
+                    userVmData.setRootDeviceType("Not created");
+                }
+            }
+            userVmData.setInitialized();
+        }
+
+
+        Long securityGroupId = rs.getLong("security_group.id");
+        if (securityGroupId != null && securityGroupId.longValue() != 0){
+            SecurityGroupData resp = userVmData.newSecurityGroupData();
+            resp.setId(rs.getLong("security_group.id"));
+            resp.setName(rs.getString("security_group.name"));
+            resp.setDescription(rs.getString("security_group.description"));
+            resp.setObjectName("securitygroup");
+            userVmData.addSecurityGroup(resp);
+        }
+
+        long nic_id = rs.getLong("nics.id");
+        if (nic_id > 0){
+            NicData nicResponse = userVmData.newNicData();
+            nicResponse.setId(nic_id);
+            nicResponse.setIpaddress(rs.getString("nics.ip4_address"));
+            nicResponse.setGateway(rs.getString("nics.gateway"));
+            nicResponse.setNetmask(rs.getString("nics.netmask"));
+            nicResponse.setNetworkid(rs.getLong("nics.network_id"));
+            nicResponse.setMacAddress(rs.getString("nics.mac_address"));
+
+            int account_type = rs.getInt("account.type");
+            if (account_type == Account.ACCOUNT_TYPE_ADMIN) {
+                nicResponse.setBroadcastUri(rs.getString("nics.broadcast_uri"));
+                nicResponse.setIsolationUri(rs.getString("nics.isolation_uri"));
+            }
+
+
+            nicResponse.setTrafficType(rs.getString("networks.traffic_type"));
+            nicResponse.setType(rs.getString("networks.guest_type"));
+            nicResponse.setIsDefault(rs.getBoolean("nics.default_nic"));
+            nicResponse.setObjectName("nic");
+            userVmData.addNic(nicResponse);
+        }
+
+        long publicIpId = rs.getLong("user_ip_address.id");
+        if (publicIpId > 0){
+            userVmData.setPublicIpId(publicIpId);
+            userVmData.setPublicIp(rs.getString("user_ip_address.public_ip_address"));
+        }
+
+        return userVmData;
+    }
+
+    public String getQueryBatchAppender(int count){
+        StringBuilder sb = new StringBuilder();
+        for (int i=0;i<count;i++){
+            sb.append(" ?,");
+        }
+        sb.deleteCharAt(sb.length()-1).append(")");
+        return sb.toString();
+    }
+
+
+    @Override
+    public Long countAllocatedVMsForAccount(long accountId) {
+	SearchCriteria<Long> sc = CountByAccount.create();
+        sc.setParameters("account", accountId);
+        sc.setParameters("type", VirtualMachine.Type.User);
+		sc.setParameters("state", new Object[] {State.Destroyed, State.Error, State.Expunging});
+        return customSearch(sc, null).get(0);
+    }
+
     @Override
     public boolean remove(Long id) {
         Transaction txn = Transaction.currentTxn();
@@ -580,6 +580,6 @@ public class UserVmDaoImpl extends GenericDaoBase<UserVmVO, Long> implements Use
         boolean result = super.remove(id);
         txn.commit();
         return result;
-    }
-    
-}
+    }
+
+}


Mime
View raw message