Search in sources :

Example 1 with FieldValue

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

the class TestTopScreenModel method testSort.

@Test
public void testSort() {
    // The sort key is LOCALITY
    topScreenModel.setSortFieldAndFields(Field.LOCALITY, fields);
    FieldValue previous = null;
    // Test for ascending sort
    topScreenModel.refreshMetricsData();
    for (Record record : topScreenModel.getRecords()) {
        FieldValue current = record.get(Field.LOCALITY);
        if (previous != null) {
            assertTrue(current.compareTo(previous) < 0);
        }
        previous = current;
    }
    // Test for descending sort
    topScreenModel.switchSortOrder();
    topScreenModel.refreshMetricsData();
    previous = null;
    for (Record record : topScreenModel.getRecords()) {
        FieldValue current = record.get(Field.LOCALITY);
        if (previous != null) {
            assertTrue(current.compareTo(previous) > 0);
        }
        previous = current;
    }
}
Also used : Record(org.apache.hadoop.hbase.hbtop.Record) FieldValue(org.apache.hadoop.hbase.hbtop.field.FieldValue) Test(org.junit.Test)

Example 2 with FieldValue

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

the class TestTopScreenModel method testFilters.

@Test
public void testFilters() {
    topScreenModel.addFilter("TABLE==table1", false);
    topScreenModel.refreshMetricsData();
    for (Record record : topScreenModel.getRecords()) {
        FieldValue value = record.get(Field.TABLE);
        assertThat(value.asString(), is("table1"));
    }
    topScreenModel.clearFilters();
    topScreenModel.addFilter("TABLE==TABLE1", false);
    topScreenModel.refreshMetricsData();
    assertThat(topScreenModel.getRecords().size(), is(0));
    // Test for ignore case
    topScreenModel.clearFilters();
    topScreenModel.addFilter("TABLE==TABLE1", true);
    topScreenModel.refreshMetricsData();
    for (Record record : topScreenModel.getRecords()) {
        FieldValue value = record.get(Field.TABLE);
        assertThat(value.asString(), is("table1"));
    }
}
Also used : Record(org.apache.hadoop.hbase.hbtop.Record) FieldValue(org.apache.hadoop.hbase.hbtop.field.FieldValue) Test(org.junit.Test)

Example 3 with FieldValue

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

the class TopScreenModel method refreshRecords.

private void refreshRecords(ClusterMetrics clusterMetrics) {
    List<Record> records = currentMode.getRecords(clusterMetrics, pushDownFilters);
    // Filter and sort
    records = records.stream().filter(r -> filters.stream().allMatch(f -> f.execute(r))).sorted((recordLeft, recordRight) -> {
        FieldValue left = recordLeft.get(currentSortField);
        FieldValue right = recordRight.get(currentSortField);
        return (ascendingSort ? 1 : -1) * left.compareTo(right);
    }).collect(Collectors.toList());
    this.records = Collections.unmodifiableList(records);
}
Also used : RecordFilter(org.apache.hadoop.hbase.hbtop.RecordFilter) Logger(org.slf4j.Logger) Collection(java.util.Collection) LoggerFactory(org.slf4j.LoggerFactory) ClusterMetrics(org.apache.hadoop.hbase.ClusterMetrics) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) Objects(java.util.Objects) List(java.util.List) DrillDownInfo(org.apache.hadoop.hbase.hbtop.mode.DrillDownInfo) InterfaceAudience(org.apache.yetus.audience.InterfaceAudience) Admin(org.apache.hadoop.hbase.client.Admin) Field(org.apache.hadoop.hbase.hbtop.field.Field) FieldInfo(org.apache.hadoop.hbase.hbtop.field.FieldInfo) FieldValue(org.apache.hadoop.hbase.hbtop.field.FieldValue) Mode(org.apache.hadoop.hbase.hbtop.mode.Mode) EnvironmentEdgeManager(org.apache.hadoop.hbase.util.EnvironmentEdgeManager) Nullable(edu.umd.cs.findbugs.annotations.Nullable) Record(org.apache.hadoop.hbase.hbtop.Record) ISO_8601_EXTENDED_TIME_FORMAT(org.apache.commons.lang3.time.DateFormatUtils.ISO_8601_EXTENDED_TIME_FORMAT) Collections(java.util.Collections) Record(org.apache.hadoop.hbase.hbtop.Record) FieldValue(org.apache.hadoop.hbase.hbtop.field.FieldValue)

Example 4 with FieldValue

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

the class ClientModeStrategy method aggregateRecordsAndAddDistinct.

