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