|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one or more |
| 3 | + * contributor license agreements. See the NOTICE file distributed with |
| 4 | + * this work for additional information regarding copyright ownership. |
| 5 | + * The ASF licenses this file to You under the Apache License, Version 2.0 |
| 6 | + * (the "License"); you may not use this file except in compliance with |
| 7 | + * the License. You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
| 17 | + |
| 18 | +package org.apache.shenyu.web.endpoint; |
| 19 | + |
| 20 | +import org.apache.shenyu.common.dto.PluginData; |
| 21 | +import org.apache.shenyu.common.dto.RuleData; |
| 22 | +import org.apache.shenyu.common.dto.SelectorData; |
| 23 | +import org.apache.shenyu.plugin.api.ShenyuPlugin; |
| 24 | +import org.apache.shenyu.plugin.base.cache.BaseDataCache; |
| 25 | +import org.apache.shenyu.web.handler.ShenyuWebHandler; |
| 26 | +import org.springframework.http.MediaType; |
| 27 | +import org.springframework.web.bind.annotation.GetMapping; |
| 28 | +import org.springframework.web.bind.annotation.RequestMapping; |
| 29 | +import org.springframework.web.bind.annotation.RestController; |
| 30 | +import reactor.core.publisher.Flux; |
| 31 | + |
| 32 | +import java.util.List; |
| 33 | +import java.util.Map; |
| 34 | +import java.util.stream.Collectors; |
| 35 | + |
| 36 | +/** |
| 37 | + * The type Shenyu controller endpoint. |
| 38 | + */ |
| 39 | +@RestController |
| 40 | +@RequestMapping(value = "/actuator", produces = {MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE}) |
| 41 | +public class ShenyuControllerEndpoint { |
| 42 | + |
| 43 | + private final ShenyuWebHandler webHandler; |
| 44 | + |
| 45 | + /** |
| 46 | + * Instantiates a new Shenyu controller endpoint. |
| 47 | + * |
| 48 | + * @param webHandler the web handler |
| 49 | + */ |
| 50 | + public ShenyuControllerEndpoint(final ShenyuWebHandler webHandler) { |
| 51 | + this.webHandler = webHandler; |
| 52 | + } |
| 53 | + |
| 54 | + /** |
| 55 | + * Plugins flux. |
| 56 | + * |
| 57 | + * @return the flux |
| 58 | + */ |
| 59 | + @GetMapping("/plugins") |
| 60 | + public Flux<Map<String, Integer>> plugins() { |
| 61 | + List<ShenyuPlugin> plugins = webHandler.getPlugins(); |
| 62 | + return Flux.just(plugins.stream().collect(Collectors.toMap(ShenyuPlugin::toString, ShenyuPlugin::getOrder))); |
| 63 | + } |
| 64 | + |
| 65 | + /** |
| 66 | + * Plugin datas flux. |
| 67 | + * |
| 68 | + * @return the flux |
| 69 | + */ |
| 70 | + @GetMapping("/pluginData") |
| 71 | + public Flux<Map<String, PluginData>> pluginDatas() { |
| 72 | + return Flux.just(BaseDataCache.getInstance().getPluginMap()); |
| 73 | + } |
| 74 | + |
| 75 | + /** |
| 76 | + * Selector data flux. |
| 77 | + * |
| 78 | + * @return the flux |
| 79 | + */ |
| 80 | + @GetMapping("/selectorData") |
| 81 | + public Flux<Map<String, List<SelectorData>>> selectorData() { |
| 82 | + return Flux.just(BaseDataCache.getInstance().getSelectorMap()); |
| 83 | + } |
| 84 | + |
| 85 | + /** |
| 86 | + * Rule data flux. |
| 87 | + * |
| 88 | + * @return the flux |
| 89 | + */ |
| 90 | + @GetMapping("/ruleData") |
| 91 | + public Flux<Map<String, List<RuleData>>> ruleData() { |
| 92 | + return Flux.just(BaseDataCache.getInstance().getRuleMap()); |
| 93 | + } |
| 94 | +} |
0 commit comments