]> git.proxmox.com Git - ceph.git/blame - ceph/src/pybind/mgr/dashboard/frontend/src/app/ceph/shared/pg-category.service.ts
import ceph quincy 17.2.1
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / src / app / ceph / shared / pg-category.service.ts
CommitLineData
11fdf7f2
TL
1import { Injectable } from '@angular/core';
2
f67539c2 3import _ from 'lodash';
11fdf7f2
TL
4
5import { CephSharedModule } from './ceph-shared.module';
6import { PgCategory } from './pg-category.model';
7
8@Injectable({
9 providedIn: CephSharedModule
10})
11export class PgCategoryService {
12 private categories: object;
13
14 constructor() {
15 this.categories = this.createCategories();
16 }
17
18 getAllTypes() {
19 return PgCategory.VALID_CATEGORIES;
20 }
21
22 getTypeByStates(pgStatesText: string): string {
23 const pgStates = this.getPgStatesFromText(pgStatesText);
24
25 if (pgStates.length === 0) {
26 return PgCategory.CATEGORY_UNKNOWN;
27 }
28
29 const intersections = _.zipObject(
30 PgCategory.VALID_CATEGORIES,
31 PgCategory.VALID_CATEGORIES.map(
32 (category) => _.intersection(this.categories[category].states, pgStates).length
33 )
34 );
35
36 if (intersections[PgCategory.CATEGORY_WARNING] > 0) {
37 return PgCategory.CATEGORY_WARNING;
38 }
39
40 const pgWorkingStates = intersections[PgCategory.CATEGORY_WORKING];
41 if (pgStates.length > intersections[PgCategory.CATEGORY_CLEAN] + pgWorkingStates) {
42 return PgCategory.CATEGORY_UNKNOWN;
43 }
44
45 return pgWorkingStates ? PgCategory.CATEGORY_WORKING : PgCategory.CATEGORY_CLEAN;
46 }
47
48 private createCategories() {
49 return _.zipObject(
50 PgCategory.VALID_CATEGORIES,
51 PgCategory.VALID_CATEGORIES.map((category) => new PgCategory(category))
52 );
53 }
54
9f95a23c 55 private getPgStatesFromText(pgStatesText: string) {
11fdf7f2 56 const pgStates = pgStatesText
33c7a0ef 57 .replace(/[^a-z_]+/g, ' ')
11fdf7f2
TL
58 .trim()
59 .split(' ');
60
61 return _.uniq(pgStates);
62 }
63}