1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.hadoop.hbase.protobuf;
19
20 import java.io.IOException;
21 import java.util.List;
22 import java.util.regex.Pattern;
23
24 import org.apache.hadoop.hbase.classification.InterfaceAudience;
25 import org.apache.hadoop.hbase.CellScannable;
26 import org.apache.hadoop.hbase.DoNotRetryIOException;
27 import org.apache.hadoop.hbase.HColumnDescriptor;
28 import org.apache.hadoop.hbase.HConstants;
29 import org.apache.hadoop.hbase.HRegionInfo;
30 import org.apache.hadoop.hbase.HTableDescriptor;
31 import org.apache.hadoop.hbase.ServerName;
32 import org.apache.hadoop.hbase.TableName;
33 import org.apache.hadoop.hbase.client.Action;
34 import org.apache.hadoop.hbase.client.Append;
35 import org.apache.hadoop.hbase.client.Delete;
36 import org.apache.hadoop.hbase.client.Durability;
37 import org.apache.hadoop.hbase.client.Get;
38 import org.apache.hadoop.hbase.client.Increment;
39 import org.apache.hadoop.hbase.client.Mutation;
40 import org.apache.hadoop.hbase.client.Put;
41 import org.apache.hadoop.hbase.client.RegionCoprocessorServiceExec;
42 import org.apache.hadoop.hbase.client.Row;
43 import org.apache.hadoop.hbase.client.RowMutations;
44 import org.apache.hadoop.hbase.client.Scan;
45 import org.apache.hadoop.hbase.exceptions.DeserializationException;
46 import org.apache.hadoop.hbase.filter.ByteArrayComparable;
47 import org.apache.hadoop.hbase.protobuf.generated.AccessControlProtos;
48 import org.apache.hadoop.hbase.protobuf.generated.AdminProtos.CloseRegionRequest;
49 import org.apache.hadoop.hbase.protobuf.generated.AdminProtos.CompactRegionRequest;
50 import org.apache.hadoop.hbase.protobuf.generated.AdminProtos.FlushRegionRequest;
51 import org.apache.hadoop.hbase.protobuf.generated.AdminProtos.GetOnlineRegionRequest;
52 import org.apache.hadoop.hbase.protobuf.generated.AdminProtos.GetRegionInfoRequest;
53 import org.apache.hadoop.hbase.protobuf.generated.AdminProtos.GetServerInfoRequest;
54 import org.apache.hadoop.hbase.protobuf.generated.AdminProtos.GetStoreFileRequest;
55 import org.apache.hadoop.hbase.protobuf.generated.AdminProtos.MergeRegionsRequest;
56 import org.apache.hadoop.hbase.protobuf.generated.AdminProtos.OpenRegionRequest;
57 import org.apache.hadoop.hbase.protobuf.generated.AdminProtos.OpenRegionRequest.RegionOpenInfo;
58 import org.apache.hadoop.hbase.protobuf.generated.AdminProtos.RollWALWriterRequest;
59 import org.apache.hadoop.hbase.protobuf.generated.AdminProtos.SplitRegionRequest;
60 import org.apache.hadoop.hbase.protobuf.generated.AdminProtos.StopServerRequest;
61 import org.apache.hadoop.hbase.protobuf.generated.AdminProtos.UpdateFavoredNodesRequest;
62 import org.apache.hadoop.hbase.protobuf.generated.AdminProtos.UpdateFavoredNodesRequest.RegionUpdateInfo;
63 import org.apache.hadoop.hbase.protobuf.generated.AdminProtos.WarmupRegionRequest;
64 import org.apache.hadoop.hbase.protobuf.generated.ClientProtos;
65 import org.apache.hadoop.hbase.protobuf.generated.ClientProtos.BulkLoadHFileRequest;
66 import org.apache.hadoop.hbase.protobuf.generated.ClientProtos.BulkLoadHFileRequest.FamilyPath;
67 import org.apache.hadoop.hbase.protobuf.generated.ClientProtos.Column;
68 import org.apache.hadoop.hbase.protobuf.generated.ClientProtos.Condition;
69 import org.apache.hadoop.hbase.protobuf.generated.ClientProtos.GetRequest;
70 import org.apache.hadoop.hbase.protobuf.generated.ClientProtos.MutateRequest;
71 import org.apache.hadoop.hbase.protobuf.generated.ClientProtos.MutationProto;
72 import org.apache.hadoop.hbase.protobuf.generated.ClientProtos.MutationProto.ColumnValue;
73 import org.apache.hadoop.hbase.protobuf.generated.ClientProtos.MutationProto.ColumnValue.QualifierValue;
74 import org.apache.hadoop.hbase.protobuf.generated.ClientProtos.MutationProto.MutationType;
75 import org.apache.hadoop.hbase.protobuf.generated.ClientProtos.RegionAction;
76 import org.apache.hadoop.hbase.protobuf.generated.ClientProtos.ScanRequest;
77 import org.apache.hadoop.hbase.protobuf.generated.HBaseProtos.CompareType;
78 import org.apache.hadoop.hbase.protobuf.generated.HBaseProtos.RegionSpecifier;
79 import org.apache.hadoop.hbase.protobuf.generated.HBaseProtos.RegionSpecifier.RegionSpecifierType;
80 import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.AddColumnRequest;
81 import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.AssignRegionRequest;
82 import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.BalanceRequest;
83 import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.CreateTableRequest;
84 import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.DeleteColumnRequest;
85 import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.DeleteTableRequest;
86 import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.DisableTableRequest;
87 import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.DispatchMergingRegionsRequest;
88 import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.EnableCatalogJanitorRequest;
89 import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.EnableTableRequest;
90 import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.GetClusterStatusRequest;
91 import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.GetSchemaAlterStatusRequest;
92 import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.GetTableDescriptorsRequest;
93 import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.GetTableNamesRequest;
94 import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.IsBalancerEnabledRequest;
95 import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.IsCatalogJanitorEnabledRequest;
96 import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.IsMasterRunningRequest;
97 import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.IsNormalizerEnabledRequest;
98 import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.ModifyColumnRequest;
99 import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.ModifyTableRequest;
100 import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.MoveRegionRequest;
101 import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.NormalizeRequest;
102 import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.OfflineRegionRequest;
103 import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.RunCatalogScanRequest;
104 import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.SetBalancerRunningRequest;
105 import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.SetNormalizerRunningRequest;
106 import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.TruncateTableRequest;
107 import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.UnassignRegionRequest;
108 import org.apache.hadoop.hbase.protobuf.generated.RegionServerStatusProtos.GetLastFlushedSequenceIdRequest;
109 import org.apache.hadoop.hbase.util.ByteStringer;
110 import org.apache.hadoop.hbase.util.Bytes;
111 import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
112 import org.apache.hadoop.hbase.util.Pair;
113 import org.apache.hadoop.hbase.util.Triple;
114
115 import com.google.protobuf.ByteString;
116
117
118
119
120
121 @InterfaceAudience.Private
122 public final class RequestConverter {
123
124 private RequestConverter() {
125 }
126
127
128
129
130
131
132
133
134
135
136
137
138
139 public static GetRequest buildGetRowOrBeforeRequest(
140 final byte[] regionName, final byte[] row, final byte[] family) {
141 GetRequest.Builder builder = GetRequest.newBuilder();
142 RegionSpecifier region = buildRegionSpecifier(
143 RegionSpecifierType.REGION_NAME, regionName);
144 builder.setRegion(region);
145
146 Column.Builder columnBuilder = Column.newBuilder();
147 columnBuilder.setFamily(ByteStringer.wrap(family));
148 ClientProtos.Get.Builder getBuilder =
149 ClientProtos.Get.newBuilder();
150 getBuilder.setRow(ByteStringer.wrap(row));
151 getBuilder.addColumn(columnBuilder.build());
152 getBuilder.setClosestRowBefore(true);
153 builder.setGet(getBuilder.build());
154 return builder.build();
155 }
156
157
158
159
160
161
162
163
164
165 public static GetRequest buildGetRequest(final byte[] regionName,
166 final Get get) throws IOException {
167 GetRequest.Builder builder = GetRequest.newBuilder();
168 RegionSpecifier region = buildRegionSpecifier(
169 RegionSpecifierType.REGION_NAME, regionName);
170 builder.setRegion(region);
171 builder.setGet(ProtobufUtil.toGet(get));
172 return builder.build();
173 }
174
175
176
177
178
179
180
181
182
183
184
185
186 public static MutateRequest buildIncrementRequest(
187 final byte[] regionName, final byte[] row, final byte[] family, final byte[] qualifier,
188 final long amount, final Durability durability, long nonceGroup, long nonce) {
189 MutateRequest.Builder builder = MutateRequest.newBuilder();
190 RegionSpecifier region = buildRegionSpecifier(
191 RegionSpecifierType.REGION_NAME, regionName);
192 builder.setRegion(region);
193
194 MutationProto.Builder mutateBuilder = MutationProto.newBuilder();
195 mutateBuilder.setRow(ByteStringer.wrap(row));
196 mutateBuilder.setMutateType(MutationType.INCREMENT);
197 mutateBuilder.setDurability(ProtobufUtil.toDurability(durability));
198 ColumnValue.Builder columnBuilder = ColumnValue.newBuilder();
199 columnBuilder.setFamily(ByteStringer.wrap(family));
200 QualifierValue.Builder valueBuilder = QualifierValue.newBuilder();
201 valueBuilder.setValue(ByteStringer.wrap(Bytes.toBytes(amount)));
202 valueBuilder.setQualifier(ByteStringer.wrap(qualifier));
203 columnBuilder.addQualifierValue(valueBuilder.build());
204 mutateBuilder.addColumnValue(columnBuilder.build());
205 if (nonce != HConstants.NO_NONCE) {
206 mutateBuilder.setNonce(nonce);
207 }
208 builder.setMutation(mutateBuilder.build());
209 if (nonceGroup != HConstants.NO_NONCE) {
210 builder.setNonceGroup(nonceGroup);
211 }
212 return builder.build();
213 }
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228 public static MutateRequest buildMutateRequest(
229 final byte[] regionName, final byte[] row, final byte[] family,
230 final byte [] qualifier, final ByteArrayComparable comparator,
231 final CompareType compareType, final Put put) throws IOException {
232 MutateRequest.Builder builder = MutateRequest.newBuilder();
233 RegionSpecifier region = buildRegionSpecifier(
234 RegionSpecifierType.REGION_NAME, regionName);
235 builder.setRegion(region);
236 Condition condition = buildCondition(
237 row, family, qualifier, comparator, compareType);
238 builder.setMutation(ProtobufUtil.toMutation(MutationType.PUT, put, MutationProto.newBuilder()));
239 builder.setCondition(condition);
240 return builder.build();
241 }
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256 public static MutateRequest buildMutateRequest(
257 final byte[] regionName, final byte[] row, final byte[] family,
258 final byte [] qualifier, final ByteArrayComparable comparator,
259 final CompareType compareType, final Delete delete) throws IOException {
260 MutateRequest.Builder builder = MutateRequest.newBuilder();
261 RegionSpecifier region = buildRegionSpecifier(
262 RegionSpecifierType.REGION_NAME, regionName);
263 builder.setRegion(region);
264 Condition condition = buildCondition(
265 row, family, qualifier, comparator, compareType);
266 builder.setMutation(ProtobufUtil.toMutation(MutationType.DELETE, delete,
267 MutationProto.newBuilder()));
268 builder.setCondition(condition);
269 return builder.build();
270 }
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285 public static ClientProtos.MultiRequest buildMutateRequest(
286 final byte[] regionName, final byte[] row, final byte[] family,
287 final byte [] qualifier, final ByteArrayComparable comparator,
288 final CompareType compareType, final RowMutations rowMutations) throws IOException {
289 RegionAction.Builder builder =
290 getRegionActionBuilderWithRegion(RegionAction.newBuilder(), regionName);
291 builder.setAtomic(true);
292 ClientProtos.Action.Builder actionBuilder = ClientProtos.Action.newBuilder();
293 MutationProto.Builder mutationBuilder = MutationProto.newBuilder();
294 Condition condition = buildCondition(
295 row, family, qualifier, comparator, compareType);
296 for (Mutation mutation: rowMutations.getMutations()) {
297 MutationType mutateType = null;
298 if (mutation instanceof Put) {
299 mutateType = MutationType.PUT;
300 } else if (mutation instanceof Delete) {
301 mutateType = MutationType.DELETE;
302 } else {
303 throw new DoNotRetryIOException("RowMutations supports only put and delete, not " +
304 mutation.getClass().getName());
305 }
306 mutationBuilder.clear();
307 MutationProto mp = ProtobufUtil.toMutation(mutateType, mutation, mutationBuilder);
308 actionBuilder.clear();
309 actionBuilder.setMutation(mp);
310 builder.addAction(actionBuilder.build());
311 }
312 ClientProtos.MultiRequest request =
313 ClientProtos.MultiRequest.newBuilder().addRegionAction(builder.build())
314 .setCondition(condition).build();
315 return request;
316 }
317
318
319
320
321
322
323
324
325
326 public static MutateRequest buildMutateRequest(
327 final byte[] regionName, final Put put) throws IOException {
328 MutateRequest.Builder builder = MutateRequest.newBuilder();
329 RegionSpecifier region = buildRegionSpecifier(
330 RegionSpecifierType.REGION_NAME, regionName);
331 builder.setRegion(region);
332 builder.setMutation(ProtobufUtil.toMutation(MutationType.PUT, put, MutationProto.newBuilder()));
333 return builder.build();
334 }
335
336
337
338
339
340
341
342
343
344 public static MutateRequest buildMutateRequest(final byte[] regionName,
345 final Append append, long nonceGroup, long nonce) throws IOException {
346 MutateRequest.Builder builder = MutateRequest.newBuilder();
347 RegionSpecifier region = buildRegionSpecifier(
348 RegionSpecifierType.REGION_NAME, regionName);
349 builder.setRegion(region);
350 if (nonce != HConstants.NO_NONCE && nonceGroup != HConstants.NO_NONCE) {
351 builder.setNonceGroup(nonceGroup);
352 }
353 builder.setMutation(ProtobufUtil.toMutation(MutationType.APPEND, append,
354 MutationProto.newBuilder(), nonce));
355 return builder.build();
356 }
357
358
359
360
361
362
363
364
365 public static MutateRequest buildMutateRequest(final byte[] regionName,
366 final Increment increment, final long nonceGroup, final long nonce) {
367 MutateRequest.Builder builder = MutateRequest.newBuilder();
368 RegionSpecifier region = buildRegionSpecifier(
369 RegionSpecifierType.REGION_NAME, regionName);
370 builder.setRegion(region);
371 if (nonce != HConstants.NO_NONCE && nonceGroup != HConstants.NO_NONCE) {
372 builder.setNonceGroup(nonceGroup);
373 }
374 builder.setMutation(ProtobufUtil.toMutation(increment, MutationProto.newBuilder(), nonce));
375 return builder.build();
376 }
377
378
379
380
381
382
383
384
385
386 public static MutateRequest buildMutateRequest(
387 final byte[] regionName, final Delete delete) throws IOException {
388 MutateRequest.Builder builder = MutateRequest.newBuilder();
389 RegionSpecifier region = buildRegionSpecifier(
390 RegionSpecifierType.REGION_NAME, regionName);
391 builder.setRegion(region);
392 builder.setMutation(ProtobufUtil.toMutation(MutationType.DELETE, delete,
393 MutationProto.newBuilder()));
394 return builder.build();
395 }
396
397
398
399
400
401
402
403
404
405
406 public static RegionAction.Builder buildRegionAction(final byte [] regionName,
407 final RowMutations rowMutations)
408 throws IOException {
409 RegionAction.Builder builder =
410 getRegionActionBuilderWithRegion(RegionAction.newBuilder(), regionName);
411 ClientProtos.Action.Builder actionBuilder = ClientProtos.Action.newBuilder();
412 MutationProto.Builder mutationBuilder = MutationProto.newBuilder();
413 for (Mutation mutation: rowMutations.getMutations()) {
414 MutationType mutateType = null;
415 if (mutation instanceof Put) {
416 mutateType = MutationType.PUT;
417 } else if (mutation instanceof Delete) {
418 mutateType = MutationType.DELETE;
419 } else {
420 throw new DoNotRetryIOException("RowMutations supports only put and delete, not " +
421 mutation.getClass().getName());
422 }
423 mutationBuilder.clear();
424 MutationProto mp = ProtobufUtil.toMutation(mutateType, mutation, mutationBuilder);
425 actionBuilder.clear();
426 actionBuilder.setMutation(mp);
427 builder.addAction(actionBuilder.build());
428 }
429 return builder;
430 }
431
432
433
434
435
436
437
438
439
440
441
442
443 public static RegionAction.Builder buildNoDataRegionAction(final byte[] regionName,
444 final RowMutations rowMutations, final List<CellScannable> cells,
445 final RegionAction.Builder regionActionBuilder,
446 final ClientProtos.Action.Builder actionBuilder,
447 final MutationProto.Builder mutationBuilder)
448 throws IOException {
449 for (Mutation mutation: rowMutations.getMutations()) {
450 MutationType type = null;
451 if (mutation instanceof Put) {
452 type = MutationType.PUT;
453 } else if (mutation instanceof Delete) {
454 type = MutationType.DELETE;
455 } else {
456 throw new DoNotRetryIOException("RowMutations supports only put and delete, not " +
457 mutation.getClass().getName());
458 }
459 mutationBuilder.clear();
460 MutationProto mp = ProtobufUtil.toMutationNoData(type, mutation, mutationBuilder);
461 cells.add(mutation);
462 actionBuilder.clear();
463 regionActionBuilder.addAction(actionBuilder.setMutation(mp).build());
464 }
465 return regionActionBuilder;
466 }
467
468 public static RegionAction.Builder getRegionActionBuilderWithRegion(
469 final RegionAction.Builder regionActionBuilder, final byte [] regionName) {
470 RegionSpecifier region = buildRegionSpecifier(RegionSpecifierType.REGION_NAME, regionName);
471 regionActionBuilder.setRegion(region);
472 return regionActionBuilder;
473 }
474
475
476
477
478
479
480
481
482
483
484
485 public static ScanRequest buildScanRequest(final byte[] regionName, final Scan scan,
486 final int numberOfRows, final boolean closeScanner) throws IOException {
487 ScanRequest.Builder builder = ScanRequest.newBuilder();
488 RegionSpecifier region = buildRegionSpecifier(
489 RegionSpecifierType.REGION_NAME, regionName);
490 builder.setNumberOfRows(numberOfRows);
491 builder.setCloseScanner(closeScanner);
492 builder.setRegion(region);
493 builder.setScan(ProtobufUtil.toScan(scan));
494 builder.setClientHandlesPartials(true);
495 builder.setClientHandlesHeartbeats(true);
496 builder.setTrackScanMetrics(scan.isScanMetricsEnabled());
497 return builder.build();
498 }
499
500
501
502
503
504
505
506
507
508 public static ScanRequest buildScanRequest(final long scannerId, final int numberOfRows,
509 final boolean closeScanner, final boolean trackMetrics) {
510 ScanRequest.Builder builder = ScanRequest.newBuilder();
511 builder.setNumberOfRows(numberOfRows);
512 builder.setCloseScanner(closeScanner);
513 builder.setScannerId(scannerId);
514 builder.setClientHandlesPartials(true);
515 builder.setClientHandlesHeartbeats(true);
516 builder.setTrackScanMetrics(trackMetrics);
517 return builder.build();
518 }
519
520
521
522
523
524
525
526
527
528
529 public static ScanRequest buildScanRequest(final long scannerId, final int numberOfRows,
530 final boolean closeScanner, final long nextCallSeq, final boolean trackMetrics,
531 final boolean renew) {
532 ScanRequest.Builder builder = ScanRequest.newBuilder();
533 builder.setNumberOfRows(numberOfRows);
534 builder.setCloseScanner(closeScanner);
535 builder.setScannerId(scannerId);
536 builder.setNextCallSeq(nextCallSeq);
537 builder.setClientHandlesPartials(true);
538 builder.setClientHandlesHeartbeats(true);
539 builder.setTrackScanMetrics(trackMetrics);
540 builder.setRenew(renew);
541 return builder.build();
542 }
543
544
545
546
547
548
549
550
551
552 public static BulkLoadHFileRequest buildBulkLoadHFileRequest(
553 final List<Pair<byte[], String>> familyPaths,
554 final byte[] regionName, boolean assignSeqNum) {
555 BulkLoadHFileRequest.Builder builder = BulkLoadHFileRequest.newBuilder();
556 RegionSpecifier region = buildRegionSpecifier(
557 RegionSpecifierType.REGION_NAME, regionName);
558 builder.setRegion(region);
559 FamilyPath.Builder familyPathBuilder = FamilyPath.newBuilder();
560 for (Pair<byte[], String> familyPath: familyPaths) {
561 familyPathBuilder.setFamily(ByteStringer.wrap(familyPath.getFirst()));
562 familyPathBuilder.setPath(familyPath.getSecond());
563 builder.addFamilyPath(familyPathBuilder.build());
564 }
565 builder.setAssignSeqNum(assignSeqNum);
566 return builder.build();
567 }
568
569
570
571
572
573
574
575
576
577
578 public static <R> RegionAction.Builder buildRegionAction(final byte[] regionName,
579 final List<Action<R>> actions, final RegionAction.Builder regionActionBuilder,
580 final ClientProtos.Action.Builder actionBuilder,
581 final MutationProto.Builder mutationBuilder) throws IOException {
582 for (Action<R> action: actions) {
583 Row row = action.getAction();
584 actionBuilder.clear();
585 actionBuilder.setIndex(action.getOriginalIndex());
586 mutationBuilder.clear();
587 if (row instanceof Get) {
588 Get g = (Get)row;
589 regionActionBuilder.addAction(actionBuilder.setGet(ProtobufUtil.toGet(g)));
590 } else if (row instanceof Put) {
591 regionActionBuilder.addAction(actionBuilder.
592 setMutation(ProtobufUtil.toMutation(MutationType.PUT, (Put)row, mutationBuilder)));
593 } else if (row instanceof Delete) {
594 regionActionBuilder.addAction(actionBuilder.
595 setMutation(ProtobufUtil.toMutation(MutationType.DELETE, (Delete)row, mutationBuilder)));
596 } else if (row instanceof Append) {
597 regionActionBuilder.addAction(actionBuilder.setMutation(ProtobufUtil.toMutation(
598 MutationType.APPEND, (Append)row, mutationBuilder, action.getNonce())));
599 } else if (row instanceof Increment) {
600 regionActionBuilder.addAction(actionBuilder.setMutation(
601 ProtobufUtil.toMutation((Increment)row, mutationBuilder, action.getNonce())));
602 } else if (row instanceof RegionCoprocessorServiceExec) {
603 RegionCoprocessorServiceExec exec = (RegionCoprocessorServiceExec) row;
604 regionActionBuilder.addAction(actionBuilder.setServiceCall(
605 ClientProtos.CoprocessorServiceCall.newBuilder()
606 .setRow(ByteStringer.wrap(exec.getRow()))
607 .setServiceName(exec.getMethod().getService().getFullName())
608 .setMethodName(exec.getMethod().getName())
609 .setRequest(exec.getRequest().toByteString())));
610 } else if (row instanceof RowMutations) {
611 throw new UnsupportedOperationException("No RowMutations in multi calls; use mutateRow");
612 } else {
613 throw new DoNotRetryIOException("Multi doesn't support " + row.getClass().getName());
614 }
615 }
616 return regionActionBuilder;
617 }
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635 public static <R> RegionAction.Builder buildNoDataRegionAction(final byte[] regionName,
636 final List<Action<R>> actions, final List<CellScannable> cells,
637 final RegionAction.Builder regionActionBuilder,
638 final ClientProtos.Action.Builder actionBuilder,
639 final MutationProto.Builder mutationBuilder) throws IOException {
640 RegionAction.Builder builder = getRegionActionBuilderWithRegion(
641 RegionAction.newBuilder(), regionName);
642 for (Action<R> action: actions) {
643 Row row = action.getAction();
644 actionBuilder.clear();
645 actionBuilder.setIndex(action.getOriginalIndex());
646 mutationBuilder.clear();
647 if (row instanceof Get) {
648 Get g = (Get)row;
649 builder.addAction(actionBuilder.setGet(ProtobufUtil.toGet(g)));
650 } else if (row instanceof Put) {
651 Put p = (Put)row;
652 cells.add(p);
653 builder.addAction(actionBuilder.
654 setMutation(ProtobufUtil.toMutationNoData(MutationType.PUT, p, mutationBuilder)));
655 } else if (row instanceof Delete) {
656 Delete d = (Delete)row;
657 int size = d.size();
658
659
660
661
662
663 if (size > 0) {
664 cells.add(d);
665 builder.addAction(actionBuilder.
666 setMutation(ProtobufUtil.toMutationNoData(MutationType.DELETE, d, mutationBuilder)));
667 } else {
668 builder.addAction(actionBuilder.
669 setMutation(ProtobufUtil.toMutation(MutationType.DELETE, d, mutationBuilder)));
670 }
671 } else if (row instanceof Append) {
672 Append a = (Append)row;
673 cells.add(a);
674 builder.addAction(actionBuilder.setMutation(ProtobufUtil.toMutationNoData(
675 MutationType.APPEND, a, mutationBuilder, action.getNonce())));
676 } else if (row instanceof Increment) {
677 Increment i = (Increment)row;
678 cells.add(i);
679 builder.addAction(actionBuilder.setMutation(ProtobufUtil.toMutationNoData(
680 MutationType.INCREMENT, i, mutationBuilder, action.getNonce())));
681 } else if (row instanceof RegionCoprocessorServiceExec) {
682 RegionCoprocessorServiceExec exec = (RegionCoprocessorServiceExec) row;
683 builder.addAction(actionBuilder.setServiceCall(ClientProtos.CoprocessorServiceCall
684 .newBuilder().setRow(ByteStringer.wrap(exec.getRow()))
685 .setServiceName(exec.getMethod().getService().getFullName())
686 .setMethodName(exec.getMethod().getName())
687 .setRequest(exec.getRequest().toByteString())));
688 } else if (row instanceof RowMutations) {
689 throw new UnsupportedOperationException("No RowMutations in multi calls; use mutateRow");
690 } else {
691 throw new DoNotRetryIOException("Multi doesn't support " + row.getClass().getName());
692 }
693 }
694 return builder;
695 }
696
697
698
699
700
701
702
703
704
705
706 public static GetRegionInfoRequest
707 buildGetRegionInfoRequest(final byte[] regionName) {
708 return buildGetRegionInfoRequest(regionName, false);
709 }
710
711
712
713
714
715
716
717
718 public static GetRegionInfoRequest
719 buildGetRegionInfoRequest(final byte[] regionName,
720 final boolean includeCompactionState) {
721 GetRegionInfoRequest.Builder builder = GetRegionInfoRequest.newBuilder();
722 RegionSpecifier region = buildRegionSpecifier(
723 RegionSpecifierType.REGION_NAME, regionName);
724 builder.setRegion(region);
725 if (includeCompactionState) {
726 builder.setCompactionState(includeCompactionState);
727 }
728 return builder.build();
729 }
730
731
732
733
734
735
736
737
738 public static GetStoreFileRequest
739 buildGetStoreFileRequest(final byte[] regionName, final byte[] family) {
740 GetStoreFileRequest.Builder builder = GetStoreFileRequest.newBuilder();
741 RegionSpecifier region = buildRegionSpecifier(
742 RegionSpecifierType.REGION_NAME, regionName);
743 builder.setRegion(region);
744 builder.addFamily(ByteStringer.wrap(family));
745 return builder.build();
746 }
747
748
749
750
751
752
753 public static GetOnlineRegionRequest buildGetOnlineRegionRequest() {
754 return GetOnlineRegionRequest.newBuilder().build();
755 }
756
757
758
759
760
761
762
763 public static FlushRegionRequest
764 buildFlushRegionRequest(final byte[] regionName) {
765 return buildFlushRegionRequest(regionName, false);
766 }
767
768
769
770
771
772
773
774 public static FlushRegionRequest
775 buildFlushRegionRequest(final byte[] regionName, boolean writeFlushWALMarker) {
776 FlushRegionRequest.Builder builder = FlushRegionRequest.newBuilder();
777 RegionSpecifier region = buildRegionSpecifier(
778 RegionSpecifierType.REGION_NAME, regionName);
779 builder.setRegion(region);
780 builder.setWriteFlushWalMarker(writeFlushWALMarker);
781 return builder.build();
782 }
783
784
785
786
787
788
789
790
791
792 public static OpenRegionRequest
793 buildOpenRegionRequest(ServerName server, final List<Triple<HRegionInfo, Integer,
794 List<ServerName>>> regionOpenInfos, Boolean openForReplay) {
795 OpenRegionRequest.Builder builder = OpenRegionRequest.newBuilder();
796 for (Triple<HRegionInfo, Integer, List<ServerName>> regionOpenInfo: regionOpenInfos) {
797 Integer second = regionOpenInfo.getSecond();
798 int versionOfOfflineNode = second == null ? -1 : second.intValue();
799 builder.addOpenInfo(buildRegionOpenInfo(regionOpenInfo.getFirst(), versionOfOfflineNode,
800 regionOpenInfo.getThird(), openForReplay));
801 }
802 if (server != null) {
803 builder.setServerStartCode(server.getStartcode());
804 }
805
806 builder.setMasterSystemTime(EnvironmentEdgeManager.currentTime());
807 return builder.build();
808 }
809
810
811
812
813
814
815
816
817
818
819
820 public static OpenRegionRequest buildOpenRegionRequest(ServerName server,
821 final HRegionInfo region, final int versionOfOfflineNode, List<ServerName> favoredNodes,
822 Boolean openForReplay) {
823 OpenRegionRequest.Builder builder = OpenRegionRequest.newBuilder();
824 builder.addOpenInfo(buildRegionOpenInfo(region, versionOfOfflineNode, favoredNodes,
825 openForReplay));
826 if (server != null) {
827 builder.setServerStartCode(server.getStartcode());
828 }
829 builder.setMasterSystemTime(EnvironmentEdgeManager.currentTime());
830 return builder.build();
831 }
832
833
834
835
836
837
838 public static UpdateFavoredNodesRequest buildUpdateFavoredNodesRequest(
839 final List<Pair<HRegionInfo, List<ServerName>>> updateRegionInfos) {
840 UpdateFavoredNodesRequest.Builder ubuilder = UpdateFavoredNodesRequest.newBuilder();
841 for (Pair<HRegionInfo, List<ServerName>> pair : updateRegionInfos) {
842 RegionUpdateInfo.Builder builder = RegionUpdateInfo.newBuilder();
843 builder.setRegion(HRegionInfo.convert(pair.getFirst()));
844 for (ServerName server : pair.getSecond()) {
845 builder.addFavoredNodes(ProtobufUtil.toServerName(server));
846 }
847 ubuilder.addUpdateInfo(builder.build());
848 }
849 return ubuilder.build();
850 }
851
852
853
854
855
856
857
858
859 public static CloseRegionRequest buildCloseRegionRequest(ServerName server,
860 final byte[] regionName, final boolean transitionInZK) {
861 CloseRegionRequest.Builder builder = CloseRegionRequest.newBuilder();
862 RegionSpecifier region = buildRegionSpecifier(
863 RegionSpecifierType.REGION_NAME, regionName);
864 builder.setRegion(region);
865 builder.setTransitionInZK(transitionInZK);
866 if (server != null) {
867 builder.setServerStartCode(server.getStartcode());
868 }
869 return builder.build();
870 }
871
872 public static CloseRegionRequest buildCloseRegionRequest(ServerName server,
873 final byte[] regionName, final int versionOfClosingNode,
874 ServerName destinationServer, final boolean transitionInZK) {
875 CloseRegionRequest.Builder builder = CloseRegionRequest.newBuilder();
876 RegionSpecifier region = buildRegionSpecifier(
877 RegionSpecifierType.REGION_NAME, regionName);
878 builder.setRegion(region);
879 builder.setVersionOfClosingNode(versionOfClosingNode);
880 builder.setTransitionInZK(transitionInZK);
881 if (destinationServer != null){
882 builder.setDestinationServer(ProtobufUtil.toServerName( destinationServer) );
883 }
884 if (server != null) {
885 builder.setServerStartCode(server.getStartcode());
886 }
887 return builder.build();
888 }
889
890
891
892
893
894
895 public static WarmupRegionRequest buildWarmupRegionRequest(final HRegionInfo regionInfo) {
896 WarmupRegionRequest.Builder builder = WarmupRegionRequest.newBuilder();
897 builder.setRegionInfo(HRegionInfo.convert(regionInfo));
898 return builder.build();
899 }
900
901
902
903
904
905
906
907 public static CloseRegionRequest
908 buildCloseRegionRequest(ServerName server, final String encodedRegionName,
909 final boolean transitionInZK) {
910 CloseRegionRequest.Builder builder = CloseRegionRequest.newBuilder();
911 RegionSpecifier region = buildRegionSpecifier(
912 RegionSpecifierType.ENCODED_REGION_NAME,
913 Bytes.toBytes(encodedRegionName));
914 builder.setRegion(region);
915 builder.setTransitionInZK(transitionInZK);
916 if (server != null) {
917 builder.setServerStartCode(server.getStartcode());
918 }
919 return builder.build();
920 }
921
922
923
924
925
926
927
928
929 public static SplitRegionRequest buildSplitRegionRequest(
930 final byte[] regionName, final byte[] splitPoint) {
931 SplitRegionRequest.Builder builder = SplitRegionRequest.newBuilder();
932 RegionSpecifier region = buildRegionSpecifier(
933 RegionSpecifierType.REGION_NAME, regionName);
934 builder.setRegion(region);
935 if (splitPoint != null) {
936 builder.setSplitPoint(ByteStringer.wrap(splitPoint));
937 }
938 return builder.build();
939 }
940
941
942
943
944
945
946
947
948 public static MergeRegionsRequest buildMergeRegionsRequest(
949 final byte[] regionA, final byte[] regionB, final boolean forcible) {
950 MergeRegionsRequest.Builder builder = MergeRegionsRequest.newBuilder();
951 RegionSpecifier regionASpecifier = buildRegionSpecifier(
952 RegionSpecifierType.REGION_NAME, regionA);
953 RegionSpecifier regionBSpecifier = buildRegionSpecifier(
954 RegionSpecifierType.REGION_NAME, regionB);
955 builder.setRegionA(regionASpecifier);
956 builder.setRegionB(regionBSpecifier);
957 builder.setForcible(forcible);
958
959 builder.setMasterSystemTime(EnvironmentEdgeManager.currentTime());
960 return builder.build();
961 }
962
963
964
965
966
967
968
969
970 public static CompactRegionRequest buildCompactRegionRequest(
971 final byte[] regionName, final boolean major, final byte [] family) {
972 CompactRegionRequest.Builder builder = CompactRegionRequest.newBuilder();
973 RegionSpecifier region = buildRegionSpecifier(
974 RegionSpecifierType.REGION_NAME, regionName);
975 builder.setRegion(region);
976 builder.setMajor(major);
977 if (family != null) {
978 builder.setFamily(ByteStringer.wrap(family));
979 }
980 return builder.build();
981 }
982
983
984
985
986 private static RollWALWriterRequest ROLL_WAL_WRITER_REQUEST =
987 RollWALWriterRequest.newBuilder().build();
988
989
990
991
992
993
994 public static RollWALWriterRequest buildRollWALWriterRequest() {
995 return ROLL_WAL_WRITER_REQUEST;
996 }
997
998
999
1000
1001 private static GetServerInfoRequest GET_SERVER_INFO_REQUEST =
1002 GetServerInfoRequest.newBuilder().build();
1003
1004
1005
1006
1007
1008
1009 public static GetServerInfoRequest buildGetServerInfoRequest() {
1010 return GET_SERVER_INFO_REQUEST;
1011 }
1012
1013
1014
1015
1016
1017
1018
1019 public static StopServerRequest buildStopServerRequest(final String reason) {
1020 StopServerRequest.Builder builder = StopServerRequest.newBuilder();
1021 builder.setReason(reason);
1022 return builder.build();
1023 }
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034 public static RegionSpecifier buildRegionSpecifier(
1035 final RegionSpecifierType type, final byte[] value) {
1036 RegionSpecifier.Builder regionBuilder = RegionSpecifier.newBuilder();
1037 regionBuilder.setValue(ByteStringer.wrap(value));
1038 regionBuilder.setType(type);
1039 return regionBuilder.build();
1040 }
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053 public static Condition buildCondition(final byte[] row,
1054 final byte[] family, final byte [] qualifier,
1055 final ByteArrayComparable comparator,
1056 final CompareType compareType) throws IOException {
1057 Condition.Builder builder = Condition.newBuilder();
1058 builder.setRow(ByteStringer.wrap(row));
1059 builder.setFamily(ByteStringer.wrap(family));
1060 builder.setQualifier(ByteStringer.wrap(qualifier));
1061 builder.setComparator(ProtobufUtil.toComparator(comparator));
1062 builder.setCompareType(compareType);
1063 return builder.build();
1064 }
1065
1066
1067
1068
1069
1070
1071
1072
1073 public static AddColumnRequest buildAddColumnRequest(
1074 final TableName tableName,
1075 final HColumnDescriptor column,
1076 final long nonceGroup,
1077 final long nonce) {
1078 AddColumnRequest.Builder builder = AddColumnRequest.newBuilder();
1079 builder.setTableName(ProtobufUtil.toProtoTableName(tableName));
1080 builder.setColumnFamilies(column.convert());
1081 builder.setNonceGroup(nonceGroup);
1082 builder.setNonce(nonce);
1083 return builder.build();
1084 }
1085
1086
1087
1088
1089
1090
1091
1092
1093 public static DeleteColumnRequest buildDeleteColumnRequest(
1094 final TableName tableName,
1095 final byte [] columnName,
1096 final long nonceGroup,
1097 final long nonce) {
1098 DeleteColumnRequest.Builder builder = DeleteColumnRequest.newBuilder();
1099 builder.setTableName(ProtobufUtil.toProtoTableName((tableName)));
1100 builder.setColumnName(ByteStringer.wrap(columnName));
1101 builder.setNonceGroup(nonceGroup);
1102 builder.setNonce(nonce);
1103 return builder.build();
1104 }
1105
1106
1107
1108
1109
1110
1111
1112
1113 public static ModifyColumnRequest buildModifyColumnRequest(
1114 final TableName tableName,
1115 final HColumnDescriptor column,
1116 final long nonceGroup,
1117 final long nonce) {
1118 ModifyColumnRequest.Builder builder = ModifyColumnRequest.newBuilder();
1119 builder.setTableName(ProtobufUtil.toProtoTableName((tableName)));
1120 builder.setColumnFamilies(column.convert());
1121 builder.setNonceGroup(nonceGroup);
1122 builder.setNonce(nonce);
1123 return builder.build();
1124 }
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134 public static MoveRegionRequest buildMoveRegionRequest(
1135 final byte [] encodedRegionName, final byte [] destServerName) throws
1136 DeserializationException {
1137 MoveRegionRequest.Builder builder = MoveRegionRequest.newBuilder();
1138 builder.setRegion(
1139 buildRegionSpecifier(RegionSpecifierType.ENCODED_REGION_NAME,encodedRegionName));
1140 if (destServerName != null) {
1141 builder.setDestServerName(
1142 ProtobufUtil.toServerName(ServerName.valueOf(Bytes.toString(destServerName))));
1143 }
1144 return builder.build();
1145 }
1146
1147 public static DispatchMergingRegionsRequest buildDispatchMergingRegionsRequest(
1148 final byte[] encodedNameOfRegionA, final byte[] encodedNameOfRegionB,
1149 final boolean forcible) throws DeserializationException {
1150 DispatchMergingRegionsRequest.Builder builder = DispatchMergingRegionsRequest.newBuilder();
1151 builder.setRegionA(buildRegionSpecifier(
1152 RegionSpecifierType.ENCODED_REGION_NAME, encodedNameOfRegionA));
1153 builder.setRegionB(buildRegionSpecifier(
1154 RegionSpecifierType.ENCODED_REGION_NAME, encodedNameOfRegionB));
1155 builder.setForcible(forcible);
1156 return builder.build();
1157 }
1158
1159
1160
1161
1162
1163
1164
1165 public static AssignRegionRequest buildAssignRegionRequest(final byte [] regionName) {
1166 AssignRegionRequest.Builder builder = AssignRegionRequest.newBuilder();
1167 builder.setRegion(buildRegionSpecifier(RegionSpecifierType.REGION_NAME,regionName));
1168 return builder.build();
1169 }
1170
1171
1172
1173
1174
1175
1176
1177
1178 public static UnassignRegionRequest buildUnassignRegionRequest(
1179 final byte [] regionName, final boolean force) {
1180 UnassignRegionRequest.Builder builder = UnassignRegionRequest.newBuilder();
1181 builder.setRegion(buildRegionSpecifier(RegionSpecifierType.REGION_NAME,regionName));
1182 builder.setForce(force);
1183 return builder.build();
1184 }
1185
1186
1187
1188
1189
1190
1191
1192 public static OfflineRegionRequest buildOfflineRegionRequest(final byte [] regionName) {
1193 OfflineRegionRequest.Builder builder = OfflineRegionRequest.newBuilder();
1194 builder.setRegion(buildRegionSpecifier(RegionSpecifierType.REGION_NAME,regionName));
1195 return builder.build();
1196 }
1197
1198
1199
1200
1201
1202
1203
1204 public static DeleteTableRequest buildDeleteTableRequest(
1205 final TableName tableName,
1206 final long nonceGroup,
1207 final long nonce) {
1208 DeleteTableRequest.Builder builder = DeleteTableRequest.newBuilder();
1209 builder.setTableName(ProtobufUtil.toProtoTableName(tableName));
1210 builder.setNonceGroup(nonceGroup);
1211 builder.setNonce(nonce);
1212 return builder.build();
1213 }
1214
1215
1216
1217
1218
1219
1220
1221
1222 public static TruncateTableRequest buildTruncateTableRequest(
1223 final TableName tableName,
1224 final boolean preserveSplits,
1225 final long nonceGroup,
1226 final long nonce) {
1227 TruncateTableRequest.Builder builder = TruncateTableRequest.newBuilder();
1228 builder.setTableName(ProtobufUtil.toProtoTableName(tableName));
1229 builder.setPreserveSplits(preserveSplits);
1230 builder.setNonceGroup(nonceGroup);
1231 builder.setNonce(nonce);
1232 return builder.build();
1233 }
1234
1235
1236
1237
1238
1239
1240
1241 public static EnableTableRequest buildEnableTableRequest(
1242 final TableName tableName,
1243 final long nonceGroup,
1244 final long nonce) {
1245 EnableTableRequest.Builder builder = EnableTableRequest.newBuilder();
1246 builder.setTableName(ProtobufUtil.toProtoTableName(tableName));
1247 builder.setNonceGroup(nonceGroup);
1248 builder.setNonce(nonce);
1249 return builder.build();
1250 }
1251
1252
1253
1254
1255
1256
1257
1258 public static DisableTableRequest buildDisableTableRequest(
1259 final TableName tableName,
1260 final long nonceGroup,
1261 final long nonce) {
1262 DisableTableRequest.Builder builder = DisableTableRequest.newBuilder();
1263 builder.setTableName(ProtobufUtil.toProtoTableName((tableName)));
1264 builder.setNonceGroup(nonceGroup);
1265 builder.setNonce(nonce);
1266 return builder.build();
1267 }
1268
1269
1270
1271
1272
1273
1274
1275
1276 public static CreateTableRequest buildCreateTableRequest(
1277 final HTableDescriptor hTableDesc,
1278 final byte [][] splitKeys,
1279 final long nonceGroup,
1280 final long nonce) {
1281 CreateTableRequest.Builder builder = CreateTableRequest.newBuilder();
1282 builder.setTableSchema(hTableDesc.convert());
1283 if (splitKeys != null) {
1284 for (byte [] splitKey : splitKeys) {
1285 builder.addSplitKeys(ByteStringer.wrap(splitKey));
1286 }
1287 }
1288 builder.setNonceGroup(nonceGroup);
1289 builder.setNonce(nonce);
1290 return builder.build();
1291 }
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301 public static ModifyTableRequest buildModifyTableRequest(
1302 final TableName tableName,
1303 final HTableDescriptor hTableDesc,
1304 final long nonceGroup,
1305 final long nonce) {
1306 ModifyTableRequest.Builder builder = ModifyTableRequest.newBuilder();
1307 builder.setTableName(ProtobufUtil.toProtoTableName((tableName)));
1308 builder.setTableSchema(hTableDesc.convert());
1309 builder.setNonceGroup(nonceGroup);
1310 builder.setNonce(nonce);
1311 return builder.build();
1312 }
1313
1314
1315
1316
1317
1318
1319
1320 public static GetSchemaAlterStatusRequest buildGetSchemaAlterStatusRequest(
1321 final TableName tableName) {
1322 GetSchemaAlterStatusRequest.Builder builder = GetSchemaAlterStatusRequest.newBuilder();
1323 builder.setTableName(ProtobufUtil.toProtoTableName((tableName)));
1324 return builder.build();
1325 }
1326
1327
1328
1329
1330
1331
1332
1333 public static GetTableDescriptorsRequest buildGetTableDescriptorsRequest(
1334 final List<TableName> tableNames) {
1335 GetTableDescriptorsRequest.Builder builder = GetTableDescriptorsRequest.newBuilder();
1336 if (tableNames != null) {
1337 for (TableName tableName : tableNames) {
1338 builder.addTableNames(ProtobufUtil.toProtoTableName(tableName));
1339 }
1340 }
1341 return builder.build();
1342 }
1343
1344
1345
1346
1347
1348
1349
1350
1351 public static GetTableDescriptorsRequest buildGetTableDescriptorsRequest(final Pattern pattern,
1352 boolean includeSysTables) {
1353 GetTableDescriptorsRequest.Builder builder = GetTableDescriptorsRequest.newBuilder();
1354 if (pattern != null) builder.setRegex(pattern.toString());
1355 builder.setIncludeSysTables(includeSysTables);
1356 return builder.build();
1357 }
1358
1359
1360
1361
1362
1363
1364
1365
1366 public static GetTableNamesRequest buildGetTableNamesRequest(final Pattern pattern,
1367 boolean includeSysTables) {
1368 GetTableNamesRequest.Builder builder = GetTableNamesRequest.newBuilder();
1369 if (pattern != null) builder.setRegex(pattern.toString());
1370 builder.setIncludeSysTables(includeSysTables);
1371 return builder.build();
1372 }
1373
1374
1375
1376
1377
1378
1379
1380 public static GetTableDescriptorsRequest buildGetTableDescriptorsRequest(
1381 final TableName tableName) {
1382 return GetTableDescriptorsRequest.newBuilder()
1383 .addTableNames(ProtobufUtil.toProtoTableName(tableName))
1384 .build();
1385 }
1386
1387
1388
1389
1390
1391
1392 public static IsMasterRunningRequest buildIsMasterRunningRequest() {
1393 return IsMasterRunningRequest.newBuilder().build();
1394 }
1395
1396
1397
1398
1399
1400
1401 public static BalanceRequest buildBalanceRequest() {
1402 return BalanceRequest.newBuilder().build();
1403 }
1404
1405
1406
1407
1408
1409
1410
1411
1412 public static SetBalancerRunningRequest buildSetBalancerRunningRequest(
1413 boolean on,
1414 boolean synchronous) {
1415 return SetBalancerRunningRequest.newBuilder().setOn(on).setSynchronous(synchronous).build();
1416 }
1417
1418
1419
1420
1421
1422
1423 public static IsBalancerEnabledRequest buildIsBalancerEnabledRequest() {
1424 return IsBalancerEnabledRequest.newBuilder().build();
1425 }
1426
1427
1428
1429
1430 private static final GetClusterStatusRequest GET_CLUSTER_STATUS_REQUEST =
1431 GetClusterStatusRequest.newBuilder().build();
1432
1433
1434
1435
1436
1437
1438 public static GetClusterStatusRequest buildGetClusterStatusRequest() {
1439 return GET_CLUSTER_STATUS_REQUEST;
1440 }
1441
1442
1443
1444
1445 private static final RunCatalogScanRequest CATALOG_SCAN_REQUEST =
1446 RunCatalogScanRequest.newBuilder().build();
1447
1448
1449
1450
1451
1452 public static RunCatalogScanRequest buildCatalogScanRequest() {
1453 return CATALOG_SCAN_REQUEST;
1454 }
1455
1456
1457
1458
1459
1460 public static EnableCatalogJanitorRequest buildEnableCatalogJanitorRequest(boolean enable) {
1461 return EnableCatalogJanitorRequest.newBuilder().setEnable(enable).build();
1462 }
1463
1464
1465
1466
1467 private static final IsCatalogJanitorEnabledRequest IS_CATALOG_JANITOR_ENABLED_REQUEST =
1468 IsCatalogJanitorEnabledRequest.newBuilder().build();
1469
1470
1471
1472
1473
1474 public static IsCatalogJanitorEnabledRequest buildIsCatalogJanitorEnabledRequest() {
1475 return IS_CATALOG_JANITOR_ENABLED_REQUEST;
1476 }
1477
1478
1479
1480
1481
1482
1483 public static GetLastFlushedSequenceIdRequest buildGetLastFlushedSequenceIdRequest(
1484 byte[] regionName) {
1485 return GetLastFlushedSequenceIdRequest.newBuilder().setRegionName(
1486 ByteStringer.wrap(regionName)).build();
1487 }
1488
1489
1490
1491
1492
1493
1494
1495
1496 public static AccessControlProtos.GrantRequest buildGrantRequest(
1497 String username, AccessControlProtos.Permission.Action... actions) {
1498 AccessControlProtos.Permission.Builder ret =
1499 AccessControlProtos.Permission.newBuilder();
1500 AccessControlProtos.GlobalPermission.Builder permissionBuilder =
1501 AccessControlProtos.GlobalPermission.newBuilder();
1502 for (AccessControlProtos.Permission.Action a : actions) {
1503 permissionBuilder.addAction(a);
1504 }
1505 ret.setType(AccessControlProtos.Permission.Type.Global)
1506 .setGlobalPermission(permissionBuilder);
1507 return AccessControlProtos.GrantRequest.newBuilder()
1508 .setUserPermission(
1509 AccessControlProtos.UserPermission.newBuilder()
1510 .setUser(ByteString.copyFromUtf8(username))
1511 .setPermission(ret)
1512 ).build();
1513 }
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525 public static AccessControlProtos.GrantRequest buildGrantRequest(
1526 String username, TableName tableName, byte[] family, byte[] qualifier,
1527 AccessControlProtos.Permission.Action... actions) {
1528 AccessControlProtos.Permission.Builder ret =
1529 AccessControlProtos.Permission.newBuilder();
1530 AccessControlProtos.TablePermission.Builder permissionBuilder =
1531 AccessControlProtos.TablePermission.newBuilder();
1532 for (AccessControlProtos.Permission.Action a : actions) {
1533 permissionBuilder.addAction(a);
1534 }
1535 if (tableName == null) {
1536 throw new NullPointerException("TableName cannot be null");
1537 }
1538 permissionBuilder.setTableName(ProtobufUtil.toProtoTableName(tableName));
1539
1540 if (family != null) {
1541 permissionBuilder.setFamily(ByteStringer.wrap(family));
1542 }
1543 if (qualifier != null) {
1544 permissionBuilder.setQualifier(ByteStringer.wrap(qualifier));
1545 }
1546 ret.setType(AccessControlProtos.Permission.Type.Table)
1547 .setTablePermission(permissionBuilder);
1548 return AccessControlProtos.GrantRequest.newBuilder()
1549 .setUserPermission(
1550 AccessControlProtos.UserPermission.newBuilder()
1551 .setUser(ByteString.copyFromUtf8(username))
1552 .setPermission(ret)
1553 ).build();
1554 }
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564 public static AccessControlProtos.GrantRequest buildGrantRequest(
1565 String username, String namespace,
1566 AccessControlProtos.Permission.Action... actions) {
1567 AccessControlProtos.Permission.Builder ret =
1568 AccessControlProtos.Permission.newBuilder();
1569 AccessControlProtos.NamespacePermission.Builder permissionBuilder =
1570 AccessControlProtos.NamespacePermission.newBuilder();
1571 for (AccessControlProtos.Permission.Action a : actions) {
1572 permissionBuilder.addAction(a);
1573 }
1574 if (namespace != null) {
1575 permissionBuilder.setNamespaceName(ByteString.copyFromUtf8(namespace));
1576 }
1577 ret.setType(AccessControlProtos.Permission.Type.Namespace)
1578 .setNamespacePermission(permissionBuilder);
1579 return AccessControlProtos.GrantRequest.newBuilder()
1580 .setUserPermission(
1581 AccessControlProtos.UserPermission.newBuilder()
1582 .setUser(ByteString.copyFromUtf8(username))
1583 .setPermission(ret)
1584 ).build();
1585 }
1586
1587
1588
1589
1590
1591
1592
1593
1594 public static AccessControlProtos.RevokeRequest buildRevokeRequest(
1595 String username, AccessControlProtos.Permission.Action... actions) {
1596 AccessControlProtos.Permission.Builder ret =
1597 AccessControlProtos.Permission.newBuilder();
1598 AccessControlProtos.GlobalPermission.Builder permissionBuilder =
1599 AccessControlProtos.GlobalPermission.newBuilder();
1600 for (AccessControlProtos.Permission.Action a : actions) {
1601 permissionBuilder.addAction(a);
1602 }
1603 ret.setType(AccessControlProtos.Permission.Type.Global)
1604 .setGlobalPermission(permissionBuilder);
1605 return AccessControlProtos.RevokeRequest.newBuilder()
1606 .setUserPermission(
1607 AccessControlProtos.UserPermission.newBuilder()
1608 .setUser(ByteString.copyFromUtf8(username))
1609 .setPermission(ret)
1610 ).build();
1611 }
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623 public static AccessControlProtos.RevokeRequest buildRevokeRequest(
1624 String username, TableName tableName, byte[] family, byte[] qualifier,
1625 AccessControlProtos.Permission.Action... actions) {
1626 AccessControlProtos.Permission.Builder ret =
1627 AccessControlProtos.Permission.newBuilder();
1628 AccessControlProtos.TablePermission.Builder permissionBuilder =
1629 AccessControlProtos.TablePermission.newBuilder();
1630 for (AccessControlProtos.Permission.Action a : actions) {
1631 permissionBuilder.addAction(a);
1632 }
1633 if (tableName != null) {
1634 permissionBuilder.setTableName(ProtobufUtil.toProtoTableName(tableName));
1635 }
1636 if (family != null) {
1637 permissionBuilder.setFamily(ByteStringer.wrap(family));
1638 }
1639 if (qualifier != null) {
1640 permissionBuilder.setQualifier(ByteStringer.wrap(qualifier));
1641 }
1642 ret.setType(AccessControlProtos.Permission.Type.Table)
1643 .setTablePermission(permissionBuilder);
1644 return AccessControlProtos.RevokeRequest.newBuilder()
1645 .setUserPermission(
1646 AccessControlProtos.UserPermission.newBuilder()
1647 .setUser(ByteString.copyFromUtf8(username))
1648 .setPermission(ret)
1649 ).build();
1650 }
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660 public static AccessControlProtos.RevokeRequest buildRevokeRequest(
1661 String username, String namespace,
1662 AccessControlProtos.Permission.Action... actions) {
1663 AccessControlProtos.Permission.Builder ret =
1664 AccessControlProtos.Permission.newBuilder();
1665 AccessControlProtos.NamespacePermission.Builder permissionBuilder =
1666 AccessControlProtos.NamespacePermission.newBuilder();
1667 for (AccessControlProtos.Permission.Action a : actions) {
1668 permissionBuilder.addAction(a);
1669 }
1670 if (namespace != null) {
1671 permissionBuilder.setNamespaceName(ByteString.copyFromUtf8(namespace));
1672 }
1673 ret.setType(AccessControlProtos.Permission.Type.Namespace)
1674 .setNamespacePermission(permissionBuilder);
1675 return AccessControlProtos.RevokeRequest.newBuilder()
1676 .setUserPermission(
1677 AccessControlProtos.UserPermission.newBuilder()
1678 .setUser(ByteString.copyFromUtf8(username))
1679 .setPermission(ret)
1680 ).build();
1681 }
1682
1683
1684
1685
1686 private static RegionOpenInfo buildRegionOpenInfo(
1687 final HRegionInfo region, final int versionOfOfflineNode,
1688 final List<ServerName> favoredNodes, Boolean openForReplay) {
1689 RegionOpenInfo.Builder builder = RegionOpenInfo.newBuilder();
1690 builder.setRegion(HRegionInfo.convert(region));
1691 if (versionOfOfflineNode >= 0) {
1692 builder.setVersionOfOfflineNode(versionOfOfflineNode);
1693 }
1694 if (favoredNodes != null) {
1695 for (ServerName server : favoredNodes) {
1696 builder.addFavoredNodes(ProtobufUtil.toServerName(server));
1697 }
1698 }
1699 if(openForReplay != null) {
1700 builder.setOpenForDistributedLogReplay(openForReplay);
1701 }
1702 return builder.build();
1703 }
1704
1705
1706
1707
1708
1709
1710 public static NormalizeRequest buildNormalizeRequest() {
1711 return NormalizeRequest.newBuilder().build();
1712 }
1713
1714
1715
1716
1717
1718
1719 public static IsNormalizerEnabledRequest buildIsNormalizerEnabledRequest() {
1720 return IsNormalizerEnabledRequest.newBuilder().build();
1721 }
1722
1723
1724
1725
1726
1727
1728
1729 public static SetNormalizerRunningRequest buildSetNormalizerRunningRequest(boolean on) {
1730 return SetNormalizerRunningRequest.newBuilder().setOn(on).build();
1731 }
1732 }