use of com.cloud.legacymodel.user.User in project cosmic by MissionCriticalCloud.
the class ConfigurationManagerImpl method createServiceOffering.
protected ServiceOfferingVO createServiceOffering(final long userId, final boolean isSystem, final VirtualMachineType vmType, final String name, final Integer cpu, final Integer ramSize, final String displayText, final String provisioningType, final boolean localStorageRequired, final boolean offerHA, final boolean limitResourceUse, final boolean volatileVm, String tags, final Long domainId, final String hostTag, final Integer networkRate, final String deploymentPlanner, final Map<String, String> details, final Boolean isCustomizedIops, Long minIops, Long maxIops, Long bytesReadRate, Long bytesWriteRate, Long iopsReadRate, Long iopsWriteRate, Long iopsTotalRate, final boolean iopsRatePerGb, final Integer hypervisorSnapshotReserve) {
// Check if user exists in the system
final User user = _userDao.findById(userId);
if (user == null || user.getRemoved() != null) {
throw new InvalidParameterValueException("Unable to find active user by id " + userId);
}
final Account account = _accountDao.findById(user.getAccountId());
if (account.getType() == Account.ACCOUNT_TYPE_DOMAIN_ADMIN) {
if (domainId == null) {
throw new InvalidParameterValueException("Unable to create public service offering by id " + userId + " because it is domain-admin");
}
if (tags != null || hostTag != null) {
throw new InvalidParameterValueException("Unable to create service offering with storage tags or host tags by id " + userId + " because it is domain-admin");
}
if (!_domainDao.isChildDomain(account.getDomainId(), domainId)) {
throw new InvalidParameterValueException("Unable to create service offering by another domain admin with id " + userId);
}
} else if (account.getType() != Account.ACCOUNT_TYPE_ADMIN) {
throw new InvalidParameterValueException("Unable to create service offering by id " + userId + " because it is not root-admin or domain-admin");
}
final StorageProvisioningType typedProvisioningType = StorageProvisioningType.valueOf(provisioningType);
tags = StringUtils.cleanupTags(tags);
ServiceOfferingVO offering = new ServiceOfferingVO(name, cpu, ramSize, networkRate, null, offerHA, limitResourceUse, volatileVm, displayText, typedProvisioningType, localStorageRequired, false, tags, isSystem, vmType, domainId, hostTag, deploymentPlanner);
if (isCustomizedIops != null) {
bytesReadRate = null;
bytesWriteRate = null;
iopsReadRate = null;
iopsWriteRate = null;
if (isCustomizedIops) {
minIops = null;
maxIops = null;
} else {
if (minIops == null && maxIops == null) {
minIops = 0L;
maxIops = 0L;
} else {
if (minIops == null || minIops <= 0) {
throw new InvalidParameterValueException("The min IOPS must be greater than 0.");
}
if (maxIops == null) {
maxIops = 0L;
}
if (minIops > maxIops) {
throw new InvalidParameterValueException("The min IOPS must be less than or equal to the max IOPS.");
}
}
}
} else {
minIops = null;
maxIops = null;
}
offering.setCustomizedIops(isCustomizedIops);
offering.setMinIops(minIops);
offering.setMaxIops(maxIops);
if (bytesReadRate != null && bytesReadRate > 0) {
offering.setBytesReadRate(bytesReadRate);
}
if (bytesWriteRate != null && bytesWriteRate > 0) {
offering.setBytesWriteRate(bytesWriteRate);
}
if (iopsReadRate != null && iopsReadRate > 0) {
offering.setIopsReadRate(iopsReadRate);
}
if (iopsWriteRate != null && iopsWriteRate > 0) {
offering.setIopsWriteRate(iopsWriteRate);
}
if (iopsTotalRate != null && iopsTotalRate > 0) {
if (iopsWriteRate != null && iopsWriteRate > 0 || iopsReadRate != null && iopsReadRate > 0) {
throw new InvalidParameterValueException("Total IOPS rate cannot be used together with IOPS read rate or IOPS write rate");
}
offering.setIopsTotalRate(iopsTotalRate);
}
if (iopsRatePerGb) {
offering.setIopsRatePerGb(iopsRatePerGb);
}
if (hypervisorSnapshotReserve != null && hypervisorSnapshotReserve < 0) {
throw new InvalidParameterValueException("If provided, Hypervisor Snapshot Reserve must be greater than or equal to 0.");
}
offering.setHypervisorSnapshotReserve(hypervisorSnapshotReserve);
List<ServiceOfferingDetailsVO> detailsVO = null;
if (details != null) {
// To have correct input, either both gpu card name and VGPU type should be passed or nothing should be passed.
// Use XOR condition to verify that.
final boolean entry1 = details.containsKey(GPU.Keys.pciDevice.toString());
final boolean entry2 = details.containsKey(GPU.Keys.vgpuType.toString());
if ((entry1 || entry2) && !(entry1 && entry2)) {
throw new InvalidParameterValueException("Please specify the pciDevice and vgpuType correctly.");
}
detailsVO = new ArrayList<>();
for (final Entry<String, String> detailEntry : details.entrySet()) {
if (detailEntry.getKey().equals(GPU.Keys.pciDevice.toString())) {
if (detailEntry.getValue() == null) {
throw new InvalidParameterValueException("Please specify a GPU Card.");
}
}
if (detailEntry.getKey().equals(GPU.Keys.vgpuType.toString())) {
if (detailEntry.getValue() == null) {
throw new InvalidParameterValueException("vGPUType value cannot be null");
}
}
detailsVO.add(new ServiceOfferingDetailsVO(offering.getId(), detailEntry.getKey(), detailEntry.getValue(), true));
}
}
if ((offering = _serviceOfferingDao.persist(offering)) != null) {
if (detailsVO != null && !detailsVO.isEmpty()) {
for (int index = 0; index < detailsVO.size(); index++) {
detailsVO.get(index).setResourceId(offering.getId());
}
_serviceOfferingDetailsDao.saveDetails(detailsVO);
}
CallContext.current().setEventDetails("Service offering id=" + offering.getId());
return offering;
} else {
return null;
}
}
use of com.cloud.legacymodel.user.User in project cosmic by MissionCriticalCloud.
the class ConfigurationManagerImpl method deleteServiceOffering.
@Override
@ActionEvent(eventType = EventTypes.EVENT_SERVICE_OFFERING_DELETE, eventDescription = "deleting service offering")
public boolean deleteServiceOffering(final DeleteServiceOfferingCmd cmd) {
final Long offeringId = cmd.getId();
Long userId = CallContext.current().getCallingUserId();
if (userId == null) {
userId = Long.valueOf(User.UID_SYSTEM);
}
// Verify service offering id
final ServiceOfferingVO offering = _serviceOfferingDao.findById(offeringId);
if (offering == null) {
throw new InvalidParameterValueException("unable to find service offering " + offeringId);
}
if (offering.getDefaultUse()) {
throw new InvalidParameterValueException("Default service offerings cannot be deleted");
}
final User user = _userDao.findById(userId);
if (user == null || user.getRemoved() != null) {
throw new InvalidParameterValueException("Unable to find active user by id " + userId);
}
final Account account = _accountDao.findById(user.getAccountId());
if (account.getType() == Account.ACCOUNT_TYPE_DOMAIN_ADMIN) {
if (offering.getDomainId() == null) {
throw new InvalidParameterValueException("Unable to delete public service offering by id " + userId + " because it is domain-admin");
}
if (!_domainDao.isChildDomain(account.getDomainId(), offering.getDomainId())) {
throw new InvalidParameterValueException("Unable to delete service offering by another domain admin with id " + userId);
}
} else if (account.getType() != Account.ACCOUNT_TYPE_ADMIN) {
throw new InvalidParameterValueException("Unable to delete service offering by id " + userId + " because it is not root-admin or domain-admin");
}
offering.setState(DiskOffering.State.Inactive);
if (_serviceOfferingDao.update(offeringId, offering)) {
CallContext.current().setEventDetails("Service offering id=" + offeringId);
return true;
} else {
return false;
}
}
use of com.cloud.legacymodel.user.User in project cosmic by MissionCriticalCloud.
the class ConfigurationManagerImpl method updateConfiguration.
@Override
@ActionEvent(eventType = EventTypes.EVENT_CONFIGURATION_VALUE_EDIT, eventDescription = "updating configuration")
public Configuration updateConfiguration(final UpdateCfgCmd cmd) throws InvalidParameterValueException {
final Long userId = CallContext.current().getCallingUserId();
final Account caller = CallContext.current().getCallingAccount();
final User user = _userDao.findById(userId);
final String name = cmd.getCfgName();
String value = cmd.getValue();
final Long zoneId = cmd.getZoneId();
final Long clusterId = cmd.getClusterId();
final Long storagepoolId = cmd.getStoragepoolId();
final Long accountId = cmd.getAccountId();
CallContext.current().setEventDetails(" Name: " + name + " New Value: " + (name.toLowerCase().contains("password") ? "*****" : value == null ? "" : value));
// check if config value exists
final ConfigurationVO config = _configDao.findByName(name);
final String catergory;
// FIX ME - All configuration parameters are not moved from config.java to configKey
if (config == null) {
if (_configDepot.get(name) == null) {
s_logger.warn("Probably the component manager where configuration variable " + name + " is defined needs to implement Configurable interface");
throw new InvalidParameterValueException("Config parameter with name " + name + " doesn't exist");
}
catergory = _configDepot.get(name).category();
} else {
catergory = config.getCategory();
}
if (value == null) {
return _configDao.findByName(name);
}
value = value.trim();
if (value.isEmpty() || value.equals("null")) {
value = null;
}
String scope = null;
Long id = null;
int paramCountCheck = 0;
// Non-ROOT may only update the Account scope
if (!_accountMgr.isRootAdmin(caller.getId()) && accountId == null) {
throw new InvalidParameterValueException("Please specify AccountId to update the config for the given account.");
}
if (accountId != null) {
final Account accountToUpdate = _accountDao.findById(accountId);
_accountMgr.checkAccess(caller, null, true, accountToUpdate);
scope = ConfigKey.Scope.Account.toString();
id = accountId;
paramCountCheck++;
}
if (_accountMgr.isRootAdmin(caller.getId())) {
if (zoneId != null) {
scope = ConfigKey.Scope.Zone.toString();
id = zoneId;
paramCountCheck++;
}
if (clusterId != null) {
scope = ConfigKey.Scope.Cluster.toString();
id = clusterId;
paramCountCheck++;
}
if (storagepoolId != null) {
scope = ConfigKey.Scope.StoragePool.toString();
id = storagepoolId;
paramCountCheck++;
}
}
if (paramCountCheck > 1) {
throw new InvalidParameterValueException("cannot handle multiple IDs, provide only one ID corresponding to the scope");
}
final String updatedValue = updateConfiguration(userId, name, catergory, value, scope, id);
if (value == null && updatedValue == null || updatedValue.equalsIgnoreCase(value)) {
return _configDao.findByName(name);
} else {
throw new CloudRuntimeException("Unable to update configuration parameter " + name);
}
}
use of com.cloud.legacymodel.user.User in project cosmic by MissionCriticalCloud.
the class ConfigurationManagerImpl method updateDiskOffering.
@Override
@ActionEvent(eventType = EventTypes.EVENT_DISK_OFFERING_EDIT, eventDescription = "updating disk offering")
public DiskOffering updateDiskOffering(final UpdateDiskOfferingCmd cmd) {
final Long diskOfferingId = cmd.getId();
final String name = cmd.getDiskOfferingName();
final String displayText = cmd.getDisplayText();
final Integer sortKey = cmd.getSortKey();
final Boolean displayDiskOffering = cmd.getDisplayOffering();
// Check if diskOffering exists
final DiskOffering diskOfferingHandle = _entityMgr.findById(DiskOffering.class, diskOfferingId);
if (diskOfferingHandle == null) {
throw new InvalidParameterValueException("Unable to find disk offering by id " + diskOfferingId);
}
Long userId = CallContext.current().getCallingUserId();
if (userId == null) {
userId = Long.valueOf(User.UID_SYSTEM);
}
final User user = _userDao.findById(userId);
if (user == null || user.getRemoved() != null) {
throw new InvalidParameterValueException("Unable to find active user by id " + userId);
}
final Account account = _accountDao.findById(user.getAccountId());
if (account.getType() == Account.ACCOUNT_TYPE_DOMAIN_ADMIN) {
if (diskOfferingHandle.getDomainId() == null) {
throw new InvalidParameterValueException("Unable to update public disk offering by id " + userId + " because it is domain-admin");
}
if (!_domainDao.isChildDomain(account.getDomainId(), diskOfferingHandle.getDomainId())) {
throw new InvalidParameterValueException("Unable to update disk offering by another domain admin with id " + userId);
}
} else if (account.getType() != Account.ACCOUNT_TYPE_ADMIN) {
throw new InvalidParameterValueException("Unable to update disk offering by id " + userId + " because it is not root-admin or domain-admin");
}
final boolean updateNeeded = name != null || displayText != null || sortKey != null || displayDiskOffering != null;
if (!updateNeeded) {
return _diskOfferingDao.findById(diskOfferingId);
}
final DiskOfferingVO diskOffering = _diskOfferingDao.createForUpdate(diskOfferingId);
if (name != null) {
diskOffering.setName(name);
}
if (displayText != null) {
diskOffering.setDisplayText(displayText);
}
if (sortKey != null) {
diskOffering.setSortKey(sortKey);
}
if (displayDiskOffering != null) {
diskOffering.setDisplayOffering(displayDiskOffering);
}
if (_diskOfferingDao.update(diskOfferingId, diskOffering)) {
CallContext.current().setEventDetails("Disk offering id=" + diskOffering.getId());
return _diskOfferingDao.findById(diskOfferingId);
} else {
return null;
}
}
use of com.cloud.legacymodel.user.User in project cosmic by MissionCriticalCloud.
the class ConfigurationManagerImpl method deleteDiskOffering.
@Override
@ActionEvent(eventType = EventTypes.EVENT_DISK_OFFERING_DELETE, eventDescription = "deleting disk offering")
public boolean deleteDiskOffering(final DeleteDiskOfferingCmd cmd) {
final Long diskOfferingId = cmd.getId();
final DiskOfferingVO offering = _diskOfferingDao.findById(diskOfferingId);
if (offering == null) {
throw new InvalidParameterValueException("Unable to find disk offering by id " + diskOfferingId);
}
Long userId = CallContext.current().getCallingUserId();
if (userId == null) {
userId = Long.valueOf(User.UID_SYSTEM);
}
final User user = _userDao.findById(userId);
if (user == null || user.getRemoved() != null) {
throw new InvalidParameterValueException("Unable to find active user by id " + userId);
}
final Account account = _accountDao.findById(user.getAccountId());
if (account.getType() == Account.ACCOUNT_TYPE_DOMAIN_ADMIN) {
if (offering.getDomainId() == null) {
throw new InvalidParameterValueException("Unable to delete public disk offering by id " + userId + " because it is domain-admin");
}
if (!_domainDao.isChildDomain(account.getDomainId(), offering.getDomainId())) {
throw new InvalidParameterValueException("Unable to delete disk offering by another domain admin with id " + userId);
}
} else if (account.getType() != Account.ACCOUNT_TYPE_ADMIN) {
throw new InvalidParameterValueException("Unable to delete disk offering by id " + userId + " because it is not root-admin or domain-admin");
}
offering.setState(DiskOffering.State.Inactive);
if (_diskOfferingDao.update(offering.getId(), offering)) {
CallContext.current().setEventDetails("Disk offering id=" + diskOfferingId);
return true;
} else {
return false;
}
}
Aggregations