001/** 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018package org.apache.hadoop.hbase.hbtop.mode; 019 020import java.util.Arrays; 021import java.util.Collections; 022import java.util.List; 023import java.util.stream.Collectors; 024import java.util.stream.Stream; 025import org.apache.hadoop.hbase.ClusterMetrics; 026import org.apache.hadoop.hbase.hbtop.Record; 027import org.apache.hadoop.hbase.hbtop.RecordFilter; 028import org.apache.hadoop.hbase.hbtop.field.Field; 029import org.apache.hadoop.hbase.hbtop.field.FieldInfo; 030import org.apache.yetus.audience.InterfaceAudience; 031 032 033/** 034 * Implementation for {@link ModeStrategy} for Namespace Mode. 035 */ 036@InterfaceAudience.Private 037public final class NamespaceModeStrategy implements ModeStrategy { 038 039 private final List<FieldInfo> fieldInfos = Arrays.asList( 040 new FieldInfo(Field.NAMESPACE, 0, true), 041 new FieldInfo(Field.REGION_COUNT, 7, true), 042 new FieldInfo(Field.REQUEST_COUNT_PER_SECOND, 10, true), 043 new FieldInfo(Field.READ_REQUEST_COUNT_PER_SECOND, 10, true), 044 new FieldInfo(Field.FILTERED_READ_REQUEST_COUNT_PER_SECOND, 8, true), 045 new FieldInfo(Field.WRITE_REQUEST_COUNT_PER_SECOND, 10, true), 046 new FieldInfo(Field.STORE_FILE_SIZE, 13, true), 047 new FieldInfo(Field.UNCOMPRESSED_STORE_FILE_SIZE, 15, false), 048 new FieldInfo(Field.NUM_STORE_FILES, 7, true), 049 new FieldInfo(Field.MEM_STORE_SIZE, 11, true) 050 ); 051 052 private final RegionModeStrategy regionModeStrategy = new RegionModeStrategy(); 053 054 NamespaceModeStrategy(){ 055 } 056 057 @Override 058 public List<FieldInfo> getFieldInfos() { 059 return fieldInfos; 060 } 061 062 @Override 063 public Field getDefaultSortField() { 064 return Field.REQUEST_COUNT_PER_SECOND; 065 } 066 067 @Override 068 public List<Record> getRecords(ClusterMetrics clusterMetrics) { 069 // Get records from RegionModeStrategy and add REGION_COUNT field 070 List<Record> records = regionModeStrategy.getRecords(clusterMetrics).stream() 071 .map(record -> 072 Record.ofEntries(fieldInfos.stream() 073 .filter(fi -> record.containsKey(fi.getField())) 074 .map(fi -> Record.entry(fi.getField(), record.get(fi.getField()))))) 075 .map(record -> Record.builder().putAll(record).put(Field.REGION_COUNT, 1).build()) 076 .collect(Collectors.toList()); 077 078 // Aggregation by NAMESPACE field 079 return records.stream() 080 .collect(Collectors.groupingBy(r -> r.get(Field.NAMESPACE).asString())) 081 .entrySet().stream() 082 .flatMap( 083 e -> e.getValue().stream() 084 .reduce(Record::combine) 085 .map(Stream::of) 086 .orElse(Stream.empty())) 087 .collect(Collectors.toList()); 088 } 089 090 @Override 091 public DrillDownInfo drillDown(Record selectedRecord) { 092 List<RecordFilter> initialFilters = 093 Collections.singletonList(RecordFilter.newBuilder(Field.NAMESPACE) 094 .doubleEquals(selectedRecord.get(Field.NAMESPACE))); 095 return new DrillDownInfo(Mode.TABLE, initialFilters); 096 } 097}