Search in sources :

Example 96 with InvalidParameterValueException

use of com.cloud.utils.exception.InvalidParameterValueException in project cosmic by MissionCriticalCloud.

the class LoadBalancingRulesManagerImpl method updateLBStickinessPolicy.

@Override
@ActionEvent(eventType = EventTypes.EVENT_LB_STICKINESSPOLICY_UPDATE, eventDescription = "updating lb stickiness policy", async = true)
public StickinessPolicy updateLBStickinessPolicy(final long id, final String customId, final Boolean forDisplay) {
    final LBStickinessPolicyVO policy = _lb2stickinesspoliciesDao.findById(id);
    if (policy == null) {
        throw new InvalidParameterValueException("Fail to find stickiness policy with " + id);
    }
    final LoadBalancerVO loadBalancer = _lbDao.findById(Long.valueOf(policy.getLoadBalancerId()));
    if (loadBalancer == null) {
        throw new InvalidParameterException("Invalid Load balancer : " + policy.getLoadBalancerId() + " for Stickiness policy id: " + id);
    }
    _accountMgr.checkAccess(CallContext.current().getCallingAccount(), null, true, loadBalancer);
    if (customId != null) {
        policy.setUuid(customId);
    }
    if (forDisplay != null) {
        policy.setDisplay(forDisplay);
    }
    _lb2stickinesspoliciesDao.update(id, policy);
    return _lb2stickinesspoliciesDao.findById(id);
}
Also used : InvalidParameterException(java.security.InvalidParameterException) InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) LoadBalancerVO(com.cloud.network.dao.LoadBalancerVO) LBStickinessPolicyVO(com.cloud.network.dao.LBStickinessPolicyVO) ActionEvent(com.cloud.event.ActionEvent)

Example 97 with InvalidParameterValueException

use of com.cloud.utils.exception.InvalidParameterValueException in project cosmic by MissionCriticalCloud.

the class LoadBalancingRulesManagerImpl method removeFromLoadBalancerInternal.

