Search in sources :

Example 11 with ActionEvent

use of com.cloud.event.ActionEvent in project cloudstack by apache.

the class VirtualNetworkApplianceManagerImpl method rebootRouter.

@Override
@ActionEvent(eventType = EventTypes.EVENT_ROUTER_REBOOT, eventDescription = "rebooting router Vm", async = true)
public VirtualRouter rebootRouter(final long routerId, final boolean reprogramNetwork) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException {
    final Account caller = CallContext.current().getCallingAccount();
    // verify parameters
    final DomainRouterVO router = _routerDao.findById(routerId);
    if (router == null) {
        throw new InvalidParameterValueException("Unable to find domain router with id " + routerId + ".");
    }
    _accountMgr.checkAccess(caller, null, true, router);
    // Can reboot domain router only in Running state
    if (router == null || router.getState() != VirtualMachine.State.Running) {
        s_logger.warn("Unable to reboot, virtual router is not in the right state " + router.getState());
        throw new ResourceUnavailableException("Unable to reboot domR, it is not in right state " + router.getState(), DataCenter.class, router.getDataCenterId());
    }
    final UserVO user = _userDao.findById(CallContext.current().getCallingUserId());
    s_logger.debug("Stopping and starting router " + router + " as a part of router reboot");
    if (stop(router, false, user, caller) != null) {
        return startRouter(routerId, reprogramNetwork);
    } else {
        throw new CloudRuntimeException("Failed to reboot router " + router);
    }
}
Also used : Account(com.cloud.user.Account) UserVO(com.cloud.user.UserVO) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) DomainRouterVO(com.cloud.vm.DomainRouterVO) ActionEvent(com.cloud.event.ActionEvent)

Example 12 with ActionEvent

use of com.cloud.event.ActionEvent in project cloudstack by apache.

the class VpcManagerImpl method deleteVpc.

@Override
@ActionEvent(eventType = EventTypes.EVENT_VPC_DELETE, eventDescription = "deleting VPC")
public boolean deleteVpc(final long vpcId) throws ConcurrentOperationException, ResourceUnavailableException {
    CallContext.current().setEventDetails(" Id: " + vpcId);
    final CallContext ctx = CallContext.current();
    // Verify vpc id
    final Vpc vpc = _vpcDao.findById(vpcId);
    if (vpc == null) {
        throw new InvalidParameterValueException("unable to find VPC id=" + vpcId);
    }
    // verify permissions
    _accountMgr.checkAccess(ctx.getCallingAccount(), null, false, vpc);
    return destroyVpc(vpc, ctx.getCallingAccount(), ctx.getCallingUserId());
}
Also used : InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) CallContext(org.apache.cloudstack.context.CallContext) ActionEvent(com.cloud.event.ActionEvent)

Example 13 with ActionEvent

use of com.cloud.event.ActionEvent in project cloudstack by apache.

the class VpcManagerImpl method associateIPToVpc.

@DB
@Override
@ActionEvent(eventType = EventTypes.EVENT_NET_IP_ASSIGN, eventDescription = "associating Ip", async = true)
public IpAddress associateIPToVpc(final long ipId, final long vpcId) throws ResourceAllocationException, ResourceUnavailableException, InsufficientAddressCapacityException, ConcurrentOperationException {
    final Account caller = CallContext.current().getCallingAccount();
    Account owner = null;
    final IpAddress ipToAssoc = _ntwkModel.getIp(ipId);
    if (ipToAssoc != null) {
        _accountMgr.checkAccess(caller, null, true, ipToAssoc);
        owner = _accountMgr.getAccount(ipToAssoc.getAllocatedToAccountId());
    } else {
        s_logger.debug("Unable to find ip address by id: " + ipId);
        return null;
    }
    final Vpc vpc = _vpcDao.findById(vpcId);
    if (vpc == null) {
        throw new InvalidParameterValueException("Invalid VPC id provided");
    }
    // check permissions
    _accountMgr.checkAccess(caller, null, true, owner, vpc);
    boolean isSourceNat = false;
    if (getExistingSourceNatInVpc(owner.getId(), vpcId) == null) {
        isSourceNat = true;
    }
    s_logger.debug("Associating ip " + ipToAssoc + " to vpc " + vpc);
    final boolean isSourceNatFinal = isSourceNat;
    Transaction.execute(new TransactionCallbackNoReturn() {

        @Override
        public void doInTransactionWithoutResult(final TransactionStatus status) {
            final IPAddressVO ip = _ipAddressDao.findById(ipId);
            // update ip address with networkId
            ip.setVpcId(vpcId);
            ip.setSourceNat(isSourceNatFinal);
            _ipAddressDao.update(ipId, ip);
            // mark ip as allocated
            _ipAddrMgr.markPublicIpAsAllocated(ip);
        }
    });
    s_logger.debug("Successfully assigned ip " + ipToAssoc + " to vpc " + vpc);
    return _ipAddressDao.findById(ipId);
}
Also used : Account(com.cloud.user.Account) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) TransactionStatus(com.cloud.utils.db.TransactionStatus) IpAddress(com.cloud.network.IpAddress) TransactionCallbackNoReturn(com.cloud.utils.db.TransactionCallbackNoReturn) IPAddressVO(com.cloud.network.dao.IPAddressVO) ActionEvent(com.cloud.event.ActionEvent) DB(com.cloud.utils.db.DB)

