Search in sources :

Example 26 with InvalidParameterValueException

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

the class EnableStaticNatCmd method getNetworkId.

public long getNetworkId() {
    final IpAddress ip = _entityMgr.findById(IpAddress.class, getIpAddressId());
    Long ntwkId = null;
    if (ip.getAssociatedWithNetworkId() != null) {
        ntwkId = ip.getAssociatedWithNetworkId();
    } else {
        ntwkId = networkId;
    }
    if (ntwkId == null) {
        throw new InvalidParameterValueException("Unable to enable static NAT for the ipAddress id=" + ipAddressId + " as IP is not associated with any network and no networkId is passed in");
    }
    return ntwkId;
}
Also used : InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) IpAddress(com.cloud.network.IpAddress)

Example 27 with InvalidParameterValueException

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

the class CreateTemplateCmd method getEntityOwnerId.

@Override
public long getEntityOwnerId() {
    final Long volumeId = getVolumeId();
    final Long snapshotId = getSnapshotId();
    final Account callingAccount = CallContext.current().getCallingAccount();
    if (volumeId != null) {
        final Volume volume = _entityMgr.findById(Volume.class, volumeId);
        if (volume != null) {
            _accountService.checkAccess(callingAccount, SecurityChecker.AccessType.UseEntry, false, volume);
        } else {
            throw new InvalidParameterValueException("Unable to find volume by id=" + volumeId);
        }
    } else {
        final Snapshot snapshot = _entityMgr.findById(Snapshot.class, snapshotId);
        if (snapshot != null) {
            _accountService.checkAccess(callingAccount, SecurityChecker.AccessType.UseEntry, false, snapshot);
        } else {
            throw new InvalidParameterValueException("Unable to find snapshot by id=" + snapshotId);
        }
    }
    if (projectId != null) {
        final Project project = _projectService.getProject(projectId);
        if (project != null) {
            if (project.getState() == Project.State.Active) {
                final Account projectAccount = _accountService.getAccount(project.getProjectAccountId());
                _accountService.checkAccess(callingAccount, SecurityChecker.AccessType.UseEntry, false, projectAccount);
                return project.getProjectAccountId();
            } else {
                final PermissionDeniedException ex = new PermissionDeniedException("Can't add resources to the project with specified projectId in state=" + project.getState() + " as it's no longer active");
                ex.addProxyObject(project.getUuid(), "projectId");
                throw ex;
            }
        } else {
            throw new InvalidParameterValueException("Unable to find project by id");
        }
    }
    return callingAccount.getId();
}
Also used : Account(com.cloud.user.Account) Snapshot(com.cloud.storage.Snapshot) Project(com.cloud.projects.Project) Volume(com.cloud.storage.Volume) InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) PermissionDeniedException(com.cloud.exception.PermissionDeniedException)

Example 28 with InvalidParameterValueException

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

the class CreateSnapshotCmd method getEntityOwnerId.

@Override
public long getEntityOwnerId() {
    final Volume volume = _entityMgr.findById(Volume.class, getVolumeId());
    if (volume == null) {
        throw new InvalidParameterValueException("Unable to find volume by id=" + volumeId);
    }
    final Account account = _accountService.getAccount(volume.getAccountId());
    // Can create templates for enabled projects/accounts only
    if (account.getType() == Account.ACCOUNT_TYPE_PROJECT) {
        final Project project = _projectService.findByProjectAccountId(volume.getAccountId());
        if (project.getState() != Project.State.Active) {
            throw new PermissionDeniedException("Can't add resources to the project id=" + project.getId() + " in state=" + project.getState() + " as it's no longer active");
        }
    } else if (account.getState() == Account.State.disabled) {
        throw new PermissionDeniedException("The owner of template is disabled: " + account);
    }
    return volume.getAccountId();
}
Also used : Account(com.cloud.user.Account) Project(com.cloud.projects.Project) Volume(com.cloud.storage.Volume) InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) PermissionDeniedException(com.cloud.exception.PermissionDeniedException)

Example 29 with InvalidParameterValueException

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

the class CreateSnapshotFromVMSnapshotCmd method getHostId.

private Long getHostId() {
    final VMSnapshot vmsnapshot = _entityMgr.findById(VMSnapshot.class, getVMSnapshotId());
    if (vmsnapshot == null) {
        throw new InvalidParameterValueException("Unable to find vm snapshot by id=" + getVMSnapshotId());
    }
    final UserVm vm = _entityMgr.findById(UserVm.class, vmsnapshot.getVmId());
    if (vm != null) {
        if (vm.getHostId() != null) {
            return vm.getHostId();
        } else if (vm.getLastHostId() != null) {
            return vm.getLastHostId();
        }
    }
    return null;
}
Also used : UserVm(com.cloud.uservm.UserVm) InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) VMSnapshot(com.cloud.vm.snapshot.VMSnapshot)

Example 30 with InvalidParameterValueException

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

the class CreateSnapshotFromVMSnapshotCmd method getVmId.

private Long getVmId() {
    final VMSnapshot vmsnapshot = _entityMgr.findById(VMSnapshot.class, getVMSnapshotId());
    if (vmsnapshot == null) {
        throw new InvalidParameterValueException("Unable to find vm snapshot by id=" + getVMSnapshotId());
    }
    final UserVm vm = _entityMgr.findById(UserVm.class, vmsnapshot.getVmId());
    if (vm == null) {
        throw new InvalidParameterValueException("Unable to find vm by vm snapshot id=" + getVMSnapshotId());
    }
    return vm.getId();
}
Also used : UserVm(com.cloud.uservm.UserVm) InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) VMSnapshot(com.cloud.vm.snapshot.VMSnapshot)

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