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;
023
024import org.apache.hadoop.hbase.ClusterMetrics;
025import org.apache.hadoop.hbase.hbtop.Record;
026import org.apache.hadoop.hbase.hbtop.RecordFilter;
027import org.apache.hadoop.hbase.hbtop.field.Field;
028import org.apache.hadoop.hbase.hbtop.field.FieldInfo;
029import org.apache.yetus.audience.InterfaceAudience;
030
031
032/**
033 * Implementation for {@link ModeStrategy} for Namespace Mode.
034 */
035@InterfaceAudience.Private
036public final class NamespaceModeStrategy implements ModeStrategy {
037
038  private final List<FieldInfo> fieldInfos = Arrays.asList(
039    new FieldInfo(Field.NAMESPACE, 0, true),
040    new FieldInfo(Field.REGION_COUNT, 7, true),
041    new FieldInfo(Field.REQUEST_COUNT_PER_SECOND, 10, true),
042    new FieldInfo(Field.READ_REQUEST_COUNT_PER_SECOND, 10, true),
043    new FieldInfo(Field.FILTERED_READ_REQUEST_COUNT_PER_SECOND, 8, true),
044    new FieldInfo(Field.WRITE_REQUEST_COUNT_PER_SECOND, 10, true),
045    new FieldInfo(Field.STORE_FILE_SIZE, 13, true),
046    new FieldInfo(Field.UNCOMPRESSED_STORE_FILE_SIZE, 15, false),
047    new FieldInfo(Field.NUM_STORE_FILES, 7, true),
048    new FieldInfo(Field.MEM_STORE_SIZE, 11, true)
049  );
050
051  private final RegionModeStrategy regionModeStrategy = new RegionModeStrategy();
052
053  NamespaceModeStrategy(){
054  }
055
056  @Override
057  public List<FieldInfo> getFieldInfos() {
058    return fieldInfos;
059  }
060
061  @Override
062  public Field getDefaultSortField() {
063    return Field.REQUEST_COUNT_PER_SECOND;
064  }
065
066  @Override public List<Record> getRecords(ClusterMetrics clusterMetrics,
067      List<RecordFilter> pushDownFilters) {
068    // Get records from RegionModeStrategy and add REGION_COUNT field
069    List<Record> records = regionModeStrategy.selectModeFieldsAndAddCountField(fieldInfos,
070        regionModeStrategy.getRecords(clusterMetrics, pushDownFilters), Field.REGION_COUNT);
071
072    // Aggregation by NAMESPACE field
073    return ModeStrategyUtils.aggregateRecords(records, Field.NAMESPACE);
074  }
075
076  @Override
077  public DrillDownInfo drillDown(Record selectedRecord) {
078    List<RecordFilter> initialFilters =
079      Collections.singletonList(RecordFilter.newBuilder(Field.NAMESPACE)
080        .doubleEquals(selectedRecord.get(Field.NAMESPACE)));
081    return new DrillDownInfo(Mode.TABLE, initialFilters);
082  }
083}