Skip to content

Commit

Permalink
restart-slave:
Browse files Browse the repository at this point in the history
- added "restart-slave" cli command 
- added /api/restart-slave/...
- web: showing restart-slave button when appropriate (replaces "start
slave" on replication trouble)
  • Loading branch information
shlomi-noach committed Aug 24, 2015
1 parent b418ea8 commit e3bf450
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 3 deletions.
2 changes: 1 addition & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#
set -e

RELEASE_VERSION="1.4.323"
RELEASE_VERSION="1.4.324"
TOPDIR=/tmp/orchestrator-release
export RELEASE_VERSION TOPDIR

Expand Down
14 changes: 14 additions & 0 deletions go/app/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,20 @@ func Cli(command string, strict bool, instance string, destination string, owner
}
fmt.Println(instanceKey.DisplayString())
}
case cliCommand("restart-slave"):
{
if instanceKey == nil {
instanceKey = thisInstanceKey
}
if instanceKey == nil {
log.Fatal("Cannot deduce instance:", instance)
}
_, err := inst.RestartSlave(instanceKey)
if err != nil {
log.Fatale(err)
}
fmt.Println(instanceKey.DisplayString())
}
case cliCommand("reset-slave"):
{
if instanceKey == nil {
Expand Down
22 changes: 22 additions & 0 deletions go/http/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -829,6 +829,27 @@ func (this *HttpAPI) StartSlave(params martini.Params, r render.Render, req *htt
r.JSON(200, &APIResponse{Code: OK, Message: fmt.Sprintf("Slave started: %+v", instance.Key), Details: instance})
}

// RestartSlave stops & starts replication on given instance
func (this *HttpAPI) RestartSlave(params martini.Params, r render.Render, req *http.Request, user auth.User) {
if !isAuthorizedForAction(req, user) {
r.JSON(200, &APIResponse{Code: ERROR, Message: "Unauthorized"})
return
}
instanceKey, err := this.getInstanceKey(params["host"], params["port"])

if err != nil {
r.JSON(200, &APIResponse{Code: ERROR, Message: err.Error()})
return
}
instance, err := inst.RestartSlave(&instanceKey)
if err != nil {
r.JSON(200, &APIResponse{Code: ERROR, Message: err.Error()})
return
}

r.JSON(200, &APIResponse{Code: OK, Message: fmt.Sprintf("Slave restarted: %+v", instance.Key), Details: instance})
}

// StopSlave stops replication on given instance
func (this *HttpAPI) StopSlave(params martini.Params, r render.Render, req *http.Request, user auth.User) {
if !isAuthorizedForAction(req, user) {
Expand Down Expand Up @@ -1731,6 +1752,7 @@ func (this *HttpAPI) RegisterRequests(m *martini.ClassicMartini) {
m.Get("/api/end-downtime/:host/:port", this.EndDowntime)
m.Get("/api/skip-query/:host/:port", this.SkipQuery)
m.Get("/api/start-slave/:host/:port", this.StartSlave)
m.Get("/api/restart-slave/:host/:port", this.RestartSlave)
m.Get("/api/stop-slave/:host/:port", this.StopSlave)
m.Get("/api/stop-slave-nice/:host/:port", this.StopSlaveNicely)
m.Get("/api/set-read-only/:host/:port", this.SetReadOnly)
Expand Down
14 changes: 14 additions & 0 deletions go/inst/instance_dao.go
Original file line number Diff line number Diff line change
Expand Up @@ -1735,6 +1735,20 @@ func StartSlave(instanceKey *InstanceKey) (*Instance, error) {
return instance, err
}

// RestartSlave stops & starts replication on a given instance
func RestartSlave(instanceKey *InstanceKey) (instance *Instance, err error) {
instance, err = StopSlave(instanceKey)
if err != nil {
return instance, log.Errore(err)
}
instance, err = StartSlave(instanceKey)
if err != nil {
return instance, log.Errore(err)
}
return instance, nil

}

// StartSlaves will do concurrent start-slave
func StartSlaves(slaves [](*Instance)) {
// use concurrency but wait for all to complete
Expand Down
9 changes: 7 additions & 2 deletions resources/public/js/orchestrator.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ function openNodeModal(node) {

td = addNodeModalDataAttribute("Replication running", booleanString(node.replicationRunning));
$('#node_modal button[data-btn=start-slave]').appendTo(td.find("div"))
$('#node_modal button[data-btn=restart-slave]').appendTo(td.find("div"))
$('#node_modal [data-btn-group=stop-slave]').appendTo(td.find("div"))

if (!node.replicationRunning) {
Expand Down Expand Up @@ -273,6 +274,9 @@ function openNodeModal(node) {
$('#node_modal button[data-btn=start-slave]').click(function(){
apiCommand("/api/start-slave/"+node.Key.Hostname+"/"+node.Key.Port);
});
$('#node_modal button[data-btn=restart-slave]').click(function(){
apiCommand("/api/restart-slave/"+node.Key.Hostname+"/"+node.Key.Port);
});
$('#node_modal [data-btn=stop-slave]').click(function(){
apiCommand("/api/stop-slave/"+node.Key.Hostname+"/"+node.Key.Port);
});
Expand Down Expand Up @@ -331,13 +335,14 @@ function openNodeModal(node) {
}
$('#node_modal button[data-btn=skip-query]').hide();
$('#node_modal button[data-btn=start-slave]').hide();
$('#node_modal button[data-btn=restart-slave]').hide();
$('#node_modal [data-btn-group=stop-slave]').hide();

if (node.MasterKey.Hostname) {
if (node.replicationRunning || node.replicationAttemptingToRun) {
$('#node_modal [data-btn-group=stop-slave]').show();
}
if (!node.replicationRunning) {
$('#node_modal button[data-btn=restart-slave]').show();
} else if (!node.replicationRunning) {
$('#node_modal button[data-btn=start-slave]').show();
}
if (!node.Slave_SQL_Running && node.LastSQLError) {
Expand Down
1 change: 1 addition & 0 deletions resources/templates/layout.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@
<button type="button" class="btn btn-success" data-btn="recover" title="Recover from failure"><span class="glyphicon glyphicon-heart"></span> Recover</button>
<button type="button" class="btn alert-success" data-btn="refresh-instance" title="Refresh instance status now"><span class="glyphicon glyphicon-refresh"></span> Refresh</button>
<button type="button" class="btn btn-success" data-btn="start-slave"><span class="glyphicon glyphicon-play"></span> Start slave</button>
<button type="button" class="btn btn-warning" data-btn="restart-slave"><span class="glyphicon glyphicon-repeat"></span> Restart slave</button>

<div class="btn-group" data-btn-group="stop-slave">
<button type="button" class="btn btn-danger" data-btn="stop-slave" data-grouped="true">Stop slave</button>
Expand Down

0 comments on commit e3bf450

Please sign in to comment.