Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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
21 changes: 18 additions & 3 deletions api/src/main/java/com/cloud/offering/DiskOffering.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@
// under the License.
package com.cloud.offering;

import java.util.Date;

import com.cloud.storage.Storage.ProvisioningType;
import org.apache.cloudstack.acl.InfrastructureEntity;
import org.apache.cloudstack.api.Identity;
import org.apache.cloudstack.api.InternalIdentity;

import com.cloud.storage.Storage.ProvisioningType;
import java.util.Date;

/**
* Represents a disk offering that specifies what the end user needs in
Expand Down Expand Up @@ -111,6 +110,22 @@ public String toString() {

Long getIopsWriteRate();

Long getMinIopsPerGb();

void setMinIopsPerGb(Long minIopsPerGB);

Long getMaxIopsPerGb();

void setMaxIopsPerGb(Long maxIopsPerGB);

Long getHighestMinIops();

void setHighestMinIops(Long highestMinIops);

Long getHighestMaxIops();

void setHighestMaxIops(Long highestMaxIops);

void setHypervisorSnapshotReserve(Integer hypervisorSnapshotReserve);

Integer getHypervisorSnapshotReserve();
Expand Down
4 changes: 4 additions & 0 deletions api/src/main/java/org/apache/cloudstack/api/ApiConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -698,6 +698,10 @@ public class ApiConstants {
public static final String VIRTUAL_SIZE = "virtualsize";
public static final String NETSCALER_CONTROLCENTER_ID = "netscalercontrolcenterid";
public static final String NETSCALER_SERVICEPACKAGE_ID = "netscalerservicepackageid";
public static final String MIN_IOPS_PER_GB = "miniopspergb";
public static final String MAX_IOPS_PER_GB = "maxiopspergb";
public static final String HIGHEST_MIN_IOPS = "highestminiops";
public static final String HIGHEST_MAX_IOPS = "highestmaxiops";

public static final String ZONE_ID_LIST = "zoneids";
public static final String DESTINATION_ZONE_ID_LIST = "destzoneids";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,18 @@ public class CreateDiskOfferingCmd extends BaseCmd {
@Parameter(name = ApiConstants.MAX_IOPS, type = CommandType.LONG, required = false, description = "max iops of the disk offering")
private Long maxIops;

@Parameter(name = ApiConstants.MIN_IOPS_PER_GB, type = CommandType.LONG, required = false, description = "IOPS/GB rate for min IOPS. miniops = size * miniopspergb")
private Long minIopsPerGb;

@Parameter(name = ApiConstants.MAX_IOPS_PER_GB, type = CommandType.LONG, required = false, description = "IOPS/GB rate for max IOPS. maxiops = size * maxiopspergb")
private Long maxIopsPerGb;

@Parameter(name = ApiConstants.HIGHEST_MIN_IOPS, type = CommandType.LONG, required = false, description = "Highest Min IOPS value that is allowed for this offering")
private Long highestMinIops;

@Parameter(name = ApiConstants.HIGHEST_MAX_IOPS, type = CommandType.LONG, required = false, description = "Highest Max IOPS value that is allowed for this offering")
private Long highestMaxIops;

@Parameter(name = ApiConstants.HYPERVISOR_SNAPSHOT_RESERVE,
type = CommandType.INTEGER,
required = false,
Expand Down Expand Up @@ -176,6 +188,21 @@ public Integer getHypervisorSnapshotReserve() {
return hypervisorSnapshotReserve;
}

public Long getMinIopsPerGb() {
return minIopsPerGb;
}

public Long getMaxIopsPerGb() {
return maxIopsPerGb;
}

public Long getHighestMinIops() {
return highestMinIops;
}

public Long getHighestMaxIops() {
return highestMaxIops;
}
/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,14 @@
// under the License.
package org.apache.cloudstack.api.response;

import java.util.Date;

import com.cloud.offering.DiskOffering;
import com.cloud.serializer.Param;
import com.google.gson.annotations.SerializedName;

import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.BaseResponse;
import org.apache.cloudstack.api.EntityReference;

import com.cloud.offering.DiskOffering;
import com.cloud.serializer.Param;
import java.util.Date;

@EntityReference(value = DiskOffering.class)
public class DiskOfferingResponse extends BaseResponse {
Expand Down Expand Up @@ -112,6 +110,21 @@ public class DiskOfferingResponse extends BaseResponse {
@Param(description = "whether to display the offering to the end user or not.")
private Boolean displayOffering;

@SerializedName(ApiConstants.MIN_IOPS_PER_GB)
@Param(description = "IOPS/GB rate for min IOPS. miniops = size * miniopspergb")
private Long minIopsPerGb;
@SerializedName(ApiConstants.MAX_IOPS_PER_GB)
@Param(description = "IOPS/GB rate for max IOPS. miniops = size * miniopspergb")
private Long maxIopsPerGb;

@SerializedName(ApiConstants.HIGHEST_MIN_IOPS)
@Param(description = "Highest Min IOPS value that is allowed for this offering")
private Long highestMinIops;

@SerializedName(ApiConstants.HIGHEST_MAX_IOPS)
@Param(description = "Highest Max IOPS value that is allowed for this offering")
private Long highestMaxIops;

public Boolean getDisplayOffering() {
return displayOffering;
}
Expand Down Expand Up @@ -221,6 +234,38 @@ public Integer getHypervisorSnapshotReserve() {
return hypervisorSnapshotReserve;
}

public Long getMinIopsPerGb() {
return minIopsPerGb;
}

public void setMinIopsPerGb(Long minIopsPerGb) {
this.minIopsPerGb = minIopsPerGb;
}

public Long getMaxIopsPerGb() {
return maxIopsPerGb;
}

public void setMaxIopsPerGb(Long maxIopsPerGb) {
this.maxIopsPerGb = maxIopsPerGb;
}

public Long getHighestMinIops() {
return highestMinIops;
}

public void setHighestMinIops(Long highestMinIops) {
this.highestMinIops = highestMinIops;
}

public Long getHighestMaxIops() {
return highestMaxIops;
}

public void setHighestMaxIops(Long highestMaxIops) {
this.highestMaxIops = highestMaxIops;
}

public void setHypervisorSnapshotReserve(Integer hypervisorSnapshotReserve) {
this.hypervisorSnapshotReserve = hypervisorSnapshotReserve;
}
Expand Down Expand Up @@ -264,4 +309,5 @@ public void setIopsReadRate(Long iopsReadRate) {
public void setIopsWriteRate(Long iopsWriteRate) {
this.iopsWriteRate = iopsWriteRate;
}

}
65 changes: 58 additions & 7 deletions engine/schema/src/main/java/com/cloud/storage/DiskOfferingVO.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@
// under the License.
package com.cloud.storage;

import java.util.Date;
import java.util.List;
import java.util.UUID;
import com.cloud.offering.DiskOffering;
import com.cloud.utils.db.GenericDao;

import javax.persistence.Column;
import javax.persistence.DiscriminatorColumn;
Expand All @@ -35,9 +34,9 @@
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;

import com.cloud.offering.DiskOffering;
import com.cloud.utils.db.GenericDao;
import java.util.Date;
import java.util.List;
import java.util.UUID;

@Entity
@Table(name = "disk_offering")
Expand Down Expand Up @@ -117,6 +116,18 @@ public class DiskOfferingVO implements DiskOffering {
@Column(name = "iops_write_rate")
Long iopsWriteRate;

@Column(name = "min_iops_per_gb")
Long minIopsPerGb;

@Column(name = "max_iops_per_gb")
Long maxIopsPerGb;

@Column(name = "highest_min_iops")
Long highestMinIops;

@Column(name = "highest_max_iops")
Long highestMaxIops;

@Column(name = "cache_mode", updatable = true, nullable = false)
@Enumerated(value = EnumType.STRING)
private DiskCacheMode cacheMode;
Expand Down Expand Up @@ -465,7 +476,7 @@ public void setDisplayOffering(boolean displayOffering) {
this.displayOffering = displayOffering;
}

@Override
@Override
public void setBytesReadRate(Long bytesReadRate) {
this.bytesReadRate = bytesReadRate;
}
Expand Down Expand Up @@ -505,6 +516,46 @@ public Long getIopsWriteRate() {
return iopsWriteRate;
}

@Override
public Long getMinIopsPerGb() {
return this.minIopsPerGb;
}

@Override
public void setMinIopsPerGb(Long minIopsPerGb) {
this.minIopsPerGb = minIopsPerGb;
}

@Override
public Long getMaxIopsPerGb() {
return maxIopsPerGb;
}

@Override
public void setMaxIopsPerGb(Long maxIopsPerGb) {
this.maxIopsPerGb = maxIopsPerGb;
}

@Override
public Long getHighestMinIops() {
return this.highestMinIops;
}

@Override
public void setHighestMinIops(Long highestMinIops) {
this.highestMinIops = highestMinIops;
}

@Override
public Long getHighestMaxIops() {
return this.highestMaxIops;
}

@Override
public void setHighestMaxIops(Long highestMaxIops) {
this.highestMaxIops = highestMaxIops;
}

@Override
public void setHypervisorSnapshotReserve(Integer hypervisorSnapshotReserve) {
this.hypervisorSnapshotReserve = hypervisorSnapshotReserve;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
-- IOPS per GB disk offering
DROP PROCEDURE IF EXISTS `cloud`.`ADD_COLUMN_TO_TABLE_IDEMPOTENT`;

DELIMITER //
CREATE PROCEDURE `cloud`.`ADD_COLUMN_TO_TABLE_IDEMPOTENT`(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this being introduced by some other PR?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. This is only for this PR

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm.. Then, I think it is better to coordinate with PR #2449.

IN tableName VARCHAR(255),
IN colName VARCHAR(255),
IN colType VARCHAR(255),
IN comment VARCHAR(255))
BEGIN
SET @t1=CONCAT('SELECT COUNT(*) FROM information_schema.COLUMNS WHERE TABLE_SCHEMA="cloud" AND TABLE_NAME="', tableName, '" AND COLUMN_NAME="', colName, '" into @outvar');
PREPARE stmt1 FROM @t1;
EXECUTE stmt1;
DEALLOCATE PREPARE stmt1;
IF (@outvar < 1) THEN
SET @t2=CONCAT('ALTER TABLE `cloud`.`', tableName, '` ADD COLUMN `', colName, '` ', colType, ' DEFAULT NULL COMMENT "', comment , '"');
PREPARE stmt2 FROM @t2;
EXECUTE stmt2;
DEALLOCATE PREPARE stmt2;
END IF; END //
DELIMITER ;

CALL `cloud`.`ADD_COLUMN_TO_TABLE_IDEMPOTENT`('disk_offering', 'min_iops_per_gb', 'int unsigned', 'Min IOPS per GB for rate based offering');
CALL `cloud`.`ADD_COLUMN_TO_TABLE_IDEMPOTENT`('disk_offering', 'max_iops_per_gb', 'int unsigned', 'Max IOPS per GB for rate based offering');
CALL `cloud`.`ADD_COLUMN_TO_TABLE_IDEMPOTENT`('disk_offering', 'highest_min_iops', 'int unsigned', 'Highest Min IOPS value for this offering');
CALL `cloud`.`ADD_COLUMN_TO_TABLE_IDEMPOTENT`('disk_offering', 'highest_max_iops', 'int unsigned', 'Highest Max IOPS value for this offering');

DROP PROCEDURE `cloud`.`ADD_COLUMN_TO_TABLE_IDEMPOTENT`;

DROP VIEW IF EXISTS `cloud`.`disk_offering_view`;
CREATE VIEW `cloud`.`disk_offering_view` AS
select
disk_offering.id,
disk_offering.uuid,
disk_offering.name,
disk_offering.display_text,
disk_offering.provisioning_type,
disk_offering.disk_size,
disk_offering.min_iops,
disk_offering.max_iops,
disk_offering.created,
disk_offering.tags,
disk_offering.customized,
disk_offering.customized_iops,
disk_offering.removed,
disk_offering.use_local_storage,
disk_offering.system_use,
disk_offering.hv_ss_reserve,
disk_offering.bytes_read_rate,
disk_offering.bytes_write_rate,
disk_offering.iops_read_rate,
disk_offering.iops_write_rate,
disk_offering.min_iops_per_gb,
disk_offering.max_iops_per_gb,
disk_offering.highest_min_iops,
disk_offering.highest_max_iops,
disk_offering.cache_mode,
disk_offering.sort_key,
disk_offering.type,
disk_offering.display_offering,
domain.id domain_id,
domain.uuid domain_uuid,
domain.name domain_name,
domain.path domain_path
from
`cloud`.`disk_offering`
left join
`cloud`.`domain` ON disk_offering.domain_id = domain.id
where
disk_offering.state='ACTIVE';
11 changes: 9 additions & 2 deletions framework/db/src/main/java/com/cloud/utils/db/ScriptRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
*/
package com.cloud.utils.db;

