Browse Source

[1207] Remove InMemoryClient-specific code from auth_srv

Made the getZoneCount() method from inmemory client a general datasource client
call (which throws NotImplemented by default), as this does seem useful in other
 cases as well.

Now the work starts to pay off; removed the temporary pointer variable (getInMemoryClientP() still returns a pointer but now directly retrieved from the container), and any direct reference to isc::datasrc::InMemoryClient is removed from au
th_srv (but not from tests as of yet)
Jelte Jansen 13 years ago
parent
commit
188b12ea58

+ 11 - 24
src/bin/auth/auth_srv.cc

@@ -141,9 +141,7 @@ public:
 
     /// In-memory data source.  Currently class IN only for simplicity.
     const RRClass memory_client_class_;
-    //AuthSrv::InMemoryClientPtr memory_client_;
     isc::datasrc::DataSourceClientContainerPtr memory_client_container_;
-    isc::datasrc::InMemoryClient* memory_client_p_;
 
     /// Hot spot cache
     isc::datasrc::HotCache cache_;
@@ -205,7 +203,6 @@ AuthSrvImpl::AuthSrvImpl(const bool use_cache,
     config_session_(NULL),
     xfrin_session_(NULL),
     memory_client_class_(RRClass::IN()),
-    memory_client_p_(NULL),
     statistics_timer_(io_service_),
     counters_(),
     keyring_(NULL),
@@ -402,23 +399,19 @@ AuthSrv::getInMemoryClientContainer(const RRClass& rrclass) {
     return (impl_->memory_client_container_);
 }
 
-isc::datasrc::InMemoryClient*
+isc::datasrc::DataSourceClient*
 AuthSrv::getInMemoryClientP(const RRClass& rrclass) {
-    if (rrclass != impl_->memory_client_class_) {
-        isc_throw(InvalidParameter,
-                  "Memory data source is not supported for RR class "
-                  << rrclass);
-    }
-    if (!impl_->memory_client_p_) {
-        isc_throw(InvalidOperation, "no memory client set");
+    if (hasInMemoryClient()) {
+        return (&getInMemoryClientContainer(rrclass)->getInstance());
+    } else {
+        return (NULL);
     }
-    return static_cast<isc::datasrc::InMemoryClient*>(
-        &getInMemoryClientContainer(rrclass)->getInstance());
 }
 
 bool
 AuthSrv::hasInMemoryClient() {
-    return (impl_->memory_client_p_ != NULL);
+    return (impl_->memory_client_container_ !=
+            isc::datasrc::DataSourceClientContainerPtr());
 }
 
 void
@@ -437,14 +430,6 @@ AuthSrv::setInMemoryClient(const isc::dns::RRClass& rrclass,
                   .arg(rrclass);
     }
     impl_->memory_client_container_ = memory_client;
-    // temp fix for tests; fool tests with a fake inmemoryclientptr
-    if (memory_client) {
-        impl_->memory_client_p_ =
-            static_cast<isc::datasrc::InMemoryClient*>(
-                &memory_client->getInstance());
-    } else {
-        impl_->memory_client_p_ = NULL;
-    }
 }
 
 
@@ -614,10 +599,12 @@ AuthSrvImpl::processNormalQuery(const IOMessage& io_message, Message& message,
         // If a memory data source is configured call the separate
         // Query::process()
         const ConstQuestionPtr question = *message.beginQuestion();
-        if (memory_client_p_ && memory_client_class_ == question->getClass()) {
+        if (memory_client_container_ &&
+            memory_client_class_ == question->getClass()) {
             const RRType& qtype = question->getType();
             const Name& qname = question->getName();
-            query_.process(*memory_client_p_, qname, qtype, message, dnssec_ok);
+            query_.process(memory_client_container_->getInstance(),
+                           qname, qtype, message, dnssec_ok);
         } else {
             datasrc::Query query(message, cache_, dnssec_ok);
             data_sources_.doQuery(query);

+ 10 - 23
src/bin/auth/auth_srv.h

@@ -17,10 +17,6 @@
 
 #include <string>
 
-// For InMemoryClientPtr below.  This should be a temporary definition until
-// we reorganize the data source framework.
-#include <boost/shared_ptr.hpp>
-
 #include <cc/data.h>
 #include <config/ccsession.h>
 #include <datasrc/factory.h>
@@ -41,9 +37,6 @@
 #include <auth/statistics.h>
 
 namespace isc {
-namespace datasrc {
-class InMemoryClient;
-}
 namespace xfr {
 class AbstractXfroutClient;
 }
@@ -236,19 +229,14 @@ public:
     ///
     void setXfrinSession(isc::cc::AbstractSession* xfrin_session);
 
-    /// A shared pointer type for \c InMemoryClient.
-    ///
-    /// This is defined inside the \c AuthSrv class as it's supposed to be
-    /// a short term interface until we integrate the in-memory and other
-    /// data source frameworks.
-    typedef boost::shared_ptr<isc::datasrc::InMemoryClient> InMemoryClientPtr;
-
-    /// An immutable shared pointer type for \c InMemoryClient.
-    typedef boost::shared_ptr<const isc::datasrc::InMemoryClient>
-    ConstInMemoryClientPtr;
-
     /// Returns the in-memory data source configured for the \c AuthSrv,
-    /// if any.
+    /// if any, as a pointer.
+    ///
+    /// This is mostly a convenience function around
+    /// \c getInMemoryClientContainer, which saves the caller the step
+    /// of having to call getInstance().
+    /// The pointer is of course only valid as long as the container
+    /// exists.
     ///
     /// The in-memory data source is configured per RR class.  However,
     /// the data source may not be available for all RR classes.
@@ -263,7 +251,7 @@ public:
     /// \param rrclass The RR class of the requested in-memory data source.
     /// \return A pointer to the in-memory data source, if configured;
     /// otherwise NULL.
-    isc::datasrc::InMemoryClient* getInMemoryClientP(
+    isc::datasrc::DataSourceClient* getInMemoryClientP(
         const isc::dns::RRClass& rrclass);
 
     /// Returns the DataSourceClientContainer of the in-memory datasource
@@ -292,9 +280,8 @@ public:
 
     /// Sets or replaces the in-memory data source of the specified RR class.
     ///
-    /// As noted in \c getInMemoryClient(), some RR classes may not be
-    /// supported, in which case an exception of class \c InvalidParameter
-    /// will be thrown.
+    /// Some RR classes may not be supported, in which case an exception
+    /// of class \c InvalidParameter will be thrown.
     /// This method never throws an exception otherwise.
     ///
     /// If there is already an in memory data source configured, it will be

+ 2 - 2
src/bin/auth/command.cc

@@ -210,7 +210,7 @@ private:
         const RRClass zone_class =
             class_elem ? RRClass(class_elem->stringValue()) : RRClass::IN();
 
-        isc::datasrc::InMemoryClient* datasrc(
+        isc::datasrc::DataSourceClient* datasrc(
             server.getInMemoryClientP(zone_class));
         if (datasrc == NULL) {
             isc_throw(AuthCommandError, "Memory data source is disabled");
@@ -223,7 +223,7 @@ private:
         const Name origin = Name(origin_elem->stringValue());
 
         // Get the current zone
-        const InMemoryClient::FindResult result = datasrc->findZone(origin);
+        const DataSourceClient::FindResult result = datasrc->findZone(origin);
         if (result.code != result::SUCCESS) {
             isc_throw(AuthCommandError, "Zone " << origin <<
                       " is not found in data source");

+ 12 - 6
src/bin/auth/tests/auth_srv_unittest.cc

@@ -1254,18 +1254,24 @@ public:
     /// The initializer creates a fresh instance of a memory datasource,
     /// which is ignored for the rest (but we do not allow 'null' containers
     /// atm, and this is only needed in these tests)
-    FakeContainer(AuthSrv::InMemoryClientPtr client) :
+    ///
+    /// The client given will be deleted upon destruction of this container
+    FakeContainer(isc::datasrc::DataSourceClient* client) :
         DataSourceClientContainer("memory",
                                   Element::fromJSON("{\"type\": \"memory\"}")),
         client_(client)
     {}
 
+    ~FakeContainer() {
+        delete client_;
+    }
+
     isc::datasrc::DataSourceClient& getInstance() {
         return (*client_);
     }
 
 private:
-    AuthSrv::InMemoryClientPtr client_;
+    isc::datasrc::DataSourceClient* client_;
 };
 
 } // end anonymous namespace for throwing proxy classes
@@ -1278,15 +1284,15 @@ TEST_F(AuthSrvTest, queryWithInMemoryClientProxy) {
     // Set real inmem client to proxy
     updateConfig(&server, CONFIG_INMEMORY_EXAMPLE, true);
 
-    AuthSrv::InMemoryClientPtr fake_client(
+    isc::datasrc::InMemoryClient* fake_client(
         new FakeInMemoryClient(server.getInMemoryClientContainer(rrclass),
                                THROW_NEVER, false));
     EXPECT_TRUE(server.hasInMemoryClient());
-/*
+
     isc::datasrc::DataSourceClientContainerPtr fake_client_container(
         new FakeContainer(fake_client));
     server.setInMemoryClient(rrclass, fake_client_container);
-*/
+
     createDataFromFile("nsec3query_nodnssec_fromWire.wire");
     server.processMessage(*io_message, *parse_message, *response_obuffer,
                           &dnsserv);
@@ -1311,7 +1317,7 @@ setupThrow(AuthSrv* server, const char *config, ThrowWhen throw_when,
 
     // Set it to throw on findZone(), this should result in
     // SERVFAIL on any exception
-    AuthSrv::InMemoryClientPtr fake_client(
+    isc::datasrc::InMemoryClient* fake_client(
         new FakeInMemoryClient(
             server->getInMemoryClientContainer(isc::dns::RRClass::IN()),
             throw_when, isc_exception, rrset));

+ 14 - 0
src/lib/datasrc/client.h

@@ -362,6 +362,20 @@ public:
     virtual std::pair<ZoneJournalReader::Result, ZoneJournalReaderPtr>
     getJournalReader(const isc::dns::Name& zone, uint32_t begin_serial,
                      uint32_t end_serial) const = 0;
+
+    /// Return the number of zones currently known to this datasource
+    ///
+    /// This is an optional convenience method, currently only implemented
+    /// by the InMemory datasource. By default, it throws NotImplemented
+    ///
+    /// \exception NotImplemented Thrown if this method is not supported
+    ///            by the datasource
+    ///
+    /// \return The number of zones known to this datasource
+    virtual unsigned int getZoneCount() const {
+        isc_throw(isc::NotImplemented,
+                  "Data source doesn't support getZoneCount");
+    }
 };
 }
 }

+ 1 - 1
src/lib/datasrc/memory_datasrc.h

@@ -286,7 +286,7 @@ public:
     /// This method never throws an exception.
     ///
     /// \return The number of zones stored in the client.
-    unsigned int getZoneCount() const;
+    virtual unsigned int getZoneCount() const;
 
     /// Add a zone (in the form of \c ZoneFinder) to the \c InMemoryClient.
     ///