-
Notifications
You must be signed in to change notification settings - Fork 139
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Reafactor into new datasources module Signed-off-by: vamsi-amazon <reddyvam@amazon.com> * Refactored all the datasource releated code to new datasources module Signed-off-by: vamsi-amazon <reddyvam@amazon.com> * More unit tests Signed-off-by: vamsi-amazon <reddyvam@amazon.com> --------- Signed-off-by: vamsi-amazon <reddyvam@amazon.com> (cherry picked from commit 7584f79) Co-authored-by: Vamsi Manohar <reddyvam@amazon.com>
- Loading branch information
1 parent
ae15c3b
commit 5f8ffe8
Showing
56 changed files
with
1,625 additions
and
494 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
plugins { | ||
id 'java-library' | ||
id "io.freefair.lombok" | ||
id 'jacoco' | ||
} | ||
|
||
repositories { | ||
mavenCentral() | ||
} | ||
|
||
dependencies { | ||
implementation project(':core') | ||
implementation project(':protocol') | ||
implementation group: 'org.opensearch', name: 'opensearch', version: "${opensearch_version}" | ||
implementation group: 'org.opensearch', name: 'opensearch-x-content', version: "${opensearch_version}" | ||
implementation group: 'org.opensearch', name: 'common-utils', version: "${opensearch_build}" | ||
implementation group: 'commons-io', name: 'commons-io', version: '2.8.0' | ||
implementation 'com.amazonaws:aws-encryption-sdk-java:2.4.0' | ||
|
||
testImplementation group: 'junit', name: 'junit', version: '4.13.2' | ||
testImplementation('org.junit.jupiter:junit-jupiter:5.6.2') | ||
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.2.0' | ||
testImplementation group: 'org.mockito', name: 'mockito-junit-jupiter', version: '5.2.0' | ||
testImplementation 'org.junit.jupiter:junit-jupiter:5.6.2' | ||
} | ||
|
||
test { | ||
useJUnitPlatform() | ||
testLogging { | ||
events "passed", "skipped", "failed" | ||
exceptionFormat "full" | ||
} | ||
} | ||
|
||
jacocoTestReport { | ||
reports { | ||
html.enabled true | ||
xml.enabled true | ||
} | ||
afterEvaluate { | ||
classDirectories.setFrom(files(classDirectories.files.collect { | ||
fileTree(dir: it) | ||
})) | ||
} | ||
} | ||
test.finalizedBy(project.tasks.jacocoTestReport) | ||
|
||
jacocoTestCoverageVerification { | ||
violationRules { | ||
rule { | ||
element = 'CLASS' | ||
excludes = [ | ||
'org.opensearch.sql.datasources.settings.DataSourceSettings', | ||
'org.opensearch.sql.datasources.exceptions.*', | ||
'org.opensearch.sql.datasources.model.*', | ||
'org.opensearch.sql.datasources.rest.*' | ||
] | ||
limit { | ||
counter = 'LINE' | ||
minimum = 1.0 | ||
} | ||
limit { | ||
counter = 'BRANCH' | ||
minimum = 0.9 | ||
} | ||
} | ||
} | ||
afterEvaluate { | ||
classDirectories.setFrom(files(classDirectories.files.collect { | ||
fileTree(dir: it) | ||
})) | ||
} | ||
} | ||
check.dependsOn jacocoTestCoverageVerification | ||
jacocoTestCoverageVerification.dependsOn jacocoTestReport |
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,3 @@ | ||
# This file is generated by the 'io.freefair.lombok' Gradle plugin | ||
config.stopBubbling = true | ||
lombok.addLombokGeneratedAnnotation = true |
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
8 changes: 6 additions & 2 deletions
8
...ce/DataSourceUserAuthorizationHelper.java → ...th/DataSourceUserAuthorizationHelper.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
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
78 changes: 78 additions & 0 deletions
78
datasources/src/main/java/org/opensearch/sql/datasources/exceptions/ErrorMessage.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,78 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
|
||
package org.opensearch.sql.datasources.exceptions; | ||
|
||
import com.google.gson.Gson; | ||
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 new Gson().toJson(jsonObject); | ||
} | ||
|
||
private JsonObject getErrorAsJson() { | ||
JsonObject errorJson = new JsonObject(); | ||
errorJson.addProperty("type", type); | ||
errorJson.addProperty("reason", reason); | ||
errorJson.addProperty("details", details); | ||
return errorJson; | ||
} | ||
} |
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
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
Oops, something went wrong.