Skip to content

Commit

Permalink
Merge pull request #641 from perfectsense/bugfix/dynamo-db-verificati…
Browse files Browse the repository at this point in the history
…on-fix

Fixed validation of read and write capacities
  • Loading branch information
deepanjan90 authored Mar 13, 2024
2 parents 74a3f2e + d0d5b5c commit 52db84e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import gyro.aws.Copyable;
import gyro.core.resource.Diffable;
import gyro.core.resource.Updatable;
import gyro.core.validation.Min;
import gyro.core.validation.Required;
import gyro.core.validation.ValidStrings;
import gyro.core.validation.ValidationError;
Expand Down Expand Up @@ -84,6 +85,7 @@ public void setRangeKey(String rangeKey) {
* The maximum number of writes per second for this table before an exception is thrown. Required if ``billing-mode`` is set to ``PROVISIONED``.
*/
@Updatable
@Min(1)
public Long getWriteCapacity() {
return writeCapacity;
}
Expand All @@ -96,6 +98,7 @@ public void setWriteCapacity(Long writeCapacity) {
* The maximum number of reads per second for this table before an exception is thrown. Required if ``billing-mode`` is set to ``PROVISIONED``.
*/
@Updatable
@Min(1)
public Long getReadCapacity() {
return readCapacity;
}
Expand Down Expand Up @@ -234,8 +237,7 @@ public List<ValidationError> validate(Set<String> configuredFields) {
"'read-capacity' and 'write-capacity' must both be provided when the table 'billing-mode' is set to 'PROVISIONED'!"));
}

if ("PAY_PER_REQUEST".equals(parentTable.getBillingMode()) && (getReadCapacity() != null
|| getWriteCapacity() != null)) {
if ("PAY_PER_REQUEST".equals(parentTable.getBillingMode()) && ((getReadCapacity() != null && getReadCapacity() > 0) || (getWriteCapacity() != null && getWriteCapacity() > 0))) {
errors.add(new ValidationError(
this,
null,
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/gyro/aws/dynamodb/DynamoDbTableResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import gyro.core.resource.Resource;
import gyro.core.resource.Updatable;
import gyro.core.scope.State;
import gyro.core.validation.Min;
import gyro.core.validation.Regex;
import gyro.core.validation.Required;
import gyro.core.validation.ValidStrings;
Expand Down Expand Up @@ -253,6 +254,7 @@ public void setLocalSecondaryIndex(Set<DynamoDbLocalSecondaryIndex> localSeconda
* The maximum number of writes per second for this table before an exception is thrown. Required if ``billing-mode`` is set to ``PROVISIONED``.
*/
@Updatable
@Min(1)
public Long getWriteCapacity() {
return writeCapacity;
}
Expand All @@ -265,6 +267,7 @@ public void setWriteCapacity(Long writeCapacity) {
* The maximum number of reads per second for this table before an exception is thrown. Required if ``billing-mode`` is set to ``PROVISIONED``.
*/
@Updatable
@Min(1)
public Long getReadCapacity() {
return readCapacity;
}
Expand Down Expand Up @@ -598,7 +601,7 @@ public List<ValidationError> validate(Set<String> configuredFields) {
"'read-capacity' and 'write-capacity' must both be provided when 'billing-mode' is set to 'PROVISIONED'!"));
}

if ("PAY_PER_REQUEST".equals(getBillingMode()) && (getReadCapacity() != null || getWriteCapacity() != null)) {
if ("PAY_PER_REQUEST".equals(getBillingMode()) && ((getReadCapacity() != null && getReadCapacity() > 0) || (getWriteCapacity() != null && getWriteCapacity() > 0))) {
errors.add(new ValidationError(
this,
null,
Expand Down

0 comments on commit 52db84e

Please sign in to comment.