Search in sources :

Example 51 with InvalidParameterValueException

use of com.cloud.exception.InvalidParameterValueException 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)

Example 52 with InvalidParameterValueException

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

the class ProjectManagerImpl method activateProject.

@Override
@ActionEvent(eventType = EventTypes.EVENT_PROJECT_ACTIVATE, eventDescription = "activating project")
@DB
public Project activateProject(final long projectId) {
    Account caller = CallContext.current().getCallingAccount();
    //check that the project exists
    final ProjectVO 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;
    }
    //verify permissions
    _accountMgr.checkAccess(caller, AccessType.ModifyProject, true, _accountMgr.getAccount(project.getProjectAccountId()));
    //allow project activation only when it's in Suspended state
    Project.State currentState = project.getState();
    if (currentState == State.Active) {
        s_logger.debug("The project id=" + projectId + " is already active, no need to activate it again");
        return project;
    }
    if (currentState != State.Suspended) {
        throw new InvalidParameterValueException("Can't activate the project in " + currentState + " state");
    }
    Transaction.execute(new TransactionCallbackNoReturn() {

        @Override
        public void doInTransactionWithoutResult(TransactionStatus status) {
            project.setState(Project.State.Active);
            _projectDao.update(projectId, project);
            _accountMgr.enableAccount(project.getProjectAccountId());
        }
    });
    return _projectDao.findById(projectId);
}
Also used : Account(com.cloud.user.Account) State(com.cloud.projects.Project.State) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) TransactionStatus(com.cloud.utils.db.TransactionStatus) TransactionCallbackNoReturn(com.cloud.utils.db.TransactionCallbackNoReturn) ActionEvent(com.cloud.event.ActionEvent) DB(com.cloud.utils.db.DB)

Example 53 with InvalidParameterValueException

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

the class Site2SiteVpnManagerImpl method updateCustomerGateway.

