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 @@
Volume name | +Created at | +Attached to | +On | ++ |
---|---|---|---|---|
=$res['name']?> (=$res['username']?>) |
+ =$cdate?> | +=empty($res['vname'])?'-': $res['vname']?> | +=empty($res['mountpoint'])?'-': $res['mountpoint']?> | ++ + + =Html::a("$delete_icon Delete",null,['class'=>"btn btn-danger btn-md delete-volume-btn", + 'id'=>"delete-$vol_id"])?> + + =Html::a("$create_icon Create",['project/create-volume','id'=>$res['id'],'ret'=>'a'],['class'=>"btn btn-success btn-md"])?> + + =Html::a("$manage_icon Manage attachment",['/project/manage-volumes','id'=>$pid, 'vid'=>$vol_id, 'ret'=>'a'],['class'=>"btn btn-secondary btn-md $manage_button_class"])?> + | +
Volume name | +Created at | +Attached to | +On | ++ |
---|---|---|---|---|
=$pname?> =$proj[$i]['username']?> |
+ =$cdate?> | +=(empty($proj[$i]['vmachname'])) ? '-': $proj[$i]['vmachname']?> | +=(empty($proj[$i]['mountpoint'])) ? '-': $proj[$i]['mountpoint']?> | ++ + + =Html::a("$delete_icon Delete",null,['class'=>"btn btn-danger btn-md delete-volume-btn", + 'id'=>"delete-$vol_id"])?> + + =Html::a("$create_icon Create",['project/create-volume','id'=>$pid,'order'=>$i,'ret'=>'a'],['class'=>"btn btn-success btn-md"])?> + + =Html::a("$manage_icon Manage attachment",['/project/manage-volumes','id'=>$pid,'vid'=>$vol_id,'ret'=>'a'], ['class'=>"btn btn-secondary btn-md $manage_button_class"])?> + | +