Centralized the install/uninstall operations for the scheduler into a set of PHP files. This will make it easier to maintain the database because 1) the code is now in a scripting language which means, for instance, that writing upgrade scripts will be easier and also allows these install scripts to use the same infrastructure and code as the storageServer, 2) it allows the developers to see the database creation all in one place 3) simplifies and speeds up the C++ code.

This commit is contained in:
paul 2007-01-09 17:26:53 +00:00
parent 7911089b62
commit 219c8cc06f
43 changed files with 602 additions and 1270 deletions

View File

@ -83,12 +83,12 @@ case "$mode" in
'install') 'install')
echo "Installing Campcaster scheduler database tables..." echo "Installing Campcaster scheduler database tables..."
$scheduler_exe -c $config_file install php install.php -c $config_file
;; ;;
'uninstall') 'uninstall')
echo "Uninstalling Campcaster scheduler database tables..." echo "Uninstalling Campcaster scheduler database tables..."
$scheduler_exe -c $config_file uninstall php uninstall.php -c $config_file
;; ;;
'kill') 'kill')

View File

@ -0,0 +1,27 @@
<?php
/**
* @author Paul Baranowski <paul@paulbaranowski.org>
* @version $Revision: 2774 $
* @package Campcaster
* @subpackage Scheduler
* @copyright 2006 MDLF, Inc.
* @license http://www.gnu.org/licenses/gpl.txt
* @link http://www.campware.org
*
*/
// Do not allow remote execution
$arr = array_diff_assoc($_SERVER, $_ENV);
if (isset($arr["DOCUMENT_ROOT"]) && ($arr["DOCUMENT_ROOT"] != "") ) {
header("HTTP/1.1 400");
header("Content-type: text/plain; charset=UTF-8");
echo "400 Not executable\r\n";
exit(1);
}
require_once('installInit.php');
require_once('installScheduler.php');
echo " * Scheduler install complete\n";
?>

View File

@ -0,0 +1,80 @@
<?php
if (!function_exists('pg_connect')) {
trigger_error("PostgreSQL PHP extension required and not found.", E_USER_ERROR);
exit(2);
}
require_once('DB.php');
function camp_db_table_exists($p_name)
{
global $CC_DBC;
$sql = "SELECT * FROM ".$p_name;
$result = $CC_DBC->GetOne($sql);
if (PEAR::isError($result)) {
return false;
}
return true;
}
function camp_install_query($sql)
{
global $CC_DBC;
$result = $CC_DBC->query($sql);
if (PEAR::isError($result)) {
echo "Error! ".$result->getMessage()."\n";
echo " SQL statement was:\n";
echo " ".$sql."\n\n";
} else {
echo "done.\n";
}
}
$options = getopt("c:");
if (!$options) {
echo "\nYou must specific the config file with -c.\n\n";
exit;
}
$configFile = $options['c'];
if (!file_exists($configFile)) {
echo "\nThe config file '$configFile' does not exist.\n\n";
exit;
}
echo " * Using config file $configFile\n";
$xml = file_get_contents($configFile);
$parser = xml_parser_create();
xml_parse_into_struct($parser, $xml, $vals, $index);
xml_parser_free($parser);
$CC_CONFIG['dsn'] = array('hostspec' => 'localhost',
'phptype' => 'pgsql');
// Get the user index
$userIndex = $index['SIMPLECONNECTIONMANAGER'][0];
$CC_CONFIG['dsn']['username'] = $vals[$userIndex]['attributes']['USERNAME'];
$CC_CONFIG['dsn']['password'] = $vals[$userIndex]['attributes']['PASSWORD'];
$CC_CONFIG['dsn']['database'] = $vals[$userIndex]['attributes']['DSN'];
$CC_CONFIG['playlogTable'] = 'playlog';
$CC_CONFIG['scheduleTable'] = 'schedule';
$CC_CONFIG['backupTable'] = 'backup';
$CC_DBC = DB::connect($CC_CONFIG['dsn'], TRUE);
if (PEAR::isError($CC_DBC)) {
echo $CC_DBC->getMessage()."\n";
echo $CC_DBC->getUserInfo()."\n";
echo "Database connection problem.\n";
echo "Check if database '{$CC_CONFIG['dsn']['database']}' exists".
" with corresponding permissions.\n";
exit(1);
} else {
echo " * Connected to database\n";
}
$CC_DBC->setFetchMode(DB_FETCHMODE_ASSOC);
?>

View File

@ -0,0 +1,51 @@
<?php
// Do not allow remote execution
$arr = array_diff_assoc($_SERVER, $_ENV);
if (isset($arr["DOCUMENT_ROOT"]) && ($arr["DOCUMENT_ROOT"] != "") ) {
header("HTTP/1.1 400");
header("Content-type: text/plain; charset=UTF-8");
echo "400 Not executable\r\n";
exit(1);
}
if (!camp_db_table_exists($CC_CONFIG['scheduleTable'])) {
echo " * Creating database table ".$CC_CONFIG['scheduleTable']."...";
$sql = "CREATE TABLE ".$CC_CONFIG['scheduleTable']."("
." id BIGINT NOT NULL,"
." playlist BIGINT NOT NULL,"
." starts TIMESTAMP NOT NULL,"
." ends TIMESTAMP NOT NULL,"
." PRIMARY KEY(id))";
camp_install_query($sql);
} else {
echo " * Skipping: database table already exists: ".$CC_CONFIG['scheduleTable']."\n";
}
if (!camp_db_table_exists($CC_CONFIG['playlogTable'])) {
echo " * Creating database table ".$CC_CONFIG['playlogTable']."...";
$sql = "CREATE TABLE ".$CC_CONFIG['playlogTable']."("
." id BIGINT NOT NULL,"
." audioClipId BIGINT NOT NULL,"
." timestamp TIMESTAMP NOT NULL,"
." PRIMARY KEY(id))";
camp_install_query($sql);
} else {
echo " * Skipping: database table already exists: ".$CC_CONFIG['playlogTable']."\n";
}
if (!camp_db_table_exists($CC_CONFIG['backupTable'])) {
echo " * Creating database table ".$CC_CONFIG['backupTable']."...";
$sql = "CREATE TABLE ".$CC_CONFIG['backupTable']." ("
." token VARCHAR(64) NOT NULL,"
." sessionId VARCHAR(64) NOT NULL,"
." status VARCHAR(32) NOT NULL,"
." fromTime TIMESTAMP NOT NULL,"
." toTime TIMESTAMP NOT NULL,"
." PRIMARY KEY(token))";
camp_install_query($sql);
} else {
echo " * Skipping: database table already exists: ".$CC_CONFIG['backupTable']."\n";
}
?>

View File

@ -0,0 +1,27 @@
<?php
/**
* @author Paul Baranowski <paul@paulbaranowski.org>
* @version $Revision: 2774 $
* @package Campcaster
* @subpackage Scheduler
* @copyright 2006 MDLF, Inc.
* @license http://www.gnu.org/licenses/gpl.txt
* @link http://www.campware.org
*/
// Do not allow remote execution.
$arr = array_diff_assoc($_SERVER, $_ENV);
if (isset($arr["DOCUMENT_ROOT"]) && ($arr["DOCUMENT_ROOT"] != "") ) {
header("HTTP/1.1 400");
header("Content-type: text/plain; charset=UTF-8");
echo "400 Not executable\r\n";
exit;
}
require_once('installInit.php');
require_once('uninstallScheduler.php');
echo " * Scheduler uninstall complete\n";
?>

View File

