Search in sources :

Example 1 with AttributeVisitor

use of org.apache.ignite.spi.systemview.view.SystemViewRowAttributeWalker.AttributeVisitor in project ignite by apache.

the class SystemViewCommandTest method systemView.

/**
 * Gets system view content via control utility from specified node. Here we also check if attributes names
 * returned by the command match the real ones. And that both "SQL" and "Java" command names styles are supported.
 *
 * @param node The node to obtain system view from.
 * @param sysViewName Name of the system view which content is required.
 * @return Content of the requested system view.
 */
private List<List<String>> systemView(IgniteEx node, String sysViewName) {
    List<String> attrNames = new ArrayList<>();
    SystemView<?> sysView = node.context().systemView().view(sysViewName);
    sysView.walker().visitAll(new AttributeVisitor() {

        @Override
        public <T> void accept(int idx, String name, Class<T> clazz) {
            attrNames.add(name);
        }
    });
    String nodeId = node.context().discovery().localNode().id().toString();
    List<List<String>> rows = parseSystemViewCommandOutput(executeCommand(EXIT_CODE_OK, CMD_SYS_VIEW, toSqlName(sysViewName), NODE_ID.argName(), nodeId));
    assertEquals(attrNames, rows.get(0));
    rows = parseSystemViewCommandOutput(executeCommand(EXIT_CODE_OK, CMD_SYS_VIEW, toSqlName(sysViewName).toLowerCase(), NODE_ID.argName(), nodeId));
    assertEquals(attrNames, rows.get(0));
    rows = parseSystemViewCommandOutput(executeCommand(EXIT_CODE_OK, CMD_SYS_VIEW, sysViewName, NODE_ID.argName(), nodeId));
    assertEquals(attrNames, rows.remove(0));
    int attrsCnt = sysView.walker().count();
    rows.forEach(row -> assertEquals(attrsCnt, row.size()));
    return rows;
}
Also used : TXS_MON_LIST(org.apache.ignite.internal.processors.cache.transactions.IgniteTxManager.TXS_MON_LIST) ArrayList(java.util.ArrayList) AttributeVisitor(org.apache.ignite.spi.systemview.view.SystemViewRowAttributeWalker.AttributeVisitor) Arrays.asList(java.util.Arrays.asList) ArrayList(java.util.ArrayList) CommandList(org.apache.ignite.internal.commandline.CommandList) List(java.util.List)

Example 2 with AttributeVisitor

use of org.apache.ignite.spi.systemview.view.SystemViewRowAttributeWalker.AttributeVisitor in project ignite by apache.

the class SystemViewLocal method columnsList.

/**
 * Extract column array for specific {@link SystemView}.
 *
 * @param sysView System view.
 * @param <R> Row type.
 * @return SQL column array for {@code sysView}.
 */
private static <R> Column[] columnsList(SystemView<R> sysView) {
    Column[] cols = new Column[sysView.walker().count()];
    sysView.walker().visitAll(new AttributeVisitor() {

        @Override
        public <T> void accept(int idx, String name, Class<T> clazz) {
            int type = CLS_TO_VAL_TYPE.getOrDefault(clazz, Value.STRING);
            cols[idx] = newColumn(toSqlName(name), type);
        }
    });
    return cols;
}
Also used : Column(org.h2.table.Column) AttributeVisitor(org.apache.ignite.spi.systemview.view.SystemViewRowAttributeWalker.AttributeVisitor) ValueString(org.h2.value.ValueString)

Aggregations

AttributeVisitor (org.apache.ignite.spi.systemview.view.SystemViewRowAttributeWalker.AttributeVisitor)2 ArrayList (java.util.ArrayList)1 Arrays.asList (java.util.Arrays.asList)1 List (java.util.List)1 CommandList (org.apache.ignite.internal.commandline.CommandList)1 TXS_MON_LIST (org.apache.ignite.internal.processors.cache.transactions.IgniteTxManager.TXS_MON_LIST)1 Column (org.h2.table.Column)1 ValueString (org.h2.value.ValueString)1