com.amazonaws.handlers.RequestHandler2 Java Examples

The following examples show how to use com.amazonaws.handlers.RequestHandler2. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GlueHiveMetastore.java    From presto with Apache License 2.0 6 votes vote down vote up
@Inject
public GlueHiveMetastore(
        HdfsEnvironment hdfsEnvironment,
        GlueHiveMetastoreConfig glueConfig,
        GlueColumnStatisticsProvider columnStatisticsProvider,
        @ForGlueHiveMetastore Executor executor,
        @ForGlueHiveMetastore Optional<RequestHandler2> requestHandler)
{
    requireNonNull(glueConfig, "glueConfig is null");
    this.hdfsEnvironment = requireNonNull(hdfsEnvironment, "hdfsEnvironment is null");
    this.hdfsContext = new HdfsContext(ConnectorIdentity.ofUser(DEFAULT_METASTORE_USER));
    this.glueClient = createAsyncGlueClient(glueConfig, requestHandler);
    this.defaultDir = glueConfig.getDefaultWarehouseDir();
    this.catalogId = glueConfig.getCatalogId().orElse(null);
    this.partitionSegments = glueConfig.getPartitionSegments();
    this.executor = requireNonNull(executor, "executor is null");
    this.columnStatisticsProvider = requireNonNull(columnStatisticsProvider, "columnStatisticsProvider is null");
}
 
Example #2
Source File: GlueHiveMetastore.java    From presto with Apache License 2.0 6 votes vote down vote up
private static AWSGlueAsync createAsyncGlueClient(GlueHiveMetastoreConfig config, Optional<RequestHandler2> requestHandler)
{
    ClientConfiguration clientConfig = new ClientConfiguration().withMaxConnections(config.getMaxGlueConnections());
    AWSGlueAsyncClientBuilder asyncGlueClientBuilder = AWSGlueAsyncClientBuilder.standard()
            .withClientConfiguration(clientConfig);

    requestHandler.ifPresent(asyncGlueClientBuilder::setRequestHandlers);

    if (config.getGlueEndpointUrl().isPresent()) {
        checkArgument(config.getGlueRegion().isPresent(), "Glue region must be set when Glue endpoint URL is set");
        asyncGlueClientBuilder.setEndpointConfiguration(new EndpointConfiguration(
                config.getGlueEndpointUrl().get(),
                config.getGlueRegion().get()));
    }
    else if (config.getGlueRegion().isPresent()) {
        asyncGlueClientBuilder.setRegion(config.getGlueRegion().get());
    }
    else if (config.getPinGlueClientToCurrentRegion()) {
        asyncGlueClientBuilder.setRegion(getCurrentRegionFromEC2Metadata().getName());
    }

    asyncGlueClientBuilder.setCredentials(getAwsCredentialsProvider(config));

    return asyncGlueClientBuilder.build();
}
 
Example #3
Source File: KmsMasterKeyProvider.java    From aws-encryption-sdk-java with Apache License 2.0 6 votes vote down vote up
private AWSKMSClientBuilder cloneClientBuilder(final AWSKMSClientBuilder builder) {
    // We need to copy all arguments out of the builder in case it's mutated later on.
    // Unfortunately AWSKMSClientBuilder doesn't support .clone() so we'll have to do it by hand.

    if (builder.getEndpoint() != null) {
        // We won't be able to set the region later if a custom endpoint is set.
        throw new IllegalArgumentException("Setting endpoint configuration is not compatible with passing a " +
                                           "builder to the KmsMasterKeyProvider. Use withCustomClientFactory" +
                                           " instead.");
    }

    final AWSKMSClientBuilder newBuilder = AWSKMSClient.builder();
    newBuilder.setClientConfiguration(builder.getClientConfiguration());
    newBuilder.setCredentials(builder.getCredentials());
    newBuilder.setEndpointConfiguration(builder.getEndpoint());
    newBuilder.setMetricsCollector(builder.getMetricsCollector());
    if (builder.getRequestHandlers() != null) {
        newBuilder.setRequestHandlers(builder.getRequestHandlers().toArray(new RequestHandler2[0]));
    }
    return newBuilder;
}
 
