30 #include <BESSyntaxUserError.h>
31 #include <BESInternalError.h>
32 #include <BESNotFoundError.h>
35 #include <TheBESKeys.h>
36 #include <WhiteList.h>
38 #include "CmrContainer.h"
41 #include "RemoteHttpResource.h"
46 #define prolog std::string("CmrContainer::").append(__func__).append("() - ")
60 CmrContainer::CmrContainer(
const string &sym_name,
61 const string &real_name,
const string &type) :
62 BESContainer(sym_name, real_name, type), d_remoteResource(0) {
64 BESDEBUG( MODULE, prolog <<
"BEGIN sym_name: " << sym_name
65 <<
" real_name: " << real_name <<
" type: " << type << endl);
70 BESDEBUG(MODULE, prolog <<
"path: '" << path <<
"' path_elements.size(): " << path_elements.size() << endl);
105 BESDEBUG( MODULE, prolog <<
"END" << endl);
113 BESContainer(copy_from), d_remoteResource(copy_from.d_remoteResource) {
116 if (d_remoteResource) {
117 string err = (string)
"The Container has already been accessed, "
118 +
"can not create a copy of this container.";
124 if (copy_to.d_remoteResource) {
125 string err = (string)
"The Container has already been accessed, "
126 +
"can not duplicate this resource.";
129 copy_to.d_remoteResource = d_remoteResource;
136 _duplicate(*container);
140 CmrContainer::~CmrContainer() {
141 if (d_remoteResource) {
153 BESDEBUG( MODULE, prolog <<
"BEGIN" << endl);
157 BESDEBUG( MODULE, prolog <<
"path: " << path << endl);
159 Granule *granule = CmrUtils::getTemporalFacetGranule(path);
161 throw BESNotFoundError(
"Failed locate a granule associated with the path "+path,__FILE__,__LINE__);
163 string url = granule->getDataAccessUrl();
171 if(!d_remoteResource) {
172 BESDEBUG( MODULE, prolog <<
"Building new RemoteResource." << endl );
176 BESDEBUG( MODULE, prolog <<
"Located remote resource." << endl );
180 BESDEBUG( MODULE, prolog <<
"Using local cache file: " << cachedResource << endl );
182 type = d_remoteResource->
getType();
184 BESDEBUG( MODULE, prolog <<
"Type: " << type << endl );
187 BESDEBUG( MODULE, prolog <<
"Done accessing " <<
get_real_name() <<
" returning cached file " << cachedResource << endl);
188 BESDEBUG( MODULE, prolog <<
"Done accessing " << *
this << endl);
189 BESDEBUG( MODULE, prolog <<
"END" << endl);
191 return cachedResource;
203 BESDEBUG( MODULE, prolog <<
"BEGIN" << endl);
204 if (d_remoteResource) {
205 BESDEBUG( MODULE, prolog <<
"Releasing RemoteResource" << endl);
206 delete d_remoteResource;
207 d_remoteResource = 0;
209 BESDEBUG( MODULE, prolog <<
"END" << endl);
221 strm << BESIndent::LMarg << prolog <<
"(" << (
void *)
this
225 if (d_remoteResource) {
226 strm << BESIndent::LMarg <<
"RemoteResource.getCacheFileName(): " << d_remoteResource->
getCacheFileName()
228 strm << BESIndent::LMarg <<
"response headers: ";
234 vector<string>::const_iterator i = hdrs->begin();
235 vector<string>::const_iterator e = hdrs->end();
236 for (; i != e; i++) {
237 string hdr_line = (*i);
238 strm << BESIndent::LMarg << hdr_line << endl;
240 BESIndent::UnIndent();
242 strm <<
"none" << endl;
245 strm << BESIndent::LMarg <<
"response not yet obtained" << endl;
247 BESIndent::UnIndent();
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.
virtual void dump(std::ostream &strm) const
dumps information about this object
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.
exception thrown if internal error encountered
error thrown if the resource requested cannot be found
static std::vector< std::string > split(const std::string &s, char delim='/', bool skip_empty=true)
Splits the string s into the return vector of tokens using the delimiter delim and skipping empty val...
static std::string normalize_path(const std::string &path, bool leading_separator, bool trailing_separator, const std::string separator="/")
Removes duplicate separators and provides leading and trailing separators as directed.
Container representing a remote request.
virtual bool release()
release the resources
virtual void dump(std::ostream &strm) const
dumps information about this object
virtual BESContainer * ptr_duplicate()
pure abstract method to duplicate this instances of BESContainer
virtual std::string access()
access the remote target response by making the remote request
std::vector< std::string > * getResponseHeaders()
std::string getCacheFileName()