0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Public Member Functions | Private Attributes | List of all members
Hypertable::ClusterDefinitionFile::TranslatorTask Class Reference

Translates a task definition. More...

#include <TranslatorTask.h>

Inheritance diagram for Hypertable::ClusterDefinitionFile::TranslatorTask:
Inheritance graph
[legend]
Collaboration diagram for Hypertable::ClusterDefinitionFile::TranslatorTask:
Collaboration graph
[legend]

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...
 

Detailed Description

Translates a task definition.

Definition at line 43 of file TranslatorTask.h.

Constructor & Destructor Documentation

Hypertable::ClusterDefinitionFile::TranslatorTask::TranslatorTask ( const string &  fname,
size_t  lineno,
const string &  text 
)
inline

Constructor.

Parameters
fnameFilename of source file containing task definition
linenoLine number within source file of task definition
textText of task definition

Definition at line 49 of file TranslatorTask.h.

Member Function Documentation

const string TranslatorTask::translate ( TranslationContext context)
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.

Parameters
contextContext object containing symbol tables
Returns
translated task statement

Implements Hypertable::ClusterDefinitionFile::Translator.

Definition at line 157 of file TranslatorTask.cc.

Member Data Documentation

string Hypertable::ClusterDefinitionFile::TranslatorTask::m_fname
private

Source file name containing task definition.

Definition at line 96 of file TranslatorTask.h.

size_t Hypertable::ClusterDefinitionFile::TranslatorTask::m_lineno
private

Line number within m_fname of task definition.

Definition at line 98 of file TranslatorTask.h.

string Hypertable::ClusterDefinitionFile::TranslatorTask::m_text
private

Text of task definition.

Definition at line 100 of file TranslatorTask.h.


The documentation for this class was generated from the following files: