Commit 16ff5fd9 by Jason Song Committed by GitHub

Merge pull request #353 from lepdou/rollback

回滚优化
parents 4d79b4f7 c18edfac
package com.ctrip.framework.apollo.portal.entity.vo;
import com.ctrip.framework.apollo.portal.enums.ChangeType;
public class Change {
private ChangeType type;
private EntityPair<KVEntity> entity;
public Change(ChangeType type, EntityPair<KVEntity> entity) {
this.type = type;
this.entity = entity;
}
public ChangeType getType() {
return type;
}
public void setType(ChangeType type) {
this.type = type;
}
public EntityPair<KVEntity> getEntity() {
return entity;
}
public void setEntity(
EntityPair<KVEntity> entity) {
this.entity = entity;
}
}
package com.ctrip.framework.apollo.portal.entity.vo; package com.ctrip.framework.apollo.portal.entity.vo;
import com.ctrip.framework.apollo.portal.enums.ChangeType;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
public class ReleaseCompareResult { public class ReleaseCompareResult {
private List<EntityPair<KVEntity>> changes = new LinkedList<>(); private List<Change> changes = new LinkedList<>();
public void addEntityPair(KVEntity firstEntity, KVEntity secondEntity){ public void addEntityPair(ChangeType type, KVEntity firstEntity, KVEntity secondEntity) {
changes.add(new EntityPair<>(firstEntity, secondEntity)); changes.add(new Change(type, new EntityPair<>(firstEntity, secondEntity)));
} }
public List<EntityPair<KVEntity>> getChanges() { public List<Change> getChanges() {
return changes; return changes;
} }
public void setChanges( public void setChanges(List<Change> changes) {
List<EntityPair<KVEntity>> changes) {
this.changes = changes; this.changes = changes;
} }
} }
package com.ctrip.framework.apollo.portal.enums;
public enum ChangeType {
ADDED, MODIFIED, DELETED
}
...@@ -12,6 +12,7 @@ import com.ctrip.framework.apollo.portal.entity.form.NamespaceReleaseModel; ...@@ -12,6 +12,7 @@ import com.ctrip.framework.apollo.portal.entity.form.NamespaceReleaseModel;
import com.ctrip.framework.apollo.portal.entity.vo.KVEntity; import com.ctrip.framework.apollo.portal.entity.vo.KVEntity;
import com.ctrip.framework.apollo.portal.entity.vo.ReleaseCompareResult; import com.ctrip.framework.apollo.portal.entity.vo.ReleaseCompareResult;
import com.ctrip.framework.apollo.portal.entity.vo.ReleaseVO; import com.ctrip.framework.apollo.portal.entity.vo.ReleaseVO;
import com.ctrip.framework.apollo.portal.enums.ChangeType;
import com.dianping.cat.Cat; import com.dianping.cat.Cat;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -98,9 +99,15 @@ public class ReleaseService { ...@@ -98,9 +99,15 @@ public class ReleaseService {
String key = entry.getKey(); String key = entry.getKey();
String firstValue = entry.getValue(); String firstValue = entry.getValue();
String secondValue = secondItems.get(key); String secondValue = secondItems.get(key);
if (!Objects.equal(firstValue, secondValue)) { //added
compareResult.addEntityPair(new KVEntity(key, firstValue), new KVEntity(key, secondValue)); if (secondValue == null) {
compareResult.addEntityPair(ChangeType.DELETED, new KVEntity(key, firstValue),
new KVEntity(key, secondValue));
} else if (!Objects.equal(firstValue, secondValue)) {
compareResult.addEntityPair(ChangeType.MODIFIED, new KVEntity(key, firstValue),
new KVEntity(key, secondValue));
} }
} }
//deleted in firstRelease //deleted in firstRelease
...@@ -108,7 +115,8 @@ public class ReleaseService { ...@@ -108,7 +115,8 @@ public class ReleaseService {
String key = entry.getKey(); String key = entry.getKey();
String value = entry.getValue(); String value = entry.getValue();
if (firstItems.get(key) == null) { if (firstItems.get(key) == null) {
compareResult.addEntityPair(new KVEntity(key, ""), new KVEntity(key, value)); compareResult
.addEntityPair(ChangeType.ADDED, new KVEntity(key, ""), new KVEntity(key, value));
} }
} }
......
...@@ -97,7 +97,7 @@ ...@@ -97,7 +97,7 @@
pre-release-ns="prepareReleaseNamespace" pre-release-ns="prepareReleaseNamespace"
create-item="createItem" edit-item="editItem" create-item="createItem" edit-item="editItem"
pre-delete-item="preDeleteItem" commit-change="commitChange" pre-delete-item="preDeleteItem" commit-change="commitChange"
show-rollback-tips="showRollbackTips"></apollonspanel> pre-rollback="preRollback"></apollonspanel>
</div> </div>
<!-- delete modal--> <!-- delete modal-->
...@@ -116,9 +116,9 @@ ...@@ -116,9 +116,9 @@
apollo-detail="'您不能发布哟~ 编辑和发布不能为同一个人'" apollo-detail="'您不能发布哟~ 编辑和发布不能为同一个人'"
apollo-show-cancel-btn="false"></apolloconfirmdialog> apollo-show-cancel-btn="false"></apolloconfirmdialog>
<apolloconfirmdialog apollo-dialog-id="'rollbackTips'" apollo-title="'回滚'" <apolloconfirmdialog apollo-dialog-id="'rollbackAlertDialog'" apollo-title="'回滚'"
apollo-detail="'此操作将会回滚到上一个发布版本,且作废当前版本。确定要回滚吗?'" apollo-detail="'确定要回滚吗?'"
apollo-show-cancel-btn="true" apollo-confirm="preRollback"></apolloconfirmdialog> apollo-show-cancel-btn="true" apollo-confirm="rollback"></apolloconfirmdialog>
<!--create createRelease modal--> <!--create createRelease modal-->
...@@ -325,29 +325,37 @@ ...@@ -325,29 +325,37 @@
<!--rollback--> <!--rollback-->
<form class="modal fade form-horizontal" id="rollbackModal" tabindex="-1" role="dialog" <form class="modal fade form-horizontal" id="rollbackModal" tabindex="-1" role="dialog"
ng-submit="rollback()"> ng-submit="showRollbackAlertDialog()">
<div class="modal-dialog" role="document" style="width: 960px"> <div class="modal-dialog" role="document" style="width: 960px">
<div class="modal-content"> <div class="modal-content">
<div class="modal-header panel-primary"> <div class="modal-header panel-primary">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
aria-hidden="true">&times;</span></button> aria-hidden="true">&times;</span></button>
<h4 class="modal-title">回滚</h4> <div class="modal-title text-center">
</div>
<div class="modal-body">
<div class="row text-center">
<span style="font-size: 18px;" ng-bind="firstRelease.name"></span> <span style="font-size: 18px;" ng-bind="firstRelease.name"></span>
<span style="font-size: 18px;"> &nbsp;回滚到&nbsp;</span> <span style="font-size: 18px;"> &nbsp;回滚到&nbsp;</span>
<span style="font-size: 18px;" ng-bind="secondRelease.name"></span> <span style="font-size: 18px;" ng-bind="secondRelease.name"></span>
</div> </div>
</div>
<div class="modal-body">
<div class="alert alert-warning" role="alert">
此操作将会回滚到上一个发布版本,且当前版本作废,但不影响正在修改的配置。可在发布历史页面查看当前生效的版本
<a target="_blank"
href="/config/history.html?#/appid={{toRollbackNamespace.baseInfo.appId}}&env={{pageContext.env}}&clusterName={{toRollbackNamespace.baseInfo.clusterName}}&namespaceName={{toRollbackNamespace.baseInfo.namespaceName}}">点击查看</a>
</div>
<div class="form-group" style="margin-top: 15px;"> <div class="form-group" style="margin-top: 15px;">
<label class="col-sm-2 control-label"> <!--properties format-->
Changes:</label> <div class="col-sm-12"
<div class="col-sm-10" ng-if="releaseCompareResult.length > 0"> ng-if="releaseCompareResult.length > 0 && toRollbackNamespace.isPropertiesFormat">
<table class="table table-bordered table-striped text-center table-hover"> <table class="table table-bordered table-striped text-center table-hover"
ng-if="toRollbackNamespace.isPropertiesFormat">
<thead> <thead>
<tr> <tr>
<th> <th>
Type
</th>
<th>
Key Key
</th> </th>
<th> <th>
...@@ -360,22 +368,45 @@ ...@@ -360,22 +368,45 @@
</thead> </thead>
<tbody> <tbody>
<tr ng-repeat="pair in releaseCompareResult"> <tr ng-repeat="change in releaseCompareResult">
<td width="20%" ng-bind="pair.firstEntity.key"> <td width="10%">
<span ng-show="change.type == 'ADDED'">新增</span>
<span ng-show="change.type == 'MODIFIED'">更新</span>
<span ng-show="change.type == 'DELETED'">删除</span>
</td>
<td width="20%" ng-bind="change.entity.firstEntity.key">
</td> </td>
<td width="40%" ng-bind="pair.firstEntity.value"> <td width="35%" ng-bind="change.entity.firstEntity.value">
</td> </td>
<td width="40%" ng-bind="pair.secondEntity.value"> <td width="35%" ng-bind="change.entity.secondEntity.value">
</td> </td>
</tr> </tr>
</tbody> </tbody>
</table> </table>
</div> </div>
<div class="col-sm-5">
<span ng-if="releaseCompareResult.length == 0"> <!--file format -->
<div class="col-sm-12"
ng-if="releaseCompareResult.length > 0 && !toRollbackNamespace.isPropertiesFormat">
<div ng-repeat="change in releaseCompareResult"
ng-if="!toRollbackNamespace.isPropertiesFormat">
<h5>回滚前</h5>
<textarea class="form-control no-radius" rows="20"
ng-disabled="true" ng-bind="change.entity.firstEntity.value">
</textarea>
<hr>
<h5>回滚后</h5>
<textarea class="form-control no-radius" rows="20"
ng-disabled="true" ng-bind="change.entity.secondEntity.value">
</textarea>
</div>
</div>
<div class="col-sm-12 text-center" ng-if="releaseCompareResult.length == 0">
<h4>
配置没有变化 配置没有变化
</span> </h4>
</div> </div>
</div> </div>
...@@ -384,7 +415,7 @@ ...@@ -384,7 +415,7 @@
<div class="modal-footer"> <div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">取消</button> <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
<button type="submit" class="btn btn-danger" ng-if="releaseCompareResult.length > 0" <button type="submit" class="btn btn-danger" ng-if="releaseCompareResult.length > 0"
ng-disabled="rollbackBtnDisabled">确定回滚 ng-disabled="rollbackBtnDisabled">回滚
</button> </button>
</div> </div>
</div> </div>
......
...@@ -12,23 +12,15 @@ $(document).ready(function () { ...@@ -12,23 +12,15 @@ $(document).ready(function () {
zindex: '1000' zindex: '1000'
}); });
// bootstrap tooltip // bootstrap tooltip & textarea scroll
setInterval(function () { setInterval(function () {
$('[data-tooltip="tooltip"]').tooltip(); $('[data-tooltip="tooltip"]').tooltip();
$('html').bind('mousewheel DOMMouseScroll',
function (e) {
var e0 = e.originalEvent,
delta = e0.wheelDelta
|| -e0.detail;
this.scrollTop += $("textarea").niceScroll({styler: "fb", cursorcolor: "#fff"});
( delta < 0 ? 1 : -1 ) * 30;
e.preventDefault();
});
}, 2500); }, 2500);
}); });
// (new Date()).Format("yyyy-MM-dd hh:mm:ss.S") ==> 2006-07-02 08:09:04.423 // (new Date()).Format("yyyy-MM-dd hh:mm:ss.S") ==> 2006-07-02 08:09:04.423
// (new Date()).Format("yyyy-M-d h:m:s.S") ==> 2006-7-2 8:9:4.18 // (new Date()).Format("yyyy-M-d h:m:s.S") ==> 2006-7-2 8:9:4.18
Date.prototype.Format = function (fmt) { Date.prototype.Format = function (fmt) {
......
...@@ -26,7 +26,7 @@ application_module.controller("ConfigNamespaceController", ...@@ -26,7 +26,7 @@ application_module.controller("ConfigNamespaceController",
$scope.release = release; $scope.release = release;
$scope.showRollbackTips = showRollbackTips; $scope.showRollbackAlertDialog = showRollbackAlertDialog;
$scope.preRollback = preRollback; $scope.preRollback = preRollback;
...@@ -152,21 +152,20 @@ application_module.controller("ConfigNamespaceController", ...@@ -152,21 +152,20 @@ application_module.controller("ConfigNamespaceController",
); );
} }
var toRollbackNamespace = {}; function showRollbackAlertDialog() {
function showRollbackTips(namespace) { $("#rollbackModal").modal('hide');
toRollbackNamespace = namespace; $("#rollbackAlertDialog").modal('show');
$("#rollbackTips").modal('show');
} }
$scope.toRollbackNamespace = {};
function preRollback() { function preRollback(namespace) {
$scope.toRollbackNamespace = namespace;
//load latest two active releases //load latest two active releases
ReleaseService.findActiveRelease($rootScope.pageContext.appId, ReleaseService.findActiveRelease($rootScope.pageContext.appId,
$rootScope.pageContext.env, $rootScope.pageContext.env,
$rootScope.pageContext.clusterName, $rootScope.pageContext.clusterName,
toRollbackNamespace.baseInfo.namespaceName, 0, 2) $scope.toRollbackNamespace.baseInfo.namespaceName, 0, 2)
.then(function (result) { .then(function (result) {
if (result.length <= 1) { if (result.length <= 1) {
toastr.error("没有可以回滚的发布历史"); toastr.error("没有可以回滚的发布历史");
...@@ -180,6 +179,7 @@ application_module.controller("ConfigNamespaceController", ...@@ -180,6 +179,7 @@ application_module.controller("ConfigNamespaceController",
$scope.secondRelease.id) $scope.secondRelease.id)
.then(function (result) { .then(function (result) {
$scope.releaseCompareResult = result.changes; $scope.releaseCompareResult = result.changes;
$("#rollbackModal").modal('show'); $("#rollbackModal").modal('show');
}, function (result) { }, function (result) {
toastr.error(AppUtil.errorMsg(result), "对比失败"); toastr.error(AppUtil.errorMsg(result), "对比失败");
......
...@@ -12,7 +12,7 @@ directive_module.directive('apollonspanel', ...@@ -12,7 +12,7 @@ directive_module.directive('apollonspanel',
env: '=', env: '=',
cluster: '=', cluster: '=',
preReleaseNs: '=', preReleaseNs: '=',
showRollbackTips: '=', preRollback: '=',
createItem: '=', createItem: '=',
editItem: '=', editItem: '=',
preDeleteItem: '=', preDeleteItem: '=',
......
...@@ -33,7 +33,7 @@ ...@@ -33,7 +33,7 @@
<button type="button" <button type="button"
class="btn btn-default btn-sm J_tableview_btn" class="btn btn-default btn-sm J_tableview_btn"
ng-show="namespace.hasReleasePermission" ng-show="namespace.hasReleasePermission"
ng-click="showRollbackTips(namespace)"> ng-click="preRollback(namespace)">
<img src="img/rollback.png"> <img src="img/rollback.png">
回滚 回滚
</button> </button>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment