use of org.opensearch.cluster.node.DiscoveryNodeRole in project OpenSearch by opensearch-project.
the class ListTasksResponse method toXContentGroupedByNode.
/**
* Convert this task response to XContent grouping by executing nodes.
*/
public XContentBuilder toXContentGroupedByNode(XContentBuilder builder, Params params, DiscoveryNodes discoveryNodes) throws IOException {
toXContentCommon(builder, params);
builder.startObject("nodes");
for (Map.Entry<String, List<TaskInfo>> entry : getPerNodeTasks().entrySet()) {
DiscoveryNode node = discoveryNodes.get(entry.getKey());
builder.startObject(entry.getKey());
if (node != null) {
// If the node is no longer part of the cluster, oh well, we'll just skip it's useful information.
builder.field("name", node.getName());
builder.field("transport_address", node.getAddress().toString());
builder.field("host", node.getHostName());
builder.field("ip", node.getAddress());
builder.startArray("roles");
for (DiscoveryNodeRole role : node.getRoles()) {
builder.value(role.roleName());
}
builder.endArray();
if (!node.getAttributes().isEmpty()) {
builder.startObject("attributes");
for (Map.Entry<String, String> attrEntry : node.getAttributes().entrySet()) {
builder.field(attrEntry.getKey(), attrEntry.getValue());
}
builder.endObject();
}
}
builder.startObject(TASKS);
for (TaskInfo task : entry.getValue()) {
builder.startObject(task.getTaskId().toString());
task.toXContent(builder, params);
builder.endObject();
}
builder.endObject();
builder.endObject();
}
builder.endObject();
return builder;
}
use of org.opensearch.cluster.node.DiscoveryNodeRole in project OpenSearch by opensearch-project.
the class NodesInfoResponse method toXContent.
@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject("nodes");
for (NodeInfo nodeInfo : getNodes()) {
builder.startObject(nodeInfo.getNode().getId());
builder.field("name", nodeInfo.getNode().getName());
builder.field("transport_address", nodeInfo.getNode().getAddress().toString());
builder.field("host", nodeInfo.getNode().getHostName());
builder.field("ip", nodeInfo.getNode().getHostAddress());
builder.field("version", nodeInfo.getVersion());
builder.field("build_type", nodeInfo.getBuild().type().displayName());
builder.field("build_hash", nodeInfo.getBuild().hash());
if (nodeInfo.getTotalIndexingBuffer() != null) {
builder.humanReadableField("total_indexing_buffer", "total_indexing_buffer_in_bytes", nodeInfo.getTotalIndexingBuffer());
}
builder.startArray("roles");
for (DiscoveryNodeRole role : nodeInfo.getNode().getRoles()) {
builder.value(role.roleName());
}
builder.endArray();
if (!nodeInfo.getNode().getAttributes().isEmpty()) {
builder.startObject("attributes");
for (Map.Entry<String, String> entry : nodeInfo.getNode().getAttributes().entrySet()) {
builder.field(entry.getKey(), entry.getValue());
}
builder.endObject();
}
if (nodeInfo.getSettings() != null) {
builder.startObject("settings");
Settings settings = nodeInfo.getSettings();
settings.toXContent(builder, params);
builder.endObject();
}
if (nodeInfo.getInfo(OsInfo.class) != null) {
nodeInfo.getInfo(OsInfo.class).toXContent(builder, params);
}
if (nodeInfo.getInfo(ProcessInfo.class) != null) {
nodeInfo.getInfo(ProcessInfo.class).toXContent(builder, params);
}
if (nodeInfo.getInfo(JvmInfo.class) != null) {
nodeInfo.getInfo(JvmInfo.class).toXContent(builder, params);
}
if (nodeInfo.getInfo(ThreadPoolInfo.class) != null) {
nodeInfo.getInfo(ThreadPoolInfo.class).toXContent(builder, params);
}
if (nodeInfo.getInfo(TransportInfo.class) != null) {
nodeInfo.getInfo(TransportInfo.class).toXContent(builder, params);
}
if (nodeInfo.getInfo(HttpInfo.class) != null) {
nodeInfo.getInfo(HttpInfo.class).toXContent(builder, params);
}
if (nodeInfo.getInfo(PluginsAndModules.class) != null) {
nodeInfo.getInfo(PluginsAndModules.class).toXContent(builder, params);
}
if (nodeInfo.getInfo(IngestInfo.class) != null) {
nodeInfo.getInfo(IngestInfo.class).toXContent(builder, params);
}
if (nodeInfo.getInfo(AggregationInfo.class) != null) {
nodeInfo.getInfo(AggregationInfo.class).toXContent(builder, params);
}
builder.endObject();
}
builder.endObject();
return builder;
}
use of org.opensearch.cluster.node.DiscoveryNodeRole in project OpenSearch by opensearch-project.
the class TransportNodesActionTests method setUp.
@Before
public void setUp() throws Exception {
super.setUp();
transport = new CapturingTransport();
clusterService = createClusterService(THREAD_POOL);
transportService = transport.createTransportService(clusterService.getSettings(), THREAD_POOL, TransportService.NOOP_TRANSPORT_INTERCEPTOR, x -> clusterService.localNode(), null, Collections.emptySet());
transportService.start();
transportService.acceptIncomingRequests();
int numNodes = randomIntBetween(3, 10);
DiscoveryNodes.Builder discoBuilder = DiscoveryNodes.builder();
List<DiscoveryNode> discoveryNodes = new ArrayList<>();
for (int i = 0; i < numNodes; i++) {
Map<String, String> attributes = new HashMap<>();
Set<DiscoveryNodeRole> roles = new HashSet<>(randomSubsetOf(DiscoveryNodeRole.BUILT_IN_ROLES));
if (frequently()) {
attributes.put("custom", randomBoolean() ? "match" : randomAlphaOfLengthBetween(3, 5));
}
final DiscoveryNode node = newNode(i, attributes, roles);
discoBuilder = discoBuilder.add(node);
discoveryNodes.add(node);
}
discoBuilder.localNodeId(randomFrom(discoveryNodes).getId());
discoBuilder.masterNodeId(randomFrom(discoveryNodes).getId());
ClusterState.Builder stateBuilder = ClusterState.builder(clusterService.getClusterName());
stateBuilder.nodes(discoBuilder);
ClusterState clusterState = stateBuilder.build();
setState(clusterService, clusterState);
}
use of org.opensearch.cluster.node.DiscoveryNodeRole in project OpenSearch by opensearch-project.
the class NodeJoinTests method newNode.
protected DiscoveryNode newNode(int i, boolean master) {
final Set<DiscoveryNodeRole> roles;
if (master) {
roles = singleton(DiscoveryNodeRole.MASTER_ROLE);
} else {
roles = Collections.emptySet();
}
final String prefix = master ? "master_" : "data_";
return new DiscoveryNode(prefix + i, i + "", buildNewFakeTransportAddress(), emptyMap(), roles, Version.CURRENT);
}
use of org.opensearch.cluster.node.DiscoveryNodeRole in project OpenSearch by opensearch-project.
the class SniffConnectionStrategyTests method testGetNodePredicateNodeAttrs.
public void testGetNodePredicateNodeAttrs() {
TransportAddress address = new TransportAddress(TransportAddress.META_ADDRESS, 0);
Set<DiscoveryNodeRole> roles = DiscoveryNodeRole.BUILT_IN_ROLES;
Settings settings = Settings.builder().put("cluster.remote.node.attr", "gateway").build();
Predicate<DiscoveryNode> nodePredicate = SniffConnectionStrategy.getNodePredicate(settings);
{
DiscoveryNode nonGatewayNode = new DiscoveryNode("id", address, Collections.singletonMap("gateway", "false"), roles, Version.CURRENT);
assertFalse(nodePredicate.test(nonGatewayNode));
assertTrue(SniffConnectionStrategy.getNodePredicate(Settings.EMPTY).test(nonGatewayNode));
}
{
DiscoveryNode gatewayNode = new DiscoveryNode("id", address, Collections.singletonMap("gateway", "true"), roles, Version.CURRENT);
assertTrue(nodePredicate.test(gatewayNode));
assertTrue(SniffConnectionStrategy.getNodePredicate(Settings.EMPTY).test(gatewayNode));
}
{
DiscoveryNode noAttrNode = new DiscoveryNode("id", address, Collections.emptyMap(), roles, Version.CURRENT);
assertFalse(nodePredicate.test(noAttrNode));
assertTrue(SniffConnectionStrategy.getNodePredicate(Settings.EMPTY).test(noAttrNode));
}
}
Aggregations