private boolean removeFromLoadBalancerInternal(final long loadBalancerId, final List<Long> instanceIds, final boolean rollBack, Map<Long, List<String>> vmIdIpMap) {
    final CallContext caller = CallContext.current();
    final LoadBalancerVO loadBalancer = _lbDao.findById(Long.valueOf(loadBalancerId));
    if (loadBalancer == null) {
        throw new InvalidParameterException("Invalid load balancer value: " + loadBalancerId);
    }
    _accountMgr.checkAccess(caller.getCallingAccount(), null, true, loadBalancer);
    if (instanceIds == null && vmIdIpMap.isEmpty()) {
        throw new InvalidParameterValueException("Both instanceids and vmidipmap  can't be null");
    }
    // instanceIds and vmIdipmap is passed
    if (instanceIds != null && !vmIdIpMap.isEmpty()) {
        for (final long instanceId : instanceIds) {
            if (!vmIdIpMap.containsKey(instanceId)) {
                vmIdIpMap.put(instanceId, null);
            }
        }
    }
    // only instanceids list passed
    if (instanceIds != null && vmIdIpMap.isEmpty()) {
        vmIdIpMap = new HashMap<>();
        for (final long instanceId : instanceIds) {
            vmIdIpMap.put(instanceId, null);
        }
    }
    boolean success = false;
    final FirewallRule.State backupState = loadBalancer.getState();
    final Set<Long> vmIds = vmIdIpMap.keySet();
    try {
        loadBalancer.setState(FirewallRule.State.Add);
        _lbDao.persist(loadBalancer);
        for (final long instanceId : vmIds) {
            final List<String> lbVmIps = vmIdIpMap.get(instanceId);
            if (lbVmIps == null || lbVmIps.isEmpty()) {
                final List<LoadBalancerVMMapVO> lbVms = _lb2VmMapDao.listByLoadBalancerIdAndVmId(loadBalancerId, instanceId);
                if (lbVms == null) {
                    throw new InvalidParameterValueException("The instance id: " + instanceId + " is not configured " + " for LB rule id " + loadBalancerId);
                }
                for (final LoadBalancerVMMapVO lbvm : lbVms) {
                    lbvm.setRevoke(true);
                    _lb2VmMapDao.persist(lbvm);
                }
                s_logger.debug("Set load balancer rule for revoke: rule id " + loadBalancerId + ", vmId " + instanceId);
            } else {
                for (final String vmIp : lbVmIps) {
                    final LoadBalancerVMMapVO map = _lb2VmMapDao.findByLoadBalancerIdAndVmIdVmIp(loadBalancerId, instanceId, vmIp);
                    if (map == null) {
                        throw new InvalidParameterValueException("The instance id: " + instanceId + " is not configured " + " for LB rule id " + loadBalancerId);
                    }
                    map.setRevoke(true);
                    _lb2VmMapDao.persist(map);
                    s_logger.debug("Set load balancer rule for revoke: rule id " + loadBalancerId + ", vmId " + instanceId + ", vmip " + vmIp);
                }
            }
        }
        if (!applyLoadBalancerConfig(loadBalancerId)) {
            s_logger.warn("Failed to remove load balancer rule id " + loadBalancerId + " for vms " + instanceIds);
            final CloudRuntimeException ex = new CloudRuntimeException("Failed to remove specified load balancer rule id for vms " + instanceIds);
            ex.addProxyObject(loadBalancer.getUuid(), "loadBalancerId");
            throw ex;
        }
        success = true;
    } catch (final ResourceUnavailableException e) {
        if (rollBack && isRollBackAllowedForProvider(loadBalancer)) {
            for (final long instanceId : vmIds) {
                final List<String> lbVmIps = vmIdIpMap.get(instanceId);
                if (lbVmIps == null || lbVmIps.isEmpty()) {
                    final LoadBalancerVMMapVO map = _lb2VmMapDao.findByLoadBalancerIdAndVmId(loadBalancerId, instanceId);
                    map.setRevoke(false);
                    _lb2VmMapDao.persist(map);
                    s_logger.debug("LB Rollback rule id: " + loadBalancerId + ",while removing vmId " + instanceId);
                } else {
                    for (final String vmIp : lbVmIps) {
                        final LoadBalancerVMMapVO map = _lb2VmMapDao.findByLoadBalancerIdAndVmIdVmIp(loadBalancerId, instanceId, vmIp);
                        map.setRevoke(true);
                        _lb2VmMapDao.persist(map);
                        s_logger.debug("LB Rollback rule id: " + loadBalancerId + ",while removing vmId " + instanceId + ", vmip " + vmIp);
                    }
                }
            }
            loadBalancer.setState(backupState);
            _lbDao.persist(loadBalancer);
            s_logger.debug("LB Rollback rule id: " + loadBalancerId + " while removing vm instances");
        }
        s_logger.warn("Unable to apply the load balancer config because resource is unavaliable.", e);
    }
    if (!success) {
        final CloudRuntimeException ex = new CloudRuntimeException("Failed to remove specified load balancer rule id for vms " + vmIds);
        ex.addProxyObject(loadBalancer.getUuid(), "loadBalancerId");
        throw ex;
    }
    return success;
}
Also used : LoadBalancerVO(com.cloud.network.dao.LoadBalancerVO) CallContext(com.cloud.context.CallContext) InvalidParameterException(java.security.InvalidParameterException) InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) LoadBalancerVMMapVO(com.cloud.network.dao.LoadBalancerVMMapVO) ArrayList(java.util.ArrayList) List(java.util.List) FirewallRule(com.cloud.network.rules.FirewallRule)

Example 98 with InvalidParameterValueException

use of com.cloud.utils.exception.InvalidParameterValueException in project cosmic by MissionCriticalCloud.

the class LoadBalancingRulesManagerImpl method deleteLoadBalancerRule.

