Pārlūkot izejas kodu

Add an ApiCommandHandler to list all available commands and description (#491)

* Add a ApiCommandHandler which fetch all registered CommandHandlers so that user can get all available CommandHandlers by request /api
* Add a customized CommandHandler demo
master
逅弈 Eric Zhao pirms 6 gadiem
vecāks
revīzija
59d923ebc1
40 mainītis faili ar 259 papildinājumiem un 37 dzēšanām
  1. +1
    -1
      sentinel-cluster/sentinel-cluster-client-default/src/main/java/com/alibaba/csp/sentinel/command/handler/FetchClusterClientConfigHandler.java
  2. +1
    -1
      sentinel-cluster/sentinel-cluster-client-default/src/main/java/com/alibaba/csp/sentinel/command/handler/ModifyClusterClientConfigHandler.java
  3. +1
    -1
      sentinel-cluster/sentinel-cluster-server-default/src/main/java/com/alibaba/csp/sentinel/cluster/server/command/handler/FetchClusterFlowRulesCommandHandler.java
  4. +1
    -1
      sentinel-cluster/sentinel-cluster-server-default/src/main/java/com/alibaba/csp/sentinel/cluster/server/command/handler/FetchClusterMetricCommandHandler.java
  5. +1
    -1
      sentinel-cluster/sentinel-cluster-server-default/src/main/java/com/alibaba/csp/sentinel/cluster/server/command/handler/FetchClusterParamFlowRulesCommandHandler.java
  6. +1
    -1
      sentinel-cluster/sentinel-cluster-server-default/src/main/java/com/alibaba/csp/sentinel/cluster/server/command/handler/FetchClusterServerConfigHandler.java
  7. +1
    -1
      sentinel-cluster/sentinel-cluster-server-default/src/main/java/com/alibaba/csp/sentinel/cluster/server/command/handler/FetchClusterServerInfoCommandHandler.java
  8. +1
    -1
      sentinel-cluster/sentinel-cluster-server-default/src/main/java/com/alibaba/csp/sentinel/cluster/server/command/handler/ModifyClusterFlowRulesCommandHandler.java
  9. +1
    -1
      sentinel-cluster/sentinel-cluster-server-default/src/main/java/com/alibaba/csp/sentinel/cluster/server/command/handler/ModifyClusterParamFlowRulesCommandHandler.java
  10. +1
    -1
      sentinel-cluster/sentinel-cluster-server-default/src/main/java/com/alibaba/csp/sentinel/cluster/server/command/handler/ModifyClusterServerFlowConfigHandler.java
  11. +1
    -1
      sentinel-cluster/sentinel-cluster-server-default/src/main/java/com/alibaba/csp/sentinel/cluster/server/command/handler/ModifyClusterServerTransportConfigHandler.java
  12. +1
    -1
      sentinel-cluster/sentinel-cluster-server-default/src/main/java/com/alibaba/csp/sentinel/cluster/server/command/handler/ModifyServerNamespaceSetHandler.java
  13. +1
    -0
      sentinel-demo/pom.xml
  14. +35
    -0
      sentinel-demo/sentinel-demo-command-handler/pom.xml
  15. +31
    -0
      sentinel-demo/sentinel-demo-command-handler/src/main/java/com/alibaba/csp/sentinel/demo/commandhandler/Application.java
  16. +46
    -0
      sentinel-demo/sentinel-demo-command-handler/src/main/java/com/alibaba/csp/sentinel/demo/commandhandler/EchoCommandHandler.java
  17. +48
    -0
      sentinel-demo/sentinel-demo-command-handler/src/main/java/com/alibaba/csp/sentinel/demo/commandhandler/MainController.java
  18. +1
    -0
      sentinel-demo/sentinel-demo-command-handler/src/main/resources/META-INF/services/com.alibaba.csp.sentinel.command.CommandHandler
  19. +1
    -1
      sentinel-extension/sentinel-parameter-flow-control/src/main/java/com/alibaba/csp/sentinel/command/handler/FetchTopParamsCommandHandler.java
  20. +1
    -1
      sentinel-extension/sentinel-parameter-flow-control/src/main/java/com/alibaba/csp/sentinel/command/handler/GetParamFlowRulesCommandHandler.java
  21. +1
    -1
      sentinel-extension/sentinel-parameter-flow-control/src/main/java/com/alibaba/csp/sentinel/command/handler/ModifyParamFlowRulesCommandHandler.java
  22. +4
    -5
      sentinel-transport/sentinel-transport-common/src/main/java/com/alibaba/csp/sentinel/command/annotation/CommandMapping.java
  23. +60
    -0
      sentinel-transport/sentinel-transport-common/src/main/java/com/alibaba/csp/sentinel/command/handler/ApiCommandHandler.java
  24. +1
    -1
      sentinel-transport/sentinel-transport-common/src/main/java/com/alibaba/csp/sentinel/command/handler/BasicInfoCommandHandler.java
  25. +1
    -1
      sentinel-transport/sentinel-transport-common/src/main/java/com/alibaba/csp/sentinel/command/handler/FetchActiveRuleCommandHandler.java
  26. +1
    -1
      sentinel-transport/sentinel-transport-common/src/main/java/com/alibaba/csp/sentinel/command/handler/FetchClusterNodeByIdCommandHandler.java
  27. +1
    -1
      sentinel-transport/sentinel-transport-common/src/main/java/com/alibaba/csp/sentinel/command/handler/FetchClusterNodeHumanCommandHandler.java
  28. +1
    -1
      sentinel-transport/sentinel-transport-common/src/main/java/com/alibaba/csp/sentinel/command/handler/FetchJsonTreeCommandHandler.java
  29. +1
    -1
      sentinel-transport/sentinel-transport-common/src/main/java/com/alibaba/csp/sentinel/command/handler/FetchOriginCommandHandler.java
  30. +1
    -1
      sentinel-transport/sentinel-transport-common/src/main/java/com/alibaba/csp/sentinel/command/handler/FetchSimpleClusterNodeCommandHandler.java
  31. +1
    -1
      sentinel-transport/sentinel-transport-common/src/main/java/com/alibaba/csp/sentinel/command/handler/FetchSystemStatusCommandHandler.java
  32. +1
    -1
      sentinel-transport/sentinel-transport-common/src/main/java/com/alibaba/csp/sentinel/command/handler/FetchTreeCommandHandler.java
  33. +1
    -1
      sentinel-transport/sentinel-transport-common/src/main/java/com/alibaba/csp/sentinel/command/handler/ModifyRulesCommandHandler.java
  34. +1
    -1
      sentinel-transport/sentinel-transport-common/src/main/java/com/alibaba/csp/sentinel/command/handler/OnOffGetCommandHandler.java
  35. +1
    -1
      sentinel-transport/sentinel-transport-common/src/main/java/com/alibaba/csp/sentinel/command/handler/OnOffSetCommandHandler.java
  36. +1
    -1
      sentinel-transport/sentinel-transport-common/src/main/java/com/alibaba/csp/sentinel/command/handler/SendMetricCommandHandler.java
  37. +1
    -1
      sentinel-transport/sentinel-transport-common/src/main/java/com/alibaba/csp/sentinel/command/handler/VersionCommandHandler.java
  38. +1
    -1
      sentinel-transport/sentinel-transport-common/src/main/java/com/alibaba/csp/sentinel/command/handler/cluster/FetchClusterModeCommandHandler.java
  39. +1
    -1
      sentinel-transport/sentinel-transport-common/src/main/java/com/alibaba/csp/sentinel/command/handler/cluster/ModifyClusterModeCommandHandler.java
  40. +2
    -1
      sentinel-transport/sentinel-transport-common/src/main/resources/META-INF/services/com.alibaba.csp.sentinel.command.CommandHandler

+ 1
- 1
sentinel-cluster/sentinel-cluster-client-default/src/main/java/com/alibaba/csp/sentinel/command/handler/FetchClusterClientConfigHandler.java Parādīt failu

@@ -29,7 +29,7 @@ import com.alibaba.fastjson.JSON;
* @author Eric Zhao
* @since 1.4.0
*/
@CommandMapping(name = "cluster/client/fetchConfig")
@CommandMapping(name = "cluster/client/fetchConfig", desc = "get cluster client config")
public class FetchClusterClientConfigHandler implements CommandHandler<String> {

@Override


+ 1
- 1
sentinel-cluster/sentinel-cluster-client-default/src/main/java/com/alibaba/csp/sentinel/command/handler/ModifyClusterClientConfigHandler.java Parādīt failu

@@ -33,7 +33,7 @@ import com.alibaba.fastjson.JSON;
* @author Eric Zhao
* @since 1.4.0
*/
@CommandMapping(name = "cluster/client/modifyConfig")
@CommandMapping(name = "cluster/client/modifyConfig", desc = "modify cluster client config")
public class ModifyClusterClientConfigHandler implements CommandHandler<String> {

@Override


+ 1
- 1
sentinel-cluster/sentinel-cluster-server-default/src/main/java/com/alibaba/csp/sentinel/cluster/server/command/handler/FetchClusterFlowRulesCommandHandler.java Parādīt failu

@@ -27,7 +27,7 @@ import com.alibaba.fastjson.JSON;
* @author Eric Zhao
* @since 1.4.0
*/
@CommandMapping(name = "cluster/server/flowRules")
@CommandMapping(name = "cluster/server/flowRules", desc = "get cluster flow rules")
public class FetchClusterFlowRulesCommandHandler implements CommandHandler<String> {

@Override


+ 1
- 1
sentinel-cluster/sentinel-cluster-server-default/src/main/java/com/alibaba/csp/sentinel/cluster/server/command/handler/FetchClusterMetricCommandHandler.java Parādīt failu

@@ -27,7 +27,7 @@ import com.alibaba.fastjson.JSON;
* @author Eric Zhao
* @since 1.4.1
*/
@CommandMapping(name = "cluster/server/metricList")
@CommandMapping(name = "cluster/server/metricList", desc = "get cluster server metrics")
public class FetchClusterMetricCommandHandler implements CommandHandler<String> {

@Override


+ 1
- 1
sentinel-cluster/sentinel-cluster-server-default/src/main/java/com/alibaba/csp/sentinel/cluster/server/command/handler/FetchClusterParamFlowRulesCommandHandler.java Parādīt failu

@@ -27,7 +27,7 @@ import com.alibaba.fastjson.JSON;
* @author Eric Zhao
* @since 1.4.0
*/
@CommandMapping(name = "cluster/server/paramRules")
@CommandMapping(name = "cluster/server/paramRules", desc = "get cluster server param flow rules")
public class FetchClusterParamFlowRulesCommandHandler implements CommandHandler<String> {

@Override


+ 1
- 1
sentinel-cluster/sentinel-cluster-server-default/src/main/java/com/alibaba/csp/sentinel/cluster/server/command/handler/FetchClusterServerConfigHandler.java Parādīt failu

@@ -29,7 +29,7 @@ import com.alibaba.fastjson.JSONObject;
* @author Eric Zhao
* @since 1.4.0
*/
@CommandMapping(name = "cluster/server/fetchConfig")
@CommandMapping(name = "cluster/server/fetchConfig", desc = "get cluster server config")
public class FetchClusterServerConfigHandler implements CommandHandler<String> {

@Override


+ 1
- 1
sentinel-cluster/sentinel-cluster-server-default/src/main/java/com/alibaba/csp/sentinel/cluster/server/command/handler/FetchClusterServerInfoCommandHandler.java Parādīt failu

@@ -35,7 +35,7 @@ import com.alibaba.fastjson.JSONObject;
* @author Eric Zhao
* @since 1.4.0
*/
@CommandMapping(name = "cluster/server/info")
@CommandMapping(name = "cluster/server/info", desc = "get cluster server info")
public class FetchClusterServerInfoCommandHandler implements CommandHandler<String> {

@Override


+ 1
- 1
sentinel-cluster/sentinel-cluster-server-default/src/main/java/com/alibaba/csp/sentinel/cluster/server/command/handler/ModifyClusterFlowRulesCommandHandler.java Parādīt failu

@@ -32,7 +32,7 @@ import com.alibaba.fastjson.JSONArray;
* @author Eric Zhao
* @since 1.4.0
*/
@CommandMapping(name = "cluster/server/modifyFlowRules")
@CommandMapping(name = "cluster/server/modifyFlowRules", desc = "modify cluster flow rules")
public class ModifyClusterFlowRulesCommandHandler implements CommandHandler<String> {

@Override


+ 1
- 1
sentinel-cluster/sentinel-cluster-server-default/src/main/java/com/alibaba/csp/sentinel/cluster/server/command/handler/ModifyClusterParamFlowRulesCommandHandler.java Parādīt failu

@@ -32,7 +32,7 @@ import com.alibaba.fastjson.JSONArray;
* @author Eric Zhao
* @since 1.4.0
*/
@CommandMapping(name = "cluster/server/modifyParamRules")
@CommandMapping(name = "cluster/server/modifyParamRules", desc = "modify cluster param flow rules")
public class ModifyClusterParamFlowRulesCommandHandler implements CommandHandler<String> {

@Override


+ 1
- 1
sentinel-cluster/sentinel-cluster-server-default/src/main/java/com/alibaba/csp/sentinel/cluster/server/command/handler/ModifyClusterServerFlowConfigHandler.java Parādīt failu

@@ -32,7 +32,7 @@ import com.alibaba.fastjson.JSON;
* @author Eric Zhao
* @since 1.4.0
*/
@CommandMapping(name = "cluster/server/modifyFlowConfig")
@CommandMapping(name = "cluster/server/modifyFlowConfig", desc = "modify cluster server flow config")
public class ModifyClusterServerFlowConfigHandler implements CommandHandler<String> {

@Override


+ 1
- 1
sentinel-cluster/sentinel-cluster-server-default/src/main/java/com/alibaba/csp/sentinel/cluster/server/command/handler/ModifyClusterServerTransportConfigHandler.java Parādīt failu

@@ -27,7 +27,7 @@ import com.alibaba.csp.sentinel.util.StringUtil;
* @author Eric Zhao
* @since 1.4.0
*/
@CommandMapping(name = "cluster/server/modifyTransportConfig")
@CommandMapping(name = "cluster/server/modifyTransportConfig", desc = "modify cluster server transport config")
public class ModifyClusterServerTransportConfigHandler implements CommandHandler<String> {

@Override


+ 1
- 1
sentinel-cluster/sentinel-cluster-server-default/src/main/java/com/alibaba/csp/sentinel/cluster/server/command/handler/ModifyServerNamespaceSetHandler.java Parādīt failu

@@ -33,7 +33,7 @@ import com.alibaba.fastjson.TypeReference;
* @author Eric Zhao
* @since 1.4.0
*/
@CommandMapping(name = "cluster/server/modifyNamespaceSet")
@CommandMapping(name = "cluster/server/modifyNamespaceSet", desc = "modify server namespace set")
public class ModifyServerNamespaceSetHandler implements CommandHandler<String> {

@Override


+ 1
- 0
sentinel-demo/pom.xml Parādīt failu

@@ -29,6 +29,7 @@
<module>sentinel-demo-parameter-flow-control</module>
<module>sentinel-demo-slot-chain-spi</module>
<module>sentinel-demo-cluster</module>
<module>sentinel-demo-command-handler</module>
</modules>

<dependencies>


+ 35
- 0
sentinel-demo/sentinel-demo-command-handler/pom.xml Parādīt failu

@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>sentinel-demo</artifactId>
<groupId>com.alibaba.csp</groupId>
<version>1.4.2-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>sentinel-demo-command-handler</artifactId>

<dependencies>
<dependency>
<groupId>com.alibaba.csp</groupId>
<artifactId>sentinel-cluster-client-default</artifactId>
<version>1.4.2-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.alibaba.csp</groupId>
<artifactId>sentinel-cluster-server-default</artifactId>
<version>1.4.2-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.alibaba.csp</groupId>
<artifactId>sentinel-transport-simple-http</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>1.5.17.RELEASE</version>
</dependency>
</dependencies>
</project>

+ 31
- 0
sentinel-demo/sentinel-demo-command-handler/src/main/java/com/alibaba/csp/sentinel/demo/commandhandler/Application.java Parādīt failu

@@ -0,0 +1,31 @@
/*
* Copyright 1999-2019 Alibaba Group Holding Ltd.
*
* 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.
*/
package com.alibaba.csp.sentinel.demo.commandhandler;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

/**
* @author houyi
**/
@SpringBootApplication(scanBasePackages = {"com.alibaba.csp.sentinel"})
public class Application {

public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}

}

+ 46
- 0
sentinel-demo/sentinel-demo-command-handler/src/main/java/com/alibaba/csp/sentinel/demo/commandhandler/EchoCommandHandler.java Parādīt failu

@@ -0,0 +1,46 @@
/*
* Copyright 1999-2019 Alibaba Group Holding Ltd.
*
* 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.
*/
package com.alibaba.csp.sentinel.demo.commandhandler;

import com.alibaba.csp.sentinel.command.CommandHandler;
import com.alibaba.csp.sentinel.command.CommandRequest;
import com.alibaba.csp.sentinel.command.CommandResponse;
import com.alibaba.csp.sentinel.command.annotation.CommandMapping;

/**
* Customized CommandHandler
* This Class is a demo shows how to create a customized CommandHandler
* <ul>
* <li>1.Create a class which implements the {@link CommandHandler} interface </li>
* <li>2.Use a {@link CommandMapping} to specify the url and desc of your CommandHandler </li>
* <li>3.Implement your own handle method </li>
* <li>4.Add your CommandHandler in com.alibaba.csp.sentinel.command.CommandHandler file which is stored in resources/META-INF/services/ </li>
* </ul>
* @author houyi
**/
@CommandMapping(name = "echo", desc = "echo service")
public class EchoCommandHandler implements CommandHandler<String> {

@Override
public CommandResponse<String> handle(CommandRequest request) {
String name = request.getParam("name");
if(name==null || name.trim().length()==0){
return CommandResponse.ofSuccess("Tell us what's your name by submit a name parameter");
}
return CommandResponse.ofSuccess("Hello: "+name);
}

}

+ 48
- 0
sentinel-demo/sentinel-demo-command-handler/src/main/java/com/alibaba/csp/sentinel/demo/commandhandler/MainController.java Parādīt failu

@@ -0,0 +1,48 @@
/*
* Copyright 1999-2019 Alibaba Group Holding Ltd.
*
* 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.
*/
package com.alibaba.csp.sentinel.demo.commandhandler;

import com.alibaba.csp.sentinel.SphU;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
* @author houyi
**/
@Controller
public class MainController {

/**
* init sentinel
* @return pass or block
*/
@GetMapping("/init")
public @ResponseBody
String init() {
String retVal;
String resource = "init";
try{
SphU.entry(resource);
retVal = "pass";
}catch (BlockException e){
retVal = "block";
}
return retVal;
}

}

+ 1
- 0
sentinel-demo/sentinel-demo-command-handler/src/main/resources/META-INF/services/com.alibaba.csp.sentinel.command.CommandHandler Parādīt failu

@@ -0,0 +1 @@
com.alibaba.csp.sentinel.demo.commandhandler.EchoCommandHandler

+ 1
- 1
sentinel-extension/sentinel-parameter-flow-control/src/main/java/com/alibaba/csp/sentinel/command/handler/FetchTopParamsCommandHandler.java Parādīt failu

@@ -30,7 +30,7 @@ import com.alibaba.fastjson.JSON;
* @author Eric Zhao
* @since 0.2.0
*/
@CommandMapping(name = "topParams")
@CommandMapping(name = "topParams", desc = "get topN param in specified resource, accept param: res={resourceName}&idx={paramIndex}&n={topN}")
public class FetchTopParamsCommandHandler implements CommandHandler<String> {

@Override


+ 1
- 1
sentinel-extension/sentinel-parameter-flow-control/src/main/java/com/alibaba/csp/sentinel/command/handler/GetParamFlowRulesCommandHandler.java Parādīt failu

@@ -26,7 +26,7 @@ import com.alibaba.fastjson.JSON;
* @author Eric Zhao
* @since 0.2.0
*/
@CommandMapping(name = "getParamFlowRules")
@CommandMapping(name = "getParamFlowRules", desc = "get param flow rules")
public class GetParamFlowRulesCommandHandler implements CommandHandler<String> {

@Override


+ 1
- 1
sentinel-extension/sentinel-parameter-flow-control/src/main/java/com/alibaba/csp/sentinel/command/handler/ModifyParamFlowRulesCommandHandler.java Parādīt failu

@@ -33,7 +33,7 @@ import com.alibaba.fastjson.JSONArray;
* @author Eric Zhao
* @since 0.2.0
*/
@CommandMapping(name = "setParamFlowRules")
@CommandMapping(name = "setParamFlowRules", desc = "set param flow rules, accept param: data={paramFlowRule Json}")
public class ModifyParamFlowRulesCommandHandler implements CommandHandler<String> {

private static WritableDataSource<List<ParamFlowRule>> paramFlowWds = null;


+ 4
- 5
sentinel-transport/sentinel-transport-common/src/main/java/com/alibaba/csp/sentinel/command/annotation/CommandMapping.java Parādīt failu

@@ -15,11 +15,7 @@
*/
package com.alibaba.csp.sentinel.command.annotation;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.annotation.*;

/**
* @author Eric Zhao
@@ -30,4 +26,7 @@ import java.lang.annotation.Target;
public @interface CommandMapping {

String name();

String desc();

}

+ 60
- 0
sentinel-transport/sentinel-transport-common/src/main/java/com/alibaba/csp/sentinel/command/handler/ApiCommandHandler.java Parādīt failu

@@ -0,0 +1,60 @@
/*
* Copyright 1999-2019 Alibaba Group Holding Ltd.
*
* 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.
*/
package com.alibaba.csp.sentinel.command.handler;

import com.alibaba.csp.sentinel.command.CommandHandler;
import com.alibaba.csp.sentinel.command.CommandHandlerProvider;
import com.alibaba.csp.sentinel.command.CommandRequest;
import com.alibaba.csp.sentinel.command.CommandResponse;
import com.alibaba.csp.sentinel.command.annotation.CommandMapping;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

import java.util.Map;

/**
* <p>
* List all available command handlers by request: </br>
* {@code curl http://localhost:8719/api}
* </p>
* @author houyi
**/
@CommandMapping(name = "api", desc = "get all available command handlers")
public class ApiCommandHandler implements CommandHandler<String> {

@Override
public CommandResponse<String> handle(CommandRequest request) {
Map<String, CommandHandler> handlers = CommandHandlerProvider.getInstance().namedHandlers();
JSONArray array = new JSONArray();
if (handlers.isEmpty()) {
return CommandResponse.ofSuccess(array.toJSONString());
}
for (CommandHandler handler : handlers.values()) {
CommandMapping commandMapping = handler.getClass().getAnnotation(CommandMapping.class);
if (commandMapping == null) {
continue;
}
String api = commandMapping.name();
String desc = commandMapping.desc();
JSONObject obj = new JSONObject();
obj.put("url", "/" + api);
obj.put("desc", desc);
array.add(obj);
}
return CommandResponse.ofSuccess(array.toJSONString());
}

}

+ 1
- 1
sentinel-transport/sentinel-transport-common/src/main/java/com/alibaba/csp/sentinel/command/handler/BasicInfoCommandHandler.java Parādīt failu

@@ -26,7 +26,7 @@ import com.alibaba.csp.sentinel.util.HostNameUtil;
*
* @author Eric Zhao
*/
@CommandMapping(name = "basicInfo")
@CommandMapping(name = "basicInfo", desc = "get sentinel config info")
public class BasicInfoCommandHandler implements CommandHandler<String> {

@Override


+ 1
- 1
sentinel-transport/sentinel-transport-common/src/main/java/com/alibaba/csp/sentinel/command/handler/FetchActiveRuleCommandHandler.java Parādīt failu

@@ -28,7 +28,7 @@ import com.alibaba.fastjson.JSON;
/**
* @author jialiang.linjl
*/
@CommandMapping(name = "getRules")
@CommandMapping(name = "getRules", desc = "get all active rules by type, request param: type={ruleType}")
public class FetchActiveRuleCommandHandler implements CommandHandler<String> {

@Override


+ 1
- 1
sentinel-transport/sentinel-transport-common/src/main/java/com/alibaba/csp/sentinel/command/handler/FetchClusterNodeByIdCommandHandler.java Parādīt failu

@@ -28,7 +28,7 @@ import com.alibaba.fastjson.JSON;
/**
* @author qinan.qn
*/
@CommandMapping(name = "clusterNodeById")
@CommandMapping(name = "clusterNodeById", desc = "get clusterNode VO by id, request param: id={resourceName}")
public class FetchClusterNodeByIdCommandHandler implements CommandHandler<String> {

@Override


+ 1
- 1
sentinel-transport/sentinel-transport-common/src/main/java/com/alibaba/csp/sentinel/command/handler/FetchClusterNodeHumanCommandHandler.java Parādīt failu

@@ -29,7 +29,7 @@ import com.alibaba.csp.sentinel.slots.clusterbuilder.ClusterBuilderSlot;
/**
* @author qinan.qn
*/
@CommandMapping(name = "cnode")
@CommandMapping(name = "cnode", desc = "get clusterNode metrics by id, request param: id={resourceName}")
public class FetchClusterNodeHumanCommandHandler implements CommandHandler<String> {

private final static String FORMAT = "%-4s%-80s%-10s%-10s%-10s%-11s%-9s%-6s%-10s%-11s%-9s%-11s";


+ 1
- 1
sentinel-transport/sentinel-transport-common/src/main/java/com/alibaba/csp/sentinel/command/handler/FetchJsonTreeCommandHandler.java Parādīt failu

@@ -32,7 +32,7 @@ import com.alibaba.fastjson.JSON;
/**
* @author leyou
*/
@CommandMapping(name = "jsonTree")
@CommandMapping(name = "jsonTree", desc = "get tree node VO start from root node")
public class FetchJsonTreeCommandHandler implements CommandHandler<String> {

@Override


+ 1
- 1
sentinel-transport/sentinel-transport-common/src/main/java/com/alibaba/csp/sentinel/command/handler/FetchOriginCommandHandler.java Parādīt failu

@@ -29,7 +29,7 @@ import com.alibaba.csp.sentinel.slots.clusterbuilder.ClusterBuilderSlot;
/**
* @author qinan.qn
*/
@CommandMapping(name = "origin")
@CommandMapping(name = "origin", desc = "get origin clusterNode by id, request param: id={resourceName}")
public class FetchOriginCommandHandler implements CommandHandler<String> {

private final static String FORMAT = "%-4s%-80s%-10s%-10s%-11s%-9s%-6s%-10s%-11s%-9s";


+ 1
- 1
sentinel-transport/sentinel-transport-common/src/main/java/com/alibaba/csp/sentinel/command/handler/FetchSimpleClusterNodeCommandHandler.java Parādīt failu

@@ -32,7 +32,7 @@ import com.alibaba.fastjson.JSONArray;
/**
* @author jialiang.linjl
*/
@CommandMapping(name = "clusterNode")
@CommandMapping(name = "clusterNode", desc = "get all clusterNode VO, use type=notZero to ignore those nodes with totalRequest <=0")
public class FetchSimpleClusterNodeCommandHandler implements CommandHandler<String> {

@Override


+ 1
- 1
sentinel-transport/sentinel-transport-common/src/main/java/com/alibaba/csp/sentinel/command/handler/FetchSystemStatusCommandHandler.java Parādīt failu

@@ -28,7 +28,7 @@ import com.alibaba.fastjson.JSONObject;
/**
* @author jialiang.linjl
*/
@CommandMapping(name = "systemStatus")
@CommandMapping(name = "systemStatus", desc = "get system status")
public class FetchSystemStatusCommandHandler implements CommandHandler<String> {

@Override


+ 1
- 1
sentinel-transport/sentinel-transport-common/src/main/java/com/alibaba/csp/sentinel/command/handler/FetchTreeCommandHandler.java Parādīt failu

@@ -27,7 +27,7 @@ import com.alibaba.csp.sentinel.node.Node;
/**
* @author qinan.qn
*/
@CommandMapping(name = "tree")
@CommandMapping(name = "tree", desc = "get metrics in tree mode, use id to specify detailed tree root")
public class FetchTreeCommandHandler implements CommandHandler<String> {

@Override


+ 1
- 1
sentinel-transport/sentinel-transport-common/src/main/java/com/alibaba/csp/sentinel/command/handler/ModifyRulesCommandHandler.java Parādīt failu

@@ -41,7 +41,7 @@ import static com.alibaba.csp.sentinel.transport.util.WritableDataSourceRegistry
* @author jialiang.linjl
* @author Eric Zhao
*/
@CommandMapping(name = "setRules")
@CommandMapping(name = "setRules", desc = "modify the rules, accept param: type={ruleType}&data={ruleJson}")
public class ModifyRulesCommandHandler implements CommandHandler<String> {

@Override


+ 1
- 1
sentinel-transport/sentinel-transport-common/src/main/java/com/alibaba/csp/sentinel/command/handler/OnOffGetCommandHandler.java Parādīt failu

@@ -24,7 +24,7 @@ import com.alibaba.csp.sentinel.command.annotation.CommandMapping;
/**
* @author youji.zj
*/
@CommandMapping(name = "getSwitch")
@CommandMapping(name = "getSwitch", desc = "get sentinel switch status")
public class OnOffGetCommandHandler implements CommandHandler<String> {

@Override


+ 1
- 1
sentinel-transport/sentinel-transport-common/src/main/java/com/alibaba/csp/sentinel/command/handler/OnOffSetCommandHandler.java Parādīt failu

@@ -25,7 +25,7 @@ import com.alibaba.csp.sentinel.Constants;
/**
* @author youji.zj
*/
@CommandMapping(name = "setSwitch")
@CommandMapping(name = "setSwitch", desc = "set sentinel switch, accept param: value={true|false}")
public class OnOffSetCommandHandler implements CommandHandler<String> {

@Override


+ 1
- 1
sentinel-transport/sentinel-transport-common/src/main/java/com/alibaba/csp/sentinel/command/handler/SendMetricCommandHandler.java Parādīt failu

@@ -34,7 +34,7 @@ import com.alibaba.csp.sentinel.node.metric.MetricWriter;
* @author leyou
* @author Eric Zhao
*/
@CommandMapping(name = "metric")
@CommandMapping(name = "metric", desc = "get and aggregate metrics, accept param: startTime={startTime}&endTime={endTime}&maxLines={maxLines}&identify={resourceName}")
public class SendMetricCommandHandler implements CommandHandler<String> {

private MetricSearcher searcher;


+ 1
- 1
sentinel-transport/sentinel-transport-common/src/main/java/com/alibaba/csp/sentinel/command/handler/VersionCommandHandler.java Parādīt failu

@@ -25,7 +25,7 @@ import com.alibaba.csp.sentinel.command.annotation.CommandMapping;
* @author jialiang.linjl
* @author Eric Zhao
*/
@CommandMapping(name = "version")
@CommandMapping(name = "version", desc = "get sentinel version")
public class VersionCommandHandler implements CommandHandler<String> {

@Override


+ 1
- 1
sentinel-transport/sentinel-transport-common/src/main/java/com/alibaba/csp/sentinel/command/handler/cluster/FetchClusterModeCommandHandler.java Parādīt failu

@@ -28,7 +28,7 @@ import com.alibaba.fastjson.JSONObject;
* @author Eric Zhao
* @since 1.4.0
*/
@CommandMapping(name = "getClusterMode")
@CommandMapping(name = "getClusterMode", desc = "get cluster mode status")
public class FetchClusterModeCommandHandler implements CommandHandler<String> {

@Override


+ 1
- 1
sentinel-transport/sentinel-transport-common/src/main/java/com/alibaba/csp/sentinel/command/handler/cluster/ModifyClusterModeCommandHandler.java Parādīt failu

@@ -28,7 +28,7 @@ import com.alibaba.csp.sentinel.log.RecordLog;
* @author Eric Zhao
* @since 1.4.0
*/
@CommandMapping(name = "setClusterMode")
@CommandMapping(name = "setClusterMode", desc = "set cluster mode, accept param: mode={0|1} 0:client mode 1:server mode")
public class ModifyClusterModeCommandHandler implements CommandHandler<String> {

@Override


+ 2
- 1
sentinel-transport/sentinel-transport-common/src/main/resources/META-INF/services/com.alibaba.csp.sentinel.command.CommandHandler Parādīt failu

@@ -13,4 +13,5 @@ com.alibaba.csp.sentinel.command.handler.OnOffSetCommandHandler
com.alibaba.csp.sentinel.command.handler.SendMetricCommandHandler
com.alibaba.csp.sentinel.command.handler.VersionCommandHandler
com.alibaba.csp.sentinel.command.handler.cluster.FetchClusterModeCommandHandler
com.alibaba.csp.sentinel.command.handler.cluster.ModifyClusterModeCommandHandler
com.alibaba.csp.sentinel.command.handler.cluster.ModifyClusterModeCommandHandler
com.alibaba.csp.sentinel.command.handler.ApiCommandHandler

Notiek ielāde…
Atcelt
Saglabāt