You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by pr...@apache.org on 2012/09/26 17:58:02 UTC

git commit: CS-15644-Autoscale: Implemented UUIDs for templateId-serviceOff Reviewed-By:Vijay

Updated Branches:
  refs/heads/autoscale 49ecfeb06 -> 70bbd8b07


CS-15644-Autoscale: Implemented UUIDs for templateId-serviceOff Reviewed-By:Vijay


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

Branch: refs/heads/autoscale
Commit: 70bbd8b07dbda32e98c6fd404678f0a5c9254cac
Parents: 49ecfeb
Author: Deepak Garg <de...@gmail.com>
Authored: Wed Sep 26 21:25:08 2012 +0530
Committer: Pranav Saxena <pr...@citrix.com>
Committed: Wed Sep 26 21:25:08 2012 +0530

----------------------------------------------------------------------
 api/src/com/cloud/agent/api/to/LoadBalancerTO.java |   55 +++---
 api/src/com/cloud/network/as/AutoScaleVmGroup.java |   30 ++--
 .../com/cloud/network/lb/LoadBalancingRule.java    |   33 +++-
 api/src/com/cloud/network/rules/LoadBalancer.java  |    7 +-
 .../network/lb/ElasticLoadBalancerManagerImpl.java |   67 ++----
 .../cloud/network/element/NetscalerElement.java    |   69 +++---
 .../cloud/network/resource/NetscalerResource.java  |  183 +++++++++------
 .../ExternalLoadBalancerDeviceManagerImpl.java     |   43 ++--
 .../com/cloud/network/as/AutoScaleVmGroupVO.java   |    5 +
 .../network/lb/LoadBalancingRulesManagerImpl.java  |   38 ++--
 .../router/VirtualNetworkApplianceManagerImpl.java |    3 +-
 11 files changed, 296 insertions(+), 237 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/70bbd8b0/api/src/com/cloud/agent/api/to/LoadBalancerTO.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/agent/api/to/LoadBalancerTO.java b/api/src/com/cloud/agent/api/to/LoadBalancerTO.java
