]>
Commit | Line | Data |
---|---|---|
f6b5b4d7 | 1 | import { HttpClient } from '@angular/common/http'; |
11fdf7f2 TL |
2 | import { Injectable } from '@angular/core'; |
3 | ||
4 | import { I18n } from '@ngx-translate/i18n-polyfill'; | |
9f95a23c | 5 | import { map } from 'rxjs/operators'; |
11fdf7f2 | 6 | |
9f95a23c TL |
7 | import * as _ from 'lodash'; |
8 | import { CdDevice } from '../models/devices'; | |
9 | import { SmartDataResponseV1 } from '../models/smart'; | |
10 | import { DeviceService } from '../services/device.service'; | |
11fdf7f2 TL |
11 | import { ApiModule } from './api.module'; |
12 | ||
13 | @Injectable({ | |
14 | providedIn: ApiModule | |
15 | }) | |
16 | export class OsdService { | |
17 | private path = 'api/osd'; | |
18 | ||
19 | osdRecvSpeedModalPriorities = { | |
20 | KNOWN_PRIORITIES: [ | |
21 | { | |
22 | name: null, | |
23 | text: this.i18n('-- Select the priority --'), | |
24 | values: { | |
25 | osd_max_backfills: null, | |
26 | osd_recovery_max_active: null, | |
27 | osd_recovery_max_single_start: null, | |
28 | osd_recovery_sleep: null | |
29 | } | |
30 | }, | |
31 | { | |
32 | name: 'low', | |
33 | text: this.i18n('Low'), | |
34 | values: { | |
35 | osd_max_backfills: 1, | |
36 | osd_recovery_max_active: 1, | |
37 | osd_recovery_max_single_start: 1, | |
38 | osd_recovery_sleep: 0.5 | |
39 | } | |
40 | }, | |
41 | { | |
42 | name: 'default', | |
43 | text: this.i18n('Default'), | |
44 | values: { | |
45 | osd_max_backfills: 1, | |
46 | osd_recovery_max_active: 3, | |
47 | osd_recovery_max_single_start: 1, | |
48 | osd_recovery_sleep: 0 | |
49 | } | |
50 | }, | |
51 | { | |
52 | name: 'high', | |
53 | text: this.i18n('High'), | |
54 | values: { | |
55 | osd_max_backfills: 4, | |
56 | osd_recovery_max_active: 4, | |
57 | osd_recovery_max_single_start: 4, | |
58 | osd_recovery_sleep: 0 | |
59 | } | |
60 | } | |
61 | ] | |
62 | }; | |
63 | ||
9f95a23c TL |
64 | constructor(private http: HttpClient, private i18n: I18n, private deviceService: DeviceService) {} |
65 | ||
66 | create(driveGroups: Object[]) { | |
67 | const request = { | |
68 | method: 'drive_groups', | |
69 | data: driveGroups, | |
70 | tracking_id: _.join(_.map(driveGroups, 'service_id'), ', ') | |
71 | }; | |
72 | return this.http.post(this.path, request, { observe: 'response' }); | |
73 | } | |
11fdf7f2 TL |
74 | |
75 | getList() { | |
76 | return this.http.get(`${this.path}`); | |
77 | } | |
78 | ||
79 | getDetails(id: number) { | |
9f95a23c TL |
80 | interface OsdData { |
81 | osd_map: { [key: string]: any }; | |
82 | osd_metadata: { [key: string]: any }; | |
83 | histogram: { [key: string]: object }; | |
84 | smart: { [device_identifier: string]: any }; | |
85 | } | |
86 | return this.http.get<OsdData>(`${this.path}/${id}`); | |
87 | } | |
88 | ||
89 | /** | |
90 | * @param id OSD ID | |
91 | */ | |
92 | getSmartData(id: number) { | |
93 | return this.http.get<SmartDataResponseV1>(`${this.path}/${id}/smart`); | |
11fdf7f2 TL |
94 | } |
95 | ||
9f95a23c | 96 | scrub(id: string, deep: boolean) { |
11fdf7f2 TL |
97 | return this.http.post(`${this.path}/${id}/scrub?deep=${deep}`, null); |
98 | } | |
99 | ||
100 | getFlags() { | |
101 | return this.http.get(`${this.path}/flags`); | |
102 | } | |
103 | ||
104 | updateFlags(flags: string[]) { | |
105 | return this.http.put(`${this.path}/flags`, { flags: flags }); | |
106 | } | |
107 | ||
108 | markOut(id: number) { | |
109 | return this.http.post(`${this.path}/${id}/mark_out`, null); | |
110 | } | |
111 | ||
112 | markIn(id: number) { | |
113 | return this.http.post(`${this.path}/${id}/mark_in`, null); | |
114 | } | |
115 | ||
116 | markDown(id: number) { | |
117 | return this.http.post(`${this.path}/${id}/mark_down`, null); | |
118 | } | |
119 | ||
120 | reweight(id: number, weight: number) { | |
121 | return this.http.post(`${this.path}/${id}/reweight`, { weight: weight }); | |
122 | } | |
123 | ||
9f95a23c TL |
124 | update(id: number, deviceClass: string) { |
125 | return this.http.put(`${this.path}/${id}`, { device_class: deviceClass }); | |
126 | } | |
127 | ||
11fdf7f2 TL |
128 | markLost(id: number) { |
129 | return this.http.post(`${this.path}/${id}/mark_lost`, null); | |
130 | } | |
131 | ||
132 | purge(id: number) { | |
133 | return this.http.post(`${this.path}/${id}/purge`, null); | |
134 | } | |
135 | ||
136 | destroy(id: number) { | |
137 | return this.http.post(`${this.path}/${id}/destroy`, null); | |
138 | } | |
139 | ||
f6b5b4d7 TL |
140 | delete(id: number, preserveId?: boolean, force?: boolean) { |
141 | const params = { | |
142 | preserve_id: preserveId ? 'true' : 'false', | |
143 | force: force ? 'true' : 'false' | |
144 | }; | |
145 | return this.http.delete(`${this.path}/${id}`, { observe: 'response', params: params }); | |
9f95a23c TL |
146 | } |
147 | ||
148 | safeToDestroy(ids: string) { | |
11fdf7f2 | 149 | interface SafeToDestroyResponse { |
9f95a23c | 150 | is_safe_to_destroy: boolean; |
11fdf7f2 TL |
151 | message?: string; |
152 | } | |
9f95a23c TL |
153 | return this.http.get<SafeToDestroyResponse>(`${this.path}/safe_to_destroy?ids=${ids}`); |
154 | } | |
155 | ||
156 | safeToDelete(ids: string) { | |
157 | interface SafeToDeleteResponse { | |
158 | is_safe_to_delete: boolean; | |
159 | message?: string; | |
160 | } | |
161 | return this.http.get<SafeToDeleteResponse>(`${this.path}/safe_to_delete?svc_ids=${ids}`); | |
162 | } | |
163 | ||
164 | getDevices(osdId: number) { | |
165 | return this.http | |
166 | .get<CdDevice[]>(`${this.path}/${osdId}/devices`) | |
167 | .pipe(map((devices) => devices.map((device) => this.deviceService.prepareDevice(device)))); | |
11fdf7f2 TL |
168 | } |
169 | } |