Search in sources :

Example 16 with Version

use of org.elasticsearch.Version in project elasticsearch by elastic.

the class Murmur3FieldMapperTests method testEmptyName.

public void testEmptyName() throws Exception {
    String mapping = XContentFactory.jsonBuilder().startObject().startObject("type").startObject("properties").startObject("").field("type", "murmur3").endObject().endObject().endObject().endObject().string();
    IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> parser.parse("type", new CompressedXContent(mapping)));
    assertThat(e.getMessage(), containsString("name cannot be empty string"));
    // before 5.x
    Version oldVersion = VersionUtils.randomVersionBetween(getRandom(), Version.V_2_0_0, Version.V_2_3_5);
    Settings oldIndexSettings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, oldVersion).build();
    IndexService indexService2x = createIndex("test_old", oldIndexSettings);
    Supplier<QueryShardContext> queryShardContext = () -> {
        return indexService2x.newQueryShardContext(0, null, () -> {
            throw new UnsupportedOperationException();
        });
    };
    DocumentMapperParser parser = new DocumentMapperParser(indexService2x.getIndexSettings(), indexService2x.mapperService(), indexService2x.getIndexAnalyzers(), indexService2x.xContentRegistry(), indexService2x.similarityService(), mapperRegistry, queryShardContext);
    DocumentMapper defaultMapper = parser.parse("type", new CompressedXContent(mapping));
    assertEquals(mapping, defaultMapper.mappingSource().string());
}
Also used : Version(org.elasticsearch.Version) IndexService(org.elasticsearch.index.IndexService) DocumentMapper(org.elasticsearch.index.mapper.DocumentMapper) CompressedXContent(org.elasticsearch.common.compress.CompressedXContent) QueryShardContext(org.elasticsearch.index.query.QueryShardContext) Matchers.containsString(org.hamcrest.Matchers.containsString) DocumentMapperParser(org.elasticsearch.index.mapper.DocumentMapperParser) Settings(org.elasticsearch.common.settings.Settings)

Example 17 with Version

use of org.elasticsearch.Version in project elasticsearch by elastic.

the class ESClientYamlSuiteTestCase method readVersionsFromInfo.

private static Version readVersionsFromInfo(RestClient restClient, int numHosts) throws IOException {
    Version version = null;
    for (int i = 0; i < numHosts; i++) {
        //we don't really use the urls here, we rely on the client doing round-robin to touch all the nodes in the cluster
        Response response = restClient.performRequest("GET", "/");
        ClientYamlTestResponse restTestResponse = new ClientYamlTestResponse(response);
        Object latestVersion = restTestResponse.evaluate("version.number");
        if (latestVersion == null) {
            throw new RuntimeException("elasticsearch version not found in the response");
        }
        final Version currentVersion = Version.fromString(latestVersion.toString());
        if (version == null) {
            version = currentVersion;
        } else if (version.onOrAfter(currentVersion)) {
            version = currentVersion;
        }
    }
    return version;
}
Also used : Response(org.elasticsearch.client.Response) Version(org.elasticsearch.Version)

Example 18 with Version

use of org.elasticsearch.Version in project elasticsearch by elastic.

the class OldIndexUtils method getIndexDir.

public static Path getIndexDir(final Logger logger, final String indexName, final String indexFile, final Path dataDir) throws IOException {
    final Version version = Version.fromString(indexName.substring("index-".length()));
    if (version.before(Version.V_5_0_0_alpha1)) {
        // the bwc scripts packs the indices under this path
        Path src = dataDir.resolve("nodes/0/indices/" + indexName);
        assertTrue("[" + indexFile + "] missing index dir: " + src.toString(), Files.exists(src));
        return src;
    } else {
        final List<Path> indexFolders = new ArrayList<>();
        try (DirectoryStream<Path> stream = Files.newDirectoryStream(dataDir.resolve("0/indices"), (p) -> p.getFileName().toString().startsWith("extra") == false)) {
            // extra FS can break this...
            for (final Path path : stream) {
                indexFolders.add(path);
            }
        }
        assertThat(indexFolders.toString(), indexFolders.size(), equalTo(1));
        final IndexMetaData indexMetaData = IndexMetaData.FORMAT.loadLatestState(logger, NamedXContentRegistry.EMPTY, indexFolders.get(0));
        assertNotNull(indexMetaData);
        assertThat(indexFolders.get(0).getFileName().toString(), equalTo(indexMetaData.getIndexUUID()));
        assertThat(indexMetaData.getCreationVersion(), equalTo(version));
        return indexFolders.get(0);
    }
}
Also used : Path(java.nio.file.Path) Version(org.elasticsearch.Version) ArrayList(java.util.ArrayList) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData)

