Java Code Examples for org.elasticsearch.Version#CURRENT

The following examples show how to use org.elasticsearch.Version#CURRENT . 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: ADStatsTests.java    From anomaly-detection with Apache License 2.0 6 votes vote down vote up
@Override
@Before
public void setUp() throws Exception {
    super.setUp();
    node1 = "node1";
    nodeName1 = "nodename1";
    clusterName = "test-cluster-name";
    discoveryNode1 = new DiscoveryNode(
        nodeName1,
        node1,
        new TransportAddress(TransportAddress.META_ADDRESS, 9300),
        emptyMap(),
        emptySet(),
        Version.CURRENT
    );
    clusterStats = new HashMap<>();
}
 
Example 2
Source File: LuceneQueryBuilderTest.java    From crate with Apache License 2.0 6 votes vote down vote up
private Version indexVersion() {
    try {
        Class<?> clazz = this.getClass();
        Method method = clazz.getMethod(testName.getMethodName());
        IndexVersionCreated annotation = method.getAnnotation(IndexVersionCreated.class);
        if (annotation == null) {
            annotation = clazz.getAnnotation(IndexVersionCreated.class);
            if (annotation == null) {
                return Version.CURRENT;
            }
        }
        int value = annotation.value();
        if (value == -1) {
            return Version.CURRENT;
        }
        return Version.fromId(value);
    } catch (NoSuchMethodException ignored) {
        return Version.CURRENT;
    }
}
 
Example 3
Source File: ADClusterEventListenerTests.java    From anomaly-detection with Apache License 2.0 6 votes vote down vote up
@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 4
Source File: GenericFunctionQueryTest.java    From crate with Apache License 2.0 6 votes vote down vote up
@Test
public void test_generic_function_query_cannot_be_cached_with_un_deterministic_functions_present() throws Exception {
    QueryTester.Builder builder = new QueryTester.Builder(
        createTempDir(),
        THREAD_POOL,
        clusterService,
        Version.CURRENT,
        "create table t (x int)"
    );
    builder.indexValues("x", 1, 2, 3);
    try (QueryTester tester = builder.build()) {
        var query = tester.toQuery("x = random()");
        var searcher = tester.searcher();
        var weight = query.createWeight(searcher, ScoreMode.COMPLETE_NO_SCORES, 1.0f);
        assertThat(weight.isCacheable(searcher.getTopReaderContext().leaves().get(0)), is(false));
    }
}
 
Example 5
Source File: GenericFunctionQueryTest.java    From crate with Apache License 2.0 6 votes vote down vote up
@Test
public void test_generic_function_query_can_be_cached_if_deterministic() throws Exception {
    QueryTester.Builder builder = new QueryTester.Builder(
        createTempDir(),
        THREAD_POOL,
        clusterService,
        Version.CURRENT,
        "create table t (x int)"
    );
    builder.indexValues("x", 1, 2, 3);
    try (QueryTester tester = builder.build()) {
        var query = tester.toQuery("abs(x) = 1");
        var searcher = tester.searcher();
        var weight = query.createWeight(searcher, ScoreMode.COMPLETE_NO_SCORES, 1.0f);
        assertThat(weight.isCacheable(searcher.getTopReaderContext().leaves().get(0)), is(true));
        assertThat(tester.runQuery("x", "abs(x) = 1"), contains(1));
    }
}
 
Example 6
Source File: TransportClearVotingConfigExclusionsActionTests.java    From crate with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void createThreadPoolAndClusterService() {
    threadPool = new TestThreadPool("test", Settings.EMPTY);
    localNode = new DiscoveryNode("local", buildNewFakeTransportAddress(), Version.CURRENT);
    otherNode1 = new DiscoveryNode("other1", "other1", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT);
    otherNode1Exclusion = new VotingConfigExclusion(otherNode1);
    otherNode2 = new DiscoveryNode("other2", "other2", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT);
    otherNode2Exclusion = new VotingConfigExclusion(otherNode2);
    clusterService = createClusterService(threadPool, localNode);
}
 
Example 7
Source File: DiscoveryNodes.java    From crate with Apache License 2.0 5 votes vote down vote up
public static DiscoveryNode newNode(String name, String id) {
    return new DiscoveryNode(
        name,
        id,
        newFakeAddress(),
        Collections.emptyMap(),
        Collections.emptySet(),
        Version.CURRENT);
}
 
