Skip to content

Commit f9b3233

Browse files
committed
Divide redisFactory class. Apply codecov again
1 parent f3d34c0 commit f9b3233

29 files changed

+209
-173
lines changed

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ before_script:
1515
- "chmod +x gradlew"
1616
script:
1717
- "./gradlew clean build"
18-
#- "./gradlew clean jacocoTestReport"
18+
- "./gradlew clean jacocoTestReport"
1919
after_success:
20-
#:- "bash <(curl -s https://codecov.io/bash) -t 173de125-e3f2-41eb-ab59-afca23c26c40"
20+
:- "bash <(curl -s https://codecov.io/bash) -t 173de125-e3f2-41eb-ab59-afca23c26c40"
2121

2222
notifications:
2323
email:

build.gradle

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,6 @@ dependencies {
7373

7474
// test
7575
testCompile('org.springframework.boot:spring-boot-starter-test')
76-
testCompile('junit:junit:4.13-beta-1')
77-
testCompile('ai.grakn:redis-mock:0.1.6')
7876

7977
}
8078

src/main/java/com/longcoding/moon/MoonApplication.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ public static void main(String[] args) {
3232
.properties("spring.config.location:classpath:/apps/, classpath:/apis/, classpath:/")
3333
.build().run(args);
3434

35-
36-
3735
}
3836

3937
}

