use of org.elasticsearch.cluster.node.DiscoveryNodes in project crate by crate.
the class NodeDisconnectJobMonitorServiceTest method testOnParticipatingNodeDisconnectedKillsJob.
@Test
public void testOnParticipatingNodeDisconnectedKillsJob() throws Exception {
JobContextService jobContextService = jobContextService();
DiscoveryNode coordinator_node = new DiscoveryNode("coordinator_node_id", DummyTransportAddress.INSTANCE, Version.CURRENT);
DiscoveryNode data_node = new DiscoveryNode("data_node_id", DummyTransportAddress.INSTANCE, Version.CURRENT);
DiscoveryNodes discoveryNodes = DiscoveryNodes.builder().localNodeId("coordinator_node_id").put(coordinator_node).put(data_node).build();
JobExecutionContext.Builder builder = jobContextService.newBuilder(UUID.randomUUID(), coordinator_node.getId(), Arrays.asList(coordinator_node.getId(), data_node.getId()));
builder.addSubContext(new DummySubContext());
jobContextService.createContext(builder);
TransportKillJobsNodeAction killAction = mock(TransportKillJobsNodeAction.class);
NodeDisconnectJobMonitorService monitorService = new NodeDisconnectJobMonitorService(Settings.EMPTY, mock(ThreadPool.class), jobContextService, mock(TransportService.class), killAction);
monitorService.onNodeDisconnected(discoveryNodes.get("data_node_id"));
verify(killAction, times(1)).broadcast(any(KillJobsRequest.class), any(ActionListener.class), eq(Arrays.asList(discoveryNodes.get("data_node_id").getId())));
}
use of org.elasticsearch.cluster.node.DiscoveryNodes in project elasticsearch by elastic.
the class InternalTestCluster method nodesInclude.
/**
* Returns a set of nodes that have at least one shard of the given index.
*/
public synchronized Set<String> nodesInclude(String index) {
if (clusterService().state().routingTable().hasIndex(index)) {
List<ShardRouting> allShards = clusterService().state().routingTable().allShards(index);
DiscoveryNodes discoveryNodes = clusterService().state().getNodes();
Set<String> nodes = new HashSet<>();
for (ShardRouting shardRouting : allShards) {
if (shardRouting.assignedToNode()) {
DiscoveryNode discoveryNode = discoveryNodes.get(shardRouting.currentNodeId());
nodes.add(discoveryNode.getName());
}
}
return nodes;
}
return Collections.emptySet();
}
use of org.elasticsearch.cluster.node.DiscoveryNodes in project elasticsearch by elastic.
the class ClusterServiceUtils method createClusterService.
public static ClusterService createClusterService(Settings settings, ThreadPool threadPool, DiscoveryNode localNode) {
ClusterService clusterService = new ClusterService(Settings.builder().put("cluster.name", "ClusterServiceTests").put(settings).build(), new ClusterSettings(settings, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS), threadPool, () -> localNode);
clusterService.setNodeConnectionsService(new NodeConnectionsService(Settings.EMPTY, null, null) {
@Override
public void connectToNodes(DiscoveryNodes discoveryNodes) {
// skip
}
@Override
public void disconnectFromNodesExcept(DiscoveryNodes nodesToKeep) {
// skip
}
});
clusterService.setClusterStatePublisher((event, ackListener) -> {
});
clusterService.setDiscoverySettings(new DiscoverySettings(Settings.EMPTY, new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS)));
clusterService.start();
final DiscoveryNodes.Builder nodes = DiscoveryNodes.builder(clusterService.state().nodes());
nodes.masterNodeId(clusterService.localNode().getId());
setState(clusterService, ClusterState.builder(clusterService.state()).nodes(nodes));
return clusterService;
}
use of org.elasticsearch.cluster.node.DiscoveryNodes in project elasticsearch by elastic.
the class ClusterServiceTests method testLocalNodeMasterListenerCallbacks.
public void testLocalNodeMasterListenerCallbacks() throws Exception {
TimedClusterService timedClusterService = createTimedClusterService(false);
AtomicBoolean isMaster = new AtomicBoolean();
timedClusterService.addLocalNodeMasterListener(new LocalNodeMasterListener() {
@Override
public void onMaster() {
isMaster.set(true);
}
@Override
public void offMaster() {
isMaster.set(false);
}
@Override
public String executorName() {
return ThreadPool.Names.SAME;
}
});
ClusterState state = timedClusterService.state();
DiscoveryNodes nodes = state.nodes();
DiscoveryNodes.Builder nodesBuilder = DiscoveryNodes.builder(nodes).masterNodeId(nodes.getLocalNodeId());
state = ClusterState.builder(state).blocks(ClusterBlocks.EMPTY_CLUSTER_BLOCK).nodes(nodesBuilder).build();
setState(timedClusterService, state);
assertThat(isMaster.get(), is(true));
nodes = state.nodes();
nodesBuilder = DiscoveryNodes.builder(nodes).masterNodeId(null);
state = ClusterState.builder(state).blocks(ClusterBlocks.builder().addGlobalBlock(DiscoverySettings.NO_MASTER_BLOCK_WRITES)).nodes(nodesBuilder).build();
setState(timedClusterService, state);
assertThat(isMaster.get(), is(false));
nodesBuilder = DiscoveryNodes.builder(nodes).masterNodeId(nodes.getLocalNodeId());
state = ClusterState.builder(state).blocks(ClusterBlocks.EMPTY_CLUSTER_BLOCK).nodes(nodesBuilder).build();
setState(timedClusterService, state);
assertThat(isMaster.get(), is(true));
timedClusterService.close();
}
use of org.elasticsearch.cluster.node.DiscoveryNodes in project crate by crate.
the class BlobService method getRedirectAddress.
/**
* @param index the name of blob-enabled index
* @param digest sha-1 hash value of the file
* @return null if no redirect is required, Otherwise the address to which should be redirected.
*/
public String getRedirectAddress(String index, String digest) throws MissingHTTPEndpointException {
ShardIterator shards = clusterService.operationRouting().getShards(clusterService.state(), index, null, digest, "_local");
String localNodeId = clusterService.localNode().getId();
DiscoveryNodes nodes = clusterService.state().getNodes();
ShardRouting shard;
while ((shard = shards.nextOrNull()) != null) {
if (!shard.active()) {
continue;
}
if (shard.currentNodeId().equals(localNodeId)) {
// no redirect required if the shard is on this node
return null;
}
DiscoveryNode node = nodes.get(shard.currentNodeId());
String httpAddress = node.getAttributes().get("http_address");
if (httpAddress != null) {
return httpAddress + "/_blobs/" + BlobIndex.stripPrefix(index) + "/" + digest;
}
}
throw new MissingHTTPEndpointException("Can't find a suitable http server to serve the blob");
}
Aggregations