1
// -*- indent-tabs-mode: nil -*-
7
#include <arc/ArcConfig.h>
8
#include <arc/Logger.h>
9
#include <arc/StringConv.h>
10
#include <arc/Thread.h>
12
#include <arc/XMLNode.h>
13
#include <arc/client/TargetGenerator.h>
14
#include <arc/message/MCC.h>
15
#include <arc/data/DataHandle.h>
16
#include <arc/client/ClientInterface.h>
17
#include <arc/message/PayloadSOAP.h>
18
#include "TargetRetrieverEMIREG.h"
20
#include "TargetRetrieverEMIREG.h"
24
class ThreadArgEMIREG {
27
const UserConfig *usercfg;
29
bool isExecutionTarget;
31
std::map<middlewareType, std::string> query_path;
34
ThreadArgEMIREG* TargetRetrieverEMIREG::CreateThreadArg(TargetGenerator& mom,
35
bool isExecutionTarget) {
36
ThreadArgEMIREG *arg = new ThreadArgEMIREG;
38
arg->usercfg = &usercfg;
40
arg->isExecutionTarget = isExecutionTarget;
41
arg->flavour = flavour;
42
arg->query_path = queryPath;
46
Logger TargetRetrieverEMIREG::logger(Logger::getRootLogger(),
47
"TargetRetriever.EMIREG");
49
static URL CreateURL(std::string service, ServiceType /* st */) {
50
std::string::size_type pos1 = service.find("://");
51
if (pos1 == std::string::npos) {
52
service = "https://" + service;
54
std::string proto = lower(service.substr(0,pos1));
55
if((proto != "http") && (proto != "https")) return URL();
57
// Default port other than 443?
62
TargetRetrieverEMIREG::TargetRetrieverEMIREG(const UserConfig& usercfg,
63
const std::string& service,
65
const std::string& flav)
66
: TargetRetriever(usercfg, CreateURL(service, st), st, flav) {
67
queryPath.insert(std::pair<middlewareType, std::string>(ARC0, "services/query.xml?Service_Type=org.nordugrid.arc-classic"));
68
queryPath.insert(std::pair<middlewareType, std::string>(ARC1, "services/query.xml?Service_Type=org.nordugrid.execution.arex"));
69
queryPath.insert(std::pair<middlewareType, std::string>(GLITE, "services/query.xml?Service_Type=org.ogf.bes"));
70
queryPath.insert(std::pair<middlewareType, std::string>(UNICORE, "services/query.xml?Service_Type=eu.unicore.tsf"));
71
queryPath.insert(std::pair<middlewareType, std::string>(EMIES, "services/query.xml?Service_Type=eu.eu-emi.emies"));
74
TargetRetrieverEMIREG::~TargetRetrieverEMIREG() {}
76
Plugin* TargetRetrieverEMIREG::Instance(PluginArgument *arg) {
77
TargetRetrieverPluginArgument *trarg =
78
dynamic_cast<TargetRetrieverPluginArgument*>(arg);
81
return new TargetRetrieverEMIREG(*trarg, *trarg, *trarg);
84
void TargetRetrieverEMIREG::GetExecutionTargets(TargetGenerator& mom) {
85
logger.msg(VERBOSE, "TargetRetriver%s initialized with %s service url: %s",
86
flavour, tostring(serviceType), url.str());
89
for (std::list<std::string>::const_iterator it =
90
usercfg.GetRejectedServices(serviceType).begin();
91
it != usercfg.GetRejectedServices(serviceType).end(); it++) {
92
std::string::size_type pos = it->find(":");
93
if (pos != std::string::npos) {
94
std::string flav = it->substr(0, pos);
95
if (flav == flavour || flav == "*" || flav.empty())
96
if (url == CreateURL(it->substr(pos + 1), serviceType)) {
97
logger.msg(INFO, "Rejecting service: %s", url.str());
103
if (serviceType == INDEX && flavour != "EMIREG") return;
104
if ( (serviceType == COMPUTING && mom.AddService(flavour, url)) ||
105
(serviceType == INDEX && mom.AddIndexServer(flavour, url))) {
106
ThreadArgEMIREG *arg = CreateThreadArg(mom, true);
107
if (!CreateThreadFunction( &QueryIndex, arg, &(mom.ServiceCounter()))) {
113
void TargetRetrieverEMIREG::QueryIndex(void *arg) {
114
ThreadArgEMIREG *thrarg = (ThreadArgEMIREG*)arg;
116
std::string EMIREG_URL = thrarg->url.str();
117
if ( EMIREG_URL.at(EMIREG_URL.length()-1) != '/' ){
122
thrarg->usercfg->ApplyToConfig(cfg);
124
std::list< std::pair<URL, ServiceType> > services;
126
std::map<middlewareType, std::string>::const_iterator it;
127
for ( it=thrarg->query_path.begin(); it != thrarg->query_path.end(); it++ ){
128
// create a query path
129
Arc::URL url(EMIREG_URL+(*it).second);
130
ClientHTTP httpclient(cfg, url);
131
httpclient.RelativeURI(true);
133
PayloadRaw http_request;
134
PayloadRawInterface *http_response = NULL;
135
HTTPClientInfo http_info;
136
std::multimap<std::string, std::string> http_attributes;
138
Arc::MCC_Status status;
140
TargetRetrieverLoader tartgetloader;
142
// send query message to the EMIRegistry
143
status=httpclient.process("GET", http_attributes, &http_request, &http_info, &http_response);
145
if ( http_info.code == 200 ) {
146
Arc::XMLNode resp_xml(http_response->Content());
147
for (int i=0; i<resp_xml.Size(); i++) {
148
std::string service_url = (std::string)resp_xml["Service"][i]["Endpoint"]["URL"];
149
services.push_back( std::pair<URL, ServiceType>(Arc::URL(service_url), COMPUTING) );
150
std::string mtype = "";
169
logger.msg(ERROR, "Wrong middleware type: %s", it->first);
173
r = tartgetloader.load(mtype, *(thrarg->usercfg), service_url, COMPUTING);
174
if (thrarg->isExecutionTarget) {
175
r->GetExecutionTargets(*(thrarg->mom));
179
if ( i == resp_xml.Size()-1 ){
181
"Found %u %s execution services from the index service at %s",
182
resp_xml.Size(), mtype, thrarg->url.str());
189
//TODO: where can remove the "r" memory place?
194
"Found %u execution services from the index service at %s",
195
services.size(), thrarg->url.str());