Commit ed999fc4 by Nepxion

接入Apollo Open Api,升级Nacos Client

parent eeca5e96
...@@ -41,6 +41,6 @@ public class ApolloOperation { ...@@ -41,6 +41,6 @@ public class ApolloOperation {
} }
public void unsubscribeConfig(String group, String serviceId, ConfigChangeListener configListener) { public void unsubscribeConfig(String group, String serviceId, ConfigChangeListener configListener) {
apolloConfig.removeChangeListener(configListener);
} }
} }
\ No newline at end of file
<?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">
<artifactId>discovery-console-starter-apollo</artifactId>
<name>Nepxion Discovery Console Starter Apollo</name>
<packaging>jar</packaging>
<modelVersion>4.0.0</modelVersion>
<description>Nepxion Discovery is an enhancement for Spring Cloud Discovery</description>
<url>http://www.nepxion.com</url>
<parent>
<groupId>com.nepxion</groupId>
<artifactId>discovery</artifactId>
<version>4.7.11</version>
</parent>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>discovery-console</artifactId>
</dependency>
<dependency>
<groupId>com.ctrip.framework.apollo</groupId>
<artifactId>apollo-openapi</artifactId>
</dependency>
</dependencies>
</project>
\ No newline at end of file
package com.nepxion.discovery.console.apollo.adapter;
/**
* <p>Title: Nepxion Discovery</p>
* <p>Description: Nepxion Discovery</p>
* <p>Copyright: Copyright (c) 2017-2050</p>
* <p>Company: Nepxion</p>
* @author Haojun Ren
* @version 1.0
*/
import java.text.SimpleDateFormat;
import java.util.Date;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import com.ctrip.framework.apollo.openapi.client.ApolloOpenApiClient;
import com.ctrip.framework.apollo.openapi.dto.NamespaceReleaseDTO;
import com.ctrip.framework.apollo.openapi.dto.OpenItemDTO;
import com.nepxion.discovery.console.adapter.ConfigAdapter;
import com.nepxion.discovery.console.apollo.constant.ApolloConstant;
public class ApolloConfigAdapter implements ConfigAdapter {
@Autowired
private Environment environment;
@Autowired
private ApolloOpenApiClient apolloOpenApiClient;
@Override
public boolean updateConfig(String group, String serviceId, String config) throws Exception {
String appId = environment.getProperty(ApolloConstant.APOLLO_PLUGIN_APP_ID);
if (StringUtils.isEmpty(appId)) {
throw new IllegalArgumentException(ApolloConstant.APOLLO_PLUGIN_APP_ID + " can't be null or empty");
}
String env = environment.getProperty(ApolloConstant.APOLLO_PLUGIN_ENV);
if (StringUtils.isEmpty(env)) {
throw new IllegalArgumentException(ApolloConstant.APOLLO_PLUGIN_ENV + " can't be null or empty");
}
String operator = environment.getProperty(ApolloConstant.APOLLO_OPERATOR);
if (StringUtils.isEmpty(operator)) {
throw new IllegalArgumentException(ApolloConstant.APOLLO_OPERATOR + " can't be null or empty");
}
String cluster = environment.getProperty(ApolloConstant.APOLLO_PLUGIN_CLUSTER, String.class, ApolloConstant.DEFAULT_CLUSTER);
String namespace = environment.getProperty(ApolloConstant.APOLLO_PLUGIN_NAMESPACE, String.class, ApolloConstant.DEFAULT_NAMESPACE);
Date now = new Date();
OpenItemDTO openItemDTO = new OpenItemDTO();
openItemDTO.setKey(group + "-" + serviceId);
openItemDTO.setValue(config);
openItemDTO.setComment("Operated by Nepxion Discovery Console");
openItemDTO.setDataChangeCreatedBy(operator);
openItemDTO.setDataChangeLastModifiedBy(operator);
openItemDTO.setDataChangeCreatedTime(now);
openItemDTO.setDataChangeLastModifiedTime(now);
apolloOpenApiClient.createOrUpdateItem(appId, env, cluster, namespace, openItemDTO);
NamespaceReleaseDTO namespaceReleaseDTO = new NamespaceReleaseDTO();
namespaceReleaseDTO.setReleaseTitle(new SimpleDateFormat("yyyyMMddHHmmss").format(now) + "-release");
namespaceReleaseDTO.setReleasedBy(operator);
namespaceReleaseDTO.setReleaseComment("Released by Nepxion Discovery Console");
namespaceReleaseDTO.setEmergencyPublish(true);
apolloOpenApiClient.publishNamespace(appId, env, cluster, namespace, namespaceReleaseDTO);
return true;
}
@Override
public boolean clearConfig(String group, String serviceId) throws Exception {
String appId = environment.getProperty(ApolloConstant.APOLLO_PLUGIN_APP_ID);
if (StringUtils.isEmpty(appId)) {
throw new IllegalArgumentException(ApolloConstant.APOLLO_PLUGIN_APP_ID + " can't be null or empty");
}
String env = environment.getProperty(ApolloConstant.APOLLO_PLUGIN_ENV);
if (StringUtils.isEmpty(env)) {
throw new IllegalArgumentException(ApolloConstant.APOLLO_PLUGIN_ENV + " can't be null or empty");
}
String operator = environment.getProperty(ApolloConstant.APOLLO_OPERATOR);
if (StringUtils.isEmpty(operator)) {
throw new IllegalArgumentException(ApolloConstant.APOLLO_OPERATOR + " can't be null or empty");
}
String cluster = environment.getProperty(ApolloConstant.APOLLO_PLUGIN_CLUSTER, String.class, ApolloConstant.DEFAULT_CLUSTER);
String namespace = environment.getProperty(ApolloConstant.APOLLO_PLUGIN_NAMESPACE, String.class, ApolloConstant.DEFAULT_NAMESPACE);
apolloOpenApiClient.removeItem(appId, env, cluster, namespace, group + "-" + serviceId, operator);
Date now = new Date();
NamespaceReleaseDTO namespaceReleaseDTO = new NamespaceReleaseDTO();
namespaceReleaseDTO.setReleaseTitle(new SimpleDateFormat("yyyyMMddHHmmss").format(now) + "-release");
namespaceReleaseDTO.setReleasedBy(operator);
namespaceReleaseDTO.setReleaseComment("Deleted by Nepxion Discovery Console");
namespaceReleaseDTO.setEmergencyPublish(true);
apolloOpenApiClient.publishNamespace(appId, env, cluster, namespace, namespaceReleaseDTO);
return true;
}
@Override
public String getConfig(String group, String serviceId) throws Exception {
String appId = environment.getProperty(ApolloConstant.APOLLO_PLUGIN_APP_ID);
if (StringUtils.isEmpty(appId)) {
throw new IllegalArgumentException(ApolloConstant.APOLLO_PLUGIN_APP_ID + " can't be null or empty");
}
String env = environment.getProperty(ApolloConstant.APOLLO_PLUGIN_ENV);
if (StringUtils.isEmpty(env)) {
throw new IllegalArgumentException(ApolloConstant.APOLLO_PLUGIN_ENV + " can't be null or empty");
}
String cluster = environment.getProperty(ApolloConstant.APOLLO_PLUGIN_CLUSTER, String.class, ApolloConstant.DEFAULT_CLUSTER);
String namespace = environment.getProperty(ApolloConstant.APOLLO_PLUGIN_NAMESPACE, String.class, ApolloConstant.DEFAULT_NAMESPACE);
return apolloOpenApiClient.getLatestActiveRelease(appId, env, cluster, namespace).getConfigurations().get(group + "-" + serviceId);
}
@Override
public String getConfigType() {
return ApolloConstant.TYPE;
}
}
\ No newline at end of file
package com.nepxion.discovery.console.apollo.configuration;
import org.apache.commons.lang3.StringUtils;
/**
* <p>Title: Nepxion Discovery</p>
* <p>Description: Nepxion Discovery</p>
* <p>Copyright: Copyright (c) 2017-2050</p>
* <p>Company: Nepxion</p>
* @author Haojun Ren
* @version 1.0
*/
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import com.ctrip.framework.apollo.openapi.client.ApolloOpenApiClient;
import com.nepxion.discovery.console.adapter.ConfigAdapter;
import com.nepxion.discovery.console.apollo.adapter.ApolloConfigAdapter;
import com.nepxion.discovery.console.apollo.constant.ApolloConstant;
@Configuration
public class ApolloConfigAutoConfiguration {
static {
System.out.println("");
System.out.println("╔═╗ ╔╗");
System.out.println("║║╚╗║║");
System.out.println("║╔╗╚╝╠══╦══╦══╦══╗");
System.out.println("║║╚╗║║╔╗║╔═╣╔╗║══╣");
System.out.println("║║ ║║║╔╗║╚═╣╚╝╠══║");
System.out.println("╚╝ ╚═╩╝╚╩══╩══╩══╝");
System.out.println(ApolloConstant.TYPE + " Config");
System.out.println("");
}
@Autowired
private Environment environment;
@Bean
public ApolloOpenApiClient openApiClient() {
String portalUrl = environment.getProperty(ApolloConstant.APOLLO_PORTAL_URL);
if (StringUtils.isEmpty(portalUrl)) {
throw new IllegalArgumentException(ApolloConstant.APOLLO_PORTAL_URL + " can't be null or empty");
}
String token = environment.getProperty(ApolloConstant.APOLLO_TOKEN);
if (StringUtils.isEmpty(token)) {
throw new IllegalArgumentException(ApolloConstant.APOLLO_TOKEN + " can't be null or empty");
}
int connectTimeout = environment.getProperty(ApolloConstant.APOLLO_CONNECT_TIMEOUT, Integer.class, ApolloConstant.DEFAULT_CONNECT_TIMEOUT);
int readTimeout = environment.getProperty(ApolloConstant.APOLLO_READ_TIMEOUT, Integer.class, ApolloConstant.DEFAULT_READ_TIMEOUT);
return ApolloOpenApiClient.newBuilder().withPortalUrl(portalUrl).withToken(token).withConnectTimeout(connectTimeout).withReadTimeout(readTimeout).build();
}
@Bean
public ConfigAdapter configAdapter() {
return new ApolloConfigAdapter();
}
}
\ No newline at end of file
package com.nepxion.discovery.console.apollo.constant;
/**
* <p>Title: Nepxion Discovery</p>
* <p>Description: Nepxion Discovery</p>
* <p>Copyright: Copyright (c) 2017-2050</p>
* <p>Company: Nepxion</p>
* @author Haojun Ren
* @version 1.0
*/
import com.ctrip.framework.apollo.openapi.client.constant.ApolloOpenApiConstants;
public class ApolloConstant implements ApolloOpenApiConstants {
public static final String TYPE = "Apollo";
public static final String APOLLO_PORTAL_URL = "apollo.portal-url";
public static final String APOLLO_TOKEN = "apollo.token";
public static final String APOLLO_OPERATOR = "apollo.operator";
public static final String APOLLO_READ_TIMEOUT = "apollo.read-timeout";
public static final String APOLLO_CONNECT_TIMEOUT = "apollo.connect-timeout";
public static final String APOLLO_PLUGIN_APP_ID = "apollo.plugin.app.id";
public static final String APOLLO_PLUGIN_ENV = "apollo.plugin.env";
public static final String APOLLO_PLUGIN_CLUSTER = "apollo.plugin.cluster";
public static final String APOLLO_PLUGIN_NAMESPACE = "apollo.plugin.namespace";
public static final String DEFAULT_CLUSTER = "default";
public static final String DEFAULT_NAMESPACE = "application";
}
\ No newline at end of file
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
com.nepxion.discovery.console.configuration.ConsoleAutoConfiguration,\
com.nepxion.discovery.console.apollo.configuration.ApolloConfigAutoConfiguration
\ No newline at end of file
...@@ -50,8 +50,8 @@ ...@@ -50,8 +50,8 @@
<commons.collections4.version>4.1</commons.collections4.version> <commons.collections4.version>4.1</commons.collections4.version>
<commons.io.version>2.5</commons.io.version> <commons.io.version>2.5</commons.io.version>
<dom4j.version>1.6.1</dom4j.version> <dom4j.version>1.6.1</dom4j.version>
<apollo.version>1.0.0</apollo.version> <apollo.version>1.1.0</apollo.version>
<nacos.version>0.2.0</nacos.version> <nacos.version>0.2.1</nacos.version>
<guava.version>26.0-jre</guava.version> <guava.version>26.0-jre</guava.version>
<caffeine.version>2.6.2</caffeine.version> <caffeine.version>2.6.2</caffeine.version>
<swagger.version>2.7.0</swagger.version> <swagger.version>2.7.0</swagger.version>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment