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;
}
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);
}
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);
}
}
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);
}
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);
}
Aggregations