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
33 changed files
with
913 additions
and
22 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
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); | ||
} |
137 changes: 137 additions & 0 deletions
137
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,137 @@ | ||
/* | ||
* 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.FlintJob --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.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.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.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) { | ||
sparkResponse.setValue(jobId); | ||
JSONObject result = sparkResponse.getResultFromOpensearchIndex(); | ||
if (result == null) { | ||
result = new JSONObject(); | ||
result.put("status", getJobRunState(applicationId, jobId)); | ||
} | ||
return result; | ||
} | ||
|
||
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)); | ||
} | ||
} |
Oops, something went wrong.