mirror of
https://github.com/apache/cloudstack.git
synced 2025-11-02 20:02:29 +01:00
CLOUDSTACK-62 [AWS Style Health Checks] Response of the API listLoadBalancerRuleInstances should show the service state of a VM if health check is configured for it
This commit is contained in:
parent
71e387f1fa
commit
24a8d60d6f
@ -103,9 +103,10 @@ public interface LoadBalancingRulesService {
|
||||
* balancer.
|
||||
*
|
||||
* @param cmd
|
||||
* @return list of vm instances that have been or can be applied to a load balancer
|
||||
* @return list of vm instances that have been or can be applied to a load balancer along with service state,
|
||||
* if the LB has health check policy created on it from cloudstack.
|
||||
*/
|
||||
List<? extends UserVm> listLoadBalancerInstances(ListLoadBalancerRuleInstancesCmd cmd);
|
||||
Pair<List<? extends UserVm>, List<String>> listLoadBalancerInstances(ListLoadBalancerRuleInstancesCmd cmd);
|
||||
|
||||
/**
|
||||
* List load balancer rules based on the given criteria
|
||||
|
||||
@ -517,7 +517,7 @@ public class ApiConstants {
|
||||
public static final String IS_DYNAMICALLY_SCALABLE = "isdynamicallyscalable";
|
||||
public static final String ROUTING = "isrouting";
|
||||
public static final String MAX_CONNECTIONS = "maxconnections";
|
||||
|
||||
public static final String SERVICE_STATE = "servicestate";
|
||||
public enum HostDetails {
|
||||
all, capacity, events, stats, min;
|
||||
}
|
||||
|
||||
@ -17,6 +17,7 @@
|
||||
package org.apache.cloudstack.api.command.user.loadbalancer;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.cloudstack.api.APICommand;
|
||||
@ -29,6 +30,7 @@ import org.apache.cloudstack.api.response.UserVmResponse;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
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)
|
||||
public class ListLoadBalancerRuleInstancesCmd extends BaseListCmd {
|
||||
@ -70,12 +72,18 @@ public class ListLoadBalancerRuleInstancesCmd extends BaseListCmd {
|
||||
|
||||
@Override
|
||||
public void execute(){
|
||||
List<? extends UserVm> result = _lbService.listLoadBalancerInstances(this);
|
||||
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("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());
|
||||
this.setResponseObject(response);
|
||||
|
||||
@ -191,6 +191,8 @@ public class UserVmResponse extends BaseResponse implements ControlledEntityResp
|
||||
|
||||
@SerializedName(ApiConstants.IS_DYNAMICALLY_SCALABLE) @Param(description="true if vm contains XS/VMWare tools inorder to support dynamic scaling of VM cpu/memory.")
|
||||
private Boolean isDynamicallyScalable;
|
||||
@SerializedName(ApiConstants.SERVICE_STATE) @Param(description="State of the Service from LB rule")
|
||||
private String serviceState;
|
||||
|
||||
public UserVmResponse(){
|
||||
securityGroupList = new LinkedHashSet<SecurityGroupResponse>();
|
||||
@ -439,4 +441,8 @@ public class UserVmResponse extends BaseResponse implements ControlledEntityResp
|
||||
this.isDynamicallyScalable = isDynamicallyScalable;
|
||||
}
|
||||
|
||||
public void setServiceState(String state) {
|
||||
this.serviceState = state;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1835,7 +1835,7 @@ public class LoadBalancingRulesManagerImpl<Type> extends ManagerBase implements
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<UserVmVO> listLoadBalancerInstances(ListLoadBalancerRuleInstancesCmd cmd)
|
||||
public Pair<List<? extends UserVm>, List<String>> listLoadBalancerInstances(ListLoadBalancerRuleInstancesCmd cmd)
|
||||
throws PermissionDeniedException {
|
||||
Account caller = CallContext.current().getCallingAccount();
|
||||
Long loadBalancerId = cmd.getId();
|
||||
@ -1853,14 +1853,16 @@ public class LoadBalancingRulesManagerImpl<Type> extends ManagerBase implements
|
||||
_accountMgr.checkAccess(caller, null, true, loadBalancer);
|
||||
|
||||
List<UserVmVO> loadBalancerInstances = new ArrayList<UserVmVO>();
|
||||
List<String> serviceStates = new ArrayList<String>();
|
||||
List<LoadBalancerVMMapVO> vmLoadBalancerMappings = null;
|
||||
|
||||
vmLoadBalancerMappings = _lb2VmMapDao.listByLoadBalancerId(loadBalancerId);
|
||||
|
||||
Map<Long, String> vmServiceState = new HashMap<Long, String>(vmLoadBalancerMappings.size());
|
||||
List<Long> appliedInstanceIdList = new ArrayList<Long>();
|
||||
|
||||
if ((vmLoadBalancerMappings != null) && !vmLoadBalancerMappings.isEmpty()) {
|
||||
for (LoadBalancerVMMapVO vmLoadBalancerMapping : vmLoadBalancerMappings) {
|
||||
appliedInstanceIdList.add(vmLoadBalancerMapping.getInstanceId());
|
||||
vmServiceState.put(vmLoadBalancerMapping.getInstanceId(), vmLoadBalancerMapping.getState());
|
||||
}
|
||||
}
|
||||
|
||||
@ -1881,10 +1883,10 @@ public class LoadBalancingRulesManagerImpl<Type> extends ManagerBase implements
|
||||
boolean isApplied = appliedInstanceIdList.contains(userVm.getId());
|
||||
if ((isApplied && applied) || (!isApplied && !applied)) {
|
||||
loadBalancerInstances.add(userVm);
|
||||
serviceStates.add(vmServiceState.get(userVm.getId()));
|
||||
}
|
||||
}
|
||||
|
||||
return loadBalancerInstances;
|
||||
return new Pair<List<? extends UserVm>, List<String>>(loadBalancerInstances,serviceStates);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user