Search in sources :

Example 1 with DiscoveryNodeRole

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;
}
Also used : TaskInfo(org.opensearch.tasks.TaskInfo) DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) DiscoveryNodeRole(org.opensearch.cluster.node.DiscoveryNodeRole) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with DiscoveryNodeRole

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;
}
Also used : ThreadPoolInfo(org.opensearch.threadpool.ThreadPoolInfo) DiscoveryNodeRole(org.opensearch.cluster.node.DiscoveryNodeRole) JvmInfo(org.opensearch.monitor.jvm.JvmInfo) TransportInfo(org.opensearch.transport.TransportInfo) ProcessInfo(org.opensearch.monitor.process.ProcessInfo) HttpInfo(org.opensearch.http.HttpInfo) OsInfo(org.opensearch.monitor.os.OsInfo) IngestInfo(org.opensearch.ingest.IngestInfo) AggregationInfo(org.opensearch.search.aggregations.support.AggregationInfo) Map(java.util.Map) Settings(org.opensearch.common.settings.Settings)

Example 3 with DiscoveryNodeRole

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);
}
Also used : DiscoveryNodes(org.opensearch.cluster.node.DiscoveryNodes) BeforeClass(org.junit.BeforeClass) ThreadPool(org.opensearch.threadpool.ThreadPool) TestThreadPool(org.opensearch.threadpool.TestThreadPool) Version(org.opensearch.Version) StreamOutput(org.opensearch.common.io.stream.StreamOutput) HashMap(java.util.HashMap) ClusterServiceUtils.setState(org.opensearch.test.ClusterServiceUtils.setState) Writeable(org.opensearch.common.io.stream.Writeable) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) AtomicReferenceArray(java.util.concurrent.atomic.AtomicReferenceArray) HashSet(java.util.HashSet) ClusterState(org.opensearch.cluster.ClusterState) DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) PlainActionFuture(org.opensearch.action.support.PlainActionFuture) After(org.junit.After) Map(java.util.Map) Before(org.junit.Before) StreamInput(org.opensearch.common.io.stream.StreamInput) TransportBroadcastByNodeActionTests(org.opensearch.action.support.broadcast.node.TransportBroadcastByNodeActionTests) AfterClass(org.junit.AfterClass) ClusterServiceUtils.createClusterService(org.opensearch.test.ClusterServiceUtils.createClusterService) FailedNodeException(org.opensearch.action.FailedNodeException) OpenSearchTestCase(org.opensearch.test.OpenSearchTestCase) Set(java.util.Set) IOException(java.io.IOException) DiscoveryNodeRole(org.opensearch.cluster.node.DiscoveryNodeRole) TransportService(org.opensearch.transport.TransportService) TimeUnit(java.util.concurrent.TimeUnit) ActionFilters(org.opensearch.action.support.ActionFilters) List(java.util.List) ClusterService(org.opensearch.cluster.service.ClusterService) ClusterName(org.opensearch.cluster.ClusterName) CapturingTransport(org.opensearch.test.transport.CapturingTransport) Collections(java.util.Collections) Mockito.mock(org.mockito.Mockito.mock) ClusterState(org.opensearch.cluster.ClusterState) DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) DiscoveryNodeRole(org.opensearch.cluster.node.DiscoveryNodeRole) HashMap(java.util.HashMap) CapturingTransport(org.opensearch.test.transport.CapturingTransport) ArrayList(java.util.ArrayList) DiscoveryNodes(org.opensearch.cluster.node.DiscoveryNodes) HashSet(java.util.HashSet) Before(org.junit.Before)

Example 4 with DiscoveryNodeRole

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);
}
Also used : DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) DiscoveryNodeRole(org.opensearch.cluster.node.DiscoveryNodeRole) Matchers.containsString(org.hamcrest.Matchers.containsString)

Example 5 with DiscoveryNodeRole

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));
    }
}
Also used : DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) DiscoveryNodeRole(org.opensearch.cluster.node.DiscoveryNodeRole) TransportAddress(org.opensearch.common.transport.TransportAddress) AbstractScopedSettings(org.opensearch.common.settings.AbstractScopedSettings) ClusterSettings(org.opensearch.common.settings.ClusterSettings) Settings(org.opensearch.common.settings.Settings)

Aggregations

DiscoveryNodeRole (org.opensearch.cluster.node.DiscoveryNodeRole)14 DiscoveryNode (org.opensearch.cluster.node.DiscoveryNode)11 HashSet (java.util.HashSet)8 Settings (org.opensearch.common.settings.Settings)6 ArrayList (java.util.ArrayList)5 Map (java.util.Map)5 HashMap (java.util.HashMap)4 List (java.util.List)4 IOException (java.io.IOException)3 Set (java.util.Set)3 Version (org.opensearch.Version)3 Collections (java.util.Collections)2 Matchers.equalTo (org.hamcrest.Matchers.equalTo)2 After (org.junit.After)2 Before (org.junit.Before)2 Mockito.mock (org.mockito.Mockito.mock)2 ActionFilters (org.opensearch.action.support.ActionFilters)2 PlainActionFuture (org.opensearch.action.support.PlainActionFuture)2 DiscoveryNodes (org.opensearch.cluster.node.DiscoveryNodes)2 ClusterService (org.opensearch.cluster.service.ClusterService)2