Search in sources :

Example 6 with SearchVersion

use of org.graylog2.storage.SearchVersion in project graylog2-server by Graylog2.

the class ElasticsearchVersionProvider method get.

@Override
public SearchVersion get() {
    if (this.versionOverride.isPresent()) {
        final SearchVersion explicitVersion = versionOverride.get();
        LOG.info("Elasticsearch version set to " + explicitVersion + " - disabling version probe.");
        return explicitVersion;
    }
    try {
        return this.cachedVersion.get(() -> {
            final Optional<SearchVersion> probedVersion = this.versionProbe.probe(this.elasticsearchHosts);
            probedVersion.ifPresent(version -> LOG.info("Elasticsearch cluster is running " + version));
            return probedVersion;
        }).orElseThrow(() -> new ElasticsearchProbeException(NO_HOST_REACHABLE_ERROR + "!"));
    } catch (ExecutionException | InterruptedException e) {
        throw new ElasticsearchProbeException(NO_HOST_REACHABLE_ERROR + ": ", e);
    }
}
Also used : Logger(org.slf4j.Logger) Provider(javax.inject.Provider) LoggerFactory(org.slf4j.LoggerFactory) SearchVersion(org.graylog2.storage.SearchVersion) Singleton(javax.inject.Singleton) VersionProbe(org.graylog2.storage.versionprobe.VersionProbe) Inject(javax.inject.Inject) ExecutionException(java.util.concurrent.ExecutionException) List(java.util.List) ElasticsearchProbeException(org.graylog2.storage.versionprobe.ElasticsearchProbeException) Optional(java.util.Optional) Named(javax.inject.Named) URI(java.net.URI) Nullable(javax.annotation.Nullable) ElasticsearchProbeException(org.graylog2.storage.versionprobe.ElasticsearchProbeException) Optional(java.util.Optional) SearchVersion(org.graylog2.storage.SearchVersion) ExecutionException(java.util.concurrent.ExecutionException)

Example 7 with SearchVersion

use of org.graylog2.storage.SearchVersion in project graylog2-server by Graylog2.

the class EventsIndexMappingTest method createsValidMappingTemplates.

@ParameterizedTest
@ValueSource(strings = { "5.0.0", "6.0.0", "7.0.0" })
void createsValidMappingTemplates(String versionString) throws Exception {
    final SearchVersion version = SearchVersion.elasticsearch(versionString);
    final IndexMappingTemplate mapping = new EventIndexTemplateProvider().create(version, null);
    assertJsonPath(mapping.toTemplate(indexSetConfig, "test_*"), at -> {
        at.jsonPathAsString("$.index_patterns").isEqualTo("test_*");
        at.jsonPathAsInteger("$.order").isEqualTo(-1);
        assertStandardMappingValues(at, version);
    });
    assertJsonPath(mapping.toTemplate(indexSetConfig, "test_*", 23), at -> {
        at.jsonPathAsString("$.index_patterns").isEqualTo("test_*");
        at.jsonPathAsInteger("$.order").isEqualTo(23);
        assertStandardMappingValues(at, version);
    });
}
Also used : SearchVersion(org.graylog2.storage.SearchVersion) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 8 with SearchVersion

use of org.graylog2.storage.SearchVersion in project graylog2-server by Graylog2.

the class MajorVersionConverterTest method convertSimpleNumber.

@Test
void convertSimpleNumber() {
    final SearchVersion version = converter.convertFrom("7");
    assertThat(version).isEqualTo(SearchVersion.elasticsearch("7.0.0"));
}
Also used : SearchVersion(org.graylog2.storage.SearchVersion) Test(org.junit.jupiter.api.Test)

Example 9 with SearchVersion

use of org.graylog2.storage.SearchVersion in project graylog2-server by Graylog2.

the class ContainerMatrixClassSelectorResolver method newClassTestDescriptor.

private ClassBasedTestDescriptor newClassTestDescriptor(TestDescriptor parent, Class<?> testClass) {
    Optional<ContainerMatrixTestsDescriptor> containerMatrixTestsDescriptor = findContainerMatrixTestsDescriptor(parent);
    if (containerMatrixTestsDescriptor.isPresent()) {
        final SearchVersion esVersion = containerMatrixTestsDescriptor.get().getEsVersion();
        final MongodbServer mongoVersion = containerMatrixTestsDescriptor.get().getMongoVersion();
        return new ContainerMatrixTestClassDescriptor(parent, testClass, configuration, esVersion, mongoVersion, ContainerMatrixTestEngine.getMongoDBFixtures(Lifecycle.CLASS, testClass));
    } else {
        return new ContainerMatrixTestClassDescriptor(parent, testClass, configuration, ContainerMatrixTestEngine.getMongoDBFixtures(Lifecycle.CLASS, testClass));
    }
}
Also used : ContainerMatrixTestsDescriptor(org.junit.jupiter.engine.descriptor.ContainerMatrixTestsDescriptor) ContainerMatrixTestClassDescriptor(org.junit.jupiter.engine.descriptor.ContainerMatrixTestClassDescriptor) MongodbServer(org.graylog.testing.containermatrix.MongodbServer) SearchVersion(org.graylog2.storage.SearchVersion)

Example 10 with SearchVersion

use of org.graylog2.storage.SearchVersion in project graylog2-server by Graylog2.

the class ContainerMatrixHierarchicalTestEngine method execute.

