Search in sources :

Example 1 with FieldInfo

use of org.apache.hadoop.hbase.hbtop.field.FieldInfo in project hbase by apache.

the class TestTopScreenPresenter method setup.

@Before
public void setup() {
    when(topScreenView.getTerminalSize()).thenReturn(new TerminalSize(100, 100));
    when(topScreenView.getPageSize()).thenReturn(100);
    when(topScreenModel.getFieldInfos()).thenReturn(TEST_FIELD_INFOS);
    when(topScreenModel.getFields()).thenReturn(TEST_FIELD_INFOS.stream().map(FieldInfo::getField).collect(Collectors.toList()));
    when(topScreenModel.getRecords()).thenReturn(TEST_RECORDS);
    when(topScreenModel.getSummary()).thenReturn(TEST_SUMMARY);
    topScreenPresenter = new TopScreenPresenter(topScreenView, 3000, topScreenModel, null, Long.MAX_VALUE);
}
Also used : TerminalSize(org.apache.hadoop.hbase.hbtop.terminal.TerminalSize) FieldInfo(org.apache.hadoop.hbase.hbtop.field.FieldInfo) Before(org.junit.Before)

Example 2 with FieldInfo

use of org.apache.hadoop.hbase.hbtop.field.FieldInfo in project hbase by apache.

the class HBTop method run.

