Requests -> RequestSchedulers
authorChocobozzz <florian.bigard@gmail.com>
Sun, 25 Jun 2017 15:19:46 +0000 (17:19 +0200)
committerChocobozzz <florian.bigard@gmail.com>
Sun, 25 Jun 2017 15:19:46 +0000 (17:19 +0200)
36 files changed:
client/src/app/+admin/admin-routing.module.ts
client/src/app/+admin/admin.module.ts
client/src/app/+admin/index.ts
client/src/app/+admin/request-schedulers/index.ts [new file with mode: 0644]
client/src/app/+admin/request-schedulers/request-schedulers-stats/index.ts [new file with mode: 0644]
client/src/app/+admin/request-schedulers/request-schedulers-stats/request-schedulers-stats.component.html [new file with mode: 0644]
client/src/app/+admin/request-schedulers/request-schedulers-stats/request-schedulers-stats.component.scss [new file with mode: 0644]
client/src/app/+admin/request-schedulers/request-schedulers-stats/request-schedulers-stats.component.ts [new file with mode: 0644]
client/src/app/+admin/request-schedulers/request-schedulers.component.ts [new file with mode: 0644]
client/src/app/+admin/request-schedulers/request-schedulers.routes.ts [new file with mode: 0644]
client/src/app/+admin/request-schedulers/shared/index.ts [new file with mode: 0644]
client/src/app/+admin/request-schedulers/shared/request-schedulers-stats-attributes.model.ts [new file with mode: 0644]
client/src/app/+admin/request-schedulers/shared/request-schedulers.service.ts [new file with mode: 0644]
client/src/app/+admin/requests/index.ts [deleted file]
client/src/app/+admin/requests/request-stats/index.ts [deleted file]
client/src/app/+admin/requests/request-stats/request-stats.component.html [deleted file]
client/src/app/+admin/requests/request-stats/request-stats.component.scss [deleted file]
client/src/app/+admin/requests/request-stats/request-stats.component.ts [deleted file]
client/src/app/+admin/requests/requests.component.ts [deleted file]
client/src/app/+admin/requests/requests.routes.ts [deleted file]
client/src/app/+admin/requests/shared/index.ts [deleted file]
client/src/app/+admin/requests/shared/request-stats-attributes.model.ts [deleted file]
client/src/app/+admin/requests/shared/request.service.ts [deleted file]
server/controllers/api/index.ts
server/controllers/api/request-schedulers.ts [new file with mode: 0644]
server/controllers/api/requests.ts [deleted file]
server/tests/api/check-params/index.js
server/tests/api/check-params/request-schedulers.js [new file with mode: 0644]
server/tests/api/check-params/requests.js [deleted file]
server/tests/api/index.js
server/tests/api/request-schedulers.js [new file with mode: 0644]
server/tests/api/requests.js [deleted file]
server/tests/real-world/real-world.js
server/tests/utils/request-schedulers.js [new file with mode: 0644]
server/tests/utils/requests-stats.js [deleted file]
shared/models/request-scheduler.model.ts

index 839913135fba9da2d4416c8a147017e01ebbf9f0..bcc94a9f36c7510c1d9b72f955101c40c80241b9 100644 (file)
@@ -3,7 +3,7 @@ import { RouterModule, Routes } from '@angular/router'
 
 import { AdminComponent } from './admin.component'
 import { FriendsRoutes } from './friends'
-import { RequestsRoutes } from './requests'
+import { RequestSchedulersRoutes } from './request-schedulers'
 import { UsersRoutes } from './users'
 import { VideoAbusesRoutes } from './video-abuses'
 
@@ -18,7 +18,7 @@ const adminRoutes: Routes = [
         pathMatch: 'full'
       },
       ...FriendsRoutes,
-      ...RequestsRoutes,
+      ...RequestSchedulersRoutes,
       ...UsersRoutes,
       ...VideoAbusesRoutes
     ]
index 9ecce5dc3a7722caa144ba4f7761e1a827196ffa..e4ba8e5b74c5ec006c07ba38fc9ff20736cc253d 100644 (file)
@@ -3,7 +3,7 @@ import { NgModule } from '@angular/core'
 import { AdminComponent } from './admin.component'
 import { AdminRoutingModule } from './admin-routing.module'
 import { FriendsComponent, FriendAddComponent, FriendListComponent, FriendService } from './friends'
-import { RequestsComponent, RequestStatsComponent, RequestService } from './requests'
+import { RequestSchedulersComponent, RequestSchedulersStatsComponent, RequestSchedulersService } from './request-schedulers'
 import { UsersComponent, UserAddComponent, UserListComponent, UserService } from './users'
 import { VideoAbusesComponent, VideoAbuseListComponent } from './video-abuses'
 import { SharedModule } from '../shared'
@@ -21,8 +21,8 @@ import { SharedModule } from '../shared'
     FriendAddComponent,
     FriendListComponent,
 
-    RequestsComponent,
-    RequestStatsComponent,
+    RequestSchedulersComponent,
+    RequestSchedulersStatsComponent,
 
     UsersComponent,
     UserAddComponent,
@@ -38,7 +38,7 @@ import { SharedModule } from '../shared'
 
   providers: [
     FriendService,
-    RequestService,
+    RequestSchedulersService,
     UserService
   ]
 })
index 11e2587c088e9f234fb168b821cddd9ee330b7b1..b628a366291da81269333dc9524449d0f216970c 100644 (file)
@@ -1,6 +1 @@
-export * from './friends'
-export * from './requests'
-export * from './users'
-export * from './admin-routing.module'
 export * from './admin.module'
