Search in sources :

Example 56 with InvalidParameterValueException

use of com.cloud.legacymodel.exceptions.InvalidParameterValueException in project cosmic by MissionCriticalCloud.

the class Site2SiteVpnManagerImpl method createVpnGateway.

@Override
@ActionEvent(eventType = EventTypes.EVENT_S2S_VPN_GATEWAY_CREATE, eventDescription = "creating s2s vpn gateway", async = true)
public Site2SiteVpnGateway createVpnGateway(final CreateVpnGatewayCmd cmd) {
    final Account caller = CallContext.current().getCallingAccount();
    final Account owner = _accountMgr.getAccount(cmd.getEntityOwnerId());
    // Verify that caller can perform actions in behalf of vpc owner
    _accountMgr.checkAccess(caller, null, false, owner);
    final Long vpcId = cmd.getVpcId();
    final VpcVO vpc = _vpcDao.findById(vpcId);
    if (vpc == null) {
        throw new InvalidParameterValueException("Invalid VPC " + vpcId + " for site to site vpn gateway creation!");
    }
    final Site2SiteVpnGatewayVO gws = _vpnGatewayDao.findByVpcId(vpcId);
    if (gws != null) {
        throw new InvalidParameterValueException("The VPN gateway of VPC " + vpcId + " already exists!");
    }
    // Use source NAT ip for VPC
    final List<IPAddressVO> ips = _ipAddressDao.listByVpc(vpcId, true);
    if (ips.size() != 1) {
        throw new CloudRuntimeException("Vpc " + vpcId + " does not have a Public IP address with SourceNat, so no VPN is possible.");
    }
    final 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.legacymodel.user.Account) VpcVO(com.cloud.network.vpc.VpcVO) InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) Site2SiteVpnGatewayVO(com.cloud.network.dao.Site2SiteVpnGatewayVO) IPAddressVO(com.cloud.network.dao.IPAddressVO) ActionEvent(com.cloud.event.ActionEvent)

Example 57 with InvalidParameterValueException

use of com.cloud.legacymodel.exceptions.InvalidParameterValueException in project cosmic by MissionCriticalCloud.

the class Site2SiteVpnManagerImpl method createVpnConnection.

