You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@datalab.apache.org by hs...@apache.org on 2022/02/28 10:44:32 UTC

[incubator-datalab] branch DATALAB-2697 updated: temp commit

This is an automated email from the ASF dual-hosted git repository.

hshpak pushed a commit to branch DATALAB-2697
in repository https://gitbox.apache.org/repos/asf/incubator-datalab.git


The following commit(s) were added to refs/heads/DATALAB-2697 by this push:
     new 788a895  temp commit
     new c1dce88  Merge pull request #1440 from GennadiyShpak/feat/DATALAB-2697/Support-possibility-to-start-instance
788a895 is described below

commit 788a895aef76ac9c5c525c8b9eff141acfe7e420
Author: Hennadii_Shpak <bo...@gmail.com>
AuthorDate: Mon Feb 28 12:43:27 2022 +0200

    temp commit
---
 .../management/management.component.ts             | 172 +++++++++++----------
 .../administration/management/management.model.ts  |  21 +++
 2 files changed, 112 insertions(+), 81 deletions(-)

diff --git a/services/self-service/src/main/resources/webapp/src/app/administration/management/management.component.ts b/services/self-service/src/main/resources/webapp/src/app/administration/management/management.component.ts
index 9ce01ad..e655021 100644
--- a/services/self-service/src/main/resources/webapp/src/app/administration/management/management.component.ts
+++ b/services/self-service/src/main/resources/webapp/src/app/administration/management/management.component.ts
@@ -29,7 +29,7 @@ import {
   StorageService
 } from '../../core/services';
 
-import { EnvironmentModel, GeneralEnvironmentStatus } from './management.model';
+import { ActionsType, EnvironmentModel, GeneralEnvironmentStatus, ModalData, ModalDataType } from './management.model';
 import { HTTP_STATUS_CODES } from '../../core/util';
 import { BackupDilogComponent } from './backup-dilog/backup-dilog.component';
 import { SsnMonitorComponent } from './ssn-monitor/ssn-monitor.component';
