diff --git a/dispatch/BESRequestHandlerList.cc b/dispatch/BESRequestHandlerList.cc index 1537ac9b74..fa7dd7c46b 100644 --- a/dispatch/BESRequestHandlerList.cc +++ b/dispatch/BESRequestHandlerList.cc @@ -240,6 +240,9 @@ void BESRequestHandlerList::execute_current(BESDataHandlerInterface &dhi) { // expensive, even when the container is intelligently written (DMR++ documents // can be many megabytes in size). Fix this mess so that get_container_type() // works without all of the handlers calling access() twice. jhrg 2/18/25 + // SBL 1.31.26 - Update: NgapOwnedContainer::access() now just sets the container type + // and does not return the dmrpp string, which is handled in NgapOwnedContainer::alt_access() + // all other container access fcts remain the same dhi.container->access(); // Given the kind of thing in the DHI's container (netcdf file, ...) find the diff --git a/modules/dmrpp_module/DmrppRequestHandler.cc b/modules/dmrpp_module/DmrppRequestHandler.cc index b9c8ff2652..46c216a124 100644 --- a/modules/dmrpp_module/DmrppRequestHandler.cc +++ b/modules/dmrpp_module/DmrppRequestHandler.cc @@ -80,6 +80,7 @@ using namespace bes; using namespace http; using namespace libdap; using namespace std; +using namespace ngap; // These should be set in the Makefile.am. jhrg 11/23/24 #ifndef MODULE_NAME @@ -325,6 +326,7 @@ catch (...) { */ void DmrppRequestHandler::get_dmrpp_from_container_or_cache(BESContainer *container, DMR *dmr) { try { + auto ngo_cont = dynamic_cast(container); // If the container is an NGAP container (or maybe other types in the future), // the DMR++ itself might be returned as a string by access(). If the container // did not come from the NGAP handler, the return value might be a string that @@ -341,7 +343,7 @@ void DmrppRequestHandler::get_dmrpp_from_container_or_cache(BESContainer *contai DmrppTypeFactory factory(dmz); dmr->set_factory(&factory); - string dmrpp_content = container->access(); + string dmrpp_content = ngo_cont->alt_access(); dmz->parse_xml_string(dmrpp_content); diff --git a/modules/dmrpp_module/Makefile.am b/modules/dmrpp_module/Makefile.am index 4ee7d73031..c27b26093c 100644 --- a/modules/dmrpp_module/Makefile.am +++ b/modules/dmrpp_module/Makefile.am @@ -30,7 +30,7 @@ CXXFLAGS_DEBUG = -g3 -O0 -Wall -W -Wcast-align AM_LDFLAGS = include $(top_srcdir)/coverage.mk -SUBDIRS = ngap_container dmrpp_transmitter build_dmrpp_h4 . unit-tests tests data tests_build_dmrpp get_dmrpp +SUBDIRS = ngap_container dmrpp_transmitter . build_dmrpp_h4 unit-tests tests data tests_build_dmrpp get_dmrpp lib_besdir=$(libdir)/bes lib_bes_LTLIBRARIES = libdmrpp_module.la @@ -56,7 +56,7 @@ DMRPP_MODULE = DmrppModule.cc DmrppRequestHandler.cc DmrppModule.h DmrppRequestH libdmrpp_module_la_SOURCES = $(BES_HDRS) $(BES_SRCS) $(DMRPP_MODULE) libdmrpp_module_la_LDFLAGS = -avoid-version -module libdmrpp_module_la_LIBADD = -L$(builddir)/ngap_container -lngap $(BES_DISPATCH_LIB) \ - $(BES_HTTP_LIB) $(DAP_SERVER_LIBS) $(DAP_CLIENT_LIBS) \ + $(BES_HTTP_LIB) $(BES_DAP_LIB) $(DAP_SERVER_LIBS) $(DAP_CLIENT_LIBS) \ $(H5_LDFLAGS) $(H5_LIBS) $(OPENSSL_LDFLAGS) $(OPENSSL_LIBS) -ltest-types \ -Ldmrpp_transmitter -ldmrpp_return_as @@ -73,10 +73,10 @@ h5common.h: Makefile build_dmrpp_CPPFLAGS = $(AM_CPPFLAGS) $(H5_CPPFLAGS) -I$(top_srcdir)/modules/hdf5_handler build_dmrpp_SOURCES = $(BES_SRCS) $(BES_HDRS) DmrppRequestHandler.cc DmrppRequestHandler.h \ build_dmrpp.cc build_dmrpp_util.cc build_dmrpp_util.h h5common.cc h5common.h -build_dmrpp_LDFLAGS = $(top_builddir)/dap/.libs/libdap_module.a -build_dmrpp_LDADD = $(BES_DISPATCH_LIB) $(BES_HTTP_LIB) $(H5_LDFLAGS) \ - $(H5_LIBS) $(DAP_SERVER_LIBS) $(DAP_CLIENT_LIBS) $(OPENSSL_LDFLAGS) $(OPENSSL_LIBS) \ - $(XML2_LIBS) $(BYTESWAP_LIBS) -lz +build_dmrpp_LDFLAGS = +build_dmrpp_LDADD = $(top_builddir)/dap/.libs/libdap_module.a -L$(builddir)/ngap_container -lngap \ +$(BES_DISPATCH_LIB) $(BES_HTTP_LIB) $(H5_LDFLAGS) $(H5_LIBS) $(DAP_SERVER_LIBS) $(DAP_CLIENT_LIBS) \ +$(OPENSSL_LDFLAGS) $(OPENSSL_LIBS) $(XML2_LIBS) $(BYTESWAP_LIBS) -lz # jhrg 6/2/23 $(BES_EXTRA_LIBS) diff --git a/modules/dmrpp_module/build_dmrpp_h4/Makefile.am b/modules/dmrpp_module/build_dmrpp_h4/Makefile.am index 6b52380ee3..b67c070160 100644 --- a/modules/dmrpp_module/build_dmrpp_h4/Makefile.am +++ b/modules/dmrpp_module/build_dmrpp_h4/Makefile.am @@ -22,46 +22,29 @@ AM_CXXFLAGS= AM_LDFLAGS = include $(top_srcdir)/coverage.mk -# SUBDIRS = . unit-tests tests - -# These tests will fail if the DmrApiTest also fails: tests jhrg 6/29/23 - -#noinst_PROGRAMS = build_dmrpp_h4 bin_PROGRAMS = build_dmrpp_h4 build_dmrpp_h4_SOURCES = $(SRC) $(HDR) -SRC = build_dmrpp_h4.cc build_dmrpp_util_h4.cc ../Chunk.cc ../DMRpp.cc ../DMZ.cc ../DmrppArray.cc ../DmrppByte.cc ../DmrppCommon.cc \ - ../DmrppD4Enum.cc ../DmrppD4Group.cc ../DmrppD4Opaque.cc ../DmrppD4Sequence.cc ../DmrppFloat32.cc ../DmrppFloat64.cc \ - ../DmrppInt16.cc ../DmrppInt32.cc ../DmrppInt64.cc ../DmrppInt8.cc ../DmrppStr.cc ../DmrppStructure.cc \ - ../DmrppTypeFactory.cc ../DmrppUInt16.cc ../DmrppUInt32.cc ../DmrppUInt64.cc ../DmrppUrl.cc ../SuperChunk.cc \ - ../DmrppRequestHandler.cc ../CurlHandlePool.cc ../vlsa_util.cc ../float_byteswap.cc +SRC = build_dmrpp_h4.cc build_dmrpp_util_h4.cc -HDR = build_dmrpp_util_h4.h ../Chunk.h ../DMRpp.h ../DMZ.h ../DmrppArray.h ../DmrppByte.h ../DmrppCommon.h \ - ../DmrppD4Enum.h ../DmrppD4Group.h ../DmrppD4Opaque.h ../DmrppD4Sequence.h ../DmrppFloat32.h ../DmrppFloat64.h \ - ../DmrppInt16.h ../DmrppInt32.h ../DmrppInt64.h ../DmrppInt8.h ../DmrppStr.h ../DmrppStructure.h \ - ../DmrppTypeFactory.h ../DmrppUInt16.h ../DmrppUInt32.h ../DmrppUInt64.h ../DmrppUrl.h ../SuperChunk.h \ - ../DmrppRequestHandler.h ../CurlHandlePool.h ../vlsa_util.h ../byteswap_compat.h ../float_byteswap.h +HDR = build_dmrpp_util_h4.h build_dmrpp_h4_CPPFLAGS = $(AM_CPPFLAGS) -#build_dmrpp_h4_LDFLAGS = $(HDFEOS2_LDFLAGS) $(HDFEOS2_LIBS) $(HDF4_LDFLAGS) $(BES_DAP_LIB_LDFLAGS) build_dmrpp_h4_LDFLAGS = $(HDFEOS2_LDFLAGS) $(HDF4_LDFLAGS) $(BES_DAP_LIB_LDFLAGS) -# jhrg 12/18/23 $(top_builddir)/dap/.libs/libdap_module.a +# The code in dmrpp_module now builds a convenience library that is then linked +# with the DmrppRequestHandler and DmrppModule classes to make the module. That convenience library +# is also used to make standalone programs like build_dmrpp_h4. SBL & JHRG 2.2.26 -build_dmrpp_h4_LDADD = $(BES_DISPATCH_LIB) $(BES_HTTP_LIB) $(DAP_SERVER_LIBS) $(DAP_CLIENT_LIBS) \ - $(OPENSSL_LDFLAGS) $(OPENSSL_LIBS) $(XML2_LIBS) $(BYTESWAP_LIBS) $(HDFEOS2_LIBS) $(HDF4_LIBS) +build_dmrpp_h4_LDADD = $(top_builddir)/modules/dmrpp_module/.libs/libdmrpp_module.a \ +-L$(top_builddir)/modules/dmrpp_module/ngap_container -lngap \ +$(BES_DISPATCH_LIB) $(BES_DAP_LIB) $(BES_HTTP_LIB) $(DAP_SERVER_LIBS) $(DAP_CLIENT_LIBS) $(OPENSSL_LDFLAGS) \ +$(OPENSSL_LIBS) $(XML2_LIBS) $(BYTESWAP_LIBS) $(HDFEOS2_LIBS) $(HDF4_LIBS) lib_besdir=$(libdir)/bes -# lib_bes_LTLIBRARIES = libcmr_module.la - -# libcmr_module_la_SOURCES = $(CMR_SRC) $(CMR_HDR) -# libcmr_module_la_LDFLAGS = -avoid-version -module -# libcmr_module_la_LIBADD = $(LIBADD) - - EXTRA_DIST = get_dmrpp_h4 CLEANFILES = *~ diff --git a/modules/dmrpp_module/ngap_container/NgapOwnedContainer.cc b/modules/dmrpp_module/ngap_container/NgapOwnedContainer.cc index 5b90362860..0270599e40 100644 --- a/modules/dmrpp_module/ngap_container/NgapOwnedContainer.cc +++ b/modules/dmrpp_module/ngap_container/NgapOwnedContainer.cc @@ -570,22 +570,39 @@ bool NgapOwnedContainer::get_dmrpp_from_cache_or_remote_source(string &dmrpp_str * @throws BESError if there is a problem making the remote request */ string NgapOwnedContainer::access() { - - string dmrpp_string; - - // Get the DMR++ from the S3 bucket or the cache. - // get_dmrpp...() returns false for various caching errors, but throws if it cannot - // get the remote DMR++. jhrg 4/29/24 - get_dmrpp_from_cache_or_remote_source(dmrpp_string); - - set_attributes("as-string"); // This means access() returns a string. jhrg 10/19/23 // Originally, this was either hard-coded (as it is now) or was set using the 'extension' // on the URL. But it's always a DMR++. jhrg 11/16/23 set_container_type("dmrpp"); - return dmrpp_string; + return ""; } +/** + * @brief alternate version of ::access() that get the DMR++ + * + * @note alternate version of ::access() that retrieve the dmrpp data, + * used in the RequestHandler + * + * @return The DMR++ as a string. + * @throws BESError if there is a problem making the remote request + */ +string NgapOwnedContainer::alt_access() { + string dmrpp_string; + + // Get the DMR++ from the S3 bucket or the cache. + // get_dmrpp...() returns false for various caching errors, but throws if it cannot + // get the remote DMR++. jhrg 4/29/24 + get_dmrpp_from_cache_or_remote_source(dmrpp_string); + + set_attributes("as-string"); // This means access() returns a string. jhrg 10/19/23 + + // Originally, this was either hard-coded (as it is now) or was set using the 'extension' + // on the URL. But it's always a DMR++. jhrg 11/16/23 + set_container_type("dmrpp"); + + return dmrpp_string; + } + /** @brief dumps information about this object * * Displays the pointer value of this instance along with information about diff --git a/modules/dmrpp_module/ngap_container/NgapOwnedContainer.h b/modules/dmrpp_module/ngap_container/NgapOwnedContainer.h index 3be72acd60..0da283ee9d 100644 --- a/modules/dmrpp_module/ngap_container/NgapOwnedContainer.h +++ b/modules/dmrpp_module/ngap_container/NgapOwnedContainer.h @@ -137,6 +137,7 @@ class NgapOwnedContainer: public BESContainer { static std::string get_data_source_location() { return d_data_source_location; } std::string access() override; + std::string alt_access(); bool release() override { return true; diff --git a/modules/dmrpp_module/ngap_container/unit-tests/NgapOwnedContainerTest.cc b/modules/dmrpp_module/ngap_container/unit-tests/NgapOwnedContainerTest.cc index 36a77b95b6..efe59a8d39 100644 --- a/modules/dmrpp_module/ngap_container/unit-tests/NgapOwnedContainerTest.cc +++ b/modules/dmrpp_module/ngap_container/unit-tests/NgapOwnedContainerTest.cc @@ -305,6 +305,26 @@ class NgapOwnedContainerTest: public CppUnit::TestFixture { container.set_data_source_location(TEST_DATA_LOCATION); string dmrpp = container.access(); + // .access() changed to only set the container type, SBL 1.23.26 + // DBG2(cerr << "DMR++: " << dmrpp << '\n'); + // CPPUNIT_ASSERT_MESSAGE("The DMR++ should be in the string", !dmrpp.empty()); + + // string attrs = container.get_attributes(); + // CPPUNIT_ASSERT_MESSAGE("The container attributes should be 'as-string'", attrs == "as-string"); + + CPPUNIT_ASSERT_MESSAGE("The container type should be 'dmrpp'", container.get_container_type() == "dmrpp"); + } + + void test_alt_access() { + TEST_NAME; + + NgapOwnedContainer container; + // The REST path will become data/d_int.h5 + container.set_real_name("collections/data/granules/d_int.h5"); + // Set the location of the data as a file:// URL for this test. + container.set_data_source_location(TEST_DATA_LOCATION); + + string dmrpp = container.alt_access(); DBG2(cerr << "DMR++: " << dmrpp << '\n'); CPPUNIT_ASSERT_MESSAGE("The DMR++ should be in the string", !dmrpp.empty()); @@ -338,7 +358,7 @@ class NgapOwnedContainerTest: public CppUnit::TestFixture { container.set_data_source_location(DMRPP_TEST_BUCKET_OPENDAP_AWS); string dmrpp; // = container.access(); - CPPUNIT_ASSERT_NO_THROW_MESSAGE("This should not throw an exception", dmrpp = container.access()); + CPPUNIT_ASSERT_NO_THROW_MESSAGE("This should not throw an exception", dmrpp = container.alt_access()); DBG2(cerr << "DMR++: " << dmrpp << '\n'); CPPUNIT_ASSERT_MESSAGE("The response should not be empty", !dmrpp.empty()); string dmrpp_str = R"(dmrpp:href="https://s3.amazonaws.com/cloudydap/ngap_owned/d_int.h5")"; @@ -423,6 +443,7 @@ class NgapOwnedContainerTest: public CppUnit::TestFixture { CPPUNIT_TEST(test_get_dmrpp_from_cache_or_remote_source_test_cache_use); CPPUNIT_TEST(test_access); + CPPUNIT_TEST(test_alt_access); CPPUNIT_TEST(test_access_s3); CPPUNIT_TEST(test_filter_response_injects_s3_data_urls);