Example #4
Source File: KMSProviderBuilderIntegrationTests.java    From aws-encryption-sdk-java with Apache License 2.0 6 votes vote down vote up
@Test
public void whenHandlerConfigured_handlerIsInvoked() throws Exception {
    RequestHandler2 handler = spy(new RequestHandler2() {});
    KmsMasterKeyProvider mkp =
            KmsMasterKeyProvider.builder()
                                .withClientBuilder(
                                        AWSKMSClientBuilder.standard()
                                                           .withRequestHandlers(handler)
                                )
                                .withKeysForEncryption(KMSTestFixtures.TEST_KEY_IDS[0])
                                .build();

    new AwsCrypto().encryptData(mkp, new byte[1]);

    verify(handler).beforeRequest(any());
}
 
Example #5
Source File: GlueMetastoreModule.java    From presto with Apache License 2.0 5 votes vote down vote up
@Override
protected void setup(Binder binder)
{
    configBinder(binder).bindConfig(GlueHiveMetastoreConfig.class);

    newOptionalBinder(binder, GlueColumnStatisticsProvider.class)
            .setDefault().to(DisabledGlueColumnStatisticsProvider.class).in(Scopes.SINGLETON);

    newOptionalBinder(binder, Key.get(RequestHandler2.class, ForGlueHiveMetastore.class));

    if (buildConfigObject(HiveConfig.class).getRecordingPath() != null) {
        binder.bind(HiveMetastore.class)
                .annotatedWith(ForRecordingHiveMetastore.class)
                .to(GlueHiveMetastore.class)
                .in(Scopes.SINGLETON);
        binder.bind(GlueHiveMetastore.class).in(Scopes.SINGLETON);
        newExporter(binder).export(GlueHiveMetastore.class).withGeneratedName();

        binder.bind(HiveMetastore.class)
                .annotatedWith(ForCachingHiveMetastore.class)
                .to(RecordingHiveMetastore.class)
                .in(Scopes.SINGLETON);
        binder.bind(RecordingHiveMetastore.class).in(Scopes.SINGLETON);
        newExporter(binder).export(RecordingHiveMetastore.class).withGeneratedName();

        Multibinder<Procedure> procedures = newSetBinder(binder, Procedure.class);
        procedures.addBinding().toProvider(WriteHiveMetastoreRecordingProcedure.class).in(Scopes.SINGLETON);
    }
    else {
        binder.bind(HiveMetastore.class)
                .annotatedWith(ForCachingHiveMetastore.class)
                .to(GlueHiveMetastore.class)
                .in(Scopes.SINGLETON);
        newExporter(binder).export(HiveMetastore.class)
                .as(generator -> generator.generatedNameOf(GlueHiveMetastore.class));
    }
    binder.install(new CachingHiveMetastoreModule());
}
 
Example #6
Source File: AWSLambdaConfiguration.java    From micronaut-aws with Apache License 2.0 5 votes vote down vote up
/**
 * @param handlers The {@link RequestHandler2}
 */
@Inject
public void setRequestHandlers(@Nullable RequestHandler2... handlers) {
    if (ArrayUtils.isNotEmpty(handlers)) {
        builder.setRequestHandlers(handlers);
    }
}
 
Example #7
Source File: KmsMasterKeyProvider.java    From aws-encryption-sdk-java with Apache License 2.0 5 votes vote down vote up
private RegionalClientSupplier clientFactory() {
    if (regionalClientSupplier_ != null) {
        return regionalClientSupplier_;
    }

    // Clone again; this MKP builder might be reused to build a second MKP with different creds.
    AWSKMSClientBuilder builder = templateBuilder_ != null ? cloneClientBuilder(templateBuilder_)
                                                           : AWSKMSClientBuilder.standard();

    ConcurrentHashMap<String, AWSKMS> clientCache = new ConcurrentHashMap<>();
    snoopClientCache(clientCache);

    return region -> {
        AWSKMS kms = clientCache.get(region);

        if (kms != null) return kms;

        // We can't just use computeIfAbsent as we need to avoid leaking KMS clients if we're asked to decrypt
        // an EDK with a bogus region in its ARN. So we'll install a request handler to identify the first
        // successful call, and cache it when we see that.
        SuccessfulRequestCacher cacher = new SuccessfulRequestCacher(clientCache, region);
        ArrayList<RequestHandler2> handlers = new ArrayList<>();
        if (builder.getRequestHandlers() != null) {
            handlers.addAll(builder.getRequestHandlers());
        }
        handlers.add(cacher);

        kms = cloneClientBuilder(builder)
                .withRegion(region)
                .withRequestHandlers(handlers.toArray(new RequestHandler2[handlers.size()]))
                .build();
        cacher.client_ = kms;

        return kms;
    };
}
 