@Override
public int run(String[] args) throws Exception {
    long initialRefreshDelay = 3 * 1000;
    Mode initialMode = Mode.REGION;
    List<Field> initialFields = null;
    Field initialSortField = null;
    Boolean initialAscendingSort = null;
    List<RecordFilter> initialFilters = null;
    long numberOfIterations = Long.MAX_VALUE;
    boolean batchMode = false;
    try {
        Options opts = getOptions();
        CommandLine commandLine = new DefaultParser().parse(opts, args);
        if (commandLine.hasOption("help")) {
            printUsage(opts);
            return 0;
        }
        if (commandLine.hasOption("mode")) {
            String mode = commandLine.getOptionValue("mode");
            switch(mode) {
                case "n":
                    initialMode = Mode.NAMESPACE;
                    break;
                case "t":
                    initialMode = Mode.TABLE;
                    break;
                case "r":
                    initialMode = Mode.REGION;
                    break;
                case "s":
                    initialMode = Mode.REGION_SERVER;
                    break;
                case "u":
                    initialMode = Mode.USER;
                    break;
                case "c":
                    initialMode = Mode.CLIENT;
                    break;
                default:
                    LOGGER.warn("Mode set invalid, using default");
                    break;
            }
        }
        if (commandLine.hasOption("outputFieldNames")) {
            initialMode.getFieldInfos().forEach(f -> System.out.println(f.getField().getHeader()));
            return 0;
        }
        if (commandLine.hasOption("delay")) {
            int delay = 0;
            try {
                delay = Integer.parseInt(commandLine.getOptionValue("delay"));
            } catch (NumberFormatException ignored) {
            }
            if (delay < 1) {
                LOGGER.warn("Delay set too low or invalid, using default");
            } else {
                initialRefreshDelay = delay * 1000L;
            }
        }
        if (commandLine.hasOption("numberOfIterations")) {
            try {
                numberOfIterations = Long.parseLong(commandLine.getOptionValue("numberOfIterations"));
            } catch (NumberFormatException ignored) {
                LOGGER.warn("The number of iterations set invalid, ignoring");
            }
        }
        if (commandLine.hasOption("sortField")) {
            String sortField = commandLine.getOptionValue("sortField");
            String field;
            boolean ascendingSort;
            if (sortField.startsWith("+")) {
                field = sortField.substring(1);
                ascendingSort = false;
            } else if (sortField.startsWith("-")) {
                field = sortField.substring(1);
                ascendingSort = true;
            } else {
                field = sortField;
                ascendingSort = false;
            }
            Optional<FieldInfo> fieldInfo = initialMode.getFieldInfos().stream().filter(f -> f.getField().getHeader().equals(field)).findFirst();
            if (fieldInfo.isPresent()) {
                initialSortField = fieldInfo.get().getField();
                initialAscendingSort = ascendingSort;
            } else {
                LOGGER.warn("The specified sort field " + field + " is not found, using default");
            }
        }
        if (commandLine.hasOption("fields")) {
            String[] fields = commandLine.getOptionValue("fields").split(",");
            initialFields = new ArrayList<>();
            for (String field : fields) {
                Optional<FieldInfo> fieldInfo = initialMode.getFieldInfos().stream().filter(f -> f.getField().getHeader().equals(field)).findFirst();
                if (fieldInfo.isPresent()) {
                    initialFields.add(fieldInfo.get().getField());
                } else {
                    LOGGER.warn("The specified field " + field + " is not found, ignoring");
                }
            }
        }
        if (commandLine.hasOption("filters")) {
            String[] filters = commandLine.getOptionValue("filters").split(",");
            List<Field> fields = initialMode.getFieldInfos().stream().map(FieldInfo::getField).collect(Collectors.toList());
            for (String filter : filters) {
                RecordFilter f = RecordFilter.parse(filter, fields, false);
                if (f != null) {
                    if (initialFilters == null) {
                        initialFilters = new ArrayList<>();
                    }
                    initialFilters.add(f);
                } else {
                    LOGGER.warn("The specified filter " + filter + " is invalid, ignoring");
                }
            }
        }
        if (commandLine.hasOption("batchMode")) {
            batchMode = true;
        }
    } catch (Exception e) {
        LOGGER.error("Unable to parse options", e);
        return 1;
    }
    try (Screen screen = new Screen(getConf(), initialRefreshDelay, initialMode, initialFields, initialSortField, initialAscendingSort, initialFilters, numberOfIterations, batchMode)) {
        screen.run();
    }
    return 0;
}
Also used : Logger(org.slf4j.Logger) Options(org.apache.hbase.thirdparty.org.apache.commons.cli.Options) ToolRunner(org.apache.hadoop.util.ToolRunner) LoggerFactory(org.slf4j.LoggerFactory) HBaseInterfaceAudience(org.apache.hadoop.hbase.HBaseInterfaceAudience) HelpFormatter(org.apache.hbase.thirdparty.org.apache.commons.cli.HelpFormatter) Collectors(java.util.stream.Collectors) Tool(org.apache.hadoop.util.Tool) ArrayList(java.util.ArrayList) Objects(java.util.Objects) Screen(org.apache.hadoop.hbase.hbtop.screen.Screen) List(java.util.List) InterfaceAudience(org.apache.yetus.audience.InterfaceAudience) Field(org.apache.hadoop.hbase.hbtop.field.Field) FieldInfo(org.apache.hadoop.hbase.hbtop.field.FieldInfo) HBaseConfiguration(org.apache.hadoop.hbase.HBaseConfiguration) Mode(org.apache.hadoop.hbase.hbtop.mode.Mode) DefaultParser(org.apache.hbase.thirdparty.org.apache.commons.cli.DefaultParser) Configured(org.apache.hadoop.conf.Configured) Configuration(org.apache.hadoop.conf.Configuration) Optional(java.util.Optional) CommandLine(org.apache.hbase.thirdparty.org.apache.commons.cli.CommandLine) Options(org.apache.hbase.thirdparty.org.apache.commons.cli.Options) Screen(org.apache.hadoop.hbase.hbtop.screen.Screen) Mode(org.apache.hadoop.hbase.hbtop.mode.Mode) Field(org.apache.hadoop.hbase.hbtop.field.Field) CommandLine(org.apache.hbase.thirdparty.org.apache.commons.cli.CommandLine) FieldInfo(org.apache.hadoop.hbase.hbtop.field.FieldInfo) DefaultParser(org.apache.hbase.thirdparty.org.apache.commons.cli.DefaultParser)

Example 3 with FieldInfo

use of org.apache.hadoop.hbase.hbtop.field.FieldInfo in project hbase by apache.

the class TopScreenPresenter method initFieldDisplayMapAndFieldLengthMap.

