forked from opensearch-project/sql
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Vamsi Manohar <[email protected]>
- Loading branch information
Showing
28 changed files
with
846 additions
and
16 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
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
16 changes: 16 additions & 0 deletions
16
spark/src/main/java/org/opensearch/sql/spark/client/EmrServerlessClient.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,16 @@ | ||
package org.opensearch.sql.spark.client; | ||
|
||
import org.json.JSONObject; | ||
import org.opensearch.sql.spark.helper.FlintHelper; | ||
|
||
public interface EmrServerlessClient { | ||
|
||
String startJobRun( | ||
String applicationId, | ||
String query, | ||
String datasourceRoleArn, | ||
String executionRoleArn, | ||
FlintHelper flintHelper); | ||
|
||
JSONObject getJobResult(String applicationId, String jobId); | ||
} |
131 changes: 131 additions & 0 deletions
131
spark/src/main/java/org/opensearch/sql/spark/client/EmrServerlessClientImpl.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,131 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.sql.spark.client; | ||
|
||
import static org.opensearch.sql.spark.data.constants.SparkConstants.GLUE_CATALOG_HIVE_JAR; | ||
import static org.opensearch.sql.spark.data.constants.SparkConstants.SPARK_INDEX_NAME; | ||
import static org.opensearch.sql.spark.data.constants.SparkConstants.SPARK_SQL_APPLICATION_JAR; | ||
|
||
import com.amazonaws.services.emrserverless.AWSEMRServerless; | ||
import com.amazonaws.services.emrserverless.model.CancelJobRunRequest; | ||
import com.amazonaws.services.emrserverless.model.GetJobRunRequest; | ||
import com.amazonaws.services.emrserverless.model.GetJobRunResult; | ||
import com.amazonaws.services.emrserverless.model.JobDriver; | ||
import com.amazonaws.services.emrserverless.model.SparkSubmit; | ||
import com.amazonaws.services.emrserverless.model.StartJobRunRequest; | ||
import com.amazonaws.services.emrserverless.model.StartJobRunResult; | ||
import java.util.Set; | ||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
import org.json.JSONObject; | ||
import org.opensearch.sql.spark.helper.FlintHelper; | ||
import org.opensearch.sql.spark.response.SparkResponse; | ||
|
||
public class EmrServerlessClientImpl implements EmrServerlessClient { | ||
|
||
private final AWSEMRServerless emrServerless; | ||
private final String sparkApplicationJar; | ||
private SparkResponse sparkResponse; | ||
private static final Logger logger = LogManager.getLogger(EmrServerlessClientImpl.class); | ||
private static final Set<String> terminalStates = Set.of("CANCELLED", "FAILED", "SUCCESS"); | ||
private static final String JOB_NAME = "flint-opensearch-query"; | ||
|
||
public EmrServerlessClientImpl(AWSEMRServerless emrServerless, SparkResponse sparkResponse) { | ||
this.emrServerless = emrServerless; | ||
this.sparkApplicationJar = SPARK_SQL_APPLICATION_JAR; | ||
this.sparkResponse = sparkResponse; | ||
} | ||
|
||
@Override | ||
public String startJobRun( | ||
String applicationId, | ||
String query, | ||
String datasourceRoleArn, | ||
String executionRoleArn, | ||
FlintHelper flint) { | ||
StartJobRunRequest request = | ||
new StartJobRunRequest() | ||
.withName(JOB_NAME) | ||
.withApplicationId(applicationId) | ||
.withExecutionRoleArn(executionRoleArn) | ||
.withJobDriver( | ||
new JobDriver() | ||
.withSparkSubmit( | ||
new SparkSubmit() | ||
.withEntryPoint(sparkApplicationJar) | ||
.withEntryPointArguments(query, SPARK_INDEX_NAME) | ||
.withSparkSubmitParameters( | ||
"--class org.opensearch.sql.SQLJob --conf" | ||
+ " spark.hadoop.fs.s3.customAWSCredentialsProvider=com.amazonaws.emr.AssumeRoleAWSCredentialsProvider" | ||
+ " --conf" | ||
+ " spark.emr-serverless.driverEnv.ASSUME_ROLE_CREDENTIALS_ROLE_ARN=" | ||
+ datasourceRoleArn | ||
+ " --conf spark.executorEnv.ASSUME_ROLE_CREDENTIALS_ROLE_ARN=" | ||
+ datasourceRoleArn | ||
+ " --conf" | ||
+ " spark.hadoop.aws.catalog.credentials.provider.factory.class=" | ||
+ "com.amazonaws.glue.catalog.metastore.STSAssumeRoleSessionCredentialsProviderFactory" | ||
+ " --conf spark.hive.metastore.glue.role.arn=" | ||
+ datasourceRoleArn | ||
// + " --conf | ||
// spark.driver.cores=1" | ||
// + " --conf | ||
// spark.driver.memory=1g" | ||
// + " --conf | ||
// spark.executor.cores=2" | ||
// + " --conf | ||
// spark.executor.memory=4g" | ||
+ " --conf spark.jars=" | ||
+ GLUE_CATALOG_HIVE_JAR | ||
+ " --conf spark.jars.packages=" | ||
+ "org.opensearch:opensearch-spark-standalone_2.12:0.1.0-SNAPSHOT" | ||
+ " --conf spark.jars.repositories=" | ||
+ "https://aws.oss.sonatype.org/content/repositories/snapshots" | ||
+ " --conf spark.datasource.flint.host=" | ||
+ flint.getFlintHost() | ||
+ " --conf spark.datasource.flint.port=" | ||
+ flint.getFlintPort() | ||
+ " --conf spark.datasource.flint.scheme=" | ||
+ flint.getFlintScheme() | ||
+ " --conf spark.datasource.flint.auth=" | ||
+ flint.getFlintAuth() | ||
+ " --conf spark.datasource.flint.region=" | ||
+ flint.getFlintRegion() | ||
+ " --conf" | ||
+ " spark.emr-serverless.driverEnv.JAVA_HOME=/usr/lib/jvm/java-17-amazon-corretto.x86_64/" | ||
+ " --conf" | ||
+ " spark.executorEnv.JAVA_HOME=/usr/lib/jvm/java-17-amazon-corretto.x86_64/" | ||
+ " --conf" | ||
+ " spark.datasource.flint.customAWSCredentialsProvider=com.amazonaws.emr.AssumeRoleAWSCredentialsProvider" | ||
+ " --conf" | ||
+ " spark.sql.extensions=org.opensearch.flint.spark.FlintSparkExtensions" | ||
+ " --conf spark.hadoop.hive.metastore.client.factory.class=" | ||
+ "com.amazonaws.glue.catalog.metastore.AWSGlueDataCatalogHiveClientFactory"))); | ||
StartJobRunResult response = emrServerless.startJobRun(request); | ||
logger.info("Job Run ID: " + response.getJobRunId()); | ||
sparkResponse.setValue(response.getJobRunId()); | ||
return response.getJobRunId(); | ||
} | ||
|
||
@Override | ||
public JSONObject getJobResult(String applicationId, String jobId) { | ||
return sparkResponse.getResultFromOpensearchIndex(); | ||
} | ||
|
||
public String getJobRunState(String applicationId, String jobRunId) { | ||
GetJobRunRequest request = | ||
new GetJobRunRequest().withApplicationId(applicationId).withJobRunId(jobRunId); | ||
GetJobRunResult response = emrServerless.getJobRun(request); | ||
logger.info("Job Run state: " + response.getJobRun().getState()); | ||
return response.getJobRun().getState(); | ||
} | ||
|
||
public void cancelJobRun(String applicationId, String jobRunId) { | ||
// Cancel the job run | ||
emrServerless.cancelJobRun( | ||
new CancelJobRunRequest().withApplicationId(applicationId).withJobRunId(jobRunId)); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
spark/src/main/java/org/opensearch/sql/spark/config/SparkExecutionEngineConfig.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,21 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.sql.spark.config; | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; | ||
import com.google.gson.Gson; | ||
import lombok.Data; | ||
|
||
@Data | ||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
public class SparkExecutionEngineConfig { | ||
private String applicationId; | ||
private String region; | ||
|
||
public static SparkExecutionEngineConfig toSparkExecutionEngineConfig(String jsonString) { | ||
return new Gson().fromJson(jsonString, SparkExecutionEngineConfig.class); | ||
} | ||
} |
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.