Search in sources :

Example 66 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 67 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)

Example 68 with InvalidParameterValueException

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

the class CreateSnapshotFromVMSnapshotCmd method getEntityOwnerId.

@Override
public long getEntityOwnerId() {
    final VMSnapshot vmsnapshot = _entityMgr.findById(VMSnapshot.class, getVMSnapshotId());
    if (vmsnapshot == null) {
        throw new InvalidParameterValueException("Unable to find vmsnapshot by id=" + getVMSnapshotId());
    }
    final Account account = _accountService.getAccount(vmsnapshot.getAccountId());
    // Can create templates for enabled projects/accounts only
    if (account.getType() == Account.ACCOUNT_TYPE_PROJECT) {
        final Project project = _projectService.findByProjectAccountId(vmsnapshot.getAccountId());
        if (project == null) {
            throw new InvalidParameterValueException("Unable to find project by account id=" + account.getUuid());
        }
        if (project.getState() != Project.State.Active) {
            throw new PermissionDeniedException("Can't add resources to the project id=" + project.getUuid() + " 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 vmsnapshot.getAccountId();
}
Also used : Account(com.cloud.user.Account) Project(com.cloud.projects.Project) InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) PermissionDeniedException(com.cloud.exception.PermissionDeniedException) VMSnapshot(com.cloud.vm.snapshot.VMSnapshot)

Example 69 with InvalidParameterValueException

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

the class RemoveFromLoadBalancerRuleCmd method getVmIdIpListMap.

public Map<Long, List<String>> getVmIdIpListMap() {
    final Map<Long, List<String>> vmIdIpsMap = new HashMap<>();
    if (vmIdIpMap != null && !vmIdIpMap.isEmpty()) {
        final Collection idIpsCollection = vmIdIpMap.values();
        final Iterator iter = idIpsCollection.iterator();
        while (iter.hasNext()) {
            final HashMap<String, String> idIpsMap = (HashMap<String, String>) iter.next();
            final String vmId = idIpsMap.get("vmid");
            final String vmIp = idIpsMap.get("vmip");
            final VirtualMachine lbvm = _entityMgr.findByUuid(VirtualMachine.class, vmId);
            if (lbvm == null) {
                throw new InvalidParameterValueException("Unable to find virtual machine ID: " + vmId);
            }
            final Long longVmId = lbvm.getId();
            List<String> ipsList = null;
            if (vmIdIpsMap.containsKey(longVmId)) {
                ipsList = vmIdIpsMap.get(longVmId);
            } else {
                ipsList = new ArrayList<>();
            }
            ipsList.add(vmIp);
            vmIdIpsMap.put(longVmId, ipsList);
        }
    }
    return vmIdIpsMap;
}
Also used : HashMap(java.util.HashMap) InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) Iterator(java.util.Iterator) Collection(java.util.Collection) ArrayList(java.util.ArrayList) List(java.util.List) VirtualMachine(com.cloud.vm.VirtualMachine)

Example 70 with InvalidParameterValueException

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

the class CreateLBHealthCheckPolicyCmd method create.

@Override
public void create() {
    try {
        final HealthCheckPolicy result = _lbService.createLBHealthCheckPolicy(this);
        this.setEntityId(result.getId());
        this.setEntityUuid(result.getUuid());
    } catch (final InvalidParameterValueException e) {
        s_logger.warn("Exception: ", e);
        throw new ServerApiException(ApiErrorCode.MALFORMED_PARAMETER_ERROR, e.getMessage());
    }
}
Also used : ServerApiException(com.cloud.api.ServerApiException) InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) HealthCheckPolicy(com.cloud.network.rules.HealthCheckPolicy)

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