From 327726d3c7272806c8f3c3b7479758c26e55fd43 Mon Sep 17 00:00:00 2001 From: Michael Park Date: Tue, 19 Dec 2017 09:25:14 -0800 Subject: [PATCH] Added validation / normalized resources for storage-related operations. 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 --- src/common/resources_utils.cpp | 44 ++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/src/common/resources_utils.cpp b/src/common/resources_utils.cpp index 1676b72a9ad..50651dcf294 100644 --- a/src/common/resources_utils.cpp +++ b/src/common/resources_utils.cpp @@ -599,6 +599,17 @@ Option validateAndNormalizeResources(Offer::Operation* operation) " the Offer.Operation.create_volume field set."); } + Option 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: { @@ -611,6 +622,17 @@ Option validateAndNormalizeResources(Offer::Operation* operation) " the Offer.Operation.destroy_volume field set."); } + Option 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: { @@ -623,6 +645,17 @@ Option validateAndNormalizeResources(Offer::Operation* operation) " the Offer.Operation.create_block field set."); } + Option 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: { @@ -635,6 +668,17 @@ Option validateAndNormalizeResources(Offer::Operation* operation) " the Offer.Operation.destroy_block field set."); } + Option 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: {