Skip to content

Commit

Permalink
Merge branch 'master' into feautre/IncrementalSync
Browse files Browse the repository at this point in the history
  • Loading branch information
nobodyiam authored Dec 28, 2024
2 parents a4a2d05 + 0c7c341 commit 04f50ac
Show file tree
Hide file tree
Showing 67 changed files with 693 additions and 67 deletions.
9 changes: 5 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,12 @@ jobs:
with:
java-version: ${{ matrix.jdk }}
- name: Cache Maven packages
uses: actions/cache@v1
uses: actions/cache@v4
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
- name: JDK 8
if: matrix.jdk == '8'
run: mvn -B clean package jacoco:report -Dmaven.gitcommitid.skip=true
Expand Down
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ Apollo 2.4.0
* [Fix: ensure clusters order in envClusters open api](https://github.com/apolloconfig/apollo/pull/5277)
* [Fix: bump xstream from 1.4.20 to 1.4.21 to fix CVE-2024-47072](https://github.com/apolloconfig/apollo/pull/5280)
* [Feature: highlight diffs for properties](https://github.com/apolloconfig/apollo/pull/5282)
* [Feature: Add rate limiting function to ConsumerToken](https://github.com/apolloconfig/apollo/pull/5267)
* [Feature: add JSON formatting function in apollo-portal](https://github.com/apolloconfig/apollo/pull/5287)
* [Fix: add missing url patterns for AdminServiceAuthenticationFilter](https://github.com/apolloconfig/apollo/pull/5291)
* [Fix: support java.time.Instant serialization with gson](https://github.com/apolloconfig/apollo/pull/5298)

------------------
All issues and pull requests are [here](https://github.com/apolloconfig/apollo/milestone/15?closed=1)
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,15 @@ public FilterRegistrationBean<AdminServiceAuthenticationFilter> adminServiceAuth
FilterRegistrationBean<AdminServiceAuthenticationFilter> filterRegistrationBean = new FilterRegistrationBean<>();

filterRegistrationBean.setFilter(new AdminServiceAuthenticationFilter(bizConfig));
filterRegistrationBean.addUrlPatterns("/apollo/audit/*");
filterRegistrationBean.addUrlPatterns("/apps/*");
filterRegistrationBean.addUrlPatterns("/appnamespaces/*");
filterRegistrationBean.addUrlPatterns("/instances/*");
filterRegistrationBean.addUrlPatterns("/items/*");
filterRegistrationBean.addUrlPatterns("/items-search/*");
filterRegistrationBean.addUrlPatterns("/namespaces/*");
filterRegistrationBean.addUrlPatterns("/releases/*");
filterRegistrationBean.addUrlPatterns("/server/*");

return filterRegistrationBean;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public void appendDataInfluence(String entityName, String entityId, String field
@Override
public void appendDataInfluences(List<Object> entities, Class<?> beanDefinition) {
String tableName = ApolloAuditUtil.getApolloAuditLogTableName(beanDefinition);
if (Objects.isNull(tableName) || tableName.equals("")) {
if (Objects.isNull(tableName) || Objects.equals(tableName, "")) {
return;
}
List<Field> dataInfluenceFields = ApolloAuditUtil.getAnnotatedFields(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.ctrip.framework.apollo.audit.dto.ApolloAuditLogDataInfluenceDTO;
import com.ctrip.framework.apollo.audit.dto.ApolloAuditLogDetailsDTO;
import com.ctrip.framework.apollo.audit.dto.ApolloAuditLogDTO;
import java.util.Collections;
import java.util.Date;
import java.util.List;

Expand Down Expand Up @@ -50,28 +51,28 @@ public void appendDataInfluences(List<Object> entities, Class<?> beanDefinition)

@Override
public List<ApolloAuditLogDTO> queryLogs(int page, int size) {
return null;
return Collections.emptyList();
}

@Override
public List<ApolloAuditLogDTO> queryLogsByOpName(String opName, Date startDate,
Date endDate, int page, int size) {
return null;
return Collections.emptyList();
}

@Override
public List<ApolloAuditLogDetailsDTO> queryTraceDetails(String traceId) {
return null;
return Collections.emptyList();
}

@Override
public List<ApolloAuditLogDataInfluenceDTO> queryDataInfluencesByField(String entityName,
String entityId, String fieldName, int page, int size) {
return null;
return Collections.emptyList();
}

@Override
public List<ApolloAuditLogDTO> searchLogByNameOrTypeOrOperator(String query, int page, int size) {
return null;
return Collections.emptyList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ public void setOpName(String opName) {
this.opName = opName;
}

@Override
public String toString() {
return toStringHelper().add("entityName", entityName).add("entityId", entityId)
.add("opName", opName).add("comment", comment).toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ public void setComment(String comment) {
this.comment = comment;
}

@Override
public String toString() {
return toStringHelper().add("name", name).add("appId", appId)
.add("parentClusterId", parentClusterId).add("comment", comment).toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ public void setType(int type) {
this.type = type;
}

@Override
public String toString() {
return toStringHelper().add("namespaceId", namespaceId).add("key", key)
.add("type", type).add("value", value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public void setNamespaceName(String namespaceName) {
this.namespaceName = namespaceName;
}

@Override
public String toString() {
return toStringHelper().add("appId", appId).add("clusterName", clusterName)
.add("namespaceName", namespaceName).toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public void setPrivilType(String privilType) {
this.privilType = privilType;
}

@Override
public String toString() {
return toStringHelper().add("namespaceId", namespaceId).add("privilType", privilType)
.add("name", name).toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ public void setAbandoned(boolean abandoned) {
isAbandoned = abandoned;
}

@Override
public String toString() {
return toStringHelper().add("name", name).add("appId", appId).add("clusterName", clusterName)
.add("namespaceName", namespaceName).add("configurations", configurations)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ public void setOperationContext(String operationContext) {
this.operationContext = operationContext;
}

@Override
public String toString() {
return toStringHelper().add("appId", appId).add("clusterName", clusterName)
.add("namespaceName", namespaceName).add("branchName", branchName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ public void setCluster(String cluster) {
this.cluster = cluster;
}

@Override
public String toString() {
return toStringHelper().add("key", key).add("value", value).add("comment", comment).toString();
return toStringHelper().add("key", key).add("value", value).add("cluster", cluster).add("comment", comment).toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,13 @@ static ServiceRegistry convert(ServiceInstance instance) {
return serviceRegistry;
}

@Override
public void register(ServiceInstance instance) {
ServiceRegistry serviceRegistry = convert(instance);
this.serviceRegistryService.saveIfNotExistByServiceNameAndUri(serviceRegistry);
}

@Override
public void deregister(ServiceInstance instance) {
ServiceRegistry serviceRegistry = convert(instance);
this.serviceRegistryService.delete(serviceRegistry);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ public void setEnabled(boolean enabled) {
this.enabled = enabled;
}

@Override
public String getServiceName() {
return serviceName;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import com.ctrip.framework.apollo.core.ConfigConsts;
import com.google.common.base.Splitter;
import java.util.Collections;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -42,7 +43,7 @@ public static List<String> messageToList(String message) {
//message should be appId+cluster+namespace
if (keys.size() != 3) {
logger.error("message format invalid - {}", message);
return null;
return Collections.emptyList();
}
return keys;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@

import java.util.List;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Set;
import java.util.concurrent.CountDownLatch;
Expand All @@ -33,7 +31,6 @@
import java.util.concurrent.TimeUnit;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;

/**
* @author Jason Song([email protected])
Expand Down Expand Up @@ -80,7 +77,8 @@ public void testMessageToList() {

message = "appId+cluster";
keys = ReleaseMessageKeyGenerator.messageToList(message);
assertNull(keys);
assert keys != null;
assertEquals(0, keys.size());
}

private Runnable generateReleaseKeysTask(Namespace namespace, Set<String> releaseKeys,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@
import com.google.common.collect.Lists;
import com.google.gson.GsonBuilder;

import com.google.gson.JsonDeserializer;
import com.google.gson.JsonNull;
import com.google.gson.JsonPrimitive;
import com.google.gson.JsonSerializer;
import java.time.Instant;
import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
Expand All @@ -37,9 +42,23 @@
public class HttpMessageConverterConfiguration {
@Bean
public HttpMessageConverters messageConverters() {
// Custom Gson TypeAdapter for Instant
JsonSerializer<Instant> instantJsonSerializer = (src, typeOfSrc, context) ->
src == null ? JsonNull.INSTANCE : new JsonPrimitive(src.toString()); // Serialize Instant as ISO-8601 string

JsonDeserializer<Instant> instantJsonDeserializer = (json, typeOfT, context) -> {
if (json == null || json.isJsonNull()) {
return null;
}
return Instant.parse(json.getAsString()); // Deserialize from ISO-8601 string
};

GsonHttpMessageConverter gsonHttpMessageConverter = new GsonHttpMessageConverter();
gsonHttpMessageConverter.setGson(
new GsonBuilder().setDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ").create());
new GsonBuilder().setDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ")
.registerTypeAdapter(Instant.class, instantJsonSerializer)
.registerTypeAdapter(Instant.class, instantJsonDeserializer)
.create());
final List<HttpMessageConverter<?>> converters = Lists.newArrayList(
new ByteArrayHttpMessageConverter(), new StringHttpMessageConverter(),
new AllEncompassingFormHttpMessageConverter(), gsonHttpMessageConverter);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.security.CodeSource;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import javax.sql.DataSource;
import org.springframework.boot.jdbc.DataSourceBuilder;
Expand Down Expand Up @@ -101,7 +102,7 @@ private static List<String> resolveLocations(Collection<String> locations,
private static Collection<String> convertRepositoryLocations(Collection<String> locations,
DataSource dataSource) {
if (CollectionUtils.isEmpty(locations)) {
return null;
return Collections.emptyList();
}
String repositoryDir = findRepositoryDirectory();
String suffix = findSuffix(dataSource);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ public void setOwnerName(String ownerName) {
this.ownerName = ownerName;
}

@Override
public String toString() {
return toStringHelper().add("name", name).add("appId", appId)
.add("orgId", orgId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ public void setFormat(String format) {
this.format = format;
}

@Override
public String toString() {
return toStringHelper().add("name", name).add("appId", appId).add("comment", comment)
.add("format", format).add("isPublic", isPublic).toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ protected ToStringHelper toStringHelper() {
.add("dataChangeLastModifiedTime", dataChangeLastModifiedTime);
}

@Override
public String toString(){
return toStringHelper().toString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ public static BadRequestException orgIdIsBlank() {
return new BadRequestException("orgId can not be blank");
}

public static BadRequestException rateLimitIsInvalid() {
return new BadRequestException("rate limit must be greater than 1");
}

public static BadRequestException itemAlreadyExists(String itemKey) {
return new BadRequestException("item already exists for itemKey:%s", itemKey);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import com.ctrip.framework.apollo.common.entity.BaseEntity;

import javax.validation.constraints.PositiveOrZero;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.Where;

Expand All @@ -41,6 +42,10 @@ public class ConsumerToken extends BaseEntity {
@Column(name = "`Token`", nullable = false)
private String token;

@PositiveOrZero
@Column(name = "`RateLimit`", nullable = false)
private Integer rateLimit;

@Column(name = "`Expires`", nullable = false)
private Date expires;

Expand All @@ -60,6 +65,14 @@ public void setToken(String token) {
this.token = token;
}

public Integer getRateLimit() {
return rateLimit;
}

public void setRateLimit(Integer rateLimit) {
this.rateLimit = rateLimit;
}

public Date getExpires() {
return expires;
}
Expand All @@ -71,6 +84,7 @@ public void setExpires(Date expires) {
@Override
public String toString() {
return toStringHelper().add("consumerId", consumerId).add("token", token)
.add("rateLimit", rateLimit)
.add("expires", expires).toString();
}
}
Loading

0 comments on commit 04f50ac

Please sign in to comment.