Skip to content
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
wants to merge 2 commits into
base: v3.0-develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions console/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public ConsoleConfigController(ConfigProxy configProxy) {
*/
@GetMapping
@Secured(action = ActionTypes.READ, signType = SignType.CONFIG, apiType = ApiType.CONSOLE_API)
public Result<ConfigAllInfo> getConfigDetail(ConfigFormV3 configForm) throws NacosException {
public Result<ConfigAllInfo> getConfigDetail(ConfigFormV3 configForm) throws Exception {
configForm.validate();
String namespaceId = NamespaceUtil.processNamespaceParameter(configForm.getNamespaceId());
String dataId = configForm.getDataId();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ Page<ConfigInfo> getConfigList(int pageNo, int pageSize, String dataId, String g
* @return A ConfigAllInfo object containing all details of the specified configuration.
* @throws NacosException If an error related to Nacos configuration occurs.
*/
ConfigAllInfo getConfigDetail(String dataId, String group, String namespaceId) throws NacosException;
ConfigAllInfo getConfigDetail(String dataId, String group, String namespaceId) throws Exception;

/**
* Publishes a new configuration or updates an existing configuration.
Expand Down
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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public Page<ConfigInfo> getConfigList(int pageNo, int pageSize, String dataId, S
/**
* Get the specific configuration information.
*/
public ConfigAllInfo getConfigDetail(String dataId, String group, String namespaceId) throws NacosException {
public ConfigAllInfo getConfigDetail(String dataId, String group, String namespaceId) throws Exception {
return configHandler.getConfigDetail(dataId, group, namespaceId);
}

Expand Down
71 changes: 71 additions & 0 deletions maintainer-client/pom.xml
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>
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;
}
}
Loading