private void initFieldDisplayMapAndFieldLengthMap(@Nullable List<Field> initialFields) {
    fieldDisplayMap.clear();
    fieldLengthMap.clear();
    for (FieldInfo fieldInfo : topScreenModel.getFieldInfos()) {
        if (initialFields != null) {
            fieldDisplayMap.put(fieldInfo.getField(), initialFields.contains(fieldInfo.getField()));
        } else {
            fieldDisplayMap.put(fieldInfo.getField(), fieldInfo.isDisplayByDefault());
        }
        fieldLengthMap.put(fieldInfo.getField(), fieldInfo.getDefaultLength());
    }
}
Also used : FieldInfo(org.apache.hadoop.hbase.hbtop.field.FieldInfo)

Example 4 with FieldInfo

use of org.apache.hadoop.hbase.hbtop.field.FieldInfo in project hbase by apache.

the class TestFieldScreenPresenter method setup.

@Before
public void setup() {
    Field sortField = Mode.REGION.getDefaultSortField();
    fields = Mode.REGION.getFieldInfos().stream().map(FieldInfo::getField).collect(Collectors.toList());
    fieldDisplayMap = Mode.REGION.getFieldInfos().stream().collect(() -> new EnumMap<>(Field.class), (r, fi) -> r.put(fi.getField(), fi.isDisplayByDefault()), (r1, r2) -> {
    });
    fieldScreenPresenter = new FieldScreenPresenter(fieldScreenView, sortField, fields, fieldDisplayMap, resultListener, topScreenView);
    for (int i = 0; i < fields.size(); i++) {
        Field field = fields.get(i);
        if (field == sortField) {
            sortFieldPosition = i;
            break;
        }
    }
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Mock(org.mockito.Mock) RunWith(org.junit.runner.RunWith) ArgumentMatchers.anyBoolean(org.mockito.ArgumentMatchers.anyBoolean) TopScreenView(org.apache.hadoop.hbase.hbtop.screen.top.TopScreenView) FieldInfo(org.apache.hadoop.hbase.hbtop.field.FieldInfo) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) ClassRule(org.junit.ClassRule) ArgumentMatchers.anyInt(org.mockito.ArgumentMatchers.anyInt) Before(org.junit.Before) InOrder(org.mockito.InOrder) EnumMap(java.util.EnumMap) HBaseClassTestRule(org.apache.hadoop.hbase.HBaseClassTestRule) Test(org.junit.Test) Category(org.junit.experimental.categories.Category) Collectors(java.util.stream.Collectors) Mockito.verify(org.mockito.Mockito.verify) List(java.util.List) MockitoJUnitRunner(org.mockito.runners.MockitoJUnitRunner) Field(org.apache.hadoop.hbase.hbtop.field.Field) Mode(org.apache.hadoop.hbase.hbtop.mode.Mode) Mockito.inOrder(org.mockito.Mockito.inOrder) SmallTests(org.apache.hadoop.hbase.testclassification.SmallTests) Field(org.apache.hadoop.hbase.hbtop.field.Field) EnumMap(java.util.EnumMap) FieldInfo(org.apache.hadoop.hbase.hbtop.field.FieldInfo) Before(org.junit.Before)

Aggregations

FieldInfo (org.apache.hadoop.hbase.hbtop.field.FieldInfo)4 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 Field (org.apache.hadoop.hbase.hbtop.field.Field)2 Mode (org.apache.hadoop.hbase.hbtop.mode.Mode)2 Before (org.junit.Before)2 ArrayList (java.util.ArrayList)1 EnumMap (java.util.EnumMap)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 Configuration (org.apache.hadoop.conf.Configuration)1 Configured (org.apache.hadoop.conf.Configured)1 HBaseClassTestRule (org.apache.hadoop.hbase.HBaseClassTestRule)1 HBaseConfiguration (org.apache.hadoop.hbase.HBaseConfiguration)1 HBaseInterfaceAudience (org.apache.hadoop.hbase.HBaseInterfaceAudience)1 Screen (org.apache.hadoop.hbase.hbtop.screen.Screen)1 TopScreenView (org.apache.hadoop.hbase.hbtop.screen.top.TopScreenView)1 TerminalSize (org.apache.hadoop.hbase.hbtop.terminal.TerminalSize)1 SmallTests (org.apache.hadoop.hbase.testclassification.SmallTests)1 Tool (org.apache.hadoop.util.Tool)1