-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdatasets.inc
218 lines (192 loc) · 6.95 KB
/
datasets.inc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
<?php
function get_dataset_form() {
$form['name'] = array(
'#type' => 'textfield',
'#title' => t('Dataset Name'),
'#size' => 60,
'#maxlength' => 50,
'#required' => TRUE,
);
$form['path'] = array(
'#type' => 'textfield',
'#title' => t('HDFS Folder Name'),
'#maxlength' => 255,
'#size' => 60,
);
$form['compilerpath'] = array(
'#type' => 'textfield',
'#title' => t('Compiler Folder Name'),
'#maxlength' => 255,
'#size' => 60,
);
$form['opts'] = array(
'#type' => 'textfield',
'#title' => t('Runtime Arguments'),
'#maxlength' => 4096,
'#size' => 60,
);
$form['enabled'] = array(
'#type' => 'checkbox',
'#title' => t('Release dataset to users'),
'#default_value' => NULL,
);
$form['submit'] = array(
'#type' => 'submit',
);
return $form;
}
function boa_dataset_add_form($form, &$form_state) {
$f = get_dataset_form();
$f['path']['#required'] = TRUE;
$f['compilerpath']['#required'] = TRUE;
$f['submit']['#value'] = t('Add Dataset');
return $f;
}
function boa_dataset_add_form_validate($form, &$form_state) {
$path = $form_state['values']['path'];
$out = system(hadoop_exec_path() . ' fs -ls /repcache/' . escapeshellcmd($path) . '/projects.seq > /dev/null', $retval);
if ($retval != 0)
form_set_error('path', t('HDFS Folder Name ') . "'$path'" . t(' does not exist or is not a valid input dataset.'));
$compiler_base = boa_variable_get('compiler_path') . '/';
$compiler_path = $form_state['values']['compilerpath'];
if (!is_dir($compiler_base . $compiler_path))
form_set_error('compilerpath', t('Compiler Folder Name ') . "'$compiler_path'" . t(' does not exist.'));
else if (!is_file($compiler_base . $compiler_path . '/dist/boa-runtime.jar'))
form_set_error('compilerpath', t('Compiler Folder Name ') . "'$compiler_path'" . t(' does not contain a runtime JAR.'));
else if (!is_file($compiler_base . $compiler_path . '/dist/boa-compiler.jar'))
form_set_error('compilerpath', t('Compiler Folder Name ') . "'$compiler_path'" . t(' does not contain a compiler JAR.'));
}
function boa_dataset_add_form_submit($form, &$form_state) {
$query = db_insert('boa_input');
$query->fields(array(
'name' => $form_state['values']['name'],
'path' => $form_state['values']['path'],
'run_opts' => isset($form_state['values']['opts']) ? $form_state['values']['opts'] : NULL,
'compiler_path' => $form_state['values']['compilerpath'],
'enabled' => (int)$form_state['values']['enabled'],
));
$query->execute();
drupal_set_message(t('Dataset was added'), 'status');
drupal_goto('boa/datasets/add');
drupal_exit();
}
function boa_dataset_edit_form($form, &$form_state, $input_id) {
$f = get_dataset_form();
$f['submit']['#value'] = t('Update Dataset');
$f['id'] = array(
'#type' => 'hidden',
'#value' => $input_id,
);
$query = db_select('boa_input', 'i');
$query->fields('i', array('name', 'path', 'run_opts', 'compiler_path', 'enabled'));
$query->condition('i.id', $input_id);
$result = $query->execute();
$record = $result->fetchObject();
$f['name']['#default_value'] = $record->name;
$f['path']['#default_value'] = $record->path;
$f['compilerpath']['#default_value'] = $record->compiler_path;
$f['opts']['#default_value'] = $record->run_opts;
$f['enabled']['#default_value'] = $record->enabled;
return $f;
}
function boa_dataset_edit_form_validate($form, &$form_state) {
if (strlen($form_state['values']['path']) > 0) {
$path = $form_state['values']['path'];
$out = system(hadoop_exec_path() . ' fs -ls /repcache/' . escapeshellcmd($path) . '/projects.seq > /dev/null', $retval);
if ($retval != 0)
form_set_error('path', t('HDFS Folder Name ') . "'$path'" . t(' does not exist or is not a valid input dataset.'));
}
if (strlen($form_state['values']['compilerpath']) > 0) {
$compiler_base = boa_variable_get('compiler_path') . '/';
$compiler_path = $form_state['values']['compilerpath'];
if (!is_dir($compiler_base . $compiler_path))
form_set_error('compilerpath', t('Compiler Folder Name ') . "'$compiler_path'" . t(' does not exist.'));
else if (!is_file($compiler_base . $compiler_path . '/dist/boa-runtime.jar'))
form_set_error('compilerpath', t('Compiler Folder Name ') . "'$compiler_path'" . t(' does not contain a runtime JAR.'));
else if (!is_file($compiler_base . $compiler_path . '/dist/boa-compiler.jar'))
form_set_error('compilerpath', t('Compiler Folder Name ') . "'$compiler_path'" . t(' does not contain a compiler JAR.'));
}
}
function boa_dataset_edit_form_submit($form, &$form_state) {
$input_id = (int)$form_state['values']['id'];
$query = db_update('boa_input');
$query->fields(array(
'name' => $form_state['values']['name'],
'path' => strlen($form_state['values']['path']) > 0 ? $form_state['values']['path'] : NULL,
'run_opts' => $form_state['values']['opts'],
'compiler_path' => strlen($form_state['values']['compilerpath']) > 0 ? $form_state['values']['compilerpath'] : NULL,
'enabled' => isset($form_state['values']['enabled']) ? (int)$form_state['values']['enabled'] : 0,
));
$query->condition('id', $input_id);
$query->execute();
drupal_set_message(t('Dataset was updated'), 'status');
drupal_goto("boa/datasets/$input_id/edit");
drupal_exit();
}
function boa_dataset_list() {
global $user;
$header = array(
array(
'data' => t('ID'),
'field' => 'id',
'sort' => 'desc',
'descending' => false,
),
array(
'data' => t('Name'),
'field' => 'name',
'descending' => true,
),
array(
'data' => t('HDFS Path'),
'field' => 'path',
'descending' => true,
),
array(
'data' => t('Compiler Path'),
'field' => 'compiler_path',
'descending' => true,
),
array(
'data' => t('Run Options'),
'field' => 'run_opts',
'descending' => true,
),
array(
'data' => t('Released'),
'field' => 'enabled',
'descending' => true,
),
array(
'data' => t('Commands'),
),
);
$query = db_select('boa_input', 'i');
$query->fields('i', array('id', 'name', 'path', 'compiler_path', 'run_opts', 'enabled'));
$user_data = field_get_items('user', user_load($user->uid), 'field_table_rows');
$maxRows = empty($user_data) ? 10 : $user_data[0]['value'];
$query = $query->extend('TableSort')->orderByHeader($header)->extend('PagerDefault')->limit($maxRows);
$result = $query->execute();
$rows = array();
while ($data = $result->fetchObject())
$rows[] = array(
$data->id,
$data->name,
$data->path,
$data->compiler_path,
'<div style="-ms-word-break: break-all; word-break: break-all; word-break: break-word; -webkit-hyphens: auto; -moz-hyphens: auto; -ms-hyphens: auto; hyphens: auto;">' . $data->run_opts . '</div>',
$data->enabled ? 'Yes' : 'NO',
"[<a href=\"?q=boa/datasets/{$data->id}/edit\">" . t('edit') . '</a>]',
);
$options = array(
'header' => $header,
'rows' => $rows,
'attributes' => array('width' => '100%'),
'sticky' => true,
'colgroups' => array(),
'caption' => '<a href="index.php?q=boa/datasets/add">' . t('Add a dataset') . '</a>',
'empty' => t('No datasets exist yet.'),
);
return theme_table($options).theme('pager');
}
?>