sureshanaparti commented on a change in pull request #1872: CLOUDSTACK-3223 
Exception observed while creating CPVM in VMware Setup with DVS
URL: https://github.com/apache/cloudstack/pull/1872#discussion_r113858258
 
 

 ##########
 File path: 
vmware-base/src/com/cloud/hypervisor/vmware/mo/DistributedVirtualSwitchMO.java
 ##########
 @@ -36,24 +37,67 @@
 public class DistributedVirtualSwitchMO extends BaseMO {
     @SuppressWarnings("unused")
     private static final Logger s_logger = 
Logger.getLogger(DistributedVirtualSwitchMO.class);
+    private static ConcurrentHashMap<String, List<String>> 
s_dvPortGroupCacheMap = null;
 
     public DistributedVirtualSwitchMO(VmwareContext context, 
ManagedObjectReference morDvs) {
         super(context, morDvs);
+        s_dvPortGroupCacheMap = new ConcurrentHashMap<String, List<String>>();
     }
 
     public DistributedVirtualSwitchMO(VmwareContext context, String morType, 
String morValue) {
         super(context, morType, morValue);
+        s_dvPortGroupCacheMap = new ConcurrentHashMap<String, List<String>>();
     }
 
     public void createDVPortGroup(DVPortgroupConfigSpec dvPortGroupSpec) 
throws Exception {
         List<DVPortgroupConfigSpec> dvPortGroupSpecArray = new 
ArrayList<DVPortgroupConfigSpec>();
         dvPortGroupSpecArray.add(dvPortGroupSpec);
-        _context.getService().addDVPortgroupTask(_mor, dvPortGroupSpecArray);
+        boolean dvPortGroupExists = false;
+        String dvSwitchInstance = _mor.getValue();
+        String dvPortGroupName = dvPortGroupSpec.getName();
+        String uniquedvPortGroupPerDvs = dvSwitchInstance + dvPortGroupName;
+        List<String> dvPortGroupList = null;
+        synchronized (uniquedvPortGroupPerDvs.intern()) {
+            // Looking up local cache rather than firing another API call to 
see if dvPortGroup exists already.
+            if (s_dvPortGroupCacheMap.containsKey(dvSwitchInstance)) {
+                dvPortGroupList = s_dvPortGroupCacheMap.get(dvSwitchInstance);
+                if (dvPortGroupList != null && 
dvPortGroupList.contains(dvPortGroupName)) {
+                    dvPortGroupExists = true;
+                }
+            }
+            if (!dvPortGroupExists) {
+                ManagedObjectReference task = 
_context.getService().addDVPortgroupTask(_mor, dvPortGroupSpecArray);
+                if (!_context.getVimClient().waitForTask(task)) {
+                    throw new Exception("Failed to create dvPortGroup " + 
dvPortGroupSpec.getName());
+                } else {
+                    if (s_dvPortGroupCacheMap.containsKey(dvSwitchInstance)) {
+                        dvPortGroupList = 
s_dvPortGroupCacheMap.get(dvSwitchInstance);
+                        if (dvPortGroupList == null) {
+                            dvPortGroupList = new ArrayList<String>();
+                        }
+                        dvPortGroupList.add(dvPortGroupName); //does this 
update map?
 
 Review comment:
   @sateesh-chodapuneedi `s_dvPortGroupCacheMap` update required here?
 
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to