@Override
@ActionEvent(eventType = EventTypes.EVENT_S2S_VPN_CONNECTION_CREATE, eventDescription = "creating s2s vpn connection", create = true)
public Site2SiteVpnConnection createVpnConnection(final CreateVpnConnectionCmd cmd) throws NetworkRuleConflictException {
    final Account caller = CallContext.current().getCallingAccount();
    final Account owner = _accountMgr.getAccount(cmd.getEntityOwnerId());
    // Verify that caller can perform actions in behalf of vpc owner
    _accountMgr.checkAccess(caller, null, false, owner);
    final Long customerGatewayId = cmd.getCustomerGatewayId();
    final Site2SiteCustomerGateway customerGateway = _customerGatewayDao.findById(customerGatewayId);
    if (customerGateway == null) {
        throw new InvalidParameterValueException("Unable to found specified Site to Site VPN customer gateway " + customerGatewayId + " !");
    }
    _accountMgr.checkAccess(caller, null, false, customerGateway);
    final Long vpnGatewayId = cmd.getVpnGatewayId();
    final Site2SiteVpnGateway vpnGateway = _vpnGatewayDao.findById(vpnGatewayId);
    if (vpnGateway == null) {
        throw new InvalidParameterValueException("Unable to found specified Site to Site VPN gateway " + vpnGatewayId + " !");
    }
    _accountMgr.checkAccess(caller, null, false, vpnGateway);
    if (customerGateway.getAccountId() != vpnGateway.getAccountId() || customerGateway.getDomainId() != vpnGateway.getDomainId()) {
        throw new InvalidParameterValueException("VPN connection can only be esitablished between same account's VPN gateway and customer gateway!");
    }
    if (_vpnConnectionDao.findByVpnGatewayIdAndCustomerGatewayId(vpnGatewayId, customerGatewayId) != null) {
        throw new InvalidParameterValueException("The vpn connection with customer gateway id " + customerGatewayId + " and vpn gateway id " + vpnGatewayId + " already existed!");
    }
    final String[] cidrList = customerGateway.getGuestCidrList().split(",");
    // Remote sub nets cannot overlap VPC's sub net
    final String vpcCidr = _vpcDao.findById(vpnGateway.getVpcId()).getCidr();
    for (final String cidr : cidrList) {
        if (NetUtils.isNetworksOverlap(vpcCidr, cidr)) {
            throw new InvalidParameterValueException("The subnets of customer gateway " + customerGatewayId + "'s subnet " + cidr + " is overlapped with VPC cidr " + vpcCidr + "!");
        }
    }
    // We also need to check if the new connection's remote CIDR is overlapped with existed connections
    final List<Site2SiteVpnConnectionVO> conns = _vpnConnectionDao.listByVpnGatewayId(vpnGatewayId);
    if (conns.size() >= _connLimit) {
        throw new InvalidParameterValueException("There are too many VPN connections with current VPN gateway! The limit is " + _connLimit);
    }
    for (final Site2SiteVpnConnectionVO vc : conns) {
        if (vc == null) {
            continue;
        }
        final Site2SiteCustomerGatewayVO gw = _customerGatewayDao.findById(vc.getCustomerGatewayId());
        final String[] oldCidrList = gw.getGuestCidrList().split(",");
        for (final String oldCidr : oldCidrList) {
            for (final String cidr : cidrList) {
                if (NetUtils.isNetworksOverlap(cidr, oldCidr)) {
                    throw new InvalidParameterValueException("The new connection's remote subnet " + cidr + " is overlapped with existed VPN connection to customer gateway " + gw.getName() + "'s subnet " + oldCidr);
                }
            }
        }
    }
    final Site2SiteVpnConnectionVO conn = new Site2SiteVpnConnectionVO(owner.getAccountId(), owner.getDomainId(), vpnGatewayId, customerGatewayId, cmd.isPassive());
    conn.setState(State.Pending);
    if (cmd.getDisplay() != null) {
        conn.setDisplay(cmd.getDisplay());
    }
    _vpnConnectionDao.persist(conn);
    return conn;
}
Also used : Account(com.cloud.legacymodel.user.Account) Site2SiteVpnGateway(com.cloud.network.Site2SiteVpnGateway) InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException) Site2SiteCustomerGatewayVO(com.cloud.network.dao.Site2SiteCustomerGatewayVO) Site2SiteVpnConnectionVO(com.cloud.network.dao.Site2SiteVpnConnectionVO) Site2SiteCustomerGateway(com.cloud.network.Site2SiteCustomerGateway) ActionEvent(com.cloud.event.ActionEvent)

Example 58 with InvalidParameterValueException

use of com.cloud.legacymodel.exceptions.InvalidParameterValueException in project cosmic by MissionCriticalCloud.

the class Site2SiteVpnManagerImpl method deleteCustomerGateway.

@Override
@ActionEvent(eventType = EventTypes.EVENT_S2S_VPN_CUSTOMER_GATEWAY_DELETE, eventDescription = "deleting s2s vpn customer gateway", create = true)
public boolean deleteCustomerGateway(final DeleteVpnCustomerGatewayCmd cmd) {
    CallContext.current().setEventDetails(" Id: " + cmd.getId());
    final Account caller = CallContext.current().getCallingAccount();
    final Long id = cmd.getId();
    final Site2SiteCustomerGateway customerGateway = _customerGatewayDao.findById(id);
    if (customerGateway == null) {
        throw new InvalidParameterValueException("Fail to find customer gateway with " + id + " !");
    }
    _accountMgr.checkAccess(caller, null, false, customerGateway);
    return doDeleteCustomerGateway(customerGateway);
}
Also used : Account(com.cloud.legacymodel.user.Account) InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException) Site2SiteCustomerGateway(com.cloud.network.Site2SiteCustomerGateway) ActionEvent(com.cloud.event.ActionEvent)

Example 59 with InvalidParameterValueException

use of com.cloud.legacymodel.exceptions.InvalidParameterValueException in project cosmic by MissionCriticalCloud.

the class Site2SiteVpnManagerImpl method startVpnConnection.

