Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 9D8B4200BF5 for ; Fri, 23 Dec 2016 13:21:33 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 9C889160B37; Fri, 23 Dec 2016 12:21:33 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id C092B160B3B for ; Fri, 23 Dec 2016 13:21:32 +0100 (CET) Received: (qmail 82938 invoked by uid 500); 23 Dec 2016 12:21:31 -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 82623 invoked by uid 99); 23 Dec 2016 12:21:30 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 23 Dec 2016 12:21:30 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id B1572DFE20; Fri, 23 Dec 2016 12:21:30 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: bhaisaab@apache.org To: commits@cloudstack.apache.org Date: Fri, 23 Dec 2016 12:21:35 -0000 Message-Id: <5e6ccbf549e549ba8e86231549ddb580@git.apache.org> In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [06/19] git commit: updated refs/heads/4.9 to 20986ba archived-at: Fri, 23 Dec 2016 12:21:33 -0000 CLOUDSTACK-9673 Exception occured while creating the CPVM in the VmWare Setup over standard vSwitches Issue ==== Exception occured while creating the CPVM in the VmWare Setup using standard vswitches. StartCommand failed due to Exception: com.vmware.vim25.AlreadyExists message: [] com.vmware.vim25.AlreadyExistsFaultMsg: The specified key, name, or identifier already exists Fix === Ensure synchronization while attempting to create port group such that simultaneous attempts are not made with same port group name on same ESXi host. Signed-off-by: Sateesh Chodapuneedi Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/32e9e29a Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/32e9e29a Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/32e9e29a Branch: refs/heads/4.9 Commit: 32e9e29a17a04fc844f75e25f611b860528835f1 Parents: a0e36b7 Author: Sateesh Chodapuneedi Authored: Wed Dec 14 00:10:42 2016 +0530 Committer: Sateesh Chodapuneedi Committed: Thu Dec 22 01:35:10 2016 +0530 ---------------------------------------------------------------------- .../vmware/resource/VmwareResource.java | 16 +++--- .../com/cloud/hypervisor/vmware/mo/HostMO.java | 54 ++++++++++++++++++++ .../vmware/mo/HypervisorHostHelper.java | 7 ++- 3 files changed, 65 insertions(+), 12 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cloudstack/blob/32e9e29a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java ---------------------------------------------------------------------- diff --git a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java index 830a75b..ad4ae26 100644 --- a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java +++ b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java @@ -1125,11 +1125,9 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa * so we assume that it's VLAN for now */ if (VirtualSwitchType.StandardVirtualSwitch == vSwitchType) { - synchronized (vmMo.getRunningHost().getMor().getValue().intern()) { - networkInfo = - HypervisorHostHelper.prepareNetwork(_publicTrafficInfo.getVirtualSwitchName(), "cloud.public", vmMo.getRunningHost(), vlanId, null, null, - _opsTimeout, true, BroadcastDomainType.Vlan, null); - } + networkInfo = HypervisorHostHelper.prepareNetwork(_publicTrafficInfo.getVirtualSwitchName(), + "cloud.public", vmMo.getRunningHost(), vlanId, null, null, + _opsTimeout, true, BroadcastDomainType.Vlan, null); } else { networkInfo = HypervisorHostHelper.prepareNetwork(_publicTrafficInfo.getVirtualSwitchName(), "cloud.public", vmMo.getRunningHost(), vlanId, null, null, null, @@ -2852,11 +2850,9 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa s_logger.info("Prepare network on " + switchType + " " + switchName + " with name prefix: " + namePrefix); if (VirtualSwitchType.StandardVirtualSwitch == switchType) { - synchronized(hostMo.getMor().getValue().intern()) { - networkInfo = HypervisorHostHelper.prepareNetwork(switchName, namePrefix, hostMo, getVlanInfo(nicTo, vlanToken), nicTo.getNetworkRateMbps(), - nicTo.getNetworkRateMulticastMbps(), _opsTimeout, - !namePrefix.startsWith("cloud.private"), nicTo.getBroadcastType(), nicTo.getUuid()); - } + networkInfo = HypervisorHostHelper.prepareNetwork(switchName, namePrefix, hostMo, + getVlanInfo(nicTo, vlanToken), nicTo.getNetworkRateMbps(), nicTo.getNetworkRateMulticastMbps(), + _opsTimeout, !namePrefix.startsWith("cloud.private"), nicTo.getBroadcastType(), nicTo.getUuid()); } else { String vlanId = getVlanInfo(nicTo, vlanToken); http://git-wip-us.apache.org/repos/asf/cloudstack/blob/32e9e29a/vmware-base/src/com/cloud/hypervisor/vmware/mo/HostMO.java ---------------------------------------------------------------------- diff --git a/vmware-base/src/com/cloud/hypervisor/vmware/mo/HostMO.java b/vmware-base/src/com/cloud/hypervisor/vmware/mo/HostMO.java index d8fa7f3..c008e6b 100644 --- a/vmware-base/src/com/cloud/hypervisor/vmware/mo/HostMO.java +++ b/vmware-base/src/com/cloud/hypervisor/vmware/mo/HostMO.java @@ -1110,4 +1110,58 @@ public class HostMO extends BaseMO implements VmwareHypervisorHost { } return networkName; } + + public void createPortGroup(HostVirtualSwitch vSwitch, String portGroupName, Integer vlanId, + HostNetworkSecurityPolicy secPolicy, HostNetworkTrafficShapingPolicy shapingPolicy, long timeOutMs) + throws Exception { + assert (portGroupName != null); + + // Prepare lock to avoid simultaneous execution of the synchronized block for + // duplicate port groups on the ESXi host it's being created on. + String hostPortGroup = _mor.getValue() + "-" + portGroupName; + synchronized (hostPortGroup.intern()) { + // Check if port group exists already + if (hasPortGroup(vSwitch, portGroupName)) { + if (s_logger.isDebugEnabled()) { + s_logger.debug("Found port group " + portGroupName + " in vSwitch " + vSwitch.getName() + + ". Not attempting to create port group as it already exists."); + } + return; + } else { + if (s_logger.isDebugEnabled()) { + s_logger.debug("Port group " + portGroupName + " doesn't exist in vSwitch " + vSwitch.getName() + + ". Attempting to create port group in this vSwitch."); + } + } + // Create port group if not exists already + createPortGroup(vSwitch, portGroupName, vlanId, secPolicy, shapingPolicy); + + // Wait for port group to turn up ready on vCenter upto timeout of timeOutMs milli seconds + waitForPortGroup(portGroupName, timeOutMs); + } + + if (s_logger.isDebugEnabled()) { + s_logger.debug("Successfully created port group " + portGroupName + " in vSwitch " + vSwitch.getName() + + " on host " + getHostName()); + } + } + + public ManagedObjectReference waitForPortGroup(String networkName, long timeOutMs) throws Exception { + ManagedObjectReference morNetwork = null; + // if portGroup is just created, getNetwork may fail to retrieve it, we + // need to retry + long startTick = System.currentTimeMillis(); + while (System.currentTimeMillis() - startTick <= timeOutMs) { + morNetwork = getNetworkMor(networkName); + if (morNetwork != null) { + break; + } + + if (s_logger.isInfoEnabled()) { + s_logger.info("Waiting for network " + networkName + " to be ready"); + } + Thread.sleep(1000); + } + return morNetwork; + } } http://git-wip-us.apache.org/repos/asf/cloudstack/blob/32e9e29a/vmware-base/src/com/cloud/hypervisor/vmware/mo/HypervisorHostHelper.java ---------------------------------------------------------------------- diff --git a/vmware-base/src/com/cloud/hypervisor/vmware/mo/HypervisorHostHelper.java b/vmware-base/src/com/cloud/hypervisor/vmware/mo/HypervisorHostHelper.java index fb63b12..71c007d 100644 --- a/vmware-base/src/com/cloud/hypervisor/vmware/mo/HypervisorHostHelper.java +++ b/vmware-base/src/com/cloud/hypervisor/vmware/mo/HypervisorHostHelper.java @@ -1082,8 +1082,11 @@ public class HypervisorHostHelper { } } else { if (!hostMo.hasPortGroup(vSwitch, networkName)) { - hostMo.createPortGroup(vSwitch, networkName, vid, secPolicy, shapingPolicy); - bWaitPortGroupReady = true; + hostMo.createPortGroup(vSwitch, networkName, vid, secPolicy, shapingPolicy, timeOutMs); + // Setting flag "bWaitPortGroupReady" to false. + // This flag indicates whether we need to wait for portgroup on vCenter. + // Above createPortGroup() method itself ensures creation of portgroup as well as wait for portgroup. + bWaitPortGroupReady = false; } else { HostPortGroupSpec spec = hostMo.getPortGroupSpec(networkName); if (!isSpecMatch(spec, vid, shapingPolicy)) {