Return-Path: X-Original-To: apmail-cloudstack-commits-archive@www.apache.org Delivered-To: apmail-cloudstack-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id E6E8E101DC for ; Fri, 12 Jul 2013 07:51:33 +0000 (UTC) Received: (qmail 16379 invoked by uid 500); 12 Jul 2013 07:51:08 -0000 Delivered-To: apmail-cloudstack-commits-archive@cloudstack.apache.org Received: (qmail 16184 invoked by uid 500); 12 Jul 2013 07:51:05 -0000 Mailing-List: contact commits-help@cloudstack.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cloudstack.apache.org Delivered-To: mailing list commits@cloudstack.apache.org Received: (qmail 15657 invoked by uid 99); 12 Jul 2013 07:50:59 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 12 Jul 2013 07:50:59 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id C5A8E894AE1; Fri, 12 Jul 2013 07:50:57 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: sebgoa@apache.org To: commits@cloudstack.apache.org Date: Fri, 12 Jul 2013 07:51:44 -0000 Message-Id: <7bdb4d3ec3e44445a09ecf268595743e@git.apache.org> In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [49/50] git commit: updated refs/heads/sdnextensions to bcfb4e6 CLOUDSTACK-3094: Adding a shared network to already deployed VM is failing. Signed-off-by: Mice Xia Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/bdc7e4ce Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/bdc7e4ce Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/bdc7e4ce Branch: refs/heads/sdnextensions Commit: bdc7e4ce337f2f7cba8320808755119a835de07c Parents: dd91974 Author: Saksham Srivastava Authored: Mon Jul 8 19:50:03 2013 +0530 Committer: Mice Xia Committed: Fri Jul 12 14:30:10 2013 +0800 ---------------------------------------------------------------------- .../src/com/cloud/vm/dao/VMInstanceDao.java | 2 ++ .../src/com/cloud/vm/dao/VMInstanceDaoImpl.java | 12 ++++++++++++ server/src/com/cloud/vm/UserVmManagerImpl.java | 19 +++++++++++-------- 3 files changed, 25 insertions(+), 8 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cloudstack/blob/bdc7e4ce/engine/schema/src/com/cloud/vm/dao/VMInstanceDao.java ---------------------------------------------------------------------- diff --git a/engine/schema/src/com/cloud/vm/dao/VMInstanceDao.java b/engine/schema/src/com/cloud/vm/dao/VMInstanceDao.java index 830e464..e564052 100644 --- a/engine/schema/src/com/cloud/vm/dao/VMInstanceDao.java +++ b/engine/schema/src/com/cloud/vm/dao/VMInstanceDao.java @@ -76,6 +76,8 @@ public interface VMInstanceDao extends GenericDao, StateDao< VMInstanceVO findVMByInstanceName(String name); + VMInstanceVO findVMByHostName(String hostName); + void updateProxyId(long id, Long proxyId, Date time); List listByHostIdTypes(long hostid, VirtualMachine.Type... types); http://git-wip-us.apache.org/repos/asf/cloudstack/blob/bdc7e4ce/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 ffb1a0b..ec04085 100644 --- a/engine/schema/src/com/cloud/vm/dao/VMInstanceDaoImpl.java +++ b/engine/schema/src/com/cloud/vm/dao/VMInstanceDaoImpl.java @@ -78,6 +78,7 @@ public class VMInstanceDaoImpl extends GenericDaoBase implem protected SearchBuilder HostIdUpTypesSearch; protected SearchBuilder HostUpSearch; protected SearchBuilder InstanceNameSearch; + protected SearchBuilder HostNameSearch; protected GenericSearchBuilder CountVirtualRoutersByAccount; protected GenericSearchBuilder CountRunningByHost; protected GenericSearchBuilder CountRunningByAccount; @@ -192,6 +193,10 @@ public class VMInstanceDaoImpl extends GenericDaoBase implem InstanceNameSearch.and("instanceName", InstanceNameSearch.entity().getInstanceName(), Op.EQ); InstanceNameSearch.done(); + HostNameSearch = createSearchBuilder(); + HostNameSearch.and("hostName", HostNameSearch.entity().getHostName(), Op.EQ); + HostNameSearch.done(); + CountVirtualRoutersByAccount = createSearchBuilder(Long.class); CountVirtualRoutersByAccount.select(null, Func.COUNT, null); CountVirtualRoutersByAccount.and("account", CountVirtualRoutersByAccount.entity().getAccountId(), SearchCriteria.Op.EQ); @@ -362,6 +367,13 @@ public class VMInstanceDaoImpl extends GenericDaoBase implem } @Override + public VMInstanceVO findVMByHostName(String hostName) { + SearchCriteria sc = HostNameSearch.create(); + sc.setParameters("hostName", hostName); + return findOneBy(sc); + } + + @Override public void updateProxyId(long id, Long proxyId, Date time) { VMInstanceVO vo = createForUpdate(); vo.setProxyId(proxyId); http://git-wip-us.apache.org/repos/asf/cloudstack/blob/bdc7e4ce/server/src/com/cloud/vm/UserVmManagerImpl.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/vm/UserVmManagerImpl.java b/server/src/com/cloud/vm/UserVmManagerImpl.java index f95123e..79e7f5a 100755 --- a/server/src/com/cloud/vm/UserVmManagerImpl.java +++ b/server/src/com/cloud/vm/UserVmManagerImpl.java @@ -870,14 +870,17 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Use throw new CloudRuntimeException(vmInstance + " is in zone:" + vmInstance.getDataCenterId() + " but " + network + " is in zone:" + network.getDataCenterId()); } - if(_networkModel.getNicInNetwork(vmInstance.getId(),network.getId()) != null){ - s_logger.debug(vmInstance + " already in " + network + " going to add another NIC"); - } else { - //* get all vms hostNames in the network - List hostNames = _vmInstanceDao.listDistinctHostNames(network.getId()); - //* verify that there are no duplicates - if (hostNames.contains(vmInstance.getHostName())) { - throw new CloudRuntimeException(network + " already has a vm with host name: '" + vmInstance.getHostName()); + // Get all vms hostNames in the network + List hostNames = _vmInstanceDao.listDistinctHostNames(network.getId()); + // verify that there are no duplicates, listDistictHostNames could return hostNames even if the NIC + //in the network is removed, so also check if the NIC is present and then throw an exception. + //This will also check if there are multiple nics of same vm in the network + if (hostNames.contains(vmInstance.getHostName())) { + for (String hostName : hostNames) { + VMInstanceVO vm = _vmInstanceDao.findVMByHostName(hostName); + if(_networkModel.getNicInNetwork(vm.getId(),network.getId())!=null && vm.getHostName().equals(vmInstance.getHostName())) { + throw new CloudRuntimeException(network + " already has a vm with host name: " + vmInstance.getHostName()); + } } }