From 07eba81abd09fb648844a3740cae9d3cc01b4060 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Tue, 28 Feb 2012 17:59:03 +0100 Subject: [PATCH] Feature #1112: refactor Request::get_info --- include/Request.h | 20 ++++++++++++++++++++ include/RequestManagerChown.h | 7 ------- include/RequestManagerCluster.h | 7 ------- src/rm/Request.cc | 28 ++++++++++++++++++++++++++++ src/rm/RequestManagerAllocate.cc | 18 ++---------------- src/rm/RequestManagerChown.cc | 27 --------------------------- src/rm/RequestManagerCluster.cc | 29 ----------------------------- 7 files changed, 50 insertions(+), 86 deletions(-) diff --git a/include/Request.h b/include/Request.h index 1078fd8898..9c479d97b6 100644 --- a/include/Request.h +++ b/include/Request.h @@ -219,6 +219,26 @@ protected: * @return string for logging */ string allocate_error (PoolObjectSQL::ObjectType obj, const string& error); + + /** + * Locks the requested object, gets information, and unlocks it + * + * @param pool object pool + * @param id of the object + * @param type of the object + * @param att the specific request attributes + * + * @param perms returns the object's permissions + * @param name returns the object's name + * + * @return 0 on success, -1 otherwise + */ + int get_info (PoolSQL * pool, + int id, + PoolObjectSQL::ObjectType type, + RequestAttributes& att, + PoolObjectAuth& perms, + string& name); }; /* -------------------------------------------------------------------------- */ diff --git a/include/RequestManagerChown.h b/include/RequestManagerChown.h index 78569079e0..c0591bb36c 100644 --- a/include/RequestManagerChown.h +++ b/include/RequestManagerChown.h @@ -52,13 +52,6 @@ protected: virtual void request_execute(xmlrpc_c::paramList const& _paramList, RequestAttributes& att); - - int get_info (PoolSQL * pool, - int id, - PoolObjectSQL::ObjectType type, - RequestAttributes& att, - PoolObjectAuth& perms, - string& name); }; /* ------------------------------------------------------------------------- */ diff --git a/include/RequestManagerCluster.h b/include/RequestManagerCluster.h index 94958600d7..c90cb124e4 100644 --- a/include/RequestManagerCluster.h +++ b/include/RequestManagerCluster.h @@ -67,13 +67,6 @@ protected: virtual int del_object(Cluster* cluster, int id, string& error_msg) = 0; virtual void get(int oid, bool lock, PoolObjectSQL ** object, Clusterable ** cluster_obj) = 0; - - int get_info (PoolSQL * pool, - int id, - PoolObjectSQL::ObjectType type, - RequestAttributes& att, - PoolObjectAuth& perms, - string& name); }; /* ------------------------------------------------------------------------- */ diff --git a/src/rm/Request.cc b/src/rm/Request.cc index cf50bec1ed..bd5b9a9f82 100644 --- a/src/rm/Request.cc +++ b/src/rm/Request.cc @@ -297,3 +297,31 @@ string Request::allocate_error (const string& error) /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ + +int Request::get_info( + PoolSQL * pool, + int id, + PoolObjectSQL::ObjectType type, + RequestAttributes& att, + PoolObjectAuth& perms, + string& name) +{ + PoolObjectSQL * ob; + + if ((ob = pool->get(id,true)) == 0 ) + { + failure_response(NO_EXISTS, get_error(object_name(type), id), att); + return -1; + } + + ob->get_permissions(perms); + + name = ob->get_name(); + + ob->unlock(); + + return 0; +} + +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ diff --git a/src/rm/RequestManagerAllocate.cc b/src/rm/RequestManagerAllocate.cc index 53751545c9..909bfcfcc4 100644 --- a/src/rm/RequestManagerAllocate.cc +++ b/src/rm/RequestManagerAllocate.cc @@ -328,24 +328,10 @@ void HostAllocate::request_execute( ClusterPool * clpool = nd.get_clpool(); HostPool * hpool = static_cast(pool); - Cluster * cluster; - // ------------------------- Check Cluster exists ------------------------ - if ((cluster = clpool->get(cluster_id,true)) == 0 ) - { - failure_response(NO_EXISTS, - get_error(object_name(PoolObjectSQL::CLUSTER), cluster_id), - att); - - return; - } - - cluster->get_permissions(cluster_perms); - - cluster_name = cluster->get_name(); - - cluster->unlock(); + get_info(clpool, cluster_id, PoolObjectSQL::CLUSTER, att, + cluster_perms, cluster_name); // ------------- Set authorization request for non-oneadmin's ------------- diff --git a/src/rm/RequestManagerChown.cc b/src/rm/RequestManagerChown.cc index 4ecbf9ee48..768a87c5e8 100644 --- a/src/rm/RequestManagerChown.cc +++ b/src/rm/RequestManagerChown.cc @@ -23,33 +23,6 @@ /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ -int RequestManagerChown::get_info (PoolSQL * pool, - int id, - PoolObjectSQL::ObjectType type, - RequestAttributes& att, - PoolObjectAuth& perms, - string& name) -{ - PoolObjectSQL * ob; - - if ((ob = pool->get(id,true)) == 0 ) - { - failure_response(NO_EXISTS, get_error(object_name(type), id), att); - return -1; - } - - ob->get_permissions(perms); - - name = ob->get_name(); - - ob->unlock(); - - return 0; -} - -/* -------------------------------------------------------------------------- */ -/* -------------------------------------------------------------------------- */ - void RequestManagerChown::request_execute(xmlrpc_c::paramList const& paramList, RequestAttributes& att) { diff --git a/src/rm/RequestManagerCluster.cc b/src/rm/RequestManagerCluster.cc index 91584334ea..09089e110c 100644 --- a/src/rm/RequestManagerCluster.cc +++ b/src/rm/RequestManagerCluster.cc @@ -21,35 +21,6 @@ using namespace std; /* ------------------------------------------------------------------------- */ /* ------------------------------------------------------------------------- */ -// TODO: same method in RequestManagerChown, should be moved to Request - -int RequestManagerCluster::get_info (PoolSQL * pool, - int id, - PoolObjectSQL::ObjectType type, - RequestAttributes& att, - PoolObjectAuth& perms, - string& name) -{ - PoolObjectSQL * ob; - - if ((ob = pool->get(id,true)) == 0 ) - { - failure_response(NO_EXISTS, get_error(object_name(type), id), att); - return -1; - } - - ob->get_permissions(perms); - - name = ob->get_name(); - - ob->unlock(); - - return 0; -} - -/* ------------------------------------------------------------------------- */ -/* ------------------------------------------------------------------------- */ - void RequestManagerCluster::add_generic( xmlrpc_c::paramList const& paramList, RequestAttributes& att,