diff --git a/include/RequestManagerCluster.h b/include/RequestManagerCluster.h index 2c03973351..5a2f8ce330 100644 --- a/include/RequestManagerCluster.h +++ b/include/RequestManagerCluster.h @@ -183,7 +183,7 @@ public: { // First param is ignored, as objects can be assigned to only // one cluster - int cluster_id = ClusterPool::NONE_CLUSTER_ID; + int cluster_id = ClusterPool::DEFAULT_CLUSTER_ID; int object_id = xmlrpc_c::value_int(paramList.getInt(2)); return add_generic(cluster_id, object_id, att); diff --git a/src/im/InformationManager.cc b/src/im/InformationManager.cc index 3d1ce767a5..995e8837d7 100644 --- a/src/im/InformationManager.cc +++ b/src/im/InformationManager.cc @@ -220,24 +220,21 @@ void InformationManager::stop_monitor(int hid) // ------------------------------------------------------------------------- // Remove host from cluster // ------------------------------------------------------------------------- - if ( cluster_id != ClusterPool::NONE_CLUSTER_ID ) + Cluster * cluster = clpool->get(cluster_id, true); + + if( cluster != 0 ) { - Cluster * cluster = clpool->get(cluster_id, true); + rc = cluster->del_host(hid, error_msg); - if( cluster != 0 ) + if ( rc < 0 ) { - rc = cluster->del_host(hid, error_msg); - - if ( rc < 0 ) - { - cluster->unlock(); - return; - } - - clpool->update(cluster); - cluster->unlock(); + return; } + + clpool->update(cluster); + + cluster->unlock(); } } diff --git a/src/rm/RequestManagerCluster.cc b/src/rm/RequestManagerCluster.cc index ec86042ec6..49af9da518 100644 --- a/src/rm/RequestManagerCluster.cc +++ b/src/rm/RequestManagerCluster.cc @@ -204,19 +204,12 @@ void RequestManagerClusterHost::add_generic( int old_cluster_id; string old_cluster_name; - if ( cluster_id != ClusterPool::NONE_CLUSTER_ID ) - { - rc = get_info(clpool, cluster_id, PoolObjectSQL::CLUSTER, att, c_perms, - cluster_name, true); + rc = get_info(clpool, cluster_id, PoolObjectSQL::CLUSTER, att, c_perms, + cluster_name, true); - if ( rc == -1 ) - { - return; - } - } - else + if ( rc == -1 ) { - cluster_name = ClusterPool::NONE_CLUSTER_NAME; + return; } rc = get_info(hpool, host_id, PoolObjectSQL::HOST, att, obj_perms, obj_name, true); @@ -230,11 +223,7 @@ void RequestManagerClusterHost::add_generic( { AuthRequest ar(att.uid, att.group_ids); - if ( cluster_id != ClusterPool::NONE_CLUSTER_ID ) - { - ar.add_auth(auth_op, c_perms); // ADMIN CLUSTER - } - + ar.add_auth(auth_op, c_perms); // ADMIN CLUSTER ar.add_auth(AuthRequest::ADMIN, obj_perms); // ADMIN HOST if (UserPool::authorize(ar) == -1) @@ -274,85 +263,79 @@ void RequestManagerClusterHost::add_generic( host->unlock(); // ------------- Add object to new cluster --------------------- - if ( cluster_id != ClusterPool::NONE_CLUSTER_ID ) + cluster = clpool->get(cluster_id, true); + + if ( cluster == 0 ) { - cluster = clpool->get(cluster_id, true); + att.resp_obj = PoolObjectSQL::CLUSTER; + att.resp_id = cluster_id; + failure_response(NO_EXISTS, att); - if ( cluster == 0 ) + // Rollback + host = hpool->get(host_id, true); + + if ( host != 0 ) { - att.resp_obj = PoolObjectSQL::CLUSTER; - att.resp_id = cluster_id; - failure_response(NO_EXISTS, att); + host->set_cluster(old_cluster_id, old_cluster_name); - // Rollback - host = hpool->get(host_id, true); + hpool->update(host); - if ( host != 0 ) - { - host->set_cluster(old_cluster_id, old_cluster_name); - - hpool->update(host); - - host->unlock(); - } - - return; + host->unlock(); } - if ( cluster->add_host(host_id, att.resp_msg) < 0 ) - { - cluster->unlock(); - - failure_response(INTERNAL, att); - - // Rollback - host = hpool->get(host_id, true); - - if ( host != 0 ) - { - host->set_cluster(old_cluster_id, old_cluster_name); - - hpool->update(host); - - host->unlock(); - } - - return; - } - - clpool->update(cluster); - - cluster->unlock(); + return; } + if ( cluster->add_host(host_id, att.resp_msg) < 0 ) + { + cluster->unlock(); + + failure_response(INTERNAL, att); + + // Rollback + host = hpool->get(host_id, true); + + if ( host != 0 ) + { + host->set_cluster(old_cluster_id, old_cluster_name); + + hpool->update(host); + + host->unlock(); + } + + return; + } + + clpool->update(cluster); + + cluster->unlock(); + // ------------- Remove host from old cluster --------------------- - if ( old_cluster_id != ClusterPool::NONE_CLUSTER_ID ) + cluster = clpool->get(old_cluster_id, true); + + if ( cluster == 0 ) { - cluster = clpool->get(old_cluster_id, true); - - if ( cluster == 0 ) - { - // This point should be unreachable. - // The old cluster is not empty (at least has the host_id), - // so it cannot be deleted - success_response(cluster_id, att); - return; - } - - if ( cluster->del_host(host_id, att.resp_msg) < 0 ) - { - cluster->unlock(); - - failure_response(INTERNAL, att); - return; - } - - clpool->update(cluster); - - cluster->unlock(); + // This point should be unreachable. + // The old cluster is not empty (at least has the host_id), + // so it cannot be deleted + success_response(cluster_id, att); + return; } + if ( cluster->del_host(host_id, att.resp_msg) < 0 ) + { + cluster->unlock(); + + failure_response(INTERNAL, att); + return; + } + + clpool->update(cluster); + + cluster->unlock(); + success_response(cluster_id, att); return; diff --git a/src/rm/RequestManagerDelete.cc b/src/rm/RequestManagerDelete.cc index fb81ed93c0..cbbe3e6c42 100644 --- a/src/rm/RequestManagerDelete.cc +++ b/src/rm/RequestManagerDelete.cc @@ -123,24 +123,21 @@ int RequestManagerDelete::drop( { for(set::iterator it=cluster_ids.begin(); it!=cluster_ids.end(); it++) { - if ( *it != ClusterPool::NONE_CLUSTER_ID ) + Cluster * cluster = clpool->get(*it, true); + + if( cluster != 0 ) { - Cluster * cluster = clpool->get(*it, true); + rc = del_from_cluster(cluster, oid, error_msg); - if( cluster != 0 ) + if ( rc < 0 ) { - rc = del_from_cluster(cluster, oid, error_msg); - - if ( rc < 0 ) - { - cluster->unlock(); - return rc; - } - - clpool->update(cluster); - cluster->unlock(); + return rc; } + + clpool->update(cluster); + + cluster->unlock(); } } } diff --git a/src/rm/RequestManagerVirtualMachine.cc b/src/rm/RequestManagerVirtualMachine.cc index 9cc75c3bd4..2ed5f444d6 100644 --- a/src/rm/RequestManagerVirtualMachine.cc +++ b/src/rm/RequestManagerVirtualMachine.cc @@ -224,44 +224,37 @@ int RequestManagerVirtualMachine::get_default_ds_information( ds_id = -1; - if (cluster_id == ClusterPool::NONE_CLUSTER_ID) + cluster = clpool->get(cluster_id, true); + + if (cluster == 0) { - ds_id = DatastorePool::SYSTEM_DS_ID; + att.resp_obj = PoolObjectSQL::CLUSTER; + att.resp_id = cluster_id; + failure_response(NO_EXISTS, att); + + return -1; } - else + + set ds_ids = cluster->get_datastores(); + + cluster->unlock(); + + ds_id = Cluster::get_default_system_ds(ds_ids); + + if (ds_id == -1) { - cluster = clpool->get(cluster_id, true); + ostringstream oss; - if (cluster == 0) - { - att.resp_obj = PoolObjectSQL::CLUSTER; - att.resp_id = cluster_id; - failure_response(NO_EXISTS, att); + oss << object_name(PoolObjectSQL::CLUSTER) << " [" << cluster_id + << "] does not have any " << object_name(PoolObjectSQL::DATASTORE) + << " of type " << Datastore::type_to_str(Datastore::SYSTEM_DS) + << "."; - return -1; - } + att.resp_msg = oss.str(); - set ds_ids = cluster->get_datastores(); + failure_response(ACTION, att); - cluster->unlock(); - - ds_id = Cluster::get_default_system_ds(ds_ids); - - if (ds_id == -1) - { - ostringstream oss; - - oss << object_name(PoolObjectSQL::CLUSTER) << " [" << cluster_id - << "] does not have any " << object_name(PoolObjectSQL::DATASTORE) - << " of type " << Datastore::type_to_str(Datastore::SYSTEM_DS) - << "."; - - att.resp_msg = oss.str(); - - failure_response(ACTION, att); - - return -1; - } + return -1; } set ds_cluster_ids; diff --git a/src/scheduler/src/pool/HostPoolXML.cc b/src/scheduler/src/pool/HostPoolXML.cc index 36f424db69..ed93bffa7c 100644 --- a/src/scheduler/src/pool/HostPoolXML.cc +++ b/src/scheduler/src/pool/HostPoolXML.cc @@ -112,23 +112,20 @@ void HostPoolXML::merge_clusters(ClusterPoolXML * clpool) cluster_id = host->get_cid(); - if(cluster_id != -1) //ClusterPool::NONE_CLUSTER_ID + cluster = clpool->get(cluster_id); + + if(cluster != 0) { - cluster = clpool->get(cluster_id); + nodes.clear(); - if(cluster != 0) + cluster->get_nodes("/CLUSTER/TEMPLATE", nodes); + + if (!nodes.empty()) { - nodes.clear(); - - cluster->get_nodes("/CLUSTER/TEMPLATE", nodes); - - if (!nodes.empty()) - { - host->add_node("/HOST", nodes[0], "CLUSTER_TEMPLATE"); - } - - cluster->free_nodes(nodes); + host->add_node("/HOST", nodes[0], "CLUSTER_TEMPLATE"); } + + cluster->free_nodes(nodes); } } }