@Override
public void execute(ExecutionRequest request) {
    request.getRootTestDescriptor().getChildren().forEach(descriptor -> {
        if (descriptor instanceof ContainerMatrixTestWithRunningESMongoTestsDescriptor) {
            GraylogBackend backend = RunningGraylogBackend.createStarted();
            RequestSpecification specification = requestSpec(backend);
            this.execute(request, ((ContainerMatrixTestsDescriptor) descriptor).getChildren(), backend, specification);
        } else if (descriptor instanceof ContainerMatrixTestsDescriptor) {
            ContainerMatrixTestsDescriptor containerMatrixTestsDescriptor = (ContainerMatrixTestsDescriptor) descriptor;
            SearchVersion esVersion = containerMatrixTestsDescriptor.getEsVersion();
            MongodbServer mongoVersion = containerMatrixTestsDescriptor.getMongoVersion();
            int[] extraPorts = containerMatrixTestsDescriptor.getExtraPorts();
            List<URL> mongoDBFixtures = containerMatrixTestsDescriptor.getMongoDBFixtures();
            PluginJarsProvider pluginJarsProvider = instantiateFactory(containerMatrixTestsDescriptor.getPluginJarsProvider());
            MavenProjectDirProvider mavenProjectDirProvider = instantiateFactory(containerMatrixTestsDescriptor.getMavenProjectDirProvider());
            if (Lifecycle.VM.equals(containerMatrixTestsDescriptor.getLifecycle())) {
                try (ContainerizedGraylogBackend backend = ContainerizedGraylogBackend.createStarted(esVersion, mongoVersion, extraPorts, mongoDBFixtures, pluginJarsProvider, mavenProjectDirProvider)) {
                    RequestSpecification specification = requestSpec(backend);
                    this.execute(request, ((ContainerMatrixTestsDescriptor) descriptor).getChildren(), backend, specification);
                } catch (Exception exception) {
                    throw new JUnitException("Error executing tests for engine " + getId(), exception);
                }
            } else if (Lifecycle.CLASS.equals(containerMatrixTestsDescriptor.getLifecycle())) {
                for (TestDescriptor td : containerMatrixTestsDescriptor.getChildren()) {
                    List<URL> fixtures = mongoDBFixtures;
                    if (td instanceof ContainerMatrixTestClassDescriptor) {
                        fixtures = ((ContainerMatrixTestClassDescriptor) td).getMongoFixtures();
                    }
                    try (ContainerizedGraylogBackend backend = ContainerizedGraylogBackend.createStarted(esVersion, mongoVersion, extraPorts, fixtures, pluginJarsProvider, mavenProjectDirProvider)) {
                        RequestSpecification specification = requestSpec(backend);
                        this.execute(request, Collections.singleton(td), backend, specification);
                    } catch (Exception exception) {
                        throw new JUnitException("Error executing tests for engine " + getId(), exception);
                    }
                }
            } else {
                LOG.error("Unknown lifecycle: " + containerMatrixTestsDescriptor.getLifecycle());
            }
        } else {
            LOG.error("All children of the root should be of type 'ContainerMatrixTestsDescriptor' or 'ContainerMatrixTestWithRunningESMongoTestsDescriptor'");
        }
        request.getEngineExecutionListener().executionFinished(descriptor, TestExecutionResult.successful());
    });
}
Also used : ContainerMatrixTestsDescriptor(org.junit.jupiter.engine.descriptor.ContainerMatrixTestsDescriptor) ContainerMatrixTestClassDescriptor(org.junit.jupiter.engine.descriptor.ContainerMatrixTestClassDescriptor) RequestSpecification(io.restassured.specification.RequestSpecification) JUnitException(org.junit.platform.commons.JUnitException) MavenProjectDirProvider(org.graylog.testing.completebackend.MavenProjectDirProvider) JUnitException(org.junit.platform.commons.JUnitException) URL(java.net.URL) ContainerizedGraylogBackend(org.graylog.testing.completebackend.ContainerizedGraylogBackend) PluginJarsProvider(org.graylog.testing.completebackend.PluginJarsProvider) GraylogBackend(org.graylog.testing.completebackend.GraylogBackend) ContainerizedGraylogBackend(org.graylog.testing.completebackend.ContainerizedGraylogBackend) RunningGraylogBackend(org.graylog.testing.completebackend.RunningGraylogBackend) MongodbServer(org.graylog.testing.containermatrix.MongodbServer) List(java.util.List) SearchVersion(org.graylog2.storage.SearchVersion) TestDescriptor(org.junit.platform.engine.TestDescriptor) ContainerMatrixTestWithRunningESMongoTestsDescriptor(org.junit.jupiter.engine.descriptor.ContainerMatrixTestWithRunningESMongoTestsDescriptor)

Aggregations

SearchVersion (org.graylog2.storage.SearchVersion)16 Optional (java.util.Optional)3 Inject (javax.inject.Inject)3 ElasticsearchProbeException (org.graylog2.storage.versionprobe.ElasticsearchProbeException)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 JestResult (io.searchbox.client.JestResult)2 Ping (io.searchbox.core.Ping)2 URI (java.net.URI)2 List (java.util.List)2 ExecutionException (java.util.concurrent.ExecutionException)2 Named (javax.inject.Named)2 MongodbServer (org.graylog.testing.containermatrix.MongodbServer)2 ContainerMatrixTestClassDescriptor (org.junit.jupiter.engine.descriptor.ContainerMatrixTestClassDescriptor)2 ContainerMatrixTestsDescriptor (org.junit.jupiter.engine.descriptor.ContainerMatrixTestsDescriptor)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 Duration (com.github.joschi.jadconfig.util.Duration)1 Attempt (com.github.rholder.retry.Attempt)1 RetryException (com.github.rholder.retry.RetryException)1