Example 19 with Version

use of org.elasticsearch.Version in project elasticsearch by elastic.

the class AbstractQueryTestCase method beforeClass.

@BeforeClass
public static void beforeClass() {
    // we have to prefer CURRENT since with the range of versions we support it's rather unlikely to get the current actually.
    Version indexVersionCreated = randomBoolean() ? Version.CURRENT : VersionUtils.randomVersionBetween(random(), null, Version.CURRENT);
    nodeSettings = Settings.builder().put("node.name", AbstractQueryTestCase.class.toString()).put(Environment.PATH_HOME_SETTING.getKey(), createTempDir()).put(ScriptService.SCRIPT_AUTO_RELOAD_ENABLED_SETTING.getKey(), false).build();
    indexSettings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, indexVersionCreated).build();
    index = new Index(randomAsciiOfLengthBetween(1, 10), "_na_");
    //create some random type with some default field, those types will stick around for all of the subclasses
    currentTypes = new String[randomIntBetween(0, 5)];
    for (int i = 0; i < currentTypes.length; i++) {
        String type = randomAsciiOfLengthBetween(1, 10);
        currentTypes[i] = type;
    }
    //set some random types to be queried as part the search request, before each test
    randomTypes = getRandomTypes();
}
Also used : Version(org.elasticsearch.Version) Index(org.elasticsearch.index.Index) Matchers.containsString(org.hamcrest.Matchers.containsString) BeforeClass(org.junit.BeforeClass)

Example 20 with Version

use of org.elasticsearch.Version in project elasticsearch by elastic.

the class NodeTests method testWarnIfPreRelease.

public void testWarnIfPreRelease() {
    final Logger logger = mock(Logger.class);
    final int id = randomIntBetween(1, 9) * 1000000;
    final Version releaseVersion = Version.fromId(id + 99);
    final Version preReleaseVersion = Version.fromId(id + randomIntBetween(0, 98));
    Node.warnIfPreRelease(releaseVersion, false, logger);
    verifyNoMoreInteractions(logger);
    reset(logger);
    Node.warnIfPreRelease(releaseVersion, true, logger);
    verify(logger).warn("version [{}] is a pre-release version of Elasticsearch and is not suitable for production", releaseVersion + "-SNAPSHOT");
    reset(logger);
    final boolean isSnapshot = randomBoolean();
    Node.warnIfPreRelease(preReleaseVersion, isSnapshot, logger);
    verify(logger).warn("version [{}] is a pre-release version of Elasticsearch and is not suitable for production", preReleaseVersion + (isSnapshot ? "-SNAPSHOT" : ""));
}
Also used : Version(org.elasticsearch.Version) Logger(org.apache.logging.log4j.Logger)

Aggregations

Version (org.elasticsearch.Version)124 Settings (org.elasticsearch.common.settings.Settings)51 StreamInput (org.elasticsearch.common.io.stream.StreamInput)21 XContentBuilder (org.elasticsearch.common.xcontent.XContentBuilder)20 HashMap (java.util.HashMap)17 ArrayList (java.util.ArrayList)16 BytesStreamOutput (org.elasticsearch.common.io.stream.BytesStreamOutput)16 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)14 IOException (java.io.IOException)13 SearchResponse (org.elasticsearch.action.search.SearchResponse)12 List (java.util.List)11 Map (java.util.Map)11 ClusterState (org.elasticsearch.cluster.ClusterState)10 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)9 ClusterName (org.elasticsearch.cluster.ClusterName)9 TimeValue (org.elasticsearch.common.unit.TimeValue)9 VersionUtils.randomVersion (org.elasticsearch.test.VersionUtils.randomVersion)9 IndexMetaData (org.elasticsearch.cluster.metadata.IndexMetaData)8 CompressedXContent (org.elasticsearch.common.compress.CompressedXContent)8 GeoPoint (org.elasticsearch.common.geo.GeoPoint)8