@Override
@DB
@ActionEvent(eventType = EventTypes.EVENT_S2S_VPN_CONNECTION_CREATE, eventDescription = "starting s2s vpn connection", async = true)
public Site2SiteVpnConnection startVpnConnection(final long id) throws ResourceUnavailableException {
    final Site2SiteVpnConnectionVO conn = _vpnConnectionDao.acquireInLockTable(id);
    if (conn == null) {
        throw new CloudRuntimeException("Unable to acquire lock on " + conn);
    }
    try {
        if (conn.getState() != State.Pending && conn.getState() != State.Disconnected) {
            throw new InvalidParameterValueException("Site to site VPN connection with specified connectionId not in correct state(pending or disconnected) to process!");
        }
        conn.setState(State.Pending);
        _vpnConnectionDao.persist(conn);
        boolean result = true;
        for (final Site2SiteVpnServiceProvider element : _s2sProviders) {
            result = result & element.startSite2SiteVpn(conn);
        }
        if (result) {
            if (conn.isPassive()) {
                conn.setState(State.Disconnected);
            } else {
                conn.setState(State.Connected);
            }
            _vpnConnectionDao.persist(conn);
            return conn;
        }
        conn.setState(State.Error);
        _vpnConnectionDao.persist(conn);
        throw new ResourceUnavailableException("Failed to apply site-to-site VPN", Site2SiteVpnConnection.class, id);
    } finally {
        _vpnConnectionDao.releaseFromLockTable(conn.getId());
    }
}
Also used : InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) Site2SiteVpnServiceProvider(com.cloud.network.element.Site2SiteVpnServiceProvider) ResourceUnavailableException(com.cloud.legacymodel.exceptions.ResourceUnavailableException) Site2SiteVpnConnectionVO(com.cloud.network.dao.Site2SiteVpnConnectionVO) ActionEvent(com.cloud.event.ActionEvent) DB(com.cloud.utils.db.DB)

Example 60 with InvalidParameterValueException

use of com.cloud.legacymodel.exceptions.InvalidParameterValueException in project cosmic by MissionCriticalCloud.

the class Site2SiteVpnManagerImpl method deleteVpnConnection.

@Override
@ActionEvent(eventType = EventTypes.EVENT_S2S_VPN_CONNECTION_DELETE, eventDescription = "deleting s2s vpn connection", create = true)
public boolean deleteVpnConnection(final DeleteVpnConnectionCmd cmd) throws ResourceUnavailableException {
    CallContext.current().setEventDetails(" Id: " + cmd.getId());
    final Account caller = CallContext.current().getCallingAccount();
    final Long id = cmd.getId();
    final Site2SiteVpnConnectionVO conn = _vpnConnectionDao.findById(id);
    if (conn == null) {
        throw new InvalidParameterValueException("Fail to find site to site VPN connection " + id + " to delete!");
    }
    _accountMgr.checkAccess(caller, null, false, conn);
    stopVpnConnection(id);
    _vpnConnectionDao.remove(id);
    return true;
}
Also used : Account(com.cloud.legacymodel.user.Account) InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException) Site2SiteVpnConnectionVO(com.cloud.network.dao.Site2SiteVpnConnectionVO) ActionEvent(com.cloud.event.ActionEvent)

Aggregations

InvalidParameterValueException (com.cloud.legacymodel.exceptions.InvalidParameterValueException)483 Account (com.cloud.legacymodel.user.Account)219 ActionEvent (com.cloud.event.ActionEvent)159 CloudRuntimeException (com.cloud.legacymodel.exceptions.CloudRuntimeException)153 ArrayList (java.util.ArrayList)105 DB (com.cloud.utils.db.DB)97 PermissionDeniedException (com.cloud.legacymodel.exceptions.PermissionDeniedException)76 List (java.util.List)62 TransactionStatus (com.cloud.utils.db.TransactionStatus)58 ResourceUnavailableException (com.cloud.legacymodel.exceptions.ResourceUnavailableException)53 Network (com.cloud.legacymodel.network.Network)51 ServerApiException (com.cloud.api.ServerApiException)47 ConcurrentOperationException (com.cloud.legacymodel.exceptions.ConcurrentOperationException)43 Pair (com.cloud.legacymodel.utils.Pair)36 HashMap (java.util.HashMap)36 ConfigurationException (javax.naming.ConfigurationException)36 ResourceAllocationException (com.cloud.legacymodel.exceptions.ResourceAllocationException)33 NetworkVO (com.cloud.network.dao.NetworkVO)31 TransactionCallbackNoReturn (com.cloud.utils.db.TransactionCallbackNoReturn)30 HostVO (com.cloud.host.HostVO)29