From d3215ef0a6efc4aec65eeb07949bf2a8db10e2fa Mon Sep 17 00:00:00 2001 From: zenggang Date: Mon, 25 Sep 2023 05:38:59 +0000 Subject: [PATCH] * Fix task#103387 --- module/cne/model.php | 2 +- module/instance/control.php | 28 ++++++++++------------ module/instance/lang/de.php | 1 + module/instance/lang/en.php | 1 + module/instance/lang/fr.php | 1 + module/instance/lang/zh-cn.php | 1 + module/space/js/createapplication.ui.js | 12 ++++++++++ module/space/ui/createapplication.html.php | 1 + 8 files changed, 30 insertions(+), 17 deletions(-) diff --git a/module/cne/model.php b/module/cne/model.php index bcdbfc9657..d5ac00d3c7 100644 --- a/module/cne/model.php +++ b/module/cne/model.php @@ -1334,7 +1334,7 @@ class cneModel extends model public function tryAllocate(array $resources): object { $apiParams = new stdclass(); - $apiParams->resources = $resources; + $apiParams->requests = $resources; $apiUrl = "/api/cne/system/resource/try-allocate"; return $this->apiPost($apiUrl, $apiParams, $this->config->CNE->api->headers); diff --git a/module/instance/control.php b/module/instance/control.php index 723e85550a..b6977b7a61 100644 --- a/module/instance/control.php +++ b/module/instance/control.php @@ -530,30 +530,16 @@ class instance extends control * Install app. * * @param int $appID + * @param string $checkResource * @access public * @return void */ - public function install($appID) + public function install(int $appID, string $checkResource = 'true') { if(!commonModel::hasPriv('instance', 'manage')) $this->loadModel('common')->deny('instance', 'manage', false); $cloudApp = $this->store->getAppInfo($appID); if(empty($cloudApp)) return $this->send(array('result' => 'fail', 'message' => $this->lang->instance->errors->noAppInfo)); - if(empty($this->config->demoAccounts)) - { - $clusterResource = $this->cne->cneMetrics(); - $freeMemory = intval($clusterResource->metrics->memory->allocatable * 0.9); // Remain 10% memory for system. - if($cloudApp->memory > $freeMemory) - { - $cloudApp = $cloudApp; - $gapMemory = helper::formatKB(intval(($cloudApp->memory - $freeMemory))); - $requiredMemory = helper::formatKB(intval($cloudApp->memory)); - $freeMemory = helper::formatKB(intval($freeMemory)); - - return $this->send(array('result' => 'fail', 'message' => sprintf($this->lang->instance->errors->notEnoughMemory, $cloudApp->alias, $requiredMemory, $freeMemory, $gapMemory))); - } - } - $versionList = $this->store->appVersionList($cloudApp->id); $mysqlList = $this->cne->sharedDBList('mysql'); $pgList = $this->cne->sharedDBList('postgresql'); @@ -581,6 +567,16 @@ class instance extends control if(!validater::checkLength($customData->customDomain, 20, 2)) return $this->send(array('result' => 'fail', 'message' => $this->lang->instance->errors->domainLength)); if(!validater::checkREG($customData->customDomain, '/^[a-z\d]+$/')) return $this->send(array('result' => 'fail', 'message' => $this->lang->instance->errors->wrongDomainCharacter)); + if($checkResource == 'true') + { + $resource = new stdclass(); + $resource->cpu = $cloudApp->cpu; + $resource->memory = $cloudApp->memory; + + $result = $this->cne->tryAllocate(array($resource)); + if(!isset($result->code) || $result->code != 200) return $this->send(array('callback' => 'alertResource()')); + } + /* If select the version, replace the latest version of App by selected version. */ if($customData->version) { diff --git a/module/instance/lang/de.php b/module/instance/lang/de.php index 867a6a70f0..31495e683a 100644 --- a/module/instance/lang/de.php +++ b/module/instance/lang/de.php @@ -302,6 +302,7 @@ $lang->instance->notices['enableSMTPSuccess'] = 'Enable SMTP successfully'; $lang->instance->notices['disableSMTPSuccess'] = 'Disable SMTP successfully'; $lang->instance->notices['confirmCustom'] = 'After modifying the custom configuration, the service will automatically restart to make the configuration effective.'; $lang->instance->notices['required'] = 'cannot be empty'; +$lang->instance->notices['notEnoughResource'] = 'Insufficient platform resources. Do you want to continue installing?'; $lang->instance->nameChangeTo = '%s is modified to %s.'; $lang->instance->versionChangeTo = 'Upgrade %s to %s.'; diff --git a/module/instance/lang/en.php b/module/instance/lang/en.php index 867a6a70f0..31495e683a 100644 --- a/module/instance/lang/en.php +++ b/module/instance/lang/en.php @@ -302,6 +302,7 @@ $lang->instance->notices['enableSMTPSuccess'] = 'Enable SMTP successfully'; $lang->instance->notices['disableSMTPSuccess'] = 'Disable SMTP successfully'; $lang->instance->notices['confirmCustom'] = 'After modifying the custom configuration, the service will automatically restart to make the configuration effective.'; $lang->instance->notices['required'] = 'cannot be empty'; +$lang->instance->notices['notEnoughResource'] = 'Insufficient platform resources. Do you want to continue installing?'; $lang->instance->nameChangeTo = '%s is modified to %s.'; $lang->instance->versionChangeTo = 'Upgrade %s to %s.'; diff --git a/module/instance/lang/fr.php b/module/instance/lang/fr.php index 867a6a70f0..31495e683a 100644 --- a/module/instance/lang/fr.php +++ b/module/instance/lang/fr.php @@ -302,6 +302,7 @@ $lang->instance->notices['enableSMTPSuccess'] = 'Enable SMTP successfully'; $lang->instance->notices['disableSMTPSuccess'] = 'Disable SMTP successfully'; $lang->instance->notices['confirmCustom'] = 'After modifying the custom configuration, the service will automatically restart to make the configuration effective.'; $lang->instance->notices['required'] = 'cannot be empty'; +$lang->instance->notices['notEnoughResource'] = 'Insufficient platform resources. Do you want to continue installing?'; $lang->instance->nameChangeTo = '%s is modified to %s.'; $lang->instance->versionChangeTo = 'Upgrade %s to %s.'; diff --git a/module/instance/lang/zh-cn.php b/module/instance/lang/zh-cn.php index c9b8c0f975..d7e3e81b02 100644 --- a/module/instance/lang/zh-cn.php +++ b/module/instance/lang/zh-cn.php @@ -302,6 +302,7 @@ $lang->instance->notices['enableSMTPSuccess'] = '启用SMTP成功'; $lang->instance->notices['disableSMTPSuccess'] = '禁用SMTP成功'; $lang->instance->notices['confirmCustom'] = '修改自定义配置后服务将自动重启以使配置生效。'; $lang->instance->notices['required'] = '不能为空'; +$lang->instance->notices['notEnoughResource'] = '平台资源不足,要继续安装吗?'; $lang->instance->nameChangeTo = ' %s 修改为 %s 。'; $lang->instance->versionChangeTo = ' %s 升级为 %s 。'; diff --git a/module/space/js/createapplication.ui.js b/module/space/js/createapplication.ui.js index ae3c9c2738..c3fc0f1dde 100644 --- a/module/space/js/createapplication.ui.js +++ b/module/space/js/createapplication.ui.js @@ -159,6 +159,18 @@ function onChangeDbType(event) } } +window.alertResource = function() +{ + zui.Modal.confirm({'message': resourceAlert}).then((res) => + { + if(res) + { + $('#createStoreAppForm').attr('action', $('#createStoreAppForm').attr('action') + '&checkResource=false'); + $('#createStoreAppForm .form-row .toolbar button[type=submit]').trigger('click'); + } + }); +} + $(function() { onChangeStoreAppType(); diff --git a/module/space/ui/createapplication.html.php b/module/space/ui/createapplication.html.php index f1274f095f..dda6f82eb5 100644 --- a/module/space/ui/createapplication.html.php +++ b/module/space/ui/createapplication.html.php @@ -29,6 +29,7 @@ jsVar('mysqlList', $mysqlList); jsVar('defaultApp', $defaultApp); jsVar('showVersion', $showVersion); jsVar('externalApps', $config->space->zentaoApps); +jsVar('resourceAlert', $lang->instance->notices['notEnoughResource']); if($config->inQuickon) {