Search in sources :

Example 81 with InvalidParameterValueException

use of com.cloud.exception.InvalidParameterValueException in project cloudstack by apache.

the class ListLBHealthCheckPoliciesCmd method execute.

@Override
public void execute() {
    List<LBHealthCheckResponse> hcpResponses = new ArrayList<LBHealthCheckResponse>();
    ListResponse<LBHealthCheckResponse> response = new ListResponse<LBHealthCheckResponse>();
    Long lbRuleId = getLbRuleId();
    Long hId = getId();
    if (lbRuleId == null) {
        if (hId != null) {
            lbRuleId = _lbService.findLBIdByHealtCheckPolicyId(hId);
        } else {
            throw new InvalidParameterValueException("Either load balancer rule ID or health check policy ID should be specified");
        }
    }
    LoadBalancer lb = _lbService.findById(lbRuleId);
    if (lb != null) {
        List<? extends HealthCheckPolicy> healthCheckPolicies = _lbService.searchForLBHealthCheckPolicies(this);
        LBHealthCheckResponse spResponse = _responseGenerator.createLBHealthCheckPolicyResponse(healthCheckPolicies, lb);
        hcpResponses.add(spResponse);
        response.setResponses(hcpResponses);
    }
    response.setResponseName(getCommandName());
    this.setResponseObject(response);
}
Also used : ListResponse(org.apache.cloudstack.api.response.ListResponse) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) ArrayList(java.util.ArrayList) LoadBalancer(com.cloud.network.rules.LoadBalancer) LBHealthCheckResponse(org.apache.cloudstack.api.response.LBHealthCheckResponse)

Example 82 with InvalidParameterValueException

use of com.cloud.exception.InvalidParameterValueException in project cloudstack by apache.

the class ListLBStickinessPoliciesCmd method execute.

@Override
public void execute() {
    LoadBalancer lb = null;
    if (lbRuleId == null && id == null) {
        throw new InvalidParameterValueException("load balancer rule ID and stickiness policy ID can't be null");
    }
    if (id != null) {
        lb = _lbService.findLbByStickinessId(id);
        if (lb == null) {
            throw new InvalidParameterValueException("stickiness policy ID doesn't exist");
        }
        if ((lbRuleId != null) && (lbRuleId != lb.getId())) {
            throw new InvalidParameterValueException("stickiness policy ID doesn't belong to lbId" + lbRuleId);
        }
    }
    if (lbRuleId != null && lb == null) {
        lb = _lbService.findById(getLbRuleId());
    }
    List<LBStickinessResponse> spResponses = new ArrayList<LBStickinessResponse>();
    ListResponse<LBStickinessResponse> response = new ListResponse<LBStickinessResponse>();
    if (lb != null) {
        //check permissions
        Account caller = CallContext.current().getCallingAccount();
        _accountService.checkAccess(caller, null, true, lb);
        List<? extends StickinessPolicy> stickinessPolicies = _lbService.searchForLBStickinessPolicies(this);
        LBStickinessResponse spResponse = _responseGenerator.createLBStickinessPolicyResponse(stickinessPolicies, lb);
        spResponses.add(spResponse);
        response.setResponses(spResponses);
    }
    response.setResponseName(getCommandName());
    this.setResponseObject(response);
}
Also used : Account(com.cloud.user.Account) ListResponse(org.apache.cloudstack.api.response.ListResponse) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) ArrayList(java.util.ArrayList) LoadBalancer(com.cloud.network.rules.LoadBalancer) LBStickinessResponse(org.apache.cloudstack.api.response.LBStickinessResponse)

Example 83 with InvalidParameterValueException

use of com.cloud.exception.InvalidParameterValueException in project cloudstack by apache.

the class AssignToLoadBalancerRuleCmd method getVmIdIpListMap.

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");
            VirtualMachine lbvm = _entityMgr.findByUuid(VirtualMachine.class, vmId);
            if (lbvm == null) {
                throw new InvalidParameterValueException("Unable to find virtual machine ID: " + vmId);
            }
            //check wether the given ip is valid ip or not
            if (vmIp == null || !NetUtils.isValidIp(vmIp)) {
                throw new InvalidParameterValueException("Invalid ip address " + vmIp + " passed in vmidipmap for " + "vmid " + vmId);
            }
            Long longVmId = lbvm.getId();
            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;
}
Also used : HashMap(java.util.HashMap) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) Iterator(java.util.Iterator) Collection(java.util.Collection) ArrayList(java.util.ArrayList) List(java.util.List) VirtualMachine(com.cloud.vm.VirtualMachine)

Example 84 with InvalidParameterValueException

use of com.cloud.exception.InvalidParameterValueException in project cloudstack by apache.

the class CreateIpForwardingRuleCmd method create.

@Override
public void create() {
    //cidr list parameter is deprecated
    if (cidrlist != null) {
        throw new InvalidParameterValueException("Parameter cidrList is deprecated; if you need to open firewall rule for the specific CIDR, please refer to createFirewallRule command");
    }
    try {
        StaticNatRule rule = _rulesService.createStaticNatRule(this, getOpenFirewall());
        setEntityId(rule.getId());
        setEntityUuid(rule.getUuid());
    } catch (NetworkRuleConflictException e) {
        s_logger.info("Unable to create static NAT rule due to ", e);
        throw new ServerApiException(ApiErrorCode.NETWORK_RULE_CONFLICT_ERROR, e.getMessage());
    }
}
Also used : ServerApiException(org.apache.cloudstack.api.ServerApiException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) StaticNatRule(com.cloud.network.rules.StaticNatRule) NetworkRuleConflictException(com.cloud.exception.NetworkRuleConflictException)

Example 85 with InvalidParameterValueException

use of com.cloud.exception.InvalidParameterValueException in project cloudstack by apache.

the class DeleteLBHealthCheckPolicyCmd method getSyncObjId.

@Override
public Long getSyncObjId() {
    HealthCheckPolicy policy = _entityMgr.findById(HealthCheckPolicy.class, getId());
    if (policy == null) {
        throw new InvalidParameterValueException("Unable to find load balancer health check rule: " + id);
    }
    LoadBalancer lb = _lbService.findById(policy.getLoadBalancerId());
    if (lb == null) {
        throw new InvalidParameterValueException("Unable to find load balancer rule for health check rule: " + id);
    }
    return lb.getNetworkId();
}
Also used : InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) LoadBalancer(com.cloud.network.rules.LoadBalancer) HealthCheckPolicy(com.cloud.network.rules.HealthCheckPolicy)

Aggregations

InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)725 Account (com.cloud.user.Account)242 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)229 ArrayList (java.util.ArrayList)186 ActionEvent (com.cloud.event.ActionEvent)171 DB (com.cloud.utils.db.DB)139 ServerApiException (org.apache.cloudstack.api.ServerApiException)110 PermissionDeniedException (com.cloud.exception.PermissionDeniedException)94 TransactionStatus (com.cloud.utils.db.TransactionStatus)88 List (java.util.List)80 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)69 PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)63 Network (com.cloud.network.Network)58 HashMap (java.util.HashMap)58 ConfigurationException (javax.naming.ConfigurationException)53 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)52 Pair (com.cloud.utils.Pair)50 HostVO (com.cloud.host.HostVO)46 NetworkVO (com.cloud.network.dao.NetworkVO)46 DataCenterVO (com.cloud.dc.DataCenterVO)44