Search in sources :

Example 1 with AutoScalePolicyResponse

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

the class ListAutoScalePoliciesCmd method execute.

@Override
public void execute() {
    List<? extends AutoScalePolicy> autoScalePolicies = _autoScaleService.listAutoScalePolicies(this);
    ListResponse<AutoScalePolicyResponse> response = new ListResponse<AutoScalePolicyResponse>();
    List<AutoScalePolicyResponse> responses = new ArrayList<AutoScalePolicyResponse>();
    if (autoScalePolicies != null) {
        for (AutoScalePolicy autoScalePolicy : autoScalePolicies) {
            AutoScalePolicyResponse autoScalePolicyResponse = _responseGenerator.createAutoScalePolicyResponse(autoScalePolicy);
            autoScalePolicyResponse.setObjectName("autoscalepolicy");
            responses.add(autoScalePolicyResponse);
        }
    }
    response.setResponses(responses);
    response.setResponseName(getCommandName());
    setResponseObject(response);
}
Also used : AutoScalePolicyResponse(org.apache.cloudstack.api.response.AutoScalePolicyResponse) ListResponse(org.apache.cloudstack.api.response.ListResponse) AutoScalePolicy(com.cloud.network.as.AutoScalePolicy) ArrayList(java.util.ArrayList)

Example 2 with AutoScalePolicyResponse

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

the class CreateAutoScalePolicyCmd method execute.

@Override
public void execute() {
    AutoScalePolicy result = _entityMgr.findById(AutoScalePolicy.class, getEntityId());
    AutoScalePolicyResponse response = _responseGenerator.createAutoScalePolicyResponse(result);
    response.setResponseName(getCommandName());
    setResponseObject(response);
}
Also used : AutoScalePolicyResponse(org.apache.cloudstack.api.response.AutoScalePolicyResponse) AutoScalePolicy(com.cloud.network.as.AutoScalePolicy)

Example 3 with AutoScalePolicyResponse

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

the class ApiResponseHelper method createAutoScalePolicyResponse.

@Override
public AutoScalePolicyResponse createAutoScalePolicyResponse(AutoScalePolicy policy) {
    AutoScalePolicyResponse response = new AutoScalePolicyResponse();
    response.setId(policy.getUuid());
    response.setDuration(policy.getDuration());
    response.setQuietTime(policy.getQuietTime());
    response.setAction(policy.getAction());
    List<ConditionVO> vos = ApiDBUtils.getAutoScalePolicyConditions(policy.getId());
    ArrayList<ConditionResponse> conditions = new ArrayList<ConditionResponse>(vos.size());
    for (ConditionVO vo : vos) {
        conditions.add(createConditionResponse(vo));
    }
    response.setConditions(conditions);
    response.setObjectName("autoscalepolicy");
    // Populates the account information in the response
    populateOwner(response, policy);
    return response;
}
Also used : AutoScalePolicyResponse(org.apache.cloudstack.api.response.AutoScalePolicyResponse) ConditionResponse(org.apache.cloudstack.api.response.ConditionResponse) ConditionVO(com.cloud.network.as.ConditionVO) ArrayList(java.util.ArrayList)

Example 4 with AutoScalePolicyResponse

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

the class UpdateAutoScalePolicyCmd method execute.

@Override
public void execute() {
    CallContext.current().setEventDetails("AutoScale Policy Id: " + getId());
    AutoScalePolicy result = _autoScaleService.updateAutoScalePolicy(this);
    if (result != null) {
        AutoScalePolicyResponse response = _responseGenerator.createAutoScalePolicyResponse(result);
        response.setResponseName(getCommandName());
        setResponseObject(response);
    } else {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to update autoscale policy");
    }
}
Also used : AutoScalePolicyResponse(org.apache.cloudstack.api.response.AutoScalePolicyResponse) ServerApiException(org.apache.cloudstack.api.ServerApiException) AutoScalePolicy(com.cloud.network.as.AutoScalePolicy)

Example 5 with AutoScalePolicyResponse

use of org.apache.cloudstack.api.response.AutoScalePolicyResponse 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

AutoScalePolicyResponse (org.apache.cloudstack.api.response.AutoScalePolicyResponse)5 AutoScalePolicy (com.cloud.network.as.AutoScalePolicy)4 ArrayList (java.util.ArrayList)3 AutoScaleVmProfileVO (com.cloud.network.as.AutoScaleVmProfileVO)1 ConditionVO (com.cloud.network.as.ConditionVO)1 FirewallRuleVO (com.cloud.network.rules.FirewallRuleVO)1 ServerApiException (org.apache.cloudstack.api.ServerApiException)1 AutoScaleVmGroupResponse (org.apache.cloudstack.api.response.AutoScaleVmGroupResponse)1 ConditionResponse (org.apache.cloudstack.api.response.ConditionResponse)1 ListResponse (org.apache.cloudstack.api.response.ListResponse)1