Feature 11009 Ns Config Template as first class citizens in OSM
- Added UI support
- Added New page for NS config template under packages section
- User can create, edit & delete template
- Added template field under ns instance
Change-Id: I3e9a895b4415165d6c96b9840dee64cc197b40e4
Signed-off-by: SANDHYA.JS <sandhya.j@tataelxsi.co.in>
diff --git a/src/app/packages/PackagesModule.ts b/src/app/packages/PackagesModule.ts
index 5a8ea2e..1cd7e81 100644
--- a/src/app/packages/PackagesModule.ts
+++ b/src/app/packages/PackagesModule.ts
@@ -36,6 +36,7 @@
import { SidebarModule } from 'ng-sidebar';
import { Ng2SmartTableModule } from 'ng2-smart-table';
import { NSComposerComponent } from 'NSComposer';
+import { NSConfigTemplateComponent } from 'NSCONFIGTEMPLATE';
import { NSPackagesComponent } from 'NSPackages';
import { PackagesComponent } from 'Packages';
import { PagePerRowModule } from 'PagePerRowModule';
@@ -102,6 +103,14 @@
projectInfo, { title: 'VNFPACKAGES', url: '/packages/vnf' }, { title: '{id}', url: null }]
},
component: VNFComposerComponent
+ },
+ {
+ path: 'nsconfigtemplate',
+ data: {
+ breadcrumb: [{ title: 'PAGE.DASHBOARD.DASHBOARD', url: '/' }, { title: 'PAGE.DASHBOARD.PROJECTS', url: '/projects' },
+ projectInfo, { title: 'PAGE.DASHBOARD.NSCONFIGTEMPLATE', url: null }]
+ },
+ component: NSConfigTemplateComponent
}
]
}
@@ -115,7 +124,7 @@
CodemirrorModule, TranslateModule, RouterModule.forChild(routes), NgbModule, NgSelectModule,
PagePerRowModule, SidebarModule.forRoot(), LoaderModule, PageReloadModule],
declarations: [PackagesComponent, NSPackagesComponent, VNFPackagesComponent, NetsliceTemplateComponent,
- DragDirective, ShowContentComponent, NSComposerComponent, VNFComposerComponent, EditPackagesComponent, ClonePackageComponent],
+ DragDirective, ShowContentComponent, NSComposerComponent, VNFComposerComponent, EditPackagesComponent, ClonePackageComponent, NSConfigTemplateComponent],
providers: [DataService],
schemas: [CUSTOM_ELEMENTS_SCHEMA]
})
diff --git a/src/app/packages/instantiate-ns/InstantiateNsComponent.html b/src/app/packages/instantiate-ns/InstantiateNsComponent.html
index 428515e..11f3a2e 100644
--- a/src/app/packages/instantiate-ns/InstantiateNsComponent.html
+++ b/src/app/packages/instantiate-ns/InstantiateNsComponent.html
@@ -47,7 +47,7 @@
<div class="form-group row mb-3">
<label class="col-sm-4 col-form-label" for="nsdId">{{'PAGE.INSTANCEINSTANTIATE.NSID' | translate}}*</label>
<div class="col-sm-8">
- <ng-select [items]="nsdSelect" bindLabel="name" bindValue="_id"
+ <ng-select (change)="getDetailsconfigtemplateAccount()" [items]="nsdSelect" bindLabel="name" bindValue="_id"
placeholder="{{'SELECT' | translate}} {{'PAGE.INSTANCEINSTANTIATE.NSID' | translate}}"
formControlName="nsdId" [(ngModel)]="nsdId" id="nsdId"
[ngClass]="{ 'is-invalid': submitted && f.nsdId.errors }" required>
@@ -98,6 +98,12 @@
<div class="form-group row mb-3">
<label class="col-sm-4 col-form-label" for="config">{{'CONFIG' | translate}}</label>
<div class="col-sm-8">
+ <ng-select [items]="nsConfigSelect" bindLabel="name" bindValue="_id"
+ placeholder="{{'SELECT' | translate}} {{'PAGE.DASHBOARD.NSCONFIGTEMPLATE' | translate}}"
+ formControlName="nsConfigTemplateId" id="nsConfigTemplateId"
+ [ngClass]="{ 'is-invalid': submitted && f.nsConfigTemplateId.errors }">
+ </ng-select>
+ <div class="fileupload-text mt-1 mb-1">{{'CONFIGFILEUPLOADLABEL' | translate}}</div>
<textarea class="form-control" placeholder="{{'YAMLCONFIG' | translate}}" formControlName="config"
id="config"></textarea>
<div class="fileupload-text mt-1 mb-1">{{'FILEUPLOADLABEL' | translate}}</div>
diff --git a/src/app/packages/instantiate-ns/InstantiateNsComponent.ts b/src/app/packages/instantiate-ns/InstantiateNsComponent.ts
index 9ba89da..08d6232 100644
--- a/src/app/packages/instantiate-ns/InstantiateNsComponent.ts
+++ b/src/app/packages/instantiate-ns/InstantiateNsComponent.ts
@@ -18,18 +18,20 @@
/**
* @file Instantiate NS Modal Component.
*/
-import { Component, ElementRef, Injector, OnInit, ViewChild } from '@angular/core';
+import { Component, ElementRef, Injector, Input, OnInit, ViewChild } from '@angular/core';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { Router } from '@angular/router';
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
import { TranslateService } from '@ngx-translate/core';
import { NotifierService } from 'angular-notifier';
-import { APIURLHEADER, ERRORDATA, MODALCLOSERESPONSEDATA } from 'CommonModel';
+import { APIURLHEADER, ERRORDATA, MODALCLOSERESPONSEDATA, URLPARAMS } from 'CommonModel';
import { DataService } from 'DataService';
import { environment } from 'environment';
import * as jsyaml from 'js-yaml';
-import { NSCREATEPARAMS, NSData, NSDDetails } from 'NSDModel';
+import { NSCONFIG } from 'NSCONFIGTEMPLATEMODEL';
+import { NSData, NSDDetails } from 'NSDModel';
import { RestService } from 'RestService';
+import { Subscription } from 'rxjs';
import { SharedService, isNullOrUndefined } from 'SharedService';
import { VimAccountDetails } from 'VimAccountModel';
@@ -56,9 +58,15 @@
/** Contains all vim account collections */
public vimAccountSelect: VimAccountDetails;
+ /** Contains all NS Config template details */
+ public nsConfigSelect: NSCONFIG;
+
/** Instance for active modal service @public */
public activeModal: NgbActiveModal;
+ /** Used to subscribe nsdId @public */
+ public nsdID: Subscription;
+
/** Variable set for twoway binding @public */
public nsdId: string;
@@ -66,13 +74,13 @@
public vimAccountId: string;
/** Form submission Add */
- public submitted: boolean = false;
+ public submitted = false;
/** Check the loading results @public */
- public isLoadingResults: boolean = false;
+ public isLoadingResults = false;
/** Give the message for the loading @public */
- public message: string = 'PLEASEWAIT';
+ public message = 'PLEASEWAIT';
/** Contains Selected VIM Details @public */
public selectedVIMDetails: VimAccountDetails = null;
@@ -113,6 +121,9 @@
/** Contains the ssh key to be hosted in dom @private */
private copySSHKey: string;
+ /** Input contains component objects @private */
+ @Input() private params: URLPARAMS;
+
constructor(injector: Injector) {
this.injector = injector;
this.restService = this.injector.get(RestService);
@@ -127,10 +138,11 @@
public ngOnInit(): void {
/** Setting up initial value for NSD */
- this.dataService.currentMessage.subscribe((event: NSData) => {
- if (event.identifier !== undefined || event.identifier !== '' || event.identifier !== null) {
+ this.nsdID = this.dataService.currentMessage.subscribe((event: NSData) => {
+ if (!isNullOrUndefined(event?.identifier) || event?.identifier !== '') {
this.nsdId = event.identifier;
}
+ this.getDetailsconfigtemplateAccount();
});
/** On Initializing call the methods */
this.instantiateFormAction();
@@ -143,10 +155,11 @@
this.instantiateForm = this.formBuilder.group({
nsName: ['', [Validators.required]],
nsDescription: ['', [Validators.required]],
- nsdId: ['', [Validators.required]],
+ nsdId: [null, [Validators.required]],
vimAccountId: ['', [Validators.required]],
ssh_keys: [null],
- config: [null]
+ config: [null],
+ nsConfigTemplateId: [null]
});
}
@@ -171,6 +184,15 @@
});
}
+ /** Call the ns config template details in the selection options @public */
+ public getDetailsconfigtemplateAccount(): void {
+ this.restService.getResource(environment.NSCONFIGTEMPLATE_URL + '?nsdId=' + this.nsdId).subscribe((template: NSCONFIG) => {
+ this.nsConfigSelect = template;
+ }, (error: ERRORDATA) => {
+ this.restService.handleError(error, 'get');
+ });
+ }
+
/** On modal submit instantiateNsSubmit will called @public */
public instantiateNsSubmit(): void {
this.submitted = true;
@@ -181,6 +203,9 @@
const modalData: MODALCLOSERESPONSEDATA = {
message: 'Done'
};
+ if (isNullOrUndefined(this.instantiateForm.value.nsConfigTemplateId)) {
+ delete this.instantiateForm.value.nsConfigTemplateId;
+ }
if (isNullOrUndefined(this.instantiateForm.value.ssh_keys) || this.instantiateForm.value.ssh_keys === '') {
delete this.instantiateForm.value.ssh_keys;
} else {
@@ -206,6 +231,7 @@
});
delete this.instantiateForm.value.config;
}
+ delete this.instantiateForm.value.nsConfigTemplateId;
}
const apiURLHeader: APIURLHEADER = {
url: environment.NSINSTANCESCONTENT_URL
@@ -217,7 +243,7 @@
this.translateService.instant('PAGE.NSINSTANCE.CREATEDSUCCESSFULLY'));
this.router.navigate(['/instances/ns']).catch((): void => {
// Catch Navigation Error
- });
+ });
}, (error: ERRORDATA) => {
this.isLoadingResults = false;
this.restService.handleError(error, 'post');
@@ -292,4 +318,11 @@
this.selectedVIMDetails = vimDetails;
}
}
+
+ /**
+ * Lifecyle Hooks the trigger before component is deleted
+ */
+ public ngOnDestroy(): void {
+ this.nsdID.unsubscribe();
+ }
}
diff --git a/src/app/packages/ns-config-template/NSConfigTemplateComponent.html b/src/app/packages/ns-config-template/NSConfigTemplateComponent.html
new file mode 100644
index 0000000..b508609
--- /dev/null
+++ b/src/app/packages/ns-config-template/NSConfigTemplateComponent.html
@@ -0,0 +1,35 @@
+<!--
+Copyright 2020 TATA ELXSI
+
+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.
+See the License for the specific language governing permissions and
+limitations under the License.
+
+Author: SANDHYA JS (sandhya.j@tataelxsi.co.in)
+-->
+<div class="d-flex flex-row justify-content-between">
+ <div class="d-flex align-items-center header-style">{{'PAGE.DASHBOARD.NSCONFIGTEMPLATE' | translate}}</div>
+ <span class="button">
+ <button class="btn btn-primary" type="button" placement="top" container="body" ngbTooltip="{{'PAGE.NSCONFIGTEMPLATE.NEWNSCONFIGTEMPLATE' | translate}}"
+ (click)="composeTemplate()">
+ <i class="fas fa-plus-circle" aria-hidden="true"></i> {{'PAGE.NSCONFIGTEMPLATE.NEWNSCONFIGTEMPLATE' | translate}}
+ </button>
+ </span>
+</div>
+<div class="mt-2 mb-0 form-group justify-content-end list-utilites-actions">
+ <page-per-row class="me-2" (pagePerRow)="onChange($event)"></page-per-row>
+ <page-reload></page-reload>
+</div>
+<div class="smarttable-style bg-white mt-1">
+ <ng2-smart-table [ngClass]="checkDataClass" [settings]="settings" [source]="dataSource" (userRowSelect)="onUserRowSelect($event)">
+ </ng2-smart-table>
+</div>
+<app-loader [waitingMessage]="message" *ngIf="isLoadingResults"></app-loader>
\ No newline at end of file
diff --git a/src/app/packages/ns-config-template/NSConfigTemplateComponent.scss b/src/app/packages/ns-config-template/NSConfigTemplateComponent.scss
new file mode 100644
index 0000000..c55461a
--- /dev/null
+++ b/src/app/packages/ns-config-template/NSConfigTemplateComponent.scss
@@ -0,0 +1,17 @@
+/*
+ Copyright 2020 TATA ELXSI
+
+ 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.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+ Author: SANDHYA JS (sandhya.j@tataelxsi.co.in)
+*/
\ No newline at end of file
diff --git a/src/app/packages/ns-config-template/NSConfigTemplateComponent.ts b/src/app/packages/ns-config-template/NSConfigTemplateComponent.ts
new file mode 100644
index 0000000..298207a
--- /dev/null
+++ b/src/app/packages/ns-config-template/NSConfigTemplateComponent.ts
@@ -0,0 +1,224 @@
+/*
+ Copyright 2020 TATA ELXSI
+
+ 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.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+ Author: SANDHYA JS (sandhya.j@tataelxsi.co.in)
+*/
+/**
+ * @file NS Config Template details Component.
+ */
+import { HttpHeaders } from '@angular/common/http';
+import { Component, Injector, OnInit } from '@angular/core';
+import { NgbModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap';
+import { TranslateService } from '@ngx-translate/core';
+import { ERRORDATA, MODALCLOSERESPONSEDATA } from 'CommonModel';
+import { ComposePackages } from 'ComposePackages';
+import { DataService } from 'DataService';
+import { environment } from 'environment';
+import { LocalDataSource } from 'ng2-smart-table';
+import { NSConfigTemplateActionComponent } from 'NSCONFIGTEMPLATEACTION';
+import { NSCONFIG, NSConfigData } from 'NSCONFIGTEMPLATEMODEL';
+import { RestService } from 'RestService';
+import { Subscription } from 'rxjs';
+import { SharedService } from 'SharedService';
+import { VNFData } from 'VNFDModel';
+
+/**
+ * Creating component
+ * @Component takes NSConfigTemplateComponent.html as template url
+ */
+@Component({
+ selector: 'app-ns-config-template',
+ templateUrl: './NSConfigTemplateComponent.html',
+ styleUrls: ['./NSConfigTemplateComponent.scss']
+})
+/** Exporting a class @exports NSConfigTemplateComponent */
+export class NSConfigTemplateComponent implements OnInit {
+ /** To inject services @public */
+ public injector: Injector;
+
+ /** Data of smarttable populate through LocalDataSource @public */
+ public dataSource: LocalDataSource = new LocalDataSource();
+
+ /** handle translate @public */
+ public translateService: TranslateService;
+
+ /** Columns list of the smart table @public */
+ public columnLists: object = {};
+
+ /** Settings for smarttable to populate the table with columns @public */
+ public settings: object = {};
+
+ /** Check the loading results @public */
+ public isLoadingResults: boolean = true;
+
+ /** Give the message for the loading @public */
+ public message: string = 'PLEASEWAIT';
+
+ /** Class for empty and present data @public */
+ public checkDataClass: string;
+
+ /** Instance of the rest service @private */
+ private restService: RestService;
+
+ /** dataService to pass the data from one component to another @private */
+ private dataService: DataService;
+
+ /** Formation of appropriate Data for LocalDatasource @private */
+ private nsConfigData: NSConfigData[] = [];
+
+ /** Contains all methods related to shared @private */
+ private sharedService: SharedService;
+
+ /** Controls the header form @private */
+ private headers: HttpHeaders;
+
+ /** Instance of the modal service @private */
+ private modalService: NgbModal;
+
+ /** Instance of subscriptions @private */
+ private generateDataSub: Subscription;
+
+ constructor(injector: Injector) {
+ this.injector = injector;
+ this.restService = this.injector.get(RestService);
+ this.dataService = this.injector.get(DataService);
+ this.sharedService = this.injector.get(SharedService);
+ this.translateService = this.injector.get(TranslateService);
+ this.modalService = this.injector.get(NgbModal);
+ }
+
+ /**
+ * Lifecyle Hooks the trigger before component is instantiate
+ */
+ public ngOnInit(): void {
+ this.generateColumns();
+ this.generateSettings();
+ this.generateData();
+ this.headers = new HttpHeaders({
+ 'Content-Type': 'application/gzip',
+ Accept: 'application/json',
+ 'Cache-Control': 'no-cache, no-store, must-revalidate, max-age=0'
+ });
+ this.generateDataSub = this.sharedService.dataEvent.subscribe((): void => { this.generateData(); });
+ }
+
+ /** smart table Header Colums @public */
+ public generateColumns(): void {
+ this.columnLists = {
+ name: { title: this.translateService.instant('NAME'), width: '25%' },
+ identifier: { title: this.translateService.instant('IDENTIFIER'), width: '25%' },
+ nsdId: { title: this.translateService.instant('PAGE.INSTANCEINSTANTIATE.NSID'), width: '25%' },
+ created: { title: this.translateService.instant('Created'), width: '15%' },
+ Actions: {
+ name: 'Action', width: '15%', filter: false, sort: false, type: 'custom',
+ title: this.translateService.instant('ACTIONS'),
+ valuePrepareFunction: (cell: VNFData, row: VNFData): VNFData => row, renderComponent: NSConfigTemplateActionComponent
+ }
+ };
+ }
+
+ /** smart table Data Settings @public */
+ public generateSettings(): void {
+ this.settings = {
+ edit: {
+ editButtonContent: '<i class="fa fa-edit" title="Edit"></i>',
+ confirmSave: true
+ },
+ delete: {
+ deleteButtonContent: '<i class="far fa-trash-alt" title="delete"></i>',
+ confirmDelete: true
+ },
+ columns: this.columnLists,
+ actions: {
+ add: false,
+ edit: false,
+ delete: false,
+ position: 'right'
+ },
+ attr: this.sharedService.tableClassConfig(),
+ pager: this.sharedService.paginationPagerConfig(),
+ noDataMessage: this.translateService.instant('NODATAMSG')
+ };
+ }
+
+ /** smart table listing manipulation @public */
+ public onChange(perPageValue: number): void {
+ this.dataSource.setPaging(1, perPageValue, true);
+ }
+
+ /** OnUserRowSelect Function @public */
+ public onUserRowSelect(event: MessageEvent): void {
+ Object.assign(event.data, { page: 'ns-config-template' });
+ this.dataService.changeMessage(event.data);
+ }
+
+
+ /** Generate nsData object from loop and return for the datasource @public */
+ public generatetemplateData(nsData: NSCONFIG): NSConfigData {
+ return {
+ nsdId: nsData.nsdId,
+ identifier: nsData._id,
+ operationalState: nsData._admin.operationalState,
+ created: this.sharedService.convertEpochTime(Number(nsData._admin.created)),
+ modified: this.sharedService.convertEpochTime(Number(nsData._admin.modified)),
+ name: nsData.name
+ };
+ }
+ /** Handle compose new ns package method @public */
+ public composeTemplate(): void {
+ // eslint-disable-next-line security/detect-non-literal-fs-filename
+ const modalRef: NgbModalRef = this.modalService.open(ComposePackages, { backdrop: 'static' });
+ modalRef.componentInstance.params = { page: 'ns-config-template' };
+ modalRef.result.then((result: MODALCLOSERESPONSEDATA) => {
+ if (result) {
+ this.sharedService.callData();
+ }
+ }).catch((): void => {
+ // Catch Navigation Error
+ });
+ }
+
+ /**
+ * Lifecyle hook which get trigger on component destruction
+ */
+ public ngOnDestroy(): void {
+ this.generateDataSub.unsubscribe();
+ }
+
+ /** Fetching the data from server to Load in the smarttable @protected */
+ protected generateData(): void {
+ this.isLoadingResults = true;
+ this.restService.getResource(environment.NSCONFIGTEMPLATE_URL).subscribe((nsdConfigData: NSCONFIG[]): void => {
+ this.nsConfigData = [];
+ nsdConfigData.forEach((nsddata: NSCONFIG): void => {
+ const vnfDataObj: NSConfigData = this.generatetemplateData(nsddata);
+ this.nsConfigData.push(vnfDataObj);
+ });
+ if (this.nsConfigData.length > 0) {
+ this.checkDataClass = 'dataTables_present';
+ } else {
+ this.checkDataClass = 'dataTables_empty';
+ }
+ this.dataSource.load(this.nsConfigData).then((data: boolean): void => {
+ this.isLoadingResults = false;
+ }).catch((): void => {
+ this.isLoadingResults = false;
+ });
+ }, (error: ERRORDATA): void => {
+ this.restService.handleError(error, 'get');
+ this.isLoadingResults = false;
+ });
+ }
+}