Example 14 with ActionEvent

use of com.cloud.event.ActionEvent in project cloudstack by apache.

the class Site2SiteVpnManagerImpl method createVpnConnection.

@Override
@ActionEvent(eventType = EventTypes.EVENT_S2S_VPN_CONNECTION_CREATE, eventDescription = "creating s2s vpn connection", create = true)
public Site2SiteVpnConnection createVpnConnection(CreateVpnConnectionCmd cmd) throws NetworkRuleConflictException {
    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 customerGatewayId = cmd.getCustomerGatewayId();
    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);
    Long vpnGatewayId = cmd.getVpnGatewayId();
    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!");
    }
    String[] cidrList = customerGateway.getGuestCidrList().split(",");
    // Remote sub nets cannot overlap VPC's sub net
    String vpcCidr = _vpcDao.findById(vpnGateway.getVpcId()).getCidr();
    for (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
    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 (Site2SiteVpnConnectionVO vc : conns) {
        if (vc == null) {
            continue;
        }
        Site2SiteCustomerGatewayVO gw = _customerGatewayDao.findById(vc.getCustomerGatewayId());
        String[] oldCidrList = gw.getGuestCidrList().split(",");
        for (String oldCidr : oldCidrList) {
            for (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);
                }
            }
        }
    }
    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.user.Account) Site2SiteVpnGateway(com.cloud.network.Site2SiteVpnGateway) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) Site2SiteCustomerGatewayVO(com.cloud.network.dao.Site2SiteCustomerGatewayVO) Site2SiteVpnConnectionVO(com.cloud.network.dao.Site2SiteVpnConnectionVO) Site2SiteCustomerGateway(com.cloud.network.Site2SiteCustomerGateway) ActionEvent(com.cloud.event.ActionEvent)

Example 15 with ActionEvent

use of com.cloud.event.ActionEvent in project cloudstack by apache.

the class Site2SiteVpnManagerImpl method updateVpnConnection.

@Override
@ActionEvent(eventType = EventTypes.EVENT_S2S_VPN_CONNECTION_UPDATE, eventDescription = "creating s2s vpn gateway", async = true)
public Site2SiteVpnConnection updateVpnConnection(long id, String customId, Boolean forDisplay) {
    Account caller = CallContext.current().getCallingAccount();
    Site2SiteVpnConnectionVO conn = _vpnConnectionDao.findById(id);
    if (conn == null) {
        throw new InvalidParameterValueException("Fail to find site to site VPN connection " + id);
    }
    _accountMgr.checkAccess(caller, null, false, conn);
    if (customId != null) {
        conn.setUuid(customId);
    }
    if (forDisplay != null) {
        conn.setDisplay(forDisplay);
    }
    _vpnConnectionDao.update(id, conn);
    return _vpnConnectionDao.findById(id);
}
Also used : Account(com.cloud.user.Account) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) Site2SiteVpnConnectionVO(com.cloud.network.dao.Site2SiteVpnConnectionVO) ActionEvent(com.cloud.event.ActionEvent)

Aggregations

ActionEvent (com.cloud.event.ActionEvent)209 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)174 Account (com.cloud.user.Account)114 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)80 DB (com.cloud.utils.db.DB)79 TransactionStatus (com.cloud.utils.db.TransactionStatus)40 PermissionDeniedException (com.cloud.exception.PermissionDeniedException)32 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)32 ArrayList (java.util.ArrayList)31 CallContext (org.apache.cloudstack.context.CallContext)22 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)20 TransactionCallbackNoReturn (com.cloud.utils.db.TransactionCallbackNoReturn)20 DataCenterVO (com.cloud.dc.DataCenterVO)18 Network (com.cloud.network.Network)18 LoadBalancerVO (com.cloud.network.dao.LoadBalancerVO)17 InvalidParameterException (java.security.InvalidParameterException)16 List (java.util.List)16 NetworkVO (com.cloud.network.dao.NetworkVO)15 ConfigurationException (javax.naming.ConfigurationException)15 ResourceAllocationException (com.cloud.exception.ResourceAllocationException)14