Skip to content

Commit

Permalink
🎨 v2.5.4.40
Browse files Browse the repository at this point in the history
1. 优化自定义多级缓存,实现可以统一设置allowNullValues值,并解决存储空值时卡死问题。
2. 重新梳理、优化系统权限从Controller扫描、汇总存储至服务器以及动态修改后最终回传同步至服务的整理逻辑以及事件流。完美支持单体式架构、UPMS自身应用需求、分布式架构以及分布式各服务多实例等各种应用场景。
3. 增加Kafka条件注入配置,将条件转换为@ConditionalOnXXX,方便管理和维护。避免单体版应用相关依赖过度依赖Kafka而导致的无法启动
4. 修复部分已知BUG,将部分代码中日志由@slf4j改回传统日志编写方式,一方面提高编译效率,另一方面解决源代码包查看时Idea提醒代码不一致问题。
  • Loading branch information
herodotus-ecosystem committed Aug 11, 2021
1 parent f39daaa commit 61be16c
Show file tree
Hide file tree
Showing 48 changed files with 511 additions and 303 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<a href="https://nacos.io/zh-cn/index.html" target="_blank"><img src="https://img.shields.io/badge/Nacos-2.0.3-brightgreen" alt="Nacos 2.0.3"></a>
<a href="./LICENSE"><img src="https://img.shields.io/badge/License-Apache--2.0-blue" alt="License Apache 2.0"></a>
<a href="https://blog.csdn.net/Pointer_v" target="_blank"><img src="https://img.shields.io/badge/Author-%E7%A0%81%E5%8C%A0%E5%90%9B-orange" alt="码匠君"></a>
<a href="#" target="_blank"><img src="https://img.shields.io/badge/Version-2.5.4.30-red" alt="Version 2.5.4.30"></a>
<a href="#" target="_blank"><img src="https://img.shields.io/badge/Version-2.5.4.40-red" alt="Version 2.5.4.40"></a>
<a href="https://gitee.com/herodotus/eurynome-cloud"><img src="https://gitee.com/herodotus/eurynome-cloud/badge/star.svg?theme=dark" alt="Gitee star"></a>
<a href="https://gitee.com/herodotus/eurynome-cloud"><img src="https://gitee.com/herodotus/eurynome-cloud/badge/fork.svg?theme=dark" alt="Gitee fork"></a>
</p>
Expand Down
2 changes: 1 addition & 1 deletion configurations/docker/docker-compose/herodotus/.env
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION=2.5.4.30
VERSION=2.5.4.40
GATEWAY_SERVICE_NAME=eurynome-cloud-gateway
GATEWAY_SERVICE_PORT=8847
UAA_SERVICE_NAME=eurynome-cloud-uaa
Expand Down
2 changes: 1 addition & 1 deletion dependencies/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

<groupId>cn.herodotus.eurynome</groupId>
<artifactId>dependencies</artifactId>
<version>2.5.4.30</version>
<version>2.5.4.40</version>
<packaging>pom</packaging>

<name>eurynome-cloud-dependencies</name>
Expand Down
2 changes: 1 addition & 1 deletion packages/eurynome-cloud-assistant/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<parent>
<artifactId>packages</artifactId>
<groupId>cn.herodotus.eurynome</groupId>
<version>2.5.4.30</version>
<version>2.5.4.40</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright (c) 2019-2021 Gengwei Zheng ([email protected])
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Project Name: eurynome-cloud
* Module Name: eurynome-cloud-assistant
* File Name: ConditionalOnKafkaEnabled.java
* Author: gengwei.zheng
* Date: 2021/08/11 20:36:11
*/

package cn.herodotus.eurynome.assistant.annotation;

import cn.herodotus.eurynome.constant.magic.PropertyConstants;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;

import java.lang.annotation.*;

/**
* <p>Description: kafka是否开启条件准基 </p>
*
* @author : gengwei.zheng
* @date : 2021/8/11 20:36
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE, ElementType.METHOD})
@Documented
@ConditionalOnProperty(value = PropertyConstants.ITEM_PLATFORM_KAFKA_ENABLED)
public @interface ConditionalOnKafkaEnabled {
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,43 +14,28 @@
* limitations under the License.
*
* Project Name: eurynome-cloud
* Module Name: eurynome-cloud-security
* File Name: SecurityMetadata.java
* Module Name: eurynome-cloud-assistant
* File Name: DestinationResolver.java
* Author: gengwei.zheng
* Date: 2021/08/05 17:14:05
* Date: 2021/08/11 20:39:11
*/

package cn.herodotus.eurynome.security.definition.core;
package cn.herodotus.eurynome.assistant.utils;

import org.springframework.security.core.GrantedAuthority;

import java.util.Collection;
import org.springframework.cloud.bus.event.Destination;
import org.springframework.cloud.bus.event.PathDestinationFactory;

/**
* <p>Description: 安全元数据 </p>
* <p>Description: Spring Cloud Bus Destination辅助类 </p>
*
* @author : gengwei.zheng
* @date : 2021/8/5 17:14
* @date : 2021/8/11 20:39
*/
public interface SecurityMetadata {

String getDefaultExpression();

String getStaticExpression();

String getDynamicExpression();

String getScopeExpression();

Collection<? extends GrantedAuthority> getRoles();

Collection<? extends GrantedAuthority> getScopes();

String getIpExpression();

String getUrl();
public class DestinationResolver {

String getRequestMethod();
private static final PathDestinationFactory pathDestinationFactory = new PathDestinationFactory();

String getServiceId();
public static Destination create(String serviceName) {
return pathDestinationFactory.getDestination(serviceName + ":**");
}
}
4 changes: 2 additions & 2 deletions packages/eurynome-cloud-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@
<parent>
<artifactId>packages</artifactId>
<groupId>cn.herodotus.eurynome</groupId>
<version>2.5.4.30</version>
<version>2.5.4.40</version>
</parent>

<artifactId>eurynome-cloud-common</artifactId>
<version>2.5.4.30</version>
<version>2.5.4.40</version>
<packaging>jar</packaging>

<description>结对基础通用的工具类包,此包的定位是放在任何工程中都可以使用,而且尽可能依赖少的存在上下文组件</description>
Expand Down
2 changes: 1 addition & 1 deletion packages/eurynome-cloud-constant/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<parent>
<artifactId>packages</artifactId>
<groupId>cn.herodotus.eurynome</groupId>
<version>2.5.4.30</version>
<version>2.5.4.40</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,20 @@
*/
public class CacheConstants {

public static final String CACHE_SIMPLE_BASE_PREFIX = "cache:simple:";
public static final String CACHE_PREFIX = "cache:";

public static final String CACHE_TOKEN_BASE_PREFIX = "cache:token:";
public static final String CACHE_SIMPLE_BASE_PREFIX = CACHE_PREFIX + "simple:";
public static final String CACHE_TOKEN_BASE_PREFIX = CACHE_PREFIX + "token:";

public static final String CACHE_SECURITY_PREFIX = CACHE_PREFIX + "security:";
public static final String CACHE_SECURITY_METADATA_PREFIX = CACHE_SECURITY_PREFIX + "metadata:";

public static final String CACHE_NAME_SECURITY_METADATA_ATTRIBUTES = CACHE_SECURITY_METADATA_PREFIX + "attributes:";
public static final String CACHE_NAME_SECURITY_METADATA_INDEXABLE = CACHE_SECURITY_METADATA_PREFIX + "indexable:";
public static final String CACHE_NAME_SECURITY_METADATA_COMPATIBLE = CACHE_SECURITY_METADATA_PREFIX + "compatible:";

public static final int DEFAULT_UPMS_CACHE_EXPIRE = 86400;
public static final int DEFAULT_UPMS_LOCAL_LIMIT = 1000;


public static final String INDEX_CACHE_NAME = "index:";
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public class PropertyConstants {

public static final String ITEM_PLATFORM_DATA_ACCESS_STRATEGY = PROPERTY_PREFIX_PLATFORM + ".data-access-strategy";
public static final String ITEM_PLATFORM_ARCHITECTURE = PROPERTY_PREFIX_PLATFORM + ".architecture";
public static final String ITEM_PLATFORM_KAFKA_ENABLED = PROPERTY_PREFIX_MANAGEMENT_QUEUE + ".kafka.enabled";

public static final String ANNOTATION_DEBEZIUM_ENABLED = "${herodotus.platform.debezium.enabled}";
}
4 changes: 2 additions & 2 deletions packages/eurynome-cloud-crud/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@
<parent>
<artifactId>packages</artifactId>
<groupId>cn.herodotus.eurynome</groupId>
<version>2.5.4.30</version>
<version>2.5.4.40</version>
</parent>

<artifactId>eurynome-cloud-crud</artifactId>
<version>2.5.4.30</version>
<version>2.5.4.40</version>
<packaging>jar</packaging>

<dependencies>
Expand Down
4 changes: 2 additions & 2 deletions packages/eurynome-cloud-data/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@
<parent>
<artifactId>packages</artifactId>
<groupId>cn.herodotus.eurynome</groupId>
<version>2.5.4.30</version>
<version>2.5.4.40</version>
</parent>

<artifactId>eurynome-cloud-data</artifactId>
<version>2.5.4.30</version>
<version>2.5.4.40</version>
<packaging>jar</packaging>

<description>数据相关通用代码组件包,包括JPA,Redis,数据实体等相关内容</description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,11 @@
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cache.Cache;
import org.springframework.cache.caffeine.CaffeineCache;
import org.springframework.cache.support.AbstractValueAdaptingCache;
import org.springframework.cache.support.NullValue;
import org.springframework.data.redis.cache.RedisCache;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;

import java.util.concurrent.Callable;

Expand All @@ -45,6 +43,7 @@
* @date : 2021/7/14 11:04
*/
public class HerodotusCache extends AbstractValueAdaptingCache {

private static final Logger log = LoggerFactory.getLogger(HerodotusCache.class);

private final String name;
Expand All @@ -53,10 +52,6 @@ public class HerodotusCache extends AbstractValueAdaptingCache {
private final boolean desensitization;
private final boolean clearRemoteOnExit;

public HerodotusCache(String name, CaffeineCache caffeineCache, RedisCache redisCache, boolean desensitization, boolean clearRemoteOnExit) {
this(name, caffeineCache, redisCache, desensitization, clearRemoteOnExit, true);
}

public HerodotusCache(String name, CaffeineCache caffeineCache, RedisCache redisCache, boolean desensitization, boolean clearRemoteOnExit, boolean allowNullValues) {
super(allowNullValues);
this.name = name;
Expand Down Expand Up @@ -139,7 +134,6 @@ public <T> T get(Object key, Class<T> type) {

String secure = secure(key);


T caffeineValue = caffeineCache.get(secure, type);
if (ObjectUtils.isNotEmpty(caffeineValue)) {
log.trace("[Eurynome] |- CACHE - Get <T> with type form caffeine cache, hit the cache.");
Expand Down Expand Up @@ -189,14 +183,20 @@ public <T> T get(Object key, Callable<T> valueLoader) {
}

@Override
public void put(Object key, Object value) {
public void put(Object key, @Nullable Object value) {

String secure = secure(key);
if (!isAllowNullValues() && value == null) {
throw new IllegalArgumentException(String.format(
"Cache '%s' does not allow 'null' values. Avoid storing null via '@Cacheable(unless=\"#result == null\")' or configure RedisCache to allow 'null' via RedisCacheConfiguration.",
name));
} else {
String secure = secure(key);

caffeineCache.put(secure, value);
redisCache.put(secure, value);
caffeineCache.put(secure, value);
redisCache.put(secure, value);

log.debug("[Eurynome] |- CACHE - Put data into Herodotus Cache, with key: [{}] and value: [{}]", secure, value);
log.debug("[Eurynome] |- CACHE - Put data into Herodotus Cache, with key: [{}] and value: [{}]", secure, value);
}
}

@Override
Expand Down Expand Up @@ -230,7 +230,7 @@ public void evict(Object key) {
@Override
public void clear() {

log.debug("[Eurynome] |- CACHE - Clear Herodotus Cache.");
log.trace("[Eurynome] |- CACHE - Clear Herodotus Cache.");

if (clearRemoteOnExit) {
redisCache.clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public class HerodotusCacheManager implements CacheManager {
private CaffeineCacheManager caffeineCacheManager;
private boolean desensitization = true;
private boolean clearRemoteOnExit = false;
private boolean allowNullValues = true;

private boolean dynamic = true;

Expand Down Expand Up @@ -80,6 +81,14 @@ public void setClearRemoteOnExit(boolean clearRemoteOnExit) {
this.clearRemoteOnExit = clearRemoteOnExit;
}

public boolean isAllowNullValues() {
return allowNullValues;
}

public void setAllowNullValues(boolean allowNullValues) {
this.allowNullValues = allowNullValues;
}

/**
* Specify the set of cache names for this CacheManager's 'static' mode.
* <p>The number of caches and their names will be fixed after a call to this method,
Expand All @@ -102,7 +111,7 @@ protected Cache createHerodotusCache(String name) {
CaffeineCache caffeineCache = (CaffeineCache) this.caffeineCacheManager.getCache(name);
RedisCache redisCache = (RedisCache) this.redisCacheManager.getCache(name);
log.debug("[Eurynome] |- CACHE - Herodotus cache [{}] is CREATED.", name);
return new HerodotusCache(name, caffeineCache, redisCache, desensitization, clearRemoteOnExit);
return new HerodotusCache(name, caffeineCache, redisCache, desensitization, clearRemoteOnExit, isAllowNullValues());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public Caffeine<Object, Object> caffeine() {
public CaffeineCacheManager caffeineCacheManager() {
CaffeineCacheManager caffeineCacheManager = new CaffeineCacheManager();
caffeineCacheManager.setCaffeine(caffeine());
caffeineCacheManager.setAllowNullValues(cacheProperties.getAllowNullValues());

log.trace("[Eurynome] |- Bean [Caffeine Cache Manager] Auto Configure.");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
import cn.herodotus.eurynome.data.cache.layer.HerodotusCacheManager;
import cn.herodotus.eurynome.data.properties.CacheProperties;
import cn.hutool.extra.spring.SpringUtil;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.data.jpa.JpaRepositoriesAutoConfiguration;
Expand Down Expand Up @@ -63,13 +64,13 @@
* @author : gengwei.zheng
* @date : 2020/3/4 10:49
*/
@Slf4j
@Configuration(proxyBeanMethods = false)
@EnableJpaAuditing
@AutoConfigureAfter(JpaRepositoriesAutoConfiguration.class)
@Import({SpringUtil.class, CaffeineConfiguration.class, KafkaConfiguration.class})
public class DataConfiguration {

private static final Logger log = LoggerFactory.getLogger(DataConfiguration.class);

@Autowired
private CacheProperties cacheProperties;
Expand All @@ -87,6 +88,7 @@ public HerodotusCacheManager herodotusCacheManager(CaffeineCacheManager caffeine
herodotusCacheManager.setRedisCacheManager(redisCacheManager);
herodotusCacheManager.setDesensitization(cacheProperties.getDesensitization());
herodotusCacheManager.setClearRemoteOnExit(cacheProperties.getClearRemoteOnExit());
herodotusCacheManager.setAllowNullValues(cacheProperties.getAllowNullValues());

log.trace("[Eurynome] |- Bean [Herodotus Cache Manager] Auto Configure.");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

package cn.herodotus.eurynome.data.configuration;

import cn.herodotus.eurynome.assistant.annotation.ConditionalOnKafkaEnabled;
import cn.herodotus.eurynome.data.properties.QueueProperties;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -41,6 +42,7 @@
* @date : 2021/8/8 10:41
*/
@Configuration
@ConditionalOnKafkaEnabled
public class KafkaConfiguration {

private static final Logger log = LoggerFactory.getLogger(KafkaConfiguration.class);
Expand Down
Loading

0 comments on commit 61be16c

Please sign in to comment.