From fd8f3bf29fc5777719403e39fc20c155fb40da9c Mon Sep 17 00:00:00 2001 From: Katerina Mastoraki <110672874+katmastt@users.noreply.github.com> Date: Fri, 19 Jan 2024 12:05:06 +0200 Subject: [PATCH] Fixed bugs #158, #153, #154, #155 (#2) --- controllers/AdministrationController.php | 19 +- controllers/ProjectController.php | 2 +- models/ColdStorageRequest.php | 92 +++++++ models/Project.php | 10 +- models/Vm.php | 14 +- views/administration/all_projects.php | 49 +++- views/administration/storage_volumes.php | 254 +++++++++++++++++- views/administration/view_active_jupyters.php | 9 +- views/project/manage_volumes.php | 7 +- web/css/administration/all_projects.css | 7 + web/js/administration/all_projects.js | 13 +- 11 files changed, 436 insertions(+), 40 deletions(-) diff --git a/controllers/AdministrationController.php b/controllers/AdministrationController.php index 8f9869f..2ad7591 100644 --- a/controllers/AdministrationController.php +++ b/controllers/AdministrationController.php @@ -598,7 +598,7 @@ public function actionViewPage($id) return $this->render('view-page',['page'=>$page]); } - public function actionAllProjects() + public function actionAllProjects($exp=-1, $pr_drp=-1, $user='', $project='') { if (!Userw::hasRole('Admin',$superadminAllowed=true)) { @@ -614,9 +614,9 @@ public function actionAllProjects() $deleted=Project::getAllDeletedProjects(); - $filters=['exp'=>Yii::$app->request->post('expiry_date_t','-1'),'user'=>Yii::$app->request->post('username',''), 'type'=>Yii::$app->request->post('project_type','-1')]; - $all_projects=Project::getAllActiveProjectsAdm($filters['user'],$filters['type'],$filters['exp']); - $expired_owner=Project::getAllExpiredProjects($filters['user'],$filters['type'],$filters['exp']); + $filters=['exp'=>Yii::$app->request->post('expiry_date_t','-1'),'user'=>Yii::$app->request->post('username',''), 'type'=>Yii::$app->request->post('project_type','-1'), 'name'=>Yii::$app->request->post('project_name','')]; + $all_projects=Project::getAllActiveProjectsAdm($filters['user'],$filters['type'],$filters['exp'], $filters['name']); + $expired_owner=Project::getAllExpiredProjects($filters['user'],$filters['type'],$filters['exp'], $filters['name']); $resources=Project::getActiveResources(); $role=User::getRoleType(); $username=Userw::getCurrentUser()['username']; @@ -769,11 +769,14 @@ public function actionStorageVolumes() /* * Get storage active projects for user */ - $results=ColdStorageRequest::getActiveProjectsAdmin(); - $services=$results[0]; - $machines=$results[1]; + $results_active=ColdStorageRequest::getActiveProjectsAdmin(); + $active_services=$results_active[0]; + $active_machines=$results_active[1]; + $results_expired=ColdStorageRequest::getExpiredProjectsAdmin(); + $expired_services=$results_expired[0]; + $expired_machines=$results_expired[1]; - return $this->render('storage_volumes', ['services'=>$services, 'machines'=>$machines, 'results'=>$results]); + return $this->render('storage_volumes', ['services'=>$active_services, 'machines'=>$active_machines, 'results'=>$results_active,'expired_services'=>$expired_services, 'expired_machines'=>$expired_machines, 'expired_results'=>$results_expired]); } public function actionReactivate($id) diff --git a/controllers/ProjectController.php b/controllers/ProjectController.php index 96e0a20..8e317f0 100644 --- a/controllers/ProjectController.php +++ b/controllers/ProjectController.php @@ -3380,7 +3380,7 @@ public function actionManageVolumes($id,$vid,$ret='u') $form_params= [ - 'action' => URL::to(['project/manage-volumes','id'=>$id, 'vid'=>$vid,'ret'=>$ret]), + 'action' => URL::to(['project/manage-volumes','id'=>$id, 'vid'=>$vid,'ret'=>$ret,'return'=>$return]), 'method' => 'POST' ]; diff --git a/models/ColdStorageRequest.php b/models/ColdStorageRequest.php index dfa1ea8..e6ecb8b 100644 --- a/models/ColdStorageRequest.php +++ b/models/ColdStorageRequest.php @@ -468,6 +468,98 @@ public static function getActiveProjectsAdmin() } + public static function getExpiredProjectsAdmin() + { + $user=Userw::getCurrentUser()['id']; + $query=new Query; + $date=date("Y-m-d"); + $status=[1,2]; + $results=$query->select(['p.id','u.username','c.vm_type','p.name', 'c.num_of_volumes as vnum']) + ->from('project as p') + ->innerJoin('project_request as pr','p.latest_project_request_id=pr.id') + ->innerJoin('cold_storage_request as c','c.request_id=pr.id') + ->innerJoin('user as u','pr.submitted_by=u.id') + ->where(['<', 'end_date', $date]) + ->andWhere(['IN','pr.status',$status]) + ->orderBy('pr.submission_date DESC') + ->all(); + $machines=[]; + $services=[]; + $project_ids=[]; + + foreach ($results as $res) + { + $project_ids[]=$res['id']; + if($res['vm_type']==1) + { + $services[$res['id']]=$res; + $services[$res['id']]['created_at']=''; + $services[$res['id']]['mountpoint']=''; + $services[$res['id']]['vol_id']=''; + $services[$res['id']]['mult_order']=''; + $services[$res['id']]['vname']=''; + $services[$res['id']]['username']=explode('@',$res['username'])[0]; + + + } + else + { + if (!isset($machines[$res['id']])) + { + $machines[$res['id']]=['count'=>$res['vnum'],'name'=>$res['name']]; + for ($i=1; $i<=$res['vnum']; $i++) + { + $machines[$res['id']][$i]=$res; + $machines[$res['id']][$i]['created_at']=''; + $machines[$res['id']][$i]['mountpoint']=''; + $machines[$res['id']][$i]['vol_id']=''; + $machines[$res['id']][$i]['vmachname']=''; + $machines[$res['id']][$i]['username']=explode('@',$machines[$res['id']][$i]['username'])[0]; + } + + } + + } + + } + + $query=new Query; + $date=date("Y-m-d"); + + $results=$query->select(['h.project_id', 'h.id as vol_id', 'h.created_at', 'h.mountpoint', + 'h.active', 'h.mult_order', 'v.name as vname', 'h.vm_type', 'vmach.name as vmachname']) + ->from('hot_volumes as h') + ->leftJoin('vm as v','v.id=h.vm_id') + ->leftJoin('vm_machines as vmach','vmach.id=h.vm_id') + ->where(['IN','h.project_id',$project_ids]) + ->andWhere(['h.active'=>true]) + ->all(); + + foreach ($results as $res) + { + if($res['vm_type']==1) + { + $services[$res['project_id']]['created_at']=$res['created_at']; + $services[$res['project_id']]['mountpoint']=$res['mountpoint']; + $services[$res['project_id']]['vol_id']=$res['vol_id']; + $services[$res['project_id']]['mult_order']=$res['mult_order']; + $services[$res['project_id']]['vname']=$res['vname']; + + } + else + { + $machines[$res['project_id']][$res['mult_order']]['created_at']=$res['created_at']; + $machines[$res['project_id']][$res['mult_order']]['mountpoint']=$res['mountpoint']; + $machines[$res['project_id']][$res['mult_order']]['vol_id']=$res['vol_id']; + $machines[$res['project_id']][$res['mult_order']]['vmachname']=$res['vmachname']; + } + + } + + return [$services,$machines]; + + } + public function changed($new) { $changed=false; diff --git a/models/Project.php b/models/Project.php index 885f4a9..3c967a5 100644 --- a/models/Project.php +++ b/models/Project.php @@ -454,7 +454,7 @@ public static function getAllDeletedProjects() } - public static function getAllExpiredProjects($user='',$type='-1',$exp='-1') + public static function getAllExpiredProjects($user='',$type='-1',$exp='-1', $name='') { $query=new Query; @@ -486,6 +486,9 @@ public static function getAllExpiredProjects($user='',$type='-1',$exp='-1') $query->orderBy('pr.end_date ASC'); } + if (!empty($name)){ + $query->andWhere("p.name like '%$name%'"); + } $results=$query->all(); @@ -551,7 +554,7 @@ public static function getActiveResources() return [$active_jupyter, $active_vms, $active_machines, $active_volumes]; } - public static function getAllActiveProjectsAdm($user='',$type='-1', $exp='-1') + public static function getAllActiveProjectsAdm($user='',$type='-1', $exp='-1', $name='') { $query=new Query; $date=date("Y-m-d"); @@ -584,6 +587,9 @@ public static function getAllActiveProjectsAdm($user='',$type='-1', $exp='-1') $query->orderBy('pr.end_date ASC'); } + if(!empty($name)){ + $query->andWhere("p.name like '%$name%'"); + } $results=$query->all(); return $results; diff --git a/models/Vm.php b/models/Vm.php index 65031b9..bab3e73 100644 --- a/models/Vm.php +++ b/models/Vm.php @@ -1146,17 +1146,13 @@ public function deleteVM() { $vmid=$this->id; $user=Userw::getCurrentUser()['id']; - Yii::$app->db->createCommand() - ->update('vm',['deleted_by'=>$user,], "id=$this->id") - ->execute(); - $result=self::authenticate(); $this->token=$result[0]; $message=$result[1]; if (empty($this->token)) { - return [1,$this->$delete_errors[1],$message]; + return [1,$this->delete_errors[1],$message]; } $result=$this->deleteIP(); @@ -1165,7 +1161,7 @@ public function deleteVM() if (!$ipDeleted) { - return [2,$this->$delete_errors[2],$message]; + return [2,$this->delete_errors[2],$message]; } $result=$this->deleteServer(); @@ -1173,7 +1169,7 @@ public function deleteVM() $message=$result[1]; if (!$serverDeleted) { - return [3,$this->$delete_errors[3],$message]; + return [3,$this->delete_errors[3],$message]; } $result=$this->deleteKey($this->keypair_name); @@ -1184,6 +1180,10 @@ public function deleteVM() return [4,$this->$delete_errors[4],$message]; } + Yii::$app->db->createCommand() + ->update('vm',['deleted_by'=>$user,], "id=$this->id") + ->execute(); + Yii::$app->db->createCommand() ->update('vm',['active'=>false,'deleted_at'=>'NOW()'], "id=$this->id") ->execute(); diff --git a/views/administration/all_projects.php b/views/administration/all_projects.php index 92d2b9f..cfcfb70 100644 --- a/views/administration/all_projects.php +++ b/views/administration/all_projects.php @@ -245,8 +245,8 @@ { $projectLink="https://schema.imsi.athenarc.gr?r=software/index&selected_project=". $res['name']; $projectTarget='_blank'; - $project_icon=''; - $title='On-demand batch computation'; + $project_icon=''; + $title='On-demand batch computation project'; if (isset($active_resources[0][$res['name']])) { $active=true; @@ -257,12 +257,31 @@ } } + else if ($res['project_type']==4) { + + $projectLink=$schema_url; + if(empty($schema_url)) + { + $ondemand_access_class='disabled'; + } + $projectTarget='_blank'; + $project_icon=''; + $title='On demand notebooks'; + if (isset($active_resources[4][$res['project_id']])) + { + $active=true; + } + else + { + $active=false; + } + } else if ($res['project_type']==1) { $projectLink=Url::to(['/project/configure-vm','id'=>$res['id']]); $projectTarget='_self'; - $project_icon=''; - $title='24/7 Service'; + $project_icon=''; + $title='24/7 service project'; if (isset($active_resources[1][$res['project_id']])) { $active=true; @@ -277,8 +296,8 @@ { $projectLink=Url::to(['/project/machine-compute-configure-vm','id'=>$res['id']]); $projectTarget='_self'; - $project_icon=''; - $title='On-demand computation machines'; + $project_icon=''; + $title='On-demand computation machines project'; if (isset($active_resources[2][$res['project_id']])) { $active=true; @@ -294,7 +313,7 @@ $projectLink=Url::to(['/site/under-construction']); $projectTarget='_self'; $project_icon=''; - $title='Cold Storage'; + $title='Storage volume project'; $active=false; } @@ -364,6 +383,7 @@