/**
 * Aggregate the records and count the unique values for the given distinctField
 *
 * @param records               records to be processed
 * @param groupBy               Field on which group by needs to be done
 * @param distinctField         Field whose unique values needs to be counted
 * @param uniqueCountAssignedTo a target field to which the unique count is assigned to
 * @return aggregated records
 */
List<Record> aggregateRecordsAndAddDistinct(List<Record> records, Field groupBy, Field distinctField, Field uniqueCountAssignedTo) {
    List<Record> result = new ArrayList<>();
    records.stream().collect(Collectors.groupingBy(r -> r.get(groupBy))).values().forEach(val -> {
        Set<FieldValue> distinctValues = new HashSet<>();
        Map<Field, FieldValue> map = new HashMap<>();
        for (Record record : val) {
            for (Map.Entry<Field, FieldValue> field : record.entrySet()) {
                if (distinctField.equals(field.getKey())) {
                    // We will not be adding the field in the new record whose distinct count is required
                    distinctValues.add(record.get(distinctField));
                } else {
                    if (field.getKey().getFieldValueType() == FieldValueType.STRING) {
                        map.put(field.getKey(), field.getValue());
                    } else {
                        if (map.get(field.getKey()) == null) {
                            map.put(field.getKey(), field.getValue());
                        } else {
                            map.put(field.getKey(), map.get(field.getKey()).plus(field.getValue()));
                        }
                    }
                }
            }
        }
        // Add unique count field
        map.put(uniqueCountAssignedTo, uniqueCountAssignedTo.newValue(distinctValues.size()));
        result.add(Record.ofEntries(map.entrySet().stream().map(k -> Record.entry(k.getKey(), k.getValue()))));
    });
    return result;
}
Also used : RecordFilter(org.apache.hadoop.hbase.hbtop.RecordFilter) Arrays(java.util.Arrays) UserMetrics(org.apache.hadoop.hbase.UserMetrics) Set(java.util.Set) ServerMetrics(org.apache.hadoop.hbase.ServerMetrics) HashMap(java.util.HashMap) ClusterMetrics(org.apache.hadoop.hbase.ClusterMetrics) Collectors(java.util.stream.Collectors) FieldValueType(org.apache.hadoop.hbase.hbtop.field.FieldValueType) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) 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) FieldValue(org.apache.hadoop.hbase.hbtop.field.FieldValue) Map(java.util.Map) Record(org.apache.hadoop.hbase.hbtop.Record) Collections(java.util.Collections) Field(org.apache.hadoop.hbase.hbtop.field.Field) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Record(org.apache.hadoop.hbase.hbtop.Record) FieldValue(org.apache.hadoop.hbase.hbtop.field.FieldValue) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Example 5 with FieldValue

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

the class RecordFilter method execute.

public boolean execute(Record record) {
    FieldValue fieldValue = record.get(field);
    if (fieldValue == null) {
        return false;
    }
    if (operator == Operator.EQUAL) {
        boolean ret;
        if (ignoreCase) {
            ret = fieldValue.asString().toLowerCase().contains(value.asString().toLowerCase());
        } else {
            ret = fieldValue.asString().contains(value.asString());
        }
        return not != ret;
    }
    int compare = ignoreCase ? fieldValue.compareToIgnoreCase(value) : fieldValue.compareTo(value);
    boolean ret;
    switch(operator) {
        case DOUBLE_EQUALS:
            ret = compare == 0;
            break;
        case GREATER:
            ret = compare > 0;
            break;
        case GREATER_OR_EQUAL:
            ret = compare >= 0;
            break;
        case LESS:
            ret = compare < 0;
            break;
        case LESS_OR_EQUAL:
            ret = compare <= 0;
            break;
        default:
            throw new AssertionError();
    }
    return not != ret;
}
Also used : FieldValue(org.apache.hadoop.hbase.hbtop.field.FieldValue)

Aggregations

FieldValue (org.apache.hadoop.hbase.hbtop.field.FieldValue)6 Record (org.apache.hadoop.hbase.hbtop.Record)4 Field (org.apache.hadoop.hbase.hbtop.field.Field)3 ArrayList (java.util.ArrayList)2 Collections (java.util.Collections)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 ClusterMetrics (org.apache.hadoop.hbase.ClusterMetrics)2 RecordFilter (org.apache.hadoop.hbase.hbtop.RecordFilter)2 FieldInfo (org.apache.hadoop.hbase.hbtop.field.FieldInfo)2 InterfaceAudience (org.apache.yetus.audience.InterfaceAudience)2 Test (org.junit.Test)2 Nullable (edu.umd.cs.findbugs.annotations.Nullable)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Set (java.util.Set)1