Search in sources :

Example 6 with AutoScaleVmGroupResponse

use of org.apache.cloudstack.api.response.AutoScaleVmGroupResponse in project cloudstack by apache.

the class ApiResponseHelper method createAutoScaleVmGroupResponse.

@Override
public AutoScaleVmGroupResponse createAutoScaleVmGroupResponse(AutoScaleVmGroup vmGroup) {
    AutoScaleVmGroupResponse response = new AutoScaleVmGroupResponse();
    response.setId(vmGroup.getUuid());
    response.setMinMembers(vmGroup.getMinMembers());
    response.setMaxMembers(vmGroup.getMaxMembers());
    response.setState(vmGroup.getState());
    response.setInterval(vmGroup.getInterval());
    response.setForDisplay(vmGroup.isDisplay());
    AutoScaleVmProfileVO profile = ApiDBUtils.findAutoScaleVmProfileById(vmGroup.getProfileId());
    if (profile != null) {
        response.setProfileId(profile.getUuid());
    }
    FirewallRuleVO fw = ApiDBUtils.findFirewallRuleById(vmGroup.getLoadBalancerId());
    if (fw != null) {
        response.setLoadBalancerId(fw.getUuid());
    }
    List<AutoScalePolicyResponse> scaleUpPoliciesResponse = new ArrayList<AutoScalePolicyResponse>();
    List<AutoScalePolicyResponse> scaleDownPoliciesResponse = new ArrayList<AutoScalePolicyResponse>();
    response.setScaleUpPolicies(scaleUpPoliciesResponse);
    response.setScaleDownPolicies(scaleDownPoliciesResponse);
    response.setObjectName("autoscalevmgroup");
    // Fetch policies for vmgroup
    List<AutoScalePolicy> scaleUpPolicies = new ArrayList<AutoScalePolicy>();
    List<AutoScalePolicy> scaleDownPolicies = new ArrayList<AutoScalePolicy>();
    ApiDBUtils.getAutoScaleVmGroupPolicies(vmGroup.getId(), scaleUpPolicies, scaleDownPolicies);
    // populate policies
    for (AutoScalePolicy autoScalePolicy : scaleUpPolicies) {
        scaleUpPoliciesResponse.add(createAutoScalePolicyResponse(autoScalePolicy));
    }
    for (AutoScalePolicy autoScalePolicy : scaleDownPolicies) {
        scaleDownPoliciesResponse.add(createAutoScalePolicyResponse(autoScalePolicy));
    }
    return response;
}
Also used : AutoScaleVmProfileVO(com.cloud.network.as.AutoScaleVmProfileVO) AutoScalePolicyResponse(org.apache.cloudstack.api.response.AutoScalePolicyResponse) AutoScalePolicy(com.cloud.network.as.AutoScalePolicy) ArrayList(java.util.ArrayList) AutoScaleVmGroupResponse(org.apache.cloudstack.api.response.AutoScaleVmGroupResponse) FirewallRuleVO(com.cloud.network.rules.FirewallRuleVO)

Aggregations

AutoScaleVmGroupResponse (org.apache.cloudstack.api.response.AutoScaleVmGroupResponse)6 AutoScaleVmGroup (com.cloud.network.as.AutoScaleVmGroup)5 ServerApiException (org.apache.cloudstack.api.ServerApiException)4 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)2 ArrayList (java.util.ArrayList)2 ResourceAllocationException (com.cloud.exception.ResourceAllocationException)1 AutoScalePolicy (com.cloud.network.as.AutoScalePolicy)1 AutoScaleVmProfileVO (com.cloud.network.as.AutoScaleVmProfileVO)1 FirewallRuleVO (com.cloud.network.rules.FirewallRuleVO)1 AutoScalePolicyResponse (org.apache.cloudstack.api.response.AutoScalePolicyResponse)1 ListResponse (org.apache.cloudstack.api.response.ListResponse)1