1 import { Component, OnInit } from '@angular/core';
2 import { FormControl, Validators } from '@angular/forms';
3 import { ActionLabelsI18n } from '~/app/shared/constants/app.constants';
4 import { CdForm } from '~/app/shared/forms/cd-form';
5 import { CdFormBuilder } from '~/app/shared/forms/cd-form-builder';
6 import { CdFormGroup } from '~/app/shared/forms/cd-form-group';
7 import _ from 'lodash';
8 import { Router } from '@angular/router';
9 import { RgwStorageClassService } from '~/app/shared/api/rgw-storage-class.service';
10 import { RgwZonegroupService } from '~/app/shared/api/rgw-zonegroup.service';
18 } from '../models/rgw-storage-class.model';
19 import { NotificationType } from '~/app/shared/enum/notification-type.enum';
20 import { NotificationService } from '~/app/shared/services/notification.service';
23 selector: 'cd-rgw-storage-class-form',
24 templateUrl: './rgw-storage-class-form.component.html',
25 styleUrls: ['./rgw-storage-class-form.component.scss']
27 export class RgwStorageClassFormComponent extends CdForm implements OnInit {
28 storageClassForm: CdFormGroup;
31 targetPathText: string;
32 targetEndpointText: string;
33 targetRegionText: string;
34 showAdvanced: boolean = false;
35 defaultZoneGroup: string;
36 zonegroupNames: ZoneGroup[];
37 placementTargets: string[] = [];
38 multipartMinPartText: string;
39 multipartSyncThreholdText: string;
40 selectedZoneGroup: string;
41 defaultZonegroup: ZoneGroup;
42 zoneGroupDeatils: ZoneGroupDetails;
43 targetSecretKeyText: string;
44 targetAccessKeyText: string;
45 retainHeadObjectText: string;
48 public actionLabels: ActionLabelsI18n,
49 private formBuilder: CdFormBuilder,
50 private notificationService: NotificationService,
51 private rgwStorageService: RgwStorageClassService,
52 private rgwZoneGroupService: RgwZonegroupService,
53 private router: Router
56 this.resource = $localize`Tiering Storage Class`;
60 this.multipartMinPartText =
61 'It specifies that objects this size or larger are transitioned to the cloud using multipart upload.';
62 this.multipartSyncThreholdText =
63 'It specifies the minimum part size to use when transitioning objects using multipart upload.';
65 'Target Path refers to the storage location (e.g., bucket or container) in the cloud where data will be stored.';
66 this.targetRegionText = 'The region of the remote cloud service where storage is located.';
67 this.targetEndpointText = 'The URL endpoint of the remote cloud service for accessing storage.';
68 this.targetAccessKeyText =
69 "To view or copy your access key, go to your cloud service's user management or credentials section, find your user profile, and locate the access key. You can view and copy the key by following the instructions provided.";
71 this.targetSecretKeyText =
72 "To view or copy your secret key, go to your cloud service's user management or credentials section, find your user profile, and locate the access key. You can view and copy the key by following the instructions provided.";
73 this.retainHeadObjectText =
74 'Retain object metadata after transition to the cloud (default: deleted).';
75 this.action = this.actionLabels.CREATE;
81 this.storageClassForm = this.formBuilder.group({
82 storage_class: new FormControl('', {
83 validators: [Validators.required]
85 zonegroup: new FormControl(this.selectedZoneGroup, {
86 validators: [Validators.required]
88 region: new FormControl('', {
89 validators: [Validators.required]
91 placement_target: new FormControl('', {
92 validators: [Validators.required]
94 endpoint: new FormControl(null, {
95 validators: [Validators.required]
97 access_key: new FormControl(null, Validators.required),
98 secret_key: new FormControl(null, Validators.required),
99 target_path: new FormControl('', {
100 validators: [Validators.required]
102 retain_head_object: new FormControl(false),
103 multipart_sync_threshold: new FormControl(33554432),
104 multipart_min_part_size: new FormControl(33554432)
108 loadZoneGroup(): Promise<void> {
109 return new Promise((resolve, reject) => {
110 this.rgwZoneGroupService.getAllZonegroupsInfo().subscribe(
111 (data: ZoneGroupDetails) => {
112 this.zoneGroupDeatils = data;
113 this.zonegroupNames = [];
114 this.placementTargets = [];
115 if (data.zonegroups && data.zonegroups.length > 0) {
116 this.zonegroupNames = data.zonegroups.map((zoneGroup: ZoneGroup) => {
123 this.defaultZonegroup = this.zonegroupNames.find(
124 (zonegroups: ZoneGroup) => zonegroups.id === data.default_zonegroup
127 this.storageClassForm.get('zonegroup').setValue(this.defaultZonegroup.name);
128 this.onZonegroupChange();
131 (error) => reject(error)
136 onZonegroupChange() {
137 const zoneGroupControl = this.storageClassForm.get('zonegroup').value;
138 const selectedZoneGroup = this.zoneGroupDeatils.zonegroups.find(
139 (zonegroup) => zonegroup.name === zoneGroupControl
141 const defaultPlacementTarget = selectedZoneGroup.placement_targets.find(
142 (target: Target) => target.name === DEFAULT_PLACEMENT
144 if (selectedZoneGroup) {
145 const placementTargetNames = selectedZoneGroup.placement_targets.map(
146 (target: Target) => target.name
148 this.placementTargets = placementTargetNames;
150 if (defaultPlacementTarget) {
151 this.storageClassForm.get('placement_target').setValue(defaultPlacementTarget.name);
156 const component = this;
157 const requestModel = this.buildRequest();
158 const storageclassName = this.storageClassForm.get('storage_class').value;
159 this.rgwStorageService.createStorageClass(requestModel).subscribe(
161 this.notificationService.show(
162 NotificationType.success,
163 $localize`Created Storage Class '${storageclassName}'`
168 component.storageClassForm.setErrors({ cdSubmitButton: true });
174 this.router.navigate([`rgw/tiering`]);
178 const rawFormValue = _.cloneDeep(this.storageClassForm.value);
179 const requestModel: RequestModel = {
180 zone_group: rawFormValue.zonegroup,
184 placement_id: rawFormValue.placement_target,
185 storage_class: rawFormValue.storage_class,
186 tier_type: CLOUD_TIER,
188 endpoint: rawFormValue.endpoint,
189 access_key: rawFormValue.access_key,
190 secret: rawFormValue.secret_key,
191 target_path: rawFormValue.target_path,
192 retain_head_object: rawFormValue.retain_head_object,
193 region: rawFormValue.region,
194 multipart_sync_threshold: rawFormValue.multipart_sync_threshold,
195 multipart_min_part_size: rawFormValue.multipart_min_part_size