本文整理汇总了Java中org.elasticsearch.cluster.node.DiscoveryNode.Role方法的典型用法代码示例。如果您正苦于以下问题:Java DiscoveryNode.Role方法的具体用法?Java DiscoveryNode.Role怎么用?Java DiscoveryNode.Role使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.elasticsearch.cluster.node.DiscoveryNode
的用法示例。
在下文中一共展示了DiscoveryNode.Role方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: generateRandomNodes
import org.elasticsearch.cluster.node.DiscoveryNode; //导入方法依赖的package包/类
List<DiscoveryNode> generateRandomNodes() {
int count = scaledRandomIntBetween(1, 100);
ArrayList<DiscoveryNode> nodes = new ArrayList<>(count);
for (int i = 0; i < count; i++) {
Set<DiscoveryNode.Role> roles = new HashSet<>();
if (randomBoolean()) {
roles.add(DiscoveryNode.Role.MASTER);
}
DiscoveryNode node = new DiscoveryNode("n_" + i, "n_" + i, buildNewFakeTransportAddress(), Collections.emptyMap(),
roles, Version.CURRENT);
nodes.add(node);
}
Collections.shuffle(nodes, random());
return nodes;
}
示例2: createNode
import org.elasticsearch.cluster.node.DiscoveryNode; //导入方法依赖的package包/类
protected DiscoveryNode createNode(DiscoveryNode.Role... mustHaveRoles) {
Set<DiscoveryNode.Role> roles = new HashSet<>(randomSubsetOf(Sets.newHashSet(DiscoveryNode.Role.values())));
for (DiscoveryNode.Role mustHaveRole : mustHaveRoles) {
roles.add(mustHaveRole);
}
final String id = String.format(Locale.ROOT, "node_%03d", nodeIdGenerator.incrementAndGet());
return new DiscoveryNode(id, id, buildNewFakeTransportAddress(), Collections.emptyMap(), roles,
Version.CURRENT);
}
示例3: newNode
import org.elasticsearch.cluster.node.DiscoveryNode; //导入方法依赖的package包/类
protected DiscoveryNode newNode(int i, boolean master) {
Set<DiscoveryNode.Role> roles = new HashSet<>();
if (master) {
roles.add(DiscoveryNode.Role.MASTER);
}
final String prefix = master ? "master_" : "data_";
return new DiscoveryNode(prefix + i, i + "", buildNewFakeTransportAddress(), emptyMap(), roles, Version.CURRENT);
}
示例4: generateRandomCandidates
import org.elasticsearch.cluster.node.DiscoveryNode; //导入方法依赖的package包/类
List<MasterCandidate> generateRandomCandidates() {
int count = scaledRandomIntBetween(1, 100);
ArrayList<MasterCandidate> candidates = new ArrayList<>(count);
for (int i = 0; i < count; i++) {
Set<DiscoveryNode.Role> roles = new HashSet<>();
roles.add(DiscoveryNode.Role.MASTER);
DiscoveryNode node = new DiscoveryNode("n_" + i, "n_" + i, buildNewFakeTransportAddress(), Collections.emptyMap(),
roles, Version.CURRENT);
candidates.add(
new MasterCandidate(node, randomBoolean() ? MasterCandidate.UNRECOVERED_CLUSTER_VERSION : randomNonNegativeLong()));
}
Collections.shuffle(candidates, random());
return candidates;
}
示例5: generateNodes
import org.elasticsearch.cluster.node.DiscoveryNode; //导入方法依赖的package包/类
private List<DiscoveryNode> generateNodes() {
List<DiscoveryNode> nodes = new ArrayList<>();
for (int i = randomIntBetween(20, 50); i > 0; i--) {
Set<DiscoveryNode.Role> roles = new HashSet<>(randomSubsetOf(Arrays.asList(DiscoveryNode.Role.values())));
nodes.add(new DiscoveryNode("node_" + i, "" + i, buildNewFakeTransportAddress(), Collections.emptyMap(),
roles, Version.CURRENT));
}
return nodes;
}
示例6: setUp
import org.elasticsearch.cluster.node.DiscoveryNode; //导入方法依赖的package包/类
@Before
public void setUp() throws Exception {
super.setUp();
transport = new CapturingTransport();
clusterService = createClusterService(THREAD_POOL);
transportService = new TransportService(clusterService.getSettings(), transport, THREAD_POOL,
TransportService.NOOP_TRANSPORT_INTERCEPTOR, x -> clusterService.localNode(), null);
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<DiscoveryNode.Role> roles = new HashSet<>(randomSubsetOf(Arrays.asList(DiscoveryNode.Role.values())));
if (frequently()) {
attributes.put("custom", randomBoolean() ? "match" : randomAsciiOfLengthBetween(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);
}
示例7: newNode
import org.elasticsearch.cluster.node.DiscoveryNode; //导入方法依赖的package包/类
protected static DiscoveryNode newNode(String nodeId, Set<DiscoveryNode.Role> roles) {
return new DiscoveryNode(nodeId, buildNewFakeTransportAddress(), emptyMap(), roles, Version.CURRENT);
}
示例8: toXContent
import org.elasticsearch.cluster.node.DiscoveryNode; //导入方法依赖的package包/类
@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_hash", nodeInfo.getBuild().shortHash());
if (nodeInfo.getTotalIndexingBuffer() != null) {
builder.byteSizeField("total_indexing_buffer", "total_indexing_buffer_in_bytes", nodeInfo.getTotalIndexingBuffer());
}
builder.startArray("roles");
for (DiscoveryNode.Role role : nodeInfo.getNode().getRoles()) {
builder.value(role.getRoleName());
}
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.getOs() != null) {
nodeInfo.getOs().toXContent(builder, params);
}
if (nodeInfo.getProcess() != null) {
nodeInfo.getProcess().toXContent(builder, params);
}
if (nodeInfo.getJvm() != null) {
nodeInfo.getJvm().toXContent(builder, params);
}
if (nodeInfo.getThreadPool() != null) {
nodeInfo.getThreadPool().toXContent(builder, params);
}
if (nodeInfo.getTransport() != null) {
nodeInfo.getTransport().toXContent(builder, params);
}
if (nodeInfo.getHttp() != null) {
nodeInfo.getHttp().toXContent(builder, params);
}
if (nodeInfo.getPlugins() != null) {
nodeInfo.getPlugins().toXContent(builder, params);
}
if (nodeInfo.getIngest() != null) {
nodeInfo.getIngest().toXContent(builder, params);
}
builder.endObject();
}
builder.endObject();
return builder;
}
示例9: toXContentGroupedByNode
import org.elasticsearch.cluster.node.DiscoveryNode; //导入方法依赖的package包/类
/**
* 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 (DiscoveryNode.Role role : node.getRoles()) {
builder.value(role.getRoleName());
}
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;
}
示例10: toXContent
import org.elasticsearch.cluster.node.DiscoveryNode; //导入方法依赖的package包/类
@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.field("name", getNode().getName());
builder.field("transport_address", getNode().getAddress().toString());
builder.field("host", getNode().getHostName());
builder.field("ip", getNode().getAddress());
builder.startArray("roles");
for (DiscoveryNode.Role role : getNode().getRoles()) {
builder.value(role.getRoleName());
}
builder.endArray();
if (!getNode().getAttributes().isEmpty()) {
builder.startObject("attributes");
for (Map.Entry<String, String> attrEntry : getNode().getAttributes().entrySet()) {
builder.field(attrEntry.getKey(), attrEntry.getValue());
}
builder.endObject();
}
if (getIndices() != null) {
getIndices().toXContent(builder, params);
}
if (getOs() != null) {
getOs().toXContent(builder, params);
}
if (getProcess() != null) {
getProcess().toXContent(builder, params);
}
if (getJvm() != null) {
getJvm().toXContent(builder, params);
}
if (getThreadPool() != null) {
getThreadPool().toXContent(builder, params);
}
if (getFs() != null) {
getFs().toXContent(builder, params);
}
if (getTransport() != null) {
getTransport().toXContent(builder, params);
}
if (getHttp() != null) {
getHttp().toXContent(builder, params);
}
if (getBreaker() != null) {
getBreaker().toXContent(builder, params);
}
if (getScriptStats() != null) {
getScriptStats().toXContent(builder, params);
}
if (getDiscoveryStats() != null) {
getDiscoveryStats().toXContent(builder, params);
}
if (getIngestStats() != null) {
getIngestStats().toXContent(builder, params);
}
return builder;
}
示例11: generateDiscoveryNodes
import org.elasticsearch.cluster.node.DiscoveryNode; //导入方法依赖的package包/类
private DiscoveryNodes.Builder generateDiscoveryNodes(boolean masterEligible) {
Set<DiscoveryNode.Role> dataOnlyRoles = Collections.singleton(DiscoveryNode.Role.DATA);
return DiscoveryNodes.builder().add(newNode("node1", masterEligible ? MASTER_DATA_ROLES : dataOnlyRoles))
.add(newNode("master_node", MASTER_DATA_ROLES)).localNodeId("node1").masterNodeId(masterEligible ? "node1" : "master_node");
}
示例12: newNode
import org.elasticsearch.cluster.node.DiscoveryNode; //导入方法依赖的package包/类
private static DiscoveryNode newNode(final String nodeId, Set<DiscoveryNode.Role> roles) {
return new DiscoveryNode(nodeId, nodeId, nodeId, "host", "host_address", buildNewFakeTransportAddress(),
Collections.emptyMap(), roles, Version.CURRENT);
}
示例13: newNode
import org.elasticsearch.cluster.node.DiscoveryNode; //导入方法依赖的package包/类
private static DiscoveryNode newNode(int nodeId, Map<String, String> attributes, Set<DiscoveryNode.Role> roles) {
String node = "node_" + nodeId;
return new DiscoveryNode(node, node, buildNewFakeTransportAddress(), attributes, roles, Version.CURRENT);
}