-export * from './admin.component'
diff --git a/client/src/app/+admin/request-schedulers/index.ts b/client/src/app/+admin/request-schedulers/index.ts
new file mode 100644 (file)
index 0000000..87b72e8
--- /dev/null
@@ -0,0 +1,4 @@
+export * from './request-schedulers-stats'
+export * from './shared'
+export * from './request-schedulers.component'
+export * from './request-schedulers.routes'
diff --git a/client/src/app/+admin/request-schedulers/request-schedulers-stats/index.ts b/client/src/app/+admin/request-schedulers/request-schedulers-stats/index.ts
new file mode 100644 (file)
index 0000000..a3323e6
--- /dev/null
@@ -0,0 +1 @@
+export * from './request-schedulers-stats.component'
diff --git a/client/src/app/+admin/request-schedulers/request-schedulers-stats/request-schedulers-stats.component.html b/client/src/app/+admin/request-schedulers/request-schedulers-stats/request-schedulers-stats.component.html
new file mode 100644 (file)
index 0000000..4508ab4
--- /dev/null
@@ -0,0 +1,46 @@
+<div class="row">
+  <div class="content-padding">
+
+    <h3>Requests stats</h3>
+
+    <ng-template [ngIf]="stats">
+      <div *ngFor="let requestSchedulerName of statsTitles | keys" class="col-lg-4 col-md-12">
+        <div class="panel panel-default" *ngIf="stats[requestSchedulerName] !== null">
+          <div class="panel-heading">{{ statsTitles[requestSchedulerName] }}</div>
+
+          <div class="panel-body">
+            <div class="requests-general">
+              <div>
+                <span class="label-description">Remaining requests:</span>
+                {{ stats[requestSchedulerName].totalRequests }}
+              </div>
+
+              <div>
+                <span class="label-description">Interval seconds between requests:</span>
+                {{ stats[requestSchedulerName].secondsInterval }}
+              </div>
+
+              <div>
+                <span class="label-description">Remaining time before the scheduled request:</span>
+                {{ stats[requestSchedulerName].remainingSeconds }}
+              </div>
+            </div>
+
+            <div class="requests-limit">
+              <div>
+                <span class="label-description">Maximum number of different pods for a scheduled request:</span>
+                {{ stats[requestSchedulerName].requestsLimitPods }}
+              </div>
+
+              <div>
+                <span class="label-description">Maximum number of requests per pod for a scheduled request:</span>
+                {{ stats[requestSchedulerName].requestsLimitPerPod }}
+              </div>
+            </div>
+          </div>
+        </div>
+      </div>
+    </ng-template>
+
+  </div>
+</div>
diff --git a/client/src/app/+admin/request-schedulers/request-schedulers-stats/request-schedulers-stats.component.scss b/client/src/app/+admin/request-schedulers/request-schedulers-stats/request-schedulers-stats.component.scss
new file mode 100644 (file)
index 0000000..b2c4132
--- /dev/null
@@ -0,0 +1,8 @@
+.label-description {
+  font-weight: bold;
+  color: black;
+}
+
+.requests-limit {
+  margin-top: 20px;
+}
diff --git a/client/src/app/+admin/request-schedulers/request-schedulers-stats/request-schedulers-stats.component.ts b/client/src/app/+admin/request-schedulers/request-schedulers-stats/request-schedulers-stats.component.ts
new file mode 100644 (file)
index 0000000..4e3fabc
--- /dev/null
@@ -0,0 +1,77 @@
+import { Component, OnInit, OnDestroy } from '@angular/core'
+
+import { NotificationsService } from 'angular2-notifications'
+
+import { RequestSchedulersService, RequestSchedulerStatsAttributes } from '../shared'
+import { RequestSchedulerStats } from '../../../../../../shared'
+
+@Component({
+  selector: 'my-request-schedulers-stats',
+  templateUrl: './request-schedulers-stats.component.html',
+  styleUrls: [ './request-schedulers-stats.component.scss' ]
+})
+export class RequestSchedulersStatsComponent implements OnInit, OnDestroy {
+  statsTitles = {
+    requestScheduler: 'Basic request scheduler',
+    requestVideoEventScheduler: 'Video events request scheduler',
+    requestVideoQaduScheduler: 'Quick and dirty video updates request scheduler'
+  }
+
+  stats: RequestSchedulerStats
+
+  private intervals: { [ id: string ]: number } = {
+    requestScheduler: null,
+    requestVideoEventScheduler: null,
+    requestVideoQaduScheduler: null
+  }
+
+  private timeouts: { [ id: string ]: number } = {
+    requestScheduler: null,
+    requestVideoEventScheduler: null,
+    requestVideoQaduScheduler: null
+  }
+
+  constructor (
+    private notificationsService: NotificationsService,
+    private requestService: RequestSchedulersService
+  ) { }
+
+  ngOnInit () {
+    this.getStats()
+    this.runIntervals()
+  }
+
+  ngOnDestroy () {
+    Object.keys(this.stats).forEach(requestSchedulerName => {
+      if (this.intervals[requestSchedulerName] !== null) {
+        window.clearInterval(this.intervals[requestSchedulerName])
+      }
+
+      if (this.timeouts[requestSchedulerName] !== null) {
+        window.clearTimeout(this.timeouts[requestSchedulerName])
+      }
+    })
+  }
+
+  getStats () {
+    this.requestService.getStats().subscribe(
+      stats => this.stats = stats,
+
+      err => this.notificationsService.error('Error', err.text)
+    )
+  }
+
+  private runIntervals () {
+    Object.keys(this.intervals).forEach(requestSchedulerName => {
+      this.intervals[requestSchedulerName] = window.setInterval(() => {
+        const stats: RequestSchedulerStatsAttributes = this.stats[requestSchedulerName]
+
+        stats.remainingMilliSeconds -= 1000
+
+        if (stats.remainingMilliSeconds <= 0) {
+          this.timeouts[requestSchedulerName] = window.setTimeout(() => this.getStats(), stats.remainingMilliSeconds + 100)
+        }
+      }, 1000)
+    })
+  }
+}
diff --git a/client/src/app/+admin/request-schedulers/request-schedulers.component.ts b/client/src/app/+admin/request-schedulers/request-schedulers.component.ts
new file mode 100644 (file)
index 0000000..5444d6e
--- /dev/null
@@ -0,0 +1,7 @@
+import { Component } from '@angular/core'
+
+@Component({
+  template: '<router-outlet></router-outlet>'
+})
+export class RequestSchedulersComponent {
+}
diff --git a/client/src/app/+admin/request-schedulers/request-schedulers.routes.ts b/client/src/app/+admin/request-schedulers/request-schedulers.routes.ts
new file mode 100644 (file)
index 0000000..4961c64
--- /dev/null
@@ -0,0 +1,27 @@
+import { Routes } from '@angular/router'
+
+import { RequestSchedulersComponent } from './request-schedulers.component'
+import { RequestSchedulersStatsComponent } from './request-schedulers-stats'
+
+export const RequestSchedulersRoutes: Routes = [
+  {
+    path: 'requests',
+    component: RequestSchedulersComponent,
+    children: [
+      {
+        path: '',
+        redirectTo: 'stats',
+        pathMatch: 'full'
+      },
+      {
+        path: 'stats',
+        component: RequestSchedulersStatsComponent,
+        data: {
+          meta: {
+            title: 'Request stats'
+          }
+        }
+      }
+    ]
+  }
+]
diff --git a/client/src/app/+admin/request-schedulers/shared/index.ts b/client/src/app/+admin/request-schedulers/shared/index.ts
new file mode 100644 (file)
index 0000000..1a01744
--- /dev/null
@@ -0,0 +1,2 @@
+export * from './request-schedulers-stats-attributes.model'
+export * from './request-schedulers.service'
diff --git a/client/src/app/+admin/request-schedulers/shared/request-schedulers-stats-attributes.model.ts b/client/src/app/+admin/request-schedulers/shared/request-schedulers-stats-attributes.model.ts
new file mode 100644 (file)
index 0000000..6e19a0e
--- /dev/null
@@ -0,0 +1,37 @@
+import { RequestSchedulerStatsAttributes as FormatedRequestSchedulerStatsAttributes } from '../../../../../../shared'
+
+export interface Request {
+  request: any
+  to: any
+}
+
+export class RequestSchedulerStatsAttributes implements FormatedRequestSchedulerStatsAttributes {
+  requestsLimitPods: number
+  requestsLimitPerPod: number
+  milliSecondsInterval: number
+  remainingMilliSeconds: number
+  totalRequests: number
+
+  constructor (hash: {
+    requestsLimitPods: number,
+    requestsLimitPerPod: number,
+    milliSecondsInterval: number,
+    remainingMilliSeconds: number,
+    totalRequests: number
+  }) {
+    this.requestsLimitPods = hash.requestsLimitPods
+    this.requestsLimitPerPod = hash.requestsLimitPerPod
+    this.milliSecondsInterval = hash.milliSecondsInterval
+    this.remainingMilliSeconds = hash.remainingMilliSeconds
+    this.totalRequests = hash.totalRequests
+  }
+
+  get remainingSeconds () {
+    return Math.floor(this.remainingMilliSeconds / 1000)
+  }
+
+  get secondsInterva () {
+    return Math.floor(this.milliSecondsInterval / 1000)
+  }
+
+}
diff --git a/client/src/app/+admin/request-schedulers/shared/request-schedulers.service.ts b/client/src/app/+admin/request-schedulers/shared/request-schedulers.service.ts
new file mode 100644 (file)
index 0000000..e9b166f
--- /dev/null
@@ -0,0 +1,35 @@
+import { Injectable } from '@angular/core'
+import { Observable } from 'rxjs/Observable'
+import 'rxjs/add/operator/catch'
+import 'rxjs/add/operator/map'
+
+import { RequestSchedulerStats } from '../../../../../../shared'
+import { AuthHttp, RestExtractor } from '../../../shared'
+import { RequestSchedulerStatsAttributes } from './request-schedulers-stats-attributes.model'
+
+@Injectable()
+export class RequestSchedulersService {
+  private static BASE_REQUEST_URL = API_URL + '/api/v1/request-schedulers/'
+
+  constructor (
+    private authHttp: AuthHttp,
+    private restExtractor: RestExtractor
+  ) {}
+
+  getStats (): Observable<RequestSchedulerStats> {
+    return this.authHttp.get(RequestSchedulersService.BASE_REQUEST_URL + 'stats')
+                        .map(this.restExtractor.extractDataGet)
+                        .map(this.buildRequestObjects)
+                        .catch((res) => this.restExtractor.handleError(res))
+  }
+
+  private buildRequestObjects (data: RequestSchedulerStats) {
+    const requestSchedulers = {}
+
+    Object.keys(data).forEach(requestSchedulerName => {
+      requestSchedulers[requestSchedulerName] = new RequestSchedulerStatsAttributes(data[requestSchedulerName])
+    })
+
+    return requestSchedulers
+  }
+}
diff --git a/client/src/app/+admin/requests/index.ts b/client/src/app/+admin/requests/index.ts
deleted file mode 100644 (file)
index d96a893..0000000
+++ /dev/null
@@ -1,4 +0,0 @@
-export * from './request-stats'
-export * from './shared'
-export * from './requests.component'
-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
deleted file mode 100644 (file)
index 740c401..0000000
+++ /dev/null
@@ -1 +0,0 @@
-export * from './request-stats.component'
diff --git a/client/src/app/+admin/requests/request-stats/request-stats.component.html b/client/src/app/+admin/requests/request-stats/request-stats.component.html
deleted file mode 100644 (file)
index 4508ab4..0000000
+++ /dev/null
@@ -1,46 +0,0 @@
-<div class="row">
-  <div class="content-padding">
-
-    <h3>Requests stats</h3>
-
-    <ng-template [ngIf]="stats">
-      <div *ngFor="let requestSchedulerName of statsTitles | keys" class="col-lg-4 col-md-12">
-        <div class="panel panel-default" *ngIf="stats[requestSchedulerName] !== null">
-          <div class="panel-heading">{{ statsTitles[requestSchedulerName] }}</div>
-
-          <div class="panel-body">
-            <div class="requests-general">
-              <div>
-                <span class="label-description">Remaining requests:</span>
-                {{ stats[requestSchedulerName].totalRequests }}
-              </div>
-
-              <div>
-                <span class="label-description">Interval seconds between requests:</span>
-                {{ stats[requestSchedulerName].secondsInterval }}
-              </div>
-
-              <div>
-                <span class="label-description">Remaining time before the scheduled request:</span>
-                {{ stats[requestSchedulerName].remainingSeconds }}
-              </div>
-            </div>
-
-            <div class="requests-limit">
-              <div>
-                <span class="label-description">Maximum number of different pods for a scheduled request:</span>
-                {{ stats[requestSchedulerName].requestsLimitPods }}
-              </div>
-
-              <div>
-                <span class="label-description">Maximum number of requests per pod for a scheduled request:</span>
-                {{ stats[requestSchedulerName].requestsLimitPerPod }}
-              </div>
-            </div>
-          </div>
-        </div>
-      </div>
-    </ng-template>
-
-  </div>
-</div>
diff --git a/client/src/app/+admin/requests/request-stats/request-stats.component.scss b/client/src/app/+admin/requests/request-stats/request-stats.component.scss
deleted file mode 100644 (file)
index b2c4132..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-.label-description {
-  font-weight: bold;
-  color: black;
-}
-
-.requests-limit {
-  margin-top: 20px;
-}
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
deleted file mode 100644 (file)
index 140aaf4..0000000
+++ /dev/null
@@ -1,77 +0,0 @@
-import { Component, OnInit, OnDestroy } from '@angular/core'
-
-import { NotificationsService } from 'angular2-notifications'
-
-import { RequestService, RequestSchedulerStatsAttributes } from '../shared'
-import { RequestScheduler } from '../../../../../../shared'
-
-@Component({
-  selector: 'my-request-stats',
-  templateUrl: './request-stats.component.html',
-  styleUrls: [ './request-stats.component.scss' ]
-})
-export class RequestStatsComponent implements OnInit, OnDestroy {
-  statsTitles = {
-    requestScheduler: 'Basic request scheduler',
-    requestVideoEventScheduler: 'Video events request scheduler',
-    requestVideoQaduScheduler: 'Quick and dirty video updates request scheduler'
-  }
-
-  stats: RequestScheduler
-
-  private intervals: { [ id: string ]: number } = {
-    requestScheduler: null,
-    requestVideoEventScheduler: null,
-    requestVideoQaduScheduler: null
-  }
-
-  private timeouts: { [ id: string ]: number } = {
-    requestScheduler: null,
-    requestVideoEventScheduler: null,
-    requestVideoQaduScheduler: null
-  }
-
-  constructor (
-    private notificationsService: NotificationsService,
-    private requestService: RequestService
-  ) { }
-
-  ngOnInit () {
-    this.getStats()
-    this.runIntervals()
-  }
-
-  ngOnDestroy () {
-    Object.keys(this.stats).forEach(requestSchedulerName => {
-      if (this.intervals[requestSchedulerName] !== null) {
-        window.clearInterval(this.intervals[requestSchedulerName])
-      }
-
-      if (this.timeouts[requestSchedulerName] !== null) {
-        window.clearTimeout(this.timeouts[requestSchedulerName])
-      }
-    })
-  }
-
-  getStats () {
-    this.requestService.getStats().subscribe(
-      stats => this.stats = stats,
-
-      err => this.notificationsService.error('Error', err.text)
-    )
-  }
-
-  private runIntervals () {
-    Object.keys(this.intervals).forEach(requestSchedulerName => {
-      this.intervals[requestSchedulerName] = window.setInterval(() => {
-        const stats: RequestSchedulerStatsAttributes = this.stats[requestSchedulerName]
-
-        stats.remainingMilliSeconds -= 1000
-
-        if (stats.remainingMilliSeconds <= 0) {
-          this.timeouts[requestSchedulerName] = window.setTimeout(() => this.getStats(), stats.remainingMilliSeconds + 100)
-        }
-      }, 1000)
-    })
-  }
-}
diff --git a/client/src/app/+admin/requests/requests.component.ts b/client/src/app/+admin/requests/requests.component.ts
deleted file mode 100644 (file)
index 88a90fa..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-import { Component } from '@angular/core'
-
-@Component({
-  template: '<router-outlet></router-outlet>'
-})
-export class RequestsComponent {
-}
diff --git a/client/src/app/+admin/requests/requests.routes.ts b/client/src/app/+admin/requests/requests.routes.ts
deleted file mode 100644 (file)
index 84db3fe..0000000
+++ /dev/null
@@ -1,27 +0,0 @@
-import { Routes } from '@angular/router'
-
-import { RequestsComponent } from './requests.component'
-import { RequestStatsComponent } from './request-stats'
-
-export const RequestsRoutes: Routes = [
-  {
-    path: 'requests',
-    component: RequestsComponent,
-    children: [
-      {
-        path: '',
-        redirectTo: 'stats',
-        pathMatch: 'full'
-      },
-      {
-        path: 'stats',
-        component: RequestStatsComponent,
-        data: {
-          meta: {
-            title: 'Request stats'
-          }
-        }
-      }
-    ]
-  }
-]
diff --git a/client/src/app/+admin/requests/shared/index.ts b/client/src/app/+admin/requests/shared/index.ts
deleted file mode 100644 (file)
index 857fe9d..0000000
+++ /dev/null
@@ -1,2 +0,0 @@
-export * from './request-stats-attributes.model'
-export * from './request.service'
diff --git a/client/src/app/+admin/requests/shared/request-stats-attributes.model.ts b/client/src/app/+admin/requests/shared/request-stats-attributes.model.ts
deleted file mode 100644 (file)
index 394acc7..0000000
+++ /dev/null
@@ -1,37 +0,0 @@
-import { RequestSchedulerAttributes as FormatedRequestSchedulerAttributes } from '../../../../../../shared'
-
-export interface Request {
-  request: any
-  to: any
-}
-
-export class RequestSchedulerStatsAttributes implements FormatedRequestSchedulerAttributes {
-  requestsLimitPods: number
-  requestsLimitPerPod: number
-  milliSecondsInterval: number
-  remainingMilliSeconds: number
-  totalRequests: number
-
-  constructor (hash: {
-    requestsLimitPods: number,
-    requestsLimitPerPod: number,
-    milliSecondsInterval: number,
-    remainingMilliSeconds: number,
-    totalRequests: number
-  }) {
-    this.requestsLimitPods = hash.requestsLimitPods
-    this.requestsLimitPerPod = hash.requestsLimitPerPod
-    this.milliSecondsInterval = hash.milliSecondsInterval
-    this.remainingMilliSeconds = hash.remainingMilliSeconds
-    this.totalRequests = hash.totalRequests
-  }
-
-  get remainingSeconds () {
-    return Math.floor(this.remainingMilliSeconds / 1000)
-  }
-
-  get secondsInterva () {
-    return Math.floor(this.milliSecondsInterval / 1000)
-  }
-
-}
diff --git a/client/src/app/+admin/requests/shared/request.service.ts b/client/src/app/+admin/requests/shared/request.service.ts
deleted file mode 100644 (file)
index 53682b1..0000000
+++ /dev/null
@@ -1,35 +0,0 @@
-import { Injectable } from '@angular/core'
-import { Observable } from 'rxjs/Observable'
-import 'rxjs/add/operator/catch'
-import 'rxjs/add/operator/map'
-
-import { RequestScheduler } from '../../../../../../shared'
-import { AuthHttp, RestExtractor } from '../../../shared'
-import { RequestSchedulerStatsAttributes } from './request-stats-attributes.model'
-
-@Injectable()
-export class RequestService {
-  private static BASE_REQUEST_URL = API_URL + '/api/v1/requests/'
-
-  constructor (
-    private authHttp: AuthHttp,
-    private restExtractor: RestExtractor
-  ) {}
-
-  getStats (): Observable<RequestScheduler> {
-    return this.authHttp.get(RequestService.BASE_REQUEST_URL + 'stats')
-                        .map(this.restExtractor.extractDataGet)
-                        .map(this.buildRequestObjects)
-                        .catch((res) => this.restExtractor.handleError(res))
-  }
-
-  private buildRequestObjects (data: RequestScheduler) {
-    const requestSchedulers = {}
-
-    Object.keys(data).forEach(requestSchedulerName => {
-      requestSchedulers[requestSchedulerName] = new RequestSchedulerStatsAttributes(data[requestSchedulerName])
-    })
-
-    return requestSchedulers
-  }
-}
index ac3972ac63d8c00fb2aa5dea60d3ba604337836f..3abe9bcf82f8ddf809b33c08c73bc9ceb82a8477 100644 (file)
@@ -6,7 +6,7 @@ import { clientsRouter } from './clients'
 import { configRouter } from './config'
 import { podsRouter } from './pods'
 import { remoteRouter } from './remote'
-import { requestsRouter } from './requests'
+import { requestSchedulerRouter } from './request-schedulers'
 import { usersRouter } from './users'
 import { videosRouter } from './videos'
 
@@ -16,7 +16,7 @@ apiRouter.use('/clients', clientsRouter)
 apiRouter.use('/config', configRouter)
 apiRouter.use('/pods', podsRouter)
 apiRouter.use('/remote', remoteRouter)
-apiRouter.use('/requests', requestsRouter)
+apiRouter.use('/request-schedulers', requestSchedulerRouter)
 apiRouter.use('/users', usersRouter)
 apiRouter.use('/videos', videosRouter)
 apiRouter.use('/ping', pong)
diff --git a/server/controllers/api/request-schedulers.ts b/server/controllers/api/request-schedulers.ts
new file mode 100644 (file)
index 0000000..8dd8490
--- /dev/null
@@ -0,0 +1,59 @@
+import * as express from 'express'
+import { parallel } from 'async'
+
+import {
+  AbstractRequestScheduler,
+  getRequestScheduler,
+  getRequestVideoQaduScheduler,
+  getRequestVideoEventScheduler
+} from '../../lib'
+import { authenticate, ensureIsAdmin } from '../../middlewares'
+import { RequestSchedulerStatsAttributes } from '../../../shared'
+
+const requestSchedulerRouter = express.Router()
+
+requestSchedulerRouter.get('/stats',
+  authenticate,
+  ensureIsAdmin,
+  getRequestSchedulersStats
+)
+
+// ---------------------------------------------------------------------------
+
+export {
+  requestSchedulerRouter
+}
+
+// ---------------------------------------------------------------------------
+
+function getRequestSchedulersStats (req: express.Request, res: express.Response, next: express.NextFunction) {
+  parallel({
+    requestScheduler: buildRequestSchedulerStats(getRequestScheduler()),
+    requestVideoQaduScheduler: buildRequestSchedulerStats(getRequestVideoQaduScheduler()),
+    requestVideoEventScheduler: buildRequestSchedulerStats(getRequestVideoEventScheduler())
+  }, function (err, result) {
+    if (err) return next(err)
+
+    return res.json(result)
+  })
+}
+
+// ---------------------------------------------------------------------------
+
+function buildRequestSchedulerStats (requestScheduler: AbstractRequestScheduler) {
+  return function (callback) {
+    requestScheduler.remainingRequestsCount(function (err, count) {
+      if (err) return callback(err)
+
+      const result: RequestSchedulerStatsAttributes = {
+        totalRequests: count,
+        requestsLimitPods: requestScheduler.limitPods,
+        requestsLimitPerPod: requestScheduler.limitPerPod,
+        remainingMilliSeconds: requestScheduler.remainingMilliSeconds(),
+        milliSecondsInterval: requestScheduler.requestInterval
+      }
+
+      return callback(null, result)
+    })
+  }
+}
diff --git a/server/controllers/api/requests.ts b/server/controllers/api/requests.ts
deleted file mode 100644 (file)
index 5718b59..0000000
+++ /dev/null
@@ -1,59 +0,0 @@
-import * as express from 'express'
-import { parallel } from 'async'
-
-import {
-  AbstractRequestScheduler,
-  getRequestScheduler,
-  getRequestVideoQaduScheduler,
-  getRequestVideoEventScheduler
-} from '../../lib'
-import { authenticate, ensureIsAdmin } from '../../middlewares'
-import { RequestSchedulerAttributes } from '../../../shared'
-
-const requestsRouter = express.Router()
-
-requestsRouter.get('/stats',
-  authenticate,
-  ensureIsAdmin,
-  getStatsRequests
-)
-
-// ---------------------------------------------------------------------------
-
-export {
-  requestsRouter
-}
-
-// ---------------------------------------------------------------------------
-
-function getStatsRequests (req: express.Request, res: express.Response, next: express.NextFunction) {
-  parallel({
-    requestScheduler: buildRequestSchedulerFunction(getRequestScheduler()),
-    requestVideoQaduScheduler: buildRequestSchedulerFunction(getRequestVideoQaduScheduler()),
-    requestVideoEventScheduler: buildRequestSchedulerFunction(getRequestVideoEventScheduler())
-  }, function (err, result) {
-    if (err) return next(err)
-
-    return res.json(result)
-  })
-}
-
-// ---------------------------------------------------------------------------
-
-function buildRequestSchedulerFunction (requestScheduler: AbstractRequestScheduler) {
-  return function (callback) {
-    requestScheduler.remainingRequestsCount(function (err, count) {
-      if (err) return callback(err)
-
-      const result: RequestSchedulerAttributes = {
-        totalRequests: count,
-        requestsLimitPods: requestScheduler.limitPods,
-        requestsLimitPerPod: requestScheduler.limitPerPod,
-        remainingMilliSeconds: requestScheduler.remainingMilliSeconds(),
-        milliSecondsInterval: requestScheduler.requestInterval
-      }
-
-      return callback(null, result)
-    })
-  }
-}
index 527ab65a9a8c37d3cfbccbcbb23e45c8a311a035..1ba16ff328381d5dad6050574b32bebaf490de0f 100644 (file)
@@ -4,7 +4,7 @@
 require('./pods')
 require('./remotes')
 require('./users')
-require('./requests')
+require('./request-schedulers')
 require('./videos')
 require('./video-abuses')
 require('./video-blacklists')
diff --git a/server/tests/api/check-params/request-schedulers.js b/server/tests/api/check-params/request-schedulers.js
new file mode 100644 (file)
index 0000000..9ba0df7
--- /dev/null
@@ -0,0 +1,89 @@
+/* eslint-disable no-unused-expressions */
+
+'use strict'
+
+const request = require('supertest')
+const series = require('async/series')
+
+const loginUtils = require('../../utils/login')
+const usersUtils = require('../../utils/users')
+const serversUtils = require('../../utils/servers')
+
+describe('Test request schedulers stats API validators', function () {
+  const path = '/api/v1/request-schedulers/stats'
+  let server = null
+  let userAccessToken = null
+
+  // ---------------------------------------------------------------
+
+  before(function (done) {
+    this.timeout(20000)
+
+    series([
+      function (next) {
+        serversUtils.flushTests(next)
+      },
+      function (next) {
+        serversUtils.runServer(1, function (server1) {
+          server = server1
+
+          next()
+        })
+      },
+      function (next) {
+        loginUtils.loginAndGetAccessToken(server, function (err, token) {
+          if (err) throw err
+          server.accessToken = token
+
+          next()
+        })
+      },
+      function (next) {
+        const username = 'user'
+        const password = 'my super password'
+
+        usersUtils.createUser(server.url, server.accessToken, username, password, next)
+      },
+      function (next) {
+        const user = {
+          username: 'user',
+          password: 'my super password'
+        }
+
+        loginUtils.getUserAccessToken(server, user, function (err, accessToken) {
+          if (err) throw err
+
+          userAccessToken = accessToken
+
+          next()
+        })
+      }
+    ], done)
+  })
+
+  it('Should fail with an non authenticated user', function (done) {
+    request(server.url)
+      .get(path)
+      .set('Accept', 'application/json')
+      .expect(401, done)
+  })
+
+  it('Should fail with a non admin user', function (done) {
+    request(server.url)
+      .get(path)
+      .set('Authorization', 'Bearer ' + userAccessToken)
+      .set('Accept', 'application/json')
+      .expect(403, done)
+  })
+
+  after(function (done) {
+    process.kill(-server.app.pid)
+
+    // Keep the logs if the test failed
+    if (this.ok) {
+      serversUtils.flushTests(done)
+    } else {
+      done()
+    }
+  })
+})
diff --git a/server/tests/api/check-params/requests.js b/server/tests/api/check-params/requests.js
deleted file mode 100644 (file)
index 0ce5582..0000000
+++ /dev/null
@@ -1,89 +0,0 @@
-/* eslint-disable no-unused-expressions */
-
-'use strict'
-
-const request = require('supertest')
-const series = require('async/series')
-
-const loginUtils = require('../../utils/login')
-const usersUtils = require('../../utils/users')
-const serversUtils = require('../../utils/servers')
-
-describe('Test requests API validators', function () {
-  const path = '/api/v1/requests/stats'
-  let server = null
-  let userAccessToken = null
-
-  // ---------------------------------------------------------------
-
-  before(function (done) {
-    this.timeout(20000)
-
-    series([
-      function (next) {
-        serversUtils.flushTests(next)
-      },
-      function (next) {
-        serversUtils.runServer(1, function (server1) {
-          server = server1
-
-          next()
-        })
-      },
-      function (next) {
-        loginUtils.loginAndGetAccessToken(server, function (err, token) {
-          if (err) throw err
-          server.accessToken = token
-
-          next()
-        })
-      },
-      function (next) {
-        const username = 'user'
-        const password = 'my super password'
-
-        usersUtils.createUser(server.url, server.accessToken, username, password, next)
-      },
-      function (next) {
-        const user = {
-          username: 'user',
-          password: 'my super password'
-        }
-
-        loginUtils.getUserAccessToken(server, user, function (err, accessToken) {
-          if (err) throw err
-
-          userAccessToken = accessToken
-
-          next()
-        })
-      }
-    ], done)
-  })
-
-  it('Should fail with an non authenticated user', function (done) {
-    request(server.url)
-      .get(path)
-      .set('Accept', 'application/json')
-      .expect(401, done)
-  })
-
-  it('Should fail with a non admin user', function (done) {
-    request(server.url)
-      .get(path)
-      .set('Authorization', 'Bearer ' + userAccessToken)
-      .set('Accept', 'application/json')
-      .expect(403, done)
-  })
-
-  after(function (done) {
-    process.kill(-server.app.pid)
-
-    // Keep the logs if the test failed
-    if (this.ok) {
-      serversUtils.flushTests(done)
-    } else {
-      done()
-    }
-  })
-})
index cc86a3d3b84628e8c523f8ae4d03bb35909f1e37..7404d7d88c7cd42c21d2594fb151b210e334f4f3 100644 (file)
@@ -9,6 +9,6 @@ require('./single-pod')
 require('./video-abuse')
 require('./video-blacklist')
 require('./multiple-pods')
