diff --git a/codec/seata-codec-seata/src/test/resources/file.conf b/codec/seata-codec-seata/src/test/resources/file.conf index 2a62dd98f98..e92a43ff133 100644 --- a/codec/seata-codec-seata/src/test/resources/file.conf +++ b/codec/seata-codec-seata/src/test/resources/file.conf @@ -33,8 +33,8 @@ service { default.grouplist = "127.0.0.1:8091" #degrade current not support enableDegrade = false - #disable - disable = false + #disable globaltransaction + disableGlobalTransaction = false } client { @@ -42,10 +42,13 @@ client { lock { retry.internal = 10 retry.times = 30 + retry.policy.branch-rollback-on-conflict = true } report.retry.count = 5 tm.commit.retry.count = 1 tm.rollback.retry.count = 1 + #schedule check table meta + table.meta.check.enable = true } transaction { diff --git a/codec/seata-codec-seata/src/test/resources/registry.conf b/codec/seata-codec-seata/src/test/resources/registry.conf index e14f0d88e9d..7070aa6133a 100644 --- a/codec/seata-codec-seata/src/test/resources/registry.conf +++ b/codec/seata-codec-seata/src/test/resources/registry.conf @@ -8,7 +8,7 @@ registry { cluster = "default" } eureka { - serviceUrl = "http://localhost:1001/eureka" + serviceUrl = "http://localhost:8761/eureka" application = "default" weight = "1" } diff --git a/config/seata-config-core/src/main/java/io/seata/config/ConfigurationFactory.java b/config/seata-config-core/src/main/java/io/seata/config/ConfigurationFactory.java index e0c574315ed..54afae9e32c 100644 --- a/config/seata-config-core/src/main/java/io/seata/config/ConfigurationFactory.java +++ b/config/seata-config-core/src/main/java/io/seata/config/ConfigurationFactory.java @@ -50,8 +50,16 @@ public final class ConfigurationFactory { if (null == envValue) { envValue = System.getenv(ENV_SYSTEM_KEY); } - CURRENT_FILE_INSTANCE = (null == envValue) ? new FileConfiguration(seataConfigName + REGISTRY_CONF_SUFFIX) + Configuration configuration = (null == envValue) ? new FileConfiguration(seataConfigName + REGISTRY_CONF_SUFFIX) : new FileConfiguration(seataConfigName + "-" + envValue + REGISTRY_CONF_SUFFIX); + Configuration extConfiguration = null; + try { + extConfiguration = EnhancedServiceLoader.load(ExtConfigurationProvider.class).provide(configuration); + + } catch (Exception ignore) { + + } + CURRENT_FILE_INSTANCE = null == extConfiguration ? configuration : extConfiguration; } private static final String NAME_KEY = "name"; @@ -91,7 +99,15 @@ private static Configuration buildConfiguration() { + FILE_TYPE + ConfigurationKeys.FILE_CONFIG_SPLIT_CHAR + NAME_KEY; String name = CURRENT_FILE_INSTANCE.getConfig(pathDataId); - return new FileConfiguration(name); + Configuration configuration = new FileConfiguration(name); + Configuration extConfiguration = null; + try { + extConfiguration = EnhancedServiceLoader.load(ExtConfigurationProvider.class).provide(configuration); + } catch (Exception ignore) { + + } + + return null == extConfiguration ? configuration : extConfiguration; } else { return EnhancedServiceLoader.load(ConfigurationProvider.class, Objects.requireNonNull(configType).name()) .provide(); diff --git a/config/seata-config-core/src/main/java/io/seata/config/ExtConfigurationProvider.java b/config/seata-config-core/src/main/java/io/seata/config/ExtConfigurationProvider.java new file mode 100644 index 00000000000..c19f5376850 --- /dev/null +++ b/config/seata-config-core/src/main/java/io/seata/config/ExtConfigurationProvider.java @@ -0,0 +1,30 @@ +/* + * Copyright 1999-2019 Seata.io Group. + * + * 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 io.seata.config; + +/** + * the interface ext configuration provider + * @author xingfudeshi@gmail.com + * @date 2019/10/03 + */ +public interface ExtConfigurationProvider { + /** + * provide a AbstractConfiguration implementation instance + * @param originalConfiguration + * @return configuration + */ + Configuration provide(Configuration originalConfiguration); +} diff --git a/config/seata-config-core/src/main/resources/file.conf b/config/seata-config-core/src/main/resources/file.conf index beeea0272d6..e92a43ff133 100644 --- a/config/seata-config-core/src/main/resources/file.conf +++ b/config/seata-config-core/src/main/resources/file.conf @@ -33,8 +33,8 @@ service { default.grouplist = "127.0.0.1:8091" #degrade current not support enableDegrade = false - #disable - disable = false + #disable globaltransaction + disableGlobalTransaction = false } client { @@ -42,6 +42,7 @@ client { lock { retry.internal = 10 retry.times = 30 + retry.policy.branch-rollback-on-conflict = true } report.retry.count = 5 tm.commit.retry.count = 1 diff --git a/config/seata-config-core/src/main/resources/registry.conf b/config/seata-config-core/src/main/resources/registry.conf index 2f2f2adb301..a0c917f8c8d 100644 --- a/config/seata-config-core/src/main/resources/registry.conf +++ b/config/seata-config-core/src/main/resources/registry.conf @@ -8,7 +8,7 @@ registry { cluster = "default" } eureka { - serviceUrl = "http://localhost:1001/eureka" + serviceUrl = "http://localhost:8761/eureka" application = "default" weight = "1" } diff --git a/pom.xml b/pom.xml index 9d7d6852c9f..5126ae58f18 100644 --- a/pom.xml +++ b/pom.xml @@ -44,6 +44,7 @@ tm metrics codec + seata-spring-boot-starter compressor saga diff --git a/seata-spring-boot-starter/pom.xml b/seata-spring-boot-starter/pom.xml new file mode 100644 index 00000000000..d55a10ffb8f --- /dev/null +++ b/seata-spring-boot-starter/pom.xml @@ -0,0 +1,66 @@ + + + + + io.seata + seata-parent + ${revision} + + 4.0.0 + seata-spring-boot-starter + jar + seata-spring-boot-starter ${project.version} + + + 1.5.22.RELEASE + + + + + + org.springframework.boot + spring-boot-dependencies + ${spring-boot.version} + pom + import + + + + + + + + ${project.groupId} + seata-all + ${project.version} + + + + org.springframework.boot + spring-boot-autoconfigure + true + + + org.springframework.boot + spring-boot-configuration-processor + true + + + + diff --git a/seata-spring-boot-starter/src/main/java/io/seata/spring/boot/autoconfigure/SeataAutoConfiguration.java b/seata-spring-boot-starter/src/main/java/io/seata/spring/boot/autoconfigure/SeataAutoConfiguration.java new file mode 100644 index 00000000000..6083b8e33ca --- /dev/null +++ b/seata-spring-boot-starter/src/main/java/io/seata/spring/boot/autoconfigure/SeataAutoConfiguration.java @@ -0,0 +1,64 @@ +/* + * Copyright 1999-2019 Seata.io Group. + * + * 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 io.seata.spring.boot.autoconfigure; + +import io.seata.rm.datasource.DataSourceProxy; +import io.seata.spring.annotation.GlobalTransactionScanner; +import io.seata.spring.boot.autoconfigure.properties.SeataProperties; +import io.seata.spring.boot.autoconfigure.util.SpringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.DependsOn; + +/** + * @author xingfudeshi@gmail.com + * @date 2019/09/30 + */ +@ComponentScan(basePackages = "io.seata.spring.boot.autoconfigure.properties") +@ConditionalOnProperty(prefix = StarterConstants.SEATA_PREFIX, name = "enabled", matchIfMissing = true) +@ConditionalOnClass({DataSourceProxy.class}) +@Configuration +@EnableConfigurationProperties({SeataProperties.class}) +public class SeataAutoConfiguration { + private static final Logger LOGGER = LoggerFactory.getLogger(SeataAutoConfiguration.class); + @Autowired + private SeataProperties seataProperties; + + @Bean + public SpringUtils springUtils() { + return new SpringUtils(); + } + + @Bean + @DependsOn({"springUtils"}) + @ConditionalOnMissingBean(GlobalTransactionScanner.class) + public GlobalTransactionScanner globalTransactionScanner() { + if (LOGGER.isInfoEnabled()) { + LOGGER.info("Automatically configure Seata"); + } + return new GlobalTransactionScanner(seataProperties.getApplicationId(), seataProperties.getTxServiceGroup()); + } + + +} diff --git a/seata-spring-boot-starter/src/main/java/io/seata/spring/boot/autoconfigure/StarterConstants.java b/seata-spring-boot-starter/src/main/java/io/seata/spring/boot/autoconfigure/StarterConstants.java new file mode 100644 index 00000000000..91490e2a0b8 --- /dev/null +++ b/seata-spring-boot-starter/src/main/java/io/seata/spring/boot/autoconfigure/StarterConstants.java @@ -0,0 +1,142 @@ +/* + * Copyright 1999-2019 Seata.io Group. + * + * 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 io.seata.spring.boot.autoconfigure; + +import java.util.HashMap; + +import io.seata.spring.boot.autoconfigure.properties.file.ClientProperties; +import io.seata.spring.boot.autoconfigure.properties.file.LockProperties; +import io.seata.spring.boot.autoconfigure.properties.file.ServiceProperties; +import io.seata.spring.boot.autoconfigure.properties.file.ShutdownProperties; +import io.seata.spring.boot.autoconfigure.properties.file.SpringProperties; +import io.seata.spring.boot.autoconfigure.properties.file.SupportProperties; +import io.seata.spring.boot.autoconfigure.properties.file.ThreadFactoryProperties; +import io.seata.spring.boot.autoconfigure.properties.file.TransactionProperties; +import io.seata.spring.boot.autoconfigure.properties.file.TransportProperties; +import io.seata.spring.boot.autoconfigure.properties.registry.ConfigApolloProperties; +import io.seata.spring.boot.autoconfigure.properties.registry.ConfigConsulProperties; +import io.seata.spring.boot.autoconfigure.properties.registry.ConfigEtcd3Properties; +import io.seata.spring.boot.autoconfigure.properties.registry.ConfigFileProperties; +import io.seata.spring.boot.autoconfigure.properties.registry.ConfigNacosProperties; +import io.seata.spring.boot.autoconfigure.properties.registry.ConfigProperties; +import io.seata.spring.boot.autoconfigure.properties.registry.ConfigZooKeeperProperties; +import io.seata.spring.boot.autoconfigure.properties.registry.RegistryConsulProperties; +import io.seata.spring.boot.autoconfigure.properties.registry.RegistryEtcd3Properties; +import io.seata.spring.boot.autoconfigure.properties.registry.RegistryEurekaProperties; +import io.seata.spring.boot.autoconfigure.properties.registry.RegistryFileProperties; +import io.seata.spring.boot.autoconfigure.properties.registry.RegistryNacosProperties; +import io.seata.spring.boot.autoconfigure.properties.registry.RegistryProperties; +import io.seata.spring.boot.autoconfigure.properties.registry.RegistryRedisProperties; +import io.seata.spring.boot.autoconfigure.properties.registry.RegistrySofaProperties; +import io.seata.spring.boot.autoconfigure.properties.registry.RegistryZooKeeperProperties; + +/** + * @author xingfudeshi@gmail.com + * @date 2019/09/30 + */ +public class StarterConstants { + private static final int MAP_CAPACITY = 64; + public static final String SEATA_PREFIX = "seata"; + public static final String TRANSPORT_PREFIX = SEATA_PREFIX + ".transport"; + public static final String THREAD_FACTORY_PREFIX = TRANSPORT_PREFIX + ".thread-factory"; + public static final String SHUTDOWN_PREFIX = TRANSPORT_PREFIX + ".shutdown"; + public static final String SERVICE_PREFIX = SEATA_PREFIX + ".service"; + public static final String CLIENT_PREFIX = SEATA_PREFIX + ".client"; + public static final String LOCK_PREFIX = CLIENT_PREFIX + ".lock"; + public static final String TRANSACTION_PREFIX = SEATA_PREFIX + ".transaction"; + public static final String SUPPORT_PREFIX = SEATA_PREFIX + ".support"; + public static final String SPRING_PREFIX = SUPPORT_PREFIX + ".spring"; + + public static final String REGISTRY_PREFIX = SEATA_PREFIX + ".registry"; + public static final String REGISTRY_NACOS_PREFIX = REGISTRY_PREFIX + ".nacos"; + public static final String REGISTRY_EUREKA_PREFIX = REGISTRY_PREFIX + ".eureka"; + public static final String REGISTRY_REDIS_PREFIX = REGISTRY_PREFIX + ".redis"; + public static final String REGISTRY_ZK_PREFIX = REGISTRY_PREFIX + ".zk"; + public static final String REGISTRY_CONSUL_PREFIX = REGISTRY_PREFIX + ".consul"; + public static final String REGISTRY_ETCD3_PREFIX = REGISTRY_PREFIX + ".etcd3"; + public static final String REGISTRY_SOFA_PREFIX = REGISTRY_PREFIX + ".sofa"; + public static final String REGISTRY_FILE_PREFIX = REGISTRY_PREFIX + ".file"; + + public static final String CONFIG_PREFIX = SEATA_PREFIX + ".config"; + public static final String CONFIG_NACOS_PREFIX = CONFIG_PREFIX + ".nacos"; + public static final String CONFIG_CONSUL_PREFIX = CONFIG_PREFIX + ".consul"; + public static final String CONFIG_ETCD3_PREFIX = CONFIG_PREFIX + ".etcd3"; + public static final String CONFIG_APOLLO_PREFIX = CONFIG_PREFIX + ".apollo"; + public static final String CONFIG_ZK_PREFIX = CONFIG_PREFIX + ".zk"; + public static final String CONFIG_FILE_PREFIX = CONFIG_PREFIX + ".file"; + + public static final HashMap PROPERTY_MAP = new HashMap(MAP_CAPACITY) { + private static final long serialVersionUID = -8902807645596274597L; + + { + put(CLIENT_PREFIX, ClientProperties.class); + put(LOCK_PREFIX, LockProperties.class); + put(SERVICE_PREFIX, ServiceProperties.class); + put(SHUTDOWN_PREFIX, ShutdownProperties.class); + put(SPRING_PREFIX, SpringProperties.class); + put(SUPPORT_PREFIX, SupportProperties.class); + put(THREAD_FACTORY_PREFIX, ThreadFactoryProperties.class); + put(TRANSACTION_PREFIX, TransactionProperties.class); + put(TRANSPORT_PREFIX, TransportProperties.class); + put(CONFIG_PREFIX, ConfigProperties.class); + put(CONFIG_FILE_PREFIX, ConfigFileProperties.class); + put(REGISTRY_PREFIX, RegistryProperties.class); + put(REGISTRY_FILE_PREFIX, RegistryFileProperties.class); + + put(CONFIG_NACOS_PREFIX, ConfigNacosProperties.class); + put(CONFIG_CONSUL_PREFIX, ConfigConsulProperties.class); + put(CONFIG_ZK_PREFIX, ConfigZooKeeperProperties.class); + put(CONFIG_APOLLO_PREFIX, ConfigApolloProperties.class); + put(CONFIG_ETCD3_PREFIX, ConfigEtcd3Properties.class); + + put(REGISTRY_CONSUL_PREFIX, RegistryConsulProperties.class); + put(REGISTRY_ETCD3_PREFIX, RegistryEtcd3Properties.class); + put(REGISTRY_EUREKA_PREFIX, RegistryEurekaProperties.class); + put(REGISTRY_NACOS_PREFIX, RegistryNacosProperties.class); + put(REGISTRY_REDIS_PREFIX, RegistryRedisProperties.class); + put(REGISTRY_SOFA_PREFIX, RegistrySofaProperties.class); + put(REGISTRY_ZK_PREFIX, RegistryZooKeeperProperties.class); + } + + }; + + + /** + * The following special keys need to be normalized. + */ + public static String SPECIAL_KEY_VGROUP_MAPPING = "service.vgroup_mapping"; + public static String NORMALIZED_KEY_VGROUP_MAPPING = "vgroupMapping"; + public static String SPECIAL_KEY_GROUPLIST = "grouplist"; + public static String NORMALIZED_KEY_GROUPLIST = "grouplist"; + public static String SPECIAL_KEY_DATASOURCE_AUTOPROXY = "datasource.autoproxy"; + public static String NORMALIZED_KEY_DATASOURCE_AUTOPROXY = "datasourceAutoproxy"; + public static String SPECIAL_KEY_TRANSACTION = "transaction."; + public static String NORMALIZED_KEY_TRANSACTION = "transaction."; + public static String SPECIAL_KEY_CLIENT = "client."; + public static String NORMALIZED_KEY_CLIENT = "client."; + public static String SPECIAL_KEY_CLIENT_LOCK = "client.lock."; + public static String NORMALIZED_KEY_CLIENT_LOCK = "client.lock."; + public static String SPECIAL_KEY_TRANSPORT_THREAD_FACTORY = "transport.thread-factory."; + public static String NORMALIZED_KEY_TRANSPORT_THREAD_FACTORY = "transport.thread-factory."; + + public static String SPECIAL_KEY_REGISTRY_ZK = "registry.zk."; + public static String NORMALIZED_KEY_REGISTRY_ZK = "registry.zk."; + public static String SPECIAL_KEY_CONFIG_ZK = "config.zk."; + public static String NORMALIZED_KEY_CONFIG_ZK = "config.zk."; + public static String SPECIAL_KEY_CONFIG_APOLLO = "config.apollo."; + public static String NORMALIZED_KEY_CONFIG_APOLLO = "config.apollo."; + +} diff --git a/seata-spring-boot-starter/src/main/java/io/seata/spring/boot/autoconfigure/properties/SeataProperties.java b/seata-spring-boot-starter/src/main/java/io/seata/spring/boot/autoconfigure/properties/SeataProperties.java new file mode 100644 index 00000000000..c5168d4ecab --- /dev/null +++ b/seata-spring-boot-starter/src/main/java/io/seata/spring/boot/autoconfigure/properties/SeataProperties.java @@ -0,0 +1,69 @@ +/* + * Copyright 1999-2019 Seata.io Group. + * + * 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 io.seata.spring.boot.autoconfigure.properties; + +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.stereotype.Component; + +import static io.seata.spring.boot.autoconfigure.StarterConstants.SEATA_PREFIX; + +/** + * @author xingfudeshi@gmail.com + * @date 2019/09/30 + */ +@Component +@ConfigurationProperties(prefix = SEATA_PREFIX) +public class SeataProperties { + /** + * whether enable auto configuration + */ + private boolean enabled = true; + /** + * application id + */ + private String applicationId; + /** + * transaction service group + */ + private String txServiceGroup; + + public boolean isEnabled() { + return enabled; + } + + public SeataProperties setEnabled(boolean enabled) { + this.enabled = enabled; + return this; + } + + public String getApplicationId() { + return applicationId; + } + + public SeataProperties setApplicationId(String applicationId) { + this.applicationId = applicationId; + return this; + } + + public String getTxServiceGroup() { + return txServiceGroup; + } + + public SeataProperties setTxServiceGroup(String txServiceGroup) { + this.txServiceGroup = txServiceGroup; + return this; + } +} diff --git a/seata-spring-boot-starter/src/main/java/io/seata/spring/boot/autoconfigure/properties/file/ClientProperties.java b/seata-spring-boot-starter/src/main/java/io/seata/spring/boot/autoconfigure/properties/file/ClientProperties.java new file mode 100644 index 00000000000..d8b588b52af --- /dev/null +++ b/seata-spring-boot-starter/src/main/java/io/seata/spring/boot/autoconfigure/properties/file/ClientProperties.java @@ -0,0 +1,80 @@ +/* + * Copyright 1999-2019 Seata.io Group. + * + * 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 io.seata.spring.boot.autoconfigure.properties.file; + +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.stereotype.Component; + +import static io.seata.spring.boot.autoconfigure.StarterConstants.CLIENT_PREFIX; + +/** + * @author xingfudeshi@gmail.com + * @date 2019/09/30 + */ +@Component +@ConfigurationProperties(prefix = CLIENT_PREFIX) +public class ClientProperties { + private int asyncCommitBufferLimit = 10000; + private int reportRetryCount = 5; + private int tmCommitRetryCount = 5; + private int tmRollbackRetryCount = 1; + private boolean tableMetaCheckEnable = true; + + public int getAsyncCommitBufferLimit() { + return asyncCommitBufferLimit; + } + + public ClientProperties setAsyncCommitBufferLimit(int asyncCommitBufferLimit) { + this.asyncCommitBufferLimit = asyncCommitBufferLimit; + return this; + } + + public int getReportRetryCount() { + return reportRetryCount; + } + + public ClientProperties setReportRetryCount(int reportRetryCount) { + this.reportRetryCount = reportRetryCount; + return this; + } + + public int getTmCommitRetryCount() { + return tmCommitRetryCount; + } + + public ClientProperties setTmCommitRetryCount(int tmCommitRetryCount) { + this.tmCommitRetryCount = tmCommitRetryCount; + return this; + } + + public int getTmRollbackRetryCount() { + return tmRollbackRetryCount; + } + + public ClientProperties setTmRollbackRetryCount(int tmRollbackRetryCount) { + this.tmRollbackRetryCount = tmRollbackRetryCount; + return this; + } + + public boolean isTableMetaCheckEnable() { + return tableMetaCheckEnable; + } + + public ClientProperties setTableMetaCheckEnable(boolean tableMetaCheckEnable) { + this.tableMetaCheckEnable = tableMetaCheckEnable; + return this; + } +} diff --git a/seata-spring-boot-starter/src/main/java/io/seata/spring/boot/autoconfigure/properties/file/LockProperties.java b/seata-spring-boot-starter/src/main/java/io/seata/spring/boot/autoconfigure/properties/file/LockProperties.java new file mode 100644 index 00000000000..a2b4d3f2a60 --- /dev/null +++ b/seata-spring-boot-starter/src/main/java/io/seata/spring/boot/autoconfigure/properties/file/LockProperties.java @@ -0,0 +1,60 @@ +/* + * Copyright 1999-2019 Seata.io Group. + * + * 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 io.seata.spring.boot.autoconfigure.properties.file; + +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.stereotype.Component; + +import static io.seata.spring.boot.autoconfigure.StarterConstants.LOCK_PREFIX; + +/** + * @author xingfudeshi@gmail.com + * @date 2019/09/30 + */ +@Component +@ConfigurationProperties(prefix = LOCK_PREFIX) +public class LockProperties { + private int lockRetryInterval = 10; + private int lockRetryTimes = 30; + private boolean lockRetryPolicyBranchRollbackOnConflict = true; + + public int getLockRetryInterval() { + return lockRetryInterval; + } + + public LockProperties setLockRetryInterval(int lockRetryInterval) { + this.lockRetryInterval = lockRetryInterval; + return this; + } + + public int getLockRetryTimes() { + return lockRetryTimes; + } + + public LockProperties setLockRetryTimes(int lockRetryTimes) { + this.lockRetryTimes = lockRetryTimes; + return this; + } + + public boolean isLockRetryPolicyBranchRollbackOnConflict() { + return lockRetryPolicyBranchRollbackOnConflict; + } + + public LockProperties setLockRetryPolicyBranchRollbackOnConflict(boolean lockRetryPolicyBranchRollbackOnConflict) { + this.lockRetryPolicyBranchRollbackOnConflict = lockRetryPolicyBranchRollbackOnConflict; + return this; + } +} diff --git a/seata-spring-boot-starter/src/main/java/io/seata/spring/boot/autoconfigure/properties/file/ServiceProperties.java b/seata-spring-boot-starter/src/main/java/io/seata/spring/boot/autoconfigure/properties/file/ServiceProperties.java new file mode 100644 index 00000000000..039173705ef --- /dev/null +++ b/seata-spring-boot-starter/src/main/java/io/seata/spring/boot/autoconfigure/properties/file/ServiceProperties.java @@ -0,0 +1,82 @@ +/* + * Copyright 1999-2019 Seata.io Group. + * + * 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 io.seata.spring.boot.autoconfigure.properties.file; + +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.stereotype.Component; + +import static io.seata.spring.boot.autoconfigure.StarterConstants.SERVICE_PREFIX; + +/** + * @author xingfudeshi@gmail.com + * @date 2019/09/30 + */ +@Component +@ConfigurationProperties(prefix = SERVICE_PREFIX) +public class ServiceProperties { + /** + * vgroup->rgroup + */ + private String vgroupMapping = "default"; + /** + * only support single node + */ + private String grouplist = "127.0.0.1:8091"; + /** + * degrade current not support + */ + private boolean enableDegrade = false; + /** + * disable globalTransaction + */ + private boolean disableGlobalTransaction = false; + + public String getVgroupMapping() { + return vgroupMapping; + } + + public ServiceProperties setVgroupMapping(String vgroupMapping) { + this.vgroupMapping = vgroupMapping; + return this; + } + + public String getGrouplist() { + return grouplist; + } + + public ServiceProperties setGrouplist(String grouplist) { + this.grouplist = grouplist; + return this; + } + + public boolean isEnableDegrade() { + return enableDegrade; + } + + public ServiceProperties setEnableDegrade(boolean enableDegrade) { + this.enableDegrade = enableDegrade; + return this; + } + + public boolean isDisableGlobalTransaction() { + return disableGlobalTransaction; + } + + public ServiceProperties setDisableGlobalTransaction(boolean disableGlobalTransaction) { + this.disableGlobalTransaction = disableGlobalTransaction; + return this; + } +} diff --git a/seata-spring-boot-starter/src/main/java/io/seata/spring/boot/autoconfigure/properties/file/ShutdownProperties.java b/seata-spring-boot-starter/src/main/java/io/seata/spring/boot/autoconfigure/properties/file/ShutdownProperties.java new file mode 100644 index 00000000000..79179c31574 --- /dev/null +++ b/seata-spring-boot-starter/src/main/java/io/seata/spring/boot/autoconfigure/properties/file/ShutdownProperties.java @@ -0,0 +1,43 @@ +/* + * Copyright 1999-2019 Seata.io Group. + * + * 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 io.seata.spring.boot.autoconfigure.properties.file; + +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.stereotype.Component; + +import static io.seata.spring.boot.autoconfigure.StarterConstants.SHUTDOWN_PREFIX; + +/** + * @author xingfudeshi@gmail.com + * @date 2019/09/30 + */ +@Component +@ConfigurationProperties(prefix = SHUTDOWN_PREFIX) +public class ShutdownProperties { + /** + * when destroy server, wait seconds + */ + private long wait = 3L; + + public long getWait() { + return wait; + } + + public ShutdownProperties setWait(long wait) { + this.wait = wait; + return this; + } +} diff --git a/seata-spring-boot-starter/src/main/java/io/seata/spring/boot/autoconfigure/properties/file/SpringProperties.java b/seata-spring-boot-starter/src/main/java/io/seata/spring/boot/autoconfigure/properties/file/SpringProperties.java new file mode 100644 index 00000000000..763a9ce277a --- /dev/null +++ b/seata-spring-boot-starter/src/main/java/io/seata/spring/boot/autoconfigure/properties/file/SpringProperties.java @@ -0,0 +1,43 @@ +/* + * Copyright 1999-2019 Seata.io Group. + * + * 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 io.seata.spring.boot.autoconfigure.properties.file; + +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.stereotype.Component; + +import static io.seata.spring.boot.autoconfigure.StarterConstants.SPRING_PREFIX; + +/** + * @author xingfudeshi@gmail.com + * @date 2019/09/30 + */ +@Component +@ConfigurationProperties(prefix = SPRING_PREFIX) +public class SpringProperties { + /** + * auto proxy the DataSource bean + */ + private boolean datasourceAutoproxy = true; + + public boolean isDatasourceAutoproxy() { + return datasourceAutoproxy; + } + + public SpringProperties setDatasourceAutoproxy(boolean datasourceAutoproxy) { + this.datasourceAutoproxy = datasourceAutoproxy; + return this; + } +} diff --git a/seata-spring-boot-starter/src/main/java/io/seata/spring/boot/autoconfigure/properties/file/SupportProperties.java b/seata-spring-boot-starter/src/main/java/io/seata/spring/boot/autoconfigure/properties/file/SupportProperties.java new file mode 100644 index 00000000000..8bb15785258 --- /dev/null +++ b/seata-spring-boot-starter/src/main/java/io/seata/spring/boot/autoconfigure/properties/file/SupportProperties.java @@ -0,0 +1,30 @@ +/* + * Copyright 1999-2019 Seata.io Group. + * + * 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 io.seata.spring.boot.autoconfigure.properties.file; + +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.stereotype.Component; + +import static io.seata.spring.boot.autoconfigure.StarterConstants.SUPPORT_PREFIX; + +/** + * @author xingfudeshi@gmail.com + * @date 2019/09/30 + */ +@Component +@ConfigurationProperties(prefix = SUPPORT_PREFIX) +public class SupportProperties { +} diff --git a/seata-spring-boot-starter/src/main/java/io/seata/spring/boot/autoconfigure/properties/file/ThreadFactoryProperties.java b/seata-spring-boot-starter/src/main/java/io/seata/spring/boot/autoconfigure/properties/file/ThreadFactoryProperties.java new file mode 100644 index 00000000000..39f484f1827 --- /dev/null +++ b/seata-spring-boot-starter/src/main/java/io/seata/spring/boot/autoconfigure/properties/file/ThreadFactoryProperties.java @@ -0,0 +1,126 @@ +/* + * Copyright 1999-2019 Seata.io Group. + * + * 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 io.seata.spring.boot.autoconfigure.properties.file; + +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.stereotype.Component; + +import static io.seata.spring.boot.autoconfigure.StarterConstants.THREAD_FACTORY_PREFIX; + +/** + * @author xingfudeshi@gmail.com + * @date 2019/09/30 + */ +@Component +@ConfigurationProperties(prefix = THREAD_FACTORY_PREFIX) +public class ThreadFactoryProperties { + private String bossThreadPrefix = "NettyBoss"; + private String workerThreadPrefix = "NettyServerNIOWorker"; + private String serverExecutorThreadPrefix = "NettyServerBizHandler"; + private boolean shareBossWorker = false; + private String clientSelectorThreadPrefix = "NettyClientSelector"; + private int clientSelectorThreadSize = 1; + private String clientWorkerThreadPrefix = "NettyClientWorkerThread"; + /** + * netty boss thread size,will not be used for UDT + */ + private int bossThreadSize = 1; + /** + * auto default pin or 8 + */ + private int workerThreadSize = 8; + + public String getBossThreadPrefix() { + return bossThreadPrefix; + } + + public ThreadFactoryProperties setBossThreadPrefix(String bossThreadPrefix) { + this.bossThreadPrefix = bossThreadPrefix; + return this; + } + + public String getWorkerThreadPrefix() { + return workerThreadPrefix; + } + + public ThreadFactoryProperties setWorkerThreadPrefix(String workerThreadPrefix) { + this.workerThreadPrefix = workerThreadPrefix; + return this; + } + + public String getServerExecutorThreadPrefix() { + return serverExecutorThreadPrefix; + } + + public ThreadFactoryProperties setServerExecutorThreadPrefix(String serverExecutorThreadPrefix) { + this.serverExecutorThreadPrefix = serverExecutorThreadPrefix; + return this; + } + + public boolean isShareBossWorker() { + return shareBossWorker; + } + + public ThreadFactoryProperties setShareBossWorker(boolean shareBossWorker) { + this.shareBossWorker = shareBossWorker; + return this; + } + + public String getClientSelectorThreadPrefix() { + return clientSelectorThreadPrefix; + } + + public ThreadFactoryProperties setClientSelectorThreadPrefix(String clientSelectorThreadPrefix) { + this.clientSelectorThreadPrefix = clientSelectorThreadPrefix; + return this; + } + + public String getClientWorkerThreadPrefix() { + return clientWorkerThreadPrefix; + } + + public ThreadFactoryProperties setClientWorkerThreadPrefix(String clientWorkerThreadPrefix) { + this.clientWorkerThreadPrefix = clientWorkerThreadPrefix; + return this; + } + + public int getClientSelectorThreadSize() { + return clientSelectorThreadSize; + } + + public ThreadFactoryProperties setClientSelectorThreadSize(int clientSelectorThreadSize) { + this.clientSelectorThreadSize = clientSelectorThreadSize; + return this; + } + + public int getBossThreadSize() { + return bossThreadSize; + } + + public ThreadFactoryProperties setBossThreadSize(int bossThreadSize) { + this.bossThreadSize = bossThreadSize; + return this; + } + + public int getWorkerThreadSize() { + return workerThreadSize; + } + + public ThreadFactoryProperties setWorkerThreadSize(int workerThreadSize) { + this.workerThreadSize = workerThreadSize; + return this; + } +} diff --git a/seata-spring-boot-starter/src/main/java/io/seata/spring/boot/autoconfigure/properties/file/TransactionProperties.java b/seata-spring-boot-starter/src/main/java/io/seata/spring/boot/autoconfigure/properties/file/TransactionProperties.java new file mode 100644 index 00000000000..2b83181fd0a --- /dev/null +++ b/seata-spring-boot-starter/src/main/java/io/seata/spring/boot/autoconfigure/properties/file/TransactionProperties.java @@ -0,0 +1,85 @@ +/* + * Copyright 1999-2019 Seata.io Group. + * + * 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 io.seata.spring.boot.autoconfigure.properties.file; + +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.stereotype.Component; + +import static io.seata.core.constants.ConfigurationKeys.TRANSACTION_UNDO_LOG_DEFAULT_TABLE; +import static io.seata.core.protocol.transaction.UndoLogDeleteRequest.DEFAULT_SAVE_DAYS; +import static io.seata.spring.boot.autoconfigure.StarterConstants.TRANSACTION_PREFIX; + +/** + * @author xingfudeshi@gmail.com + * @date 2019/09/30 + */ +@Component +@ConfigurationProperties(prefix = TRANSACTION_PREFIX) +public class TransactionProperties { + private boolean undoDataValidation = true; + private String undoLogSerialization = "jackson"; + private int undoLogSaveDays = DEFAULT_SAVE_DAYS; + /** + * schedule delete expired undo_log in milliseconds + */ + private long undoLogDeletePeriod = 86400000L; + private String undoLogTable = TRANSACTION_UNDO_LOG_DEFAULT_TABLE; + + public boolean isUndoDataValidation() { + return undoDataValidation; + } + + public TransactionProperties setUndoDataValidation(boolean undoDataValidation) { + this.undoDataValidation = undoDataValidation; + return this; + } + + public String getUndoLogSerialization() { + return undoLogSerialization; + } + + public TransactionProperties setUndoLogSerialization(String undoLogSerialization) { + this.undoLogSerialization = undoLogSerialization; + return this; + } + + public int getUndoLogSaveDays() { + return undoLogSaveDays; + } + + public TransactionProperties setUndoLogSaveDays(int undoLogSaveDays) { + this.undoLogSaveDays = undoLogSaveDays; + return this; + } + + public long getUndoLogDeletePeriod() { + return undoLogDeletePeriod; + } + + public TransactionProperties setUndoLogDeletePeriod(long undoLogDeletePeriod) { + this.undoLogDeletePeriod = undoLogDeletePeriod; + return this; + } + + public String getUndoLogTable() { + return undoLogTable; + } + + public TransactionProperties setUndoLogTable(String undoLogTable) { + this.undoLogTable = undoLogTable; + return this; + } +} diff --git a/seata-spring-boot-starter/src/main/java/io/seata/spring/boot/autoconfigure/properties/file/TransportProperties.java b/seata-spring-boot-starter/src/main/java/io/seata/spring/boot/autoconfigure/properties/file/TransportProperties.java new file mode 100644 index 00000000000..96e7b05d9c8 --- /dev/null +++ b/seata-spring-boot-starter/src/main/java/io/seata/spring/boot/autoconfigure/properties/file/TransportProperties.java @@ -0,0 +1,96 @@ +/* + * Copyright 1999-2019 Seata.io Group. + * + * 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 io.seata.spring.boot.autoconfigure.properties.file; + +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.stereotype.Component; + +import static io.seata.spring.boot.autoconfigure.StarterConstants.TRANSPORT_PREFIX; + +/** + * @author xingfudeshi@gmail.com + * @date 2019/09/30 + */ +@Component +@ConfigurationProperties(prefix = TRANSPORT_PREFIX) +public class TransportProperties { + /** + * tcp udt unix-domain-socket + */ + private String type = "TCP"; + /** + * NIO NATIVE + */ + private String server = "NIO"; + /** + * enable heartbeat + */ + private boolean heartbeat = true; + /** + * serialization + */ + private String serialization = "seata"; + /** + * compressor + */ + private String compressor = "none"; + + public String getType() { + return type; + } + + public TransportProperties setType(String type) { + this.type = type; + return this; + } + + public String getServer() { + return server; + } + + public TransportProperties setServer(String server) { + this.server = server; + return this; + } + + public boolean isHeartbeat() { + return heartbeat; + } + + public TransportProperties setHeartbeat(boolean heartbeat) { + this.heartbeat = heartbeat; + return this; + } + + public String getSerialization() { + return serialization; + } + + public TransportProperties setSerialization(String serialization) { + this.serialization = serialization; + return this; + } + + public String getCompressor() { + return compressor; + } + + public TransportProperties setCompressor(String compressor) { + this.compressor = compressor; + return this; + } + +} diff --git a/seata-spring-boot-starter/src/main/java/io/seata/spring/boot/autoconfigure/properties/registry/ConfigApolloProperties.java b/seata-spring-boot-starter/src/main/java/io/seata/spring/boot/autoconfigure/properties/registry/ConfigApolloProperties.java new file mode 100644 index 00000000000..b04807b3aa4 --- /dev/null +++ b/seata-spring-boot-starter/src/main/java/io/seata/spring/boot/autoconfigure/properties/registry/ConfigApolloProperties.java @@ -0,0 +1,50 @@ +/* + * Copyright 1999-2019 Seata.io Group. + * + * 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 io.seata.spring.boot.autoconfigure.properties.registry; + +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.stereotype.Component; + +import static io.seata.spring.boot.autoconfigure.StarterConstants.CONFIG_APOLLO_PREFIX; + +/** + * @author xingfudeshi@gmail.com + * @date 2019/10/03 + */ +@Component +@ConfigurationProperties(prefix = CONFIG_APOLLO_PREFIX) +public class ConfigApolloProperties { + private String appId = "seata-server"; + private String apolloMeta = "http://192.168.1.204:8801"; + + public String getAppId() { + return appId; + } + + public ConfigApolloProperties setAppId(String appId) { + this.appId = appId; + return this; + } + + public String getApolloMeta() { + return apolloMeta; + } + + public ConfigApolloProperties setApolloMeta(String apolloMeta) { + this.apolloMeta = apolloMeta; + return this; + } +} diff --git a/seata-spring-boot-starter/src/main/java/io/seata/spring/boot/autoconfigure/properties/registry/ConfigConsulProperties.java b/seata-spring-boot-starter/src/main/java/io/seata/spring/boot/autoconfigure/properties/registry/ConfigConsulProperties.java new file mode 100644 index 00000000000..065e10dafa6 --- /dev/null +++ b/seata-spring-boot-starter/src/main/java/io/seata/spring/boot/autoconfigure/properties/registry/ConfigConsulProperties.java @@ -0,0 +1,41 @@ +/* + * Copyright 1999-2019 Seata.io Group. + * + * 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 io.seata.spring.boot.autoconfigure.properties.registry; + +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.stereotype.Component; + +import static io.seata.spring.boot.autoconfigure.StarterConstants.CONFIG_CONSUL_PREFIX; + +/** + * @author xingfudeshi@gmail.com + * @date 2019/10/11 + */ +@Component +@ConfigurationProperties(prefix = CONFIG_CONSUL_PREFIX) +public class ConfigConsulProperties { + private String serverAddr = "127.0.0.1:8500"; + + public String getServerAddr() { + return serverAddr; + } + + public ConfigConsulProperties setServerAddr(String serverAddr) { + this.serverAddr = serverAddr; + return this; + } + +} diff --git a/seata-spring-boot-starter/src/main/java/io/seata/spring/boot/autoconfigure/properties/registry/ConfigEtcd3Properties.java b/seata-spring-boot-starter/src/main/java/io/seata/spring/boot/autoconfigure/properties/registry/ConfigEtcd3Properties.java new file mode 100644 index 00000000000..f3652186a40 --- /dev/null +++ b/seata-spring-boot-starter/src/main/java/io/seata/spring/boot/autoconfigure/properties/registry/ConfigEtcd3Properties.java @@ -0,0 +1,42 @@ +/* + * Copyright 1999-2019 Seata.io Group. + * + * 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 io.seata.spring.boot.autoconfigure.properties.registry; + +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.stereotype.Component; + +import static io.seata.spring.boot.autoconfigure.StarterConstants.CONFIG_ETCD3_PREFIX; + + +/** + * @author xingfudeshi@gmail.com + * @date 2019/10/11 + */ +@Component +@ConfigurationProperties(prefix = CONFIG_ETCD3_PREFIX) +public class ConfigEtcd3Properties { + private String serverAddr = "http://localhost:2379"; + + public String getServerAddr() { + return serverAddr; + } + + public ConfigEtcd3Properties setServerAddr(String serverAddr) { + this.serverAddr = serverAddr; + return this; + } + +} diff --git a/seata-spring-boot-starter/src/main/java/io/seata/spring/boot/autoconfigure/properties/registry/ConfigFileProperties.java b/seata-spring-boot-starter/src/main/java/io/seata/spring/boot/autoconfigure/properties/registry/ConfigFileProperties.java new file mode 100644 index 00000000000..ca98bc2eca0 --- /dev/null +++ b/seata-spring-boot-starter/src/main/java/io/seata/spring/boot/autoconfigure/properties/registry/ConfigFileProperties.java @@ -0,0 +1,40 @@ +/* + * Copyright 1999-2019 Seata.io Group. + * + * 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 io.seata.spring.boot.autoconfigure.properties.registry; + +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.stereotype.Component; + +import static io.seata.spring.boot.autoconfigure.StarterConstants.CONFIG_FILE_PREFIX; + +/** + * @author xingfudeshi@gmail.com + * @date 2019/10/03 + */ +@Component +@ConfigurationProperties(prefix = CONFIG_FILE_PREFIX) +public class ConfigFileProperties { + private String name = "file.conf"; + + public String getName() { + return name; + } + + public ConfigFileProperties setName(String name) { + this.name = name; + return this; + } +} diff --git a/seata-spring-boot-starter/src/main/java/io/seata/spring/boot/autoconfigure/properties/registry/ConfigNacosProperties.java b/seata-spring-boot-starter/src/main/java/io/seata/spring/boot/autoconfigure/properties/registry/ConfigNacosProperties.java new file mode 100644 index 00000000000..fae63f5fc61 --- /dev/null +++ b/seata-spring-boot-starter/src/main/java/io/seata/spring/boot/autoconfigure/properties/registry/ConfigNacosProperties.java @@ -0,0 +1,50 @@ +/* + * Copyright 1999-2019 Seata.io Group. + * + * 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 io.seata.spring.boot.autoconfigure.properties.registry; + +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.stereotype.Component; + +import static io.seata.spring.boot.autoconfigure.StarterConstants.CONFIG_NACOS_PREFIX; + +/** + * @author xingfudeshi@gmail.com + * @date 2019/10/03 + */ +@Component +@ConfigurationProperties(prefix = CONFIG_NACOS_PREFIX) +public class ConfigNacosProperties { + private String serverAddr = "localhost"; + private String namespace = ""; + + public String getServerAddr() { + return serverAddr; + } + + public ConfigNacosProperties setServerAddr(String serverAddr) { + this.serverAddr = serverAddr; + return this; + } + + public String getNamespace() { + return namespace; + } + + public ConfigNacosProperties setNamespace(String namespace) { + this.namespace = namespace; + return this; + } +} diff --git a/seata-spring-boot-starter/src/main/java/io/seata/spring/boot/autoconfigure/properties/registry/ConfigProperties.java b/seata-spring-boot-starter/src/main/java/io/seata/spring/boot/autoconfigure/properties/registry/ConfigProperties.java new file mode 100644 index 00000000000..7454ad85a16 --- /dev/null +++ b/seata-spring-boot-starter/src/main/java/io/seata/spring/boot/autoconfigure/properties/registry/ConfigProperties.java @@ -0,0 +1,43 @@ +/* + * Copyright 1999-2019 Seata.io Group. + * + * 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 io.seata.spring.boot.autoconfigure.properties.registry; + +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.stereotype.Component; + +import static io.seata.spring.boot.autoconfigure.StarterConstants.CONFIG_PREFIX; + +/** + * @author xingfudeshi@gmail.com + * @date 2019/10/03 + */ +@Component +@ConfigurationProperties(prefix = CONFIG_PREFIX) +public class ConfigProperties { + /** + * file、nacos、apollo、zk、consul、etcd3 + */ + private String type = "file"; + + public String getType() { + return type; + } + + public ConfigProperties setType(String type) { + this.type = type; + return this; + } +} diff --git a/seata-spring-boot-starter/src/main/java/io/seata/spring/boot/autoconfigure/properties/registry/ConfigZooKeeperProperties.java b/seata-spring-boot-starter/src/main/java/io/seata/spring/boot/autoconfigure/properties/registry/ConfigZooKeeperProperties.java new file mode 100644 index 00000000000..e1f8bf62f40 --- /dev/null +++ b/seata-spring-boot-starter/src/main/java/io/seata/spring/boot/autoconfigure/properties/registry/ConfigZooKeeperProperties.java @@ -0,0 +1,60 @@ +/* + * Copyright 1999-2019 Seata.io Group. + * + * 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 io.seata.spring.boot.autoconfigure.properties.registry; + +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.stereotype.Component; + +import static io.seata.spring.boot.autoconfigure.StarterConstants.CONFIG_ZK_PREFIX; + +/** + * @author xingfudeshi@gmail.com + * @date 2019/10/03 + */ +@Component +@ConfigurationProperties(prefix = CONFIG_ZK_PREFIX) +public class ConfigZooKeeperProperties { + private String serverAddr = "127.0.0.1:2181"; + private long sessionTimeout = 6000L; + private long connectTimeout = 2000L; + + public String getServerAddr() { + return serverAddr; + } + + public ConfigZooKeeperProperties setServerAddr(String serverAddr) { + this.serverAddr = serverAddr; + return this; + } + + public long getSessionTimeout() { + return sessionTimeout; + } + + public ConfigZooKeeperProperties setSessionTimeout(long sessionTimeout) { + this.sessionTimeout = sessionTimeout; + return this; + } + + public long getConnectTimeout() { + return connectTimeout; + } + + public ConfigZooKeeperProperties setConnectTimeout(long connectTimeout) { + this.connectTimeout = connectTimeout; + return this; + } +} diff --git a/seata-spring-boot-starter/src/main/java/io/seata/spring/boot/autoconfigure/properties/registry/RegistryConsulProperties.java b/seata-spring-boot-starter/src/main/java/io/seata/spring/boot/autoconfigure/properties/registry/RegistryConsulProperties.java new file mode 100644 index 00000000000..c84afa8f2ac --- /dev/null +++ b/seata-spring-boot-starter/src/main/java/io/seata/spring/boot/autoconfigure/properties/registry/RegistryConsulProperties.java @@ -0,0 +1,50 @@ +/* + * Copyright 1999-2019 Seata.io Group. + * + * 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 io.seata.spring.boot.autoconfigure.properties.registry; + +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.stereotype.Component; + +import static io.seata.spring.boot.autoconfigure.StarterConstants.REGISTRY_CONSUL_PREFIX; + +/** + * @author xingfudeshi@gmail.com + * @date 2019/10/03 + */ +@Component +@ConfigurationProperties(prefix = REGISTRY_CONSUL_PREFIX) +public class RegistryConsulProperties { + private String cluster = "default"; + private String serverAddr = "127.0.0.1:8500"; + + public String getCluster() { + return cluster; + } + + public RegistryConsulProperties setCluster(String cluster) { + this.cluster = cluster; + return this; + } + + public String getServerAddr() { + return serverAddr; + } + + public RegistryConsulProperties setServerAddr(String serverAddr) { + this.serverAddr = serverAddr; + return this; + } +} diff --git a/seata-spring-boot-starter/src/main/java/io/seata/spring/boot/autoconfigure/properties/registry/RegistryEtcd3Properties.java b/seata-spring-boot-starter/src/main/java/io/seata/spring/boot/autoconfigure/properties/registry/RegistryEtcd3Properties.java new file mode 100644 index 00000000000..7293614cfaf --- /dev/null +++ b/seata-spring-boot-starter/src/main/java/io/seata/spring/boot/autoconfigure/properties/registry/RegistryEtcd3Properties.java @@ -0,0 +1,50 @@ +/* + * Copyright 1999-2019 Seata.io Group. + * + * 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 io.seata.spring.boot.autoconfigure.properties.registry; + +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.stereotype.Component; + +import static io.seata.spring.boot.autoconfigure.StarterConstants.REGISTRY_ETCD3_PREFIX; + +/** + * @author xingfudeshi@gmail.com + * @date 2019/10/03 + */ +@Component +@ConfigurationProperties(prefix = REGISTRY_ETCD3_PREFIX) +public class RegistryEtcd3Properties { + private String cluster = "default"; + private String serverAddr = "http://localhost:2379"; + + public String getCluster() { + return cluster; + } + + public RegistryEtcd3Properties setCluster(String cluster) { + this.cluster = cluster; + return this; + } + + public String getServerAddr() { + return serverAddr; + } + + public RegistryEtcd3Properties setServerAddr(String serverAddr) { + this.serverAddr = serverAddr; + return this; + } +} diff --git a/seata-spring-boot-starter/src/main/java/io/seata/spring/boot/autoconfigure/properties/registry/RegistryEurekaProperties.java b/seata-spring-boot-starter/src/main/java/io/seata/spring/boot/autoconfigure/properties/registry/RegistryEurekaProperties.java new file mode 100644 index 00000000000..faa34b300a7 --- /dev/null +++ b/seata-spring-boot-starter/src/main/java/io/seata/spring/boot/autoconfigure/properties/registry/RegistryEurekaProperties.java @@ -0,0 +1,60 @@ +/* + * Copyright 1999-2019 Seata.io Group. + * + * 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 io.seata.spring.boot.autoconfigure.properties.registry; + +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.stereotype.Component; + +import static io.seata.spring.boot.autoconfigure.StarterConstants.REGISTRY_EUREKA_PREFIX; + +/** + * @author xingfudeshi@gmail.com + * @date 2019/10/03 + */ +@Component +@ConfigurationProperties(prefix = REGISTRY_EUREKA_PREFIX) +public class RegistryEurekaProperties { + private String serviceUrl = "http://localhost:8761/eureka"; + private String application = "default"; + private String weight = "1"; + + public String getServiceUrl() { + return serviceUrl; + } + + public RegistryEurekaProperties setServiceUrl(String serviceUrl) { + this.serviceUrl = serviceUrl; + return this; + } + + public String getApplication() { + return application; + } + + public RegistryEurekaProperties setApplication(String application) { + this.application = application; + return this; + } + + public String getWeight() { + return weight; + } + + public RegistryEurekaProperties setWeight(String weight) { + this.weight = weight; + return this; + } +} diff --git a/seata-spring-boot-starter/src/main/java/io/seata/spring/boot/autoconfigure/properties/registry/RegistryFileProperties.java b/seata-spring-boot-starter/src/main/java/io/seata/spring/boot/autoconfigure/properties/registry/RegistryFileProperties.java new file mode 100644 index 00000000000..f2860336efb --- /dev/null +++ b/seata-spring-boot-starter/src/main/java/io/seata/spring/boot/autoconfigure/properties/registry/RegistryFileProperties.java @@ -0,0 +1,40 @@ +/* + * Copyright 1999-2019 Seata.io Group. + * + * 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 io.seata.spring.boot.autoconfigure.properties.registry; + +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.stereotype.Component; + +import static io.seata.spring.boot.autoconfigure.StarterConstants.REGISTRY_FILE_PREFIX; + +/** + * @author xingfudeshi@gmail.com + * @date 2019/10/03 + */ +@Component +@ConfigurationProperties(prefix = REGISTRY_FILE_PREFIX) +public class RegistryFileProperties { + private String name = "file.conf"; + + public String getName() { + return name; + } + + public RegistryFileProperties setName(String name) { + this.name = name; + return this; + } +} diff --git a/seata-spring-boot-starter/src/main/java/io/seata/spring/boot/autoconfigure/properties/registry/RegistryNacosProperties.java b/seata-spring-boot-starter/src/main/java/io/seata/spring/boot/autoconfigure/properties/registry/RegistryNacosProperties.java new file mode 100644 index 00000000000..6a2fc77456a --- /dev/null +++ b/seata-spring-boot-starter/src/main/java/io/seata/spring/boot/autoconfigure/properties/registry/RegistryNacosProperties.java @@ -0,0 +1,60 @@ +/* + * Copyright 1999-2019 Seata.io Group. + * + * 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 io.seata.spring.boot.autoconfigure.properties.registry; + +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.stereotype.Component; + +import static io.seata.spring.boot.autoconfigure.StarterConstants.REGISTRY_NACOS_PREFIX; + +/** + * @author xingfudeshi@gmail.com + * @date 2019/10/03 + */ +@Component +@ConfigurationProperties(prefix = REGISTRY_NACOS_PREFIX) +public class RegistryNacosProperties { + private String serverAddr = "localhost"; + private String namespace = ""; + private String cluster = "default"; + + public String getServerAddr() { + return serverAddr; + } + + public RegistryNacosProperties setServerAddr(String serverAddr) { + this.serverAddr = serverAddr; + return this; + } + + public String getNamespace() { + return namespace; + } + + public RegistryNacosProperties setNamespace(String namespace) { + this.namespace = namespace; + return this; + } + + public String getCluster() { + return cluster; + } + + public RegistryNacosProperties setCluster(String cluster) { + this.cluster = cluster; + return this; + } +} diff --git a/seata-spring-boot-starter/src/main/java/io/seata/spring/boot/autoconfigure/properties/registry/RegistryProperties.java b/seata-spring-boot-starter/src/main/java/io/seata/spring/boot/autoconfigure/properties/registry/RegistryProperties.java new file mode 100644 index 00000000000..2891be9eb25 --- /dev/null +++ b/seata-spring-boot-starter/src/main/java/io/seata/spring/boot/autoconfigure/properties/registry/RegistryProperties.java @@ -0,0 +1,43 @@ +/* + * Copyright 1999-2019 Seata.io Group. + * + * 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 io.seata.spring.boot.autoconfigure.properties.registry; + +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.stereotype.Component; + +import static io.seata.spring.boot.autoconfigure.StarterConstants.REGISTRY_PREFIX; + +/** + * @author xingfudeshi@gmail.com + * @date 2019/10/03 + */ +@Component +@ConfigurationProperties(prefix = REGISTRY_PREFIX) +public class RegistryProperties { + /** + * file 、nacos 、eureka、redis、zk、consul、etcd3、sofa + */ + private String type = "file"; + + public String getType() { + return type; + } + + public RegistryProperties setType(String type) { + this.type = type; + return this; + } +} diff --git a/seata-spring-boot-starter/src/main/java/io/seata/spring/boot/autoconfigure/properties/registry/RegistryRedisProperties.java b/seata-spring-boot-starter/src/main/java/io/seata/spring/boot/autoconfigure/properties/registry/RegistryRedisProperties.java new file mode 100644 index 00000000000..5cc6dc778e7 --- /dev/null +++ b/seata-spring-boot-starter/src/main/java/io/seata/spring/boot/autoconfigure/properties/registry/RegistryRedisProperties.java @@ -0,0 +1,50 @@ +/* + * Copyright 1999-2019 Seata.io Group. + * + * 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 io.seata.spring.boot.autoconfigure.properties.registry; + +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.stereotype.Component; + +import static io.seata.spring.boot.autoconfigure.StarterConstants.REGISTRY_REDIS_PREFIX; + +/** + * @author xingfudeshi@gmail.com + * @date 2019/10/03 + */ +@Component +@ConfigurationProperties(prefix = REGISTRY_REDIS_PREFIX) +public class RegistryRedisProperties { + private String serverAddr = "localhost:6379"; + private String db = "0"; + + public String getServerAddr() { + return serverAddr; + } + + public RegistryRedisProperties setServerAddr(String serverAddr) { + this.serverAddr = serverAddr; + return this; + } + + public String getDb() { + return db; + } + + public RegistryRedisProperties setDb(String db) { + this.db = db; + return this; + } +} diff --git a/seata-spring-boot-starter/src/main/java/io/seata/spring/boot/autoconfigure/properties/registry/RegistrySofaProperties.java b/seata-spring-boot-starter/src/main/java/io/seata/spring/boot/autoconfigure/properties/registry/RegistrySofaProperties.java new file mode 100644 index 00000000000..b0d6cf16f9d --- /dev/null +++ b/seata-spring-boot-starter/src/main/java/io/seata/spring/boot/autoconfigure/properties/registry/RegistrySofaProperties.java @@ -0,0 +1,100 @@ +/* + * Copyright 1999-2019 Seata.io Group. + * + * 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 io.seata.spring.boot.autoconfigure.properties.registry; + +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.stereotype.Component; + +import static io.seata.spring.boot.autoconfigure.StarterConstants.REGISTRY_SOFA_PREFIX; + +/** + * @author xingfudeshi@gmail.com + * @date 2019/10/03 + */ +@Component +@ConfigurationProperties(prefix = REGISTRY_SOFA_PREFIX) +public class RegistrySofaProperties { + private String serverAddr = "127.0.0.1:9603"; + private String application = "default"; + private String region = "DEFAULT_ZONE"; + private String datacenter = "DefaultDataCenter"; + private String cluster = "default"; + private String group = "SEATA_GROUP"; + private String addressWaitTime = "3000"; + + public String getServerAddr() { + return serverAddr; + } + + public RegistrySofaProperties setServerAddr(String serverAddr) { + this.serverAddr = serverAddr; + return this; + } + + public String getApplication() { + return application; + } + + public RegistrySofaProperties setApplication(String application) { + this.application = application; + return this; + } + + public String getRegion() { + return region; + } + + public RegistrySofaProperties setRegion(String region) { + this.region = region; + return this; + } + + public String getDatacenter() { + return datacenter; + } + + public RegistrySofaProperties setDatacenter(String datacenter) { + this.datacenter = datacenter; + return this; + } + + public String getCluster() { + return cluster; + } + + public RegistrySofaProperties setCluster(String cluster) { + this.cluster = cluster; + return this; + } + + public String getGroup() { + return group; + } + + public RegistrySofaProperties setGroup(String group) { + this.group = group; + return this; + } + + public String getAddressWaitTime() { + return addressWaitTime; + } + + public RegistrySofaProperties setAddressWaitTime(String addressWaitTime) { + this.addressWaitTime = addressWaitTime; + return this; + } +} diff --git a/seata-spring-boot-starter/src/main/java/io/seata/spring/boot/autoconfigure/properties/registry/RegistryZooKeeperProperties.java b/seata-spring-boot-starter/src/main/java/io/seata/spring/boot/autoconfigure/properties/registry/RegistryZooKeeperProperties.java new file mode 100644 index 00000000000..47c4f07d4e6 --- /dev/null +++ b/seata-spring-boot-starter/src/main/java/io/seata/spring/boot/autoconfigure/properties/registry/RegistryZooKeeperProperties.java @@ -0,0 +1,70 @@ +/* + * Copyright 1999-2019 Seata.io Group. + * + * 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 io.seata.spring.boot.autoconfigure.properties.registry; + +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.stereotype.Component; + +import static io.seata.spring.boot.autoconfigure.StarterConstants.REGISTRY_ZK_PREFIX; + +/** + * @author xingfudeshi@gmail.com + * @date 2019/10/03 + */ +@Component +@ConfigurationProperties(prefix = REGISTRY_ZK_PREFIX) +public class RegistryZooKeeperProperties { + private String cluster = "default"; + private String serverAddr = "127.0.0.1:2181"; + private long sessionTimeout = 6000L; + private long connectTimeout = 2000L; + + public String getCluster() { + return cluster; + } + + public RegistryZooKeeperProperties setCluster(String cluster) { + this.cluster = cluster; + return this; + } + + public String getServerAddr() { + return serverAddr; + } + + public RegistryZooKeeperProperties setServerAddr(String serverAddr) { + this.serverAddr = serverAddr; + return this; + } + + public long getSessionTimeout() { + return sessionTimeout; + } + + public RegistryZooKeeperProperties setSessionTimeout(long sessionTimeout) { + this.sessionTimeout = sessionTimeout; + return this; + } + + public long getConnectTimeout() { + return connectTimeout; + } + + public RegistryZooKeeperProperties setConnectTimeout(long connectTimeout) { + this.connectTimeout = connectTimeout; + return this; + } +} diff --git a/seata-spring-boot-starter/src/main/java/io/seata/spring/boot/autoconfigure/provider/SpringBootConfigurationProvider.java b/seata-spring-boot-starter/src/main/java/io/seata/spring/boot/autoconfigure/provider/SpringBootConfigurationProvider.java new file mode 100644 index 00000000000..5b973e9b762 --- /dev/null +++ b/seata-spring-boot-starter/src/main/java/io/seata/spring/boot/autoconfigure/provider/SpringBootConfigurationProvider.java @@ -0,0 +1,196 @@ +/* + * Copyright 1999-2019 Seata.io Group. + * + * 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 io.seata.spring.boot.autoconfigure.provider; + +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.util.Map; +import java.util.Optional; +import java.util.stream.Stream; + +import io.seata.config.Configuration; +import io.seata.config.ExtConfigurationProvider; +import io.seata.spring.boot.autoconfigure.StarterConstants; +import io.seata.spring.boot.autoconfigure.util.SpringUtils; +import io.seata.spring.boot.autoconfigure.util.StringFormatUtils; +import org.apache.commons.lang.StringUtils; +import org.springframework.cglib.proxy.Enhancer; +import org.springframework.cglib.proxy.MethodInterceptor; +import org.springframework.cglib.proxy.MethodProxy; + +import static io.seata.spring.boot.autoconfigure.StarterConstants.NORMALIZED_KEY_CLIENT; +import static io.seata.spring.boot.autoconfigure.StarterConstants.NORMALIZED_KEY_CLIENT_LOCK; +import static io.seata.spring.boot.autoconfigure.StarterConstants.NORMALIZED_KEY_CONFIG_APOLLO; +import static io.seata.spring.boot.autoconfigure.StarterConstants.NORMALIZED_KEY_CONFIG_ZK; +import static io.seata.spring.boot.autoconfigure.StarterConstants.NORMALIZED_KEY_DATASOURCE_AUTOPROXY; +import static io.seata.spring.boot.autoconfigure.StarterConstants.NORMALIZED_KEY_GROUPLIST; +import static io.seata.spring.boot.autoconfigure.StarterConstants.NORMALIZED_KEY_REGISTRY_ZK; +import static io.seata.spring.boot.autoconfigure.StarterConstants.NORMALIZED_KEY_TRANSACTION; +import static io.seata.spring.boot.autoconfigure.StarterConstants.NORMALIZED_KEY_TRANSPORT_THREAD_FACTORY; +import static io.seata.spring.boot.autoconfigure.StarterConstants.NORMALIZED_KEY_VGROUP_MAPPING; +import static io.seata.spring.boot.autoconfigure.StarterConstants.PROPERTY_MAP; +import static io.seata.spring.boot.autoconfigure.StarterConstants.SPECIAL_KEY_CLIENT; +import static io.seata.spring.boot.autoconfigure.StarterConstants.SPECIAL_KEY_CLIENT_LOCK; +import static io.seata.spring.boot.autoconfigure.StarterConstants.SPECIAL_KEY_CONFIG_APOLLO; +import static io.seata.spring.boot.autoconfigure.StarterConstants.SPECIAL_KEY_CONFIG_ZK; +import static io.seata.spring.boot.autoconfigure.StarterConstants.SPECIAL_KEY_DATASOURCE_AUTOPROXY; +import static io.seata.spring.boot.autoconfigure.StarterConstants.SPECIAL_KEY_GROUPLIST; +import static io.seata.spring.boot.autoconfigure.StarterConstants.SPECIAL_KEY_REGISTRY_ZK; +import static io.seata.spring.boot.autoconfigure.StarterConstants.SPECIAL_KEY_TRANSACTION; +import static io.seata.spring.boot.autoconfigure.StarterConstants.SPECIAL_KEY_TRANSPORT_THREAD_FACTORY; +import static io.seata.spring.boot.autoconfigure.StarterConstants.SPECIAL_KEY_VGROUP_MAPPING; + + +/** + * @author xingfudeshi@gmail.com + * @date 2019/10/03 + */ +public class SpringBootConfigurationProvider implements ExtConfigurationProvider { + private static final String INTERCEPT_METHOD_PREFIX = "get"; + + @Override + public Configuration provide(Configuration originalConfiguration) { + return (Configuration) Enhancer.create(originalConfiguration.getClass(), new MethodInterceptor() { + @Override + public Object intercept(Object proxy, Method method, Object[] args, MethodProxy methodProxy) throws Throwable { + if (method.getName().startsWith(INTERCEPT_METHOD_PREFIX) && args.length > 0) { + Object result = null; + String rawDataId = (String) args[0]; + if (args.length == 1) { + result = get(convertDataId(rawDataId)); + } else if (args.length == 2) { + result = get(convertDataId(rawDataId), args[1]); + } else if (args.length == 3) { + result = get(convertDataId(rawDataId), args[1], (Long) args[2]); + } + if (null != result) { + return result; + } + + } + + return method.invoke(originalConfiguration, args); + } + }); + } + + private Object get(String dataId, Object defaultValue, long timeoutMills) throws IllegalAccessException { + return get(dataId, defaultValue); + + } + + private Object get(String dataId, Object defaultValue) throws IllegalAccessException { + Object result = get(dataId); + if (null == result) { + return defaultValue; + } + return result; + } + + private Object get(String dataId) throws IllegalAccessException { + String propertySuffix = getPropertySuffix(dataId); + Class propertyClass = getPropertyClass(getPropertyPrefix(dataId)); + if (null != propertyClass) { + Object propertyObject = SpringUtils.getBean(propertyClass); + Optional fieldOptional = Stream.of(propertyObject.getClass().getDeclaredFields()).filter(f -> f.getName().equalsIgnoreCase(propertySuffix)).findAny(); + if (fieldOptional.isPresent()) { + Field field = fieldOptional.get(); + field.setAccessible(true); + return field.get(propertyObject); + } + } + return null; + } + + /** + * convert data id + * + * @param rawDataId + * @return dataId + */ + private String convertDataId(String rawDataId) { + if (rawDataId.startsWith(SPECIAL_KEY_VGROUP_MAPPING)) { + return StarterConstants.SERVICE_PREFIX + "." + NORMALIZED_KEY_VGROUP_MAPPING; + } + if (rawDataId.endsWith(SPECIAL_KEY_GROUPLIST)) { + return StarterConstants.SERVICE_PREFIX + "." + NORMALIZED_KEY_GROUPLIST; + } + if (rawDataId.endsWith(SPECIAL_KEY_DATASOURCE_AUTOPROXY)) { + return StarterConstants.SPRING_PREFIX + "." + NORMALIZED_KEY_DATASOURCE_AUTOPROXY; + } + if (rawDataId.startsWith(SPECIAL_KEY_TRANSACTION)) { + String suffix = StringUtils.removeStart(rawDataId, NORMALIZED_KEY_TRANSACTION); + return StarterConstants.TRANSACTION_PREFIX + "." + StringFormatUtils.dotToCamel(suffix); + } + if (rawDataId.startsWith(SPECIAL_KEY_CLIENT_LOCK)) { + String suffix = StringUtils.removeStart(rawDataId, NORMALIZED_KEY_CLIENT_LOCK); + return StarterConstants.LOCK_PREFIX + "." + StringFormatUtils.minusToCamel(StringFormatUtils.dotToCamel(suffix)); + } + if (rawDataId.startsWith(SPECIAL_KEY_CLIENT)) { + String suffix = StringUtils.removeStart(rawDataId, NORMALIZED_KEY_CLIENT); + return StarterConstants.CLIENT_PREFIX + "." + StringFormatUtils.dotToCamel(suffix); + } + if (rawDataId.startsWith(SPECIAL_KEY_TRANSPORT_THREAD_FACTORY)) { + String suffix = StringUtils.removeStart(rawDataId, NORMALIZED_KEY_TRANSPORT_THREAD_FACTORY); + return StarterConstants.THREAD_FACTORY_PREFIX + "." + StringFormatUtils.minusToCamel(suffix); + } + if (rawDataId.startsWith(SPECIAL_KEY_REGISTRY_ZK)) { + String suffix = StringUtils.removeStart(rawDataId, NORMALIZED_KEY_REGISTRY_ZK); + return StarterConstants.REGISTRY_ZK_PREFIX + "." + StringFormatUtils.dotToCamel(suffix); + } + if (rawDataId.startsWith(SPECIAL_KEY_CONFIG_ZK)) { + String suffix = StringUtils.removeStart(rawDataId, NORMALIZED_KEY_CONFIG_ZK); + return StarterConstants.CONFIG_ZK_PREFIX + "." + StringFormatUtils.dotToCamel(suffix); + } + if (rawDataId.startsWith(SPECIAL_KEY_CONFIG_APOLLO)) { + String suffix = StringUtils.removeStart(rawDataId, NORMALIZED_KEY_CONFIG_APOLLO); + return StarterConstants.CONFIG_APOLLO_PREFIX + "." + StringFormatUtils.dotToCamel(suffix); + } + + return StarterConstants.SEATA_PREFIX + "." + rawDataId; + } + + /** + * Get property prefix + * + * @param dataId + * @return propertyPrefix + */ + private String getPropertyPrefix(String dataId) { + return StringFormatUtils.underlineToCamel(StringFormatUtils.minusToCamel(StringUtils.substringBeforeLast(dataId, "."))); + } + + /** + * Get property suffix + * + * @param dataId + * @return propertySuffix + */ + private String getPropertySuffix(String dataId) { + return StringUtils.substringAfterLast(dataId, "."); + } + + /** + * Get property class + * + * @param propertyPrefix + * @return propertyClass + */ + private Class getPropertyClass(String propertyPrefix) { + Optional> entry = PROPERTY_MAP.entrySet().stream().filter(e -> propertyPrefix.equals(e.getKey())).findAny(); + return entry.map(Map.Entry::getValue).orElse(null); + } +} diff --git a/seata-spring-boot-starter/src/main/java/io/seata/spring/boot/autoconfigure/util/SpringUtils.java b/seata-spring-boot-starter/src/main/java/io/seata/spring/boot/autoconfigure/util/SpringUtils.java new file mode 100644 index 00000000000..bbee6d8328a --- /dev/null +++ b/seata-spring-boot-starter/src/main/java/io/seata/spring/boot/autoconfigure/util/SpringUtils.java @@ -0,0 +1,76 @@ +/* + * Copyright 1999-2019 Seata.io Group. + * + * 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 io.seata.spring.boot.autoconfigure.util; + +import org.springframework.beans.BeansException; +import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationContextAware; + +/** + * @author xingfudeshi@gmail.com + * @date 2019/10/03 + */ +public class SpringUtils implements ApplicationContextAware { + + private static ApplicationContext applicationContext; + + /** + * get applicationContext + * + * @return applicationContext + */ + public static ApplicationContext getApplicationContext() { + return applicationContext; + } + + /** + * get by name + * + * @param name + * @return bean + */ + public static Object getBean(String name) { + return getApplicationContext().getBean(name); + } + + /** + * get by class + * + * @param clazz + * @param + * @return bean + */ + public static T getBean(Class clazz) { + return getApplicationContext().getBean(clazz); + } + + /** + * get by name & class + * + * @param name + * @param clazz + * @param + * @return bean + */ + public static T getBean(String name, Class clazz) { + return getApplicationContext().getBean(name, clazz); + } + + @Override + public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { + SpringUtils.applicationContext = applicationContext; + } +} \ No newline at end of file diff --git a/seata-spring-boot-starter/src/main/java/io/seata/spring/boot/autoconfigure/util/StringFormatUtils.java b/seata-spring-boot-starter/src/main/java/io/seata/spring/boot/autoconfigure/util/StringFormatUtils.java new file mode 100644 index 00000000000..658a9d395ab --- /dev/null +++ b/seata-spring-boot-starter/src/main/java/io/seata/spring/boot/autoconfigure/util/StringFormatUtils.java @@ -0,0 +1,108 @@ +/* + * Copyright 1999-2019 Seata.io Group. + * + * 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 io.seata.spring.boot.autoconfigure.util; + +/** + * @author xingfudeshi@gmail.com + * @date 2019/10/03 + */ +public class StringFormatUtils { + private static final char MINUS = '-'; + private static final char UNDERLINE = '_'; + private static final char DOT = '.'; + + /** + * camelTo underline format + * + * @param param + * @return formatted string + */ + public static String camelToUnderline(String param) { + if (param == null || "".equals(param.trim())) { + return ""; + } + int len = param.length(); + StringBuilder sb = new StringBuilder(len); + for (int i = 0; i < len; i++) { + char c = param.charAt(i); + if (Character.isUpperCase(c)) { + sb.append(UNDERLINE); + sb.append(Character.toLowerCase(c)); + } else { + sb.append(c); + } + } + return sb.toString(); + } + + /** + * underline to camel + * + * @param param + * @return formatted string + */ + public static String underlineToCamel(String param) { + return formatCamel(param, UNDERLINE); + } + + /** + * minus to camel + * + * @param param + * @return formatted string + */ + public static String minusToCamel(String param) { + return formatCamel(param, MINUS); + } + + /** + * dot to camel + * + * @param param + * @return formatted string + */ + public static String dotToCamel(String param) { + return formatCamel(param, DOT); + } + + /** + * format camel + * + * @param param + * @param sign + * @return formatted string + */ + private static String formatCamel(String param, char sign) { + if (param == null || "".equals(param.trim())) { + return ""; + } + int len = param.length(); + StringBuilder sb = new StringBuilder(len); + for (int i = 0; i < len; i++) { + char c = param.charAt(i); + if (c == sign) { + if (++i < len) { + sb.append(Character.toUpperCase(param.charAt(i))); + } + } else { + sb.append(c); + } + } + return sb.toString(); + } + + +} \ No newline at end of file diff --git a/seata-spring-boot-starter/src/main/resources/META-INF/services/io.seata.config.ExtConfigurationProvider b/seata-spring-boot-starter/src/main/resources/META-INF/services/io.seata.config.ExtConfigurationProvider new file mode 100644 index 00000000000..8ee3b2b4f45 --- /dev/null +++ b/seata-spring-boot-starter/src/main/resources/META-INF/services/io.seata.config.ExtConfigurationProvider @@ -0,0 +1 @@ +io.seata.spring.boot.autoconfigure.provider.SpringBootConfigurationProvider \ No newline at end of file diff --git a/seata-spring-boot-starter/src/main/resources/META-INF/spring.factories b/seata-spring-boot-starter/src/main/resources/META-INF/spring.factories new file mode 100644 index 00000000000..f38b1880a78 --- /dev/null +++ b/seata-spring-boot-starter/src/main/resources/META-INF/spring.factories @@ -0,0 +1,2 @@ +# Auto Configure +org.springframework.boot.autoconfigure.EnableAutoConfiguration=io.seata.spring.boot.autoconfigure.SeataAutoConfiguration diff --git a/server/src/main/resources/file.conf b/server/src/main/resources/file.conf index 9967e90aad6..6baf229ca95 100644 --- a/server/src/main/resources/file.conf +++ b/server/src/main/resources/file.conf @@ -33,8 +33,8 @@ service { default.grouplist = "127.0.0.1:8091" #degrade current not support enableDegrade = false - #disable - disable = false + #disable globaltransaction + disableGlobalTransaction = 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" diff --git a/test/src/test/resources/file.conf b/test/src/test/resources/file.conf index 4fe50f1a002..b6e9da2dc21 100644 --- a/test/src/test/resources/file.conf +++ b/test/src/test/resources/file.conf @@ -33,8 +33,8 @@ service { default.grouplist = "127.0.0.1:8091" #degrade current not support enableDegrade = false - #disable - disable = false + #disable globaltransaction + disableGlobalTransaction = false } client { @@ -42,10 +42,13 @@ client { lock { retry.internal = 10 retry.times = 30 + retry.policy.branch-rollback-on-conflict = true } report.retry.count = 5 tm.commit.retry.count = 1 tm.rollback.retry.count = 1 + #schedule check table meta + table.meta.check.enable = true } transaction { undo.data.validation = true