Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
discovery
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
谢捷峰
discovery
Commits
ed999fc4
Commit
ed999fc4
authored
Oct 07, 2018
by
Nepxion
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
接入Apollo Open Api,升级Nacos Client
parent
eeca5e96
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
264 additions
and
3 deletions
+264
-3
discovery-common-apollo/src/main/java/com/nepxion/discovery/common/apollo/operation/ApolloOperation.java
+2
-1
discovery-console-starter-apollo/pom.xml
+29
-0
discovery-console-starter-apollo/src/main/java/com/nepxion/discovery/console/apollo/adapter/ApolloConfigAdapter.java
+134
-0
discovery-console-starter-apollo/src/main/java/com/nepxion/discovery/console/apollo/configuration/ApolloConfigAutoConfiguration.java
+64
-0
discovery-console-starter-apollo/src/main/java/com/nepxion/discovery/console/apollo/constant/ApolloConstant.java
+29
-0
discovery-console-starter-apollo/src/main/resources/META-INF/spring.factories
+4
-0
pom.xml
+2
-2
No files found.
discovery-common-apollo/src/main/java/com/nepxion/discovery/common/apollo/operation/ApolloOperation.java
View file @
ed999fc4
...
@@ -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
discovery-console-starter-apollo/pom.xml
0 → 100644
View file @
ed999fc4
<?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
discovery-console-starter-apollo/src/main/java/com/nepxion/discovery/console/apollo/adapter/ApolloConfigAdapter.java
0 → 100644
View file @
ed999fc4
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
discovery-console-starter-apollo/src/main/java/com/nepxion/discovery/console/apollo/configuration/ApolloConfigAutoConfiguration.java
0 → 100644
View file @
ed999fc4
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
discovery-console-starter-apollo/src/main/java/com/nepxion/discovery/console/apollo/constant/ApolloConstant.java
0 → 100644
View file @
ed999fc4
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
discovery-console-starter-apollo/src/main/resources/META-INF/spring.factories
0 → 100644
View file @
ed999fc4
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
com.nepxion.discovery.console.configuration.ConsoleAutoConfiguration,\
com.nepxion.discovery.console.apollo.configuration.ApolloConfigAutoConfiguration
\ No newline at end of file
pom.xml
View file @
ed999fc4
...
@@ -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>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment