Revision 6368bb51 src/market/MarketPlaceAppPool.cc

View differences:

src/market/MarketPlaceAppPool.cc
128 128

  
129 129
    *oid = PoolSQL::allocate(mp, error_str);
130 130

  
131
    // ------------------------------------------------------------------------
132
    // Insert id into map_check
133
    // --------------------------------------------------------------------------
134
    insert_map_check(name);
135

  
136 131
    return *oid;
137 132

  
138 133
error_duplicated:
......
188 183
        return 0;
189 184
    }
190 185

  
191
    drop_map_check(objsql->get_name());
192

  
193 186
    return PoolSQL::drop(objsql, error_msg);
194 187
}
195 188

  
......
197 190
/* -------------------------------------------------------------------------- */
198 191

  
199 192
int MarketPlaceAppPool::import(const std::string& t64, int mp_id,
200
        const std::string& mp_name, std::string& error_str)
193
        const std::string& mp_name, int& app_id, std::string& error_str)
201 194
{
202 195
    // -------------------------------------------------------------------------
203 196
    // Build the marketplace app object
......
236 229

  
237 230
    if( mp_aux != 0 ) //Marketplace app already imported
238 231
    {
239
        reset_map_check(app->name);
232
        app_id = mp_aux->oid;
233

  
240 234
        if ( mp_aux->version != app->version || mp_aux->md5 != app->md5 )
241 235
        {
242 236
            mp_aux->from_template64(t64, error_str);
......
256 250
    // -------------------------------------------------------------------------
257 251
    if (Nebula::instance().is_federation_slave())
258 252
    {
259
        int oid = master_allocate(app, error_str);
253
        app_id = master_allocate(app, error_str);
260 254

  
261 255
        app->lock();
262 256
        delete app;
263 257

  
264
        return oid;
258
        return app_id;
265 259
    }
266
    insert_map_check(app->name);
267
    return PoolSQL::allocate(app, error_str);
260

  
261
    app_id = PoolSQL::allocate(app, error_str);
262

  
263
    return app_id;
268 264
}
269 265

  
270 266
/* -------------------------------------------------------------------------- */
......
316 312

  
317 313
/* -------------------------------------------------------------------------- */
318 314
/* -------------------------------------------------------------------------- */
315
const int MarketPlaceAppPool::MAX_MISSING_MONITORS = 3;
316

  
317
bool MarketPlaceAppPool::test_map_check(int app_id)
318
{
319
    map<int, int>::iterator it = map_check.find(app_id);
320

  
321
    if ( it == map_check.end() )
322
    {
323
        return false;
324
    }
325

  
326
    it->second++;
327

  
328
    bool to_delete = it->second >= MAX_MISSING_MONITORS;
319 329

  
330
    if ( to_delete )
331
    {
332
        map_check.erase(it); 
333
    }
334

  
335
    return to_delete;
336
}
337

  
338
void MarketPlaceAppPool::reset_map_check(int app_id)
339
{
340
    map<int, int>::iterator it = map_check.find(app_id);
341

  
342
    if ( it == map_check.end() )
343
    {
344
        map_check.insert(make_pair(app_id, -1));
345
    }
346
    else
347
    {
348
        it->second = -1;
349
    }
350
}

Also available in: Unified diff