Search in sources :

Example 71 with InvalidParameterValueException

use of com.cloud.legacymodel.exceptions.InvalidParameterValueException in project cosmic by MissionCriticalCloud.

the class ManagementServerImpl method getVMPassword.

@Override
public String getVMPassword(final GetVMPasswordCmd cmd) {
    final Account caller = getCaller();
    final UserVmVO vm = _userVmDao.findById(cmd.getId());
    if (vm == null) {
        final InvalidParameterValueException ex = new InvalidParameterValueException("No VM with specified id found.");
        ex.addProxyObject(cmd.getId().toString(), "vmId");
        throw ex;
    }
    // make permission check
    _accountMgr.checkAccess(caller, null, true, vm);
    _userVmDao.loadDetails(vm);
    final String password = vm.getDetail("Encrypted.Password");
    if (password == null || password.equals("")) {
        final InvalidParameterValueException ex = new InvalidParameterValueException("No password for VM with specified id found. " + "If VM is created from password enabled template and SSH keypair is assigned to VM then only password can be retrieved.");
        ex.addProxyObject(vm.getUuid(), "vmId");
        throw ex;
    }
    return password;
}
Also used : Account(com.cloud.legacymodel.user.Account) UserVmVO(com.cloud.vm.UserVmVO) InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException)

Example 72 with InvalidParameterValueException

use of com.cloud.legacymodel.exceptions.InvalidParameterValueException in project cosmic by MissionCriticalCloud.

the class ManagementServerImpl method updateGuestOs.

@Override
@DB
@ActionEvent(eventType = EventTypes.EVENT_GUEST_OS_UPDATE, eventDescription = "updating guest OS type", async = true)
public GuestOS updateGuestOs(final UpdateGuestOsCmd cmd) {
    final Long id = cmd.getId();
    final String displayName = cmd.getOsDisplayName();
    // check if guest OS exists
    final GuestOS guestOsHandle = ApiDBUtils.findGuestOSById(id);
    if (guestOsHandle == null) {
        throw new InvalidParameterValueException("Guest OS not found. Please specify a valid ID for the Guest OS");
    }
    if (!guestOsHandle.getIsUserDefined()) {
        throw new InvalidParameterValueException("Unable to modify system defined guest OS");
    }
    // Check if update is needed
    if (displayName.equals(guestOsHandle.getDisplayName())) {
        return guestOsHandle;
    }
    // Check if another Guest OS by same name exists
    final GuestOS duplicate = ApiDBUtils.findGuestOSByDisplayName(displayName);
    if (duplicate != null) {
        throw new InvalidParameterValueException("The specified Guest OS name : " + displayName + " already exists. Please specify a unique guest OS name");
    }
    final GuestOSVO guestOs = _guestOSDao.createForUpdate(id);
    guestOs.setDisplayName(displayName);
    if (_guestOSDao.update(id, guestOs)) {
        return _guestOSDao.findById(id);
    } else {
        return null;
    }
}
Also used : InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException) GuestOS(com.cloud.storage.GuestOS) GuestOSVO(com.cloud.storage.GuestOSVO) ActionEvent(com.cloud.event.ActionEvent) DB(com.cloud.utils.db.DB)

Example 73 with InvalidParameterValueException

use of com.cloud.legacymodel.exceptions.InvalidParameterValueException in project cosmic by MissionCriticalCloud.

the class ManagementServerImpl method updateDomain.

@Override
@DB
public DomainVO updateDomain(final UpdateDomainCmd cmd) {
    final Long domainId = cmd.getId();
    final String domainName = cmd.getDomainName();
    final String networkDomain = cmd.getNetworkDomain();
    // check if domain exists in the system
    final DomainVO domain = _domainDao.findById(domainId);
    if (domain == null) {
        final InvalidParameterValueException ex = new InvalidParameterValueException("Unable to find domain with specified domain id");
        ex.addProxyObject(domainId.toString(), "domainId");
        throw ex;
    } else if (domain.getParent() == null && domainName != null) {
        // name
        throw new InvalidParameterValueException("ROOT domain can not be edited with a new name");
    }
    final Account caller = getCaller();
    _accountMgr.checkAccess(caller, domain);
    // domain name is unique under the parent domain
    if (domainName != null) {
        final SearchCriteria<DomainVO> sc = _domainDao.createSearchCriteria();
        sc.addAnd("name", SearchCriteria.Op.EQ, domainName);
        sc.addAnd("parent", SearchCriteria.Op.EQ, domain.getParent());
        final List<DomainVO> domains = _domainDao.search(sc, null);
        final boolean sameDomain = domains.size() == 1 && domains.get(0).getId() == domainId;
        if (!domains.isEmpty() && !sameDomain) {
            final InvalidParameterValueException ex = new InvalidParameterValueException("Failed to update specified domain id with name '" + domainName + "' since it already exists in the system");
            ex.addProxyObject(domain.getUuid(), "domainId");
            throw ex;
        }
    }
    // validate network domain
    if (networkDomain != null && !networkDomain.isEmpty()) {
        if (!NetUtils.verifyDomainName(networkDomain)) {
            throw new InvalidParameterValueException("Invalid network domain. Total length shouldn't exceed 190 chars. Each domain label must be between 1 and 63 characters long, can contain ASCII letters " + "'a' through 'z', the digits '0' through '9', " + "and the hyphen ('-'); can't start or end with \"-\"");
        }
    }
    Transaction.execute(new TransactionCallbackNoReturn() {

        @Override
        public void doInTransactionWithoutResult(final TransactionStatus status) {
            if (domainName != null) {
                final String updatedDomainPath = getUpdatedDomainPath(domain.getPath(), domainName);
                updateDomainChildren(domain, updatedDomainPath);
                domain.setName(domainName);
                domain.setPath(updatedDomainPath);
            }
            if (networkDomain != null) {
                if (networkDomain.isEmpty()) {
                    domain.setNetworkDomain(null);
                } else {
                    domain.setNetworkDomain(networkDomain);
                }
            }
            _domainDao.update(domainId, domain);
        }
    });
    return _domainDao.findById(domainId);
}
Also used : DomainVO(com.cloud.domain.DomainVO) Account(com.cloud.legacymodel.user.Account) InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException) TransactionStatus(com.cloud.utils.db.TransactionStatus) TransactionCallbackNoReturn(com.cloud.utils.db.TransactionCallbackNoReturn) DB(com.cloud.utils.db.DB)

