Newer
Older
Federico Montesino Pouzols
committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#include "MantidKernel/ComputeResourceInfo.h"
#include "MantidKernel/FacilityInfo.h"
#include "MantidKernel/Logger.h"
#include <Poco/DOM/AutoPtr.h>
#include <Poco/DOM/Element.h>
#include <Poco/DOM/NodeList.h>
#include <Poco/DOM/Text.h>
namespace Mantid {
namespace Kernel {
namespace {
// static logger object
Logger g_log("ComputeResourceInfo");
}
/**
* Construct a compute resource from information found in a facilities
* definition file.
*
* @param f Facility where this (remote) compute resource is available
* @param elem A (Poco::XML::) Element to read the data from
*
* @throw std::runtime_error if name or required attributes are not
* found
*/
ComputeResourceInfo::ComputeResourceInfo(const FacilityInfo *fac,
const Poco::XML::Element *elem)
: m_facility(fac) {
m_name = elem->getAttribute("name");
if (m_name.empty()) {
std::string elemStr = "";
if (elem)
elemStr = elem->innerText();
throw std::runtime_error(
"The compute resource name is not defined, at element: " + elemStr);
}
m_managerType = "MantidWebServiceAPI";
std::string type = elem->getAttribute("jobManagerType");
if (!type.empty()) {
m_managerType = type;
}
const std::string baseTag = "baseURL";
Poco::AutoPtr<Poco::XML::NodeList> nl = elem->getElementsByTagName(baseTag);
if (!nl || nl->length() != 1 || !nl->item(0) || !nl->item(0)->childNodes()) {
g_log.error("Failed to get base URL for remote compute resource '" +
m_name + "'");
throw std::runtime_error("Remote compute resources must have exactly one "
"baseURL tag. It was not found for the resource "
"'" +
m_name + "'");
} else {
nl = nl->item(0)->childNodes();
if (nl->length() > 0) {
Poco::XML::Text *txt = dynamic_cast<Poco::XML::Text *>(nl->item(0));
if (txt) {
m_baseURL = txt->getData();
} else {
g_log.error("Failed to get base URL for remote compute resource '" +
m_name + "'. The " + baseTag + " tag seems empty!");
throw std::runtime_error(
"Remote compute resources must have exactly one "
"baseURL tag containing a URL string. A tag was found for the "
"resource "
"'" +
m_name + "', but it seems empty!");
}
}
}
}
std::string ComputeResourceInfo::name() const { return m_name; }
std::string ComputeResourceInfo::baseURL() const { return m_baseURL; }
std::string ComputeResourceInfo::remoteJobManagerType() const {
return m_managerType;
}
const FacilityInfo &ComputeResourceInfo::facility() const {
return *m_facility;
}
/**
* Prints the instrument name into an output stream
*
* @param buffer an output stream being written to
* @param cr a ComputeResourceInfo object to print
*
* @return reference to the output stream being written to
*/
std::ostream &operator<<(std::ostream &buffer, const ComputeResourceInfo &cr) {
buffer << "'" + cr.name() + "', at '" + cr.baseURL() + "', of type '" +
cr.remoteJobManagerType();
return buffer;
}
} // namespace Kernel
} // namespace Mantid