Filter

'filters-form'])?> +
@@ -376,7 +396,6 @@
 
-
@@ -384,12 +403,23 @@
- 'username_field'])?> + 'username_field','id'=>'username'])?>
 
+
+
+ +
+
+
+
+ 'projectname_field','id'=>'project_name'])?> +
+
+
 
@@ -401,6 +431,7 @@
+
 
diff --git a/views/administration/storage_volumes.php b/views/administration/storage_volumes.php index 651a1d9..c13eb63 100644 --- a/views/administration/storage_volumes.php +++ b/views/administration/storage_volumes.php @@ -30,7 +30,7 @@ 'buttons'=> [ - ['fontawesome_class'=>'','name'=> 'Back', 'action'=>['/project/index'], + ['fontawesome_class'=>'','name'=> 'Back', 'action'=>['/administration/index'], 'options'=>['class'=>'btn btn-default'], 'type'=>'a'], ['fontawesome_class'=>'','name'=> 'Volume guide', 'action'=>['site/additional-storage-tutorial'], 'options'=>['class'=>'btn btn-primary', 'title'=>'Guide to partition, format and mount a volume, which is attached to a VM', 'target'=>'_blank'], 'type'=>'a'] @@ -46,7 +46,7 @@ -

Volumes for 24/7 services

+

Active volumes for 24/7 services

@@ -121,16 +121,100 @@ else {?>
-

No active volumes for on-demand computation machines

+

No active volumes for 24/7 serviced

+ +

Expired volumes for 24/7 services

+
+ + + + + + + + + + + + $res) + { + $manage_button_class=''; + if(empty($res['vol_id'])) + { + $vol_id=''; + $manage_button_class='disabled'; + } + else + { + $vol_id=$res['vol_id']; + } + + if (!empty($res['created_at'])) + { + $obj=new DateTime($res['created_at']); + $cdate=$obj->format('d-m-Y'); + } + else + { + $cdate='-'; + } + + + ?> + + + + + + + + + + +
Volume nameCreated atAttached toOn 

()
+ + + "btn btn-danger btn-md delete-volume-btn", + 'id'=>"delete-$vol_id"])?> + + $res['id'],'ret'=>'a'],['class'=>"btn btn-success btn-md"])?> + + $pid, 'vid'=>$vol_id, 'ret'=>'a'],['class'=>"btn btn-secondary btn-md $manage_button_class"])?> +
+
+ +
+

