Search in sources :

Example 6 with AutoScalePolicy

use of com.cloud.network.as.AutoScalePolicy 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)

Example 7 with AutoScalePolicy

use of com.cloud.network.as.AutoScalePolicy in project cloudstack by apache.

the class LoadBalancingRulesManagerImpl method getLbAutoScaleVmGroup.

private LbAutoScaleVmGroup getLbAutoScaleVmGroup(AutoScaleVmGroupVO vmGroup, String currentState, LoadBalancerVO lb) {
    long lbNetworkId = lb.getNetworkId();
    String lbName = lb.getName();
    List<AutoScaleVmGroupPolicyMapVO> vmGroupPolicyMapList = _autoScaleVmGroupPolicyMapDao.listByVmGroupId(vmGroup.getId());
    List<LbAutoScalePolicy> autoScalePolicies = new ArrayList<LbAutoScalePolicy>();
    for (AutoScaleVmGroupPolicyMapVO vmGroupPolicyMap : vmGroupPolicyMapList) {
        AutoScalePolicy autoScalePolicy = _autoScalePolicyDao.findById(vmGroupPolicyMap.getPolicyId());
        List<AutoScalePolicyConditionMapVO> autoScalePolicyConditionMapList = _autoScalePolicyConditionMapDao.listByAll(autoScalePolicy.getId(), null);
        List<LbCondition> lbConditions = new ArrayList<LbCondition>();
        for (AutoScalePolicyConditionMapVO autoScalePolicyConditionMap : autoScalePolicyConditionMapList) {
            Condition condition = _conditionDao.findById(autoScalePolicyConditionMap.getConditionId());
            Counter counter = _counterDao.findById(condition.getCounterid());
            lbConditions.add(new LbCondition(counter, condition));
        }
        autoScalePolicies.add(new LbAutoScalePolicy(autoScalePolicy, lbConditions));
    }
    AutoScaleVmProfile autoScaleVmProfile = _autoScaleVmProfileDao.findById(vmGroup.getProfileId());
    Long autoscaleUserId = autoScaleVmProfile.getAutoScaleUserId();
    User user = _userDao.findByIdIncludingRemoved(autoscaleUserId);
    String apiKey = user.getApiKey();
    String secretKey = user.getSecretKey();
    String csUrl = ApiServiceConfiguration.ApiServletPath.value();
    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();
    String vmName = "AutoScale-LB-" + lbName;
    String lbNetworkUuid = null;
    DataCenter zone = _entityMgr.findById(DataCenter.class, vmGroup.getZoneId());
    if (zone == null) {
        // This should never happen, but still a cautious check
        s_logger.warn("Unable to find zone while packaging AutoScale Vm Group, zoneid: " + vmGroup.getZoneId());
        throw new InvalidParameterValueException("Unable to find zone");
    } else {
        if (zone.getNetworkType() == NetworkType.Advanced) {
            NetworkVO lbNetwork = _networkDao.findById(lbNetworkId);
            lbNetworkUuid = lbNetwork.getUuid();
        }
    }
    if (apiKey == null) {
        throw new InvalidParameterValueException("apiKey for user: " + user.getUsername() + " is empty. Please generate it");
    }
    if (secretKey == null) {
        throw new InvalidParameterValueException("secretKey for user: " + user.getUsername() + " is empty. Please generate it");
    }
    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, zoneId, domainId, serviceOfferingId, templateId, vmName, lbNetworkUuid);
    return new LbAutoScaleVmGroup(vmGroup, autoScalePolicies, lbAutoScaleVmProfile, currentState);
}
Also used : Condition(com.cloud.network.as.Condition) LbCondition(com.cloud.network.lb.LoadBalancingRule.LbCondition) AutoScaleVmGroupPolicyMapVO(com.cloud.network.as.AutoScaleVmGroupPolicyMapVO) NetworkVO(com.cloud.network.dao.NetworkVO) User(com.cloud.user.User) LbAutoScaleVmProfile(com.cloud.network.lb.LoadBalancingRule.LbAutoScaleVmProfile) ArrayList(java.util.ArrayList) LbAutoScalePolicy(com.cloud.network.lb.LoadBalancingRule.LbAutoScalePolicy) LbAutoScaleVmProfile(com.cloud.network.lb.LoadBalancingRule.LbAutoScaleVmProfile) AutoScaleVmProfile(com.cloud.network.as.AutoScaleVmProfile) Counter(com.cloud.network.as.Counter) DataCenter(com.cloud.dc.DataCenter) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) LbAutoScalePolicy(com.cloud.network.lb.LoadBalancingRule.LbAutoScalePolicy) AutoScalePolicy(com.cloud.network.as.AutoScalePolicy) LbCondition(com.cloud.network.lb.LoadBalancingRule.LbCondition) LbAutoScaleVmGroup(com.cloud.network.lb.LoadBalancingRule.LbAutoScaleVmGroup) AutoScalePolicyConditionMapVO(com.cloud.network.as.AutoScalePolicyConditionMapVO)

Aggregations

AutoScalePolicy (com.cloud.network.as.AutoScalePolicy)7 ArrayList (java.util.ArrayList)4 AutoScalePolicyResponse (org.apache.cloudstack.api.response.AutoScalePolicyResponse)4 AutoScaleVmProfile (com.cloud.network.as.AutoScaleVmProfile)2 Condition (com.cloud.network.as.Condition)2 Counter (com.cloud.network.as.Counter)2 LbAutoScalePolicy (com.cloud.network.lb.LoadBalancingRule.LbAutoScalePolicy)2 LbAutoScaleVmGroup (com.cloud.network.lb.LoadBalancingRule.LbAutoScaleVmGroup)2 LbAutoScaleVmProfile (com.cloud.network.lb.LoadBalancingRule.LbAutoScaleVmProfile)2 LbCondition (com.cloud.network.lb.LoadBalancingRule.LbCondition)2 ServerApiException (org.apache.cloudstack.api.ServerApiException)2 DataCenter (com.cloud.dc.DataCenter)1 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)1 AutoScalePolicyConditionMapVO (com.cloud.network.as.AutoScalePolicyConditionMapVO)1 AutoScaleVmGroup (com.cloud.network.as.AutoScaleVmGroup)1 AutoScaleVmGroupPolicyMapVO (com.cloud.network.as.AutoScaleVmGroupPolicyMapVO)1 AutoScaleVmProfileVO (com.cloud.network.as.AutoScaleVmProfileVO)1 NetworkVO (com.cloud.network.dao.NetworkVO)1 FirewallRuleVO (com.cloud.network.rules.FirewallRuleVO)1 User (com.cloud.user.User)1