Search in sources :

Example 46 with InvalidParameterValueException

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

the class RemoteAccessVpnManagerImpl method updateRemoteAccessVpn.

@Override
@ActionEvent(eventType = EventTypes.EVENT_REMOTE_ACCESS_VPN_UPDATE, eventDescription = "updating remote access vpn", async = true)
public RemoteAccessVpn updateRemoteAccessVpn(long id, String customId, Boolean forDisplay) {
    final RemoteAccessVpnVO vpn = _remoteAccessVpnDao.findById(id);
    if (vpn == null) {
        throw new InvalidParameterValueException("Can't find remote access vpn by id " + id);
    }
    _accountMgr.checkAccess(CallContext.current().getCallingAccount(), null, true, vpn);
    if (customId != null) {
        vpn.setUuid(customId);
    }
    if (forDisplay != null) {
        vpn.setDisplay(forDisplay);
    }
    _remoteAccessVpnDao.update(vpn.getId(), vpn);
    return _remoteAccessVpnDao.findById(id);
}
Also used : RemoteAccessVpnVO(com.cloud.network.dao.RemoteAccessVpnVO) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) ActionEvent(com.cloud.event.ActionEvent)

Example 47 with InvalidParameterValueException

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

the class VpcManagerImpl method findCapabilityForService.

private boolean findCapabilityForService(final Map serviceCapabilitystList, final Capability capability, final Service service) {
    boolean foundCapability = false;
    if (serviceCapabilitystList != null && !serviceCapabilitystList.isEmpty()) {
        final Iterator iter = serviceCapabilitystList.values().iterator();
        while (iter.hasNext()) {
            final HashMap<String, String> currentCapabilityMap = (HashMap<String, String>) iter.next();
            final String currentCapabilityService = currentCapabilityMap.get(SERVICE);
            final String currentCapabilityName = currentCapabilityMap.get(CAPABILITYTYPE);
            final String currentCapabilityValue = currentCapabilityMap.get(CAPABILITYVALUE);
            if (currentCapabilityName == null || currentCapabilityService == null || currentCapabilityValue == null) {
                throw new InvalidParameterValueException(String.format("Invalid capability with name %s, value %s and service %s", currentCapabilityName, currentCapabilityValue, currentCapabilityService));
            }
            if (currentCapabilityName.equalsIgnoreCase(capability.getName())) {
                foundCapability = currentCapabilityValue.equalsIgnoreCase(TRUE_VALUE);
                if (!currentCapabilityService.equalsIgnoreCase(service.getName())) {
                    throw new InvalidParameterValueException(String.format("Invalid Service: %s specified. Capability %s can be specified only for service %s", currentCapabilityService, service.getName(), currentCapabilityName));
                }
                break;
            }
        }
    }
    return foundCapability;
}
Also used : HashMap(java.util.HashMap) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) Iterator(java.util.Iterator)

Example 48 with InvalidParameterValueException

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

the class VpcManagerImpl method updateVpcOffering.

@Override
@ActionEvent(eventType = EventTypes.EVENT_VPC_OFFERING_UPDATE, eventDescription = "updating vpc offering")
public VpcOffering updateVpcOffering(final long vpcOffId, final String vpcOfferingName, final String displayText, final String state) {
    CallContext.current().setEventDetails(" Id: " + vpcOffId);
    // Verify input parameters
    final VpcOfferingVO offeringToUpdate = _vpcOffDao.findById(vpcOffId);
    if (offeringToUpdate == null) {
        throw new InvalidParameterValueException("Unable to find vpc offering " + vpcOffId);
    }
    final VpcOfferingVO offering = _vpcOffDao.createForUpdate(vpcOffId);
    if (vpcOfferingName != null) {
        offering.setName(vpcOfferingName);
    }
    if (displayText != null) {
        offering.setDisplayText(displayText);
    }
    if (state != null) {
        boolean validState = false;
        for (final VpcOffering.State st : VpcOffering.State.values()) {
            if (st.name().equalsIgnoreCase(state)) {
                validState = true;
                offering.setState(st);
            }
        }
        if (!validState) {
            throw new InvalidParameterValueException("Incorrect state value: " + state);
        }
    }
    if (_vpcOffDao.update(vpcOffId, offering)) {
        s_logger.debug("Updated VPC offeirng id=" + vpcOffId);
        return _vpcOffDao.findById(vpcOffId);
    } else {
        return null;
    }
}
Also used : State(com.cloud.network.vpc.VpcOffering.State) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) ActionEvent(com.cloud.event.ActionEvent)

