Search in sources :

Example 66 with InvalidParameterValueException

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

the class ManagementServerImpl method getCloudIdentifierResponse.

@Override
public ArrayList<String> getCloudIdentifierResponse(final long userId) {
    final Account caller = getCaller();
    // verify that user exists
    User user = _accountMgr.getUserIncludingRemoved(userId);
    if (user == null || user.getRemoved() != null) {
        final InvalidParameterValueException ex = new InvalidParameterValueException("Unable to find active user of specified id");
        ex.addProxyObject(String.valueOf(userId), "userId");
        throw ex;
    }
    // check permissions
    _accountMgr.checkAccess(caller, null, true, _accountMgr.getAccount(user.getAccountId()));
    String cloudIdentifier = _configDao.getValue("cloud.identifier");
    if (cloudIdentifier == null) {
        cloudIdentifier = "";
    }
    String signature = "";
    try {
        // get the user obj to get his secret key
        user = _accountMgr.getActiveUser(userId);
        final String secretKey = user.getSecretKey();
        final String input = cloudIdentifier;
        signature = signRequest(input, secretKey);
    } catch (final Exception e) {
        s_logger.warn("Exception whilst creating a signature:" + e);
    }
    final ArrayList<String> cloudParams = new ArrayList<>();
    cloudParams.add(cloudIdentifier);
    cloudParams.add(signature);
    return cloudParams;
}
Also used : Account(com.cloud.legacymodel.user.Account) User(com.cloud.legacymodel.user.User) InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException) ArrayList(java.util.ArrayList) ConcurrentOperationException(com.cloud.legacymodel.exceptions.ConcurrentOperationException) OperationTimedoutException(com.cloud.legacymodel.exceptions.OperationTimedoutException) PermissionDeniedException(com.cloud.legacymodel.exceptions.PermissionDeniedException) VirtualMachineMigrationException(com.cloud.legacymodel.exceptions.VirtualMachineMigrationException) InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException) ConfigurationException(javax.naming.ConfigurationException) ResourceUnavailableException(com.cloud.legacymodel.exceptions.ResourceUnavailableException) ManagementServerException(com.cloud.legacymodel.exceptions.ManagementServerException) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException)

Example 67 with InvalidParameterValueException

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

the class ManagementServerImpl method addGuestOsMapping.

@Override
@DB
@ActionEvent(eventType = EventTypes.EVENT_GUEST_OS_MAPPING_ADD, eventDescription = "Adding new guest OS to hypervisor name mapping", create = true)
public GuestOSHypervisor addGuestOsMapping(final AddGuestOsMappingCmd cmd) {
    final Long osTypeId = cmd.getOsTypeId();
    final String osStdName = cmd.getOsStdName();
    final String hypervisor = cmd.getHypervisor();
    final String hypervisorVersion = cmd.getHypervisorVersion();
    final String osNameForHypervisor = cmd.getOsNameForHypervisor();
    GuestOS guestOs = null;
    if (osTypeId == null && (osStdName == null || osStdName.isEmpty())) {
        throw new InvalidParameterValueException("Please specify either a guest OS name or UUID");
    }
    final HypervisorType hypervisorType = HypervisorType.getType(hypervisor);
    if (!(hypervisorType == HypervisorType.KVM || hypervisorType == HypervisorType.XenServer)) {
        throw new InvalidParameterValueException("Please specify a valid hypervisor : XenServer or KVM");
    }
    final HypervisorCapabilitiesVO hypervisorCapabilities = _hypervisorCapabilitiesDao.findByHypervisorTypeAndVersion(hypervisorType, hypervisorVersion);
    if (hypervisorCapabilities == null) {
        throw new InvalidParameterValueException("Please specify a valid hypervisor and supported version");
    }
    // by this point either osTypeId or osStdType is non-empty. Find by either of them. ID takes preference if both are specified
    if (osTypeId != null) {
        guestOs = ApiDBUtils.findGuestOSById(osTypeId);
    } else if (osStdName != null) {
        guestOs = ApiDBUtils.findGuestOSByDisplayName(osStdName);
    }
    if (guestOs == null) {
        throw new InvalidParameterValueException("Unable to find the guest OS by name or UUID");
    }
    // check for duplicates
    final GuestOSHypervisorVO duplicate = _guestOSHypervisorDao.findByOsIdAndHypervisorAndUserDefined(guestOs.getId(), hypervisorType.toString(), hypervisorVersion, true);
    if (duplicate != null) {
        throw new InvalidParameterValueException("Mapping from hypervisor : " + hypervisorType.toString() + ", version : " + hypervisorVersion + " and guest OS : " + guestOs.getDisplayName() + " already exists!");
    }
    final GuestOSHypervisorVO guestOsMapping = new GuestOSHypervisorVO();
    guestOsMapping.setGuestOsId(guestOs.getId());
    guestOsMapping.setGuestOsName(osNameForHypervisor);
    guestOsMapping.setHypervisorType(hypervisorType.toString());
    guestOsMapping.setHypervisorVersion(hypervisorVersion);
    guestOsMapping.setIsUserDefined(true);
    return _guestOSHypervisorDao.persist(guestOsMapping);
}
Also used : HypervisorType(com.cloud.model.enumeration.HypervisorType) HypervisorCapabilitiesVO(com.cloud.hypervisor.HypervisorCapabilitiesVO) GuestOSHypervisorVO(com.cloud.storage.GuestOSHypervisorVO) InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException) GuestOS(com.cloud.storage.GuestOS) ActionEvent(com.cloud.event.ActionEvent) DB(com.cloud.utils.db.DB)