No expired volumes for 24/7 services

+
+ + + -

Volumes for on-demand computation machines

+

Active volumes for on-demand computation machines

@@ -222,6 +306,100 @@ +

Expired volumes for on-demand computation machines

+
+ + + + + + + + + + + $proj) + { + for ($i=1; $i<=$proj['count']; $i++) + { + $manage_button_class=''; + if(empty($proj[$i]['vol_id'])) + { + $manage_button_class='disabled'; + } + + $vol_id=''; + if(!empty($proj[$i]['vol_id'])) + { + $vol_id=$proj[$i]['vol_id']; + } + + if ($proj['count']>1) + { + $pname=$proj['name'] . '_' . $i; + } + else + { + $pname=$proj['name']; + } + + if (!empty($proj[$i]['created_at'])) + { + $obj=new DateTime($proj[$i]['created_at']); + $cdate=$obj->format('d-m-Y'); + } + else + { + $cdate='-'; + } + ?> + + + + + + + + + + + +
Volume nameCreated atAttached toOn 

+ + + "btn btn-danger btn-md delete-volume-btn", + 'id'=>"delete-$vol_id"])?> + + $pid,'order'=>$i,'ret'=>'a'],['class'=>"btn btn-success btn-md"])?> + + $pid,'vid'=>$vol_id,'ret'=>'a'], ['class'=>"btn btn-secondary btn-md $manage_button_class"])?> +
+
+ +
+

