blob: 05ac971340bed3a68d3aa258cf4e6f1fbf3346f7 [file] [log] [blame]
Matteo Scandolod3cd3b12018-03-22 16:59:48 -07001
2/*
3 * Copyright 2017-present Open Networking Foundation
4
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8
9 * http://www.apache.org/licenses/LICENSE-2.0
10
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18import {IXosAppConfig} from '../../../index';
19import IHttpPromise = angular.IHttpPromise;
20
21interface IXosServiceStatus {
22 name: string;
23 state: 'load' | 'unload' | 'present';
24 version: string;
25}
26
27interface IXosServiceStatusResponse {
28 model_output: string;
29 model_status: number;
30 services: IXosServiceStatus[];
31}
32
33class XosServiceStatusController {
34
35 static $inject = [
36 '$log',
37 '$http',
38 '$interval',
39 'AppConfig'
40 ];
41
42 public services: IXosServiceStatus[] = [];
43 public error: boolean;
44 public loaded: boolean = false;
45
46 constructor (
47 private $log: angular.ILogService,
48 private $http: angular.IHttpService,
49 private $interval: ng.IIntervalService,
50 private AppConfig: IXosAppConfig,
51 ) {
52 this.$interval(() => {
53 this.getServiceStatus()
54 .then(res => {
55 this.services = res.data.services;
56 this.loaded = true;
57 })
58 .catch(e => {
59 this.error = true;
60 this.$log.error(`[XosServiceStatus] Cannot read status from the backend`, e);
61 });
62 }, 10 * 1000);
63 }
64
65 private getServiceStatus(): IHttpPromise<IXosServiceStatusResponse> {
66 return this.$http.get(`${this.AppConfig.apiEndpoint}/dynamicload/load_status`);
67 }
68}
69
70export const xosServiceStatus: angular.IComponentOptions = {
71 template: require('./service-status.html'),
72 controllerAs: 'vm',
73 controller: XosServiceStatusController,
74};