Back to index

nordugrid-arc-nox  1.1.0~rc6
RandomBroker.cpp
Go to the documentation of this file.
00001 // -*- indent-tabs-mode: nil -*-
00002 
00003 #ifdef HAVE_CONFIG_H
00004 #include <config.h>
00005 #endif
00006 
00007 #include <cstdlib>
00008 #include <algorithm>
00009 
00010 #include <arc/client/ExecutionTarget.h>
00011 
00012 #include "RandomBroker.h"
00013 
00014 namespace Arc {
00015 
00016   RandomBroker::RandomBroker(const UserConfig& usercfg)
00017     : Broker(usercfg) {}
00018 
00019   RandomBroker::~RandomBroker() {}
00020 
00021   Plugin* RandomBroker::Instance(PluginArgument *arg) {
00022     BrokerPluginArgument *brokerarg = dynamic_cast<BrokerPluginArgument*>(arg);
00023     if (!brokerarg)
00024       return NULL;
00025     return new RandomBroker(*brokerarg);
00026   }
00027 
00028   void RandomBroker::SortTargets() {
00029 
00030     std::list<ExecutionTarget*>::iterator iter = PossibleTargets.begin();
00031 
00032     logger.msg(VERBOSE, "Matching against job description, following targets possible for RandomBroker: %d", PossibleTargets.size());
00033 
00034     for (int i = 1; iter != PossibleTargets.end(); iter++, i++)
00035       logger.msg(VERBOSE, "%d. Cluster: %s; Queue: %s", i, (*iter)->DomainName, (*iter)->ComputingShareName);
00036 
00037     int i, j;
00038     std::srand(time(NULL));
00039 
00040     for (unsigned int k = 1; k < 2 * (std::rand() % PossibleTargets.size()) + 1; k++) {
00041       std::list<ExecutionTarget*>::iterator itI = PossibleTargets.begin();
00042       std::list<ExecutionTarget*>::iterator itJ = PossibleTargets.begin();
00043       for (int i = rand() % PossibleTargets.size(); i > 0; i--)
00044         itI++;
00045       for (int i = rand() % PossibleTargets.size(); i > 0; i--)
00046         itJ++;
00047       std::iter_swap(itI, itJ);
00048     }
00049 
00050     logger.msg(VERBOSE, "Best targets are: %d", PossibleTargets.size());
00051 
00052     iter = PossibleTargets.begin();
00053 
00054     for (int i = 1; iter != PossibleTargets.end(); iter++, i++)
00055       logger.msg(VERBOSE, "%d. Cluster: %s; Queue: %s", i, (*iter)->DomainName, (*iter)->ComputingShareName);
00056 
00057     TargetSortingDone = true;
00058   }
00059 
00060 } // namespace Arc