Skip to content

Commit

Permalink
error handling changes for elasticsearch
Browse files Browse the repository at this point in the history
# Conflicts:
#	athena-elasticsearch/src/main/java/com/amazonaws/athena/connectors/elasticsearch/AWSRequestSigningApacheInterceptor.java
#	athena-elasticsearch/src/main/java/com/amazonaws/athena/connectors/elasticsearch/AwsRestHighLevelClient.java
#	athena-elasticsearch/src/main/java/com/amazonaws/athena/connectors/elasticsearch/ElasticsearchDomainMapProvider.java
#	athena-elasticsearch/src/main/java/com/amazonaws/athena/connectors/elasticsearch/ElasticsearchMetadataHandler.java
#	athena-elasticsearch/src/main/java/com/amazonaws/athena/connectors/elasticsearch/ElasticsearchRecordHandler.java
  • Loading branch information
ritiktrianz committed Nov 8, 2024
1 parent 623454c commit a4ac524
Showing 1 changed file with 12 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,15 @@
*/

import com.amazonaws.athena.connector.lambda.exceptions.AthenaConnectorException;
import com.amazonaws.services.glue.model.ErrorDetails;
import com.amazonaws.services.glue.model.FederationSourceErrorCode;
import com.amazonaws.services.secretsmanager.AWSSecretsManager;
import com.amazonaws.services.secretsmanager.model.GetSecretValueRequest;
import com.amazonaws.services.secretsmanager.model.GetSecretValueResult;
import com.amazonaws.services.secretsmanager.model.ResourceNotFoundException;
import org.apache.arrow.util.VisibleForTesting;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import software.amazon.awssdk.services.glue.model.ErrorDetails;
import software.amazon.awssdk.services.glue.model.FederationSourceErrorCode;
import software.amazon.awssdk.services.secretsmanager.model.GetSecretValueRequest;
import software.amazon.awssdk.services.secretsmanager.SecretsManagerClient;
import software.amazon.awssdk.services.secretsmanager.model.GetSecretValueResponse;
import software.amazon.awssdk.services.secretsmanager.model.ResourceNotFoundException;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
Expand All @@ -56,9 +55,9 @@ public class CachableSecretsManager
private static final Pattern NAME_PATTERN = Pattern.compile(SECRET_NAME_PATTERN);

private final LinkedHashMap<String, CacheEntry> cache = new LinkedHashMap<>();
private final AWSSecretsManager secretsManager;
private final SecretsManagerClient secretsManager;

public CachableSecretsManager(AWSSecretsManager secretsManager)
public CachableSecretsManager(SecretsManagerClient secretsManager)
{
this.secretsManager = secretsManager;
}
Expand Down Expand Up @@ -103,15 +102,14 @@ public String getSecret(String secretName)

if (cacheEntry == null || cacheEntry.getAge() > MAX_CACHE_AGE_MS) {
logger.info("getSecret: Resolving secret[{}].", secretName);
GetSecretValueResult secretValueResult = secretsManager.getSecretValue(new GetSecretValueRequest()
.withSecretId(secretName));
cacheEntry = new CacheEntry(secretName, secretValueResult.getSecretString());
evictCache(cache.size() >= MAX_CACHE_SIZE);
cache.put(secretName, cacheEntry);
GetSecretValueResponse secretValueResult = secretsManager.getSecretValue(GetSecretValueRequest.builder()
.secretId(secretName)
.build());
cacheEntry = new CacheEntry(secretName, secretValueResult.secretString());
}
}
catch (ResourceNotFoundException e) {
throw new AthenaConnectorException(e.getMessage(), new ErrorDetails().withErrorCode(FederationSourceErrorCode.EntityNotFoundException.toString()));
throw new AthenaConnectorException(e.getMessage(), ErrorDetails.builder().errorCode(FederationSourceErrorCode.ENTITY_NOT_FOUND_EXCEPTION.toString()).build());
}

return cacheEntry.getValue();
Expand Down

0 comments on commit a4ac524

Please sign in to comment.