Skip to content

Commit

Permalink
Added validation / normalized resources for storage-related operations.
Browse files Browse the repository at this point in the history
When the storage-related operations were added, the cases were added to
the `switch` but the corresponding validation / normalization code was
not added. This patch adds the missing code.

Review: https://reviews.apache.org/r/64737
  • Loading branch information
mpark committed Dec 20, 2017
1 parent a9d3f1e commit 327726d
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions src/common/resources_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,17 @@ Option<Error> validateAndNormalizeResources(Offer::Operation* operation)
" the Offer.Operation.create_volume field set.");
}

Option<Error> error =
Resources::validate(operation->create_volume().source());

if (error.isSome()) {
return error;
}

convertResourceFormat(
operation->mutable_create_volume()->mutable_source(),
POST_RESERVATION_REFINEMENT);

return None();
}
case Offer::Operation::DESTROY_VOLUME: {
Expand All @@ -611,6 +622,17 @@ Option<Error> validateAndNormalizeResources(Offer::Operation* operation)
" the Offer.Operation.destroy_volume field set.");
}

Option<Error> error =
Resources::validate(operation->destroy_volume().volume());

if (error.isSome()) {
return error;
}

convertResourceFormat(
operation->mutable_destroy_volume()->mutable_volume(),
POST_RESERVATION_REFINEMENT);

return None();
}
case Offer::Operation::CREATE_BLOCK: {
Expand All @@ -623,6 +645,17 @@ Option<Error> validateAndNormalizeResources(Offer::Operation* operation)
" the Offer.Operation.create_block field set.");
}

Option<Error> error =
Resources::validate(operation->create_block().source());

if (error.isSome()) {
return error;
}

convertResourceFormat(
operation->mutable_create_block()->mutable_source(),
POST_RESERVATION_REFINEMENT);

return None();
}
case Offer::Operation::DESTROY_BLOCK: {
Expand All @@ -635,6 +668,17 @@ Option<Error> validateAndNormalizeResources(Offer::Operation* operation)
" the Offer.Operation.destroy_block field set.");
}

Option<Error> error =
Resources::validate(operation->destroy_block().block());

if (error.isSome()) {
return error;
}

convertResourceFormat(
operation->mutable_destroy_block()->mutable_block(),
POST_RESERVATION_REFINEMENT);

return None();
}
case Offer::Operation::UNKNOWN: {
Expand Down

0 comments on commit 327726d

Please sign in to comment.