Skip to content

Commit

Permalink
[POC-4] Show Pending Tasks, start and stop times
Browse files Browse the repository at this point in the history
  • Loading branch information
apfadler committed Jun 16, 2016
1 parent e174e2c commit 4298188
Show file tree
Hide file tree
Showing 8 changed files with 91 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ public PricePortfolio(String taskName, String taskXML) {

@Override
public void run() throws Exception {


Task.updateStatus(_taskName, Status.RUNNING);

JSONParser parser = new JSONParser();

final JSONObject taskDescription = (JSONObject) parser.parse(_taskDescription);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ public PriceTrade(String taskName, String taskXML) {

@Override
public void run() throws Exception {


Task.updateStatus(_taskName, Status.RUNNING);

JSONParser parser = new JSONParser();

final JSONObject taskDescription = (JSONObject) parser.parse(_taskDescription);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public ScriptedTask(String taskName, String taskXML) {

@Override
public void run() throws Exception {

Task.updateStatus(_taskName, Status.RUNNING);

JSONParser parser = new JSONParser();

Expand Down
45 changes: 42 additions & 3 deletions interpreter/src/main/java/org/quil/server/Tasks/Task.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@
import org.apache.ignite.configuration.CacheConfiguration;
import org.apache.ignite.internal.util.IgniteExceptionRegistry;
import org.apache.ignite.resources.LoggerResource;
import org.joda.time.DateTime;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;

import javax.cache.Cache.Entry;
import java.io.Serializable;
import java.lang.reflect.Constructor;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.UUID;

Expand All @@ -38,7 +41,16 @@ public abstract class Task implements Serializable {

@QuerySqlField
protected int _taskStatus = 0;


@QuerySqlField
protected Date _submitTime = new Date(0);

@QuerySqlField
protected Date _startTime = new Date(0);

@QuerySqlField
protected Date _stopTime = new Date(0);

static class Status {
final static int PENDING = 0;
final static int RUNNING = 1;
Expand Down Expand Up @@ -156,11 +168,21 @@ public Task(String taskName, String taskXML) {
// TODO Auto-generated catch block
e.printStackTrace();
}

_submitTime = new Date();
}


public void setStatus(int status) {
_taskStatus = status;

if (status == Status.RUNNING) {
_startTime = new Date();
}

if (status == Status.FINISHED || status == Status.ERROR) {
_stopTime = new Date();
}
}

public String getDescription() {
Expand Down Expand Up @@ -188,13 +210,30 @@ public String toJSONString() {
}

public JSONObject toJSONObj() {


SimpleDateFormat df = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");

JSONObject obj = new JSONObject();
obj.put("name", _taskName);
obj.put("status", _taskStatus);
obj.put("result", _taskResult);
obj.put("tag", _taskTag);


if (_submitTime.compareTo(new Date(0)) == 0)
obj.put("submitTime", " ");
else
obj.put("submitTime", df.format(_submitTime));

if (_startTime.compareTo(new Date(0)) == 0)
obj.put("startTime", " ");
else
obj.put("startTime", df.format(_startTime));

if (_stopTime.compareTo(new Date(0)) == 0)
obj.put("stopTime", " ");
else
obj.put("stopTime", df.format(_stopTime));

return obj;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,22 @@ import org.json.simple.JSONObject
import org.json.simple.parser.JSONParser
import org.quil.interpreter.Interpreter
import org.quil.server.ResultsCache
import org.quil.server.Tasks.Task.Status
import org.slf4j.LoggerFactory

/**
* Created by d90590 on 07.06.2016.
*/

object RunQLObjectsApplication {

}

class RunQLObjectsApplication(val taskName:String, val taskDescription:String) extends
org.quil.server.Tasks.Task(taskName,taskDescription) {

val logger = LoggerFactory.getLogger(classOf[RunQLObjectsApplication])

def run() = {

Task.updateStatus(_taskName, Status.RUNNING)

val parser: JSONParser = new JSONParser

val taskDescription: JSONObject = parser.parse(_taskDescription).asInstanceOf[JSONObject]
Expand Down
2 changes: 1 addition & 1 deletion server/src/main/java/org/quil/server/Tasks/TaskRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ private static void init() {
}
if (evt.name().compareTo("TASK_STARTED") == 0)
{
Task.updateStatus(evt.taskName(),Task.Status.RUNNING);
Task.updateStatus(evt.taskName(),Task.Status.PENDING);
}
if (evt.name().compareTo("TASK_FAILED") == 0)
{
Expand Down
4 changes: 4 additions & 0 deletions webapp/src/main/webapp/js/controllers.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ controllers.controller("MainController", ['$scope', '$interval', 'ClusterNodes',

for (var i=0; i < $scope.tasks.length; i++)
{
if ($scope.tasks[i].status == 0) {
$scope.runningTasks.push($scope.tasks[i]);
$scope.tasks[i].status_text = "Pending";
}
if ($scope.tasks[i].status == 1) {
$scope.runningTasks.push($scope.tasks[i]);
$scope.tasks[i].status_text = "Running";
Expand Down
67 changes: 33 additions & 34 deletions webapp/src/main/webapp/partials/task_management.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,7 @@ <h1 class="page-header">Task Management</h1>

<div class="col-lg-12">

<uib-tabset active="active" >
<!-- <uib-tab heading="Submit Task">
<div class="panel panel-default" style="border-top: none" >
<div class="panel-heading">
Running Tasks
</div>
<div class="panel-body" style="height:75vh">
<div class="row">
<div class="col-lg-4">
<div ui-view="task_forms">
</div>
</div>
</div>
</div>
</div>
</uib-tab> -->
<uib-tabset active="active">
<uib-tab heading="Running Tasks">
<div class="panel panel-default" style="border-top: none" style="height:70vh;overflow-y:scroll">
<!--<div class="panel-heading">
Expand All @@ -46,14 +30,17 @@ <h3>Running Tasks</h3><hr>
<table class="table table-striped table-bordered table-hover" id="dataTables-example2">
<thead>
<tr>
<th width="40%">ID</th>
<th width="40%">Tag</th>
<th width="20%">State</th>
<th width="30%">ID</th>
<th width="30%">Tag</th>
<th width="10%">State</th>
<th width="10%">Submitted</th>
<th width="10%">Started</th>
<th width="10%">Finished</th>
</tr>
</thead>
<tbody>
<tr class="odd gradeX">
<td colspan="3">No tasks are running.</td>
<td colspan="6">No tasks are running.</td>
</tr>
</tbody>
</table>
Expand All @@ -63,16 +50,22 @@ <h3>Running Tasks</h3><hr>
<table class="table table-striped table-bordered table-hover" id="dataTables-example">
<thead>
<tr>
<th width="40%">ID</th>
<th width="40%">Tag</th>
<th width="20%">State</th>
<th width="30%">ID</th>
<th width="30%">Tag</th>
<th width="10%">State</th>
<th width="10%">Submitted</th>
<th width="10%">Started</th>
<th width="10%">Finished</th>
</tr>
</thead>
<tbody>
<tr class="odd gradeX" ng-repeat="task in runningTasks">
<td width="40%">{{ task.name }}</td>
<td width="40%">{{ task.tag }}</td>
<td width="20%">{{ task.status_text }}</td>
<td width="30%">{{ task.name }}</td>
<td width="30%">{{ task.tag }}</td>
<td width="10%">{{ task.status_text }}</td>
<td width="10%">{{ task.submitTime }}</td>
<td width="10%">{{ task.startTime }}</td>
<td width="10%">{{ task.stopTime }}</td>
</tr>
</tbody>
</table>
Expand Down Expand Up @@ -103,18 +96,24 @@ <h3>Recently completed Tasks</h3><hr>
id="dataTables-example" >
<thead>
<tr>
<th width="30%">ID</th>
<th width="30%">Tag</th>
<th width="20%">State</th>
<th width="20%">ID</th>
<th width="20%">Tag</th>
<th width="10%">State</th>
<th width="10%">Submitted</th>
<th width="10%">Started</th>
<th width="10%">Finished</th>
<th width="20%">Inspect</th>
</tr>
</thead>
<tbody>
<tr class="odd gradeX" ng-repeat="task in finishedTasks">
<td width="30%">{{ task.name }}</td>
<td width="30%">{{ task.tag }}</td>
<td width="20%">{{ task.status_text }}</td>
<td width="20%"><!--<json-formatter json="task.result" open="0"></json-formatter>-->
<td width="20%">{{ task.name }}</td>
<td width="20%">{{ task.tag }}</td>
<td width="10%">{{ task.status_text }}</td>
<td width="10%">{{ task.submitTime }}</td>
<td width="10%">{{ task.startTime }}</td>
<td width="10%">{{ task.stopTime }}</td>
<td width="20%">
<button type="button" class="btn btn-default btn-sm" style="margin:0px"
ng-click="viewResult(task)">View</button>
<a href="/api/compute/tasks/{{task.name}}/result" download="{{task.name}}.json">
Expand Down

0 comments on commit 4298188

Please sign in to comment.