Browse Source

[2833] introduced ZoneTableConfig

it's intended to be used as an interface between ClientList and
ZoneTableSegment.
JINMEI Tatuya 12 years ago
parent
commit
745c28556f

+ 1 - 0
src/lib/datasrc/Makefile.am

@@ -39,6 +39,7 @@ libb10_datasrc_la_SOURCES += master_loader_callbacks.h
 libb10_datasrc_la_SOURCES += master_loader_callbacks.cc
 libb10_datasrc_la_SOURCES += rrset_collection_base.h rrset_collection_base.cc
 libb10_datasrc_la_SOURCES += zone_loader.h zone_loader.cc
+libb10_datasrc_la_SOURCES += zone_table_config.h zone_table_config.cc
 nodist_libb10_datasrc_la_SOURCES = datasrc_messages.h datasrc_messages.cc
 libb10_datasrc_la_LDFLAGS = -no-undefined -version-info 1:0:1
 

+ 13 - 11
src/lib/datasrc/client_list.cc

@@ -13,16 +13,17 @@
 // PERFORMANCE OF THIS SOFTWARE.
 
 
-#include "client_list.h"
-#include "exceptions.h"
-#include "client.h"
-#include "factory.h"
-#include "memory/memory_client.h"
-#include "memory/zone_table_segment.h"
-#include "memory/zone_writer.h"
-#include "memory/zone_data_loader.h"
-#include "memory/zone_data_updater.h"
-#include "logger.h"
+#include <datasrc/client_list.h>
+#include <datasrc/exceptions.h>
+#include <datasrc/client.h>
+#include <datasrc/factory.h>
+#include <datasrc/zone_table_config.h>
+#include <datasrc/memory/memory_client.h>
+#include <datasrc/memory/zone_table_segment.h>
+#include <datasrc/memory/zone_writer.h>
+#include <datasrc/memory/zone_data_loader.h>
+#include <datasrc/memory/zone_data_updater.h>
+#include <datasrc/logger.h>
 #include <dns/masterload.h>
 #include <util/memory_segment_local.h>
 
