~ubuntu-branches/ubuntu/utopic/nordugrid-arc/utopic

« back to all changes in this revision

Viewing changes to src/hed/acc/SER/ServiceEndpointRetrieverPluginEMIR.cpp

  • Committer: Package Import Robot
  • Author(s): Mattias Ellert
  • Date: 2014-05-01 20:51:02 UTC
  • mfrom: (1.1.11)
  • Revision ID: package-import@ubuntu.com-20140501205102-icy9t3348uxobyx7
Tags: 4.1.0-1
* 4.1.0 Release
* Call dh_autoreconf to support ppc64le (Closes: #744639)

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
    return false;
32
32
  }
33
33
 
34
 
  static URL CreateURL(std::string service, int entryPerMessage, int skipOffset) {
35
 
    std::string::size_type pos1 = service.find("://");
36
 
    if (pos1 == std::string::npos) {
37
 
      service = "http://" + service;
38
 
      pos1 = service.find("://");
39
 
    } else {
40
 
      std::string proto = lower(service.substr(0,pos1));
41
 
      if((proto != "http") && (proto != "https")) return URL();
42
 
    }
43
 
    /* 
44
 
     *  URL structure and response format: 
45
 
     *    * in JSON: http[s]://<host_name>:<port>/services?limit=<nr_of_entries_per_message>[&skip=<offset>]
46
 
     *
47
 
     *    * in XML:  http[s]://<host_name>:<port>/services/query.xml?limit=<nr_of_entries_per_message>[&skip=<offset>]
48
 
     */
49
 
    std::string::size_type pos2 = service.find(":", pos1 + 3);
50
 
    std::string::size_type pos3 = service.find("/", pos1 + 3);
51
 
    if (pos2 == std::string::npos && pos3 == std::string::npos) {
52
 
      service += ":9126"; // Default port seems to be 9126.
53
 
    }
54
 
    if (pos3 == std::string::npos || pos3 == service.size()-1) {
55
 
      service += "/services/query.xml";
56
 
    }
57
 
    URL serviceURL(service);
58
 
 
59
 
    if (entryPerMessage > 0) serviceURL.AddHTTPOption("limit", tostring(entryPerMessage));
60
 
    if (skipOffset > 0)      serviceURL.AddHTTPOption("skip",  tostring(skipOffset));
61
 
    return serviceURL;
62
 
  }
63
 
 
64
34
  EndpointQueryingStatus ServiceEndpointRetrieverPluginEMIR::Query(const UserConfig& uc,
65
35
                                                                   const Endpoint& rEndpoint,
66
36
                                                                   std::list<Endpoint>& seList,
71
41
    MCCConfig cfg;
72
42
    uc.ApplyToConfig(cfg);
73
43
    
 
44
    if (isEndpointNotSupported(rEndpoint)) {
 
45
      return EndpointQueryingStatus::FAILED;
 
46
    }
 
47
    URL url((rEndpoint.URLString.find("://") == std::string::npos ? "http://" : "") + rEndpoint.URLString, false, 9126, "/services/query.xml");
 
48
    if (!url) {
 
49
      s = EndpointQueryingStatus::FAILED;
 
50
      return s;
 
51
    }
 
52
 
74
53
    // Limitation: Max number of services the below loop will fetch, according to parameters:
75
54
    // ServiceEndpointRetrieverPluginEMIR::maxEntries * 100 = 500.000 (currently)
76
55
    for (int iAvoidInfiniteLoop = 0; iAvoidInfiniteLoop < 100; ++iAvoidInfiniteLoop) {
77
 
      URL url(CreateURL(rEndpoint.URLString, maxEntries, currentSkip));
78
 
      if (!url) {
79
 
        s = EndpointQueryingStatus::FAILED;
80
 
        return s;
81
 
      }
 
56
      if (maxEntries > 0)  url.AddHTTPOption("limit", tostring(maxEntries),  true);
 
57
      if (currentSkip > 0) url.AddHTTPOption("skip",  tostring(currentSkip), true);
 
58
 
82
59
      // increment the starting point of the fetched DB 
83
60
      currentSkip += maxEntries;
84
61