X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;ds=sidebyside;f=webapp-frontend%2Fsrc%2Fapp%2Fac-xapp%2Fac-xapp.component.ts;h=1f1d61e2f64fc0aef9322a8079106428d376fdef;hb=refs%2Fchanges%2F72%2F2272%2F8;hp=9b9f23c74ea0a92400db872dca9e7d2d22cc5383;hpb=1379dce23d47c42d169ed13a337bbee827714830;p=portal%2Fric-dashboard.git diff --git a/webapp-frontend/src/app/ac-xapp/ac-xapp.component.ts b/webapp-frontend/src/app/ac-xapp/ac-xapp.component.ts index 9b9f23c7..1f1d61e2 100644 --- a/webapp-frontend/src/app/ac-xapp/ac-xapp.component.ts +++ b/webapp-frontend/src/app/ac-xapp/ac-xapp.component.ts @@ -2,14 +2,14 @@ * ========================LICENSE_START================================= * O-RAN-SC * %% - * Copyright (C) 2019 AT&T Intellectual Property and Nokia + * Copyright (C) 2019 AT&T Intellectual Property * %% * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -18,49 +18,81 @@ * ========================LICENSE_END=================================== */ -import { Component, OnInit } from '@angular/core'; -import { FormGroup, FormControl, Validators } from '@angular/forms'; -import { ACAdmissionIntervalControl, ACAdmissionIntervalControlAck } from '../interfaces/ac-xapp.types'; +import { HttpErrorResponse } from '@angular/common/http'; +import { Component, OnDestroy, OnInit } from '@angular/core'; +import { FormControl, FormGroup, Validators } from '@angular/forms'; +import { Subscription } from 'rxjs'; +import { ACAdmissionIntervalControl } from '../interfaces/ac-xapp.types'; +import { RicInstance } from '../interfaces/dashboard.types'; import { ACXappService } from '../services/ac-xapp/ac-xapp.service'; +import { InstanceSelectorService } from '../services/instance-selector/instance-selector.service'; import { ErrorDialogService } from '../services/ui/error-dialog.service'; -import { NotificationService } from './../services/ui/notification.service'; +import { NotificationService } from '../services/ui/notification.service'; @Component({ selector: 'rd-ac-xapp', templateUrl: './ac-xapp.component.html', styleUrls: ['./ac-xapp.component.scss'] }) -export class AcXappComponent implements OnInit { +export class AcXappComponent implements OnInit, OnDestroy { private acForm: FormGroup; - - // this is probably the A1 version string - acVersion: string; + private instanceChange: Subscription; + private instanceKey: string; constructor( private acXappService: ACXappService, private errorDialogService: ErrorDialogService, - private notificationService: NotificationService) { } + private notificationService: NotificationService, + public instanceSelectorService: InstanceSelectorService, ) { } ngOnInit() { - const windowLengthPattern = /^([0-9]{1}|[1-5][0-9]{1}|60)$/; - const blockingRatePattern = /^([0-9]{1,2}|100)$/; - const triggerPattern = /^([0-9]+)$/; - // No way to fetch current settings via A1 at present this.acForm = new FormGroup({ - enforce: new FormControl(true, [Validators.required]), - windowLength: new FormControl('', [Validators.required, Validators.pattern(windowLengthPattern)]), - blockingRate: new FormControl('', [Validators.required, Validators.pattern(blockingRatePattern)]), - triggerThreshold: new FormControl('', [Validators.required, Validators.pattern(triggerPattern)]) + // Names must match the ACAdmissionIntervalControl interface + enforce: new FormControl(true, [Validators.required]), + class: new FormControl('', [Validators.required, Validators.min(1), Validators.max(256)]), + window_length: new FormControl('', [Validators.required, Validators.min(15), Validators.max(300)]), + blocking_rate: new FormControl('', [Validators.required, Validators.min(0), Validators.max(100)]), + trigger_threshold: new FormControl('', [Validators.required, Validators.min(1)]) + }); + + this.instanceChange = this.instanceSelectorService.getSelectedInstance().subscribe((instance: RicInstance) => { + if (instance.key) { + // TODO: show pending action indicator + this.instanceKey = instance.key; + this.acXappService.getPolicy(instance.key).subscribe((res: ACAdmissionIntervalControl) => { + this.acForm.controls['class'].setValue(res.class); + this.acForm.controls['enforce'].setValue(res.enforce); + this.acForm.controls['window_length'].setValue(res.window_length); + this.acForm.controls['blocking_rate'].setValue(res.blocking_rate); + this.acForm.controls['trigger_threshold'].setValue(res.trigger_threshold); + // TODO: clear pending action indicator + }, + (error: HttpErrorResponse) => { + // TODO: clear pending action indicator + this.errorDialogService.displayError(error.message); + }); + } }); - this.acXappService.getVersion().subscribe((res: string) => this.acVersion = res); + } + + ngOnDestroy() { + this.instanceChange.unsubscribe(); } updateAc = (acFormValue: ACAdmissionIntervalControl) => { if (this.acForm.valid) { - this.acXappService.putPolicy(acFormValue).subscribe( + // convert strings to numbers using the plus operator + const acFormValueConverted = { + class: +acFormValue.class, + enforce: acFormValue.enforce, + window_length: +acFormValue.window_length, + blocking_rate: +acFormValue.blocking_rate, + trigger_threshold: +acFormValue.trigger_threshold + }; + this.acXappService.putPolicy(this.instanceKey, acFormValueConverted).subscribe( response => { - if (response.status === 200 ) { + if (response.status === 200) { this.notificationService.success('AC update policy succeeded!'); } },