Skip to content

Commit

Permalink
Merge pull request #452 from himanshuvar/HuaweiSFS
Browse files Browse the repository at this point in the history
[Hw-SFS FileShare Support] Implement Hw Cloud SFS FileShare Dashboard Support for Multi-Cloud
  • Loading branch information
kumarashit authored Oct 19, 2020
2 parents 9771bde + 47b3749 commit 894081b
Show file tree
Hide file tree
Showing 7 changed files with 188 additions and 102 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,15 @@ export class CloudFileShareComponent implements OnInit{
},
disabled:false
}

];
}

getBackends() {
this.http.get('v1/{project_id}/backends').subscribe((res)=>{
this.allBackends = res.json().backends ? res.json().backends :[];
this.allBackends.forEach(element => {
if(element.type == 'aws-file' || element.type == 'azure-file' || element.type == 'gcp-file'){
if(element.type == 'aws-file' || element.type == 'azure-file' || element.type == 'gcp-file'|| element.type == 'hw-file'){
this.selectedBackends.push(element);
}
});
Expand All @@ -114,7 +114,7 @@ export class CloudFileShareComponent implements OnInit{
this.cloudFS.getAllFileShares().subscribe((res) => {
let shares = res.json() && res.json().fileshares ? res.json().fileshares : [];
this.allFileShares = shares;

if(this.allFileShares.length){
this.allFileShares.forEach(element => {
if(!element['tags']){
Expand All @@ -137,13 +137,13 @@ export class CloudFileShareComponent implements OnInit{
metaitem['value'] = value['Kind']['NumberValue'];
metaitem['type'] = 'number';
}

metadataArr.push(metaitem);

})
element['metadataArr'] = metadataArr;
}

});
}
}, (error) => {
Expand Down Expand Up @@ -172,7 +172,7 @@ export class CloudFileShareComponent implements OnInit{
msg = "<h3>Are you sure you want to delete the selected " + fileShare.length + " FileShares?</h3><h4>[ "+ selectedNames.join(',') +" FileShare(s) ]</h4>";
}else{
arr.push(fileShare.id)
msg = "<h3>Are you sure you want to delete the selected FileShare?</h3><h4>[ "+ fileShare.name +" ]</h4>";
msg = "<h3>Are you sure you want to delete the selected FileShare?</h3><h4>[ "+ fileShare.name +" ]</h4>";
}
this.confirmationService.confirm({
message: msg,
Expand All @@ -199,4 +199,4 @@ export class CloudFileShareComponent implements OnInit{
this.msgs.push({severity: 'error', summary: 'Error', detail: 'Error deleting Fileshare'});
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,26 @@ <h1>{{i18n.keyID['sds_creatFileShare']}}</h1>
<form-item label="{{label.backend}}" [required]="true">
<p-dropdown [style]="{'min-width':'150px','width':'220px'}" placeholder="Please select" [options]="backendsOption" (onChange)="updateFormAndRegion()" formControlName="backend"></p-dropdown>
</form-item>
<form-item *ngIf="cloudFileShareCreateForm.controls['sfsType']" label="{{label.sfs_type}}" [required]="true">
<span><p-radioButton label="SFS" formControlName="sfsType" name="typeRadioGroup" value="SFS"></p-radioButton></span>
<span style="margin-left: 30px;"><p-radioButton label="SFS_Turbo" formControlName="sfsType" name="typeRadioGroup" value="SFS_Turbo" disabled="true"></p-radioButton></span>

</form-item>
<form-item [required]="true" label="{{label.name}}">
<input formControlName="name" type="text" size="30" pInputText>
<input formControlName="name" type="text" size="30" pInputText>
</form-item>
<form-item label="{{label.description}}">
<textarea [rows]="5" [cols]="30" pInputTextarea formControlName="description" [maxlength]="250"></textarea>
</form-item>
<form-item *ngIf="cloudFileShareCreateForm.controls['availabilityZone']" label="{{label.az}}">
<input formControlName="availabilityZone" type="text" size="30" pInputText>
<input formControlName="availabilityZone" type="text" size="30" pInputText>
</form-item>
<form-item *ngIf="cloudFileShareCreateForm.controls['encrypted']" label="Enable Encryption?" >
<p-inputSwitch formControlName="encrypted" onLabel="Yes" offLabel="No" (onChange)="encryptionControl()"></p-inputSwitch>
</form-item>

<form-item *ngIf="cloudFileShareCreateForm.controls['encryptionSettings'] && isVisible" label="{{label.encryptionSettings}}">

<div class="encryption-settings-array" formArrayName="encryptionSettings"
*ngFor="let item of cloudFileShareCreateForm.get('encryptionSettings')['controls']; let i = index">
<div class="ui-g ui-fluid" [formGroupName]="i">
Expand All @@ -40,16 +45,21 @@ <h1>{{i18n.keyID['sds_creatFileShare']}}</h1>
</div>
<div class="ui-g-12 ui-md-2 ui-md-offset-1">
<div class="ui-inputgroup">

</div>
</div>
</div>
</div>

</form-item>
<form-item *ngIf="cloudFileShareCreateForm.controls['size']" label="{{label.size}}">
<input formControlName="size" type="text" size="30" pInputText>
<input formControlName="size" type="text" size="30" pInputText>
</form-item>

<form-item *ngIf="cloudFileShareCreateForm.controls['protocols']" [required]="true" label="{{label.protocols}}">
<input formControlName="protocols" type="text" size="30" pInputText>
</form-item>

<form-item *ngIf="cloudFileShareCreateForm.controls['tags']" [required]="true" label="{{label.tags}}">
<a class="add-tag" (click)="addNextTag()"><i class="fa fa-plus-circle" ></i></a>
<div class="tag-array" formArrayName="tags"
Expand All @@ -67,12 +77,12 @@ <h1>{{i18n.keyID['sds_creatFileShare']}}</h1>
</div>
<div class="ui-g-12 ui-md-2 ui-md-offset-1">
<div class="ui-inputgroup">
<a disabled="cloudFileShareCreateForm.get('tags')['length'] > 1" class="remove-tag" (click)="removeTagLink(i)"><i class="fa fa-minus-circle"></i></a>
<a disabled="cloudFileShareCreateForm.get('tags')['length'] > 1" class="remove-tag" (click)="removeTagLink(i)"><i class="fa fa-minus-circle"></i></a>
</div>
</div>
</div>
</div>

</form-item>

<form-item *ngIf="cloudFileShareCreateForm.controls['metadata']" [required]="true" label="{{label.metadata}}">
Expand All @@ -92,21 +102,21 @@ <h1>{{i18n.keyID['sds_creatFileShare']}}</h1>
</div>
<div class="ui-g-12 ui-md-2 ui-md-offset-1">
<div class="ui-inputgroup">
<a *ngIf="(key != 'PerformanceMode') || (key != 'ThroughputMode') || (key != 'ProvisionedThroughputInMibps') || (key != 'Tier')"
disabled="cloudFileShareCreateForm.get('metadata')['length'] > 1"
class="remove-metadata"
<a *ngIf="(key != 'PerformanceMode') || (key != 'ThroughputMode') || (key != 'ProvisionedThroughputInMibps') || (key != 'Tier')"
disabled="cloudFileShareCreateForm.get('metadata')['length'] > 1"
class="remove-metadata"
(click)="removeMetadataLink(i)">
<i class="fa fa-minus-circle"></i>
</a>
</a>
</div>
</div>
</div>
</div>

</form-item>

<div class="bottom-button-margin">
<button pButton type="submit" class="ui-button-secondary" label="{{i18n.keyID['ok']}}" [disabled]="cloudFileShareCreateForm.invalid"></button>
<button pButton type="button" label="{{i18n.keyID['cancel']}}" [routerLink]="['/block','fromCloudFileShare']"></button>
</div>
</form>
</form>
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ export class CloudFileShareCreateComponent implements OnInit{
selectedSse;
isVisible: boolean = false;
showField: boolean = true;
sfsType: string = "SFS";
errorMessage = {
"name": {
"name": {
required: "Name is required",
minlength: "The file share name should have minimum 2 characters.",
maxlength: "The file share name should have maximum 128 characters.",
Expand Down Expand Up @@ -70,7 +71,9 @@ export class CloudFileShareCreateComponent implements OnInit{
metadata: "Metadata",
backend_type: "Type",
backend: "Backend",
az: "Availability Zone"
az: "Availability Zone",
protocols: "Protocols",
sfs_type: "SFS Type"
};
msgs: Message[];

Expand All @@ -83,7 +86,7 @@ export class CloudFileShareCreateComponent implements OnInit{
private http: HttpService,
private fb: FormBuilder,
private msg: MsgBoxService,
private availabilityZonesService:AvailabilityZonesService,
private availabilityZonesService:AvailabilityZonesService,
private ProfileService: ProfileService,
private BucketService: BucketService){

Expand All @@ -103,18 +106,18 @@ export class CloudFileShareCreateComponent implements OnInit{
getTypes() {
this.allTypes = [];
this.BucketService.getTypes().subscribe((res) => {

let types = res.json().types;
types.forEach(element => {
if( element.name=='aws-file' || element.name == 'azure-file' || element.name == 'gcp-file'){
if( element.name=='aws-file' || element.name == 'azure-file' || element.name == 'gcp-file' || element.name == 'hw-file'){
this.allTypes.push({
label: Consts.CLOUD_TYPE_NAME[element.name],
value: element.name
})
}
});
});

}

getBackendsByTypeId() {
Expand Down Expand Up @@ -147,6 +150,12 @@ export class CloudFileShareCreateComponent implements OnInit{

prepareCreateForm(type){
if(type == 'azure-file' ) {
if(this.cloudFileShareCreateForm.controls['protocols']){
this.cloudFileShareCreateForm.removeControl('protocols');
}
if(this.cloudFileShareCreateForm.controls['sfsType']){
this.cloudFileShareCreateForm.removeControl('sfsType');
}
this.cloudFileShareCreateForm.addControl('size', this.fb.control(''));
this.cloudFileShareCreateForm.removeControl('availabilityZone');
if(this.cloudFileShareCreateForm.get('metadata')){
Expand All @@ -158,8 +167,14 @@ export class CloudFileShareCreateComponent implements OnInit{
this.cloudFileShareCreateForm.removeControl('tags');
this.cloudFileShareCreateForm.removeControl('encrypted');
this.cloudFileShareCreateForm.removeControl('encryptionSettings');
}
}
if(type == 'gcp-file'){
if(this.cloudFileShareCreateForm.controls['protocols']){
this.cloudFileShareCreateForm.removeControl('protocols');
}
if(this.cloudFileShareCreateForm.controls['sfsType']){
this.cloudFileShareCreateForm.removeControl('sfsType');
}
this.cloudFileShareCreateForm.controls['name'].setValidators([Validators.required, Validators.minLength(2), Validators.maxLength(16), Validators.pattern(this.validRule.name),Utils.isExisted(this.allNamesForCheck)]);
this.errorMessage.name.maxlength = "The file share name should have maximum 16 characters."
this.cloudFileShareCreateForm.controls['name'].updateValueAndValidity();
Expand All @@ -174,13 +189,19 @@ export class CloudFileShareCreateComponent implements OnInit{
} else{
this.cloudFileShareCreateForm.addControl('metadata', this.fb.array([this.createMetadata('Tier', 'STANDARD')]));
}
}
}
else{
this.cloudFileShareCreateForm.controls['name'].setValidators([Validators.required, Validators.minLength(2), Validators.maxLength(128), Validators.pattern(this.validRule.name),Utils.isExisted(this.allNamesForCheck)]);
this.errorMessage.name.maxlength = "The file share name should have maximum 128 characters."
this.errorMessage.name.maxlength = "The file share name should have maximum 128 characters."
this.cloudFileShareCreateForm.controls['name'].updateValueAndValidity();
}
if(type == 'aws-file') {
if(this.cloudFileShareCreateForm.controls['protocols']){
this.cloudFileShareCreateForm.removeControl('protocols');
}
if(this.cloudFileShareCreateForm.controls['sfsType']){
this.cloudFileShareCreateForm.removeControl('sfsType');
}
if(this.cloudFileShareCreateForm.controls['size']){
this.cloudFileShareCreateForm.removeControl('size');
}
Expand All @@ -195,7 +216,32 @@ export class CloudFileShareCreateComponent implements OnInit{
this.cloudFileShareCreateForm.addControl('metadata', this.fb.array([this.createMetadata('PerformanceMode', 'generalPurpose')]));
this.addNextMetadata('ThroughputMode', 'bursting');
this.addNextMetadata('ProvisionedThroughputInMibps', '');
}
}
if(type == 'hw-file') {
this.cloudFileShareCreateForm.addControl('sfsType', new FormControl('SFS'));

if(this.cloudFileShareCreateForm.controls['sfsType']){
this.cloudFileShareCreateForm.get("sfsType").valueChanges.subscribe(
(value:string)=>{
this.sfsType = value
}
);
}

this.cloudFileShareCreateForm.addControl('size', this.fb.control('1', [Validators.required]));
this.cloudFileShareCreateForm.addControl('availabilityZone', this.fb.control(''));
this.cloudFileShareCreateForm.addControl('encrypted', this.fb.control(false, [Validators.required]));
this.cloudFileShareCreateForm.addControl('protocols', this.fb.control('NFS'));
if(this.cloudFileShareCreateForm.controls['encrypted']){
this.cloudFileShareCreateForm.addControl('encryptionSettings', this.fb.array([this.createEncryptionSettings('KmsKeyId', '')]));
this.addNextEncryptionSettings('KmsKeyName', 'sfs/default');
this.addNextEncryptionSettings('DomainId', '');
}
this.cloudFileShareCreateForm.removeControl('tags');
this.cloudFileShareCreateForm.addControl('tags', this.fb.array([this.createTags('Name','')]));
this.cloudFileShareCreateForm.removeControl('metadata');
this.cloudFileShareCreateForm.addControl('metadata', this.fb.array([this.createMetadata('VpcID', '')]));
}
}

updateFormAndRegion(){
Expand All @@ -209,14 +255,14 @@ export class CloudFileShareCreateComponent implements OnInit{
this.cloudFileShareCreateForm.patchValue({
'region' : this.selectedRegion
})

}

updateEncryptionSettings(visible){
const encSettingsControl = this.cloudFileShareCreateForm.get('encryptionSettings');
let encGrp:any = this.cloudFileShareCreateForm.controls['encryptionSettings']['controls'];
if(visible){

encGrp.forEach(item => {
item.controls['key'].setValidators(Validators.required);
item.controls['value'].setValidators(Validators.required);
Expand All @@ -243,6 +289,14 @@ export class CloudFileShareCreateComponent implements OnInit{
value: new FormControl(value ? value : '')
})
}
addNextEncryptionSettings(key?, value?) {
(this.cloudFileShareCreateForm.controls['encryptionSettings'] as FormArray).push(this.createEncryptionSettings((key ? key : ''), (value ? value : '')))
}
removeEncryptionSettingsLink(i: number) {
if(this.cloudFileShareCreateForm.get('encryptionSettings')['length'] > 1){
this.cloudFileShareCreateForm.get('encryptionSettings')['removeAt'](i);
}
}

createTags(key?, value?){
return this.fb.group({
Expand Down Expand Up @@ -284,6 +338,9 @@ export class CloudFileShareCreateComponent implements OnInit{
}
if(value['metadata']){
let meta = {};
if(this.selectType == 'hw-file'){
meta['HwSFSType'] = this.sfsType;
}
dataArr['metadata'] = [];
value['metadata'].forEach(element => {
if(element['key']=="ProvisionedThroughputInMibps"){
Expand All @@ -308,7 +365,7 @@ export class CloudFileShareCreateComponent implements OnInit{
dataArr['encryptionSettings'] = enc;
}
}

if(value['availabilityZone']){
dataArr['availabilityZone'] = value['availabilityZone'];
}
Expand All @@ -318,6 +375,11 @@ export class CloudFileShareCreateComponent implements OnInit{
if(value['tags']){
dataArr['tags'] = value['tags'];
}
if(value['protocols']){
var protoArr:string[];
protoArr = [value['protocols']]
dataArr['protocols'] = protoArr;
}

return dataArr;
}
Expand All @@ -343,7 +405,7 @@ export class CloudFileShareCreateComponent implements OnInit{
console.log("Something went wrong. File share could not be created.", error);
})
}

getFileShares(){
this.cloudFS.getAllFileShares().subscribe((res)=>{
let fileShares = res.json();
Expand All @@ -352,4 +414,4 @@ export class CloudFileShareCreateComponent implements OnInit{
})
})
}
}
}
Loading

0 comments on commit 894081b

Please sign in to comment.