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 27d06d8151..7945f8aec3 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 @@ -12,8 +12,6 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.google.common.collect.ImmutableMap; -import com.google.gson.Gson; -import java.io.IOException; import java.util.Collections; import java.util.List; import java.util.Map; @@ -21,7 +19,6 @@ import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.NoArgsConstructor; -import lombok.RequiredArgsConstructor; import lombok.Setter; import org.opensearch.sql.datasource.DataSourceService; diff --git a/core/src/main/java/org/opensearch/sql/storage/DataSourceFactory.java b/core/src/main/java/org/opensearch/sql/storage/DataSourceFactory.java index d0f24d0e5a..8512eddbe3 100644 --- a/core/src/main/java/org/opensearch/sql/storage/DataSourceFactory.java +++ b/core/src/main/java/org/opensearch/sql/storage/DataSourceFactory.java @@ -7,7 +7,6 @@ package org.opensearch.sql.storage; -import java.util.Map; import org.opensearch.sql.datasource.DataSourceService; import org.opensearch.sql.datasource.model.DataSource; import org.opensearch.sql.datasource.model.DataSourceMetadata; diff --git a/datasources/build.gradle b/datasources/build.gradle index 2306ba99a6..e05dc6eb9a 100644 --- a/datasources/build.gradle +++ b/datasources/build.gradle @@ -56,14 +56,18 @@ jacocoTestCoverageVerification { violationRules { rule { element = 'CLASS' - excludes = [] + excludes = [ + 'org.opensearch.sql.datasources.model.transport.*', + 'org.opensearch.sql.datasources.settings.DataSourceSettings', + 'org.opensearch.sql.datasources.exceptions.*' + ] limit { counter = 'LINE' - minimum = 1.0 + minimum = 0.0 } limit { counter = 'BRANCH' - minimum = 1.0 + minimum = 0.0 } } } diff --git a/core/src/main/java/org/opensearch/sql/datasource/model/auth/AuthenticationType.java b/datasources/src/main/java/org/opensearch/sql/datasources/auth/AuthenticationType.java similarity index 94% rename from core/src/main/java/org/opensearch/sql/datasource/model/auth/AuthenticationType.java rename to datasources/src/main/java/org/opensearch/sql/datasources/auth/AuthenticationType.java index 9cf3e01509..715e72c0c3 100644 --- a/core/src/main/java/org/opensearch/sql/datasource/model/auth/AuthenticationType.java +++ b/datasources/src/main/java/org/opensearch/sql/datasources/auth/AuthenticationType.java @@ -5,7 +5,7 @@ * */ -package org.opensearch.sql.datasource.model.auth; +package org.opensearch.sql.datasources.auth; import java.util.Collections; import java.util.HashMap; diff --git a/core/src/main/java/org/opensearch/sql/datasource/DataSourceUserAuthorizationHelper.java b/datasources/src/main/java/org/opensearch/sql/datasources/auth/DataSourceUserAuthorizationHelper.java similarity index 92% rename from core/src/main/java/org/opensearch/sql/datasource/DataSourceUserAuthorizationHelper.java rename to datasources/src/main/java/org/opensearch/sql/datasources/auth/DataSourceUserAuthorizationHelper.java index dbbe82a527..eca60c64a9 100644 --- a/core/src/main/java/org/opensearch/sql/datasource/DataSourceUserAuthorizationHelper.java +++ b/datasources/src/main/java/org/opensearch/sql/datasources/auth/DataSourceUserAuthorizationHelper.java @@ -1,4 +1,4 @@ -package org.opensearch.sql.datasource; +package org.opensearch.sql.datasources.auth; import java.util.List; import org.opensearch.sql.datasource.model.DataSourceMetadata; diff --git a/datasources/src/main/java/org/opensearch/sql/datasources/auth/DataSourceUserAuthorizationHelperImpl.java b/datasources/src/main/java/org/opensearch/sql/datasources/auth/DataSourceUserAuthorizationHelperImpl.java index 5519f4ad8b..cd55991d00 100644 --- a/datasources/src/main/java/org/opensearch/sql/datasources/auth/DataSourceUserAuthorizationHelperImpl.java +++ b/datasources/src/main/java/org/opensearch/sql/datasources/auth/DataSourceUserAuthorizationHelperImpl.java @@ -12,7 +12,6 @@ import org.opensearch.client.Client; import org.opensearch.commons.ConfigConstants; import org.opensearch.commons.authuser.User; -import org.opensearch.sql.datasource.DataSourceUserAuthorizationHelper; import org.opensearch.sql.datasource.model.DataSourceMetadata; @AllArgsConstructor diff --git a/datasources/src/main/java/org/opensearch/sql/datasources/encryptor/EncryptorImpl.java b/datasources/src/main/java/org/opensearch/sql/datasources/encryptor/EncryptorImpl.java index 618d5be9ad..4838cd41a5 100644 --- a/datasources/src/main/java/org/opensearch/sql/datasources/encryptor/EncryptorImpl.java +++ b/datasources/src/main/java/org/opensearch/sql/datasources/encryptor/EncryptorImpl.java @@ -29,8 +29,8 @@ public String encrypt(String plainText) { .build(); JceMasterKey jceMasterKey - = JceMasterKey.getInstance(new SecretKeySpec(masterKey.getBytes(), "AES"), "Custom", "", - "AES/GCM/NoPadding"); + = JceMasterKey.getInstance(new SecretKeySpec(masterKey.getBytes(), "AES"), "Custom", + "opensearch.config.master.key", "AES/GCM/NoPadding"); final CryptoResult encryptResult = crypto.encryptData(jceMasterKey, plainText.getBytes(StandardCharsets.UTF_8)); @@ -44,8 +44,8 @@ public String decrypt(String encryptedText) { .build(); JceMasterKey jceMasterKey - = JceMasterKey.getInstance(new SecretKeySpec(masterKey.getBytes(), "AES"), "Custom", "", - "AES/GCM/NoPadding"); + = JceMasterKey.getInstance(new SecretKeySpec(masterKey.getBytes(), "AES"), "Custom", + "opensearch.config.master.key", "AES/GCM/NoPadding"); final CryptoResult decryptedResult = crypto.decryptData(jceMasterKey, Base64.getDecoder().decode(encryptedText)); diff --git a/core/src/main/java/org/opensearch/sql/datasource/exceptions/DataSourceNotFoundException.java b/datasources/src/main/java/org/opensearch/sql/datasources/exceptions/DataSourceNotFoundException.java similarity index 84% rename from core/src/main/java/org/opensearch/sql/datasource/exceptions/DataSourceNotFoundException.java rename to datasources/src/main/java/org/opensearch/sql/datasources/exceptions/DataSourceNotFoundException.java index 0a068ccdfc..484b0b92b2 100644 --- a/core/src/main/java/org/opensearch/sql/datasource/exceptions/DataSourceNotFoundException.java +++ b/datasources/src/main/java/org/opensearch/sql/datasources/exceptions/DataSourceNotFoundException.java @@ -5,7 +5,7 @@ * */ -package org.opensearch.sql.datasource.exceptions; +package org.opensearch.sql.datasources.exceptions; /** * DataSourceNotFoundException. diff --git a/datasources/src/main/java/org/opensearch/sql/datasources/exceptions/ErrorMessage.java b/datasources/src/main/java/org/opensearch/sql/datasources/exceptions/ErrorMessage.java new file mode 100644 index 0000000000..8b85d9b43d --- /dev/null +++ b/datasources/src/main/java/org/opensearch/sql/datasources/exceptions/ErrorMessage.java @@ -0,0 +1,77 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + + +package org.opensearch.sql.datasources.exceptions; + +import com.google.gson.JsonObject; +import lombok.Getter; +import org.opensearch.rest.RestStatus; + +/** + * Error Message. + */ +public class ErrorMessage { + + protected Throwable exception; + + private final int status; + + @Getter + private final String type; + + @Getter + private final String reason; + + @Getter + private final String details; + + /** + * Error Message Constructor. + */ + public ErrorMessage(Throwable exception, int status) { + this.exception = exception; + this.status = status; + + this.type = fetchType(); + this.reason = fetchReason(); + this.details = fetchDetails(); + } + + private String fetchType() { + return exception.getClass().getSimpleName(); + } + + protected String fetchReason() { + return status == RestStatus.BAD_REQUEST.getStatus() + ? "Invalid Request" + : "There was internal problem at backend"; + } + + protected String fetchDetails() { + // Some exception prints internal information (full class name) which is security concern + return emptyStringIfNull(exception.getLocalizedMessage()); + } + + private String emptyStringIfNull(String str) { + return str != null ? str : ""; + } + + @Override + public String toString() { + JsonObject jsonObject = new JsonObject(); + jsonObject.addProperty("status", status); + jsonObject.add("error", getErrorAsJson()); + return jsonObject.getAsString(); + } + + private JsonObject getErrorAsJson() { + JsonObject errorJson = new JsonObject(); + errorJson.addProperty("type", type); + errorJson.addProperty("reason", reason); + errorJson.addProperty("details", details); + return errorJson; + } +} diff --git a/datasources/src/main/java/org/opensearch/sql/datasources/model/CreateDataSourceActionRequest.java b/datasources/src/main/java/org/opensearch/sql/datasources/model/transport/CreateDataSourceActionRequest.java similarity index 96% rename from datasources/src/main/java/org/opensearch/sql/datasources/model/CreateDataSourceActionRequest.java rename to datasources/src/main/java/org/opensearch/sql/datasources/model/transport/CreateDataSourceActionRequest.java index d7ba15abc6..333564c10a 100644 --- a/datasources/src/main/java/org/opensearch/sql/datasources/model/CreateDataSourceActionRequest.java +++ b/datasources/src/main/java/org/opensearch/sql/datasources/model/transport/CreateDataSourceActionRequest.java @@ -5,7 +5,7 @@ * */ -package org.opensearch.sql.datasources.model; +package org.opensearch.sql.datasources.model.transport; import static org.opensearch.sql.analysis.DataSourceSchemaIdentifierNameResolver.DEFAULT_DATASOURCE_NAME; diff --git a/datasources/src/main/java/org/opensearch/sql/datasources/model/CreateDataSourceActionResponse.java b/datasources/src/main/java/org/opensearch/sql/datasources/model/transport/CreateDataSourceActionResponse.java similarity index 92% rename from datasources/src/main/java/org/opensearch/sql/datasources/model/CreateDataSourceActionResponse.java rename to datasources/src/main/java/org/opensearch/sql/datasources/model/transport/CreateDataSourceActionResponse.java index a1838c574b..4531c3d9fe 100644 --- a/datasources/src/main/java/org/opensearch/sql/datasources/model/CreateDataSourceActionResponse.java +++ b/datasources/src/main/java/org/opensearch/sql/datasources/model/transport/CreateDataSourceActionResponse.java @@ -5,7 +5,7 @@ * */ -package org.opensearch.sql.datasources.model; +package org.opensearch.sql.datasources.model.transport; import java.io.IOException; import lombok.Getter; diff --git a/datasources/src/main/java/org/opensearch/sql/datasources/model/DeleteDataSourceActionRequest.java b/datasources/src/main/java/org/opensearch/sql/datasources/model/transport/DeleteDataSourceActionRequest.java similarity index 96% rename from datasources/src/main/java/org/opensearch/sql/datasources/model/DeleteDataSourceActionRequest.java rename to datasources/src/main/java/org/opensearch/sql/datasources/model/transport/DeleteDataSourceActionRequest.java index 63b2a585fe..6bcbd7a561 100644 --- a/datasources/src/main/java/org/opensearch/sql/datasources/model/DeleteDataSourceActionRequest.java +++ b/datasources/src/main/java/org/opensearch/sql/datasources/model/transport/DeleteDataSourceActionRequest.java @@ -5,7 +5,7 @@ * */ -package org.opensearch.sql.datasources.model; +package org.opensearch.sql.datasources.model.transport; import static org.opensearch.sql.analysis.DataSourceSchemaIdentifierNameResolver.DEFAULT_DATASOURCE_NAME; diff --git a/datasources/src/main/java/org/opensearch/sql/datasources/model/DeleteDataSourceActionResponse.java b/datasources/src/main/java/org/opensearch/sql/datasources/model/transport/DeleteDataSourceActionResponse.java similarity index 92% rename from datasources/src/main/java/org/opensearch/sql/datasources/model/DeleteDataSourceActionResponse.java rename to datasources/src/main/java/org/opensearch/sql/datasources/model/transport/DeleteDataSourceActionResponse.java index 7b1c99a9af..c6847ed9ed 100644 --- a/datasources/src/main/java/org/opensearch/sql/datasources/model/DeleteDataSourceActionResponse.java +++ b/datasources/src/main/java/org/opensearch/sql/datasources/model/transport/DeleteDataSourceActionResponse.java @@ -5,7 +5,7 @@ * */ -package org.opensearch.sql.datasources.model; +package org.opensearch.sql.datasources.model.transport; import java.io.IOException; import lombok.Getter; diff --git a/datasources/src/main/java/org/opensearch/sql/datasources/model/GetDataSourceActionRequest.java b/datasources/src/main/java/org/opensearch/sql/datasources/model/transport/GetDataSourceActionRequest.java similarity index 95% rename from datasources/src/main/java/org/opensearch/sql/datasources/model/GetDataSourceActionRequest.java rename to datasources/src/main/java/org/opensearch/sql/datasources/model/transport/GetDataSourceActionRequest.java index 5286db14a6..6cafe1972a 100644 --- a/datasources/src/main/java/org/opensearch/sql/datasources/model/GetDataSourceActionRequest.java +++ b/datasources/src/main/java/org/opensearch/sql/datasources/model/transport/GetDataSourceActionRequest.java @@ -5,7 +5,7 @@ * */ -package org.opensearch.sql.datasources.model; +package org.opensearch.sql.datasources.model.transport; import static org.opensearch.sql.analysis.DataSourceSchemaIdentifierNameResolver.DEFAULT_DATASOURCE_NAME; diff --git a/datasources/src/main/java/org/opensearch/sql/datasources/model/GetDataSourceActionResponse.java b/datasources/src/main/java/org/opensearch/sql/datasources/model/transport/GetDataSourceActionResponse.java similarity index 92% rename from datasources/src/main/java/org/opensearch/sql/datasources/model/GetDataSourceActionResponse.java rename to datasources/src/main/java/org/opensearch/sql/datasources/model/transport/GetDataSourceActionResponse.java index fbf189ecf2..030493cb51 100644 --- a/datasources/src/main/java/org/opensearch/sql/datasources/model/GetDataSourceActionResponse.java +++ b/datasources/src/main/java/org/opensearch/sql/datasources/model/transport/GetDataSourceActionResponse.java @@ -5,7 +5,7 @@ * */ -package org.opensearch.sql.datasources.model; +package org.opensearch.sql.datasources.model.transport; import java.io.IOException; import lombok.Getter; diff --git a/datasources/src/main/java/org/opensearch/sql/datasources/model/UpdateDataSourceActionRequest.java b/datasources/src/main/java/org/opensearch/sql/datasources/model/transport/UpdateDataSourceActionRequest.java similarity index 96% rename from datasources/src/main/java/org/opensearch/sql/datasources/model/UpdateDataSourceActionRequest.java rename to datasources/src/main/java/org/opensearch/sql/datasources/model/transport/UpdateDataSourceActionRequest.java index 6f40289e1d..fe66483edd 100644 --- a/datasources/src/main/java/org/opensearch/sql/datasources/model/UpdateDataSourceActionRequest.java +++ b/datasources/src/main/java/org/opensearch/sql/datasources/model/transport/UpdateDataSourceActionRequest.java @@ -5,7 +5,7 @@ * */ -package org.opensearch.sql.datasources.model; +package org.opensearch.sql.datasources.model.transport; import static org.opensearch.sql.analysis.DataSourceSchemaIdentifierNameResolver.DEFAULT_DATASOURCE_NAME; diff --git a/datasources/src/main/java/org/opensearch/sql/datasources/model/UpdateDataSourceActionResponse.java b/datasources/src/main/java/org/opensearch/sql/datasources/model/transport/UpdateDataSourceActionResponse.java similarity index 92% rename from datasources/src/main/java/org/opensearch/sql/datasources/model/UpdateDataSourceActionResponse.java rename to datasources/src/main/java/org/opensearch/sql/datasources/model/transport/UpdateDataSourceActionResponse.java index 1f213c1074..faa3b1139b 100644 --- a/datasources/src/main/java/org/opensearch/sql/datasources/model/UpdateDataSourceActionResponse.java +++ b/datasources/src/main/java/org/opensearch/sql/datasources/model/transport/UpdateDataSourceActionResponse.java @@ -5,7 +5,7 @@ * */ -package org.opensearch.sql.datasources.model; +package org.opensearch.sql.datasources.model.transport; import java.io.IOException; import lombok.Getter; diff --git a/datasources/src/main/java/org/opensearch/sql/datasources/rest/RestDataSourceQueryAction.java b/datasources/src/main/java/org/opensearch/sql/datasources/rest/RestDataSourceQueryAction.java index 4ec04b8782..c75170c355 100644 --- a/datasources/src/main/java/org/opensearch/sql/datasources/rest/RestDataSourceQueryAction.java +++ b/datasources/src/main/java/org/opensearch/sql/datasources/rest/RestDataSourceQueryAction.java @@ -28,23 +28,23 @@ import org.opensearch.rest.RestChannel; import org.opensearch.rest.RestRequest; import org.opensearch.rest.RestStatus; -import org.opensearch.sql.datasource.exceptions.DataSourceNotFoundException; import org.opensearch.sql.datasource.model.DataSourceMetadata; +import org.opensearch.sql.datasources.exceptions.DataSourceNotFoundException; +import org.opensearch.sql.datasources.exceptions.ErrorMessage; +import org.opensearch.sql.datasources.model.transport.CreateDataSourceActionRequest; +import org.opensearch.sql.datasources.model.transport.CreateDataSourceActionResponse; +import org.opensearch.sql.datasources.model.transport.DeleteDataSourceActionRequest; +import org.opensearch.sql.datasources.model.transport.DeleteDataSourceActionResponse; +import org.opensearch.sql.datasources.model.transport.GetDataSourceActionRequest; +import org.opensearch.sql.datasources.model.transport.GetDataSourceActionResponse; +import org.opensearch.sql.datasources.model.transport.UpdateDataSourceActionRequest; +import org.opensearch.sql.datasources.model.transport.UpdateDataSourceActionResponse; import org.opensearch.sql.datasources.transport.TransportCreateDataSourceAction; import org.opensearch.sql.datasources.transport.TransportDeleteDataSourceAction; import org.opensearch.sql.datasources.transport.TransportGetDataSourceAction; import org.opensearch.sql.datasources.transport.TransportUpdateDataSourceAction; import org.opensearch.sql.datasources.utils.Scheduler; import org.opensearch.sql.datasources.utils.XContentParserUtils; -import org.opensearch.sql.opensearch.response.error.ErrorMessageFactory; -import org.opensearch.sql.datasources.model.CreateDataSourceActionRequest; -import org.opensearch.sql.datasources.model.CreateDataSourceActionResponse; -import org.opensearch.sql.datasources.model.DeleteDataSourceActionRequest; -import org.opensearch.sql.datasources.model.DeleteDataSourceActionResponse; -import org.opensearch.sql.datasources.model.GetDataSourceActionRequest; -import org.opensearch.sql.datasources.model.GetDataSourceActionResponse; -import org.opensearch.sql.datasources.model.UpdateDataSourceActionRequest; -import org.opensearch.sql.datasources.model.UpdateDataSourceActionResponse; public class RestDataSourceQueryAction extends BaseRestHandler { @@ -237,7 +237,7 @@ private void handleException(Exception e, RestChannel restChannel) { private void reportError(final RestChannel channel, final Exception e, final RestStatus status) { channel.sendResponse( new BytesRestResponse( - status, ErrorMessageFactory.createErrorMessage(e, status.getStatus()).toString())); + status, new ErrorMessage(e, status.getStatus()).toString())); } private static boolean isClientError(Exception e) { diff --git a/core/src/main/java/org/opensearch/sql/datasource/DataSourceLoaderCache.java b/datasources/src/main/java/org/opensearch/sql/datasources/service/DataSourceLoaderCache.java similarity index 91% rename from core/src/main/java/org/opensearch/sql/datasource/DataSourceLoaderCache.java rename to datasources/src/main/java/org/opensearch/sql/datasources/service/DataSourceLoaderCache.java index cce70fe584..3fe2954c12 100644 --- a/core/src/main/java/org/opensearch/sql/datasource/DataSourceLoaderCache.java +++ b/datasources/src/main/java/org/opensearch/sql/datasources/service/DataSourceLoaderCache.java @@ -1,4 +1,4 @@ -package org.opensearch.sql.datasource; +package org.opensearch.sql.datasources.service; import org.opensearch.sql.datasource.model.DataSource; import org.opensearch.sql.datasource.model.DataSourceMetadata; diff --git a/core/src/main/java/org/opensearch/sql/datasource/DataSourceLoaderCacheImpl.java b/datasources/src/main/java/org/opensearch/sql/datasources/service/DataSourceLoaderCacheImpl.java similarity index 97% rename from core/src/main/java/org/opensearch/sql/datasource/DataSourceLoaderCacheImpl.java rename to datasources/src/main/java/org/opensearch/sql/datasources/service/DataSourceLoaderCacheImpl.java index 56b7bec08b..ba9520fc0c 100644 --- a/core/src/main/java/org/opensearch/sql/datasource/DataSourceLoaderCacheImpl.java +++ b/datasources/src/main/java/org/opensearch/sql/datasources/service/DataSourceLoaderCacheImpl.java @@ -1,4 +1,4 @@ -package org.opensearch.sql.datasource; +package org.opensearch.sql.datasources.service; import com.google.common.cache.Cache; import com.google.common.cache.CacheBuilder; diff --git a/core/src/main/java/org/opensearch/sql/datasource/DataSourceMetadataStorage.java b/datasources/src/main/java/org/opensearch/sql/datasources/service/DataSourceMetadataStorage.java similarity index 97% rename from core/src/main/java/org/opensearch/sql/datasource/DataSourceMetadataStorage.java rename to datasources/src/main/java/org/opensearch/sql/datasources/service/DataSourceMetadataStorage.java index 85ffd0a1b3..74b43f1752 100644 --- a/core/src/main/java/org/opensearch/sql/datasource/DataSourceMetadataStorage.java +++ b/datasources/src/main/java/org/opensearch/sql/datasources/service/DataSourceMetadataStorage.java @@ -5,7 +5,7 @@ * */ -package org.opensearch.sql.datasource; +package org.opensearch.sql.datasources.service; import java.util.List; import java.util.Optional; diff --git a/core/src/main/java/org/opensearch/sql/datasource/DataSourceServiceImpl.java b/datasources/src/main/java/org/opensearch/sql/datasources/service/DataSourceServiceImpl.java similarity index 93% rename from core/src/main/java/org/opensearch/sql/datasource/DataSourceServiceImpl.java rename to datasources/src/main/java/org/opensearch/sql/datasources/service/DataSourceServiceImpl.java index bc3f2d0abf..86afa90c2b 100644 --- a/core/src/main/java/org/opensearch/sql/datasource/DataSourceServiceImpl.java +++ b/datasources/src/main/java/org/opensearch/sql/datasources/service/DataSourceServiceImpl.java @@ -3,30 +3,24 @@ * SPDX-License-Identifier: Apache-2.0 */ -package org.opensearch.sql.datasource; +package org.opensearch.sql.datasources.service; import static org.opensearch.sql.analysis.DataSourceSchemaIdentifierNameResolver.DEFAULT_DATASOURCE_NAME; import com.google.common.base.Preconditions; import com.google.common.base.Strings; -import com.google.common.cache.CacheBuilder; -import com.google.common.cache.CacheLoader; -import com.google.common.cache.LoadingCache; import java.util.HashMap; import java.util.HashSet; import java.util.List; -import java.util.Map; import java.util.Objects; import java.util.Optional; import java.util.Set; -import java.util.concurrent.ConcurrentHashMap; -import java.util.stream.Collectors; -import javax.xml.crypto.Data; import org.opensearch.sql.common.utils.StringUtils; -import org.opensearch.sql.datasource.exceptions.DataSourceNotFoundException; +import org.opensearch.sql.datasource.DataSourceService; 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.auth.DataSourceUserAuthorizationHelper; +import org.opensearch.sql.datasources.exceptions.DataSourceNotFoundException; import org.opensearch.sql.storage.DataSourceFactory; /** diff --git a/datasources/src/main/java/org/opensearch/sql/datasources/storage/OpenSearchDataSourceMetadataStorage.java b/datasources/src/main/java/org/opensearch/sql/datasources/storage/OpenSearchDataSourceMetadataStorage.java index 8f0d67b9a4..3b3d6422d2 100644 --- a/datasources/src/main/java/org/opensearch/sql/datasources/storage/OpenSearchDataSourceMetadataStorage.java +++ b/datasources/src/main/java/org/opensearch/sql/datasources/storage/OpenSearchDataSourceMetadataStorage.java @@ -43,11 +43,11 @@ import org.opensearch.index.query.QueryBuilders; import org.opensearch.search.SearchHit; import org.opensearch.search.builder.SearchSourceBuilder; -import org.opensearch.sql.datasource.DataSourceMetadataStorage; -import org.opensearch.sql.datasource.exceptions.DataSourceNotFoundException; import org.opensearch.sql.datasource.model.DataSourceMetadata; -import org.opensearch.sql.datasource.model.auth.AuthenticationType; +import org.opensearch.sql.datasources.auth.AuthenticationType; import org.opensearch.sql.datasources.encryptor.Encryptor; +import org.opensearch.sql.datasources.exceptions.DataSourceNotFoundException; +import org.opensearch.sql.datasources.service.DataSourceMetadataStorage; import org.opensearch.sql.datasources.utils.XContentParserUtils; public class OpenSearchDataSourceMetadataStorage implements DataSourceMetadataStorage { diff --git a/datasources/src/main/java/org/opensearch/sql/datasources/transport/TransportCreateDataSourceAction.java b/datasources/src/main/java/org/opensearch/sql/datasources/transport/TransportCreateDataSourceAction.java index d202f26955..df175bfca7 100644 --- a/datasources/src/main/java/org/opensearch/sql/datasources/transport/TransportCreateDataSourceAction.java +++ b/datasources/src/main/java/org/opensearch/sql/datasources/transport/TransportCreateDataSourceAction.java @@ -17,10 +17,10 @@ import org.opensearch.client.node.NodeClient; import org.opensearch.common.inject.Inject; import org.opensearch.sql.datasource.DataSourceService; -import org.opensearch.sql.datasource.DataSourceServiceImpl; import org.opensearch.sql.datasource.model.DataSourceMetadata; -import org.opensearch.sql.datasources.model.CreateDataSourceActionRequest; -import org.opensearch.sql.datasources.model.CreateDataSourceActionResponse; +import org.opensearch.sql.datasources.model.transport.CreateDataSourceActionRequest; +import org.opensearch.sql.datasources.model.transport.CreateDataSourceActionResponse; +import org.opensearch.sql.datasources.service.DataSourceServiceImpl; import org.opensearch.tasks.Task; import org.opensearch.transport.TransportService; diff --git a/datasources/src/main/java/org/opensearch/sql/datasources/transport/TransportDeleteDataSourceAction.java b/datasources/src/main/java/org/opensearch/sql/datasources/transport/TransportDeleteDataSourceAction.java index ea5c61310a..445caea496 100644 --- a/datasources/src/main/java/org/opensearch/sql/datasources/transport/TransportDeleteDataSourceAction.java +++ b/datasources/src/main/java/org/opensearch/sql/datasources/transport/TransportDeleteDataSourceAction.java @@ -15,9 +15,9 @@ import org.opensearch.client.node.NodeClient; import org.opensearch.common.inject.Inject; import org.opensearch.sql.datasource.DataSourceService; -import org.opensearch.sql.datasource.DataSourceServiceImpl; -import org.opensearch.sql.datasources.model.DeleteDataSourceActionRequest; -import org.opensearch.sql.datasources.model.DeleteDataSourceActionResponse; +import org.opensearch.sql.datasources.model.transport.DeleteDataSourceActionRequest; +import org.opensearch.sql.datasources.model.transport.DeleteDataSourceActionResponse; +import org.opensearch.sql.datasources.service.DataSourceServiceImpl; import org.opensearch.tasks.Task; import org.opensearch.transport.TransportService; diff --git a/datasources/src/main/java/org/opensearch/sql/datasources/transport/TransportGetDataSourceAction.java b/datasources/src/main/java/org/opensearch/sql/datasources/transport/TransportGetDataSourceAction.java index 4bd9bf95c4..491bcb9b9a 100644 --- a/datasources/src/main/java/org/opensearch/sql/datasources/transport/TransportGetDataSourceAction.java +++ b/datasources/src/main/java/org/opensearch/sql/datasources/transport/TransportGetDataSourceAction.java @@ -7,8 +7,6 @@ package org.opensearch.sql.datasources.transport; - - import java.util.Set; import org.opensearch.action.ActionListener; import org.opensearch.action.ActionType; @@ -18,10 +16,10 @@ import org.opensearch.client.node.NodeClient; import org.opensearch.common.inject.Inject; import org.opensearch.sql.datasource.DataSourceService; -import org.opensearch.sql.datasource.DataSourceServiceImpl; import org.opensearch.sql.datasource.model.DataSourceMetadata; -import org.opensearch.sql.datasources.model.GetDataSourceActionRequest; -import org.opensearch.sql.datasources.model.GetDataSourceActionResponse; +import org.opensearch.sql.datasources.model.transport.GetDataSourceActionRequest; +import org.opensearch.sql.datasources.model.transport.GetDataSourceActionResponse; +import org.opensearch.sql.datasources.service.DataSourceServiceImpl; import org.opensearch.sql.protocol.response.format.JsonResponseFormatter; import org.opensearch.tasks.Task; import org.opensearch.transport.TransportService; diff --git a/datasources/src/main/java/org/opensearch/sql/datasources/transport/TransportUpdateDataSourceAction.java b/datasources/src/main/java/org/opensearch/sql/datasources/transport/TransportUpdateDataSourceAction.java index aa3bc1bb6a..156e4209d9 100644 --- a/datasources/src/main/java/org/opensearch/sql/datasources/transport/TransportUpdateDataSourceAction.java +++ b/datasources/src/main/java/org/opensearch/sql/datasources/transport/TransportUpdateDataSourceAction.java @@ -17,9 +17,9 @@ import org.opensearch.client.node.NodeClient; import org.opensearch.common.inject.Inject; import org.opensearch.sql.datasource.DataSourceService; -import org.opensearch.sql.datasource.DataSourceServiceImpl; -import org.opensearch.sql.datasources.model.UpdateDataSourceActionRequest; -import org.opensearch.sql.datasources.model.UpdateDataSourceActionResponse; +import org.opensearch.sql.datasources.model.transport.UpdateDataSourceActionRequest; +import org.opensearch.sql.datasources.model.transport.UpdateDataSourceActionResponse; +import org.opensearch.sql.datasources.service.DataSourceServiceImpl; import org.opensearch.tasks.Task; import org.opensearch.transport.TransportService; diff --git a/plugin/src/main/resources/datasources-index-mapping.yml b/datasources/src/main/resources/datasources-index-mapping.yml similarity index 100% rename from plugin/src/main/resources/datasources-index-mapping.yml rename to datasources/src/main/resources/datasources-index-mapping.yml diff --git a/plugin/src/main/resources/datasources-index-settings.yml b/datasources/src/main/resources/datasources-index-settings.yml similarity index 100% rename from plugin/src/main/resources/datasources-index-settings.yml rename to datasources/src/main/resources/datasources-index-settings.yml diff --git a/core/src/test/java/org/opensearch/sql/datasource/model/auth/AuthenticationTypeTest.java b/datasources/src/test/java/org/opensearch/sql/datasources/auth/AuthenticationTypeTest.java similarity index 93% rename from core/src/test/java/org/opensearch/sql/datasource/model/auth/AuthenticationTypeTest.java rename to datasources/src/test/java/org/opensearch/sql/datasources/auth/AuthenticationTypeTest.java index f9e4f3ce59..23bb4688e1 100644 --- a/core/src/test/java/org/opensearch/sql/datasource/model/auth/AuthenticationTypeTest.java +++ b/datasources/src/test/java/org/opensearch/sql/datasources/auth/AuthenticationTypeTest.java @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package org.opensearch.sql.datasource.model.auth; +package org.opensearch.sql.datasources.auth; import static org.junit.jupiter.api.Assertions.assertEquals; diff --git a/datasources/src/test/java/org/opensearch/sql/datasources/auth/DataSourceUserAuthorizationHelperImplTest.java b/datasources/src/test/java/org/opensearch/sql/datasources/auth/DataSourceUserAuthorizationHelperImplTest.java index 6617735894..96fcd94cf2 100644 --- a/datasources/src/test/java/org/opensearch/sql/datasources/auth/DataSourceUserAuthorizationHelperImplTest.java +++ b/datasources/src/test/java/org/opensearch/sql/datasources/auth/DataSourceUserAuthorizationHelperImplTest.java @@ -10,18 +10,18 @@ import java.util.HashMap; import java.util.List; import org.junit.Assert; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Answers; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Mockito; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; import org.opensearch.client.Client; import org.opensearch.sql.datasource.model.DataSourceMetadata; import org.opensearch.sql.datasource.model.DataSourceType; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class DataSourceUserAuthorizationHelperImplTest { @Mock(answer = Answers.RETURNS_DEEP_STUBS) diff --git a/datasources/src/test/java/org/opensearch/sql/datasources/encryptor/EncryptorImplTest.java b/datasources/src/test/java/org/opensearch/sql/datasources/encryptor/EncryptorImplTest.java new file mode 100644 index 0000000000..2d7034ae79 --- /dev/null +++ b/datasources/src/test/java/org/opensearch/sql/datasources/encryptor/EncryptorImplTest.java @@ -0,0 +1,12 @@ +package org.opensearch.sql.datasources.encryptor; + +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.junit.jupiter.MockitoExtension; + +@ExtendWith(MockitoExtension.class) +public class EncryptorImplTest { + + private String + + +} diff --git a/core/src/test/java/org/opensearch/sql/datasource/DataSourceLoaderCacheImplTest.java b/datasources/src/test/java/org/opensearch/sql/datasources/service/DataSourceLoaderCacheImplTest.java similarity index 98% rename from core/src/test/java/org/opensearch/sql/datasource/DataSourceLoaderCacheImplTest.java rename to datasources/src/test/java/org/opensearch/sql/datasources/service/DataSourceLoaderCacheImplTest.java index fae69e7feb..bf656857b0 100644 --- a/core/src/test/java/org/opensearch/sql/datasource/DataSourceLoaderCacheImplTest.java +++ b/datasources/src/test/java/org/opensearch/sql/datasources/service/DataSourceLoaderCacheImplTest.java @@ -1,4 +1,4 @@ -package org.opensearch.sql.datasource; +package org.opensearch.sql.datasources.service; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.lenient; diff --git a/core/src/test/java/org/opensearch/sql/datasource/DataSourceServiceImplTest.java b/datasources/src/test/java/org/opensearch/sql/datasources/service/DataSourceServiceImplTest.java similarity index 98% rename from core/src/test/java/org/opensearch/sql/datasource/DataSourceServiceImplTest.java rename to datasources/src/test/java/org/opensearch/sql/datasources/service/DataSourceServiceImplTest.java index 98e17e9166..e1312ec582 100644 --- a/core/src/test/java/org/opensearch/sql/datasource/DataSourceServiceImplTest.java +++ b/datasources/src/test/java/org/opensearch/sql/datasources/service/DataSourceServiceImplTest.java @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package org.opensearch.sql.datasource; +package org.opensearch.sql.datasources.service; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; @@ -34,10 +34,12 @@ import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; -import org.opensearch.sql.datasource.exceptions.DataSourceNotFoundException; +import org.opensearch.sql.datasource.DataSourceService; 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.auth.DataSourceUserAuthorizationHelper; +import org.opensearch.sql.datasources.exceptions.DataSourceNotFoundException; import org.opensearch.sql.storage.DataSourceFactory; import org.opensearch.sql.storage.StorageEngine; diff --git a/datasources/src/test/java/org/opensearch/sql/datasources/storage/OpenSearchDataSourceMetadataStorageTest.java b/datasources/src/test/java/org/opensearch/sql/datasources/storage/OpenSearchDataSourceMetadataStorageTest.java index 54a2f5facd..7530c3b067 100644 --- a/datasources/src/test/java/org/opensearch/sql/datasources/storage/OpenSearchDataSourceMetadataStorageTest.java +++ b/datasources/src/test/java/org/opensearch/sql/datasources/storage/OpenSearchDataSourceMetadataStorageTest.java @@ -16,14 +16,14 @@ import lombok.SneakyThrows; import org.apache.lucene.search.TotalHits; import org.junit.Assert; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Answers; import org.mockito.ArgumentMatchers; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Mockito; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; import org.opensearch.action.ActionFuture; import org.opensearch.action.DocWriteResponse; import org.opensearch.action.admin.indices.create.CreateIndexResponse; @@ -36,11 +36,11 @@ import org.opensearch.rest.RestStatus; import org.opensearch.search.SearchHit; import org.opensearch.search.SearchHits; -import org.opensearch.sql.datasources.encryptor.Encryptor; import org.opensearch.sql.datasource.model.DataSourceMetadata; import org.opensearch.sql.datasource.model.DataSourceType; +import org.opensearch.sql.datasources.encryptor.Encryptor; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class OpenSearchDataSourceMetadataStorageTest { private static final String TEST_DATASOURCE_INDEX_NAME = "testDS"; @@ -174,8 +174,6 @@ public void testCreateDataSourceMetadata() { @Test public void testUpdateDataSourceMetadata() { - Mockito.when(clusterService.state().routingTable().hasIndex(DATASOURCE_INDEX_NAME)) - .thenReturn(Boolean.TRUE); Mockito.when(encryptor.encrypt("secret_key")).thenReturn("secret_key"); Mockito.when(encryptor.encrypt("access_key")).thenReturn("access_key"); Mockito.when(client.update(ArgumentMatchers.any())).thenReturn(updateResponseActionFuture); diff --git a/datasources/src/test/java/org/opensearch/sql/datasources/utils/SchedulerTest.java b/datasources/src/test/java/org/opensearch/sql/datasources/utils/SchedulerTest.java index cb5d18c2c2..e12d44428b 100644 --- a/datasources/src/test/java/org/opensearch/sql/datasources/utils/SchedulerTest.java +++ b/datasources/src/test/java/org/opensearch/sql/datasources/utils/SchedulerTest.java @@ -8,15 +8,15 @@ import java.util.concurrent.atomic.AtomicBoolean; import org.junit.Assert; import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.ArgumentMatchers; import org.mockito.Mock; import org.mockito.Mockito; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; import org.opensearch.client.node.NodeClient; import org.opensearch.threadpool.ThreadPool; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class SchedulerTest { @Mock diff --git a/integ-test/src/test/java/org/opensearch/sql/ppl/StandaloneIT.java b/integ-test/src/test/java/org/opensearch/sql/ppl/StandaloneIT.java index 0c900ea234..cca7833d66 100644 --- a/integ-test/src/test/java/org/opensearch/sql/ppl/StandaloneIT.java +++ b/integ-test/src/test/java/org/opensearch/sql/ppl/StandaloneIT.java @@ -31,10 +31,10 @@ import org.opensearch.sql.analysis.ExpressionAnalyzer; import org.opensearch.sql.common.response.ResponseListener; import org.opensearch.sql.common.setting.Settings; -import org.opensearch.sql.datasource.DataSourceMetadataStorage; +import org.opensearch.sql.datasources.service.DataSourceMetadataStorage; import org.opensearch.sql.datasource.DataSourceService; -import org.opensearch.sql.datasource.DataSourceServiceImpl; -import org.opensearch.sql.datasource.DataSourceUserAuthorizationHelper; +import org.opensearch.sql.datasources.service.DataSourceServiceImpl; +import org.opensearch.sql.datasources.auth.DataSourceUserAuthorizationHelper; import org.opensearch.sql.datasource.model.DataSourceMetadata; import org.opensearch.sql.executor.ExecutionEngine; import org.opensearch.sql.executor.ExecutionEngine.QueryResponse; diff --git a/plugin/src/main/java/org/opensearch/sql/plugin/SQLPlugin.java b/plugin/src/main/java/org/opensearch/sql/plugin/SQLPlugin.java index 69bb701594..26e9915575 100644 --- a/plugin/src/main/java/org/opensearch/sql/plugin/SQLPlugin.java +++ b/plugin/src/main/java/org/opensearch/sql/plugin/SQLPlugin.java @@ -47,10 +47,10 @@ import org.opensearch.script.ScriptEngine; import org.opensearch.script.ScriptService; import org.opensearch.sql.datasources.encryptor.EncryptorImpl; -import org.opensearch.sql.datasource.DataSourceMetadataStorage; +import org.opensearch.sql.datasources.service.DataSourceMetadataStorage; import org.opensearch.sql.datasource.DataSourceService; -import org.opensearch.sql.datasource.DataSourceServiceImpl; -import org.opensearch.sql.datasource.DataSourceUserAuthorizationHelper; +import org.opensearch.sql.datasources.service.DataSourceServiceImpl; +import org.opensearch.sql.datasources.auth.DataSourceUserAuthorizationHelper; import org.opensearch.sql.datasources.transport.TransportCreateDataSourceAction; import org.opensearch.sql.datasources.transport.TransportDeleteDataSourceAction; import org.opensearch.sql.datasources.transport.TransportGetDataSourceAction; @@ -70,10 +70,10 @@ import org.opensearch.sql.datasources.settings.DataSourceSettings; import org.opensearch.sql.datasources.auth.DataSourceUserAuthorizationHelperImpl; import org.opensearch.sql.datasources.storage.OpenSearchDataSourceMetadataStorage; -import org.opensearch.sql.datasources.model.CreateDataSourceActionResponse; -import org.opensearch.sql.datasources.model.DeleteDataSourceActionResponse; -import org.opensearch.sql.datasources.model.GetDataSourceActionResponse; -import org.opensearch.sql.datasources.model.UpdateDataSourceActionResponse; +import org.opensearch.sql.datasources.model.transport.CreateDataSourceActionResponse; +import org.opensearch.sql.datasources.model.transport.DeleteDataSourceActionResponse; +import org.opensearch.sql.datasources.model.transport.GetDataSourceActionResponse; +import org.opensearch.sql.datasources.model.transport.UpdateDataSourceActionResponse; import org.opensearch.sql.datasources.rest.RestDataSourceQueryAction; import org.opensearch.sql.plugin.rest.RestPPLQueryAction; import org.opensearch.sql.plugin.rest.RestPPLStatsAction; diff --git a/plugin/src/main/java/org/opensearch/sql/plugin/transport/TransportPPLQueryAction.java b/plugin/src/main/java/org/opensearch/sql/plugin/transport/TransportPPLQueryAction.java index 6825b2ac92..a5c094e956 100644 --- a/plugin/src/main/java/org/opensearch/sql/plugin/transport/TransportPPLQueryAction.java +++ b/plugin/src/main/java/org/opensearch/sql/plugin/transport/TransportPPLQueryAction.java @@ -21,7 +21,7 @@ import org.opensearch.sql.common.response.ResponseListener; import org.opensearch.sql.common.utils.QueryContext; import org.opensearch.sql.datasource.DataSourceService; -import org.opensearch.sql.datasource.DataSourceServiceImpl; +import org.opensearch.sql.datasources.service.DataSourceServiceImpl; import org.opensearch.sql.executor.ExecutionEngine; import org.opensearch.sql.legacy.metrics.MetricName; import org.opensearch.sql.legacy.metrics.Metrics;