@ -0,0 +1,34 @@
<?PHP
// Do not allow remote execution.
$arr = array_diff_assoc($_SERVER, $_ENV);
if (isset($arr["DOCUMENT_ROOT"]) && ($arr["DOCUMENT_ROOT"] != "") ) {
header("HTTP/1.1 400");
header("Content-type: text/plain; charset=UTF-8");
echo "400 Not executable\r\n";
exit;
}
if (camp_db_table_exists($CC_CONFIG['scheduleTable'])) {
echo " * Removing database table ".$CC_CONFIG['scheduleTable']."...";
camp_install_query("DROP TABLE ".$CC_CONFIG['scheduleTable']);
} else {
echo " * Skipping: database table ".$CC_CONFIG['scheduleTable']."\n";
}
if (camp_db_table_exists($CC_CONFIG['backupTable'])) {
echo " * Removing database table ".$CC_CONFIG['backupTable']."...";
camp_install_query("DROP TABLE ".$CC_CONFIG['backupTable']);
} else {
echo " * Skipping: database table ".$CC_CONFIG['backupTable']."\n";
}
if (camp_db_table_exists($CC_CONFIG['playlogTable'])) {
echo " * Removing database table ".$CC_CONFIG['playlogTable']."...";
$sql = "DROP TABLE ".$CC_CONFIG['playlogTable'];
camp_install_query($sql);
} else {
echo " * Skipping: database table ".$CC_CONFIG['playlogTable']."\n";
}
?>

View File

@ -124,46 +124,3 @@ BackupFactory :: configure(const xmlpp::Element & element)
throw std::invalid_argument("could not configure BackupFactory"); throw std::invalid_argument("could not configure BackupFactory");
} }
} }
/*------------------------------------------------------------------------------
* Install the backup factory.
*----------------------------------------------------------------------------*/
void
BackupFactory :: install(void) throw (std::exception)
{
if (!backup) {
throw std::logic_error("BackupFactory not yet configured");
}
backup->install();
}
/*------------------------------------------------------------------------------
* Check to see if the backup factory has already been installed.
*----------------------------------------------------------------------------*/
bool
BackupFactory :: isInstalled(void) throw (std::exception)
{
if (!backup) {
throw std::logic_error("BackupFactory not yet configured");
}
return backup->isInstalled();
}
/*------------------------------------------------------------------------------
* Install the backup factory.
*----------------------------------------------------------------------------*/
void
BackupFactory :: uninstall(void) throw (std::exception)
{
if (!backup) {
throw std::logic_error("BackupFactory not yet configured");
}
backup->uninstall();
}

View File

