View Javadoc

1   /**
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
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  * Helper utility to build protocol buffer requests,
119  * or build components for protocol buffer requests.
120  */
121 @InterfaceAudience.Private
122 public final class RequestConverter {
123 
124   private RequestConverter() {
125   }
126 
127 // Start utilities for Client
128 
129 /**
130    * Create a new protocol buffer GetRequest to get a row, all columns in a family.
131    * If there is no such row, return the closest row before it.
132    *
133    * @param regionName the name of the region to get
134    * @param row the row to get
135    * @param family the column family to get
136    * should return the immediate row before
137    * @return a protocol buffer GetReuqest
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    * Create a protocol buffer GetRequest for a client Get
160    *
161    * @param regionName the name of the region to get
162    * @param get the client Get
163    * @return a protocol buffer GetRequest
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    * Create a protocol buffer MutateRequest for a client increment
177    *
178    * @param regionName
179    * @param row
180    * @param family
181    * @param qualifier
182    * @param amount
183    * @param durability
184    * @return a mutate request
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    * Create a protocol buffer MutateRequest for a conditioned put
217    *
218    * @param regionName
219    * @param row
220    * @param family
221    * @param qualifier
222    * @param comparator
223    * @param compareType
224    * @param put
225    * @return a mutate request
226    * @throws IOException
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    * Create a protocol buffer MutateRequest for a conditioned delete
245    *
246    * @param regionName
247    * @param row
248    * @param family
249    * @param qualifier
250    * @param comparator
251    * @param compareType
252    * @param delete
253    * @return a mutate request
254    * @throws IOException
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    * Create a protocol buffer MutateRequest for conditioned row mutations
274    *
275    * @param regionName
276    * @param row
277    * @param family
278    * @param qualifier
279    * @param comparator
280    * @param compareType
281    * @param rowMutations
282    * @return a mutate request
283    * @throws IOException
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    * Create a protocol buffer MutateRequest for a put
320    *
321    * @param regionName
322    * @param put
323    * @return a mutate request
324    * @throws IOException
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    * Create a protocol buffer MutateRequest for an append
338    *
339    * @param regionName
340    * @param append
341    * @return a mutate request
342    * @throws IOException
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    * Create a protocol buffer MutateRequest for a client increment
360    *
361    * @param regionName
362    * @param increment
363    * @return a mutate request
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    * Create a protocol buffer MutateRequest for a delete
380    *
381    * @param regionName
382    * @param delete
383    * @return a mutate request
384    * @throws IOException
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    * Create a protocol buffer MultiRequest for row mutations.
399    * Does not propagate Action absolute position.  Does not set atomic action on the created
400    * RegionAtomic.  Caller should do that if wanted.
401    * @param regionName
402    * @param rowMutations
403    * @return a data-laden RegionMutation.Builder
404    * @throws IOException
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    * Create a protocol buffer MultiRequest for row mutations that does not hold data.  Data/Cells
434    * are carried outside of protobuf.  Return references to the Cells in <code>cells</code> param.
435     * Does not propagate Action absolute position.  Does not set atomic action on the created
436    * RegionAtomic.  Caller should do that if wanted.
437    * @param regionName
438    * @param rowMutations
439    * @param cells Return in here a list of Cells as CellIterable.
440    * @return a region mutation minus data
441    * @throws IOException
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   private 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    * Create a protocol buffer ScanRequest for a client Scan
477    *
478    * @param regionName
479    * @param scan
480    * @param numberOfRows
481    * @param closeScanner
482    * @return a scan request
483    * @throws IOException
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    * Create a protocol buffer ScanRequest for a scanner id
502    *
503    * @param scannerId
504    * @param numberOfRows
505    * @param closeScanner
506    * @return a scan request
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    * Create a protocol buffer ScanRequest for a scanner id
522    *
523    * @param scannerId
524    * @param numberOfRows
525    * @param closeScanner
526    * @param nextCallSeq
527    * @return a scan request
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    * Create a protocol buffer bulk load request
546    *
547    * @param familyPaths
548    * @param regionName
549    * @param assignSeqNum
550    * @return a bulk load request
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    * Create a protocol buffer multi request for a list of actions.
571    * Propagates Actions original index.
572    *
573    * @param regionName
574    * @param actions
575    * @return a multi request
576    * @throws IOException
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    * Create a protocol buffer multirequest with NO data for a list of actions (data is carried
621    * otherwise than via protobuf).  This means it just notes attributes, whether to write the
622    * WAL, etc., and the presence in protobuf serves as place holder for the data which is
623    * coming along otherwise.  Note that Get is different.  It does not contain 'data' and is always
624    * carried by protobuf.  We return references to the data by adding them to the passed in
625    * <code>data</code> param.
626    *
627    * <p>Propagates Actions original index.
628    *
629    * @param regionName
630    * @param actions
631    * @param cells Place to stuff references to actual data.
632    * @return a multi request that does not carry any data.
633    * @throws IOException
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         // Note that a legitimate Delete may have a size of zero; i.e. a Delete that has nothing
659         // in it but the row to delete.  In this case, the current implementation does not make
660         // a KeyValue to represent a delete-of-all-the-row until we serialize... For such cases
661         // where the size returned is zero, we will send the Delete fully pb'd rather than have
662         // metadata only in the pb and then send the kv along the side in cells.
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 // End utilities for Client
698 //Start utilities for Admin
699 
700   /**
701    * Create a protocol buffer GetRegionInfoRequest for a given region name
702    *
703    * @param regionName the name of the region to get info
704    * @return a protocol buffer GetRegionInfoRequest
705    */
706   public static GetRegionInfoRequest
707       buildGetRegionInfoRequest(final byte[] regionName) {
708     return buildGetRegionInfoRequest(regionName, false);
709   }
710 
711   /**
712    * Create a protocol buffer GetRegionInfoRequest for a given region name
713    *
714    * @param regionName the name of the region to get info
715    * @param includeCompactionState indicate if the compaction state is requested
716    * @return a protocol buffer GetRegionInfoRequest
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   * Create a protocol buffer GetStoreFileRequest for a given region name
733   *
734   * @param regionName the name of the region to get info
735   * @param family the family to get store file list
736   * @return a protocol buffer GetStoreFileRequest
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   * Create a protocol buffer GetOnlineRegionRequest
750   *
751   * @return a protocol buffer GetOnlineRegionRequest
752   */
753  public static GetOnlineRegionRequest buildGetOnlineRegionRequest() {
754    return GetOnlineRegionRequest.newBuilder().build();
755  }
756 
757  /**
758   * Create a protocol buffer FlushRegionRequest for a given region name
759   *
760   * @param regionName the name of the region to get info
761   * @return a protocol buffer FlushRegionRequest
762   */
763  public static FlushRegionRequest
764      buildFlushRegionRequest(final byte[] regionName) {
765    return buildFlushRegionRequest(regionName, false);
766  }
767 
768  /**
769   * Create a protocol buffer FlushRegionRequest for a given region name
770   *
771   * @param regionName the name of the region to get info
772   * @return a protocol buffer FlushRegionRequest
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   * Create a protocol buffer OpenRegionRequest to open a list of regions
786   *
787   * @param server the serverName for the RPC
788   * @param regionOpenInfos info of a list of regions to open
789   * @param openForReplay
790   * @return a protocol buffer OpenRegionRequest
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    // send the master's wall clock time as well, so that the RS can refer to it
806    builder.setMasterSystemTime(EnvironmentEdgeManager.currentTime());
807    return builder.build();
808  }
809 
810  /**
811   * Create a protocol buffer OpenRegionRequest for a given region
812   *
813   * @param server the serverName for the RPC
814   * @param region the region to open
815   * @param versionOfOfflineNode that needs to be present in the offline node
816   * @param favoredNodes
817   * @param openForReplay
818   * @return a protocol buffer OpenRegionRequest
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   * Create a protocol buffer UpdateFavoredNodesRequest to update a list of favorednode mappings
835   * @param updateRegionInfos
836   * @return a protocol buffer UpdateFavoredNodesRequest
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   * Create a CloseRegionRequest for a given region name
854   *
855   * @param regionName the name of the region to close
856   * @param transitionInZK indicator if to transition in ZK
857   * @return a CloseRegionRequest
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    *  Create a WarmupRegionRequest for a given region name
892    *
893    *  @param regionInfo Region we are warming up
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   * Create a CloseRegionRequest for a given encoded region name
902   *
903   * @param encodedRegionName the name of the region to close
904   * @param transitionInZK indicator if to transition in ZK
905   * @return a CloseRegionRequest
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   * Create a SplitRegionRequest for a given region name
924   *
925   * @param regionName the name of the region to split
926   * @param splitPoint the split point
927   * @return a SplitRegionRequest
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    * Create a MergeRegionsRequest for the given regions
943    * @param regionA name of region a
944    * @param regionB name of region b
945    * @param forcible true if it is a compulsory merge
946    * @return a MergeRegionsRequest
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     // send the master's wall clock time as well, so that the RS can refer to it
959     builder.setMasterSystemTime(EnvironmentEdgeManager.currentTime());
960     return builder.build();
961   }
962 
963  /**
964   * Create a  CompactRegionRequest for a given region name
965   *
966   * @param regionName the name of the region to get info
967   * @param major indicator if it is a major compaction
968   * @return a CompactRegionRequest
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   * @see {@link #buildRollWALWriterRequest()
985   */
986  private static RollWALWriterRequest ROLL_WAL_WRITER_REQUEST =
987      RollWALWriterRequest.newBuilder().build();
988 
989   /**
990   * Create a new RollWALWriterRequest
991   *
992   * @return a ReplicateWALEntryRequest
993   */
994  public static RollWALWriterRequest buildRollWALWriterRequest() {
995    return ROLL_WAL_WRITER_REQUEST;
996  }
997 
998  /**
999   * @see {@link #buildGetServerInfoRequest()}
1000   */
1001  private static GetServerInfoRequest GET_SERVER_INFO_REQUEST =
1002    GetServerInfoRequest.newBuilder().build();
1003 
1004  /**
1005   * Create a new GetServerInfoRequest
1006   *
1007   * @return a GetServerInfoRequest
1008   */
1009  public static GetServerInfoRequest buildGetServerInfoRequest() {
1010    return GET_SERVER_INFO_REQUEST;
1011  }
1012 
1013  /**
1014   * Create a new StopServerRequest
1015   *
1016   * @param reason the reason to stop the server
1017   * @return a StopServerRequest
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 //End utilities for Admin
1026 
1027   /**
1028    * Convert a byte array to a protocol buffer RegionSpecifier
1029    *
1030    * @param type the region specifier type
1031    * @param value the region specifier byte array value
1032    * @return a protocol buffer RegionSpecifier
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    * Create a protocol buffer Condition
1044    *
1045    * @param row
1046    * @param family
1047    * @param qualifier
1048    * @param comparator
1049    * @param compareType
1050    * @return a Condition
1051    * @throws IOException
1052    */
1053   private 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    * Create a protocol buffer AddColumnRequest
1068    *
1069    * @param tableName
1070    * @param column
1071    * @return an AddColumnRequest
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    * Create a protocol buffer DeleteColumnRequest
1088    *
1089    * @param tableName
1090    * @param columnName
1091    * @return a DeleteColumnRequest
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    * Create a protocol buffer ModifyColumnRequest
1108    *
1109    * @param tableName
1110    * @param column
1111    * @return an ModifyColumnRequest
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    * Create a protocol buffer MoveRegionRequest
1128    *
1129    * @param encodedRegionName
1130    * @param destServerName
1131    * @return A MoveRegionRequest
1132    * @throws DeserializationException
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    * Create a protocol buffer AssignRegionRequest
1161    *
1162    * @param regionName
1163    * @return an AssignRegionRequest
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    * Creates a protocol buffer UnassignRegionRequest
1173    *
1174    * @param regionName
1175    * @param force
1176    * @return an UnassignRegionRequest
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    * Creates a protocol buffer OfflineRegionRequest
1188    *
1189    * @param regionName
1190    * @return an OfflineRegionRequest
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    * Creates a protocol buffer DeleteTableRequest
1200    *
1201    * @param tableName
1202    * @return a DeleteTableRequest
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    * Creates a protocol buffer TruncateTableRequest
1217    *
1218    * @param tableName name of table to truncate
1219    * @param preserveSplits True if the splits should be preserved
1220    * @return a TruncateTableRequest
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    * Creates a protocol buffer EnableTableRequest
1237    *
1238    * @param tableName
1239    * @return an EnableTableRequest
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    * Creates a protocol buffer DisableTableRequest
1254    *
1255    * @param tableName
1256    * @return a DisableTableRequest
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    * Creates a protocol buffer CreateTableRequest
1271    *
1272    * @param hTableDesc
1273    * @param splitKeys
1274    * @return a CreateTableRequest
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    * Creates a protocol buffer ModifyTableRequest
1296    *
1297    * @param tableName
1298    * @param hTableDesc
1299    * @return a ModifyTableRequest
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    * Creates a protocol buffer GetSchemaAlterStatusRequest
1316    *
1317    * @param tableName
1318    * @return a GetSchemaAlterStatusRequest
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    * Creates a protocol buffer GetTableDescriptorsRequest
1329    *
1330    * @param tableNames
1331    * @return a GetTableDescriptorsRequest
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    * Creates a protocol buffer GetTableDescriptorsRequest
1346    *
1347    * @param pattern The compiled regular expression to match against
1348    * @param includeSysTables False to match only against userspace tables
1349    * @return a GetTableDescriptorsRequest
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    * Creates a protocol buffer GetTableNamesRequest
1361    *
1362    * @param pattern The compiled regular expression to match against
1363    * @param includeSysTables False to match only against userspace tables
1364    * @return a GetTableNamesRequest
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    * Creates a protocol buffer GetTableDescriptorsRequest for a single table
1376    *
1377    * @param tableName the table name
1378    * @return a GetTableDescriptorsRequest
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    * Creates a protocol buffer IsMasterRunningRequest
1389    *
1390    * @return a IsMasterRunningRequest
1391    */
1392   public static IsMasterRunningRequest buildIsMasterRunningRequest() {
1393     return IsMasterRunningRequest.newBuilder().build();
1394   }
1395 
1396   /**
1397    * Creates a protocol buffer BalanceRequest
1398    *
1399    * @return a BalanceRequest
1400    */
1401   public static BalanceRequest buildBalanceRequest() {
1402     return BalanceRequest.newBuilder().build();
1403   }
1404 
1405   /**
1406    * Creates a protocol buffer SetBalancerRunningRequest
1407    *
1408    * @param on
1409    * @param synchronous
1410    * @return a SetBalancerRunningRequest
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    * Creates a protocol buffer IsBalancerEnabledRequest
1420    *
1421    * @return a IsBalancerEnabledRequest
1422    */
1423   public static IsBalancerEnabledRequest buildIsBalancerEnabledRequest() {
1424     return IsBalancerEnabledRequest.newBuilder().build();
1425   }
1426 
1427   /**
1428    * @see {@link #buildGetClusterStatusRequest}
1429    */
1430   private static final GetClusterStatusRequest GET_CLUSTER_STATUS_REQUEST =
1431       GetClusterStatusRequest.newBuilder().build();
1432 
1433   /**
1434    * Creates a protocol buffer GetClusterStatusRequest
1435    *
1436    * @return A GetClusterStatusRequest
1437    */
1438   public static GetClusterStatusRequest buildGetClusterStatusRequest() {
1439     return GET_CLUSTER_STATUS_REQUEST;
1440   }
1441 
1442   /**
1443    * @see {@link #buildCatalogScanRequest}
1444    */
1445   private static final RunCatalogScanRequest CATALOG_SCAN_REQUEST =
1446     RunCatalogScanRequest.newBuilder().build();
1447 
1448   /**
1449    * Creates a request for running a catalog scan
1450    * @return A {@link RunCatalogScanRequest}
1451    */
1452   public static RunCatalogScanRequest buildCatalogScanRequest() {
1453     return CATALOG_SCAN_REQUEST;
1454   }
1455 
1456   /**
1457    * Creates a request for enabling/disabling the catalog janitor
1458    * @return A {@link EnableCatalogJanitorRequest}
1459    */
1460   public static EnableCatalogJanitorRequest buildEnableCatalogJanitorRequest(boolean enable) {
1461     return EnableCatalogJanitorRequest.newBuilder().setEnable(enable).build();
1462   }
1463 
1464   /**
1465    * @see {@link #buildIsCatalogJanitorEnabledRequest()}
1466    */
1467   private static final IsCatalogJanitorEnabledRequest IS_CATALOG_JANITOR_ENABLED_REQUEST =
1468     IsCatalogJanitorEnabledRequest.newBuilder().build();
1469 
1470   /**
1471    * Creates a request for querying the master whether the catalog janitor is enabled
1472    * @return A {@link IsCatalogJanitorEnabledRequest}
1473    */
1474   public static IsCatalogJanitorEnabledRequest buildIsCatalogJanitorEnabledRequest() {
1475     return IS_CATALOG_JANITOR_ENABLED_REQUEST;
1476   }
1477 
1478   /**
1479    * Creates a request for querying the master the last flushed sequence Id for a region
1480    * @param regionName
1481    * @return A {@link GetLastFlushedSequenceIdRequest}
1482    */
1483   public static GetLastFlushedSequenceIdRequest buildGetLastFlushedSequenceIdRequest(
1484       byte[] regionName) {
1485     return GetLastFlushedSequenceIdRequest.newBuilder().setRegionName(
1486         ByteStringer.wrap(regionName)).build();
1487   }
1488 
1489   /**
1490    * Create a request to grant user permissions.
1491    *
1492    * @param username the short user name who to grant permissions
1493    * @param actions the permissions to be granted
1494    * @return A {@link AccessControlProtos} GrantRequest
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    * Create a request to grant user permissions.
1517    *
1518    * @param username the short user name who to grant permissions
1519    * @param tableName optional table name the permissions apply
1520    * @param family optional column family
1521    * @param qualifier optional qualifier
1522    * @param actions the permissions to be granted
1523    * @return A {@link AccessControlProtos} GrantRequest
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    * Create a request to grant user permissions.
1558    *
1559    * @param username the short user name who to grant permissions
1560    * @param namespace optional table name the permissions apply
1561    * @param actions the permissions to be granted
1562    * @return A {@link AccessControlProtos} GrantRequest
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    * Create a request to revoke user permissions.
1589    *
1590    * @param username the short user name whose permissions to be revoked
1591    * @param actions the permissions to be revoked
1592    * @return A {@link AccessControlProtos} RevokeRequest
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    * Create a request to revoke user permissions.
1615    *
1616    * @param username the short user name whose permissions to be revoked
1617    * @param tableName optional table name the permissions apply
1618    * @param family optional column family
1619    * @param qualifier optional qualifier
1620    * @param actions the permissions to be revoked
1621    * @return A {@link AccessControlProtos} RevokeRequest
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    * Create a request to revoke user permissions.
1654    *
1655    * @param username the short user name whose permissions to be revoked
1656    * @param namespace optional table name the permissions apply
1657    * @param actions the permissions to be revoked
1658    * @return A {@link AccessControlProtos} RevokeRequest
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    * Create a RegionOpenInfo based on given region info and version of offline node
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    * Creates a protocol buffer NormalizeRequest
1707    *
1708    * @return a NormalizeRequest
1709    */
1710   public static NormalizeRequest buildNormalizeRequest() {
1711     return NormalizeRequest.newBuilder().build();
1712   }
1713 
1714   /**
1715    * Creates a protocol buffer IsNormalizerEnabledRequest
1716    *
1717    * @return a IsNormalizerEnabledRequest
1718    */
1719   public static IsNormalizerEnabledRequest buildIsNormalizerEnabledRequest() {
1720     return IsNormalizerEnabledRequest.newBuilder().build();
1721   }
1722 
1723   /**
1724    * Creates a protocol buffer SetNormalizerRunningRequest
1725    *
1726    * @param on
1727    * @return a SetNormalizerRunningRequest
1728    */
1729   public static SetNormalizerRunningRequest buildSetNormalizerRunningRequest(boolean on) {
1730     return SetNormalizerRunningRequest.newBuilder().setOn(on).build();
1731   }
1732 }