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"));
}
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]"));
}
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() + "]"));
}
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);
}
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]"));
}
}
Aggregations