Back to index

nordugrid-arc-nox  1.1.0~rc6
TargetRetrieverUNICORE.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 <utility>
00008 
00009 #include <arc/ArcConfig.h>
00010 #include <arc/message/MCC.h>
00011 #include <arc/Logger.h>
00012 #include <arc/StringConv.h>
00013 #include <arc/Thread.h>
00014 #include <arc/URL.h>
00015 #include <arc/XMLNode.h>
00016 #include <arc/client/ExecutionTarget.h>
00017 #include <arc/client/TargetGenerator.h>
00018 
00019 #include "UNICOREClient.h"
00020 #include "TargetRetrieverUNICORE.h"
00021 
00022 namespace Arc {
00023 
00024   struct ThreadArg {
00025     TargetGenerator *mom;
00026     const UserConfig *usercfg;
00027     URL url;
00028     int targetType;
00029     int detailLevel;
00030   };
00031 
00032   ThreadArg* TargetRetrieverUNICORE::CreateThreadArg(TargetGenerator& mom,
00033                                                      int targetType,
00034                                                      int detailLevel) {
00035     ThreadArg *arg = new ThreadArg;
00036     arg->mom = &mom;
00037     arg->usercfg = &usercfg;
00038     arg->url = url;
00039     arg->targetType = targetType;
00040     arg->detailLevel = detailLevel;
00041     return arg;
00042   }
00043 
00044   Logger TargetRetrieverUNICORE::logger(TargetRetriever::logger, "UNICORE");
00045 
00046   TargetRetrieverUNICORE::TargetRetrieverUNICORE(const UserConfig& usercfg,
00047                                                  const URL& url, ServiceType st)
00048     : TargetRetriever(usercfg, url, st, "UNICORE") {}
00049 
00050   TargetRetrieverUNICORE::~TargetRetrieverUNICORE() {}
00051 
00052   Plugin* TargetRetrieverUNICORE::Instance(PluginArgument *arg) {
00053     TargetRetrieverPluginArgument *trarg =
00054       dynamic_cast<TargetRetrieverPluginArgument*>(arg);
00055     if (!trarg)
00056       return NULL;
00057     return new TargetRetrieverUNICORE(*trarg, *trarg, *trarg);
00058   }
00059 
00060   void TargetRetrieverUNICORE::GetTargets(TargetGenerator& mom, int targetType,
00061                                           int detailLevel) {
00062 
00063     logger.msg(INFO, "TargetRetriverUNICORE initialized with %s service url: %s",
00064                tostring(serviceType), url.str());
00065 
00066     switch (serviceType) {
00067     case COMPUTING:
00068       if (mom.AddService(url)) {
00069         ThreadArg *arg = CreateThreadArg(mom, targetType, detailLevel);
00070         if (!CreateThreadFunction(&InterrogateTarget, arg)) {
00071           delete arg;
00072           mom.RetrieverDone();
00073         }
00074       }
00075       break;
00076     case INDEX:
00077       if (mom.AddIndexServer(url)) {
00078         ThreadArg *arg = CreateThreadArg(mom, targetType, detailLevel);
00079         if (!CreateThreadFunction(&QueryIndex, arg)) {
00080           delete arg;
00081           mom.RetrieverDone();
00082         }
00083       }
00084       break;
00085     }
00086   }
00087 
00088   void TargetRetrieverUNICORE::QueryIndex(void *arg) {
00089     ThreadArg *thrarg = (ThreadArg*)arg;
00090     TargetGenerator& mom = *thrarg->mom;
00091     const UserConfig& usercfg = *thrarg->usercfg;
00092 
00093     URL& url = thrarg->url;
00094     MCCConfig cfg;
00095     usercfg.ApplyToConfig(cfg);
00096     UNICOREClient uc(url, cfg, usercfg.Timeout());
00097     std::list< std::pair<URL, ServiceType> > beses;
00098     uc.listTargetSystemFactories(beses);
00099     for (std::list< std::pair<URL, ServiceType> >::iterator it = beses.begin(); it != beses.end(); it++) {
00100       TargetRetrieverUNICORE r(usercfg, it->first, it->second);
00101       r.GetTargets(mom, thrarg->targetType, thrarg->detailLevel);
00102     }
00103 
00104     delete thrarg;
00105     mom.RetrieverDone();
00106   }
00107 
00108   void TargetRetrieverUNICORE::InterrogateTarget(void *arg) {
00109     ThreadArg *thrarg = (ThreadArg*)arg;
00110     TargetGenerator& mom = *thrarg->mom;
00111     const UserConfig& usercfg = *thrarg->usercfg;
00112 
00113     URL& url = thrarg->url;
00114     MCCConfig cfg;
00115     usercfg.ApplyToConfig(cfg);
00116     UNICOREClient uc(url, cfg, usercfg.Timeout());
00117     std::string status;
00118     if (!uc.sstat(status)) {
00119       delete thrarg;
00120       mom.RetrieverDone();
00121       return;
00122     }
00123 
00124 
00125     ExecutionTarget target;
00126     target.GridFlavour = "UNICORE";
00127     target.Cluster = url;
00128     target.url = url;
00129     target.InterfaceName = "BES";
00130     target.Implementor = "UNICORE";
00131     target.Implementation = Software("UNICORE");
00132     target.HealthState = "ok";
00133     target.DomainName = url.Host();
00134 
00135 
00136     delete thrarg;
00137     mom.AddTarget(target);
00138     mom.RetrieverDone();
00139   }
00140 
00141 } // namespace Arc