35#include "BESStopWatch.h"
37#include "BESSyntaxUserError.h"
38#include "BESInternalError.h"
40#include "TheBESKeys.h"
41#include "BESContextManager.h"
43#include "RemoteResource.h"
46#include "NgapContainer.h"
50#define prolog std::string("NgapContainer::").append(__func__).append("() - ")
67NgapContainer::NgapContainer(
const string &sym_name,
68 const string &real_name,
71 d_dmrpp_rresource(nullptr) {
76void NgapContainer::initialize()
78 BESDEBUG(MODULE, prolog <<
"BEGIN (obj_addr: "<< (
void *)
this <<
")" << endl);
80 BESDEBUG(MODULE, prolog <<
"real_name: "<<
get_real_name() << endl);
89 string uid = BESContextManager::TheManager()->
get_context(EDL_UID_KEY, found);
90 BESDEBUG(MODULE, prolog <<
"EDL_UID_KEY(" << EDL_UID_KEY <<
"): " << uid << endl);
98 BESDEBUG(MODULE, prolog <<
"END (obj_addr: "<< (
void *)
this <<
")" << endl);
107 d_dmrpp_rresource(copy_from.d_dmrpp_rresource) {
108 BESDEBUG(MODULE, prolog <<
"BEGIN object address: "<< (
void *)
this <<
" Copying from: " << (
void *) ©_from << endl);
111 if (d_dmrpp_rresource) {
112 string err = (string)
"The Container has already been accessed, "
113 +
"can not create a copy of this container.";
116 BESDEBUG(MODULE, prolog <<
"object address: "<< (
void *)
this << endl);
120 if (copy_to.d_dmrpp_rresource) {
121 string err = (string)
"The Container has already been accessed, "
122 +
"can not duplicate this resource.";
125 BESDEBUG(MODULE, prolog <<
"BEGIN object address: "<< (
void *)
this <<
" Copying to: " << (
void *) ©_to << endl);
126 copy_to.d_dmrpp_rresource = d_dmrpp_rresource;
133 _duplicate(*container);
134 BESDEBUG(MODULE, prolog <<
"object address: "<< (
void *)
this <<
" to: " << (
void *)container << endl);
138NgapContainer::~NgapContainer() {
139 BESDEBUG(MODULE, prolog <<
"BEGIN object address: "<< (
void *)
this << endl);
140 if (d_dmrpp_rresource) {
143 BESDEBUG(MODULE, prolog <<
"END object address: "<< (
void *)
this << endl);
154 BESDEBUG(MODULE, prolog <<
"BEGIN (obj_addr: "<< (
void *)
this <<
")" << endl);
160 string dmrpp_url_str = data_access_url_str +
".dmrpp";
163 string missing_data_url_str = data_access_url_str +
".missing";
165 BESDEBUG(MODULE, prolog <<
" data_access_url: " << data_access_url_str << endl);
166 BESDEBUG(MODULE, prolog <<
" dmrpp_url: " << dmrpp_url_str << endl);
167 BESDEBUG(MODULE, prolog <<
"missing_data_url: " << missing_data_url_str << endl);
169 string href=
"href=\"";
170 string trusted_url_hack=
"\" dmrpp:trust=\"true\"";
172 string data_access_url_key = href + DATA_ACCESS_URL_KEY +
"\"";
173 BESDEBUG(MODULE, prolog <<
" data_access_url_key: " << data_access_url_key << endl);
175 string data_access_url_with_trusted_attr_str = href + data_access_url_str + trusted_url_hack;
176 BESDEBUG(MODULE, prolog <<
" data_access_url_with_trusted_attr_str: " << data_access_url_with_trusted_attr_str << endl);
178 string missing_data_access_url_key = href + MISSING_DATA_ACCESS_URL_KEY +
"\"";
179 BESDEBUG(MODULE, prolog <<
" missing_data_access_url_key: " << missing_data_access_url_key << endl);
181 string missing_data_url_with_trusted_attr_str = href + missing_data_url_str + trusted_url_hack;
182 BESDEBUG(MODULE, prolog <<
"missing_data_url_with_trusted_attr_str: " << missing_data_url_with_trusted_attr_str << endl);
188 if (!d_dmrpp_rresource) {
189 BESDEBUG(MODULE, prolog <<
"Building new RemoteResource (dmr++)." << endl);
190 map<string,string> content_filters;
191 if (inject_data_url()) {
192 content_filters.insert(pair<string,string>(data_access_url_key, data_access_url_with_trusted_attr_str));
193 content_filters.insert(pair<string,string>(missing_data_access_url_key, missing_data_url_with_trusted_attr_str));
195 shared_ptr<http::url> dmrpp_url(
new http::url(dmrpp_url_str,
true));
199 if (BESISDEBUG(MODULE) ||
BESDebug::IsSet(TIMING_LOG_KEY) || BESLog::TheLog()->is_verbose()){
200 besTimer.
start(
"DMR++ retrieval: "+ dmrpp_url->str());
204 BESDEBUG(MODULE, prolog <<
"Retrieved remote resource: " << dmrpp_url->str() << endl);
210 BESDEBUG(MODULE, prolog <<
"Using local cache file: " << cachedResource << endl);
212 type = d_dmrpp_rresource->
getType();
214 BESDEBUG(MODULE, prolog <<
"Type: " << type << endl);
215 BESDEBUG(MODULE, prolog <<
"Done retrieving: " << dmrpp_url_str <<
" returning cached file " << cachedResource << endl);
216 BESDEBUG(MODULE, prolog <<
"END (obj_addr: "<< (
void *)
this <<
")" << endl);
218 return cachedResource;
231 if (d_dmrpp_rresource) {
232 BESDEBUG(MODULE, prolog <<
"Releasing RemoteResource" << endl);
233 delete d_dmrpp_rresource;
234 d_dmrpp_rresource = 0;
237 BESDEBUG(MODULE, prolog <<
"Done releasing Ngap response" << endl);
249 strm << BESIndent::LMarg <<
"NgapContainer::dump - (" << (
void *)
this
253 if (d_dmrpp_rresource) {
254 strm << BESIndent::LMarg <<
"RemoteResource.getCacheFileName(): " << d_dmrpp_rresource->
getCacheFileName()
256 strm << BESIndent::LMarg <<
"response headers: ";
261 vector<string>::const_iterator i = hdrs->begin();
262 vector<string>::const_iterator e = hdrs->end();
263 for (; i != e; i++) {
264 string hdr_line = (*i);
265 strm << BESIndent::LMarg << hdr_line << endl;
267 BESIndent::UnIndent();
269 strm <<
"none" << endl;
272 strm << BESIndent::LMarg <<
"response not yet obtained" << endl;
274 BESIndent::UnIndent();
277bool NgapContainer::inject_data_url(){
282 if (found && key_value ==
"true") {
285 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