Search in sources :

Example 21 with ActionEvent

use of com.cloud.event.ActionEvent 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 22 with ActionEvent

use of com.cloud.event.ActionEvent 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 23 with ActionEvent

use of com.cloud.event.ActionEvent 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 24 with ActionEvent

use of com.cloud.event.ActionEvent 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)

Example 25 with ActionEvent

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

the class ProjectManagerImpl method addAccountToProject.

@Override
@ActionEvent(eventType = EventTypes.EVENT_PROJECT_ACCOUNT_ADD, eventDescription = "adding account to project", async = true)
public boolean addAccountToProject(long projectId, String accountName, String email) {
    Account caller = CallContext.current().getCallingAccount();
    //check that the project exists
    Project project = getProject(projectId);
    if (project == null) {
        InvalidParameterValueException ex = new InvalidParameterValueException("Unable to find project with specified id");
        ex.addProxyObject(String.valueOf(projectId), "projectId");
        throw ex;
    }
    //User can be added to Active project only
    if (project.getState() != Project.State.Active) {
        InvalidParameterValueException ex = new InvalidParameterValueException("Can't add account to the specified project id in state=" + project.getState() + " as it's no longer active");
        ex.addProxyObject(project.getUuid(), "projectId");
        throw ex;
    }
    //check that account-to-add exists
    Account account = null;
    if (accountName != null) {
        account = _accountMgr.getActiveAccountByName(accountName, project.getDomainId());
        if (account == null) {
            InvalidParameterValueException ex = new InvalidParameterValueException("Unable to find account name=" + accountName + " in specified domain id");
            DomainVO domain = ApiDBUtils.findDomainById(project.getDomainId());
            String domainUuid = String.valueOf(project.getDomainId());
            if (domain != null) {
                domainUuid = domain.getUuid();
            }
            ex.addProxyObject(domainUuid, "domainId");
            throw ex;
        }
        //verify permissions - only project owner can assign
        _accountMgr.checkAccess(caller, AccessType.ModifyProject, true, _accountMgr.getAccount(project.getProjectAccountId()));
        //Check if the account already added to the project
        ProjectAccount projectAccount = _projectAccountDao.findByProjectIdAccountId(projectId, account.getId());
        if (projectAccount != null) {
            s_logger.debug("Account " + accountName + " already added to the project id=" + projectId);
            return true;
        }
    }
    if (_invitationRequired) {
        return inviteAccountToProject(project, account, email);
    } else {
        if (account == null) {
            throw new InvalidParameterValueException("Account information is required for assigning account to the project");
        }
        if (assignAccountToProject(project, account.getId(), ProjectAccount.Role.Regular) != null) {
            return true;
        } else {
            s_logger.warn("Failed to add account " + accountName + " to project id=" + projectId);
            return false;
        }
    }
}
Also used : Account(com.cloud.user.Account) DomainVO(com.cloud.domain.DomainVO) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) 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