com.alibaba.csp.sentinel.slots.system.SystemRule Java Examples
The following examples show how to use
com.alibaba.csp.sentinel.slots.system.SystemRule.
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: SystemGuardDemo.java From Sentinel with Apache License 2.0 | 6 votes |
private static void initSystemRule() { List<SystemRule> rules = new ArrayList<SystemRule>(); SystemRule rule = new SystemRule(); // max load is 3 rule.setHighestSystemLoad(3.0); // max cpu usage is 60% rule.setHighestCpuUsage(0.6); // max avg rt of all request is 10 ms rule.setAvgRt(10); // max total qps is 20 rule.setQps(20); // max parallel working thread is 10 rule.setMaxThread(10); rules.add(rule); SystemRuleManager.loadRules(Collections.singletonList(rule)); }
Example #4
Source File: FileDataSourceDemo.java From Sentinel with Apache License 2.0 | 6 votes |
private void listenRules() throws Exception { ClassLoader classLoader = getClass().getClassLoader(); String flowRulePath = URLDecoder.decode(classLoader.getResource("FlowRule.json").getFile(), "UTF-8"); String degradeRulePath = URLDecoder.decode(classLoader.getResource("DegradeRule.json").getFile(), "UTF-8"); String systemRulePath = URLDecoder.decode(classLoader.getResource("SystemRule.json").getFile(), "UTF-8"); // Data source for FlowRule FileRefreshableDataSource<List<FlowRule>> flowRuleDataSource = new FileRefreshableDataSource<>( flowRulePath, flowRuleListParser); FlowRuleManager.register2Property(flowRuleDataSource.getProperty()); // Data source for DegradeRule FileRefreshableDataSource<List<DegradeRule>> degradeRuleDataSource = new FileRefreshableDataSource<>( degradeRulePath, degradeRuleListParser); DegradeRuleManager.register2Property(degradeRuleDataSource.getProperty()); // Data source for SystemRule FileRefreshableDataSource<List<SystemRule>> systemRuleDataSource = new FileRefreshableDataSource<>( systemRulePath, systemRuleListParser); SystemRuleManager.register2Property(systemRuleDataSource.getProperty()); }
Example #5
Source File: SystemGuardDemo.java From Sentinel-Dashboard-Nacos with Apache License 2.0 | 6 votes |
private static void initSystemRule() { List<SystemRule> rules = new ArrayList<SystemRule>(); SystemRule rule = new SystemRule(); // max load is 3 rule.setHighestSystemLoad(3.0); // max cpu usage is 60% rule.setHighestCpuUsage(0.6); // max avg rt of all request is 10 ms rule.setAvgRt(10); // max total qps is 20 rule.setQps(20); // max parallel working thread is 10 rule.setMaxThread(10); rules.add(rule); SystemRuleManager.loadRules(Collections.singletonList(rule)); }
Example #6
Source File: FileDataSourceDemo.java From Sentinel-Dashboard-Nacos with Apache License 2.0 | 6 votes |
private void listenRules() throws Exception { ClassLoader classLoader = getClass().getClassLoader(); String flowRulePath = URLDecoder.decode(classLoader.getResource("FlowRule.json").getFile(), "UTF-8"); String degradeRulePath = URLDecoder.decode(classLoader.getResource("DegradeRule.json").getFile(), "UTF-8"); String systemRulePath = URLDecoder.decode(classLoader.getResource("SystemRule.json").getFile(), "UTF-8"); // Data source for FlowRule FileRefreshableDataSource<List<FlowRule>> flowRuleDataSource = new FileRefreshableDataSource<>( flowRulePath, flowRuleListParser); FlowRuleManager.register2Property(flowRuleDataSource.getProperty()); // Data source for DegradeRule FileRefreshableDataSource<List<DegradeRule>> degradeRuleDataSource = new FileRefreshableDataSource<>( degradeRulePath, degradeRuleListParser); DegradeRuleManager.register2Property(degradeRuleDataSource.getProperty()); // Data source for SystemRule FileRefreshableDataSource<List<SystemRule>> systemRuleDataSource = new FileRefreshableDataSource<>( systemRulePath, systemRuleListParser); SystemRuleManager.register2Property(systemRuleDataSource.getProperty()); }
Example #7
Source File: SystemRuleEntity.java From Sentinel-Dashboard-Nacos with Apache License 2.0 | 5 votes |
public static SystemRuleEntity fromSystemRule(String app, String ip, Integer port, SystemRule rule) { SystemRuleEntity entity = new SystemRuleEntity(); entity.setApp(app); entity.setIp(ip); entity.setPort(port); entity.setAvgLoad(rule.getHighestSystemLoad()); entity.setAvgRt(rule.getAvgRt()); entity.setMaxThread(rule.getMaxThread()); entity.setQps(rule.getQps()); return entity; }
Example #8
Source File: SystemRuleEntity.java From Sentinel-Dashboard-Nacos with Apache License 2.0 | 5 votes |
@Override public SystemRule toRule() { SystemRule rule = new SystemRule(); rule.setHighestSystemLoad(avgLoad); rule.setAvgRt(avgRt); rule.setMaxThread(maxThread); rule.setQps(qps); return rule; }
Example #9
Source File: SentinelApiClient.java From Sentinel-Dashboard-Nacos with Apache License 2.0 | 5 votes |
public List<SystemRuleEntity> fetchSystemRuleOfMachine(String app, String ip, int port) { List<SystemRule> rules = fetchRules(ip, port, SYSTEM_RULE_TYPE, SystemRule.class); if (rules != null) { return rules.stream().map(rule -> SystemRuleEntity.fromSystemRule(app, ip, port, rule)) .collect(Collectors.toList()); } else { return null; } }
Example #10
Source File: SystemRuleTest.java From Sentinel-Dashboard-Nacos with Apache License 2.0 | 5 votes |
@Test public void testSystemRule_load() { SystemRule systemRule = new SystemRule(); systemRule.setAvgRt(4000L); SystemRuleManager.loadRules(Collections.singletonList(systemRule)); }
Example #11
Source File: SystemRuleTest.java From Sentinel with Apache License 2.0 | 5 votes |
@Test public void testSystemRule_load() { SystemRule systemRule = new SystemRule(); systemRule.setAvgRt(4000L); SystemRuleManager.loadRules(Collections.singletonList(systemRule)); }
Example #12
Source File: AppLifecycleBean.java From Sentinel with Apache License 2.0 | 5 votes |
void onStart(@Observes StartupEvent ev) { LOGGER.info("The application is starting..."); FlowRule rule = new FlowRule() .setCount(1) .setGrade(RuleConstant.FLOW_GRADE_QPS) .setResource("GET:/hello/txt") .setLimitApp("default") .as(FlowRule.class); FlowRuleManager.loadRules(Arrays.asList(rule)); SystemRule systemRule = new SystemRule(); systemRule.setLimitApp("default"); systemRule.setAvgRt(3000); SystemRuleManager.loadRules(Arrays.asList(systemRule)); DegradeRule degradeRule1 = new DegradeRule("greeting1") .setCount(1) .setGrade(RuleConstant.DEGRADE_GRADE_EXCEPTION_COUNT) .setTimeWindow(10) .setMinRequestAmount(1); DegradeRule degradeRule2 = new DegradeRule("greeting2") .setCount(1) .setGrade(RuleConstant.DEGRADE_GRADE_EXCEPTION_COUNT) .setTimeWindow(10) .setMinRequestAmount(1); DegradeRuleManager.loadRules(Arrays.asList(degradeRule1, degradeRule2)); }
Example #13
Source File: SystemRuleEntity.java From Sentinel with Apache License 2.0 | 5 votes |
public static SystemRuleEntity fromSystemRule(String app, String ip, Integer port, SystemRule rule) { SystemRuleEntity entity = new SystemRuleEntity(); entity.setApp(app); entity.setIp(ip); entity.setPort(port); entity.setHighestSystemLoad(rule.getHighestSystemLoad()); entity.setHighestCpuUsage(rule.getHighestCpuUsage()); entity.setAvgRt(rule.getAvgRt()); entity.setMaxThread(rule.getMaxThread()); entity.setQps(rule.getQps()); return entity; }
Example #14
Source File: SystemRuleEntity.java From Sentinel with Apache License 2.0 | 5 votes |
@Override public SystemRule toRule() { SystemRule rule = new SystemRule(); rule.setHighestSystemLoad(highestSystemLoad); rule.setAvgRt(avgRt); rule.setMaxThread(maxThread); rule.setQps(qps); rule.setHighestCpuUsage(highestCpuUsage); return rule; }
Example #15
Source File: SentinelApiClient.java From Sentinel with Apache License 2.0 | 5 votes |
public List<SystemRuleEntity> fetchSystemRuleOfMachine(String app, String ip, int port) { List<SystemRule> rules = fetchRules(ip, port, SYSTEM_RULE_TYPE, SystemRule.class); if (rules != null) { return rules.stream().map(rule -> SystemRuleEntity.fromSystemRule(app, ip, port, rule)) .collect(Collectors.toList()); } else { return null; } }
Example #16
Source File: SentinelAutoConfiguration.java From spring-cloud-alibaba with Apache License 2.0 | 4 votes |
@Bean("sentinel-json-system-converter") public JsonConverter jsonSystemConverter() { return new JsonConverter(objectMapper, SystemRule.class); }
Example #17
Source File: SentinelAutoConfiguration.java From spring-cloud-alibaba with Apache License 2.0 | 4 votes |
@Bean("sentinel-xml-system-converter") public XmlConverter xmlSystemConverter() { return new XmlConverter(xmlMapper, SystemRule.class); }
Example #18
Source File: WritableDataSourceRegistry.java From Sentinel-Dashboard-Nacos with Apache License 2.0 | 4 votes |
public static synchronized void registerSystemDataSource(WritableDataSource<List<SystemRule>> dataSource) { systemSource = dataSource; }
Example #19
Source File: WritableDataSourceRegistry.java From Sentinel with Apache License 2.0 | 4 votes |
public static WritableDataSource<List<SystemRule>> getSystemSource() { return systemSource; }
Example #20
Source File: WritableDataSourceRegistry.java From Sentinel with Apache License 2.0 | 4 votes |
public static synchronized void registerSystemDataSource(WritableDataSource<List<SystemRule>> dataSource) { systemSource = dataSource; }
Example #21
Source File: WritableDataSourceRegistry.java From Sentinel-Dashboard-Nacos with Apache License 2.0 | 4 votes |
public static WritableDataSource<List<SystemRule>> getSystemSource() { return systemSource; }
Example #22
Source File: SystemRuleTest.java From Sentinel with Apache License 2.0 | 3 votes |
@Test public void testSystemRule_avgRt() throws BlockException { SystemRule systemRule = new SystemRule(); systemRule.setAvgRt(4L); Context context = mock(Context.class); DefaultNode node = mock(DefaultNode.class); ClusterNode cn = mock(ClusterNode.class); when(context.getOrigin()).thenReturn(""); when(node.getClusterNode()).thenReturn(cn); }
Example #23
Source File: SystemRuleTest.java From Sentinel-Dashboard-Nacos with Apache License 2.0 | 3 votes |
@Test public void testSystemRule_avgRt() throws BlockException { SystemRule systemRule = new SystemRule(); systemRule.setAvgRt(4L); Context context = mock(Context.class); DefaultNode node = mock(DefaultNode.class); ClusterNode cn = mock(ClusterNode.class); when(context.getOrigin()).thenReturn(""); when(node.getClusterNode()).thenReturn(cn); }