(w http.ResponseWriter, req *http.Request)
| 132 | } |
| 133 | |
| 134 | func (h *PartitionRingPageHandler) handlePostRequest(w http.ResponseWriter, req *http.Request) { |
| 135 | if req.FormValue("action") == "change_state" { |
| 136 | partitionID, err := strconv.Atoi(req.FormValue("partition_id")) |
| 137 | if err != nil { |
| 138 | http.Error(w, fmt.Sprintf("invalid partition ID: %s", err.Error()), http.StatusBadRequest) |
| 139 | return |
| 140 | } |
| 141 | |
| 142 | toState, ok := PartitionState_value[req.FormValue("partition_state")] |
| 143 | if !ok { |
| 144 | http.Error(w, "invalid partition state", http.StatusBadRequest) |
| 145 | return |
| 146 | } |
| 147 | |
| 148 | if err := h.updater.ChangePartitionState(req.Context(), int32(partitionID), PartitionState(toState)); err != nil { |
| 149 | http.Error(w, fmt.Sprintf("failed to change partition state: %s", err.Error()), http.StatusBadRequest) |
| 150 | return |
| 151 | } |
| 152 | } else if req.FormValue("action") == "change_state_and_lock" { |
| 153 | // NOTE: To avoid playing Whac-a-Mole with rollout-operator (or other actors) reverting the state to active BEFORE the operator |
| 154 | // is able to lock the partition state change, we offer this method which attempts to change the state and lock immediately. |
| 155 | // This currently contains a race. But since usually this endpoint is served by many replicas, fixing the race would require |
| 156 | // some work. We believe it's not worth it to add the additional complexity and we rely on the user using this to ensure |
| 157 | // that the state change is locked in the desired state. |
| 158 | partitionID, err := strconv.Atoi(req.FormValue("partition_id")) |
| 159 | if err != nil { |
| 160 | http.Error(w, fmt.Sprintf("invalid partition ID: %s", err.Error()), http.StatusBadRequest) |
| 161 | return |
| 162 | } |
| 163 | |
| 164 | toState, ok := PartitionState_value[req.FormValue("partition_state")] |
| 165 | if !ok { |
| 166 | http.Error(w, "invalid partition state", http.StatusBadRequest) |
| 167 | return |
| 168 | } |
| 169 | |
| 170 | if err := h.updater.ChangePartitionState(req.Context(), int32(partitionID), PartitionState(toState)); err != nil { |
| 171 | http.Error(w, fmt.Sprintf("failed to change partition state: %s", err.Error()), http.StatusBadRequest) |
| 172 | return |
| 173 | } |
| 174 | |
| 175 | if err := h.updater.SetPartitionStateChangeLock(req.Context(), int32(partitionID), true); err != nil { |
| 176 | http.Error(w, fmt.Sprintf("failed to lock partition state change: %s", err.Error()), http.StatusBadRequest) |
| 177 | return |
| 178 | } |
| 179 | } else if req.FormValue("action") == "state_change_lock" { |
| 180 | partitionID, err := strconv.Atoi(req.FormValue("partition_id")) |
| 181 | if err != nil { |
| 182 | http.Error(w, fmt.Sprintf("invalid partition ID: %s", err.Error()), http.StatusBadRequest) |
| 183 | return |
| 184 | } |
| 185 | |
| 186 | locked, err := strconv.ParseBool(req.FormValue("locked")) |
| 187 | if err != nil { |
| 188 | http.Error(w, fmt.Sprintf("invalid locked value: %s", err.Error()), http.StatusBadRequest) |
| 189 | return |
| 190 | } |
| 191 |
no test coverage detected