From e7886fa1956403d8226f129cfe22bcbfadd8925b Mon Sep 17 00:00:00 2001 From: zhanglong Date: Sun, 31 May 2020 17:43:57 +0800 Subject: [PATCH 1/2] fix some issue for the consul sync --- README.md | 2 +- nacossync-console/pom.xml | 2 +- nacossync-distribution/pom.xml | 2 +- nacossync-test/pom.xml | 4 +- nacossync-worker/pom.xml | 4 +- .../com/alibaba/nacossync/api/ClusterApi.java | 40 ++++++++------- .../com/alibaba/nacossync/api/TaskApi.java | 50 +++++++++++-------- .../extension/SyncManagerService.java | 18 ++++--- .../impl/ConsulSyncToNacosServiceImpl.java | 43 ++++++++++------ .../impl/NacosSyncToConsulServiceImpl.java | 8 +-- .../impl/NacosSyncToZookeeperServiceImpl.java | 22 ++++---- .../impl/ZookeeperSyncToNacosServiceImpl.java | 29 +++++++---- .../template/processor/TaskAddProcessor.java | 18 ++++--- .../alibaba/nacossync/util/ConsulUtils.java | 2 +- .../src/main/resources/application.properties | 1 - pom.xml | 4 +- 16 files changed, 144 insertions(+), 105 deletions(-) diff --git a/README.md b/README.md index f948c3e3..98a87f87 100644 --- a/README.md +++ b/README.md @@ -103,7 +103,7 @@ The path to the target file: ``` xml -nacos-sync/nacossync-distribution/target/nacosSync.0.3.0.zip +nacos-sync/nacossync-distribution/target/nacosSync.0.3.8.zip ``` diff --git a/nacossync-console/pom.xml b/nacossync-console/pom.xml index 431902a9..0d592491 100644 --- a/nacossync-console/pom.xml +++ b/nacossync-console/pom.xml @@ -16,7 +16,7 @@ nacossync-parent com.alibaba.nacossync - 0.3.7 + 0.3.8 4.0.0 diff --git a/nacossync-distribution/pom.xml b/nacossync-distribution/pom.xml index 5492cf77..a08eb83c 100644 --- a/nacossync-distribution/pom.xml +++ b/nacossync-distribution/pom.xml @@ -5,7 +5,7 @@ nacossync-parent com.alibaba.nacossync - 0.3.7 + 0.3.8 4.0.0 pom diff --git a/nacossync-test/pom.xml b/nacossync-test/pom.xml index 688d8f25..e402e5f4 100644 --- a/nacossync-test/pom.xml +++ b/nacossync-test/pom.xml @@ -17,7 +17,7 @@ nacossync-parent com.alibaba.nacossync - 0.3.7 + 0.3.8 ../pom.xml 4.0.0 @@ -39,7 +39,7 @@ com.alibaba.nacossync nacossync-worker - 0.3.7 + 0.3.8 org.springframework.boot diff --git a/nacossync-worker/pom.xml b/nacossync-worker/pom.xml index f537288b..4702db44 100644 --- a/nacossync-worker/pom.xml +++ b/nacossync-worker/pom.xml @@ -16,11 +16,11 @@ nacossync-parent com.alibaba.nacossync - 0.3.7 + 0.3.8 4.0.0 nacossync-worker - 0.3.7 + 0.3.8 3.4.9 4.1.0 diff --git a/nacossync-worker/src/main/java/com/alibaba/nacossync/api/ClusterApi.java b/nacossync-worker/src/main/java/com/alibaba/nacossync/api/ClusterApi.java index a7c231ae..616d36b6 100644 --- a/nacossync-worker/src/main/java/com/alibaba/nacossync/api/ClusterApi.java +++ b/nacossync-worker/src/main/java/com/alibaba/nacossync/api/ClusterApi.java @@ -16,25 +16,26 @@ */ package com.alibaba.nacossync.api; -import lombok.extern.slf4j.Slf4j; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.bind.annotation.RestController; - import com.alibaba.nacossync.constant.ClusterTypeEnum; -import com.alibaba.nacossync.pojo.result.*; import com.alibaba.nacossync.pojo.request.ClusterAddRequest; import com.alibaba.nacossync.pojo.request.ClusterDeleteRequest; import com.alibaba.nacossync.pojo.request.ClusterDetailQueryRequest; import com.alibaba.nacossync.pojo.request.ClusterListQueryRequest; +import com.alibaba.nacossync.pojo.result.ClusterAddResult; +import com.alibaba.nacossync.pojo.result.ClusterDeleteResult; +import com.alibaba.nacossync.pojo.result.ClusterDetailQueryResult; +import com.alibaba.nacossync.pojo.result.ClusterListQueryResult; +import com.alibaba.nacossync.pojo.result.ClusterTypeResult; import com.alibaba.nacossync.template.SkyWalkerTemplate; import com.alibaba.nacossync.template.processor.ClusterAddProcessor; import com.alibaba.nacossync.template.processor.ClusterDeleteProcessor; import com.alibaba.nacossync.template.processor.ClusterDetailQueryProcessor; import com.alibaba.nacossync.template.processor.ClusterListQueryProcessor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RestController; /** * @author NacosSync @@ -44,17 +45,22 @@ @RestController public class ClusterApi { - @Autowired - private ClusterAddProcessor clusterAddProcessor; + private final ClusterAddProcessor clusterAddProcessor; + + private final ClusterDeleteProcessor clusterDeleteProcessor; - @Autowired - private ClusterDeleteProcessor clusterDeleteProcessor; + private final ClusterDetailQueryProcessor clusterDetailQueryProcessor; - @Autowired - private ClusterDetailQueryProcessor clusterDetailQueryProcessor; + private final ClusterListQueryProcessor clusterListQueryProcessor; - @Autowired - private ClusterListQueryProcessor clusterListQueryProcessor; + public ClusterApi( + ClusterAddProcessor clusterAddProcessor, ClusterDeleteProcessor clusterDeleteProcessor, + ClusterDetailQueryProcessor clusterDetailQueryProcessor, ClusterListQueryProcessor clusterListQueryProcessor) { + this.clusterAddProcessor = clusterAddProcessor; + this.clusterDeleteProcessor = clusterDeleteProcessor; + this.clusterDetailQueryProcessor = clusterDetailQueryProcessor; + this.clusterListQueryProcessor = clusterListQueryProcessor; + } @RequestMapping(path = "/v1/cluster/list", method = RequestMethod.GET) public ClusterListQueryResult clusters(ClusterListQueryRequest clusterListQueryRequest) { diff --git a/nacossync-worker/src/main/java/com/alibaba/nacossync/api/TaskApi.java b/nacossync-worker/src/main/java/com/alibaba/nacossync/api/TaskApi.java index 5de3381f..f0e2510e 100644 --- a/nacossync-worker/src/main/java/com/alibaba/nacossync/api/TaskApi.java +++ b/nacossync-worker/src/main/java/com/alibaba/nacossync/api/TaskApi.java @@ -16,21 +16,26 @@ */ package com.alibaba.nacossync.api; -import com.alibaba.nacossync.pojo.request.*; -import com.alibaba.nacossync.template.processor.*; -import lombok.extern.slf4j.Slf4j; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.bind.annotation.RestController; - +import com.alibaba.nacossync.pojo.request.TaskAddRequest; +import com.alibaba.nacossync.pojo.request.TaskDeleteRequest; +import com.alibaba.nacossync.pojo.request.TaskDetailQueryRequest; +import com.alibaba.nacossync.pojo.request.TaskListQueryRequest; +import com.alibaba.nacossync.pojo.request.TaskUpdateRequest; import com.alibaba.nacossync.pojo.result.BaseResult; import com.alibaba.nacossync.pojo.result.TaskAddResult; import com.alibaba.nacossync.pojo.result.TaskDetailQueryResult; import com.alibaba.nacossync.pojo.result.TaskListQueryResult; import com.alibaba.nacossync.template.SkyWalkerTemplate; +import com.alibaba.nacossync.template.processor.TaskAddProcessor; +import com.alibaba.nacossync.template.processor.TaskDeleteProcessor; +import com.alibaba.nacossync.template.processor.TaskDetailProcessor; +import com.alibaba.nacossync.template.processor.TaskListQueryProcessor; +import com.alibaba.nacossync.template.processor.TaskUpdateProcessor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RestController; /** * @author NacosSync @@ -40,20 +45,25 @@ @RestController public class TaskApi { - @Autowired - private TaskUpdateProcessor taskUpdateProcessor; + private final TaskUpdateProcessor taskUpdateProcessor; + + private final TaskAddProcessor taskAddProcessor; - @Autowired - private TaskAddProcessor taskAddProcessor; + private final TaskDeleteProcessor taskDeleteProcessor; - @Autowired - private TaskDeleteProcessor taskDeleteProcessor; + private final TaskListQueryProcessor taskListQueryProcessor; - @Autowired - private TaskListQueryProcessor taskListQueryProcessor; + private final TaskDetailProcessor taskDetailProcessor; - @Autowired - private TaskDetailProcessor taskDetailProcessor; + public TaskApi(TaskUpdateProcessor taskUpdateProcessor, + TaskAddProcessor taskAddProcessor, TaskDeleteProcessor taskDeleteProcessor, + TaskListQueryProcessor taskListQueryProcessor, TaskDetailProcessor taskDetailProcessor) { + this.taskUpdateProcessor = taskUpdateProcessor; + this.taskAddProcessor = taskAddProcessor; + this.taskDeleteProcessor = taskDeleteProcessor; + this.taskListQueryProcessor = taskListQueryProcessor; + this.taskDetailProcessor = taskDetailProcessor; + } @RequestMapping(path = "/v1/task/list", method = RequestMethod.GET) public TaskListQueryResult tasks(TaskListQueryRequest taskListQueryRequest) { diff --git a/nacossync-worker/src/main/java/com/alibaba/nacossync/extension/SyncManagerService.java b/nacossync-worker/src/main/java/com/alibaba/nacossync/extension/SyncManagerService.java index c390406e..0d6ebc4f 100644 --- a/nacossync-worker/src/main/java/com/alibaba/nacossync/extension/SyncManagerService.java +++ b/nacossync-worker/src/main/java/com/alibaba/nacossync/extension/SyncManagerService.java @@ -12,23 +12,21 @@ */ package com.alibaba.nacossync.extension; +import static com.alibaba.nacossync.util.SkyWalkerUtil.generateSyncKey; + import com.alibaba.nacos.api.exception.NacosException; import com.alibaba.nacossync.cache.SkyWalkerCacheServices; import com.alibaba.nacossync.constant.ClusterTypeEnum; import com.alibaba.nacossync.extension.annotation.NacosSyncService; import com.alibaba.nacossync.pojo.model.TaskDO; +import java.util.concurrent.ConcurrentHashMap; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.BeansException; import org.springframework.beans.factory.InitializingBean; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; import org.springframework.stereotype.Service; -import java.util.Hashtable; - -import static com.alibaba.nacossync.util.SkyWalkerUtil.generateSyncKey; - /** * @author NacosSync * @version $Id: SyncManagerService.java, v 0.1 2018-09-25 PM5:17 NacosSync Exp $$ @@ -37,13 +35,17 @@ @Service public class SyncManagerService implements InitializingBean, ApplicationContextAware { - @Autowired - protected SkyWalkerCacheServices skyWalkerCacheServices; + protected final SkyWalkerCacheServices skyWalkerCacheServices; - private Hashtable syncServiceMap = new Hashtable(); + private ConcurrentHashMap syncServiceMap = new ConcurrentHashMap(); private ApplicationContext applicationContext; + public SyncManagerService( + SkyWalkerCacheServices skyWalkerCacheServices) { + this.skyWalkerCacheServices = skyWalkerCacheServices; + } + public boolean delete(TaskDO taskDO) throws NacosException { return getSyncService(taskDO.getSourceClusterId(), taskDO.getDestClusterId()).delete(taskDO); diff --git a/nacossync-worker/src/main/java/com/alibaba/nacossync/extension/impl/ConsulSyncToNacosServiceImpl.java b/nacossync-worker/src/main/java/com/alibaba/nacossync/extension/impl/ConsulSyncToNacosServiceImpl.java index 366d090a..5805c948 100644 --- a/nacossync-worker/src/main/java/com/alibaba/nacossync/extension/impl/ConsulSyncToNacosServiceImpl.java +++ b/nacossync-worker/src/main/java/com/alibaba/nacossync/extension/impl/ConsulSyncToNacosServiceImpl.java @@ -12,6 +12,7 @@ */ package com.alibaba.nacossync.extension.impl; +import com.alibaba.nacos.api.exception.NacosException; import com.alibaba.nacos.api.naming.NamingService; import com.alibaba.nacos.api.naming.pojo.Instance; import com.alibaba.nacossync.cache.SkyWalkerCacheServices; @@ -96,22 +97,8 @@ public boolean sync(TaskDO taskDO) { consulClient.getHealthServices(taskDO.getServiceName(), true, QueryParams.DEFAULT); List healthServiceList = response.getValue(); Set instanceKeys = new HashSet<>(); - for (HealthService healthService : healthServiceList) { - if (needSync(ConsulUtils.transferMetadata(healthService.getService().getTags()))) { - destNamingService.registerInstance(taskDO.getServiceName(), - buildSyncInstance(healthService, taskDO)); - instanceKeys.add(composeInstanceKey(healthService.getService().getAddress(), - healthService.getService().getPort())); - } - } - List allInstances = destNamingService.getAllInstances(taskDO.getServiceName()); - for (Instance instance : allInstances) { - if (needDelete(instance.getMetadata(), taskDO) - && !instanceKeys.contains(composeInstanceKey(instance.getIp(), instance.getPort()))) { - - destNamingService.deregisterInstance(taskDO.getServiceName(), instance.getIp(), instance.getPort()); - } - } + overrideAllInstance(taskDO, destNamingService, healthServiceList, instanceKeys); + cleanAllOldInstance(taskDO, destNamingService, instanceKeys); specialSyncEventBus.subscribe(taskDO, this::sync); } catch (Exception e) { log.error("Sync task from consul to nacos was failed, taskId:{}", taskDO.getTaskId(), e); @@ -121,6 +108,30 @@ public boolean sync(TaskDO taskDO) { return true; } + private void cleanAllOldInstance(TaskDO taskDO, NamingService destNamingService, Set instanceKeys) + throws NacosException { + List allInstances = destNamingService.getAllInstances(taskDO.getServiceName()); + for (Instance instance : allInstances) { + if (needDelete(instance.getMetadata(), taskDO) + && !instanceKeys.contains(composeInstanceKey(instance.getIp(), instance.getPort()))) { + + destNamingService.deregisterInstance(taskDO.getServiceName(), instance.getIp(), instance.getPort()); + } + } + } + + private void overrideAllInstance(TaskDO taskDO, NamingService destNamingService, + List healthServiceList, Set instanceKeys) throws NacosException { + for (HealthService healthService : healthServiceList) { + if (needSync(ConsulUtils.transferMetadata(healthService.getService().getTags()))) { + destNamingService.registerInstance(taskDO.getServiceName(), + buildSyncInstance(healthService, taskDO)); + instanceKeys.add(composeInstanceKey(healthService.getService().getAddress(), + healthService.getService().getPort())); + } + } + } + private Instance buildSyncInstance(HealthService instance, TaskDO taskDO) { Instance temp = new Instance(); temp.setIp(instance.getService().getAddress()); diff --git a/nacossync-worker/src/main/java/com/alibaba/nacossync/extension/impl/NacosSyncToConsulServiceImpl.java b/nacossync-worker/src/main/java/com/alibaba/nacossync/extension/impl/NacosSyncToConsulServiceImpl.java index 64184b73..0a117412 100644 --- a/nacossync-worker/src/main/java/com/alibaba/nacossync/extension/impl/NacosSyncToConsulServiceImpl.java +++ b/nacossync-worker/src/main/java/com/alibaba/nacossync/extension/impl/NacosSyncToConsulServiceImpl.java @@ -33,6 +33,8 @@ import com.ecwid.consul.v1.agent.model.NewService; import com.ecwid.consul.v1.health.model.HealthService; import com.google.common.collect.Lists; +import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; import lombok.extern.slf4j.Slf4j; import java.util.HashSet; @@ -123,7 +125,8 @@ public boolean sync(TaskDO taskDO) { if (needDelete(ConsulUtils.transferMetadata(healthService.getService().getTags()), taskDO) && !instanceKeySet.contains(composeInstanceKey(healthService.getService().getAddress(), healthService.getService().getPort()))) { - consulClient.agentServiceDeregister(healthService.getService().getId()); + consulClient.agentServiceDeregister(URLEncoder + .encode(healthService.getService().getId(), StandardCharsets.UTF_8.toString())); } } } catch (Exception e) { @@ -150,7 +153,7 @@ public NewService buildSyncInstance(Instance instance, TaskDO taskDO) { NewService newService = new NewService(); newService.setAddress(instance.getIp()); newService.setPort(instance.getPort()); - newService.setName(instance.getServiceName()); + newService.setName(taskDO.getServiceName()); newService.setId(instance.getInstanceId()); List tags = Lists.newArrayList(); tags.addAll(instance.getMetadata().entrySet().stream() @@ -163,5 +166,4 @@ public NewService buildSyncInstance(Instance instance, TaskDO taskDO) { return newService; } - } diff --git a/nacossync-worker/src/main/java/com/alibaba/nacossync/extension/impl/NacosSyncToZookeeperServiceImpl.java b/nacossync-worker/src/main/java/com/alibaba/nacossync/extension/impl/NacosSyncToZookeeperServiceImpl.java index 5b1b9b23..65699734 100644 --- a/nacossync-worker/src/main/java/com/alibaba/nacossync/extension/impl/NacosSyncToZookeeperServiceImpl.java +++ b/nacossync-worker/src/main/java/com/alibaba/nacossync/extension/impl/NacosSyncToZookeeperServiceImpl.java @@ -12,6 +12,9 @@ */ package com.alibaba.nacossync.extension.impl; +import static com.alibaba.nacossync.util.StringUtils.convertDubboFullPathForZk; +import static com.alibaba.nacossync.util.StringUtils.convertDubboProvidersPath; + import com.alibaba.nacos.api.naming.NamingService; import com.alibaba.nacos.api.naming.listener.EventListener; import com.alibaba.nacos.api.naming.listener.NamingEvent; @@ -29,25 +32,21 @@ import com.alibaba.nacossync.pojo.model.TaskDO; import com.alibaba.nacossync.util.DubboConstants; import com.google.common.collect.Sets; +import java.io.UnsupportedEncodingException; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; import lombok.extern.slf4j.Slf4j; import org.apache.curator.framework.CuratorFramework; -import org.apache.curator.framework.listen.ListenerContainer; import org.apache.curator.framework.recipes.cache.PathChildrenCache; import org.apache.curator.framework.recipes.cache.PathChildrenCacheEvent; -import org.apache.curator.framework.recipes.cache.PathChildrenCacheListener; import org.apache.curator.utils.CloseableUtils; import org.apache.zookeeper.CreateMode; -import org.apache.zookeeper.KeeperException.NodeExistsException; import org.springframework.beans.factory.annotation.Autowired; -import java.io.UnsupportedEncodingException; -import java.text.DecimalFormat; -import java.util.*; -import java.util.concurrent.ConcurrentHashMap; - -import static com.alibaba.nacossync.util.StringUtils.convertDubboFullPathForZk; -import static com.alibaba.nacossync.util.StringUtils.convertDubboProvidersPath; - /** * Nacos 同步 Zk 数据 * @@ -131,6 +130,7 @@ public boolean sync(TaskDO taskDO) { nacosListenerMap.putIfAbsent(taskDO.getTaskId(), event -> { if (event instanceof NamingEvent) { try { + List sourceInstances = sourceNamingService.getAllInstances(taskDO.getServiceName()); Set newInstanceUrlSet = getWaitingToAddInstance(taskDO, client, sourceInstances); diff --git a/nacossync-worker/src/main/java/com/alibaba/nacossync/extension/impl/ZookeeperSyncToNacosServiceImpl.java b/nacossync-worker/src/main/java/com/alibaba/nacossync/extension/impl/ZookeeperSyncToNacosServiceImpl.java index 25ae4032..c66d2b20 100644 --- a/nacossync-worker/src/main/java/com/alibaba/nacossync/extension/impl/ZookeeperSyncToNacosServiceImpl.java +++ b/nacossync-worker/src/main/java/com/alibaba/nacossync/extension/impl/ZookeeperSyncToNacosServiceImpl.java @@ -12,6 +12,17 @@ */ package com.alibaba.nacossync.extension.impl; +import static com.alibaba.nacossync.util.DubboConstants.GROUP_KEY; +import static com.alibaba.nacossync.util.DubboConstants.INSTANCE_IP_KEY; +import static com.alibaba.nacossync.util.DubboConstants.INSTANCE_PORT_KEY; +import static com.alibaba.nacossync.util.DubboConstants.PROTOCOL_KEY; +import static com.alibaba.nacossync.util.DubboConstants.VERSION_KEY; +import static com.alibaba.nacossync.util.DubboConstants.WEIGHT_KEY; +import static com.alibaba.nacossync.util.DubboConstants.createServiceName; +import static com.alibaba.nacossync.util.StringUtils.convertDubboProvidersPath; +import static com.alibaba.nacossync.util.StringUtils.parseIpAndPortString; +import static com.alibaba.nacossync.util.StringUtils.parseQueryString; + import com.alibaba.nacos.api.exception.NacosException; import com.alibaba.nacos.api.naming.NamingService; import com.alibaba.nacos.api.naming.pojo.Instance; @@ -25,6 +36,12 @@ import com.alibaba.nacossync.extension.holder.ZookeeperServerHolder; import com.alibaba.nacossync.monitor.MetricsManager; import com.alibaba.nacossync.pojo.model.TaskDO; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.concurrent.ConcurrentHashMap; +import java.util.function.Predicate; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.apache.curator.framework.recipes.cache.ChildData; @@ -33,16 +50,6 @@ import org.apache.curator.utils.CloseableUtils; import org.springframework.beans.factory.annotation.Autowired; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.concurrent.ConcurrentHashMap; -import java.util.function.Predicate; - -import static com.alibaba.nacossync.util.DubboConstants.*; -import static com.alibaba.nacossync.util.StringUtils.*; - /** * @author paderlol * @version 1.0 @@ -221,7 +228,7 @@ protected Instance buildSyncInstance(Map queryParam, Map metaData = new HashMap<>(queryParam); diff --git a/nacossync-worker/src/main/java/com/alibaba/nacossync/template/processor/TaskAddProcessor.java b/nacossync-worker/src/main/java/com/alibaba/nacossync/template/processor/TaskAddProcessor.java index a2aa2365..3316b4e0 100644 --- a/nacossync-worker/src/main/java/com/alibaba/nacossync/template/processor/TaskAddProcessor.java +++ b/nacossync-worker/src/main/java/com/alibaba/nacossync/template/processor/TaskAddProcessor.java @@ -16,7 +16,6 @@ */ package com.alibaba.nacossync.template.processor; -import com.alibaba.nacossync.constant.ClusterTypeEnum; import com.alibaba.nacossync.constant.TaskStatusEnum; import com.alibaba.nacossync.dao.ClusterAccessService; import com.alibaba.nacossync.dao.TaskAccessService; @@ -29,7 +28,6 @@ import com.alibaba.nacossync.template.Processor; import com.alibaba.nacossync.util.SkyWalkerUtil; import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; /** @@ -40,14 +38,18 @@ @Service public class TaskAddProcessor implements Processor { - @Autowired - private SyncManagerService syncManagerService; + private final SyncManagerService syncManagerService; - @Autowired - private TaskAccessService taskAccessService; + private final TaskAccessService taskAccessService; - @Autowired - private ClusterAccessService clusterAccessService; + private final ClusterAccessService clusterAccessService; + + public TaskAddProcessor(SyncManagerService syncManagerService, + TaskAccessService taskAccessService, ClusterAccessService clusterAccessService) { + this.syncManagerService = syncManagerService; + this.taskAccessService = taskAccessService; + this.clusterAccessService = clusterAccessService; + } @Override public void process(TaskAddRequest taskAddRequest, TaskAddResult taskAddResult, diff --git a/nacossync-worker/src/main/java/com/alibaba/nacossync/util/ConsulUtils.java b/nacossync-worker/src/main/java/com/alibaba/nacossync/util/ConsulUtils.java index de4229f2..55d94b42 100644 --- a/nacossync-worker/src/main/java/com/alibaba/nacossync/util/ConsulUtils.java +++ b/nacossync-worker/src/main/java/com/alibaba/nacossync/util/ConsulUtils.java @@ -28,7 +28,7 @@ public static Map transferMetadata(List tags) { Map metadata = new HashMap<>(); if (!CollectionUtils.isEmpty(tags)) { return tags.stream().filter(tag -> tag.split("=", -1).length == 2).map(tag -> tag.split("=", -1)) - .collect(Collectors.toMap(tagSplitArray -> tagSplitArray[0], tagSplitArray -> tagSplitArray[2])); + .collect(Collectors.toMap(tagSplitArray -> tagSplitArray[0], tagSplitArray -> tagSplitArray[1])); } return metadata; } diff --git a/nacossync-worker/src/main/resources/application.properties b/nacossync-worker/src/main/resources/application.properties index f9d7b729..cebf630c 100644 --- a/nacossync-worker/src/main/resources/application.properties +++ b/nacossync-worker/src/main/resources/application.properties @@ -9,6 +9,5 @@ spring.datasource.url=jdbc:mysql://127.0.0.1:3306/nacos_sync?characterEncoding=u spring.datasource.username=root spring.datasource.password=root -eureka.client.service-url management.endpoints.web.exposure.include=* management.endpoint.health.show-details=always diff --git a/pom.xml b/pom.xml index d47a72ec..6704e235 100644 --- a/pom.xml +++ b/pom.xml @@ -18,7 +18,7 @@ com.alibaba.nacossync nacossync-parent - 0.3.7 + 0.3.8 nacossync-console nacossync-worker @@ -73,7 +73,7 @@ com.alibaba.nacossync nacossync-worker - 0.3.7 + 0.3.8 From 896021a3a6668892bfca06de8e36172ea17987b2 Mon Sep 17 00:00:00 2001 From: zhanglong Date: Sun, 31 May 2020 17:55:09 +0800 Subject: [PATCH 2/2] fix merge conflict --- .../com/alibaba/nacossync/api/TaskApi.java | 37 ++++++++----------- 1 file changed, 16 insertions(+), 21 deletions(-) diff --git a/nacossync-worker/src/main/java/com/alibaba/nacossync/api/TaskApi.java b/nacossync-worker/src/main/java/com/alibaba/nacossync/api/TaskApi.java index 346b13a5..6c9f98a4 100644 --- a/nacossync-worker/src/main/java/com/alibaba/nacossync/api/TaskApi.java +++ b/nacossync-worker/src/main/java/com/alibaba/nacossync/api/TaskApi.java @@ -1,22 +1,19 @@ /* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE + * file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file + * to You 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 + * 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. + * 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.nacossync.api; import com.alibaba.nacossync.pojo.request.TaskAddRequest; +import com.alibaba.nacossync.pojo.request.TaskDeleteInBatchRequest; import com.alibaba.nacossync.pojo.request.TaskDeleteRequest; import com.alibaba.nacossync.pojo.request.TaskDetailQueryRequest; import com.alibaba.nacossync.pojo.request.TaskListQueryRequest; @@ -27,6 +24,7 @@ import com.alibaba.nacossync.pojo.result.TaskListQueryResult; import com.alibaba.nacossync.template.SkyWalkerTemplate; import com.alibaba.nacossync.template.processor.TaskAddProcessor; +import com.alibaba.nacossync.template.processor.TaskDeleteInBatchProcessor; import com.alibaba.nacossync.template.processor.TaskDeleteProcessor; import com.alibaba.nacossync.template.processor.TaskDetailProcessor; import com.alibaba.nacossync.template.processor.TaskListQueryProcessor; @@ -51,20 +49,19 @@ public class TaskApi { private final TaskDeleteProcessor taskDeleteProcessor; - - @Autowired - private TaskDeleteInBatchProcessor taskDeleteInBatchProcessor; + private final TaskDeleteInBatchProcessor taskDeleteInBatchProcessor; private final TaskListQueryProcessor taskListQueryProcessor; private final TaskDetailProcessor taskDetailProcessor; - public TaskApi(TaskUpdateProcessor taskUpdateProcessor, - TaskAddProcessor taskAddProcessor, TaskDeleteProcessor taskDeleteProcessor, + public TaskApi(TaskUpdateProcessor taskUpdateProcessor, TaskAddProcessor taskAddProcessor, + TaskDeleteProcessor taskDeleteProcessor, TaskDeleteInBatchProcessor taskDeleteInBatchProcessor, TaskListQueryProcessor taskListQueryProcessor, TaskDetailProcessor taskDetailProcessor) { this.taskUpdateProcessor = taskUpdateProcessor; this.taskAddProcessor = taskAddProcessor; this.taskDeleteProcessor = taskDeleteProcessor; + this.taskDeleteInBatchProcessor = taskDeleteInBatchProcessor; this.taskListQueryProcessor = taskListQueryProcessor; this.taskDetailProcessor = taskDetailProcessor; } @@ -72,15 +69,13 @@ public TaskApi(TaskUpdateProcessor taskUpdateProcessor, @RequestMapping(path = "/v1/task/list", method = RequestMethod.GET) public TaskListQueryResult tasks(TaskListQueryRequest taskListQueryRequest) { - return SkyWalkerTemplate.run(taskListQueryProcessor, taskListQueryRequest, - new TaskListQueryResult()); + return SkyWalkerTemplate.run(taskListQueryProcessor, taskListQueryRequest, new TaskListQueryResult()); } @RequestMapping(path = "/v1/task/detail", method = RequestMethod.GET) public TaskDetailQueryResult getByTaskId(TaskDetailQueryRequest taskDetailQueryRequest) { - return SkyWalkerTemplate.run(taskDetailProcessor, taskDetailQueryRequest, - new TaskDetailQueryResult()); + return SkyWalkerTemplate.run(taskDetailProcessor, taskDetailQueryRequest, new TaskDetailQueryResult()); } @RequestMapping(path = "/v1/task/delete", method = RequestMethod.DELETE)