org.elasticsearch.cluster.node.DiscoveryNodes Java Examples
The following examples show how to use
org.elasticsearch.cluster.node.DiscoveryNodes.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BundlePlugin.java From elasticsearch-plugin-bundle with GNU Affero General Public License v3.0 | 6 votes |
@Override public List<RestHandler> getRestHandlers(Settings settings, RestController restController, ClusterSettings clusterSettings, IndexScopedSettings indexScopedSettings, SettingsFilter settingsFilter, IndexNameExpressionResolver indexNameExpressionResolver, Supplier<DiscoveryNodes> nodesInCluster) { List<RestHandler> extra = new ArrayList<>(); if (settings.getAsBoolean("plugins.xbib.isbnformat.enabled", true)) { extra.add(new RestISBNFormatterAction(settings, restController)); } if (settings.getAsBoolean("plugins.xbib.langdetect.enabled", true)) { extra.add(new RestLangdetectAction(settings, restController)); } return extra; }
Example #2
Source File: ZentityPlugin.java From zentity with Apache License 2.0 | 6 votes |
@Override public List<RestHandler> getRestHandlers( Settings settings, RestController restController, ClusterSettings clusterSettings, IndexScopedSettings indexScopedSettings, SettingsFilter settingsFilter, IndexNameExpressionResolver indexNameExpressionResolver, Supplier<DiscoveryNodes> nodesInCluster) { List<RestHandler> handlers = new ArrayList<RestHandler>() {{ new HomeAction(restController); new ModelsAction(restController); new ResolutionAction(restController); new SetupAction(restController); }}; return handlers; }
Example #3
Source File: FollowersChecker.java From crate with Apache License 2.0 | 6 votes |
/** * Update the set of known nodes, starting to check any new ones and stopping checking any previously-known-but-now-unknown ones. */ public void setCurrentNodes(DiscoveryNodes discoveryNodes) { synchronized (mutex) { final Predicate<DiscoveryNode> isUnknownNode = n -> discoveryNodes.nodeExists(n) == false; followerCheckers.keySet().removeIf(isUnknownNode); faultyNodes.removeIf(isUnknownNode); discoveryNodes.mastersFirstStream().forEach(discoveryNode -> { if (discoveryNode.equals(discoveryNodes.getLocalNode()) == false && followerCheckers.containsKey(discoveryNode) == false && faultyNodes.contains(discoveryNode) == false) { final FollowerChecker followerChecker = new FollowerChecker(discoveryNode); followerCheckers.put(discoveryNode, followerChecker); followerChecker.start(); } }); } }
Example #4
Source File: TransportKillJobsNodeAction.java From Elasticsearch with Apache License 2.0 | 6 votes |
public void executeKillOnAllNodes(KillJobsRequest request, ActionListener<KillResponse> listener) { DiscoveryNodes nodes = clusterService.state().nodes(); listener = new MultiActionListener<>(nodes.size(), KillResponse.MERGE_FUNCTION, listener); DefaultTransportResponseHandler<KillResponse> transportResponseHandler = new DefaultTransportResponseHandler<KillResponse>(listener) { @Override public KillResponse newInstance() { return new KillResponse(0); } }; logger.trace("Sending {} to {}", request, nodes); for (DiscoveryNode node : nodes) { transportService.sendRequest(node, TRANSPORT_ACTION, request, transportResponseHandler); } }
Example #5
Source File: JoinClusterAction.java From Elasticsearch with Apache License 2.0 | 6 votes |
@Override public ClusterState execute(ClusterState currentState) { DiscoveryNodes.Builder nodesBuilder; nodesBuilder = DiscoveryNodes.builder(currentState.nodes()); if (currentState.nodes().nodeExists(node.id())) { logger.debug("received a join request for an existing node [{}]", node); return currentState; } // If this node is not in dead node list, then ignore this request ImmutableOpenMap<String, DiscoveryNode> deadNodes = clusterService.state().nodes().deadNodes(); if (deadNodes.get(node.getIpPortAddress()) == null) { logger.warn("failed to find node [{}] in node list, ignore the join request", node); throw new IllegalStateException("could not find this node " + node + " from active node list and dead node list"); } nodesBuilder.put(node); nodesBuilder.removeDeadNodeByIpPort(node); final ClusterState.Builder newStateBuilder = ClusterState.builder(currentState); newStateBuilder.nodes(nodesBuilder); ClusterState newState = newStateBuilder.build(); return newState; }
Example #6
Source File: Coordinator.java From crate with Apache License 2.0 | 6 votes |
@Override protected void doStart() { synchronized (mutex) { CoordinationState.PersistedState persistedState = persistedStateSupplier.get(); coordinationState.set(new CoordinationState(settings, getLocalNode(), persistedState)); peerFinder.setCurrentTerm(getCurrentTerm()); configuredHostsResolver.start(); VotingConfiguration votingConfiguration = coordinationState.get().getLastAcceptedState().getLastCommittedConfiguration(); if (singleNodeDiscovery && votingConfiguration.isEmpty() == false && votingConfiguration.hasQuorum(Collections.singleton(getLocalNode().getId())) == false) { throw new IllegalStateException("cannot start with [" + DiscoveryModule.DISCOVERY_TYPE_SETTING.getKey() + "] set to [" + DiscoveryModule.SINGLE_NODE_DISCOVERY_TYPE + "] when local node " + getLocalNode() + " does not have quorum in voting configuration " + votingConfiguration); } ClusterState initialState = ClusterState.builder(ClusterName.CLUSTER_NAME_SETTING.get(settings)) .blocks(ClusterBlocks.builder() .addGlobalBlock(STATE_NOT_RECOVERED_BLOCK) .addGlobalBlock(noMasterBlockService.getNoMasterBlock())) .nodes(DiscoveryNodes.builder().add(getLocalNode()).localNodeId(getLocalNode().getId())) .build(); applierState = initialState; clusterApplier.setInitialState(initialState); } }
Example #7
Source File: NodeJoinTests.java From crate with Apache License 2.0 | 6 votes |
private static ClusterState initialState(DiscoveryNode localNode, long term, long version, VotingConfiguration config) { return ClusterState.builder(new ClusterName(ClusterServiceUtils.class.getSimpleName())) .nodes(DiscoveryNodes.builder() .add(localNode) .localNodeId(localNode.getId())) .metaData(MetaData.builder() .coordinationMetaData( CoordinationMetaData.builder() .term(term) .lastAcceptedConfiguration(config) .lastCommittedConfiguration(config) .build())) .version(version) .blocks(ClusterBlocks.EMPTY_CLUSTER_BLOCK).build(); }
Example #8
Source File: ADClusterEventListenerTests.java From anomaly-detection with Apache License 2.0 | 6 votes |
@Override @Before public void setUp() throws Exception { super.setUp(); super.setUpLog4jForJUnit(ADClusterEventListener.class); clusterService = createClusterService(threadPool); hashRing = mock(HashRing.class); when(hashRing.build()).thenReturn(true); modelManager = mock(ModelManager.class); nodeFilter = new DiscoveryNodeFilterer(clusterService); masterNode = new DiscoveryNode(masterNodeId, buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT); dataNode1 = new DiscoveryNode(dataNode1Id, buildNewFakeTransportAddress(), emptyMap(), BUILT_IN_ROLES, Version.CURRENT); oldClusterState = ClusterState .builder(new ClusterName(clusterName)) .nodes(new DiscoveryNodes.Builder().masterNodeId(masterNodeId).localNodeId(masterNodeId).add(masterNode)) .build(); newClusterState = ClusterState .builder(new ClusterName(clusterName)) .nodes(new DiscoveryNodes.Builder().masterNodeId(masterNodeId).localNodeId(dataNode1Id).add(masterNode).add(dataNode1)) .build(); listener = new ADClusterEventListener(clusterService, hashRing, modelManager, nodeFilter); }
Example #9
Source File: ClusterState.java From crate with Apache License 2.0 | 6 votes |
public static ClusterState readFrom(StreamInput in, DiscoveryNode localNode) throws IOException { ClusterName clusterName = new ClusterName(in); Builder builder = new Builder(clusterName); builder.version = in.readLong(); builder.uuid = in.readString(); builder.metaData = MetaData.readFrom(in); builder.routingTable = RoutingTable.readFrom(in); builder.nodes = DiscoveryNodes.readFrom(in, localNode); builder.blocks = new ClusterBlocks(in); int customSize = in.readVInt(); for (int i = 0; i < customSize; i++) { Custom customIndexMetaData = in.readNamedWriteable(Custom.class); builder.putCustom(customIndexMetaData.getWriteableName(), customIndexMetaData); } return builder.build(); }
Example #10
Source File: ADClusterEventListenerTests.java From anomaly-detection with Apache License 2.0 | 6 votes |
public void testNodeRemoved() { ClusterState twoDataNodeClusterState = ClusterState .builder(new ClusterName(clusterName)) .nodes( new DiscoveryNodes.Builder() .masterNodeId(masterNodeId) .localNodeId(dataNode1Id) .add(new DiscoveryNode(masterNodeId, buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT)) .add(dataNode1) .add(new DiscoveryNode("dataNode2", buildNewFakeTransportAddress(), emptyMap(), BUILT_IN_ROLES, Version.CURRENT)) ) .build(); listener.clusterChanged(new ClusterChangedEvent("foo", newClusterState, twoDataNodeClusterState)); assertTrue(!testAppender.containsMessage(ADClusterEventListener.NODE_ADDED_MSG)); assertTrue(testAppender.containsMessage(ADClusterEventListener.NODE_REMOVED_MSG)); }
Example #11
Source File: HashRingTests.java From anomaly-detection with Apache License 2.0 | 6 votes |
private void setNodeState(Map<String, String> attributesForNode1) { DiscoveryNodes.Builder discoBuilder = DiscoveryNodes.builder(); List<DiscoveryNode> discoveryNodes = new ArrayList<>(); for (int i = 0; i < 3; i++) { DiscoveryNode node = null; if (i != 1) { node = createNode(Integer.toString(i), emptyMap()); } else { node = createNode(Integer.toString(i), attributesForNode1); } discoBuilder = discoBuilder.add(node); discoveryNodes.add(node); } discoBuilder.localNodeId("1"); discoBuilder.masterNodeId("0"); ClusterState.Builder stateBuilder = ClusterState.builder(clusterService.getClusterName()); stateBuilder.nodes(discoBuilder); ClusterState clusterState = stateBuilder.build(); setState(clusterService.getClusterApplierService(), clusterState); }
Example #12
Source File: RoutingTest.java From crate with Apache License 2.0 | 6 votes |
@Test public void testRoutingForRandomMasterOrDataNode() throws IOException { Map<String, String> attr = ImmutableMap.of(); Set<DiscoveryNode.Role> master_and_data = ImmutableSet.of(DiscoveryNode.Role.MASTER, DiscoveryNode.Role.DATA); DiscoveryNode local = new DiscoveryNode("client_node_1", buildNewFakeTransportAddress(), attr, ImmutableSet.of(), null); DiscoveryNodes nodes = new DiscoveryNodes.Builder() .add(new DiscoveryNode("data_master_node_1", buildNewFakeTransportAddress(), attr, master_and_data, null)) .add(new DiscoveryNode("data_master_node_2", buildNewFakeTransportAddress(), attr, master_and_data, null)) .add(local) .add(new DiscoveryNode("client_node_2", buildNewFakeTransportAddress(), attr, ImmutableSet.of(), null)) .add(new DiscoveryNode("client_node_3", buildNewFakeTransportAddress(), attr, ImmutableSet.of(), null)) .localNodeId(local.getId()) .build(); RoutingProvider routingProvider = new RoutingProvider(Randomness.get().nextInt(), Collections.emptyList()); Routing routing = routingProvider.forRandomMasterOrDataNode(new RelationName("doc", "table"), nodes); assertThat(routing.locations().keySet(), anyOf(contains("data_master_node_1"), contains("data_master_node_2"))); Routing routing2 = routingProvider.forRandomMasterOrDataNode(new RelationName("doc", "table"), nodes); assertThat("routingProvider is seeded and must return deterministic routing", routing.locations(), equalTo(routing2.locations())); }
Example #13
Source File: MasterServiceTests.java From crate with Apache License 2.0 | 6 votes |
private TimedMasterService createTimedMasterService(boolean makeMaster) throws InterruptedException { DiscoveryNode localNode = new DiscoveryNode("node1", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT); TimedMasterService timedMasterService = new TimedMasterService(Settings.builder().put("cluster.name", MasterServiceTests.class.getSimpleName()).build(), threadPool); ClusterState initialClusterState = ClusterState.builder(new ClusterName(MasterServiceTests.class.getSimpleName())) .nodes(DiscoveryNodes.builder() .add(localNode) .localNodeId(localNode.getId()) .masterNodeId(makeMaster ? localNode.getId() : null)) .blocks(ClusterBlocks.EMPTY_CLUSTER_BLOCK).build(); AtomicReference<ClusterState> clusterStateRef = new AtomicReference<>(initialClusterState); timedMasterService.setClusterStatePublisher((event, publishListener, ackListener) -> { clusterStateRef.set(event.state()); publishListener.onResponse(null); }); timedMasterService.setClusterStateSupplier(clusterStateRef::get); timedMasterService.start(); return timedMasterService; }
Example #14
Source File: LicenseServiceTest.java From crate with Apache License 2.0 | 6 votes |
@Test public void testThatMaxNumberOfNodesIsWithinLimit() { final ClusterState state = ClusterState.builder(ClusterName.DEFAULT) .nodes(DiscoveryNodes.builder() .add(new DiscoveryNode("n1", buildNewFakeTransportAddress(), Version.CURRENT)) .add(new DiscoveryNode("n2", buildNewFakeTransportAddress(), Version.CURRENT)) .add(new DiscoveryNode("n3", buildNewFakeTransportAddress(), Version.CURRENT)) .localNodeId("n1") ) .build(); LicenseData licenseData = new LicenseData(UNLIMITED_EXPIRY_DATE_IN_MS, "test", 3); licenseService.onUpdatedLicense(state, licenseData); assertThat(licenseService.isMaxNumberOfNodesExceeded(), is(false)); }
Example #15
Source File: RestMasterAction.java From Elasticsearch with Apache License 2.0 | 6 votes |
private Table buildTable(RestRequest request, ClusterStateResponse state) { Table table = getTableWithHeader(request); DiscoveryNodes nodes = state.getState().nodes(); table.startRow(); DiscoveryNode master = nodes.get(nodes.masterNodeId()); if (master == null) { table.addCell("-"); table.addCell("-"); table.addCell("-"); table.addCell("-"); } else { table.addCell(master.getId()); table.addCell(master.getHostName()); table.addCell(master.getHostAddress()); table.addCell(master.getName()); } table.endRow(); return table; }
Example #16
Source File: AlterTableReroutePlan.java From crate with Apache License 2.0 | 6 votes |
@VisibleForTesting public static AllocationCommand createRerouteCommand(AnalyzedStatement reroute, CoordinatorTxnCtx txnCtx, Functions functions, Row parameters, SubQueryResults subQueryResults, DiscoveryNodes nodes) { Function<? super Symbol, Object> eval = x -> SymbolEvaluator.evaluate( txnCtx, functions, x, parameters, subQueryResults ); return reroute.accept( REROUTE_STATEMENTS_VISITOR, new Context(nodes, eval)); }
Example #17
Source File: ClusterState.java From Elasticsearch with Apache License 2.0 | 6 votes |
public ClusterState readFrom(StreamInput in, DiscoveryNode localNode) throws IOException { ClusterName clusterName = ClusterName.readClusterName(in); Builder builder = new Builder(clusterName); builder.version = in.readLong(); builder.uuid = in.readString(); builder.metaData = MetaData.Builder.readFrom(in); builder.routingTable = RoutingTable.Builder.readFrom(in); builder.nodes = DiscoveryNodes.Builder.readFrom(in, localNode); builder.blocks = ClusterBlocks.Builder.readClusterBlocks(in); int customSize = in.readVInt(); for (int i = 0; i < customSize; i++) { String type = in.readString(); Custom customIndexMetaData = lookupPrototypeSafe(type).readFrom(in); builder.putCustom(type, customIndexMetaData); } return builder.build(); }
Example #18
Source File: IndexShardRoutingTable.java From Elasticsearch with Apache License 2.0 | 6 votes |
private static List<ShardRouting> collectAttributeShards(AttributesKey key, DiscoveryNodes nodes, ArrayList<ShardRouting> from) { final ArrayList<ShardRouting> to = new ArrayList<>(); for (final String attribute : key.attributes) { final String localAttributeValue = nodes.localNode().attributes().get(attribute); if (localAttributeValue != null) { for (Iterator<ShardRouting> iterator = from.iterator(); iterator.hasNext(); ) { ShardRouting fromShard = iterator.next(); final DiscoveryNode discoveryNode = nodes.get(fromShard.currentNodeId()); if (discoveryNode == null) { iterator.remove(); // node is not present anymore - ignore shard } else if (localAttributeValue.equals(discoveryNode.attributes().get(attribute))) { iterator.remove(); to.add(fromShard); } } } } return Collections.unmodifiableList(to); }
Example #19
Source File: IndicesClusterStateService.java From crate with Apache License 2.0 | 6 votes |
private void createShard(DiscoveryNodes nodes, RoutingTable routingTable, ShardRouting shardRouting, ClusterState state) { assert shardRouting.initializing() : "only allow shard creation for initializing shard but was " + shardRouting; DiscoveryNode sourceNode = null; if (shardRouting.recoverySource().getType() == Type.PEER) { sourceNode = findSourceNodeForPeerRecovery(LOGGER, routingTable, nodes, shardRouting); if (sourceNode == null) { LOGGER.trace("ignoring initializing shard {} - no source node can be found.", shardRouting.shardId()); return; } } try { LOGGER.debug("{} creating shard", shardRouting.shardId()); RecoveryState recoveryState = new RecoveryState(shardRouting, nodes.getLocalNode(), sourceNode); indicesService.createShard(shardRouting, recoveryState, recoveryTargetService, new RecoveryListener(shardRouting), repositoriesService, failedShardHandler, globalCheckpointSyncer); } catch (Exception e) { failAndRemoveShard(shardRouting, true, "failed to create shard", e, state); } }
Example #20
Source File: InternalClusterService.java From Elasticsearch with Apache License 2.0 | 6 votes |
@Override protected void doStart() { add(localNodeMasterListeners); add(taskManager); this.clusterState = ClusterState.builder(clusterState).blocks(initialBlocks).build(); this.updateTasksExecutor = EsExecutors.newSinglePrioritizing(UPDATE_THREAD_NAME, daemonThreadFactory(settings, UPDATE_THREAD_NAME)); this.reconnectToNodes = threadPool.schedule(reconnectInterval, ThreadPool.Names.GENERIC, new ReconnectToNodes()); Map<String, String> nodeAttributes = discoveryNodeService.buildAttributes(); // note, we rely on the fact that its a new id each time we start, see FD and "kill -9" handling final String nodeId = DiscoveryService.generateNodeId(settings); final TransportAddress publishAddress = transportService.boundAddress().publishAddress(); DiscoveryNode localNode = new DiscoveryNode(settings.get("name"), nodeId, publishAddress, nodeAttributes, version); DiscoveryNodes.Builder nodeBuilder = DiscoveryNodes.builder().put(localNode).localNodeId(localNode.id()); this.clusterState = ClusterState.builder(clusterState).nodes(nodeBuilder).blocks(initialBlocks).build(); this.transportService.setLocalNode(localNode); }
Example #21
Source File: InternalClusterService.java From Elasticsearch with Apache License 2.0 | 6 votes |
AckCountDownListener(AckedClusterStateTaskListener ackedTaskListener, long clusterStateVersion, DiscoveryNodes nodes, ThreadPool threadPool) { this.ackedTaskListener = ackedTaskListener; this.clusterStateVersion = clusterStateVersion; this.nodes = nodes; int countDown = 0; for (DiscoveryNode node : nodes) { if (ackedTaskListener.mustAck(node)) { countDown++; } } //we always wait for at least 1 node (the master) countDown = Math.max(1, countDown); logger.trace("expecting {} acknowledgements for cluster_state update (version: {})", countDown, clusterStateVersion); this.countDown = new CountDown(countDown); this.ackTimeoutCallback = threadPool.schedule(ackedTaskListener.ackTimeout(), ThreadPool.Names.GENERIC, new Runnable() { @Override public void run() { onTimeout(); } }); }
Example #22
Source File: NodeIndexDeletedAction.java From Elasticsearch with Apache License 2.0 | 6 votes |
public void nodeIndexDeleted(final ClusterState clusterState, final String index, final Settings indexSettings, final String nodeId) { final DiscoveryNodes nodes = clusterState.nodes(); transportService.sendRequest(clusterState.nodes().masterNode(), INDEX_DELETED_ACTION_NAME, new NodeIndexDeletedMessage(index, nodeId), EmptyTransportResponseHandler.INSTANCE_SAME); if (nodes.localNode().isDataNode() == false) { logger.trace("[{}] not acking store deletion (not a data node)", index); return; } threadPool.generic().execute(new AbstractRunnable() { @Override public void onFailure(Throwable t) { logger.warn("[{}] failed to ack index store deleted for index", t, index); } @Override protected void doRun() throws Exception { lockIndexAndAck(index, nodes, nodeId, clusterState, indexSettings); } }); }
Example #23
Source File: MasterService.java From crate with Apache License 2.0 | 6 votes |
AckCountDownListener(AckedClusterStateTaskListener ackedTaskListener, long clusterStateVersion, DiscoveryNodes nodes, ThreadPool threadPool) { this.ackedTaskListener = ackedTaskListener; this.clusterStateVersion = clusterStateVersion; this.threadPool = threadPool; this.masterNode = nodes.getMasterNode(); int countDown = 0; for (DiscoveryNode node : nodes) { //we always wait for at least the master node if (node.equals(masterNode) || ackedTaskListener.mustAck(node)) { countDown++; } } LOGGER.trace("expecting {} acknowledgements for cluster_state update (version: {})", countDown, clusterStateVersion); this.countDown = new CountDown(countDown + 1); // we also wait for onCommit to be called }
Example #24
Source File: BaseTransportClient.java From elasticsearch-helper with Apache License 2.0 | 6 votes |
protected boolean connect(Collection<InetSocketTransportAddress> addresses, boolean autodiscover) { logger.info("trying to connect to {}", addresses); client.addTransportAddresses(addresses); if (client.connectedNodes() != null) { List<DiscoveryNode> nodes = client.connectedNodes(); if (!nodes.isEmpty()) { logger.info("connected to {}", nodes); if (autodiscover) { logger.info("trying to auto-discover all cluster nodes..."); ClusterStateRequestBuilder clusterStateRequestBuilder = new ClusterStateRequestBuilder(client, ClusterStateAction.INSTANCE); ClusterStateResponse clusterStateResponse = clusterStateRequestBuilder.execute().actionGet(); DiscoveryNodes discoveryNodes = clusterStateResponse.getState().getNodes(); client.addDiscoveryNodes(discoveryNodes); logger.info("after auto-discovery connected to {}", client.connectedNodes()); } return true; } return false; } return false; }
Example #25
Source File: NodeRemovalClusterStateTaskExecutor.java From crate with Apache License 2.0 | 6 votes |
@Override public ClusterTasksResult<Task> execute(final ClusterState currentState, final List<Task> tasks) throws Exception { final DiscoveryNodes.Builder remainingNodesBuilder = DiscoveryNodes.builder(currentState.nodes()); boolean removed = false; for (final Task task : tasks) { if (currentState.nodes().nodeExists(task.node())) { remainingNodesBuilder.remove(task.node()); removed = true; } else { logger.debug("node [{}] does not exist in cluster state, ignoring", task); } } if (!removed) { // no nodes to remove, keep the current cluster state return ClusterTasksResult.<Task>builder().successes(tasks).build(currentState); } final ClusterState remainingNodesClusterState = remainingNodesClusterState(currentState, remainingNodesBuilder); return getTaskClusterTasksResult(currentState, tasks, remainingNodesClusterState); }
Example #26
Source File: LicenseServiceTest.java From crate with Apache License 2.0 | 6 votes |
@Test public void testThatMaxNumberOfNodesIsExceeded() { final ClusterState state = ClusterState.builder(ClusterName.DEFAULT) .nodes(DiscoveryNodes.builder() .add(new DiscoveryNode("n1", buildNewFakeTransportAddress(), Version.CURRENT)) .add(new DiscoveryNode("n2", buildNewFakeTransportAddress(), Version.CURRENT)) .add(new DiscoveryNode("n3", buildNewFakeTransportAddress(), Version.CURRENT)) .add(new DiscoveryNode("n4", buildNewFakeTransportAddress(), Version.CURRENT)) .localNodeId("n1") ) .build(); LicenseData licenseData = new LicenseData(UNLIMITED_EXPIRY_DATE_IN_MS, "test", 3); licenseService.onUpdatedLicense(state, licenseData); assertThat(licenseService.isMaxNumberOfNodesExceeded(), is(true)); }
Example #27
Source File: IndexShardRoutingTable.java From crate with Apache License 2.0 | 6 votes |
private static List<ShardRouting> collectAttributeShards(AttributesKey key, DiscoveryNodes nodes, ArrayList<ShardRouting> from) { final ArrayList<ShardRouting> to = new ArrayList<>(); for (final String attribute : key.attributes) { final String localAttributeValue = nodes.getLocalNode().getAttributes().get(attribute); if (localAttributeValue != null) { for (Iterator<ShardRouting> iterator = from.iterator(); iterator.hasNext(); ) { ShardRouting fromShard = iterator.next(); final DiscoveryNode discoveryNode = nodes.get(fromShard.currentNodeId()); if (discoveryNode == null) { iterator.remove(); // node is not present anymore - ignore shard } else if (localAttributeValue.equals(discoveryNode.getAttributes().get(attribute))) { iterator.remove(); to.add(fromShard); } } } } return Collections.unmodifiableList(to); }
Example #28
Source File: AsyncShardFetch.java From Elasticsearch with Apache License 2.0 | 6 votes |
/** * Fills the shard fetched data with new (data) nodes and a fresh NodeEntry, and removes from * it nodes that are no longer part of the state. */ private void fillShardCacheWithDataNodes(Map<String, NodeEntry<T>> shardCache, DiscoveryNodes nodes) { // verify that all current data nodes are there for (ObjectObjectCursor<String, DiscoveryNode> cursor : nodes.dataNodes()) { DiscoveryNode node = cursor.value; if (shardCache.containsKey(node.getId()) == false) { shardCache.put(node.getId(), new NodeEntry<T>(node.getId())); } } // remove nodes that are not longer part of the data nodes set for (Iterator<String> it = shardCache.keySet().iterator(); it.hasNext(); ) { String nodeId = it.next(); if (nodes.nodeExists(nodeId) == false) { it.remove(); } } }
Example #29
Source File: PeerFinder.java From crate with Apache License 2.0 | 5 votes |
public void activate(final DiscoveryNodes lastAcceptedNodes) { LOGGER.trace("activating with {}", lastAcceptedNodes); synchronized (mutex) { assert assertInactiveWithNoKnownPeers(); active = true; this.lastAcceptedNodes = lastAcceptedNodes; leader = Optional.empty(); handleWakeUp(); // return value discarded: there are no known peers, so none can be disconnected } onFoundPeersUpdated(); // trigger a check for a quorum already }
Example #30
Source File: CoordinationStateTests.java From crate with Apache License 2.0 | 5 votes |
public static ClusterState clusterState(long term, long version, DiscoveryNodes discoveryNodes, VotingConfiguration lastCommittedConfig, VotingConfiguration lastAcceptedConfig, long value) { return setValue(ClusterState.builder(ClusterName.DEFAULT) .version(version) .nodes(discoveryNodes) .metaData(MetaData.builder() .clusterUUID(UUIDs.randomBase64UUID(random())) // generate cluster UUID deterministically for repeatable tests .coordinationMetaData(CoordinationMetaData.builder() .term(term) .lastCommittedConfiguration(lastCommittedConfig) .lastAcceptedConfiguration(lastAcceptedConfig) .build())) .stateUUID(UUIDs.randomBase64UUID(random())) // generate cluster state UUID deterministically for repeatable tests .build(), value); }