View Javadoc

1   /*
2    *
3    * Licensed to the Apache Software Foundation (ASF) under one
4    * or more contributor license agreements.  See the NOTICE file
5    * distributed with this work for additional information
6    * regarding copyright ownership.  The ASF licenses this file
7    * to you under the Apache License, Version 2.0 (the
8    * "License"); you may not use this file except in compliance
9    * with the License.  You may obtain a copy of the License at
10   *
11   *     http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing, software
14   * distributed under the License is distributed on an "AS IS" BASIS,
15   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   * See the License for the specific language governing permissions and
17   * limitations under the License.
18   */
19  
20  package org.apache.hadoop.hbase.rest.model;
21  
22  import com.fasterxml.jackson.annotation.JsonProperty;
23  
24  import java.io.IOException;
25  import java.io.Serializable;
26  import java.util.ArrayList;
27  import java.util.List;
28  
29  import javax.xml.bind.annotation.XmlAttribute;
30  import javax.xml.bind.annotation.XmlElement;
31  import javax.xml.bind.annotation.XmlElementWrapper;
32  import javax.xml.bind.annotation.XmlRootElement;
33  
34  import org.apache.hadoop.hbase.util.ByteStringer;
35  import org.apache.hadoop.hbase.classification.InterfaceAudience;
36  import org.apache.hadoop.hbase.protobuf.ProtobufUtil;
37  import org.apache.hadoop.hbase.rest.ProtobufMessageHandler;
38  import org.apache.hadoop.hbase.rest.protobuf.generated.StorageClusterStatusMessage.StorageClusterStatus;
39  import org.apache.hadoop.hbase.util.Bytes;
40  
41  /**
42   * Representation of the status of a storage cluster:
43   * <p>
44   * <ul>
45   * <li>regions: the total number of regions served by the cluster</li>
46   * <li>requests: the total number of requests per second handled by the
47   * cluster in the last reporting interval</li>
48   * <li>averageLoad: the average load of the region servers in the cluster</li>
49   * <li>liveNodes: detailed status of the live region servers</li>
50   * <li>deadNodes: the names of region servers declared dead</li>
51   * </ul>
52   *
53   * <pre>
54   * &lt;complexType name="StorageClusterStatus"&gt;
55   *   &lt;sequence&gt;
56   *     &lt;element name="liveNode" type="tns:Node"
57   *       maxOccurs="unbounded" minOccurs="0"&gt;
58   *     &lt;/element&gt;
59   *     &lt;element name="deadNode" type="string" maxOccurs="unbounded"
60   *       minOccurs="0"&gt;
61   *     &lt;/element&gt;
62   *   &lt;/sequence&gt;
63   *   &lt;attribute name="regions" type="int"&gt;&lt;/attribute&gt;
64   *   &lt;attribute name="requests" type="int"&gt;&lt;/attribute&gt;
65   *   &lt;attribute name="averageLoad" type="float"&gt;&lt;/attribute&gt;
66   * &lt;/complexType&gt;
67   *
68   * &lt;complexType name="Node"&gt;
69   *   &lt;sequence&gt;
70   *     &lt;element name="region" type="tns:Region"
71   *       maxOccurs="unbounded" minOccurs="0"&gt;&lt;/element&gt;
72   *   &lt;/sequence&gt;
73   *   &lt;attribute name="name" type="string"&gt;&lt;/attribute&gt;
74   *   &lt;attribute name="startCode" type="int"&gt;&lt;/attribute&gt;
75   *   &lt;attribute name="requests" type="int"&gt;&lt;/attribute&gt;
76   *   &lt;attribute name="heapSizeMB" type="int"&gt;&lt;/attribute&gt;
77   *   &lt;attribute name="maxHeapSizeMB" type="int"&gt;&lt;/attribute&gt;
78   * &lt;/complexType&gt;
79   *
80   * &lt;complexType name="Region"&gt;
81   *   &lt;attribute name="name" type="base64Binary"&gt;&lt;/attribute&gt;
82   *   &lt;attribute name="stores" type="int"&gt;&lt;/attribute&gt;
83   *   &lt;attribute name="storefiles" type="int"&gt;&lt;/attribute&gt;
84   *   &lt;attribute name="storefileSizeMB" type="int"&gt;&lt;/attribute&gt;
85   *   &lt;attribute name="memstoreSizeMB" type="int"&gt;&lt;/attribute&gt;
86   *   &lt;attribute name="storefileIndexSizeMB" type="int"&gt;&lt;/attribute&gt;
87   *   &lt;attribute name="readRequestsCount" type="int"&gt;&lt;/attribute&gt;
88   *   &lt;attribute name="writeRequestsCount" type="int"&gt;&lt;/attribute&gt;
89   *   &lt;attribute name="rootIndexSizeKB" type="int"&gt;&lt;/attribute&gt;
90   *   &lt;attribute name="totalStaticIndexSizeKB" type="int"&gt;&lt;/attribute&gt;
91   *   &lt;attribute name="totalStaticBloomSizeKB" type="int"&gt;&lt;/attribute&gt;
92   *   &lt;attribute name="totalCompactingKVs" type="int"&gt;&lt;/attribute&gt;
93   *   &lt;attribute name="currentCompactedKVs" type="int"&gt;&lt;/attribute&gt;
94   * &lt;/complexType&gt;
95   * </pre>
96   */
97  @XmlRootElement(name="ClusterStatus")
98  @InterfaceAudience.Private
99  public class StorageClusterStatusModel
100     implements Serializable, ProtobufMessageHandler {
101   private static final long serialVersionUID = 1L;
102 
103   /**
104    * Represents a region server.
105    */
106   public static class Node implements Serializable {
107     private static final long serialVersionUID = 1L;
108 
109     /**
110      * Represents a region hosted on a region server.
111      */
112     public static class Region implements Serializable {
113       private static final long serialVersionUID = -1326683840086398193L;
114       private byte[] name;
115       private int stores;
116       private int storefiles;
117       private int storefileSizeMB;
118       private int memstoreSizeMB;
119       private int storefileIndexSizeMB;
120       private long readRequestsCount;
121       private long writeRequestsCount;
122       private int rootIndexSizeKB;
123       private int totalStaticIndexSizeKB;
124       private int totalStaticBloomSizeKB;
125       private long totalCompactingKVs;
126       private long currentCompactedKVs;
127 
128       /**
129        * Default constructor
130        */
131       public Region() {
132       }
133 
134       /**
135        * Constructor
136        * @param name the region name
137        */
138       public Region(byte[] name) {
139         this.name = name;
140       }
141 
142       /**
143        * Constructor
144        * @param name the region name
145        * @param stores the number of stores
146        * @param storefiles the number of store files
147        * @param storefileSizeMB total size of store files, in MB
148        * @param memstoreSizeMB total size of memstore, in MB
149        * @param storefileIndexSizeMB total size of store file indexes, in MB
150        */
151       public Region(byte[] name, int stores, int storefiles,
152           int storefileSizeMB, int memstoreSizeMB, int storefileIndexSizeMB,
153           long readRequestsCount, long writeRequestsCount, int rootIndexSizeKB,
154           int totalStaticIndexSizeKB, int totalStaticBloomSizeKB,
155           long totalCompactingKVs, long currentCompactedKVs) {
156         this.name = name;
157         this.stores = stores;
158         this.storefiles = storefiles;
159         this.storefileSizeMB = storefileSizeMB;
160         this.memstoreSizeMB = memstoreSizeMB;
161         this.storefileIndexSizeMB = storefileIndexSizeMB;
162         this.readRequestsCount = readRequestsCount;
163         this.writeRequestsCount = writeRequestsCount;
164         this.rootIndexSizeKB = rootIndexSizeKB;
165         this.totalStaticIndexSizeKB = totalStaticIndexSizeKB;
166         this.totalStaticBloomSizeKB = totalStaticBloomSizeKB;
167         this.totalCompactingKVs = totalCompactingKVs;
168         this.currentCompactedKVs = currentCompactedKVs;
169       }
170 
171       /**
172        * @return the region name
173        */
174       @XmlAttribute
175       public byte[] getName() {
176         return name;
177       }
178 
179       /**
180        * @return the number of stores
181        */
182       @XmlAttribute
183       public int getStores() {
184         return stores;
185       }
186 
187       /**
188        * @return the number of store files
189        */
190       @XmlAttribute
191       public int getStorefiles() {
192         return storefiles;
193       }
194 
195       /**
196        * @return the total size of store files, in MB
197        */
198       @XmlAttribute
199       public int getStorefileSizeMB() {
200         return storefileSizeMB;
201       }
202 
203       /**
204        * @return memstore size, in MB
205        */
206       @XmlAttribute
207       public int getMemstoreSizeMB() {
208         return memstoreSizeMB;
209       }
210 
211       /**
212        * @return the total size of store file indexes, in MB
213        */
214       @XmlAttribute
215       public int getStorefileIndexSizeMB() {
216         return storefileIndexSizeMB;
217       }
218 
219       /**
220        * @return the current total read requests made to region
221        */
222       @XmlAttribute
223       public long getReadRequestsCount() {
224         return readRequestsCount;
225       }
226 
227       /**
228        * @return the current total write requests made to region
229        */
230       @XmlAttribute
231       public long getWriteRequestsCount() {
232         return writeRequestsCount;
233       }
234 
235       /**
236        * @return The current total size of root-level indexes for the region, in KB.
237        */
238       @XmlAttribute
239       public int getRootIndexSizeKB() {
240         return rootIndexSizeKB;
241       }
242 
243       /**
244        * @return The total size of static index, in KB
245        */
246       @XmlAttribute
247       public int getTotalStaticIndexSizeKB() {
248         return totalStaticIndexSizeKB;
249       }
250 
251       /**
252        * @return The total size of static bloom, in KB
253        */
254       @XmlAttribute
255       public int getTotalStaticBloomSizeKB() {
256         return totalStaticBloomSizeKB;
257       }
258 
259       /**
260        * @return The total number of compacting key-values
261        */
262       @XmlAttribute
263       public long getTotalCompactingKVs() {
264         return totalCompactingKVs;
265       }
266 
267       /**
268        * @return The number of current compacted key-values
269        */
270       @XmlAttribute
271       public long getCurrentCompactedKVs() {
272         return currentCompactedKVs;
273       }
274 
275       /**
276        * @param readRequestsCount The current total read requests made to region
277        */
278       public void setReadRequestsCount(long readRequestsCount) {
279         this.readRequestsCount = readRequestsCount;
280       }
281 
282       /**
283        * @param rootIndexSizeKB The current total size of root-level indexes
284        *                        for the region, in KB
285        */
286       public void setRootIndexSizeKB(int rootIndexSizeKB) {
287         this.rootIndexSizeKB = rootIndexSizeKB;
288       }
289 
290       /**
291        * @param writeRequestsCount The current total write requests made to region
292        */
293       public void setWriteRequestsCount(long writeRequestsCount) {
294         this.writeRequestsCount = writeRequestsCount;
295       }
296 
297       /**
298        * @param currentCompactedKVs The completed count of key values
299        *                            in currently running compaction
300        */
301       public void setCurrentCompactedKVs(long currentCompactedKVs) {
302         this.currentCompactedKVs = currentCompactedKVs;
303       }
304 
305       /**
306        * @param totalCompactingKVs The total compacting key values
307        *                           in currently running compaction
308        */
309       public void setTotalCompactingKVs(long totalCompactingKVs) {
310         this.totalCompactingKVs = totalCompactingKVs;
311       }
312 
313       /**
314        * @param totalStaticBloomSizeKB The total size of all Bloom filter blocks,
315        *                               not just loaded into the block cache, in KB.
316        */
317       public void setTotalStaticBloomSizeKB(int totalStaticBloomSizeKB) {
318         this.totalStaticBloomSizeKB = totalStaticBloomSizeKB;
319       }
320 
321       /**
322        * @param totalStaticIndexSizeKB The total size of all index blocks,
323        *                               not just the root level, in KB.
324        */
325       public void setTotalStaticIndexSizeKB(int totalStaticIndexSizeKB) {
326         this.totalStaticIndexSizeKB = totalStaticIndexSizeKB;
327       }
328 
329       /**
330        * @param name the region name
331        */
332       public void setName(byte[] name) {
333         this.name = name;
334       }
335 
336       /**
337        * @param stores the number of stores
338        */
339       public void setStores(int stores) {
340         this.stores = stores;
341       }
342 
343       /**
344        * @param storefiles the number of store files
345        */
346       public void setStorefiles(int storefiles) {
347         this.storefiles = storefiles;
348       }
349 
350       /**
351        * @param storefileSizeMB total size of store files, in MB
352        */
353       public void setStorefileSizeMB(int storefileSizeMB) {
354         this.storefileSizeMB = storefileSizeMB;
355       }
356 
357       /**
358        * @param memstoreSizeMB memstore size, in MB
359        */
360       public void setMemstoreSizeMB(int memstoreSizeMB) {
361         this.memstoreSizeMB = memstoreSizeMB;
362       }
363 
364       /**
365        * @param storefileIndexSizeMB total size of store file indexes, in MB
366        */
367       public void setStorefileIndexSizeMB(int storefileIndexSizeMB) {
368         this.storefileIndexSizeMB = storefileIndexSizeMB;
369       }
370     }
371 
372     private String name;
373     private long startCode;
374     private long requests;
375     private int heapSizeMB;
376     private int maxHeapSizeMB;
377     private List<Region> regions = new ArrayList<Region>();
378 
379     /**
380      * Add a region name to the list
381      * @param name the region name
382      */
383     public void addRegion(byte[] name, int stores, int storefiles,
384         int storefileSizeMB, int memstoreSizeMB, int storefileIndexSizeMB,
385         long readRequestsCount, long writeRequestsCount, int rootIndexSizeKB,
386         int totalStaticIndexSizeKB, int totalStaticBloomSizeKB,
387         long totalCompactingKVs, long currentCompactedKVs) {
388       regions.add(new Region(name, stores, storefiles, storefileSizeMB,
389         memstoreSizeMB, storefileIndexSizeMB, readRequestsCount,
390         writeRequestsCount, rootIndexSizeKB, totalStaticIndexSizeKB,
391         totalStaticBloomSizeKB, totalCompactingKVs, currentCompactedKVs));
392     }
393 
394     /**
395      * @param index the index
396      * @return the region name
397      */
398     public Region getRegion(int index) {
399       return regions.get(index);
400     }
401 
402     /**
403      * Default constructor
404      */
405     public Node() {}
406 
407     /**
408      * Constructor
409      * @param name the region server name
410      * @param startCode the region server's start code
411      */
412     public Node(String name, long startCode) {
413       this.name = name;
414       this.startCode = startCode;
415     }
416 
417     /**
418      * @return the region server's name
419      */
420     @XmlAttribute
421     public String getName() {
422       return name;
423     }
424 
425     /**
426      * @return the region server's start code
427      */
428     @XmlAttribute
429     public long getStartCode() {
430       return startCode;
431     }
432 
433     /**
434      * @return the current heap size, in MB
435      */
436     @XmlAttribute
437     public int getHeapSizeMB() {
438       return heapSizeMB;
439     }
440 
441     /**
442      * @return the maximum heap size, in MB
443      */
444     @XmlAttribute
445     public int getMaxHeapSizeMB() {
446       return maxHeapSizeMB;
447     }
448 
449     /**
450      * @return the list of regions served by the region server
451      */
452     @XmlElement(name="Region")
453     public List<Region> getRegions() {
454       return regions;
455     }
456 
457     /**
458      * @return the number of requests per second processed by the region server
459      */
460     @XmlAttribute
461     public long getRequests() {
462       return requests;
463     }
464 
465     /**
466      * @param name the region server's hostname
467      */
468     public void setName(String name) {
469       this.name = name;
470     }
471 
472     /**
473      * @param startCode the region server's start code
474      */
475     public void setStartCode(long startCode) {
476       this.startCode = startCode;
477     }
478 
479     /**
480      * @param heapSizeMB the current heap size, in MB
481      */
482     public void setHeapSizeMB(int heapSizeMB) {
483       this.heapSizeMB = heapSizeMB;
484     }
485 
486     /**
487      * @param maxHeapSizeMB the maximum heap size, in MB
488      */
489     public void setMaxHeapSizeMB(int maxHeapSizeMB) {
490       this.maxHeapSizeMB = maxHeapSizeMB;
491     }
492 
493     /**
494      * @param regions a list of regions served by the region server
495      */
496     public void setRegions(List<Region> regions) {
497       this.regions = regions;
498     }
499 
500     /**
501      * @param requests the number of requests per second processed by the
502      * region server
503      */
504     public void setRequests(long requests) {
505       this.requests = requests;
506     }
507   }
508 
509   private List<Node> liveNodes = new ArrayList<Node>();
510   private List<String> deadNodes = new ArrayList<String>();
511   private int regions;
512   private long requests;
513   private double averageLoad;
514 
515   /**
516    * Add a live node to the cluster representation.
517    * @param name the region server name
518    * @param startCode the region server's start code
519    * @param heapSizeMB the current heap size, in MB
520    * @param maxHeapSizeMB the maximum heap size, in MB
521    */
522   public Node addLiveNode(String name, long startCode, int heapSizeMB, int maxHeapSizeMB) {
523     Node node = new Node(name, startCode);
524     node.setHeapSizeMB(heapSizeMB);
525     node.setMaxHeapSizeMB(maxHeapSizeMB);
526     liveNodes.add(node);
527     return node;
528   }
529 
530   /**
531    * @param index the index
532    * @return the region server model
533    */
534   public Node getLiveNode(int index) {
535     return liveNodes.get(index);
536   }
537 
538   /**
539    * Add a dead node to the cluster representation.
540    * @param node the dead region server's name
541    */
542   public void addDeadNode(String node) {
543     deadNodes.add(node);
544   }
545 
546   /**
547    * @param index the index
548    * @return the dead region server's name
549    */
550   public String getDeadNode(int index) {
551     return deadNodes.get(index);
552   }
553 
554   /**
555    * Default constructor
556    */
557   public StorageClusterStatusModel() {
558   }
559 
560   /**
561    * @return the list of live nodes
562    */
563   @XmlElement(name = "Node")
564   @XmlElementWrapper(name = "LiveNodes")
565   // workaround https://github.com/FasterXML/jackson-dataformat-xml/issues/192
566   @JsonProperty("LiveNodes")
567   public List<Node> getLiveNodes() {
568     return liveNodes;
569   }
570 
571   /**
572    * @return the list of dead nodes
573    */
574   @XmlElement(name = "Node")
575   @XmlElementWrapper(name = "DeadNodes")
576   // workaround https://github.com/FasterXML/jackson-dataformat-xml/issues/192
577   @JsonProperty("DeadNodes")
578   public List<String> getDeadNodes() {
579     return deadNodes;
580   }
581 
582   /**
583    * @return the total number of regions served by the cluster
584    */
585   @XmlAttribute
586   public int getRegions() {
587     return regions;
588   }
589 
590   /**
591    * @return the total number of requests per second handled by the cluster in
592    * the last reporting interval
593    */
594   @XmlAttribute
595   public long getRequests() {
596     return requests;
597   }
598 
599   /**
600    * @return the average load of the region servers in the cluster
601    */
602   @XmlAttribute
603   public double getAverageLoad() {
604     return averageLoad;
605   }
606 
607   /**
608    * @param nodes the list of live node models
609    */
610   public void setLiveNodes(List<Node> nodes) {
611     this.liveNodes = nodes;
612   }
613 
614   /**
615    * @param nodes the list of dead node names
616    */
617   public void setDeadNodes(List<String> nodes) {
618     this.deadNodes = nodes;
619   }
620 
621   /**
622    * @param regions the total number of regions served by the cluster
623    */
624   public void setRegions(int regions) {
625     this.regions = regions;
626   }
627 
628   /**
629    * @param requests the total number of requests per second handled by the
630    * cluster
631    */
632   public void setRequests(int requests) {
633     this.requests = requests;
634   }
635 
636   /**
637    * @param averageLoad the average load of region servers in the cluster
638    */
639   public void setAverageLoad(double averageLoad) {
640     this.averageLoad = averageLoad;
641   }
642 
643   /*
644    * (non-Javadoc)
645    * @see java.lang.Object#toString()
646    */
647   @Override
648   public String toString() {
649     StringBuilder sb = new StringBuilder();
650     sb.append(String.format("%d live servers, %d dead servers, " +
651       "%.4f average load%n%n", liveNodes.size(), deadNodes.size(),
652       averageLoad));
653     if (!liveNodes.isEmpty()) {
654       sb.append(liveNodes.size());
655       sb.append(" live servers\n");
656       for (Node node: liveNodes) {
657         sb.append("    ");
658         sb.append(node.name);
659         sb.append(' ');
660         sb.append(node.startCode);
661         sb.append("\n        requests=");
662         sb.append(node.requests);
663         sb.append(", regions=");
664         sb.append(node.regions.size());
665         sb.append("\n        heapSizeMB=");
666         sb.append(node.heapSizeMB);
667         sb.append("\n        maxHeapSizeMB=");
668         sb.append(node.maxHeapSizeMB);
669         sb.append("\n\n");
670         for (Node.Region region: node.regions) {
671           sb.append("        ");
672           sb.append(Bytes.toString(region.name));
673           sb.append("\n            stores=");
674           sb.append(region.stores);
675           sb.append("\n            storefiless=");
676           sb.append(region.storefiles);
677           sb.append("\n            storefileSizeMB=");
678           sb.append(region.storefileSizeMB);
679           sb.append("\n            memstoreSizeMB=");
680           sb.append(region.memstoreSizeMB);
681           sb.append("\n            storefileIndexSizeMB=");
682           sb.append(region.storefileIndexSizeMB);
683           sb.append("\n            readRequestsCount=");
684           sb.append(region.readRequestsCount);
685           sb.append("\n            writeRequestsCount=");
686           sb.append(region.writeRequestsCount);
687           sb.append("\n            rootIndexSizeKB=");
688           sb.append(region.rootIndexSizeKB);
689           sb.append("\n            totalStaticIndexSizeKB=");
690           sb.append(region.totalStaticIndexSizeKB);
691           sb.append("\n            totalStaticBloomSizeKB=");
692           sb.append(region.totalStaticBloomSizeKB);
693           sb.append("\n            totalCompactingKVs=");
694           sb.append(region.totalCompactingKVs);
695           sb.append("\n            currentCompactedKVs=");
696           sb.append(region.currentCompactedKVs);
697           sb.append('\n');
698         }
699         sb.append('\n');
700       }
701     }
702     if (!deadNodes.isEmpty()) {
703       sb.append('\n');
704       sb.append(deadNodes.size());
705       sb.append(" dead servers\n");
706       for (String node: deadNodes) {
707         sb.append("    ");
708         sb.append(node);
709         sb.append('\n');
710       }
711     }
712     return sb.toString();
713   }
714 
715   @Override
716   public byte[] createProtobufOutput() {
717     StorageClusterStatus.Builder builder = StorageClusterStatus.newBuilder();
718     builder.setRegions(regions);
719     builder.setRequests(requests);
720     builder.setAverageLoad(averageLoad);
721     for (Node node: liveNodes) {
722       StorageClusterStatus.Node.Builder nodeBuilder =
723         StorageClusterStatus.Node.newBuilder();
724       nodeBuilder.setName(node.name);
725       nodeBuilder.setStartCode(node.startCode);
726       nodeBuilder.setRequests(node.requests);
727       nodeBuilder.setHeapSizeMB(node.heapSizeMB);
728       nodeBuilder.setMaxHeapSizeMB(node.maxHeapSizeMB);
729       for (Node.Region region: node.regions) {
730         StorageClusterStatus.Region.Builder regionBuilder =
731           StorageClusterStatus.Region.newBuilder();
732         regionBuilder.setName(ByteStringer.wrap(region.name));
733         regionBuilder.setStores(region.stores);
734         regionBuilder.setStorefiles(region.storefiles);
735         regionBuilder.setStorefileSizeMB(region.storefileSizeMB);
736         regionBuilder.setMemstoreSizeMB(region.memstoreSizeMB);
737         regionBuilder.setStorefileIndexSizeMB(region.storefileIndexSizeMB);
738         regionBuilder.setReadRequestsCount(region.readRequestsCount);
739         regionBuilder.setWriteRequestsCount(region.writeRequestsCount);
740         regionBuilder.setRootIndexSizeKB(region.rootIndexSizeKB);
741         regionBuilder.setTotalStaticIndexSizeKB(region.totalStaticIndexSizeKB);
742         regionBuilder.setTotalStaticBloomSizeKB(region.totalStaticBloomSizeKB);
743         regionBuilder.setTotalCompactingKVs(region.totalCompactingKVs);
744         regionBuilder.setCurrentCompactedKVs(region.currentCompactedKVs);
745         nodeBuilder.addRegions(regionBuilder);
746       }
747       builder.addLiveNodes(nodeBuilder);
748     }
749     for (String node: deadNodes) {
750       builder.addDeadNodes(node);
751     }
752     return builder.build().toByteArray();
753   }
754 
755   @Override
756   public ProtobufMessageHandler getObjectFromMessage(byte[] message)
757       throws IOException {
758     StorageClusterStatus.Builder builder = StorageClusterStatus.newBuilder();
759     ProtobufUtil.mergeFrom(builder, message);
760     if (builder.hasRegions()) {
761       regions = builder.getRegions();
762     }
763     if (builder.hasRequests()) {
764       requests = builder.getRequests();
765     }
766     if (builder.hasAverageLoad()) {
767       averageLoad = builder.getAverageLoad();
768     }
769     for (StorageClusterStatus.Node node: builder.getLiveNodesList()) {
770       long startCode = node.hasStartCode() ? node.getStartCode() : -1;
771       StorageClusterStatusModel.Node nodeModel =
772         addLiveNode(node.getName(), startCode, node.getHeapSizeMB(),
773           node.getMaxHeapSizeMB());
774       long requests = node.hasRequests() ? node.getRequests() : 0;
775       nodeModel.setRequests(requests);
776       for (StorageClusterStatus.Region region: node.getRegionsList()) {
777         nodeModel.addRegion(
778           region.getName().toByteArray(),
779           region.getStores(),
780           region.getStorefiles(),
781           region.getStorefileSizeMB(),
782           region.getMemstoreSizeMB(),
783           region.getStorefileIndexSizeMB(),
784           region.getReadRequestsCount(),
785           region.getWriteRequestsCount(),
786           region.getRootIndexSizeKB(),
787           region.getTotalStaticIndexSizeKB(),
788           region.getTotalStaticBloomSizeKB(),
789           region.getTotalCompactingKVs(),
790           region.getCurrentCompactedKVs());
791       }
792     }
793     for (String node: builder.getDeadNodesList()) {
794       addDeadNode(node);
795     }
796     return this;
797   }
798 }