merge from 2.2.4.RELEASE
commit
36bc0e5caf
@ -1 +0,0 @@
|
||||
-DaltSnapshotDeploymentRepository=repo.spring.io::default::https://repo.spring.io/libs-snapshot-local -P spring
|
@ -1,67 +0,0 @@
|
||||
transport {
|
||||
# tcp udt unix-domain-socket
|
||||
type = "TCP"
|
||||
#NIO NATIVE
|
||||
server = "NIO"
|
||||
#enable heartbeat
|
||||
heartbeat = false
|
||||
#thread factory for netty
|
||||
thread-factory {
|
||||
boss-thread-prefix = "NettyBoss"
|
||||
worker-thread-prefix = "NettyServerNIOWorker"
|
||||
server-executor-thread-prefix = "NettyServerBizHandler"
|
||||
share-boss-worker = false
|
||||
client-selector-thread-prefix = "NettyClientSelector"
|
||||
client-selector-thread-size = 1
|
||||
client-worker-thread-prefix = "NettyClientWorkerThread"
|
||||
# netty boss thread size,will not be used for UDT
|
||||
boss-thread-size = 1
|
||||
#auto default pin or 8
|
||||
worker-thread-size = 8
|
||||
}
|
||||
shutdown {
|
||||
# when destroy server, wait seconds
|
||||
wait = 3
|
||||
}
|
||||
serialization = "seata"
|
||||
compressor = "none"
|
||||
}
|
||||
service {
|
||||
#vgroup->rgroup
|
||||
vgroup_mapping.account-service-seata-service-group = "default"
|
||||
#only support single node
|
||||
default.grouplist = "127.0.0.1:8091"
|
||||
#degrade current not support
|
||||
enableDegrade = false
|
||||
#disable
|
||||
disable = false
|
||||
#unit ms,s,m,h,d represents milliseconds, seconds, minutes, hours, days, default permanent
|
||||
max.commit.retry.timeout = "-1"
|
||||
max.rollback.retry.timeout = "-1"
|
||||
}
|
||||
client {
|
||||
async.commit.buffer.limit = 10000
|
||||
lock {
|
||||
retry.internal = 10
|
||||
retry.times = 30
|
||||
}
|
||||
report.retry.count = 5
|
||||
tm.commit.retry.count = 1
|
||||
tm.rollback.retry.count = 1
|
||||
}
|
||||
transaction {
|
||||
undo.data.validation = true
|
||||
undo.log.serialization = "jackson"
|
||||
undo.log.save.days = 7
|
||||
#schedule delete expired undo_log in milliseconds
|
||||
undo.log.delete.period = 86400000
|
||||
undo.log.table = "undo_log"
|
||||
}
|
||||
|
||||
support {
|
||||
## spring
|
||||
spring {
|
||||
# auto proxy the DataSource bean
|
||||
datasource.autoproxy = false
|
||||
}
|
||||
}
|
@ -1,73 +0,0 @@
|
||||
registry {
|
||||
# file 、nacos 、eureka、redis、zk、consul、etcd3、sofa
|
||||
type = "file"
|
||||
|
||||
nacos {
|
||||
serverAddr = "localhost"
|
||||
namespace = ""
|
||||
cluster = "default"
|
||||
}
|
||||
eureka {
|
||||
serviceUrl = "http://localhost:8761/eureka"
|
||||
application = "default"
|
||||
weight = "1"
|
||||
}
|
||||
redis {
|
||||
serverAddr = "localhost:6379"
|
||||
db = "0"
|
||||
}
|
||||
zk {
|
||||
cluster = "default"
|
||||
serverAddr = "127.0.0.1:2181"
|
||||
session.timeout = 6000
|
||||
connect.timeout = 2000
|
||||
}
|
||||
consul {
|
||||
cluster = "default"
|
||||
serverAddr = "127.0.0.1:8500"
|
||||
}
|
||||
etcd3 {
|
||||
cluster = "default"
|
||||
serverAddr = "http://localhost:2379"
|
||||
}
|
||||
sofa {
|
||||
serverAddr = "127.0.0.1:9603"
|
||||
application = "default"
|
||||
region = "DEFAULT_ZONE"
|
||||
datacenter = "DefaultDataCenter"
|
||||
cluster = "default"
|
||||
group = "SEATA_GROUP"
|
||||
addressWaitTime = "3000"
|
||||
}
|
||||
file {
|
||||
name = "file.conf"
|
||||
}
|
||||
}
|
||||
|
||||
config {
|
||||
# file、nacos 、apollo、zk、consul、etcd3
|
||||
type = "file"
|
||||
|
||||
nacos {
|
||||
serverAddr = "localhost"
|
||||
namespace = ""
|
||||
}
|
||||
consul {
|
||||
serverAddr = "127.0.0.1:8500"
|
||||
}
|
||||
apollo {
|
||||
app.id = "seata-server"
|
||||
apollo.meta = "http://192.168.1.204:8801"
|
||||
}
|
||||
zk {
|
||||
serverAddr = "127.0.0.1:2181"
|
||||
session.timeout = 6000
|
||||
connect.timeout = 2000
|
||||
}
|
||||
etcd3 {
|
||||
serverAddr = "http://localhost:2379"
|
||||
}
|
||||
file {
|
||||
name = "file.conf"
|
||||
}
|
||||
}
|
@ -1,67 +0,0 @@
|
||||
transport {
|
||||
# tcp udt unix-domain-socket
|
||||
type = "TCP"
|
||||
#NIO NATIVE
|
||||
server = "NIO"
|
||||
#enable heartbeat
|
||||
heartbeat = false
|
||||
#thread factory for netty
|
||||
thread-factory {
|
||||
boss-thread-prefix = "NettyBoss"
|
||||
worker-thread-prefix = "NettyServerNIOWorker"
|
||||
server-executor-thread-prefix = "NettyServerBizHandler"
|
||||
share-boss-worker = false
|
||||
client-selector-thread-prefix = "NettyClientSelector"
|
||||
client-selector-thread-size = 1
|
||||
client-worker-thread-prefix = "NettyClientWorkerThread"
|
||||
# netty boss thread size,will not be used for UDT
|
||||
boss-thread-size = 1
|
||||
#auto default pin or 8
|
||||
worker-thread-size = 8
|
||||
}
|
||||
shutdown {
|
||||
# when destroy server, wait seconds
|
||||
wait = 3
|
||||
}
|
||||
serialization = "seata"
|
||||
compressor = "none"
|
||||
}
|
||||
service {
|
||||
#vgroup->rgroup
|
||||
vgroup_mapping.business-service-seata-service-group = "default"
|
||||
#only support single node
|
||||
default.grouplist = "127.0.0.1:8091"
|
||||
#degrade current not support
|
||||
enableDegrade = false
|
||||
#disable
|
||||
disable = false
|
||||
#unit ms,s,m,h,d represents milliseconds, seconds, minutes, hours, days, default permanent
|
||||
max.commit.retry.timeout = "-1"
|
||||
max.rollback.retry.timeout = "-1"
|
||||
}
|
||||
client {
|
||||
async.commit.buffer.limit = 10000
|
||||
lock {
|
||||
retry.internal = 10
|
||||
retry.times = 30
|
||||
}
|
||||
report.retry.count = 5
|
||||
tm.commit.retry.count = 1
|
||||
tm.rollback.retry.count = 1
|
||||
}
|
||||
transaction {
|
||||
undo.data.validation = true
|
||||
undo.log.serialization = "jackson"
|
||||
undo.log.save.days = 7
|
||||
#schedule delete expired undo_log in milliseconds
|
||||
undo.log.delete.period = 86400000
|
||||
undo.log.table = "undo_log"
|
||||
}
|
||||
|
||||
support {
|
||||
## spring
|
||||
spring {
|
||||
# auto proxy the DataSource bean
|
||||
datasource.autoproxy = false
|
||||
}
|
||||
}
|
@ -1,73 +0,0 @@
|
||||
registry {
|
||||
# file 、nacos 、eureka、redis、zk、consul、etcd3、sofa
|
||||
type = "file"
|
||||
|
||||
nacos {
|
||||
serverAddr = "localhost"
|
||||
namespace = ""
|
||||
cluster = "default"
|
||||
}
|
||||
eureka {
|
||||
serviceUrl = "http://localhost:8761/eureka"
|
||||
application = "default"
|
||||
weight = "1"
|
||||
}
|
||||
redis {
|
||||
serverAddr = "localhost:6379"
|
||||
db = "0"
|
||||
}
|
||||
zk {
|
||||
cluster = "default"
|
||||
serverAddr = "127.0.0.1:2181"
|
||||
session.timeout = 6000
|
||||
connect.timeout = 2000
|
||||
}
|
||||
consul {
|
||||
cluster = "default"
|
||||
serverAddr = "127.0.0.1:8500"
|
||||
}
|
||||
etcd3 {
|
||||
cluster = "default"
|
||||
serverAddr = "http://localhost:2379"
|
||||
}
|
||||
sofa {
|
||||
serverAddr = "127.0.0.1:9603"
|
||||
application = "default"
|
||||
region = "DEFAULT_ZONE"
|
||||
datacenter = "DefaultDataCenter"
|
||||
cluster = "default"
|
||||
group = "SEATA_GROUP"
|
||||
addressWaitTime = "3000"
|
||||
}
|
||||
file {
|
||||
name = "file.conf"
|
||||
}
|
||||
}
|
||||
|
||||
config {
|
||||
# file、nacos 、apollo、zk、consul、etcd3
|
||||
type = "file"
|
||||
|
||||
nacos {
|
||||
serverAddr = "localhost"
|
||||
namespace = ""
|
||||
}
|
||||
consul {
|
||||
serverAddr = "127.0.0.1:8500"
|
||||
}
|
||||
apollo {
|
||||
app.id = "seata-server"
|
||||
apollo.meta = "http://192.168.1.204:8801"
|
||||
}
|
||||
zk {
|
||||
serverAddr = "127.0.0.1:2181"
|
||||
session.timeout = 6000
|
||||
connect.timeout = 2000
|
||||
}
|
||||
etcd3 {
|
||||
serverAddr = "http://localhost:2379"
|
||||
}
|
||||
file {
|
||||
name = "file.conf"
|
||||
}
|
||||
}
|
@ -1,67 +0,0 @@
|
||||
transport {
|
||||
# tcp udt unix-domain-socket
|
||||
type = "TCP"
|
||||
#NIO NATIVE
|
||||
server = "NIO"
|
||||
#enable heartbeat
|
||||
heartbeat = false
|
||||
#thread factory for netty
|
||||
thread-factory {
|
||||
boss-thread-prefix = "NettyBoss"
|
||||
worker-thread-prefix = "NettyServerNIOWorker"
|
||||
server-executor-thread-prefix = "NettyServerBizHandler"
|
||||
share-boss-worker = false
|
||||
client-selector-thread-prefix = "NettyClientSelector"
|
||||
client-selector-thread-size = 1
|
||||
client-worker-thread-prefix = "NettyClientWorkerThread"
|
||||
# netty boss thread size,will not be used for UDT
|
||||
boss-thread-size = 1
|
||||
#auto default pin or 8
|
||||
worker-thread-size = 8
|
||||
}
|
||||
shutdown {
|
||||
# when destroy server, wait seconds
|
||||
wait = 3
|
||||
}
|
||||
serialization = "seata"
|
||||
compressor = "none"
|
||||
}
|
||||
service {
|
||||
#vgroup->rgroup
|
||||
vgroup_mapping.order-service-seata-service-group = "default"
|
||||
#only support single node
|
||||
default.grouplist = "127.0.0.1:8091"
|
||||
#degrade current not support
|
||||
enableDegrade = false
|
||||
#disable
|
||||
disable = false
|
||||
#unit ms,s,m,h,d represents milliseconds, seconds, minutes, hours, days, default permanent
|
||||
max.commit.retry.timeout = "-1"
|
||||
max.rollback.retry.timeout = "-1"
|
||||
}
|
||||
client {
|
||||
async.commit.buffer.limit = 10000
|
||||
lock {
|
||||
retry.internal = 10
|
||||
retry.times = 30
|
||||
}
|
||||
report.retry.count = 5
|
||||
tm.commit.retry.count = 1
|
||||
tm.rollback.retry.count = 1
|
||||
}
|
||||
transaction {
|
||||
undo.data.validation = true
|
||||
undo.log.serialization = "jackson"
|
||||
undo.log.save.days = 7
|
||||
#schedule delete expired undo_log in milliseconds
|
||||
undo.log.delete.period = 86400000
|
||||
undo.log.table = "undo_log"
|
||||
}
|
||||
|
||||
support {
|
||||
## spring
|
||||
spring {
|
||||
# auto proxy the DataSource bean
|
||||
datasource.autoproxy = false
|
||||
}
|
||||
}
|
@ -1,73 +0,0 @@
|
||||
registry {
|
||||
# file 、nacos 、eureka、redis、zk、consul、etcd3、sofa
|
||||
type = "file"
|
||||
|
||||
nacos {
|
||||
serverAddr = "localhost"
|
||||
namespace = ""
|
||||
cluster = "default"
|
||||
}
|
||||
eureka {
|
||||
serviceUrl = "http://localhost:8761/eureka"
|
||||
application = "default"
|
||||
weight = "1"
|
||||
}
|
||||
redis {
|
||||
serverAddr = "localhost:6379"
|
||||
db = "0"
|
||||
}
|
||||
zk {
|
||||
cluster = "default"
|
||||
serverAddr = "127.0.0.1:2181"
|
||||
session.timeout = 6000
|
||||
connect.timeout = 2000
|
||||
}
|
||||
consul {
|
||||
cluster = "default"
|
||||
serverAddr = "127.0.0.1:8500"
|
||||
}
|
||||
etcd3 {
|
||||
cluster = "default"
|
||||
serverAddr = "http://localhost:2379"
|
||||
}
|
||||
sofa {
|
||||
serverAddr = "127.0.0.1:9603"
|
||||
application = "default"
|
||||
region = "DEFAULT_ZONE"
|
||||
datacenter = "DefaultDataCenter"
|
||||
cluster = "default"
|
||||
group = "SEATA_GROUP"
|
||||
addressWaitTime = "3000"
|
||||
}
|
||||
file {
|
||||
name = "file.conf"
|
||||
}
|
||||
}
|
||||
|
||||
config {
|
||||
# file、nacos 、apollo、zk、consul、etcd3
|
||||
type = "file"
|
||||
|
||||
nacos {
|
||||
serverAddr = "localhost"
|
||||
namespace = ""
|
||||
}
|
||||
consul {
|
||||
serverAddr = "127.0.0.1:8500"
|
||||
}
|
||||
apollo {
|
||||
app.id = "seata-server"
|
||||
apollo.meta = "http://192.168.1.204:8801"
|
||||
}
|
||||
zk {
|
||||
serverAddr = "127.0.0.1:2181"
|
||||
session.timeout = 6000
|
||||
connect.timeout = 2000
|
||||
}
|
||||
etcd3 {
|
||||
serverAddr = "http://localhost:2379"
|
||||
}
|
||||
file {
|
||||
name = "file.conf"
|
||||
}
|
||||
}
|
@ -1,67 +0,0 @@
|
||||
transport {
|
||||
# tcp udt unix-domain-socket
|
||||
type = "TCP"
|
||||
#NIO NATIVE
|
||||
server = "NIO"
|
||||
#enable heartbeat
|
||||
heartbeat = false
|
||||
#thread factory for netty
|
||||
thread-factory {
|
||||
boss-thread-prefix = "NettyBoss"
|
||||
worker-thread-prefix = "NettyServerNIOWorker"
|
||||
server-executor-thread-prefix = "NettyServerBizHandler"
|
||||
share-boss-worker = false
|
||||
client-selector-thread-prefix = "NettyClientSelector"
|
||||
client-selector-thread-size = 1
|
||||
client-worker-thread-prefix = "NettyClientWorkerThread"
|
||||
# netty boss thread size,will not be used for UDT
|
||||
boss-thread-size = 1
|
||||
#auto default pin or 8
|
||||
worker-thread-size = 8
|
||||
}
|
||||
shutdown {
|
||||
# when destroy server, wait seconds
|
||||
wait = 3
|
||||
}
|
||||
serialization = "seata"
|
||||
compressor = "none"
|
||||
}
|
||||
service {
|
||||
#vgroup->rgroup
|
||||
vgroup_mapping.storage-service-seata-service-group = "default"
|
||||
#only support single node
|
||||
default.grouplist = "127.0.0.1:8091"
|
||||
#degrade current not support
|
||||
enableDegrade = false
|
||||
#disable
|
||||
disable = false
|
||||
#unit ms,s,m,h,d represents milliseconds, seconds, minutes, hours, days, default permanent
|
||||
max.commit.retry.timeout = "-1"
|
||||
max.rollback.retry.timeout = "-1"
|
||||
}
|
||||
client {
|
||||
async.commit.buffer.limit = 10000
|
||||
lock {
|
||||
retry.internal = 10
|
||||
retry.times = 30
|
||||
}
|
||||
report.retry.count = 5
|
||||
tm.commit.retry.count = 1
|
||||
tm.rollback.retry.count = 1
|
||||
}
|
||||
transaction {
|
||||
undo.data.validation = true
|
||||
undo.log.serialization = "jackson"
|
||||
undo.log.save.days = 7
|
||||
#schedule delete expired undo_log in milliseconds
|
||||
undo.log.delete.period = 86400000
|
||||
undo.log.table = "undo_log"
|
||||
}
|
||||
|
||||
support {
|
||||
## spring
|
||||
spring {
|
||||
# auto proxy the DataSource bean
|
||||
datasource.autoproxy = false
|
||||
}
|
||||
}
|
@ -1,73 +0,0 @@
|
||||
registry {
|
||||
# file 、nacos 、eureka、redis、zk、consul、etcd3、sofa
|
||||
type = "file"
|
||||
|
||||
nacos {
|
||||
serverAddr = "localhost"
|
||||
namespace = ""
|
||||
cluster = "default"
|
||||
}
|
||||
eureka {
|
||||
serviceUrl = "http://localhost:8761/eureka"
|
||||
application = "default"
|
||||
weight = "1"
|
||||
}
|
||||
redis {
|
||||
serverAddr = "localhost:6379"
|
||||
db = "0"
|
||||
}
|
||||
zk {
|
||||
cluster = "default"
|
||||
serverAddr = "127.0.0.1:2181"
|
||||
session.timeout = 6000
|
||||
connect.timeout = 2000
|
||||
}
|
||||
consul {
|
||||
cluster = "default"
|
||||
serverAddr = "127.0.0.1:8500"
|
||||
}
|
||||
etcd3 {
|
||||
cluster = "default"
|
||||
serverAddr = "http://localhost:2379"
|
||||
}
|
||||
sofa {
|
||||
serverAddr = "127.0.0.1:9603"
|
||||
application = "default"
|
||||
region = "DEFAULT_ZONE"
|
||||
datacenter = "DefaultDataCenter"
|
||||
cluster = "default"
|
||||
group = "SEATA_GROUP"
|
||||
addressWaitTime = "3000"
|
||||
}
|
||||
file {
|
||||
name = "file.conf"
|
||||
}
|
||||
}
|
||||
|
||||
config {
|
||||
# file、nacos 、apollo、zk、consul、etcd3
|
||||
type = "file"
|
||||
|
||||
nacos {
|
||||
serverAddr = "localhost"
|
||||
namespace = ""
|
||||
}
|
||||
consul {
|
||||
serverAddr = "127.0.0.1:8500"
|
||||
}
|
||||
apollo {
|
||||
app.id = "seata-server"
|
||||
apollo.meta = "http://192.168.1.204:8801"
|
||||
}
|
||||
zk {
|
||||
serverAddr = "127.0.0.1:2181"
|
||||
session.timeout = 6000
|
||||
connect.timeout = 2000
|
||||
}
|
||||
etcd3 {
|
||||
serverAddr = "http://localhost:2379"
|
||||
}
|
||||
file {
|
||||
name = "file.conf"
|
||||
}
|
||||
}
|
@ -0,0 +1,129 @@
|
||||
/*
|
||||
* Copyright 2013-2018 the original author or authors.
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* https://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.cloud.nacos.parser;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
|
||||
import org.springframework.boot.env.PropertySourceLoader;
|
||||
import org.springframework.core.env.PropertySource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import static com.alibaba.cloud.nacos.parser.AbstractNacosDataParser.DOT;
|
||||
|
||||
/**
|
||||
* Nacos-specific loader, If need to support other methods of parsing,you need to do the
|
||||
* following steps:
|
||||
* <p>
|
||||
* 1.inherit {@link AbstractPropertySourceLoader} ;<br/>
|
||||
* 2. define the file{@code spring.factories} and append
|
||||
* {@code org.springframework.boot.env.PropertySourceLoader=..}; <br/>
|
||||
* 3.the last step validate.
|
||||
* </p>
|
||||
* Notice the use of {@link NacosByteArrayResource} .
|
||||
*
|
||||
* @author zkz
|
||||
*/
|
||||
public abstract class AbstractPropertySourceLoader implements PropertySourceLoader {
|
||||
|
||||
/**
|
||||
* Prevent interference with other loaders.Nacos-specific loader, unless the reload
|
||||
* changes it.
|
||||
* @param name the root name of the property source. If multiple documents are loaded
|
||||
* an additional suffix should be added to the name for each source loaded.
|
||||
* @param resource the resource to load
|
||||
* @return if the resource can be loaded
|
||||
*/
|
||||
protected boolean canLoad(String name, Resource resource) {
|
||||
return resource instanceof NacosByteArrayResource;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the resource into one or more property sources. Implementations may either
|
||||
* return a list containing a single source, or in the case of a multi-document format
|
||||
* such as yaml a source for each document in the resource.
|
||||
* @param name the root name of the property source. If multiple documents are loaded
|
||||
* an additional suffix should be added to the name for each source loaded.
|
||||
* @param resource the resource to load
|
||||
* @return a list property sources
|
||||
* @throws IOException if the source cannot be loaded
|
||||
*/
|
||||
@Override
|
||||
public List<PropertySource<?>> load(String name, Resource resource)
|
||||
throws IOException {
|
||||
if (!canLoad(name, resource)) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return this.doLoad(name, resource);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the resource into one or more property sources. Implementations may either
|
||||
* return a list containing a single source, or in the case of a multi-document format
|
||||
* such as yaml a source for each document in the resource.
|
||||
* @param name the root name of the property source. If multiple documents are loaded
|
||||
* an additional suffix should be added to the name for each source loaded.
|
||||
* @param resource the resource to load
|
||||
* @return a list property sources
|
||||
* @throws IOException if the source cannot be loaded
|
||||
*/
|
||||
protected abstract List<PropertySource<?>> doLoad(String name, Resource resource)
|
||||
throws IOException;
|
||||
|
||||
protected void flattenedMap(Map<String, Object> result, Map<String, Object> dataMap,
|
||||
String parentKey) {
|
||||
if (dataMap == null || dataMap.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
Set<Entry<String, Object>> entries = dataMap.entrySet();
|
||||
for (Iterator<Entry<String, Object>> iterator = entries.iterator(); iterator
|
||||
.hasNext();) {
|
||||
Map.Entry<String, Object> entry = iterator.next();
|
||||
String key = entry.getKey();
|
||||
Object value = entry.getValue();
|
||||
|
||||
String fullKey = StringUtils.isEmpty(parentKey) ? key : key.startsWith("[")
|
||||
? parentKey.concat(key) : parentKey.concat(DOT).concat(key);
|
||||
|
||||
if (value instanceof Map) {
|
||||
Map<String, Object> map = (Map<String, Object>) value;
|
||||
flattenedMap(result, map, fullKey);
|
||||
continue;
|
||||
}
|
||||
else if (value instanceof Collection) {
|
||||
int count = 0;
|
||||
Collection<Object> collection = (Collection<Object>) value;
|
||||
for (Object object : collection) {
|
||||
flattenedMap(result,
|
||||
Collections.singletonMap("[" + (count++) + "]", object),
|
||||
fullKey);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
result.put(fullKey, value);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Copyright 2013-2018 the original author or authors.
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* https://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.cloud.nacos.parser;
|
||||
|
||||
import org.springframework.core.io.ByteArrayResource;
|
||||
|
||||
/**
|
||||
* Nacos-specific resource.
|
||||
*
|
||||
* @author zkz
|
||||
*/
|
||||
public class NacosByteArrayResource extends ByteArrayResource {
|
||||
|
||||
private String filename;
|
||||
|
||||
/**
|
||||
* Create a new {@code ByteArrayResource}.
|
||||
* @param byteArray the byte array to wrap
|
||||
*/
|
||||
public NacosByteArrayResource(byte[] byteArray) {
|
||||
super(byteArray);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new {@code ByteArrayResource} with a description.
|
||||
* @param byteArray the byte array to wrap
|
||||
* @param description where the byte array comes from
|
||||
*/
|
||||
public NacosByteArrayResource(byte[] byteArray, String description) {
|
||||
super(byteArray, description);
|
||||
}
|
||||
|
||||
public void setFilename(String filename) {
|
||||
this.filename = filename;
|
||||
}
|
||||
|
||||
/**
|
||||
* This implementation always returns {@code null}, assuming that this resource type
|
||||
* does not have a filename.
|
||||
*/
|
||||
@Override
|
||||
public String getFilename() {
|
||||
return null == this.filename ? this.getDescription() : this.filename;
|
||||
}
|
||||
|
||||
}
|
@ -1,66 +0,0 @@
|
||||
/*
|
||||
* Copyright 2013-2018 the original author or authors.
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* https://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.cloud.nacos.parser;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* @author zkz
|
||||
* @author yuhuangbin
|
||||
*/
|
||||
public class NacosDataJsonParser extends AbstractNacosDataParser {
|
||||
|
||||
protected NacosDataJsonParser() {
|
||||
super("json");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Map<String, Object> doParse(String data) throws IOException {
|
||||
if (StringUtils.isEmpty(data)) {
|
||||
return null;
|
||||
}
|
||||
Map<String, Object> map = parseJSON2Map(data);
|
||||
return this.reloadMap(map);
|
||||
}
|
||||
|
||||
/**
|
||||
* JSON to Map.
|
||||
* @param json json data
|
||||
* @return the map convert by json string
|
||||
* @throws IOException thrown if there is a problem parsing config.
|
||||
*/
|
||||
private Map<String, Object> parseJSON2Map(String json) throws IOException {
|
||||
Map<String, Object> result = new LinkedHashMap<>(32);
|
||||
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
Map<String, Object> nacosDataMap = mapper.readValue(json, LinkedHashMap.class);
|
||||
|
||||
if (CollectionUtils.isEmpty(nacosDataMap)) {
|
||||
return result;
|
||||
}
|
||||
flattenedMap(result, nacosDataMap, EMPTY_STRING);
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
@ -1,44 +0,0 @@
|
||||
/*
|
||||
* Copyright 2013-2018 the original author or authors.
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* https://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.cloud.nacos.parser;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.beans.factory.config.YamlMapFactoryBean;
|
||||
import org.springframework.core.io.ByteArrayResource;
|
||||
|
||||
/**
|
||||
* @author zkz
|
||||
*/
|
||||
public class NacosDataYamlParser extends AbstractNacosDataParser {
|
||||
|
||||
public NacosDataYamlParser() {
|
||||
super(",yml,yaml,");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Map<String, Object> doParse(String data) {
|
||||
YamlMapFactoryBean yamlFactory = new YamlMapFactoryBean();
|
||||
yamlFactory.setResources(new ByteArrayResource(data.getBytes()));
|
||||
|
||||
Map<String, Object> result = new LinkedHashMap<>();
|
||||
flattenedMap(result, yamlFactory.getObject(), EMPTY_STRING);
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,92 @@
|
||||
/*
|
||||
* Copyright 2013-2018 the original author or authors.
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* https://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.cloud.nacos.parser;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
import org.springframework.boot.env.OriginTrackedMapPropertySource;
|
||||
import org.springframework.core.env.PropertySource;
|
||||
import org.springframework.core.io.Resource;
|
||||
|
||||
import static com.alibaba.cloud.nacos.parser.AbstractNacosDataParser.DOT;
|
||||
import static com.alibaba.cloud.nacos.parser.AbstractNacosDataParser.VALUE;
|
||||
|
||||
/**
|
||||
* @author zkz
|
||||
*/
|
||||
public class NacosJsonPropertySourceLoader extends AbstractPropertySourceLoader {
|
||||
|
||||
/**
|
||||
* Returns the file extensions that the loader supports (excluding the '.').
|
||||
* @return the file extensions
|
||||
*/
|
||||
@Override
|
||||
public String[] getFileExtensions() {
|
||||
return new String[] { "json" };
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the resource into one or more property sources. Implementations may either
|
||||
* return a list containing a single source, or in the case of a multi-document format
|
||||
* such as yaml a source for each document in the resource.
|
||||
* @param name the root name of the property source. If multiple documents are loaded
|
||||
* an additional suffix should be added to the name for each source loaded.
|
||||
* @param resource the resource to load
|
||||
* @return a list property sources
|
||||
* @throws IOException if the source cannot be loaded
|
||||
*/
|
||||
@Override
|
||||
protected List<PropertySource<?>> doLoad(String name, Resource resource)
|
||||
throws IOException {
|
||||
Map<String, Object> result = new LinkedHashMap<>(32);
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
Map<String, Object> nacosDataMap = mapper.readValue(resource.getInputStream(),
|
||||
LinkedHashMap.class);
|
||||
flattenedMap(result, nacosDataMap, null);
|
||||
return Collections.singletonList(
|
||||
new OriginTrackedMapPropertySource(name, this.reloadMap(result)));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Reload the key ending in `value` if need.
|
||||
*/
|
||||
protected Map<String, Object> reloadMap(Map<String, Object> map) {
|
||||
if (map == null || map.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
Map<String, Object> result = new LinkedHashMap<>(map);
|
||||
for (Map.Entry<String, Object> entry : map.entrySet()) {
|
||||
String key = entry.getKey();
|
||||
if (key.contains(DOT)) {
|
||||
int idx = key.lastIndexOf(DOT);
|
||||
String suffix = key.substring(idx + 1);
|
||||
if (VALUE.equalsIgnoreCase(suffix)) {
|
||||
result.put(key.substring(0, idx), entry.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue