Enhance UpdateDiskOfferingCmd (#4409)

This commit is contained in:
Gabriel Beims Bräscher 2020-10-24 08:00:11 -03:00 committed by GitHub
parent ee5094b77f
commit f4f35a8995
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 219 additions and 83 deletions

View File

@ -85,6 +85,44 @@ public class UpdateDiskOfferingCmd extends BaseCmd {
since = "4.15")
private String tags;
@Parameter(name = ApiConstants.BYTES_READ_RATE, type = CommandType.LONG, description = "bytes read rate of the disk offering", since = "4.15")
private Long bytesReadRate;
@Parameter(name = ApiConstants.BYTES_READ_RATE_MAX, type = CommandType.LONG, description = "burst bytes read rate of the disk offering", since = "4.15")
private Long bytesReadRateMax;
@Parameter(name = ApiConstants.BYTES_READ_RATE_MAX_LENGTH, type = CommandType.LONG, description = "length (in seconds) of the burst", since = "4.15")
private Long bytesReadRateMaxLength;
@Parameter(name = ApiConstants.BYTES_WRITE_RATE, type = CommandType.LONG, description = "bytes write rate of the disk offering", since = "4.15")
private Long bytesWriteRate;
@Parameter(name = ApiConstants.BYTES_WRITE_RATE_MAX, type = CommandType.LONG, description = "burst bytes write rate of the disk offering", since = "4.15")
private Long bytesWriteRateMax;
@Parameter(name = ApiConstants.BYTES_WRITE_RATE_MAX_LENGTH, type = CommandType.LONG, description = "length (in seconds) of the burst", since = "4.15")
private Long bytesWriteRateMaxLength;
@Parameter(name = ApiConstants.IOPS_READ_RATE, type = CommandType.LONG, description = "io requests read rate of the disk offering", since = "4.15")
private Long iopsReadRate;
@Parameter(name = ApiConstants.IOPS_READ_RATE_MAX, type = CommandType.LONG, description = "burst requests read rate of the disk offering", since = "4.15")
private Long iopsReadRateMax;
@Parameter(name = ApiConstants.IOPS_READ_RATE_MAX_LENGTH, type = CommandType.LONG, description = "length (in seconds) of the burst", since = "4.15")
private Long iopsReadRateMaxLength;
@Parameter(name = ApiConstants.IOPS_WRITE_RATE, type = CommandType.LONG, description = "io requests write rate of the disk offering", since = "4.15")
private Long iopsWriteRate;
@Parameter(name = ApiConstants.IOPS_WRITE_RATE_MAX, type = CommandType.LONG, description = "burst io requests write rate of the disk offering", since = "4.15")
private Long iopsWriteRateMax;
@Parameter(name = ApiConstants.IOPS_WRITE_RATE_MAX_LENGTH, type = CommandType.LONG, description = "length (in seconds) of the burst", since = "4.15")
private Long iopsWriteRateMaxLength;
@Parameter(name = ApiConstants.CACHE_MODE, type = CommandType.STRING, description = "the cache mode to use for this disk offering", since = "4.15")
private String cacheMode;
/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
@ -174,7 +212,59 @@ public class UpdateDiskOfferingCmd extends BaseCmd {
return tags;
}
/////////////////////////////////////////////////////
public String getCacheMode() {
return cacheMode;
}
public Long getBytesReadRate() {
return bytesReadRate;
}
public Long getBytesReadRateMax() {
return bytesReadRateMax;
}
public Long getBytesReadRateMaxLength() {
return bytesReadRateMaxLength;
}
public Long getBytesWriteRate() {
return bytesWriteRate;
}
public Long getBytesWriteRateMax() {
return bytesWriteRateMax;
}
public Long getBytesWriteRateMaxLength() {
return bytesWriteRateMaxLength;
}
public Long getIopsReadRate() {
return iopsReadRate;
}
public Long getIopsReadRateMax() {
return iopsReadRateMax;
}
public Long getIopsReadRateMaxLength() {
return iopsReadRateMaxLength;
}
public Long getIopsWriteRate() {
return iopsWriteRate;
}
public Long getIopsWriteRateMax() {
return iopsWriteRateMax;
}
public Long getIopsWriteRateMaxLength() {
return iopsWriteRateMaxLength;
}
/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////

View File

@ -2530,42 +2530,9 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
offering.setMinIops(minIops);
offering.setMaxIops(maxIops);
if (bytesReadRate != null && bytesReadRate > 0) {
offering.setBytesReadRate(bytesReadRate);
}
if (bytesReadRateMax != null && bytesReadRateMax > 0) {
offering.setBytesReadRateMax(bytesReadRateMax);
}
if (bytesReadRateMaxLength != null && bytesReadRateMaxLength > 0) {
offering.setBytesReadRateMaxLength(bytesReadRateMaxLength);
}
if (bytesWriteRate != null && bytesWriteRate > 0) {
offering.setBytesWriteRate(bytesWriteRate);
}
if (bytesWriteRateMax != null && bytesWriteRateMax > 0) {
offering.setBytesWriteRateMax(bytesWriteRateMax);
}
if (bytesWriteRateMaxLength != null && bytesWriteRateMaxLength > 0) {
offering.setBytesWriteRateMaxLength(bytesWriteRateMaxLength);
}
if (iopsReadRate != null && iopsReadRate > 0) {
offering.setIopsReadRate(iopsReadRate);
}
if (iopsReadRateMax != null && iopsReadRateMax > 0) {
offering.setIopsReadRateMax(iopsReadRateMax);
}
if (iopsReadRateMaxLength != null && iopsReadRateMaxLength > 0) {
offering.setIopsReadRateMaxLength(iopsReadRateMaxLength);
}
if (iopsWriteRate != null && iopsWriteRate > 0) {
offering.setIopsWriteRate(iopsWriteRate);
}
if (iopsWriteRateMax != null && iopsWriteRateMax > 0) {
offering.setIopsWriteRateMax(iopsWriteRateMax);
}
if (iopsWriteRateMaxLength != null && iopsWriteRateMaxLength > 0) {
offering.setIopsWriteRateMaxLength(iopsWriteRateMaxLength);
}
setBytesRate(offering, bytesReadRate, bytesReadRateMax, bytesReadRateMaxLength, bytesWriteRate, bytesWriteRateMax, bytesWriteRateMaxLength);
setIopsRate(offering, iopsReadRate, iopsReadRateMax, iopsReadRateMaxLength, iopsWriteRate, iopsWriteRateMax, iopsWriteRateMaxLength);
if(cacheMode != null) {
offering.setCacheMode(DiskOffering.DiskCacheMode.valueOf(cacheMode.toUpperCase()));
}
@ -2631,6 +2598,48 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
}
}
private void setIopsRate(DiskOffering offering, Long iopsReadRate, Long iopsReadRateMax, Long iopsReadRateMaxLength, Long iopsWriteRate, Long iopsWriteRateMax, Long iopsWriteRateMaxLength) {
if (iopsReadRate != null && iopsReadRate > 0) {
offering.setIopsReadRate(iopsReadRate);
}
if (iopsReadRateMax != null && iopsReadRateMax > 0) {
offering.setIopsReadRateMax(iopsReadRateMax);
}
if (iopsReadRateMaxLength != null && iopsReadRateMaxLength > 0) {
offering.setIopsReadRateMaxLength(iopsReadRateMaxLength);
}
if (iopsWriteRate != null && iopsWriteRate > 0) {
offering.setIopsWriteRate(iopsWriteRate);
}
if (iopsWriteRateMax != null && iopsWriteRateMax > 0) {
offering.setIopsWriteRateMax(iopsWriteRateMax);
}
if (iopsWriteRateMaxLength != null && iopsWriteRateMaxLength > 0) {
offering.setIopsWriteRateMaxLength(iopsWriteRateMaxLength);
}
}
private void setBytesRate(DiskOffering offering, Long bytesReadRate, Long bytesReadRateMax, Long bytesReadRateMaxLength, Long bytesWriteRate, Long bytesWriteRateMax, Long bytesWriteRateMaxLength) {
if (bytesReadRate != null && bytesReadRate > 0) {
offering.setBytesReadRate(bytesReadRate);
}
if (bytesReadRateMax != null && bytesReadRateMax > 0) {
offering.setBytesReadRateMax(bytesReadRateMax);
}
if (bytesReadRateMaxLength != null && bytesReadRateMaxLength > 0) {
offering.setBytesReadRateMaxLength(bytesReadRateMaxLength);
}
if (bytesWriteRate != null && bytesWriteRate > 0) {
offering.setBytesWriteRate(bytesWriteRate);
}
if (bytesWriteRateMax != null && bytesWriteRateMax > 0) {
offering.setBytesWriteRateMax(bytesWriteRateMax);
}
if (bytesWriteRateMaxLength != null && bytesWriteRateMaxLength > 0) {
offering.setBytesWriteRateMaxLength(bytesWriteRateMaxLength);
}
}
@Override
@ActionEvent(eventType = EventTypes.EVENT_SERVICE_OFFERING_EDIT, eventDescription = "updating service offering")
public ServiceOffering updateServiceOffering(final UpdateServiceOfferingCmd cmd) {
@ -2897,42 +2906,9 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
newDiskOffering.setUseLocalStorage(localStorageRequired);
newDiskOffering.setDisplayOffering(isDisplayOfferingEnabled);
if (bytesReadRate != null && bytesReadRate > 0) {
newDiskOffering.setBytesReadRate(bytesReadRate);
}
if (bytesReadRateMax != null && bytesReadRateMax > 0) {
newDiskOffering.setBytesReadRateMax(bytesReadRateMax);
}
if (bytesReadRateMaxLength != null && bytesReadRateMaxLength > 0) {
newDiskOffering.setBytesReadRateMaxLength(bytesReadRateMaxLength);
}
if (bytesWriteRate != null && bytesWriteRate > 0) {
newDiskOffering.setBytesWriteRate(bytesWriteRate);
}
if (bytesWriteRateMax != null && bytesWriteRateMax > 0) {
newDiskOffering.setBytesWriteRateMax(bytesWriteRateMax);
}
if (bytesWriteRateMaxLength != null && bytesWriteRateMaxLength > 0) {
newDiskOffering.setBytesWriteRateMaxLength(bytesWriteRateMaxLength);
}
if (iopsReadRate != null && iopsReadRate > 0) {
newDiskOffering.setIopsReadRate(iopsReadRate);
}
if (iopsReadRateMax != null && iopsReadRateMax > 0) {
newDiskOffering.setIopsReadRateMax(iopsReadRateMax);
}
if (iopsReadRateMaxLength != null && iopsReadRateMaxLength > 0) {
newDiskOffering.setIopsReadRateMaxLength(iopsReadRateMaxLength);
}
if (iopsWriteRate != null && iopsWriteRate > 0) {
newDiskOffering.setIopsWriteRate(iopsWriteRate);
}
if (iopsWriteRateMax != null && iopsWriteRateMax > 0) {
newDiskOffering.setIopsWriteRateMax(iopsWriteRateMax);
}
if (iopsWriteRateMaxLength != null && iopsWriteRateMaxLength > 0) {
newDiskOffering.setIopsWriteRateMaxLength(iopsWriteRateMaxLength);
}
setBytesRate(newDiskOffering, bytesReadRate, bytesReadRateMax, bytesReadRateMaxLength, bytesWriteRate, bytesWriteRateMax, bytesWriteRateMaxLength);
setIopsRate(newDiskOffering, iopsReadRate, iopsReadRateMax, iopsReadRateMaxLength, iopsWriteRate, iopsWriteRateMax, iopsWriteRateMaxLength);
if (cacheMode != null) {
newDiskOffering.setCacheMode(DiskOffering.DiskCacheMode.valueOf(cacheMode.toUpperCase()));
}
@ -3111,6 +3087,20 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
final List<Long> zoneIds = cmd.getZoneIds();
final String tags = cmd.getTags();
Long bytesReadRate = cmd.getBytesReadRate();
Long bytesReadRateMax = cmd.getBytesReadRateMax();
Long bytesReadRateMaxLength = cmd.getBytesReadRateMaxLength();
Long bytesWriteRate = cmd.getBytesWriteRate();
Long bytesWriteRateMax = cmd.getBytesWriteRateMax();
Long bytesWriteRateMaxLength = cmd.getBytesWriteRateMaxLength();
Long iopsReadRate = cmd.getIopsReadRate();
Long iopsReadRateMax = cmd.getIopsReadRateMax();
Long iopsReadRateMaxLength = cmd.getIopsReadRateMaxLength();
Long iopsWriteRate = cmd.getIopsWriteRate();
Long iopsWriteRateMax = cmd.getIopsWriteRateMax();
Long iopsWriteRateMaxLength = cmd.getIopsWriteRateMaxLength();
String cacheMode = cmd.getCacheMode();
// Check if diskOffering exists
final DiskOffering diskOfferingHandle = _entityMgr.findById(DiskOffering.class, diskOfferingId);
if (diskOfferingHandle == null) {
@ -3191,7 +3181,10 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
throw new InvalidParameterValueException(String.format("Unable to update disk offering: %s by id user: %s because it is not root-admin or domain-admin", diskOfferingHandle.getUuid(), user.getUuid()));
}
final boolean updateNeeded = shouldUpdateDiskOffering(name, displayText, sortKey, displayDiskOffering, tags);
boolean updateNeeded = shouldUpdateDiskOffering(name, displayText, sortKey, displayDiskOffering, tags, cacheMode) ||
shouldUpdateIopsRateParameters(iopsReadRate, iopsReadRateMax, iopsReadRateMaxLength, iopsWriteRate, iopsWriteRateMax, iopsWriteRateMaxLength) ||
shouldUpdateBytesRateParameters(bytesReadRate, bytesReadRateMax, bytesReadRateMaxLength, bytesWriteRate, bytesWriteRateMax, bytesWriteRateMaxLength);
final boolean detailsUpdateNeeded = !filteredDomainIds.equals(existingDomainIds) || !filteredZoneIds.equals(existingZoneIds);
if (!updateNeeded && !detailsUpdateNeeded) {
return _diskOfferingDao.findById(diskOfferingId);
@ -3217,6 +3210,20 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
updateDiskOfferingTagsIfIsNotNull(tags, diskOffering);
validateMaxRateEqualsOrGreater(iopsReadRate, iopsReadRateMax, IOPS_READ_RATE);
validateMaxRateEqualsOrGreater(iopsWriteRate, iopsWriteRateMax, IOPS_WRITE_RATE);
validateMaxRateEqualsOrGreater(bytesReadRate, bytesReadRateMax, BYTES_READ_RATE);
validateMaxRateEqualsOrGreater(bytesWriteRate, bytesWriteRateMax, BYTES_WRITE_RATE);
validateMaximumIopsAndBytesLength(iopsReadRateMaxLength, iopsWriteRateMaxLength, bytesReadRateMaxLength, bytesWriteRateMaxLength);
setBytesRate(diskOffering, bytesReadRate, bytesReadRateMax, bytesReadRateMaxLength, bytesWriteRate, bytesWriteRateMax, bytesWriteRateMaxLength);
setIopsRate(diskOffering, iopsReadRate, iopsReadRateMax, iopsReadRateMaxLength, iopsWriteRate, iopsWriteRateMax, iopsWriteRateMaxLength);
if (cacheMode != null) {
validateCacheMode(cacheMode);
diskOffering.setCacheMode(DiskOffering.DiskCacheMode.valueOf(cacheMode.toUpperCase()));
}
if (updateNeeded && !_diskOfferingDao.update(diskOfferingId, diskOffering)) {
return null;
}
@ -3273,8 +3280,17 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
* Check if it needs to update any parameter when updateDiskoffering is called
* Verify if name or displayText are not blank, tags is not null, sortkey and displayDiskOffering is not null
*/
protected boolean shouldUpdateDiskOffering(String name, String displayText, Integer sortKey, Boolean displayDiskOffering, String tags) {
return StringUtils.isNotBlank(name) || StringUtils.isNotBlank(displayText) || tags != null || sortKey != null || displayDiskOffering != null;
protected boolean shouldUpdateDiskOffering(String name, String displayText, Integer sortKey, Boolean displayDiskOffering, String tags, String cacheMode) {
return StringUtils.isNotBlank(name) || StringUtils.isNotBlank(displayText) || tags != null || sortKey != null || displayDiskOffering != null || StringUtils.isNotBlank(cacheMode);
}
protected boolean shouldUpdateBytesRateParameters(Long bytesReadRate, Long bytesReadRateMax, Long bytesReadRateMaxLength, Long bytesWriteRate, Long bytesWriteRateMax, Long bytesWriteRateMaxLength) {
return bytesReadRate != null || bytesReadRateMax != null || bytesReadRateMaxLength != null || bytesWriteRate != null ||
bytesWriteRateMax != null || bytesWriteRateMaxLength != null;
}
protected boolean shouldUpdateIopsRateParameters(Long iopsReadRate, Long iopsReadRateMax, Long iopsReadRateMaxLength, Long iopsWriteRate, Long iopsWriteRateMax, Long iopsWriteRateMaxLength) {
return iopsReadRate != null || iopsReadRateMax != null || iopsReadRateMaxLength != null || iopsWriteRate != null || iopsWriteRateMax != null || iopsWriteRateMaxLength != null;
}
@Override

View File

@ -946,17 +946,47 @@ public class ConfigurationManagerTest {
@Test
public void shouldUpdateDiskOfferingTests(){
Assert.assertTrue(configurationMgr.shouldUpdateDiskOffering(Mockito.anyString(), Mockito.anyString(), Mockito.anyInt(), Mockito.anyBoolean(), Mockito.anyString()));
Assert.assertTrue(configurationMgr.shouldUpdateDiskOffering(Mockito.anyString(), nullable(String.class), nullable(Integer.class), nullable(Boolean.class), nullable(String.class)));
Assert.assertTrue(configurationMgr.shouldUpdateDiskOffering(nullable(String.class), Mockito.anyString(), nullable(Integer.class), nullable(Boolean.class), nullable(String.class)));
Assert.assertTrue(configurationMgr.shouldUpdateDiskOffering(nullable(String.class), nullable(String.class), Mockito.anyInt(), nullable(Boolean.class), nullable(String.class)));
Assert.assertTrue(configurationMgr.shouldUpdateDiskOffering(nullable(String.class), nullable(String.class), nullable(int.class), Mockito.anyBoolean(), nullable(String.class)));
Assert.assertTrue(configurationMgr.shouldUpdateDiskOffering(nullable(String.class), nullable(String.class), nullable(int.class), nullable(Boolean.class), Mockito.anyString()));
Assert.assertTrue(configurationMgr.shouldUpdateDiskOffering(Mockito.anyString(), Mockito.anyString(), Mockito.anyInt(), Mockito.anyBoolean(), Mockito.anyString(), Mockito.anyString()));
Assert.assertTrue(configurationMgr.shouldUpdateDiskOffering(Mockito.anyString(), nullable(String.class), nullable(Integer.class), nullable(Boolean.class), nullable(String.class), nullable(String.class)));
Assert.assertTrue(configurationMgr.shouldUpdateDiskOffering(nullable(String.class), Mockito.anyString(), nullable(Integer.class), nullable(Boolean.class), nullable(String.class), nullable(String.class)));
Assert.assertTrue(configurationMgr.shouldUpdateDiskOffering(nullable(String.class), nullable(String.class), Mockito.anyInt(), nullable(Boolean.class), nullable(String.class), nullable(String.class)));
Assert.assertTrue(configurationMgr.shouldUpdateDiskOffering(nullable(String.class), nullable(String.class), nullable(int.class), Mockito.anyBoolean(), nullable(String.class), nullable(String.class)));
Assert.assertTrue(configurationMgr.shouldUpdateDiskOffering(nullable(String.class), nullable(String.class), nullable(int.class), nullable(Boolean.class), Mockito.anyString(), Mockito.anyString()));
}
@Test
public void shouldUpdateDiskOfferingTestFalse(){
Assert.assertFalse(configurationMgr.shouldUpdateDiskOffering(null, null, null, null, null));
Assert.assertFalse(configurationMgr.shouldUpdateDiskOffering(null, null, null, null, null, null));
}
@Test
public void shouldUpdateIopsRateParametersTestFalse() {
Assert.assertFalse(configurationMgr.shouldUpdateIopsRateParameters(null, null, null, null, null, null));
}
@Test
public void shouldUpdateIopsRateParametersTests(){
Assert.assertTrue(configurationMgr.shouldUpdateIopsRateParameters(Mockito.anyLong(), Mockito.anyLong(), Mockito.anyLong(), Mockito.anyLong(), Mockito.anyLong(), Mockito.anyLong()));
Assert.assertTrue(configurationMgr.shouldUpdateIopsRateParameters(nullable(Long.class), Mockito.anyLong(), nullable(Long.class), nullable(Long.class), nullable(Long.class), nullable(Long.class)));
Assert.assertTrue(configurationMgr.shouldUpdateIopsRateParameters(nullable(Long.class), nullable(Long.class), Mockito.anyLong(), nullable(Long.class), nullable(Long.class), nullable(Long.class)));
Assert.assertTrue(configurationMgr.shouldUpdateIopsRateParameters(nullable(Long.class), nullable(Long.class), nullable(Long.class), Mockito.anyLong(), nullable(Long.class), nullable(Long.class)));
Assert.assertTrue(configurationMgr.shouldUpdateIopsRateParameters(nullable(Long.class), nullable(Long.class), nullable(Long.class), nullable(Long.class), Mockito.anyLong(), nullable(Long.class)));
Assert.assertTrue(configurationMgr.shouldUpdateIopsRateParameters(nullable(Long.class), nullable(Long.class), nullable(Long.class), nullable(Long.class), nullable(Long.class), Mockito.anyLong()));
}
@Test
public void shouldUpdateBytesRateParametersTestFalse() {
Assert.assertFalse(configurationMgr.shouldUpdateBytesRateParameters(null, null, null, null, null, null));
}
@Test
public void shouldUpdateBytesRateParametersTests(){
Assert.assertTrue(configurationMgr.shouldUpdateBytesRateParameters(Mockito.anyLong(), Mockito.anyLong(), Mockito.anyLong(), Mockito.anyLong(), Mockito.anyLong(), Mockito.anyLong()));
Assert.assertTrue(configurationMgr.shouldUpdateBytesRateParameters(nullable(Long.class), Mockito.anyLong(), nullable(Long.class), nullable(Long.class), nullable(Long.class), nullable(Long.class)));
Assert.assertTrue(configurationMgr.shouldUpdateBytesRateParameters(nullable(Long.class), nullable(Long.class), Mockito.anyLong(), nullable(Long.class), nullable(Long.class), nullable(Long.class)));
Assert.assertTrue(configurationMgr.shouldUpdateBytesRateParameters(nullable(Long.class), nullable(Long.class), nullable(Long.class), Mockito.anyLong(), nullable(Long.class), nullable(Long.class)));
Assert.assertTrue(configurationMgr.shouldUpdateBytesRateParameters(nullable(Long.class), nullable(Long.class), nullable(Long.class), nullable(Long.class), Mockito.anyLong(), nullable(Long.class)));
Assert.assertTrue(configurationMgr.shouldUpdateBytesRateParameters(nullable(Long.class), nullable(Long.class), nullable(Long.class), nullable(Long.class), nullable(Long.class), Mockito.anyLong()));
}
@Test