1 | /*
|
---|
2 | * Project: MoleCuilder
|
---|
3 | * Description: creates and alters molecular systems
|
---|
4 | * Copyright (C) 2012 University of Bonn. All rights reserved.
|
---|
5 | * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
|
---|
6 | */
|
---|
7 |
|
---|
8 | /*
|
---|
9 | * controller_SystemCommandJob.cpp
|
---|
10 | *
|
---|
11 | * Created on: 01.06.2012
|
---|
12 | * Author: heber
|
---|
13 | */
|
---|
14 |
|
---|
15 | // include config.h
|
---|
16 | #ifdef HAVE_CONFIG_H
|
---|
17 | #include <config.h>
|
---|
18 | #endif
|
---|
19 |
|
---|
20 | #include "CodePatterns/MemDebug.hpp"
|
---|
21 |
|
---|
22 | #include "controller_SystemCommandJob.hpp"
|
---|
23 |
|
---|
24 | #include <boost/assign.hpp>
|
---|
25 | #include <boost/bind.hpp>
|
---|
26 |
|
---|
27 | #include "FragmentController.hpp"
|
---|
28 | #include "Jobs/SystemCommandJob.hpp"
|
---|
29 | #include "Results/FragmentResult.hpp"
|
---|
30 |
|
---|
31 | #include "ControllerCommand.hpp"
|
---|
32 | #include "ControllerCommandRegistry.hpp"
|
---|
33 | #include "ControllerOptions_SystemCommandJob.hpp"
|
---|
34 |
|
---|
35 | /** Print received results.
|
---|
36 | *
|
---|
37 | * @param results received results to print
|
---|
38 | */
|
---|
39 | void printReceivedResults(const std::vector<FragmentResult::ptr> &results)
|
---|
40 | {
|
---|
41 | for (std::vector<FragmentResult::ptr>::const_iterator iter = results.begin();
|
---|
42 | iter != results.end(); ++iter)
|
---|
43 | LOG(1, "RESULT: job #"+toString((*iter)->getId())+": "+toString((*iter)->result));
|
---|
44 | }
|
---|
45 |
|
---|
46 | /** Creates a SystemCommandJob out of give \a command with \a argument.
|
---|
47 | *
|
---|
48 | * @param controller reference to controller to add jobs
|
---|
49 | * @param ControllerInfo information on the job
|
---|
50 | */
|
---|
51 | void createJobs(FragmentController &controller, const ControllerOptions_SystemCommandJob &ControllerInfo)
|
---|
52 | {
|
---|
53 | const JobId_t next_id = controller.getAvailableId();
|
---|
54 | LOG(2, "DEBUG: Creating new SystemCommandJob with '"
|
---|
55 | +toString(ControllerInfo.executable)+"' and argument '"
|
---|
56 | +toString(ControllerInfo.jobcommand)+"'.");
|
---|
57 | FragmentJob::ptr testJob(
|
---|
58 | new SystemCommandJob(ControllerInfo.executable, ControllerInfo.jobcommand, next_id) );
|
---|
59 | std::vector<FragmentJob::ptr> jobs;
|
---|
60 | jobs.push_back(testJob);
|
---|
61 | controller.addJobs(jobs);
|
---|
62 | controller.sendJobs(ControllerInfo.server, ControllerInfo.serverport);
|
---|
63 | LOG(1, "INFO: Added one SystemCommandJob.");
|
---|
64 | }
|
---|
65 |
|
---|
66 | inline std::vector<std::string> getListOfCommands(const ControllerCommandRegistry &ControllerCommands)
|
---|
67 | {
|
---|
68 | std::vector<std::string> Commands;
|
---|
69 | for (ControllerCommandRegistry::const_iterator iter = ControllerCommands.getBeginIter();
|
---|
70 | iter != ControllerCommands.getEndIter(); ++iter)
|
---|
71 | Commands.push_back(iter->first);
|
---|
72 |
|
---|
73 | return Commands;
|
---|
74 | }
|
---|
75 |
|
---|
76 | ControllerOptions *controller_SystemCommandJob::allocateControllerInfo()
|
---|
77 | {
|
---|
78 | return new ControllerOptions_SystemCommandJob();
|
---|
79 | }
|
---|
80 |
|
---|
81 | void controller_SystemCommandJob::addSpecificCommands(
|
---|
82 | boost::function<void (ControllerCommand *)> ®istrator,
|
---|
83 | FragmentController &controller,
|
---|
84 | ControllerOptions &ControllerInfo)
|
---|
85 | {
|
---|
86 | ControllerOptions_SystemCommandJob &CI =
|
---|
87 | reinterpret_cast<ControllerOptions_SystemCommandJob &>(ControllerInfo);
|
---|
88 | registrator(new ControllerCommand("createjobs",
|
---|
89 | boost::assign::list_of< ControllerCommand::commands_t >
|
---|
90 | (boost::bind(&FragmentController::requestIds,
|
---|
91 | boost::ref(controller), boost::cref(ControllerInfo.server), boost::cref(ControllerInfo.serverport), 1))
|
---|
92 | (boost::bind(&createJobs, boost::ref(controller), boost::cref(CI)))
|
---|
93 | ));
|
---|
94 | registrator(new ControllerCommand("receiveresults",
|
---|
95 | boost::assign::list_of< ControllerCommand::commands_t >
|
---|
96 | (boost::bind(&FragmentController::receiveResults,
|
---|
97 | boost::ref(controller), boost::cref(ControllerInfo.server), boost::cref(ControllerInfo.serverport)))
|
---|
98 | (boost::bind(&printReceivedResults,
|
---|
99 | boost::bind(&FragmentController::getReceivedResults, boost::ref(controller))))
|
---|
100 | ));
|
---|
101 | }
|
---|
102 |
|
---|
103 | void controller_SystemCommandJob::addSpecificOption(
|
---|
104 | boost::program_options::options_description_easy_init option)
|
---|
105 | {
|
---|
106 | option
|
---|
107 | ("jobcommand", boost::program_options::value< std::string >(), "command argument for executable for 'createjobs'")
|
---|
108 | ("executable", boost::program_options::value< std::string >(), "executable for commands 'createjobs'")
|
---|
109 | ;
|
---|
110 | }
|
---|
111 |
|
---|
112 | int controller_SystemCommandJob::addOtherParsings(
|
---|
113 | ControllerOptions &ControllerInfo,
|
---|
114 | boost::program_options::variables_map &vm)
|
---|
115 | {
|
---|
116 | ControllerOptions_SystemCommandJob &CI =
|
---|
117 | reinterpret_cast<ControllerOptions_SystemCommandJob &>(ControllerInfo);
|
---|
118 | int status = 0;
|
---|
119 | status = CI.parseExecutable(vm);
|
---|
120 | if (status) return status;
|
---|
121 | status = CI.parseJobCommand(vm);
|
---|
122 | return status;
|
---|
123 | }
|
---|