]> git.apps.os.sepia.ceph.com Git - ceph.git/blob
041915186c05ed928d41b6c8941b8b4ce3fd2029
[ceph.git] /
1 import { Component, EventEmitter, Output } from '@angular/core';
2 import { FormControl, Validators } from '@angular/forms';
3 import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
4 import { RgwMultisiteService } from '~/app/shared/api/rgw-multisite.service';
5 import { RgwRealmService } from '~/app/shared/api/rgw-realm.service';
6 import { RgwZoneService } from '~/app/shared/api/rgw-zone.service';
7 import { RgwZonegroupService } from '~/app/shared/api/rgw-zonegroup.service';
8 import { ActionLabelsI18n } from '~/app/shared/constants/app.constants';
9 import { CdFormGroup } from '~/app/shared/forms/cd-form-group';
10 import { ModalService } from '~/app/shared/services/modal.service';
11 import { NotificationService } from '~/app/shared/services/notification.service';
12 import { RgwRealm, RgwZonegroup, RgwZone, SystemKey } from '../models/rgw-multisite';
13 import { NotificationType } from '~/app/shared/enum/notification-type.enum';
14 import { Subscription } from 'rxjs';
15
16 @Component({
17   selector: 'cd-create-rgw-service-entities',
18   templateUrl: './create-rgw-service-entities.component.html',
19   styleUrls: ['./create-rgw-service-entities.component.scss']
20 })
21 export class CreateRgwServiceEntitiesComponent {
22   public sub = new Subscription();
23   createMultisiteEntitiesForm: CdFormGroup;
24   realm: RgwRealm;
25   zonegroup: RgwZonegroup;
26   zone: RgwZone;
27
28   @Output()
29   submitAction = new EventEmitter();
30
31   constructor(
32     public activeModal: NgbActiveModal,
33     public actionLabels: ActionLabelsI18n,
34     public rgwMultisiteService: RgwMultisiteService,
35     public rgwZoneService: RgwZoneService,
36     public notificationService: NotificationService,
37     public rgwZonegroupService: RgwZonegroupService,
38     public rgwRealmService: RgwRealmService,
39     public modalService: ModalService
40   ) {
41     this.createForm();
42   }
43
44   createForm() {
45     this.createMultisiteEntitiesForm = new CdFormGroup({
46       realmName: new FormControl(null, {
47         validators: [Validators.required]
48       }),
49       zonegroupName: new FormControl(null, {
50         validators: [Validators.required]
51       }),
52       zoneName: new FormControl(null, {
53         validators: [Validators.required]
54       })
55     });
56   }
57
58   submit() {
59     const values = this.createMultisiteEntitiesForm.value;
60     this.realm = new RgwRealm();
61     this.realm.name = values['realmName'];
62     this.zonegroup = new RgwZonegroup();
63     this.zonegroup.name = values['zonegroupName'];
64     this.zonegroup.endpoints = '';
65     this.zone = new RgwZone();
66     this.zone.name = values['zoneName'];
67     this.zone.endpoints = '';
68     this.zone.system_key = new SystemKey();
69     this.zone.system_key.access_key = '';
70     this.zone.system_key.secret_key = '';
71     this.rgwRealmService
72       .create(this.realm, true)
73       .toPromise()
74       .then(() => {
75         this.rgwZonegroupService
76           .create(this.realm, this.zonegroup, true, true)
77           .toPromise()
78           .then(() => {
79             this.rgwZoneService
80               .create(this.zone, this.zonegroup, true, true, this.zone.endpoints)
81               .toPromise()
82               .then(() => {
83                 this.notificationService.show(
84                   NotificationType.success,
85                   $localize`Realm/Zonegroup/Zone created successfully`
86                 );
87                 this.submitAction.emit();
88                 this.activeModal.close();
89               })
90               .catch(() => {
91                 this.notificationService.show(
92                   NotificationType.error,
93                   $localize`Realm/Zonegroup/Zone creation failed`
94                 );
95               });
96           });
97       });
98   }
99 }