-require('./requests')
+require('./request-schedulers')
 require('./friends-advanced')
 require('./video-transcoder')
diff --git a/server/tests/api/request-schedulers.js b/server/tests/api/request-schedulers.js
new file mode 100644 (file)
index 0000000..c5c443f
--- /dev/null
@@ -0,0 +1,111 @@
+/* eslint-disable no-unused-expressions */
+
+'use strict'
+
+const chai = require('chai')
+const each = require('async/each')
+const expect = chai.expect
+const request = require('supertest')
+
+const loginUtils = require('../utils/login')
+const podsUtils = require('../utils/pods')
+const serversUtils = require('../utils/servers')
+const videosUtils = require('../utils/videos')
+
+describe('Test requests schedulers stats', function () {
+  const requestSchedulerNames = [ 'requestScheduler', 'requestVideoQaduScheduler', 'requestVideoEventScheduler' ]
+  const path = '/api/v1/request-schedulers/stats'
+  let servers = []
+
+  function uploadVideo (server, callback) {
+    const videoAttributes = {
+      tags: [ 'tag1', 'tag2' ]
+    }
+
+    videosUtils.uploadVideo(server.url, server.accessToken, videoAttributes, callback)
+  }
+
+  function getRequestsStats (server, callback) {
+    request(server.url)
+      .get(path)
+      .set('Accept', 'application/json')
+      .set('Authorization', 'Bearer ' + server.accessToken)
+      .expect(200)
+      .end(callback)
+  }
+
+  // ---------------------------------------------------------------
+
+  before(function (done) {
+    this.timeout(20000)
+    serversUtils.flushAndRunMultipleServers(2, function (serversRun, urlsRun) {
+      servers = serversRun
+
+      each(servers, function (server, callbackEach) {
+        loginUtils.loginAndGetAccessToken(server, function (err, accessToken) {
+          if (err) return callbackEach(err)
+
+          server.accessToken = accessToken
+          callbackEach()
+        })
+      }, function (err) {
+        if (err) throw err
+
+        const server1 = servers[0]
+        podsUtils.makeFriends(server1.url, server1.accessToken, done)
+      })
+    })
+  })
+
+  it('Should have a correct timer', function (done) {
+    const server = servers[0]
+
+    getRequestsStats(server, function (err, res) {
+      if (err) throw err
+
+      const requestSchedulers = res.body
+      for (const requestSchedulerName of requestSchedulerNames) {
+        const requestScheduler = requestSchedulers[requestSchedulerName]
+
+        expect(requestScheduler.remainingMilliSeconds).to.be.at.least(0)
+        expect(requestScheduler.remainingMilliSeconds).to.be.at.most(10000)
+      }
+
+      done()
+    })
+  })
+
+  it('Should have the correct total request', function (done) {
+    this.timeout(15000)
+
+    const server = servers[0]
+    // Ensure the requests of pod 1 won't be made
+    servers[1].app.kill()
+
+    uploadVideo(server, function (err) {
+      if (err) throw err
+
+      setTimeout(function () {
+        getRequestsStats(server, function (err, res) {
+          if (err) throw err
+
+          const requestSchedulers = res.body
+          const requestScheduler = requestSchedulers.requestScheduler
+          expect(requestScheduler.totalRequests).to.equal(1)
+
+          done()
+        })
+      }, 1000)
+    })
+  })
+
+  after(function (done) {
+    process.kill(-servers[0].app.pid)
+
+    if (this.ok) {
+      serversUtils.flushTests(done)
+    } else {
+      done()
+    }
+  })
+})
diff --git a/server/tests/api/requests.js b/server/tests/api/requests.js
deleted file mode 100644 (file)
index 8762163..0000000
+++ /dev/null
@@ -1,111 +0,0 @@
-/* eslint-disable no-unused-expressions */
-
-'use strict'
-
-const chai = require('chai')
-const each = require('async/each')
-const expect = chai.expect
-const request = require('supertest')
-
-const loginUtils = require('../utils/login')
-const podsUtils = require('../utils/pods')
-const serversUtils = require('../utils/servers')
-const videosUtils = require('../utils/videos')
-
-describe('Test requests stats', function () {
-  const requestSchedulerNames = [ 'requestScheduler', 'requestVideoQaduScheduler', 'requestVideoEventScheduler' ]
-  const path = '/api/v1/requests/stats'
-  let servers = []
-
-  function uploadVideo (server, callback) {
-    const videoAttributes = {
-      tags: [ 'tag1', 'tag2' ]
-    }
-
-    videosUtils.uploadVideo(server.url, server.accessToken, videoAttributes, callback)
-  }
-
-  function getRequestsStats (server, callback) {
-    request(server.url)
-      .get(path)
-      .set('Accept', 'application/json')
-      .set('Authorization', 'Bearer ' + server.accessToken)
-      .expect(200)
-      .end(callback)
-  }
-
-  // ---------------------------------------------------------------
-
-  before(function (done) {
-    this.timeout(20000)
-    serversUtils.flushAndRunMultipleServers(2, function (serversRun, urlsRun) {
-      servers = serversRun
-
-      each(servers, function (server, callbackEach) {
-        loginUtils.loginAndGetAccessToken(server, function (err, accessToken) {
-          if (err) return callbackEach(err)
-
-          server.accessToken = accessToken
-          callbackEach()
-        })
-      }, function (err) {
-        if (err) throw err
-
-        const server1 = servers[0]
-        podsUtils.makeFriends(server1.url, server1.accessToken, done)
-      })
-    })
-  })
-
-  it('Should have a correct timer', function (done) {
-    const server = servers[0]
-
-    getRequestsStats(server, function (err, res) {
-      if (err) throw err
-
-      const requestSchedulers = res.body
-      for (const requestSchedulerName of requestSchedulerNames) {
-        const requestScheduler = requestSchedulers[requestSchedulerName]
-
-        expect(requestScheduler.remainingMilliSeconds).to.be.at.least(0)
-        expect(requestScheduler.remainingMilliSeconds).to.be.at.most(10000)
-      }
-
-      done()
-    })
-  })
-
-  it('Should have the correct total request', function (done) {
-    this.timeout(15000)
-
-    const server = servers[0]
-    // Ensure the requests of pod 1 won't be made
-    servers[1].app.kill()
-
-    uploadVideo(server, function (err) {
-      if (err) throw err
-
-      setTimeout(function () {
-        getRequestsStats(server, function (err, res) {
-          if (err) throw err
-
-          const requestSchedulers = res.body
-          const requestScheduler = requestSchedulers.requestScheduler
-          expect(requestScheduler.totalRequests).to.equal(1)
-
-          done()
-        })
-      }, 1000)
-    })
-  })
-
-  after(function (done) {
-    process.kill(-servers[0].app.pid)
-
-    if (this.ok) {
-      serversUtils.flushTests(done)
-    } else {
-      done()
-    }
-  })
-})
index 3ac13f053f3ddb4f90ce7b1e2880aa86fa2cf9b6..ea189c5f2089f7f4330f19004115f431fda1ba52 100644 (file)
@@ -13,7 +13,7 @@ const loginUtils = require('../utils/login')
 const podsUtils = require('../utils/pods')
 const serversUtils = require('../utils/servers')
 const videosUtils = require('../utils/videos')
