-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[ISSUE#12979] Develop a maintainer sdk. #13064
Draft
MatthewAden
wants to merge
6
commits into
alibaba:v3.0-develop
Choose a base branch
from
MatthewAden:develop-maintainer-sdk
base: v3.0-develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
5b05a32
Develop maintainer sdk.
MatthewAden 15c5c23
Develop maintainer sdk.
MatthewAden 43be536
Initial SDK POC implementation
MatthewAden f5e7b18
initial integration of maintainer sdk.
MatthewAden 8db883b
Rollback the console changes.
MatthewAden fc41536
Add all admin api.
MatthewAden File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -77,6 +77,11 @@ | |
<groupId>org.slf4j</groupId> | ||
<artifactId>jul-to-slf4j</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.alibaba.nacos</groupId> | ||
<artifactId>maintainer-client</artifactId> | ||
<version>0.0.1-SNAPSHOT</version> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. version follow parent |
||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-security</artifactId> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
141 changes: 141 additions & 0 deletions
141
...c/main/java/com/alibaba/nacos/console/handler/impl/remote/config/ConfigRemoteHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
/* | ||
* Copyright 1999-2023 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.nacos.console.handler.impl.remote.config; | ||
|
||
import com.alibaba.nacos.api.exception.NacosException; | ||
import com.alibaba.nacos.api.model.v2.Result; | ||
import com.alibaba.nacos.config.server.controller.parameters.SameNamespaceCloneConfigBean; | ||
import com.alibaba.nacos.config.server.model.ConfigAllInfo; | ||
import com.alibaba.nacos.config.server.model.ConfigInfo; | ||
import com.alibaba.nacos.config.server.model.ConfigInfo4Beta; | ||
import com.alibaba.nacos.config.server.model.ConfigRequestInfo; | ||
import com.alibaba.nacos.config.server.model.GroupkeyListenserStatus; | ||
import com.alibaba.nacos.config.server.model.SameConfigPolicy; | ||
import com.alibaba.nacos.config.server.model.form.ConfigForm; | ||
import com.alibaba.nacos.console.handler.config.ConfigHandler; | ||
import com.alibaba.nacos.maintainer.client.config.ConfigService; | ||
import com.alibaba.nacos.maintainer.client.utils.JacksonUtils; | ||
import com.alibaba.nacos.persistence.model.Page; | ||
import jakarta.servlet.ServletException; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.web.multipart.MultipartFile; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
/** | ||
* Implementation of ConfigHandler for handling internal configuration operations. | ||
* | ||
* @author Nacos | ||
*/ | ||
@Service | ||
//@EnabledRemoteHandler | ||
public class ConfigRemoteHandler implements ConfigHandler { | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(ConfigRemoteHandler.class); | ||
|
||
private final ConfigService configService; | ||
|
||
public ConfigRemoteHandler(ConfigService configService) { | ||
this.configService = configService; | ||
} | ||
|
||
@Override | ||
public Page<ConfigInfo> getConfigList(int pageNo, int pageSize, String dataId, String group, String namespaceId, | ||
Map<String, Object> configAdvanceInfo) throws IOException, ServletException, NacosException { | ||
return null; | ||
} | ||
|
||
@Override | ||
public ConfigAllInfo getConfigDetail(String dataId, String group, String namespaceId) throws Exception { | ||
return JacksonUtils.toObj(configService.getConfig(dataId, group, namespaceId), ConfigAllInfo.class); | ||
} | ||
|
||
@Override | ||
public Boolean publishConfig(ConfigForm configForm, ConfigRequestInfo configRequestInfo) throws NacosException { | ||
return null; | ||
} | ||
|
||
@Override | ||
public Boolean deleteConfig(String dataId, String group, String namespaceId, String tag, String clientIp, | ||
String srcUser) throws NacosException { | ||
return null; | ||
} | ||
|
||
@Override | ||
public Boolean batchDeleteConfigs(List<Long> ids, String clientIp, String srcUser) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public ResponseEntity<byte[]> exportConfig(String dataId, String group, String namespaceId, String appName, | ||
List<Long> ids) throws Exception { | ||
return null; | ||
} | ||
|
||
@Override | ||
public ResponseEntity<byte[]> exportConfigV2(String dataId, String group, String namespaceId, String appName, | ||
List<Long> ids) throws Exception { | ||
return null; | ||
} | ||
|
||
@Override | ||
public Page<ConfigInfo> getConfigListByContent(String search, int pageNo, int pageSize, String dataId, String group, | ||
String namespaceId, Map<String, Object> configAdvanceInfo) throws NacosException { | ||
return null; | ||
} | ||
|
||
@Override | ||
public GroupkeyListenserStatus getListeners(String dataId, String group, String namespaceId, int sampleTime) | ||
throws Exception { | ||
return null; | ||
} | ||
|
||
@Override | ||
public GroupkeyListenserStatus getAllSubClientConfigByIp(String ip, boolean all, String namespaceId, | ||
int sampleTime) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public Result<Map<String, Object>> importAndPublishConfig(String srcUser, String namespaceId, | ||
SameConfigPolicy policy, MultipartFile file, String srcIp, String requestIpApp) throws NacosException { | ||
return null; | ||
} | ||
|
||
@Override | ||
public Result<Map<String, Object>> cloneConfig(String srcUser, String namespaceId, | ||
List<SameNamespaceCloneConfigBean> configBeansList, SameConfigPolicy policy, String srcIp, | ||
String requestIpApp) throws NacosException { | ||
return null; | ||
} | ||
|
||
@Override | ||
public boolean removeBetaConfig(String dataId, String group, String namespaceId, String remoteIp, | ||
String requestIpApp) { | ||
return false; | ||
} | ||
|
||
@Override | ||
public Result<ConfigInfo4Beta> queryBetaConfig(String dataId, String group, String namespaceId) { | ||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>com.alibaba.nacos</groupId> | ||
<artifactId>nacos-all</artifactId> | ||
<version>${revision}</version> | ||
</parent> | ||
<groupId>com.alibaba.nacos</groupId> | ||
<artifactId>maintainer-client</artifactId> | ||
<version>0.0.1-SNAPSHOT</version> | ||
<name>maintainer-client</name> | ||
<description>maintainer-client</description> | ||
<url/> | ||
<licenses> | ||
<license/> | ||
</licenses> | ||
<developers> | ||
<developer/> | ||
</developers> | ||
<scm> | ||
<connection/> | ||
<developerConnection/> | ||
<tag/> | ||
<url/> | ||
</scm> | ||
<properties> | ||
<java.version>17</java.version> | ||
</properties> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.apache.httpcomponents.client5</groupId> | ||
<artifactId>httpclient5</artifactId> | ||
<version>5.4.1</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>com.fasterxml.jackson.core</groupId> | ||
<artifactId>jackson-databind</artifactId> | ||
<version>2.18.2</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>commons-collections</groupId> | ||
<artifactId>commons-collections</artifactId> | ||
<version>3.2.2</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-test</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-maven-plugin</artifactId> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
141 changes: 141 additions & 0 deletions
141
.../src/main/java/com/alibaba/nacos/maintainer/client/address/AbstractServerListManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
/* | ||
* Copyright 1999-2024 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.nacos.maintainer.client.address; | ||
|
||
import com.alibaba.nacos.maintainer.client.constants.PropertyKeyConstants; | ||
import com.alibaba.nacos.maintainer.client.env.NacosClientProperties; | ||
import com.alibaba.nacos.maintainer.client.exception.NacosException; | ||
import com.alibaba.nacos.maintainer.client.lifecycle.Closeable; | ||
import com.alibaba.nacos.maintainer.client.remote.client.NacosRestTemplate; | ||
import com.alibaba.nacos.maintainer.client.spi.NacosServiceLoader; | ||
import com.alibaba.nacos.maintainer.client.utils.JustForTest; | ||
import com.alibaba.nacos.maintainer.client.utils.StringUtils; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.util.Collection; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
/** | ||
* Server list Manager. | ||
* | ||
* @author Nacos | ||
*/ | ||
public abstract class AbstractServerListManager implements ServerListManager, Closeable { | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(AbstractServerListManager.class); | ||
|
||
protected ServerListProvider serverListProvider; | ||
|
||
protected NacosClientProperties properties; | ||
|
||
public AbstractServerListManager(NacosClientProperties properties) { | ||
this(properties, null); | ||
} | ||
|
||
public AbstractServerListManager(NacosClientProperties properties, String namespace) { | ||
// To avoid set operation affect the original properties. | ||
NacosClientProperties tmpProperties = properties.derive(); | ||
if (StringUtils.isNotBlank(namespace)) { | ||
tmpProperties.setProperty(PropertyKeyConstants.NAMESPACE, namespace); | ||
} | ||
tmpProperties.setProperty(PropertyKeyConstants.CLIENT_MODULE_TYPE, getModuleName()); | ||
this.properties = tmpProperties; | ||
} | ||
|
||
@Override | ||
public List<String> getServerList() { | ||
return serverListProvider.getServerList(); | ||
} | ||
|
||
@Override | ||
public void shutdown() throws NacosException { | ||
String className = this.getClass().getName(); | ||
LOGGER.info("{} do shutdown begin", className); | ||
if (null != serverListProvider) { | ||
serverListProvider.shutdown(); | ||
} | ||
serverListProvider = null; | ||
LOGGER.info("{} do shutdown stop", className); | ||
} | ||
|
||
/** | ||
* Start server list manager. | ||
* | ||
* @throws NacosException during start and initialize. | ||
*/ | ||
public void start() throws NacosException { | ||
Collection<ServerListProvider> serverListProviders = NacosServiceLoader.load(ServerListProvider.class); | ||
Collection<ServerListProvider> sorted = serverListProviders.stream() | ||
.sorted((a, b) -> b.getOrder() - a.getOrder()).collect(Collectors.toList()); | ||
for (ServerListProvider each : sorted) { | ||
boolean matchResult = each.match(properties); | ||
LOGGER.info("Load and match ServerListProvider {}, match result: {}", each.getClass().getCanonicalName(), | ||
matchResult); | ||
if (matchResult) { | ||
this.serverListProvider = each; | ||
LOGGER.info("Will use {} as ServerListProvider", this.serverListProvider.getClass().getCanonicalName()); | ||
break; | ||
} | ||
} | ||
if (null == serverListProvider) { | ||
LOGGER.error("No server list provider found, SPI load size: {}", sorted.size()); | ||
throw new NacosException(NacosException.CLIENT_INVALID_PARAM, "No server list provider found."); | ||
} | ||
this.serverListProvider.init(properties, getNacosRestTemplate()); | ||
} | ||
|
||
public String getServerName() { | ||
return getModuleName() + "-" + serverListProvider.getServerName(); | ||
} | ||
|
||
public String getContextPath() { | ||
return serverListProvider.getContextPath(); | ||
} | ||
|
||
public String getNamespace() { | ||
return serverListProvider.getNamespace(); | ||
} | ||
|
||
public String getAddressSource() { | ||
return serverListProvider.getAddressSource(); | ||
} | ||
|
||
public boolean isFixed() { | ||
return serverListProvider.isFixed(); | ||
} | ||
|
||
/** | ||
* get module name. | ||
* | ||
* @return module name | ||
*/ | ||
protected abstract String getModuleName(); | ||
|
||
/** | ||
* get nacos rest template. | ||
* | ||
* @return nacos rest template | ||
*/ | ||
protected abstract NacosRestTemplate getNacosRestTemplate(); | ||
|
||
@JustForTest | ||
NacosClientProperties getProperties() { | ||
return properties; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be nacos-maintainer-client?