@@ -70,7 +70,7 @@ public class FlowControllerV2 { | |||
@GetMapping("/rules") | |||
@AuthAction(PrivilegeType.READ_RULE) | |||
public Result<List<FlowRuleEntity>> apiQueryMachineRules(@RequestParam String app) { | |||
System.out.println("FlowControllerV2 apiQueryMachineRules app is " + app); | |||
if (StringUtil.isEmpty(app)) { | |||
return Result.ofFail(-1, "app can't be null or empty"); | |||
} | |||
@@ -163,8 +163,7 @@ public class FlowControllerV2 { | |||
@PutMapping("/rule/{id}") | |||
@AuthAction(AuthService.PrivilegeType.WRITE_RULE) | |||
public Result<FlowRuleEntity> apiUpdateFlowRule(@PathVariable("id") Long id, | |||
@RequestBody FlowRuleEntity entity) { | |||
public Result<FlowRuleEntity> apiUpdateFlowRule(@PathVariable("id") Long id, @RequestBody FlowRuleEntity entity) { | |||
if (id == null || id <= 0) { | |||
return Result.ofFail(-1, "Invalid id"); | |||
} | |||
@@ -42,6 +42,7 @@ public class SimpleMachineDiscovery implements MachineDiscovery { | |||
@Override | |||
public long addMachine(MachineInfo machineInfo) { | |||
logger.info("SimpleMachineDiscovery addMachine"); | |||
AssertUtil.notNull(machineInfo, "machineInfo cannot be null"); | |||
AppInfo appInfo = apps.computeIfAbsent(machineInfo.getApp(), o -> new AppInfo(machineInfo.getApp(), machineInfo.getAppType())); | |||
appInfo.addMachine(machineInfo); | |||
@@ -20,6 +20,8 @@ import com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.FlowRuleEntity; | |||
import com.alibaba.csp.sentinel.dashboard.rule.DynamicRuleProvider; | |||
import com.alibaba.csp.sentinel.datasource.Converter; | |||
import com.alibaba.nacos.api.config.ConfigService; | |||
import org.slf4j.Logger; | |||
import org.slf4j.LoggerFactory; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.beans.factory.annotation.Qualifier; | |||
import org.springframework.stereotype.Service; | |||
@@ -33,6 +35,8 @@ import java.util.List; | |||
@Service | |||
public class FlowRuleNacosProvider implements DynamicRuleProvider<List<FlowRuleEntity>> { | |||
@Autowired | |||
private static Logger logger = LoggerFactory.getLogger(FlowRuleNacosProvider.class); | |||
@Autowired | |||
@Qualifier("nacosConfiguration") | |||
private ConfigService nacosConfiguration; | |||
@@ -43,6 +47,7 @@ public class FlowRuleNacosProvider implements DynamicRuleProvider<List<FlowRuleE | |||
@Override | |||
public List<FlowRuleEntity> getRules(String appName) throws Exception { | |||
logger.info("FlowRuleNacosProvider getRules [appName] " + appName); | |||
String dataId=new StringBuilder(appName).append(NacosConstants.DATA_ID_POSTFIX).toString(); | |||
String rules = nacosConfiguration.getConfig(dataId,nacosProperties.getGroupId(),3000); | |||
//log.info("pull FlowRule from nacos Config:"+rules); | |||
@@ -21,6 +21,8 @@ import com.alibaba.csp.sentinel.dashboard.rule.DynamicRulePublisher; | |||
import com.alibaba.csp.sentinel.datasource.Converter; | |||
import com.alibaba.csp.sentinel.util.AssertUtil; | |||
import com.alibaba.nacos.api.config.ConfigService; | |||
import org.slf4j.Logger; | |||
import org.slf4j.LoggerFactory; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.beans.factory.annotation.Qualifier; | |||
import org.springframework.stereotype.Service; | |||
@@ -33,6 +35,8 @@ import java.util.List; | |||
@Service | |||
public class FlowRuleNacosPublisher implements DynamicRulePublisher<List<FlowRuleEntity>> { | |||
@Autowired | |||
private static Logger logger = LoggerFactory.getLogger(FlowRuleNacosPublisher.class); | |||
@Autowired | |||
@Qualifier("nacosConfiguration") | |||
private ConfigService nacosConfiguration; | |||
@@ -44,6 +48,7 @@ public class FlowRuleNacosPublisher implements DynamicRulePublisher<List<FlowRul | |||
@Override | |||
public void publish(String appName, List<FlowRuleEntity> rules) throws Exception { | |||
logger.info("FlowRuleNacosPublisher publish [appName] " + appName); | |||
AssertUtil.notEmpty(appName, "appName不能为空"); | |||
if(rules == null) { | |||
return; | |||