39 #include "BESStopWatch.h"
41 #include "BESSyntaxUserError.h"
42 #include "BESNotFoundError.h"
43 #include "BESInternalError.h"
46 #include "TheBESKeys.h"
47 #include "AllowedHosts.h"
48 #include "BESContextManager.h"
49 #include "CurlUtils.h"
50 #include "HttpUtils.h"
51 #include "RemoteResource.h"
54 #include "NgapContainer.h"
56 #include "NgapNames.h"
58 #define prolog std::string("NgapContainer::").append(__func__).append("() - ")
75 NgapContainer::NgapContainer(
const string &sym_name,
76 const string &real_name,
79 d_dmrpp_rresource(0) {
84 void NgapContainer::initialize()
86 BESDEBUG(MODULE, prolog <<
"BEGIN (obj_addr: "<< (
void *)
this <<
")" << endl);
88 BESDEBUG(MODULE, prolog <<
"real_name: "<<
get_real_name() << endl);
97 string uid = BESContextManager::TheManager()->
get_context(EDL_UID_KEY, found);
98 BESDEBUG(MODULE, prolog <<
"EDL_UID_KEY(" << EDL_UID_KEY <<
"): " << uid << endl);
106 BESDEBUG(MODULE, prolog <<
"END (obj_addr: "<< (
void *)
this <<
")" << endl);
115 d_dmrpp_rresource(copy_from.d_dmrpp_rresource) {
116 BESDEBUG(MODULE, prolog <<
"BEGIN object address: "<< (
void *)
this <<
" Copying from: " << (
void *) ©_from << endl);
119 if (d_dmrpp_rresource) {
120 string err = (string)
"The Container has already been accessed, "
121 +
"can not create a copy of this container.";
124 BESDEBUG(MODULE, prolog <<
"object address: "<< (
void *)
this << endl);
128 if (copy_to.d_dmrpp_rresource) {
129 string err = (string)
"The Container has already been accessed, "
130 +
"can not duplicate this resource.";
133 BESDEBUG(MODULE, prolog <<
"BEGIN object address: "<< (
void *)
this <<
" Copying to: " << (
void *) ©_to << endl);
134 copy_to.d_dmrpp_rresource = d_dmrpp_rresource;
141 _duplicate(*container);
142 BESDEBUG(MODULE, prolog <<
"object address: "<< (
void *)
this <<
" to: " << (
void *)container << endl);
146 NgapContainer::~NgapContainer() {
147 BESDEBUG(MODULE, prolog <<
"BEGIN object address: "<< (
void *)
this << endl);
148 if (d_dmrpp_rresource) {
151 BESDEBUG(MODULE, prolog <<
"END object address: "<< (
void *)
this << endl);
162 BESDEBUG(MODULE, prolog <<
"BEGIN (obj_addr: "<< (
void *)
this <<
")" << endl);
168 string dmrpp_url_str = data_access_url_str +
".dmrpp";
171 string missing_data_url_str = data_access_url_str +
".missing";
173 BESDEBUG(MODULE, prolog <<
" data_access_url: " << data_access_url_str << endl);
174 BESDEBUG(MODULE, prolog <<
" dmrpp_url: " << dmrpp_url_str << endl);
175 BESDEBUG(MODULE, prolog <<
"missing_data_url: " << missing_data_url_str << endl);
178 string trusted_url_hack=
"\" dmrpp:trust=\"true";
179 string data_access_url_with_trusted_attr_str = data_access_url_str + trusted_url_hack;
180 string dmrpp_url_with_trusted_attr_str = dmrpp_url_str + trusted_url_hack;
181 string missing_data_url_with_trusted_attr_str = missing_data_url_str + trusted_url_hack;
183 BESDEBUG(MODULE, prolog <<
" data_access_url_with_trusted_attr_str: " << data_access_url_with_trusted_attr_str << endl);
184 BESDEBUG(MODULE, prolog <<
" dmrpp_url_with_trusted_attr_str: " << dmrpp_url_with_trusted_attr_str << endl);
185 BESDEBUG(MODULE, prolog <<
"missing_data_url_with_trusted_attr_str: " << missing_data_url_with_trusted_attr_str << endl);
191 if (!d_dmrpp_rresource) {
192 BESDEBUG(MODULE, prolog <<
"Building new RemoteResource (dmr++)." << endl);
193 map<string,string> content_filters;
194 if (inject_data_url()) {
195 content_filters.insert(pair<string,string>(DATA_ACCESS_URL_KEY,data_access_url_with_trusted_attr_str));
196 content_filters.insert(pair<string,string>(MISSING_DATA_ACCESS_URL_KEY,missing_data_url_with_trusted_attr_str));
198 shared_ptr<http::url> dmrpp_url(
new http::url(dmrpp_url_str,
true));
202 if (BESISDEBUG(MODULE) ||
BESDebug::IsSet(TIMING_LOG_KEY) || BESLog::TheLog()->is_verbose()){
203 besTimer.
start(
"DMR++ retrieval: "+ dmrpp_url->str());
207 BESDEBUG(MODULE, prolog <<
"Retrieved remote resource: " << dmrpp_url->str() << endl);
213 BESDEBUG(MODULE, prolog <<
"Using local cache file: " << cachedResource << endl);
215 type = d_dmrpp_rresource->
getType();
217 BESDEBUG(MODULE, prolog <<
"Type: " << type << endl);
218 BESDEBUG(MODULE, prolog <<
"Done retrieving: " << dmrpp_url_str <<
" returning cached file " << cachedResource << endl);
219 BESDEBUG(MODULE, prolog <<
"END (obj_addr: "<< (
void *)
this <<
")" << endl);
221 return cachedResource;
234 if (d_dmrpp_rresource) {
235 BESDEBUG(MODULE, prolog <<
"Releasing RemoteResource" << endl);
236 delete d_dmrpp_rresource;
237 d_dmrpp_rresource = 0;
240 BESDEBUG(MODULE, prolog <<
"Done releasing Ngap response" << endl);
252 strm << BESIndent::LMarg <<
"NgapContainer::dump - (" << (
void *)
this
256 if (d_dmrpp_rresource) {
257 strm << BESIndent::LMarg <<
"RemoteResource.getCacheFileName(): " << d_dmrpp_rresource->
getCacheFileName()
259 strm << BESIndent::LMarg <<
"response headers: ";
264 vector<string>::const_iterator i = hdrs->begin();
265 vector<string>::const_iterator e = hdrs->end();
266 for (; i != e; i++) {
267 string hdr_line = (*i);
268 strm << BESIndent::LMarg << hdr_line << endl;
270 BESIndent::UnIndent();
272 strm <<
"none" << endl;
275 strm << BESIndent::LMarg <<
"response not yet obtained" << endl;
277 BESIndent::UnIndent();
280 bool NgapContainer::inject_data_url(){
285 if (found && key_value ==
"true") {
288 BESDEBUG(MODULE, prolog <<
"NGAP_INJECT_DATA_URL_KEY(" << NGAP_INJECT_DATA_URL_KEY <<
"): " << result << endl);
A container is something that holds data. E.G., a netcdf file or a database entry.
void set_container_type(const std::string &type)
set the type of data that this container represents, such as cedar or netcdf.
std::string get_symbolic_name() const
retrieve the symbolic name for this container
virtual void dump(std::ostream &strm) const
dumps information about this object
void set_real_name(const std::string &real_name)
set the real name for this container, such as a file name if reading a data file.
std::string get_container_type() const
retrieve the type of data this container holds, such as cedar or netcdf.
void set_relative_name(const std::string &relative)
Set the relative name of the object in this container.
void _duplicate(BESContainer ©_to)
duplicate this instance into the passed container
std::string get_real_name() const
retrieve the real name for this container, such as a file name.
virtual std::string get_context(const std::string &name, bool &found)
retrieve the value of the specified context from the BES
static bool IsSet(const std::string &flagName)
see if the debug context flagName is set to true
exception thrown if internal error encountered
virtual bool start(std::string name)
void get_value(const std::string &s, std::string &val, bool &found)
Retrieve the value of a given key, if set.
static TheBESKeys * TheKeys()
std::string getCacheFileName()
std::vector< std::string > * getResponseHeaders()
std::string convert_ngap_resty_path_to_data_access_url(const std::string &restified_path, const std::string &uid="")
Converts an NGAP restified granule path into a CMR metadata query for the granule.
virtual void dump(std::ostream &strm) const
dumps information about this object
virtual std::string access()
access the remote target response by making the remote request
virtual BESContainer * ptr_duplicate()
pure abstract method to duplicate this instances of BESContainer
virtual bool release()
release the resources