Commit 92adc1fb authored by Thomas Markwalder's avatar Thomas Markwalder

[3086] Addressed review comments

Added virtual method for validating state handler map, added additional unit tests and commentary.
parent c542421c
......@@ -77,7 +77,7 @@ D2UpdateMgr::checkFinishedTransactions() {
// NOTE: One must use postfix increments of the iterator on the calls
// to erase. This replaces the old iterator which becomes invalid by the
// erase with a the next valid iterator. Prefix incrementing will not
// work.
// work.
TransactionList::iterator it = transaction_list_.begin();
while (it != transaction_list_.end()) {
NameChangeTransactionPtr trans = (*it).second;
......@@ -108,12 +108,6 @@ void D2UpdateMgr::pickNextJob() {
if (!hasTransaction(found_ncr->getDhcid())) {
queue_mgr_->dequeueAt(index);
makeTransaction(found_ncr);
#if 0
// this will run it up to its first IO
trans->startTransaction();
#endif
return;
}
}
......
......@@ -37,7 +37,6 @@ const int NameChangeTransaction::NO_MORE_SERVERS_EVT;
const int NameChangeTransaction::IO_COMPLETED_EVT;
const int NameChangeTransaction::UPDATE_OK_EVT;
const int NameChangeTransaction::UPDATE_FAILED_EVT;
const int NameChangeTransaction::CANCEL_TRANSACTION_EVT;
const int NameChangeTransaction::ALL_DONE_EVT;
const int NameChangeTransaction::DERIVED_EVENTS;
......@@ -80,17 +79,15 @@ NameChangeTransaction::startTransaction() {
// Initialize the state handler map first.
initStateHandlerMap();
// Test validity of the handler map. This provides an opportunity to
// sanity check the map prior to attempting to execute the model.
verifyStateHandlerMap();
// Set the current state to READY and enter the run loop.
setState(READY_ST);
runStateModel(START_TRANSACTION_EVT);
}
void
NameChangeTransaction::cancelTransaction() {
//@todo It is up to the deriving state model to handle this event.
runStateModel(CANCEL_TRANSACTION_EVT);
}
void
NameChangeTransaction::operator()(DNSClient::Status status) {
// Stow the completion status and re-enter the run loop with the event
......@@ -165,11 +162,6 @@ NameChangeTransaction::setDnsUpdateStatus(const DNSClient::Status& status) {
dns_update_status_ = status;
}
void
NameChangeTransaction::setDnsUpdateResponse(D2UpdateMessagePtr& response) {
dns_update_response_ = response;
}
void
NameChangeTransaction::setForwardChangeCompleted(const bool value) {
forward_change_completed_ = value;
......@@ -206,7 +198,11 @@ NameChangeTransaction::getReverseDomain() {
}
void
NameChangeTransaction::initServerSelection(DdnsDomainPtr& domain) {
NameChangeTransaction::initServerSelection(const DdnsDomainPtr& domain) {
if (!domain) {
isc_throw(NameChangeTransactionError,
"initServerSelection called with an empty domain");
}
current_server_list_ = domain->getServers();
next_server_pos_ = 0;
current_server_.reset();
......@@ -219,8 +215,8 @@ NameChangeTransaction::selectNextServer() {
current_server_ = (*current_server_list_)[next_server_pos_];
dns_update_response_.reset(new
D2UpdateMessage(D2UpdateMessage::INBOUND));
// @todo Prototype is set on DNSClient constructor. We need
// to progate a configruation value downward, probably starting
// @todo Protocol is set on DNSClient constructor. We need
// to propagate a configuration value downward, probably starting
// at global, then domain, then server
// Once that is supported we need to add it here.
dns_client_.reset(new DNSClient(dns_update_response_ , this,
......
......@@ -57,7 +57,7 @@ typedef std::map<unsigned int, StateHandler> StateHandlerMap;
/// of DNS server(s) needed. It is responsible for knowing what conversations
/// it must have with which servers and in the order necessary to fulfill the
/// request. Upon fulfillment of the request, the transaction's work is complete
/// it is destroyed.
/// and it is destroyed.
///
/// Fulfillment of the request is carried out through the performance of the
/// transaction's state model. Using a state driven implementation accounts
......@@ -121,10 +121,22 @@ public:
static const int NEW_ST = 0;
/// @brief State from which a transaction is started.
static const int READY_ST = 1;
/// @brief State in which forward DNS server selection is done.
/// @brief State in which forward DNS server selection is done.
///
/// Within this state, the actual selection of the next forward server
/// to use is conducted. Upon conclusion of this state the next server
/// is either selected or it should transition out with NO_MORE_SERVERS_EVT
/// event.
static const int SELECTING_FWD_SERVER_ST = 2;
/// @brief State in which reverse DNS server selection is done.
///
/// Within this state, the actual selection of the next reverse server
/// to use is conducted. Upon conclusion of this state the next server
/// is either selected or it should transition out with NO_MORE_SERVERS_EVT
/// event.
static const int SELECTING_REV_SERVER_ST = 3;
/// @brief Final state, all work has been performed.
static const int DONE_ST = 4;
......@@ -163,11 +175,8 @@ public:
/// the failure is given by the DNSClient return status and the response
/// packet (if one was received).
static const int UPDATE_FAILED_EVT = 8;
/// @brief Issued when the transaction should be cancelled.
/// @todo - still on the fence about this one.
static const int CANCEL_TRANSACTION_EVT = 9;
/// @brief Issued when the state model has no more work left to do.
static const int ALL_DONE_EVT = 10;
static const int ALL_DONE_EVT = 9;
/// @define Value at which custom events in a derived class should begin.
static const int DERIVED_EVENTS = 100;
......@@ -182,7 +191,7 @@ public:
/// @param forward_domain is the domain to use for forward DNS updates
/// @param reverse_domain is the domain to use for reverse DNS updates
///
/// @throw NameChangeTransaction error if given an null request,
/// @throw NameChangeTransactionError if given an null request,
/// if forward change is enabled but forward domain is null, if
/// reverse change is enabled but reverse domain is null.
NameChangeTransaction(isc::asiolink::IOService& io_service,
......@@ -190,6 +199,7 @@ public:
DdnsDomainPtr& forward_domain,
DdnsDomainPtr& reverse_domain);
/// @brief Destructor
virtual ~NameChangeTransaction();
/// @brief Begins execution of the transaction.
......@@ -200,9 +210,6 @@ public:
/// parameter of START_TRANSACTION_EVT.
void startTransaction();
/// @todo - Not sure about this yet.
void cancelTransaction();
/// @brief Serves as the DNSClient IO completion event handler.
///
/// This is the implementation of the method inherited by our derivation
......@@ -225,11 +232,39 @@ protected:
/// Implementations should use the addToMap() method add entries to
/// the map.
/// @todo This method should be pure virtual but until there are
/// derivations for the update manager to use we will provide an
/// derivations for the update manager to use, we will provide a
/// temporary empty, implementation. If we make it pure virtual now
/// D2UpdateManager will not compile.
virtual void initStateHandlerMap() {};
/// @brief Validates the contents of the state handler map.
///
/// This method is invoked immediately after initStateHandlerMap and
/// provides an opportunity for derivations to verify that the map
/// is correct. If the map is determined to be invalid this method
/// should throw a NameChangeTransactionError.
///
/// The simplest implementation would include a call to getStateHandler,
/// for each state the derivation supports. For example, a implementation
/// which included three states, READY_ST, DO_WORK_ST, and DONE_ST could
/// implement this function as follows:
///
/// @code
/// void verifyStateHandlerMap() {
/// getStateHandler(READY_ST);
/// getStateHandler(DO_WORK_ST);
/// getStateHandler(DONE_ST);
/// }
/// @endcode
///
/// @todo This method should be pure virtual but until there are
/// derivations for the update manager to use, we will provide a
/// temporary empty, implementation. If we make it pure virtual now
/// D2UpdateManager will not compile.
/// @throw NameChangeTransactionError if the map is invalid.
virtual void verifyStateHandlerMap() {};
/// @brief Adds an entry to the state handler map.
///
/// This method attempts to add an entry to the handler map which maps
......@@ -257,7 +292,7 @@ protected:
///
/// @throw NameChangeTransactionError if the map already contains an entry
/// for the given state.
void addToMap(unsigned int idx, StateHandler handler);
void addToMap(unsigned int state, StateHandler handler);
/// @brief Processes events through the state model
///
......@@ -345,7 +380,7 @@ protected:
///
/// @param domain is the domain from which server selection is to be
/// conducted.
void initServerSelection(DdnsDomainPtr& domain);
void initServerSelection(const DdnsDomainPtr& domain);
/// @brief Selects the next server in the current server list.
///
......@@ -387,7 +422,7 @@ public:
///
/// This is the current status of the NameChangeRequest, not to
/// be confused with the state of the transaction. Once the transaction
/// is reached it's conclusion, the request will end up with a final
/// is reached its conclusion, the request will end up with a final
/// status.
///
/// @return A dhcp_ddns::NameChangeStatus representing the current
......@@ -396,16 +431,14 @@ public:
/// @brief Fetches the forward DdnsDomain.
///
/// This value is only meaningful if the request calls for a forward change.
///
/// @return A pointer reference to the forward DdnsDomain
/// @return A pointer reference to the forward DdnsDomain. If the
/// the request does not include a forward change, the pointer will empty.
DdnsDomainPtr& getForwardDomain();
/// @brief Fetches the reverse DdnsDomain.
///
/// This value is only meaningful if the request calls for a reverse change.
///
/// @return A pointer reference to the reverse DdnsDomain
/// @return A pointer reference to the reverse DdnsDomain. If the
/// the request does not include a reverse change, the pointer will empty.
DdnsDomainPtr& getReverseDomain();
/// @brief Fetches the transaction's current state.
......
This diff is collapsed.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment