2017-12-15 21:39:18 +00:00
|
|
|
import { inject as service } from '@ember/service';
|
|
|
|
import Component from '@ember/component';
|
|
|
|
import { computed } from '@ember/object';
|
2018-02-26 20:23:01 +00:00
|
|
|
import RSVP from 'rsvp';
|
2017-11-15 20:45:11 +00:00
|
|
|
import { logger } from 'nomad-ui/utils/classes/log';
|
|
|
|
import WindowResizable from 'nomad-ui/mixins/window-resizable';
|
2018-02-26 20:23:01 +00:00
|
|
|
import timeout from 'nomad-ui/utils/timeout';
|
2017-11-15 17:13:17 +00:00
|
|
|
|
2017-11-15 20:45:11 +00:00
|
|
|
export default Component.extend(WindowResizable, {
|
2017-12-15 21:39:18 +00:00
|
|
|
token: service(),
|
2017-11-15 17:13:17 +00:00
|
|
|
|
2017-11-16 02:13:28 +00:00
|
|
|
classNames: ['boxed-section', 'task-log'],
|
2017-11-15 17:13:17 +00:00
|
|
|
|
|
|
|
allocation: null,
|
|
|
|
task: null,
|
|
|
|
|
2018-02-27 21:38:31 +00:00
|
|
|
// When true, request logs from the server agent
|
2018-02-26 20:23:01 +00:00
|
|
|
useServer: false,
|
|
|
|
|
2018-02-27 21:38:31 +00:00
|
|
|
// When true, logs cannot be fetched from either the client or the server
|
|
|
|
noConnection: false,
|
|
|
|
|
|
|
|
clientTimeout: 1000,
|
|
|
|
serverTimeout: 5000,
|
|
|
|
|
2019-06-27 19:10:34 +00:00
|
|
|
isStreaming: true,
|
|
|
|
streamMode: 'streaming',
|
2017-11-15 20:45:11 +00:00
|
|
|
|
2017-11-15 17:13:17 +00:00
|
|
|
mode: 'stdout',
|
|
|
|
|
2018-02-26 20:23:01 +00:00
|
|
|
logUrl: computed('allocation.id', 'allocation.node.httpAddr', 'useServer', function() {
|
2017-11-15 17:13:17 +00:00
|
|
|
const address = this.get('allocation.node.httpAddr');
|
|
|
|
const allocation = this.get('allocation.id');
|
|
|
|
|
2018-02-26 20:23:01 +00:00
|
|
|
const url = `/v1/client/fs/logs/${allocation}`;
|
2019-03-26 07:46:44 +00:00
|
|
|
return this.useServer ? url : `//${address}${url}`;
|
2017-11-15 17:13:17 +00:00
|
|
|
}),
|
|
|
|
|
|
|
|
logParams: computed('task', 'mode', function() {
|
|
|
|
return {
|
2019-03-26 07:46:44 +00:00
|
|
|
task: this.task,
|
|
|
|
type: this.mode,
|
2017-11-15 17:13:17 +00:00
|
|
|
};
|
|
|
|
}),
|
|
|
|
|
2018-02-26 20:23:01 +00:00
|
|
|
logger: logger('logUrl', 'logParams', function logFetch() {
|
|
|
|
// If the log request can't settle in one second, the client
|
|
|
|
// must be unavailable and the server should be used instead
|
2019-03-26 07:46:44 +00:00
|
|
|
const timing = this.useServer ? this.serverTimeout : this.clientTimeout;
|
2018-02-26 20:23:01 +00:00
|
|
|
return url =>
|
2019-03-26 07:46:44 +00:00
|
|
|
RSVP.race([this.token.authorizedRequest(url), timeout(timing)]).then(
|
2018-02-26 20:23:01 +00:00
|
|
|
response => response,
|
|
|
|
error => {
|
2019-03-26 07:46:44 +00:00
|
|
|
if (this.useServer) {
|
2018-02-27 21:38:31 +00:00
|
|
|
this.set('noConnection', true);
|
|
|
|
} else {
|
|
|
|
this.send('failoverToServer');
|
|
|
|
}
|
2018-02-26 20:23:01 +00:00
|
|
|
throw error;
|
|
|
|
}
|
|
|
|
);
|
2017-11-15 17:13:17 +00:00
|
|
|
}),
|
|
|
|
|
|
|
|
actions: {
|
|
|
|
setMode(mode) {
|
2019-03-26 07:46:44 +00:00
|
|
|
this.logger.stop();
|
2017-11-15 20:45:11 +00:00
|
|
|
this.set('mode', mode);
|
2017-11-15 17:13:17 +00:00
|
|
|
},
|
|
|
|
toggleStream() {
|
2019-06-27 19:10:34 +00:00
|
|
|
this.set('streamMode', 'streaming');
|
|
|
|
this.toggleProperty('isStreaming');
|
|
|
|
},
|
|
|
|
gotoHead() {
|
|
|
|
this.set('streamMode', 'head');
|
|
|
|
this.set('isStreaming', false);
|
|
|
|
},
|
|
|
|
gotoTail() {
|
|
|
|
this.set('streamMode', 'tail');
|
|
|
|
this.set('isStreaming', false);
|
2017-11-15 17:13:17 +00:00
|
|
|
},
|
2018-02-26 20:23:01 +00:00
|
|
|
failoverToServer() {
|
|
|
|
this.set('useServer', true);
|
|
|
|
},
|
2017-11-15 17:13:17 +00:00
|
|
|
},
|
|
|
|
});
|