Example #1
0
 public function processAPI()
 {
     switch ($this->method) {
         case "GET":
             $gotNew = false;
             // get older jobs first
             $allJobs = get_job_list();
             sort($allJobs);
             foreach ($allJobs as $job) {
                 // found a new job
                 if ($job->is_new()) {
                     $JSON = array('newJob' => true, 'jobID' => $job->id, 'dependencies' => $job->get_dependency_links());
                     $gotNew = true;
                     // log
                     $GLOBALS['log']->info('Found new job with ID: ' . $job->id);
                     break;
                 }
             }
             // if no new jobs
             if (!$gotNew) {
                 $JSON = array('newJob' => false);
                 // log
                 //$GLOBALS['log']->info('No new job found!');
             }
             // send JSON
             $this->response($JSON);
             break;
         case "PUT":
             if (!isset($this->args[0])) {
                 $GLOBALS['log']->error('Queue ID not set!');
                 $this->fail("Invalid queue ID", 406);
             }
             // check type is json
             if ($_SERVER['CONTENT_TYPE'] != "application/json") {
                 $GLOBALS['log']->error('Unsupported content type: ' . $_SERVER['CONTENT_TYPE']);
                 $this->fail("Unsupported content type. Expecting: application/json.", 500);
             }
             // if job with this id does not exist, fail
             $jobID = $this->args[0];
             if (!job_exists($jobID)) {
                 $GLOBALS['log']->error('No job with ID ' . $jobID);
                 $this->fail("Invalid queue ID, no such job", 406);
             }
             $job = new Job($jobID);
             // parse incoming json
             $json = file_get_contents('php://input');
             $json = json_decode($json, true);
             if ($json == null) {
                 $GLOBALS['log']->error('Incorrectly formatted json input.');
                 $this->fail("Incorrectly formatted json input.", 500);
             }
             // update job
             if ($json['action'] == 'update') {
                 // status update
                 if (isset($json['status'])) {
                     if ($json['status'] == 'submitted') {
                         $job->set_to_submitted();
                         $GLOBALS['log']->info('Job ' . $jobID . ' status set to SUBMITTED.');
                     } elseif ($json['status'] == 'running') {
                         // since we update the status with all messages, log just the first time
                         if (!$job->is_running()) {
                             $GLOBALS['log']->info('Job ' . $jobID . ' status set to RUNNING.');
                         }
                         $job->set_to_running();
                     } elseif ($json['status'] == 'success') {
                         $job->set_to_success();
                         $GLOBALS['log']->info('Job ' . $jobID . ' status set to SUCCESS.');
                     } elseif ($json['status'] == 'fail') {
                         $job->set_to_fail();
                         $GLOBALS['log']->info('Job ' . $jobID . ' status set to FAIL.');
                     }
                 }
                 // tracking URL
                 if (isset($json['tracking'])) {
                     // since we update the url with all messages, log just the first time
                     if (!$job->has_hadoop_track_link()) {
                         $GLOBALS['log']->info('Job ' . $jobID . ' setting tracking link.');
                     }
                     $job->set_hadoop_track_link($json['tracking']);
                 }
                 // progress
                 if (isset($json['progress'])) {
                     $job->update_progress($json['progress']);
                     //$GLOBALS['log']->info('Job '.$jobID. ' updating progress.');
                 }
                 // hadoop out
                 if (isset($json['hadoop_out'])) {
                     $job->store_hadoop_out($json['hadoop_out']);
                     $GLOBALS['log']->info('Job ' . $jobID . ' storing hadoop out.');
                 }
             }
             break;
         default:
             $GLOBALS['log']->error('Method not allowed!.');
             $this->fail("Method not allowed.", 405);
     }
 }
Example #2
0
<?php

include_once "../lib/header.html";
include_once "../lib/job_handler.php";
// Report all PHP errors (see changelog)
//error_reporting(E_ALL);
//ini_set('display_errors', '1');
if (isset($_GET['show_form_id'])) {
    if (!job_exists($_GET['show_form_id'])) {
        //redirect
        header('Location: index.php');
    }
    $SHOW = true;
    $job = new Job($_GET['show_form_id']);
    $DATA = $job->get_post_data();
} else {
    $SHOW = false;
}
function insert_input($name)
{
    global $SHOW, $DATA, $job;
    if ($SHOW) {
        if (isset($DATA[$name])) {
            echo '<a href="' . $job->get_dependency_link($DATA[$name]) . '" target="_blank" >
                <input type="text" class="form-control" value="' . $DATA[$name] . '" disabled></a>';
        } else {
            echo '<input type="text" class="form-control" value="" disabled></a>';
        }
    } else {
        echo '<input name="' . $name . '" id="' . $name . '" type="file" class="file" data-show-preview="false" data-show-upload="false">';
    }