moveTablet can be used to move a tablet to a specific group. It takes in tablet and group as argument.
(w http.ResponseWriter, r *http.Request)
| 139 | // moveTablet can be used to move a tablet to a specific group. It takes in tablet and group as |
| 140 | // argument. |
| 141 | func (st *state) moveTablet(w http.ResponseWriter, r *http.Request) { |
| 142 | x.AddCorsHeaders(w) |
| 143 | if r.Method == "OPTIONS" { |
| 144 | return |
| 145 | } |
| 146 | if r.Method != http.MethodGet { |
| 147 | w.WriteHeader(http.StatusBadRequest) |
| 148 | x.SetStatus(w, x.ErrorInvalidMethod, "Invalid method") |
| 149 | return |
| 150 | } |
| 151 | |
| 152 | if !st.node.AmLeader() { |
| 153 | w.WriteHeader(http.StatusBadRequest) |
| 154 | x.SetStatus(w, x.ErrorInvalidRequest, |
| 155 | "This Zero server is not the leader. Re-run command on leader.") |
| 156 | return |
| 157 | } |
| 158 | |
| 159 | namespace := r.URL.Query().Get("namespace") |
| 160 | namespace = strings.TrimSpace(namespace) |
| 161 | ns := x.RootNamespace |
| 162 | if namespace != "" { |
| 163 | var err error |
| 164 | if ns, err = strconv.ParseUint(namespace, 0, 64); err != nil { |
| 165 | w.WriteHeader(http.StatusBadRequest) |
| 166 | x.SetStatus(w, x.ErrorInvalidRequest, "Invalid namespace in query parameter.") |
| 167 | return |
| 168 | } |
| 169 | } |
| 170 | |
| 171 | tablet := r.URL.Query().Get("tablet") |
| 172 | if len(tablet) == 0 { |
| 173 | w.WriteHeader(http.StatusBadRequest) |
| 174 | x.SetStatus(w, x.ErrorInvalidRequest, "tablet is a mandatory query parameter") |
| 175 | return |
| 176 | } |
| 177 | |
| 178 | groupId, ok := intFromQueryParam(w, r, "group") |
| 179 | if !ok { |
| 180 | w.WriteHeader(http.StatusBadRequest) |
| 181 | x.SetStatus(w, x.ErrorInvalidRequest, |
| 182 | "Query parameter 'group' should contain a valid integer.") |
| 183 | return |
| 184 | } |
| 185 | dstGroup := uint32(groupId) |
| 186 | |
| 187 | var resp *pb.Status |
| 188 | var err error |
| 189 | if resp, err = st.zero.MoveTablet( |
| 190 | context.Background(), |
| 191 | &pb.MoveTabletRequest{Namespace: ns, Tablet: tablet, DstGroup: dstGroup}, |
| 192 | ); err != nil { |
| 193 | if resp.GetMsg() == x.ErrorInvalidRequest { |
| 194 | w.WriteHeader(http.StatusBadRequest) |
| 195 | x.SetStatus(w, x.ErrorInvalidRequest, err.Error()) |
| 196 | } else { |
| 197 | w.WriteHeader(http.StatusInternalServerError) |
| 198 | x.SetStatus(w, x.Error, err.Error()) |
nothing calls this directly
no test coverage detected