src/main/java/com/longcoding/moon/configs/MoonServletConfig.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
import com.fasterxml.jackson.databind.ObjectMapper;
66
import com.fasterxml.jackson.databind.SerializationFeature;
77
import com.google.common.collect.Lists;
8+
import com.longcoding.moon.interceptors.AbstractBaseInterceptor;
89
import com.longcoding.moon.interceptors.impl.*;
10+
import org.springframework.beans.factory.annotation.Value;
911
import org.springframework.context.annotation.Bean;
1012
import org.springframework.context.annotation.Configuration;
1113
import org.springframework.core.Ordered;
@@ -38,6 +40,10 @@ public class MoonServletConfig implements WebMvcConfigurer {
3840
* The internal api and swagger settings are likely to change.
3941
*/
4042

43+
@Value("${moon.service.api-ratelimit.enable}")
44+
boolean useApiRatelimit;
45+
46+
4147
private static final List<String> EXCLUDE_PATH_INTERNAL_API = Arrays.asList("/internal/**", "/");
4248
private static final List<String> EXCLUDE_PATH_SWAGGER_UI = Arrays.asList("/swagger-ui.html", "/swagger-resources/**", "/v2/api-docs", "/webjars/**", "/error", "/csrf", "/");
4349
private static List<String> EXCLUDE_TOTAL_PATH = Lists.newArrayList();
@@ -81,14 +87,14 @@ public class MoonServletConfig implements WebMvcConfigurer {
8187
* It is aimed to prevent load of outbound service.
8288
*/
8389
@Bean
84-
public ServiceCapacityInterceptor serviceCapacityInterceptor() { return new ServiceCapacityInterceptor(); }
90+
public AbstractBaseInterceptor serviceCapacityInterceptor() { return useApiRatelimit? new ServiceCapacityInterceptor() : new NoRatelimitInterceptor(); }
8591

8692
/**
8793
* ServiceCapacity interceptor and ApplicationRatelimitInterceptor are preliminary tasks to execute executeRedisValidation.
8894
* Execute the stored job at once and determine whether the request can be passed to the outbound service.
8995
* */
9096
@Bean
91-
public ExecuteRedisValidationInterceptor executeRedisValidationInterceptor() { return new ExecuteRedisValidationInterceptor(); }
97+
public AbstractBaseInterceptor executeRedisValidationInterceptor() { return useApiRatelimit? new ExecuteRedisValidationInterceptor(): new NoRatelimitInterceptor(); }
9298

9399
/**
94100
* Split the request path by '/' and save it.
@@ -117,7 +123,7 @@ public class MoonServletConfig implements WebMvcConfigurer {
117123
* Later, it may lead to a billing model.
118124
*/
119125
@Bean
120-
public ApplicationRatelimitInterceptor applicationRatelimitInterceptor() { return new ApplicationRatelimitInterceptor(); }
126+
public AbstractBaseInterceptor applicationRatelimitInterceptor() { return useApiRatelimit? new ApplicationRatelimitInterceptor(): new NoRatelimitInterceptor(); }
121127

122128
/**
123129
* Also check the service contract.

src/main/java/com/longcoding/moon/helpers/APIExposeSpecLoader.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import com.longcoding.moon.configs.APIExposeSpecConfig;
55
import com.longcoding.moon.exceptions.ExceptionType;
66
import com.longcoding.moon.exceptions.GeneralException;
7-
import com.longcoding.moon.helpers.cluster.IClusterRepository;
87
import com.longcoding.moon.models.apis.TransformData;
98
import com.longcoding.moon.models.cluster.ApiSync;
109
import com.longcoding.moon.models.ehcache.ApiInfo;
@@ -108,7 +107,8 @@ public void afterPropertiesSet() throws Exception {
108107
.routingType(serviceRoutingType)
109108
.build();
110109
apiExposeSpecification.getServiceInfoCache().put(service.getServiceId(), serviceInfo);
111-
clusterRepository.setServiceInfo(serviceInfo);
110+
111+
if (enableCluster) clusterRepository.setServiceInfo(serviceInfo);
112112
});
113113
} catch (Exception ex) {
114114
throw new GeneralException(ExceptionType.E_1200_FAIL_SERVICE_INFO_CONFIGURATION_INIT, ex);
@@ -158,9 +158,9 @@ public void afterPropertiesSet() throws Exception {
158158
.transformData(transformRequests)
159159
.build();
160160

161-
clusterRepository.setApiInfo(apiInfo);
162161
apiExposeSpecification.getApiInfoCache().put(apiSpec.getApiId(), apiInfo);
163162

163+
if (enableCluster) clusterRepository.setApiInfo(apiInfo);
164164
});
165165
});
166166

src/main/java/com/longcoding/moon/helpers/cluster/ClusterSyncUtil.java renamed to src/main/java/com/longcoding/moon/helpers/ClusterSyncUtil.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.longcoding.moon.helpers.cluster;
1+
package com.longcoding.moon.helpers;
22

33
import com.longcoding.moon.helpers.Constant;
44
import com.longcoding.moon.helpers.JedisFactory;

src/main/java/com/longcoding/moon/helpers/cluster/DBClusterRepository.java renamed to src/main/java/com/longcoding/moon/helpers/DBClusterRepository.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.longcoding.moon.helpers.cluster;
1+
package com.longcoding.moon.helpers;
22

33
import com.longcoding.moon.exceptions.ExceptionType;
44
import com.longcoding.moon.exceptions.GeneralException;

src/main/java/com/longcoding/moon/helpers/cluster/IClusterRepository.java renamed to src/main/java/com/longcoding/moon/helpers/IClusterRepository.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.longcoding.moon.helpers.cluster;
1+
package com.longcoding.moon.helpers;
22

33
import com.longcoding.moon.models.ehcache.ApiInfo;
44
import com.longcoding.moon.models.ehcache.AppInfo;

src/main/java/com/longcoding/moon/helpers/InitAppLoader.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import com.longcoding.moon.configs.InitAppConfig;
44
import com.longcoding.moon.exceptions.ExceptionType;
55
import com.longcoding.moon.exceptions.GeneralException;
6-
import com.longcoding.moon.helpers.cluster.IClusterRepository;
76
import com.longcoding.moon.models.cluster.AppSync;
87
import com.longcoding.moon.models.ehcache.AppInfo;
98
import com.longcoding.moon.models.enumeration.SyncType;
@@ -17,7 +16,6 @@
1716
import org.springframework.stereotype.Component;
1817

1918
import java.util.ArrayList;
20-
import java.util.stream.Collectors;
2119

2220
/**
2321
* A class that takes application information and loads it into the cache.
@@ -58,9 +56,7 @@ public void afterPropertiesSet() throws Exception {
5856
if (enableCluster) {
5957
try {
6058
clusterRepository.getAllAppInfo()
61-
.forEach(appInfo -> {
62-
syncService.syncAppInfoToCache(new AppSync(SyncType.CREATE, appInfo));
63-
});
59+
.forEach(appInfo -> syncService.syncAppInfoToCache(new AppSync(SyncType.CREATE, appInfo)));
6460
} catch (Exception ex) {
6561
throw new GeneralException(ExceptionType.E_1203_FAIL_CLUSTER_SYNC, ex);
6662
}
@@ -88,9 +84,9 @@ public void afterPropertiesSet() throws Exception {
8884
.build();
8985

9086
appInfoCaches.put(app.getAppId(), appInfo);
91-
92-
clusterRepository.setAppInfo(appInfo);
9387
aclIpChecker.enrolledInitAclIp(app.getAppId(), app.getAppIpAcl());
88+
89+
if (enableCluster) clusterRepository.setAppInfo(appInfo);
9490
});
9591

9692
} catch (Exception ex) {

src/main/java/com/longcoding/moon/helpers/cluster/RedisClusterRepository.java renamed to src/main/java/com/longcoding/moon/helpers/RedisClusterRepository.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1-
package com.longcoding.moon.helpers.cluster;
1+
package com.longcoding.moon.helpers;
22

33
import com.longcoding.moon.exceptions.ExceptionType;
44
import com.longcoding.moon.exceptions.GeneralException;
5-
import com.longcoding.moon.helpers.Constant;
6-
import com.longcoding.moon.helpers.JedisFactory;
7-
import com.longcoding.moon.helpers.JsonUtil;
85
import com.longcoding.moon.models.ehcache.ApiInfo;
96
import com.longcoding.moon.models.ehcache.AppInfo;
107
import com.longcoding.moon.models.ehcache.ServiceInfo;

0 commit comments

Comments
 (0)