Example #8
Source File: KMSProviderBuilderIntegrationTests.java    From aws-encryption-sdk-java with Apache License 2.0 5 votes vote down vote up
@Test
public void whenBuilderCloned_clientBuilderCustomizationIsRetained() throws Exception {
    RequestHandler2 handler = spy(new RequestHandler2() {});

    KmsMasterKeyProvider mkp = KmsMasterKeyProvider.builder()
            .withClientBuilder(
                    AWSKMSClientBuilder.standard().withRequestHandlers(handler)
            )
            .withKeysForEncryption(KMSTestFixtures.TEST_KEY_IDS[0])
            .clone().build();

    new AwsCrypto().encryptData(mkp, new byte[0]);

    verify(handler, atLeastOnce()).beforeRequest(any());
}
 
Example #9
Source File: KMSProviderBuilderIntegrationTests.java    From aws-encryption-sdk-java with Apache License 2.0 5 votes vote down vote up
@Test
public void whenUserAgentsOverridden_originalUAsPreserved() throws Exception {
    RequestHandler2 handler = spy(new RequestHandler2() {});

    KmsMasterKeyProvider mkp = KmsMasterKeyProvider.builder()
                                                   .withClientBuilder(
                                                           AWSKMSClientBuilder.standard().withRequestHandlers(handler)
                                                           .withClientConfiguration(
                                                                   new ClientConfiguration()
                                                                       .withUserAgentPrefix("TEST-UA-PREFIX")
                                                                       .withUserAgentSuffix("TEST-UA-SUFFIX")
                                                           )
                                                   )
                                                   .withKeysForEncryption(KMSTestFixtures.TEST_KEY_IDS[0])
                                                   .clone().build();

    new AwsCrypto().encryptData(mkp, new byte[0]);

    ArgumentCaptor<Request> captor = ArgumentCaptor.forClass(Request.class);
    verify(handler, atLeastOnce()).beforeRequest(captor.capture());

    String ua = (String)captor.getValue().getHeaders().get("User-Agent");

    assertTrue(ua.contains("TEST-UA-PREFIX"));
    assertTrue(ua.contains("TEST-UA-SUFFIX"));
    assertTrue(ua.contains(VersionInfo.USER_AGENT));
}
 
Example #10
Source File: SqsMessageTracing.java    From zipkin-aws with Apache License 2.0 4 votes vote down vote up
public RequestHandler2 requestHandler() {
  return requestHandler;
}
 
Example #11
Source File: DynamoDBDynamicFaultInjection.java    From aws-dynamodb-examples with Apache License 2.0 3 votes vote down vote up
/**
 * The only information needed to create a client are security credentials
 * consisting of the AWS Access Key ID and Secret Access Key. All other
 * configuration, such as the service endpoints, are performed
 * automatically. Client parameters, such as proxies, can be specified in an
 * optional ClientConfiguration object when constructing a client.
 *
 * @see com.amazonaws.auth.BasicAWSCredentials
 * @see com.amazonaws.auth.PropertiesCredentials
 * @see com.amazonaws.ClientConfiguration
 */
private static void init() throws Exception
{

    dynamoDBClient = new AmazonDynamoDBClient(new DefaultAWSCredentialsProviderChain());

    // pass in the client for access to the cached metadata.
    RequestHandler2 requestHandler = new FaultInjectionRequestHandler(dynamoDBClient);

    dynamoDBClient.addRequestHandler(requestHandler);
}
 
Example #12
Source File: DynamoDBDynamicFaultInjection.java    From aws-doc-sdk-examples with Apache License 2.0 1 votes vote down vote up
/**
 * The only information needed to create a client are security credentials
 * consisting of the AWS Access Key ID and Secret Access Key. All other
 * configuration, such as the service endpoints, are performed
 * automatically. Client parameters, such as proxies, can be specified in an
 * optional ClientConfiguration object when constructing a client.
 *
 * @see com.amazonaws.auth.BasicAWSCredentials
 * @see com.amazonaws.auth.PropertiesCredentials
 * @see com.amazonaws.ClientConfiguration
 */
private static void init() throws Exception {

    dynamoDBClient = new AmazonDynamoDBClient(new DefaultAWSCredentialsProviderChain());

    // pass in the client for access to the cached metadata.
    RequestHandler2 requestHandler = new FaultInjectionRequestHandler(dynamoDBClient);

    dynamoDBClient.addRequestHandler(requestHandler);
}