Example 8
Source File: TransportAddVotingConfigExclusionsActionTests.java    From crate with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void createThreadPoolAndClusterService() {
    threadPool = new TestThreadPool("test", Settings.EMPTY);
    localNode = makeDiscoveryNode("local");
    localNodeExclusion = new VotingConfigExclusion(localNode);
    otherNode1 = makeDiscoveryNode("other1");
    otherNode1Exclusion = new VotingConfigExclusion(otherNode1);
    otherNode2 = makeDiscoveryNode("other2");
    otherNode2Exclusion = new VotingConfigExclusion(otherNode2);
    otherDataNode = new DiscoveryNode("data", "data", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT);
    clusterService = createClusterService(threadPool, localNode);
}
 
Example 9
Source File: BlobStoreIndexShardRepository.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs new context
 *
 * @param snapshotId     snapshot id
 * @param shardId        shard to be snapshotted
 * @param snapshotStatus snapshot status to report progress
 */
public SnapshotContext(SnapshotId snapshotId, ShardId shardId, IndexShardSnapshotStatus snapshotStatus) {
    super(snapshotId, Version.CURRENT, shardId);
    IndexService indexService = indicesService.indexServiceSafe(shardId.getIndex());
    store = indexService.shardInjectorSafe(shardId.id()).getInstance(Store.class);
    this.snapshotStatus = snapshotStatus;

}
 
Example 10
Source File: TransportUpgradeAction.java    From crate with Apache License 2.0 5 votes vote down vote up
@Override
protected ShardUpgradeResult shardOperation(UpgradeRequest request, ShardRouting shardRouting) throws IOException {
    IndexShard indexShard = indicesService.indexServiceSafe(shardRouting.shardId().getIndex()).getShard(shardRouting.shardId().id());
    org.apache.lucene.util.Version oldestLuceneSegment = indexShard.upgrade(request);
    // We are using the current version of Elasticsearch as upgrade version since we update mapping to match the current version
    return new ShardUpgradeResult(shardRouting.shardId(), indexShard.routingEntry().primary(), Version.CURRENT, oldestLuceneSegment);
}
 
Example 11
Source File: ADClusterEventListenerTests.java    From anomaly-detection with Apache License 2.0 5 votes vote down vote up
public void testIsWarmNode() {
    HashMap<String, String> attributesForNode1 = new HashMap<>();
    attributesForNode1.put(CommonName.BOX_TYPE_KEY, CommonName.WARM_BOX_TYPE);
    dataNode1 = new DiscoveryNode(dataNode1Id, buildNewFakeTransportAddress(), attributesForNode1, BUILT_IN_ROLES, Version.CURRENT);

    ClusterState warmNodeClusterState = ClusterState
        .builder(new ClusterName(clusterName))
        .nodes(new DiscoveryNodes.Builder().masterNodeId(masterNodeId).localNodeId(dataNode1Id).add(masterNode).add(dataNode1))
        .blocks(ClusterBlocks.builder().addGlobalBlock(GatewayService.STATE_NOT_RECOVERED_BLOCK))
        .build();
    listener.clusterChanged(new ClusterChangedEvent("foo", warmNodeClusterState, oldClusterState));
    assertTrue(testAppender.containsMessage(ADClusterEventListener.NODE_NOT_APPLIED_MSG));
}
 
Example 12
Source File: MetaDataIndexUpgradeService.java    From crate with Apache License 2.0 5 votes vote down vote up
/**
 * Elasticsearch v6.0 no longer supports indices created pre v5.0. All indices
 * that were created before Elasticsearch v5.0 should be re-indexed in Elasticsearch 5.x
 * before they can be opened by this version of elasticsearch.
 */
private void checkSupportedVersion(IndexMetaData indexMetaData, Version minimumIndexCompatibilityVersion) {
    if (indexMetaData.getState() == IndexMetaData.State.OPEN
        && isSupportedVersion(indexMetaData, minimumIndexCompatibilityVersion) == false) {
        throw new IllegalStateException("The index [" + indexMetaData.getIndex() + "] was created with version ["
            + indexMetaData.getCreationVersion() + "] but the minimum compatible version is ["
            + minimumIndexCompatibilityVersion + "]."
            + "It should be re-indexed in the previous major version of CrateDB before upgrading to " + Version.CURRENT + ".");
    }
}
 
Example 13
Source File: PreVoteCollectorTests.java    From crate with Apache License 2.0 5 votes vote down vote up
public void testAcceptsPreVotesFromAnyVersionInEarlierTerms() {
    assumeTrue("unluckily hit 0 for lastAcceptedTerm, cannot decrement", 0 < lastAcceptedTerm);

    final DiscoveryNode otherNode = new DiscoveryNode("other-node", buildNewFakeTransportAddress(), Version.CURRENT);
    responsesByNode.put(otherNode,
        new PreVoteResponse(currentTerm, randomLongBetween(0, lastAcceptedTerm - 1), randomNonNegativeLong()));
    startAndRunCollector(otherNode);
    assertTrue(electionOccurred);
}
 
Example 14
Source File: PluginUsingNode.java    From nexus-public with Eclipse Public License 1.0 4 votes vote down vote up
public PluginUsingNode(final Settings preparedSettings, Collection<Class<? extends Plugin>> plugins) {
  super(InternalSettingsPreparer.prepareEnvironment(preparedSettings, null), Version.CURRENT, plugins);
}
 
Example 15
Source File: JoinHelperTests.java    From crate with Apache License 2.0 4 votes vote down vote up
public void testJoinDeduplication() {
    DeterministicTaskQueue deterministicTaskQueue = new DeterministicTaskQueue(
        Settings.builder().put(NODE_NAME_SETTING.getKey(), "node0").build(), random());
    CapturingTransport capturingTransport = new CapturingTransport();
    DiscoveryNode localNode = new DiscoveryNode("node0", buildNewFakeTransportAddress(), Version.CURRENT);
    TransportService transportService = capturingTransport.createTransportService(
        Settings.EMPTY,
        deterministicTaskQueue.getThreadPool(),
        TransportService.NOOP_TRANSPORT_INTERCEPTOR,
        x -> localNode,
        null
    );
    JoinHelper joinHelper = new JoinHelper(Settings.EMPTY, null, null, transportService, () -> 0L, () -> null,
        (joinRequest, joinCallback) -> { throw new AssertionError(); }, startJoinRequest -> { throw new AssertionError(); },
        Collections.emptyList());
    transportService.start();

    DiscoveryNode node1 = new DiscoveryNode("node1", buildNewFakeTransportAddress(), Version.CURRENT);
    DiscoveryNode node2 = new DiscoveryNode("node2", buildNewFakeTransportAddress(), Version.CURRENT);

    assertFalse(joinHelper.isJoinPending());

    // check that sending a join to node1 works
    Optional<Join> optionalJoin1 = randomBoolean() ? Optional.empty() :
        Optional.of(new Join(localNode, node1, randomNonNegativeLong(), randomNonNegativeLong(), randomNonNegativeLong()));
    joinHelper.sendJoinRequest(node1, optionalJoin1);
    CapturedRequest[] capturedRequests1 = capturingTransport.getCapturedRequestsAndClear();
    assertThat(capturedRequests1.length, equalTo(1));
    CapturedRequest capturedRequest1 = capturedRequests1[0];
    assertEquals(node1, capturedRequest1.node);

    assertTrue(joinHelper.isJoinPending());

    // check that sending a join to node2 works
    Optional<Join> optionalJoin2 = randomBoolean() ? Optional.empty() :
        Optional.of(new Join(localNode, node2, randomNonNegativeLong(), randomNonNegativeLong(), randomNonNegativeLong()));
    joinHelper.sendJoinRequest(node2, optionalJoin2);
    CapturedRequest[] capturedRequests2 = capturingTransport.getCapturedRequestsAndClear();
    assertThat(capturedRequests2.length, equalTo(1));
    CapturedRequest capturedRequest2 = capturedRequests2[0];
    assertEquals(node2, capturedRequest2.node);

    // check that sending another join to node1 is a noop as the previous join is still in progress
    joinHelper.sendJoinRequest(node1, optionalJoin1);
    assertThat(capturingTransport.getCapturedRequestsAndClear().length, equalTo(0));

    // complete the previous join to node1
    if (randomBoolean()) {
        capturingTransport.handleResponse(capturedRequest1.requestId, TransportResponse.Empty.INSTANCE);
    } else {
        capturingTransport.handleRemoteError(capturedRequest1.requestId, new CoordinationStateRejectedException("dummy"));
    }

    // check that sending another join to node1 now works again
    joinHelper.sendJoinRequest(node1, optionalJoin1);
    CapturedRequest[] capturedRequests1a = capturingTransport.getCapturedRequestsAndClear();
    assertThat(capturedRequests1a.length, equalTo(1));
    CapturedRequest capturedRequest1a = capturedRequests1a[0];
    assertEquals(node1, capturedRequest1a.node);

    // check that sending another join to node2 works if the optionalJoin is different
    Optional<Join> optionalJoin2a = optionalJoin2.isPresent() && randomBoolean() ? Optional.empty() :
        Optional.of(new Join(localNode, node2, randomNonNegativeLong(), randomNonNegativeLong(), randomNonNegativeLong()));
    joinHelper.sendJoinRequest(node2, optionalJoin2a);
    CapturedRequest[] capturedRequests2a = capturingTransport.getCapturedRequestsAndClear();
    assertThat(capturedRequests2a.length, equalTo(1));
    CapturedRequest capturedRequest2a = capturedRequests2a[0];
    assertEquals(node2, capturedRequest2a.node);

    // complete all the joins and check that isJoinPending is updated
    assertTrue(joinHelper.isJoinPending());
    capturingTransport.handleRemoteError(capturedRequest2.requestId, new CoordinationStateRejectedException("dummy"));
    capturingTransport.handleRemoteError(capturedRequest1a.requestId, new CoordinationStateRejectedException("dummy"));
    capturingTransport.handleRemoteError(capturedRequest2a.requestId, new CoordinationStateRejectedException("dummy"));
    assertFalse(joinHelper.isJoinPending());
}
 
Example 16
Source File: ClusterFormationFailureHelperTests.java    From crate with Apache License 2.0 4 votes vote down vote up
public void testScheduling() {
    final long expectedDelayMillis;
    final Settings.Builder settingsBuilder = Settings.builder();
    if (randomBoolean()) {
        expectedDelayMillis
            = ClusterFormationFailureHelper.DISCOVERY_CLUSTER_FORMATION_WARNING_TIMEOUT_SETTING.get(Settings.EMPTY).millis();
    } else {
        expectedDelayMillis = randomLongBetween(100, 100000);
        settingsBuilder.put(ClusterFormationFailureHelper.DISCOVERY_CLUSTER_FORMATION_WARNING_TIMEOUT_SETTING.getKey(),
            expectedDelayMillis + "ms");
    }

    final DiscoveryNode localNode = new DiscoveryNode("local", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT);
    final ClusterState clusterState = ClusterState.builder(ClusterName.DEFAULT)
        .nodes(DiscoveryNodes.builder().add(localNode).localNodeId(localNode.getId())).build();

    final DeterministicTaskQueue deterministicTaskQueue
        = new DeterministicTaskQueue(Settings.builder().put(NODE_NAME_SETTING.getKey(), "node").build(), random());

    final AtomicLong warningCount = new AtomicLong();
    final AtomicLong logLastFailedJoinAttemptWarningCount = new AtomicLong();

    final ClusterFormationFailureHelper clusterFormationFailureHelper = new ClusterFormationFailureHelper(settingsBuilder.build(),
        () -> {
            warningCount.incrementAndGet();
            return new ClusterFormationState(Settings.EMPTY, clusterState, emptyList(), emptyList(), 0L);
        },
        deterministicTaskQueue.getThreadPool(), () -> logLastFailedJoinAttemptWarningCount.incrementAndGet());

    deterministicTaskQueue.runAllTasks();
    assertThat("should not schedule anything yet", warningCount.get(), is(0L));

    final long startTimeMillis = deterministicTaskQueue.getCurrentTimeMillis();
    clusterFormationFailureHelper.start();

    while (warningCount.get() == 0) {
        assertTrue(clusterFormationFailureHelper.isRunning());
        if (deterministicTaskQueue.hasRunnableTasks()) {
            deterministicTaskQueue.runRandomTask();
        } else {
            deterministicTaskQueue.advanceTime();
        }
    }
    assertThat(warningCount.get(), is(1L));
    assertThat(deterministicTaskQueue.getCurrentTimeMillis() - startTimeMillis, is(expectedDelayMillis));

    while (warningCount.get() < 5) {
        assertTrue(clusterFormationFailureHelper.isRunning());
        if (deterministicTaskQueue.hasRunnableTasks()) {
            deterministicTaskQueue.runRandomTask();
        } else {
            deterministicTaskQueue.advanceTime();
        }
    }
    assertThat(deterministicTaskQueue.getCurrentTimeMillis() - startTimeMillis, equalTo(5 * expectedDelayMillis));

    clusterFormationFailureHelper.stop();
    assertFalse(clusterFormationFailureHelper.isRunning());
    deterministicTaskQueue.runAllTasksInTimeOrder();

    assertThat(warningCount.get(), is(5L));
    assertThat(logLastFailedJoinAttemptWarningCount.get(), is(5L));

    warningCount.set(0);
    logLastFailedJoinAttemptWarningCount.set(0);
    clusterFormationFailureHelper.start();
    clusterFormationFailureHelper.stop();
    clusterFormationFailureHelper.start();
    final long secondStartTimeMillis = deterministicTaskQueue.getCurrentTimeMillis();

    while (warningCount.get() < 5) {
        assertTrue(clusterFormationFailureHelper.isRunning());
        if (deterministicTaskQueue.hasRunnableTasks()) {
            deterministicTaskQueue.runRandomTask();
        } else {
            deterministicTaskQueue.advanceTime();
        }
    }
    assertThat(deterministicTaskQueue.getCurrentTimeMillis() - secondStartTimeMillis, equalTo(5 * expectedDelayMillis));

    clusterFormationFailureHelper.stop();
    assertFalse(clusterFormationFailureHelper.isRunning());
    deterministicTaskQueue.runAllTasksInTimeOrder();

    assertThat(warningCount.get(), is(5L));
    assertThat(logLastFailedJoinAttemptWarningCount.get(), is(5L));
}
 