import org.apache.log4j.Logger;

import java.io.IOException;
import java.io.LineNumberReader;
import java.io.Reader;
Expand All @@ -29,15 +31,14 @@
import java.sql.SQLException;
import java.sql.Statement;

import org.apache.log4j.Logger;

/**
* Tool to run database scripts
*/
public class ScriptRunner {
private static Logger s_logger = Logger.getLogger(ScriptRunner.class);

private static final String DEFAULT_DELIMITER = ";";
private static final String CHANGE_DELIMITER_STMT = "DELIMITER ";

private Connection connection;

Expand Down Expand Up @@ -128,6 +129,12 @@ private void runScript(Connection conn, Reader reader) throws IOException, SQLEx
// Do nothing
} else if (trimmedLine.length() < 1 || trimmedLine.startsWith("#")) {
// Do nothing
} else if (trimmedLine.startsWith(CHANGE_DELIMITER_STMT)) {
String[] res = trimmedLine.split(CHANGE_DELIMITER_STMT, 2);
if (res.length == 2) {
String newDelimiter = res[1];
setDelimiter(newDelimiter, fullLineDelimiter);
}
} else if (!fullLineDelimiter && trimmedLine.endsWith(getDelimiter()) || fullLineDelimiter && trimmedLine.equals(getDelimiter())) {
command.append(line.substring(0, line.lastIndexOf(getDelimiter())));
command.append(" ");
Expand Down
Loading