// Copyright (c) 2008 Michael Miceli and Christopher Miceli // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) #include #include "../utils/defines.hpp" #include "ConfigFileParser.hpp" #include "../xmlParser/xmlParser.h" using namespace AllPairs::Master; ConfigFileParser::ConfigFileParser() { } ConfigFileParser::ConfigFileParser(std::string cfgFilePath, AllPairs::LogWriter &log) : cfgFilePath_(cfgFilePath), log_(&log) { parse_(); } SessionDescription ConfigFileParser::getSessionDescription() { return sessionDesc_; } std::vector ConfigFileParser::getExecutableList() { return binDescList_; } std::vector > ConfigFileParser::getCompareList() { return compareDescList_; } std::vector ConfigFileParser::getTargetHostList() { return targetHostList_; } std::string ConfigFileParser::getMasterAddress() { return masterAddress_; } void ConfigFileParser::parse_(void) { std::string tmp(""); try { XMLNode xMainNode=XMLNode::openFileHelper(cfgFilePath_.c_str(),"APDL"); xMainNode = xMainNode.getChildNode("AllPairsSession"); // parse the TaskFarmingSession node if( NULL != xMainNode.getAttribute("name") ) sessionDesc_.name = xMainNode.getAttribute("name"); if( NULL != xMainNode.getAttribute("version") ) sessionDesc_.version = xMainNode.getAttribute("version"); if( NULL != xMainNode.getAttribute("user") ) sessionDesc_.user = xMainNode.getAttribute("user"); if( NULL != xMainNode.getAttribute("priority") ) sessionDesc_.priority = xMainNode.getAttribute("priority"); if( NULL != xMainNode.getAttribute("experimentID") ) sessionDesc_.experimentID = xMainNode.getAttribute("experimentID"); if( NULL != xMainNode.getAttribute("eventLevel") ) sessionDesc_.eventLevel = xMainNode.getAttribute("eventLevel"); // parse the OrchestratorDB section XMLNode xNode = xMainNode.getChildNode("OrchestratorDB").getChildNode("Host"); if( NULL != xNode.getText()) sessionDesc_.orchestrator = xNode.getText(); else { std::string message("XML Parser: Orchestrator section not found"); log_->write(message, LOGLEVEL_ERROR); } // parse the TargetHosts section xNode = xMainNode.getChildNode("TargetHosts"); int n=xNode.nChildNode("Host"); for(int i=0; iwrite(message, LOGLEVEL_ERROR); } } // parse MasterAddress information xNode = xMainNode.getChildNode("MasterAddress"); if(NULL != xNode.getText()) { masterAddress_ = xNode.getText(); } else { std::string message("XML Parser: Incomplete MasterAddress section!"); log_->write(message, LOGLEVEL_ERROR); } xNode = xMainNode.getChildNode("ApplicationBinaries"); int m=xNode.nChildNode("BinaryImage"); for(int i=0; iwrite(message, LOGLEVEL_ERROR); } } // parse the ApplicationFiles section int numCompares = xMainNode.nChildNode("CompareAssignment"); for(int i = 0; i < numCompares; ++i) { xNode = xMainNode.getChildNode("CompareAssignment", i); int k = xNode.nChildNode("Compare"); std::vector comparisons; for(int j = 0; j < k; ++j) { CompareDescription compareTemp; XMLNode xCompareNode = xNode.getChildNode("Compare", j); if((NULL != xCompareNode.getAttribute("source")) && (NULL != xCompareNode.getAttribute("target"))) { compareTemp.source = xCompareNode.getAttribute("source"); compareTemp.target = xCompareNode.getAttribute("target"); } else { std::string message("XML Parser: Incomplete Compare section found \n Example "); log_->write(message, LOGLEVEL_ERROR); APPLICATION_ABORT; } comparisons.push_back(compareTemp); } compareDescList_.push_back(comparisons); } } catch(xmlParser::exception const &e) { std::string message("XML Parser FAILED:"); message.append(e.what()); log_->write(message, LOGLEVEL_FATAL); throw e; // propagate exception! } }