mirror of
https://github.com/apache/cloudstack.git
synced 2025-11-02 20:02:29 +01:00
bug 5900: Added events for disk offering
This commit is contained in:
parent
7875de7303
commit
0e326e853c
@ -118,6 +118,11 @@ public class EventTypes {
|
||||
public static final String EVENT_SERVICE_OFFERING_EDIT = "SERVICE.OFFERING.EDIT";
|
||||
public static final String EVENT_SERVICE_OFFERING_DELETE = "SERVICE.OFFERING.DELETE";
|
||||
|
||||
// Disk Offerings
|
||||
public static final String EVENT_DISK_OFFERING_CREATE = "DISK.OFFERING.CREATE";
|
||||
public static final String EVENT_DISK_OFFERING_EDIT = "DISK.OFFERING.EDIT";
|
||||
public static final String EVENT_DISK_OFFERING_DELETE = "DISK.OFFERING.DELETE";
|
||||
|
||||
// Pods
|
||||
public static final String EVENT_POD_CREATE = "POD.CREATE";
|
||||
public static final String EVENT_POD_EDIT = "POD.EDIT";
|
||||
|
||||
@ -1836,14 +1836,14 @@ public interface ManagementServer {
|
||||
* @param tags Comma separated string to indicate special tags for the disk offering.
|
||||
* @return the created disk offering, null if failed to create
|
||||
*/
|
||||
DiskOfferingVO createDiskOffering(long domainId, String name, String description, int numGibibytes, String tags) throws InvalidParameterValueException;
|
||||
DiskOfferingVO createDiskOffering(long userId, long domainId, String name, String description, int numGibibytes, String tags) throws InvalidParameterValueException;
|
||||
|
||||
/**
|
||||
* Delete a disk offering
|
||||
* @param id id of the disk offering to delete
|
||||
* @return true if deleted, false otherwise
|
||||
*/
|
||||
boolean deleteDiskOffering(long id);
|
||||
boolean deleteDiskOffering(long userId, long id);
|
||||
|
||||
/**
|
||||
* Update a disk offering
|
||||
|
||||
@ -29,6 +29,7 @@ import com.cloud.api.ServerApiException;
|
||||
import com.cloud.domain.DomainVO;
|
||||
import com.cloud.exception.InvalidParameterValueException;
|
||||
import com.cloud.storage.DiskOfferingVO;
|
||||
import com.cloud.user.User;
|
||||
import com.cloud.utils.Pair;
|
||||
|
||||
public class CreateDiskOfferingCmd extends BaseCmd {
|
||||
@ -61,7 +62,7 @@ public class CreateDiskOfferingCmd extends BaseCmd {
|
||||
public List<Pair<String, Object>> execute(Map<String, Object> params) {
|
||||
// FIXME: add domain-private disk offerings
|
||||
// Account account = (Account)params.get(BaseCmd.Properties.ACCOUNT_OBJ.getName());
|
||||
// Long userId = (Long)params.get(BaseCmd.Properties.USER_ID.getName());
|
||||
Long userId = (Long)params.get(BaseCmd.Properties.USER_ID.getName());
|
||||
Long domainId = (Long)params.get(BaseCmd.Properties.DOMAIN_ID.getName());
|
||||
String name = (String)params.get(BaseCmd.Properties.NAME.getName());
|
||||
String displayText = (String)params.get(BaseCmd.Properties.DISPLAY_TEXT.getName());
|
||||
@ -74,11 +75,15 @@ public class CreateDiskOfferingCmd extends BaseCmd {
|
||||
// }
|
||||
if (domainId == null) {
|
||||
domainId = DomainVO.ROOT_DOMAIN;
|
||||
}
|
||||
|
||||
if (userId == null) {
|
||||
userId = Long.valueOf(User.UID_SYSTEM);
|
||||
}
|
||||
|
||||
DiskOfferingVO diskOffering = null;
|
||||
try {
|
||||
diskOffering = getManagementServer().createDiskOffering(domainId.longValue(), name, displayText, numGB.intValue(),tags);
|
||||
diskOffering = getManagementServer().createDiskOffering(userId, domainId.longValue(), name, displayText, numGB.intValue(),tags);
|
||||
} catch (InvalidParameterValueException ex) {
|
||||
throw new ServerApiException (BaseCmd.VM_INVALID_PARAM_ERROR, ex.getMessage());
|
||||
}
|
||||
|
||||
@ -27,6 +27,7 @@ import org.apache.log4j.Logger;
|
||||
import com.cloud.api.BaseCmd;
|
||||
import com.cloud.api.ServerApiException;
|
||||
import com.cloud.storage.DiskOfferingVO;
|
||||
import com.cloud.user.User;
|
||||
import com.cloud.utils.Pair;
|
||||
|
||||
public class DeleteDiskOfferingCmd extends BaseCmd {
|
||||
@ -36,7 +37,8 @@ public class DeleteDiskOfferingCmd extends BaseCmd {
|
||||
private static final List<Pair<Enum, Boolean>> s_properties = new ArrayList<Pair<Enum, Boolean>>();
|
||||
|
||||
static {
|
||||
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.ID, Boolean.TRUE));
|
||||
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.ID, Boolean.TRUE));
|
||||
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.USER_ID, Boolean.FALSE));
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
@ -48,7 +50,12 @@ public class DeleteDiskOfferingCmd extends BaseCmd {
|
||||
|
||||
@Override
|
||||
public List<Pair<String, Object>> execute(Map<String, Object> params) {
|
||||
Long id = (Long)params.get(BaseCmd.Properties.ID.getName());
|
||||
Long id = (Long)params.get(BaseCmd.Properties.ID.getName());
|
||||
Long userId = (Long)params.get(BaseCmd.Properties.USER_ID.getName());
|
||||
|
||||
if (userId == null) {
|
||||
userId = Long.valueOf(User.UID_SYSTEM);
|
||||
}
|
||||
|
||||
//verify input parameters
|
||||
DiskOfferingVO disk = getManagementServer().findDiskOfferingById(id);
|
||||
@ -56,7 +63,7 @@ public class DeleteDiskOfferingCmd extends BaseCmd {
|
||||
throw new ServerApiException(BaseCmd.PARAM_ERROR, "unable to find a disk offering with id " + id);
|
||||
}
|
||||
|
||||
boolean result = getManagementServer().deleteDiskOffering(id);
|
||||
boolean result = getManagementServer().deleteDiskOffering(userId, id);
|
||||
|
||||
List<Pair<String, Object>> returnValues = new ArrayList<Pair<String, Object>>();
|
||||
returnValues.add(new Pair<String, Object>(BaseCmd.Properties.SUCCESS.getName(), Boolean.valueOf(result).toString()));
|
||||
|
||||
@ -99,7 +99,14 @@ public interface ConfigurationManager extends Manager {
|
||||
* @param size
|
||||
* @return ID
|
||||
*/
|
||||
DiskOfferingVO createDiskOffering(long domainId, String name, String description, int numGibibytes, String tags);
|
||||
DiskOfferingVO createDiskOffering(long userId, long domainId, String name, String description, int numGibibytes, String tags);
|
||||
|
||||
/**
|
||||
* Deletes a disk offering
|
||||
* @param userId
|
||||
* @param diskOfferingId
|
||||
*/
|
||||
boolean deleteDiskOffering(long userId, long diskOfferingId);
|
||||
|
||||
/**
|
||||
* Creates a new pod
|
||||
|
||||
@ -914,6 +914,8 @@ public class ConfigurationManagerImpl implements ConfigurationManager {
|
||||
}
|
||||
|
||||
if (_diskOfferingDao.update(diskOfferingId, diskOffering)) {
|
||||
saveConfigurationEvent(userId, null, EventTypes.EVENT_DISK_OFFERING_EDIT, "Successfully updated disk offering with name: " + diskOffering.getName() + ".", "doId=" + diskOffering.getId(), "name=" + diskOffering.getName(),
|
||||
"displayText=" + diskOffering.getDisplayText(), "diskSize=" + diskOffering.getDiskSize(),"tags=" + diskOffering.getTags());
|
||||
return _diskOfferingDao.findById(diskOfferingId);
|
||||
} else {
|
||||
return null;
|
||||
@ -924,7 +926,7 @@ public class ConfigurationManagerImpl implements ConfigurationManager {
|
||||
ServiceOfferingVO offering = _serviceOfferingDao.findById(serviceOfferingId);
|
||||
|
||||
if (_serviceOfferingDao.remove(serviceOfferingId)) {
|
||||
saveConfigurationEvent(userId, null, EventTypes.EVENT_SERVICE_OFFERING_EDIT, "Successfully deleted service offering with name: " + offering.getName(), "soId=" + serviceOfferingId, "name=" + offering.getName(),
|
||||
saveConfigurationEvent(userId, null, EventTypes.EVENT_SERVICE_OFFERING_DELETE, "Successfully deleted service offering with name: " + offering.getName(), "soId=" + serviceOfferingId, "name=" + offering.getName(),
|
||||
"displayText=" + offering.getDisplayText(), "offerHA=" + offering.getOfferHA(), "useVirtualNetwork=" + (offering.getGuestIpType() == NetworkOffering.GuestIpType.Virtualized));
|
||||
return true;
|
||||
} else {
|
||||
@ -932,11 +934,32 @@ public class ConfigurationManagerImpl implements ConfigurationManager {
|
||||
}
|
||||
}
|
||||
|
||||
public DiskOfferingVO createDiskOffering(long domainId, String name, String description, int numGibibytes, String tags) {
|
||||
public DiskOfferingVO createDiskOffering(long userId, long domainId, String name, String description, int numGibibytes, String tags) {
|
||||
long diskSize = numGibibytes * 1024;
|
||||
tags = cleanupTags(tags);
|
||||
DiskOfferingVO newDiskOffering = new DiskOfferingVO(domainId, name, description, diskSize,tags);
|
||||
return _diskOfferingDao.persist(newDiskOffering);
|
||||
|
||||
if ((newDiskOffering = _diskOfferingDao.persist(newDiskOffering)) != null) {
|
||||
saveConfigurationEvent(userId, null, EventTypes.EVENT_DISK_OFFERING_CREATE, "Successfully created new disk offering with name: "
|
||||
+ name + ".", "doId=" + newDiskOffering.getId(), "name=" + name, "diskSize=" + diskSize, "description="
|
||||
+ description, "tags=" + tags);
|
||||
return newDiskOffering;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean deleteDiskOffering(long userId, long diskOfferingId) {
|
||||
DiskOfferingVO offering = _diskOfferingDao.findById(diskOfferingId);
|
||||
|
||||
if (_diskOfferingDao.remove(diskOfferingId)) {
|
||||
saveConfigurationEvent(userId, null, EventTypes.EVENT_DISK_OFFERING_DELETE, "Successfully deleted disk offering with name: "
|
||||
+ offering.getName(), "doId=" + offering.getId(), "name=" + offering.getName(), "diskSize=" + offering.getDiskSize(),
|
||||
"description=" + offering.getDisplayText(), "tags=" + offering.getTags());
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public String changePrivateIPRange(boolean add, long podId, String startIP, String endIP) throws InvalidParameterValueException {
|
||||
|
||||
@ -142,10 +142,10 @@ public class ConfigurationServerImpl implements ConfigurationServer {
|
||||
_configMgr.createServiceOffering(User.UID_SYSTEM, "Small Instance, Virtual Networking", 1, 512, 500, "Small Instance, Virtual Networking, $0.05 per hour", false, false, true, null);
|
||||
_configMgr.createServiceOffering(User.UID_SYSTEM, "Medium Instance, Virtual Networking", 1, 1024, 1000, "Medium Instance, Virtual Networking, $0.10 per hour", false, false, true, null);
|
||||
// Save default disk offerings
|
||||
_configMgr.createDiskOffering(DomainVO.ROOT_DOMAIN, "Small", "Small Disk, 5 GB", 5, null);
|
||||
_configMgr.createDiskOffering(DomainVO.ROOT_DOMAIN, "Medium", "Medium Disk, 20 GB", 20, null);
|
||||
_configMgr.createDiskOffering(DomainVO.ROOT_DOMAIN, "Large", "Large Disk, 100 GB", 100, null);
|
||||
_configMgr.createDiskOffering(DomainVO.ROOT_DOMAIN, "Private", "Private Disk", 0, null);
|
||||
_configMgr.createDiskOffering(User.UID_SYSTEM, DomainVO.ROOT_DOMAIN, "Small", "Small Disk, 5 GB", 5, null);
|
||||
_configMgr.createDiskOffering(User.UID_SYSTEM, DomainVO.ROOT_DOMAIN, "Medium", "Medium Disk, 20 GB", 20, null);
|
||||
_configMgr.createDiskOffering(User.UID_SYSTEM, DomainVO.ROOT_DOMAIN, "Large", "Large Disk, 100 GB", 100, null);
|
||||
_configMgr.createDiskOffering(User.UID_SYSTEM, DomainVO.ROOT_DOMAIN, "Private", "Private Disk", 0, null);
|
||||
|
||||
//Add default manual snapshot policy
|
||||
SnapshotPolicyVO snapPolicy = new SnapshotPolicyVO(0L, "00", "GMT", (short)4, 0);
|
||||
|
||||
@ -6836,14 +6836,14 @@ public class ManagementServerImpl implements ManagementServer {
|
||||
}
|
||||
|
||||
@Override
|
||||
public DiskOfferingVO createDiskOffering(long domainId, String name, String description, int numGibibytes, String tags) throws InvalidParameterValueException {
|
||||
public DiskOfferingVO createDiskOffering(long userId, long domainId, String name, String description, int numGibibytes, String tags) throws InvalidParameterValueException {
|
||||
if (numGibibytes!=0 && numGibibytes < 1) {
|
||||
throw new InvalidParameterValueException("Please specify a disk size of at least 1 Gb.");
|
||||
} else if (numGibibytes > _maxVolumeSizeInGb) {
|
||||
throw new InvalidParameterValueException("The maximum size for a disk is " + _maxVolumeSizeInGb + " Gb.");
|
||||
}
|
||||
|
||||
return _configMgr.createDiskOffering(domainId, name, description, numGibibytes, tags);
|
||||
return _configMgr.createDiskOffering(userId, domainId, name, description, numGibibytes, tags);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -6852,8 +6852,8 @@ public class ManagementServerImpl implements ManagementServer {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean deleteDiskOffering(long id) {
|
||||
return _diskOfferingDao.remove(Long.valueOf(id));
|
||||
public boolean deleteDiskOffering(long userId, long id) {
|
||||
return _configMgr.deleteDiskOffering(userId, id);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user