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 * Implementation for {@link ModeStrategy} for User Mode.
033 */
034@InterfaceAudience.Private public final class UserModeStrategy implements ModeStrategy {
035
036  private final List<FieldInfo> fieldInfos = Arrays
037      .asList(new FieldInfo(Field.USER, 0, true),
038          new FieldInfo(Field.CLIENT_COUNT, 7, true),
039          new FieldInfo(Field.REQUEST_COUNT_PER_SECOND, 10, true),
040          new FieldInfo(Field.READ_REQUEST_COUNT_PER_SECOND, 10, true),
041          new FieldInfo(Field.WRITE_REQUEST_COUNT_PER_SECOND, 10, true),
042          new FieldInfo(Field.FILTERED_READ_REQUEST_COUNT_PER_SECOND, 10, true));
043  private final ClientModeStrategy clientModeStrategy = new ClientModeStrategy();
044
045  UserModeStrategy() {
046  }
047
048  @Override public List<FieldInfo> getFieldInfos() {
049    return fieldInfos;
050  }
051
052  @Override public Field getDefaultSortField() {
053    return Field.REQUEST_COUNT_PER_SECOND;
054  }
055
056  @Override public List<Record> getRecords(ClusterMetrics clusterMetrics,
057      List<RecordFilter> pushDownFilters) {
058    List<Record> records = clientModeStrategy.createRecords(clusterMetrics);
059    return clientModeStrategy.aggregateRecordsAndAddDistinct(
060        ModeStrategyUtils.applyFilterAndGet(records, pushDownFilters), Field.USER, Field.CLIENT,
061        Field.CLIENT_COUNT);
062  }
063
064  @Override public DrillDownInfo drillDown(Record selectedRecord) {
065    //Drill down to client and using selected USER as a filter
066    List<RecordFilter> initialFilters = Collections.singletonList(
067        RecordFilter.newBuilder(Field.USER).doubleEquals(selectedRecord.get(Field.USER)));
068    return new DrillDownInfo(Mode.CLIENT, initialFilters);
069  }
070}