Skip to content

Commit

Permalink
Recator/rest api (apache#5222)
Browse files Browse the repository at this point in the history
* feature/register

* feature/register

* recator/rest-api

* recator/rest-api

* recator/rest-api

* recator/rest-api

* recator/rest-api

* recator/rest-api

* recator/rest-api

* recator/rest-api

---------

Co-authored-by: xiaoyu <[email protected]>
  • Loading branch information
li-keguo and yu199195 authored Oct 15, 2023
1 parent 9585f94 commit 38b8eb0
Show file tree
Hide file tree
Showing 31 changed files with 200 additions and 249 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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 org.apache.shenyu.admin.aspect.annotation;

import org.springframework.core.annotation.AliasFor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

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

/**
* RestApi.
*/
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Inherited
@Validated
@RestController
@RequestMapping
public @interface RestApi {

/**
* The value may indicate a suggestion for a logical component name,
* to be turned into a Spring bean in case of an autodetected component.
*
* @return the suggested component name, if any (or empty String otherwise)
* @since 4.0.1
*/
@AliasFor(attribute = "path", annotation = RequestMapping.class)
String[] value() default {};

}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ public RestControllerAspect(final List<ControllerMethodAdvice> methodAdviceList)
/**
* cut.
*/
@Pointcut("@within(org.springframework.web.bind.annotation.RestController)")
@Pointcut("@within(org.springframework.web.bind.annotation.RestController) "
+ "|| @within(org.apache.shenyu.admin.aspect.annotation.RestApi)")
public void controller() {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,36 +77,36 @@
*/
@Configuration
public class DataSyncConfiguration {

/**
* http long polling.
*/
@Configuration
@ConditionalOnProperty(name = "shenyu.sync.http.enabled", havingValue = "true")
@EnableConfigurationProperties(HttpSyncProperties.class)
static class HttpLongPollingListener {

@Bean
@ConditionalOnMissingBean(HttpLongPollingDataChangedListener.class)
public HttpLongPollingDataChangedListener httpLongPollingDataChangedListener(final HttpSyncProperties httpSyncProperties) {
return new HttpLongPollingDataChangedListener(httpSyncProperties);
}

@Bean
@ConditionalOnMissingBean(ConfigController.class)
public ConfigController configController(final HttpLongPollingDataChangedListener httpLongPollingDataChangedListener) {
return new ConfigController(httpLongPollingDataChangedListener);
}
}

/**
* The type Zookeeper listener.
*/
@Configuration
@ConditionalOnProperty(prefix = "shenyu.sync.zookeeper", name = "url")
@EnableConfigurationProperties(ZookeeperProperties.class)
static class ZookeeperListener {

/**
* register ZookeeperClient in spring ioc.
*
Expand All @@ -125,7 +125,7 @@ public ZookeeperClient zookeeperClient(final ZookeeperProperties zookeeperProp)
client.start();
return client;
}

/**
* Config event listener data changed listener.
*
Expand All @@ -137,11 +137,11 @@ public ZookeeperClient zookeeperClient(final ZookeeperProperties zookeeperProp)
public DataChangedListener zookeeperDataChangedListener(final ZookeeperClient zkClient) {
return new ZookeeperDataChangedListener(zkClient);
}

/**
* Zookeeper data init zookeeper data init.
*
* @param zkClient the zk client
* @param zkClient the zk client
* @return the zookeeper data init
*/
@Bean
Expand All @@ -150,15 +150,15 @@ public DataChangedInit zookeeperDataChangedInit(final ZookeeperClient zkClient)
return new ZookeeperDataChangedInit(zkClient);
}
}

/**
* The type Nacos listener.
*/
@Configuration
@ConditionalOnProperty(prefix = "shenyu.sync.nacos", name = "url")
@EnableConfigurationProperties(NacosProperties.class)
static class NacosListener {

/**
* register configService in spring ioc.
*
Expand Down Expand Up @@ -191,7 +191,7 @@ public ConfigService nacosConfigService(final NacosProperties nacosProp) throws
}
return NacosFactory.createConfigService(properties);
}

/**
* Data changed listener data changed listener.
*
Expand All @@ -203,7 +203,7 @@ public ConfigService nacosConfigService(final NacosProperties nacosProp) throws
public DataChangedListener nacosDataChangedListener(final ConfigService configService) {
return new NacosDataChangedListener(configService);
}

/**
* Nacos data init nacos data init.
*
Expand All @@ -216,15 +216,15 @@ public DataChangedInit nacosDataChangedInit(final ConfigService configService) {
return new NacosDataChangedInit(configService);
}
}

/**
* The type Polaris listener.
*/
@Configuration
@ConditionalOnProperty(prefix = "shenyu.sync.polaris", name = "url")
@EnableConfigurationProperties(PolarisProperties.class)
static class PolarisListener {

/**
* register configFileService in spring ioc.
*
Expand All @@ -237,7 +237,7 @@ public ConfigFileService polarisConfigFileService(final PolarisProperties polari
configuration.getConfigFile().getServerConnector().setAddresses(Collections.singletonList(polarisProperties.getUrl()));
return ConfigFileServiceFactory.createConfigFileService(configuration);
}

/**
* register configFilePublishService in spring ioc.
*
Expand All @@ -250,7 +250,7 @@ public ConfigFilePublishService polarisConfigFilePublishService(final PolarisPro
configuration.getConfigFile().getServerConnector().setAddresses(Collections.singletonList(polarisProperties.getUrl()));
return ConfigFileServicePublishFactory.createConfigFilePublishService(configuration);
}

/**
* Data changed listener data changed listener.
*
Expand All @@ -263,7 +263,7 @@ public DataChangedListener polarisDataChangedListener(final PolarisProperties po
final ConfigFilePublishService configFilePublishService) {
return new PolarisDataChangedListener(polarisProperties, configFileService, configFilePublishService);
}

/**
* Polaris data init polaris data init.
*
Expand All @@ -275,17 +275,17 @@ public DataChangedListener polarisDataChangedListener(final PolarisProperties po
public DataChangedInit polarisDataChangedInit(final PolarisProperties polarisProperties, final ConfigFileService configFileService) {
return new PolarisDataChangedInit(polarisProperties, configFileService);
}

}

/**
* The WebsocketListener(default strategy).
*/
@Configuration
@ConditionalOnProperty(name = "shenyu.sync.websocket.enabled", havingValue = "true", matchIfMissing = true)
@EnableConfigurationProperties(WebsocketSyncProperties.class)
static class WebsocketListener {

/**
* Config event listener data changed listener.
*
Expand All @@ -296,7 +296,7 @@ static class WebsocketListener {
public DataChangedListener websocketDataChangedListener() {
return new WebsocketDataChangedListener();
}

/**
* Websocket collector.
*
Expand All @@ -307,7 +307,7 @@ public DataChangedListener websocketDataChangedListener() {
public WebsocketCollector websocketCollector() {
return new WebsocketCollector();
}

/**
* Server endpoint exporter server endpoint exporter.
*
Expand All @@ -319,15 +319,15 @@ public ServerEndpointExporter serverEndpointExporter() {
return new ServerEndpointExporter();
}
}

/**
* The type Etcd listener.
*/
@Configuration
@ConditionalOnProperty(prefix = "shenyu.sync.etcd", name = "url")
@EnableConfigurationProperties(EtcdProperties.class)
static class EtcdListener {

/**
* Init etcd client.
*
Expand All @@ -341,7 +341,7 @@ public EtcdClient etcdClient(final EtcdProperties etcdProperties) {
.build();
return new EtcdClient(client);
}

/**
* Config event listener data changed listener.
*
Expand All @@ -353,11 +353,11 @@ public EtcdClient etcdClient(final EtcdProperties etcdProperties) {
public DataChangedListener etcdDataChangedListener(final EtcdClient etcdClient) {
return new EtcdDataDataChangedListener(etcdClient);
}

/**
* data init.
*
* @param etcdClient the etcd client
* @param etcdClient the etcd client
* @return the etcd data init
*/
@Bean
Expand All @@ -366,17 +366,18 @@ public DataChangedInit etcdDataChangedInit(final EtcdClient etcdClient) {
return new EtcdDataChangedInit(etcdClient);
}
}

/**
* The type Consul listener.
*/
@Configuration
@ConditionalOnProperty(prefix = "shenyu.sync.consul", name = "url")
@EnableConfigurationProperties(ConsulProperties.class)
static class ConsulListener {

/**
* init Consul client.
*
* @param consulProperties the consul properties
* @return Consul client
*/
Expand All @@ -393,7 +394,7 @@ public ConsulClient consulClient(final ConsulProperties consulProperties) {
throw new ShenyuException("sync.consul.url formatter is not incorrect.");
}
}

/**
* Config event listener data changed listener.
*
Expand All @@ -405,7 +406,7 @@ public ConsulClient consulClient(final ConsulProperties consulProperties) {
public DataChangedListener consulDataChangedListener(final ConsulClient consulClient) {
return new ConsulDataChangedListener(consulClient);
}

/**
* Consul data init.
*
Expand All @@ -418,15 +419,15 @@ public DataChangedInit consulDataChangedInit(final ConsulClient consulClient) {
return new ConsulDataChangedInit(consulClient);
}
}

/**
* the type apollo listener.
*/
@Configuration
@ConditionalOnProperty(prefix = "shenyu.sync.apollo", name = "meta")
@EnableConfigurationProperties(ApolloProperties.class)
static class ApolloListener {

/**
* init Consul client.
*
Expand All @@ -437,7 +438,7 @@ static class ApolloListener {
public ApolloClient apolloClient(final ApolloProperties apolloProperties) {
return new ApolloClient(apolloProperties);
}

/**
* Config event listener data changed listener.
*
Expand All @@ -449,7 +450,7 @@ public ApolloClient apolloClient(final ApolloProperties apolloProperties) {
public DataChangedListener apolloDataChangeListener(final ApolloClient apolloClient) {
return new ApolloDataChangedListener(apolloClient);
}

/**
* apollo data init.
*
Expand All @@ -461,7 +462,7 @@ public DataChangedListener apolloDataChangeListener(final ApolloClient apolloCli
public DataChangedInit apolloDataChangeInit(final ApolloClient apolloClient) {
return new ApolloDataChangedInit(apolloClient);
}

}
}

Loading

0 comments on commit 38b8eb0

Please sign in to comment.