From d6c6bdb924e76ccf94c70bbf5b8458f6a11d7f87 Mon Sep 17 00:00:00 2001 From: zhaoke Date: Mon, 25 Sep 2023 13:54:32 +0800 Subject: [PATCH] * Fix cancel btn status when install fail. --- module/install/control.php | 30 ++++++++++++++++++++------- module/install/js/app.js | 26 +++++++++++++---------- module/install/js/progress.js | 18 +++++++--------- module/install/view/progress.html.php | 2 +- 4 files changed, 46 insertions(+), 30 deletions(-) diff --git a/module/install/control.php b/module/install/control.php index 72d03e9b90..89a9fc79e8 100644 --- a/module/install/control.php +++ b/module/install/control.php @@ -358,17 +358,12 @@ class install extends control $this->send(array('result' => 'success', 'message' => $this->lang->solution->notices->success, 'data' => $solution, 'locate' => $this->inLink('progress', "id={$solution->id}&install=true"))); } - $clusterResource = $this->loadModel('cne')->cneMetrics(); - $freeMemory = intval($clusterResource->metrics->memory->allocatable * 0.9); - $appMap = $this->loadModel('store')->getAppMapByNames(array_keys($cloudSolution->apps)); - $category = helper::arrayColumn($components->category, 'name'); - $category = array_filter($category, function($cate){return $cate !== 'pms';}); + $category = helper::arrayColumn($components->category, 'name'); + $category = array_filter($category, function($cate){return $cate !== 'pms';}); $this->view->title = $this->lang->solution->install; $this->view->cloudSolution = $cloudSolution; $this->view->components = $components; - $this->view->appMap = $appMap; - $this->view->freeMemory = $freeMemory; $this->view->category = $category; $this->display(); @@ -480,4 +475,25 @@ class install extends control $this->send(array('result' => 'success', 'message' => '', 'locate' => $this->inLink('index'))); } + + /** + * Check memory and cpu. + * 检查内存与CPU是否满足安装所需。 + * + * @param int $solutionID + * @access public + * @return void + */ + public function ajaxCheck() + { + $this->loadModel('common'); + $data = fixer::input('post')->get(); + $appMap = $this->loadModel('store')->getAppMapByNames($data->apps); + $resources = array(); + + foreach($data->apps as $app) $resources[] = array('cpu' => $appMap->$app->cpu, 'memory' => $appMap->$app->memory); + $result = $this->loadModel('cne')->tryAllocate($resources); + + $this->send(array('result' => 'success', 'message' => '', 'code' => $result->code)); + } } diff --git a/module/install/js/app.js b/module/install/js/app.js index d746f7b2ac..412830bff9 100644 --- a/module/install/js/app.js +++ b/module/install/js/app.js @@ -46,22 +46,26 @@ $(function() */ function checkMemory() { - var memory = 0; + var apps = []; $.each(category, (index, cate) => { var item = $('#' + cate).val(); - memory += appMap[item].memory; + apps.push(item); }); - if(freeMemory < memory) + $.post(createLink('install', 'ajaxCheck'), {apps: apps}).done(function(response) { - $('#skipBtn').show(); - $('#overMemoryNotice').show(); - $('#submitBtn').attr('disabled', true); - return; - } + var res = JSON.parse(response); + if(res.code == undefined || res.code == 41010) + { + $('#skipBtn').show(); + $('#overMemoryNotice').show(); + $('#submitBtn').attr('disabled', true); + return; + } - $('#skipBtn').hide(); - $('#overMemoryNotice').hide(); - $('#submitBtn').attr('disabled', false); + $('#skipBtn').hide(); + $('#overMemoryNotice').hide(); + $('#submitBtn').attr('disabled', false); + }); } \ No newline at end of file diff --git a/module/install/js/progress.js b/module/install/js/progress.js index 4a86c0ceb1..ffb7b5f749 100644 --- a/module/install/js/progress.js +++ b/module/install/js/progress.js @@ -68,6 +68,7 @@ $(function() { $('#retryInstallBtn').show(); $('#skipInstallBtn').show(); + $('#cancelInstallBtn').hide(); $('.progress.loading').hide(); var errMessage = res.message; @@ -116,6 +117,8 @@ $(function() if(!result) return; $('#retryInstallBtn').hide(); + $('#skipInstallBtn').hide(); + $('#cancelInstallBtn').show(); $('.error-message').text(''); $('.progress.loading').show(); @@ -138,18 +141,11 @@ $(function() }); }); - if(hasError && !startInstall) - { - $('#retryInstallBtn').show(); - $('#skipInstallBtn').show(); - } - else - { - $('#retryInstallBtn').hide(); - $('#skipInstallBtn').hide(); - } + $('#retryInstallBtn').hide(); + $('#skipInstallBtn').hide(); + $('#cancelInstallBtn').show(); - if(startInstall) + if('true' === startInstall) { $.get(createLink('install', 'ajaxInstall', 'id=' + solutionID)).done(function(response){}); } diff --git a/module/install/view/progress.html.php b/module/install/view/progress.html.php index ebef4affa9..821a3ea8c9 100644 --- a/module/install/view/progress.html.php +++ b/module/install/view/progress.html.php @@ -48,7 +48,7 @@
- install->solution->skip, 'id="skipInstallBtn"', "class='btn btn-install btn-wide' style='display: none;'");?> + install->solution->skip, '', "class='btn btn-install btn-wide' style='display: none;' id='skipInstallBtn'");?> solution->retryInstall, "id='retryInstallBtn' class='hide'", 'btn btn-primary btn-wide');?> solution->cancelInstall, "id='cancelInstallBtn'", 'btn btn-primary btn-wide');?>