1 import { Component, OnInit } from '@angular/core';
3 import _ from 'lodash';
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';
14 selector: 'cd-create-cluster-review',
15 templateUrl: './create-cluster-review.component.html',
16 styleUrls: ['./create-cluster-review.component.scss']
18 export class CreateClusterReviewComponent implements OnInit {
20 hostsByService: object;
23 serviceOccurrences = {};
24 hostsCountPerService: object[] = [];
25 uniqueServices: Set<string> = new Set();
28 services: Array<CephServiceSpec> = [];
33 public wizardStepsService: WizardStepsService,
34 public cephServiceService: CephServiceService,
35 private dimlessBinary: DimlessBinaryPipe,
36 public hostService: HostService,
37 private osdService: OsdService
42 let dataDeviceCapacity = 0;
44 let walDeviceCapacity = 0;
46 let dbDeviceCapacity = 0;
48 this.hostsByService = {
52 name: $localize`Services`,
54 cellTransformation: CellTemplate.badge,
55 customTemplateConfig: {
60 name: $localize`Number of Hosts`,
61 prop: 'hosts_per_service',
67 this.cephServiceService.list().subscribe((resp: Array<CephServiceSpec>) => {
69 this.serviceCount = this.services.length;
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']);
76 this.totalMemory = this.dimlessBinary.transform(this.totalMemory);
78 this.uniqueServices.forEach((serviceType) => {
79 this.hostsCountPerService.push({
80 service_type: serviceType,
81 hosts_per_service: this.serviceOccurrences[serviceType]
85 this.hostsByService['data'] = [...this.hostsCountPerService];
88 this.hostService.list('true').subscribe((resp: object[]) => {
90 this.hostsCount = this.hosts.length;
91 _.forEach(this.hosts, (hostKey) => {
92 this.totalCPUs = this.totalCPUs + hostKey['cpu_count'];
94 this.totalMemory = this.totalMemory + hostKey['memory_total_kb'] * 1024;
96 this.totalMemory = this.dimlessBinary.transform(this.totalMemory);
99 if (this.osdService.osdDevices['data']) {
100 dataDevices = this.osdService.osdDevices['data']?.length;
101 dataDeviceCapacity = this.osdService.osdDevices['data']['capacity'];
104 if (this.osdService.osdDevices['wal']) {
105 walDevices = this.osdService.osdDevices['wal']?.length;
106 walDeviceCapacity = this.osdService.osdDevices['wal']['capacity'];
109 if (this.osdService.osdDevices['db']) {
110 dbDevices = this.osdService.osdDevices['db']?.length;
111 dbDeviceCapacity = this.osdService.osdDevices['db']['capacity'];
114 this.totalDevices = dataDevices + walDevices + dbDevices;
115 this.osdService.osdDevices['totalDevices'] = this.totalDevices;
116 this.totalCapacity = dataDeviceCapacity + walDeviceCapacity + dbDeviceCapacity;