* Fix task#103387

This commit is contained in:
zenggang
2023-09-25 05:38:59 +00:00
parent 3e1361ecd1
commit d3215ef0a6
8 changed files with 30 additions and 17 deletions
+1 -1
View File
@@ -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);
+12 -16
View File
@@ -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)
{
+1
View File
@@ -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.';
+1
View File
@@ -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.';
+1
View File
@@ -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.';
+1
View File
@@ -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 。';
+12
View File
@@ -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();
@@ -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)
{