Skip to content

Commit

Permalink
Merge pull request #74 from katmastt/main
Browse files Browse the repository at this point in the history
Fixed bugs #158, #153, #154, #155 (#2)
  • Loading branch information
eleni-adamidi authored Jan 19, 2024
2 parents cd4ad0f + fd8f3bf commit 83e5605
Show file tree
Hide file tree
Showing 11 changed files with 436 additions and 40 deletions.
19 changes: 11 additions & 8 deletions controllers/AdministrationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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))
{
Expand All @@ -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'];
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion controllers/ProjectController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'
];

Expand Down
92 changes: 92 additions & 0 deletions models/ColdStorageRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 8 additions & 2 deletions models/Project.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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();


Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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;
Expand Down
14 changes: 7 additions & 7 deletions models/Vm.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -1165,15 +1161,15 @@ public function deleteVM()

if (!$ipDeleted)
{
return [2,$this->$delete_errors[2],$message];
return [2,$this->delete_errors[2],$message];
}

$result=$this->deleteServer();
$serverDeleted=$result[0];
$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);
Expand All @@ -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();
Expand Down
49 changes: 40 additions & 9 deletions views/administration/all_projects.php
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,8 @@
{
$projectLink="https://schema.imsi.athenarc.gr?r=software/index&selected_project=". $res['name'];
$projectTarget='_blank';
$project_icon='<i class="fa fa-bolt" aria-hidden="true"></i>';
$title='On-demand batch computation';
$project_icon='<i class="fa fa-rocket" aria-hidden="true"></i>';
$title='On-demand batch computation project';
if (isset($active_resources[0][$res['name']]))
{
$active=true;
Expand All @@ -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='<i class="fa fa-book" aria-hidden="true"></i>';
$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='<i class="fa fa-server" aria-hidden="true"></i>';
$title='24/7 Service';
$project_icon='<i class="fa fa-leaf" aria-hidden="true"></i>';
$title='24/7 service project';
if (isset($active_resources[1][$res['project_id']]))
{
$active=true;
Expand All @@ -277,8 +296,8 @@
{
$projectLink=Url::to(['/project/machine-compute-configure-vm','id'=>$res['id']]);
$projectTarget='_self';
$project_icon='<i class="fa fa-server" aria-hidden="true"></i>';
$title='On-demand computation machines';
$project_icon='<i class="fa fa-bolt" aria-hidden="true"></i>';
$title='On-demand computation machines project';
if (isset($active_resources[2][$res['project_id']]))
{
$active=true;
Expand All @@ -294,7 +313,7 @@
$projectLink=Url::to(['/site/under-construction']);
$projectTarget='_self';
$project_icon='<i class="fa fa-database" aria-hidden="true"></i>';
$title='Cold Storage';
$title='Storage volume project';
$active=false;

}
Expand Down Expand Up @@ -364,6 +383,7 @@
<div class="filters-div">
<h4 class="text-center">Filter</h4>
<?=Html::beginForm(['administration/all-projects'],'post',['id'=>'filters-form'])?>

<div class="row">
<div class="col-md-12 text-center">
<?=Html::label('By project type:')?>
Expand All @@ -376,20 +396,30 @@
</div>

<div class="row">&nbsp;</div>

<div class="row">
<div class="col-md-12 text-center">
<?=Html::label('By owner:')?>
</div>
</div>
<div class="row">
<div class="col-md-12 text-center">
<?=Html::input(null,'username',$filters['user'],['class'=>'username_field'])?>
<?=Html::input(null,'username',$filters['user'],['class'=>'username_field','id'=>'username'])?>
</div>
</div>

<div class="row">&nbsp;</div>
<div class="row">
<div class="col-md-12 text-center">
<?=Html::label('By project name:')?>
</div>
</div>
<div class="row">
<div class="col-md-12 text-center">
<?=Html::input(null,'project_name',$filters['name'],['class'=>'projectname_field','id'=>'project_name'])?>
</div>
</div>

<div class="row">&nbsp;</div>
<div class="row">
<div class="col-md-12 text-center">
<?=Html::label('By expiration date:')?>
Expand All @@ -401,6 +431,7 @@
</div>
</div>


<div class="row">&nbsp;</div>


Expand Down
Loading

0 comments on commit 83e5605

Please sign in to comment.