Merge branch 'master' of disposed.de:scattport
This commit is contained in:
@@ -4,7 +4,7 @@ class Jobs extends CI_Controller {
|
|||||||
|
|
||||||
public function getOwn() {
|
public function getOwn() {
|
||||||
$query = $this->db->order_by('progress', 'desc')
|
$query = $this->db->order_by('progress', 'desc')
|
||||||
->get_where('jobs', array('started_by' => $this->session->user_data('user_id')));
|
->get_where('jobs', array('started_by' => $this->session->userdata('user_id')));
|
||||||
$count = $query->num_rows();
|
$count = $query->num_rows();
|
||||||
$jobs = $query->result_array();
|
$jobs = $query->result_array();
|
||||||
|
|
||||||
@@ -39,7 +39,7 @@ class Jobs extends CI_Controller {
|
|||||||
|
|
||||||
public function listResultsNotSeen() {
|
public function listResultsNotSeen() {
|
||||||
$query = $this->db->order_by('started_at', 'asc')
|
$query = $this->db->order_by('started_at', 'asc')
|
||||||
->get_where('jobs', array('started_by' => $this->session->user_data('user_id'), 'seen' => '0'));
|
->get_where('jobs', array('started_by' => $this->session->userdata('user_id'), 'seen' => '0'));
|
||||||
$count = $query->num_rows();
|
$count = $query->num_rows();
|
||||||
$jobs = $query->result_array();
|
$jobs = $query->result_array();
|
||||||
|
|
||||||
|
|||||||
49
application/controllers/statusrpc.php
Normal file
49
application/controllers/statusrpc.php
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Simple RPC class to handle requests from calculation servers.
|
||||||
|
*
|
||||||
|
* @author Karsten Heiken, karsten@disposed.de
|
||||||
|
*/
|
||||||
|
class Statusrpc extends CI_Controller {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update the state of a given job.
|
||||||
|
*
|
||||||
|
* Because we do not want any access from servers we do not trust,
|
||||||
|
* we need a special secret to authenticate the servers.
|
||||||
|
*
|
||||||
|
* @param type $secret The secret to authenticate the server.
|
||||||
|
* @param type $job_id The job id that is running on the server.
|
||||||
|
* @param type $state The state of the job.
|
||||||
|
*/
|
||||||
|
public function update_job($secret, $job_id, $progress) {
|
||||||
|
$this->load->model('job');
|
||||||
|
|
||||||
|
$query = $this->db->get_where('servers', array('secret' => $secret));
|
||||||
|
|
||||||
|
// if we are in production mode, we do not want to tell the evil hacker
|
||||||
|
// that he used a wrong secret. That just encourages him.
|
||||||
|
if($query->num_rows() < 1 && ENVIRONMENT != 'production') {
|
||||||
|
die("Unauthorized access.");
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->job->update($job_id, $progress);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update the workload of the server.
|
||||||
|
*/
|
||||||
|
public function update_workload($secret, $workload) {
|
||||||
|
$this->load->model('server');
|
||||||
|
$query = $this->db->get_where('servers', array('secret' => $secret));
|
||||||
|
|
||||||
|
// if we are in production mode, we do not want to tell the evil hacker
|
||||||
|
// that he used a wrong secret. That just encourages him.
|
||||||
|
if($query->num_rows() < 1 && ENVIRONMENT != 'production') {
|
||||||
|
die("Unauthorized access.");
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->server->update_workload($secret, $workload);
|
||||||
|
}
|
||||||
|
}
|
||||||
23
application/models/job.php
Normal file
23
application/models/job.php
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Karsten Heiken, karsten@disposed.de
|
||||||
|
*/
|
||||||
|
class Job extends CI_Model {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update the progress of a given job.
|
||||||
|
*
|
||||||
|
* @param string $job_id The job's id you want to update.
|
||||||
|
* @param integer $progress The progress of the job.
|
||||||
|
*/
|
||||||
|
public function update($job_id, $progress) {
|
||||||
|
$finished_at = "";
|
||||||
|
if($progress == 100)
|
||||||
|
$finished_at = ", `finished_at`=NOW()";
|
||||||
|
|
||||||
|
$this->db->query("UPDATE `jobs` SET `progress`=".
|
||||||
|
$this->db->escape($progress).$finished_at. " WHERE `id`=".
|
||||||
|
$this->db->escape($job_id));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -14,7 +14,7 @@ class Project extends CI_Model {
|
|||||||
* @return array The user's projects.
|
* @return array The user's projects.
|
||||||
*/
|
*/
|
||||||
public function getOwn() {
|
public function getOwn() {
|
||||||
$query = $this->db->where(array('owner' => $this->session->user_data('user_id')))
|
$query = $this->db->where(array('owner' => $this->session->userdata('user_id')))
|
||||||
->order_by('lastaccess', 'desc')
|
->order_by('lastaccess', 'desc')
|
||||||
->get('projects');
|
->get('projects');
|
||||||
$projects = $query->result_array();
|
$projects = $query->result_array();
|
||||||
@@ -25,6 +25,7 @@ class Project extends CI_Model {
|
|||||||
$ownProjects[$i]['id'] = '/projects/own/'.$project['id'];
|
$ownProjects[$i]['id'] = '/projects/own/'.$project['id'];
|
||||||
$ownProjects[$i]['cls'] = 'folder';
|
$ownProjects[$i]['cls'] = 'folder';
|
||||||
$ownProjects[$i]['text'] = $project['name'];
|
$ownProjects[$i]['text'] = $project['name'];
|
||||||
|
$ownProjects[$i]['prjId'] = $project['id'];
|
||||||
$ownProjects[$i]['leaf'] = true;
|
$ownProjects[$i]['leaf'] = true;
|
||||||
$i++;
|
$i++;
|
||||||
}
|
}
|
||||||
@@ -38,7 +39,8 @@ class Project extends CI_Model {
|
|||||||
* @return array The shared projects.
|
* @return array The shared projects.
|
||||||
*/
|
*/
|
||||||
public function getShared() {
|
public function getShared() {
|
||||||
$this->db->select('*')->from('shares')->order_by('lastaccess', 'desc')->where(array('user_id' => $this->session->user_data('user_id')));
|
$this->load->library('session');
|
||||||
|
$this->db->select('*')->from('shares')->order_by('lastaccess', 'desc')->where(array('user_id' => $this->session->userdata('user_id')));
|
||||||
$this->db->join('projects', 'projects.id = shares.project_id');
|
$this->db->join('projects', 'projects.id = shares.project_id');
|
||||||
$query = $this->db->get();
|
$query = $this->db->get();
|
||||||
|
|
||||||
@@ -50,6 +52,7 @@ class Project extends CI_Model {
|
|||||||
$sharedProjects[$i]['id'] = '/projects/shared/'.$project['id'];
|
$sharedProjects[$i]['id'] = '/projects/shared/'.$project['id'];
|
||||||
$sharedProjects[$i]['cls'] = 'folder';
|
$sharedProjects[$i]['cls'] = 'folder';
|
||||||
$sharedProjects[$i]['text'] = $project['name'];
|
$sharedProjects[$i]['text'] = $project['name'];
|
||||||
|
$sharedProjects[$i]['prjId'] = $project['id'];
|
||||||
$sharedProjects[$i]['leaf'] = true;
|
$sharedProjects[$i]['leaf'] = true;
|
||||||
$i++;
|
$i++;
|
||||||
}
|
}
|
||||||
@@ -74,6 +77,7 @@ class Project extends CI_Model {
|
|||||||
$publicProjects[$i]['id'] = '/projects/public/'.$project['id'];
|
$publicProjects[$i]['id'] = '/projects/public/'.$project['id'];
|
||||||
$publicProjects[$i]['cls'] = 'folder';
|
$publicProjects[$i]['cls'] = 'folder';
|
||||||
$publicProjects[$i]['text'] = $project['name'];
|
$publicProjects[$i]['text'] = $project['name'];
|
||||||
|
$publicProjects[$i]['prjId'] = $project['id'];
|
||||||
$publicProjects[$i]['leaf'] = true;
|
$publicProjects[$i]['leaf'] = true;
|
||||||
$i++;
|
$i++;
|
||||||
}
|
}
|
||||||
|
|||||||
40
application/models/server.php
Normal file
40
application/models/server.php
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Karsten Heiken, karsten@disposed.de
|
||||||
|
*/
|
||||||
|
class Server extends CI_Model {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a list of all available servers.
|
||||||
|
*
|
||||||
|
* @return array List of all available servers.
|
||||||
|
*/
|
||||||
|
public function get_all() {
|
||||||
|
return $this->db->get('servers')->result_array();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a list of servers that could handle another job.
|
||||||
|
*
|
||||||
|
* @return array List of servers that could handle another job.
|
||||||
|
*/
|
||||||
|
public function get_idle() {
|
||||||
|
return $this->db->get_where('servers', 'workload <= 2')->result_array();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set a server's workload.
|
||||||
|
*
|
||||||
|
* In order to check if a server can handle another job we need to know
|
||||||
|
* the workload of every server.
|
||||||
|
*
|
||||||
|
* @param type $secret The server's secret for basic authentication.
|
||||||
|
* @param type $workload The server's workload.
|
||||||
|
*/
|
||||||
|
public function update_workload($secret, $workload) {
|
||||||
|
$this->db->query("UPDATE `servers` SET `workload`=".$this->db->escape($workload)
|
||||||
|
. ", `last_update`=NOW()"
|
||||||
|
. " WHERE `secret`=".$this->db->escape($secret));
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user