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.
Refactor async executor service dependencies using guice framework
Signed-off-by: Vamsi Manohar <reddyvam@amazon.com>
- Loading branch information
Showing
20 changed files
with
533 additions
and
185 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
10 changes: 10 additions & 0 deletions
10
spark/src/main/java/org/opensearch/sql/spark/client/EMRServerlessClientFactory.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,10 @@ | ||
package org.opensearch.sql.spark.client; | ||
|
||
/** Interface for EMRServerlessClientFactory. */ | ||
public interface EMRServerlessClientFactory { | ||
|
||
/** | ||
* @return {@link EMRServerlessClient} | ||
*/ | ||
EMRServerlessClient getClient(); | ||
} |
60 changes: 60 additions & 0 deletions
60
spark/src/main/java/org/opensearch/sql/spark/client/EMRServerlessClientFactoryImpl.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,60 @@ | ||
package org.opensearch.sql.spark.client; | ||
|
||
import static org.opensearch.sql.common.setting.Settings.Key.SPARK_EXECUTION_ENGINE_CONFIG; | ||
|
||
import com.amazonaws.auth.DefaultAWSCredentialsProviderChain; | ||
import com.amazonaws.services.emrserverless.AWSEMRServerless; | ||
import com.amazonaws.services.emrserverless.AWSEMRServerlessClientBuilder; | ||
import java.security.AccessController; | ||
import java.security.PrivilegedAction; | ||
import lombok.RequiredArgsConstructor; | ||
import org.opensearch.sql.spark.config.SparkExecutionEngineConfig; | ||
import org.opensearch.sql.spark.config.SparkExecutionEngineConfigSupplier; | ||
|
||
@RequiredArgsConstructor | ||
public class EMRServerlessClientFactoryImpl implements EMRServerlessClientFactory { | ||
|
||
private final SparkExecutionEngineConfigSupplier sparkExecutionEngineConfigSupplier; | ||
private EMRServerlessClient emrServerlessClient; | ||
private String region; | ||
|
||
@Override | ||
public EMRServerlessClient getClient() { | ||
SparkExecutionEngineConfig sparkExecutionEngineConfig = | ||
this.sparkExecutionEngineConfigSupplier.getSparkExecutionEngineConfig(); | ||
validateSparkExecutionEngineConfig(sparkExecutionEngineConfig); | ||
if (isNewClientCreationRequired(sparkExecutionEngineConfig.getRegion())) { | ||
region = sparkExecutionEngineConfig.getRegion(); | ||
this.emrServerlessClient = createEMRServerlessClient(this.region); | ||
} | ||
return this.emrServerlessClient; | ||
} | ||
|
||
private boolean isNewClientCreationRequired(String region) { | ||
return !region.equals(this.region) || emrServerlessClient == null; | ||
} | ||
|
||
private void validateSparkExecutionEngineConfig( | ||
SparkExecutionEngineConfig sparkExecutionEngineConfig) { | ||
if (sparkExecutionEngineConfig == null || sparkExecutionEngineConfig.getRegion() == null) { | ||
throw new IllegalArgumentException( | ||
String.format( | ||
"Async Query APIs are disabled as %s is not configured in cluster settings. Please" | ||
+ " configure the setting and restart the domain to enable Async Query APIs", | ||
SPARK_EXECUTION_ENGINE_CONFIG.getKeyValue())); | ||
} | ||
} | ||
|
||
private EMRServerlessClient createEMRServerlessClient(String awsRegion) { | ||
return AccessController.doPrivileged( | ||
(PrivilegedAction<EMRServerlessClient>) | ||
() -> { | ||
AWSEMRServerless awsemrServerless = | ||
AWSEMRServerlessClientBuilder.standard() | ||
.withRegion(awsRegion) | ||
.withCredentials(new DefaultAWSCredentialsProviderChain()) | ||
.build(); | ||
return new EmrServerlessClientImpl(awsemrServerless); | ||
}); | ||
} | ||
} |
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.