Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

package org.apache.cloudstack.quota.activationrule.presetvariables;

public class DiskOffering extends GenericPresetVariable {

@PresetVariableDefinition(description = "A long informing the bytes read rate of the disk offering.")
private Long bytesReadRate;

@PresetVariableDefinition(description = "A long informing the burst bytes read rate of the disk offering.")
private Long bytesReadBurst;

@PresetVariableDefinition(description = "The length (in seconds) of the bytes read burst.")
private Long bytesReadBurstLength;

@PresetVariableDefinition(description = "A long informing the bytes write rate of the disk offering.")
private Long bytesWriteRate;

@PresetVariableDefinition(description = "A long informing the burst bytes write rate of the disk offering.")
private Long bytesWriteBurst;

@PresetVariableDefinition(description = "The length (in seconds) of the bytes write burst.")
private Long bytesWriteBurstLength;

@PresetVariableDefinition(description = "A long informing the I/O requests read rate of the disk offering.")
private Long iopsReadRate;

@PresetVariableDefinition(description = "A long informing the burst I/O requests read rate of the disk offering.")
private Long iopsReadBurst;

@PresetVariableDefinition(description = "The length (in seconds) of the IOPS read burst.")
private Long iopsReadBurstLength;

@PresetVariableDefinition(description = "A long informing the I/O requests write rate of the disk offering.")
private Long iopsWriteRate;

@PresetVariableDefinition(description = "A long informing the burst I/O requests write rate of the disk offering.")
private Long iopsWriteBurst;

@PresetVariableDefinition(description = "The length (in seconds) of the IOPS write burst.")
private Long iopsWriteBurstLength;

public Long getBytesReadRate() {
return bytesReadRate;
}

Check warning on line 60 in framework/quota/src/main/java/org/apache/cloudstack/quota/activationrule/presetvariables/DiskOffering.java

View check run for this annotation

Codecov / codecov/patch

framework/quota/src/main/java/org/apache/cloudstack/quota/activationrule/presetvariables/DiskOffering.java#L58-L60

Added lines #L58 - L60 were not covered by tests

public void setBytesReadRate(Long bytesReadRate) {
this.bytesReadRate = bytesReadRate;
fieldNamesToIncludeInToString.add("bytesReadRate");
}

public Long getBytesReadBurst() {
return bytesReadBurst;
}

Check warning on line 69 in framework/quota/src/main/java/org/apache/cloudstack/quota/activationrule/presetvariables/DiskOffering.java

View check run for this annotation

Codecov / codecov/patch

framework/quota/src/main/java/org/apache/cloudstack/quota/activationrule/presetvariables/DiskOffering.java#L67-L69

Added lines #L67 - L69 were not covered by tests

public void setBytesReadBurst(Long bytesReadBurst) {
this.bytesReadBurst = bytesReadBurst;
fieldNamesToIncludeInToString.add("bytesReadBurst");
}

public Long getBytesReadBurstLength() {
return bytesReadBurstLength;
}

Check warning on line 78 in framework/quota/src/main/java/org/apache/cloudstack/quota/activationrule/presetvariables/DiskOffering.java

View check run for this annotation

Codecov / codecov/patch

framework/quota/src/main/java/org/apache/cloudstack/quota/activationrule/presetvariables/DiskOffering.java#L76-L78

Added lines #L76 - L78 were not covered by tests

public void setBytesReadBurstLength(Long bytesReadBurstLength) {
this.bytesReadBurstLength = bytesReadBurstLength;
fieldNamesToIncludeInToString.add("bytesReadBurstLength");
}

public Long getBytesWriteRate() {
return bytesWriteRate;
}

Check warning on line 87 in framework/quota/src/main/java/org/apache/cloudstack/quota/activationrule/presetvariables/DiskOffering.java

View check run for this annotation

Codecov / codecov/patch

framework/quota/src/main/java/org/apache/cloudstack/quota/activationrule/presetvariables/DiskOffering.java#L85-L87

Added lines #L85 - L87 were not covered by tests

public void setBytesWriteRate(Long bytesWriteRate) {
this.bytesWriteRate = bytesWriteRate;
fieldNamesToIncludeInToString.add("bytesWriteRate");
}

public Long getBytesWriteBurst() {
return bytesWriteBurst;
}

Check warning on line 96 in framework/quota/src/main/java/org/apache/cloudstack/quota/activationrule/presetvariables/DiskOffering.java

View check run for this annotation

Codecov / codecov/patch

framework/quota/src/main/java/org/apache/cloudstack/quota/activationrule/presetvariables/DiskOffering.java#L94-L96

Added lines #L94 - L96 were not covered by tests

public void setBytesWriteBurst(Long bytesWriteBurst) {
this.bytesWriteBurst = bytesWriteBurst;
fieldNamesToIncludeInToString.add("bytesWriteBurst");
}

public Long getBytesWriteBurstLength() {
return bytesWriteBurstLength;
}

Check warning on line 105 in framework/quota/src/main/java/org/apache/cloudstack/quota/activationrule/presetvariables/DiskOffering.java

View check run for this annotation

Codecov / codecov/patch

framework/quota/src/main/java/org/apache/cloudstack/quota/activationrule/presetvariables/DiskOffering.java#L103-L105

Added lines #L103 - L105 were not covered by tests

public void setBytesWriteBurstLength(Long bytesWriteBurstLength) {
this.bytesWriteBurstLength = bytesWriteBurstLength;
fieldNamesToIncludeInToString.add("bytesWriteBurstLength");
}

public Long getIopsReadRate() {
return iopsReadRate;
}

Check warning on line 114 in framework/quota/src/main/java/org/apache/cloudstack/quota/activationrule/presetvariables/DiskOffering.java

View check run for this annotation

Codecov / codecov/patch

framework/quota/src/main/java/org/apache/cloudstack/quota/activationrule/presetvariables/DiskOffering.java#L112-L114

Added lines #L112 - L114 were not covered by tests

public void setIopsReadRate(Long iopsReadRate) {
this.iopsReadRate = iopsReadRate;
fieldNamesToIncludeInToString.add("iopsReadRate");
}

public Long getIopsReadBurst() {
return iopsReadBurst;
}

Check warning on line 123 in framework/quota/src/main/java/org/apache/cloudstack/quota/activationrule/presetvariables/DiskOffering.java

View check run for this annotation

Codecov / codecov/patch

framework/quota/src/main/java/org/apache/cloudstack/quota/activationrule/presetvariables/DiskOffering.java#L121-L123

Added lines #L121 - L123 were not covered by tests

public void setIopsReadBurst(Long iopsReadBurst) {
this.iopsReadBurst = iopsReadBurst;
fieldNamesToIncludeInToString.add("iopsReadBurst");
}

public Long getIopsReadBurstLength() {
return iopsReadBurstLength;
}

Check warning on line 132 in framework/quota/src/main/java/org/apache/cloudstack/quota/activationrule/presetvariables/DiskOffering.java

View check run for this annotation

Codecov / codecov/patch

framework/quota/src/main/java/org/apache/cloudstack/quota/activationrule/presetvariables/DiskOffering.java#L130-L132

Added lines #L130 - L132 were not covered by tests

public void setIopsReadBurstLength(Long iopsReadBurstLength) {
this.iopsReadBurstLength = iopsReadBurstLength;
fieldNamesToIncludeInToString.add("iopsReadBurstLength");
}

public Long getIopsWriteRate() {
return iopsWriteRate;
}

Check warning on line 141 in framework/quota/src/main/java/org/apache/cloudstack/quota/activationrule/presetvariables/DiskOffering.java

View check run for this annotation

Codecov / codecov/patch

framework/quota/src/main/java/org/apache/cloudstack/quota/activationrule/presetvariables/DiskOffering.java#L139-L141

Added lines #L139 - L141 were not covered by tests

public void setIopsWriteRate(Long iopsWriteRate) {
this.iopsWriteRate = iopsWriteRate;
fieldNamesToIncludeInToString.add("iopsWriteRate");
}

public Long getIopsWriteBurst() {
return iopsWriteBurst;
}

Check warning on line 150 in framework/quota/src/main/java/org/apache/cloudstack/quota/activationrule/presetvariables/DiskOffering.java

View check run for this annotation

Codecov / codecov/patch

framework/quota/src/main/java/org/apache/cloudstack/quota/activationrule/presetvariables/DiskOffering.java#L148-L150

Added lines #L148 - L150 were not covered by tests

public void setIopsWriteBurst(Long iopsWriteBurst) {
this.iopsWriteBurst = iopsWriteBurst;
fieldNamesToIncludeInToString.add("iopsWriteBurst");
}

public Long getIopsWriteBurstLength() {
return iopsWriteBurstLength;
}

Check warning on line 159 in framework/quota/src/main/java/org/apache/cloudstack/quota/activationrule/presetvariables/DiskOffering.java

View check run for this annotation

Codecov / codecov/patch

framework/quota/src/main/java/org/apache/cloudstack/quota/activationrule/presetvariables/DiskOffering.java#L157-L159

Added lines #L157 - L159 were not covered by tests

public void setIopsWriteBurstLength(Long iopsWriteBurstLength) {
this.iopsWriteBurstLength = iopsWriteBurstLength;
fieldNamesToIncludeInToString.add("iopsWriteBurstLength");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,7 @@ protected void loadPresetVariableValueForVolume(UsageVO usageRecord, Value value
value.setId(volumeVo.getUuid());
value.setName(volumeVo.getName());
value.setProvisioningType(volumeVo.getProvisioningType());
value.setVolumeType(volumeVo.getVolumeType());

Long poolId = volumeVo.getPoolId();
if (poolId == null) {
Expand All @@ -510,13 +511,25 @@ protected void loadPresetVariableValueForVolume(UsageVO usageRecord, Value value
}
}

protected GenericPresetVariable getPresetVariableValueDiskOffering(Long diskOfferingId) {
protected DiskOffering getPresetVariableValueDiskOffering(Long diskOfferingId) {
DiskOfferingVO diskOfferingVo = diskOfferingDao.findByIdIncludingRemoved(diskOfferingId);
validateIfObjectIsNull(diskOfferingVo, diskOfferingId, "disk offering");

GenericPresetVariable diskOffering = new GenericPresetVariable();
DiskOffering diskOffering = new DiskOffering();
diskOffering.setId(diskOfferingVo.getUuid());
diskOffering.setName(diskOfferingVo.getName());
diskOffering.setBytesReadRate(diskOfferingVo.getBytesReadRate());
diskOffering.setBytesReadBurst(diskOfferingVo.getBytesReadRateMax());
diskOffering.setBytesReadBurstLength(diskOfferingVo.getBytesReadRateMaxLength());
diskOffering.setBytesWriteRate(diskOfferingVo.getBytesWriteRate());
diskOffering.setBytesWriteBurst(diskOfferingVo.getBytesWriteRateMax());
diskOffering.setBytesWriteBurstLength(diskOfferingVo.getBytesWriteRateMaxLength());
diskOffering.setIopsReadRate(diskOfferingVo.getIopsReadRate());
diskOffering.setIopsReadBurst(diskOfferingVo.getIopsReadRateMax());
diskOffering.setIopsReadBurstLength(diskOfferingVo.getIopsReadRateMaxLength());
diskOffering.setIopsWriteRate(diskOfferingVo.getIopsWriteRate());
diskOffering.setIopsWriteBurst(diskOfferingVo.getIopsWriteRateMax());
diskOffering.setIopsWriteBurstLength(diskOfferingVo.getIopsWriteRateMaxLength());

return diskOffering;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import com.cloud.storage.Snapshot;
import com.cloud.storage.Storage.ProvisioningType;
import com.cloud.storage.Volume;
import com.cloud.vm.snapshot.VMSnapshot;
import org.apache.cloudstack.quota.constant.QuotaTypes;

Expand Down Expand Up @@ -75,7 +76,7 @@ public class Value extends GenericPresetVariable {
private GenericPresetVariable template;

@PresetVariableDefinition(description = "Disk offering of the volume.", supportedTypes = {QuotaTypes.VOLUME})
private GenericPresetVariable diskOffering;
private DiskOffering diskOffering;

@PresetVariableDefinition(description = "Storage where the volume or snapshot is. While handling with snapshots, this value can be from the primary storage if the global " +
"setting 'snapshot.backup.to.secondary' is false, otherwise it will be from secondary storage.", supportedTypes = {QuotaTypes.VOLUME, QuotaTypes.SNAPSHOT})
Expand All @@ -93,6 +94,10 @@ public class Value extends GenericPresetVariable {

@PresetVariableDefinition(description = "The volume format. Values can be: RAW, VHD, VHDX, OVA and QCOW2.", supportedTypes = {QuotaTypes.VOLUME, QuotaTypes.VOLUME_SECONDARY})
private String volumeFormat;

@PresetVariableDefinition(description = "The volume type. Values can be: UNKNOWN, ROOT, SWAP, DATADISK and ISO.", supportedTypes = {QuotaTypes.VOLUME})
private Volume.Type volumeType;

private String state;

public Host getHost() {
Expand Down Expand Up @@ -194,11 +199,11 @@ public void setTemplate(GenericPresetVariable template) {
fieldNamesToIncludeInToString.add("template");
}

public GenericPresetVariable getDiskOffering() {
public DiskOffering getDiskOffering() {
return diskOffering;
}

public void setDiskOffering(GenericPresetVariable diskOffering) {
public void setDiskOffering(DiskOffering diskOffering) {
this.diskOffering = diskOffering;
fieldNamesToIncludeInToString.add("diskOffering");
}
Expand Down Expand Up @@ -257,6 +262,15 @@ public String getVolumeFormat() {
return volumeFormat;
}

public Volume.Type getVolumeType() {
return volumeType;
}

public void setVolumeType(Volume.Type volumeType) {
this.volumeType = volumeType;
fieldNamesToIncludeInToString.add("volumeType");
}

public String getState() {
return state;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
import com.cloud.storage.Storage.ImageFormat;
import com.cloud.storage.Storage.ProvisioningType;
import com.cloud.storage.VMTemplateVO;
import com.cloud.storage.Volume;
import com.cloud.storage.VolumeVO;
import com.cloud.storage.dao.DiskOfferingDao;
import com.cloud.storage.dao.GuestOSDao;
Expand Down Expand Up @@ -208,14 +209,15 @@ private Value getValueForTests() {
value.setComputeOffering(getComputeOfferingForTests());
value.setTags(Collections.singletonMap("tag1", "value1"));
value.setTemplate(getGenericPresetVariableForTests());
value.setDiskOffering(getGenericPresetVariableForTests());
value.setDiskOffering(getDiskOfferingForTests());
value.setProvisioningType(ProvisioningType.THIN);
value.setStorage(getStorageForTests());
value.setSize(ByteScaleUtils.GiB);
value.setSnapshotType(Snapshot.Type.HOURLY);
value.setTag("tag_test");
value.setVmSnapshotType(VMSnapshot.Type.Disk);
value.setComputingResources(getComputingResourcesForTests());
value.setVolumeType(Volume.Type.DATADISK);
return value;
}

Expand Down Expand Up @@ -308,6 +310,13 @@ private BackupOffering getBackupOfferingForTests() {
return backupOffering;
}

private DiskOffering getDiskOfferingForTests() {
DiskOffering diskOffering = new DiskOffering();
diskOffering.setId("disk_offering_id");
diskOffering.setName("disk_offering_name");
return diskOffering;
}

private void mockMethodValidateIfObjectIsNull() {
Mockito.doNothing().when(presetVariableHelperSpy).validateIfObjectIsNull(Mockito.any(), Mockito.anyLong(), Mockito.anyString());
}
Expand Down Expand Up @@ -698,6 +707,7 @@ public void loadPresetVariableValueForVolumeTestRecordIsVolumeAndHasStorageSetFi
Mockito.doReturn(expected.getName()).when(volumeVoMock).getName();
Mockito.doReturn(expected.getDiskOffering()).when(presetVariableHelperSpy).getPresetVariableValueDiskOffering(Mockito.anyLong());
Mockito.doReturn(expected.getProvisioningType()).when(volumeVoMock).getProvisioningType();
Mockito.doReturn(expected.getVolumeType()).when(volumeVoMock).getVolumeType();
Mockito.doReturn(expected.getStorage()).when(presetVariableHelperSpy).getPresetVariableValueStorage(Mockito.anyLong(), Mockito.anyInt());
Mockito.doReturn(expected.getTags()).when(presetVariableHelperSpy).getPresetVariableValueResourceTags(Mockito.anyLong(), Mockito.any(ResourceObjectType.class));
Mockito.doReturn(expected.getSize()).when(volumeVoMock).getSize();
Expand All @@ -713,12 +723,13 @@ public void loadPresetVariableValueForVolumeTestRecordIsVolumeAndHasStorageSetFi
assertPresetVariableIdAndName(expected, result);
Assert.assertEquals(expected.getDiskOffering(), result.getDiskOffering());
Assert.assertEquals(expected.getProvisioningType(), result.getProvisioningType());
Assert.assertEquals(expected.getVolumeType(), result.getVolumeType());
Assert.assertEquals(expected.getStorage(), result.getStorage());
Assert.assertEquals(expected.getTags(), result.getTags());
Assert.assertEquals(expectedSize, result.getSize());
Assert.assertEquals(imageFormat.name(), result.getVolumeFormat());

validateFieldNamesToIncludeInToString(Arrays.asList("id", "name", "diskOffering", "provisioningType", "storage", "tags", "size", "volumeFormat"), result);
validateFieldNamesToIncludeInToString(Arrays.asList("id", "name", "diskOffering", "provisioningType", "volumeType", "storage", "tags", "size", "volumeFormat"), result);
}

Mockito.verify(presetVariableHelperSpy, Mockito.times(ImageFormat.values().length)).getPresetVariableValueResourceTags(Mockito.anyLong(),
Expand All @@ -740,6 +751,7 @@ public void loadPresetVariableValueForVolumeTestRecordIsVolumeAndDoesNotHaveStor
Mockito.doReturn(expected.getName()).when(volumeVoMock).getName();
Mockito.doReturn(expected.getDiskOffering()).when(presetVariableHelperSpy).getPresetVariableValueDiskOffering(Mockito.anyLong());
Mockito.doReturn(expected.getProvisioningType()).when(volumeVoMock).getProvisioningType();
Mockito.doReturn(expected.getVolumeType()).when(volumeVoMock).getVolumeType();
Mockito.doReturn(expected.getTags()).when(presetVariableHelperSpy).getPresetVariableValueResourceTags(Mockito.anyLong(), Mockito.any(ResourceObjectType.class));
Mockito.doReturn(expected.getSize()).when(volumeVoMock).getSize();
Mockito.doReturn(imageFormat).when(volumeVoMock).getFormat();
Expand All @@ -754,12 +766,13 @@ public void loadPresetVariableValueForVolumeTestRecordIsVolumeAndDoesNotHaveStor
assertPresetVariableIdAndName(expected, result);
Assert.assertEquals(expected.getDiskOffering(), result.getDiskOffering());
Assert.assertEquals(expected.getProvisioningType(), result.getProvisioningType());
Assert.assertEquals(expected.getVolumeType(), result.getVolumeType());
Assert.assertNull(result.getStorage());
Assert.assertEquals(expected.getTags(), result.getTags());
Assert.assertEquals(expectedSize, result.getSize());
Assert.assertEquals(imageFormat.name(), result.getVolumeFormat());

validateFieldNamesToIncludeInToString(Arrays.asList("id", "name", "diskOffering", "provisioningType", "tags", "size", "volumeFormat"), result);
validateFieldNamesToIncludeInToString(Arrays.asList("id", "name", "diskOffering", "provisioningType", "volumeType", "tags", "size", "volumeFormat"), result);
}

Mockito.verify(presetVariableHelperSpy, Mockito.times(ImageFormat.values().length)).getPresetVariableValueResourceTags(Mockito.anyLong(),
Expand All @@ -772,14 +785,15 @@ public void getPresetVariableValueDiskOfferingTestSetValuesAndReturnObject() {
Mockito.doReturn(diskOfferingVoMock).when(diskOfferingDaoMock).findByIdIncludingRemoved(Mockito.anyLong());
mockMethodValidateIfObjectIsNull();

GenericPresetVariable expected = getGenericPresetVariableForTests();
DiskOffering expected = getDiskOfferingForTests();
Mockito.doReturn(expected.getId()).when(diskOfferingVoMock).getUuid();
Mockito.doReturn(expected.getName()).when(diskOfferingVoMock).getName();

GenericPresetVariable result = presetVariableHelperSpy.getPresetVariableValueDiskOffering(1l);

assertPresetVariableIdAndName(expected, result);
validateFieldNamesToIncludeInToString(Arrays.asList("id", "name"), result);
validateFieldNamesToIncludeInToString(Arrays.asList("bytesReadBurst", "bytesReadBurstLength", "bytesReadRate", "bytesWriteBurst", "bytesWriteBurstLength", "bytesWriteRate",
"id", "iopsReadBurst", "iopsReadBurstLength", "iopsReadRate", "iopsWriteBurst", "iopsWriteBurstLength", "iopsWriteRate", "name"), result);
}

@Test
Expand Down
Loading