Commit 880f9763 authored by Matija Obreza's avatar Matija Obreza

Merge branch '29-rate-limit-calls-to-glis' into 'master'

Resolve "Rate limit calls to GLIS"

Closes #29

See merge request genesys-pgr/glis-client!18
parents 37a2a4fe 574be7a0
......@@ -6,16 +6,22 @@
<relativePath>..</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>glis-client-tests</artifactId>
<artifactId>glis-client-common</artifactId>
<packaging>jar</packaging>
<name>GLIS API client tests</name>
<description>Tests for GLIS API client</description>
<name>GLIS API client tests and common code</name>
<description>Tests and common code for GLIS API client</description>
<properties>
<org.slf4j.version>1.7.25</org.slf4j.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
<version>4.3.2.RELEASE</version>
<scope>provided</scope>
</dependency>
<!-- test dependencies -->
<dependency>
<groupId>junit</groupId>
......@@ -35,7 +41,6 @@
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${org.slf4j.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
......@@ -49,6 +54,11 @@
<version>${org.slf4j.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>23.2-jre</version>
</dependency>
</dependencies>
<build>
......
package org.genesys.glis.v1;
import com.google.common.util.concurrent.RateLimiter;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Aspect to control the rate of calls to GLIS API
*/
@Aspect
public class GlisRateLimiter {
private static final Logger LOG = LoggerFactory.getLogger(GlisRateLimiter.class);
private RateLimiter limiter = RateLimiter.create(20);
public GlisRateLimiter(double permitsPerSecond) {
setPermitsPerSecond(permitsPerSecond);
}
public void setPermitsPerSecond(double permitsPerSecond) {
limiter = RateLimiter.create(permitsPerSecond);
}
@Before("execution(* org.genesys.glis.v1.api.*.*(..))")
public void rateLimit(JoinPoint jp) {
double delay = limiter.acquire();
LOG.debug("Acquired rate limit permission ({} qps) in {} seconds for {}", limiter.getRate(), delay, jp.toLongString());
}
}
......@@ -26,7 +26,11 @@
<artifactId>swagger-annotations</artifactId>
<version>${swagger-core.version}</version>
</dependency>
<dependency>
<groupId>org.genesys-pgr</groupId>
<artifactId>glis-client-common</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<!-- HTTP client: jersey-client -->
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
......@@ -85,12 +89,6 @@
<version>2.2</version>
</dependency>
<!-- test dependencies -->
<dependency>
<groupId>org.genesys-pgr</groupId>
<artifactId>glis-client-tests</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
......
......@@ -26,6 +26,11 @@
<artifactId>swagger-annotations</artifactId>
<version>${swagger-core.version}</version>
</dependency>
<dependency>
<groupId>org.genesys-pgr</groupId>
<artifactId>glis-client-common</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.squareup.okhttp</groupId>
<artifactId>okhttp</artifactId>
......@@ -42,12 +47,6 @@
<version>${gson-version}</version>
</dependency>
<!-- test dependencies -->
<dependency>
<groupId>org.genesys-pgr</groupId>
<artifactId>glis-client-tests</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
......
......@@ -73,20 +73,35 @@
</sources>
</configuration>
</execution>
<execution>
<id>add-common-source</id>
<phase>initialize</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>../src/common/java</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>flatten-maven-plugin</artifactId>
<version>1.0.1</version>
<configuration>
<flattenMode>ossrh</flattenMode>
</configuration>
<executions>
<!-- enable flattening -->
<execution>
<id>flatten</id>
<phase>process-resources</phase>
<goals>
<goal>flatten</goal>
</goals>
</execution>
<!-- ensure proper cleanup -->
<execution>
<id>flatten.clean</id>
<phase>clean</phase>
<goals>
<goal>clean</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- <plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.7</version>
......
......@@ -42,7 +42,7 @@
</issueManagement>
<modules>
<module>tests</module>
<module>common</module>
<module>okhttp-gson</module>
<module>jersey2</module>
<module>resteasy</module>
......
......@@ -26,6 +26,11 @@
<artifactId>swagger-annotations</artifactId>
<version>${swagger-core.version}</version>
</dependency>
<dependency>
<groupId>org.genesys-pgr</groupId>
<artifactId>glis-client-common</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<!-- HTTP client: jersey-client -->
<!-- HTTP client: jersey-client -->
......@@ -76,12 +81,6 @@
</dependency>
<!-- test dependencies -->
<dependency>
<groupId>org.genesys-pgr</groupId>
<artifactId>glis-client-tests</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
......
......@@ -26,6 +26,11 @@
<artifactId>swagger-annotations</artifactId>
<version>${swagger-core.version}</version>
</dependency>
<dependency>
<groupId>org.genesys-pgr</groupId>
<artifactId>glis-client-common</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<!-- HTTP client: Spring RestTemplate -->
<dependency>
......@@ -75,12 +80,6 @@
<version>${junit-version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.genesys-pgr</groupId>
<artifactId>glis-client-tests</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-library</artifactId>
......
......@@ -26,6 +26,7 @@ import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import org.genesys.glis.v1.TermConstants;
import org.genesys.glis.v1.model.PGRFA;
import org.genesys.glis.v1.model.UpdateTargets;
import org.genesys.glis.v1.model.UpdatedTarget;
......@@ -50,7 +51,7 @@ public class GenesysGlisTest extends TestEnvironmentAPITest {
if (somePgrfa.size() > 0) {
assertThat(somePgrfa, hasSize(perPage));
UpdateTargets targets = new UpdateTargets();
targets.addKwsItem("1");
targets.addKwsItem(TermConstants.PASSPORT_DATA);
for (PGRFA pgrfa : somePgrfa) {
targets.addDoisItem(pgrfa.getDoi());
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment