Feature: 11055 Support of several node groups in clusters created by OSM

	- Added control plane support in managed post
	- When aws vim account is selected paylaod will get differed
	- Added details page in clusters to view node and ksu for
	  specified cluster
	- Fixed Bug 2402 - Unable to create Ns Config template from Ui
	  bug by chnaging api

Change-Id: I4eb327fd86b0c4a706b05a8ed10524e4d2c5bc95
Signed-off-by: SANDHYA.JS <sandhya.j@tataelxsi.co.in>
diff --git a/src/app/k8s/node-add/NodeAddComponent.html b/src/app/k8s/node-add/NodeAddComponent.html
new file mode 100644
index 0000000..5c44524
--- /dev/null
+++ b/src/app/k8s/node-add/NodeAddComponent.html
@@ -0,0 +1,126 @@
+<!--
+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)
+-->
+<form [formGroup]="nodeForm" (ngSubmit)="nodeSubmit();" (keydown.enter)="$event.preventDefault()">
+  <div class="modal-header">
+    <h4 *ngIf="profileType === 'card_node'" class="modal-title" id="modal-basic-title">
+      {{'PAGE.K8S.CREATENODEGROUP' |
+      translate}}
+    </h4>
+    <h4 *ngIf="profileType === 'edit-node'" class="modal-title" id="modal-basic-title">{{'PAGE.K8S.EDITNODE' |
+      translate}}
+    </h4>
+    <h4 *ngIf="profileType === 'k8s-scale'" class="modal-title" id="modal-basic-title">{{'PAGE.K8S.K8SSCALING' |
+      translate}}
+    </h4>
+    <button class="button-xs" type="button" class="close" aria-label="Close" (click)="activeModal.close()">
+      <i class="fas fa-times-circle text-danger"></i>
+    </button>
+  </div>
+  <div class="modal-body modal-body-custom-height">
+    <div class="form-group row mb-3" *ngIf="profileType === 'card_node'">
+      <label class="col-sm-12 col-form-label mandatory-label"
+        [ngClass]="{'text-danger': nodeForm.invalid === true && submitted === true}">{{'MANDATORYCHECK' |
+        translate}}</label>
+      <label class="col-sm-4 col-form-label" for="name">{{'PAGE.K8S.NAME' | translate}}*</label>
+      <div class="col-sm-8">
+        <input autocomplete="off" class="form-control" placeholder="{{'PAGE.K8S.NAME' | translate}}" type="text"
+          formControlName="name" id="name" [ngClass]="{ 'is-invalid': submitted && f.name.errors }" required>
+      </div>
+    </div>
+    <div class="form-group row mb-3" *ngIf="profileType === 'edit-node'">
+      <label class="col-sm-4 col-form-label" for="name">{{'PAGE.K8S.NAME' | translate}}</label>
+      <div class="col-sm-8">
+        <input autocomplete="off" class="form-control" placeholder="{{'PAGE.K8S.NAME' | translate}}" type="text"
+          formControlName="edit_name" id="name" [ngClass]="{ 'is-invalid': submitted && f.edit_name.errors }">
+      </div>
+    </div>
+    <div class="form-group row mb-3" *ngIf="profileType === 'card_node' || profileType === 'edit-node'">
+      <label class="col-sm-4 col-form-label" for="description">{{'PAGE.K8S.DESCRIPTION' | translate}}</label>
+      <div class="col-sm-8">
+        <textarea class="form-control" placeholder="{{'PAGE.K8S.DESCRIPTION' | translate}}" type="text"
+          formControlName="description" id="description"
+          [ngClass]="{ 'is-invalid': submitted && f.description.errors }"></textarea>
+      </div>
+    </div>
+    <div class="form-group row mb-3" *ngIf="profileType === 'card_node'">
+      <label class="col-sm-4 col-form-label" for="k8s_version">{{'PAGE.K8S.NODESIZE' | translate}}*</label>
+      <div class="col-sm-8">
+        <input autocomplete="off" class="form-control" placeholder="{{'PAGE.K8S.NODESIZE' | translate}}" type="text"
+          formControlName="node_size" id="node_size" [ngClass]="{ 'is-invalid': submitted && f.node_size.errors }"
+          required>
+      </div>
+    </div>
+    <div class="form-group row mb-3" *ngIf="profileType === 'card_node'">
+      <label class="col-sm-4 col-form-label" for="k8s_version">{{'PAGE.K8S.NODECOUNT' | translate}}*</label>
+      <div class="col-sm-8">
+        <input autocomplete="off" class="form-control" placeholder="{{'PAGE.K8S.NODECOUNT' | translate}}" type="text"
+          formControlName="node_count" id="node_count" [ngClass]="{ 'is-invalid': submitted && f.node_count.errors }"
+          required>
+      </div>
+    </div>
+    <div class="form-group row mb-3" *ngIf="profileType === 'k8s-scale'">
+      <label class="col-sm-4 col-form-label" for="k8s_version">{{'PAGE.K8S.NODECOUNT' | translate}}</label>
+      <div class="col-sm-8">
+        <input autocomplete="off" class="form-control" placeholder="{{'PAGE.K8S.NODECOUNT' | translate}}" type="text"
+          formControlName="nodeCount" id="node_count" [ngClass]="{ 'is-invalid': submitted && f.node_count.errors }">
+      </div>
+    </div>
+    <div class="form-group row mb-3" *ngIf="profileType === 'card_node'">
+      <label class="col-sm-4 col-form-label" for="k8s_version">{{'PAGE.K8S.NODEROLE' | translate}}</label>
+      <div class="col-sm-8">
+        <input autocomplete="off" class="form-control" placeholder="{{'arn:aws:iam::[account-id]:role/[role-name]' | translate}}" type="text"
+          formControlName="role" id="role" [ngClass]="{ 'is-invalid': submitted && f.role.errors }">
+      </div>
+    </div>
+    <div class="card bg-light" *ngIf="profileType === 'card_node'">
+      <div class="card-body">
+        <div class="form-group row mb-3">
+          <label class="col-sm-4 col-form-label fw-semibold" for="k8s_version">{{'PAGE.K8S.SUBNET' | translate}}*</label>
+        </div>
+        <div class="form-group row mb-3">
+          <label class="col-sm-4 col-form-label" for="subnets_id">{{ 'PAGE.K8S.PRIVATESUBNET' | translate }}</label>
+          <div class="col-sm-8">
+            <ng-select placeholder="{{'SELECT' | translate}} {{'PAGE.K8S.PRIVATESUBNET' | translate}}"
+              [items]="privatesubnetItems" bindLabel="id" bindValue="id" [multiple]="true" id="private_subnet"
+              formControlName="private_subnet" [ngClass]="{ 'is-invalid': submitted && f.private_subnet.errors }"
+              [(ngModel)]="privateItems">
+            </ng-select>
+          </div>
+        </div>
+        <div class="form-group row mb-3">
+          <label class="col-sm-4 col-form-label" for="subnets_id">{{ 'PAGE.K8S.PUBLICSUBNET' | translate }}</label>
+          <div class="col-sm-8">
+            <ng-select placeholder="{{'SELECT' | translate}} {{'PAGE.K8S.PUBLICSUBNET' | translate}}"
+              [items]="publicsubnetItems" bindLabel="id" bindValue="id" [multiple]="true" id="public_subnet"
+              formControlName="public_subnet" [ngClass]="{ 'is-invalid': submitted && f.public_subnet.errors }"
+              [(ngModel)]="publicItems">
+            </ng-select>
+          </div>
+        </div>
+      </div>
+    </div>
+  </div>
+  <div class="modal-footer">
+    <button type="button" class="btn btn-danger" (click)="activeModal.close()">{{'CANCEL' | translate}}</button>
+    <button *ngIf="profileType === 'card_node'" type="submit" class="btn btn-primary">{{'CREATE' | translate}}</button>
+    <button *ngIf="profileType === 'k8s-scale' || profileType === 'edit-node'" type="submit"
+      class="btn btn-primary">{{'APPLY'
+      | translate}}</button>
+  </div>
+</form>
+<app-loader [waitingMessage]="message" *ngIf="isLoadingResults"></app-loader>
\ No newline at end of file
diff --git a/src/app/k8s/node-add/NodeAddComponent.scss b/src/app/k8s/node-add/NodeAddComponent.scss
new file mode 100644
index 0000000..c55461a
--- /dev/null
+++ b/src/app/k8s/node-add/NodeAddComponent.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/k8s/node-add/NodeAddComponent.ts b/src/app/k8s/node-add/NodeAddComponent.ts
new file mode 100644
index 0000000..604a869
--- /dev/null
+++ b/src/app/k8s/node-add/NodeAddComponent.ts
@@ -0,0 +1,359 @@
+/*
+ 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 K8sAddClusterComponent.ts.
+ */
+import { HttpHeaders } from '@angular/common/http';
+import { Component, Injector, Input, OnInit } from '@angular/core';
+import { AbstractControl, FormBuilder, FormControl, FormGroup, Validators } from '@angular/forms';
+import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
+import { TranslateService } from '@ngx-translate/core';
+import { NotifierService } from 'angular-notifier';
+import { APIURLHEADER, ERRORDATA, MODALCLOSERESPONSEDATA, TYPESECTION } from 'CommonModel';
+import { environment } from 'environment';
+import { K8SCLUSTERDATA, K8SPayload } from 'K8sModel';
+import { RestService } from 'RestService';
+import { isNullOrUndefined, SharedService } from 'SharedService';
+/**
+ * Creating Component
+ * @Component takes NodeAddComponent.html as template url
+ */
+@Component({
+    selector: 'app-node-add',
+    templateUrl: './NodeAddComponent.html',
+    styleUrls: ['./NodeAddComponent.scss']
+})
+/** Exporting a class @exports NodeAddComponent */
+export class NodeAddComponent implements OnInit {
+    /** To inject services @public */
+    public injector: Injector;
+
+    /** FormGroup instance added to the form @ html @public */
+    public nodeForm: FormGroup;
+
+    /** Contains all vim account collections */
+    public clusterItems: K8SCLUSTERDATA;
+
+    /** Input contains Modal dialog component Instance @public */
+    @Input() public profileType: string;
+
+    /** Input contains Modal dialog component Instance @public */
+    @Input() public profileID: string;
+
+    /** Input contains Modal dialog component Instance @public */
+    @Input() public clusterId: string;
+
+    /** Instance for active modal service @public */
+    public activeModal: NgbActiveModal;
+
+    /** Variable set for twoway bindng @public  */
+    public vimAccountId: string;
+
+    /** contains url @public  */
+    public clusterUrl: string;
+
+    /** contains privatesubnet items @public  */
+    privateItems: [] = [];
+
+    /** contains publicsubnet items @public  */
+    publicItems: [] = [];
+
+    /** contains privatesubnet items from api @public  */
+    privatesubnetItems: {};
+
+    /** contains publicsubnet itams from api @public  */
+    publicsubnetItems: {};
+
+    /** contains cluster ID @public  */
+    public cluster_name: string;
+
+    /** contains scaling action paylaod@public  */
+    public scalingPayload = {};
+
+    /** Form submission Add */
+    public submitted: boolean = false;
+
+    /** contains payload */
+    public payload: K8SPayload;
+
+    /** Check the loading results @public */
+    public isLoadingResults: boolean = false;
+
+    /** Give the message for the loading @public */
+    public message: string = 'PLEASEWAIT';
+
+    /** FormBuilder instance added to the formBuilder @private */
+    private formBuilder: FormBuilder;
+
+    /** Utilizes rest service for any CRUD operations @private */
+    private restService: RestService;
+
+    /** Notifier service to popup notification @private */
+    private notifierService: NotifierService;
+
+    /** Contains tranlsate instance @private */
+    private translateService: TranslateService;
+
+    /** Controls the header form @private */
+    private headers: HttpHeaders;
+
+    /** Contains all methods related to shared @private */
+    private sharedService: SharedService;
+
+    constructor(injector: Injector) {
+        this.injector = injector;
+        this.restService = this.injector.get(RestService);
+        this.activeModal = this.injector.get(NgbActiveModal);
+        this.formBuilder = this.injector.get(FormBuilder);
+        this.notifierService = this.injector.get(NotifierService);
+        this.translateService = this.injector.get(TranslateService);
+        this.sharedService = this.injector.get(SharedService);
+    }
+
+    public ngOnInit(): void {
+        /** On Initializing call the methods */
+        this.nodeFormAction();
+        this.getDetailsvimAccount();
+        this.headers = new HttpHeaders({
+            Accept: 'application/json',
+            'Content-Type': 'application/json',
+            'Cache-Control': 'no-cache, no-store, must-revalidate, max-age=0'
+        });
+        if (this.profileType === 'card_node') {
+            this.cluster_name = this.clusterId;
+            this.clusterChange();
+        } else if (this.profileType === 'k8s-scale' || this.profileType === 'edit-node') {
+            this.cluster_name = this.clusterId;
+            this.getDetails();
+        }
+        else {
+            this.cluster_name = null;
+        }
+    }
+
+    /** On modal initializing forms  @public */
+    public nodeFormAction(): void {
+        this.nodeForm = this.formBuilder.group({
+            name: ['', [Validators.required]],
+            description: [''],
+            node_count: ['', [Validators.required]],
+            node_size: ['', [Validators.required]],
+            nodeCount: [''],
+            role: [''],
+            public_subnet: [[]],
+            private_subnet: [[]],
+            cluster_id: ['', [Validators.required]],
+            edit_name: ['']
+        });
+    }
+
+    /** convenience getter for easy access to form fields */
+    get f(): FormGroup['controls'] { return this.nodeForm.controls; }
+
+
+    /** Call the vimAccount details in the selection options @public */
+    public getDetailsvimAccount(): void {
+        this.isLoadingResults = true;
+        this.restService.getResource(environment.K8SCREATECLUSTER_URL).subscribe((vimAccounts: K8SCLUSTERDATA) => {
+            this.clusterItems = vimAccounts;
+            this.isLoadingResults = false;
+        }, (error: ERRORDATA) => {
+            this.restService.handleError(error, 'get');
+            this.isLoadingResults = false;
+        });
+    }
+
+    /** To patch value for edit @public */
+    public getDetails(): void {
+        this.isLoadingResults = true;
+        this.restService.getResource(environment.K8SCREATECLUSTER_URL + '/' + this.cluster_name + '/nodegroup' + '/' + this.profileID).subscribe((vimAccounts: K8SCLUSTERDATA) => {
+            if (this.profileType === 'edit-node') {
+                this.nodeForm.patchValue({ edit_name: vimAccounts.name, description: vimAccounts.description });
+            } else if (this.profileType === 'k8s-scale') {
+                this.nodeForm.patchValue({ nodeCount: vimAccounts.node_count });
+            }
+            this.isLoadingResults = false;
+        }, (error: ERRORDATA) => {
+            this.restService.handleError(error, 'get');
+            this.isLoadingResults = false;
+        });
+    }
+
+    /** To get privatesubnet and publicsubnet details @public */
+    public clusterChange(): void {
+        this.isLoadingResults = true;
+        this.restService.getResource(environment.K8SCREATECLUSTER_URL + '/' + this.cluster_name).subscribe((vimAccounts: K8SCLUSTERDATA) => {
+            if (!isNullOrUndefined(vimAccounts)) {
+                this.privatesubnetItems = vimAccounts.private_subnet;
+                this.publicsubnetItems = vimAccounts.public_subnet;
+            }
+            this.isLoadingResults = false;
+        }, (error: ERRORDATA) => {
+            this.restService.handleError(error, 'get');
+            this.isLoadingResults = false;
+        });
+    }
+
+    /** On modal submit nodeSubmit will called @public */
+    public nodeSubmit(): void {
+        if (this.profileType === 'card_node') {
+            this.getFormControl('nodeCount').disable();
+            this.getFormControl('cluster_id').disable();
+            this.getFormControl('edit_name').disable();
+            this.clusterUrl = environment.K8SCREATECLUSTER_URL + '/' + this.cluster_name + '/nodegroup';
+            this.createNode();
+        } else if (this.profileType === 'k8s-scale') {
+            this.getFormControl('cluster_id').disable();
+            this.getFormControl('name').disable();
+            this.getFormControl('description').disable();
+            this.getFormControl('private_subnet').disable();
+            this.getFormControl('public_subnet').disable();
+            this.getFormControl('role').disable();
+            this.getFormControl('node_count').disable();
+            this.getFormControl('node_size').disable();
+            this.getFormControl('edit_name').disable();
+            this.clusterUrl = environment.K8SCREATECLUSTER_URL + '/' + this.cluster_name + '/nodegroup' + '/' + this.profileID + '/scale';
+            this.scaling();
+        } else if (this.profileType === 'edit-node') {
+            this.getFormControl('cluster_id').disable();
+            this.getFormControl('nodeCount').disable();
+            this.getFormControl('private_subnet').disable();
+            this.getFormControl('public_subnet').disable();
+            this.getFormControl('role').disable();
+            this.getFormControl('node_count').disable();
+            this.getFormControl('node_size').disable();
+            this.getFormControl('name').disable();
+            this.clusterUrl = environment.K8SCREATECLUSTER_URL + '/' + this.cluster_name + '/nodegroup' + '/' + this.profileID;
+            this.update();
+        }
+    }
+
+    /** Create Node @public */
+    public createNode(): void {
+        this.submitted = true;
+        this.sharedService.cleanForm(this.nodeForm);
+        if (this.nodeForm.invalid) {
+            return;
+        }
+        const modalData: MODALCLOSERESPONSEDATA = {
+            message: 'Done'
+        };
+        const apiURLHeader: APIURLHEADER = {
+            url: this.clusterUrl,
+            httpOptions: { headers: this.headers }
+        };
+        this.isLoadingResults = true;
+        const formData = this.nodeForm.value;
+        const payload = Object.keys(formData).reduce((acc, key) => {
+            const value = formData[key];
+            if (key === 'node_count' && value !== null && value !== undefined && value !== '') {
+                acc[key] = Number(value);
+            } else if (value !== null && value !== undefined && value !== '' && value.length !== 0) {
+                acc[key] = value;
+            }
+            return acc;
+        }, {});
+        this.restService.postResource(apiURLHeader, payload).subscribe((result: {}) => {
+            this.activeModal.close(modalData);
+            this.isLoadingResults = false;
+            this.notifierService.notify('success', this.nodeForm.value.name +
+                this.translateService.instant('PAGE.K8S.NODECREATEDSUCCESSFULLY'));
+        }, (error: ERRORDATA) => {
+            this.restService.handleError(error, 'post');
+            this.isLoadingResults = false;
+        });
+    }
+    /** Node Scaling @public */
+    public scaling(): void {
+        this.submitted = true;
+        this.sharedService.cleanForm(this.nodeForm);
+        if (this.nodeForm.invalid) {
+            return;
+        }
+        const modalData: MODALCLOSERESPONSEDATA = {
+            message: 'Done'
+        };
+        const apiURLHeader: APIURLHEADER = {
+            url: this.clusterUrl,
+            httpOptions: { headers: this.headers }
+        };
+        this.isLoadingResults = true;
+        if (this.profileType === 'k8s-scale') {
+            this.scalingPayload = {
+                node_count: Number(this.nodeForm.value.nodeCount)
+            };
+        }
+        this.restService.postResource(apiURLHeader, this.scalingPayload).subscribe((result: {}) => {
+            this.activeModal.close(modalData);
+            this.isLoadingResults = false;
+            this.notifierService.notify('success',
+                this.translateService.instant('PAGE.K8S.NODEUPDATEDSUCCESSFULLY'));
+        }, (error: ERRORDATA) => {
+            this.restService.handleError(error, 'post');
+            this.isLoadingResults = false;
+        });
+    }
+    /** Node update @public */
+    public update(): void {
+        this.submitted = true;
+        this.sharedService.cleanForm(this.nodeForm);
+        if (this.nodeForm.invalid) {
+            return;
+        }
+        const modalData: MODALCLOSERESPONSEDATA = {
+            message: 'Done'
+        };
+        const apiURLHeader: APIURLHEADER = {
+            url: this.clusterUrl,
+            httpOptions: { headers: this.headers }
+        };
+        this.isLoadingResults = true;
+        if (this.profileType === 'edit-node') {
+            if (this.nodeForm.value.description === '') {
+                this.scalingPayload = {
+                    name: this.nodeForm.value.edit_name
+                };
+                delete this.nodeForm.value.description;
+            } else if (this.nodeForm.value.name === '') {
+                this.scalingPayload = {
+                    description: this.nodeForm.value.description
+                };
+                delete this.nodeForm.value.name;
+            } else {
+                this.scalingPayload = {
+                    name: this.nodeForm.value.edit_name,
+                    description: this.nodeForm.value.description
+                };
+            }
+        }
+        this.restService.patchResource(apiURLHeader, this.scalingPayload).subscribe((result: {}) => {
+            this.activeModal.close(modalData);
+            this.isLoadingResults = false;
+            this.notifierService.notify('success',
+                this.translateService.instant('PAGE.K8S.NODEUPDATEDSUCCESSFULLY'));
+        }, (error: ERRORDATA) => {
+            this.restService.handleError(error, 'post');
+            this.isLoadingResults = false;
+        });
+    }
+    /** Used to get the AbstractControl of controlName passed @private */
+    private getFormControl(controlName: string): AbstractControl {
+        // eslint-disable-next-line security/detect-object-injection
+        return this.nodeForm.controls[controlName];
+    }
+}