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 14, 2024
1 parent d0bb509 commit 09b1865
Show file tree
Hide file tree
Showing 10 changed files with 142 additions and 13 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.KeeperService;
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
KeeperService keeperService;

@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 {
keeperService.resetElection(model.getIp(), Integer.parseInt(model.getPort()), Long.parseLong(model.getShardId()));
return RetMessage.createSuccessMessage();
} catch (Throwable th) {
return RetMessage.createFailMessage(th.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 +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,7 @@
*/
public interface KeeperService {
boolean isKeeper(HostPort hostPort);

void resetElection(String keeperIp, int port, long shardId) throws Exception;

}
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
package com.ctrip.xpipe.redis.console.service.impl;

import com.ctrip.xpipe.endpoint.HostPort;
import com.ctrip.xpipe.redis.console.config.ConsoleConfig;
import com.ctrip.xpipe.redis.console.keeper.command.KeeperResetCommand;
import com.ctrip.xpipe.redis.console.service.KeeperContainerService;
import com.ctrip.xpipe.redis.core.meta.MetaCache;
import com.ctrip.xpipe.redis.console.service.KeeperService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.concurrent.ScheduledExecutorService;

import static com.ctrip.xpipe.redis.checker.resource.Resource.REDIS_COMMAND_EXECUTOR;


/**
* @author chen.zhu
Expand All @@ -20,10 +26,18 @@ public class KeeperServiceImpl implements KeeperService {
MetaCache metaCache;

@Autowired
ConsoleConfig consoleConfig;
private KeeperContainerService keeperContainerService;

@Resource(name = REDIS_COMMAND_EXECUTOR)
private ScheduledExecutorService scheduled;

@Override
public boolean isKeeper(HostPort hostPort) {
return metaCache.getAllKeepers().contains(hostPort);
}

@Override
public void resetElection(String keeperIp, int port, long shardId) throws Exception {
new KeeperResetCommand<>(keeperIp, shardId, keeperContainerService).execute(scheduled).get();
}
}
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.ableResetElection = false;
$scope.getAbleResetElection = getAbleResetElection;
$scope.resetElectionErr = null;
$scope.getResetElectionErr = getResetElectionErr;

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

function resetElection(ip, port) {
$scope.ableResetElection = true;
KeeperContainerService.resetElection(ip, port, $stateParams.shardId).then(function (response) {
$scope.ableResetElection = false;
if (response.state != 0) {
$scope.resetElectionErr = response.message;
$('#resetElectionErr').modal('show');
} else {
getShardKeeperState();
}
}).catch(function (error){
$scope.resetElectionErr = error.status + " " + error.statusText;
$scope.ableResetElection = false;
$('#resetElectionErr').modal('show');
})
}

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

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

function getAbleResetElection() {
return $scope.ableResetElection;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ function HealthCheckService($resource, $q) {
const GET_SHARD_KEEPER_STATE = "get_shard_keeper_state";
const GET_SHARD_CHECKER_HEALTH_CHECK = "get_shard_checker_health_check";
const GET_SHARD_ALL_META = "get_shard_all_meta";
const RESET_ELECTION = "reset_election";

var apis = (function initResourceParam() {
var apis = {};
Expand Down Expand Up @@ -213,6 +214,7 @@ function HealthCheckService($resource, $q) {
});
}


return {
isRedisHealth : isRedisHealth,
getReplDelay : getReplDelay,
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-click="resetElection(keeper.host, keeper.port)" ng-disabled="getAbleResetElection()">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 09b1865

Please sign in to comment.