-
Notifications
You must be signed in to change notification settings - Fork 331
Fix issue 5106 #5501
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
dlvenable
merged 4 commits into
opensearch-project:main
from
fidelity-contributions:fix-issue-5106
Apr 17, 2025
Merged
Fix issue 5106 #5501
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
f4545d9
Fix validation of pipeline's sink routes #5106
saketh-pallempati cfe5376
Fix Router_ThreeRoutesDefaultIT according to the new Conditional Rout…
saketh-pallempati 7f39895
Added Null validation and Custom Exception along with few more Test c…
saketh-pallempati 0639b14
Fixed Spotless Format Error
saketh-pallempati File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
...ava/org/opensearch/dataprepper/pipeline/parser/InvalidPipelineConfigurationException.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| package org.opensearch.dataprepper.pipeline.parser; | ||
|
|
||
| /** | ||
| * Exception thrown when pipeline configuration validation fails. | ||
| */ | ||
| public class InvalidPipelineConfigurationException extends RuntimeException { | ||
| public InvalidPipelineConfigurationException(String message) { | ||
| super(message); | ||
| } | ||
|
|
||
| public InvalidPipelineConfigurationException(String message, Throwable cause) { | ||
| super(message, cause); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
116 changes: 116 additions & 0 deletions
116
...est/java/org/opensearch/dataprepper/pipeline/parser/PipelineConfigurationValidatorIT.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,116 @@ | ||
| /* | ||
| * Copyright OpenSearch Contributors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package org.opensearch.dataprepper.pipeline.parser; | ||
|
|
||
| import org.junit.jupiter.api.Test; | ||
| import org.junit.jupiter.api.extension.ExtendWith; | ||
| import org.mockito.junit.jupiter.MockitoExtension; | ||
| import org.opensearch.dataprepper.model.configuration.PipelinesDataFlowModel; | ||
| import org.opensearch.dataprepper.pipeline.parser.model.PipelineConfiguration; | ||
|
|
||
| import java.io.ByteArrayInputStream; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| import static org.hamcrest.Matchers.equalTo; | ||
| import static org.hamcrest.Matchers.hasSize; | ||
| import static org.hamcrest.MatcherAssert.assertThat; | ||
| import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; | ||
| import static org.junit.jupiter.api.Assertions.assertThrows; | ||
| import static org.mockito.Mockito.mock; | ||
| import static org.mockito.Mockito.when; | ||
|
|
||
| @ExtendWith(MockitoExtension.class) | ||
| public class PipelineConfigurationValidatorIT { | ||
| private static final String TEST_YAML_CONFIG = | ||
|
saketh-pallempati marked this conversation as resolved.
|
||
| "entry-pipeline:\n" + | ||
| " source:\n" + | ||
| " random:\n" + | ||
| " routes:\n" + | ||
| " - route_one: \"/my_route == 10\"\n" + | ||
| " - route_two: \"/my_route == 11\"\n" + | ||
| " sink:\n" + | ||
| " - pipeline:\n" + | ||
| " name: \"sub-pipeline-1\"\n" + | ||
| " routes:\n" + | ||
| " - FIRST_ROUTE\n" + | ||
| " - pipeline:\n" + | ||
| " name: \"sub-pipeline-2\"\n" + | ||
| " routes:\n" + | ||
| " - SECOND_ROUTE\n"; | ||
|
|
||
| private static final String SIMPLE_PIPELINE_NO_ROUTES_CONFIG = | ||
| "entry-pipeline:\n" + | ||
| " source:\n" + | ||
| " random:\n" + | ||
| " sink:\n" + | ||
| " - stdout:\n"; | ||
|
|
||
| private static final String ROUTES_DEFINED_NO_SINK_ROUTES_CONFIG = | ||
| "entry-pipeline:\n" + | ||
| " source:\n" + | ||
| " random:\n" + | ||
| " routes:\n" + | ||
| " - route_one: \"/my_route == 10\"\n" + | ||
| " - route_two: \"/my_route == 11\"\n" + | ||
| " sink:\n" + | ||
| " - stdout:\n"; | ||
|
|
||
| @Test | ||
| public void test_with_invalid_sink_routes_in_yaml_should_throw() { | ||
| Map<String, PipelineConfiguration> pipelineConfigMap = getPipelineConfigMap(TEST_YAML_CONFIG); | ||
|
|
||
| InvalidPipelineConfigurationException exception = assertThrows(InvalidPipelineConfigurationException.class, () -> | ||
| PipelineConfigurationValidator.validateAndGetPipelineNames(pipelineConfigMap)); | ||
|
|
||
| String expectedErrorMessage = "The following routes do not exist in pipeline \"entry-pipeline\": " + | ||
| "[FIRST_ROUTE]. Configured routes include [route_one, route_two]"; | ||
|
|
||
| assertThat(exception.getMessage(), equalTo(expectedErrorMessage)); | ||
| } | ||
|
|
||
| @Test | ||
| public void test_simple_pipeline_with_no_routes_succeeds() { | ||
| Map<String, PipelineConfiguration> pipelineConfigMap = getPipelineConfigMap(SIMPLE_PIPELINE_NO_ROUTES_CONFIG); | ||
|
|
||
| List<String> pipelineNames = assertDoesNotThrow(() -> | ||
| PipelineConfigurationValidator.validateAndGetPipelineNames(pipelineConfigMap)); | ||
|
|
||
| assertThat(pipelineNames, hasSize(1)); | ||
| assertThat(pipelineNames.get(0), equalTo("entry-pipeline")); | ||
| } | ||
|
|
||
| @Test | ||
| public void test_routes_defined_but_no_routes_on_sinks_succeeds() { | ||
| Map<String, PipelineConfiguration> pipelineConfigMap = getPipelineConfigMap(ROUTES_DEFINED_NO_SINK_ROUTES_CONFIG); | ||
|
|
||
| List<String> pipelineNames = assertDoesNotThrow(() -> | ||
| PipelineConfigurationValidator.validateAndGetPipelineNames(pipelineConfigMap)); | ||
|
|
||
| assertThat(pipelineNames, hasSize(1)); | ||
| assertThat(pipelineNames.get(0), equalTo("entry-pipeline")); | ||
| } | ||
|
|
||
| /** | ||
| * Helper method to create a pipeline configuration map from a YAML string | ||
| */ | ||
| private Map<String, PipelineConfiguration> getPipelineConfigMap(final String yamlConfig) { | ||
| PipelineConfigurationReader configReader = mock(PipelineConfigurationReader.class); | ||
| when(configReader.getPipelineConfigurationInputStreams()) | ||
| .thenReturn(List.of(new ByteArrayInputStream(yamlConfig.getBytes()))); | ||
|
|
||
| PipelinesDataflowModelParser modelParser = new PipelinesDataflowModelParser(configReader); | ||
| PipelinesDataFlowModel dataFlowModel = modelParser.parseConfiguration(); | ||
|
|
||
| return dataFlowModel.getPipelines().entrySet() | ||
| .stream() | ||
| .collect(Collectors.toMap( | ||
| Map.Entry::getKey, | ||
| entry -> new PipelineConfiguration(entry.getValue()) | ||
| )); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.