Revision fc15b997 src/host/HostPool.cc

View differences:

src/host/HostPool.cc
18 18
/* Host Pool                                                    			  */
19 19
/* ************************************************************************** */
20 20

  
21
#include <stdexcept>
22

  
21 23
#include "HostPool.h"
22 24
#include "ClusterPool.h"
23 25
#include "NebulaLog.h"
24 26

  
27
/* -------------------------------------------------------------------------- */
28
/* -------------------------------------------------------------------------- */
29

  
25 30
int HostPool::init_cb(void *nil, int num, char **values, char **names)
26 31
{
27 32
    if ( num != 2 || values == 0 || values[0] == 0 )
......
51 56

  
52 57
    if (cluster_pool.cluster_names.empty())
53 58
    {
54
        string default_name = "default";
55

  
56
        // Insert the "default" cluster
57
        int rc = cluster_pool.insert(0, default_name, db);
59
        int rc = cluster_pool.insert(0, ClusterPool::DEFAULT_CLUSTER_NAME, db);
58 60

  
59 61
        if(rc != 0)
60 62
        {
61
            NebulaLog::log("HOST",Log::ERROR,
62
                "Cluster pool is empty but couldn't create default cluster.");
63
            throw runtime_error("Could not create default cluster HostPool");
63 64
        }
64 65
    }
65 66
}
......
184 185
{
185 186
    int                         rc;
186 187
    map<int, string>::iterator  it;
188
    string                      cluster_name;
187 189

  
188 190
    it = cluster_pool.cluster_names.find(clid);
189 191

  
192
    if ( it == cluster_pool.cluster_names.end() )
193
    {
194
        return -1;
195
    }
196

  
197
    cluster_name = it->second;
198

  
190 199
    // try to drop the cluster from the pool and DB
191 200
    rc = cluster_pool.drop(clid, db);
192 201

  
193 202
    // Move the hosts assigned to the deleted cluster to the default one
194 203
    if( rc == 0 )
195 204
    {
196
        // Search the hosts assigned to this cluster
197 205
        Host*                   host;
198 206
        vector<int>             hids;
199 207
        vector<int>::iterator   hid_it;
200 208

  
201
        string cluster_name = it->second;
202
        string where        = "cluster = '" + cluster_name + "'";
203

  
209
        string                  where = "cluster = '" + cluster_name + "'";
204 210

  
205 211
        search(hids, Host::table, where);
206 212

  
......
208 214
        {
209 215
            host = get(*hid_it, true);
210 216

  
211
            remove_cluster(host);
217
            if ( host == 0 )
218
            {
219
                continue;
220
            }
221

  
222
            set_default_cluster(host);
223

  
212 224
            update(host);
213 225

  
214 226
            host->unlock();

Also available in: Unified diff