Example 17
Source File: TransportAddVotingConfigExclusionsActionTests.java    From crate with Apache License 2.0 4 votes vote down vote up
private static DiscoveryNode makeDiscoveryNode(String name) {
    return new DiscoveryNode(name, name, buildNewFakeTransportAddress(), emptyMap(), singleton(Role.MASTER), Version.CURRENT);
}
 
Example 18
Source File: Snapshot.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
public static Snapshot fromXContent(XContentParser parser) throws IOException {
    String name = null;
    Version version = Version.CURRENT;
    SnapshotState state = SnapshotState.IN_PROGRESS;
    String reason = null;
    List<String> indices = Collections.emptyList();
    long startTime = 0;
    long endTime = 0;
    int totalShard = 0;
    int successfulShards = 0;
    List<SnapshotShardFailure> shardFailures = NO_FAILURES;
    if (parser.currentToken() == null) { // fresh parser? move to the first token
        parser.nextToken();
    }
    if (parser.currentToken() == XContentParser.Token.START_OBJECT) {  // on a start object move to next token
        parser.nextToken();
    }
    XContentParser.Token token;
    if ((token = parser.nextToken()) == XContentParser.Token.START_OBJECT) {
        String currentFieldName = parser.currentName();
        if ("snapshot".equals(currentFieldName)) {
            while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
                if (token == XContentParser.Token.FIELD_NAME) {
                    currentFieldName = parser.currentName();
                    token = parser.nextToken();
                    if (token.isValue()) {
                        if ("name".equals(currentFieldName)) {
                            name = parser.text();
                        } else if ("state".equals(currentFieldName)) {
                            state = SnapshotState.valueOf(parser.text());
                        } else if ("reason".equals(currentFieldName)) {
                            reason = parser.text();
                        } else if ("start_time".equals(currentFieldName)) {
                            startTime = parser.longValue();
                        } else if ("end_time".equals(currentFieldName)) {
                            endTime = parser.longValue();
                        } else if ("total_shards".equals(currentFieldName)) {
                            totalShard = parser.intValue();
                        } else if ("successful_shards".equals(currentFieldName)) {
                            successfulShards = parser.intValue();
                        } else if ("version_id".equals(currentFieldName)) {
                            version = Version.fromId(parser.intValue());
                        }
                    } else if (token == XContentParser.Token.START_ARRAY) {
                        if ("indices".equals(currentFieldName)) {
                            ArrayList<String> indicesArray = new ArrayList<>();
                            while (parser.nextToken() != XContentParser.Token.END_ARRAY) {
                                indicesArray.add(parser.text());
                            }
                            indices = Collections.unmodifiableList(indicesArray);
                        } else if ("failures".equals(currentFieldName)) {
                            ArrayList<SnapshotShardFailure> shardFailureArrayList = new ArrayList<>();
                            while (parser.nextToken() != XContentParser.Token.END_ARRAY) {
                                shardFailureArrayList.add(SnapshotShardFailure.fromXContent(parser));
                            }
                            shardFailures = Collections.unmodifiableList(shardFailureArrayList);
                        } else {
                            // It was probably created by newer version - ignoring
                            parser.skipChildren();
                        }
                    } else if (token == XContentParser.Token.START_OBJECT) {
                        // It was probably created by newer version - ignoring
                        parser.skipChildren();
                    }
                }
            }
        }
    } else {
        throw new ElasticsearchParseException("unexpected token  [" + token + "]");
    }
    return new Snapshot(name, indices, state, reason, version, startTime, endTime, totalShard, successfulShards, shardFailures);
}
 