@Override
@ActionEvent(eventType = EventTypes.EVENT_LOAD_BALANCER_DELETE, eventDescription = "deleting load balancer", async = true)
public boolean deleteLoadBalancerRule(final long loadBalancerId, final boolean apply) {
    final CallContext ctx = CallContext.current();
    final Account caller = ctx.getCallingAccount();
    final LoadBalancerVO rule = _lbDao.findById(loadBalancerId);
    if (rule == null) {
        throw new InvalidParameterValueException("Unable to find load balancer rule " + loadBalancerId);
    }
    _accountMgr.checkAccess(caller, null, true, rule);
    final boolean result = deleteLoadBalancerRule(loadBalancerId, apply, caller, ctx.getCallingUserId(), true);
    if (!result) {
        throw new CloudRuntimeException("Unable to remove load balancer rule " + loadBalancerId);
    }
    return result;
}
Also used : Account(com.cloud.user.Account) InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) LoadBalancerVO(com.cloud.network.dao.LoadBalancerVO) CallContext(com.cloud.context.CallContext) ActionEvent(com.cloud.event.ActionEvent)

Example 99 with InvalidParameterValueException

use of com.cloud.utils.exception.InvalidParameterValueException in project cosmic by MissionCriticalCloud.

the class LoadBalancingRulesManagerImpl method isLbServiceSupportedInNetwork.

@Override
public void isLbServiceSupportedInNetwork(final long networkId, final Scheme scheme) {
    final Network network = _networkDao.findById(networkId);
    // 1) Check if the LB service is supported
    if (!_networkModel.areServicesSupportedInNetwork(network.getId(), Service.Lb)) {
        final InvalidParameterValueException ex = new InvalidParameterValueException("LB service is not supported in specified network id");
        ex.addProxyObject(network.getUuid(), "networkId");
        throw ex;
    }
    // 2) Check if the Scheme is supported
    final NetworkOffering off = _entityMgr.findById(NetworkOffering.class, network.getNetworkOfferingId());
    if (scheme == Scheme.Public) {
        if (!off.getPublicLb()) {
            throw new InvalidParameterValueException("Scheme " + scheme + " is not supported by the network offering " + off);
        }
    }
    // 3) Check if the provider supports the scheme
    final LoadBalancingServiceProvider lbProvider = _networkMgr.getLoadBalancingProviderForNetwork(network, scheme);
    if (lbProvider == null) {
        throw new InvalidParameterValueException("Lb rule with scheme " + scheme.toString() + " is not supported by lb providers in network " + network);
    }
}
Also used : InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) NetworkOffering(com.cloud.offering.NetworkOffering) Network(com.cloud.network.Network) LoadBalancingServiceProvider(com.cloud.network.element.LoadBalancingServiceProvider)

Example 100 with InvalidParameterValueException

use of com.cloud.utils.exception.InvalidParameterValueException in project cosmic by MissionCriticalCloud.

the class LoadBalancingRulesManagerImpl method createLBHealthCheckPolicy.