@@ -225,86 +225,7 @@ export class ManagementComponent implements OnInit {
 
   toggleResourceAction($event): void {
     const { environment, action, resource } = $event;
-    if (resource) {
-      const resource_name = resource ? resource.computational_name : environment.name;
-      this.dialog.open(ReconfirmationDialogComponent, {
-        data: { 
-          action, 
-          resource_name, 
-          user: environment.user, 
-          type: 'cluster' 
-        },
-        width: '550px', 
-        panelClass: 'error-modalbox'
-      }).afterClosed().subscribe(result => {
-        result && this.manageEnvironmentAction({ action, environment, resource });
-      });
-    } else {
-      let notebooks = this.selected.length ? this.selected : [environment];
-      if (action === 'stop') {
-        notebooks = notebooks.filter(note => note.status !== 'stopped');
-        this.dialog.open(ReconfirmationDialogComponent, {
-          data: { 
-            notebooks: notebooks, 
-            type: 'notebook', 
-            action 
-          },
-          width: '550px', 
-          panelClass: 'error-modalbox'
-        }).afterClosed().subscribe((res) => {
-          if (res) {
-            notebooks.forEach((env) => {
-              this.manageEnvironmentsService.environmentManagement(env.user, 'stop', env.project, env.name)
-                .subscribe(response => {
-                  this.buildGrid();
-                },
-                  error => console.log(error)
-                );
-            });
-            this.clearSelection();
-          } else {
-            this.clearSelection();
-          }
-          this.isActionsOpen = false;
-        });
-      } else if (action === 'terminate') {
-        this.dialog.open(ReconfirmationDialogComponent, {
-          data: { 
-            notebooks: notebooks, 
-            type: 'notebook', 
-            action 
-          }, 
-          width: '550px', 
-          panelClass: 'error-modalbox'
-        }).afterClosed().subscribe((res) => {
-          if (res) {
-            notebooks.forEach((env) => {
-              this.manageEnvironmentsService.environmentManagement(env.user, 'terminate', env.project, env.name)
-                .subscribe(
-                  response => {
-                    this.buildGrid();
-                  },
-                  error => console.log(error)
-                );
-            });
-            this.clearSelection();
-          } else {
-            this.clearSelection();
-          }
-          this.isActionsOpen = false;
-        });
-        // } else if (action === 'run') {
-        //   this.healthStatusService.runEdgeNode().subscribe(() => {
-        //     this.buildGrid();
-        //     this.toastr.success('Edge node is starting!', 'Processing!');
-        //   }, () => this.toastr.error('Edge Node running failed!', 'Oops!'));
-        // } else if (action === 'recreate') {
-        //   this.healthStatusService.recreateEdgeNode().subscribe(() => {
-        //     this.buildGrid();
-        //     this.toastr.success('Edge Node recreation is processing!', 'Processing!');
-        //   }, () => this.toastr.error('Edge Node recreation failed!', 'Oops!'));
-      }
-    }
+    this.openDialog(environment, action, resource);
   }
 
   private clearSelection() {
@@ -319,4 +240,93 @@ export class ManagementComponent implements OnInit {
   public resourseAction(action) {
     this.toggleResourceAction({ environment: this.selected, action: action });
   }
+
+  private openDialog(environment, action, resource) {
+    let config: ModalData = { 
+      type: '', 
+      action 
+    };
+    let observer = {
+      next: (res) => {}
+    };
+
+    if(resource) {
+      config.resource_name = resource.computational_name;
+      config.user = environment.user;
+      config.type = ModalDataType.cluster
+      observer.next = (res) => {
+        res && this.manageEnvironmentAction({ action, environment, resource })
+      }
+    } else {
+      const notebooks = this.selected.length ? this.selected : [environment];
+      config = this.getModalConfig(config, action, notebooks);
+      observer.next = (res) => {
+        if (res) {
+          notebooks.forEach((env) => {
+            this.getNotebookAction(env, action)
+          });
+        }
+        this.clearSelection();
+      }
+      this.isActionsOpen = false;
+    }
+
+    //TODO if action run and recreate are restored, uncomment this piece of code
+
+    // if(action === 'run' || action === 'recreate') {
+    //   this.getHealthAction(action);
+    // } else {
+    //   this.dialog.open(ReconfirmationDialogComponent, {
+    //     data: config,
+    //     width: '550px', 
+    //     panelClass: 'error-modalbox'
+    //   }).afterClosed().subscribe(observer);
+    // }
+
+    //TODO if action run and recreate are restored remove this piece of code
+    
+      this.dialog.open(ReconfirmationDialogComponent, {
+        data: config,
+        width: '550px', 
+        panelClass: 'error-modalbox'
+      }).afterClosed().subscribe(observer);
+  }
+
+  private getModalConfig(config: ModalData, action: ActionsType, notebooks: EnvironmentModel[]): ModalData {
+    config = {...config, type: ModalDataType.notebook}
+    if(action === ActionsType.stop) {
+      notebooks = notebooks.filter(note => note.status !== 'stopped');
+      return {...config, notebooks}
+    }
+    return {...config, notebooks}
+  }
+
+  private getNotebookAction(env: EnvironmentModel, action: ActionsType) {
+    this.manageEnvironmentsService.environmentManagement(env.user, action, env.project, env.name)
+      .subscribe(
+        () => this.buildGrid(),
+        error => console.log(error)
+      );
+  }
+
+  private getHealthAction(action: ActionsType) {
+    let nodeAction: ActionsType.run | ActionsType.recreate;
+    const observer = {
+      next: () => {
+        this.buildGrid();
+        this.toastr.success(`Edge Node ${nodeAction} is processing!`, 'Processing!');
+      },
+      error: () => this.toastr.error(`Edge Node ${nodeAction} failed!`, 'Oops!')
+    }
+    if(action === ActionsType.run) {
+      nodeAction = ActionsType.run;
+      this.healthStatusService.runEdgeNode().subscribe(observer)
+    }
+    if(action === ActionsType.recreate) {
+      nodeAction = ActionsType.recreate
+      this.healthStatusService.recreateEdgeNode().subscribe(observer)
+    }
+  }
 }
+
+
diff --git a/services/self-service/src/main/resources/webapp/src/app/administration/management/management.model.ts b/services/self-service/src/main/resources/webapp/src/app/administration/management/management.model.ts
index 2e67871..56ce00f 100644
--- a/services/self-service/src/main/resources/webapp/src/app/administration/management/management.model.ts
+++ b/services/self-service/src/main/resources/webapp/src/app/administration/management/management.model.ts
@@ -114,3 +114,24 @@ export class ManagementConfigModel {
     this.endpoints = [];
   }
 }
+
+export interface ModalData {
+  action: ActionsType;
+  resource_name?: any; 
+  user?: any, 
+  type: string;
+  notebooks?: any
+}
+
+export enum ModalDataType {
+  cluster = 'cluster',
+  notebook = 'notebook',
+}
+
+export enum ActionsType {
+  stop = 'stop',
+  terminate = 'terminate',
+  start = 'start',
+  run = 'run',
+  recreate = 'recreate'
+}
\ No newline at end of file

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datalab.apache.org
For additional commands, e-mail: commits-help@datalab.apache.org