Example 74 with InvalidParameterValueException

use of com.cloud.legacymodel.exceptions.InvalidParameterValueException in project cosmic by MissionCriticalCloud.

the class ManagementServerImpl method createSSHKeyPair.

@Override
public SSHKeyPair createSSHKeyPair(final CreateSSHKeyPairCmd cmd) {
    final Account caller = getCaller();
    final String accountName = cmd.getAccountName();
    final Long domainId = cmd.getDomainId();
    final Long projectId = cmd.getProjectId();
    final Account owner = _accountMgr.finalizeOwner(caller, accountName, domainId, projectId);
    final SSHKeyPairVO s = _sshKeyPairDao.findByName(owner.getAccountId(), owner.getDomainId(), cmd.getName());
    if (s != null) {
        throw new InvalidParameterValueException("A key pair with name '" + cmd.getName() + "' already exists.");
    }
    final SSHKeysHelper keys = new SSHKeysHelper();
    final String name = cmd.getName();
    final String publicKey = keys.getPublicKey();
    final String fingerprint = keys.getPublicKeyFingerPrint();
    final String privateKey = keys.getPrivateKey();
    return createAndSaveSSHKeyPair(name, fingerprint, publicKey, privateKey, owner);
}
Also used : Account(com.cloud.legacymodel.user.Account) InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException) SSHKeysHelper(com.cloud.utils.ssh.SSHKeysHelper) SSHKeyPairVO(com.cloud.user.SSHKeyPairVO)

Example 75 with InvalidParameterValueException

use of com.cloud.legacymodel.exceptions.InvalidParameterValueException in project cosmic by MissionCriticalCloud.

the class ManagementServerImpl method startSystemVM.

@Override
@ActionEvent(eventType = "", eventDescription = "", async = true)
public VirtualMachine startSystemVM(final long vmId) {
    final VMInstanceVO systemVm = _vmInstanceDao.findByIdTypes(vmId, VirtualMachineType.ConsoleProxy, VirtualMachineType.SecondaryStorageVm);
    if (systemVm == null) {
        final InvalidParameterValueException ex = new InvalidParameterValueException("unable to find a system vm with specified vmId");
        ex.addProxyObject(String.valueOf(vmId), "vmId");
        throw ex;
    }
    if (systemVm.getType() == VirtualMachineType.ConsoleProxy) {
        ActionEventUtils.startNestedActionEvent(EventTypes.EVENT_PROXY_START, "starting console proxy Vm");
        return startConsoleProxy(vmId);
    } else if (systemVm.getType() == VirtualMachineType.SecondaryStorageVm) {
        ActionEventUtils.startNestedActionEvent(EventTypes.EVENT_SSVM_START, "starting secondary storage Vm");
        return startSecondaryStorageVm(vmId);
    } else {
        final InvalidParameterValueException ex = new InvalidParameterValueException("Unable to find a system vm with specified vmId");
        ex.addProxyObject(systemVm.getUuid(), "vmId");
        throw ex;
    }
}
Also used : InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException) VMInstanceVO(com.cloud.vm.VMInstanceVO) ActionEvent(com.cloud.event.ActionEvent)

Aggregations

InvalidParameterValueException (com.cloud.legacymodel.exceptions.InvalidParameterValueException)483 Account (com.cloud.legacymodel.user.Account)219 ActionEvent (com.cloud.event.ActionEvent)159 CloudRuntimeException (com.cloud.legacymodel.exceptions.CloudRuntimeException)153 ArrayList (java.util.ArrayList)105 DB (com.cloud.utils.db.DB)97 PermissionDeniedException (com.cloud.legacymodel.exceptions.PermissionDeniedException)76 List (java.util.List)62 TransactionStatus (com.cloud.utils.db.TransactionStatus)58 ResourceUnavailableException (com.cloud.legacymodel.exceptions.ResourceUnavailableException)53 Network (com.cloud.legacymodel.network.Network)51 ServerApiException (com.cloud.api.ServerApiException)47 ConcurrentOperationException (com.cloud.legacymodel.exceptions.ConcurrentOperationException)43 Pair (com.cloud.legacymodel.utils.Pair)36 HashMap (java.util.HashMap)36 ConfigurationException (javax.naming.ConfigurationException)36 ResourceAllocationException (com.cloud.legacymodel.exceptions.ResourceAllocationException)33 NetworkVO (com.cloud.network.dao.NetworkVO)31 TransactionCallbackNoReturn (com.cloud.utils.db.TransactionCallbackNoReturn)30 HostVO (com.cloud.host.HostVO)29