Example 49 with InvalidParameterValueException

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

the class VpcManagerImpl method updateVpc.

@Override
@ActionEvent(eventType = EventTypes.EVENT_VPC_UPDATE, eventDescription = "updating vpc")
public Vpc updateVpc(final long vpcId, final String vpcName, final String displayText, final String customId, final Boolean displayVpc) {
    CallContext.current().setEventDetails(" Id: " + vpcId);
    final Account caller = CallContext.current().getCallingAccount();
    // Verify input parameters
    final VpcVO vpcToUpdate = _vpcDao.findById(vpcId);
    if (vpcToUpdate == null) {
        throw new InvalidParameterValueException("Unable to find vpc by id " + vpcId);
    }
    _accountMgr.checkAccess(caller, null, false, vpcToUpdate);
    final VpcVO vpc = _vpcDao.createForUpdate(vpcId);
    if (vpcName != null) {
        vpc.setName(vpcName);
    }
    if (displayText != null) {
        vpc.setDisplayText(displayText);
    }
    if (customId != null) {
        vpc.setUuid(customId);
    }
    if (displayVpc != null) {
        vpc.setDisplay(displayVpc);
    }
    if (_vpcDao.update(vpcId, vpc)) {
        s_logger.debug("Updated VPC id=" + vpcId);
        return _vpcDao.findById(vpcId);
    } else {
        return null;
    }
}
Also used : Account(com.cloud.user.Account) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) ActionEvent(com.cloud.event.ActionEvent)

Example 50 with InvalidParameterValueException

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

the class Site2SiteVpnManagerImpl method createVpnGateway.

@Override
@ActionEvent(eventType = EventTypes.EVENT_S2S_VPN_GATEWAY_CREATE, eventDescription = "creating s2s vpn gateway", async = true)
public Site2SiteVpnGateway createVpnGateway(CreateVpnGatewayCmd cmd) {
    Account caller = CallContext.current().getCallingAccount();
    Account owner = _accountMgr.getAccount(cmd.getEntityOwnerId());
    //Verify that caller can perform actions in behalf of vpc owner
    _accountMgr.checkAccess(caller, null, false, owner);
    Long vpcId = cmd.getVpcId();
    VpcVO vpc = _vpcDao.findById(vpcId);
    if (vpc == null) {
        throw new InvalidParameterValueException("Invalid VPC " + vpcId + " for site to site vpn gateway creation!");
    }
    Site2SiteVpnGatewayVO gws = _vpnGatewayDao.findByVpcId(vpcId);
    if (gws != null) {
        throw new InvalidParameterValueException("The VPN gateway of VPC " + vpcId + " already existed!");
    }
    //Use source NAT ip for VPC
    List<IPAddressVO> ips = _ipAddressDao.listByAssociatedVpc(vpcId, true);
    if (ips.size() != 1) {
        throw new CloudRuntimeException("Cannot found source nat ip of vpc " + vpcId);
    }
    Site2SiteVpnGatewayVO gw = new Site2SiteVpnGatewayVO(owner.getAccountId(), owner.getDomainId(), ips.get(0).getId(), vpcId);
    if (cmd.getDisplay() != null) {
        gw.setDisplay(cmd.getDisplay());
    }
    _vpnGatewayDao.persist(gw);
    return gw;
}
Also used : Account(com.cloud.user.Account) VpcVO(com.cloud.network.vpc.VpcVO) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) Site2SiteVpnGatewayVO(com.cloud.network.dao.Site2SiteVpnGatewayVO) IPAddressVO(com.cloud.network.dao.IPAddressVO) ActionEvent(com.cloud.event.ActionEvent)

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