Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jupyters project: impose condition to check if the deployment wasnt created correctly #78

Merged
merged 1 commit into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions config/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,24 @@
],
],
'log' => [
'traceLevel' => YII_DEBUG ? 3 : 0,
'traceLevel' => YII_DEBUG ? 3 : 0,
'flushInterval' => 1,
'targets' => [
[
'class' => 'yii\log\FileTarget',
'levels' => ['error', 'warning'],
],
],
[
'class' => 'yii\log\FileTarget',
'categories' => ['application'],
'levels' => ['error', 'warning', 'info','trace'],
'exportInterval' => 1, // Export (write) the message to file after every log message
'logFile' => '@runtime/logs/debug.log',
'logVars' => [],
'maxFileSize' => 1024 * 2, // Maximum file size in kilobytes (2MB here)
'maxLogFiles' => 10, // Max number of log files before rotation
'except' => ['yii\db*']
]
],
],
'db' => $db,
Expand Down
4 changes: 2 additions & 2 deletions controllers/ProjectController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3491,9 +3491,9 @@ public function actionUserStatistics()

public function actionJupyterIndex($pid, $id)
{

Yii::debug("Inside controllers.ProjectController.actionJupyterIndex()");
$name = Project::find('name')->where(['id'=>$pid])->one();
$owner = Project::getProjectOwner($name['name']);
$owner = Project::getProjectOwner($name['name']);
$current_user = Userw::getCurrentUser()['id'];
//check if there is a server running, created by the current user
$server=JupyterServer::find()->where(['active'=>true,'project'=>$name['name'], 'created_by'=>Userw::getCurrentUser()['username']])->one();
Expand Down
105 changes: 88 additions & 17 deletions models/JupyterServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,17 +121,25 @@ public static function matchServersWithProjects($projects)

public function startServer()
{
Yii::debug('Inside models.JupyterServer.startServer()');

Yii::debug('Looking for existing active server');
$server=JupyterServer::find()->where(['active'=>true,'project'=>$this->project, 'created_by'=> User::getCurrentUser()['username']])->one();
if (!empty($server))
{
{
Yii::debug('An active server exists');
$success = '';
$error = 'You already have an active server';
$error = 'You already have an active server';
Yii::debug('Exiting models.JupyterServer.startServer()');
return [$success, $error];
}
}
Yii::debug("No active server was found");
$ssid=uniqid();
$sid = 'a'.$ssid;
$username=User::getCurrentUser()['username'];
$user=explode('@',$username)[0];
$user=explode('@',$username)[0];

Yii::debug("User: ".$user);

$image=JupyterImages::find()->where(['id'=>$this->image_id])->one();
if (empty($image))
Expand Down Expand Up @@ -244,7 +252,8 @@ public function startServer()
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
Yii::debug('Creating deployment');
$out2 = curl_exec($ch);

if(curl_errno($ch)){
Expand All @@ -263,13 +272,26 @@ public function startServer()
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
$count=0;
$count=0;
Yii::debug('Asserting deployment status');
$out10 = curl_exec($ch);
curl_close($ch);
$deploym = json_decode($out10, true);
$condition2=$deploym['status']['conditions'][0]['status'];
$condition1=$deploym['status']['conditions'][1]['status'];
while ($condition1=='True' && $condition2=='False') {
// $cond1=$deploym['status']['conditions'][0]['status'];
// $cond2=$deploym['status']['conditions'][1]['status'];
$available='False';
$progressing='True';
if ($deploym['status']['conditions'][0]['type']=='Available'){
$available=$deploym['status']['conditions'][0]['status'];
} elseif ($deploym['status']['conditions'][0]['type']=='Progressing'){
$progressing=$available=$deploym['status']['conditions'][0]['status'];
}
if ($deploym['status']['conditions'][1]['type']=='Available'){
$available=$deploym['status']['conditions'][1]['status'];
} elseif ($deploym['status']['conditions'][1]['type']=='Progressing'){
$progressing=$available=$deploym['status']['conditions'][1]['status'];
}
while ($progressing=='True' && $available=='False') {
//while ($count<60 && $condition=='False') {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, Yii::$app->params['jupyter_deployments_url'] .'/'.$sid);
Expand All @@ -278,23 +300,64 @@ public function startServer()
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
Yii::debug('Asserting deployment status');
$out10 = curl_exec($ch);
$deploym = json_decode($out10, true);
$condition2=$deploym['status']['conditions'][0]['status'];
$condition1=$deploym['status']['conditions'][1]['status'];
if ($deploym['status']['conditions'][0]['type']=='Available'){
$available=$deploym['status']['conditions'][0]['status'];
} elseif ($deploym['status']['conditions'][0]['type']=='Progressing'){
$progressing=$available=$deploym['status']['conditions'][0]['status'];
}
if ($deploym['status']['conditions'][1]['type']=='Available'){
$available=$deploym['status']['conditions'][1]['status'];
} elseif ($deploym['status']['conditions'][1]['type']=='Progressing'){
$progressing=$available=$deploym['status']['conditions'][1]['status'];
}
curl_close($ch);
$count = $count+1;
sleep(5);
}


if ($deploym['status']['conditions'][0]['status']=='False'){
if ($progressing=='False' && $available=='False'){

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, Yii::$app->params['jupyter_ingresses_url'] . '/' .$sid);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE');
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
$out1 = curl_exec($ch);
$out4 = ' ';
if(curl_errno($ch)){
$out4=curl_error($ch);
$error_c=1;
}
curl_close($ch);

curl_close($ch);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, Yii::$app->params['jupyter_deployments_url'] . '/' . $sid);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE');
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
$out3 = curl_exec($ch);
$out6 = ' ';
if(curl_errno($ch)){
$out6=curl_error($ch);
$error_c=1;
}
curl_close($ch);

$error = 'Your request could not be fulfilled at the current time due to insufficient resources at the cluster: '. $deploym['status']['conditions'][0]['message'];
return ['',$error,''];

} else{
} elseif($progressing=='True' && $available=='True'){
$service = [];
$service = array (
'metadata' => array (
Expand Down Expand Up @@ -325,7 +388,8 @@ public function startServer()
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
Yii::debug('Creating service');
$out5 = curl_exec($ch);

if(curl_errno($ch)){
Expand Down Expand Up @@ -384,7 +448,8 @@ public function startServer()
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
Yii::debug('Creating ingress');
$out6 = curl_exec($ch);

if(curl_errno($ch)){
Expand Down Expand Up @@ -441,14 +506,20 @@ public function startServer()

public function stopServer()
{
$username=User::getCurrentUser()['username'];
Yii::debug("Entering models.JupyterServer.stopServer()");

$username=User::getCurrentUser()['username'];
Yii::debug("Current user: ".$username);
$error_c = 0;

$headers = [
Yii::$app->params['jupyter_bearer_token'],
'Content-Type: application/json'
];

Yii::debug("Deleting corresponding Kubernetes resources");

Yii::debug("Deleting ingress...");
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, Yii::$app->params['jupyter_ingresses_url'] . '/' . $this->server_id);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
Expand Down
Loading