From 927db108936b600c22419e6c1b0aeeffbee85b9c Mon Sep 17 00:00:00 2001 From: Vamsi Manohar <reddyvam@amazon.com> Date: Thu, 21 Sep 2023 17:00:03 -0700 Subject: [PATCH 1/3] Fix mockito core Signed-off-by: Vamsi Manohar <reddyvam@amazon.com> --- plugin/build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugin/build.gradle b/plugin/build.gradle index 9e2011059d..53d2e21f10 100644 --- a/plugin/build.gradle +++ b/plugin/build.gradle @@ -152,8 +152,8 @@ dependencies { testImplementation group: 'net.bytebuddy', name: 'byte-buddy-agent', version: '1.12.13' testImplementation group: 'org.hamcrest', name: 'hamcrest-library', version: '2.1' - testImplementation group: 'org.mockito', name: 'mockito-core', version: '5.4.0' - testImplementation group: 'org.mockito', name: 'mockito-junit-jupiter', version: '5.4.0' + testImplementation group: 'org.mockito', name: 'mockito-core', version: '5.5.0' + testImplementation group: 'org.mockito', name: 'mockito-junit-jupiter', version: '5.5.0' testImplementation 'org.junit.jupiter:junit-jupiter:5.6.2' } From 086bc747d01727785f67d8d242b1579b7005cf22 Mon Sep 17 00:00:00 2001 From: Vamsi Manohar <reddyvam@amazon.com> Date: Thu, 21 Sep 2023 17:23:42 -0700 Subject: [PATCH 2/3] Use mockito version from core Signed-off-by: Vamsi Manohar <reddyvam@amazon.com> --- plugin/build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugin/build.gradle b/plugin/build.gradle index 53d2e21f10..6b6706391a 100644 --- a/plugin/build.gradle +++ b/plugin/build.gradle @@ -152,8 +152,8 @@ dependencies { testImplementation group: 'net.bytebuddy', name: 'byte-buddy-agent', version: '1.12.13' testImplementation group: 'org.hamcrest', name: 'hamcrest-library', version: '2.1' - testImplementation group: 'org.mockito', name: 'mockito-core', version: '5.5.0' - testImplementation group: 'org.mockito', name: 'mockito-junit-jupiter', version: '5.5.0' + testImplementation group: 'org.mockito', name: 'mockito-core', version: "${versions.mockito}" + testImplementation group: 'org.mockito', name: 'mockito-junit-jupiter', version: "${versions.mockito}" testImplementation 'org.junit.jupiter:junit-jupiter:5.6.2' } From 34f5a1166da70a01b1077d6dc690faba4892ef08 Mon Sep 17 00:00:00 2001 From: Vamsi Manohar <reddyvam@amazon.com> Date: Thu, 21 Sep 2023 18:23:31 -0700 Subject: [PATCH 3/3] Add datasource description Signed-off-by: Vamsi Manohar <reddyvam@amazon.com> --- .../datasource/model/DataSourceMetadata.java | 25 +++++++++++++++++-- .../utils/XContentParserUtils.java | 9 ++++++- .../utils/XContentParserUtilsTest.java | 2 +- .../sql/datasource/DataSourceAPIsIT.java | 3 +++ 4 files changed, 35 insertions(+), 4 deletions(-) diff --git a/core/src/main/java/org/opensearch/sql/datasource/model/DataSourceMetadata.java b/core/src/main/java/org/opensearch/sql/datasource/model/DataSourceMetadata.java index 8e5ff7e1a6..a61f5a7a20 100644 --- a/core/src/main/java/org/opensearch/sql/datasource/model/DataSourceMetadata.java +++ b/core/src/main/java/org/opensearch/sql/datasource/model/DataSourceMetadata.java @@ -11,26 +11,29 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.google.common.collect.ImmutableMap; +import java.util.ArrayList; import java.util.Collections; +import java.util.HashMap; import java.util.List; import java.util.Map; import lombok.AllArgsConstructor; import lombok.EqualsAndHashCode; import lombok.Getter; -import lombok.NoArgsConstructor; import lombok.Setter; +import org.apache.commons.lang3.StringUtils; import org.opensearch.sql.datasource.DataSourceService; @Getter @Setter @AllArgsConstructor -@NoArgsConstructor @EqualsAndHashCode @JsonIgnoreProperties(ignoreUnknown = true) public class DataSourceMetadata { @JsonProperty private String name; + @JsonProperty private String description; + @JsonProperty @JsonFormat(with = JsonFormat.Feature.ACCEPT_CASE_INSENSITIVE_PROPERTIES) private DataSourceType connector; @@ -39,6 +42,24 @@ public class DataSourceMetadata { @JsonProperty private Map<String, String> properties; + public DataSourceMetadata( + String name, + DataSourceType connector, + List<String> allowedRoles, + Map<String, String> properties) { + this.name = name; + this.connector = connector; + this.description = StringUtils.EMPTY; + this.properties = properties; + this.allowedRoles = allowedRoles; + } + + public DataSourceMetadata() { + this.description = StringUtils.EMPTY; + this.allowedRoles = new ArrayList<>(); + this.properties = new HashMap<>(); + } + /** * Default OpenSearch {@link DataSourceMetadata}. Which is used to register default OpenSearch * {@link DataSource} to {@link DataSourceService}. diff --git a/datasources/src/main/java/org/opensearch/sql/datasources/utils/XContentParserUtils.java b/datasources/src/main/java/org/opensearch/sql/datasources/utils/XContentParserUtils.java index 1ad79addac..53f0054dc2 100644 --- a/datasources/src/main/java/org/opensearch/sql/datasources/utils/XContentParserUtils.java +++ b/datasources/src/main/java/org/opensearch/sql/datasources/utils/XContentParserUtils.java @@ -13,6 +13,7 @@ import java.util.List; import java.util.Map; import lombok.experimental.UtilityClass; +import org.apache.commons.lang3.StringUtils; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.common.xcontent.XContentType; import org.opensearch.core.xcontent.DeprecationHandler; @@ -26,6 +27,7 @@ @UtilityClass public class XContentParserUtils { public static final String NAME_FIELD = "name"; + public static final String DESCRIPTION_FIELD = "description"; public static final String CONNECTOR_FIELD = "connector"; public static final String PROPERTIES_FIELD = "properties"; public static final String ALLOWED_ROLES_FIELD = "allowedRoles"; @@ -39,6 +41,7 @@ public class XContentParserUtils { */ public static DataSourceMetadata toDataSourceMetadata(XContentParser parser) throws IOException { String name = null; + String description = StringUtils.EMPTY; DataSourceType connector = null; List<String> allowedRoles = new ArrayList<>(); Map<String, String> properties = new HashMap<>(); @@ -50,6 +53,9 @@ public static DataSourceMetadata toDataSourceMetadata(XContentParser parser) thr case NAME_FIELD: name = parser.textOrNull(); break; + case DESCRIPTION_FIELD: + description = parser.textOrNull(); + break; case CONNECTOR_FIELD: connector = DataSourceType.fromString(parser.textOrNull()); break; @@ -74,7 +80,7 @@ public static DataSourceMetadata toDataSourceMetadata(XContentParser parser) thr if (name == null || connector == null) { throw new IllegalArgumentException("name and connector are required fields."); } - return new DataSourceMetadata(name, connector, allowedRoles, properties); + return new DataSourceMetadata(name, description, connector, allowedRoles, properties); } /** @@ -108,6 +114,7 @@ public static XContentBuilder convertToXContent(DataSourceMetadata metadata) thr XContentBuilder builder = XContentFactory.jsonBuilder(); builder.startObject(); builder.field(NAME_FIELD, metadata.getName()); + builder.field(DESCRIPTION_FIELD, metadata.getDescription()); builder.field(CONNECTOR_FIELD, metadata.getConnector().name()); builder.field(ALLOWED_ROLES_FIELD, metadata.getAllowedRoles().toArray()); builder.startObject(PROPERTIES_FIELD); diff --git a/datasources/src/test/java/org/opensearch/sql/datasources/utils/XContentParserUtilsTest.java b/datasources/src/test/java/org/opensearch/sql/datasources/utils/XContentParserUtilsTest.java index c0c05c0282..eab0b8e168 100644 --- a/datasources/src/test/java/org/opensearch/sql/datasources/utils/XContentParserUtilsTest.java +++ b/datasources/src/test/java/org/opensearch/sql/datasources/utils/XContentParserUtilsTest.java @@ -31,7 +31,7 @@ public void testConvertToXContent() { XContentBuilder contentBuilder = XContentParserUtils.convertToXContent(dataSourceMetadata); String contentString = BytesReference.bytes(contentBuilder).utf8ToString(); Assertions.assertEquals( - "{\"name\":\"testDS\",\"connector\":\"PROMETHEUS\",\"allowedRoles\":[\"prometheus_access\"],\"properties\":{\"prometheus.uri\":\"https://localhost:9090\"}}", + "{\"name\":\"testDS\",\"description\":\"\",\"connector\":\"PROMETHEUS\",\"allowedRoles\":[\"prometheus_access\"],\"properties\":{\"prometheus.uri\":\"https://localhost:9090\"}}", contentString); } diff --git a/integ-test/src/test/java/org/opensearch/sql/datasource/DataSourceAPIsIT.java b/integ-test/src/test/java/org/opensearch/sql/datasource/DataSourceAPIsIT.java index e1d071d522..312f2b685a 100644 --- a/integ-test/src/test/java/org/opensearch/sql/datasource/DataSourceAPIsIT.java +++ b/integ-test/src/test/java/org/opensearch/sql/datasource/DataSourceAPIsIT.java @@ -51,6 +51,7 @@ public void createDataSourceAPITest() { DataSourceMetadata createDSM = new DataSourceMetadata( "create_prometheus", + "Prometheus Creation for Integ test", DataSourceType.PROMETHEUS, ImmutableList.of(), ImmutableMap.of( @@ -79,6 +80,7 @@ public void createDataSourceAPITest() { new Gson().fromJson(getResponseString, DataSourceMetadata.class); Assert.assertEquals( "https://localhost:9090", dataSourceMetadata.getProperties().get("prometheus.uri")); + Assert.assertEquals("Prometheus Creation for Integ test", dataSourceMetadata.getDescription()); } @SneakyThrows @@ -142,6 +144,7 @@ public void updateDataSourceAPITest() { new Gson().fromJson(getResponseString, DataSourceMetadata.class); Assert.assertEquals( "https://randomtest.com:9090", dataSourceMetadata.getProperties().get("prometheus.uri")); + Assert.assertEquals("", dataSourceMetadata.getDescription()); } @SneakyThrows