diff --git a/livesupport/modules/schedulerClient/etc/Makefile.in b/livesupport/modules/schedulerClient/etc/Makefile.in index a355ed5ad..2adcb1eab 100644 --- a/livesupport/modules/schedulerClient/etc/Makefile.in +++ b/livesupport/modules/schedulerClient/etc/Makefile.in @@ -21,7 +21,7 @@ # # # Author : $Author: maroy $ -# Version : $Revision: 1.1 $ +# Version : $Revision: 1.2 $ # Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/schedulerClient/etc/Makefile.in,v $ # # @configure_input@ @@ -63,6 +63,12 @@ CORE_LIB_DIR = ${CORE_DIR}/lib CORE_LIB = livesupport_core CORE_LIB_FILE = ${CORE_LIB_DIR}/lib${CORE_LIB}.a +AUTHENTICATION_DIR = ${MODULES_DIR}/authentication +AUTHENTICATION_INCLUDE_DIR = ${AUTHENTICATION_DIR}/include +AUTHENTICATION_LIB_DIR = ${AUTHENTICATION_DIR}/lib +AUTHENTICATION_LIB = livesupport_authentication +AUTHENTICATION_LIB_FILE = ${AUTHENTICATION_LIB_DIR}/lib${AUTHENTICATION_LIB}.a + PRODUCTS_DIR = ${BASE_DIR}/../../products SCHEDULER_DIR = ${PRODUCTS_DIR}/scheduler @@ -94,8 +100,13 @@ CXXFLAGS = @CXXFLAGS@ @DEFS@ @COVERAGE_CXXFLAGS@ -pthread \ -I${BOOST_INCLUDE_DIR} \ -I${LIBXMLPP_INCLUDE_DIR} \ -I${CORE_INCLUDE_DIR} \ + -I${AUTHENTICATION_INCLUDE_DIR} \ -I${INCLUDE_DIR} -I${TMP_DIR} -LDFLAGS = @LDFLAGS@ -pthread -L${USR_LIB_DIR} -L${CORE_LIB_DIR} -L${LIB_DIR} +LDFLAGS = @LDFLAGS@ -pthread \ + -L${USR_LIB_DIR} \ + -L${CORE_LIB_DIR} \ + -L${AUTHENTICATION_LIB_DIR} \ + -L${LIB_DIR} #------------------------------------------------------------------------------- @@ -108,7 +119,10 @@ TEST_RUNNER_OBJS = ${TMP_DIR}/TestRunner.o \ ${TMP_DIR}/SchedulerDaemonXmlRpcClientTest.o \ ${TMP_DIR}/SchedulerClientFactoryTest.o -TEST_RUNNER_LIBS = -l${SCHEDULER_CLIENT_LIB} -l${CORE_LIB} -lxml++-1.0 \ +TEST_RUNNER_LIBS = -l${SCHEDULER_CLIENT_LIB} \ + -l${CORE_LIB} \ + -l${AUTHENTICATION_LIB} \ + -lboost_date_time-gcc -lxml++-1.0 \ -lcppunit -ldl -lxmlrpc++ -lssl @@ -136,6 +150,8 @@ docclean: ${RM} ${TEST_RESULTS} depclean: clean + ${MAKE} -C ${AUTHENTICATION_DIR} clean + ${MAKE} -C ${CORE_DIR} clean distclean: clean docclean ${RMDIR} ${TMP_DIR}/config* ${TMP_DIR}/autom4te* @@ -176,6 +192,9 @@ ${TEST_RUNNER}: ${CORE_LIB_FILE} ${TEST_RUNNER_OBJS} ${SCHEDULER_CLIENT_LIB_FILE ${CORE_LIB_FILE}: ${MAKE} -C ${CORE_DIR} +${AUTHENTICATION_LIB_FILE}: + ${MAKE} -C ${AUTHENTICATION_DIR} + ${SCHEDULER_EXE}: ${MAKE} -C ${SCHEDULER_DIR} diff --git a/livesupport/modules/schedulerClient/etc/configure.ac b/livesupport/modules/schedulerClient/etc/configure.ac index b963933f7..c1eb30838 100644 --- a/livesupport/modules/schedulerClient/etc/configure.ac +++ b/livesupport/modules/schedulerClient/etc/configure.ac @@ -21,7 +21,7 @@ dnl Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA dnl dnl dnl Author : $Author: maroy $ -dnl Version : $Revision: 1.1 $ +dnl Version : $Revision: 1.2 $ dnl Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/schedulerClient/etc/configure.ac,v $ dnl----------------------------------------------------------------------------- @@ -35,14 +35,14 @@ dnl----------------------------------------------------------------------------- AC_INIT(StorageClient, 1.0, bugs@campware.org) AC_PREREQ(2.59) AC_COPYRIGHT([Copyright (c) 2004 Media Development Loan Fund under the GNU GPL]) -AC_REVISION($Revision: 1.1 $) +AC_REVISION($Revision: 1.2 $) AC_CONFIG_SRCDIR(../include/LiveSupport/SchedulerClient/SchedulerClientFactory.h) AC_CONFIG_HEADERS(configure.h) AC_PROG_CXX() -AC_CHECK_HEADERS(getopt.h) +AC_CHECK_HEADERS(getopt.h sys/time.h) dnl----------------------------------------------------------------------------- dnl enable compilaton for code coverage data diff --git a/livesupport/modules/schedulerClient/include/LiveSupport/SchedulerClient/SchedulerClientInterface.h b/livesupport/modules/schedulerClient/include/LiveSupport/SchedulerClient/SchedulerClientInterface.h index 1ea557a6f..44c13d239 100644 --- a/livesupport/modules/schedulerClient/include/LiveSupport/SchedulerClient/SchedulerClientInterface.h +++ b/livesupport/modules/schedulerClient/include/LiveSupport/SchedulerClient/SchedulerClientInterface.h @@ -22,7 +22,7 @@ Author : $Author: maroy $ - Version : $Revision: 1.1 $ + Version : $Revision: 1.2 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/schedulerClient/include/LiveSupport/SchedulerClient/SchedulerClientInterface.h,v $ ------------------------------------------------------------------------------*/ @@ -41,8 +41,10 @@ #endif #include +#include "boost/date_time/posix_time/posix_time.hpp" #include "LiveSupport/Core/Ptr.h" +#include "LiveSupport/Core/SessionId.h" namespace LiveSupport { namespace SchedulerClient { @@ -62,7 +64,7 @@ using namespace LiveSupport::Core; * An interface to access the scheduler daemon as a client. * * @author $Author: maroy $ - * @version $Revision: 1.1 $ + * @version $Revision: 1.2 $ */ class SchedulerClientInterface { @@ -76,6 +78,18 @@ class SchedulerClientInterface virtual Ptr::Ref getVersion(void) throw () = 0; + + /** + * Return the current time at the scheduler server. + * + * @param sessionId a sessionId previously acquired by successfully + * authenticating with the authentication module + * @return the current time at the scheduler server. + */ + virtual Ptr::Ref + getSchedulerTime(Ptr::Ref sessionId) + throw () + = 0; }; diff --git a/livesupport/modules/schedulerClient/src/SchedulerDaemonXmlRpcClient.cxx b/livesupport/modules/schedulerClient/src/SchedulerDaemonXmlRpcClient.cxx index e4f551f0e..dfa9f5727 100644 --- a/livesupport/modules/schedulerClient/src/SchedulerDaemonXmlRpcClient.cxx +++ b/livesupport/modules/schedulerClient/src/SchedulerDaemonXmlRpcClient.cxx @@ -22,7 +22,7 @@ Author : $Author: maroy $ - Version : $Revision: 1.1 $ + Version : $Revision: 1.2 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/schedulerClient/src/SchedulerDaemonXmlRpcClient.cxx,v $ ------------------------------------------------------------------------------*/ @@ -39,6 +39,7 @@ #include #include +#include "LiveSupport/Core/TimeConversion.h" #include "SchedulerDaemonXmlRpcClient.h" using namespace boost::posix_time; @@ -150,3 +151,39 @@ SchedulerDaemonXmlRpcClient :: getVersion(void) throw () return result; } + +/*------------------------------------------------------------------------------ + * Get the current time from the server. + *----------------------------------------------------------------------------*/ +Ptr::Ref +SchedulerDaemonXmlRpcClient :: getSchedulerTime( + Ptr::Ref sessionId) + throw () +{ + XmlRpcValue xmlRpcParams; + XmlRpcValue xmlRpcResult; + Ptr::Ref result; + + XmlRpcClient xmlRpcClient(xmlRpcHost->c_str(), + xmlRpcPort, + xmlRpcUri->c_str(), + false); + + xmlRpcResult.clear(); + xmlRpcParams["sessionId"] = sessionId->getId(); + xmlRpcClient.execute("getSchedulerTime", xmlRpcParams, xmlRpcResult); + + if (xmlRpcResult.hasMember("schedulerTime")) { + struct tm time = xmlRpcResult["schedulerTime"]; + + try { + result = TimeConversion::tmToPtime(&time); + } catch (std::out_of_range &e) { + // TODO: report error, for some reason the returned time is wrong + } + + } + + return result; +} + diff --git a/livesupport/modules/schedulerClient/src/SchedulerDaemonXmlRpcClient.h b/livesupport/modules/schedulerClient/src/SchedulerDaemonXmlRpcClient.h index ef17b770d..8a66536e9 100644 --- a/livesupport/modules/schedulerClient/src/SchedulerDaemonXmlRpcClient.h +++ b/livesupport/modules/schedulerClient/src/SchedulerDaemonXmlRpcClient.h @@ -22,7 +22,7 @@ Author : $Author: maroy $ - Version : $Revision: 1.1 $ + Version : $Revision: 1.2 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/schedulerClient/src/SchedulerDaemonXmlRpcClient.h,v $ ------------------------------------------------------------------------------*/ @@ -90,7 +90,7 @@ using namespace LiveSupport::Core; * * * @author $Author: maroy $ - * @version $Revision: 1.1 $ + * @version $Revision: 1.2 $ */ class SchedulerDaemonXmlRpcClient : virtual public Configurable, @@ -162,6 +162,14 @@ class SchedulerDaemonXmlRpcClient : */ virtual Ptr::Ref getVersion(void) throw (); + + /** + * Return the current time at the scheduler server. + * + * @return the current time at the scheduler server. + */ + virtual Ptr::Ref + getSchedulerTime(Ptr::Ref sessionId) throw (); }; diff --git a/livesupport/modules/schedulerClient/src/SchedulerDaemonXmlRpcClientTest.cxx b/livesupport/modules/schedulerClient/src/SchedulerDaemonXmlRpcClientTest.cxx index baa4fbfb7..fc19c8180 100644 --- a/livesupport/modules/schedulerClient/src/SchedulerDaemonXmlRpcClientTest.cxx +++ b/livesupport/modules/schedulerClient/src/SchedulerDaemonXmlRpcClientTest.cxx @@ -22,7 +22,7 @@ Author : $Author: maroy $ - Version : $Revision: 1.1 $ + Version : $Revision: 1.2 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/schedulerClient/src/SchedulerDaemonXmlRpcClientTest.cxx,v $ ------------------------------------------------------------------------------*/ @@ -44,10 +44,15 @@ #include #include +#include "LiveSupport/Core/TimeConversion.h" +#include "LiveSupport/Authentication/AuthenticationClientFactory.h" #include "SchedulerDaemonXmlRpcClientTest.h" +using namespace boost::posix_time; + using namespace LiveSupport::Core; +using namespace LiveSupport::Authentication; using namespace LiveSupport::SchedulerClient; /* =================================================== local data structures */ @@ -62,12 +67,34 @@ CPPUNIT_TEST_SUITE_REGISTRATION(SchedulerDaemonXmlRpcClientTest); */ static const std::string configFileName = "etc/schedulerDaemonXmlRpcClient.xml"; +/** + * The name of the configuration file for the authentication client factory. + */ +static const std::string authenticationClientConfigFileName = + "etc/authenticationClient.xml"; + /* =============================================== local function prototypes */ /* ============================================================= module code */ +/*------------------------------------------------------------------------------ * Configure a Configurable with an XML file. + *----------------------------------------------------------------------------*/void +SchedulerDaemonXmlRpcClientTest :: configure( + Ptr::Ref configurable, + const std::string & fileName) + throw (std::invalid_argument, + xmlpp::exception) +{ + Ptr::Ref parser(new xmlpp::DomParser(fileName, true)); + const xmlpp::Document * document = parser->get_document(); + const xmlpp::Element * root = document->get_root_node(); + + configurable->configure(*root); +} + + /*------------------------------------------------------------------------------ * Set up the test environment *----------------------------------------------------------------------------*/ @@ -87,6 +114,24 @@ SchedulerDaemonXmlRpcClientTest :: setUp(void) throw () } catch (xmlpp::exception &e) { CPPUNIT_FAIL("error parsing configuration file"); } + + try { + Ptr::Ref acf; + acf = AuthenticationClientFactory::getInstance(); + configure(acf, authenticationClientConfigFileName); + authentication = acf->getAuthenticationClient(); + } catch (std::invalid_argument &e) { + std::cerr << e.what() << std::endl; + CPPUNIT_FAIL("semantic error in authentication configuration file"); + } catch (xmlpp::exception &e) { + std::cerr << e.what() << std::endl; + CPPUNIT_FAIL("error parsing authentication configuration file"); + } + + if (!(sessionId = authentication->login("root", "q"))) { + CPPUNIT_FAIL("could not log in to authentication server"); + } + } @@ -97,14 +142,18 @@ void SchedulerDaemonXmlRpcClientTest :: tearDown(void) throw () { schedulerClient.reset(); + + authentication->logout(sessionId); + sessionId.reset(); + authentication.reset(); } /*------------------------------------------------------------------------------ - * Test to see if we can log on and off + * Test to see if we can get the version string of the scheduler. *----------------------------------------------------------------------------*/ void -SchedulerDaemonXmlRpcClientTest :: firstTest(void) +SchedulerDaemonXmlRpcClientTest :: getVersionTest(void) throw (CPPUNIT_NS::Exception) { Ptr::Ref version = schedulerClient->getVersion(); @@ -112,3 +161,20 @@ SchedulerDaemonXmlRpcClientTest :: firstTest(void) CPPUNIT_ASSERT(version.get()); } + +/*------------------------------------------------------------------------------ + * Test to see if we can get the time of the scheduler. + *----------------------------------------------------------------------------*/ +void +SchedulerDaemonXmlRpcClientTest :: getSchedulerTimeTest(void) + throw (CPPUNIT_NS::Exception) +{ + Ptr::Ref time = schedulerClient->getSchedulerTime(sessionId); + Ptr::Ref now = TimeConversion::now(); + + CPPUNIT_ASSERT(time.get()); + // assume that the scheduler and the client is in the same year + // this can break at new year's eve - so don't run the test then :) + CPPUNIT_ASSERT(time->date().year() == now->date().year()); +} + diff --git a/livesupport/modules/schedulerClient/src/SchedulerDaemonXmlRpcClientTest.h b/livesupport/modules/schedulerClient/src/SchedulerDaemonXmlRpcClientTest.h index e882dc285..83c994963 100644 --- a/livesupport/modules/schedulerClient/src/SchedulerDaemonXmlRpcClientTest.h +++ b/livesupport/modules/schedulerClient/src/SchedulerDaemonXmlRpcClientTest.h @@ -22,7 +22,7 @@ Author : $Author: maroy $ - Version : $Revision: 1.1 $ + Version : $Revision: 1.2 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/schedulerClient/src/SchedulerDaemonXmlRpcClientTest.h,v $ ------------------------------------------------------------------------------*/ @@ -42,6 +42,7 @@ #include +#include "LiveSupport/Core/AuthenticationClientInterface.h" #include "SchedulerDaemonXmlRpcClient.h" namespace LiveSupport { @@ -61,13 +62,14 @@ using namespace LiveSupport::Core; * Unit test for the SchedulerDaemonXmlRpcClient class. * * @author $Author: maroy $ - * @version $Revision: 1.1 $ + * @version $Revision: 1.2 $ * @see SchedulerDaemonXmlRpcClient */ class SchedulerDaemonXmlRpcClientTest : public CPPUNIT_NS::TestFixture { CPPUNIT_TEST_SUITE(SchedulerDaemonXmlRpcClientTest); - CPPUNIT_TEST(firstTest); + CPPUNIT_TEST(getVersionTest); + CPPUNIT_TEST(getSchedulerTimeTest); CPPUNIT_TEST_SUITE_END(); private: @@ -76,15 +78,49 @@ class SchedulerDaemonXmlRpcClientTest : public CPPUNIT_NS::TestFixture */ Ptr::Ref schedulerClient; + /** + * An authentication client. + */ + Ptr::Ref authentication; + + /** + * A session ID from the authentication client login() method. + */ + Ptr::Ref sessionId; + + /** + * Configure a configurable with an XML file. + * + * @param configurable configure this + * @param fileName the name of the XML file to configure with. + * @exception std::invalid_argument on configuration errors. + * @exception xmlpp::exception on XML parsing errors. + */ + void + configure(Ptr::Ref configurable, + const std::string & fileName) + throw (std::invalid_argument, + xmlpp::exception); + + protected: /** - * A simple test. + * A simple test, just to get the version string from the scheduler. * * @exception CPPUNIT_NS::Exception on test failures. */ void - firstTest(void) throw (CPPUNIT_NS::Exception); + getVersionTest(void) throw (CPPUNIT_NS::Exception); + + /** + * A test to check the getSchedulerTime XML-RPC method. + * + * @exception CPPUNIT_NS::Exception on test failures. + */ + void + getSchedulerTimeTest(void) throw (CPPUNIT_NS::Exception); + public: