Advanced Cluster Management Enhancements

	- Chnaged cluster page design from switch to single page
	- Added bootstrap option in creation and registration
	- Added horizontal scaling, vertical scaling and upgrade in
	  cluster action
	- In cluster page, for list combined two apis to show list done
	  temporary fix from UI

Change-Id: Ie4d30f5db28025ec92398cc60fc50ab7030f8f9b
Signed-off-by: SANDHYA.JS <sandhya.j@tataelxsi.co.in>
diff --git a/src/app/k8s/k8s-add-cluster/K8sAddClusterComponent.ts b/src/app/k8s/k8s-add-cluster/K8sAddClusterComponent.ts
index bb5dcfa..cf03f0f 100644
--- a/src/app/k8s/k8s-add-cluster/K8sAddClusterComponent.ts
+++ b/src/app/k8s/k8s-add-cluster/K8sAddClusterComponent.ts
@@ -29,7 +29,7 @@
 import * as jsyaml from 'js-yaml';
 import { K8SPayload } from 'K8sModel';
 import { RestService } from 'RestService';
-import { SharedService } from 'SharedService';
+import { isNullOrUndefined, SharedService } from 'SharedService';
 import { VimAccountDetails } from 'VimAccountModel';
 /**
  * Creating Component
@@ -81,6 +81,9 @@
   /** contains payload */
   public payload: K8SPayload;
 
+  /** Check the checkbox status */
+  public isChecked: boolean = true;
+
   /** Check the loading results @public */
   public isLoadingResults: boolean = false;
 
@@ -154,14 +157,18 @@
       name: ['', [Validators.required]],
       k8s_version: ['', [Validators.required]],
       vim_account: [null, [Validators.required]],
-      description: ['', [Validators.required]],
+      description: [''],
       nets: ['', [Validators.required]],
       deployment_methods: ['', [Validators.required]],
       credentials: ['', [Validators.required]],
       region_name: [''],
       resource_group: [''],
       node_count: ['', [Validators.required]],
-      node_size: ['', [Validators.required]]
+      node_size: ['', [Validators.required]],
+      bootstrap: [true],
+      k8sVersion: ['', [Validators.required]],
+      nodeCount: ['', [Validators.required]],
+      nodeSize: ['', [Validators.required]]
     });
   }
 
@@ -180,6 +187,11 @@
     });
   }
 
+  /** Call the event when checkbox is checked @public */
+  public getValue(event: Event): void {
+    this.isChecked = (event.target as HTMLInputElement).checked;
+  }
+
 
   /** Contain selected vimAccount details @public */
   public getDetailsvim(event: VimAccountDetails): void {
@@ -192,45 +204,64 @@
       this.getFormControl('nets').disable();
       this.getFormControl('credentials').disable();
       this.getFormControl('deployment_methods').disable();
+      this.getFormControl('k8sVersion').disable();
+      this.getFormControl('nodeSize').disable();
+      this.getFormControl('nodeCount').disable();
       this.manageCluster();
-    } else if (this.profileType === 'Register') {
+    } else if (this.profileType === 'Register' && this.isChecked === true) {
       this.clusterUrl = environment.K8SCREATECLUSTER_URL + '/register';
       this.getFormControl('region_name').disable();
       this.getFormControl('resource_group').disable();
-      this.getFormControl('node_count').disable();
-      this.getFormControl('node_size').disable();
-      this.registerCluster();
-    } else if (this.profileType === 'upgrade') {
-      this.clusterUrl = environment.K8SCREATECLUSTER_URL + '/' + this.profileID + '/' + 'upgrade';
-      this.getFormControl('region_name').disable();
-      this.getFormControl('resource_group').disable();
-      this.getFormControl('node_count').disable();
-      this.getFormControl('node_size').disable();
-      this.getFormControl('nets').disable();
-      this.getFormControl('credentials').disable();
-      this.getFormControl('deployment_methods').disable();
-      this.getFormControl('name').disable();
-      this.getFormControl('vim_account').disable();
-      this.getFormControl('description').disable();
-      this.updateCluster();
-    } else if (this.profileType === 'scale') {
-      this.clusterUrl = environment.K8SCREATECLUSTER_URL + '/' + this.profileID + '/' + 'scale';
-      this.getFormControl('region_name').disable();
-      this.getFormControl('resource_group').disable();
       this.getFormControl('k8s_version').disable();
       this.getFormControl('node_size').disable();
+      this.getFormControl('node_count').disable();
+      this.getFormControl('nets').disable();
+      this.getFormControl('deployment_methods').disable();
+      this.getFormControl('k8sVersion').disable();
+      this.getFormControl('nodeSize').disable();
+      this.getFormControl('nodeCount').disable();
+      this.registerCluster();
+    } if (this.isChecked === false && this.profileType === 'Register') {
+      this.clusterUrl = environment.K8SCLUSTER_URL;
+      this.getFormControl('bootstrap').disable();
+      this.getFormControl('region_name').disable();
+      this.getFormControl('resource_group').disable();
+      this.getFormControl('node_count').disable();
+      this.getFormControl('node_size').disable();
+      this.getFormControl('k8sVersion').disable();
+      this.getFormControl('nodeSize').disable();
+      this.getFormControl('nodeCount').disable();
+      this.oldregisterCluster();
+    } else if (this.profileType === 'upgrade' || this.profileType === 'horizontal' || this.profileType === 'vertical') {
+      this.clusterUrl = environment.K8SCREATECLUSTER_URL + '/' + this.profileID + '/' + 'update';
+      this.getFormControl('region_name').disable();
+      this.getFormControl('resource_group').disable();
       this.getFormControl('nets').disable();
       this.getFormControl('credentials').disable();
       this.getFormControl('deployment_methods').disable();
       this.getFormControl('name').disable();
       this.getFormControl('vim_account').disable();
       this.getFormControl('description').disable();
+      this.getFormControl('bootstrap').disable();
+      this.getFormControl('node_count').disable();
+      this.getFormControl('node_size').disable();
+      this.getFormControl('k8s_version').disable();
+      if (this.profileType === 'upgrade') {
+        this.getFormControl('nodeCount').disable();
+        this.getFormControl('nodeSize').disable();
+      } else if (this.profileType === 'vertical') {
+        this.getFormControl('nodeCount').disable();
+        this.getFormControl('k8sVersion').disable();
+      } else if (this.profileType === 'horizontal') {
+        this.getFormControl('nodeSize').disable();
+        this.getFormControl('k8sVersion').disable();
+      }
       this.updateCluster();
     }
   }
 
-  /** Register cluster @public */
-  public registerCluster(): void {
+  /** Old Register cluster flow @public */
+  public oldregisterCluster(): void {
     this.submitted = true;
     this.sharedService.cleanForm(this.k8sclusterForm);
     if (this.k8sclusterForm.invalid) {
@@ -275,6 +306,49 @@
 
     this.k8sclusterForm.value.vim_account = this.vimAccountId;
 
+    if (this.k8sclusterForm.value.description === '') {
+      delete this.k8sclusterForm.value.description;
+    }
+
+    const apiURLHeader: APIURLHEADER = {
+      url: this.clusterUrl,
+      httpOptions: { headers: this.headers }
+    };
+
+    this.isLoadingResults = true;
+    this.restService.postResource(apiURLHeader, this.k8sclusterForm.value).subscribe((result: {}) => {
+      this.activeModal.close(modalData);
+      this.isLoadingResults = false;
+      this.notifierService.notify('success', this.k8sclusterForm.value.name +
+        this.translateService.instant('PAGE.K8S.REGISTEREDSUCCESSFULLY'));
+    }, (error: ERRORDATA) => {
+      this.restService.handleError(error, 'post');
+      this.isLoadingResults = false;
+    });
+  }
+
+  /** New Register cluster flow @public */
+  public registerCluster(): void {
+    this.submitted = true;
+    this.sharedService.cleanForm(this.k8sclusterForm);
+    if (this.k8sclusterForm.invalid) {
+      return;
+    }
+    const modalData: MODALCLOSERESPONSEDATA = {
+      message: 'Done'
+    };
+    const validJSONCredentails: boolean = this.sharedService.checkJson(this.k8sclusterForm.value.credentials);
+    if (validJSONCredentails) {
+      this.k8sclusterForm.value.credentials = jsyaml.load(this.k8sclusterForm.value.credentials.toString(), { json: true });
+    } else {
+      this.notifierService.notify('error', this.translateService.instant('INVALIDCONFIG'));
+      return;
+    }
+
+    if (this.k8sclusterForm.value.description === '') {
+      delete this.k8sclusterForm.value.description;
+    }
+
     const apiURLHeader: APIURLHEADER = {
       url: this.clusterUrl,
       httpOptions: { headers: this.headers }
@@ -317,16 +391,20 @@
       k8s_version: this.k8sclusterForm.value.k8s_version,
       node_size: this.k8sclusterForm.value.node_size,
       node_count: Number(this.k8sclusterForm.value.node_count),
-      description: this.k8sclusterForm.value.description
+      description: this.k8sclusterForm.value.description,
+      bootstrap: Boolean(this.k8sclusterForm.value.bootstrap)
     };
     if (this.k8sclusterForm.value.region_name === '') {
       delete payload.region_name;
     } else if (this.k8sclusterForm.value.resource_group === '') {
       delete payload.resource_group;
+    } else if (this.k8sclusterForm.value.description === '') {
+      delete payload.description;
     }
-    if (this.k8sclusterForm.value.region_name === '' && this.k8sclusterForm.value.resource_group === '') {
+    if (this.k8sclusterForm.value.region_name === '' && this.k8sclusterForm.value.resource_group === '' && this.k8sclusterForm.value.description === '') {
       delete payload.region_name;
       delete payload.resource_group;
+      delete payload.description;
     }
     this.restService.postResource(apiURLHeader, payload).subscribe((result: {}) => {
       this.activeModal.close(modalData);
@@ -353,17 +431,20 @@
       url: this.clusterUrl,
       httpOptions: { headers: this.headers }
     };
-
-    this.isLoadingResults = true;
     if (this.profileType === 'upgrade') {
       this.payload = {
-        k8s_version: this.k8sclusterForm.value.k8s_version
+        k8s_version: this.k8sclusterForm.value.k8sVersion
       };
-    } else if (this.profileType === 'scale') {
+    } else if (this.profileType === 'vertical') {
       this.payload = {
-        node_count: this.k8sclusterForm.value.node_count
+        node_size: (this.k8sclusterForm.value.nodeSize)
+      };
+    } else if (this.profileType === 'horizontal') {
+      this.payload = {
+        node_count: Number(this.k8sclusterForm.value.nodeCount)
       };
     }
+    this.isLoadingResults = true;
     this.restService.postResource(apiURLHeader, this.payload).subscribe((result: {}) => {
       this.activeModal.close(modalData);
       this.isLoadingResults = false;