added scheduler client wrappers for the create backup methods
(part of #1581)
This commit is contained in:
parent
427ae579b0
commit
a7ecedfb2c
7 changed files with 368 additions and 1 deletions
|
@ -681,6 +681,18 @@ class XmlRpcTools
|
||||||
XmlRpc::XmlRpcValue & returnValue)
|
XmlRpc::XmlRpcValue & returnValue)
|
||||||
throw ();
|
throw ();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extract a fault string from the XML-RPC parameters.
|
||||||
|
*
|
||||||
|
* @param xmlRpcValue the XML-RPC parameter to extract from.
|
||||||
|
* @return a fault string that was found in the XML-RPC parameter.
|
||||||
|
* @exception std::invalid_argument if there was no "faultString"
|
||||||
|
* member in xmlRpcValue.
|
||||||
|
*/
|
||||||
|
static Ptr<Glib::ustring>::Ref
|
||||||
|
extractFaultString(XmlRpc::XmlRpcValue & xmlRpcValue)
|
||||||
|
throw (std::invalid_argument);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert a fault string to an XmlRpcValue.
|
* Convert a fault string to an XmlRpcValue.
|
||||||
*
|
*
|
||||||
|
|
|
@ -1066,6 +1066,25 @@ XmlRpcTools :: pathToXmlRpcValue(
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*------------------------------------------------------------------------------
|
||||||
|
* Extract a fault string from the XML-RPC parameters.
|
||||||
|
*----------------------------------------------------------------------------*/
|
||||||
|
Ptr<Glib::ustring>::Ref
|
||||||
|
XmlRpcTools :: extractFaultString(XmlRpc::XmlRpcValue & xmlRpcValue)
|
||||||
|
throw (std::invalid_argument)
|
||||||
|
{
|
||||||
|
if (!xmlRpcValue.hasMember(faultStringName)
|
||||||
|
|| xmlRpcValue[faultStringName].getType()
|
||||||
|
!= XmlRpc::XmlRpcValue::TypeString) {
|
||||||
|
throw std::invalid_argument("missing or bad faultString argument");
|
||||||
|
}
|
||||||
|
|
||||||
|
Ptr<Glib::ustring>::Ref faultString(new Glib::ustring(
|
||||||
|
xmlRpcValue[faultStringName] ));
|
||||||
|
return faultString;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*------------------------------------------------------------------------------
|
/*------------------------------------------------------------------------------
|
||||||
* Convert a fault string to an XmlRpcValue.
|
* Convert a fault string to an XmlRpcValue.
|
||||||
*----------------------------------------------------------------------------*/
|
*----------------------------------------------------------------------------*/
|
||||||
|
|
|
@ -50,7 +50,8 @@
|
||||||
#include "LiveSupport/Core/ScheduleEntry.h"
|
#include "LiveSupport/Core/ScheduleEntry.h"
|
||||||
#include "LiveSupport/Core/XmlRpcException.h"
|
#include "LiveSupport/Core/XmlRpcException.h"
|
||||||
#include "LiveSupport/Core/Playlist.h"
|
#include "LiveSupport/Core/Playlist.h"
|
||||||
#include "LiveSupport/Core/AudioClip.h"
|
#include "LiveSupport/Core/SearchCriteria.h"
|
||||||
|
#include "LiveSupport/Core/AsyncState.h"
|
||||||
|
|
||||||
namespace LiveSupport {
|
namespace LiveSupport {
|
||||||
namespace SchedulerClient {
|
namespace SchedulerClient {
|
||||||
|
@ -167,6 +168,70 @@ class SchedulerClientInterface
|
||||||
throw (XmlRpcException)
|
throw (XmlRpcException)
|
||||||
= 0;
|
= 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Start the schedule backup creation process.
|
||||||
|
* This will produce a combined backup, including a storage portion.
|
||||||
|
* The scheduler daemon first calls the storage server, and gets
|
||||||
|
* a storage backup archive file from it; then it adds the schedule
|
||||||
|
* backup to this archive file.
|
||||||
|
*
|
||||||
|
* @param sessionId a valid, authenticated session id.
|
||||||
|
* @param criteria the search criteria for the storage portion
|
||||||
|
* of the backup.
|
||||||
|
* @param fromTime entries are included in the schedule backup
|
||||||
|
* starting from this time.
|
||||||
|
* @param toTime entries are included in the schedule backup
|
||||||
|
* up to but not including this time.
|
||||||
|
* @return a token which can be used to query the backup process.
|
||||||
|
* @exception XmlRpcException if there is a problem with the XML-RPC
|
||||||
|
* call.
|
||||||
|
*/
|
||||||
|
virtual Ptr<Glib::ustring>::Ref
|
||||||
|
createBackupOpen(Ptr<SessionId>::Ref sessionId,
|
||||||
|
Ptr<SearchCriteria>::Ref criteria,
|
||||||
|
Ptr<ptime>::Ref fromTime,
|
||||||
|
Ptr<ptime>::Ref toTime) const
|
||||||
|
throw (XmlRpcException)
|
||||||
|
= 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check on the progress of the schedule backup creation process.
|
||||||
|
*
|
||||||
|
* @param token the token obtained from createBackupOpen().
|
||||||
|
* @param url return parameter;
|
||||||
|
* if a finishedState is returned, it contains the
|
||||||
|
* URL of the created backup file.
|
||||||
|
* @param path return parameter;
|
||||||
|
* if a finishedState is returned, it contains the
|
||||||
|
* local access path of the created backup file.
|
||||||
|
* @param errorMessage return parameter;
|
||||||
|
* if a failedState is returned, it contains the
|
||||||
|
* fault string.
|
||||||
|
* @return the state of the backup process: one of pendingState,
|
||||||
|
* finishedState, or failedState.
|
||||||
|
* @exception XmlRpcException if there is a problem with the XML-RPC
|
||||||
|
* call.
|
||||||
|
*/
|
||||||
|
virtual AsyncState
|
||||||
|
createBackupCheck(const Glib::ustring & token,
|
||||||
|
Ptr<const Glib::ustring>::Ref & url,
|
||||||
|
Ptr<const Glib::ustring>::Ref & path,
|
||||||
|
Ptr<const Glib::ustring>::Ref & errorMessage) const
|
||||||
|
throw (XmlRpcException)
|
||||||
|
= 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Close the schedule backup creation process.
|
||||||
|
*
|
||||||
|
* @param token the token obtained from createBackupOpen().
|
||||||
|
* @exception XmlRpcException if there is a problem with the XML-RPC
|
||||||
|
* call.
|
||||||
|
*/
|
||||||
|
virtual void
|
||||||
|
createBackupClose(const Glib::ustring & token) const
|
||||||
|
throw (XmlRpcException)
|
||||||
|
= 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A virtual destructor, as this class has virtual functions.
|
* A virtual destructor, as this class has virtual functions.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -366,3 +366,154 @@ SchedulerDaemonXmlRpcClient :: removeFromSchedule(
|
||||||
xmlRpcClient.close();
|
xmlRpcClient.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*------------------------------------------------------------------------------
|
||||||
|
* Start the schedule backup creation process.
|
||||||
|
*----------------------------------------------------------------------------*/
|
||||||
|
Ptr<Glib::ustring>::Ref
|
||||||
|
SchedulerDaemonXmlRpcClient :: createBackupOpen(
|
||||||
|
Ptr<SessionId>::Ref sessionId,
|
||||||
|
Ptr<SearchCriteria>::Ref criteria,
|
||||||
|
Ptr<ptime>::Ref fromTime,
|
||||||
|
Ptr<ptime>::Ref toTime) const
|
||||||
|
throw (Core::XmlRpcException)
|
||||||
|
{
|
||||||
|
XmlRpcValue xmlRpcParams;
|
||||||
|
XmlRpcValue xmlRpcResult;
|
||||||
|
|
||||||
|
XmlRpcClient xmlRpcClient(xmlRpcHost->c_str(),
|
||||||
|
xmlRpcPort,
|
||||||
|
xmlRpcUri->c_str(),
|
||||||
|
false);
|
||||||
|
|
||||||
|
XmlRpcTools::sessionIdToXmlRpcValue(sessionId, xmlRpcParams);
|
||||||
|
XmlRpcTools::searchCriteriaToXmlRpcValue(criteria, xmlRpcParams);
|
||||||
|
XmlRpcTools::fromTimeToXmlRpcValue(fromTime, xmlRpcParams);
|
||||||
|
XmlRpcTools::toTimeToXmlRpcValue(toTime, xmlRpcParams);
|
||||||
|
|
||||||
|
if (!xmlRpcClient.execute("createBackupOpen",
|
||||||
|
xmlRpcParams,
|
||||||
|
xmlRpcResult)) {
|
||||||
|
throw Core::XmlRpcCommunicationException(
|
||||||
|
"cannot execute XML-RPC method 'createBackupOpen'");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (xmlRpcClient.isFault()) {
|
||||||
|
std::stringstream eMsg;
|
||||||
|
eMsg << "XML-RPC method 'createBackupOpen' returned error message:\n"
|
||||||
|
<< xmlRpcResult;
|
||||||
|
throw Core::XmlRpcMethodFaultException(eMsg.str());
|
||||||
|
}
|
||||||
|
|
||||||
|
xmlRpcClient.close();
|
||||||
|
|
||||||
|
Ptr<Glib::ustring>::Ref token;
|
||||||
|
try {
|
||||||
|
token = XmlRpcTools::extractToken(xmlRpcResult);
|
||||||
|
} catch (std::invalid_argument &e) {
|
||||||
|
throw Core::XmlRpcMethodResponseException(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
return token;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*------------------------------------------------------------------------------
|
||||||
|
* Check on the progress of the schedule backup creation process.
|
||||||
|
*----------------------------------------------------------------------------*/
|
||||||
|
AsyncState
|
||||||
|
SchedulerDaemonXmlRpcClient :: createBackupCheck(
|
||||||
|
const Glib::ustring & token,
|
||||||
|
Ptr<const Glib::ustring>::Ref & url,
|
||||||
|
Ptr<const Glib::ustring>::Ref & path,
|
||||||
|
Ptr<const Glib::ustring>::Ref & errorMessage) const
|
||||||
|
throw (Core::XmlRpcException)
|
||||||
|
{
|
||||||
|
XmlRpcValue xmlRpcParams;
|
||||||
|
XmlRpcValue xmlRpcResult;
|
||||||
|
|
||||||
|
XmlRpcClient xmlRpcClient(xmlRpcHost->c_str(),
|
||||||
|
xmlRpcPort,
|
||||||
|
xmlRpcUri->c_str(),
|
||||||
|
false);
|
||||||
|
|
||||||
|
Ptr<const Glib::ustring>::Ref tokenPtr(new const Glib::ustring(token));
|
||||||
|
XmlRpcTools::tokenToXmlRpcValue(tokenPtr, xmlRpcParams);
|
||||||
|
|
||||||
|
if (!xmlRpcClient.execute("createBackupCheck",
|
||||||
|
xmlRpcParams,
|
||||||
|
xmlRpcResult)) {
|
||||||
|
throw Core::XmlRpcCommunicationException(
|
||||||
|
"cannot execute XML-RPC method 'createBackupCheck'");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (xmlRpcClient.isFault()) {
|
||||||
|
std::stringstream eMsg;
|
||||||
|
eMsg << "XML-RPC method 'createBackupCheck' returned error message:\n"
|
||||||
|
<< xmlRpcResult;
|
||||||
|
throw Core::XmlRpcMethodFaultException(eMsg.str());
|
||||||
|
}
|
||||||
|
|
||||||
|
xmlRpcClient.close();
|
||||||
|
|
||||||
|
AsyncState state;
|
||||||
|
try {
|
||||||
|
state = XmlRpcTools::extractBackupStatus(xmlRpcResult);
|
||||||
|
} catch (std::invalid_argument &e) {
|
||||||
|
throw Core::XmlRpcMethodResponseException(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (state == AsyncState::finishedState) {
|
||||||
|
try {
|
||||||
|
url = XmlRpcTools::extractUrl(xmlRpcResult);
|
||||||
|
path = XmlRpcTools::extractPath(xmlRpcResult);
|
||||||
|
} catch (std::invalid_argument &e) {
|
||||||
|
throw Core::XmlRpcMethodResponseException(e);
|
||||||
|
}
|
||||||
|
} else if (state == AsyncState::failedState) {
|
||||||
|
try {
|
||||||
|
errorMessage = XmlRpcTools::extractFaultString(xmlRpcResult);
|
||||||
|
} catch (std::invalid_argument &e) {
|
||||||
|
throw Core::XmlRpcMethodResponseException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*------------------------------------------------------------------------------
|
||||||
|
*
|
||||||
|
*----------------------------------------------------------------------------*/
|
||||||
|
void
|
||||||
|
SchedulerDaemonXmlRpcClient :: createBackupClose(
|
||||||
|
const Glib::ustring & token) const
|
||||||
|
throw (Core::XmlRpcException)
|
||||||
|
{
|
||||||
|
XmlRpcValue xmlRpcParams;
|
||||||
|
XmlRpcValue xmlRpcResult;
|
||||||
|
|
||||||
|
XmlRpcClient xmlRpcClient(xmlRpcHost->c_str(),
|
||||||
|
xmlRpcPort,
|
||||||
|
xmlRpcUri->c_str(),
|
||||||
|
false);
|
||||||
|
|
||||||
|
Ptr<const Glib::ustring>::Ref tokenPtr(new const Glib::ustring(token));
|
||||||
|
XmlRpcTools::tokenToXmlRpcValue(tokenPtr, xmlRpcParams);
|
||||||
|
|
||||||
|
if (!xmlRpcClient.execute("createBackupClose",
|
||||||
|
xmlRpcParams,
|
||||||
|
xmlRpcResult)) {
|
||||||
|
throw Core::XmlRpcCommunicationException(
|
||||||
|
"cannot execute XML-RPC method 'createBackupClose'");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (xmlRpcClient.isFault()) {
|
||||||
|
std::stringstream eMsg;
|
||||||
|
eMsg << "XML-RPC method 'createBackupClose' returned error message:\n"
|
||||||
|
<< xmlRpcResult;
|
||||||
|
throw Core::XmlRpcMethodFaultException(eMsg.str());
|
||||||
|
}
|
||||||
|
|
||||||
|
xmlRpcClient.close();
|
||||||
|
}
|
||||||
|
|
|
@ -252,6 +252,67 @@ class SchedulerDaemonXmlRpcClient :
|
||||||
removeFromSchedule(Ptr<SessionId>::Ref sessionId,
|
removeFromSchedule(Ptr<SessionId>::Ref sessionId,
|
||||||
Ptr<UniqueId>::Ref scheduleEntryId)
|
Ptr<UniqueId>::Ref scheduleEntryId)
|
||||||
throw (XmlRpcException);
|
throw (XmlRpcException);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Start the schedule backup creation process.
|
||||||
|
* This will produce a combined backup, including a storage portion.
|
||||||
|
* The scheduler daemon first calls the storage server, and gets
|
||||||
|
* a storage backup archive file from it; then it adds the schedule
|
||||||
|
* backup to this archive file.
|
||||||
|
*
|
||||||
|
* @param sessionId a valid, authenticated session id.
|
||||||
|
* @param criteria the search criteria for the storage portion
|
||||||
|
* of the backup.
|
||||||
|
* @param fromTime entries are included in the schedule backup
|
||||||
|
* starting from this time.
|
||||||
|
* @param toTime entries are included in the schedule backup
|
||||||
|
* up to but not including this time.
|
||||||
|
* @return a token which can be used to query the backup process.
|
||||||
|
* @exception XmlRpcException if there is a problem with the XML-RPC
|
||||||
|
* call.
|
||||||
|
*/
|
||||||
|
virtual Ptr<Glib::ustring>::Ref
|
||||||
|
createBackupOpen(Ptr<SessionId>::Ref sessionId,
|
||||||
|
Ptr<SearchCriteria>::Ref criteria,
|
||||||
|
Ptr<ptime>::Ref fromTime,
|
||||||
|
Ptr<ptime>::Ref toTime) const
|
||||||
|
throw (XmlRpcException);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check on the progress of the schedule backup creation process.
|
||||||
|
*
|
||||||
|
* @param token the token obtained from createBackupOpen().
|
||||||
|
* @param url return parameter;
|
||||||
|
* if a finishedState is returned, it contains the
|
||||||
|
* URL of the created backup file.
|
||||||
|
* @param path return parameter;
|
||||||
|
* if a finishedState is returned, it contains the
|
||||||
|
* local access path of the created backup file.
|
||||||
|
* @param errorMessage return parameter;
|
||||||
|
* if a failedState is returned, it contains the
|
||||||
|
* fault string.
|
||||||
|
* @return the state of the backup process: one of pendingState,
|
||||||
|
* finishedState, or failedState.
|
||||||
|
* @exception XmlRpcException if there is a problem with the XML-RPC
|
||||||
|
* call.
|
||||||
|
*/
|
||||||
|
virtual AsyncState
|
||||||
|
createBackupCheck(const Glib::ustring & token,
|
||||||
|
Ptr<const Glib::ustring>::Ref & url,
|
||||||
|
Ptr<const Glib::ustring>::Ref & path,
|
||||||
|
Ptr<const Glib::ustring>::Ref & errorMessage) const
|
||||||
|
throw (XmlRpcException);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Close the schedule backup creation process.
|
||||||
|
*
|
||||||
|
* @param token the token obtained from createBackupOpen().
|
||||||
|
* @exception XmlRpcException if there is a problem with the XML-RPC
|
||||||
|
* call.
|
||||||
|
*/
|
||||||
|
virtual void
|
||||||
|
createBackupClose(const Glib::ustring & token) const
|
||||||
|
throw (XmlRpcException);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -332,3 +332,53 @@ SchedulerDaemonXmlRpcClientTest :: xmlRpcErrorTest(void)
|
||||||
CPPUNIT_ASSERT(gotException);
|
CPPUNIT_ASSERT(gotException);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*------------------------------------------------------------------------------
|
||||||
|
* Test the create backup functions.
|
||||||
|
*----------------------------------------------------------------------------*/
|
||||||
|
void
|
||||||
|
SchedulerDaemonXmlRpcClientTest :: createBackupTest(void)
|
||||||
|
throw (CPPUNIT_NS::Exception)
|
||||||
|
{
|
||||||
|
Ptr<SearchCriteria>::Ref criteria(new SearchCriteria);
|
||||||
|
criteria->setLimit(10);
|
||||||
|
Ptr<ptime>::Ref from(new ptime(time_from_string("2004-07-23 10:00:00")));
|
||||||
|
Ptr<ptime>::Ref to(new ptime(time_from_string("2004-07-23 11:00:00")));
|
||||||
|
|
||||||
|
Ptr<Glib::ustring>::Ref token;
|
||||||
|
CPPUNIT_ASSERT_NO_THROW(
|
||||||
|
token = schedulerClient->createBackupOpen(sessionId,
|
||||||
|
criteria,
|
||||||
|
from,
|
||||||
|
to);
|
||||||
|
);
|
||||||
|
CPPUNIT_ASSERT(token);
|
||||||
|
|
||||||
|
Ptr<const Glib::ustring>::Ref url;
|
||||||
|
Ptr<const Glib::ustring>::Ref path;
|
||||||
|
Ptr<const Glib::ustring>::Ref errorMessage;
|
||||||
|
AsyncState status;
|
||||||
|
int iterations = 20;
|
||||||
|
do {
|
||||||
|
std::cerr << "-/|\\"[iterations%4] << '\b';
|
||||||
|
sleep(1);
|
||||||
|
CPPUNIT_ASSERT_NO_THROW(
|
||||||
|
status = schedulerClient->createBackupCheck(*token,
|
||||||
|
url,
|
||||||
|
path,
|
||||||
|
errorMessage);
|
||||||
|
);
|
||||||
|
CPPUNIT_ASSERT(status == AsyncState::pendingState
|
||||||
|
|| status == AsyncState::finishedState
|
||||||
|
|| status == AsyncState::failedState);
|
||||||
|
} while (--iterations && status == AsyncState::pendingState);
|
||||||
|
|
||||||
|
CPPUNIT_ASSERT_EQUAL(AsyncState::finishedState, status);
|
||||||
|
// TODO: test accessibility of the URL?
|
||||||
|
|
||||||
|
CPPUNIT_ASSERT_NO_THROW(
|
||||||
|
schedulerClient->createBackupClose(*token);
|
||||||
|
);
|
||||||
|
// TODO: test existence of schedule backup in tarball
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -75,6 +75,7 @@ class SchedulerDaemonXmlRpcClientTest : public BaseTestMethod
|
||||||
CPPUNIT_TEST(displayScheduleEmptyTest);
|
CPPUNIT_TEST(displayScheduleEmptyTest);
|
||||||
CPPUNIT_TEST(playlistMgmtTest);
|
CPPUNIT_TEST(playlistMgmtTest);
|
||||||
CPPUNIT_TEST(xmlRpcErrorTest);
|
CPPUNIT_TEST(xmlRpcErrorTest);
|
||||||
|
CPPUNIT_TEST(createBackupTest);
|
||||||
CPPUNIT_TEST_SUITE_END();
|
CPPUNIT_TEST_SUITE_END();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -132,6 +133,14 @@ class SchedulerDaemonXmlRpcClientTest : public BaseTestMethod
|
||||||
void
|
void
|
||||||
xmlRpcErrorTest(void) throw (CPPUNIT_NS::Exception);
|
xmlRpcErrorTest(void) throw (CPPUNIT_NS::Exception);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test the create backup functions.
|
||||||
|
*
|
||||||
|
* @exception CPPUNIT_NS::Exception on test failures.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
createBackupTest(void) throw (CPPUNIT_NS::Exception);
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue