-
Notifications
You must be signed in to change notification settings - Fork 504
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #872 from wangqifan/feature/disable_db
add disable db mode for console
- Loading branch information
Showing
77 changed files
with
3,173 additions
and
1,165 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
...checker/src/main/java/com/ctrip/xpipe/redis/checker/spring/ConsoleDisableDbCondition.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.ctrip.xpipe.redis.checker.spring; | ||
|
||
import com.ctrip.xpipe.redis.checker.config.impl.CommonConfigBean; | ||
import org.springframework.context.annotation.Condition; | ||
import org.springframework.context.annotation.ConditionContext; | ||
import org.springframework.core.type.AnnotatedTypeMetadata; | ||
|
||
import java.util.Map; | ||
|
||
public class ConsoleDisableDbCondition implements Condition { | ||
|
||
private static CommonConfigBean commonConfigBean = new CommonConfigBean(); | ||
|
||
|
||
@Override | ||
public boolean matches(ConditionContext conditionContext, AnnotatedTypeMetadata annotatedTypeMetadata) { | ||
Map<String, Object> attributes = annotatedTypeMetadata.getAnnotationAttributes(DisableDbMode.class.getName()); | ||
boolean disable = (boolean) attributes.getOrDefault("value", false); | ||
return commonConfigBean.disableDb() == disable; | ||
} | ||
|
||
|
||
} |
15 changes: 15 additions & 0 deletions
15
redis/redis-checker/src/main/java/com/ctrip/xpipe/redis/checker/spring/DisableDbMode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.ctrip.xpipe.redis.checker.spring; | ||
|
||
import org.springframework.context.annotation.Conditional; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
@Target({ ElementType.TYPE, ElementType.METHOD }) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Conditional(ConsoleDisableDbCondition.class) | ||
public @interface DisableDbMode { | ||
boolean value(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
...ole/src/main/java/com/ctrip/xpipe/redis/console/cache/impl/AzGroupCacheWithoutDBImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package com.ctrip.xpipe.redis.console.cache.impl; | ||
|
||
import com.ctrip.xpipe.redis.checker.spring.ConsoleDisableDbCondition; | ||
import com.ctrip.xpipe.redis.checker.spring.DisableDbMode; | ||
import com.ctrip.xpipe.redis.console.cache.AzGroupCache; | ||
import com.ctrip.xpipe.redis.console.model.AzGroupModel; | ||
import com.ctrip.xpipe.redis.console.resources.ConsolePortalService; | ||
import org.apache.commons.collections.SetUtils; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.context.annotation.Conditional; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.function.Function; | ||
import java.util.stream.Collectors; | ||
|
||
@Service | ||
@Conditional(ConsoleDisableDbCondition.class) | ||
@DisableDbMode(true) | ||
public class AzGroupCacheWithoutDBImpl implements AzGroupCache { | ||
|
||
private ConsolePortalService consolePortalService; | ||
|
||
@Autowired | ||
public AzGroupCacheWithoutDBImpl(ConsolePortalService consolePortalService) { | ||
this.consolePortalService = consolePortalService; | ||
} | ||
|
||
private List<AzGroupModel> azGroupModels = null; | ||
|
||
private Map<Long, AzGroupModel> idAzGroupMap = null; | ||
|
||
@Override | ||
public List<AzGroupModel> getAllAzGroup() { | ||
if (this.azGroupModels == null) { | ||
this.loadAzGroupCache(); | ||
} | ||
return this.azGroupModels; | ||
} | ||
|
||
@Override | ||
public AzGroupModel getAzGroupById(Long id) { | ||
if (this.azGroupModels == null) { | ||
this.loadAzGroupCache(); | ||
} | ||
return this.idAzGroupMap.get(id); | ||
} | ||
|
||
@Override | ||
public AzGroupModel getAzGroupByAzs(List<String> azs) { | ||
if (this.azGroupModels == null) { | ||
this.loadAzGroupCache(); | ||
} | ||
for (AzGroupModel model : this.azGroupModels) { | ||
if (SetUtils.isEqualSet(model.getAzs(), azs)) { | ||
return model; | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
private void loadAzGroupCache() { | ||
this.azGroupModels = consolePortalService.getAllAzGroups(); | ||
this.idAzGroupMap = this.azGroupModels.stream().collect(Collectors.toMap(AzGroupModel::getId, Function.identity())); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.