cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jaya...@apache.org
Subject git commit: updated refs/heads/4.4 to 936de7e
Date Fri, 04 Apr 2014 13:17:45 GMT
Repository: cloudstack
Updated Branches:
  refs/heads/4.4 38fc91801 -> 936de7e1c


CLOUDSTACK-6327: Updated the removeFromLoadBalancerRule and listLoadBalancerRuleInstances
API

Updated these APIs to use VM primary/secondary details on LB rule.

listLoadBalancerRuleInstances API lists the vm ips which are assigned to lb rule when passed
listlbvmips
removeFromLoadBalancerRule is updated to remove the spcific vm ip entry assinged to LB rule.
Added new param vmidipmap to this API


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

Branch: refs/heads/4.4
Commit: 936de7e1c566386b08e1ab8ecb1459913bcaa0d0
Parents: 38fc918
Author: Jayapal <jayapal@apache.org>
Authored: Fri Apr 4 18:32:27 2014 +0530
Committer: Jayapal <jayapal@apache.org>
Committed: Fri Apr 4 18:32:43 2014 +0530

----------------------------------------------------------------------
 .../network/lb/LoadBalancingRulesService.java   |   4 +-
 .../org/apache/cloudstack/api/ApiConstants.java |   1 +
 ...ListLoadBalancerRuleInstancesCmdByAdmin.java |  54 +++++++--
 .../ListLoadBalancerRuleInstancesCmd.java       |  66 +++++++++--
 .../RemoveFromLoadBalancerRuleCmd.java          |  63 ++++++++--
 .../response/LoadBalancerRuleVmMapResponse.java |  54 +++++++++
 .../cloud/network/dao/LoadBalancerVMMapDao.java |   6 +
 .../network/dao/LoadBalancerVMMapDaoImpl.java   |  35 ++++++
 .../cloud/network/as/AutoScaleManagerImpl.java  |   2 +-
 .../lb/LoadBalancingRulesManagerImpl.java       | 114 +++++++++++++++----
 10 files changed, 346 insertions(+), 53 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/936de7e1/api/src/com/cloud/network/lb/LoadBalancingRulesService.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/network/lb/LoadBalancingRulesService.java b/api/src/com/cloud/network/lb/LoadBalancingRulesService.java
