From e5c1c549bb5062d2ff6e3f26b74cf94a2a83df1c Mon Sep 17 00:00:00 2001 From: Jaime Melis Date: Tue, 26 Jan 2016 23:19:31 +0100 Subject: [PATCH] Feature #4217: Get the attributes from the App properly --- include/MarketPlaceApp.h | 20 ++++++++-- src/market/MarketPlaceApp.cc | 32 +++------------- src/rm/RequestManagerAllocate.cc | 64 ++++++++++---------------------- 3 files changed, 41 insertions(+), 75 deletions(-) diff --git a/include/MarketPlaceApp.h b/include/MarketPlaceApp.h index 3be441db6f..9aa10dfbdd 100644 --- a/include/MarketPlaceApp.h +++ b/include/MarketPlaceApp.h @@ -121,10 +121,8 @@ public: * Copies the special attributes of the App to the template * @param tmp The template object * @param error_str Returns the error reason, if any - * - * @return 0 on success, -1 otherwise */ - int to_template(Template * tmpl, std::string& error_str); + void to_template(Template * tmpl); /** * Enable or disable the app. A disabled app cannot be exported @@ -182,6 +180,22 @@ public: return source; } + const string& get_md5() + { + return md5; + } + + long long get_size() + { + return size_mb; + } + + const string& get_format() + { + return format; + } + + MarketPlaceAppState get_state() { return state; diff --git a/src/market/MarketPlaceApp.cc b/src/market/MarketPlaceApp.cc index 1fdc8aeab1..1b1e18d8a9 100644 --- a/src/market/MarketPlaceApp.cc +++ b/src/market/MarketPlaceApp.cc @@ -411,34 +411,12 @@ int MarketPlaceApp::enable(bool enable, string& error_str) /* --------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------- */ -int MarketPlaceApp::to_template(Template * tmpl, std::string& error_str) +void MarketPlaceApp::to_template(Template * tmpl) { - bool rc; - - string app_path; - string app_format; - string app_md5; - string app_name; - - int market_id; - - get_template_attribute("SOURCE", app_path); - get_template_attribute("FORMAT", app_format); - get_template_attribute("MD5", app_md5); - get_template_attribute("NAME", app_name); - - if ( app_path.empty() ) - { - error_str = "The appliance has no SOURCE"; - return -1; - } - - tmpl->replace("PATH", app_path); - tmpl->replace("FORMAT", app_format); - tmpl->replace("MD5", app_format); - tmpl->replace("FROM_APP_NAME", app_name); - - return 0; + tmpl->replace("FROM_APP_NAME", get_name()); + tmpl->replace("PATH", get_source()); + tmpl->replace("FORMAT", get_format()); + tmpl->replace("MD5", get_md5()); } /* --------------------------------------------------------------------------- */ diff --git a/src/rm/RequestManagerAllocate.cc b/src/rm/RequestManagerAllocate.cc index 5a4bb1f138..b9339f446b 100644 --- a/src/rm/RequestManagerAllocate.cc +++ b/src/rm/RequestManagerAllocate.cc @@ -398,53 +398,25 @@ void ImageAllocate::request_execute(xmlrpc_c::paramList const& params, { // This image comes from a MarketPlaceApp. Get the Market info and // the size. - bool market_check; app = apppool->get(app_id, true); - if ( app_id == 0 ) + if ( app == 0 ) { failure_response(INTERNAL, - "Cannot find appliance referenced by FROM_APP", + "Cannot find appliance referenced by FROM_APP.", att); delete tmpl; return; } - rc = app->to_template(tmpl, error_str); + app->to_template(tmpl); - app->get_template_attribute("SIZE", size_str); - - market_check = app->get_template_attribute("MARKETPLACE_ID", market_id); + size_mb = app->get_size(); + market_id = app->get_market_id(); app->unlock(); - if ( rc == -1 ) - { - failure_response(INTERNAL, allocate_error(error_str), att); - - delete tmpl; - return; - } - - if ( !market_check ) - { - error_str = "The appliance has no MARKETPLACE_ID"; - failure_response(INTERNAL, allocate_error(error_str), att); - - delete tmpl; - return; - } - - if ( size_str.empty() ) - { - error_str = "The appliance has no SIZE"; - failure_response(INTERNAL, allocate_error(error_str), att); - - delete tmpl; - return; - } - market = marketpool->get(market_id, true); if ( market == 0 ) @@ -466,24 +438,26 @@ void ImageAllocate::request_execute(xmlrpc_c::paramList const& params, if ( rc == -1 ) { failure_response(INTERNAL, - request_error("Cannot determine Image SIZE", size_str), + request_error("Cannot determine Image SIZE", + size_str), + att); + delete tmpl; + return; + } + + iss.str(size_str); + iss >> size_mb; + + if ( iss.fail() ) + { + failure_response(INTERNAL, + request_error("Cannot parse SIZE", size_str), att); delete tmpl; return; } } - iss.str(size_str); - iss >> size_mb; - - if ( iss.fail() ) - { - failure_response(INTERNAL, - request_error("Cannot parse SIZE", size_str), - att); - delete tmpl; - return; - } if (ds_check && (size_mb > avail)) {