Search in sources :

Example 96 with OpenSearchParseException

use of org.opensearch.OpenSearchParseException in project OpenSearch by opensearch-project.

the class SettingsTests method testIndentationWithExplicitDocumentStart.

public void testIndentationWithExplicitDocumentStart() throws Exception {
    String yaml = "/org/opensearch/common/settings/loader/indentation-with-explicit-document-start-settings.yml";
    OpenSearchParseException e = expectThrows(OpenSearchParseException.class, () -> {
        Settings.builder().loadFromStream(yaml, getClass().getResourceAsStream(yaml), false);
    });
    assertTrue(e.getMessage(), e.getMessage().contains("malformed"));
}
Also used : OpenSearchParseException(org.opensearch.OpenSearchParseException) Matchers.hasToString(org.hamcrest.Matchers.hasToString) Matchers.containsString(org.hamcrest.Matchers.containsString)

Example 97 with OpenSearchParseException

use of org.opensearch.OpenSearchParseException in project OpenSearch by opensearch-project.

the class SettingsTests method testMissingValue.

public void testMissingValue() throws Exception {
    Path tmp = createTempFile("test", ".yaml");
    Files.write(tmp, Collections.singletonList("foo: # missing value\n"), StandardCharsets.UTF_8);
    OpenSearchParseException e = expectThrows(OpenSearchParseException.class, () -> {
        Settings.builder().loadFromPath(tmp);
    });
    assertTrue(e.getMessage(), e.getMessage().contains("null-valued setting found for key [foo] found at line number [1], column number [5]"));
}
Also used : Path(java.nio.file.Path) OpenSearchParseException(org.opensearch.OpenSearchParseException)

Example 98 with OpenSearchParseException

use of org.opensearch.OpenSearchParseException in project OpenSearch by opensearch-project.

the class ConfigurationUtilsTests method testReadProcessorFromObjectOrMap.

public void testReadProcessorFromObjectOrMap() throws Exception {
    Processor processor = mock(Processor.class);
    Map<String, Processor.Factory> registry = Collections.singletonMap("script", (processorFactories, tag, description, config) -> {
        config.clear();
        return processor;
    });
    Object emptyConfig = Collections.emptyMap();
    Processor processor1 = ConfigurationUtils.readProcessor(registry, scriptService, "script", emptyConfig);
    assertThat(processor1, sameInstance(processor));
    Object inlineScript = "test_script";
    Processor processor2 = ConfigurationUtils.readProcessor(registry, scriptService, "script", inlineScript);
    assertThat(processor2, sameInstance(processor));
    Object invalidConfig = 12L;
    OpenSearchParseException ex = expectThrows(OpenSearchParseException.class, () -> ConfigurationUtils.readProcessor(registry, scriptService, "unknown_processor", invalidConfig));
    assertThat(ex.getMessage(), equalTo("property isn't a map, but of type [" + invalidConfig.getClass().getName() + "]"));
}
Also used : OpenSearchParseException(org.opensearch.OpenSearchParseException) Mockito.anyString(org.mockito.Mockito.anyString)

Example 99 with OpenSearchParseException

use of org.opensearch.OpenSearchParseException in project OpenSearch by opensearch-project.

the class IngestServiceTests method testValidate.

public void testValidate() throws Exception {
    IngestService ingestService = createWithProcessors();
    PutPipelineRequest putRequest = new PutPipelineRequest("_id", new BytesArray("{\"processors\": [{\"set\" : {\"field\": \"_field\", \"value\": \"_value\", \"tag\": \"tag1\"}}," + "{\"remove\" : {\"field\": \"_field\", \"tag\": \"tag2\"}}]}"), XContentType.JSON);
    DiscoveryNode node1 = new DiscoveryNode("_node_id1", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT);
    DiscoveryNode node2 = new DiscoveryNode("_node_id2", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT);
    Map<DiscoveryNode, IngestInfo> ingestInfos = new HashMap<>();
    ingestInfos.put(node1, new IngestInfo(Arrays.asList(new ProcessorInfo("set"), new ProcessorInfo("remove"))));
    ingestInfos.put(node2, new IngestInfo(Arrays.asList(new ProcessorInfo("set"))));
    OpenSearchParseException e = expectThrows(OpenSearchParseException.class, () -> ingestService.validatePipeline(ingestInfos, putRequest));
    assertEquals("Processor type [remove] is not installed on node [" + node2 + "]", e.getMessage());
    assertEquals("remove", e.getMetadata("opensearch.processor_type").get(0));
    assertEquals("tag2", e.getMetadata("opensearch.processor_tag").get(0));
    ingestInfos.put(node2, new IngestInfo(Arrays.asList(new ProcessorInfo("set"), new ProcessorInfo("remove"))));
    ingestService.validatePipeline(ingestInfos, putRequest);
}
Also used : BytesArray(org.opensearch.common.bytes.BytesArray) DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) OpenSearchParseException(org.opensearch.OpenSearchParseException) HashMap(java.util.HashMap) PutPipelineRequest(org.opensearch.action.ingest.PutPipelineRequest)

Example 100 with OpenSearchParseException

use of org.opensearch.OpenSearchParseException in project OpenSearch by opensearch-project.

