@@ -65,7 +65,7 @@ func (st *state) assign(w http.ResponseWriter, r *http.Request) {
65
65
return
66
66
}
67
67
68
- num := & pb.Num {Val : uint64 ( val ) }
68
+ num := & pb.Num {Val : val }
69
69
ctx , cancel := context .WithTimeout (context .Background (), 30 * time .Second )
70
70
defer cancel ()
71
71
@@ -87,7 +87,7 @@ func (st *state) assign(w http.ResponseWriter, r *http.Request) {
87
87
ids , err = st .zero .AssignIds (ctx , num )
88
88
default :
89
89
x .SetStatus (w , x .Error ,
90
- fmt .Sprintf ("Invalid what: [%s]. Must be one of uids or timestamps" , what ))
90
+ fmt .Sprintf ("Invalid what: [%s]. Must be one of: [ uids, timestamps, nsids] " , what ))
91
91
return
92
92
}
93
93
if err != nil {
@@ -124,7 +124,10 @@ func (st *state) removeNode(w http.ResponseWriter, r *http.Request) {
124
124
return
125
125
}
126
126
127
- if err := st .zero .removeNode (context .Background (), nodeId , uint32 (groupId )); err != nil {
127
+ if _ , err := st .zero .RemoveNode (
128
+ context .Background (),
129
+ & pb.RemoveNodeRequest {NodeId : nodeId , GroupId : uint32 (groupId )},
130
+ ); err != nil {
128
131
x .SetStatus (w , x .Error , err .Error ())
129
132
return
130
133
}
@@ -154,8 +157,6 @@ func (st *state) moveTablet(w http.ResponseWriter, r *http.Request) {
154
157
return
155
158
}
156
159
157
- tablet := r .URL .Query ().Get ("tablet" )
158
-
159
160
namespace := r .URL .Query ().Get ("namespace" )
160
161
namespace = strings .TrimSpace (namespace )
161
162
ns := x .GalaxyNamespace
@@ -168,7 +169,7 @@ func (st *state) moveTablet(w http.ResponseWriter, r *http.Request) {
168
169
}
169
170
}
170
171
171
- tablet = x . NamespaceAttr ( ns , tablet )
172
+ tablet := r . URL . Query (). Get ( " tablet" )
172
173
if len (tablet ) == 0 {
173
174
w .WriteHeader (http .StatusBadRequest )
174
175
x .SetStatus (w , x .ErrorInvalidRequest , "tablet is a mandatory query parameter" )
@@ -178,50 +179,28 @@ func (st *state) moveTablet(w http.ResponseWriter, r *http.Request) {
178
179
groupId , ok := intFromQueryParam (w , r , "group" )
179
180
if ! ok {
180
181
w .WriteHeader (http .StatusBadRequest )
181
- x .SetStatus (w , x .ErrorInvalidRequest , fmt .Sprintf (
182
- "Query parameter 'group' should contain a valid integer." ))
183
- return
184
- }
185
- dstGroup := uint32 (groupId )
186
- knownGroups := st .zero .KnownGroups ()
187
- var isKnown bool
188
- for _ , grp := range knownGroups {
189
- if grp == dstGroup {
190
- isKnown = true
191
- break
192
- }
193
- }
194
- if ! isKnown {
195
- w .WriteHeader (http .StatusBadRequest )
196
- x .SetStatus (w , x .ErrorInvalidRequest , fmt .Sprintf ("Group: [%d] is not a known group." ,
197
- dstGroup ))
198
- return
199
- }
200
-
201
- tab := st .zero .ServingTablet (tablet )
202
- if tab == nil {
203
- w .WriteHeader (http .StatusBadRequest )
204
- x .SetStatus (w , x .ErrorInvalidRequest , fmt .Sprintf ("No tablet found for: %s" , tablet ))
205
- return
206
- }
207
-
208
- srcGroup := tab .GroupId
209
- if srcGroup == dstGroup {
210
- w .WriteHeader (http .StatusInternalServerError )
211
182
x .SetStatus (w , x .ErrorInvalidRequest ,
212
- fmt . Sprintf ( "Tablet: [%s] is already being served by group: [%d]" , tablet , srcGroup ) )
183
+ "Query parameter 'group' should contain a valid integer." )
213
184
return
214
185
}
186
+ dstGroup := uint32 (groupId )
215
187
216
- if err := st .zero .movePredicate (tablet , srcGroup , dstGroup ); err != nil {
217
- glog .Errorf ("While moving predicate %s from %d -> %d. Error: %v" ,
218
- tablet , srcGroup , dstGroup , err )
219
- w .WriteHeader (http .StatusInternalServerError )
220
- x .SetStatus (w , x .Error , err .Error ())
188
+ var resp * pb.Status
189
+ var err error
190
+ if resp , err = st .zero .MoveTablet (
191
+ context .Background (),
192
+ & pb.MoveTabletRequest {Namespace : ns , Tablet : tablet , DstGroup : dstGroup },
193
+ ); err != nil {
194
+ if resp .GetMsg () == x .ErrorInvalidRequest {
195
+ w .WriteHeader (http .StatusBadRequest )
196
+ x .SetStatus (w , x .ErrorInvalidRequest , err .Error ())
197
+ } else {
198
+ w .WriteHeader (http .StatusInternalServerError )
199
+ x .SetStatus (w , x .Error , err .Error ())
200
+ }
221
201
return
222
202
}
223
- _ , err := fmt .Fprintf (w , "Predicate: [%s] moved from group [%d] to [%d]" ,
224
- tablet , srcGroup , dstGroup )
203
+ _ , err = fmt .Fprint (w , resp .GetMsg ())
225
204
if err != nil {
226
205
glog .Warningf ("Error while writing response: %+v" , err )
227
206
}
0 commit comments