Skip to content

Commit

Permalink
Add a new node role 'search' which is dedicated to provide search cap…
Browse files Browse the repository at this point in the history
…ability (#4689)

Signed-off-by: Tianli Feng <[email protected]>
  • Loading branch information
Tianli Feng authored Oct 11, 2022
1 parent cd8f0fa commit c1272c1
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- Added precommit support for MacOS ([#4682](https://github.com/opensearch-project/OpenSearch/pull/4682))
- Recommission API changes for service layer ([#4320](https://github.com/opensearch-project/OpenSearch/pull/4320))
- Update GeoGrid base class access modifier to support extensibility ([#4572](https://github.com/opensearch-project/OpenSearch/pull/4572))
- Add a new node role 'search' which is dedicated to provide search capability ([#4689](https://github.com/opensearch-project/OpenSearch/pull/4689))

### Dependencies
- Bumps `log4j-core` from 2.18.0 to 2.19.0
Expand Down
7 changes: 7 additions & 0 deletions client/rest/src/main/java/org/opensearch/client/Node.java
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,13 @@ public boolean isIngest() {
return roles.contains("ingest");
}

/**
* Returns whether the node is dedicated to provide search capability.
*/
public boolean isSearch() {
return roles.contains("search");
}

@Override
public String toString() {
return String.join(",", roles);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@
import static java.util.Collections.singletonMap;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.hamcrest.CoreMatchers.equalTo;

public class NodeTests extends RestClientTestCase {
public void testToString() {
Expand Down Expand Up @@ -161,4 +163,9 @@ public void testEqualsAndHashCode() {
)
);
}

public void testIsSearchNode() {
Roles searchRole = new Roles(Collections.singleton("search"));
assertThat(searchRole.isSearch(), equalTo(true));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ public void testNodeCounts() {
expectedCounts.put(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE.roleName(), 1);
expectedCounts.put(DiscoveryNodeRole.INGEST_ROLE.roleName(), 1);
expectedCounts.put(DiscoveryNodeRole.REMOTE_CLUSTER_CLIENT_ROLE.roleName(), 1);
expectedCounts.put(DiscoveryNodeRole.SEARCH_ROLE.roleName(), 0);
expectedCounts.put(ClusterStatsNodes.Counts.COORDINATING_ONLY, 0);
int numNodes = randomIntBetween(1, 5);

Expand Down Expand Up @@ -160,6 +161,7 @@ public void testNodeCountsWithDeprecatedMasterRole() {
expectedCounts.put(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE.roleName(), 1);
expectedCounts.put(DiscoveryNodeRole.INGEST_ROLE.roleName(), 0);
expectedCounts.put(DiscoveryNodeRole.REMOTE_CLUSTER_CLIENT_ROLE.roleName(), 0);
expectedCounts.put(DiscoveryNodeRole.SEARCH_ROLE.roleName(), 0);
expectedCounts.put(ClusterStatsNodes.Counts.COORDINATING_ONLY, 0);

ClusterStatsResponse response = client().admin().cluster().prepareClusterStats().get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,15 @@ public boolean isRemoteClusterClient() {
return roles.contains(DiscoveryNodeRole.REMOTE_CLUSTER_CLIENT_ROLE);
}

/**
* Returns whether the node is dedicated to provide search capability.
*
* @return true if the node contains search role, false otherwise
*/
public boolean isSearchNode() {
return roles.contains(DiscoveryNodeRole.SEARCH_ROLE);
}

/**
* Returns a set of all the roles that the node has. The roles are returned in sorted order by the role name.
* <p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,11 +290,24 @@ public Setting<Boolean> legacySetting() {

};

/**
* Represents the role for a search node, which is dedicated to provide search capability.
*/
public static final DiscoveryNodeRole SEARCH_ROLE = new DiscoveryNodeRole("search", "s", true) {

@Override
public Setting<Boolean> legacySetting() {
// search role is added in 2.4 so doesn't need to configure legacy setting
return null;
}

};

/**
* The built-in node roles.
*/
public static SortedSet<DiscoveryNodeRole> BUILT_IN_ROLES = Collections.unmodifiableSortedSet(
new TreeSet<>(Arrays.asList(DATA_ROLE, INGEST_ROLE, CLUSTER_MANAGER_ROLE, REMOTE_CLUSTER_CLIENT_ROLE))
new TreeSet<>(Arrays.asList(DATA_ROLE, INGEST_ROLE, CLUSTER_MANAGER_ROLE, REMOTE_CLUSTER_CLIENT_ROLE, SEARCH_ROLE))
);

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import org.opensearch.common.settings.Setting;
import org.opensearch.common.settings.Settings;
import org.opensearch.common.transport.TransportAddress;
import org.opensearch.test.NodeRoles;
import org.opensearch.test.OpenSearchTestCase;

import java.net.InetAddress;
Expand Down Expand Up @@ -204,4 +205,10 @@ public void testGetRoleFromRoleNameIsCaseInsensitive() {
assertEquals(dynamicRoleName.toLowerCase(Locale.ROOT), dynamicNodeRole.roleName());
assertEquals(dynamicRoleName.toLowerCase(Locale.ROOT), dynamicNodeRole.roleNameAbbreviation());
}

public void testDiscoveryNodeIsSearchNode() {
final Settings settingWithSearchRole = NodeRoles.onlyRole(DiscoveryNodeRole.SEARCH_ROLE);
final DiscoveryNode node = DiscoveryNode.createLocal(settingWithSearchRole, buildNewFakeTransportAddress(), "node");
assertThat(node.isSearchNode(), equalTo(true));
}
}

0 comments on commit c1272c1

Please sign in to comment.