Commit 6e178fe8 authored by Cristina Cocho's avatar Cristina Cocho
Browse files

Work on tagged confs

parent 53298aef
......@@ -23,11 +23,16 @@
#include <core/survey/Survey.h>
#include <core/session/SessionManager.h>
#include <dataprovider/transportlayer/dataprovider/ServantAccessorDirectImpl.h>
#include <command/transportlayer/MultiThreadProcessorCommunication.h>
#include <ics/InstrumentManager/HardwareManager.h>
#include <ics/InstrumentManager/InstrumentManager.h>
#include <ics/ServantConfiguration.h>
#include "CommandSystem/ConfigurationManager.h"
#include <boost/filesystem/fstream.hpp>
#include <boost/filesystem/operations.hpp>
using namespace std;
namespace fs = boost::filesystem;
namespace core {
......@@ -329,7 +334,7 @@ bool ServantCreator::removeController(uint32 clientID, uint32 controllerID, std:
return responseMessage.has_error();
}
void ServantCreator::removeAllControllers(std::string & response) {
void ServantCreator::removeAllControllers(std::string & response, bool removeAll) {
unsigned long databaseID = 0;
common::ServantDeleteResponse responseMessage;
......@@ -346,7 +351,8 @@ void ServantCreator::removeAllControllers(std::string & response) {
// get the type of the controller and use it to avoid deletin ESSENTIAL CONTROLLERS (discuss)
string controllerType = DataAccess::getInstance()->getControllerType(0, id);
if ((controllerType != "title") && (controllerType != "sample_description") && (controllerType != "acquisition_spy") && (controllerType != "serializer") && (controllerType != "scan_spy")) { // see how to do in a nicer way
if (removeAll || (!removeAll && !essential_controller_types.count(controllerType))) {
// if ((controllerType != "title") && (controllerType != "sample_description") && (controllerType != "acquisition_spy") && (controllerType != "serializer") && (controllerType != "scan_spy")) { // see how to do in a nicer way
// get the name of the controller
string controllerName = DataAccess::getInstance()->getServantName(0, id);
std::cout << "About to delete controller " << controllerName << endl;
......@@ -443,13 +449,84 @@ void ServantCreator::getControllerConfiguration(unsigned long databaseID, unsign
}
void ServantCreator::loadConfiguration(std::string configurationID, std::string & response) {
// Before removing everything do a backup (should it be done in the client?)
replaceConfiguration(configurationID);
// Remove first all drivers and controllers
removeAllControllers(response);
removeAllControllers(response, true);
removeAllDrivers(response);
// Load Configuration
ics::ServantConfiguration::getInstance()->loadConfiguration(configurationID);
// CORE: Load Configuration
ics::ServantConfiguration::resetInstance();
// ics::ServantConfiguration::initInstance2(configurationID);
ics::ServantConfiguration::initInstance();
// DATABASE: reset database and init it again
dataprovider::Database::resetInstances();
dataprovider::Database::initInstance("", false); // uses loaded stuff from ServantConfiguration
ConfigurationManager::getInstance()->loadConfiguration();
HardwareManager::getInstance()->saveTestControllers(false);
InstrumentManager::getInstance()->saveExperimentControllers(false);
// COMMAND PROCESSOR?
command::ServantManager::resetInstance();
command::ServantManager::initInstance(command::MultiThreadProcessorCommunication::getInstance()->getServantAccessor(), command::MultiThreadProcessorCommunication::getInstance()->getCommandAccessor());
}
void ServantCreator::replaceConfiguration(std::string configurationID) {
// Backup actual configuration
string hardwareBackupSaveFile = common::ServerProperties::getInstance()->getConfigPath() + "/Config/backup/" + "HardwareConfig.xml";
string hardwareFile = common::ServerProperties::getInstance()->getConfigPath() + "/Config/" + "HardwareConfig.xml";
backupFile(hardwareFile, hardwareBackupSaveFile);
string instrumentBackupSaveFile = common::ServerProperties::getInstance()->getConfigPath() + "/Config/backup/" + "InstrumentConfig.xml";
string instrumentFile = common::ServerProperties::getInstance()->getConfigPath() + "/Config/" + "InstrumentConfig.xml";
backupFile(instrumentFile, instrumentBackupSaveFile);
string nexusServerBackupSaveFile = common::ServerProperties::getInstance()->getConfigPath() + "/Config/backup/" + "NxServerDataFileConfig.xml";
string nexusServerFile = common::ServerProperties::getInstance()->getConfigPath() + "/Config/" + "NxServerDataFileConfig.xml";
backupFile(nexusServerFile, nexusServerBackupSaveFile);
string nexusClientBackupSaveFile = common::ServerProperties::getInstance()->getConfigPath() + "/Config/backup/" + "NxClientDataFileConfig.xml";
string nexusClientFile = common::ServerProperties::getInstance()->getConfigPath() + "/Config/" + "NxClientDataFileConfig.xml";
backupFile(nexusClientFile, nexusClientBackupSaveFile);
// Load tagged configuration
string hardwareConfigFile = common::ServerProperties::getInstance()->getConfigPath() + "/Config/" + "HardwareConfig.xml";
string hardwareTaggedFile = common::ServerProperties::getInstance()->getHomePath() + "/configFiles/tag/"+configurationID + "/HardwareConfig_"+configurationID+".xml";
backupFile(hardwareTaggedFile, hardwareConfigFile);
string instrumentConfigFile = common::ServerProperties::getInstance()->getConfigPath() + "/Config/" + "InstrumentConfig.xml";
string instrumentTaggedFile = common::ServerProperties::getInstance()->getHomePath() + "/configFiles/tag/" + configurationID + "/InstrumentConfig_" + configurationID + ".xml";
backupFile(instrumentTaggedFile, instrumentConfigFile);
string nexusServerConfigFile = common::ServerProperties::getInstance()->getConfigPath() + "/Config/" + "NxServerDataFileConfig.xml";
string nexusServerTaggedFile = common::ServerProperties::getInstance()->getHomePath() + "/configFiles/tag/" + configurationID + "/NxServerDataFileConfig_" + configurationID + ".xml";
backupFile(nexusServerTaggedFile, nexusServerConfigFile);
string nexusClientConfigFile = common::ServerProperties::getInstance()->getConfigPath() + "/Config/" + "NxClientDataFileConfig.xml";
string nexusClientTaggedFile = common::ServerProperties::getInstance()->getHomePath() + "/configFiles/tag/" + configurationID + "/NxClientDataFileConfig_" + configurationID + ".xml";
backupFile(nexusClientTaggedFile, nexusClientConfigFile);
}
void ServantCreator::backupFile(std::string fileToSave, std::string destinationFile) {
try {
// verify the files
fs::path backupPath = fs::system_complete(fs::path(destinationFile));
fs::path path = fs::system_complete(fs::path(fileToSave));
// copy the file
if (fs::exists(backupPath)) {
fs::remove(backupPath);
}
fs::copy_file(path, backupPath);
} catch (const std::exception & e) {
std::cout << "cannot backup the config file : " << e.what() << std::endl;
}
}
}
......
......@@ -21,6 +21,7 @@
#define SRC_CORE_CREATOR_SERVANTCREATOR_H_
#include <string>
#include <set>
#include <common/base/BaseTypes.h>
namespace dataprovider {
......@@ -47,7 +48,7 @@ public:
bool removeController(uint32 clientID, uint32 controllerID, std::string & response);
void removeAllDrivers(std::string & response);
void removeAllControllers(std::string & response);
void removeAllControllers(std::string & response, bool removeAll = false);
void setConfigurationMode(bool on);
void loadConfiguration(std::string configurationID, std::string & response);
......@@ -60,10 +61,15 @@ private:
// NOTE: Pending to discuss this method. It has the same signature that the one in ServantAccessor but it is done locally due to we cannot retrieve not configured children data through Database
virtual void getControllerConfiguration(unsigned long databaseID, unsigned long servantID, std::string& result);
virtual void replaceConfiguration(std::string configurationID);
virtual void backupFile(std::string fileToSave, std::string destinationFile);
static ServantCreator* servantCreator;
dataprovider::ServantAccessorDirectImpl* _servantAccessor;
std::set<std::string> essential_controller_types = {"title", "sample_description", "acquisition_spy", "serializer", "scan_spy"};;
};
}
......
......@@ -2265,7 +2265,7 @@ Database::ServantItem Database::getDriver(unsigned long servantID) {
item.isCommand = driver->isCommand();
item.isVisible = driver->isVisible();
item.isEnabled = driver->isEnabled();
item.isRoot = false;
item.isRoot = driver->isRoot();;
return item;
}
......
......@@ -617,7 +617,7 @@ void XMLFileConfiguration::saveExperimentControllers(const vector<ExperimentCont
/*
*
*/
void XMLFileConfiguration::loadTestControllersFromTaggedConfiguration(std::vector<TestControllerConfig> configs, const std::string &filePath) {
void XMLFileConfiguration::loadTestControllersFromTaggedConfiguration(std::vector<TestControllerConfig>& configs, const std::string &filePath) {
// Parsing the DOM tree
try {
// Quite cheap!
......@@ -660,7 +660,7 @@ void XMLFileConfiguration::loadTestControllersFromTaggedConfiguration(std::vecto
}
}
void XMLFileConfiguration::loadExperimentControllersFromTaggedConfiguration(std::vector<ExperimentControllerConfig> configs, const std::string &filePath) {
void XMLFileConfiguration::loadExperimentControllersFromTaggedConfiguration(std::vector<ExperimentControllerConfig>& configs, const std::string &filePath) {
// Parsing the DOM tree
try {
string home;
......
......@@ -86,8 +86,8 @@ public:
ExperimentControllerConfig>& configs, bool isBackup);
void loadTestControllersFromTaggedConfiguration(std::vector<TestControllerConfig> configs, const std::string& filePath);
void loadExperimentControllersFromTaggedConfiguration(std::vector<ExperimentControllerConfig> configs, const std::string& filePath);
void loadTestControllersFromTaggedConfiguration(std::vector<TestControllerConfig>& configs, const std::string& filePath);
void loadExperimentControllersFromTaggedConfiguration(std::vector<ExperimentControllerConfig>& configs, const std::string& filePath);
private:
......
......@@ -44,6 +44,7 @@ void ServantConfiguration::resetInstance() {
if (_instance != 0) {
delete _instance;
_instance = nullptr;
}
}
......@@ -73,13 +74,29 @@ void ServantConfiguration::saveExperimentControllerList(const std::vector<Experi
_configuration->saveExperimentControllers(controllerList, isBackup);
}
void ServantConfiguration::loadConfiguration(const std::string& configurationID) const {
void ServantConfiguration::loadConfiguration(const std::string& configurationID) {
_configuration->loadTestControllersFromTaggedConfiguration(_testControllerList, configurationID);
_configuration->loadExperimentControllersFromTaggedConfiguration(_experimentControllerList, configurationID);
// Save?
// _configuration->saveTestControllers(getTestControllerList(), false);
// _configuration->saveExperimentControllers(_experimentControllerList, false)
}
void ServantConfiguration::initInstance2(const std::string& configurationID) {
if (_instance == 0) {
std::cout << "in initInstance2 " << std::endl;
_instance = new ServantConfiguration();
_instance->init2(configurationID);
}
}
void ServantConfiguration::init2(const std::string& configurationID) {
_configuration = new XMLFileConfiguration();
_configuration->loadTestControllersFromTaggedConfiguration(_testControllerList, configurationID);
_configuration->loadExperimentControllersFromTaggedConfiguration(_experimentControllerList, configurationID);
std::cout << "******* SIZE MAP " << _testControllerList.size() << std::endl;
for (std::vector<TestControllerConfig>::const_reverse_iterator c = _testControllerList.rbegin(); c != _testControllerList.rend(); c++) {
std::cout << "******* driver 1 " << c->getName() << std::endl;
}
}
}
......@@ -72,13 +72,16 @@ public:
/**
* Loades a new set of configuration files
*/
void loadConfiguration(const std::string& configurationID) const;
void loadConfiguration(const std::string& configurationID);
static void initInstance2(const std::string& configurationID);
private:
ServantConfiguration();
~ServantConfiguration();
void init();
void init2(const std::string& configurationID);
XMLFileConfiguration* _configuration;
......
Supports Markdown
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