@Override
@DB
@ActionEvent(eventType = EventTypes.EVENT_LB_HEALTHCHECKPOLICY_CREATE, eventDescription = "create load balancer health check to load balancer", create = true)
public HealthCheckPolicy createLBHealthCheckPolicy(final CreateLBHealthCheckPolicyCmd cmd) {
    final CallContext caller = CallContext.current();
    /*
         * Validation of cmd Monitor interval must be greater than response
         * timeout
         */
    final Map<String, String> paramMap = cmd.getFullUrlParams();
    if (paramMap.containsKey(ApiConstants.HEALTHCHECK_RESPONSE_TIMEOUT) && paramMap.containsKey(ApiConstants.HEALTHCHECK_INTERVAL_TIME)) {
        if (cmd.getResponsTimeOut() > cmd.getHealthCheckInterval()) {
            throw new InvalidParameterValueException("Failed to create HealthCheck policy : Monitor interval must be greater than response timeout");
        }
    }
    /* Validation : check corresponding load balancer rule exist */
    final LoadBalancerVO loadBalancer = _lbDao.findById(cmd.getLbRuleId());
    if (loadBalancer == null) {
        throw new InvalidParameterValueException("Failed: LB rule id: " + cmd.getLbRuleId() + " not present ");
    }
    _accountMgr.checkAccess(caller.getCallingAccount(), null, true, loadBalancer);
    if (loadBalancer.getState() == FirewallRule.State.Revoke) {
        throw new InvalidParameterValueException("Failed:  LB rule id: " + cmd.getLbRuleId() + " is in deleting state: ");
    }
    /*
         * Validate Whether LB Provider has the capabilities to support Health
         * Checks
         */
    if (!validateHealthCheck(cmd)) {
        throw new InvalidParameterValueException("Failed to create HealthCheck policy: Validation Failed (HealthCheck Policy is not supported by LB Provider for the LB rule id :" + cmd.getLbRuleId() + ")");
    }
    /* Validation : check for the multiple hc policies to the rule id */
    final List<LBHealthCheckPolicyVO> hcPolicies = _lb2healthcheckDao.listByLoadBalancerId(cmd.getLbRuleId(), false);
    if (hcPolicies.size() > 0) {
        throw new InvalidParameterValueException("Failed to create HealthCheck policy: Already policy attached  for the LB Rule id :" + cmd.getLbRuleId());
    }
    /*
         * Specific validations using network element validator for specific
         * validations
         */
    final LBHealthCheckPolicyVO hcpolicy = new LBHealthCheckPolicyVO(loadBalancer.getId(), cmd.getPingPath(), cmd.getDescription(), cmd.getResponsTimeOut(), cmd.getHealthCheckInterval(), cmd.getHealthyThreshold(), cmd.getUnhealthyThreshold());
    final List<LbHealthCheckPolicy> hcPolicyList = new ArrayList<>();
    hcPolicyList.add(new LbHealthCheckPolicy(hcpolicy.getpingpath(), hcpolicy.getDescription(), hcpolicy.getResponseTime(), hcpolicy.getHealthcheckInterval(), hcpolicy.getHealthcheckThresshold(), hcpolicy.getUnhealthThresshold()));
    // Finally Insert into DB
    LBHealthCheckPolicyVO policy = new LBHealthCheckPolicyVO(loadBalancer.getId(), cmd.getPingPath(), cmd.getDescription(), cmd.getResponsTimeOut(), cmd.getHealthCheckInterval(), cmd.getHealthyThreshold(), cmd.getUnhealthyThreshold());
    final Boolean forDisplay = cmd.getDisplay();
    if (forDisplay != null) {
        policy.setDisplay(forDisplay);
    }
    policy = _lb2healthcheckDao.persist(policy);
    return policy;
}
Also used : InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) LoadBalancerVO(com.cloud.network.dao.LoadBalancerVO) ArrayList(java.util.ArrayList) LbHealthCheckPolicy(com.cloud.network.lb.LoadBalancingRule.LbHealthCheckPolicy) LBHealthCheckPolicyVO(com.cloud.network.LBHealthCheckPolicyVO) CallContext(com.cloud.context.CallContext) ActionEvent(com.cloud.event.ActionEvent) DB(com.cloud.utils.db.DB)

Aggregations

InvalidParameterValueException (com.cloud.utils.exception.InvalidParameterValueException)478 Account (com.cloud.user.Account)199 ActionEvent (com.cloud.event.ActionEvent)151 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)146 ArrayList (java.util.ArrayList)104 DB (com.cloud.utils.db.DB)97 PermissionDeniedException (com.cloud.exception.PermissionDeniedException)72 List (java.util.List)61 TransactionStatus (com.cloud.utils.db.TransactionStatus)57 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)53 ServerApiException (com.cloud.api.ServerApiException)46 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)44 Network (com.cloud.network.Network)40 Pair (com.cloud.utils.Pair)36 HashMap (java.util.HashMap)36 ConfigurationException (javax.naming.ConfigurationException)36 ResourceAllocationException (com.cloud.exception.ResourceAllocationException)33 NetworkVO (com.cloud.network.dao.NetworkVO)31 HostVO (com.cloud.host.HostVO)30 TransactionCallbackNoReturn (com.cloud.utils.db.TransactionCallbackNoReturn)30