com.alibaba.csp.sentinel.slots.block.authority.AuthorityRule Java Examples
The following examples show how to use
com.alibaba.csp.sentinel.slots.block.authority.AuthorityRule.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RuleTypeTests.java From spring-cloud-alibaba with Apache License 2.0 | 6 votes |
@Test public void testGetByClass() { assertThat(RuleType.getByClass(Object.class).isPresent()) .isEqualTo(Boolean.FALSE); assertThat(RuleType.getByClass(AbstractRule.class).isPresent()) .isEqualTo(Boolean.FALSE); assertThat(RuleType.getByClass(FlowRule.class).isPresent()) .isEqualTo(Boolean.TRUE); assertThat(RuleType.getByClass(DegradeRule.class).isPresent()) .isEqualTo(Boolean.TRUE); assertThat(RuleType.getByClass(ParamFlowRule.class).isPresent()) .isEqualTo(Boolean.TRUE); assertThat(RuleType.getByClass(SystemRule.class).isPresent()) .isEqualTo(Boolean.TRUE); assertThat(RuleType.getByClass(AuthorityRule.class).isPresent()) .isEqualTo(Boolean.TRUE); }
Example #2
Source File: SentinelRecorder.java From Sentinel with Apache License 2.0 | 6 votes |
/** * register fastjson serializer deserializer class info */ public void init() { SerializeConfig.getGlobalInstance().getObjectWriter(NodeVo.class); SerializeConfig.getGlobalInstance().getObjectWriter(FlowRule.class); SerializeConfig.getGlobalInstance().getObjectWriter(SystemRule.class); SerializeConfig.getGlobalInstance().getObjectWriter(DegradeRule.class); SerializeConfig.getGlobalInstance().getObjectWriter(AuthorityRule.class); SerializeConfig.getGlobalInstance().getObjectWriter(ParamFlowRule.class); ParserConfig.getGlobalInstance().getDeserializer(NodeVo.class); ParserConfig.getGlobalInstance().getDeserializer(FlowRule.class); ParserConfig.getGlobalInstance().getDeserializer(SystemRule.class); ParserConfig.getGlobalInstance().getDeserializer(DegradeRule.class); ParserConfig.getGlobalInstance().getDeserializer(AuthorityRule.class); ParserConfig.getGlobalInstance().getDeserializer(ParamFlowRule.class); }
Example #3
Source File: AuthorityDemo.java From Sentinel-Dashboard-Nacos with Apache License 2.0 | 5 votes |
private static void initWhiteRules() { AuthorityRule rule = new AuthorityRule(); rule.setResource(RESOURCE_NAME); rule.setStrategy(RuleConstant.AUTHORITY_WHITE); rule.setLimitApp("appA,appE"); AuthorityRuleManager.loadRules(Collections.singletonList(rule)); }
Example #4
Source File: AuthorityDemo.java From Sentinel-Dashboard-Nacos with Apache License 2.0 | 5 votes |
private static void initBlackRules() { AuthorityRule rule = new AuthorityRule(); rule.setResource(RESOURCE_NAME); rule.setStrategy(RuleConstant.AUTHORITY_BLACK); rule.setLimitApp("appA,appB"); AuthorityRuleManager.loadRules(Collections.singletonList(rule)); }
Example #5
Source File: AuthorityRuleEntity.java From Sentinel-Dashboard-Nacos with Apache License 2.0 | 5 votes |
public static AuthorityRuleEntity fromAuthorityRule(String app, String ip, Integer port, AuthorityRule rule) { AuthorityRuleEntity entity = new AuthorityRuleEntity(rule); entity.setApp(app); entity.setIp(ip); entity.setPort(port); return entity; }
Example #6
Source File: SentinelApiClient.java From Sentinel-Dashboard-Nacos with Apache License 2.0 | 5 votes |
/** * Fetch all authority rules from provided machine. * * @param app application name * @param ip machine client IP * @param port machine client port * @return all retrieved authority rules * @since 0.2.1 */ public List<AuthorityRuleEntity> fetchAuthorityRulesOfMachine(String app, String ip, int port) { AssertUtil.notEmpty(app, "Bad app name"); AssertUtil.notEmpty(ip, "Bad machine IP"); AssertUtil.isTrue(port > 0, "Bad machine port"); Map<String, String> params = new HashMap<>(1); params.put("type", AUTHORITY_TYPE); List<AuthorityRule> rules = fetchRules(ip, port, AUTHORITY_TYPE, AuthorityRule.class); return Optional.ofNullable(rules).map(r -> r.stream() .map(e -> AuthorityRuleEntity.fromAuthorityRule(app, ip, port, e)) .collect(Collectors.toList()) ).orElse(null); }
Example #7
Source File: AuthorityDemo.java From Sentinel with Apache License 2.0 | 5 votes |
private static void initWhiteRules() { AuthorityRule rule = new AuthorityRule(); rule.setResource(RESOURCE_NAME); rule.setStrategy(RuleConstant.AUTHORITY_WHITE); rule.setLimitApp("appA,appE"); AuthorityRuleManager.loadRules(Collections.singletonList(rule)); }
Example #8
Source File: AuthorityDemo.java From Sentinel with Apache License 2.0 | 5 votes |
private static void initBlackRules() { AuthorityRule rule = new AuthorityRule(); rule.setResource(RESOURCE_NAME); rule.setStrategy(RuleConstant.AUTHORITY_BLACK); rule.setLimitApp("appA,appB"); AuthorityRuleManager.loadRules(Collections.singletonList(rule)); }
Example #9
Source File: JsonSerializeTest.java From Sentinel with Apache License 2.0 | 5 votes |
@Test public void authorityRuleJsonSerializeTest() { AuthorityRuleEntity emptyRule = new AuthorityRuleEntity(); Assert.assertTrue("{}".equals(JSON.toJSONString(emptyRule))); AuthorityRuleEntity authorityRule = new AuthorityRuleEntity(); AuthorityRule rule = new AuthorityRule(); rule.setStrategy(0).setLimitApp("default").setResource("rs"); authorityRule.setRule(rule); Assert.assertTrue("{\"rule\":{\"limitApp\":\"default\",\"resource\":\"rs\",\"strategy\":0}}".equals(JSON.toJSONString(authorityRule))); }
Example #10
Source File: AuthorityRuleEntity.java From Sentinel with Apache License 2.0 | 5 votes |
public static AuthorityRuleEntity fromAuthorityRule(String app, String ip, Integer port, AuthorityRule rule) { AuthorityRuleEntity entity = new AuthorityRuleEntity(rule); entity.setApp(app); entity.setIp(ip); entity.setPort(port); return entity; }
Example #11
Source File: SentinelApiClient.java From Sentinel with Apache License 2.0 | 5 votes |
/** * Fetch all authority rules from provided machine. * * @param app application name * @param ip machine client IP * @param port machine client port * @return all retrieved authority rules * @since 0.2.1 */ public List<AuthorityRuleEntity> fetchAuthorityRulesOfMachine(String app, String ip, int port) { AssertUtil.notEmpty(app, "Bad app name"); AssertUtil.notEmpty(ip, "Bad machine IP"); AssertUtil.isTrue(port > 0, "Bad machine port"); Map<String, String> params = new HashMap<>(1); params.put("type", AUTHORITY_TYPE); List<AuthorityRule> rules = fetchRules(ip, port, AUTHORITY_TYPE, AuthorityRule.class); return Optional.ofNullable(rules).map(r -> r.stream() .map(e -> AuthorityRuleEntity.fromAuthorityRule(app, ip, port, e)) .collect(Collectors.toList()) ).orElse(null); }
Example #12
Source File: SentinelAutoConfiguration.java From spring-cloud-alibaba with Apache License 2.0 | 4 votes |
@Bean("sentinel-xml-authority-converter") public XmlConverter xmlAuthorityConverter() { return new XmlConverter(xmlMapper, AuthorityRule.class); }
Example #13
Source File: WritableDataSourceRegistry.java From Sentinel-Dashboard-Nacos with Apache License 2.0 | 4 votes |
public static synchronized void registerAuthorityDataSource(WritableDataSource<List<AuthorityRule>> dataSource) { authorityDataSource = dataSource; }
Example #14
Source File: SentinelAutoConfiguration.java From spring-cloud-alibaba with Apache License 2.0 | 4 votes |
@Bean("sentinel-json-authority-converter") public JsonConverter jsonAuthorityConverter() { return new JsonConverter(objectMapper, AuthorityRule.class); }
Example #15
Source File: AuthorityRuleEntity.java From Sentinel with Apache License 2.0 | 4 votes |
public AuthorityRuleEntity(AuthorityRule authorityRule) { AssertUtil.notNull(authorityRule, "Authority rule should not be null"); this.rule = authorityRule; }
Example #16
Source File: WritableDataSourceRegistry.java From Sentinel with Apache License 2.0 | 4 votes |
public static WritableDataSource<List<AuthorityRule>> getAuthorityDataSource() { return authorityDataSource; }
Example #17
Source File: WritableDataSourceRegistry.java From Sentinel with Apache License 2.0 | 4 votes |
public static synchronized void registerAuthorityDataSource(WritableDataSource<List<AuthorityRule>> dataSource) { authorityDataSource = dataSource; }
Example #18
Source File: AuthorityRuleEntity.java From Sentinel-Dashboard-Nacos with Apache License 2.0 | 4 votes |
public AuthorityRuleEntity(AuthorityRule authorityRule) { AssertUtil.notNull(authorityRule, "Authority rule should not be null"); this.rule = authorityRule; }
Example #19
Source File: WritableDataSourceRegistry.java From Sentinel-Dashboard-Nacos with Apache License 2.0 | 4 votes |
public static WritableDataSource<List<AuthorityRule>> getAuthorityDataSource() { return authorityDataSource; }