use of org.apache.ignite.spi.systemview.view.NodeAttributeView in project ignite by apache.
the class GridDiscoveryManager method nodeAttributeViewSupplier.
/**
* Node attributes view supplier.
*
* @param filter Filter.
*/
private Iterable<NodeAttributeView> nodeAttributeViewSupplier(Map<String, Object> filter) {
Object nodeFilter = filter.get(NodeAttributeViewWalker.NODE_ID_FILTER);
UUID nodeId = null;
if (nodeFilter instanceof UUID)
nodeId = (UUID) nodeFilter;
else if (nodeFilter instanceof String) {
try {
nodeId = UUID.fromString((String) nodeFilter);
} catch (RuntimeException ignored) {
return Collections.emptyList();
}
} else if (nodeFilter != null)
return Collections.emptyList();
Collection<ClusterNode> nodes;
if (nodeId != null) {
ClusterNode node = ctx.discovery().node(nodeId);
if (node != null)
nodes = Collections.singleton(node);
else
nodes = Collections.emptySet();
} else
nodes = F.concat(false, allNodes(), daemonNodes());
String attrName = (String) filter.get(NodeAttributeViewWalker.NAME_FILTER);
return F.flat(F.iterator(nodes, node -> {
Map<String, Object> attrs = node.attributes();
if (attrName != null) {
Object attrVal = attrs.get(attrName);
if (attrVal == null)
return Collections.emptyList();
attrs = F.asMap(attrName, attrs.get(attrName));
}
return F.iterator(attrs.entrySet(), na -> new NodeAttributeView(node.id(), na.getKey(), na.getValue()), true);
}, true));
}
use of org.apache.ignite.spi.systemview.view.NodeAttributeView in project ignite by apache.
the class SystemViewSelfTest method testNodeAttributes.
/**
*/
@Test
public void testNodeAttributes() throws Exception {
try (IgniteEx ignite0 = startGrid(getConfiguration(getTestIgniteInstanceName(0)).setUserAttributes(F.asMap("name", "val0")));
IgniteEx ignite1 = startGrid(getConfiguration(getTestIgniteInstanceName(1)).setUserAttributes(F.asMap("name", "val1")))) {
awaitPartitionMapExchange();
SystemView<NodeAttributeView> view = ignite0.context().systemView().view(NODE_ATTRIBUTES_SYS_VIEW);
assertEquals(ignite0.cluster().localNode().attributes().size() + ignite1.cluster().localNode().attributes().size(), view.size());
assertEquals(1, F.size(view.iterator(), row -> "name".equals(row.name()) && "val0".equals(row.value())));
assertEquals(1, F.size(view.iterator(), row -> "name".equals(row.name()) && "val1".equals(row.value())));
// Test filtering.
assertTrue(view instanceof FiltrableSystemView);
Iterator<NodeAttributeView> iter = ((FiltrableSystemView<NodeAttributeView>) view).iterator(F.asMap(NodeAttributeViewWalker.NODE_ID_FILTER, ignite0.cluster().localNode().id()));
assertEquals(1, F.size(iter, row -> "name".equals(row.name()) && "val0".equals(row.value())));
iter = ((FiltrableSystemView<NodeAttributeView>) view).iterator(F.asMap(NodeAttributeViewWalker.NODE_ID_FILTER, ignite1.cluster().localNode().id().toString()));
assertEquals(1, F.size(iter, row -> "name".equals(row.name()) && "val1".equals(row.value())));
iter = ((FiltrableSystemView<NodeAttributeView>) view).iterator(F.asMap(NodeAttributeViewWalker.NODE_ID_FILTER, "malformed-id"));
assertEquals(0, F.size(iter));
iter = ((FiltrableSystemView<NodeAttributeView>) view).iterator(F.asMap(NodeAttributeViewWalker.NAME_FILTER, "name"));
assertEquals(2, F.size(iter));
iter = ((FiltrableSystemView<NodeAttributeView>) view).iterator(F.asMap(NodeAttributeViewWalker.NODE_ID_FILTER, ignite0.cluster().localNode().id(), NodeAttributeViewWalker.NAME_FILTER, "name"));
assertEquals(1, F.size(iter));
}
}
Aggregations