diff options
Diffstat (limited to 'client/src/app/+admin/requests')
8 files changed, 88 insertions, 92 deletions
diff --git a/client/src/app/+admin/requests/index.ts b/client/src/app/+admin/requests/index.ts index 236a9ee8f..d96a893c3 100644 --- a/client/src/app/+admin/requests/index.ts +++ b/client/src/app/+admin/requests/index.ts | |||
@@ -1,4 +1,4 @@ | |||
1 | export * from './request-stats'; | 1 | export * from './request-stats' |
2 | export * from './shared'; | 2 | export * from './shared' |
3 | export * from './requests.component'; | 3 | export * from './requests.component' |
4 | export * from './requests.routes'; | 4 | export * from './requests.routes' |
diff --git a/client/src/app/+admin/requests/request-stats/index.ts b/client/src/app/+admin/requests/request-stats/index.ts index be3a66f77..740c401bb 100644 --- a/client/src/app/+admin/requests/request-stats/index.ts +++ b/client/src/app/+admin/requests/request-stats/index.ts | |||
@@ -1 +1 @@ | |||
export * from './request-stats.component'; | export * from './request-stats.component' | ||
diff --git a/client/src/app/+admin/requests/request-stats/request-stats.component.ts b/client/src/app/+admin/requests/request-stats/request-stats.component.ts index 85dd7e492..cca4926cf 100644 --- a/client/src/app/+admin/requests/request-stats/request-stats.component.ts +++ b/client/src/app/+admin/requests/request-stats/request-stats.component.ts | |||
@@ -1,12 +1,12 @@ | |||
1 | import { Component, OnInit, OnDestroy } from '@angular/core'; | 1 | import { Component, OnInit, OnDestroy } from '@angular/core' |
2 | 2 | ||
3 | import { NotificationsService } from 'angular2-notifications'; | 3 | import { NotificationsService } from 'angular2-notifications' |
4 | 4 | ||
5 | import { RequestService, RequestStats } from '../shared'; | 5 | import { RequestService, RequestStats } from '../shared' |
6 | 6 | ||
7 | @Component({ | 7 | @Component({ |
8 | selector: 'my-request-stats', | 8 | selector: 'my-request-stats', |
9 | templateUrl: './request-stats.component.html', | 9 | templateUrl: './request-stats.component.html', |
10 | styleUrls: [ './request-stats.component.scss' ] | 10 | styleUrls: [ './request-stats.component.scss' ] |
11 | }) | 11 | }) |
12 | export class RequestStatsComponent implements OnInit, OnDestroy { | 12 | export class RequestStatsComponent implements OnInit, OnDestroy { |
@@ -14,70 +14,67 @@ export class RequestStatsComponent implements OnInit, OnDestroy { | |||
14 | requestScheduler: 'Basic request scheduler', | 14 | requestScheduler: 'Basic request scheduler', |
15 | requestVideoEventScheduler: 'Video events request scheduler', | 15 | requestVideoEventScheduler: 'Video events request scheduler', |
16 | requestVideoQaduScheduler: 'Quick and dirty video updates request scheduler' | 16 | requestVideoQaduScheduler: 'Quick and dirty video updates request scheduler' |
17 | }; | 17 | } |
18 | 18 | ||
19 | stats: { [ id: string ]: RequestStats } = { | 19 | stats: { [ id: string ]: RequestStats } = { |
20 | requestScheduler: null, | 20 | requestScheduler: null, |
21 | requestVideoEventScheduler: null, | 21 | requestVideoEventScheduler: null, |
22 | requestVideoQaduScheduler: null | 22 | requestVideoQaduScheduler: null |
23 | }; | 23 | } |
24 | 24 | ||
25 | private intervals: { [ id: string ]: number } = { | 25 | private intervals: { [ id: string ]: number } = { |
26 | requestScheduler: null, | 26 | requestScheduler: null, |
27 | requestVideoEventScheduler: null, | 27 | requestVideoEventScheduler: null, |
28 | requestVideoQaduScheduler: null | 28 | requestVideoQaduScheduler: null |
29 | }; | 29 | } |
30 | 30 | ||
31 | private timeouts: { [ id: string ]: number } = { | 31 | private timeouts: { [ id: string ]: number } = { |
32 | requestScheduler: null, | 32 | requestScheduler: null, |
33 | requestVideoEventScheduler: null, | 33 | requestVideoEventScheduler: null, |
34 | requestVideoQaduScheduler: null | 34 | requestVideoQaduScheduler: null |
35 | }; | 35 | } |
36 | |||
37 | 36 | ||
38 | constructor( | 37 | constructor ( |
39 | private notificationsService: NotificationsService, | 38 | private notificationsService: NotificationsService, |
40 | private requestService: RequestService | 39 | private requestService: RequestService |
41 | ) { } | 40 | ) { } |
42 | 41 | ||
43 | ngOnInit() { | 42 | ngOnInit () { |
44 | this.getStats(); | 43 | this.getStats() |
45 | this.runIntervals(); | 44 | this.runIntervals() |
46 | } | 45 | } |
47 | 46 | ||
48 | ngOnDestroy() { | 47 | ngOnDestroy () { |
49 | Object.keys(this.stats).forEach(requestSchedulerName => { | 48 | Object.keys(this.stats).forEach(requestSchedulerName => { |
50 | if (this.intervals[requestSchedulerName] !== null) { | 49 | if (this.intervals[requestSchedulerName] !== null) { |
51 | window.clearInterval(this.intervals[requestSchedulerName]); | 50 | window.clearInterval(this.intervals[requestSchedulerName]) |
52 | } | 51 | } |
53 | 52 | ||
54 | if (this.timeouts[requestSchedulerName] !== null) { | 53 | if (this.timeouts[requestSchedulerName] !== null) { |
55 | window.clearTimeout(this.timeouts[requestSchedulerName]); | 54 | window.clearTimeout(this.timeouts[requestSchedulerName]) |
56 | } | 55 | } |
57 | }); | 56 | }) |
58 | } | 57 | } |
59 | 58 | ||
60 | getStats() { | 59 | getStats () { |
61 | this.requestService.getStats().subscribe( | 60 | this.requestService.getStats().subscribe( |
62 | stats => this.stats = stats, | 61 | stats => this.stats = stats, |
63 | 62 | ||
64 | err => this.notificationsService.error('Error', err.text) | 63 | err => this.notificationsService.error('Error', err.text) |
65 | ); | 64 | ) |
66 | } | 65 | } |
67 | 66 | ||
68 | private runIntervals() { | 67 | private runIntervals () { |
69 | Object.keys(this.intervals).forEach(requestSchedulerName => { | 68 | Object.keys(this.intervals).forEach(requestSchedulerName => { |
70 | this.intervals[requestSchedulerName] = window.setInterval(() => { | 69 | this.intervals[requestSchedulerName] = window.setInterval(() => { |
71 | const stats = this.stats[requestSchedulerName]; | 70 | const stats = this.stats[requestSchedulerName] |
72 | 71 | ||
73 | stats.remainingMilliSeconds -= 1000; | 72 | stats.remainingMilliSeconds -= 1000 |
74 | 73 | ||
75 | if (stats.remainingMilliSeconds <= 0) { | 74 | if (stats.remainingMilliSeconds <= 0) { |
76 | this.timeouts[requestSchedulerName] = window.setTimeout(() => this.getStats(), stats.remainingMilliSeconds + 100); | 75 | this.timeouts[requestSchedulerName] = window.setTimeout(() => this.getStats(), stats.remainingMilliSeconds + 100) |
77 | } | 76 | } |
78 | }, 1000); | 77 | }, 1000) |
79 | }); | 78 | }) |
80 | } | 79 | } |
81 | |||
82 | |||
83 | } | 80 | } |
diff --git a/client/src/app/+admin/requests/requests.component.ts b/client/src/app/+admin/requests/requests.component.ts index 471112b45..88a90fa4e 100644 --- a/client/src/app/+admin/requests/requests.component.ts +++ b/client/src/app/+admin/requests/requests.component.ts | |||
@@ -1,8 +1,7 @@ | |||
1 | import { Component } from '@angular/core'; | 1 | import { Component } from '@angular/core' |
2 | 2 | ||
3 | @Component({ | 3 | @Component({ |
4 | template: '<router-outlet></router-outlet>' | 4 | template: '<router-outlet></router-outlet>' |
5 | }) | 5 | }) |
6 | |||
7 | export class RequestsComponent { | 6 | export class RequestsComponent { |
8 | } | 7 | } |
diff --git a/client/src/app/+admin/requests/requests.routes.ts b/client/src/app/+admin/requests/requests.routes.ts index 251dd0da8..84db3fea8 100644 --- a/client/src/app/+admin/requests/requests.routes.ts +++ b/client/src/app/+admin/requests/requests.routes.ts | |||
@@ -1,27 +1,27 @@ | |||
1 | import { Routes } from '@angular/router'; | 1 | import { Routes } from '@angular/router' |
2 | 2 | ||
3 | import { RequestsComponent } from './requests.component'; | 3 | import { RequestsComponent } from './requests.component' |
4 | import { RequestStatsComponent } from './request-stats'; | 4 | import { RequestStatsComponent } from './request-stats' |
5 | 5 | ||
6 | export const RequestsRoutes: Routes = [ | 6 | export const RequestsRoutes: Routes = [ |
7 | { | 7 | { |
8 | path: 'requests', | 8 | path: 'requests', |
9 | component: RequestsComponent, | 9 | component: RequestsComponent, |
10 | children: [ | 10 | children: [ |
11 | { | 11 | { |
12 | path: '', | 12 | path: '', |
13 | redirectTo: 'stats', | 13 | redirectTo: 'stats', |
14 | pathMatch: 'full' | 14 | pathMatch: 'full' |
15 | }, | 15 | }, |
16 | { | 16 | { |
17 | path: 'stats', | 17 | path: 'stats', |
18 | component: RequestStatsComponent, | 18 | component: RequestStatsComponent, |
19 | data: { | 19 | data: { |
20 | meta: { | 20 | meta: { |
21 | title: 'Request stats' | 21 | title: 'Request stats' |
22 | } | ||
23 | } | 22 | } |
24 | } | 23 | } |
25 | ] | 24 | } |
26 | } | 25 | ] |
27 | ]; | 26 | } |
27 | ] | ||
diff --git a/client/src/app/+admin/requests/shared/index.ts b/client/src/app/+admin/requests/shared/index.ts index 32ab5767b..2442e810a 100644 --- a/client/src/app/+admin/requests/shared/index.ts +++ b/client/src/app/+admin/requests/shared/index.ts | |||
@@ -1,2 +1,2 @@ | |||
1 | export * from './request-stats.model'; | 1 | export * from './request-stats.model' |
2 | export * from './request.service'; | 2 | export * from './request.service' |
diff --git a/client/src/app/+admin/requests/shared/request-stats.model.ts b/client/src/app/+admin/requests/shared/request-stats.model.ts index f658c4682..31550b5c0 100644 --- a/client/src/app/+admin/requests/shared/request-stats.model.ts +++ b/client/src/app/+admin/requests/shared/request-stats.model.ts | |||
@@ -1,35 +1,35 @@ | |||
1 | export interface Request { | 1 | export interface Request { |
2 | request: any; | 2 | request: any |
3 | to: any; | 3 | to: any |
4 | } | 4 | } |
5 | 5 | ||
6 | export class RequestStats { | 6 | export class RequestStats { |
7 | requestsLimitPods: number; | 7 | requestsLimitPods: number |
8 | requestsLimitPerPod: number; | 8 | requestsLimitPerPod: number |
9 | milliSecondsInterval: number; | 9 | milliSecondsInterval: number |
10 | remainingMilliSeconds: number; | 10 | remainingMilliSeconds: number |
11 | totalRequests: number; | 11 | totalRequests: number |
12 | 12 | ||
13 | constructor(hash: { | 13 | constructor (hash: { |
14 | requestsLimitPods: number, | 14 | requestsLimitPods: number, |
15 | requestsLimitPerPod: number, | 15 | requestsLimitPerPod: number, |
16 | milliSecondsInterval: number, | 16 | milliSecondsInterval: number, |
17 | remainingMilliSeconds: number, | 17 | remainingMilliSeconds: number, |
18 | totalRequests: number; | 18 | totalRequests: number |
19 | }) { | 19 | }) { |
20 | this.requestsLimitPods = hash.requestsLimitPods; | 20 | this.requestsLimitPods = hash.requestsLimitPods |
21 | this.requestsLimitPerPod = hash.requestsLimitPerPod; | 21 | this.requestsLimitPerPod = hash.requestsLimitPerPod |
22 | this.milliSecondsInterval = hash.milliSecondsInterval; | 22 | this.milliSecondsInterval = hash.milliSecondsInterval |
23 | this.remainingMilliSeconds = hash.remainingMilliSeconds; | 23 | this.remainingMilliSeconds = hash.remainingMilliSeconds |
24 | this.totalRequests = hash.totalRequests; | 24 | this.totalRequests = hash.totalRequests |
25 | } | 25 | } |
26 | 26 | ||
27 | get remainingSeconds() { | 27 | get remainingSeconds () { |
28 | return Math.floor(this.remainingMilliSeconds / 1000); | 28 | return Math.floor(this.remainingMilliSeconds / 1000) |
29 | } | 29 | } |
30 | 30 | ||
31 | get secondsInterval() { | 31 | get secondsInterva () { |
32 | return Math.floor(this.milliSecondsInterval / 1000); | 32 | return Math.floor(this.milliSecondsInterval / 1000) |
33 | } | 33 | } |
34 | 34 | ||
35 | } | 35 | } |
diff --git a/client/src/app/+admin/requests/shared/request.service.ts b/client/src/app/+admin/requests/shared/request.service.ts index 0872ba0b8..faa6b9383 100644 --- a/client/src/app/+admin/requests/shared/request.service.ts +++ b/client/src/app/+admin/requests/shared/request.service.ts | |||
@@ -1,34 +1,34 @@ | |||
1 | import { Injectable } from '@angular/core'; | 1 | import { Injectable } from '@angular/core' |
2 | import { Observable } from 'rxjs/Observable'; | 2 | import { Observable } from 'rxjs/Observable' |
3 | import 'rxjs/add/operator/catch'; | 3 | import 'rxjs/add/operator/catch' |
4 | import 'rxjs/add/operator/map'; | 4 | import 'rxjs/add/operator/map' |
5 | 5 | ||
6 | import { RequestStats } from './request-stats.model'; | 6 | import { RequestStats } from './request-stats.model' |
7 | import { AuthHttp, RestExtractor } from '../../../shared'; | 7 | import { AuthHttp, RestExtractor } from '../../../shared' |
8 | 8 | ||
9 | @Injectable() | 9 | @Injectable() |
10 | export class RequestService { | 10 | export class RequestService { |
11 | private static BASE_REQUEST_URL = API_URL + '/api/v1/requests/'; | 11 | private static BASE_REQUEST_URL = API_URL + '/api/v1/requests/' |
12 | 12 | ||
13 | constructor ( | 13 | constructor ( |
14 | private authHttp: AuthHttp, | 14 | private authHttp: AuthHttp, |
15 | private restExtractor: RestExtractor | 15 | private restExtractor: RestExtractor |
16 | ) {} | 16 | ) {} |
17 | 17 | ||
18 | getStats(): Observable<{ [ id: string ]: RequestStats }> { | 18 | getStats (): Observable<{ [ id: string ]: RequestStats }> { |
19 | return this.authHttp.get(RequestService.BASE_REQUEST_URL + 'stats') | 19 | return this.authHttp.get(RequestService.BASE_REQUEST_URL + 'stats') |
20 | .map(this.restExtractor.extractDataGet) | 20 | .map(this.restExtractor.extractDataGet) |
21 | .map(this.buildRequestObjects) | 21 | .map(this.buildRequestObjects) |
22 | .catch((res) => this.restExtractor.handleError(res)); | 22 | .catch((res) => this.restExtractor.handleError(res)) |
23 | } | 23 | } |
24 | 24 | ||
25 | private buildRequestObjects(data: any) { | 25 | private buildRequestObjects (data: any) { |
26 | const requestSchedulers = {}; | 26 | const requestSchedulers = {} |
27 | 27 | ||
28 | Object.keys(data).forEach(requestSchedulerName => { | 28 | Object.keys(data).forEach(requestSchedulerName => { |
29 | requestSchedulers[requestSchedulerName] = new RequestStats(data[requestSchedulerName]); | 29 | requestSchedulers[requestSchedulerName] = new RequestStats(data[requestSchedulerName]) |
30 | }); | 30 | }) |
31 | 31 | ||
32 | return requestSchedulers; | 32 | return requestSchedulers |
33 | } | 33 | } |
34 | } | 34 | } |