@ -39,7 +39,6 @@
#include <stdexcept> #include <stdexcept>
#include "LiveSupport/Core/Configurable.h" #include "LiveSupport/Core/Configurable.h"
#include "LiveSupport/Core/Installable.h"
#include "BackupInterface.h" #include "BackupInterface.h"
@ -88,8 +87,7 @@ using namespace LiveSupport::Core;
* @version $Revision$ * @version $Revision$
* @see PostgresqlBackup * @see PostgresqlBackup
*/ */
class BackupFactory : virtual public Configurable, class BackupFactory : virtual public Configurable
virtual public Installable
{ {
private: private:
/** /**
@ -158,38 +156,6 @@ class BackupFactory : virtual public Configurable,
throw (std::invalid_argument, throw (std::invalid_argument,
std::logic_error); std::logic_error);
/**
* Install the component.
* This step involves creating the environment in which the component
* will run. This may be creation of coniguration files,
* database tables, etc.
*
* @exception std::exception on installation problems,
* especially if the BackupFactory was not yet configured.
*/
virtual void
install(void) throw (std::exception);
/**
* Check to see if the component has already been installed.
*
* @return true if the component is properly installed,
* false otherwise
* @exception std::exception on generic problems
*/
virtual bool
isInstalled(void) throw (std::exception);
/**
* Uninstall the component.
* Removes all the resources created in the install step.
*
* @exception std::exception on unistallation problems,
e especially if the BackupFactory was not yet configured.
*/
virtual void
uninstall(void) throw (std::exception);
/** /**
* Return a backup. * Return a backup.
* *

View File

@ -40,7 +40,6 @@
#include <boost/date_time/posix_time/posix_time.hpp> #include <boost/date_time/posix_time/posix_time.hpp>
#include "LiveSupport/Core/Ptr.h" #include "LiveSupport/Core/Ptr.h"
#include "LiveSupport/Core/Installable.h"
#include "LiveSupport/Core/Playlist.h" #include "LiveSupport/Core/Playlist.h"
#include "LiveSupport/Core/ScheduleEntry.h" #include "LiveSupport/Core/ScheduleEntry.h"
#include "LiveSupport/StorageClient/StorageClientInterface.h" #include "LiveSupport/StorageClient/StorageClientInterface.h"
@ -78,7 +77,7 @@ using namespace LiveSupport::StorageClient;
* @author $Author$ * @author $Author$
* @version $Revision$ * @version $Revision$
*/ */
class BackupInterface : virtual public Installable class BackupInterface
{ {
public: public:
/** /**

View File

@ -88,7 +88,6 @@ DisplayScheduleMethodTest :: setUp(void) throw (CPPUNIT_NS::Exception)
storage->reset(); storage->reset();
schedule = scheduler->getSchedule(); schedule = scheduler->getSchedule();
schedule->install();
} catch (std::invalid_argument &e) { } catch (std::invalid_argument &e) {
CPPUNIT_FAIL("semantic error in configuration file"); CPPUNIT_FAIL("semantic error in configuration file");
@ -117,8 +116,6 @@ DisplayScheduleMethodTest :: setUp(void) throw (CPPUNIT_NS::Exception)
void void
DisplayScheduleMethodTest :: tearDown(void) throw (CPPUNIT_NS::Exception) DisplayScheduleMethodTest :: tearDown(void) throw (CPPUNIT_NS::Exception)
{ {
schedule->uninstall();
authentication->logout(sessionId); authentication->logout(sessionId);
sessionId.reset(); sessionId.reset();
authentication.reset(); authentication.reset();

View File

@ -87,8 +87,6 @@ GeneratePlayReportMethodTest :: setUp(void) throw (CPPUNIT_NS::Exception)
storage->reset(); storage->reset();
playLog = scheduler->getPlayLog(); playLog = scheduler->getPlayLog();
playLog->install();
insertEntries(); insertEntries();
} catch (std::invalid_argument &e) { } catch (std::invalid_argument &e) {
@ -116,8 +114,6 @@ GeneratePlayReportMethodTest :: setUp(void) throw (CPPUNIT_NS::Exception)
void void
GeneratePlayReportMethodTest :: tearDown(void) throw (CPPUNIT_NS::Exception) GeneratePlayReportMethodTest :: tearDown(void) throw (CPPUNIT_NS::Exception)
{ {
playLog->uninstall();
authentication->logout(sessionId); authentication->logout(sessionId);
sessionId.reset(); sessionId.reset();
authentication.reset(); authentication.reset();

View File

@ -114,45 +114,3 @@ PlayLogFactory :: configure(const xmlpp::Element & element)
} }
} }
/*------------------------------------------------------------------------------
* Install the play log factory.
*----------------------------------------------------------------------------*/
void
PlayLogFactory :: install(void) throw (std::exception)
{
if (!playLog) {
throw std::logic_error("PlayLogFactory not yet configured");
}
playLog->install();
}
/*------------------------------------------------------------------------------
* Check to see if the factory has already been installed.
*----------------------------------------------------------------------------*/
bool
PlayLogFactory :: isInstalled(void) throw (std::exception)
{
if (!playLog) {
throw std::logic_error("PlayLogFactory not yet configured");
}
return playLog->isInstalled();
}
/*------------------------------------------------------------------------------
* Uninstall the play log factory.
*----------------------------------------------------------------------------*/
void
PlayLogFactory :: uninstall(void) throw (std::exception)
{
if (!playLog) {
throw std::logic_error("PlayLogFactory not yet configured");
}
playLog->uninstall();
}

View File

@ -43,7 +43,6 @@
#include <stdexcept> #include <stdexcept>
#include "LiveSupport/Core/Configurable.h" #include "LiveSupport/Core/Configurable.h"
#include "LiveSupport/Core/Installable.h"
#include "PlayLogInterface.h" #include "PlayLogInterface.h"
@ -89,8 +88,7 @@ using namespace LiveSupport::Core;
* @version $Revision$ * @version $Revision$
* @see PostgresqlPlayLog * @see PostgresqlPlayLog
*/ */
class PlayLogFactory : virtual public Configurable, class PlayLogFactory : virtual public Configurable
virtual public Installable
{ {
private: private:
/** /**
@ -159,38 +157,6 @@ class PlayLogFactory : virtual public Configurable,
throw (std::invalid_argument, throw (std::invalid_argument,
std::logic_error); std::logic_error);
/**
* Install the component.
* This step involves creating the environment in which the component
* will run. This may be creation of coniguration files,
* database tables, etc.
*
* @exception std::exception on installation problems,
* especially if the PlayLogFactory was not yet configured.
*/
virtual void
install(void) throw (std::exception);
/**
* Check to see if the component has already been installed.
*
* @return true if the component is properly installed,
* false otherwise
* @exception std::exception on generic problems
*/
virtual bool
isInstalled(void) throw (std::exception);
/**
* Uninstall the component.
* Removes all the resources created in the install step.
*
* @exception std::exception on unistallation problems,
e especially if the PlayLogFactory was not yet configured.
*/
virtual void
uninstall(void) throw (std::exception);
/** /**
* Return a play log. * Return a play log.
* *

View File

@ -44,7 +44,6 @@
#include <boost/date_time/posix_time/posix_time.hpp> #include <boost/date_time/posix_time/posix_time.hpp>
#include "LiveSupport/Core/Ptr.h" #include "LiveSupport/Core/Ptr.h"
#include "LiveSupport/Core/Installable.h"
#include "LiveSupport/Core/Playlist.h" #include "LiveSupport/Core/Playlist.h"
#include "LiveSupport/Core/PlayLogEntry.h" #include "LiveSupport/Core/PlayLogEntry.h"
@ -72,7 +71,7 @@ using namespace LiveSupport::Core;
* @author $Author$ * @author $Author$
* @version $Revision$ * @version $Revision$
*/ */
class PlayLogInterface : virtual public Installable class PlayLogInterface
{ {
public: public:
/** /**

View File

@ -99,13 +99,6 @@ PlaylistEventContainerTest :: setUp(void) throw (CPPUNIT_NS::Exception)
std::cerr << e.what() << std::endl; std::cerr << e.what() << std::endl;
CPPUNIT_FAIL("error parsing configuration file"); CPPUNIT_FAIL("error parsing configuration file");
} }
try {
schedule->install();
playLog->install();
} catch (std::exception &e) {
std::cerr << e.what() << std::endl;
CPPUNIT_FAIL("can't install schedule factory");
}
audioPlayer->initialize(); audioPlayer->initialize();
if (!(sessionId = authentication->login("root", "q"))) { if (!(sessionId = authentication->login("root", "q"))) {
@ -121,8 +114,6 @@ void
PlaylistEventContainerTest :: tearDown(void) throw (CPPUNIT_NS::Exception) PlaylistEventContainerTest :: tearDown(void) throw (CPPUNIT_NS::Exception)
{ {
audioPlayer->deInitialize(); audioPlayer->deInitialize();
schedule->uninstall();
playLog->uninstall();
playLog.reset(); playLog.reset();
schedule.reset(); schedule.reset();

View File

@ -97,7 +97,6 @@ PlaylistEventTest :: setUp(void) throw (CPPUNIT_NS::Exception)
} }
audioPlayer->initialize(); audioPlayer->initialize();
playLog->install();
duration.reset(new time_duration(seconds(30))); duration.reset(new time_duration(seconds(30)));
@ -113,7 +112,6 @@ PlaylistEventTest :: setUp(void) throw (CPPUNIT_NS::Exception)
void void
PlaylistEventTest :: tearDown(void) throw (CPPUNIT_NS::Exception) PlaylistEventTest :: tearDown(void) throw (CPPUNIT_NS::Exception)
{ {
playLog->uninstall();
audioPlayer->deInitialize(); audioPlayer->deInitialize();
duration.reset(); duration.reset();

View File

@ -109,26 +109,6 @@ const std::string scheduleExportFileName = "meta-inf/scheduler.xml";
*----------------------------------------------------------------------------*/ *----------------------------------------------------------------------------*/
const std::string check1Stmt = "SELECT 1"; const std::string check1Stmt = "SELECT 1";
/*------------------------------------------------------------------------------
* The SQL create statement, used for installation.
*----------------------------------------------------------------------------*/
const std::string createStmt =
"CREATE TABLE backup\n"
"(\n"
" token VARCHAR(64) NOT NULL,\n"
" sessionId VARCHAR(64) NOT NULL,\n"
" status VARCHAR(32) NOT NULL,\n"
" fromTime TIMESTAMP NOT NULL,\n"
" toTime TIMESTAMP NOT NULL,\n"
"\n"
" PRIMARY KEY(token)\n"
");";
/*------------------------------------------------------------------------------
* The SQL create statement, used for installation.
*----------------------------------------------------------------------------*/
const std::string dropStmt = "DROP TABLE backup;";
/*------------------------------------------------------------------------------ /*------------------------------------------------------------------------------
* A statement to check if the backup table exists. * A statement to check if the backup table exists.
*----------------------------------------------------------------------------*/ *----------------------------------------------------------------------------*/
@ -192,97 +172,6 @@ PostgresqlBackup :: configure(const xmlpp::Element & element)
} }
/*------------------------------------------------------------------------------
* Install the PostgresqlBackup.
*----------------------------------------------------------------------------*/
void
PostgresqlBackup :: install(void) throw (std::exception)
{
if (!isInstalled()) {
Ptr<Connection>::Ref conn;
try {
conn = connectionManager->getConnection();
Ptr<Statement>::Ref stmt(conn->createStatement());
stmt->execute(createStmt);
connectionManager->returnConnection(conn);
} catch (std::exception &e) {
if (conn) {
connectionManager->returnConnection(conn);
}
throw;
}
}
}
/*------------------------------------------------------------------------------
* Check to see if the PostgresqlBackup has already been installed.
*----------------------------------------------------------------------------*/
bool
PostgresqlBackup :: isInstalled(void) throw (std::exception)
{
Ptr<Connection>::Ref conn;
try {
Ptr<Statement>::Ref stmt;
ResultSet * res;
conn = connectionManager->getConnection();
// see if we can connect at all
stmt.reset(conn->createStatement());
stmt->execute(check1Stmt);
res = stmt->getResultSet();
if (!res->next() || (res->getInt(1) != 1)) {
throw std::runtime_error("Can't connect to database");
}
// see if the backup table exists
try {
stmt.reset(conn->createStatement());
stmt->execute(backupCountStmt);
res = stmt->getResultSet();
if (!res->next() || (res->getInt(1) < 0)) {
connectionManager->returnConnection(conn);
return false;
}
} catch (std::exception &e) {
connectionManager->returnConnection(conn);
return false;
}
connectionManager->returnConnection(conn);
} catch (std::exception &e) {
if (conn) {
connectionManager->returnConnection(conn);
}
throw;
}
return true;
}
/*------------------------------------------------------------------------------
* Uninstall the PostgresqlBackup.
*----------------------------------------------------------------------------*/
void
PostgresqlBackup :: uninstall(void) throw (std::exception)
{
Ptr<Connection>::Ref conn;
try {
conn = connectionManager->getConnection();
Ptr<Statement>::Ref stmt(conn->createStatement());
stmt->execute(dropStmt);
connectionManager->returnConnection(conn);
} catch (std::exception &e) {
if (conn) {
connectionManager->returnConnection(conn);
}
throw;
}
}
/*------------------------------------------------------------------------------ /*------------------------------------------------------------------------------
* Start a backup process. * Start a backup process.
*----------------------------------------------------------------------------*/ *----------------------------------------------------------------------------*/

View File

@ -215,36 +215,6 @@ class PostgresqlBackup : public Configurable,
throw (std::invalid_argument, throw (std::invalid_argument,
std::logic_error); std::logic_error);
/**
* Install the component.
* This step involves creating the environment in which the component
* will run. This may be creation of coniguration files,
* database tables, etc.
*
* @exception std::exception on installation problems.
*/
virtual void
install(void) throw (std::exception);
/**
* Check to see if the component has already been installed.
*
* @return true if the component is properly installed,
* false otherwise
* @exception std::exception on generic problems
*/
virtual bool
isInstalled(void) throw (std::exception);
/**
* Uninstall the component.
* Removes all the resources created in the install step.
*
* @exception std::exception on unistallation problems.
*/
virtual void
uninstall(void) throw (std::exception);
/** /**
* Start to create a backup by calling the storage, and also * Start to create a backup by calling the storage, and also
* adding a backup of the schedule. * adding a backup of the schedule.

View File

@ -91,7 +91,6 @@ PostgresqlBackupTest :: setUp(void) throw (CPPUNIT_NS::Exception)
backup.reset(new PostgresqlBackup(connectionManager, backup.reset(new PostgresqlBackup(connectionManager,
storage, storage,
schedule)); schedule));
backup->install();
} catch (std::invalid_argument &e) { } catch (std::invalid_argument &e) {
CPPUNIT_FAIL("semantic error in configuration file"); CPPUNIT_FAIL("semantic error in configuration file");
} catch (xmlpp::exception &e) { } catch (xmlpp::exception &e) {
@ -118,9 +117,6 @@ PostgresqlBackupTest :: tearDown(void) throw (CPPUNIT_NS::Exception)
CPPUNIT_ASSERT_NO_THROW( CPPUNIT_ASSERT_NO_THROW(
authentication->logout(sessionId); authentication->logout(sessionId);
); );
CPPUNIT_ASSERT_NO_THROW(
backup->uninstall();
);
remove(tempBackupTarFileName.c_str()); remove(tempBackupTarFileName.c_str());
} }

View File

@ -68,25 +68,6 @@ const std::string PostgresqlPlayLog::check1Stmt = "SELECT 1";
const std::string PostgresqlPlayLog::logCountStmt = const std::string PostgresqlPlayLog::logCountStmt =
"SELECT COUNT(*) FROM playLog"; "SELECT COUNT(*) FROM playLog";
/*------------------------------------------------------------------------------
* The SQL create statement, used for installation.
*----------------------------------------------------------------------------*/
const std::string PostgresqlPlayLog::createStmt =
"CREATE TABLE playLog\n"
"(\n"
" id BIGINT NOT NULL,\n"
" audioClipId BIGINT NOT NULL,\n"
" timestamp TIMESTAMP NOT NULL,\n"
"\n"
" PRIMARY KEY(id)\n"
");";
/*------------------------------------------------------------------------------
* The SQL create statement, used for installation.
*----------------------------------------------------------------------------*/
const std::string PostgresqlPlayLog::dropStmt =
"DROP TABLE playLog;";
/*------------------------------------------------------------------------------ /*------------------------------------------------------------------------------
* The SQL statement for adding a play log entry. * The SQL statement for adding a play log entry.
* It's a simple insert. * It's a simple insert.
@ -131,97 +112,6 @@ PostgresqlPlayLog :: configure(const xmlpp::Element & element)
} }
/*------------------------------------------------------------------------------
* Install the PostgresqlPlayLog.
*----------------------------------------------------------------------------*/
void
PostgresqlPlayLog :: install(void) throw (std::exception)
{
if (!isInstalled()) {
Ptr<Connection>::Ref conn;
try {
conn = cm->getConnection();
Ptr<Statement>::Ref stmt(conn->createStatement());
stmt->execute(createStmt);
cm->returnConnection(conn);
} catch (std::exception &e) {
if (conn) {
cm->returnConnection(conn);
}
throw std::logic_error(e.what());
}
}
}
/*------------------------------------------------------------------------------
* Check to see if the PostgresqlPlayLog has already been installed.
*----------------------------------------------------------------------------*/
bool
PostgresqlPlayLog :: isInstalled(void) throw (std::exception)
{
Ptr<Connection>::Ref conn;
try {
Ptr<Statement>::Ref stmt;
ResultSet * res;
conn = cm->getConnection();
// see if we can connect at all
stmt.reset(conn->createStatement());
stmt->execute(check1Stmt);
res = stmt->getResultSet();
if (!res->next() || (res->getInt(1) != 1)) {
throw std::runtime_error("Can't connect to database");
}
// see if the schedule table exists
try {
stmt.reset(conn->createStatement());
stmt->execute(logCountStmt);
res = stmt->getResultSet();
if (!res->next() || (res->getInt(1) < 0)) {
cm->returnConnection(conn);
return false;
}
} catch (std::exception &e) {
cm->returnConnection(conn);
return false;
}
cm->returnConnection(conn);
} catch (std::exception &e) {
if (conn) {
cm->returnConnection(conn);
}
throw;
}
return true;
}
/*------------------------------------------------------------------------------
* Uninstall the PostgresqlPlayLog.
*----------------------------------------------------------------------------*/
void
PostgresqlPlayLog :: uninstall(void) throw (std::exception)
{
Ptr<Connection>::Ref conn;
try {
conn = cm->getConnection();
Ptr<Statement>::Ref stmt(conn->createStatement());
stmt->execute(dropStmt);
cm->returnConnection(conn);
} catch (std::exception &e) {
if (conn) {
cm->returnConnection(conn);
}
throw std::logic_error(e.what());
}
}
/*------------------------------------------------------------------------------ /*------------------------------------------------------------------------------
* Add a new play log entry * Add a new play log entry
*----------------------------------------------------------------------------*/ *----------------------------------------------------------------------------*/

View File

@ -102,16 +102,6 @@ class PostgresqlPlayLog : public Configurable,
*/ */
static const std::string logCountStmt; static const std::string logCountStmt;
/**
* The SQL create statement used in the installation step.
*/
static const std::string createStmt;
/**
* The SQL drop statement used in the uninstallation step.
*/
static const std::string dropStmt;
/** /**
* The SQL statement for adding a play log entry. * The SQL statement for adding a play log entry.
*/ */
@ -185,36 +175,6 @@ class PostgresqlPlayLog : public Configurable,
throw (std::invalid_argument, throw (std::invalid_argument,
std::logic_error); std::logic_error);
/**
* Install the component.
* This step involves creating the environment in which the component
* will run. This may be creation of coniguration files,
* database tables, etc.
*
* @exception std::exception on installation problems.
*/
virtual void
install(void) throw (std::exception);
/**
* Check to see if the component has already been installed.
*
* @return true if the component is properly installed,
* false otherwise
* @exception std::exception on generic problems
*/
virtual bool
isInstalled(void) throw (std::exception);
/**
* Uninstall the component.
* Removes all the resources created in the install step.
*
* @exception std::exception on unistallation problems.
*/
virtual void
uninstall(void) throw (std::exception);
/** /**
* Add a new entry to the play log. * Add a new entry to the play log.
* *

View File

@ -77,7 +77,6 @@ PostgresqlPlayLogTest :: setUp(void) throw (CPPUNIT_NS::Exception)
cm = scheduler->getConnectionManager(); cm = scheduler->getConnectionManager();
playLog.reset(new PostgresqlPlayLog(cm)); playLog.reset(new PostgresqlPlayLog(cm));
playLog->install();
} catch (std::invalid_argument &e) { } catch (std::invalid_argument &e) {
CPPUNIT_FAIL("semantic error in configuration file"); CPPUNIT_FAIL("semantic error in configuration file");
} catch (xmlpp::exception &e) { } catch (xmlpp::exception &e) {
@ -92,13 +91,6 @@ PostgresqlPlayLogTest :: setUp(void) throw (CPPUNIT_NS::Exception)
void void
PostgresqlPlayLogTest :: tearDown(void) throw (CPPUNIT_NS::Exception) PostgresqlPlayLogTest :: tearDown(void) throw (CPPUNIT_NS::Exception)
{ {
try {
playLog->uninstall();
} catch (std::exception &e) {
std::string eMsg = "cannot uninstall playlog:\n";
eMsg += e.what();
CPPUNIT_FAIL(eMsg);
}
playLog.reset(); playLog.reset();
cm.reset(); cm.reset();
} }

View File

@ -90,26 +90,6 @@ const std::string PostgresqlSchedule::check1Stmt = "SELECT 1";
const std::string PostgresqlSchedule::scheduleCountStmt = const std::string PostgresqlSchedule::scheduleCountStmt =
"SELECT COUNT(*) FROM schedule"; "SELECT COUNT(*) FROM schedule";
/*------------------------------------------------------------------------------
* The SQL create statement, used for installation.
*----------------------------------------------------------------------------*/
const std::string PostgresqlSchedule::createStmt =
"CREATE TABLE schedule\n"
"(\n"
" id BIGINT NOT NULL,\n"
" playlist BIGINT NOT NULL,\n"
" starts TIMESTAMP NOT NULL,\n"
" ends TIMESTAMP NOT NULL,\n"
"\n"
" PRIMARY KEY(id)\n"
");";
/*------------------------------------------------------------------------------
* The SQL create statement, used for installation.
*----------------------------------------------------------------------------*/
const std::string PostgresqlSchedule::dropStmt =
"DROP TABLE schedule;";
/*------------------------------------------------------------------------------ /*------------------------------------------------------------------------------
* The SQL statement for querying if a timeframe is available. * The SQL statement for querying if a timeframe is available.
* The parameters for this call are: starts, starts, ends, ends, starts, ends, * The parameters for this call are: starts, starts, ends, ends, starts, ends,
@ -215,97 +195,6 @@ PostgresqlSchedule :: configure(const xmlpp::Element & element)
} }
/*------------------------------------------------------------------------------
* Install the PostgresqlSchedule.
*----------------------------------------------------------------------------*/
void
PostgresqlSchedule :: install(void) throw (std::exception)
{
if (!isInstalled()) {
Ptr<Connection>::Ref conn;
try {
conn = cm->getConnection();
Ptr<Statement>::Ref stmt(conn->createStatement());
stmt->execute(createStmt);
cm->returnConnection(conn);
} catch (std::exception &e) {
if (conn) {
cm->returnConnection(conn);
}
throw;
}
}
}
/*------------------------------------------------------------------------------
* Check to see if the PostgresqlSchedule has already been installed.
*----------------------------------------------------------------------------*/
bool
PostgresqlSchedule :: isInstalled(void) throw (std::exception)
{
Ptr<Connection>::Ref conn;
try {
Ptr<Statement>::Ref stmt;
ResultSet * res;
conn = cm->getConnection();
// see if we can connect at all
stmt.reset(conn->createStatement());
stmt->execute(check1Stmt);
res = stmt->getResultSet();
if (!res->next() || (res->getInt(1) != 1)) {
throw std::runtime_error("Can't connect to database");
}
// see if the schedule table exists
try {
stmt.reset(conn->createStatement());
stmt->execute(scheduleCountStmt);
res = stmt->getResultSet();
if (!res->next() || (res->getInt(1) < 0)) {
cm->returnConnection(conn);
return false;
}
} catch (std::exception &e) {
cm->returnConnection(conn);
return false;
}
cm->returnConnection(conn);
} catch (std::exception &e) {
if (conn) {
cm->returnConnection(conn);
}
throw;
}
return true;
}
/*------------------------------------------------------------------------------
* Uninstall the PostgresqlSchedule.
*----------------------------------------------------------------------------*/
void
PostgresqlSchedule :: uninstall(void) throw (std::exception)
{
Ptr<Connection>::Ref conn;
try {
conn = cm->getConnection();
Ptr<Statement>::Ref stmt(conn->createStatement());
stmt->execute(dropStmt);
cm->returnConnection(conn);
} catch (std::exception &e) {
if (conn) {
cm->returnConnection(conn);
}
throw;
}
}
/*------------------------------------------------------------------------------ /*------------------------------------------------------------------------------
* Check if a timeframe is available. * Check if a timeframe is available.
*----------------------------------------------------------------------------*/ *----------------------------------------------------------------------------*/

View File

@ -117,16 +117,6 @@ class PostgresqlSchedule : public Configurable,
*/ */
static const std::string scheduleCountStmt; static const std::string scheduleCountStmt;
/**
* The SQL create statement used in the installation step.
*/
static const std::string createStmt;
/**
* The SQL drop statement used in the uninstallation step.
*/
static const std::string dropStmt;
/** /**
* The SQL statement for querying if a time frame is available. * The SQL statement for querying if a time frame is available.
*/ */
@ -237,36 +227,6 @@ class PostgresqlSchedule : public Configurable,
throw (std::invalid_argument, throw (std::invalid_argument,
std::logic_error); std::logic_error);
/**
* Install the component.
* This step involves creating the environment in which the component
* will run. This may be creation of coniguration files,
* database tables, etc.
*
* @exception std::exception on installation problems.
*/
virtual void
install(void) throw (std::exception);
/**
* Check to see if the component has already been installed.
*
* @return true if the component is properly installed,
* false otherwise
* @exception std::exception on generic problems
*/
virtual bool
isInstalled(void) throw (std::exception);
/**
* Uninstall the component.
* Removes all the resources created in the install step.
*
* @exception std::exception on unistallation problems.
*/
virtual void
uninstall(void) throw (std::exception);
/** /**
* Check if a timeframe is available for scheduling. * Check if a timeframe is available for scheduling.
* *

View File

@ -79,7 +79,6 @@ PostgresqlScheduleTest :: setUp(void) throw (CPPUNIT_NS::Exception)
cm = scheduler->getConnectionManager(); cm = scheduler->getConnectionManager();
schedule.reset(new PostgresqlSchedule(cm)); schedule.reset(new PostgresqlSchedule(cm));
schedule->install();
} catch (std::invalid_argument &e) { } catch (std::invalid_argument &e) {
CPPUNIT_FAIL("semantic error in configuration file"); CPPUNIT_FAIL("semantic error in configuration file");
@ -95,7 +94,6 @@ PostgresqlScheduleTest :: setUp(void) throw (CPPUNIT_NS::Exception)
void void
PostgresqlScheduleTest :: tearDown(void) throw (CPPUNIT_NS::Exception) PostgresqlScheduleTest :: tearDown(void) throw (CPPUNIT_NS::Exception)
{ {
schedule->uninstall();
schedule.reset(); schedule.reset();
cm.reset(); cm.reset();
} }

View File

@ -87,7 +87,6 @@ RemoveFromScheduleMethodTest :: setUp(void) throw (CPPUNIT_NS::Exception)
storage->reset(); storage->reset();
schedule = scheduler->getSchedule(); schedule = scheduler->getSchedule();
schedule->install();
} catch (std::invalid_argument &e) { } catch (std::invalid_argument &e) {
CPPUNIT_FAIL("semantic error in configuration file"); CPPUNIT_FAIL("semantic error in configuration file");
@ -114,8 +113,6 @@ RemoveFromScheduleMethodTest :: setUp(void) throw (CPPUNIT_NS::Exception)
void void
RemoveFromScheduleMethodTest :: tearDown(void) throw (CPPUNIT_NS::Exception) RemoveFromScheduleMethodTest :: tearDown(void) throw (CPPUNIT_NS::Exception)
{ {
schedule->uninstall();
authentication->logout(sessionId); authentication->logout(sessionId);
sessionId.reset(); sessionId.reset();
authentication.reset(); authentication.reset();

View File

@ -85,7 +85,6 @@ RescheduleMethodTest :: setUp(void) throw (CPPUNIT_NS::Exception)
storage->reset(); storage->reset();
schedule = scheduler->getSchedule(); schedule = scheduler->getSchedule();
schedule->install();
} catch (std::invalid_argument &e) { } catch (std::invalid_argument &e) {
CPPUNIT_FAIL("semantic error in configuration file"); CPPUNIT_FAIL("semantic error in configuration file");
@ -112,8 +111,6 @@ RescheduleMethodTest :: setUp(void) throw (CPPUNIT_NS::Exception)
void void
RescheduleMethodTest :: tearDown(void) throw (CPPUNIT_NS::Exception) RescheduleMethodTest :: tearDown(void) throw (CPPUNIT_NS::Exception)
{ {
schedule->uninstall();
authentication->logout(sessionId); authentication->logout(sessionId);
sessionId.reset(); sessionId.reset();
authentication.reset(); authentication.reset();

View File

@ -97,8 +97,6 @@ RpcBackupTest :: setUp(void) throw (CPPUNIT_NS::Exception)
} }
} }
daemon->install();
XmlRpc::XmlRpcValue parameters; XmlRpc::XmlRpcValue parameters;
XmlRpc::XmlRpcValue result; XmlRpc::XmlRpcValue result;
@ -129,8 +127,6 @@ void
RpcBackupTest :: tearDown(void) throw (CPPUNIT_NS::Exception) RpcBackupTest :: tearDown(void) throw (CPPUNIT_NS::Exception)
{ {
Ptr<SchedulerDaemon>::Ref daemon = SchedulerDaemon::getInstance(); Ptr<SchedulerDaemon>::Ref daemon = SchedulerDaemon::getInstance();
daemon->uninstall();
CPPUNIT_ASSERT(sessionId); CPPUNIT_ASSERT(sessionId);
XmlRpc::XmlRpcValue parameters; XmlRpc::XmlRpcValue parameters;

View File

@ -87,8 +87,6 @@ RpcDisplayScheduleTest :: setUp(void) throw (CPPUNIT_NS::Exception)
} }
} }
daemon->install();
XmlRpc::XmlRpcValue parameters; XmlRpc::XmlRpcValue parameters;
XmlRpc::XmlRpcValue result; XmlRpc::XmlRpcValue result;
@ -119,7 +117,6 @@ void
RpcDisplayScheduleTest :: tearDown(void) throw (CPPUNIT_NS::Exception) RpcDisplayScheduleTest :: tearDown(void) throw (CPPUNIT_NS::Exception)
{ {
Ptr<SchedulerDaemon>::Ref daemon = SchedulerDaemon::getInstance(); Ptr<SchedulerDaemon>::Ref daemon = SchedulerDaemon::getInstance();
daemon->uninstall();
CPPUNIT_ASSERT(sessionId); CPPUNIT_ASSERT(sessionId);

View File

@ -85,7 +85,6 @@ RpcGeneratePlayReportTest :: setUp(void) throw (CPPUNIT_NS::Exception)
} }
} }
daemon->install();
insertEntries(); insertEntries();
XmlRpc::XmlRpcValue parameters; XmlRpc::XmlRpcValue parameters;
@ -118,7 +117,6 @@ void
RpcGeneratePlayReportTest :: tearDown(void) throw (CPPUNIT_NS::Exception) RpcGeneratePlayReportTest :: tearDown(void) throw (CPPUNIT_NS::Exception)
{ {
Ptr<SchedulerDaemon>::Ref daemon = SchedulerDaemon::getInstance(); Ptr<SchedulerDaemon>::Ref daemon = SchedulerDaemon::getInstance();
daemon->uninstall();
CPPUNIT_ASSERT(sessionId); CPPUNIT_ASSERT(sessionId);

View File

@ -83,7 +83,6 @@ RpcGetSchedulerTimeTest :: setUp(void) throw (CPPUNIT_NS::Exception)
} }
} }
daemon->install();
} }
@ -94,7 +93,6 @@ void
RpcGetSchedulerTimeTest :: tearDown(void) throw (CPPUNIT_NS::Exception) RpcGetSchedulerTimeTest :: tearDown(void) throw (CPPUNIT_NS::Exception)
{ {
Ptr<SchedulerDaemon>::Ref daemon = SchedulerDaemon::getInstance(); Ptr<SchedulerDaemon>::Ref daemon = SchedulerDaemon::getInstance();
daemon->uninstall();
} }

View File

@ -66,7 +66,6 @@ void
RpcGetVersionTest :: setUp(void) throw (CPPUNIT_NS::Exception) RpcGetVersionTest :: setUp(void) throw (CPPUNIT_NS::Exception)
{ {
Ptr<SchedulerDaemon>::Ref daemon = SchedulerDaemon::getInstance(); Ptr<SchedulerDaemon>::Ref daemon = SchedulerDaemon::getInstance();
daemon->install();
} }
@ -77,7 +76,6 @@ void
RpcGetVersionTest :: tearDown(void) throw (CPPUNIT_NS::Exception) RpcGetVersionTest :: tearDown(void) throw (CPPUNIT_NS::Exception)
{ {
Ptr<SchedulerDaemon>::Ref daemon = SchedulerDaemon::getInstance(); Ptr<SchedulerDaemon>::Ref daemon = SchedulerDaemon::getInstance();
daemon->uninstall();
} }

View File

@ -63,7 +63,6 @@ void
RpcRemoveFromScheduleTest :: setUp(void) throw (CPPUNIT_NS::Exception) RpcRemoveFromScheduleTest :: setUp(void) throw (CPPUNIT_NS::Exception)
{ {
Ptr<SchedulerDaemon>::Ref daemon = SchedulerDaemon::getInstance(); Ptr<SchedulerDaemon>::Ref daemon = SchedulerDaemon::getInstance();
daemon->install();
XmlRpc::XmlRpcValue parameters; XmlRpc::XmlRpcValue parameters;
XmlRpc::XmlRpcValue result; XmlRpc::XmlRpcValue result;
@ -95,7 +94,6 @@ void
RpcRemoveFromScheduleTest :: tearDown(void) throw (CPPUNIT_NS::Exception) RpcRemoveFromScheduleTest :: tearDown(void) throw (CPPUNIT_NS::Exception)
{ {
Ptr<SchedulerDaemon>::Ref daemon = SchedulerDaemon::getInstance(); Ptr<SchedulerDaemon>::Ref daemon = SchedulerDaemon::getInstance();
daemon->uninstall();
CPPUNIT_ASSERT(sessionId); CPPUNIT_ASSERT(sessionId);

View File

@ -84,8 +84,6 @@ RpcRescheduleTest :: setUp(void) throw (CPPUNIT_NS::Exception)
} }
} }
daemon->install();
XmlRpc::XmlRpcValue parameters; XmlRpc::XmlRpcValue parameters;
XmlRpc::XmlRpcValue result; XmlRpc::XmlRpcValue result;
@ -116,7 +114,6 @@ void
RpcRescheduleTest :: tearDown(void) throw (CPPUNIT_NS::Exception) RpcRescheduleTest :: tearDown(void) throw (CPPUNIT_NS::Exception)
{ {
Ptr<SchedulerDaemon>::Ref daemon = SchedulerDaemon::getInstance(); Ptr<SchedulerDaemon>::Ref daemon = SchedulerDaemon::getInstance();
daemon->uninstall();
CPPUNIT_ASSERT(sessionId); CPPUNIT_ASSERT(sessionId);

View File

@ -84,8 +84,6 @@ RpcStopCurrentlyPlayingTest :: setUp(void) throw (CPPUNIT_NS::Exception)
} }
} }
daemon->install();
XmlRpc::XmlRpcValue parameters; XmlRpc::XmlRpcValue parameters;
XmlRpc::XmlRpcValue result; XmlRpc::XmlRpcValue result;
@ -116,7 +114,6 @@ void
RpcStopCurrentlyPlayingTest :: tearDown(void) throw (CPPUNIT_NS::Exception) RpcStopCurrentlyPlayingTest :: tearDown(void) throw (CPPUNIT_NS::Exception)
{ {
Ptr<SchedulerDaemon>::Ref daemon = SchedulerDaemon::getInstance(); Ptr<SchedulerDaemon>::Ref daemon = SchedulerDaemon::getInstance();
daemon->uninstall();
CPPUNIT_ASSERT(sessionId); CPPUNIT_ASSERT(sessionId);

View File

@ -83,8 +83,6 @@ RpcUploadPlaylistTest :: setUp(void) throw (CPPUNIT_NS::Exception)
} }
} }
daemon->install();
XmlRpc::XmlRpcValue parameters; XmlRpc::XmlRpcValue parameters;
XmlRpc::XmlRpcValue result; XmlRpc::XmlRpcValue result;
@ -115,7 +113,6 @@ void
RpcUploadPlaylistTest :: tearDown(void) throw (CPPUNIT_NS::Exception) RpcUploadPlaylistTest :: tearDown(void) throw (CPPUNIT_NS::Exception)
{ {
Ptr<SchedulerDaemon>::Ref daemon = SchedulerDaemon::getInstance(); Ptr<SchedulerDaemon>::Ref daemon = SchedulerDaemon::getInstance();
daemon->uninstall();
CPPUNIT_ASSERT(sessionId); CPPUNIT_ASSERT(sessionId);

View File

@ -113,46 +113,3 @@ ScheduleFactory :: configure(const xmlpp::Element & element)
throw std::invalid_argument("no storage client factories to configure"); throw std::invalid_argument("no storage client factories to configure");
} }
} }
/*------------------------------------------------------------------------------
* Install the schedule factory.
*----------------------------------------------------------------------------*/
void
ScheduleFactory :: install(void) throw (std::exception)
{
if (!schedule) {
throw std::logic_error("ScheduleFactory not yet configured");
}
schedule->install();
}
/*------------------------------------------------------------------------------
* Check to see if the schedule factory has already been installed.
*----------------------------------------------------------------------------*/
bool
ScheduleFactory :: isInstalled(void) throw (std::exception)
{
if (!schedule) {
throw std::logic_error("ScheduleFactory not yet configured");
}
return schedule->isInstalled();
}
/*------------------------------------------------------------------------------
* Install the schedule factory.
*----------------------------------------------------------------------------*/
void
ScheduleFactory :: uninstall(void) throw (std::exception)
{
if (!schedule) {
throw std::logic_error("ScheduleFactory not yet configured");
}
schedule->uninstall();
}

View File

@ -43,7 +43,6 @@
#include <stdexcept> #include <stdexcept>
#include "LiveSupport/Core/Configurable.h" #include "LiveSupport/Core/Configurable.h"
#include "LiveSupport/Core/Installable.h"
#include "ScheduleInterface.h" #include "ScheduleInterface.h"
@ -89,8 +88,7 @@ using namespace LiveSupport::Core;
* @version $Revision$ * @version $Revision$
* @see PostgresqlSchedule * @see PostgresqlSchedule
*/ */
class ScheduleFactory : virtual public Configurable, class ScheduleFactory : virtual public Configurable
virtual public Installable
{ {
private: private:
/** /**
@ -159,38 +157,6 @@ class ScheduleFactory : virtual public Configurable,
throw (std::invalid_argument, throw (std::invalid_argument,
std::logic_error); std::logic_error);
/**
* Install the component.
* This step involves creating the environment in which the component
* will run. This may be creation of coniguration files,
* database tables, etc.
*
* @exception std::exception on installation problems,
* especially if the ScheduleFactory was not yet configured.
*/
virtual void
install(void) throw (std::exception);
/**
* Check to see if the component has already been installed.
*
* @return true if the component is properly installed,
* false otherwise
* @exception std::exception on generic problems
*/
virtual bool
isInstalled(void) throw (std::exception);
/**
* Uninstall the component.
* Removes all the resources created in the install step.
*
* @exception std::exception on unistallation problems,
e especially if the ScheduleFactory was not yet configured.
*/
virtual void
uninstall(void) throw (std::exception);
/** /**
* Return a schedule. * Return a schedule.
* *

View File

@ -44,7 +44,6 @@
#include <boost/date_time/posix_time/posix_time.hpp> #include <boost/date_time/posix_time/posix_time.hpp>
#include "LiveSupport/Core/Ptr.h" #include "LiveSupport/Core/Ptr.h"
#include "LiveSupport/Core/Installable.h"
#include "LiveSupport/Core/Playlist.h" #include "LiveSupport/Core/Playlist.h"
#include "LiveSupport/Core/ScheduleEntry.h" #include "LiveSupport/Core/ScheduleEntry.h"
@ -72,7 +71,7 @@ using namespace LiveSupport::Core;
* @author $Author$ * @author $Author$
* @version $Revision$ * @version $Revision$
*/ */
class ScheduleInterface : virtual public Installable class ScheduleInterface
{ {
public: public:
/** /**

View File

@ -302,103 +302,12 @@ SchedulerDaemon :: registerXmlRpcFunctions(
} }
/*------------------------------------------------------------------------------
* Install the scheduler daemon.
*----------------------------------------------------------------------------*/
void
SchedulerDaemon :: install(void) throw (std::exception)
{
if (!isInstalled()) {
// TODO: check if we have already been configured
Ptr<ScheduleFactory>::Ref sf = ScheduleFactory::getInstance();
sf->install();
Ptr<PlayLogFactory>::Ref plf = PlayLogFactory::getInstance();
plf->install();
Ptr<BackupFactory>::Ref bf = BackupFactory::getInstance();
bf->install();
}
}
/*------------------------------------------------------------------------------
* Check to see if the scheduler has been installed.
*----------------------------------------------------------------------------*/
bool
SchedulerDaemon :: isInstalled(void) throw (std::exception)
{
// TODO: check if we have already been configured
Ptr<ScheduleFactory>::Ref sf = ScheduleFactory::getInstance();
Ptr<PlayLogFactory>::Ref plf = PlayLogFactory::getInstance();
Ptr<BackupFactory>::Ref bf = BackupFactory::getInstance();
if (!sf || !plf || !bf) {
throw std::logic_error("couldn't initialize factories");
}
return sf->isInstalled() && plf->isInstalled() && bf->isInstalled();
}
/*------------------------------------------------------------------------------
* Install the scheduler daemon.
*----------------------------------------------------------------------------*/
void
SchedulerDaemon :: uninstall(void) throw (std::exception)
{
// TODO: check if we have already been configured
Ptr<BackupFactory>::Ref bf = BackupFactory::getInstance();
Ptr<PlayLogFactory>::Ref plf = PlayLogFactory::getInstance();
Ptr<ScheduleFactory>::Ref sf = ScheduleFactory::getInstance();
if (!bf || !plf || !sf) {
throw std::logic_error("couldn't initialize factories");
}
bool isOK = true;
std::stringstream errorMessage("error uninstalling factories:\n");
try {
bf->uninstall();
} catch (std::exception &e) {
isOK = false;
errorMessage << e.what() << std::endl;
}
try {
plf->uninstall();
} catch (std::exception &e) {
isOK = false;
errorMessage << e.what() << std::endl;
}
try {
sf->uninstall();
} catch (std::exception &e) {
isOK = false;
errorMessage << e.what() << std::endl;
}
if (!isOK) {
throw std::logic_error(errorMessage.str());
}
}
/*------------------------------------------------------------------------------ /*------------------------------------------------------------------------------
* Execute daemon startup functions. * Execute daemon startup functions.
*----------------------------------------------------------------------------*/ *----------------------------------------------------------------------------*/
void void
SchedulerDaemon :: startup (void) throw (std::logic_error) SchedulerDaemon :: startup (void) throw (std::logic_error)
{ {
try {
if (!isInstalled()) {
install();
}
} catch (std::exception &e) {
throw std::logic_error(std::string("database installation problem: ")
+ e.what());
}
try { try {
sessionId = authentication->login(login, password); sessionId = authentication->login(login, password);
} catch (XmlRpcException &e) { } catch (XmlRpcException &e) {

View File

@ -58,7 +58,6 @@
#include <XmlRpc.h> #include <XmlRpc.h>
#include "LiveSupport/Core/Ptr.h" #include "LiveSupport/Core/Ptr.h"
#include "LiveSupport/Core/Installable.h"
#include "LiveSupport/Core/Configurable.h" #include "LiveSupport/Core/Configurable.h"
#include "LiveSupport/Core/SessionId.h" #include "LiveSupport/Core/SessionId.h"
#include "LiveSupport/Db/ConnectionManagerInterface.h" #include "LiveSupport/Db/ConnectionManagerInterface.h"
@ -171,22 +170,11 @@ using namespace LiveSupport::PlaylistExecutor;
* @see ScheduleFactory * @see ScheduleFactory
* @see XmlRpcDaemon * @see XmlRpcDaemon
*/ */
class SchedulerDaemon : public Installable, class SchedulerDaemon : public Configurable,
public Configurable,
public XmlRpcDaemon public XmlRpcDaemon
{ {
private: private:
/**
* The SQL create statement used in the installation step.
*/
static const std::string createStmt;
/**
* The SQL drop statement used in the uninstallation step.
*/
static const std::string dropStmt;
/** /**
* A SQL statement to check if the database can be accessed. * A SQL statement to check if the database can be accessed.
*/ */
@ -447,36 +435,6 @@ class SchedulerDaemon : public Installable,
return audioPlayer; return audioPlayer;
} }
/**
* Install the component.
* This step involves creating the environment in which the component
* will run. This may be creation of coniguration files,
* database tables, etc.
*
* @exception std::exception on installation problems.
*/
virtual void
install(void) throw (std::exception);
/**
* Check to see if the component has already been installed.
*
* @return true if the component is properly installed,
* false otherwise
* @exception std::exception on generic problems
*/
virtual bool
isInstalled(void) throw (std::exception);
/**
* Uninstall the component.
* Removes all the resources created in the install step.
*
* @exception std::exception on unistallation problems.
*/
virtual void
uninstall(void) throw (std::exception);
/** /**
* Shut down the daemon. * Shut down the daemon.
* This function is public only because the signal handler * This function is public only because the signal handler

View File

@ -84,7 +84,6 @@ UploadPlaylistMethodTest :: setUp(void) throw (CPPUNIT_NS::Exception)
storage->reset(); storage->reset();
schedule = scheduler->getSchedule(); schedule = scheduler->getSchedule();
schedule->install();
} catch (XmlRpcException &e) { } catch (XmlRpcException &e) {
std::cerr << "caught XmlRpcException durng setUp" << std::endl std::cerr << "caught XmlRpcException durng setUp" << std::endl
@ -113,8 +112,6 @@ UploadPlaylistMethodTest :: setUp(void) throw (CPPUNIT_NS::Exception)
void void
UploadPlaylistMethodTest :: tearDown(void) throw (CPPUNIT_NS::Exception) UploadPlaylistMethodTest :: tearDown(void) throw (CPPUNIT_NS::Exception)
{ {
schedule->uninstall();
authentication->logout(sessionId); authentication->logout(sessionId);
sessionId.reset(); sessionId.reset();
authentication.reset(); authentication.reset();

View File

@ -86,11 +86,6 @@ static const struct option longOptions[] = {
{ 0, 0, 0, 0 } { 0, 0, 0, 0 }
}; };
/**
* The start command: "install"
*/
static const std::string installCommand = "install";
/** /**
* The start command: "start" * The start command: "start"
*/ */
@ -106,11 +101,6 @@ static const std::string statusCommand = "status";
*/ */
static const std::string stopCommand = "stop"; static const std::string stopCommand = "stop";
/**
* The stop command: "uninstall"
*/
static const std::string uninstallCommand = "uninstall";
/* =============================================== local function prototypes */ /* =============================================== local function prototypes */
@ -200,9 +190,7 @@ int main ( int argc,
daemon->setBackground(!debugMode); daemon->setBackground(!debugMode);
try { try {
if (installCommand == argv[optind]) { if (startCommand == argv[optind]) {
daemon->install();
} else if (startCommand == argv[optind]) {
daemon->start(); daemon->start();
} else if (statusCommand == argv[optind]) { } else if (statusCommand == argv[optind]) {
std::cout << "The Scheduler Daemon is " std::cout << "The Scheduler Daemon is "
@ -210,8 +198,6 @@ int main ( int argc,
<< "running" << std::endl; << "running" << std::endl;
} else if (stopCommand == argv[optind]) { } else if (stopCommand == argv[optind]) {
daemon->stop(); daemon->stop();
} else if (uninstallCommand == argv[optind]) {
daemon->uninstall();
} else { } else {
printUsage(argv[0], std::cout); printUsage(argv[0], std::cout);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
@ -248,7 +234,7 @@ printUsage ( const char invocation[],
<< std::endl << std::endl
<< "Usage: " << invocation << " [OPTION] COMMAND" << "Usage: " << invocation << " [OPTION] COMMAND"
<< std::endl << std::endl
<< " COMMAND is one of: install, start, stop, status or uninstall" << " COMMAND is one of: start, stop, or status"
<< std::endl << std::endl
<< std::endl << std::endl
<< " mandatory options:" << std::endl << " mandatory options:" << std::endl