diff --git a/api/v1/entries/hostsubmit.php b/api/v1/entries/hostsubmit.php index 83a2a628de..268df5fe90 100644 --- a/api/v1/entries/hostsubmit.php +++ b/api/v1/entries/hostsubmit.php @@ -23,7 +23,7 @@ class hostSubmitEntry extends baseEntry /* Check authorize. */ $header = getallheaders(); $token = isset($header['Authorization']) ? substr($header['Authorization'], 7) : ''; - // if(!$token) return $this->sendError(401, 'Unauthorized'); + if(!$token) return $this->sendError(401, 'Unauthorized'); $now = helper::now(); @@ -38,7 +38,16 @@ class hostSubmitEntry extends baseEntry ->andWhere('tokenTime')->gt($now)->fi() ->fetch('id'); - // if(!$id) return $this->sendError(400, 'Secret error.'); + if(!$id) return $this->sendError(400, 'Secret error.'); + + $imageInfo = $this->dao->select('`status`,`from`')->from(TABLE_IMAGE) + ->where('id')->eq($task) + ->fetch(); + if(empty($imageInfo)) return $this->sendSuccess(200, 'success'); + if($imageInfo->from == 'snapshot' && $imageInfo->status == 'restoring') + { + $image->status = $image->status == 'completed' ? 'restore_completed' : 'restore_failed'; + } $this->dao->update(TABLE_IMAGE)->data($image)->where("id")->eq($task)->exec(); diff --git a/db/update18.0.sql b/db/update18.0.sql index bfb3415f53..188d9253be 100644 --- a/db/update18.0.sql +++ b/db/update18.0.sql @@ -1 +1,2 @@ ALTER TABLE `zt_image` ADD `localName` VARCHAR(64) NOT NULL AFTER `name`; +ALTER TABLE `zt_image` ADD `restoreDate` datetime NOT NULL AFTER `createdDate`; diff --git a/module/action/lang/en.php b/module/action/lang/en.php index dc490dccff..7ead472084 100755 --- a/module/action/lang/en.php +++ b/module/action/lang/en.php @@ -238,6 +238,7 @@ $lang->action->desc->switchtolight = '$date, Switch from ALM mode to ligh $lang->action->desc->getvnc = '$date, Remote control $extra by $actor .' . "\n"; $lang->action->desc->unlinkproduct = '$date, the project is disassociated from the $extra, synchronization disassociates the ' . $lang->executionCommon . 's of the project from the $extra.' . "\n"; $lang->action->desc->createdsnapshot = '$date, $actor creates a snapshot $extra。' . "\n"; +$lang->action->desc->restoredsnapshot = '$date, $actor restored a snapshot $extra。' . "\n"; $lang->action->desc->editsnapshot = '$date, $actor edited the snapshot $extra。' . "\n"; /* Used to describe the history of operations related to parent-child tasks. */ @@ -422,6 +423,7 @@ $lang->action->label->linkedrepo = 'Linked Code Repo'; $lang->action->label->unlinkedrepo = 'Unlinked Code Repo'; $lang->action->label->unlinkproduct = 'Unlinked Product'; $lang->action->label->createdsnapshot = 'create snapshot'; +$lang->action->label->restoredsnapshot = 'create snapshot'; $lang->action->label->editsnapshot = 'edit snapshot'; /* Dynamic information is grouped by object. */ diff --git a/module/action/lang/zh-cn.php b/module/action/lang/zh-cn.php index f4ee36d719..868c060b34 100755 --- a/module/action/lang/zh-cn.php +++ b/module/action/lang/zh-cn.php @@ -238,6 +238,7 @@ $lang->action->desc->switchtolight = '$date, 由于 '. $lang->adm $lang->action->desc->getvnc = '$date, $actor对执行节点 $extra 进行了远程操控。' . "\n"; $lang->action->desc->unlinkproduct = '$date, 系统判断由于' . $lang->executionCommon . '所属项目与$extra取消关联,同步将' . $lang->executionCommon . '与$extra取消关联。' . "\n"; $lang->action->desc->createdsnapshot = '$date, $actor 创建了快照 $extra。' . "\n"; +$lang->action->desc->restoredsnapshot = '$date, $actor 还原了快照 $extra。' . "\n"; $lang->action->desc->editsnapshot = '$date, $actor 编辑了快照 $extra。' . "\n"; /* 用来描述和父子任务相关的操作历史记录。*/ @@ -422,6 +423,7 @@ $lang->action->label->linkedrepo = '关联代码库到'; $lang->action->label->unlinkedrepo = '取消了项目与代码库的关联'; $lang->action->label->unlinkproduct = '取消了与产品的关联'; $lang->action->label->createdsnapshot = '创建了快照'; +$lang->action->label->restoredsnapshot = '还原了快照'; $lang->action->label->editsnapshot = '编辑了快照'; /* 动态信息按照对象分组 */ diff --git a/module/zanode/control.php b/module/zanode/control.php index 75a404d7d6..76cd0eb876 100644 --- a/module/zanode/control.php +++ b/module/zanode/control.php @@ -423,6 +423,32 @@ class zanode extends control $this->display(); } + /** + * Restore node. + * + * @param int $nodeID + * @return void + */ + public function restoreSnapshot($nodeID, $snapshotID, $confirm = 'no') + { + if($confirm == 'no') + { + return print(js::confirm($this->lang->zanode->confirmRestore, inlink('restoreSnapshot', "nodeID={$nodeID}&snapshotID={$snapshotID}&confirm=yes"))); + } + + $this->zanode->restoreSnapshot($nodeID, $snapshotID); + + if(dao::isError()) + { + return print(js::alert(dao::getError()) . js::reload('parent')); + } + else + { + if(isonlybody()) return print(js::alert($this->lang->zanode->actionSuccess) . js::reload('parent')); + return print(js::alert($this->lang->zanode->actionSuccess) . js::locate($this->createLink('zanode', 'browse'), 'parent')); + } + } + /** * Ajax get template pairs by api. * diff --git a/module/zanode/lang/en.php b/module/zanode/lang/en.php index 483ec50fae..78417a405f 100644 --- a/module/zanode/lang/en.php +++ b/module/zanode/lang/en.php @@ -42,12 +42,13 @@ $lang->zanode->vnc = 'VNC Port'; $lang->zanode->destroyAt = 'Destroy Time'; $lang->zanode->creater = 'Creator'; $lang->zanode->createdDate = 'Create Date'; -$lang->zanode->confirmDelete = "Are you sure about destroying the ZenAgent Node?"; -$lang->zanode->confirmBoot = "Are you sure to start the ZenAgent Node?"; -$lang->zanode->confirmReboot = "Are you sure to restart the ZenAgent Node?"; -$lang->zanode->confirmShutdown = "Are you sure to shutdown the ZenAgent Node?"; -$lang->zanode->confirmSuspend = "Are you sure to suspend the ZenAgent Node?"; -$lang->zanode->confirmResume = "Are you sure to resume the ZenAgent Node?"; +$lang->zanode->confirmDelete = "Are you sure about destroying the ZenAgent Node?"; +$lang->zanode->confirmBoot = "Are you sure to start the ZenAgent Node?"; +$lang->zanode->confirmReboot = "Are you sure to restart the ZenAgent Node?"; +$lang->zanode->confirmShutdown = "Are you sure to shutdown the ZenAgent Node?"; +$lang->zanode->confirmSuspend = "Are you sure to suspend the ZenAgent Node?"; +$lang->zanode->confirmResume = "Are you sure to resume the ZenAgent Node?"; +$lang->zanode->confirmRestore = "Are you sure to restore the ZenAgent Node?"; $lang->zanode->actionSuccess = 'Success'; $lang->zanode->deleted = "Deleted"; $lang->zanode->scriptPath = "Script path"; @@ -87,7 +88,15 @@ $lang->zanode->restoreSnapshot = 'Revert Snapshot'; $lang->zanode->deleteSnapshot = 'Delete Snapshot'; $lang->zanode->snapshotEmpty = 'No snapshots'; -$lang->zanode->imageNameEmpty = 'Name can not be empty.'; +$lang->zanode->snapshot->statusList['creating'] = 'Creating'; +$lang->zanode->snapshot->statusList['completed'] = 'Create Completed'; +$lang->zanode->snapshot->statusList['restoring'] = 'Restoring'; +$lang->zanode->snapshot->statusList['restore_failed'] = 'Restore Failed'; +$lang->zanode->snapshot->statusList['restore_completed'] = 'Restore Completed'; + +$lang->zanode->imageNameEmpty = 'Name can not be empty.'; +$lang->zanode->snapStatusError = 'Snapshot is not ready.'; +$lang->zanode->snapRestoring = 'Snapshot is restoring.'; $lang->zanode->runTimeout = 'Network connection timeout, please check the host and execution node status.'; diff --git a/module/zanode/lang/zh-cn.php b/module/zanode/lang/zh-cn.php index 1df91949a4..f499d510d7 100644 --- a/module/zanode/lang/zh-cn.php +++ b/module/zanode/lang/zh-cn.php @@ -48,6 +48,7 @@ $lang->zanode->confirmReboot = "您确定重启执行节点吗?"; $lang->zanode->confirmShutdown = "您确定关闭执行节点吗?"; $lang->zanode->confirmSuspend = "您确定休眠执行节点吗?"; $lang->zanode->confirmResume = "您确定恢复执行节点吗?"; +$lang->zanode->confirmRestore = "您确定还原执行节点吗?"; $lang->zanode->actionSuccess = '操作成功'; $lang->zanode->deleted = "已删除"; $lang->zanode->scriptPath = "脚本目录"; @@ -87,10 +88,16 @@ $lang->zanode->restoreSnapshot = '还原快照'; $lang->zanode->deleteSnapshot = '删除快照'; $lang->zanode->snapshotEmpty = '无快照'; -$lang->zanode->snapshot->statusList['creating'] = '创建中'; -$lang->zanode->snapshot->statusList['completed'] = '已完成'; +$lang->zanode->snapshot->statusList['creating'] = '创建中'; +$lang->zanode->snapshot->statusList['completed'] = '创建完成'; +$lang->zanode->snapshot->statusList['restoring'] = '还原中'; +$lang->zanode->snapshot->statusList['restore_failed'] = '还原失败'; +$lang->zanode->snapshot->statusList['restore_completed'] = '还原成功'; $lang->zanode->imageNameEmpty = '名称不能为空'; +$lang->zanode->imageNameEmpty = '名称不能为空'; +$lang->zanode->snapStatusError = '快照不可用'; +$lang->zanode->snapRestoring = '快照正在还原中'; $lang->zanode->runTimeout = '自动执行失败,请检查宿主机和执行节点状态'; diff --git a/module/zanode/model.php b/module/zanode/model.php index 41fc14106e..ecc4bb0440 100644 --- a/module/zanode/model.php +++ b/module/zanode/model.php @@ -254,6 +254,52 @@ class zanodemodel extends model return true; } + /** + * Restore Snapshot to zanode. + * + * @param int $zanodeID + * @access public + * @return void + */ + public function restoreSnapshot($zanodeID = 0, $snapshotID = 0) + { + $node = $this->getNodeByID($zanodeID); + $snap = $this->getImageByID($snapshotID); + + $snap->status = ($snap->status == 'restoring' && time() - strtotime($snap->restoreDate) > 600) ? 'restore_failed' : $snap->status; + if(!in_array($snap->status, array('completed', 'restoring', 'restore_failed', 'restore_completed'))) dao::$errors = $this->lang->zanode->snapStatusError; + if($snap->status == 'restoring') dao::$errors = $this->lang->zanode->snapRestoring; + if(dao::isError()) return false; + + //update snapshot status + $this->dao->update(TABLE_IMAGE) + ->set('status')->eq('restoring') + ->set('restoreDate')->eq(helper::now()) + ->where('id')->eq($snapshotID)->exec(); + + /* Prepare create params. */ + $agnetUrl = 'http://' . $node->ip . ':' . $node->hzap; + $param = array(array( + 'name' => $snap->name, + 'task' => $snapshotID, + 'type' => 'revertSnap', + 'vm' => $node->name + )); + + $result = json_decode(commonModel::http($agnetUrl . static::SNAPSHOT_CREATE_PATH, json_encode($param,JSON_NUMERIC_CHECK), null, array("Authorization:$node->tokenSN"))); + + if(!empty($result) and $result->code == 'success') + { + $this->loadModel('action')->create('zanode', $zanodeID, 'restoredsnapshot', '', $snap->name); + return true; + } + + $this->dao->update(TABLE_IMAGE)->set('status')->eq('completed')->where('id')->eq($snapshotID)->exec(); + dao::$errors[] = (!empty($result) and !empty($result->msg)) ? $result->msg : $this->lang->zanode->apiError['fail']; + return false; + } + + /** * Action Node. * diff --git a/module/zanode/view/browsesnapshot.html.php b/module/zanode/view/browsesnapshot.html.php index 93663ef974..3686889565 100644 --- a/module/zanode/view/browsesnapshot.html.php +++ b/module/zanode/view/browsesnapshot.html.php @@ -34,15 +34,19 @@ - status == 'completed' ? zget($snapshot, 'path', '') : '';?> + status = ($snapshot->status == 'restoring' && time() - strtotime($snapshot->restoreDate) > 600) ? 'restore_failed' : $snapshot->status; + $restoreAttr = "title='{$lang->zanode->restoreSnapshot}' target='hiddenwin'"; + $restoreAttr .= $snapshot->status == 'restoring' ? ' class="btn disabled"' : 'class="btn"'; + ?> localName ? $snapshot->localName : $snapshot->name;?> '>zanode->snapshot->statusList, $snapshot->status, '');?> createdBy, '')?> createdDate;?> - ', 'hiddenwin', "title={$lang->zanode->editSnapshot} onclick='window.parent.editSnapshot(\"" . $this->createLink('zanode', 'editSnapshot', "snapshotID={$snapshot->id}") . "\")'");?> - createLink('zahost', 'restoreSnapshot', "nodeID={$nodeID}&snapshotID={$snapshot->id}"), '', 'hiddenwin', "title={$lang->zanode->restoreSnapshot}");?> - createLink('zahost', 'deleteSnapshot', "snapshotID={$snapshot->id}"), '', 'hiddenwin', "title={$lang->zanode->deleteSnapshot}");?> + ', 'hiddenwin', "title={$lang->zanode->editSnapshot} onclick='window.parent.editSnapshot(\"" . $this->createLink('zanode', 'editSnapshot', "snapshotID={$snapshot->id}") . "\")' class='btn'");?> + createLink('zanode', 'restoreSnapshot', "nodeID={$nodeID}&snapshotID={$snapshot->id}"), '', 'hiddenwin', $restoreAttr);?> + createLink('zanode', 'deleteSnapshot', "snapshotID={$snapshot->id}"), '', 'hiddenwin', "title={$lang->zanode->deleteSnapshot} class='btn'");?> diff --git a/module/zanode/view/view.html.php b/module/zanode/view/view.html.php index 4a128e888e..27e1210261 100644 --- a/module/zanode/view/view.html.php +++ b/module/zanode/view/view.html.php @@ -147,13 +147,17 @@ $account = strpos($zanode->osName, "windows") ? $config->zanode->defaultWinAccou
zanode->desc; ?>
desc) ? htmlspecialchars_decode($zanode->desc) : $lang->noData; ?>
+
+ +
+
+
zanode->browseSnapshot;?>
-
-
zanode->browseSnapshot;?>
-
- createLink('zanode', 'browseSnapshot', "nodeID=$zanode->id", '', true) . "' frameborder='no' allowfullscreen='true' mozallowfullscreen='true' webkitallowfullscreen='true' allowtransparency='true' scrolling='auto' onload='setIframeHeight(this)' style='min-height:300px;'>";?> -
+
+ createLink('zanode', 'browseSnapshot', "nodeID=$zanode->id", '', true) . "' frameborder='no' allowfullscreen='true' mozallowfullscreen='true' webkitallowfullscreen='true' allowtransparency='true' scrolling='auto' onload='setIframeHeight(this)' style='min-height:300px;'>";?>
+ +
noData; ?>