index 6643de6..98d29c5 100644
--- a/api/src/com/cloud/network/lb/LoadBalancingRulesService.java
+++ b/api/src/com/cloud/network/lb/LoadBalancingRulesService.java
@@ -98,7 +98,7 @@ public interface LoadBalancingRulesService {
 
     boolean assignSSLCertToLoadBalancerRule(Long lbRuleId, String certName, String publicCert,
String privateKey);
 
-    boolean removeFromLoadBalancer(long lbRuleId, List<Long> vmIds);
+    boolean removeFromLoadBalancer(long lbRuleId, List<Long> vmIds,   Map<Long,
List<String>> vmIdIpMap);
 
     boolean applyLoadBalancerConfig(long lbRuleId) throws ResourceUnavailableException;
 
@@ -153,4 +153,6 @@ public interface LoadBalancingRulesService {
     Map<Ip, UserVm> getLbInstances(long lbId);
 
     boolean isLbRuleMappedToVmGuestIp(String vmSecondaryIp);
+
+    List<String> listLbVmIpAddress(long id, long vmId);
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/936de7e1/api/src/org/apache/cloudstack/api/ApiConstants.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/ApiConstants.java b/api/src/org/apache/cloudstack/api/ApiConstants.java
index 1146cea..08ab7af 100755
--- a/api/src/org/apache/cloudstack/api/ApiConstants.java
+++ b/api/src/org/apache/cloudstack/api/ApiConstants.java
@@ -26,6 +26,7 @@ public class ApiConstants {
     public static final String API_KEY = "apikey";
     public static final String USER_API_KEY = "userapikey";
     public static final String APPLIED = "applied";
+    public static final String LIST_LB_VMIPS = "lbvmips";
     public static final String AVAILABLE = "available";
     public static final String BITS = "bits";
     public static final String BOOTABLE = "bootable";

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/936de7e1/api/src/org/apache/cloudstack/api/command/admin/loadbalancer/ListLoadBalancerRuleInstancesCmdByAdmin.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/admin/loadbalancer/ListLoadBalancerRuleInstancesCmdByAdmin.java
b/api/src/org/apache/cloudstack/api/command/admin/loadbalancer/ListLoadBalancerRuleInstancesCmdByAdmin.java
index 26202b9..0e8c377 100644
--- a/api/src/org/apache/cloudstack/api/command/admin/loadbalancer/ListLoadBalancerRuleInstancesCmdByAdmin.java
+++ b/api/src/org/apache/cloudstack/api/command/admin/loadbalancer/ListLoadBalancerRuleInstancesCmdByAdmin.java
@@ -19,6 +19,7 @@ package org.apache.cloudstack.api.command.admin.loadbalancer;
 import java.util.ArrayList;
 import java.util.List;
 
+import org.apache.cloudstack.api.response.LoadBalancerRuleVmMapResponse;
 import org.apache.log4j.Logger;
 
 import org.apache.cloudstack.api.APICommand;
@@ -30,7 +31,7 @@ import org.apache.cloudstack.api.response.UserVmResponse;
 import com.cloud.uservm.UserVm;
 import com.cloud.utils.Pair;
 
-@APICommand(name = "listLoadBalancerRuleInstances", description = "List all virtual machine
instances that are assigned to a load balancer rule.", responseObject = UserVmResponse.class,
responseView = ResponseView.Full)
+@APICommand(name = "listLoadBalancerRuleInstances", description = "List all virtual machine
instances that are assigned to a load balancer rule.", responseObject = LoadBalancerRuleVmMapResponse.class,
responseView = ResponseView.Full)
 public class ListLoadBalancerRuleInstancesCmdByAdmin extends ListLoadBalancerRuleInstancesCmd
{
     public static final Logger s_logger = Logger.getLogger (ListLoadBalancerRuleInstancesCmdByAdmin.class.getName());
 
@@ -41,17 +42,48 @@ public class ListLoadBalancerRuleInstancesCmdByAdmin extends ListLoadBalancerRul
         Pair<List<? extends UserVm>, List<String>> vmServiceMap =  _lbService.listLoadBalancerInstances(this);
         List<? extends UserVm> result = vmServiceMap.first();
         List<String> serviceStates  = vmServiceMap.second();
-        ListResponse<UserVmResponse> response = new ListResponse<UserVmResponse>();
-        List<UserVmResponse> vmResponses = new ArrayList<UserVmResponse>();
-        if (result != null) {
-            vmResponses = _responseGenerator.createUserVmResponse(ResponseView.Full, "loadbalancerruleinstance",
result.toArray(new UserVm[result.size()]));
-        }
 
-        for (int i=0;i<result.size(); i++) {
-            vmResponses.get(i).setServiceState(serviceStates.get(i));
+
+        if (!isListLbVmip()) {
+            // list lb instances
+            ListResponse<UserVmResponse> response = new ListResponse<UserVmResponse>();
+            List<UserVmResponse> vmResponses = new ArrayList<UserVmResponse>();
+            if (result != null) {
+                vmResponses = _responseGenerator.createUserVmResponse(ResponseView.Restricted,
"loadbalancerruleinstance", result.toArray(new UserVm[result.size()]));
+
+
+                for (int i = 0; i < result.size(); i++) {
+                    vmResponses.get(i).setServiceState(serviceStates.get(i));
+                }
+            }
+            response.setResponses(vmResponses);
+            response.setResponseName(getCommandName());
+            setResponseObject(response);
+
+        } else {
+            ListResponse<LoadBalancerRuleVmMapResponse> lbRes = new ListResponse<LoadBalancerRuleVmMapResponse>();
+
+            List<UserVmResponse> vmResponses = new ArrayList<UserVmResponse>();
+            List<LoadBalancerRuleVmMapResponse> listlbVmRes = new ArrayList<LoadBalancerRuleVmMapResponse>();
+
+            if (result != null) {
+                vmResponses = _responseGenerator.createUserVmResponse(ResponseView.Full,
"loadbalancerruleinstance", result.toArray(new UserVm[result.size()]));
+
+                List<String> ipaddr = null;
+
+                for (int i=0;i<result.size(); i++) {
+                    LoadBalancerRuleVmMapResponse lbRuleVmIpResponse = new LoadBalancerRuleVmMapResponse();
+                    vmResponses.get(i).setServiceState(serviceStates.get(i));
+                    lbRuleVmIpResponse.setUserVmResponse(vmResponses.get(i));
+                    lbRuleVmIpResponse.setIpAddr(_lbService.listLbVmIpAddress(getId(), result.get(i).getId()));
+                    lbRuleVmIpResponse.setObjectName("lbrulevmidip");
+                    listlbVmRes.add(lbRuleVmIpResponse);
+                }
+            }
+
+            lbRes.setResponseName(getCommandName());
+            lbRes.setResponses(listlbVmRes);
+            setResponseObject(lbRes);
         }
-        response.setResponses(vmResponses);
-        response.setResponseName(getCommandName());
-        setResponseObject(response);
     }
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/936de7e1/api/src/org/apache/cloudstack/api/command/user/loadbalancer/ListLoadBalancerRuleInstancesCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/user/loadbalancer/ListLoadBalancerRuleInstancesCmd.java
b/api/src/org/apache/cloudstack/api/command/user/loadbalancer/ListLoadBalancerRuleInstancesCmd.java
index 2d458a7..cc4203c 100644
--- a/api/src/org/apache/cloudstack/api/command/user/loadbalancer/ListLoadBalancerRuleInstancesCmd.java
+++ b/api/src/org/apache/cloudstack/api/command/user/loadbalancer/ListLoadBalancerRuleInstancesCmd.java
@@ -19,6 +19,7 @@ package org.apache.cloudstack.api.command.user.loadbalancer;
 import java.util.ArrayList;
 import java.util.List;
 
+import org.apache.cloudstack.api.response.LoadBalancerRuleVmMapResponse;
 import org.apache.log4j.Logger;
 
 import org.apache.cloudstack.api.APICommand;
@@ -33,7 +34,7 @@ import org.apache.cloudstack.api.response.UserVmResponse;
 import com.cloud.uservm.UserVm;
 import com.cloud.utils.Pair;
 
-@APICommand(name = "listLoadBalancerRuleInstances", description = "List all virtual machine
instances that are assigned to a load balancer rule.", responseObject = UserVmResponse.class,
responseView = ResponseView.Restricted,
+@APICommand(name = "listLoadBalancerRuleInstances", description = "List all virtual machine
instances that are assigned to a load balancer rule.", responseObject = LoadBalancerRuleVmMapResponse.class,
responseView = ResponseView.Restricted,
             requestHasSensitiveInfo = false,
             responseHasSensitiveInfo = true)
 public class ListLoadBalancerRuleInstancesCmd extends BaseListCmd {
@@ -57,6 +58,13 @@ public class ListLoadBalancerRuleInstancesCmd extends BaseListCmd {
                description = "the ID of the load balancer rule")
     private Long id;
 
+
+    @Parameter(name = ApiConstants.LIST_LB_VMIPS,
+            type = CommandType.BOOLEAN,
+            description = "true if lb rule vm ip information to be included; default is false")
+    private boolean isListLbVmip;
+
+
     /////////////////////////////////////////////////////
     /////////////////// Accessors ///////////////////////
     /////////////////////////////////////////////////////
@@ -69,6 +77,10 @@ public class ListLoadBalancerRuleInstancesCmd extends BaseListCmd {
         return id;
     }
 
+    public boolean isListLbVmip() {
+        return isListLbVmip;
+    }
+
     /////////////////////////////////////////////////////
     /////////////// API Implementation///////////////////
     /////////////////////////////////////////////////////
@@ -83,17 +95,49 @@ public class ListLoadBalancerRuleInstancesCmd extends BaseListCmd {
         Pair<List<? extends UserVm>, List<String>> vmServiceMap =  _lbService.listLoadBalancerInstances(this);
         List<? extends UserVm> result = vmServiceMap.first();
         List<String> serviceStates  = vmServiceMap.second();
-        ListResponse<UserVmResponse> response = new ListResponse<UserVmResponse>();
-        List<UserVmResponse> vmResponses = new ArrayList<UserVmResponse>();
-        if (result != null) {
-            vmResponses = _responseGenerator.createUserVmResponse(ResponseView.Restricted,
"loadbalancerruleinstance", result.toArray(new UserVm[result.size()]));
-        }
 
-        for (int i = 0; i < result.size(); i++) {
-            vmResponses.get(i).setServiceState(serviceStates.get(i));
+        if (!isListLbVmip()) {
+            // list lb instances
+            ListResponse<UserVmResponse> response = new ListResponse<UserVmResponse>();
+            List<UserVmResponse> vmResponses = new ArrayList<UserVmResponse>();
+            if (result != null) {
+                vmResponses = _responseGenerator.createUserVmResponse(ResponseView.Restricted,
"loadbalancerruleinstance", result.toArray(new UserVm[result.size()]));
+
+
+                for (int i = 0; i < result.size(); i++) {
+                    vmResponses.get(i).setServiceState(serviceStates.get(i));
+                }
+            }
+            response.setResponses(vmResponses);
+            response.setResponseName(getCommandName());
+            setResponseObject(response);
+
+
+        } else {
+            ListResponse<LoadBalancerRuleVmMapResponse> lbRes = new ListResponse<LoadBalancerRuleVmMapResponse>();
+
+            List<UserVmResponse> vmResponses = new ArrayList<UserVmResponse>();
+            List<LoadBalancerRuleVmMapResponse> listlbVmRes = new ArrayList<LoadBalancerRuleVmMapResponse>();
+
+            if (result != null) {
+                vmResponses = _responseGenerator.createUserVmResponse(ResponseView.Full,
"loadbalancerruleinstance", result.toArray(new UserVm[result.size()]));
+
+
+                List<String> ipaddr = null;
+
+                for (int i=0;i<result.size(); i++) {
+                    LoadBalancerRuleVmMapResponse lbRuleVmIpResponse = new LoadBalancerRuleVmMapResponse();
+                    vmResponses.get(i).setServiceState(serviceStates.get(i));
+                    lbRuleVmIpResponse.setUserVmResponse(vmResponses.get(i));
+                    lbRuleVmIpResponse.setIpAddr(_lbService.listLbVmIpAddress(getId(), result.get(i).getId()));
+                    lbRuleVmIpResponse.setObjectName("lbrulevmidip");
+                    listlbVmRes.add(lbRuleVmIpResponse);
+                }
+            }
+
+            lbRes.setResponseName(getCommandName());
+            lbRes.setResponses(listlbVmRes);
+            setResponseObject(lbRes);
         }
-        response.setResponses(vmResponses);
-        response.setResponseName(getCommandName());
-        setResponseObject(response);
     }
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/936de7e1/api/src/org/apache/cloudstack/api/command/user/loadbalancer/RemoveFromLoadBalancerRuleCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/user/loadbalancer/RemoveFromLoadBalancerRuleCmd.java
b/api/src/org/apache/cloudstack/api/command/user/loadbalancer/RemoveFromLoadBalancerRuleCmd.java
index 8714d34..b3eb159 100644
--- a/api/src/org/apache/cloudstack/api/command/user/loadbalancer/RemoveFromLoadBalancerRuleCmd.java
+++ b/api/src/org/apache/cloudstack/api/command/user/loadbalancer/RemoveFromLoadBalancerRuleCmd.java
@@ -17,6 +17,11 @@
 package org.apache.cloudstack.api.command.user.loadbalancer;
 
 import java.util.List;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.ArrayList;
 
 import org.apache.log4j.Logger;
 
@@ -60,12 +65,17 @@ public class RemoveFromLoadBalancerRuleCmd extends BaseAsyncCmd {
 
     @Parameter(name = ApiConstants.VIRTUAL_MACHINE_IDS,
                type = CommandType.LIST,
-               required = true,
                collectionType = CommandType.UUID,
                entityType = UserVmResponse.class,
                description = "the list of IDs of the virtual machines that are being removed
from the load balancer rule (i.e. virtualMachineIds=1,2,3)")
     private List<Long> virtualMachineIds;
 
+    @Parameter(name = ApiConstants.VIRTUAL_MACHINE_ID_IP,
+            type = CommandType.MAP,
+            description = "VM ID and IP map, vmidipmap[0].vmid=1 vmidipmap[0].ip=10.1.1.75",
+            since = "4.4")
+    private Map vmIdIpMap;
+
     /////////////////////////////////////////////////////
     /////////////////// Accessors ///////////////////////
     /////////////////////////////////////////////////////
@@ -78,6 +88,10 @@ public class RemoveFromLoadBalancerRuleCmd extends BaseAsyncCmd {
         return virtualMachineIds;
     }
 
+    public Map<Long, String> getVmIdIpMap() {
+        return vmIdIpMap;
+    }
+
     /////////////////////////////////////////////////////
     /////////////// API Implementation///////////////////
     /////////////////////////////////////////////////////
@@ -101,20 +115,53 @@ public class RemoveFromLoadBalancerRuleCmd extends BaseAsyncCmd {
         return EventTypes.EVENT_REMOVE_FROM_LOAD_BALANCER_RULE;
     }
 
+
+    public Map<Long, List<String>> getVmIdIpListMap() {
+        Map<Long, List<String>> vmIdIpsMap = new HashMap<Long, List<String>>();
+        if (vmIdIpMap != null && !vmIdIpMap.isEmpty()) {
+            Collection idIpsCollection = vmIdIpMap.values();
+            Iterator iter = idIpsCollection.iterator();
+            while (iter.hasNext()) {
+                HashMap<String, String> idIpsMap = (HashMap<String, String>)iter.next();
+                String vmId = idIpsMap.get("vmid");
+                String vmIp = idIpsMap.get("vmip");
+
+                Long longVmId = new Long(vmId);
+
+                List<String> ipsList = null;
+                if (vmIdIpsMap.containsKey(longVmId)) {
+                    ipsList = vmIdIpsMap.get(longVmId);
+                } else {
+                    ipsList = new ArrayList<String>();
+                }
+                ipsList.add(vmIp);
+                vmIdIpsMap.put(longVmId, ipsList);
+
+            }
+        }
+
+        return vmIdIpsMap;
+    }
+
     @Override
     public String getEventDescription() {
         return "removing instances from load balancer: " + getId() + " (ids: " + StringUtils.join(getVirtualMachineIds(),
",") + ")";
     }
 
     @Override
-    public void execute() {
+    public void execute()  {
         CallContext.current().setEventDetails("Load balancer Id: " + getId() + " VmIds: "
+ StringUtils.join(getVirtualMachineIds(), ","));
-        boolean result = _lbService.removeFromLoadBalancer(id, virtualMachineIds);
-        if (result) {
-            SuccessResponse response = new SuccessResponse(getCommandName());
-            this.setResponseObject(response);
-        } else {
-            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to remove instance
from load balancer rule");
+        Map<Long, List<String>> vmIdIpsMap = getVmIdIpListMap();
+        try {
+            boolean result = _lbService.removeFromLoadBalancer(id, virtualMachineIds, vmIdIpsMap);
+            if (result) {
+                SuccessResponse response = new SuccessResponse(getCommandName());
+                this.setResponseObject(response);
+            } else {
+                throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to remove
instance from load balancer rule");
+            }
+        }catch (InvalidParameterValueException ex) {
+            throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Failed to remove instance
from load balancer rule");
         }
     }
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/936de7e1/api/src/org/apache/cloudstack/api/response/LoadBalancerRuleVmMapResponse.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/response/LoadBalancerRuleVmMapResponse.java
b/api/src/org/apache/cloudstack/api/response/LoadBalancerRuleVmMapResponse.java
new file mode 100644
index 0000000..57c45e6
--- /dev/null
+++ b/api/src/org/apache/cloudstack/api/response/LoadBalancerRuleVmMapResponse.java
@@ -0,0 +1,54 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package org.apache.cloudstack.api.response;
+
+import com.cloud.network.router.VirtualRouter;
+import com.cloud.uservm.UserVm;
+import com.cloud.vm.VirtualMachine;
+import com.google.gson.annotations.SerializedName;
+
+import org.apache.cloudstack.api.BaseResponse;
+import org.apache.cloudstack.api.EntityReference;
+
+import com.cloud.serializer.Param;
+
+import java.util.List;
+
+@EntityReference(value = {VirtualMachine.class, UserVm.class, VirtualRouter.class})
+@SuppressWarnings("unused")
+public class LoadBalancerRuleVmMapResponse extends BaseResponse {
+
+
+    @SerializedName("loadbalancerruleinstance")
+    @Param(description = "the user vm set for lb rule")
+    private UserVmResponse UserVmResponse;
+
+    @SerializedName("lbvmipaddresses")
+    @Param(description = "IP addresses of the vm set of lb rule")
+    private List<String> ipAddr;
+
+    public void setIpAddr(List<String> ipAddr) {
+        this.ipAddr = ipAddr;
+    }
+
+    public void setUserVmResponse(UserVmResponse userVmResponse) {
+        this.UserVmResponse = userVmResponse;
+    }
+
+
+
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/936de7e1/engine/schema/src/com/cloud/network/dao/LoadBalancerVMMapDao.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/network/dao/LoadBalancerVMMapDao.java b/engine/schema/src/com/cloud/network/dao/LoadBalancerVMMapDao.java
index 51f45c2..a25534b 100644
--- a/engine/schema/src/com/cloud/network/dao/LoadBalancerVMMapDao.java
+++ b/engine/schema/src/com/cloud/network/dao/LoadBalancerVMMapDao.java
@@ -36,4 +36,10 @@ public interface LoadBalancerVMMapDao extends GenericDao<LoadBalancerVMMapVO,
Lo
     boolean isVmAttachedToLoadBalancer(long loadBalancerId);
 
     List<LoadBalancerVMMapVO> listByInstanceIp(String instanceIp);
+
+    List<LoadBalancerVMMapVO> listByLoadBalancerIdAndVmId(long loadBalancerId, long
instanceId);
+
+    LoadBalancerVMMapVO findByLoadBalancerIdAndVmIdVmIp(long loadBalancerId, long instanceId,
String instanceIp);
+
+    void remove(long id, long instanceId, String instanceIp, Boolean revoke);
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/936de7e1/engine/schema/src/com/cloud/network/dao/LoadBalancerVMMapDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/network/dao/LoadBalancerVMMapDaoImpl.java b/engine/schema/src/com/cloud/network/dao/LoadBalancerVMMapDaoImpl.java
index bb24e04..cbfda8f 100644
--- a/engine/schema/src/com/cloud/network/dao/LoadBalancerVMMapDaoImpl.java
+++ b/engine/schema/src/com/cloud/network/dao/LoadBalancerVMMapDaoImpl.java
@@ -52,6 +52,21 @@ public class LoadBalancerVMMapDaoImpl extends GenericDaoBase<LoadBalancerVMMapVO
     }
 
     @Override
+    public void remove(long loadBalancerId, long instanceId, String instanceIp, Boolean revoke)
{
+        SearchCriteria<LoadBalancerVMMapVO> sc = createSearchCriteria();
+        sc.addAnd("loadBalancerId", SearchCriteria.Op.EQ, loadBalancerId);
+        sc.addAnd("instanceId", SearchCriteria.Op.IN, instanceId);
+        sc.addAnd("instanceIp", SearchCriteria.Op.EQ, instanceIp);
+
+        if (revoke != null) {
+            sc.addAnd("revoke", SearchCriteria.Op.EQ, revoke);
+        }
+
+        expunge(sc);
+    }
+
+
+    @Override
     public List<LoadBalancerVMMapVO> listByInstanceId(long instanceId) {
         SearchCriteria<LoadBalancerVMMapVO> sc = createSearchCriteria();
         sc.addAnd("instanceId", SearchCriteria.Op.EQ, instanceId);
@@ -92,6 +107,18 @@ public class LoadBalancerVMMapDaoImpl extends GenericDaoBase<LoadBalancerVMMapVO
         return findOneBy(sc);
     }
 
+
+    @Override
+    public LoadBalancerVMMapVO findByLoadBalancerIdAndVmIdVmIp(long loadBalancerId, long
instanceId, String instanceIp) {
+        SearchCriteria<LoadBalancerVMMapVO> sc = createSearchCriteria();
+        sc.addAnd("loadBalancerId", SearchCriteria.Op.EQ, loadBalancerId);
+        sc.addAnd("instanceId", SearchCriteria.Op.EQ, instanceId);
+        sc.addAnd("instanceIp", SearchCriteria.Op.EQ, instanceIp);
+
+        return findOneBy(sc);
+    }
+
+
     @Override
     public boolean isVmAttachedToLoadBalancer(long loadBalancerId) {
         GenericSearchBuilder<LoadBalancerVMMapVO, Long> CountByAccount = createSearchBuilder(Long.class);
@@ -102,4 +129,12 @@ public class LoadBalancerVMMapDaoImpl extends GenericDaoBase<LoadBalancerVMMapVO
         sc.setParameters("loadBalancerId", loadBalancerId);
         return customSearch(sc, null).get(0) > 0;
     }
+
+    @Override
+    public List<LoadBalancerVMMapVO> listByLoadBalancerIdAndVmId(long loadBalancerId,
long instanceId) {
+        SearchCriteria<LoadBalancerVMMapVO> sc = createSearchCriteria();
+        sc.addAnd("loadBalancerId", SearchCriteria.Op.EQ, loadBalancerId);
+        sc.addAnd("instanceId", SearchCriteria.Op.EQ, instanceId);
+        return listBy(sc);
+    }
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/936de7e1/server/src/com/cloud/network/as/AutoScaleManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/as/AutoScaleManagerImpl.java b/server/src/com/cloud/network/as/AutoScaleManagerImpl.java
index 8fafcc9..09c6694 100644
--- a/server/src/com/cloud/network/as/AutoScaleManagerImpl.java
+++ b/server/src/com/cloud/network/as/AutoScaleManagerImpl.java
@@ -1431,7 +1431,7 @@ public class AutoScaleManagerImpl<Type> extends ManagerBase implements
AutoScale
         List<Long> lstVmId = new ArrayList<Long>();
         if (instanceId != -1)
             lstVmId.add(instanceId);
-        if (_loadBalancingRulesService.removeFromLoadBalancer(lbId, lstVmId))
+        if (_loadBalancingRulesService.removeFromLoadBalancer(lbId, lstVmId, new HashMap<Long,
List<String>>()))
             return instanceId;
         else
             return -1;

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/936de7e1/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 4e6d6fd..b953d42 100755
--- a/server/src/com/cloud/network/lb/LoadBalancingRulesManagerImpl.java
+++ b/server/src/com/cloud/network/lb/LoadBalancingRulesManagerImpl.java
@@ -888,7 +888,8 @@ public class LoadBalancingRulesManagerImpl<Type> extends ManagerBase
implements
                                     for (LoadBalancerVMMapVO lbVmMap : lbVmMaps) {
                                         UserVm vm = _vmDao.findById(lbVmMap.getInstanceId());
                                         Nic nic = _nicDao.findByInstanceIdAndNetworkIdIncludingRemoved(ulb.getNetworkId(),
vm.getId());
-                                        String dstIp = nic.getIp4Address();
+                                        String dstIp = lbVmMap.getInstanceIp() == null ?
nic.getIp4Address(): lbVmMap.getInstanceIp();
+
                                         for (int i = 0; i < lbto.getDestinations().length;
i++) {
                                             LoadBalancerTO.DestinationTO des = lbto.getDestinations()[i];
                                             if (dstIp.equalsIgnoreCase(lbto.getDestinations()[i].getDestIp()))
{
@@ -1068,8 +1069,8 @@ public class LoadBalancingRulesManagerImpl<Type> extends ManagerBase
implements
                 for (Long vmId : vmIds) {
                     final List<String> lbVmIps = newMap.get(vmId);
                     for (String vmIp: lbVmIps) {
-                    LoadBalancerVMMapVO map = new LoadBalancerVMMapVO(loadBalancer.getId(),
vmId, vmIp, false);
-                    map = _lb2VmMapDao.persist(map);
+                        LoadBalancerVMMapVO map = new LoadBalancerVMMapVO(loadBalancer.getId(),
vmId, vmIp, false);
+                        map = _lb2VmMapDao.persist(map);
                     }
                 }
             }
@@ -1130,8 +1131,8 @@ public class LoadBalancingRulesManagerImpl<Type> extends ManagerBase
implements
 
     @Override
     @ActionEvent(eventType = EventTypes.EVENT_REMOVE_FROM_LOAD_BALANCER_RULE, eventDescription
= "removing from load balancer", async = true)
-    public boolean removeFromLoadBalancer(long loadBalancerId, List<Long> instanceIds)
{
-        return removeFromLoadBalancerInternal(loadBalancerId, instanceIds, true);
+    public boolean removeFromLoadBalancer(long loadBalancerId, List<Long> instanceIds,
Map<Long, List<String>> vmIdIpsMap) {
+        return removeFromLoadBalancerInternal(loadBalancerId, instanceIds, true, vmIdIpsMap);
     }
 
     @Override
@@ -1265,7 +1266,7 @@ public class LoadBalancingRulesManagerImpl<Type> extends ManagerBase
implements
         return success;
     }
 
-    private boolean removeFromLoadBalancerInternal(long loadBalancerId, List<Long>
instanceIds, boolean rollBack) {
+    private boolean removeFromLoadBalancerInternal(long loadBalancerId, List<Long>
instanceIds, boolean rollBack, Map<Long, List<String>> vmIdIpMap) {
         CallContext caller = CallContext.current();
 
         LoadBalancerVO loadBalancer = _lbDao.findById(Long.valueOf(loadBalancerId));
@@ -1275,17 +1276,65 @@ public class LoadBalancingRulesManagerImpl<Type> extends ManagerBase
implements
 
         _accountMgr.checkAccess(caller.getCallingAccount(), null, loadBalancer);
 
+        if (instanceIds == null && vmIdIpMap.isEmpty()) {
+            throw new InvalidParameterValueException("Both instanceids and vmidipmap  can't
be null");
+        }
+
+        // instanceIds and vmIdipmap is passed
+        if (instanceIds != null && !vmIdIpMap.isEmpty()) {
+            for(long instanceId: instanceIds) {
+                if (!vmIdIpMap.containsKey(instanceId)) {
+                    vmIdIpMap.put(instanceId, null);
+                }
+            }
+        }
+
+        //only instanceids list passed
+        if (instanceIds != null && vmIdIpMap.isEmpty()){
+            vmIdIpMap = new HashMap<Long, List<String>>();
+            for (long instanceId: instanceIds){
+                vmIdIpMap.put(instanceId, null);
+            }
+        }
+
         boolean success = false;
         FirewallRule.State backupState = loadBalancer.getState();
+        Set<Long> vmIds = vmIdIpMap.keySet();
         try {
             loadBalancer.setState(FirewallRule.State.Add);
             _lbDao.persist(loadBalancer);
 
-            for (long instanceId : instanceIds) {
-                LoadBalancerVMMapVO map = _lb2VmMapDao.findByLoadBalancerIdAndVmId(loadBalancerId,
instanceId);
-                map.setRevoke(true);
-                _lb2VmMapDao.persist(map);
-                s_logger.debug("Set load balancer rule for revoke: rule id " + loadBalancerId
+ ", vmId " + instanceId);
+            for (long instanceId : vmIds) {
+                List<String> lbVmIps = vmIdIpMap.get(instanceId);
+
+                if (lbVmIps == null || lbVmIps.isEmpty()) {
+                    List<LoadBalancerVMMapVO> lbVms = _lb2VmMapDao.listByLoadBalancerIdAndVmId(loadBalancerId,
instanceId);
+                    if (lbVms == null) {
+                        throw new InvalidParameterValueException("The instance id: "+ instanceId
+" is not configured "
+                                + " for LB rule id " + loadBalancerId);
+                    }
+
+                    for (LoadBalancerVMMapVO lbvm: lbVms) {
+                        lbvm.setRevoke(true);
+                        _lb2VmMapDao.persist(lbvm);
+                    }
+                    s_logger.debug("Set load balancer rule for revoke: rule id " + loadBalancerId
+ ", vmId " + instanceId);
+
+                } else {
+                    for (String vmIp: lbVmIps) {
+                        LoadBalancerVMMapVO map = _lb2VmMapDao.findByLoadBalancerIdAndVmIdVmIp
(loadBalancerId, instanceId, vmIp);
+                        if (map == null) {
+                            throw new InvalidParameterValueException("The instance id: "+
instanceId +" is not configured "
+                                    + " for LB rule id " + loadBalancerId);
+                        }
+                        map.setRevoke(true);
+                        _lb2VmMapDao.persist(map);
+                        s_logger.debug("Set load balancer rule for revoke: rule id " + loadBalancerId
+ ", vmId " +
+                                instanceId + ", vmip " + vmIp);
+
+                    }
+
+                }
             }
 
             if (_autoScaleVmGroupDao.isAutoScaleLoadBalancer(loadBalancerId)) {
@@ -1307,11 +1356,23 @@ public class LoadBalancingRulesManagerImpl<Type> extends ManagerBase
implements
         } catch (ResourceUnavailableException e) {
             if (rollBack && isRollBackAllowedForProvider(loadBalancer)) {
 
-                for (long instanceId : instanceIds) {
-                    LoadBalancerVMMapVO map = _lb2VmMapDao.findByLoadBalancerIdAndVmId(loadBalancerId,
instanceId);
-                    map.setRevoke(false);
-                    _lb2VmMapDao.persist(map);
-                    s_logger.debug("LB Rollback rule id: " + loadBalancerId + ",while removing
vmId " + instanceId);
+                for (long instanceId : vmIds) {
+                    List<String> lbVmIps = vmIdIpMap.get(instanceId);
+
+                    if (lbVmIps == null || lbVmIps.isEmpty()) {
+                        LoadBalancerVMMapVO map = _lb2VmMapDao.findByLoadBalancerIdAndVmId(loadBalancerId,
instanceId);
+                        map.setRevoke(false);
+                        _lb2VmMapDao.persist(map);
+                        s_logger.debug("LB Rollback rule id: " + loadBalancerId + ",while
removing vmId " + instanceId);
+                    }else {
+                        for (String vmIp: lbVmIps) {
+                            LoadBalancerVMMapVO map = _lb2VmMapDao.findByLoadBalancerIdAndVmIdVmIp
(loadBalancerId, instanceId, vmIp);
+                            map.setRevoke(true);
+                            _lb2VmMapDao.persist(map);
+                            s_logger.debug("LB Rollback rule id: " + loadBalancerId + ",while
removing vmId " +
+                                    instanceId + ", vmip " + vmIp);
+                        }
+                    }
                 }
 
                 loadBalancer.setState(backupState);
@@ -1356,7 +1417,7 @@ public class LoadBalancingRulesManagerImpl<Type> extends ManagerBase
implements
         // Reapply all lbs that had the vm assigned
         if (lbsToReconfigure != null) {
             for (Map.Entry<Long, List<Long>> lb : lbsToReconfigure.entrySet())
{
-                if (!removeFromLoadBalancerInternal(lb.getKey(), lb.getValue(), false)) {
+                if (!removeFromLoadBalancerInternal(lb.getKey(), lb.getValue(), false, new
HashMap<Long, List<String>>())) {
                     success = false;
                 }
             }
@@ -1801,12 +1862,11 @@ public class LoadBalancingRulesManagerImpl<Type> extends ManagerBase
implements
 
                         for (LoadBalancerVMMapVO lbVmMap : lbVmMaps) {
                             instanceIds.add(lbVmMap.getInstanceId());
+                            _lb2VmMapDao.remove(lb.getId(), lbVmMap.getInstanceId(), lbVmMap.getInstanceIp(),
null);
+                            s_logger.debug("Load balancer rule id " + lb.getId() + " is removed
for vm " +
+                                    lbVmMap.getInstanceId() + " instance ip " + lbVmMap.getInstanceIp());
                         }
 
-                        if (!instanceIds.isEmpty()) {
-                            _lb2VmMapDao.remove(lb.getId(), instanceIds, null);
-                            s_logger.debug("Load balancer rule id " + lb.getId() + " is removed
for vms " + instanceIds);
-                        }
 
                         if (_lb2VmMapDao.listByLoadBalancerId(lb.getId()).isEmpty()) {
                             lb.setState(FirewallRule.State.Add);
@@ -2097,6 +2157,18 @@ public class LoadBalancingRulesManagerImpl<Type> extends ManagerBase
implements
     }
 
     @Override
+    public List<String> listLbVmIpAddress (long id, long vmId) {
+
+        List <LoadBalancerVMMapVO> listLbvmMapVo = _lb2VmMapDao.listByLoadBalancerIdAndVmId(id,
vmId);
+
+        List <String> vmIps = new ArrayList<String>();
+        for (LoadBalancerVMMapVO lbVmVo : listLbvmMapVo) {
+            vmIps.add(lbVmVo.getInstanceIp());
+        }
+        return vmIps;
+    }
+
+    @Override
     public List<LbStickinessMethod> getStickinessMethods(long networkid) {
         String capability = getLBCapability(networkid, Capability.SupportedStickinessMethods.getName());
         if (capability == null) {


Mime
View raw message