Skip to content

Commit

Permalink
Allow partial cluster config updates.
Browse files Browse the repository at this point in the history
  • Loading branch information
benbjohnson committed Mar 10, 2014
1 parent c0a59b3 commit e9a1ac1
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions server/peer_server_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,12 +215,27 @@ func (ps *PeerServer) getClusterConfigHttpHandler(w http.ResponseWriter, req *ht

// Updates the cluster configuration.
func (ps *PeerServer) setClusterConfigHttpHandler(w http.ResponseWriter, req *http.Request) {
c := &SetClusterConfigCommand{Config: &ClusterConfig{}}
if err := json.NewDecoder(req.Body).Decode(&c.Config); err != nil {
// Decode map.
m := make(map[string]interface{})
if err := json.NewDecoder(req.Body).Decode(&m); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}

// Copy config and update fields passed in.
config := &ClusterConfig{
ActiveSize: ps.clusterConfig.ActiveSize,
PromoteDelay: ps.clusterConfig.PromoteDelay,
}
if activeSize, ok := m["activeSize"].(float64); ok {
config.ActiveSize = int(activeSize)
}
if promoteDelay, ok := m["promoteDelay"].(float64); ok {
config.PromoteDelay = int(promoteDelay)
}

// Issue command to update.
c := &SetClusterConfigCommand{Config: config}
log.Debugf("[recv] Update Cluster Config Request")
ps.server.Dispatch(c, w, req)

Expand Down

0 comments on commit e9a1ac1

Please sign in to comment.