mirror of
https://github.com/fabioformosa/quartz-manager.git
synced 2026-01-10 19:43:16 +09:00
Added websocket to push job's logs to the manager panel
This commit is contained in:
@@ -69,6 +69,15 @@
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-websocket</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-messaging</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.webjars</groupId>
|
||||
<artifactId>bootstrap</artifactId>
|
||||
@@ -92,6 +101,29 @@
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-tx</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- Reactor -->
|
||||
<dependency>
|
||||
<groupId>io.projectreactor</groupId>
|
||||
<artifactId>reactor-core</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.projectreactor</groupId>
|
||||
<artifactId>reactor-net</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.projectreactor.spring</groupId>
|
||||
<artifactId>reactor-spring-context</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.netty</groupId>
|
||||
<artifactId>netty-all</artifactId>
|
||||
<version>4.0.31.Final</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-aop</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
package it.fabioformosa.quartzmanager.aspects;
|
||||
|
||||
import org.quartz.SchedulerException;
|
||||
|
||||
public interface ProgressUpdater {
|
||||
|
||||
void update() throws SchedulerException;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package it.fabioformosa.quartzmanager.aspects;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import org.quartz.Scheduler;
|
||||
import org.quartz.SchedulerException;
|
||||
import org.quartz.SimpleTrigger;
|
||||
import org.quartz.impl.triggers.SimpleTriggerImpl;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.messaging.simp.SimpMessageSendingOperations;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import it.fabioformosa.quartzmanager.dto.TriggerProgress;
|
||||
|
||||
//@Aspect
|
||||
@Component
|
||||
public class ProgressUpdaterImpl implements ProgressUpdater {
|
||||
|
||||
private static final Logger log = LoggerFactory
|
||||
.getLogger(ProgressUpdaterImpl.class);
|
||||
|
||||
@Autowired
|
||||
private SimpMessageSendingOperations messagingTemplate;
|
||||
|
||||
@Resource
|
||||
private Scheduler scheduler;
|
||||
|
||||
@Resource
|
||||
private SimpleTrigger jobTrigger = null;
|
||||
|
||||
//@AfterReturning("execution(* logAndSend(..))")
|
||||
// @Override
|
||||
// public void updateProgress(JoinPoint joinPoint) {
|
||||
// log.info("PROGRESS UPDATE!!!");
|
||||
// }
|
||||
|
||||
@Override
|
||||
public void update() throws SchedulerException {
|
||||
SimpleTriggerImpl jobTrigger = (SimpleTriggerImpl) scheduler
|
||||
.getTrigger(this.jobTrigger.getKey());
|
||||
|
||||
TriggerProgress progress = new TriggerProgress();
|
||||
if (jobTrigger != null && jobTrigger.getJobKey() != null) {
|
||||
progress.setJobKey(jobTrigger.getJobKey().getName());
|
||||
progress.setJobClass(jobTrigger.getClass().getSimpleName());
|
||||
progress.setTimesTriggered(jobTrigger.getTimesTriggered());
|
||||
progress.setRepeatCount(jobTrigger.getRepeatCount());
|
||||
progress.setFinalFireTime(jobTrigger.getFinalFireTime());
|
||||
progress.setNextFireTime(jobTrigger.getNextFireTime());
|
||||
progress.setPreviousFireTime(jobTrigger.getPreviousFireTime());
|
||||
}
|
||||
|
||||
messagingTemplate.convertAndSend("/topic/progress", progress);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,7 +1,5 @@
|
||||
package it.fabioformosa.quartzmanager.configuration;
|
||||
|
||||
import nz.net.ultraq.thymeleaf.LayoutDialect;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.ViewResolver;
|
||||
@@ -11,6 +9,8 @@ import org.thymeleaf.spring4.SpringTemplateEngine;
|
||||
import org.thymeleaf.spring4.templateresolver.SpringResourceTemplateResolver;
|
||||
import org.thymeleaf.spring4.view.ThymeleafViewResolver;
|
||||
|
||||
import nz.net.ultraq.thymeleaf.LayoutDialect;
|
||||
|
||||
@Configuration
|
||||
public class MVCConfig extends WebMvcConfigurerAdapter {
|
||||
|
||||
@@ -23,6 +23,8 @@ public class MVCConfig extends WebMvcConfigurerAdapter {
|
||||
.setViewName("manager/config-form");
|
||||
registry.addViewController("/templates/manager/progress-panel.html")
|
||||
.setViewName("manager/progress-panel");
|
||||
registry.addViewController("/templates/manager/logs-panel.html")
|
||||
.setViewName("manager/logs-panel");
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -16,20 +16,29 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
|
||||
|
||||
@Configuration
|
||||
@Order(1)
|
||||
public static class ApiWebSecurityConfig extends
|
||||
WebSecurityConfigurerAdapter {
|
||||
public static class ApiWebSecurityConfig
|
||||
extends WebSecurityConfigurerAdapter {
|
||||
@Override
|
||||
protected void configure(HttpSecurity http) throws Exception {
|
||||
http.csrf().disable().antMatcher("/notifications")
|
||||
.authorizeRequests().anyRequest().hasAnyRole("ADMIN").and()
|
||||
.httpBasic();
|
||||
http.csrf().disable() //
|
||||
.antMatcher("/notifications").authorizeRequests()
|
||||
.anyRequest().hasAnyRole("ADMIN").and().httpBasic();
|
||||
|
||||
// http.antMatcher("/logs/**").authorizeRequests().anyRequest()
|
||||
// .permitAll();
|
||||
}
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@Order(2)
|
||||
public static class FormWebSecurityConfig extends
|
||||
WebSecurityConfigurerAdapter {
|
||||
public static class FormWebSecurityConfig
|
||||
extends WebSecurityConfigurerAdapter {
|
||||
|
||||
@Override
|
||||
public void configure(WebSecurity web) throws Exception {
|
||||
web.ignoring().antMatchers("/css/**", "/js/**", "/img/**",
|
||||
"/lib/**");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configure(HttpSecurity http) throws Exception {
|
||||
@@ -39,12 +48,6 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
|
||||
.logoutRequestMatcher(new AntPathRequestMatcher("/logout"))
|
||||
.logoutSuccessUrl("/manager");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void configure(WebSecurity web) throws Exception {
|
||||
web.ignoring().antMatchers("/css/**", "/js/**", "/img/**",
|
||||
"/lib/**");
|
||||
}
|
||||
}
|
||||
|
||||
@Autowired
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
package it.fabioformosa.quartzmanager.configuration;
|
||||
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.messaging.simp.config.MessageBrokerRegistry;
|
||||
import org.springframework.web.socket.config.annotation.AbstractWebSocketMessageBrokerConfigurer;
|
||||
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker;
|
||||
import org.springframework.web.socket.config.annotation.StompEndpointRegistry;
|
||||
|
||||
@Configuration
|
||||
@EnableWebSocketMessageBroker
|
||||
public class WebsocketConfig extends AbstractWebSocketMessageBrokerConfigurer {
|
||||
|
||||
@Override
|
||||
public void configureMessageBroker(MessageBrokerRegistry config) {
|
||||
config.enableSimpleBroker("/topic");
|
||||
config.setApplicationDestinationPrefixes("/job");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerStompEndpoints(StompEndpointRegistry registry) {
|
||||
registry.addEndpoint("/logs").withSockJS();
|
||||
registry.addEndpoint("/progress").withSockJS();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -36,4 +36,11 @@ public class ManagerController {
|
||||
return mav;
|
||||
}
|
||||
|
||||
// @MessageMapping("/updates")
|
||||
// @SendTo("/topic/greetings")
|
||||
// public String greeting(String message) throws Exception {
|
||||
// Thread.sleep(3000); // simulated delay
|
||||
// return "Hello";
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
package it.fabioformosa.quartzmanager.controllers;
|
||||
|
||||
import org.springframework.messaging.handler.annotation.MessageMapping;
|
||||
import org.springframework.messaging.handler.annotation.SendTo;
|
||||
import org.springframework.stereotype.Controller;
|
||||
|
||||
@Controller
|
||||
public class WebsocketController {
|
||||
|
||||
@MessageMapping({ "/logs", "/progress" })
|
||||
@SendTo("/topic/logs")
|
||||
public String subscribe() throws Exception {
|
||||
return "subscribed";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package it.fabioformosa.quartzmanager.jobs;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import org.quartz.Job;
|
||||
import org.quartz.JobExecutionContext;
|
||||
import org.quartz.SchedulerException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.messaging.simp.SimpMessageSendingOperations;
|
||||
|
||||
import it.fabioformosa.quartzmanager.aspects.ProgressUpdater;
|
||||
|
||||
public abstract class AbstractLoggingJob implements Job {
|
||||
|
||||
private static final Logger log = LoggerFactory
|
||||
.getLogger(AbstractLoggingJob.class);
|
||||
|
||||
@Autowired
|
||||
private SimpMessageSendingOperations messagingTemplate;
|
||||
|
||||
@Resource
|
||||
private ProgressUpdater progressUpdater;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param jobExecutionContext
|
||||
* @return final log
|
||||
*/
|
||||
public abstract String doIt(JobExecutionContext jobExecutionContext);
|
||||
|
||||
@Override
|
||||
public final void execute(JobExecutionContext jobExecutionContext) {
|
||||
try {
|
||||
String logMsg = doIt(jobExecutionContext);
|
||||
logAndSend(logMsg);
|
||||
progressUpdater.update();
|
||||
} catch (SchedulerException e) {
|
||||
log.error("Error updating progress " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public void logAndSend(String logMsg) {
|
||||
log.info(logMsg);
|
||||
messagingTemplate.convertAndSend("/topic/logs", logMsg);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,16 +1,12 @@
|
||||
package it.fabioformosa.quartzmanager.jobs;
|
||||
|
||||
import org.quartz.Job;
|
||||
import org.quartz.JobExecutionContext;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class SampleJob implements Job {
|
||||
|
||||
private final Logger log = LoggerFactory.getLogger(SampleJob.class);
|
||||
public class SampleJob extends AbstractLoggingJob {
|
||||
|
||||
@Override
|
||||
public void execute(JobExecutionContext jobExecutionContext) {
|
||||
log.info("Hello!");
|
||||
public String doIt(JobExecutionContext jobExecutionContext) {
|
||||
return "Hello!";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
3340
quartz-manager/src/main/resources/static/css/animate.css
vendored
Normal file
3340
quartz-manager/src/main/resources/static/css/animate.css
vendored
Normal file
File diff suppressed because it is too large
Load Diff
@@ -28,4 +28,9 @@
|
||||
|
||||
.large-btn{
|
||||
width: 200px;
|
||||
}
|
||||
|
||||
.firstLog{
|
||||
-webkit-animation-duration: .25s;
|
||||
-moz-animation-duration: .25s;
|
||||
}
|
||||
@@ -1 +1 @@
|
||||
var schedulerApp = angular.module('schedulerApp', ['starter', 'configurator', 'progress']);
|
||||
var schedulerApp = angular.module('schedulerApp', ['starter', 'configurator', 'ff-websocket', 'progress']);
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
angular.module('progress')
|
||||
.directive('logsPanel', ['LogService', function(LogService){
|
||||
|
||||
var appendLog = function(log){
|
||||
var logTable = document.getElementById('logTable');
|
||||
var row = document.createElement('tr');
|
||||
row.style.wordWrap = 'break-word';
|
||||
row.appendChild(document.createTextNode(log));
|
||||
logTable.appendChild(row);
|
||||
}
|
||||
|
||||
var MAX_LOGS = 10;
|
||||
|
||||
return{
|
||||
restrict: 'E',
|
||||
controller : ['$scope', function($scope){
|
||||
|
||||
$scope.logs = new Array();
|
||||
|
||||
LogService.receive().then(null, null, function(logMsg){
|
||||
if($scope.logs.length > MAX_LOGS)
|
||||
$scope.logs.pop();
|
||||
|
||||
var logItem = {};
|
||||
logItem.time = new Date();
|
||||
logItem.msg = logMsg;
|
||||
|
||||
$scope.logs.unshift(logItem);
|
||||
})
|
||||
}],
|
||||
templateUrl : 'templates/manager/logs-panel.html'
|
||||
};
|
||||
}]);
|
||||
@@ -0,0 +1,10 @@
|
||||
angular.module('progress')
|
||||
.service('LogService',['WebsocketServiceFactory', function(WebsocketServiceFactory){
|
||||
|
||||
var logServiceParams = {
|
||||
SOCKET_URL : '/quartz-manager/logs',
|
||||
TOPIC_NAME : '/topic/logs'
|
||||
};
|
||||
|
||||
return WebsocketServiceFactory.create(logServiceParams);
|
||||
}]);
|
||||
@@ -0,0 +1,16 @@
|
||||
angular.module('progress')
|
||||
.directive('progressPanel',['ProgressService', function(ProgressService){
|
||||
|
||||
return{
|
||||
restrict: 'E',
|
||||
controller : ['$scope', function($scope){
|
||||
|
||||
ProgressService.receive().then(null, null, function(newStatus){
|
||||
$scope.progress = newStatus;
|
||||
$scope.percentageStr = $scope.progress.percentage + '%';
|
||||
});
|
||||
|
||||
}],
|
||||
templateUrl : 'templates/manager/progress-panel.html'
|
||||
};
|
||||
}]);
|
||||
@@ -1,14 +0,0 @@
|
||||
angular.module('progress')
|
||||
.directive('progressPanel', function(){
|
||||
|
||||
return{
|
||||
restrict: 'E',
|
||||
controller : ['$scope', '$http', function($scope, $http){
|
||||
$http.get('scheduler/progress').then(function(res){
|
||||
$scope.progress = res.data;
|
||||
$scope.percentageStr = $scope.progress.percentage + '%';
|
||||
});
|
||||
}],
|
||||
templateUrl : 'templates/manager/progress-panel.html'
|
||||
};
|
||||
});
|
||||
@@ -0,0 +1,10 @@
|
||||
angular.module('progress')
|
||||
.service('ProgressService',['WebsocketServiceFactory', function(WebsocketServiceFactory){
|
||||
|
||||
var progressServiceParams = {
|
||||
SOCKET_URL : '/quartz-manager/progress',
|
||||
TOPIC_NAME : '/topic/progress'
|
||||
};
|
||||
|
||||
return WebsocketServiceFactory.create(progressServiceParams);
|
||||
}]);
|
||||
@@ -0,0 +1,82 @@
|
||||
angular.module('ff-websocket')
|
||||
.factory('WebsocketServiceFactory',['$q', '$timeout', function($q, $timeout){
|
||||
|
||||
return{
|
||||
create : function(options){
|
||||
return new BaseSocketService(options)
|
||||
}
|
||||
};
|
||||
|
||||
function BaseSocketService(options){
|
||||
|
||||
var that = this;
|
||||
|
||||
var defaultOpt = {
|
||||
SOCKET_URL : '',
|
||||
TOPIC_NAME : '',
|
||||
BROKER_NAME : '',
|
||||
RECONNECT_TIMEOUT : 30000
|
||||
};
|
||||
that.options = angular.extend(defaultOpt, options);
|
||||
|
||||
|
||||
var _deferred = $q.defer();
|
||||
var _messageIds = [];
|
||||
var _socket = {
|
||||
client: null,
|
||||
stomp: null
|
||||
};
|
||||
|
||||
var getMessage = function(data) {
|
||||
var out = {};
|
||||
out.message = JSON.parse(data.body);
|
||||
out.headers = {};
|
||||
out.headers.messageId = data.headers["message-id"];
|
||||
|
||||
if ($.contains(_messageIds, out.headers.messageId)) {
|
||||
out.self = true;
|
||||
_messageIds = _.remove(_messageIds, out.headers.messageId);
|
||||
}
|
||||
return out;
|
||||
};
|
||||
|
||||
that.reconnect = function() {
|
||||
$timeout(function() {
|
||||
initialize();
|
||||
}, that.options.RECONNECT_TIMEOUT);
|
||||
};
|
||||
|
||||
var _startListener = function(frame){
|
||||
console.log('Connected: ' + frame);
|
||||
_socket.stomp.subscribe(that.options.TOPIC_NAME, function(data){
|
||||
_deferred.notify(getMessage(data).message);
|
||||
});
|
||||
};
|
||||
|
||||
var _initialize = function(){
|
||||
_socket.client = new SockJS(that.options.SOCKET_URL);
|
||||
_socket.stomp = Stomp.over(_socket.client);
|
||||
_socket.stomp.connect({}, _startListener);
|
||||
_socket.stomp.onclose = that.reconnect;
|
||||
};
|
||||
|
||||
that.receive = function(){
|
||||
return _deferred.promise;
|
||||
};
|
||||
|
||||
that.send = function(message) {
|
||||
var id = Math.floor(Math.random() * 1000000);
|
||||
_socket.stomp.send(that.options.BROKER_NAME, {
|
||||
priority: 9
|
||||
}, JSON.stringify({
|
||||
message: message,
|
||||
id: id
|
||||
}));
|
||||
_messageIds.push(id);
|
||||
};
|
||||
|
||||
_initialize();
|
||||
}
|
||||
|
||||
|
||||
}]);
|
||||
@@ -0,0 +1 @@
|
||||
var socketModule = angular.module('ff-websocket', []);
|
||||
2378
quartz-manager/src/main/resources/static/js/lib/sockjs-0.3.4.js
Normal file
2378
quartz-manager/src/main/resources/static/js/lib/sockjs-0.3.4.js
Normal file
File diff suppressed because it is too large
Load Diff
27
quartz-manager/src/main/resources/static/js/lib/sockjs-0.3.4.min.js
vendored
Normal file
27
quartz-manager/src/main/resources/static/js/lib/sockjs-0.3.4.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
475
quartz-manager/src/main/resources/static/js/lib/stomp.js
Normal file
475
quartz-manager/src/main/resources/static/js/lib/stomp.js
Normal file
@@ -0,0 +1,475 @@
|
||||
// Generated by CoffeeScript 1.7.1
|
||||
|
||||
/*
|
||||
Stomp Over WebSocket http://www.jmesnil.net/stomp-websocket/doc/ | Apache License V2.0
|
||||
|
||||
Copyright (C) 2010-2013 [Jeff Mesnil](http://jmesnil.net/)
|
||||
Copyright (C) 2012 [FuseSource, Inc.](http://fusesource.com)
|
||||
*/
|
||||
|
||||
(function() {
|
||||
var Byte, Client, Frame, Stomp,
|
||||
__hasProp = {}.hasOwnProperty,
|
||||
__slice = [].slice;
|
||||
|
||||
Byte = {
|
||||
LF: '\x0A',
|
||||
NULL: '\x00'
|
||||
};
|
||||
|
||||
Frame = (function() {
|
||||
var unmarshallSingle;
|
||||
|
||||
function Frame(command, headers, body) {
|
||||
this.command = command;
|
||||
this.headers = headers != null ? headers : {};
|
||||
this.body = body != null ? body : '';
|
||||
}
|
||||
|
||||
Frame.prototype.toString = function() {
|
||||
var lines, name, value, _ref;
|
||||
lines = [this.command];
|
||||
_ref = this.headers;
|
||||
for (name in _ref) {
|
||||
if (!__hasProp.call(_ref, name)) continue;
|
||||
value = _ref[name];
|
||||
lines.push("" + name + ":" + value);
|
||||
}
|
||||
if (this.body) {
|
||||
lines.push("content-length:" + (Frame.sizeOfUTF8(this.body)));
|
||||
}
|
||||
lines.push(Byte.LF + this.body);
|
||||
return lines.join(Byte.LF);
|
||||
};
|
||||
|
||||
Frame.sizeOfUTF8 = function(s) {
|
||||
if (s) {
|
||||
return encodeURI(s).split(/%..|./).length - 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
unmarshallSingle = function(data) {
|
||||
var body, chr, command, divider, headerLines, headers, i, idx, len, line, start, trim, _i, _j, _len, _ref, _ref1;
|
||||
divider = data.search(RegExp("" + Byte.LF + Byte.LF));
|
||||
headerLines = data.substring(0, divider).split(Byte.LF);
|
||||
command = headerLines.shift();
|
||||
headers = {};
|
||||
trim = function(str) {
|
||||
return str.replace(/^\s+|\s+$/g, '');
|
||||
};
|
||||
_ref = headerLines.reverse();
|
||||
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
||||
line = _ref[_i];
|
||||
idx = line.indexOf(':');
|
||||
headers[trim(line.substring(0, idx))] = trim(line.substring(idx + 1));
|
||||
}
|
||||
body = '';
|
||||
start = divider + 2;
|
||||
if (headers['content-length']) {
|
||||
len = parseInt(headers['content-length']);
|
||||
body = ('' + data).substring(start, start + len);
|
||||
} else {
|
||||
chr = null;
|
||||
for (i = _j = start, _ref1 = data.length; start <= _ref1 ? _j < _ref1 : _j > _ref1; i = start <= _ref1 ? ++_j : --_j) {
|
||||
chr = data.charAt(i);
|
||||
if (chr === Byte.NULL) {
|
||||
break;
|
||||
}
|
||||
body += chr;
|
||||
}
|
||||
}
|
||||
return new Frame(command, headers, body);
|
||||
};
|
||||
|
||||
Frame.unmarshall = function(datas) {
|
||||
var data;
|
||||
return (function() {
|
||||
var _i, _len, _ref, _results;
|
||||
_ref = datas.split(RegExp("" + Byte.NULL + Byte.LF + "*"));
|
||||
_results = [];
|
||||
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
||||
data = _ref[_i];
|
||||
if ((data != null ? data.length : void 0) > 0) {
|
||||
_results.push(unmarshallSingle(data));
|
||||
}
|
||||
}
|
||||
return _results;
|
||||
})();
|
||||
};
|
||||
|
||||
Frame.marshall = function(command, headers, body) {
|
||||
var frame;
|
||||
frame = new Frame(command, headers, body);
|
||||
return frame.toString() + Byte.NULL;
|
||||
};
|
||||
|
||||
return Frame;
|
||||
|
||||
})();
|
||||
|
||||
Client = (function() {
|
||||
var now;
|
||||
|
||||
function Client(ws) {
|
||||
this.ws = ws;
|
||||
this.ws.binaryType = "arraybuffer";
|
||||
this.counter = 0;
|
||||
this.connected = false;
|
||||
this.heartbeat = {
|
||||
outgoing: 10000,
|
||||
incoming: 10000
|
||||
};
|
||||
this.maxWebSocketFrameSize = 16 * 1024;
|
||||
this.subscriptions = {};
|
||||
}
|
||||
|
||||
Client.prototype.debug = function(message) {
|
||||
var _ref;
|
||||
return typeof window !== "undefined" && window !== null ? (_ref = window.console) != null ? _ref.log(message) : void 0 : void 0;
|
||||
};
|
||||
|
||||
now = function() {
|
||||
return Date.now || new Date().valueOf;
|
||||
};
|
||||
|
||||
Client.prototype._transmit = function(command, headers, body) {
|
||||
var out;
|
||||
out = Frame.marshall(command, headers, body);
|
||||
if (typeof this.debug === "function") {
|
||||
this.debug(">>> " + out);
|
||||
}
|
||||
while (true) {
|
||||
if (out.length > this.maxWebSocketFrameSize) {
|
||||
this.ws.send(out.substring(0, this.maxWebSocketFrameSize));
|
||||
out = out.substring(this.maxWebSocketFrameSize);
|
||||
if (typeof this.debug === "function") {
|
||||
this.debug("remaining = " + out.length);
|
||||
}
|
||||
} else {
|
||||
return this.ws.send(out);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Client.prototype._setupHeartbeat = function(headers) {
|
||||
var serverIncoming, serverOutgoing, ttl, v, _ref, _ref1;
|
||||
if ((_ref = headers.version) !== Stomp.VERSIONS.V1_1 && _ref !== Stomp.VERSIONS.V1_2) {
|
||||
return;
|
||||
}
|
||||
_ref1 = (function() {
|
||||
var _i, _len, _ref1, _results;
|
||||
_ref1 = headers['heart-beat'].split(",");
|
||||
_results = [];
|
||||
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
|
||||
v = _ref1[_i];
|
||||
_results.push(parseInt(v));
|
||||
}
|
||||
return _results;
|
||||
})(), serverOutgoing = _ref1[0], serverIncoming = _ref1[1];
|
||||
if (!(this.heartbeat.outgoing === 0 || serverIncoming === 0)) {
|
||||
ttl = Math.max(this.heartbeat.outgoing, serverIncoming);
|
||||
if (typeof this.debug === "function") {
|
||||
this.debug("send PING every " + ttl + "ms");
|
||||
}
|
||||
this.pinger = Stomp.setInterval(ttl, (function(_this) {
|
||||
return function() {
|
||||
_this.ws.send(Byte.LF);
|
||||
return typeof _this.debug === "function" ? _this.debug(">>> PING") : void 0;
|
||||
};
|
||||
})(this));
|
||||
}
|
||||
if (!(this.heartbeat.incoming === 0 || serverOutgoing === 0)) {
|
||||
ttl = Math.max(this.heartbeat.incoming, serverOutgoing);
|
||||
if (typeof this.debug === "function") {
|
||||
this.debug("check PONG every " + ttl + "ms");
|
||||
}
|
||||
return this.ponger = Stomp.setInterval(ttl, (function(_this) {
|
||||
return function() {
|
||||
var delta;
|
||||
delta = now() - _this.serverActivity;
|
||||
if (delta > ttl * 2) {
|
||||
if (typeof _this.debug === "function") {
|
||||
_this.debug("did not receive server activity for the last " + delta + "ms");
|
||||
}
|
||||
return _this.ws.close();
|
||||
}
|
||||
};
|
||||
})(this));
|
||||
}
|
||||
};
|
||||
|
||||
Client.prototype._parseConnect = function() {
|
||||
var args, connectCallback, errorCallback, headers;
|
||||
args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
|
||||
headers = {};
|
||||
switch (args.length) {
|
||||
case 2:
|
||||
headers = args[0], connectCallback = args[1];
|
||||
break;
|
||||
case 3:
|
||||
if (args[1] instanceof Function) {
|
||||
headers = args[0], connectCallback = args[1], errorCallback = args[2];
|
||||
} else {
|
||||
headers.login = args[0], headers.passcode = args[1], connectCallback = args[2];
|
||||
}
|
||||
break;
|
||||
case 4:
|
||||
headers.login = args[0], headers.passcode = args[1], connectCallback = args[2], errorCallback = args[3];
|
||||
break;
|
||||
default:
|
||||
headers.login = args[0], headers.passcode = args[1], connectCallback = args[2], errorCallback = args[3], headers.host = args[4];
|
||||
}
|
||||
return [headers, connectCallback, errorCallback];
|
||||
};
|
||||
|
||||
Client.prototype.connect = function() {
|
||||
var args, errorCallback, headers, out;
|
||||
args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
|
||||
out = this._parseConnect.apply(this, args);
|
||||
headers = out[0], this.connectCallback = out[1], errorCallback = out[2];
|
||||
if (typeof this.debug === "function") {
|
||||
this.debug("Opening Web Socket...");
|
||||
}
|
||||
this.ws.onmessage = (function(_this) {
|
||||
return function(evt) {
|
||||
var arr, c, client, data, frame, messageID, onreceive, subscription, _i, _len, _ref, _results;
|
||||
data = typeof ArrayBuffer !== 'undefined' && evt.data instanceof ArrayBuffer ? (arr = new Uint8Array(evt.data), typeof _this.debug === "function" ? _this.debug("--- got data length: " + arr.length) : void 0, ((function() {
|
||||
var _i, _len, _results;
|
||||
_results = [];
|
||||
for (_i = 0, _len = arr.length; _i < _len; _i++) {
|
||||
c = arr[_i];
|
||||
_results.push(String.fromCharCode(c));
|
||||
}
|
||||
return _results;
|
||||
})()).join('')) : evt.data;
|
||||
_this.serverActivity = now();
|
||||
if (data === Byte.LF) {
|
||||
if (typeof _this.debug === "function") {
|
||||
_this.debug("<<< PONG");
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (typeof _this.debug === "function") {
|
||||
_this.debug("<<< " + data);
|
||||
}
|
||||
_ref = Frame.unmarshall(data);
|
||||
_results = [];
|
||||
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
||||
frame = _ref[_i];
|
||||
switch (frame.command) {
|
||||
case "CONNECTED":
|
||||
if (typeof _this.debug === "function") {
|
||||
_this.debug("connected to server " + frame.headers.server);
|
||||
}
|
||||
_this.connected = true;
|
||||
_this._setupHeartbeat(frame.headers);
|
||||
_results.push(typeof _this.connectCallback === "function" ? _this.connectCallback(frame) : void 0);
|
||||
break;
|
||||
case "MESSAGE":
|
||||
subscription = frame.headers.subscription;
|
||||
onreceive = _this.subscriptions[subscription] || _this.onreceive;
|
||||
if (onreceive) {
|
||||
client = _this;
|
||||
messageID = frame.headers["message-id"];
|
||||
frame.ack = function(headers) {
|
||||
if (headers == null) {
|
||||
headers = {};
|
||||
}
|
||||
return client.ack(messageID, subscription, headers);
|
||||
};
|
||||
frame.nack = function(headers) {
|
||||
if (headers == null) {
|
||||
headers = {};
|
||||
}
|
||||
return client.nack(messageID, subscription, headers);
|
||||
};
|
||||
_results.push(onreceive(frame));
|
||||
} else {
|
||||
_results.push(typeof _this.debug === "function" ? _this.debug("Unhandled received MESSAGE: " + frame) : void 0);
|
||||
}
|
||||
break;
|
||||
case "RECEIPT":
|
||||
_results.push(typeof _this.onreceipt === "function" ? _this.onreceipt(frame) : void 0);
|
||||
break;
|
||||
case "ERROR":
|
||||
_results.push(typeof errorCallback === "function" ? errorCallback(frame) : void 0);
|
||||
break;
|
||||
default:
|
||||
_results.push(typeof _this.debug === "function" ? _this.debug("Unhandled frame: " + frame) : void 0);
|
||||
}
|
||||
}
|
||||
return _results;
|
||||
};
|
||||
})(this);
|
||||
this.ws.onclose = (function(_this) {
|
||||
return function() {
|
||||
var msg;
|
||||
msg = "Whoops! Lost connection to " + _this.ws.url;
|
||||
if (typeof _this.debug === "function") {
|
||||
_this.debug(msg);
|
||||
}
|
||||
_this._cleanUp();
|
||||
return typeof errorCallback === "function" ? errorCallback(msg) : void 0;
|
||||
};
|
||||
})(this);
|
||||
return this.ws.onopen = (function(_this) {
|
||||
return function() {
|
||||
if (typeof _this.debug === "function") {
|
||||
_this.debug('Web Socket Opened...');
|
||||
}
|
||||
headers["accept-version"] = Stomp.VERSIONS.supportedVersions();
|
||||
headers["heart-beat"] = [_this.heartbeat.outgoing, _this.heartbeat.incoming].join(',');
|
||||
return _this._transmit("CONNECT", headers);
|
||||
};
|
||||
})(this);
|
||||
};
|
||||
|
||||
Client.prototype.disconnect = function(disconnectCallback) {
|
||||
this._transmit("DISCONNECT");
|
||||
this.ws.onclose = null;
|
||||
this.ws.close();
|
||||
this._cleanUp();
|
||||
return typeof disconnectCallback === "function" ? disconnectCallback() : void 0;
|
||||
};
|
||||
|
||||
Client.prototype._cleanUp = function() {
|
||||
this.connected = false;
|
||||
if (this.pinger) {
|
||||
Stomp.clearInterval(this.pinger);
|
||||
}
|
||||
if (this.ponger) {
|
||||
return Stomp.clearInterval(this.ponger);
|
||||
}
|
||||
};
|
||||
|
||||
Client.prototype.send = function(destination, headers, body) {
|
||||
if (headers == null) {
|
||||
headers = {};
|
||||
}
|
||||
if (body == null) {
|
||||
body = '';
|
||||
}
|
||||
headers.destination = destination;
|
||||
return this._transmit("SEND", headers, body);
|
||||
};
|
||||
|
||||
Client.prototype.subscribe = function(destination, callback, headers) {
|
||||
var client;
|
||||
if (headers == null) {
|
||||
headers = {};
|
||||
}
|
||||
if (!headers.id) {
|
||||
headers.id = "sub-" + this.counter++;
|
||||
}
|
||||
headers.destination = destination;
|
||||
this.subscriptions[headers.id] = callback;
|
||||
this._transmit("SUBSCRIBE", headers);
|
||||
client = this;
|
||||
return {
|
||||
id: headers.id,
|
||||
unsubscribe: function() {
|
||||
return client.unsubscribe(headers.id);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
Client.prototype.unsubscribe = function(id) {
|
||||
delete this.subscriptions[id];
|
||||
return this._transmit("UNSUBSCRIBE", {
|
||||
id: id
|
||||
});
|
||||
};
|
||||
|
||||
Client.prototype.begin = function(transaction) {
|
||||
var client, txid;
|
||||
txid = transaction || "tx-" + this.counter++;
|
||||
this._transmit("BEGIN", {
|
||||
transaction: txid
|
||||
});
|
||||
client = this;
|
||||
return {
|
||||
id: txid,
|
||||
commit: function() {
|
||||
return client.commit(txid);
|
||||
},
|
||||
abort: function() {
|
||||
return client.abort(txid);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
Client.prototype.commit = function(transaction) {
|
||||
return this._transmit("COMMIT", {
|
||||
transaction: transaction
|
||||
});
|
||||
};
|
||||
|
||||
Client.prototype.abort = function(transaction) {
|
||||
return this._transmit("ABORT", {
|
||||
transaction: transaction
|
||||
});
|
||||
};
|
||||
|
||||
Client.prototype.ack = function(messageID, subscription, headers) {
|
||||
if (headers == null) {
|
||||
headers = {};
|
||||
}
|
||||
headers["message-id"] = messageID;
|
||||
headers.subscription = subscription;
|
||||
return this._transmit("ACK", headers);
|
||||
};
|
||||
|
||||
Client.prototype.nack = function(messageID, subscription, headers) {
|
||||
if (headers == null) {
|
||||
headers = {};
|
||||
}
|
||||
headers["message-id"] = messageID;
|
||||
headers.subscription = subscription;
|
||||
return this._transmit("NACK", headers);
|
||||
};
|
||||
|
||||
return Client;
|
||||
|
||||
})();
|
||||
|
||||
Stomp = {
|
||||
VERSIONS: {
|
||||
V1_0: '1.0',
|
||||
V1_1: '1.1',
|
||||
V1_2: '1.2',
|
||||
supportedVersions: function() {
|
||||
return '1.1,1.0';
|
||||
}
|
||||
},
|
||||
client: function(url, protocols) {
|
||||
var klass, ws;
|
||||
if (protocols == null) {
|
||||
protocols = ['v10.stomp', 'v11.stomp'];
|
||||
}
|
||||
klass = Stomp.WebSocketClass || WebSocket;
|
||||
ws = new klass(url, protocols);
|
||||
return new Client(ws);
|
||||
},
|
||||
over: function(ws) {
|
||||
return new Client(ws);
|
||||
},
|
||||
Frame: Frame
|
||||
};
|
||||
|
||||
if (typeof window !== "undefined" && window !== null) {
|
||||
Stomp.setInterval = function(interval, f) {
|
||||
return window.setInterval(f, interval);
|
||||
};
|
||||
Stomp.clearInterval = function(id) {
|
||||
return window.clearInterval(id);
|
||||
};
|
||||
window.Stomp = Stomp;
|
||||
} else if (typeof exports !== "undefined" && exports !== null) {
|
||||
exports.Stomp = Stomp;
|
||||
} else {
|
||||
self.Stomp = Stomp;
|
||||
}
|
||||
|
||||
}).call(this);
|
||||
@@ -7,6 +7,7 @@
|
||||
<link href="http://cdn.jsdelivr.net/webjars/bootstrap/3.3.4/css/bootstrap.min.css"
|
||||
rel="stylesheet" media="screen" />
|
||||
|
||||
<link th:href="@{css/animate.css}" rel="stylesheet" />
|
||||
<link th:href="@{css/dashboard-bootstrap.css}" rel="stylesheet" media="screen" />
|
||||
<link th:href="@{css/scheduler.css}" rel="stylesheet" media="screen" />
|
||||
|
||||
@@ -15,13 +16,23 @@
|
||||
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css"/>
|
||||
|
||||
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.5.0/angular.min.js"></script>
|
||||
|
||||
<script th:src="@{/js/lib/sockjs-0.3.4.js}"></script>
|
||||
<script th:src="@{/js/lib/stomp.js}"></script>
|
||||
|
||||
<script th:src="@{/js/app/components/starter/starter-module.js}"></script>
|
||||
<script th:src="@{/js/app/components/starter/starter-directives.js}"></script>
|
||||
<script th:src="@{/js/app/components/configurator/configurator-module.js}"></script>
|
||||
<script th:src="@{/js/app/components/configurator/configurator-directives.js}"></script>
|
||||
|
||||
<script th:src="@{/js/app/components/websocket/websocket-module.js}"></script>
|
||||
<script th:src="@{/js/app/components/websocket/websocket-factory.js}"></script>
|
||||
|
||||
<script th:src="@{/js/app/components/progress/progress-module.js}"></script>
|
||||
<script th:src="@{/js/app/components/progress/progress-directives.js}"></script>
|
||||
<script th:src="@{/js/app/components/progress/progress-service.js}"></script>
|
||||
<script th:src="@{/js/app/components/progress/progress-directive.js}"></script>
|
||||
<script th:src="@{/js/app/components/progress/logs-service.js}"></script>
|
||||
<script th:src="@{/js/app/components/progress/logs-directive.js}"></script>
|
||||
<script th:src="@{/js/app/app.js}"></script>
|
||||
|
||||
</head>
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
<div id="logs">
|
||||
|
||||
<table id="logTable">
|
||||
<tr data-ng-repeat="log in logs">
|
||||
<td data-ng-class="{'animated zoomIn firstLog': $first}">[{{log.time|date:'medium'}}]</td>
|
||||
<td> </td>
|
||||
<td data-ng-class="{'animated zoomIn firstLog' : $first}">{{log.msg}}</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -9,23 +9,28 @@
|
||||
</div>
|
||||
|
||||
<span class="label label-info">counter</span>
|
||||
{{progress.timesTriggered}} <span ng-show="progress.repeatCount > 0">/ {{progress.repeatCount}} </span>
|
||||
|
||||
<span class="animated pulse">{{progress.timesTriggered}}</span> <span ng-show="progress.repeatCount > 0">/ {{progress.repeatCount}} </span>
|
||||
|
||||
<br/><br/>
|
||||
|
||||
<span class="label label-info">job key</span> {{progress.jobKey}}
|
||||
<span class="label label-info">job key</span> <span class="animated pulse">{{progress.jobKey}}</span>
|
||||
<br/>
|
||||
<span class="label label-info">job class</span> {{progress.jobClass}}
|
||||
<span class="label label-info">job class</span> <span class="animated pulse">{{progress.jobClass}}</span>
|
||||
<br/>
|
||||
|
||||
<br/><br/>
|
||||
|
||||
<span class="label label-info">prev fire time</span> {{progress.previousFireTime|date:'dd-MM-yyyy HH:mm:ss'}}
|
||||
<span class="label label-info">prev fire time</span> <span class="animated pulse">{{progress.previousFireTime|date:'dd-MM-yyyy HH:mm:ss'}}</span>
|
||||
<br/>
|
||||
<span class="label label-info">next fire time</span> {{progress.nextFireTime|date:'dd-MM-yyyy HH:mm:ss'}}
|
||||
<span class="label label-info">next fire time</span> <span class="animated pulse">{{progress.nextFireTime|date:'dd-MM-yyyy HH:mm:ss'}}</span>
|
||||
<br/>
|
||||
<span class="label label-info">final fire time</span> {{progress.finalFireTime|date:'dd-MM-yyyy HH:mm:ss'}}
|
||||
<span class="label label-info">final fire time</span> <span class="animated pulse">{{progress.finalFireTime|date:'dd-MM-yyyy HH:mm:ss'}}</span>
|
||||
<br/>
|
||||
|
||||
<div id="lista">
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -42,6 +42,15 @@
|
||||
<progress-panel></progress-panel>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="panel panel-default widget-panel">
|
||||
<div class="panel-heading">
|
||||
<h3 class="panel-title">Job Logs</h3>
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<logs-panel></logs-panel>
|
||||
</div>
|
||||
</div>
|
||||
</div> <!-- /right-panel -->
|
||||
|
||||
</div><!-- row fragment-->
|
||||
|
||||
Reference in New Issue
Block a user