diff --git a/waggle-dance-core/src/main/java/com/hotels/bdp/waggledance/client/CloseableThriftHiveMetastoreIfaceClientFactory.java b/waggle-dance-core/src/main/java/com/hotels/bdp/waggledance/client/CloseableThriftHiveMetastoreIfaceClientFactory.java index acf5f0793..4e5093806 100644 --- a/waggle-dance-core/src/main/java/com/hotels/bdp/waggledance/client/CloseableThriftHiveMetastoreIfaceClientFactory.java +++ b/waggle-dance-core/src/main/java/com/hotels/bdp/waggledance/client/CloseableThriftHiveMetastoreIfaceClientFactory.java @@ -25,11 +25,8 @@ import org.apache.hadoop.hive.conf.HiveConf.ConfVars; import org.apache.hadoop.hive.metastore.api.MetaException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import com.amazonaws.glue.catalog.metastore.AWSCatalogMetastoreClient; - import com.hotels.bdp.waggledance.api.WaggleDanceException; import com.hotels.bdp.waggledance.api.model.AbstractMetaStore; import com.hotels.bdp.waggledance.client.adapter.MetastoreIfaceAdapter; diff --git a/waggle-dance-core/src/main/java/com/hotels/bdp/waggledance/client/DefaultMetaStoreClientFactory.java b/waggle-dance-core/src/main/java/com/hotels/bdp/waggledance/client/DefaultMetaStoreClientFactory.java index e150b6b80..5c2f6a5a2 100644 --- a/waggle-dance-core/src/main/java/com/hotels/bdp/waggledance/client/DefaultMetaStoreClientFactory.java +++ b/waggle-dance-core/src/main/java/com/hotels/bdp/waggledance/client/DefaultMetaStoreClientFactory.java @@ -162,7 +162,6 @@ private SaslMetastoreClientHander( this.clientManager = clientManager; } - @SuppressWarnings("unchecked") @Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { try { diff --git a/waggle-dance-extensions/src/main/java/com/hotels/bdp/waggledance/extensions/ExtensionBeans.java b/waggle-dance-extensions/src/main/java/com/hotels/bdp/waggledance/extensions/ExtensionBeans.java index cc04b7d22..33f1c387f 100644 --- a/waggle-dance-extensions/src/main/java/com/hotels/bdp/waggledance/extensions/ExtensionBeans.java +++ b/waggle-dance-extensions/src/main/java/com/hotels/bdp/waggledance/extensions/ExtensionBeans.java @@ -29,24 +29,24 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import io.github.bucket4j.distributed.ExpirationAfterWriteStrategy; -import io.github.bucket4j.distributed.serialization.Mapper; -import io.github.bucket4j.redis.redisson.cas.RedissonBasedProxyManager; - import com.hotels.bdp.waggledance.client.ThriftClientFactory; -import com.hotels.bdp.waggledance.extensions.client.ratelimit.BucketBandwithProvider; +import com.hotels.bdp.waggledance.extensions.client.ratelimit.BucketBandwidthProvider; import com.hotels.bdp.waggledance.extensions.client.ratelimit.BucketService; import com.hotels.bdp.waggledance.extensions.client.ratelimit.RateLimitingClientFactory; import com.hotels.bdp.waggledance.extensions.client.ratelimit.RefillType; import com.hotels.bdp.waggledance.extensions.client.ratelimit.memory.InMemoryBucketService; import com.hotels.bdp.waggledance.extensions.client.ratelimit.redis.RedisBucketService; +import io.github.bucket4j.distributed.ExpirationAfterWriteStrategy; +import io.github.bucket4j.distributed.serialization.Mapper; +import io.github.bucket4j.redis.redisson.cas.RedissonBasedProxyManager; + @Configuration @ConditionalOnProperty(name = "waggledance.extensions.ratelimit.enabled", havingValue = "true") public class ExtensionBeans { private static final String STORAGE_MEMORY = "MEMORY"; - private static final String STORAGE_REDIS= "REDIS"; + private static final String STORAGE_REDIS = "REDIS"; @Bean public ThriftClientFactory thriftClientFactory( @@ -57,16 +57,16 @@ public ThriftClientFactory thriftClientFactory( @ConditionalOnProperty(name = "waggledance.extensions.ratelimit.storage", havingValue = STORAGE_MEMORY) @Bean - public BucketService inMemoryBucketService(BucketBandwithProvider bucketBandwithProvider) { - return new InMemoryBucketService(bucketBandwithProvider); + public BucketService inMemoryBucketService(BucketBandwidthProvider bucketBandwidthProvider) { + return new InMemoryBucketService(bucketBandwidthProvider); } @ConditionalOnProperty(name = "waggledance.extensions.ratelimit.storage", havingValue = STORAGE_REDIS) @Bean public BucketService redisBucketService( - BucketBandwithProvider bucketBandwithProvider, + BucketBandwidthProvider bucketBandwidthProvider, RedissonBasedProxyManager redissonBasedProxyManager) { - return new RedisBucketService(bucketBandwithProvider, redissonBasedProxyManager); + return new RedisBucketService(bucketBandwidthProvider, redissonBasedProxyManager); } @ConditionalOnProperty(name = "waggledance.extensions.ratelimit.storage", havingValue = STORAGE_REDIS) @@ -88,7 +88,7 @@ public RedissonBasedProxyManager redissonBasedProxyManager( } @Bean - public BucketBandwithProvider bucketBandwithProvider( + public BucketBandwidthProvider bucketBandwidthProvider( @Value("${waggledance.extensions.ratelimit.capacity:2000}") long capacity, @Value("${waggledance.extensions.ratelimit.tokensPerMinute:1000}") long tokensPerMinute, @Value("${waggledance.extensions.ratelimit.refillType:GREEDY}") RefillType refillType) { diff --git a/waggle-dance-extensions/src/main/java/com/hotels/bdp/waggledance/extensions/client/ratelimit/BucketBandwithProvider.java b/waggle-dance-extensions/src/main/java/com/hotels/bdp/waggledance/extensions/client/ratelimit/BucketBandwidthProvider.java similarity index 100% rename from waggle-dance-extensions/src/main/java/com/hotels/bdp/waggledance/extensions/client/ratelimit/BucketBandwithProvider.java rename to waggle-dance-extensions/src/main/java/com/hotels/bdp/waggledance/extensions/client/ratelimit/BucketBandwidthProvider.java diff --git a/waggle-dance-extensions/src/main/java/com/hotels/bdp/waggledance/extensions/client/ratelimit/GreedyBandwidthProvider.java b/waggle-dance-extensions/src/main/java/com/hotels/bdp/waggledance/extensions/client/ratelimit/GreedyBandwidthProvider.java index f367139d7..7fe6b2bcf 100644 --- a/waggle-dance-extensions/src/main/java/com/hotels/bdp/waggledance/extensions/client/ratelimit/GreedyBandwidthProvider.java +++ b/waggle-dance-extensions/src/main/java/com/hotels/bdp/waggledance/extensions/client/ratelimit/GreedyBandwidthProvider.java @@ -19,7 +19,7 @@ import io.github.bucket4j.Bandwidth; -public class GreedyBandwidthProvider implements BucketBandwithProvider { +public class GreedyBandwidthProvider implements BucketBandwidthProvider { private final long capacity; private final long tokensPerMinute; @@ -30,7 +30,7 @@ public GreedyBandwidthProvider(long capacity, long tokensPerMinute) { } @Override - public Bandwidth getBandwith() { + public Bandwidth getBandwidth() { Bandwidth limit = Bandwidth .builder() .capacity(capacity) diff --git a/waggle-dance-extensions/src/main/java/com/hotels/bdp/waggledance/extensions/client/ratelimit/IntervallyBandwidthProvider.java b/waggle-dance-extensions/src/main/java/com/hotels/bdp/waggledance/extensions/client/ratelimit/IntervallyBandwidthProvider.java index 3c757de6b..c090360f1 100644 --- a/waggle-dance-extensions/src/main/java/com/hotels/bdp/waggledance/extensions/client/ratelimit/IntervallyBandwidthProvider.java +++ b/waggle-dance-extensions/src/main/java/com/hotels/bdp/waggledance/extensions/client/ratelimit/IntervallyBandwidthProvider.java @@ -19,7 +19,7 @@ import io.github.bucket4j.Bandwidth; -public class IntervallyBandwidthProvider implements BucketBandwithProvider { +public class IntervallyBandwidthProvider implements BucketBandwidthProvider { private long capacity; private long tokensPerMinute; @@ -30,7 +30,7 @@ public IntervallyBandwidthProvider(long capacity, long tokensPerMinute) { } @Override - public Bandwidth getBandwith() { + public Bandwidth getBandwidth() { Bandwidth limit = Bandwidth .builder() .capacity(capacity) diff --git a/waggle-dance-extensions/src/main/java/com/hotels/bdp/waggledance/extensions/client/ratelimit/RefillType.java b/waggle-dance-extensions/src/main/java/com/hotels/bdp/waggledance/extensions/client/ratelimit/RefillType.java index 1cd3e2b60..0afd138ba 100644 --- a/waggle-dance-extensions/src/main/java/com/hotels/bdp/waggledance/extensions/client/ratelimit/RefillType.java +++ b/waggle-dance-extensions/src/main/java/com/hotels/bdp/waggledance/extensions/client/ratelimit/RefillType.java @@ -18,16 +18,16 @@ public enum RefillType { GREEDY { @Override - public BucketBandwithProvider createBandwidthProvider(long capacity, long tokensPerMinute) { + public BucketBandwidthProvider createBandwidthProvider(long capacity, long tokensPerMinute) { return new GreedyBandwidthProvider(capacity, tokensPerMinute); } }, INTERVALLY { @Override - public BucketBandwithProvider createBandwidthProvider(long capacity, long tokensPerMinute) { + public BucketBandwidthProvider createBandwidthProvider(long capacity, long tokensPerMinute) { return new IntervallyBandwidthProvider(capacity, tokensPerMinute); } }; - public abstract BucketBandwithProvider createBandwidthProvider(long capacity, long tokensPerMinute); + public abstract BucketBandwidthProvider createBandwidthProvider(long capacity, long tokensPerMinute); } diff --git a/waggle-dance-extensions/src/main/java/com/hotels/bdp/waggledance/extensions/client/ratelimit/memory/InMemoryBucketService.java b/waggle-dance-extensions/src/main/java/com/hotels/bdp/waggledance/extensions/client/ratelimit/memory/InMemoryBucketService.java index cbfb9bc91..d29f467a9 100644 --- a/waggle-dance-extensions/src/main/java/com/hotels/bdp/waggledance/extensions/client/ratelimit/memory/InMemoryBucketService.java +++ b/waggle-dance-extensions/src/main/java/com/hotels/bdp/waggledance/extensions/client/ratelimit/memory/InMemoryBucketService.java @@ -20,7 +20,7 @@ import io.github.bucket4j.Bucket; -import com.hotels.bdp.waggledance.extensions.client.ratelimit.BucketBandwithProvider; +import com.hotels.bdp.waggledance.extensions.client.ratelimit.BucketBandwidthProvider; import com.hotels.bdp.waggledance.extensions.client.ratelimit.BucketService; /** @@ -29,15 +29,15 @@ */ public class InMemoryBucketService implements BucketService { - private final BucketBandwithProvider bucketBandwithProvider; + private final BucketBandwidthProvider bucketBandwidthProvider; private Map bucketsPerUser = new HashMap<>(); - public InMemoryBucketService(BucketBandwithProvider bucketBandwithProvider) { - this.bucketBandwithProvider = bucketBandwithProvider; + public InMemoryBucketService(BucketBandwidthProvider bucketBandwidthProvider) { + this.bucketBandwidthProvider = bucketBandwidthProvider; } private Bucket createNewBucket() { - return Bucket.builder().addLimit(bucketBandwithProvider.getBandwith()).build(); + return Bucket.builder().addLimit(bucketBandwidthProvider.getBandwidth()).build(); } public Bucket getBucket(String key) { diff --git a/waggle-dance-extensions/src/main/java/com/hotels/bdp/waggledance/extensions/client/ratelimit/redis/RedisBucketService.java b/waggle-dance-extensions/src/main/java/com/hotels/bdp/waggledance/extensions/client/ratelimit/redis/RedisBucketService.java index e6f93c475..1af0ae165 100644 --- a/waggle-dance-extensions/src/main/java/com/hotels/bdp/waggledance/extensions/client/ratelimit/redis/RedisBucketService.java +++ b/waggle-dance-extensions/src/main/java/com/hotels/bdp/waggledance/extensions/client/ratelimit/redis/RedisBucketService.java @@ -19,7 +19,7 @@ import io.github.bucket4j.BucketConfiguration; import io.github.bucket4j.redis.redisson.cas.RedissonBasedProxyManager; -import com.hotels.bdp.waggledance.extensions.client.ratelimit.BucketBandwithProvider; +import com.hotels.bdp.waggledance.extensions.client.ratelimit.BucketBandwidthProvider; import com.hotels.bdp.waggledance.extensions.client.ratelimit.BucketService; /** @@ -32,10 +32,10 @@ public class RedisBucketService implements BucketService { private final BucketConfiguration configuration; public RedisBucketService( - BucketBandwithProvider bucketBandwithProvider, + BucketBandwidthProvider bucketBandwidthProvider, RedissonBasedProxyManager proxyManager) { this.proxyManager = proxyManager; - configuration = BucketConfiguration.builder().addLimit(bucketBandwithProvider.getBandwith()).build(); + configuration = BucketConfiguration.builder().addLimit(bucketBandwidthProvider.getBandwidth()).build(); } @Override diff --git a/waggle-dance-extensions/src/test/java/com/hotels/bdp/waggledance/extensions/client/ratelimit/RateLimitingInvocationHandlerTest.java b/waggle-dance-extensions/src/test/java/com/hotels/bdp/waggledance/extensions/client/ratelimit/RateLimitingInvocationHandlerTest.java index 9b89f87a7..5da82db50 100644 --- a/waggle-dance-extensions/src/test/java/com/hotels/bdp/waggledance/extensions/client/ratelimit/RateLimitingInvocationHandlerTest.java +++ b/waggle-dance-extensions/src/test/java/com/hotels/bdp/waggledance/extensions/client/ratelimit/RateLimitingInvocationHandlerTest.java @@ -15,14 +15,15 @@ */ package com.hotels.bdp.waggledance.extensions.client.ratelimit; +import static com.hotels.bdp.waggledance.extensions.client.ratelimit.RateLimitingInvocationHandler.UNKNOWN_USER; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.Assert.fail; import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import static com.hotels.bdp.waggledance.extensions.client.ratelimit.RateLimitingInvocationHandler.UNKNOWN_USER; - import org.apache.hadoop.hive.metastore.api.NoSuchObjectException; import org.apache.hadoop.hive.metastore.api.Table; import org.junit.Test; @@ -71,6 +72,9 @@ public void testLimitDifferentUsers() throws Exception { } catch (WaggleDanceServerException e) { assertThat(e.getMessage(), is("[STATUS=429] Too many requests.")); } + + verify(client, times(3)).get_table("db", "table"); + verify(client).set_ugi(USER, null); } @Test @@ -103,6 +107,25 @@ public void testInvocationHandlerThrowsCause() throws Exception { assertThat(e.getMessage(), is("No such table")); } } + + @Test + public void testIgnoredMethods() throws Exception { + when(thriftClientFactory.newInstance(metastore)).thenReturn(client); + CloseableThriftHiveMetastoreIface handlerProxy = new RateLimitingClientFactory(thriftClientFactory, bucketService) + .newInstance(metastore); + + assertTokens(2, 2); + handlerProxy.set_ugi(USER, null); + handlerProxy.isOpen(); + handlerProxy.flushCache(); + handlerProxy.close(); + assertTokens(2, 2); + + verify(client).set_ugi(USER, null); + verify(client).isOpen(); + verify(client).flushCache(); + verify(client).close(); + } private void assertTokens(long expectedUserTokenCount, long expectedUnknownUserTokenCount) { assertThat(bucketService.getBucket(USER).getAvailableTokens(), is(expectedUserTokenCount));