@Override
@ActionEvent(eventType = EventTypes.EVENT_S2S_VPN_CUSTOMER_GATEWAY_UPDATE, eventDescription = "update s2s vpn customer gateway", create = true)
public Site2SiteCustomerGateway updateCustomerGateway(UpdateVpnCustomerGatewayCmd cmd) {
    CallContext.current().setEventDetails(" Id: " + cmd.getId());
    Account caller = CallContext.current().getCallingAccount();
    Long id = cmd.getId();
    Site2SiteCustomerGatewayVO gw = _customerGatewayDao.findById(id);
    if (gw == null) {
        throw new InvalidParameterValueException("Find to find customer gateway with id " + id);
    }
    _accountMgr.checkAccess(caller, null, false, gw);
    List<Site2SiteVpnConnectionVO> conns = _vpnConnectionDao.listByCustomerGatewayId(id);
    if (conns != null) {
        for (Site2SiteVpnConnection conn : conns) {
            if (conn.getState() != State.Error) {
                throw new InvalidParameterValueException("Unable to update customer gateway with connections in non-Error state!");
            }
        }
    }
    String name = cmd.getName();
    String gatewayIp = cmd.getGatewayIp();
    if (!NetUtils.isValidIp(gatewayIp)) {
        throw new InvalidParameterValueException("The customer gateway ip " + gatewayIp + " is invalid!");
    }
    if (name == null) {
        name = "VPN-" + gatewayIp;
    }
    String guestCidrList = cmd.getGuestCidrList();
    if (!NetUtils.validateGuestCidrList(guestCidrList)) {
        throw new InvalidParameterValueException("The customer gateway guest cidr list " + guestCidrList + " contains invalid guest cidr!");
    }
    String ipsecPsk = cmd.getIpsecPsk();
    String ikePolicy = cmd.getIkePolicy();
    String espPolicy = cmd.getEspPolicy();
    if (!NetUtils.isValidS2SVpnPolicy("ike", ikePolicy)) {
        throw new InvalidParameterValueException("The customer gateway IKE policy" + ikePolicy + " is invalid!  Verify the required Diffie Hellman (DH) group is specified.");
    }
    if (!NetUtils.isValidS2SVpnPolicy("esp", espPolicy)) {
        throw new InvalidParameterValueException("The customer gateway ESP policy" + espPolicy + " is invalid!");
    }
    Long ikeLifetime = cmd.getIkeLifetime();
    if (ikeLifetime == null) {
        // Default value of lifetime is 1 day
        ikeLifetime = (long) 86400;
    }
    if (ikeLifetime > 86400) {
        throw new InvalidParameterValueException("The IKE lifetime " + ikeLifetime + " of vpn connection is invalid!");
    }
    Long espLifetime = cmd.getEspLifetime();
    if (espLifetime == null) {
        // Default value of lifetime is 1 hour
        espLifetime = (long) 3600;
    }
    if (espLifetime > 86400) {
        throw new InvalidParameterValueException("The ESP lifetime " + espLifetime + " of vpn connection is invalid!");
    }
    Boolean dpd = cmd.getDpd();
    if (dpd == null) {
        dpd = false;
    }
    Boolean encap = cmd.getEncap();
    if (encap == null) {
        encap = false;
    }
    checkCustomerGatewayCidrList(guestCidrList);
    long accountId = gw.getAccountId();
    Site2SiteCustomerGatewayVO existedGw = _customerGatewayDao.findByGatewayIpAndAccountId(gatewayIp, accountId);
    if (existedGw != null && existedGw.getId() != gw.getId()) {
        throw new InvalidParameterValueException("The customer gateway with ip " + gatewayIp + " already existed in the system!");
    }
    existedGw = _customerGatewayDao.findByNameAndAccountId(name, accountId);
    if (existedGw != null && existedGw.getId() != gw.getId()) {
        throw new InvalidParameterValueException("The customer gateway with name " + name + " already existed!");
    }
    gw.setName(name);
    gw.setGatewayIp(gatewayIp);
    gw.setGuestCidrList(guestCidrList);
    gw.setIkePolicy(ikePolicy);
    gw.setEspPolicy(espPolicy);
    gw.setIpsecPsk(ipsecPsk);
    gw.setIkeLifetime(ikeLifetime);
    gw.setEspLifetime(espLifetime);
    gw.setDpd(dpd);
    gw.setEncap(encap);
    _customerGatewayDao.persist(gw);
    return gw;
}
Also used : Account(com.cloud.user.Account) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) Site2SiteCustomerGatewayVO(com.cloud.network.dao.Site2SiteCustomerGatewayVO) Site2SiteVpnConnectionVO(com.cloud.network.dao.Site2SiteVpnConnectionVO) Site2SiteVpnConnection(com.cloud.network.Site2SiteVpnConnection) ActionEvent(com.cloud.event.ActionEvent)

Example 54 with InvalidParameterValueException

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

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(DeleteVpnCustomerGatewayCmd cmd) {
    CallContext.current().setEventDetails(" Id: " + cmd.getId());
    Account caller = CallContext.current().getCallingAccount();
    Long id = cmd.getId();
    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.user.Account) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) Site2SiteCustomerGateway(com.cloud.network.Site2SiteCustomerGateway) ActionEvent(com.cloud.event.ActionEvent)

Example 55 with InvalidParameterValueException

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

the class Site2SiteVpnManagerImpl method updateVpnGateway.

@Override
@ActionEvent(eventType = EventTypes.EVENT_S2S_VPN_GATEWAY_UPDATE, eventDescription = "updating s2s vpn gateway", async = true)
public Site2SiteVpnGateway updateVpnGateway(Long id, String customId, Boolean forDisplay) {
    Account caller = CallContext.current().getCallingAccount();
    Site2SiteVpnGatewayVO vpnGateway = _vpnGatewayDao.findById(id);
    if (vpnGateway == null) {
        throw new InvalidParameterValueException("Fail to find vpn gateway with " + id);
    }
    _accountMgr.checkAccess(caller, null, false, vpnGateway);
    if (customId != null) {
        vpnGateway.setUuid(customId);
    }
    if (forDisplay != null) {
        vpnGateway.setDisplay(forDisplay);
    }
    _vpnGatewayDao.update(id, vpnGateway);
    return _vpnGatewayDao.findById(id);
}
Also used : Account(com.cloud.user.Account) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) Site2SiteVpnGatewayVO(com.cloud.network.dao.Site2SiteVpnGatewayVO) 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