Example 19
Source File: DiskThresholdDeciderUnitTests.java    From crate with Apache License 2.0 4 votes vote down vote up
@Test
public void testCanAllocateUsesMaxAvailableSpace() {
    ClusterSettings nss = new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS);
    DiskThresholdDecider decider = new DiskThresholdDecider(Settings.EMPTY, nss);

    MetaData metaData = MetaData.builder()
        .put(IndexMetaData.builder("test").settings(settings(Version.CURRENT)).numberOfShards(1).numberOfReplicas(1))
        .build();

    final Index index = metaData.index("test").getIndex();

    ShardRouting test_0 = ShardRouting.newUnassigned(new ShardId(index, 0), true, EmptyStoreRecoverySource.INSTANCE,
                                                     new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, "foo"));
    DiscoveryNode node_0 = new DiscoveryNode("node_0", buildNewFakeTransportAddress(), Collections.emptyMap(),
                                             new HashSet<>(Arrays.asList(DiscoveryNode.Role.values())), Version.CURRENT);
    DiscoveryNode node_1 = new DiscoveryNode("node_1", buildNewFakeTransportAddress(), Collections.emptyMap(),
                                             new HashSet<>(Arrays.asList(DiscoveryNode.Role.values())), Version.CURRENT);

    RoutingTable routingTable = RoutingTable.builder()
        .addAsNew(metaData.index("test"))
        .build();

    ClusterState clusterState = ClusterState.builder(ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY))
        .metaData(metaData).routingTable(routingTable).build();

    clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder()
                                                                .add(node_0)
                                                                .add(node_1)
    ).build();

    // actual test -- after all that bloat :)
    ImmutableOpenMap.Builder<String, DiskUsage> leastAvailableUsages = ImmutableOpenMap.builder();
    leastAvailableUsages.put("node_0", new DiskUsage("node_0", "node_0", "_na_", 100, 0)); // all full
    leastAvailableUsages.put("node_1", new DiskUsage("node_1", "node_1", "_na_", 100, 0)); // all full

    ImmutableOpenMap.Builder<String, DiskUsage> mostAvailableUsage = ImmutableOpenMap.builder();
    // 20 - 99 percent since after allocation there must be at least 10% left and shard is 10byte
    mostAvailableUsage.put("node_0", new DiskUsage("node_0", "node_0", "_na_", 100, randomIntBetween(20, 100)));
    // this is weird and smells like a bug! it should be up to 20%?
    mostAvailableUsage.put("node_1", new DiskUsage("node_1", "node_1", "_na_", 100, randomIntBetween(0, 10)));

    ImmutableOpenMap.Builder<String, Long> shardSizes = ImmutableOpenMap.builder();
    shardSizes.put("[test][0][p]", 10L); // 10 bytes
    final ClusterInfo clusterInfo = new ClusterInfo(leastAvailableUsages.build(),
                                                    mostAvailableUsage.build(), shardSizes.build(), ImmutableOpenMap.of());
    RoutingAllocation allocation = new RoutingAllocation(new AllocationDeciders(Collections.singleton(decider)),
                                                         clusterState.getRoutingNodes(), clusterState, clusterInfo, System.nanoTime());
    allocation.debugDecision(true);
    Decision decision = decider.canAllocate(test_0, new RoutingNode("node_0", node_0), allocation);
    assertEquals(mostAvailableUsage.toString(), Decision.Type.YES, decision.type());
    assertThat(decision.getExplanation(), containsString("enough disk for shard on node"));
    decision = decider.canAllocate(test_0, new RoutingNode("node_1", node_1), allocation);
    assertEquals(mostAvailableUsage.toString(), Decision.Type.NO, decision.type());
    assertThat(decision.getExplanation(), containsString("the node is above the high watermark cluster " +
                                                         "setting [cluster.routing.allocation.disk.watermark.high=90%], using more disk space than the maximum allowed [90.0%]"));
}
 
Example 20
Source File: PublicationTests.java    From crate with Apache License 2.0 4 votes vote down vote up
private static DiscoveryNode newNode(int nodeId, Map<String, String> attributes, Set<DiscoveryNode.Role> roles) {
    return new DiscoveryNode("name_" + nodeId, "node_" + nodeId, buildNewFakeTransportAddress(), attributes, roles,
        Version.CURRENT);
}