Translates a task definition. More...
#include <TranslatorTask.h>
Public Member Functions | |
TranslatorTask (const string &fname, size_t lineno, const string &text) | |
Constructor. More... | |
const string | translate (TranslationContext &context) override |
Translates a task definition. More... | |
Private Attributes | |
string | m_fname |
Source file name containing task definition. More... | |
size_t | m_lineno |
Line number within m_fname of task definition. More... | |
string | m_text |
Text of task definition. More... | |
Translates a task definition.
Definition at line 43 of file TranslatorTask.h.
|
inline |
Constructor.
fname | Filename of source file containing task definition |
lineno | Line number within source file of task definition |
text | Text of task definition |
Definition at line 49 of file TranslatorTask.h.
|
overridevirtual |
Translates a task definition.
The best way to illustrate how tasks get translated is with an example. The following task definition:
task: display_hostnames roles: master,slave { echo "before" ssh: { hostname } echo "after" }
gets translated into a bash function similar to the following:
display_hostnames () { local _SSH_HOSTS="(${ROLE_master}) + (${ROLE_slave})" if [ $# -gt 0 ] && [ $1 == "on" ]; then shift if [ $# -eq 0 ]; then echo "Missing host specification in 'on' argument" exit 1 else _SSH_HOSTS="$1" shift fi fi echo "display_hostnames $@" echo "before" /opt/hypertable/0.9.8.1/bin/ht ssh " ${_SSH_HOSTS}" "hostname" echo "after" }
Notice that the ssh:
statemnts get translated to a call to the ht_ssh
tool. Also, the function includes logic to check for on <hostspec>
initial arguments. If found, the target hosts for ssh:
statements becomes <hostspec>
instead of the default roles specified by the roles:
clause.
context | Context object containing symbol tables |
Implements Hypertable::ClusterDefinitionFile::Translator.
Definition at line 157 of file TranslatorTask.cc.
|
private |
Source file name containing task definition.
Definition at line 96 of file TranslatorTask.h.
|
private |
Line number within m_fname of task definition.
Definition at line 98 of file TranslatorTask.h.
|
private |
Text of task definition.
Definition at line 100 of file TranslatorTask.h.