]> git.apps.os.sepia.ceph.com Git - ceph.git/blob
3e0f44f958a83ccac4140f2f1235c8e71f5c080b
[ceph.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       this.totalMemory = this.dimlessBinary.transform(this.totalMemory);
77
78       this.uniqueServices.forEach((serviceType) => {
79         this.hostsCountPerService.push({
80           service_type: serviceType,
81           hosts_per_service: this.serviceOccurrences[serviceType]
82         });
83       });
84
85       this.hostsByService['data'] = [...this.hostsCountPerService];
86     });
87
88     this.hostService.list('true').subscribe((resp: object[]) => {
89       this.hosts = resp;
90       this.hostsCount = this.hosts.length;
91       _.forEach(this.hosts, (hostKey) => {
92         this.totalCPUs = this.totalCPUs + hostKey['cpu_count'];
93         // convert to bytes
94         this.totalMemory = this.totalMemory + hostKey['memory_total_kb'] * 1024;
95       });
96       this.totalMemory = this.dimlessBinary.transform(this.totalMemory);
97     });
98
99     if (this.osdService.osdDevices['data']) {
100       dataDevices = this.osdService.osdDevices['data']?.length;
101       dataDeviceCapacity = this.osdService.osdDevices['data']['capacity'];
102     }
103
104     if (this.osdService.osdDevices['wal']) {
105       walDevices = this.osdService.osdDevices['wal']?.length;
106       walDeviceCapacity = this.osdService.osdDevices['wal']['capacity'];
107     }
108
109     if (this.osdService.osdDevices['db']) {
110       dbDevices = this.osdService.osdDevices['db']?.length;
111       dbDeviceCapacity = this.osdService.osdDevices['db']['capacity'];
112     }
113
114     this.totalDevices = dataDevices + walDevices + dbDevices;
115     this.osdService.osdDevices['totalDevices'] = this.totalDevices;
116     this.totalCapacity = dataDeviceCapacity + walDeviceCapacity + dbDeviceCapacity;
117   }
118 }