No expired volumes for on-demand computation machines

+
+$res) { @@ -255,6 +433,38 @@ $res) +{ + if (empty($res['vol_id'])) + { + continue; + } + else + { + $vol_id=$res['vol_id']; + } +?> + + $proj) { for ($i=1; $i<=$proj['count']; $i++) @@ -289,5 +499,39 @@ +foreach ($expired_machines as $pid => $proj) +{ + for ($i=1; $i<=$proj['count']; $i++) + { + if (empty($proj[$i]['vol_id'])) + { + continue; + } + else + { + $vol_id=$proj[$i]['vol_id']; + } + ?> + + diff --git a/views/administration/view_active_jupyters.php b/views/administration/view_active_jupyters.php index d1f158f..b823bfc 100644 --- a/views/administration/view_active_jupyters.php +++ b/views/administration/view_active_jupyters.php @@ -21,10 +21,13 @@ ['title'=>$this->title, 'buttons'=> [ - ['fontawesome_class'=>$expired_icon,'name'=> 'Clear expired project servers', 'action'=>['project/stop-expired-jupyter-servers'], - 'options'=>['class'=>"btn btn-danger btn-md delete-volume-btn"], 'type'=>'a'], + + ['fontawesome_class'=>$expired_icon, "name"=> 'Clear expired servers','action'=>['project/stop-expired-jupyter-servers'],'options'=>['class'=>"btn btn-danger btn-md delete-volume-btn",'data' => [ + 'confirm' => 'Are you sure you want to delete all the expired servers ?', + 'method' => 'post', + ],], 'type'=>'a'], ['fontawesome_class'=>$back_icon,'name'=> 'Back', 'action'=>['administration/index'], - 'options'=>['class'=>'btn btn-default'], 'type'=>'a'], + 'options'=>['class'=>'btn btn-default'], 'type'=>'a'] ], ]) diff --git a/views/project/manage_volumes.php b/views/project/manage_volumes.php index 37e604c..dad16dd 100644 --- a/views/project/manage_volumes.php +++ b/views/project/manage_volumes.php @@ -10,6 +10,11 @@ // $this->registerJsFile('@web/js/project/project-request.js', ['depends' => [\yii\web\JqueryAsset::className()]]); $this->title="Manage volume"; +if ($ret == 'a'){ + $return='administration/storage-volumes'; +}else{ + $return='project/storage-volumes'; +} $unlink_icon=''; $link_icon=''; ?> @@ -23,7 +28,7 @@ 'buttons'=> [ - ['fontawesome_class'=>'','name'=> 'Back', 'action'=>['/project/storage-volumes'], + ['fontawesome_class'=>'','name'=> 'Back', 'action'=>[$return], 'options'=>['class'=>'btn btn-default'], 'type'=>'a'] ], ]) diff --git a/web/css/administration/all_projects.css b/web/css/administration/all_projects.css index 83ed1d1..4e8dc7c 100644 --- a/web/css/administration/all_projects.css +++ b/web/css/administration/all_projects.css @@ -53,6 +53,13 @@ } .username_field +{ + border-radius: 5px; + width: 100%; + border:1px solid #8f8f9d; +} + +.projectname_field { border-radius: 5px; width: 100%; diff --git a/web/js/administration/all_projects.js b/web/js/administration/all_projects.js index 654bf0e..223a0b5 100644 --- a/web/js/administration/all_projects.js +++ b/web/js/administration/all_projects.js @@ -18,10 +18,15 @@ $(document).ready(function(){ $("#types_dropdown").change(function(){ $('#filters-form').submit(); }); - - $("#expiry_date").change(function(){ - $('#filters-form').submit(); - }); + $("#expiry_date").change(function(){ + $('#filters-form').submit(); + }); + $("#username").change(function(){ + $('#filters-form').submit(); + }); + $("#project_name").change(function(){ + $('#filters-form').submit(); + }); $(".reactivate_btn").click(function(){ var modal_id='#' + $(this).data()['modalId'];