33
44#include " RubyHook.hpp"
55#include < stdexcept>
6+ #include < string>
67
78#include < ruby.h>
89
@@ -59,28 +60,6 @@ static int unwrapEnv(VALUE name, VALUE value, VALUE arg)
5960 return ST_CONTINUE;
6061}
6162
62- // map parts of mesos::TaskInfo into a Ruby hash structure
63- VALUE wrapTaskInfo (const mesos::TaskInfo& taskInfo)
64- {
65- // create top level hash with required PB fields
66- VALUE hash = rb_hash_new ();
67- hash_set (hash, " name" , taskInfo.name ());
68- hash_set (hash, " task_id" , taskInfo.task_id ().value ());
69- hash_set (hash, " slave_id" , taskInfo.slave_id ().value ());
70-
71- // add Labels as a strings hash and insert it into main hash as "labels"
72- // e.g. in Ruby use: taskInfo["labels"]["foo"] = "bar"
73- VALUE labels = rb_hash_new ();
74- if (taskInfo.has_labels ()) {
75- foreach (const mesos::Label& l, taskInfo.labels ().labels ()) {
76- hash_set (labels, l.key (), l.has_value () ? l.value () : " " );
77- }
78- }
79- hash_set (hash, " labels" , labels);
80-
81- return hash;
82- }
83-
8463// map parts of mesos::ExecutorInfo into a Ruby hash structure
8564VALUE wrapExecutorInfo (const mesos::ExecutorInfo& executorInfo)
8665{
@@ -104,11 +83,47 @@ VALUE wrapExecutorInfo(const mesos::ExecutorInfo& executorInfo)
10483 VALUE user = commandInfo.has_user () ? rb_str_new_cstr (commandInfo.user ().c_str ())
10584 : rb_str_new_cstr (" no_user_found" );
10685 hash_set (command, " user" , user);
86+ VALUE value = commandInfo.has_value () ? rb_str_new_cstr (commandInfo.value ().c_str ())
87+ : rb_str_new_cstr (" no command value" );
88+ hash_set (command, " value" , value);
89+
90+ VALUE args = rb_ary_new ();
91+ foreach (const std::string& arg, commandInfo.arguments ()) {
92+ ary_push (args, arg);
93+ }
94+ hash_set (command, " args" , args);
10795 }
10896 hash_set (hash, " command" , command);
10997
11098 return hash;
11199}
100+
101+ // map parts of mesos::TaskInfo into a Ruby hash structure
102+ VALUE wrapTaskInfo (const mesos::TaskInfo& taskInfo)
103+ {
104+ // create top level hash with required PB fields
105+ VALUE hash = rb_hash_new ();
106+ hash_set (hash, " name" , taskInfo.name ());
107+ hash_set (hash, " task_id" , taskInfo.task_id ().value ());
108+ hash_set (hash, " slave_id" , taskInfo.slave_id ().value ());
109+ if (taskInfo.has_executor ()) {
110+ const mesos::ExecutorInfo& executorInfo = taskInfo.executor ();
111+ hash_set (hash, " executor" , wrapExecutorInfo (executorInfo));
112+ }
113+
114+ // add Labels as a strings hash and insert it into main hash as "labels"
115+ // e.g. in Ruby use: taskInfo["labels"]["foo"] = "bar"
116+ VALUE labels = rb_hash_new ();
117+ if (taskInfo.has_labels ()) {
118+ foreach (const mesos::Label& l, taskInfo.labels ().labels ()) {
119+ hash_set (labels, l.key (), l.has_value () ? l.value () : " " );
120+ }
121+ }
122+ hash_set (hash, " labels" , labels);
123+
124+ return hash;
125+ }
126+
112127}
113128
114129// //////////////////////////////////////////////////////////////////////////////
0 commit comments