]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/blob
8960f399a77eba445133d32ec5fcd4c6318778c5
[ceph-ci.git] /
1 import { Component, OnInit } from '@angular/core';
2
3 import _ from 'lodash';
4
5 import { CephServiceService } from '~/app/shared/api/ceph-service.service';
6 import { HostService } from '~/app/shared/api/host.service';
7 import { OsdService } from '~/app/shared/api/osd.service';
8 import { CellTemplate } from '~/app/shared/enum/cell-template.enum';
9 import { CephServiceSpec } from '~/app/shared/models/service.interface';
10 import { DimlessBinaryPipe } from '~/app/shared/pipes/dimless-binary.pipe';
11 import { WizardStepsService } from '~/app/shared/services/wizard-steps.service';
12
13 @Component({
14   selector: 'cd-create-cluster-review',
15   templateUrl: './create-cluster-review.component.html',
16   styleUrls: ['./create-cluster-review.component.scss']
17 })
18 export class CreateClusterReviewComponent implements OnInit {
19   hosts: object[] = [];
20   hostsByService: object;
21   hostsCount: number;
22   serviceCount: number;
23   serviceOccurrences = {};
24   hostsCountPerService: object[] = [];
25   uniqueServices: Set<string> = new Set();
26   totalDevices: number;
27   totalCapacity = 0;
28   services: Array<CephServiceSpec> = [];
29   totalCPUs = 0;
30   totalMemory = 0;
31
32   constructor(
33     public wizardStepsService: WizardStepsService,
34     public cephServiceService: CephServiceService,
35     private dimlessBinary: DimlessBinaryPipe,
36     public hostService: HostService,
37     private osdService: OsdService
38   ) {}
39
40   ngOnInit() {
41     let dataDevices = 0;
42     let dataDeviceCapacity = 0;
43     let walDevices = 0;
44     let walDeviceCapacity = 0;
45     let dbDevices = 0;
46     let dbDeviceCapacity = 0;
47
48     this.hostsByService = {
49       columns: [
50         {
51           prop: 'service_type',
52           name: $localize`Services`,
53           flexGrow: 1,
54           cellTransformation: CellTemplate.badge,
55           customTemplateConfig: {
56             class: 'badge-dark'
57           }
58         },
59         {
60           name: $localize`Number of Hosts`,
61           prop: 'hosts_per_service',
62           flexGrow: 1
63         }
64       ]
65     };
66
67     this.cephServiceService.list().subscribe((resp: Array<CephServiceSpec>) => {
68       this.services = resp;
69       this.serviceCount = this.services.length;
70
71       _.forEach(this.services, (serviceKey) => {
72         this.serviceOccurrences[serviceKey['service_type']] =
73           (this.serviceOccurrences[serviceKey['service_type']] || 0) + 1;
74         this.uniqueServices.add(serviceKey['service_type']);
75       });
76
77       this.uniqueServices.forEach((serviceType) => {
78         this.hostsCountPerService.push({
79           service_type: serviceType,
80           hosts_per_service: this.serviceOccurrences[serviceType]
81         });
82       });
83
84       this.hostsByService['data'] = [...this.hostsCountPerService];
85     });
86
87     this.hostService.list('true').subscribe((resp: object[]) => {
88       this.hosts = resp;
89       this.hostsCount = this.hosts.length;
90       _.forEach(this.hosts, (hostKey) => {
91         this.totalCPUs = this.totalCPUs + hostKey['cpu_count'];
92         // convert to bytes
93         this.totalMemory = this.totalMemory + hostKey['memory_total_kb'] * 1024;
94       });
95       this.totalMemory = this.dimlessBinary.transform(this.totalMemory);
96     });
97
98     if (this.osdService.osdDevices['data']) {
99       dataDevices = this.osdService.osdDevices['data']?.length;
100       dataDeviceCapacity = this.osdService.osdDevices['data']['capacity'];
101     }
102
103     if (this.osdService.osdDevices['wal']) {
104       walDevices = this.osdService.osdDevices['wal']?.length;
105       walDeviceCapacity = this.osdService.osdDevices['wal']['capacity'];
106     }
107
108     if (this.osdService.osdDevices['db']) {
109       dbDevices = this.osdService.osdDevices['db']?.length;
110       dbDeviceCapacity = this.osdService.osdDevices['db']['capacity'];
111     }
112
113     this.totalDevices = dataDevices + walDevices + dbDevices;
114     this.osdService.osdDevices['totalDevices'] = this.totalDevices;
115     this.totalCapacity = dataDeviceCapacity + walDeviceCapacity + dbDeviceCapacity;
116   }
117 }