-const requestStatsUtils = require('../utils/requests-stats')
+const requestSchedulersUtils = require('../utils/request-schedulers')
 
 program
   .option('-c, --create [weight]', 'Weight for creating videos')
@@ -344,7 +344,7 @@ function isThereAwaitingRequests (servers, callback) {
 
   // Check is each server has awaiting requestq
   each(servers, function (server, callbackEach) {
-    requestStatsUtils.getRequestsStats(server, server.accessToken, function (err, res) {
+    requestSchedulersUtils.getRequestsStats(server, server.accessToken, function (err, res) {
       if (err) throw err
 
       const stats = res.body
diff --git a/server/tests/utils/request-schedulers.js b/server/tests/utils/request-schedulers.js
new file mode 100644 (file)
index 0000000..16835ce
--- /dev/null
@@ -0,0 +1,25 @@
+'use strict'
+
+const request = require('supertest')
+
+const requestsStatsUtils = {
+  getRequestsStats
+}
+
+// ---------------------- Export functions --------------------
+
+function getRequestsStats (server, accessToken, callback) {
+  const path = '/api/v1/requests/stats'
+
+  request(server.url)
+    .get(path)
+    .set('Accept', 'application/json')
+    .set('Authorization', 'Bearer ' + accessToken)
+    .expect(200)
+    .expect('Content-Type', /json/)
+    .end(callback)
+}
+
+// ---------------------------------------------------------------------------
+
+module.exports = requestsStatsUtils
diff --git a/server/tests/utils/requests-stats.js b/server/tests/utils/requests-stats.js
deleted file mode 100644 (file)
index 16835ce..0000000
+++ /dev/null
@@ -1,25 +0,0 @@
-'use strict'
-
-const request = require('supertest')
-
-const requestsStatsUtils = {
-  getRequestsStats
-}
-
-// ---------------------- Export functions --------------------
-
-function getRequestsStats (server, accessToken, callback) {
-  const path = '/api/v1/requests/stats'
-
-  request(server.url)
-    .get(path)
-    .set('Accept', 'application/json')
-    .set('Authorization', 'Bearer ' + accessToken)
-    .expect(200)
-    .expect('Content-Type', /json/)
-    .end(callback)
-}
-
-// ---------------------------------------------------------------------------
-
-module.exports = requestsStatsUtils
index f94ccfcabdf0b4850d3d34bfd59a9b69718c5446..8df184a09563c6df7c2661897261e55bcfca4b91 100644 (file)
@@ -4,7 +4,7 @@ export type RequestVideoQaduType = 'likes' | 'dislikes' | 'views'
 
 export type RequestVideoEventType = 'likes' | 'dislikes' | 'views'
 
-export type RequestSchedulerAttributes = {
+export type RequestSchedulerStatsAttributes = {
   totalRequests: number
   requestsLimitPods: number
   requestsLimitPerPod: number
@@ -12,8 +12,8 @@ export type RequestSchedulerAttributes = {
   milliSecondsInterval: number
 }
 
-export interface RequestScheduler {
-  requestScheduler: RequestSchedulerAttributes
-  requestVideoQaduScheduler: RequestSchedulerAttributes
-  requestVideoEventScheduler: RequestSchedulerAttributes
+export interface RequestSchedulerStats {
+  requestScheduler: RequestSchedulerStatsAttributes
+  requestVideoQaduScheduler: RequestSchedulerStatsAttributes
+  requestVideoEventScheduler: RequestSchedulerStatsAttributes
 }