Search in sources :

Example 11 with InvalidParameterValueException

use of com.cloud.utils.exception.InvalidParameterValueException in project cosmic by MissionCriticalCloud.

the class DeleteAlertsCmd method execute.

// ///////////////////////////////////////////////////
// ///////////// API Implementation///////////////////
// ///////////////////////////////////////////////////
@Override
public void execute() {
    if (ids == null && type == null && endDate == null) {
        throw new InvalidParameterValueException("either ids, type or enddate must be specified");
    } else if (startDate != null && endDate == null) {
        throw new InvalidParameterValueException("enddate must be specified with startdate parameter");
    }
    final boolean result = _mgr.deleteAlerts(this);
    if (result) {
        final SuccessResponse response = new SuccessResponse(getCommandName());
        this.setResponseObject(response);
    } else {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Unable to delete Alerts, one or more parameters has invalid values");
    }
}
Also used : SuccessResponse(com.cloud.api.response.SuccessResponse) ServerApiException(com.cloud.api.ServerApiException) InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException)

Example 12 with InvalidParameterValueException

use of com.cloud.utils.exception.InvalidParameterValueException in project cosmic by MissionCriticalCloud.

the class AssociateIPAddrCmd method getEntityOwnerId.

@Override
public long getEntityOwnerId() {
    final Account caller = CallContext.current().getCallingAccount();
    if (accountName != null && domainId != null) {
        final Account account = _accountService.finalizeOwner(caller, accountName, domainId, projectId);
        return account.getId();
    } else if (projectId != null) {
        final Project project = _projectService.getProject(projectId);
        if (project != null) {
            if (project.getState() == Project.State.Active) {
                return project.getProjectAccountId();
            } else {
                throw new PermissionDeniedException("Can't add resources to the project with specified projectId in state=" + project.getState() + " as it's no longer active");
            }
        } else {
            throw new InvalidParameterValueException("Unable to find project by ID");
        }
    } else if (networkId != null) {
        final Network network = _networkService.getNetwork(networkId);
        if (network == null) {
            throw new InvalidParameterValueException("Unable to find network by network id specified");
        }
        final NetworkOffering offering = _entityMgr.findById(NetworkOffering.class, network.getNetworkOfferingId());
        final DataCenter zone = _entityMgr.findById(DataCenter.class, network.getDataCenterId());
        if (zone.getNetworkType() == NetworkType.Basic && offering.getElasticIp() && offering.getElasticLb()) {
            // shared network with EIP/ELB service.
            return caller.getAccountId();
        }
        return network.getAccountId();
    } else if (vpcId != null) {
        final Vpc vpc = _entityMgr.findById(Vpc.class, getVpcId());
        if (vpc == null) {
            throw new InvalidParameterValueException("Can't find enabled VPC by ID specified");
        }
        return vpc.getAccountId();
    }
    return caller.getAccountId();
}
Also used : Account(com.cloud.user.Account) Project(com.cloud.projects.Project) DataCenter(com.cloud.dc.DataCenter) InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) NetworkOffering(com.cloud.offering.NetworkOffering) Network(com.cloud.network.Network) Vpc(com.cloud.network.vpc.Vpc) PermissionDeniedException(com.cloud.exception.PermissionDeniedException)

Example 13 with InvalidParameterValueException

use of com.cloud.utils.exception.InvalidParameterValueException in project cosmic by MissionCriticalCloud.

the class AssociateIPAddrCmd method getNetworkId.

public Long getNetworkId() {
    if (vpcId != null) {
        return null;
    }
    if (networkId != null) {
        return networkId;
    }
    final Long zoneId = getZoneId();
    final DataCenter zone = _entityMgr.findById(DataCenter.class, zoneId);
    if (zone.getNetworkType() == NetworkType.Advanced) {
        final List<? extends Network> networks = _networkService.getIsolatedNetworksOwnedByAccountInZone(getZoneId(), _accountService.getAccount(getEntityOwnerId()));
        if (networks.size() == 0) {
            final String domain = _domainService.getDomain(getDomainId()).getName();
            throw new InvalidParameterValueException("Account name=" + getAccountName() + " domain=" + domain + " doesn't have virtual networks in zone=" + zone.getName());
        }
        if (networks.size() < 1) {
            throw new InvalidParameterValueException("Account doesn't have any isolated networks in the zone");
        } else if (networks.size() > 1) {
            throw new InvalidParameterValueException("Account has more than one isolated network in the zone");
        }
        return networks.get(0).getId();
    } else {
        final Network defaultGuestNetwork = _networkService.getExclusiveGuestNetwork(zoneId);
        if (defaultGuestNetwork == null) {
            throw new InvalidParameterValueException("Unable to find a default guest network for account " + getAccountName() + " in domain ID=" + getDomainId());
        } else {
            return defaultGuestNetwork.getId();
        }
    }
}
Also used : DataCenter(com.cloud.dc.DataCenter) InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) Network(com.cloud.network.Network)

Example 14 with InvalidParameterValueException

use of com.cloud.utils.exception.InvalidParameterValueException in project cosmic by MissionCriticalCloud.

the class DisassociateIPAddrCmd method getEntityOwnerId.

@Override
public long getEntityOwnerId() {
    if (ownerId == null) {
        final IpAddress ip = getIpAddress(id);
        if (ip == null) {
            throw new InvalidParameterValueException("Unable to find IP address by ID=" + id);
        }
        ownerId = ip.getAccountId();
    }
    if (ownerId == null) {
        return Account.ACCOUNT_ID_SYSTEM;
    }
    return ownerId;
}
Also used : InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) IpAddress(com.cloud.network.IpAddress)

Example 15 with InvalidParameterValueException

use of com.cloud.utils.exception.InvalidParameterValueException in project cosmic by MissionCriticalCloud.

the class UpdateIPAddrCmd method getEntityOwnerId.

@Override
public long getEntityOwnerId() {
    if (ownerId == null) {
        final IpAddress ip = getIpAddress(id);
        if (ip == null) {
            throw new InvalidParameterValueException("Unable to find IP address by ID=" + id);
        }
        ownerId = ip.getAccountId();
    }
    if (ownerId == null) {
        return Account.ACCOUNT_ID_SYSTEM;
    }
    return ownerId;
}
Also used : InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) IpAddress(com.cloud.network.IpAddress)

Aggregations

InvalidParameterValueException (com.cloud.utils.exception.InvalidParameterValueException)478 Account (com.cloud.user.Account)199 ActionEvent (com.cloud.event.ActionEvent)151 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)146 ArrayList (java.util.ArrayList)104 DB (com.cloud.utils.db.DB)97 PermissionDeniedException (com.cloud.exception.PermissionDeniedException)72 List (java.util.List)61 TransactionStatus (com.cloud.utils.db.TransactionStatus)57 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)53 ServerApiException (com.cloud.api.ServerApiException)46 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)44 Network (com.cloud.network.Network)40 Pair (com.cloud.utils.Pair)36 HashMap (java.util.HashMap)36 ConfigurationException (javax.naming.ConfigurationException)36 ResourceAllocationException (com.cloud.exception.ResourceAllocationException)33 NetworkVO (com.cloud.network.dao.NetworkVO)31 HostVO (com.cloud.host.HostVO)30 TransactionCallbackNoReturn (com.cloud.utils.db.TransactionCallbackNoReturn)30