@@ -121,7 +122,8 @@ ConfigurableClientList::configure(const ConstElementPtr& config,
 
             shared_ptr<ZoneTableSegment> ztable_segment;
             if (want_cache) {
-                ztable_segment.reset(ZoneTableSegment::create(*config,
+                internal::ZoneTableConfig ztconfig(type, 0, *dconf);
+                ztable_segment.reset(ZoneTableSegment::create(*dconf, // XXX
                                                               rrclass_));
             }
 

+ 69 - 0
src/lib/datasrc/zone_table_config.cc

@@ -0,0 +1,69 @@
+// Copyright (C) 2013  Internet Systems Consortium, Inc. ("ISC")
+//
+// Permission to use, copy, modify, and/or distribute this software for any
+// purpose with or without fee is hereby granted, provided that the above
+// copyright notice and this permission notice appear in all copies.
+//
+// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
+// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+// AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
+// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
+// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
+// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+// PERFORMANCE OF THIS SOFTWARE.
+
+#include <datasrc/zone_table_config.h>
+#include <datasrc/client.h>
+#include <datasrc/memory/load_action.h>
+#include <dns/name.h>
+#include <cc/data.h>
+
+#include <map>
+#include <string>
+
+using namespace isc::data;
+
+namespace isc {
+namespace datasrc {
+namespace internal {
+
+ZoneTableConfig::ZoneTableConfig(const std::string& datasrc_type,
+                                 DataSourceClient* datasrc_client,
+                                 const Element& datasrc_conf) :
+    datasrc_client_(datasrc_client)
+{
+    ConstElementPtr params = datasrc_conf.get("params");
+    if (!params) {
+        params.reset(new NullElement());
+    }
+
+    if (datasrc_type == "MasterFiles") {
+        typedef std::map<std::string, ConstElementPtr> ZoneToFile;
+        const ZoneToFile& zone_to_file = params->mapValue();
+        ZoneToFile::const_iterator const it_end = zone_to_file.end();
+        for (ZoneToFile::const_iterator it = zone_to_file.begin();
+             it != it_end;
+             ++it)
+        {
+            zone_config_[dns::Name(it->first)] = it->second->stringValue();
+        }
+    } else {
+        if (!datasrc_conf.contains("cache-zones")) {
+            isc_throw(isc::NotImplemented, "Auto-detection of zones "
+                      "to cache is not yet implemented, supply "
+                      "cache-zones parameter");
+            // TODO: Auto-detect list of all zones in the
+            // data source.
+        }
+
+        // TBD: confirm cache-zones exist, must be a list, no duplicates
+        const ConstElementPtr zones = datasrc_conf.get("cache-zones");
+        for (size_t i = 0; i < zones->size(); ++i) {
+            zone_config_[dns::Name(zones->get(i)->stringValue())] = "";
+        }
+    }
+}
+
+} // namespace internal
+} // namespace datasrc
+} // namespace isc

+ 79 - 0
src/lib/datasrc/zone_table_config.h

@@ -0,0 +1,79 @@
+// Copyright (C) 2013  Internet Systems Consortium, Inc. ("ISC")
+//
+// Permission to use, copy, modify, and/or distribute this software for any
+// purpose with or without fee is hereby granted, provided that the above
+// copyright notice and this permission notice appear in all copies.
+//
+// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
+// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+// AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
+// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
+// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
+// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+// PERFORMANCE OF THIS SOFTWARE.
+
+#ifndef DATASRC_ZONE_TABLE_CONFIG_H
+#define DATASRC_ZONE_TABLE_CONFIG_H
+
+#include <datasrc/memory/load_action.h>
+#include <dns/dns_fwd.h>
+#include <cc/data.h>
+
+#include <map>
+#include <string>
+
+namespace isc {
+namespace datasrc {
+class DataSourceClient;
+
+namespace internal {
+
+/// This class is intended to be an interface between DataSourceClient and
+/// memory ZoneTableSegment implementations.  This class understands the
+/// configuration parameters for DataSourceClient related to in-memory cache,
+/// and convert it to native, type-safe objects so that it can be used by
+/// ZoneTableSegment implementations.  It also provides unified interface
+/// for getting a list of zones to be loaded in to memory and
+/// and memory::LoadAction object that can be used for the load, regardless
+/// of the underlying data source properties, i.e., whether it's special
+/// "MasterFiles" type or other generic data sources.
+///
+/// This class is publicly defined because it has to be referenced by both
+/// DataSourceClient and ZoneTableSegment (other than for testing purposes),
+/// but it's essentially private to these two classes.  It's therefore
+/// defined in an "internal" namespace, and isn't expected to be used by
+/// other classes or user applications.  Likewise, this file is not expected
+/// to be installed with other publicly usable header files.
+class ZoneTableConfig {
+public:
+    ZoneTableConfig(const std::string& datasrc_type,
+                    DataSourceClient* datasrc_client,
+                    const data::Element& datasrc_conf);
+
+    /// Return corresponding \c LoadAction for the given name of zone.
+    /// It would return a different functor depending on the details of the
+    /// underlying data source.
+    memory::LoadAction getLoadAction(const dns::Name& zone_name) const;
+
+    /// This allows ZoneTableSegment to iterate over all zones to be loaded
+    /// in to memory.  In this initial implementation we directly give
+    /// read-only access to the underlying map to minimize the diff, but
+    /// it's not clean in terms of encapsulation and performance (eventually
+    /// we may have to look up in the underlying data source to get the list
+    /// of zones, in which case constructing a map can be very expensive).
+    const std::map<dns::Name, std::string>& getZoneConfig() const;
+
+private:
+    // client of underlying data source, will be NULL for MasterFile datasrc
+    DataSourceClient* datasrc_client_;
+    std::map<dns::Name, std::string> zone_config_;
+};
+}
+}
+}
+
+#endif  // DATASRC_ZONE_TABLE_CONFIG_H
+
+// Local Variables:
+// mode: c++
+// End: