OPeNDAP Hyrax Back End Server (BES)  Updated for version 3.8.3
NCMLModule.cc
Go to the documentation of this file.
1 // This file is part of the "NcML Module" project, a BES module designed
3 // to allow NcML files to be used to be used as a wrapper to add
4 // AIS to existing datasets of any format.
5 //
6 // Copyright (c) 2009 OPeNDAP, Inc.
7 // Author: Michael Johnson <m.johnson@opendap.org>
8 //
9 // For more information, please also see the main website: http://opendap.org/
10 //
11 // This library is free software; you can redistribute it and/or
12 // modify it under the terms of the GNU Lesser General Public
13 // License as published by the Free Software Foundation; either
14 // version 2.1 of the License, or (at your option) any later version.
15 //
16 // This library is distributed in the hope that it will be useful,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 // Lesser General Public License for more details.
20 //
21 // You should have received a copy of the GNU Lesser General Public
22 // License along with this library; if not, write to the Free Software
23 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 //
25 // Please see the files COPYING and COPYRIGHT for more information on the GLPL.
26 //
27 // You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
29 
30 #include "config.h"
31 
32 #include <iostream>
33 
34 #include <BESCatalogDirectory.h>
35 #include <BESCatalogList.h>
38 #include <BESDapService.h>
39 #include <BESDebug.h>
40 #include <BESRequestHandlerList.h>
41 #include <BESResponseHandlerList.h>
42 #include <BESResponseNames.h>
43 #include <BESXMLCommand.h>
45 #include <TheBESKeys.h>
46 #include <BESInternalError.h>
47 
48 #include "NCMLModule.h"
49 #include "NCMLCacheAggXMLCommand.h"
50 #include "NCMLRequestHandler.h"
51 #include "NCMLResponseNames.h"
52 #include "NCMLContainerStorage.h"
53 
54 using std::endl;
55 using namespace ncml_module;
56 
57 static const char* const NCML_CATALOG = "catalog";
58 
59 void NCMLModule::initialize(const string &modname)
60 {
61  BESDEBUG(modname, "Initializing NCML Module " << modname << endl);
62 
63  BESDEBUG(modname, " adding " << modname << " request handler" << endl);
65 
66  // If new commands are needed, then let's declare this once here. If
67  // not, then you can remove this line.
68 #if 0
69  // Not used. jhrg 4/16/14
70  addCommandAndResponseHandlers(modname);
71 #endif
72  // Dap services
73  BESDEBUG(modname, modname << " handles dap services" << endl);
75 
76  BESDEBUG(modname, " adding " << NCML_CATALOG << " catalog" << endl);
77  if (!BESCatalogList::TheCatalogList()->ref_catalog(NCML_CATALOG)) {
79  }
80  else {
81  BESDEBUG(modname, " catalog already exists, skipping" << endl);
82  }
83 
84  BESDEBUG(modname, " adding catalog container storage " << NCML_CATALOG << endl);
85  if (!BESContainerStorageList::TheList()->ref_persistence(NCML_CATALOG)) {
88  }
89  else {
90  BESDEBUG(modname, " storage already exists, skipping" << endl);
91  }
92 
93  BESDEBUG(modname, " adding " << modname << " container storage" << endl);
95 
96  string key = "NCML.TempDirectory";
97  BESDEBUG( modname, " checking " << key << " parameter" << endl );
98  string val;
99  bool found = false;
100  TheBESKeys::TheKeys()->get_value(key, val, found);
101  if (!found || val.empty() || val == "/") {
102  string err = (string) "The parameter " + key + " must be set to use the NCML module";
103  throw BESInternalError(err, __FILE__, __LINE__);
104  }
106 
107  BESDEBUG(modname, " adding NCML debug context" << endl);
108  BESDebug::Register(modname);
109 
110  BESDEBUG(modname, "Done Initializing NCML Module " << modname << endl);
111 }
112 
113 void NCMLModule::terminate(const string &modname)
114 {
115  BESDEBUG(modname, "Cleaning NCML module " << modname << endl);
116 
117  BESDEBUG(modname, " removing " << modname << " request handler" << endl);
119  if (rh) delete rh;
120 
121  // If new commands were added, remove them here.
122 #if 0
123  // Not used. jhrg 4/16/14
124  removeCommandAndResponseHandlers();
125 #endif
126 
127  BESDEBUG(modname, " removing catalog container storage" << NCML_CATALOG << endl);
129 
130  BESDEBUG( modname, " removing ncml container storage" << endl );
132 
133  BESDEBUG(modname, " removing " << NCML_CATALOG << " catalog" << endl);
135 
136  // TERM_END
137  BESDEBUG(modname, "Done Cleaning NCML module " << modname << endl);
138 }
139 
140 extern "C" {
142 {
143  return new NCMLModule;
144 }
145 }
146 
147 void NCMLModule::dump(ostream &strm) const
148 {
149  strm << BESIndent::LMarg << "NCMLModule::dump - (" << (void *) this << ")" << endl;
150 }
151 
152 #if 0
153 // Not used. jhrg 4/16/14
154 void NCMLModule::addCommandAndResponseHandlers(const string& modname)
155 {
156  BESDEBUG(modname, "Adding module extensions..." << endl);
157  addCacheAggCommandAndResponseHandlers(modname);
158  BESDEBUG(modname, "... done adding module extensions." << endl);
159 }
160 
161 void NCMLModule::addCacheAggCommandAndResponseHandlers(const string& modname)
162 {
163  string cmdName = ModuleConstants::CACHE_AGG_RESPONSE;
164 
165  BESDEBUG( modname, " adding "
166  << cmdName
167  << " response handler" << endl );
169 
170  BESDEBUG(modname, " adding " << cmdName << " command" << endl );
172 }
173 
174 void NCMLModule::removeCommandAndResponseHandlers()
175 {
176  BESDEBUG(ModuleConstants::NCML_NAME, "Removing module extensions..." << endl);
177  removeCacheAggCommandAndResponseHandlers();
178  BESDEBUG(ModuleConstants::NCML_NAME, "... done removing module extensions." << endl);
179 }
180 
181 void NCMLModule::removeCacheAggCommandAndResponseHandlers()
182 {
183  string cmdName = ModuleConstants::CACHE_AGG_RESPONSE;
184 
185  BESDEBUG( ModuleConstants::NCML_NAME, " removing " << cmdName
186  << " response handler" << endl );
188 
189  BESDEBUG( ModuleConstants::NCML_NAME, " removing " << cmdName << " command" << endl );
191 }
192 #endif
static bool del_command(const string &cmd_str)
Deletes the command called cmd_str from the list of possible commands.
static void add_command(const string &cmd_str, p_xmlcmd_builder cmd)
Add a command to the possible commands allowed by this BES.
exception thrown if inernal error encountered
virtual bool add_handler(const string &handler_name, BESRequestHandler *handler)
add a request handler to the list of registered handlers for this server
An abstract superclass for NCMLArray that handles the non-parameterized functionality and allows u...
virtual bool add_catalog(BESCatalog *catalog)
adds the speciifed catalog to the list
virtual void terminate(const string &modname)
Definition: NCMLModule.cc:113
virtual bool add_persistence(BESContainerStorage *p)
Add a persistent store to the list.
implementation of BESContainerStorage that represents a data within a catalog repository ...
static BESXMLCommand * makeInstance(const BESDataHandlerInterface &baseDHI)
static const std::string CACHE_AGG_RESPONSE
Response name in the DHI for the cache of aggregations command.
BESAbstractModule * maker()
Definition: NCMLModule.cc:141
virtual bool deref_catalog(const string &catalog_name)
de-reference the specified catalog and remove from list if no longer referenced
builds catalogs from a directory structure
static ostream & LMarg(ostream &strm)
Definition: BESIndent.cc:73
virtual bool deref_persistence(const string &persist_name)
dereference a persistent store in the list.
virtual void initialize(const string &modname)
Definition: NCMLModule.cc:59
virtual bool add_handler(const string &handler, p_response_handler handler_method)
add a response handler to the list
implementation of BESContainerStorageVolatile that represents a list of NCML requests ...
Represents a specific data type request handler.
virtual void dump(ostream &strm) const
dump the contents of this object to the specified ostream
Definition: NCMLModule.cc:147
void get_value(const string &s, string &val, bool &found)
Retrieve the value of a given key, if set.
Definition: BESKeys.cc:453
static BESRequestHandlerList * TheList()
static BESContainerStorageList * TheList()
virtual bool remove_handler(const string &handler)
removes a response handler from the list
#define BESDEBUG(x, y)
macro used to send debug information to the debug stream
Definition: BESDebug.h:64
Handler for AIS Using NCML.
static BESCatalogList * TheCatalogList()
returns the singleton BESCatalogList instance.
static BESKeys * TheKeys()
Definition: TheBESKeys.cc:48
static void Register(const string &flagName)
register the specified debug flag
Definition: BESDebug.h:138
static const std::string NCML_NAME
The name used to specify an ncml file.
static void handle_dap_service(const string &handler)
static function to register a handler to handle the dap services
static BESResponseHandler * makeInstance(const string &name)
static BESResponseHandlerList * TheList()
virtual BESRequestHandler * remove_handler(const string &handler_name)
remove and return the specified request handler