]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/blob
c65782769a4c681ba0245d31590865ac89536477
[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 { CdTableFetchDataContext } from '~/app/shared/models/cd-table-fetch-data-context';
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   hostsCount: number;
21   totalDevices: number;
22   totalCapacity = 0;
23   services: Array<CephServiceSpec> = [];
24   totalCPUs = 0;
25   totalMemory = 0;
26   deploymentDescText: string = '-';
27   isSimpleDeployment = true;
28
29   constructor(
30     public wizardStepsService: WizardStepsService,
31     public cephServiceService: CephServiceService,
32     private dimlessBinary: DimlessBinaryPipe,
33     public hostService: HostService,
34     private osdService: OsdService
35   ) {}
36
37   ngOnInit() {
38     let dataDevices = 0;
39     let dataDeviceCapacity = 0;
40     let walDevices = 0;
41     let walDeviceCapacity = 0;
42     let dbDevices = 0;
43     let dbDeviceCapacity = 0;
44
45     this.isSimpleDeployment = this.osdService.isDeployementModeSimple;
46     const hostContext = new CdTableFetchDataContext(() => undefined);
47     this.hostService.list(hostContext.toParams(), 'true').subscribe((resp: object[]) => {
48       this.hosts = resp;
49       this.hostsCount = this.hosts.length;
50       _.forEach(this.hosts, (hostKey) => {
51         this.totalCPUs = this.totalCPUs + hostKey['cpu_count'];
52         // convert to bytes
53         this.totalMemory = this.totalMemory + hostKey['memory_total_kb'] * 1024;
54       });
55       this.totalMemory = this.dimlessBinary.transform(this.totalMemory);
56     });
57
58     if (this.osdService.osdDevices['data']) {
59       dataDevices = this.osdService.osdDevices['data']?.length;
60       dataDeviceCapacity = this.osdService.osdDevices['data']['capacity'];
61     }
62
63     if (this.osdService.osdDevices['wal']) {
64       walDevices = this.osdService.osdDevices['wal']?.length;
65       walDeviceCapacity = this.osdService.osdDevices['wal']['capacity'];
66     }
67
68     if (this.osdService.osdDevices['db']) {
69       dbDevices = this.osdService.osdDevices['db']?.length;
70       dbDeviceCapacity = this.osdService.osdDevices['db']['capacity'];
71     }
72
73     if (this.isSimpleDeployment) {
74       this.osdService.getDeploymentOptions().subscribe((optionsObj) => {
75         if (!_.isEmpty(optionsObj)) {
76           Object.keys(optionsObj.options).forEach((option) => {
77             if (
78               this.osdService.selectedFormValues &&
79               this.osdService.selectedFormValues.get('deploymentOption').value === option
80             ) {
81               this.deploymentDescText = optionsObj.options[option].desc;
82             }
83           });
84         }
85       });
86     }
87
88     this.totalDevices = dataDevices + walDevices + dbDevices;
89     this.osdService.osdDevices['totalDevices'] = this.totalDevices;
90     this.totalCapacity = dataDeviceCapacity + walDeviceCapacity + dbDeviceCapacity;
91   }
92 }