Example 68 with InvalidParameterValueException

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

the class ManagementServerImpl method upgradeStoppedSystemVm.

private VirtualMachine upgradeStoppedSystemVm(final Long systemVmId, final Long serviceOfferingId, final Map<String, String> customparameters) {
    final Account caller = getCaller();
    final VMInstanceVO systemVm = _vmInstanceDao.findByIdTypes(systemVmId, VirtualMachineType.ConsoleProxy, VirtualMachineType.SecondaryStorageVm);
    if (systemVm == null) {
        throw new InvalidParameterValueException("Unable to find SystemVm with id " + systemVmId);
    }
    _accountMgr.checkAccess(caller, null, true, systemVm);
    // Check that the specified service offering ID is valid
    ServiceOfferingVO newServiceOffering = _offeringDao.findById(serviceOfferingId);
    final ServiceOfferingVO currentServiceOffering = _offeringDao.findById(systemVmId, systemVm.getServiceOfferingId());
    _itMgr.checkIfCanUpgrade(systemVm, newServiceOffering);
    final boolean result = _itMgr.upgradeVmDb(systemVmId, serviceOfferingId);
    if (result) {
        return _vmInstanceDao.findById(systemVmId);
    } else {
        throw new CloudRuntimeException("Unable to upgrade system vm " + systemVm);
    }
}
Also used : Account(com.cloud.legacymodel.user.Account) InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) VMInstanceVO(com.cloud.vm.VMInstanceVO) ServiceOfferingVO(com.cloud.service.ServiceOfferingVO)

Example 69 with InvalidParameterValueException

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

the class ManagementServerImpl method removeGuestOs.

@Override
@DB
@ActionEvent(eventType = EventTypes.EVENT_GUEST_OS_REMOVE, eventDescription = "removing guest OS type", async = true)
public boolean removeGuestOs(final RemoveGuestOsCmd cmd) {
    final Long id = cmd.getId();
    // check if guest OS exists
    final GuestOS guestOs = ApiDBUtils.findGuestOSById(id);
    if (guestOs == null) {
        throw new InvalidParameterValueException("Guest OS not found. Please specify a valid ID for the Guest OS");
    }
    if (!guestOs.getIsUserDefined()) {
        throw new InvalidParameterValueException("Unable to remove system defined guest OS");
    }
    return _guestOSDao.remove(id);
}
Also used : InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException) GuestOS(com.cloud.storage.GuestOS) ActionEvent(com.cloud.event.ActionEvent) DB(com.cloud.utils.db.DB)

Example 70 with InvalidParameterValueException

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

the class ManagementServerImpl method addGuestOs.

@Override
@DB
@ActionEvent(eventType = EventTypes.EVENT_GUEST_OS_ADD, eventDescription = "Adding new guest OS type", create = true)
public GuestOS addGuestOs(final AddGuestOsCmd cmd) {
    final Long categoryId = cmd.getOsCategoryId();
    final String displayName = cmd.getOsDisplayName();
    final String name = cmd.getOsName();
    final GuestOSCategoryVO guestOsCategory = ApiDBUtils.findGuestOsCategoryById(categoryId);
    if (guestOsCategory == null) {
        throw new InvalidParameterValueException("Guest OS category not found. Please specify a valid Guest OS category");
    }
    final GuestOS guestOs = ApiDBUtils.findGuestOSByDisplayName(displayName);
    if (guestOs != null) {
        throw new InvalidParameterValueException("The specified Guest OS name : " + displayName + " already exists. Please specify a unique name");
    }
    final GuestOSVO guestOsVo = new GuestOSVO();
    guestOsVo.setCategoryId(categoryId.longValue());
    guestOsVo.setDisplayName(displayName);
    guestOsVo.setName(name);
    guestOsVo.setIsUserDefined(true);
    return _guestOSDao.persist(guestOsVo);
}
Also used : InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException) GuestOSCategoryVO(com.cloud.storage.GuestOSCategoryVO) GuestOS(com.cloud.storage.GuestOS) GuestOSVO(com.cloud.storage.GuestOSVO) ActionEvent(com.cloud.event.ActionEvent) DB(com.cloud.utils.db.DB)

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