diff --git a/include/ClusterPool.h b/include/ClusterPool.h index 6d6a4d9546..c7964d8752 100644 --- a/include/ClusterPool.h +++ b/include/ClusterPool.h @@ -73,7 +73,7 @@ private: * @param clid the id assigned to the cluster * @return the id assigned to the cluster or -1 in case of failure */ - int allocate(int * clid, string name, SqlDB *db); + int allocate(int * clid, string name, SqlDB *db, string& error_str); /** * Returns the xml representation of the given cluster diff --git a/include/HostPool.h b/include/HostPool.h index 6e75f2982a..4fbd9cf9c1 100644 --- a/include/HostPool.h +++ b/include/HostPool.h @@ -170,9 +170,9 @@ public: * @param clid the id assigned to the cluster * @return the id assigned to the cluster or -1 in case of failure */ - int allocate_cluster(int * clid, string name) + int allocate_cluster(int * clid, const string& name, string& error_str) { - return cluster_pool.allocate(clid, name, db); + return cluster_pool.allocate(clid, name, db, error_str); }; /** diff --git a/src/host/ClusterPool.cc b/src/host/ClusterPool.cc index ff91cc98e2..1cc54895d4 100644 --- a/src/host/ClusterPool.cc +++ b/src/host/ClusterPool.cc @@ -30,7 +30,7 @@ const string ClusterPool::DEFAULT_CLUSTER_NAME = "default"; /* -------------------------------------------------------------------------- */ -int ClusterPool::allocate(int * clid, string name, SqlDB *db) +int ClusterPool::allocate(int * clid, string name, SqlDB *db, string& error_str) { int rc; map<int, string>::iterator it; @@ -61,15 +61,15 @@ int ClusterPool::allocate(int * clid, string name, SqlDB *db) error_existing_name: oss << "Could not allocate new cluster: Name \"" - << name << "\" already exists."; + << name << "\" already exists"; goto error_common; error_db: - oss << "Could not allocate new cluster \"" << name - << "\": Database returned error code " << rc << "."; + oss << "Could not allocate new cluster \"" << name; goto error_common; error_common: + error_str = oss.str(); NebulaLog::log("CLUSTER", Log::ERROR, oss); *clid = -1; diff --git a/src/rm/RequestManagerClusterAllocate.cc b/src/rm/RequestManagerClusterAllocate.cc index be09bdf110..c6eab23991 100644 --- a/src/rm/RequestManagerClusterAllocate.cc +++ b/src/rm/RequestManagerClusterAllocate.cc @@ -27,10 +27,11 @@ void RequestManager::ClusterAllocate::execute( xmlrpc_c::value * const retval) { string session; + string error_str; string clustername; int id; - + const string method_name = "ClusterAllocate"; int rc; @@ -68,7 +69,7 @@ void RequestManager::ClusterAllocate::execute( } // Perform the allocation in the hostpool - rc = ClusterAllocate::hpool->allocate_cluster(&id, clustername); + rc = ClusterAllocate::hpool->allocate_cluster(&id, clustername, error_str); if ( rc == -1 ) { @@ -95,7 +96,8 @@ error_authorize: goto error_common; error_cluster_allocate: - oss.str(action_error(method_name, "CREATE", "CLUSTER", -2, rc)); + oss << action_error(method_name, "CREATE", "CLUSTER", -2, 0); + oss << ". " << error_str; goto error_common; error_common: diff --git a/src/rm/RequestManagerImagePersistent.cc b/src/rm/RequestManagerImagePersistent.cc index 0c4c6322b4..758ea3e6bf 100644 --- a/src/rm/RequestManagerImagePersistent.cc +++ b/src/rm/RequestManagerImagePersistent.cc @@ -31,18 +31,18 @@ void RequestManager::ImagePersistent::execute( string session; int iid; - bool persistent_flag; + bool persistent_flag; int uid; - + int image_owner; bool is_public; - + Image * image; ostringstream oss; - + bool response; - + const string method_name = "ImagePersistent"; vector<xmlrpc_c::value> arrayData; @@ -62,20 +62,20 @@ void RequestManager::ImagePersistent::execute( { goto error_authenticate; } - + // Get image from the ImagePool - image = ImagePersistent::ipool->get(iid,true); - - if ( image == 0 ) - { - goto error_image_get; + image = ImagePersistent::ipool->get(iid,true); + + if ( image == 0 ) + { + goto error_image_get; } - + image_owner = image->get_uid(); is_public = image->isPublic(); - + image->unlock(); - + //Authorize the operation if ( uid != 0 ) // uid == 0 means oneadmin { @@ -92,22 +92,22 @@ void RequestManager::ImagePersistent::execute( goto error_authorize; } } - + // Get the image locked again - image = ImagePersistent::ipool->get(iid,true); - - if ( image == 0 ) - { - goto error_image_get; - } - + image = ImagePersistent::ipool->get(iid,true); + + if ( image == 0 ) + { + goto error_image_get; + } + response = image->persistent(persistent_flag); - + if (!response) { goto error_persistent; } - + ImagePersistent::ipool->update(image); image->unlock(); @@ -124,20 +124,20 @@ void RequestManager::ImagePersistent::execute( return; error_authenticate: - oss.str(authenticate_error(method_name)); + oss.str(authenticate_error(method_name)); goto error_common; - + error_image_get: - oss.str(get_error(method_name, "IMAGE", iid)); + oss.str(get_error(method_name, "IMAGE", iid)); goto error_common; - + error_authorize: oss.str(authorization_error(method_name, "MANAGE", "IMAGE", uid, iid)); goto error_common; - + error_persistent: - oss << action_error(method_name, "MANAGE", "IMAGE", iid, NULL) - << " Is the image public? An Image cannot be public and persistent."; + oss << action_error(method_name, "MANAGE", "IMAGE", iid, 0) + << ". Is the image public? An Image cannot be public and persistent."; goto error_common; error_common: diff --git a/src/rm/RequestManagerImagePublish.cc b/src/rm/RequestManagerImagePublish.cc index 820b1961c3..8c48677097 100644 --- a/src/rm/RequestManagerImagePublish.cc +++ b/src/rm/RequestManagerImagePublish.cc @@ -31,18 +31,18 @@ void RequestManager::ImagePublish::execute( string session; int iid; - bool publish_flag; + bool publish_flag; int uid; - + int image_owner; bool is_public; - + Image * image; - + bool response; ostringstream oss; - + const string method_name = "ImagePublish"; vector<xmlrpc_c::value> arrayData; @@ -62,20 +62,20 @@ void RequestManager::ImagePublish::execute( { goto error_authenticate; } - + // Get image from the ImagePool - image = ImagePublish::ipool->get(iid,true); - - if ( image == 0 ) - { - goto error_image_get; + image = ImagePublish::ipool->get(iid,true); + + if ( image == 0 ) + { + goto error_image_get; } - + image_owner = image->get_uid(); is_public = image->isPublic(); - + image->unlock(); - + //Authorize the operation if ( uid != 0 ) // uid == 0 means oneadmin { @@ -92,22 +92,22 @@ void RequestManager::ImagePublish::execute( goto error_authorize; } } - + // Get the image locked again - image = ImagePublish::ipool->get(iid,true); - - if ( image == 0 ) - { - goto error_image_get; - } - + image = ImagePublish::ipool->get(iid,true); + + if ( image == 0 ) + { + goto error_image_get; + } + response = image->publish(publish_flag); - + if (!response) { goto error_publish; } - + ImagePublish::ipool->update(image); image->unlock(); @@ -124,20 +124,20 @@ void RequestManager::ImagePublish::execute( return; error_authenticate: - oss.str(authenticate_error(method_name)); + oss.str(authenticate_error(method_name)); goto error_common; - + error_image_get: - oss.str(get_error(method_name, "IMAGE", iid)); + oss.str(get_error(method_name, "IMAGE", iid)); goto error_common; - + error_authorize: oss.str(authorization_error(method_name, "MANAGE", "IMAGE", uid, iid)); goto error_common; error_publish: - oss << action_error(method_name, "MANAGE", "IMAGE", iid, NULL) - << " Is the image persistent? An Image cannot be public and persistent."; + oss<< action_error(method_name, "MANAGE", "IMAGE", iid, 0) + <<". Is the image persistent? An Image cannot be public and persistent."; goto error_common; error_common: