-
Notifications
You must be signed in to change notification settings - Fork 210
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create network policy for aoss source. (#3613)
Signed-off-by: Adi Suresh <[email protected]>
- Loading branch information
Showing
13 changed files
with
466 additions
and
52 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
...earch/ServerlessNetworkPolicyUpdater.java → ...earch/ServerlessNetworkPolicyUpdater.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
58 changes: 58 additions & 0 deletions
58
...ensearch/dataprepper/plugins/common/opensearch/ServerlessNetworkPolicyUpdaterFactory.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,58 @@ | ||
package org.opensearch.dataprepper.plugins.common.opensearch; | ||
|
||
import org.opensearch.dataprepper.aws.api.AwsCredentialsOptions; | ||
import org.opensearch.dataprepper.aws.api.AwsCredentialsSupplier; | ||
import org.opensearch.dataprepper.plugins.sink.opensearch.ConnectionConfiguration; | ||
import org.opensearch.dataprepper.plugins.source.opensearch.configuration.AwsAuthenticationConfiguration; | ||
import software.amazon.awssdk.core.client.config.ClientOverrideConfiguration; | ||
import software.amazon.awssdk.core.retry.RetryPolicy; | ||
import software.amazon.awssdk.core.retry.backoff.FullJitterBackoffStrategy; | ||
import software.amazon.awssdk.services.opensearchserverless.OpenSearchServerlessClient; | ||
|
||
import java.time.Duration; | ||
|
||
public class ServerlessNetworkPolicyUpdaterFactory { | ||
public static ServerlessNetworkPolicyUpdater create( | ||
final AwsCredentialsSupplier awsCredentialsSupplier, | ||
final ConnectionConfiguration connectionConfiguration | ||
) { | ||
return new ServerlessNetworkPolicyUpdater(getOpenSearchServerlessClient( | ||
awsCredentialsSupplier, connectionConfiguration.createAwsCredentialsOptions() | ||
)); | ||
} | ||
|
||
public static ServerlessNetworkPolicyUpdater create( | ||
final AwsCredentialsSupplier awsCredentialsSupplier, | ||
final AwsAuthenticationConfiguration awsConfig | ||
) { | ||
final AwsCredentialsOptions awsCredentialsOptions = AwsCredentialsOptions.builder() | ||
.withRegion(awsConfig.getAwsRegion()) | ||
.withStsRoleArn(awsConfig.getAwsStsRoleArn()) | ||
.withStsExternalId(awsConfig.getAwsStsExternalId()) | ||
.withStsHeaderOverrides(awsConfig.getAwsStsHeaderOverrides()) | ||
.build(); | ||
|
||
return new ServerlessNetworkPolicyUpdater(getOpenSearchServerlessClient( | ||
awsCredentialsSupplier, awsCredentialsOptions | ||
)); | ||
} | ||
|
||
private static OpenSearchServerlessClient getOpenSearchServerlessClient( | ||
final AwsCredentialsSupplier awsCredentialsSupplier, | ||
final AwsCredentialsOptions awsCredentialsOptions | ||
) { | ||
return OpenSearchServerlessClient.builder() | ||
.credentialsProvider(awsCredentialsSupplier.getProvider(awsCredentialsOptions)) | ||
.region(awsCredentialsOptions.getRegion()) | ||
.overrideConfiguration(ClientOverrideConfiguration.builder() | ||
.retryPolicy(RetryPolicy.builder() | ||
.backoffStrategy(FullJitterBackoffStrategy.builder() | ||
.baseDelay(Duration.ofSeconds(10)) | ||
.maxBackoffTime(Duration.ofSeconds(60)) | ||
.build()) | ||
.numRetries(10) | ||
.build()) | ||
.build()) | ||
.build(); | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
...n/java/org/opensearch/dataprepper/plugins/common/opensearch/ServerlessOptionsFactory.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,44 @@ | ||
package org.opensearch.dataprepper.plugins.common.opensearch; | ||
|
||
import org.apache.commons.lang3.StringUtils; | ||
import org.opensearch.dataprepper.plugins.source.opensearch.configuration.AwsAuthenticationConfiguration; | ||
import org.opensearch.dataprepper.plugins.sink.opensearch.ConnectionConfiguration; | ||
import org.opensearch.dataprepper.plugins.source.opensearch.configuration.ServerlessOptions; | ||
|
||
import java.util.Optional; | ||
|
||
public class ServerlessOptionsFactory { | ||
|
||
public static Optional<ServerlessOptions> create(final ConnectionConfiguration connectionConfiguration) { | ||
if (!connectionConfiguration.isServerless() || | ||
StringUtils.isBlank(connectionConfiguration.getServerlessNetworkPolicyName()) || | ||
StringUtils.isBlank(connectionConfiguration.getServerlessCollectionName()) || | ||
StringUtils.isBlank(connectionConfiguration.getServerlessVpceId()) | ||
) { | ||
return Optional.empty(); | ||
} | ||
|
||
return Optional.of(new ServerlessOptions( | ||
connectionConfiguration.getServerlessNetworkPolicyName(), | ||
connectionConfiguration.getServerlessCollectionName(), | ||
connectionConfiguration.getServerlessVpceId())); | ||
} | ||
|
||
public static Optional<ServerlessOptions> create(final AwsAuthenticationConfiguration awsConfig) { | ||
if (awsConfig == null || !awsConfig.isServerlessCollection()) { | ||
return Optional.empty(); | ||
} | ||
|
||
final ServerlessOptions serverlessOptions = awsConfig.getServerlessOptions(); | ||
if (serverlessOptions == null || | ||
StringUtils.isBlank(serverlessOptions.getNetworkPolicyName()) || | ||
StringUtils.isBlank(serverlessOptions.getCollectionName()) || | ||
StringUtils.isBlank(serverlessOptions.getVpceId()) | ||
) { | ||
return Optional.empty(); | ||
} | ||
|
||
return Optional.of(serverlessOptions); | ||
} | ||
|
||
} |
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
39 changes: 39 additions & 0 deletions
39
...org/opensearch/dataprepper/plugins/source/opensearch/configuration/ServerlessOptions.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,39 @@ | ||
package org.opensearch.dataprepper.plugins.source.opensearch.configuration; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
||
public class ServerlessOptions { | ||
|
||
@JsonProperty("network_policy_name") | ||
private String networkPolicyName; | ||
|
||
@JsonProperty("collection_name") | ||
private String collectionName; | ||
|
||
@JsonProperty("vpce_id") | ||
private String vpceId; | ||
|
||
public ServerlessOptions() { | ||
|
||
} | ||
|
||
public ServerlessOptions(String networkPolicyName, String collectionName, String vpceId) { | ||
this.networkPolicyName = networkPolicyName; | ||
this.collectionName = collectionName; | ||
this.vpceId = vpceId; | ||
} | ||
|
||
public String getNetworkPolicyName() { | ||
return networkPolicyName; | ||
} | ||
|
||
public String getCollectionName() { | ||
return collectionName; | ||
} | ||
|
||
public String getVpceId() { | ||
return vpceId; | ||
} | ||
|
||
} | ||
|
Oops, something went wrong.