Skip to content

Commit

Permalink
add switch active keeper button in full link health check
Browse files Browse the repository at this point in the history
  • Loading branch information
yifuzhou committed Oct 17, 2024
1 parent d0bb509 commit 47c1f61
Show file tree
Hide file tree
Showing 8 changed files with 129 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,13 @@
import com.ctrip.xpipe.redis.console.controller.AbstractConsoleController;
import com.ctrip.xpipe.redis.console.keeper.KeeperContainerUsedInfoAnalyzer;
import com.ctrip.xpipe.redis.console.model.ConfigModel;
import com.ctrip.xpipe.redis.console.model.KeeperRestElectionModel;
import com.ctrip.xpipe.redis.console.model.MigrationKeeperContainerDetailModel;
import com.ctrip.xpipe.redis.console.service.ConfigService;
import com.ctrip.xpipe.redis.console.service.KeeperContainerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand All @@ -33,6 +31,9 @@ public class KeeperContainerController extends AbstractConsoleController{
@Autowired
ConfigService configService;

@Autowired
KeeperContainerService keeperContainerService;

@RequestMapping(value = "/keepercontainer/overload/info/all", method = RequestMethod.GET)
public List<MigrationKeeperContainerDetailModel> getAllReadyToMigrateKeeperContainers() {
return analyzer.getCurrentDcReadyToMigrationKeeperContainers();
Expand Down Expand Up @@ -93,5 +94,14 @@ public RetMessage getIORate() {
}
}

@RequestMapping(value = "/keepers/election/reset", method = RequestMethod.POST)
public RetMessage resetElection(@RequestBody KeeperRestElectionModel model){
try {
keeperContainerService.resetKeeper(model.getIp(), Long.parseLong(model.getShardId()));
return RetMessage.createSuccessMessage();
} catch (Exception e) {
return RetMessage.createFailMessage(e.getMessage());
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.ctrip.xpipe.redis.console.model;


public class KeeperRestElectionModel {

private String ip;
private String port;
private String shardId;

public String getIp() {
return ip;
}

public void setIp(String ip) {
this.ip = ip;
}

public String getPort() {
return port;
}

public void setPort(String port) {
this.port = port;
}

public String getShardId() {
return shardId;
}

public void setShardId(String shardId) {
this.shardId = shardId;
}

@Override
public String toString() {
return "KeeperRestElectionModel{" +
"ip='" + ip + '\'' +
", port=" + port +
", shardId=" + shardId +
'}';
}
}
6 changes: 3 additions & 3 deletions redis/redis-console/src/main/resources/static/dist/bundle.js

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ angular
$mdThemingProvider.theme('orange').backgroundPalette('orange');
});

FullLinkHealthCheckCtl.$inject = ['$rootScope', '$scope', '$window', '$stateParams', 'HealthCheckService',
FullLinkHealthCheckCtl.$inject = ['$rootScope', '$scope', '$window', '$stateParams', 'HealthCheckService', 'KeeperContainerService',
'toastr', 'NgTableParams', 'AppUtil', '$interval'];

function FullLinkHealthCheckCtl($rootScope, $scope, $window, $stateParams, HealthCheckService,
function FullLinkHealthCheckCtl($rootScope, $scope, $window, $stateParams, HealthCheckService, KeeperContainerService,
toastr, NgTableParams, $interval) {
$scope.masterRoles = [];
$scope.slaveRoles = [];
Expand All @@ -25,6 +25,11 @@ function FullLinkHealthCheckCtl($rootScope, $scope, $window, $stateParams, Healt
$scope.doShowActions = doShowActions;
$scope.getShardAllMeta = getShardAllMeta;
$scope.getShardKeeperState = getShardKeeperState;
$scope.resetElection = resetElection;
$scope.disableResetElection = false;
$scope.getDisableResetElection = getDisableResetElection;
$scope.resetElectionErr = null;
$scope.getResetElectionErr = getResetElectionErr;

redisRoleHealthCheck();
shardCheckerGroupHealthCheck();
Expand Down Expand Up @@ -73,9 +78,40 @@ function FullLinkHealthCheckCtl($rootScope, $scope, $window, $stateParams, Healt
})
}

let timer = null;
function resetElection(ip, port) {
$scope.disableResetElection = true;
KeeperContainerService.resetElection(ip, port, $stateParams.shardId).then(function (response) {
if (response.state != 0) {
$scope.disableResetElection = false;
$scope.resetElectionErr = response.message;
$('#resetElectionErr').modal('show');
} else {
if (!timer) {
timer = setTimeout(() => {
clearTimeout(timer);
timer = null;
$scope.disableResetElection = false;
}, 5000);
}
}
}).catch(function (error){
$scope.disableResetElection = false;
$scope.resetElectionErr = "Status Code:" + error.status + " " + error.statusText + "\n" + error.data.exception;
$('#resetElectionErr').modal('show');
})
}

function getResetElectionErr() {
return $scope.resetElectionErr;
}

function doShowActions() {
$scope.showActions = !$scope.showActions;
}

function getDisableResetElection() {
return $scope.disableResetElection;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ function router($stateProvider, $urlRouterProvider) {
controller: 'KeepercontainerOverallCtl'
})
.state('full_link_health_check',{
url: '/full_link_health_check?currentDcName&clusterName&shardName',
url: '/full_link_health_check?currentDcName&clusterName&shardName&shardId',
templateUrl: 'views/index/full_link_health_check.html',
controller: 'FullLinkHealthCheckCtl'
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ angular
stop_to_migrate_overload_keepercontainer:{
method:'POST',
url:'/console/keepercontainer/overload/migration/stop'
},
reset_election:{
method:'POST',
url:'/api/keepers/election/reset/:ip/:port/:shardId'
}
});

Expand Down Expand Up @@ -285,6 +289,21 @@ angular
return d.promise;
}

function resetElection(ip, port, shardId) {
var d = $q.defer();
resource.reset_election({
ip:ip,
port:port,
shardId:shardId
},
function (result) {
d.resolve(result);
}, function (result) {
d.reject(result);
});
return d.promise;
}

return {
findAvailableKeepersByDc : findAvailableKeepersByDc,
findAvailableKeepersByDcAndCluster : findAvailableKeepersByDcAndCluster,
Expand All @@ -301,5 +320,6 @@ angular
getOverloadKeeperContainerMigrationProcess : getOverloadKeeperContainerMigrationProcess,
beginToMigrateOverloadKeeperContainers : beginToMigrateOverloadKeeperContainers,
migrateKeeperTaskTerminate : migrateKeeperTaskTerminate,
resetElection: resetElection
}
}]);
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ <h3 class="header smaller lighter blue">
<div class="row">
<div class="col-md-6">{{shard.shardTbl.shardName}}(cluster_{{shard.shardTbl.clusterId}}.shard_{{shard.shardTbl.id}})</div>
<div class="col-md-6 text-right">
<a class="btn btn-success btn-sm" ng-if="clusterType == 'one_way' || clusterType == 'hetero' " href="/#/full_link_health_check?currentDcName={{currentDcName}}&clusterName={{clusterName}}&shardName={{shard.shardTbl.shardName}}" target="_blank">健康检测</a>
<a class="btn btn-success btn-sm" ng-if="clusterType == 'one_way' || clusterType == 'hetero' " href="/#/full_link_health_check?currentDcName={{currentDcName}}&clusterName={{clusterName}}&shardName={{shard.shardTbl.shardName}}&shardId={{shard.shardTbl.id}}" target="_blank">健康检测</a>
<a class="btn btn-primary btn-sm" ng-if="routeAvail === true && (clusterType == 'bi_direction'|| clusterType == 'one_way')" href="/#/chain/{{clusterName}}/{{currentDcName}}">Proxy-Chain</a>
<a class="btn btn-primary btn-sm" href="/#/cluster_dc_shard_update?clusterName={{clusterName}}&shardName={{shard.shardTbl.shardName}}&currentDcName={{currentDcName}}">编辑</a>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@
<span style="margin-left: 20px;">{{keeper.masterReplOffset}}</span>
</div>
</md-card-title-text>
<md-card-actions layout="row" layout-align="end center">
<md-button class="md-raised" ng-disabled="getDisableResetElection()" ng-click="resetElection(keeper.host, keeper.port)">reset Election</md-button>
</md-card-actions>
</md-card-title>
<md-card-content>
<div style="white-space: nowrap;">
Expand Down Expand Up @@ -138,6 +141,12 @@
</md-card-content>
</md-card>
</div>


<xpipeconfirmdialog xpipe-dialog-id="'resetElectionErr'" xpipe-title="'resetElection Err'"
xpipe-detail="getResetElectionErr()"
xpipe-show-cancel-btn="true"></xpipeconfirmdialog>

<div flex-xs flex-gt-xs="50" layout="column">
<!--Checker-->
<md-card md-theme="{{shardCheckerHealthCheckResult != [] ? 'default' : 'red'}}" md-theme-watch>
Expand Down

0 comments on commit 47c1f61

Please sign in to comment.