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']);
77 this.uniqueServices.forEach((serviceType) => {
78 this.hostsCountPerService.push({
79 service_type: serviceType,
80 hosts_per_service: this.serviceOccurrences[serviceType]
84 this.hostsByService['data'] = [...this.hostsCountPerService];
87 this.hostService.list('true').subscribe((resp: object[]) => {
89 this.hostsCount = this.hosts.length;
90 _.forEach(this.hosts, (hostKey) => {
91 this.totalCPUs = this.totalCPUs + hostKey['cpu_count'];
93 this.totalMemory = this.totalMemory + hostKey['memory_total_kb'] * 1024;
95 this.totalMemory = this.dimlessBinary.transform(this.totalMemory);
98 if (this.osdService.osdDevices['data']) {
99 dataDevices = this.osdService.osdDevices['data']?.length;
100 dataDeviceCapacity = this.osdService.osdDevices['data']['capacity'];
103 if (this.osdService.osdDevices['wal']) {
104 walDevices = this.osdService.osdDevices['wal']?.length;
105 walDeviceCapacity = this.osdService.osdDevices['wal']['capacity'];
108 if (this.osdService.osdDevices['db']) {
109 dbDevices = this.osdService.osdDevices['db']?.length;
110 dbDeviceCapacity = this.osdService.osdDevices['db']['capacity'];
113 this.totalDevices = dataDevices + walDevices + dbDevices;
114 this.osdService.osdDevices['totalDevices'] = this.totalDevices;
115 this.totalCapacity = dataDeviceCapacity + walDeviceCapacity + dbDeviceCapacity;