-
Notifications
You must be signed in to change notification settings - Fork 141
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
Fix response codes returned by JSON formatting them #2156
Merged
Merged
Changes from 5 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
75e9f04
Glue datasource support (#2055)
vmmusings cda01e9
Initial commit of new job APIs (#2050)
vmmusings 71f4155
Create Job API (#2070)
vmmusings be82714
Cancel Job API (#2126)
vmmusings 6783ed7
Fix response codes returned
derek-ho 96f3ef0
Remove @opensearch datasource, update with new type
derek-ho fb2281e
Spotless Apply
derek-ho 9c5ffb8
Fix tests
derek-ho 03aba02
Revert change back to json string
derek-ho 767a9cb
Update tests to use JSON string literal instead of formatting
derek-ho e772fde
Update IT
derek-ho 0e37dca
Fix show datsources IT
derek-ho 4363d4d
Merge remote-tracking branch 'remote/main' into fix-response-code
derek-ho 97b8985
Remove files from merge
derek-ho 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 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
56 changes: 56 additions & 0 deletions
56
datasources/src/main/java/org/opensearch/sql/datasources/glue/GlueDataSourceFactory.java
This file contains 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,56 @@ | ||
package org.opensearch.sql.datasources.glue; | ||
|
||
import java.net.URISyntaxException; | ||
import java.net.UnknownHostException; | ||
import java.util.Map; | ||
import java.util.Set; | ||
import lombok.RequiredArgsConstructor; | ||
import org.opensearch.sql.common.setting.Settings; | ||
import org.opensearch.sql.datasource.model.DataSource; | ||
import org.opensearch.sql.datasource.model.DataSourceMetadata; | ||
import org.opensearch.sql.datasource.model.DataSourceType; | ||
import org.opensearch.sql.datasources.utils.DatasourceValidationUtils; | ||
import org.opensearch.sql.storage.DataSourceFactory; | ||
|
||
@RequiredArgsConstructor | ||
public class GlueDataSourceFactory implements DataSourceFactory { | ||
|
||
private final Settings pluginSettings; | ||
|
||
// Glue configuration properties | ||
public static final String GLUE_AUTH_TYPE = "glue.auth.type"; | ||
public static final String GLUE_ROLE_ARN = "glue.auth.role_arn"; | ||
public static final String FLINT_URI = "glue.indexstore.opensearch.uri"; | ||
public static final String FLINT_AUTH = "glue.indexstore.opensearch.auth"; | ||
public static final String FLINT_REGION = "glue.indexstore.opensearch.region"; | ||
|
||
@Override | ||
public DataSourceType getDataSourceType() { | ||
return DataSourceType.S3GLUE; | ||
} | ||
|
||
@Override | ||
public DataSource createDataSource(DataSourceMetadata metadata) { | ||
try { | ||
validateGlueDataSourceConfiguration(metadata.getProperties()); | ||
return new DataSource( | ||
metadata.getName(), | ||
metadata.getConnector(), | ||
(dataSourceSchemaName, tableName) -> { | ||
throw new UnsupportedOperationException("Glue storage engine is not supported."); | ||
}); | ||
} catch (URISyntaxException | UnknownHostException e) { | ||
throw new IllegalArgumentException("Invalid flint host in properties."); | ||
} | ||
} | ||
|
||
private void validateGlueDataSourceConfiguration(Map<String, String> dataSourceMetadataConfig) | ||
throws URISyntaxException, UnknownHostException { | ||
DatasourceValidationUtils.validateLengthAndRequiredFields( | ||
dataSourceMetadataConfig, | ||
Set.of(GLUE_AUTH_TYPE, GLUE_ROLE_ARN, FLINT_URI, FLINT_REGION, FLINT_AUTH)); | ||
DatasourceValidationUtils.validateHost( | ||
dataSourceMetadataConfig.get(FLINT_URI), | ||
pluginSettings.getSettingValue(Settings.Key.DATASOURCES_URI_HOSTS_DENY_LIST)); | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
115 changes: 115 additions & 0 deletions
115
datasources/src/test/java/org/opensearch/sql/datasources/glue/GlueDataSourceFactoryTest.java
This file contains 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,115 @@ | ||
package org.opensearch.sql.datasources.glue; | ||
|
||
import static org.mockito.Mockito.when; | ||
|
||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import lombok.SneakyThrows; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
import org.opensearch.sql.DataSourceSchemaName; | ||
import org.opensearch.sql.common.setting.Settings; | ||
import org.opensearch.sql.datasource.model.DataSource; | ||
import org.opensearch.sql.datasource.model.DataSourceMetadata; | ||
import org.opensearch.sql.datasource.model.DataSourceType; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
public class GlueDataSourceFactoryTest { | ||
|
||
@Mock private Settings settings; | ||
|
||
@Test | ||
void testGetConnectorType() { | ||
GlueDataSourceFactory glueDatasourceFactory = new GlueDataSourceFactory(settings); | ||
Assertions.assertEquals(DataSourceType.S3GLUE, glueDatasourceFactory.getDataSourceType()); | ||
} | ||
|
||
@Test | ||
@SneakyThrows | ||
void testCreateGLueDatSource() { | ||
when(settings.getSettingValue(Settings.Key.DATASOURCES_URI_HOSTS_DENY_LIST)) | ||
.thenReturn(Collections.emptyList()); | ||
GlueDataSourceFactory glueDatasourceFactory = new GlueDataSourceFactory(settings); | ||
|
||
DataSourceMetadata metadata = new DataSourceMetadata(); | ||
HashMap<String, String> properties = new HashMap<>(); | ||
properties.put("glue.auth.type", "iam_role"); | ||
properties.put("glue.auth.role_arn", "role_arn"); | ||
properties.put("glue.indexstore.opensearch.uri", "http://localhost:9200"); | ||
properties.put("glue.indexstore.opensearch.auth", "false"); | ||
properties.put("glue.indexstore.opensearch.region", "us-west-2"); | ||
|
||
metadata.setName("my_glue"); | ||
metadata.setConnector(DataSourceType.S3GLUE); | ||
metadata.setProperties(properties); | ||
DataSource dataSource = glueDatasourceFactory.createDataSource(metadata); | ||
Assertions.assertEquals(DataSourceType.S3GLUE, dataSource.getConnectorType()); | ||
UnsupportedOperationException unsupportedOperationException = | ||
Assertions.assertThrows( | ||
UnsupportedOperationException.class, | ||
() -> | ||
dataSource | ||
.getStorageEngine() | ||
.getTable(new DataSourceSchemaName("my_glue", "default"), "alb_logs")); | ||
Assertions.assertEquals( | ||
"Glue storage engine is not supported.", unsupportedOperationException.getMessage()); | ||
} | ||
|
||
@Test | ||
@SneakyThrows | ||
void testCreateGLueDatSourceWithInvalidFlintHost() { | ||
when(settings.getSettingValue(Settings.Key.DATASOURCES_URI_HOSTS_DENY_LIST)) | ||
.thenReturn(List.of("127.0.0.0/8")); | ||
GlueDataSourceFactory glueDatasourceFactory = new GlueDataSourceFactory(settings); | ||
|
||
DataSourceMetadata metadata = new DataSourceMetadata(); | ||
HashMap<String, String> properties = new HashMap<>(); | ||
properties.put("glue.auth.type", "iam_role"); | ||
properties.put("glue.auth.role_arn", "role_arn"); | ||
properties.put("glue.indexstore.opensearch.uri", "http://localhost:9200"); | ||
properties.put("glue.indexstore.opensearch.auth", "false"); | ||
properties.put("glue.indexstore.opensearch.region", "us-west-2"); | ||
|
||
metadata.setName("my_glue"); | ||
metadata.setConnector(DataSourceType.S3GLUE); | ||
metadata.setProperties(properties); | ||
IllegalArgumentException illegalArgumentException = | ||
Assertions.assertThrows( | ||
IllegalArgumentException.class, () -> glueDatasourceFactory.createDataSource(metadata)); | ||
Assertions.assertEquals( | ||
"Disallowed hostname in the uri. " | ||
+ "Validate with plugins.query.datasources.uri.hosts.denylist config", | ||
illegalArgumentException.getMessage()); | ||
} | ||
|
||
@Test | ||
@SneakyThrows | ||
void testCreateGLueDatSourceWithInvalidFlintHostSyntax() { | ||
when(settings.getSettingValue(Settings.Key.DATASOURCES_URI_HOSTS_DENY_LIST)) | ||
.thenReturn(List.of("127.0.0.0/8")); | ||
GlueDataSourceFactory glueDatasourceFactory = new GlueDataSourceFactory(settings); | ||
|
||
DataSourceMetadata metadata = new DataSourceMetadata(); | ||
HashMap<String, String> properties = new HashMap<>(); | ||
properties.put("glue.auth.type", "iam_role"); | ||
properties.put("glue.auth.role_arn", "role_arn"); | ||
properties.put( | ||
"glue.indexstore.opensearch.uri", | ||
"http://dummyprometheus.com:9090? paramt::localhost:9200"); | ||
properties.put("glue.indexstore.opensearch.auth", "false"); | ||
properties.put("glue.indexstore.opensearch.region", "us-west-2"); | ||
|
||
metadata.setName("my_glue"); | ||
metadata.setConnector(DataSourceType.S3GLUE); | ||
metadata.setProperties(properties); | ||
IllegalArgumentException illegalArgumentException = | ||
Assertions.assertThrows( | ||
IllegalArgumentException.class, () -> glueDatasourceFactory.createDataSource(metadata)); | ||
Assertions.assertEquals( | ||
"Invalid flint host in properties.", illegalArgumentException.getMessage()); | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just return string in json format, not schema required?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reasoning behind this change was to have a response class and later on, if we have time we can do something like return the DataSourceMetadata that was Updated/Created. Don't think we will have time for that/I don't know what the standard is for SQL repo - but I reverted it back to just a JSON string for now - it should be fine as long as the UI can parse it.