39 $this->name =
'Task Management';
40 parent::__construct($this->name);
43 'listhosts' => sprintf(
47 'listgroups' => sprintf(
59 'menu' => &$this->menu,
60 'submenu' => &$this->subMenu,
62 'notes' => &$this->notes
65 $this->headerData = array(
66 '<input type="checkbox" class="toggle-checkboxAction" id="toggler"/>'
67 .
'<label for="toggler"></label>',
70 '%s<br/><small>%s</small>',
76 _(
'Working with node'),
79 $this->templates = array(
80 '<input type="checkbox" class="toggle-action" name='
81 .
'"task[]" value="${id}" id="tasker-${id}"/><label for="'
82 .
'tasker-${id}"></label>',
85 '<p><a href="?node=host&sub=edit&id=${host_id}" title='
86 .
'"%s">${host_name}</a></p><small>${host_mac}</small>',
90 '<p><a href="?node=image&sub=edit&id=${image_id}" title='
91 .
'"%s">${image_name}</a></p>',
94 '<small>${time}</small>',
95 '<small>${node_name}</small>',
96 '${details_taskforce} <i data-state="${state_id}" class='
97 .
'"state fa fa-${icon_state} fa-1x icon" title="${state}">'
98 .
'</i> <i class="fa fa-${icon_type} fa-1x icon" title="${type}"></i>',
100 $this->attributes = array(
103 'class' =>
'filter-false',
108 'id' =>
'host-${host_id}'
124 'class' =>
'filter-false'
134 self::$returnData =
function (&
$Task) {
139 $SnapinTrue = $tmpTask->isSnapinTasking();
143 $Task->host->snapinjob->id
150 'stateID' => self::fastmerge(
151 (array)$this->getQueuedStates(),
152 (array)$this->getProgressState()
162 if (
$Task->state->id < 3) {
163 if (
$Task->type->id < 3) {
164 if (
$Task->isForced) {
165 $forcetask = sprintf(
166 '<i class="icon-forced" title="%s"></i>',
167 _(
'Task forced to start')
170 $forcetask = sprintf(
171 '<i class="icon-force icon" title="%s" href="?%s"></i>',
172 _(
'Force task to start'),
173 'node=task&sub=forceTask&id=${id}'
178 $this->data[] = array(
179 'startedby' =>
$Task->createdBy,
180 'details_taskforce' => $forcetask,
182 'name' =>
$Task->name,
183 'time' => self::formatTime(
187 'state' =>
$Task->state->name,
188 'forced' =>
$Task->isForced,
189 'type' =>
$Task->type->name,
190 'elapsed' =>
$Task->timeElapsed,
191 'remains' =>
$Task->timeRemaining,
192 'percent' =>
$Task->pct,
193 'copied' =>
$Task->dataCopied,
194 'total' =>
$Task->dataTotal,
196 'details_taskname' => (
199 '<div class="task-name">%s</div>',
204 'host_id' =>
$Task->host->id,
205 'host_name' =>
$Task->host->name,
206 'host_mac' =>
$Task->host->mac,
207 'icon_state' =>
$Task->state->icon,
208 'icon_type' =>
$Task->type->icon,
209 'state_id' =>
$Task->state->id,
210 'image_name' =>
$Task->image->name,
211 'image_id' =>
$Task->image->id,
212 'node_name' =>
$Task->storagenode->name
214 unset($tmpTask,
$Task);
233 $this->data = array();
234 array_shift($this->headerData);
235 array_shift($this->templates);
236 array_shift($this->attributes);
237 parent::searchPost();
246 $this->title = _(
'Active Tasks');
247 $this->data = array();
249 'stateID' => self::fastmerge(
250 (array) self::getQueuedStates(),
251 (array) self::getProgressState()
269 'headerData' => &$this->headerData,
270 'data' => &$this->data,
271 'templates' => &$this->templates,
272 'attributes' => &$this->attributes
295 echo
'<div class="tab-content col-xs-9">';
296 echo
'<div class="panel panel-info">';
297 echo
'<div class="panel-heading text-center">';
298 echo
'<h4 class="title">';
302 echo
'<div class="panel-body">';
322 $this->title = _(
'All Hosts');
326 '<a href="?node=task&sub=hostdeploy&type=%s&id=${id}">'
327 .
'<i class="icon hand fa fa-%s fa-fw" title="%s"></i></a>',
333 '<a href="?node=task&sub=hostdeploy&type=%s&id=${id}">'
334 .
'<i class="icon hand fa fa-%s fa-fw" title="%s"></i></a>',
340 '<a href="?node=task&sub=hostadvanced&id=${id}#host-tasks">'
341 .
'<i class="icon hand fa fa-arrows-alt fa-fw title="%s"></i></a>',
344 $this->headerData = array(
349 $this->templates = array(
350 '<a href="?node=host&sub=edit&id=${id}">${name}</a>'
351 .
'<br/><small>${mac}</small>',
352 '<small>${imagename}</small>',
360 $this->attributes = array(
370 'class' =>
'filter-false'
377 array(
'pending' => array(
'0',
'',
null))
379 $Hosts = json_decode(
382 $Hosts = $Hosts->hosts;
383 foreach ((array)$Hosts as &
$Host) {
384 $this->data[] = array(
386 'name' =>
$Host->name,
387 'mac' =>
$Host->primac,
388 'imagename' =>
$Host->image->name,
396 'headerData' => &$this->headerData,
397 'data' => &$this->data,
398 'templates' => &$this->templates,
399 'attributes' => &$this->attributes
426 $this->title = _(
'All Groups');
430 '<a href="?node=task&sub=groupdeploy&type=%s&id=${id}">'
431 .
'<i class="icon hand fa fa-%s fa-fw" title="%s"></i></a>',
437 '<a href="?node=task&sub=groupdeploy&type=%s&id=${id}">'
438 .
'<i class="icon hand fa fa-%s fa-fw" title="%s"></i></a>',
444 '<a href="?node=task&sub=groupadvanced&id=${id}#group-tasks">'
445 .
'<i class="icon hand fa fa-arrows-alt fa-fw title="%s"></i></a>',
448 $this->headerData = array(
452 $this->templates = array(
453 '<a href="?node=group&sub=edit&id=${id}">${name}</a>',
461 $this->attributes = array(
468 'class' =>
'filter-false'
472 $Groups = json_decode(
475 $Groups = $Groups->groups;
476 foreach ((array)$Groups as &$Group) {
477 $this->data[] = array(
479 'name' => $Group->name,
485 'TasksListGroupData',
487 'headerData' => &$this->headerData,
488 'data' => &$this->data,
489 'templates' => &$this->templates,
490 'attributes' => &$this->attributes
518 if (!in_array($type, $types)) {
519 throw new Exception(_(
'Invalid object type passed'));
521 $var = ucfirst($type);
523 if (!$$var->isValid()) {
524 throw new Exception(_(sprintf(
'Invalid %s', $var)));
526 $typeID = filter_input(INPUT_GET,
'type');
529 throw new Exception(_(
'Invalid Task Type'));
531 if ($type ==
'host') {
532 $Image = $$var->getImage();
534 throw new Exception(_(
'Invalid image assigned to host'));
537 &&
$Image->get(
'protected')
553 } elseif ($type ==
'group') {
555 && !$$var->doMembersHaveUniformImages()
558 _(
'Hosts do not have the same image assigned')
563 _(
'Multicast Quick Deploy') :
564 _(
'Group Quick Deploy')
567 $enableSnapins =
$TaskType->
get(
'id') == 17 ? false : -1;
568 $enableDebug = in_array(
572 $$var->createImagePackage(
579 self::$FOGUser->get(
'name'),
584 echo
'<div class="col-xs-9">';
585 echo
'<div class="panel panel-success">';
586 echo
'<div class="panel-heading text-center">';
587 echo
'<h4 class="title">';
588 echo _(
'Tasked Successfully');
591 echo
'<div class="panel-body">';
592 echo _(
'Tasked successfully, click active tasks to view in line.');
596 }
catch (Exception $e) {
597 echo
'<div class="col-xs-9">';
598 echo
'<div class="panel panel-warning">';
599 echo
'<div class="panel-heading text-center">';
600 echo
'<h4 class="title">';
601 echo _(
'Failed to create task');
604 echo
'<div class="panel-body">';
605 echo $e->getMessage();
648 '%s Advanced Actions',
657 if (!in_array($type, $types)) {
658 throw new Exception(_(
'Invalid object type passed'));
660 $this->templates = array(
662 '<a href="?node=%s&sub=%sdeploy&id=${id}&type=${type}">'
663 .
'<i class="fa fa-${icon} fa-fw fa-2x"/></i><br/>${name}</a>',
669 $this->attributes = array(
670 array(
'class' =>
'col-xs-4'),
671 array(
'class' =>
'col-xs-8 form-group'),
678 'access' => array(
'both', $type),
682 $TaskTypes = json_decode(
685 $TaskTypes = $TaskTypes->tasktypes;
686 foreach ((array)$TaskTypes as &
$TaskType) {
687 $this->data[] = array(
700 'headerData' => &$this->headerData,
701 'data' => &$this->data,
702 'templates' => &$this->templates,
703 'attributes' => &$this->attributes
757 if (!
$Task->isValid()) {
758 throw new Exception(_(
'Invalid task'));
767 $Task->set(
'isForced', 1)->save();
768 $result[
'success'] =
true;
769 }
catch (Exception $e) {
770 $result[
'error'] = $e->getMessage();
773 echo json_encode($result);
776 if ($result[
'error']) {
801 $this->title = _(
'Active Multi-cast Tasks');
802 $this->headerData = array(
803 '<input type="checkbox" name="toggle-checkbox" class='
804 .
'"toggle-checkboxAction" id="toggler1"/>'
805 .
'<label for="toggler1"></label>',
812 $this->templates = array(
813 '<input type="checkbox" name="task[]" value="${id}" class='
814 .
'"toggle-action" id="mctask-${id}"/>'
815 .
'<label for="mctask-${id}"></label>',
822 $this->attributes = array(
825 'class' =>
'filter-false',
841 $Sessions = json_decode(
844 $Sessions = $Sessions->multicastsessions;
845 foreach ((array)$Sessions as &$MulticastSession) {
846 $TaskState = $MulticastSession->state;
847 if (!$TaskState->id) {
850 $this->data[] = array(
851 'id' => $MulticastSession->id,
853 $MulticastSession->name ?: _(
'MulticastTask')
856 self::getClass(
'MulticastSessionAssociationManager')
857 ->count(array(
'msID' => $MulticastSession->id))
859 'start_date' => self::formatTime(
860 $MulticastSession->starttime,
864 $TaskState->name ?:
''
866 'percent' => $MulticastSession->percent,
868 unset($TaskState, $MulticastSession);
872 'TaskActiveMulticastData',
874 'headerData' => &$this->headerData,
875 'data' => &$this->data,
876 'templates' => &$this->templates,
877 'attributes' => &$this->attributes
903 $MulticastSessionIDs = (array)$_POST[
'task'];
905 'MulticastSessionAssociation',
907 'msID' => $MulticastSessionIDs
912 self::getClass(
'MulticastSessionManager')->cancel($_POST[
'task']);
913 unset($MulticastSessionIDs);
930 $this->title =
'Active Snapins';
931 $this->headerData = array(
932 '<input type="checkbox" name="toggle-checkbox" class='
933 .
'"toggle-checkboxAction" id="toggler2"/><label for="'
934 .
'toggler2"></label>',
940 $this->templates = array(
941 '<input type="checkbox" name="task[]" value="${id}" class='
942 .
'"toggle-action" id="sntasks-${id}"/><label for="'
943 .
'sntasks-${id}"></label>',
945 '<p><a href="?node=host&sub=edit&id=${host_id}" title='
946 .
'"%s">${host_name}</a></p><small>${host_mac}</small>',
953 $this->attributes = array(
955 'class' =>
'filter-false',
973 $SnapinTasks = json_decode(
977 (array)self::getQueuedStates(),
978 (array)self::getProgressState()
980 $SnapinTasks = $SnapinTasks->snapintasks;
981 foreach ((array)$SnapinTasks as &$SnapinTask) {
982 $Snapin = $SnapinTask->snapin;
998 $inArr = in_array($state, $activestate);
1002 $this->data[] = array(
1003 'id' => $SnapinTask->id,
1004 'name' => $Snapin->name,
1005 'host_id' =>
$Host->id,
1006 'host_name' =>
$Host->name,
1007 'host_mac' =>
$Host->primac,
1008 'startDate' => self::formatTime(
1009 $SnapinTask->checkin,
1012 'state' => $SnapinTask->state->name
1023 'TaskActiveSnapinsData',
1025 'headerData' => &$this->headerData,
1026 'data' => &$this->data,
1027 'templates' => &$this->templates,
1028 'attributes' => &$this->attributes
1031 unset($SnapinTasks);
1052 _(
'Cannot cancel tasks this way')
1066 $SnapinTaskIDs = (array)$_POST[
'task'];
1067 if (count($SnapinTaskIDs) > 0) {
1071 'id' => $SnapinTaskIDs
1077 if (count($SnapinJobIDs) > 0) {
1081 'id' => $SnapinJobIDs
1086 if (count($HostIDs) > 0) {
1090 'jobID' => $SnapinJobIDs,
1093 $TaskIDs = array_diff(
1098 if (count($TaskIDs) < 1) {
1102 'hostID' => $HostIDs,
1127 $this->title = _(
'Scheduled Tasks');
1128 $this->headerData = array(
1129 '<input type="checkbox" name="toggle-checkbox" class='
1130 .
'"toggle-checkboxAction" id="toggler3"/><label for="'
1131 .
'toggler3"></label>',
1132 _(
'Host/Group Name'),
1140 $this->templates = array(
1141 '<input type="checkbox" name="task[]" value="${id}" class='
1142 .
'"toggle-action" id="sctasks-${id}"/><label for="'
1143 .
'sctasks-${id}"></label>',
1144 '<a href="?node=${hostgroup}&sub=edit&id=${hostgroupid}" title='
1145 .
'"Edit ${nametype}: ${hostgroupname}">${hostgroupname}</a>${extra}',
1147 '<span class="icon" title="${hover}">${details_taskname}</span>',
1149 '<small>${start_time}</small>',
1153 $this->attributes = array(
1156 'class' =>
'filter-false',
1157 'task-id' =>
'${id}'
1182 $ScheduledTasks = json_decode(
1185 $ScheduledTasks = $ScheduledTasks->scheduledtasks;
1186 foreach ((array)$ScheduledTasks as &$ScheduledTask) {
1188 if ($ScheduledTask->isGroupTask) {
1191 $ObjTest = $ScheduledTask->{$method};
1192 if (!$ObjTest->id) {
1199 $sID = $ScheduledTask->other2;
1202 || $ScheduledTask->other2 == -1
1204 $hover = _(
'All snapins');
1206 $snapin =
new Snapin($sID);
1207 if (!$snapin->isValid()) {
1208 $hover = _(
'Invalid snapin');
1210 $hover = _(
'Snapin to be installed')
1212 . $snapin->get(
'name');
1216 $this->data[] = array(
1217 'id' => $ScheduledTask->id,
1218 'start_time' => $ScheduledTask->runtime,
1220 $ScheduledTask->isGroupTask ?
1225 $ScheduledTask->isActive ?
1229 'type' => $ScheduledTask->type ==
'C' ? _(
'Cron') : _(
'Delayed'),
1231 $ScheduledTask->isGroupTask ?
1235 'hostgroupname' => $ObjTest->name,
1236 'hostgroupid' => $ObjTest->id,
1237 'details_taskname' => $ScheduledTask->name,
1240 $ScheduledTask->isGroupTask ?
1247 'nametype' => $method,
1250 unset($ScheduledTask, $ObjTest,
$TaskType);
1254 'TaskScheduledData',
1256 'headerData' => &$this->headerData,
1257 'data' => &$this->data,
1258 'templates' => &$this->templates,
1259 'attributes' => &$this->attributes
1284 self::getClass(
'ScheduledTaskManager')
1286 array(
'id' => $_POST[
'task'])