00001 #include "IsPutCommand.h"
00002 #include "Archiver.h"
00003 #include "SerializableWrappers.h"
00004 #include "Sct/IS/IOManagerIS.h"
00005 #include "Sct/LogicErrors.h"
00006 #include "Sct/IoExceptions.h"
00007 #include "Sct/ISProxy/IOManagerISProxy.h"
00008 #include "Sct/ISUtilities.h"
00009
00010 #include "SummaryWriter/TestSummaryIS.h"
00011 #include "SummaryWriter/SummaryManager.h"
00012 #include "SctData/TestResult.h"
00013
00014 #include "is/isinfoany.h"
00015
00016 #include <boost/timer.hpp>
00017 #include <sstream>
00018
00019 namespace SctArchiving{
00020 IsPutCommand::IsPutCommand(boost::shared_ptr<Sct::Serializable> ob)
00021 : PutCommand(ob) {
00022 }
00023
00024 IsPutCommand::IsPutCommand() {}
00025
00026 IsPutCommand::~IsPutCommand() {}
00027
00028 void IsPutCommand::setServer(const string& name){
00029 m_server=name;
00030 }
00031
00032 boost::shared_ptr<ArchivingCommand> IsPutCommand::create()const{
00033 boost::shared_ptr<ArchivingCommand> cmd(new IsPutCommand() );
00034 return cmd;
00035 }
00036
00037 void IsPutCommand::execute(){
00038 boost::timer t;
00039
00040 if (!m_ob.get()) throw Sct::IllegalStateError("Null pointer", __FILE__, __LINE__);
00041 if (m_server=="") m_server = Archiver::instance().getRetrieveIsServer();
00042
00043 if (m_ob->getClassName()=="TestData" || m_ob->getClassName()=="SequenceData") {
00044 shared_ptr<Sct::ISSerializableWrapperI> wrap = boost::dynamic_pointer_cast<Sct::ISSerializableWrapperI>(m_ob);
00045 if (!wrap.get()) throw Sct::IllegalStateError(m_ob->getClassName() +
00046 " couldnt be cast as a ISSerializableWrapperI", __FILE__, __LINE__);
00047 wrap->publishWrappedObjectToServer( m_server );
00048 }else{
00049 Sct::IS::IOParamsIS params( m_server );
00050 Sct::ISProxy::IOManagerISProxy::instance().write(*m_ob, ¶ms);
00051 }
00052
00053
00054 if (m_ob->getClassName().find("TestResult")!=std::string::npos){
00055 try{
00056 shared_ptr<SctData::TestResult> r = boost::dynamic_pointer_cast<SctData::TestResult>(m_ob);
00057 if (!r.get()) throw Sct::IllegalStateError(string("Bad cast of TestResult ") + (string)m_ob->getUniqueID(), __FILE__, __LINE__);
00058 TestSummaryIS t;
00059 t.dataString = SctData::TestSummary::SummaryManager::instance().write(*r);
00060 std::string name = m_server;
00061 name += ".";
00062 name += "Summary.";
00063 name += (string) m_ob->getUniqueID();
00064
00065 Sct::ISUtilities::addOrUpdateOrThrow(name, t, __FILE__, __LINE__, MRS_ERROR);
00066 }catch(Sct::IsException& e){
00067 if (e.getStatus()==ISInfo::AlreadyExist){
00068 std::cerr << e.what() << std::endl;
00069 }else{
00070 throw;
00071 }
00072 }catch(Sct::Throwable& e){
00073 e.sendToMrs(MRS_DIAGNOSTIC);
00074 }
00075
00076 Archiver::instance().addISTime(t.elapsed());
00077 }
00078 }
00079 }