index 04f718e..9a58d9a 100644
--- a/api/src/com/cloud/agent/api/to/LoadBalancerTO.java
+++ b/api/src/com/cloud/agent/api/to/LoadBalancerTO.java
@@ -36,7 +36,7 @@ import com.cloud.utils.Pair;
 
 
 public class LoadBalancerTO {
-    Long id;
+    String uuid;
     String srcIp;
     int srcPort;
     String protocol;
@@ -48,11 +48,11 @@ public class LoadBalancerTO {
     private AutoScaleVmGroupTO autoScaleVmGroupTO;
     final static int MAX_STICKINESS_POLICIES = 1;
 
-    public LoadBalancerTO (Long id, String srcIp, int srcPort, String protocol, String algorithm, boolean revoked, boolean alreadyAdded, List<LbDestination> destinations) {
-        if (destinations == null) { // for autoscaleconfig destinations will be null;
+    public LoadBalancerTO(String uuid, String srcIp, int srcPort, String protocol, String algorithm, boolean revoked, boolean alreadyAdded, List<LbDestination> destinations) {
+        if(destinations == null) { // for autoscaleconfig destinations will be null;
             destinations = new ArrayList<LbDestination>();
         }
-        this.id = id;
+        this.uuid = uuid;
         this.srcIp = srcIp;
         this.srcPort = srcPort;
         this.protocol = protocol;
@@ -67,7 +67,7 @@ public class LoadBalancerTO {
         }
     }
 
-    public LoadBalancerTO (Long id, String srcIp, int srcPort, String protocol, String algorithm, boolean revoked, boolean alreadyAdded, List<LbDestination> arg_destinations, List<LbStickinessPolicy> stickinessPolicies) {
+    public LoadBalancerTO(String id, String srcIp, int srcPort, String protocol, String algorithm, boolean revoked, boolean alreadyAdded, List<LbDestination> arg_destinations, List<LbStickinessPolicy> stickinessPolicies) {
         this(id, srcIp, srcPort, protocol, algorithm, revoked, alreadyAdded, arg_destinations);
         this.stickinessPolicies = null;
         if (stickinessPolicies != null && stickinessPolicies.size() > 0) {
@@ -78,19 +78,18 @@ public class LoadBalancerTO {
                     this.stickinessPolicies[index] = new StickinessPolicyTO(stickinesspolicy.getMethodName(), stickinesspolicy.getParams());
                     index++;
                     if (index == MAX_STICKINESS_POLICIES) break;
+                    }
                 }
-            }
             if (index == 0) this.stickinessPolicies = null;
-        }
-    }
+            }
+            }
 
 
     protected LoadBalancerTO() {
     }
 
-
-    public Long getId() {
-        return id;
+    public String getUuid() {
+        return uuid;
     }
 
     public String getSrcIp() {
@@ -186,7 +185,7 @@ public class LoadBalancerTO {
             return alreadyAdded;
         }
     }
-    public static class CounterTO implements Serializable {
+    public static class CounterTO implements Serializable{
         private final String name;
         private final String source;
         private final String value;
@@ -210,7 +209,7 @@ public class LoadBalancerTO {
         }
     }
 
-    public static class ConditionTO implements Serializable {
+    public static class ConditionTO implements Serializable{
         private final long threshold;
         private final String relationalOperator;
         private final CounterTO counter;
@@ -235,7 +234,7 @@ public class LoadBalancerTO {
         }
     }
 
-    public static class AutoScalePolicyTO implements Serializable {
+    public static class AutoScalePolicyTO implements Serializable{
         private final long id;
         private final int duration;
         private final int quietTime;
@@ -277,11 +276,11 @@ public class LoadBalancerTO {
         }
     }
 
-    public static class AutoScaleVmProfileTO implements Serializable {
-        private final Long zoneId;
-        private final Long domainId;
-        private final Long serviceOfferingId;
-        private final Long templateId;
+    public static class AutoScaleVmProfileTO implements Serializable{
+        private final String zoneId;
+        private final String domainId;
+        private final String serviceOfferingId;
+        private final String templateId;
         private final String otherDeployParams;
         private final String snmpCommunity;
         private final Integer snmpPort;
@@ -290,7 +289,7 @@ public class LoadBalancerTO {
         private final String autoScaleUserApiKey;
         private final String autoScaleUserSecretKey;
 
-        public AutoScaleVmProfileTO(Long zoneId, Long domainId, String cloudStackApiUrl, String autoScaleUserApiKey, String autoScaleUserSecretKey, Long serviceOfferingId, Long templateId,
+        public AutoScaleVmProfileTO(String zoneId, String domainId, String cloudStackApiUrl, String autoScaleUserApiKey, String autoScaleUserSecretKey, String serviceOfferingId, String templateId,
                 String otherDeployParams, String snmpCommunity, Integer snmpPort, Integer destroyVmGraceperiod) {
             this.zoneId = zoneId;
             this.domainId = domainId;
@@ -305,19 +304,19 @@ public class LoadBalancerTO {
             this.autoScaleUserSecretKey = autoScaleUserSecretKey;
         }
 
-        public Long getZoneId() {
+        public String getZoneId() {
             return zoneId;
         }
 
-        public Long getDomainId() {
+        public String getDomainId() {
             return domainId;
         }
 
-        public Long getServiceOfferingId() {
+        public String getServiceOfferingId() {
             return serviceOfferingId;
         }
 
-        public Long getTemplateId() {
+        public String getTemplateId() {
             return templateId;
         }
 
@@ -350,7 +349,7 @@ public class LoadBalancerTO {
         }
     }
 
-    public static class AutoScaleVmGroupTO implements Serializable {
+    public static class AutoScaleVmGroupTO implements Serializable{
         private final int minMembers;
         private final int maxMembers;
         private final int memberPort;
@@ -402,7 +401,7 @@ public class LoadBalancerTO {
 
         public String getCurrentState() {
             return currentState;
-        }
+    }
     }
 
     public void setAutoScaleVmGroup(LbAutoScaleVmGroup lbAutoScaleVmGroup)
@@ -427,9 +426,9 @@ public class LoadBalancerTO {
         LbAutoScaleVmProfile lbAutoScaleVmProfile = lbAutoScaleVmGroup.getProfile();
         AutoScaleVmProfile autoScaleVmProfile = lbAutoScaleVmProfile.getProfile();
 
-        AutoScaleVmProfileTO autoScaleVmProfileTO = new AutoScaleVmProfileTO(autoScaleVmProfile.getZoneId(), autoScaleVmProfile.getDomainId(),
+        AutoScaleVmProfileTO autoScaleVmProfileTO = new AutoScaleVmProfileTO(lbAutoScaleVmProfile.getZoneId(), lbAutoScaleVmProfile.getDomainId(),
                 lbAutoScaleVmProfile.getCsUrl(), lbAutoScaleVmProfile.getAutoScaleUserApiKey(), lbAutoScaleVmProfile.getAutoScaleUserSecretKey(),
-                autoScaleVmProfile.getServiceOfferingId(), autoScaleVmProfile.getTemplateId(), autoScaleVmProfile.getOtherDeployParams(),
+                lbAutoScaleVmProfile.getServiceOfferingId(), lbAutoScaleVmProfile.getTemplateId(), autoScaleVmProfile.getOtherDeployParams(),
                 autoScaleVmProfile.getSnmpCommunity(), autoScaleVmProfile.getSnmpPort(), autoScaleVmProfile.getDestroyVmGraceperiod());
 
         AutoScaleVmGroup autoScaleVmGroup = lbAutoScaleVmGroup.getVmGroup();

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/70bbd8b0/api/src/com/cloud/network/as/AutoScaleVmGroup.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/network/as/AutoScaleVmGroup.java b/api/src/com/cloud/network/as/AutoScaleVmGroup.java
index 7b882fc..6d41ae3 100644
--- a/api/src/com/cloud/network/as/AutoScaleVmGroup.java
+++ b/api/src/com/cloud/network/as/AutoScaleVmGroup.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
+//       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
+//         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.
+//       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;
 
@@ -46,4 +46,6 @@ public interface AutoScaleVmGroup extends ControlledEntity {
 
     String getState();
 
+    String getUuid();
+
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/70bbd8b0/api/src/com/cloud/network/lb/LoadBalancingRule.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/network/lb/LoadBalancingRule.java b/api/src/com/cloud/network/lb/LoadBalancingRule.java
index e9cb6da..6647b8e 100644
--- a/api/src/com/cloud/network/lb/LoadBalancingRule.java
+++ b/api/src/com/cloud/network/lb/LoadBalancingRule.java
@@ -80,6 +80,11 @@ public class LoadBalancingRule implements FirewallRule, LoadBalancer {
     }
 
     @Override
+    public String getUuid() {
+        return lb.getUuid();
+    }
+
+    @Override
     public String getXid() {
         return lb.getXid();
     }
@@ -292,12 +297,20 @@ public class LoadBalancingRule implements FirewallRule, LoadBalancer {
         private final String autoScaleUserApiKey;
         private final String autoScaleUserSecretKey;
         private final String csUrl;
+        private final String zoneId;
+        private final String domainId;
+        private final String serviceOfferingId;
+        private final String templateId;
 
-        public LbAutoScaleVmProfile(AutoScaleVmProfile profile, String autoScaleUserApiKey, String autoScaleUserSecretKey, String csUrl) {
+        public LbAutoScaleVmProfile(AutoScaleVmProfile profile, String autoScaleUserApiKey, String autoScaleUserSecretKey, String csUrl, String zoneId, String domainId, String serviceOfferingId, String templateId) {
             this.profile = profile;
             this.autoScaleUserApiKey = autoScaleUserApiKey;
             this.autoScaleUserSecretKey = autoScaleUserSecretKey;
             this.csUrl = csUrl;
+            this.zoneId = zoneId;
+            this.domainId = domainId;
+            this.serviceOfferingId = serviceOfferingId;
+            this.templateId = templateId;
         }
 
         public AutoScaleVmProfile getProfile() {
@@ -311,11 +324,28 @@ public class LoadBalancingRule implements FirewallRule, LoadBalancer {
         public String getAutoScaleUserSecretKey() {
             return autoScaleUserSecretKey;
         }
+
         public String getCsUrl() {
             return csUrl;
         }
+
+        public String getZoneId() {
+            return zoneId;
+        }
+
+        public String getDomainId() {
+            return domainId;
         }
 
+        public String getServiceOfferingId() {
+            return serviceOfferingId;
+        }
+
+        public String getTemplateId() {
+            return templateId;
+    }
+    }
+
     public static class LbAutoScaleVmGroup {
         AutoScaleVmGroup vmGroup;
         private final List<LbAutoScalePolicy> policies;
@@ -345,4 +375,5 @@ public class LoadBalancingRule implements FirewallRule, LoadBalancer {
             return currentState;
         }
     }
+
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/70bbd8b0/api/src/com/cloud/network/rules/LoadBalancer.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/network/rules/LoadBalancer.java b/api/src/com/cloud/network/rules/LoadBalancer.java
index 9c67f29..9734e7e 100644
--- a/api/src/com/cloud/network/rules/LoadBalancer.java
+++ b/api/src/com/cloud/network/rules/LoadBalancer.java
@@ -17,7 +17,7 @@
 package com.cloud.network.rules;
 
 /**
- * Definition for a LoadBalancer 
+ * Definition for a LoadBalancer
  */
 public interface LoadBalancer extends FirewallRule {
 
@@ -26,9 +26,10 @@ public interface LoadBalancer extends FirewallRule {
     String getDescription();
 
     int getDefaultPortStart();
-    
+
     int getDefaultPortEnd();
 
     String getAlgorithm();
-    
+
+    String getUuid();
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/70bbd8b0/plugins/network-elements/elastic-loadbalancer/src/com/cloud/network/lb/ElasticLoadBalancerManagerImpl.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/elastic-loadbalancer/src/com/cloud/network/lb/ElasticLoadBalancerManagerImpl.java b/plugins/network-elements/elastic-loadbalancer/src/com/cloud/network/lb/ElasticLoadBalancerManagerImpl.java
index 57e631e..0cdb87f 100644
--- a/plugins/network-elements/elastic-loadbalancer/src/com/cloud/network/lb/ElasticLoadBalancerManagerImpl.java
+++ b/plugins/network-elements/elastic-loadbalancer/src/com/cloud/network/lb/ElasticLoadBalancerManagerImpl.java
@@ -5,7 +5,7 @@
 // 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,
@@ -137,7 +137,7 @@ import com.cloud.vm.dao.DomainRouterDao;
 public class ElasticLoadBalancerManagerImpl implements
 ElasticLoadBalancerManager, Manager,  VirtualMachineGuru<DomainRouterVO> {
     private static final Logger s_logger = Logger
-    .getLogger(ElasticLoadBalancerManagerImpl.class);
+            .getLogger(ElasticLoadBalancerManagerImpl.class);
 
     @Inject
     IPAddressDao _ipAddressDao;
@@ -181,16 +181,15 @@ ElasticLoadBalancerManager, Manager,  VirtualMachineGuru<DomainRouterVO> {
     PodVlanMapDao _podVlanMapDao;
     @Inject
     ElasticLbVmMapDao _elbVmMapDao;
-    @Inject
+    @Inject 
     NetworkDao _networksDao;
-    @Inject
+    @Inject 
     AccountDao _accountDao;
     @Inject
     PhysicalNetworkServiceProviderDao _physicalProviderDao;
     @Inject
     VirtualRouterProviderDao _vrProviderDao;
 
-
     String _name;
     String _instance;
     static final private String _elbVmNamePrefix = "l";
@@ -220,8 +219,7 @@ ElasticLoadBalancerManager, Manager,  VirtualMachineGuru<DomainRouterVO> {
         }
     }
 
-
-    public DomainRouterVO deployLoadBalancerVM(Long networkId, IPAddressVO ipAddr, Long accountId) {
+    public DomainRouterVO deployLoadBalancerVM(Long networkId, IPAddressVO ipAddr, Long accountId) {  
         NetworkVO network = _networkDao.findById(networkId);
         DataCenter dc = _dcDao.findById(network.getDataCenterId());
         Long podId = getPodIdForDirectIp(ipAddr);
@@ -280,7 +278,6 @@ ElasticLoadBalancerManager, Manager,  VirtualMachineGuru<DomainRouterVO> {
     private void createApplyLoadBalancingRulesCommands(
             List<LoadBalancingRule> rules, DomainRouterVO elbVm, Commands cmds) {
 
-
         LoadBalancerTO[] lbs = new LoadBalancerTO[rules.size()];
         int i = 0;
         for (LoadBalancingRule rule : rules) {
@@ -290,11 +287,12 @@ ElasticLoadBalancerManager, Manager,  VirtualMachineGuru<DomainRouterVO> {
             String algorithm = rule.getAlgorithm();
 
             String elbIp = _networkMgr.getIp(rule.getSourceIpAddressId()).getAddress()
-            .addr();
+                    .addr();
             int srcPort = rule.getSourcePortStart();
+            String uuid = rule.getUuid();
             List<LbDestination> destinations = rule.getDestinations();
-            LoadBalancerTO lb = new LoadBalancerTO(rule.getId(), elbIp, srcPort, protocol, algorithm, revoked, false, destinations);
-            lbs[i++] = lb;
+            LoadBalancerTO lb = new LoadBalancerTO(uuid, elbIp, srcPort, protocol, algorithm, revoked, false, destinations);
+            lbs[i++] = lb; 
         }
 
         LoadBalancerConfigCommand cmd = new LoadBalancerConfigCommand(lbs,elbVm.getPublicIpAddress(),elbVm.getGuestIpAddress(),elbVm.getPrivateIpAddress());
@@ -333,7 +331,7 @@ ElasticLoadBalancerManager, Manager,  VirtualMachineGuru<DomainRouterVO> {
     @Override
     public boolean applyLoadBalancerRules(Network network,
             List<? extends FirewallRule> rules)
-    throws ResourceUnavailableException {
+                    throws ResourceUnavailableException {
         if (rules == null || rules.isEmpty()) {
             return true;
         }
@@ -360,7 +358,7 @@ ElasticLoadBalancerManager, Manager,  VirtualMachineGuru<DomainRouterVO> {
                 List<LbStickinessPolicy> policyList = _lbMgr.getStickinessPolicies(lb.getId());
                 LoadBalancingRule loadBalancing = new LoadBalancingRule(
                         lb, dstList, policyList);
-                lbRules.add(loadBalancing);
+                lbRules.add(loadBalancing); 
             }
             return applyLBRules(elbVm, lbRules);
         } else if (elbVm.getState() == State.Stopped
@@ -380,7 +378,7 @@ ElasticLoadBalancerManager, Manager,  VirtualMachineGuru<DomainRouterVO> {
 
     @Override
     public boolean configure(String name, Map<String, Object> params)
-    throws ConfigurationException {
+            throws ConfigurationException {
         _name = name;
         final Map<String, String> configs = _configDao.getConfiguration("AgentManager", params);
         _systemAcct = _accountService.getSystemAccount();
@@ -396,14 +394,12 @@ ElasticLoadBalancerManager, Manager,  VirtualMachineGuru<DomainRouterVO> {
         _elasticLbVmRamSize = NumbersUtil.parseInt(configs.get(Config.ElasticLoadBalancerVmMemory.key()), DEFAULT_ELB_VM_RAMSIZE);
         _elasticLbvmCpuMHz = NumbersUtil.parseInt(configs.get(Config.ElasticLoadBalancerVmCpuMhz.key()), DEFAULT_ELB_VM_CPU_MHZ);
         _elasticLbvmNumCpu = NumbersUtil.parseInt(configs.get(Config.ElasticLoadBalancerVmNumVcpu.key()), 1);
-        _elasticLbVmOffering = new ServiceOfferingVO("System Offering For Elastic LB VM", _elasticLbvmNumCpu,
-                _elasticLbVmRamSize, _elasticLbvmCpuMHz, 0, 0, true, null, useLocalStorage,
+        _elasticLbVmOffering = new ServiceOfferingVO("System Offering For Elastic LB VM", _elasticLbvmNumCpu, 
+                _elasticLbVmRamSize, _elasticLbvmCpuMHz, 0, 0, true, null, useLocalStorage, 
                 true, null, true, VirtualMachine.Type.ElasticLoadBalancerVm, true);
         _elasticLbVmOffering.setUniqueName(ServiceOffering.elbVmDefaultOffUniqueName);
         _elasticLbVmOffering = _serviceOfferingDao.persistSystemServiceOffering(_elasticLbVmOffering);
 
-
-
         String enabled = _configDao.getValue(Config.ElasticLoadBalancerEnabled.key());
         _enabled = (enabled == null) ? false: Boolean.parseBoolean(enabled);
         s_logger.info("Elastic Load balancer enabled: " + _enabled);
@@ -417,7 +413,7 @@ ElasticLoadBalancerManager, Manager,  VirtualMachineGuru<DomainRouterVO> {
                 throw new ConfigurationException("ELB: Traffic type for front end of load balancer has to be guest or public; found : " + traffType);
             s_logger.info("ELB: Elastic Load Balancer: will balance on " + traffType );
             int gcIntervalMinutes =  NumbersUtil.parseInt(configs.get(Config.ElasticLoadBalancerVmGcInterval.key()), 5);
-            if (gcIntervalMinutes < 5)
+            if (gcIntervalMinutes < 5) 
                 gcIntervalMinutes = 5;
             s_logger.info("ELB: Elastic Load Balancer: scheduling GC to run every " + gcIntervalMinutes + " minutes" );
             _gcThreadPool = Executors.newScheduledThreadPool(1, new NamedThreadFactory("ELBVM-GC"));
@@ -425,7 +421,6 @@ ElasticLoadBalancerManager, Manager,  VirtualMachineGuru<DomainRouterVO> {
             _itMgr.registerGuru(VirtualMachine.Type.ElasticLoadBalancerVm, this);
         }
 
-
         return true;
     }
 
@@ -478,10 +473,9 @@ ElasticLoadBalancerManager, Manager,  VirtualMachineGuru<DomainRouterVO> {
             if (s_logger.isDebugEnabled()) {
                 s_logger.debug("Starting a ELB vm for network configurations: " + guestNetwork + " in " + dest);
             }
-            assert guestNetwork.getState() == Network.State.Implemented
-            || guestNetwork.getState() == Network.State.Setup
-            || guestNetwork.getState() == Network.State.Implementing
-            : "Network is not yet fully implemented: "+ guestNetwork;
+            assert guestNetwork.getState() == Network.State.Implemented 
+                    || guestNetwork.getState() == Network.State.Setup 
+                    || guestNetwork.getState() == Network.State.Implementing : "Network is not yet fully implemented: " + guestNetwork;
 
             DataCenterDeployment plan = null;
             DomainRouterVO elbVm = null;
@@ -529,7 +523,6 @@ ElasticLoadBalancerManager, Manager,  VirtualMachineGuru<DomainRouterVO> {
                 elbVm = this.start(elbVm, _accountService.getSystemUser(), _accountService.getSystemAccount(), params);
             }
 
-
             return elbVm;
         } finally {
             _networkDao.releaseFromLockTable(guestNetworkId);
@@ -546,7 +539,6 @@ ElasticLoadBalancerManager, Manager,  VirtualMachineGuru<DomainRouterVO> {
         }
     }
 
-
     private DomainRouterVO stop(DomainRouterVO elbVm, boolean forced, User user, Account caller) throws ConcurrentOperationException, ResourceUnavailableException {
         s_logger.debug("Stopping ELB vm " + elbVm);
         try {
@@ -562,7 +554,7 @@ ElasticLoadBalancerManager, Manager,  VirtualMachineGuru<DomainRouterVO> {
 
     protected List<LoadBalancerVO> findExistingLoadBalancers(String lbName, Long ipId, Long accountId, Long domainId, Integer publicPort) {
         SearchBuilder<LoadBalancerVO> sb = _lbDao.createSearchBuilder();
-        sb.and("name", sb.entity().getName(), SearchCriteria.Op.EQ);
+        sb.and("name", sb.entity().getName(), SearchCriteria.Op.EQ); 
         sb.and("accountId", sb.entity().getAccountId(), SearchCriteria.Op.EQ);
         sb.and("publicPort", sb.entity().getSourcePortStart(), SearchCriteria.Op.EQ);
         if (ipId != null) {
@@ -579,7 +571,7 @@ ElasticLoadBalancerManager, Manager,  VirtualMachineGuru<DomainRouterVO> {
         sc.setParameters("accountId", accountId);
         if (ipId != null) {
             sc.setParameters("sourceIpAddress", ipId);
-        }
+        } 
         if (domainId != null) {
             sc.setParameters("domainId",domainId);
         }
@@ -599,7 +591,7 @@ ElasticLoadBalancerManager, Manager,  VirtualMachineGuru<DomainRouterVO> {
 
         PublicIp ip = _networkMgr.assignPublicIpAddress(frontEndNetwork.getDataCenterId(), null, account, VlanType.DirectAttached, frontEndNetwork.getId(), null, true);
         IPAddressVO ipvo = _ipAddressDao.findById(ip.getId());
-        ipvo.setAssociatedWithNetworkId(frontEndNetwork.getId());
+        ipvo.setAssociatedWithNetworkId(frontEndNetwork.getId()); 
         _ipAddressDao.update(ipvo.getId(), ipvo);
         txn.commit();
         s_logger.info("Acquired frontend IP for ELB " + ip);
@@ -610,7 +602,7 @@ ElasticLoadBalancerManager, Manager,  VirtualMachineGuru<DomainRouterVO> {
     public void releaseIp(long ipId, long userId, Account caller) {
         s_logger.info("ELB: Release public IP for loadbalancing " + ipId);
         IPAddressVO ipvo = _ipAddressDao.findById(ipId);
-        ipvo.setAssociatedWithNetworkId(null);
+        ipvo.setAssociatedWithNetworkId(null); 
         _ipAddressDao.update(ipvo.getId(), ipvo);
         _networkMgr.releasePublicIpAddress(ipId, userId, caller);
         _ipAddressDao.unassignIpAddress(ipId);
@@ -643,7 +635,7 @@ ElasticLoadBalancerManager, Manager,  VirtualMachineGuru<DomainRouterVO> {
                         existingLbs = findExistingLoadBalancers(lb.getName(), null, lb.getAccountId(), lb.getDomainId(), null);
                         if (existingLbs != null) {
                             throw new InvalidParameterValueException("Supplied LB name " + lb.getName() + " is not associated with IP " + lb.getSourceIpAddressId() );
-                        }
+                        } 
                     } else {
                         s_logger.debug("Could not find any existing frontend ips for this account for this LB rule, acquiring a new frontent IP for ELB");
                         PublicIp ip = allocDirectIp(account, networkId);
@@ -676,7 +668,6 @@ ElasticLoadBalancerManager, Manager,  VirtualMachineGuru<DomainRouterVO> {
 
             DomainRouterVO elbVm = null;
 
-
             if (existingLbs == null) {
                 elbVm = findELBVmWithCapacity(network, ipAddr);
                 if (elbVm == null) {
@@ -780,7 +771,6 @@ ElasticLoadBalancerManager, Manager,  VirtualMachineGuru<DomainRouterVO> {
         }
     }
 
-
     @Override
     public DomainRouterVO findByName(String name) {
         if (!VirtualMachineName.isValidSystemVmName(name, _instance, _elbVmNamePrefix)) {
@@ -790,19 +780,16 @@ ElasticLoadBalancerManager, Manager,  VirtualMachineGuru<DomainRouterVO> {
         return _routerDao.findById(VirtualMachineName.getSystemVmId(name));
     }
 
-
     @Override
     public DomainRouterVO findById(long id) {
         return _routerDao.findById(id);
     }
 
-
     @Override
     public DomainRouterVO persist(DomainRouterVO elbVm) {
         return _routerDao.persist(elbVm);
     }
 
-
     @Override
     public boolean finalizeVirtualMachineProfile(VirtualMachineProfile<DomainRouterVO> profile, DeployDestination dest, ReservationContext context) {
         DomainRouterVO elbVm = profile.getVirtualMachine();
@@ -855,7 +842,7 @@ ElasticLoadBalancerManager, Manager,  VirtualMachineGuru<DomainRouterVO> {
         String domain = network.getNetworkDomain();
         if (domain != null) {
             buf.append(" domain=" + domain);
-        }
+        }  
 
         buf.append(" dns1=").append(defaultDns1);
         if (defaultDns2 != null) {
@@ -873,7 +860,6 @@ ElasticLoadBalancerManager, Manager,  VirtualMachineGuru<DomainRouterVO> {
         return true;
     }
 
-
     @Override
     public boolean finalizeDeployment(Commands cmds, VirtualMachineProfile<DomainRouterVO> profile, DeployDestination dest, ReservationContext context) throws ResourceUnavailableException {
         DomainRouterVO elbVm = profile.getVirtualMachine();
@@ -897,7 +883,6 @@ ElasticLoadBalancerManager, Manager,  VirtualMachineGuru<DomainRouterVO> {
         return true;
     }
 
-
     @Override
     public boolean finalizeStart(VirtualMachineProfile<DomainRouterVO> profile, long hostId, Commands cmds, ReservationContext context) {
         CheckSshAnswer answer = (CheckSshAnswer) cmds.getAnswer("checkSsh");
@@ -909,7 +894,6 @@ ElasticLoadBalancerManager, Manager,  VirtualMachineGuru<DomainRouterVO> {
         return true;
     }
 
-
     @Override
     public boolean finalizeCommandsOnStart(Commands cmds, VirtualMachineProfile<DomainRouterVO> profile) {
         DomainRouterVO elbVm = profile.getVirtualMachine();
@@ -958,7 +942,6 @@ ElasticLoadBalancerManager, Manager,  VirtualMachineGuru<DomainRouterVO> {
         return true;
     }
 
-
     @Override
     public void finalizeStop(VirtualMachineProfile<DomainRouterVO> profile, StopAnswer answer) {
         if (answer != null) {
@@ -972,7 +955,6 @@ ElasticLoadBalancerManager, Manager,  VirtualMachineGuru<DomainRouterVO> {
         //TODO: process network usage stats
     }
 
-
     @Override
     public void finalizeExpunge(DomainRouterVO vm) {
         // no-op
@@ -989,7 +971,6 @@ ElasticLoadBalancerManager, Manager,  VirtualMachineGuru<DomainRouterVO> {
         return VirtualMachineName.getSystemVmId(vmName);
     }
 
-
     @Override
     public boolean recreateNeeded(
             VirtualMachineProfile<DomainRouterVO> profile, long hostId,

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/70bbd8b0/plugins/network-elements/netscaler/src/com/cloud/network/element/NetscalerElement.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/netscaler/src/com/cloud/network/element/NetscalerElement.java b/plugins/network-elements/netscaler/src/com/cloud/network/element/NetscalerElement.java
index 1b5f17a..49c3b08 100644
--- a/plugins/network-elements/netscaler/src/com/cloud/network/element/NetscalerElement.java
+++ b/plugins/network-elements/netscaler/src/com/cloud/network/element/NetscalerElement.java
@@ -367,7 +367,7 @@ StaticNatServiceProvider {
                 HostPodVO pod = _podDao.findById(podId);
                 if (pod == null) {
                     throw new InvalidParameterValueException("Can't find pod by id " + podId);
-                }
+        }
             }
 
             for (Long podId: newPodsConfig) {
@@ -657,12 +657,13 @@ StaticNatServiceProvider {
             boolean revoked = (rule.getState().equals(FirewallRule.State.Revoke));
             String protocol = rule.getProtocol();
             String algorithm = rule.getAlgorithm();
+            String lbUuid = rule.getUuid();
             String srcIp = _networkMgr.getIp(rule.getSourceIpAddressId()).getAddress().addr();
             int srcPort = rule.getSourcePortStart();
             List<LbDestination> destinations = rule.getDestinations();
 
             if ((destinations != null && !destinations.isEmpty()) || rule.isAutoScaleConfig()) {
-                LoadBalancerTO loadBalancer = new LoadBalancerTO(rule.getId(), srcIp, srcPort, protocol, algorithm, revoked, false, destinations, rule.getStickinessPolicies());
+                LoadBalancerTO loadBalancer = new LoadBalancerTO(lbUuid, srcIp, srcPort, protocol, algorithm, revoked, false, destinations, rule.getStickinessPolicies());
                 if(rule.isAutoScaleConfig()) {
                     loadBalancer.setAutoScaleVmGroup(rule.getAutoScaleVmGroup());
                 }
@@ -699,41 +700,41 @@ StaticNatServiceProvider {
 
         try {
             if (!multiNetScalerDeployment) {
-                String errMsg;
-                ExternalLoadBalancerDeviceVO lbDevice = getExternalLoadBalancerForNetwork(config);
-                if (lbDevice == null) {
-                    try {
-                        lbDevice = allocateLoadBalancerForNetwork(config);
-                    } catch (Exception e) {
-                        errMsg = "Could not allocate a NetSclaer load balancer for configuring static NAT rules due to" + e.getMessage();
-                        s_logger.error(errMsg);
-                        throw new ResourceUnavailableException(errMsg, this.getClass(), 0);
-                    }
-                }
+        String errMsg;
+        ExternalLoadBalancerDeviceVO lbDevice = getExternalLoadBalancerForNetwork(config);
+        if (lbDevice == null) {
+            try {
+                lbDevice = allocateLoadBalancerForNetwork(config);
+            } catch (Exception e) {
+                errMsg = "Could not allocate a NetSclaer load balancer for configuring static NAT rules due to" + e.getMessage();
+                s_logger.error(errMsg);
+                throw new ResourceUnavailableException(errMsg, this.getClass(), 0);
+            }
+        }
 
-                if (!isNetscalerDevice(lbDevice.getDeviceName())) {
-                    errMsg = "There are no NetScaler load balancer assigned for this network. So NetScaler element will not be handling the static nat rules.";
-                    s_logger.error(errMsg);
-                    throw new ResourceUnavailableException(errMsg, this.getClass(), 0);
-                }
-                SetStaticNatRulesAnswer answer = null;
-                List<StaticNatRuleTO> rulesTO = null;
-                if (rules != null) {
-                    rulesTO = new ArrayList<StaticNatRuleTO>();
-                    for (StaticNat rule : rules) {
-                        IpAddress sourceIp = _networkMgr.getIp(rule.getSourceIpAddressId());
-                        StaticNatRuleTO ruleTO = new StaticNatRuleTO(0, sourceIp.getAddress().addr(), null, null, rule.getDestIpAddress(), null, null, null, rule.isForRevoke(), false);
-                        rulesTO.add(ruleTO);
-                    }
+        if (!isNetscalerDevice(lbDevice.getDeviceName())) {
+            errMsg = "There are no NetScaler load balancer assigned for this network. So NetScaler element will not be handling the static nat rules.";
+            s_logger.error(errMsg);
+            throw new ResourceUnavailableException(errMsg, this.getClass(), 0);
+        }
+        SetStaticNatRulesAnswer answer = null;
+            List<StaticNatRuleTO> rulesTO = null;
+            if (rules != null) {
+                rulesTO = new ArrayList<StaticNatRuleTO>();
+                for (StaticNat rule : rules) {
+                    IpAddress sourceIp = _networkMgr.getIp(rule.getSourceIpAddressId());
+                    StaticNatRuleTO ruleTO = new StaticNatRuleTO(0, sourceIp.getAddress().addr(), null, null, rule.getDestIpAddress(), null, null, null, rule.isForRevoke(), false);
+                    rulesTO.add(ruleTO);
                 }
+            }
 
                 SetStaticNatRulesCommand cmd = new SetStaticNatRulesCommand(rulesTO);
-                answer = (SetStaticNatRulesAnswer) _agentMgr.send(lbDevice.getHostId(), cmd);
-                if (answer == null) {
-                    return false;
-                } else {
-                    return answer.getResult();
-                }
+            answer = (SetStaticNatRulesAnswer) _agentMgr.send(lbDevice.getHostId(), cmd);
+            if (answer == null) {
+                return false;
+            } else {
+                return answer.getResult();
+            }
             } else {
                 if (rules != null) {
                     for (StaticNat rule : rules) {
@@ -787,4 +788,4 @@ StaticNatServiceProvider {
         }
         return null;
     }
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/70bbd8b0/plugins/network-elements/netscaler/src/com/cloud/network/resource/NetscalerResource.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/netscaler/src/com/cloud/network/resource/NetscalerResource.java b/plugins/network-elements/netscaler/src/com/cloud/network/resource/NetscalerResource.java
index 1a53e4d..b78e770 100644
--- a/plugins/network-elements/netscaler/src/com/cloud/network/resource/NetscalerResource.java
+++ b/plugins/network-elements/netscaler/src/com/cloud/network/resource/NetscalerResource.java
@@ -24,6 +24,7 @@ import org.apache.log4j.Logger;
 
 import com.citrix.netscaler.nitro.exception.nitro_exception;
 import com.citrix.netscaler.nitro.resource.base.base_response;
+import com.citrix.netscaler.nitro.resource.config.autoscale.autoscalepolicy;
 import com.citrix.netscaler.nitro.resource.config.autoscale.autoscaleprofile;
 import com.citrix.netscaler.nitro.resource.config.basic.server_service_binding;
 import com.citrix.netscaler.nitro.resource.config.basic.servicegroup;
@@ -45,7 +46,6 @@ import com.citrix.netscaler.nitro.resource.config.ns.nshardware;
 import com.citrix.netscaler.nitro.resource.config.ns.nsip;
 import com.citrix.netscaler.nitro.resource.config.ns.nstimer;
 import com.citrix.netscaler.nitro.resource.config.ns.nstimer_autoscalepolicy_binding;
-import com.citrix.netscaler.nitro.resource.config.autoscale.*;
 import com.citrix.netscaler.nitro.resource.stat.lb.lbvserver_stats;
 import com.citrix.netscaler.nitro.service.nitro_service;
 import com.citrix.netscaler.nitro.util.filtervalue;
@@ -615,14 +615,14 @@ public class NetscalerResource implements ServerResource {
             saveConfiguration();
             return new Answer(cmd);
         } catch (ExecutionException e) {
-            s_logger.error("Failed to execute LoadBalancerConfigCommand due to " + e.getMessage());
+            s_logger.error("Failed to execute LoadBalancerConfigCommand due to ", e);
             if (shouldRetry(numRetries)) {
                 return retry(cmd, numRetries);
             } else {
                 return new Answer(cmd, e);
             }
         }  catch (Exception e) {
-            s_logger.error("Failed to execute LoadBalancerConfigCommand due to " + e.getMessage());
+            s_logger.error("Failed to execute LoadBalancerConfigCommand due to ", e);
             if (shouldRetry(numRetries)) {
                 return retry(cmd, numRetries);
             } else {
@@ -1363,7 +1363,8 @@ public class NetscalerResource implements ServerResource {
         return nsProtocol;
     }
 
-    private void addLBVirtualServer(String virtualServerName, String publicIp, int publicPort, String lbAlgorithm, String protocol, StickinessPolicyTO[] stickyPolicies, AutoScaleVmGroupTO vmGroupTO) throws ExecutionException {
+    private void addLBVirtualServer(String virtualServerName, String publicIp, int publicPort, String lbAlgorithm, String protocol, StickinessPolicyTO[] stickyPolicies, AutoScaleVmGroupTO vmGroupTO)
+            throws ExecutionException {
         try {
             String lbMethod;
             if ("roundrobin".equalsIgnoreCase(lbAlgorithm)) {
@@ -1512,6 +1513,7 @@ public class NetscalerResource implements ServerResource {
         int srcPort = loadBalancerTO.getSrcPort();
         String lbProtocol = getNetScalerProtocol(loadBalancerTO);
         String lbAlgorithm = loadBalancerTO.getAlgorithm();
+        String vmGroupIdentifier = generateAutoScaleVmGroupIdentifier(loadBalancerTO);
         String nsVirtualServerName  = generateNSVirtualServerName(srcIp, srcPort);
         AutoScaleVmGroupTO vmGroupTO = loadBalancerTO.getAutoScaleVmGroupTO();
         if (s_logger.isDebugEnabled()) {
@@ -1519,7 +1521,7 @@ public class NetscalerResource implements ServerResource {
         }
         addLBVirtualServer(nsVirtualServerName, srcIp, srcPort, lbAlgorithm, lbProtocol, loadBalancerTO.getStickinessPolicies(), vmGroupTO);
 
-        String serviceGroupName  = generateAutoScaleServiceGroupName(srcIp, srcPort);
+        String serviceGroupName = generateAutoScaleServiceGroupName(vmGroupIdentifier);
         if(!nsServiceGroupExists(serviceGroupName)) {
             // add servicegroup lb_autoscaleGroup -autoscale POLICY -memberPort 80
             int memberPort = vmGroupTO.getMemberPort();
@@ -1558,15 +1560,16 @@ public class NetscalerResource implements ServerResource {
     private synchronized boolean removeAutoScaleConfig(LoadBalancerTO loadBalancerTO) throws Exception, ExecutionException {
         String srcIp = loadBalancerTO.getSrcIp();
         int srcPort = loadBalancerTO.getSrcPort();
+        String vmGroupIdentifier = generateAutoScaleVmGroupIdentifier(loadBalancerTO);
 
         String nsVirtualServerName  = generateNSVirtualServerName(srcIp, srcPort);
-        String serviceGroupName  = generateAutoScaleServiceGroupName(srcIp, srcPort);
+        String serviceGroupName = generateAutoScaleServiceGroupName(vmGroupIdentifier);
 
         if (loadBalancerTO.getAutoScaleVmGroupTO().getCurrentState().equals("enabled")) {
             disableAutoScaleConfig(loadBalancerTO, false);
         }
 
-        if (isServiceGroupBoundToVirtualServer(nsVirtualServerName, serviceGroupName)) {
+        if(isServiceGroupBoundToVirtualServer(nsVirtualServerName, serviceGroupName)) {
             // UnBind autoscale service group
             // unbind lb vserver lb lb_autoscaleGroup
             lbvserver_servicegroup_binding vserver_servicegroup_binding = new lbvserver_servicegroup_binding();
@@ -1597,17 +1600,18 @@ public class NetscalerResource implements ServerResource {
 
     @SuppressWarnings("static-access")
     private synchronized boolean enableAutoScaleConfig(LoadBalancerTO loadBalancerTO, boolean isCleanUp) throws Exception {
+        String vmGroupIdentifier = generateAutoScaleVmGroupIdentifier(loadBalancerTO);
         String srcIp = loadBalancerTO.getSrcIp();
         int srcPort = loadBalancerTO.getSrcPort();
 
         String nsVirtualServerName  = generateNSVirtualServerName(srcIp, srcPort);
-        String serviceGroupName  = generateAutoScaleServiceGroupName(srcIp, srcPort);
-        String profileName = generateAutoScaleProfileName(srcIp, srcPort);
-        String timerName = generateAutoScaleTimerName(srcIp, srcPort);
-        String scaleDownActionName = generateAutoScaleScaleDownActionName(srcIp, srcPort);
-        String scaleUpActionName = generateAutoScaleScaleUpActionName(srcIp, srcPort);
-        String mtName = generateSnmpMetricTableName(srcIp, srcPort);
-        String monitorName = generateSnmpMonitorName(srcIp, srcPort);
+        String serviceGroupName = generateAutoScaleServiceGroupName(vmGroupIdentifier);
+        String profileName = generateAutoScaleProfileName(vmGroupIdentifier);
+        String timerName = generateAutoScaleTimerName(vmGroupIdentifier);
+        String scaleDownActionName = generateAutoScaleScaleDownActionName(vmGroupIdentifier);
+        String scaleUpActionName = generateAutoScaleScaleUpActionName(vmGroupIdentifier);
+        String mtName = generateSnmpMetricTableName(vmGroupIdentifier);
+        String monitorName = generateSnmpMonitorName(vmGroupIdentifier);
         AutoScaleVmGroupTO vmGroupTO = loadBalancerTO.getAutoScaleVmGroupTO();
         AutoScaleVmProfileTO profileTO = vmGroupTO.getProfile();
         List<AutoScalePolicyTO> policies = vmGroupTO.getPolicies();
@@ -1630,7 +1634,8 @@ public class NetscalerResource implements ServerResource {
                 vserver.update(_netscalerService, vserver);
             } catch (Exception e) {
                 // Ignore Exception on cleanup
-                if(!isCleanUp) throw e;
+                if (!isCleanUp)
+                    throw e;
             }
 
             /* AutoScale Config */
@@ -1651,7 +1656,8 @@ public class NetscalerResource implements ServerResource {
                 autoscaleProfile.add(_netscalerService, autoscaleProfile);
             } catch (Exception e) {
                 // Ignore Exception on cleanup
-                if(!isCleanUp) throw e;
+                if (!isCleanUp)
+                    throw e;
             }
 
             // Add Timer
@@ -1662,7 +1668,8 @@ public class NetscalerResource implements ServerResource {
                 timer.add(_netscalerService, timer);
             } catch (Exception e) {
                 // Ignore Exception on cleanup
-                if(!isCleanUp) throw e;
+                if (!isCleanUp)
+                    throw e;
             }
 
             // AutoScale Actions
@@ -1703,12 +1710,13 @@ public class NetscalerResource implements ServerResource {
                 ApiConstants.SERVICE_OFFERING_ID + "=" + profileTO.getServiceOfferingId()+ "&" +
                 ApiConstants.TEMPLATE_ID + "=" + profileTO.getTemplateId()+ "&" +
                 ((profileTO.getOtherDeployParams() == null)? "" : (profileTO.getOtherDeployParams() + "&")) +
-            "lbruleid=" + loadBalancerTO.getId();
+                        "lbruleid=" + loadBalancerTO.getUuid();
                 scaleUpAction.set_parameters(scaleUpParameters);
                 scaleUpAction.add(_netscalerService, scaleUpAction);
             } catch (Exception e) {
                 // Ignore Exception on cleanup
-                if(!isCleanUp) throw e;
+                if (!isCleanUp)
+                    throw e;
             }
 
             com.citrix.netscaler.nitro.resource.config.autoscale.autoscaleaction scaleDownAction = new com.citrix.netscaler.nitro.resource.config.autoscale.autoscaleaction();
@@ -1721,23 +1729,24 @@ public class NetscalerResource implements ServerResource {
                 scaleDownAction.set_profilename(profileName);
                 scaleDownAction.set_quiettime(scaleDownQuietTime);
                 String scaleDownParameters = "command=destroyVirtualMachine" + "&" +
-            "lbruleid=" + loadBalancerTO.getId();
+                        "lbruleid=" + loadBalancerTO.getUuid();
                 scaleDownAction.set_parameters(scaleDownParameters);
                 scaleDownAction.set_vmdestroygraceperiod(destroyVmGracePeriod);
                 scaleDownAction.add(_netscalerService, scaleDownAction);
             } catch (Exception e) {
                 // Ignore Exception on cleanup
-                if(!isCleanUp) throw e;
+                if (!isCleanUp)
+                    throw e;
             }
 
             /* Create min member policy */
-        String minMemberPolicyName = generateAutoScaleMinPolicyName(srcIp, srcPort);
+            String minMemberPolicyName = generateAutoScaleMinPolicyName(vmGroupIdentifier);
             String minMemberPolicyExp = "SYS.VSERVER(\"" + nsVirtualServerName + "\").ACTIVESERVICES.LT(SYS.VSERVER(\"" + nsVirtualServerName + "\").MINAUTOSCALEMEMBERS)";
             addAutoScalePolicy(timerName, minMemberPolicyName, cur_prirotiy++, minMemberPolicyExp, scaleUpActionName,
                     interval, interval, isCleanUp);
 
             /* Create max member policy */
-        String maxMemberPolicyName = generateAutoScaleMaxPolicyName(srcIp, srcPort);
+            String maxMemberPolicyName = generateAutoScaleMaxPolicyName(vmGroupIdentifier);
             String maxMemberPolicyExp = "SYS.VSERVER(\"" + nsVirtualServerName + "\").ACTIVESERVICES.GT(SYS.VSERVER(\"" + nsVirtualServerName + "\").MAXAUTOSCALEMEMBERS)";
             addAutoScalePolicy(timerName, maxMemberPolicyName, cur_prirotiy++, maxMemberPolicyExp, scaleDownActionName,
                     interval, interval, isCleanUp);
@@ -1769,7 +1778,8 @@ public class NetscalerResource implements ServerResource {
                                 metricTable.add(_netscalerService, metricTable);
                             } catch (Exception e) {
                                 // Ignore Exception on cleanup
-                                if(!isCleanUp) throw e;
+                                if (!isCleanUp)
+                                    throw e;
                             }
 
                             // Create Monitor
@@ -1786,7 +1796,8 @@ public class NetscalerResource implements ServerResource {
                                 monitor.add(_netscalerService, monitor);
                             } catch (Exception e) {
                                 // Ignore Exception on cleanup
-                                if(!isCleanUp) throw e;
+                                if (!isCleanUp)
+                                    throw e;
                             }
 
                             // Bind monitor to servicegroup.
@@ -1803,7 +1814,8 @@ public class NetscalerResource implements ServerResource {
                                 servicegroup_lbmonitor_binding.add(_netscalerService, servicegroup_monitor_binding);
                             } catch (Exception e) {
                                 // Ignore Exception on cleanup
-                                if(!isCleanUp) throw e;
+                                if (!isCleanUp)
+                                    throw e;
                             }
                         }
 
@@ -1824,7 +1836,8 @@ public class NetscalerResource implements ServerResource {
                                 metrictable_metric_binding.add(_netscalerService, metrictable_metric_binding);
                             } catch (Exception e) {
                                 // Ignore Exception on cleanup
-                                if(!isCleanUp) throw e;
+                                if (!isCleanUp)
+                                    throw e;
                             }
 
                             // bind lb monitor lb_metric_table_mon -metric cpu -metricThreshold 1
@@ -1841,11 +1854,13 @@ public class NetscalerResource implements ServerResource {
                                 monitor_metric_binding.add(_netscalerService, monitor_metric_binding);
                             } catch (Exception e) {
                                 // Ignore Exception on cleanup
-                                if(!isCleanUp) throw e;
+                                if (!isCleanUp)
+                                    throw e;
                             }
                         }
                         // SYS.VSERVER("abcd").SNMP_TABLE(0).AVERAGE_VALUE.GT(80)
-                    int counterIndex = snmpMetrics.get(counterName); // TODO: temporary fix. later on counter name will be added as a param to SNMP_TABLE.
+                        int counterIndex = snmpMetrics.get(counterName); // TODO: temporary fix. later on counter name
+// will be added as a param to SNMP_TABLE.
                         formatter.format("SYS.VSERVER(\"%s\").SNMP_TABLE(%d).AVERAGE_VALUE.%s(%d)",nsVirtualServerName, counterIndex, operator, threshold);
                     }
                     else if (counterTO.getSource().equals("netscaler"))
@@ -1861,7 +1876,7 @@ public class NetscalerResource implements ServerResource {
                 policyExpression = "(" + policyExpression + ")";
 
                 String policyId = Long.toString(autoScalePolicyTO.getId());
-            String policyName = generateAutoScalePolicyName(srcIp, srcPort, policyId);
+                String policyName = generateAutoScalePolicyName(vmGroupIdentifier, policyId);
                 String action = null;
                 if(isScaleUpPolicy(autoScalePolicyTO)) {
                     action = scaleUpActionName;
@@ -1892,24 +1907,22 @@ public class NetscalerResource implements ServerResource {
         return true;
     }
 
-
     @SuppressWarnings("static-access")
     private synchronized boolean disableAutoScaleConfig(LoadBalancerTO loadBalancerTO, boolean isCleanUp) throws Exception {
-        String srcIp = loadBalancerTO.getSrcIp();
-        int srcPort = loadBalancerTO.getSrcPort();
 
-        String nsVirtualServerName  = generateNSVirtualServerName(srcIp, srcPort);
-        String profileName = generateAutoScaleProfileName(srcIp, srcPort);
-        String timerName = generateAutoScaleTimerName(srcIp, srcPort);
-        String scaleDownActionName = generateAutoScaleScaleDownActionName(srcIp, srcPort);
-        String scaleUpActionName = generateAutoScaleScaleUpActionName(srcIp, srcPort);
-        String mtName = generateSnmpMetricTableName(srcIp, srcPort);
-        String monitorName = generateSnmpMonitorName(srcIp, srcPort);
-        String serviceGroupName  = generateAutoScaleServiceGroupName(srcIp, srcPort);
+        String vmGroupIdentifier = generateAutoScaleVmGroupIdentifier(loadBalancerTO);
+
+        String profileName = generateAutoScaleProfileName(vmGroupIdentifier);
+        String timerName = generateAutoScaleTimerName(vmGroupIdentifier);
+        String scaleDownActionName = generateAutoScaleScaleDownActionName(vmGroupIdentifier);
+        String scaleUpActionName = generateAutoScaleScaleUpActionName(vmGroupIdentifier);
+        String mtName = generateSnmpMetricTableName(vmGroupIdentifier);
+        String monitorName = generateSnmpMonitorName(vmGroupIdentifier);
+        String serviceGroupName = generateAutoScaleServiceGroupName(vmGroupIdentifier);
         AutoScaleVmGroupTO vmGroupTO = loadBalancerTO.getAutoScaleVmGroupTO();
         List<AutoScalePolicyTO> policies = vmGroupTO.getPolicies();
-        String minMemberPolicyName = generateAutoScaleMinPolicyName(srcIp, srcPort);
-        String maxMemberPolicyName = generateAutoScaleMaxPolicyName(srcIp, srcPort);
+        String minMemberPolicyName = generateAutoScaleMinPolicyName(vmGroupIdentifier);
+        String maxMemberPolicyName = generateAutoScaleMaxPolicyName(vmGroupIdentifier);
 
         try {
 
@@ -1931,7 +1944,7 @@ public class NetscalerResource implements ServerResource {
                     }
                 }
                 String policyId = Long.toString(autoScalePolicyTO.getId());
-                String policyName = generateAutoScalePolicyName(srcIp, srcPort,policyId);
+                String policyName = generateAutoScalePolicyName(vmGroupIdentifier, policyId);
 
                 // Removing Timer policy
                 removeAutoScalePolicy(timerName, policyName, isCleanUp);
@@ -1945,7 +1958,8 @@ public class NetscalerResource implements ServerResource {
                 scaleDownAction.delete(_netscalerService, scaleDownAction);
             } catch (Exception e) {
                 // Ignore Exception on cleanup
-                if(!isCleanUp) throw e;
+                if (!isCleanUp)
+                    throw e;
             }
 
             // Delete AutoScale ScaleUp action
@@ -1955,7 +1969,8 @@ public class NetscalerResource implements ServerResource {
                 scaleUpAction.delete(_netscalerService, scaleUpAction);
             } catch (Exception e) {
                 // Ignore Exception on cleanup
-                if(!isCleanUp) throw e;
+                if (!isCleanUp)
+                    throw e;
             }
 
             // Delete Timer
@@ -1965,7 +1980,8 @@ public class NetscalerResource implements ServerResource {
                 timer.delete(_netscalerService, timer);
             } catch (Exception e) {
                 // Ignore Exception on cleanup
-                if(!isCleanUp) throw e;
+                if (!isCleanUp)
+                    throw e;
             }
 
             // Delete AutoScale Profile
@@ -1975,7 +1991,8 @@ public class NetscalerResource implements ServerResource {
                 autoscaleProfile.delete(_netscalerService, autoscaleProfile);
             } catch (Exception e) {
                 // Ignore Exception on cleanup
-                if(!isCleanUp) throw e;
+                if (!isCleanUp)
+                    throw e;
             }
 
             if(isSnmp) {
@@ -1986,7 +2003,8 @@ public class NetscalerResource implements ServerResource {
                     servicegroup_lbmonitor_binding.delete(_netscalerService, servicegroup_monitor_binding);
                 } catch (Exception e) {
                     // Ignore Exception on cleanup
-                    if(!isCleanUp) throw e;
+                    if (!isCleanUp)
+                        throw e;
                 }
 
                 // Delete Monitor
@@ -1998,7 +2016,8 @@ public class NetscalerResource implements ServerResource {
                     monitor.delete(_netscalerService, monitor);
                 } catch (Exception e) {
                     // Ignore Exception on cleanup
-                    if(!isCleanUp) throw e;
+                    if (!isCleanUp)
+                        throw e;
                 }
 
                 // Delete Metric Table
@@ -2008,7 +2027,8 @@ public class NetscalerResource implements ServerResource {
                     metricTable.delete(_netscalerService, metricTable);
                 } catch (Exception e) {
                     // Ignore Exception on cleanup
-                    if(!isCleanUp) throw e;
+                    if (!isCleanUp)
+                        throw e;
                 }
             }
         } catch (Exception ex) {
@@ -2025,7 +2045,6 @@ public class NetscalerResource implements ServerResource {
         return true;
     }
 
-
     private synchronized void addAutoScalePolicy(String timerName,String policyName,  long priority, String policyExpression, String action,
             int duration, int interval, boolean isCleanUp) throws Exception {
         // Adding a autoscale policy
@@ -2039,13 +2058,15 @@ public class NetscalerResource implements ServerResource {
             timerPolicy.add(_netscalerService, timerPolicy);
         } catch (Exception e) {
             // Ignore Exception on cleanup
-            if(!isCleanUp) throw e;
+            if (!isCleanUp)
+                throw e;
         }
 
         // bind timer policy
         // For now it is bound globally.
         // bind timer trigger lb_astimer -policyName lb_policy_scaleUp -vserver lb -priority 1 -samplesize 5
-        // TODO: later bind to lbvserver. bind timer trigger lb_astimer -policyName lb_policy_scaleUp -vserver lb -priority 1 -samplesize 5
+        // TODO: later bind to lbvserver. bind timer trigger lb_astimer -policyName lb_policy_scaleUp -vserver lb
+// -priority 1 -samplesize 5
         // -thresholdsize 5
         nstimer_autoscalepolicy_binding timer_policy_binding = new nstimer_autoscalepolicy_binding();
         int sampleSize = duration/interval;
@@ -2059,7 +2080,8 @@ public class NetscalerResource implements ServerResource {
             timer_policy_binding.add(_netscalerService, timer_policy_binding);
         } catch (Exception e) {
             // Ignore Exception on cleanup
-            if(!isCleanUp) throw e;
+            if (!isCleanUp)
+                throw e;
         }
     }
 
@@ -2073,7 +2095,8 @@ public class NetscalerResource implements ServerResource {
             timer_policy_binding.delete(_netscalerService, timer_policy_binding);
         } catch (Exception e) {
             // Ignore Exception on cleanup
-            if(!isCleanUp) throw e;
+            if (!isCleanUp)
+                throw e;
         }
 
         // Removing Timer policy
@@ -2084,12 +2107,12 @@ public class NetscalerResource implements ServerResource {
             timerPolicy.delete(_netscalerService, timerPolicy);
         } catch (Exception e) {
             // Ignore Exception on cleanup
-            if(!isCleanUp) throw e;
+            if (!isCleanUp)
+                throw e;
         }
 
     }
 
-
     private boolean isAutoScaleSupportedInNetScaler() throws ExecutionException {
         autoscaleprofile autoscaleProfile = new autoscaleprofile();
         try {
@@ -2196,44 +2219,48 @@ public class NetscalerResource implements ServerResource {
         return genObjectName("Cloud-Service", ip, port);
     }
 
-    private String generateAutoScaleServiceGroupName(String srcIp, long srcPort) {
-        return genObjectName("Cloud-AutoScaleServiceGroup", srcIp, srcPort);
+    private String generateAutoScaleVmGroupIdentifier(LoadBalancerTO lbTO) {
+        return lbTO.getSrcIp() + "-" + lbTO.getSrcPort();
+    }
+
+    private String generateAutoScaleServiceGroupName(String vmGroupIdentifier) {
+        return genObjectName("Cloud-AutoScale-SvcGrp", vmGroupIdentifier);
     }
 
-    private String generateAutoScaleTimerName(String srcIp, long srcPort) {
-        return genObjectName("Cloud-AutoScale-Timer", srcIp, srcPort);
+    private String generateAutoScaleTimerName(String vmGroupIdentifier) {
+        return genObjectName("Cloud-AutoScale-Timer", vmGroupIdentifier);
     }
 
-    private String generateAutoScaleProfileName(String srcIp, long srcPort) {
-        return genObjectName("Cloud-AutoScale-Profile", srcIp, srcPort);
+    private String generateAutoScaleProfileName(String vmGroupIdentifier) {
+        return genObjectName("Cloud-AutoScale-Profile", vmGroupIdentifier);
     }
 
-    private String generateAutoScaleScaleUpActionName(String srcIp, long srcPort) {
-        return genObjectName("Cloud-AutoScale-ScaleUpAction", srcIp, srcPort);
+    private String generateAutoScaleScaleUpActionName(String vmGroupIdentifier) {
+        return genObjectName("Cloud-AutoScale-ScaleUpAction", vmGroupIdentifier);
     }
 
-    private String generateAutoScaleScaleDownActionName(String srcIp, long srcPort) {
-        return genObjectName("Cloud-AutoScale-ScaleDownAction", srcIp, srcPort);
+    private String generateAutoScaleScaleDownActionName(String vmGroupIdentifier) {
+        return genObjectName("Cloud-AutoScale-ScaleDownAction", vmGroupIdentifier);
     }
 
-    private String generateAutoScalePolicyName(String srcIp, long srcPort, String poilcyId) {
-        return genObjectName("Cloud-AutoScale-Policy",  srcIp, srcPort, poilcyId);
+    private String generateAutoScalePolicyName(String vmGroupIdentifier, String poilcyId) {
+        return genObjectName("Cloud-AutoScale-Policy", vmGroupIdentifier, poilcyId);
     }
 
-    private String generateAutoScaleMinPolicyName(String srcIp, long srcPort) {
-        return genObjectName("Cloud-AutoScale-Policy-Min",  srcIp, srcPort);
+    private String generateAutoScaleMinPolicyName(String vmGroupIdentifier) {
+        return genObjectName("Cloud-AutoScale-Policy-Min", vmGroupIdentifier);
     }
 
-    private String generateAutoScaleMaxPolicyName(String srcIp, long srcPort) {
-        return genObjectName("Cloud-AutoScale-Policy-Max",  srcIp, srcPort);
+    private String generateAutoScaleMaxPolicyName(String vmGroupIdentifier) {
+        return genObjectName("Cloud-AutoScale-Policy-Max", vmGroupIdentifier);
     }
 
-    private String generateSnmpMetricTableName(String srcIp, long srcPort) {
-        return genObjectName("Cloud-MTbl", srcIp, srcPort);
+    private String generateSnmpMetricTableName(String vmGroupIdentifier) {
+        return genObjectName("Cloud-MTbl", vmGroupIdentifier);
     }
 
-    private String generateSnmpMonitorName(String srcIp, long srcPort) {
-        return genObjectName("Cloud-Mon", srcIp, srcPort);
+    private String generateSnmpMonitorName(String vmGroupIdentifier) {
+        return genObjectName("Cloud-Mon", vmGroupIdentifier);
     }
 
     private String generateSnmpMetricName(String counterName) {

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/70bbd8b0/server/src/com/cloud/network/ExternalLoadBalancerDeviceManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/ExternalLoadBalancerDeviceManagerImpl.java b/server/src/com/cloud/network/ExternalLoadBalancerDeviceManagerImpl.java
index ba3d689..0eb9783 100644
--- a/server/src/com/cloud/network/ExternalLoadBalancerDeviceManagerImpl.java
+++ b/server/src/com/cloud/network/ExternalLoadBalancerDeviceManagerImpl.java
@@ -5,7 +5,7 @@
 // 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,
@@ -115,6 +115,7 @@ import com.cloud.vm.Nic.State;
 import com.cloud.vm.NicVO;
 import com.cloud.vm.dao.DomainRouterDao;
 import com.cloud.vm.dao.NicDao;
+
 public abstract class ExternalLoadBalancerDeviceManagerImpl extends AdapterBase implements ExternalLoadBalancerDeviceManager, ResourceStateAdapter {
 
     @Inject
@@ -384,7 +385,7 @@ public abstract class ExternalLoadBalancerDeviceManagerImpl extends AdapterBase
                 if (deviceMapLock.lock(120)) {
                     try {
                         boolean dedicatedLB = offering.getDedicatedLB(); // does network offering supports a dedicated
-                        // load balancer?
+// load balancer?
                         long lbDeviceId;
 
                         txn.start();
@@ -398,7 +399,7 @@ public abstract class ExternalLoadBalancerDeviceManagerImpl extends AdapterBase
 
                             // persist the load balancer device id that will be used for this network. Once a network
                             // is implemented on a LB device then later on all rules will be programmed on to same
-                            // device
+// device
                             NetworkExternalLoadBalancerVO networkLB = new NetworkExternalLoadBalancerVO(guestConfig.getId(), lbDeviceId);
                             _networkExternalLBDao.persist(networkLB);
 
@@ -416,12 +417,12 @@ public abstract class ExternalLoadBalancerDeviceManagerImpl extends AdapterBase
                             if (tryLbProvisioning) {
                                 retry = false;
                                 // TODO: throwing warning instead of error for now as its possible another provider can
-                                // service this network
+// service this network
                                 s_logger.warn("There are no load balancer device with the capacity for implementing this network");
                                 throw exception;
                             } else {
                                 tryLbProvisioning = true; // if possible provision a LB appliance in to the physical
-                                // network
+// network
                             }
                         }
                     } finally {
@@ -436,7 +437,7 @@ public abstract class ExternalLoadBalancerDeviceManagerImpl extends AdapterBase
             }
 
             // there are no LB devices or there is no free capacity on the devices in the physical network so provision
-            // a new LB appliance
+// a new LB appliance
             if (tryLbProvisioning) {
                 // check if LB appliance can be dynamically provisioned
                 List<ExternalLoadBalancerDeviceVO> providerLbDevices = _externalLoadBalancerDeviceDao.listByProviderAndDeviceAllocationState(physicalNetworkId, provider, LBDeviceAllocationState.Provider);
@@ -444,7 +445,7 @@ public abstract class ExternalLoadBalancerDeviceManagerImpl extends AdapterBase
                     for (ExternalLoadBalancerDeviceVO lbProviderDevice : providerLbDevices) {
                         if (lbProviderDevice.getState() == LBDeviceState.Enabled) {
                             // acquire a private IP from the data center which will be used as management IP of
-                            // provisioned LB appliance,
+// provisioned LB appliance,
                             DataCenterIpAddressVO dcPrivateIp = _dcDao.allocatePrivateIpAddress(guestConfig.getDataCenterId(), lbProviderDevice.getUuid());
                             if (dcPrivateIp == null) {
                                 throw new InsufficientNetworkCapacityException("failed to acquire a priavate IP in the zone " + guestConfig.getDataCenterId() +
@@ -475,12 +476,12 @@ public abstract class ExternalLoadBalancerDeviceManagerImpl extends AdapterBase
                             String privateIf = createLbAnswer.getPrivateInterface();
 
                             // we have provisioned load balancer so add the appliance as cloudstack provisioned external
-                            // load balancer
+// load balancer
                             String dedicatedLb = offering.getDedicatedLB() ? "true" : "false";
                             String capacity = Long.toString(lbProviderDevice.getCapacity());
 
                             // acquire a public IP to associate with lb appliance (used as subnet IP to make the
-                            // appliance part of private network)
+// appliance part of private network)
                             PublicIp publicIp = _networkMgr.assignPublicIpAddress(guestConfig.getDataCenterId(), null, _accountMgr.getSystemAccount(), VlanType.VirtualNetwork, null, null, false);
                             String publicIPNetmask = publicIp.getVlanNetmask();
                             String publicIPgateway = publicIp.getVlanGateway();
@@ -488,8 +489,8 @@ public abstract class ExternalLoadBalancerDeviceManagerImpl extends AdapterBase
                             String publicIP = publicIp.getAddress().toString();
 
                             String url = "https://" + lbIP + "?publicinterface=" + publicIf + "&privateinterface=" + privateIf + "&lbdevicededicated=" + dedicatedLb +
-                            "&cloudmanaged=true" + "&publicip=" + publicIP + "&publicipnetmask=" + publicIPNetmask + "&lbdevicecapacity=" + capacity +
-                            "&publicipvlan=" + publicIPVlanTag + "&publicipgateway=" + publicIPgateway;
+                                    "&cloudmanaged=true" + "&publicip=" + publicIP + "&publicipnetmask=" + publicIPNetmask + "&lbdevicecapacity=" + capacity +
+                                    "&publicipvlan=" + publicIPVlanTag + "&publicipgateway=" + publicIPgateway;
                             ExternalLoadBalancerDeviceVO lbAppliance = null;
                             try {
                                 lbAppliance = addExternalLoadBalancer(physicalNetworkId, url, username, password, createLbAnswer.getDeviceName(), createLbAnswer.getServerResource());
@@ -499,7 +500,7 @@ public abstract class ExternalLoadBalancerDeviceManagerImpl extends AdapterBase
 
                             if (lbAppliance != null) {
                                 // mark the load balancer as cloudstack managed and set parent host id on which lb
-                                // appliance is provisioned
+// appliance is provisioned
                                 ExternalLoadBalancerDeviceVO managedLb = _externalLoadBalancerDeviceDao.findById(lbAppliance.getId());
                                 managedLb.setIsManagedDevice(true);
                                 managedLb.setParentHostId(lbProviderDevice.getHostId());
@@ -514,7 +515,7 @@ public abstract class ExternalLoadBalancerDeviceManagerImpl extends AdapterBase
                                         s_logger.warn("Failed to destroy load balancer appliance created");
                                     } else {
                                         // release the public & private IP back to dc pool, as the load balancer
-                                        // appliance is now destroyed
+// appliance is now destroyed
                                         _dcDao.releasePrivateIpAddress(lbIP, guestConfig.getDataCenterId(), null);
                                         _networkMgr.releasePublicIpAddress(publicIp.getId(), _accountMgr.getSystemUser().getId(), _accountMgr.getSystemAccount());
                                     }
@@ -594,7 +595,7 @@ public abstract class ExternalLoadBalancerDeviceManagerImpl extends AdapterBase
             }
 
             // if we are here then there are no existing LB devices in shared use or the devices in shared use has no
-            // free capacity left
+// free capacity left
             // so allocate a new load balancer configured for shared use from the pool of free LB devices
             lbDevices = _externalLoadBalancerDeviceDao.listByProviderAndDeviceAllocationState(physicalNetworkId, provider, LBDeviceAllocationState.Free);
             if (lbDevices != null && !lbDevices.isEmpty()) {
@@ -631,7 +632,7 @@ public abstract class ExternalLoadBalancerDeviceManagerImpl extends AdapterBase
 
                 if (!lbInUse && !lbCloudManaged) {
                     // this is the last network mapped to the load balancer device so set device allocation state to be
-                    // free
+// free
                     lbDevice.setAllocationState(LBDeviceAllocationState.Free);
                     _externalLoadBalancerDeviceDao.update(lbDevice.getId(), lbDevice);
                 }
@@ -797,9 +798,9 @@ public abstract class ExternalLoadBalancerDeviceManagerImpl extends AdapterBase
             LoadBalancingRule rule = loadBalancingRules.get(i);
 
             boolean revoked = (rule.getState().equals(FirewallRule.State.Revoke));
-            Long lbId = rule.getId();
             String protocol = rule.getProtocol();
             String algorithm = rule.getAlgorithm();
+            String uuid = rule.getUuid();
             String srcIp = _networkMgr.getIp(rule.getSourceIpAddressId()).getAddress().addr();
             int srcPort = rule.getSourcePortStart();
             List<LbDestination> destinations = rule.getDestinations();
@@ -836,7 +837,7 @@ public abstract class ExternalLoadBalancerDeviceManagerImpl extends AdapterBase
                         _inlineLoadBalancerNicMapDao.persist(mapping);
 
                         // On the firewall provider for the network, create a static NAT rule between the source IP
-                        // address and the load balancing IP address
+// address and the load balancing IP address
                         applyStaticNatRuleForInlineLBRule(zone, network, firewallProviderHost, revoked, srcIp, loadBalancingIpNic.getIp4Address());
                     } else {
                         loadBalancingIpNic = _nicDao.findById(mapping.getNicId());
@@ -847,7 +848,7 @@ public abstract class ExternalLoadBalancerDeviceManagerImpl extends AdapterBase
                         loadBalancingIpNic = _nicDao.findById(mapping.getNicId());
 
                         // On the firewall provider for the network, delete the static NAT rule between the source IP
-                        // address and the load balancing IP address
+// address and the load balancing IP address
                         applyStaticNatRuleForInlineLBRule(zone, network, firewallProviderHost, revoked, srcIp, loadBalancingIpNic.getIp4Address());
 
                         // Delete the mapping between the source IP address and the load balancing IP address
@@ -866,7 +867,7 @@ public abstract class ExternalLoadBalancerDeviceManagerImpl extends AdapterBase
             }
 
             if ((destinations != null && !destinations.isEmpty()) || rule.isAutoScaleConfig()) {
-                LoadBalancerTO loadBalancer = new LoadBalancerTO(lbId, srcIp, srcPort, protocol, algorithm, revoked, false, destinations, rule.getStickinessPolicies());
+                LoadBalancerTO loadBalancer = new LoadBalancerTO(uuid, srcIp, srcPort, protocol, algorithm, revoked, false, destinations, rule.getStickinessPolicies());
                 if(rule.isAutoScaleConfig()) {
                     loadBalancer.setAutoScaleVmGroup(rule.getAutoScaleVmGroup());
                 }
@@ -917,7 +918,7 @@ public abstract class ExternalLoadBalancerDeviceManagerImpl extends AdapterBase
             ExternalLoadBalancerDeviceVO lbDeviceVO = getExternalLoadBalancerForNetwork(guestConfig);
             if (lbDeviceVO == null) {
                 s_logger.warn("Network shutdwon requested on external load balancer element, which did not implement the network." +
-                " Either network implement failed half way through or already network shutdown is completed. So just returning.");
+                        " Either network implement failed half way through or already network shutdown is completed. So just returning.");
                 return true;
             }
 
@@ -944,7 +945,7 @@ public abstract class ExternalLoadBalancerDeviceManagerImpl extends AdapterBase
             NicVO selfipNic = getPlaceholderNic(guestConfig);
             if (selfipNic == null) {
                 s_logger.warn("Network shutdwon requested on external load balancer element, which did not implement the network." +
-                " Either network implement failed half way through or already network shutdown is completed. So just returning.");
+                        " Either network implement failed half way through or already network shutdown is completed. So just returning.");
                 return true;
             }
             selfIp = selfipNic.getIp4Address();

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/70bbd8b0/server/src/com/cloud/network/as/AutoScaleVmGroupVO.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/as/AutoScaleVmGroupVO.java b/server/src/com/cloud/network/as/AutoScaleVmGroupVO.java
index 3de9f9b..ab3ee1a 100644
--- a/server/src/com/cloud/network/as/AutoScaleVmGroupVO.java
+++ b/server/src/com/cloud/network/as/AutoScaleVmGroupVO.java
@@ -182,4 +182,9 @@ public class AutoScaleVmGroupVO implements AutoScaleVmGroup {
     public void setLoadBalancerId(Long loadBalancerId) {
         this.loadBalancerId = loadBalancerId;
     }
+
+    @Override
+    public String getUuid() {
+        return uuid;
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/70bbd8b0/server/src/com/cloud/network/lb/LoadBalancingRulesManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/lb/LoadBalancingRulesManagerImpl.java b/server/src/com/cloud/network/lb/LoadBalancingRulesManagerImpl.java
index 82b4dd4..59ae8e6 100755
--- a/server/src/com/cloud/network/lb/LoadBalancingRulesManagerImpl.java
+++ b/server/src/com/cloud/network/lb/LoadBalancingRulesManagerImpl.java
@@ -109,6 +109,8 @@ import com.cloud.network.rules.StickinessPolicy;
 import com.cloud.offering.NetworkOffering;
 import com.cloud.projects.Project.ListProjectResourcesCriteria;
 import com.cloud.server.ResourceTag.TaggedResourceType;
+import com.cloud.service.dao.ServiceOfferingDao;
+import com.cloud.storage.dao.VMTemplateDao;
 import com.cloud.tags.ResourceTagVO;
 import com.cloud.tags.dao.ResourceTagDao;
 import com.cloud.template.TemplateManager;
@@ -194,6 +196,10 @@ public class LoadBalancingRulesManagerImpl<Type> implements LoadBalancingRulesMa
     @Inject
     ResourceTagDao _resourceTagDao;
     @Inject
+    VMTemplateDao _templateDao;
+    @Inject
+    ServiceOfferingDao _offeringsDao;
+    @Inject
     CounterDao _counterDao;
     @Inject
     ConditionDao _conditionDao;
@@ -258,20 +264,24 @@ public class LoadBalancingRulesManagerImpl<Type> implements LoadBalancingRulesMa
         String apiKey = user.getApiKey();
         String secretKey = user.getSecretKey();
         String csUrl = _configDao.getValue(Config.EndpointeUrl.key());
+        String zoneId = _dcDao.findById(autoScaleVmProfile.getZoneId()).getUuid();
+        String domainId = _domainDao.findById(autoScaleVmProfile.getDomainId()).getUuid();
+        String serviceOfferingId = _offeringsDao.findById(autoScaleVmProfile.getServiceOfferingId()).getUuid();
+        String templateId = _templateDao.findById(autoScaleVmProfile.getTemplateId()).getUuid();
 
-        if (apiKey == null) {
+        if(apiKey == null) {
             throw new InvalidParameterValueException("apiKey for user: " + user.getUsername() + " is empty. Please generate it");
         }
 
-        if (secretKey == null) {
+        if(secretKey == null) {
             throw new InvalidParameterValueException("secretKey for user: " + user.getUsername() + " is empty. Please generate it");
         }
 
-        if (csUrl == null || csUrl.contains("localhost")) {
+        if(csUrl == null || csUrl.contains("localhost")) {
             throw new InvalidParameterValueException("Global setting endpointe.url has to be set to the Management Server's API end point");
         }
 
-        LbAutoScaleVmProfile lbAutoScaleVmProfile = new LbAutoScaleVmProfile(autoScaleVmProfile, apiKey, secretKey, csUrl);
+        LbAutoScaleVmProfile lbAutoScaleVmProfile = new LbAutoScaleVmProfile(autoScaleVmProfile, apiKey, secretKey, csUrl, zoneId, domainId, serviceOfferingId, templateId);
         return new LbAutoScaleVmGroup(vmGroup, autoScalePolicies, lbAutoScaleVmProfile, currentState);
     }
 
@@ -321,11 +331,11 @@ public class LoadBalancingRulesManagerImpl<Type> implements LoadBalancingRulesMa
             success = applyAutoScaleConfig(loadBalancer, vmGroup, currentState);
         } catch (ResourceUnavailableException e) {
             s_logger.warn("Unable to configure AutoScaleVmGroup to the lb rule: " + loadBalancer.getId() + " because resource is unavaliable:", e);
-            if (isRollBackAllowedForProvider(loadBalancer)) {
-                loadBalancer.setState(backupState);
-                _lbDao.persist(loadBalancer);
-                s_logger.debug("LB Rollback rule id: " + loadBalancer.getId() + " lb state rolback while creating AutoscaleVmGroup");
-            }
+                if (isRollBackAllowedForProvider(loadBalancer)) {
+                    loadBalancer.setState(backupState);
+                    _lbDao.persist(loadBalancer);
+                    s_logger.debug("LB Rollback rule id: " + loadBalancer.getId() + " lb state rolback while creating AutoscaleVmGroup");
+                }
             throw e;
         } finally {
             if (!success) {
@@ -824,10 +834,10 @@ public class LoadBalancingRulesManagerImpl<Type> implements LoadBalancingRulesMa
 
         if (apply) {
             try {
-                if (!applyLoadBalancerConfig(loadBalancerId)) {
-                    s_logger.warn("Unable to apply the load balancer config");
-                    return false;
-                }
+                    if (!applyLoadBalancerConfig(loadBalancerId)) {
+                        s_logger.warn("Unable to apply the load balancer config");
+                        return false;
+                    }
             } catch (ResourceUnavailableException e) {
                 if (rollBack && isRollBackAllowedForProvider(lb)) {
                     if (backupMaps != null) {
@@ -896,7 +906,7 @@ public class LoadBalancingRulesManagerImpl<Type> implements LoadBalancingRulesMa
             }
 
             _networkMgr.checkIpForService(ipAddressVo, Service.Lb);
-                    }
+                }
 
         // FIXME: breaking the dependency on ELB manager. This breaks functionality of ELB using virtual router
         // Bug CS-15411 opened to document this

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/70bbd8b0/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java
index 163252f..155c64c 100755
--- a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java
+++ b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java
@@ -2422,12 +2422,13 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
             boolean revoked = (rule.getState().equals(FirewallRule.State.Revoke));
             String protocol = rule.getProtocol();
             String algorithm = rule.getAlgorithm();
+            String uuid = rule.getUuid();
 
             String srcIp = _networkMgr.getIp(rule.getSourceIpAddressId()).getAddress().addr();
             int srcPort = rule.getSourcePortStart();
             List<LbDestination> destinations = rule.getDestinations();
             List<LbStickinessPolicy> stickinessPolicies = rule.getStickinessPolicies();
-            LoadBalancerTO lb = new LoadBalancerTO(rule.getId(), srcIp, srcPort, protocol, algorithm, revoked, false, destinations, stickinessPolicies);
+            LoadBalancerTO lb = new LoadBalancerTO(uuid, srcIp, srcPort, protocol, algorithm, revoked, false, destinations, stickinessPolicies);
             lbs[i++] = lb;
         }
         String RouterPublicIp = null;