the class RepositoryDataTests method testIndexThatReferencesAnUnknownSnapshot.

public void testIndexThatReferencesAnUnknownSnapshot() throws IOException {
    final XContent xContent = randomFrom(XContentType.values()).xContent();
    final RepositoryData repositoryData = generateRandomRepoData();
    XContentBuilder builder = XContentBuilder.builder(xContent);
    repositoryData.snapshotsToXContent(builder, Version.CURRENT);
    RepositoryData parsedRepositoryData;
    try (XContentParser xParser = createParser(builder)) {
        parsedRepositoryData = RepositoryData.snapshotsFromXContent(xParser, repositoryData.getGenId(), randomBoolean());
    }
    assertEquals(repositoryData, parsedRepositoryData);
    Map<String, SnapshotId> snapshotIds = new HashMap<>();
    Map<String, SnapshotState> snapshotStates = new HashMap<>();
    Map<String, Version> snapshotVersions = new HashMap<>();
    for (SnapshotId snapshotId : parsedRepositoryData.getSnapshotIds()) {
        snapshotIds.put(snapshotId.getUUID(), snapshotId);
        snapshotStates.put(snapshotId.getUUID(), parsedRepositoryData.getSnapshotState(snapshotId));
        snapshotVersions.put(snapshotId.getUUID(), parsedRepositoryData.getVersion(snapshotId));
    }
    final IndexId corruptedIndexId = randomFrom(parsedRepositoryData.getIndices().values());
    Map<IndexId, List<SnapshotId>> indexSnapshots = new HashMap<>();
    final ShardGenerations.Builder shardGenBuilder = ShardGenerations.builder();
    for (Map.Entry<String, IndexId> snapshottedIndex : parsedRepositoryData.getIndices().entrySet()) {
        IndexId indexId = snapshottedIndex.getValue();
        List<SnapshotId> snapshotsIds = new ArrayList<>(parsedRepositoryData.getSnapshots(indexId));
        if (corruptedIndexId.equals(indexId)) {
            snapshotsIds.add(new SnapshotId("_uuid", "_does_not_exist"));
        }
        indexSnapshots.put(indexId, snapshotsIds);
        final int shardCount = randomIntBetween(1, 10);
        for (int i = 0; i < shardCount; ++i) {
            shardGenBuilder.put(indexId, i, UUIDs.randomBase64UUID(random()));
        }
    }
    assertNotNull(corruptedIndexId);
    RepositoryData corruptedRepositoryData = new RepositoryData(parsedRepositoryData.getGenId(), snapshotIds, snapshotStates, snapshotVersions, indexSnapshots, shardGenBuilder.build(), IndexMetaDataGenerations.EMPTY);
    final XContentBuilder corruptedBuilder = XContentBuilder.builder(xContent);
    corruptedRepositoryData.snapshotsToXContent(corruptedBuilder, Version.CURRENT);
    try (XContentParser xParser = createParser(corruptedBuilder)) {
        OpenSearchParseException e = expectThrows(OpenSearchParseException.class, () -> RepositoryData.snapshotsFromXContent(xParser, corruptedRepositoryData.getGenId(), randomBoolean()));
        assertThat(e.getMessage(), equalTo("Detected a corrupted repository, index " + corruptedIndexId + " references an unknown " + "snapshot uuid [_does_not_exist]"));
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) SnapshotId(org.opensearch.snapshots.SnapshotId) SnapshotState(org.opensearch.snapshots.SnapshotState) OpenSearchParseException(org.opensearch.OpenSearchParseException) Version(org.opensearch.Version) XContent(org.opensearch.common.xcontent.XContent) JsonXContent(org.opensearch.common.xcontent.json.JsonXContent) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) XContentBuilder(org.opensearch.common.xcontent.XContentBuilder) XContentParser(org.opensearch.common.xcontent.XContentParser)

Aggregations

OpenSearchParseException (org.opensearch.OpenSearchParseException)105 XContentParser (org.opensearch.common.xcontent.XContentParser)34 HashMap (java.util.HashMap)27 XContentBuilder (org.opensearch.common.xcontent.XContentBuilder)15 ArrayList (java.util.ArrayList)14 Matchers.containsString (org.hamcrest.Matchers.containsString)12 Map (java.util.Map)11 IOException (java.io.IOException)10 List (java.util.List)7 ParsingException (org.opensearch.common.ParsingException)5 GeoPoint (org.opensearch.common.geo.GeoPoint)5 Token (org.opensearch.common.xcontent.XContentParser.Token)5 MappedFieldType (org.opensearch.index.mapper.MappedFieldType)5 GeometryCollectionBuilder (org.opensearch.common.geo.builders.GeometryCollectionBuilder)4 UncheckedIOException (java.io.UncheckedIOException)3 DateTimeParseException (java.time.format.DateTimeParseException)3 HashSet (java.util.HashSet)3 CoordinatesBuilder (org.opensearch.common.geo.builders.CoordinatesBuilder)3 MultiPointBuilder (org.opensearch.common.geo.builders.MultiPointBuilder)3 PointBuilder (org.opensearch.common.geo.builders.PointBuilder)3