From 17439be724d168854a4406f2ddbdb13da931b582 Mon Sep 17 00:00:00 2001 From: paderlol Date: Wed, 31 Jul 2024 15:45:05 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=9C=89=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1=E8=BF=90=E8=A1=8C=E6=97=B6=E5=8F=AF=E4=BB=A5=E5=88=A0?= =?UTF-8?q?=E9=99=A4=E9=9B=86=E7=BE=A4=E4=BF=A1=E6=81=AF=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98=20#371?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../nacossync/dao/TaskAccessService.java | 69 ++++++++++--------- .../dao/repository/TaskRepository.java | 7 +- .../processor/ClusterAddProcessor.java | 19 +++-- .../processor/ClusterDeleteProcessor.java | 36 ++++++---- 4 files changed, 73 insertions(+), 58 deletions(-) diff --git a/nacossync-worker/src/main/java/com/alibaba/nacossync/dao/TaskAccessService.java b/nacossync-worker/src/main/java/com/alibaba/nacossync/dao/TaskAccessService.java index bb215a21..ad4f11c9 100644 --- a/nacossync-worker/src/main/java/com/alibaba/nacossync/dao/TaskAccessService.java +++ b/nacossync-worker/src/main/java/com/alibaba/nacossync/dao/TaskAccessService.java @@ -14,6 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.alibaba.nacossync.dao; import com.alibaba.nacossync.constant.SkyWalkerConstants; @@ -39,7 +40,7 @@ */ @Service public class TaskAccessService implements PageQueryService { - + private final TaskRepository taskRepository; public TaskAccessService(TaskRepository taskRepository) { @@ -47,74 +48,78 @@ public TaskAccessService(TaskRepository taskRepository) { } public TaskDO findByTaskId(String taskId) { - + return taskRepository.findByTaskId(taskId); } - + public void deleteTaskById(String taskId) { taskRepository.deleteByTaskId(taskId); } /** * batch delete tasks by taskIds - * @author yongchao9 + * * @param taskIds + * @author yongchao9 */ public void deleteTaskInBatch(List taskIds) { - List tds=taskRepository.findAllByTaskIdIn(taskIds); + List tds = taskRepository.findAllByTaskIdIn(taskIds); taskRepository.deleteAllInBatch(tds); } - + public Iterable findAll() { - + return taskRepository.findAll(); } - + public void addTask(TaskDO taskDO) { - + taskRepository.save(taskDO); - + } - + + public int countByDestClusterIdOrSourceClusterId(String destClusterId, String sourceClusterId) { + return taskRepository.countByDestClusterIdOrSourceClusterId(destClusterId, sourceClusterId); + } + private Predicate getPredicate(CriteriaBuilder criteriaBuilder, List predicates) { Predicate[] p = new Predicate[predicates.size()]; return criteriaBuilder.and(predicates.toArray(p)); } - - private List getPredicates(Root root, CriteriaBuilder criteriaBuilder, QueryCondition queryCondition) { - + + private List getPredicates(Root root, CriteriaBuilder criteriaBuilder, + QueryCondition queryCondition) { + List predicates = new ArrayList<>(); predicates.add(criteriaBuilder.like(root.get("serviceName"), "%" + queryCondition.getServiceName() + "%")); - + return predicates; } - + @Override public Page findPageNoCriteria(Integer pageNum, Integer size) { - + Pageable pageable = PageRequest.of(pageNum, size, Sort.Direction.DESC, "id"); - + return taskRepository.findAll(pageable); } - + @Override public Page findPageCriteria(Integer pageNum, Integer size, QueryCondition queryCondition) { - + Pageable pageable = PageRequest.of(pageNum, size, Sort.Direction.DESC, "id"); - + return getTaskDOS(queryCondition, pageable); } - + private Page getTaskDOS(QueryCondition queryCondition, Pageable pageable) { - return taskRepository.findAll( - (Specification) (root, criteriaQuery, criteriaBuilder) -> { - - List predicates = getPredicates(root, - criteriaBuilder, queryCondition); - - return getPredicate(criteriaBuilder, predicates); - - }, pageable); + return taskRepository.findAll((Specification) (root, criteriaQuery, criteriaBuilder) -> { + + List predicates = getPredicates(root, criteriaBuilder, queryCondition); + + return getPredicate(criteriaBuilder, predicates); + + }, pageable); } public List findAllByServiceNameEqualAll() { @@ -124,5 +129,5 @@ public List findAllByServiceNameEqualAll() { public List findAllByServiceNameNotEqualAll() { return taskRepository.findAllByServiceNameNotIgnoreCase(SkyWalkerConstants.NACOS_ALL_SERVICE_NAME); } - + } diff --git a/nacossync-worker/src/main/java/com/alibaba/nacossync/dao/repository/TaskRepository.java b/nacossync-worker/src/main/java/com/alibaba/nacossync/dao/repository/TaskRepository.java index 90456366..bfbc7023 100644 --- a/nacossync-worker/src/main/java/com/alibaba/nacossync/dao/repository/TaskRepository.java +++ b/nacossync-worker/src/main/java/com/alibaba/nacossync/dao/repository/TaskRepository.java @@ -34,16 +34,15 @@ public interface TaskRepository extends CrudRepository, JpaRepo TaskDO findByTaskId(String taskId); @Transactional - int deleteByTaskId(String taskId); + void deleteByTaskId(String taskId); List findAllByTaskIdIn(List taskIds); - - List getAllByWorkerIp(String workerIp); - /** * query service is all,use ns leven sync data */ List findAllByServiceNameEqualsIgnoreCase(String serviceName); List findAllByServiceNameNotIgnoreCase(String serviceName); + + int countByDestClusterIdOrSourceClusterId(String destClusterId,String sourceClusterId); } diff --git a/nacossync-worker/src/main/java/com/alibaba/nacossync/template/processor/ClusterAddProcessor.java b/nacossync-worker/src/main/java/com/alibaba/nacossync/template/processor/ClusterAddProcessor.java index 5b99725e..1087977f 100644 --- a/nacossync-worker/src/main/java/com/alibaba/nacossync/template/processor/ClusterAddProcessor.java +++ b/nacossync-worker/src/main/java/com/alibaba/nacossync/template/processor/ClusterAddProcessor.java @@ -19,7 +19,6 @@ import com.alibaba.nacossync.constant.ClusterTypeEnum; import com.alibaba.nacossync.dao.ClusterAccessService; import com.alibaba.nacossync.exception.SkyWalkerException; -import com.alibaba.nacossync.monitor.MetricsManager; import com.alibaba.nacossync.pojo.model.ClusterDO; import com.alibaba.nacossync.pojo.request.ClusterAddRequest; import com.alibaba.nacossync.pojo.result.ClusterAddResult; @@ -28,7 +27,6 @@ import com.fasterxml.jackson.databind.ObjectMapper; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; /** @@ -38,16 +36,17 @@ @Slf4j @Service public class ClusterAddProcessor implements Processor { + - @Autowired - private MetricsManager metricsManager; - - @Autowired - private ClusterAccessService clusterAccessService; - - @Autowired - private ObjectMapper objectMapper; + private final ClusterAccessService clusterAccessService; + private final ObjectMapper objectMapper; + + public ClusterAddProcessor(ClusterAccessService clusterAccessService, ObjectMapper objectMapper) { + this.clusterAccessService = clusterAccessService; + this.objectMapper = objectMapper; + } + @Override public void process(ClusterAddRequest clusterAddRequest, ClusterAddResult clusterAddResult, Object... others) throws Exception { diff --git a/nacossync-worker/src/main/java/com/alibaba/nacossync/template/processor/ClusterDeleteProcessor.java b/nacossync-worker/src/main/java/com/alibaba/nacossync/template/processor/ClusterDeleteProcessor.java index 95536d4a..07d2b1e5 100644 --- a/nacossync-worker/src/main/java/com/alibaba/nacossync/template/processor/ClusterDeleteProcessor.java +++ b/nacossync-worker/src/main/java/com/alibaba/nacossync/template/processor/ClusterDeleteProcessor.java @@ -14,15 +14,16 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.alibaba.nacossync.template.processor; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; +package com.alibaba.nacossync.template.processor; import com.alibaba.nacossync.dao.ClusterAccessService; -import com.alibaba.nacossync.pojo.result.ClusterDeleteResult; +import com.alibaba.nacossync.dao.TaskAccessService; +import com.alibaba.nacossync.exception.SkyWalkerException; import com.alibaba.nacossync.pojo.request.ClusterDeleteRequest; +import com.alibaba.nacossync.pojo.result.ClusterDeleteResult; import com.alibaba.nacossync.template.Processor; +import org.springframework.stereotype.Service; /** * @author NacosSync @@ -30,15 +31,26 @@ */ @Service public class ClusterDeleteProcessor implements Processor { - - @Autowired - private ClusterAccessService clusterAccessService; - + + private final ClusterAccessService clusterAccessService; + + private final TaskAccessService taskAccessService; + + public ClusterDeleteProcessor(ClusterAccessService clusterAccessService, TaskAccessService taskAccessService) { + this.clusterAccessService = clusterAccessService; + this.taskAccessService = taskAccessService; + } + @Override - public void process(ClusterDeleteRequest clusterDeleteRequest, - ClusterDeleteResult clusterDeleteResult, Object... others) throws Exception { - + public void process(ClusterDeleteRequest clusterDeleteRequest, ClusterDeleteResult clusterDeleteResult, + Object... others) throws Exception { + int count = taskAccessService.countByDestClusterIdOrSourceClusterId(clusterDeleteRequest.getClusterId(), + clusterDeleteRequest.getClusterId()); + if (count > 0) { + throw new SkyWalkerException(String.format("集群下有%d个任务,请先删除任务", count)); + } + clusterAccessService.deleteByClusterId(clusterDeleteRequest.getClusterId()); - + } } From ca08bd7d6e4ef38d772cfa8fc3f44355f71a6f53 Mon Sep 17 00:00:00 2001 From: paderlol Date: Thu, 29 Aug 2024 16:43:05 +0800 Subject: [PATCH 2/4] =?UTF-8?q?1.=20=E4=BC=98=E5=8C=96=E9=83=A8=E5=88=86?= =?UTF-8?q?=E9=9B=86=E7=BE=A4=E6=96=B0=E5=A2=9E=E9=83=A8=E5=88=86=E5=86=97?= =?UTF-8?q?=E4=BD=99=E4=BB=A3=E7=A0=81=202.=20=E5=8D=87=E7=BA=A7Java=20JDK?= =?UTF-8?q?=E5=88=B017?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- nacossync-worker/pom.xml | 4 +- .../dao/repository/ClusterRepository.java | 8 +-- .../extension/client/InstanceQueryModel.java | 16 ------ .../extension/client/SyncQueryClient.java | 13 ----- .../client/impl/NacosSyncQueryClientImpl.java | 56 ------------------- .../nacossync/pojo/model/SystemConfigDO.java | 1 + .../alibaba/nacossync/pojo/model/TaskDO.java | 1 + .../nacossync/pojo/view/ClusterModel.java | 25 +++++++-- .../nacossync/pojo/view/TaskModel.java | 21 ++++++- .../processor/ClusterAddProcessor.java | 33 +++++------ .../ClusterDetailQueryProcessor.java | 11 +--- .../processor/ClusterListQueryProcessor.java | 56 +++++++------------ .../processor/TaskDetailProcessor.java | 36 +++++------- .../processor/TaskListQueryProcessor.java | 51 +++++++---------- pom.xml | 12 +++- 15 files changed, 132 insertions(+), 212 deletions(-) delete mode 100644 nacossync-worker/src/main/java/com/alibaba/nacossync/extension/client/InstanceQueryModel.java delete mode 100644 nacossync-worker/src/main/java/com/alibaba/nacossync/extension/client/SyncQueryClient.java delete mode 100644 nacossync-worker/src/main/java/com/alibaba/nacossync/extension/client/impl/NacosSyncQueryClientImpl.java diff --git a/nacossync-worker/pom.xml b/nacossync-worker/pom.xml index 96a8cadf..f8e453db 100644 --- a/nacossync-worker/pom.xml +++ b/nacossync-worker/pom.xml @@ -164,8 +164,8 @@ org.apache.maven.plugins maven-compiler-plugin - 11 - 11 + 17 + 17 diff --git a/nacossync-worker/src/main/java/com/alibaba/nacossync/dao/repository/ClusterRepository.java b/nacossync-worker/src/main/java/com/alibaba/nacossync/dao/repository/ClusterRepository.java index f4bf95d8..87edc26f 100644 --- a/nacossync-worker/src/main/java/com/alibaba/nacossync/dao/repository/ClusterRepository.java +++ b/nacossync-worker/src/main/java/com/alibaba/nacossync/dao/repository/ClusterRepository.java @@ -16,13 +16,13 @@ */ package com.alibaba.nacossync.dao.repository; -import javax.transaction.Transactional; - +import com.alibaba.nacossync.pojo.model.ClusterDO; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaSpecificationExecutor; import org.springframework.data.repository.CrudRepository; -import com.alibaba.nacossync.pojo.model.ClusterDO; +import javax.transaction.Transactional; + /** * @author NacosSync @@ -34,6 +34,6 @@ public interface ClusterRepository extends CrudRepository, J ClusterDO findByClusterId(String clusterId); @Transactional - int deleteByClusterId(String clusterId); + void deleteByClusterId(String clusterId); } diff --git a/nacossync-worker/src/main/java/com/alibaba/nacossync/extension/client/InstanceQueryModel.java b/nacossync-worker/src/main/java/com/alibaba/nacossync/extension/client/InstanceQueryModel.java deleted file mode 100644 index c9f69a09..00000000 --- a/nacossync-worker/src/main/java/com/alibaba/nacossync/extension/client/InstanceQueryModel.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.alibaba.nacossync.extension.client; - -import lombok.Data; - -@Data -@Deprecated -public class InstanceQueryModel { - - private String sourceClusterId; - private String destClusterId; - private String serviceName; - private String groupName; - private String version; - private int pageNo; - private int pageSize; -} diff --git a/nacossync-worker/src/main/java/com/alibaba/nacossync/extension/client/SyncQueryClient.java b/nacossync-worker/src/main/java/com/alibaba/nacossync/extension/client/SyncQueryClient.java deleted file mode 100644 index 2a14ea0e..00000000 --- a/nacossync-worker/src/main/java/com/alibaba/nacossync/extension/client/SyncQueryClient.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.alibaba.nacossync.extension.client; - -import com.alibaba.nacossync.pojo.view.TaskModel; -import java.util.List; - -@Deprecated -public interface SyncQueryClient { - - - List getAllInstance(InstanceQueryModel instanceQueryModel); - - -} diff --git a/nacossync-worker/src/main/java/com/alibaba/nacossync/extension/client/impl/NacosSyncQueryClientImpl.java b/nacossync-worker/src/main/java/com/alibaba/nacossync/extension/client/impl/NacosSyncQueryClientImpl.java deleted file mode 100644 index 9366d931..00000000 --- a/nacossync-worker/src/main/java/com/alibaba/nacossync/extension/client/impl/NacosSyncQueryClientImpl.java +++ /dev/null @@ -1,56 +0,0 @@ -package com.alibaba.nacossync.extension.client.impl; - -import com.alibaba.nacos.api.exception.NacosException; -import com.alibaba.nacos.api.naming.NamingService; -import com.alibaba.nacos.api.naming.pojo.ListView; -import com.alibaba.nacossync.extension.client.InstanceQueryModel; -import com.alibaba.nacossync.extension.client.SyncQueryClient; -import com.alibaba.nacossync.extension.holder.NacosServerHolder; -import com.alibaba.nacossync.pojo.view.TaskModel; -import lombok.extern.slf4j.Slf4j; -import org.springframework.stereotype.Service; - -import java.util.Collections; -import java.util.List; -import java.util.stream.Collectors; - -@Service -@Slf4j -@Deprecated -public class NacosSyncQueryClientImpl implements SyncQueryClient { - - private final NacosServerHolder nacosServerHolder; - - public NacosSyncQueryClientImpl( - NacosServerHolder nacosServerHolder) { - this.nacosServerHolder = nacosServerHolder; - } - - @Override - public List getAllInstance(InstanceQueryModel instanceQueryModel) { - NamingService namingService = nacosServerHolder - .get(instanceQueryModel.getSourceClusterId()); - try { - ListView servicesOfServer = namingService - .getServicesOfServer(instanceQueryModel.getPageNo(), - instanceQueryModel.getPageSize()); - return servicesOfServer.getData().stream() - .map(serviceName -> buildTaskModel(instanceQueryModel, serviceName)) - .collect(Collectors.toList()); - - } catch (NacosException e) { - log.error("When using nacos client failure query tasks", e); - return Collections.emptyList(); - } - } - - private TaskModel buildTaskModel(InstanceQueryModel instanceQueryModel, String serviceName) { - TaskModel taskModel = new TaskModel(); - taskModel.setServiceName(serviceName); - taskModel.setSourceClusterId(instanceQueryModel.getSourceClusterId()); - taskModel.setDestClusterId(instanceQueryModel.getDestClusterId()); - return taskModel; - } - - -} diff --git a/nacossync-worker/src/main/java/com/alibaba/nacossync/pojo/model/SystemConfigDO.java b/nacossync-worker/src/main/java/com/alibaba/nacossync/pojo/model/SystemConfigDO.java index 4b6766bb..9df8f73d 100644 --- a/nacossync-worker/src/main/java/com/alibaba/nacossync/pojo/model/SystemConfigDO.java +++ b/nacossync-worker/src/main/java/com/alibaba/nacossync/pojo/model/SystemConfigDO.java @@ -16,6 +16,7 @@ */ package com.alibaba.nacossync.pojo.model; + import lombok.Getter; import lombok.RequiredArgsConstructor; import lombok.Setter; diff --git a/nacossync-worker/src/main/java/com/alibaba/nacossync/pojo/model/TaskDO.java b/nacossync-worker/src/main/java/com/alibaba/nacossync/pojo/model/TaskDO.java index 485afe13..1371771a 100644 --- a/nacossync-worker/src/main/java/com/alibaba/nacossync/pojo/model/TaskDO.java +++ b/nacossync-worker/src/main/java/com/alibaba/nacossync/pojo/model/TaskDO.java @@ -12,6 +12,7 @@ */ package com.alibaba.nacossync.pojo.model; + import lombok.Getter; import lombok.RequiredArgsConstructor; import lombok.Setter; diff --git a/nacossync-worker/src/main/java/com/alibaba/nacossync/pojo/view/ClusterModel.java b/nacossync-worker/src/main/java/com/alibaba/nacossync/pojo/view/ClusterModel.java index a4340da9..b666dec8 100644 --- a/nacossync-worker/src/main/java/com/alibaba/nacossync/pojo/view/ClusterModel.java +++ b/nacossync-worker/src/main/java/com/alibaba/nacossync/pojo/view/ClusterModel.java @@ -14,36 +14,53 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.alibaba.nacossync.pojo.view; import com.alibaba.nacossync.constant.ClusterTypeEnum; -import java.io.Serializable; - +import com.alibaba.nacossync.pojo.model.ClusterDO; import lombok.Data; +import java.io.Serializable; + /** * @author NacosSync * @version $Id: ClusterModel.java, v 0.1 2018-09-25 下午11:09 NacosSync Exp $$ */ @Data public class ClusterModel implements Serializable { - + private String clusterId; + /** * json format,["192.168.1:8080","192.168.2?key=1"] */ private String connectKeyList; + /** * cluster name, eg:cluster of ShangHai(edas-sh) */ private String clusterName; + /** * cluster type, eg cluster of CS,cluster of Nacos, * * @see ClusterTypeEnum */ private String clusterType; - + private String namespace; + private String userName; + + public static ClusterModel from(ClusterDO clusterDO) { + ClusterModel clusterModel = new ClusterModel(); + clusterModel.setClusterId(clusterDO.getClusterId()); + clusterModel.setConnectKeyList(clusterDO.getConnectKeyList()); + clusterModel.setClusterType(clusterDO.getClusterType()); + clusterModel.setClusterName(clusterDO.getClusterName()); + clusterModel.setNamespace(clusterDO.getNamespace()); + clusterModel.setUserName(clusterDO.getUserName()); + return clusterModel; + } } diff --git a/nacossync-worker/src/main/java/com/alibaba/nacossync/pojo/view/TaskModel.java b/nacossync-worker/src/main/java/com/alibaba/nacossync/pojo/view/TaskModel.java index 7b2d8b14..7ac5515a 100644 --- a/nacossync-worker/src/main/java/com/alibaba/nacossync/pojo/view/TaskModel.java +++ b/nacossync-worker/src/main/java/com/alibaba/nacossync/pojo/view/TaskModel.java @@ -14,8 +14,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.alibaba.nacossync.pojo.view; +import com.alibaba.nacossync.pojo.model.TaskDO; import lombok.Data; /** @@ -24,12 +26,27 @@ */ @Data public class TaskModel { - + private String taskId; + private String sourceClusterId; + private String destClusterId; + private String serviceName; + private String groupName; + private String taskStatus; - + + public static TaskModel from(TaskDO taskDO) { + TaskModel taskModel = new TaskModel(); + taskModel.setDestClusterId(taskDO.getDestClusterId()); + taskModel.setGroupName(taskDO.getGroupName()); + taskModel.setServiceName(taskDO.getServiceName()); + taskModel.setSourceClusterId(taskDO.getSourceClusterId()); + taskModel.setTaskStatus(taskDO.getTaskStatus()); + taskModel.setTaskId(taskDO.getTaskId()); + return taskModel; + } } diff --git a/nacossync-worker/src/main/java/com/alibaba/nacossync/template/processor/ClusterAddProcessor.java b/nacossync-worker/src/main/java/com/alibaba/nacossync/template/processor/ClusterAddProcessor.java index 1087977f..64d2d87b 100644 --- a/nacossync-worker/src/main/java/com/alibaba/nacossync/template/processor/ClusterAddProcessor.java +++ b/nacossync-worker/src/main/java/com/alibaba/nacossync/template/processor/ClusterAddProcessor.java @@ -14,6 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.alibaba.nacossync.template.processor; import com.alibaba.nacossync.constant.ClusterTypeEnum; @@ -37,9 +38,9 @@ @Service public class ClusterAddProcessor implements Processor { - + private final ClusterAccessService clusterAccessService; - + private final ObjectMapper objectMapper; public ClusterAddProcessor(ClusterAccessService clusterAccessService, ObjectMapper objectMapper) { @@ -48,33 +49,33 @@ public ClusterAddProcessor(ClusterAccessService clusterAccessService, ObjectMapp } @Override - public void process(ClusterAddRequest clusterAddRequest, ClusterAddResult clusterAddResult, - Object... others) throws Exception { + public void process(ClusterAddRequest clusterAddRequest, ClusterAddResult clusterAddResult, Object... others) + throws Exception { ClusterDO clusterDO = new ClusterDO(); - + if (null == clusterAddRequest.getConnectKeyList() || clusterAddRequest.getConnectKeyList().isEmpty()) { - + throw new SkyWalkerException("集群列表不能为空!"); } - - if (StringUtils.isBlank(clusterAddRequest.getClusterName()) || StringUtils - .isBlank(clusterAddRequest.getClusterType())) { - + + if (StringUtils.isBlank(clusterAddRequest.getClusterName()) || StringUtils.isBlank( + clusterAddRequest.getClusterType())) { + throw new SkyWalkerException("集群名字或者类型不能为空!"); } - + if (!ClusterTypeEnum.contains(clusterAddRequest.getClusterType())) { - + throw new SkyWalkerException("集群类型不存在:" + clusterAddRequest.getClusterType()); } - + String clusterId = SkyWalkerUtil.generateClusterId(clusterAddRequest); - + if (null != clusterAccessService.findByClusterId(clusterId)) { - + throw new SkyWalkerException("重复插入,clusterId已存在:" + clusterId); } - + clusterDO.setClusterId(clusterId); clusterDO.setClusterName(clusterAddRequest.getClusterName()); clusterDO.setClusterType(clusterAddRequest.getClusterType()); diff --git a/nacossync-worker/src/main/java/com/alibaba/nacossync/template/processor/ClusterDetailQueryProcessor.java b/nacossync-worker/src/main/java/com/alibaba/nacossync/template/processor/ClusterDetailQueryProcessor.java index 95c5d831..8b855730 100644 --- a/nacossync-worker/src/main/java/com/alibaba/nacossync/template/processor/ClusterDetailQueryProcessor.java +++ b/nacossync-worker/src/main/java/com/alibaba/nacossync/template/processor/ClusterDetailQueryProcessor.java @@ -44,15 +44,8 @@ public void process(ClusterDetailQueryRequest clusterDetailQueryRequest, ClusterDO clusterDO = clusterAccessService.findByClusterId(clusterDetailQueryRequest .getClusterId()); - - ClusterModel clusterModel = new ClusterModel(); - clusterModel.setClusterId(clusterDO.getClusterId()); - clusterModel.setConnectKeyList(clusterDO.getConnectKeyList()); - clusterModel.setClusterType(clusterDO.getClusterType()); - clusterModel.setClusterName(clusterDO.getClusterName()); - clusterModel.setNamespace(clusterDO.getNamespace()); - clusterModel.setUserName(clusterDO.getUserName()); - clusterDetailQueryResult.setClusterModel(clusterModel); + + clusterDetailQueryResult.setClusterModel(ClusterModel.from(clusterDO)); } } diff --git a/nacossync-worker/src/main/java/com/alibaba/nacossync/template/processor/ClusterListQueryProcessor.java b/nacossync-worker/src/main/java/com/alibaba/nacossync/template/processor/ClusterListQueryProcessor.java index 6a5c5007..247a2ddb 100644 --- a/nacossync-worker/src/main/java/com/alibaba/nacossync/template/processor/ClusterListQueryProcessor.java +++ b/nacossync-worker/src/main/java/com/alibaba/nacossync/template/processor/ClusterListQueryProcessor.java @@ -14,71 +14,57 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.alibaba.nacossync.template.processor; -import java.util.ArrayList; -import java.util.List; +package com.alibaba.nacossync.template.processor; +import com.alibaba.nacossync.dao.ClusterAccessService; import com.alibaba.nacossync.pojo.QueryCondition; +import com.alibaba.nacossync.pojo.model.ClusterDO; +import com.alibaba.nacossync.pojo.request.ClusterListQueryRequest; +import com.alibaba.nacossync.pojo.result.ClusterListQueryResult; +import com.alibaba.nacossync.pojo.view.ClusterModel; +import com.alibaba.nacossync.template.Processor; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; import org.springframework.stereotype.Service; -import com.alibaba.nacossync.dao.ClusterAccessService; -import com.alibaba.nacossync.pojo.result.ClusterListQueryResult; -import com.alibaba.nacossync.pojo.model.ClusterDO; -import com.alibaba.nacossync.pojo.request.ClusterListQueryRequest; -import com.alibaba.nacossync.pojo.view.ClusterModel; -import com.alibaba.nacossync.template.Processor; +import java.util.List; /** * @author NacosSync * @version $Id: ClusterListQueryProcessor.java, v 0.1 2018-09-30 PM2:33 NacosSync Exp $$ */ @Service -public class ClusterListQueryProcessor implements - Processor { - +public class ClusterListQueryProcessor implements Processor { + @Autowired private ClusterAccessService clusterAccessService; - + @Override - public void process(ClusterListQueryRequest clusterListQueryRequest, - ClusterListQueryResult clusterListQueryResult, Object... others) { - + public void process(ClusterListQueryRequest clusterListQueryRequest, ClusterListQueryResult clusterListQueryResult, + Object... others) { + Page clusterDOS; - + if (StringUtils.isNotBlank(clusterListQueryRequest.getClusterName())) { - + QueryCondition queryCondition = new QueryCondition(); queryCondition.setServiceName(clusterListQueryRequest.getClusterName()); clusterDOS = clusterAccessService.findPageCriteria(clusterListQueryRequest.getPageNum() - 1, clusterListQueryRequest.getPageSize(), queryCondition); - + } else { - + clusterDOS = clusterAccessService.findPageNoCriteria(clusterListQueryRequest.getPageNum() - 1, clusterListQueryRequest.getPageSize()); - + } - - List clusterModels = new ArrayList<>(); - clusterDOS.forEach(clusterDO -> { - - ClusterModel clusterModel = new ClusterModel(); - clusterModel.setClusterId(clusterDO.getClusterId()); - clusterModel.setClusterName(clusterDO.getClusterName()); - clusterModel.setClusterType(clusterDO.getClusterType()); - clusterModel.setConnectKeyList(clusterDO.getConnectKeyList()); - clusterModel.setNamespace(clusterDO.getNamespace()); - clusterModels.add(clusterModel); - }); - + List clusterModels = clusterDOS.stream().map(ClusterModel::from).toList(); clusterListQueryResult.setClusterModels(clusterModels); clusterListQueryResult.setTotalPage(clusterDOS.getTotalPages()); clusterListQueryResult.setCurrentSize(clusterModels.size()); clusterListQueryResult.setTotalSize(clusterDOS.getTotalElements()); - + } } diff --git a/nacossync-worker/src/main/java/com/alibaba/nacossync/template/processor/TaskDetailProcessor.java b/nacossync-worker/src/main/java/com/alibaba/nacossync/template/processor/TaskDetailProcessor.java index 8a374e08..eb230b71 100644 --- a/nacossync-worker/src/main/java/com/alibaba/nacossync/template/processor/TaskDetailProcessor.java +++ b/nacossync-worker/src/main/java/com/alibaba/nacossync/template/processor/TaskDetailProcessor.java @@ -14,17 +14,17 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.alibaba.nacossync.template.processor; import com.alibaba.nacossync.dao.TaskAccessService; import com.alibaba.nacossync.exception.SkyWalkerException; -import com.alibaba.nacossync.pojo.result.TaskDetailQueryResult; import com.alibaba.nacossync.pojo.model.TaskDO; import com.alibaba.nacossync.pojo.request.TaskDetailQueryRequest; +import com.alibaba.nacossync.pojo.result.TaskDetailQueryResult; import com.alibaba.nacossync.pojo.view.TaskModel; import com.alibaba.nacossync.template.Processor; import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; /** @@ -34,29 +34,23 @@ @Slf4j @Service public class TaskDetailProcessor implements Processor { - - @Autowired - private TaskAccessService taskAccessService; - + + private final TaskAccessService taskAccessService; + + public TaskDetailProcessor(TaskAccessService taskAccessService) { + this.taskAccessService = taskAccessService; + } + @Override - public void process(TaskDetailQueryRequest taskDetailQueryRequest, TaskDetailQueryResult taskDetailQueryResult, Object... others) - throws Exception { - + public void process(TaskDetailQueryRequest taskDetailQueryRequest, TaskDetailQueryResult taskDetailQueryResult, + Object... others) throws Exception { + TaskDO taskDO = taskAccessService.findByTaskId(taskDetailQueryRequest.getTaskId()); - + if (null == taskDO) { throw new SkyWalkerException("taskDo is null,taskId :" + taskDetailQueryRequest.getTaskId()); } - - TaskModel taskModel = new TaskModel(); - - taskModel.setDestClusterId(taskDO.getDestClusterId()); - taskModel.setGroupName(taskDO.getGroupName()); - taskModel.setServiceName(taskDO.getServiceName()); - taskModel.setSourceClusterId(taskDO.getSourceClusterId()); - taskModel.setTaskStatus(taskDO.getTaskStatus()); - taskModel.setTaskId(taskDO.getTaskId()); - - taskDetailQueryResult.setTaskModel(taskModel); + + taskDetailQueryResult.setTaskModel(TaskModel.from(taskDO)); } } diff --git a/nacossync-worker/src/main/java/com/alibaba/nacossync/template/processor/TaskListQueryProcessor.java b/nacossync-worker/src/main/java/com/alibaba/nacossync/template/processor/TaskListQueryProcessor.java index 364b47cf..fb5063ed 100644 --- a/nacossync-worker/src/main/java/com/alibaba/nacossync/template/processor/TaskListQueryProcessor.java +++ b/nacossync-worker/src/main/java/com/alibaba/nacossync/template/processor/TaskListQueryProcessor.java @@ -14,25 +14,23 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.alibaba.nacossync.template.processor; -import java.util.ArrayList; -import java.util.List; +package com.alibaba.nacossync.template.processor; +import com.alibaba.nacossync.dao.TaskAccessService; import com.alibaba.nacossync.pojo.QueryCondition; import com.alibaba.nacossync.pojo.model.TaskDO; +import com.alibaba.nacossync.pojo.request.TaskListQueryRequest; +import com.alibaba.nacossync.pojo.result.TaskListQueryResult; +import com.alibaba.nacossync.pojo.view.TaskModel; +import com.alibaba.nacossync.template.Processor; import lombok.extern.slf4j.Slf4j; - import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; import org.springframework.stereotype.Service; -import com.alibaba.nacossync.dao.TaskAccessService; -import com.alibaba.nacossync.pojo.result.TaskListQueryResult; -import com.alibaba.nacossync.pojo.request.TaskListQueryRequest; -import com.alibaba.nacossync.pojo.view.TaskModel; -import com.alibaba.nacossync.template.Processor; +import java.util.List; /** * @author NacosSync @@ -41,42 +39,31 @@ @Service @Slf4j public class TaskListQueryProcessor implements Processor { - + @Autowired private TaskAccessService taskAccessService; - + @Override - public void process(TaskListQueryRequest taskListQueryRequest, - TaskListQueryResult taskListQueryResult, Object... others) { - + public void process(TaskListQueryRequest taskListQueryRequest, TaskListQueryResult taskListQueryResult, + Object... others) { + Page taskDOPage; - + if (StringUtils.isNotBlank(taskListQueryRequest.getServiceName())) { - + QueryCondition queryCondition = new QueryCondition(); queryCondition.setServiceName(taskListQueryRequest.getServiceName()); taskDOPage = taskAccessService.findPageCriteria(taskListQueryRequest.getPageNum() - 1, taskListQueryRequest.getPageSize(), queryCondition); } else { - + taskDOPage = taskAccessService.findPageNoCriteria(taskListQueryRequest.getPageNum() - 1, taskListQueryRequest.getPageSize()); - + } - - List taskList = new ArrayList<>(); - - taskDOPage.forEach(taskDO -> { - TaskModel taskModel = new TaskModel(); - taskModel.setTaskId(taskDO.getTaskId()); - taskModel.setDestClusterId(taskDO.getDestClusterId()); - taskModel.setSourceClusterId(taskDO.getSourceClusterId()); - taskModel.setServiceName(taskDO.getServiceName()); - taskModel.setGroupName(taskDO.getGroupName()); - taskModel.setTaskStatus(taskDO.getTaskStatus()); - taskList.add(taskModel); - }); - + + List taskList = taskDOPage.stream().map(TaskModel::from).toList(); + taskListQueryResult.setTaskModels(taskList); taskListQueryResult.setTotalPage(taskDOPage.getTotalPages()); taskListQueryResult.setTotalSize(taskDOPage.getTotalElements()); diff --git a/pom.xml b/pom.xml index 824aa8ff..74fc8e0c 100644 --- a/pom.xml +++ b/pom.xml @@ -38,8 +38,8 @@ 3.12.0 33.2.0-jre 2.2 - 11 - 11 + 17 + 17 3.2.0 1.4.1 3.0.1 @@ -181,6 +181,7 @@ + @@ -384,4 +385,11 @@ + + + maven_central + Maven Central + https://repo.maven.apache.org/maven2/ + + \ No newline at end of file From 116116c8c432b0495d6a6ff58ce92234f54519eb Mon Sep 17 00:00:00 2001 From: paderlol Date: Thu, 29 Aug 2024 16:48:58 +0800 Subject: [PATCH 3/4] =?UTF-8?q?1.=20=E4=BC=98=E5=8C=96=E9=83=A8=E5=88=86?= =?UTF-8?q?=E9=9B=86=E7=BE=A4=E6=96=B0=E5=A2=9E=E9=83=A8=E5=88=86=E5=86=97?= =?UTF-8?q?=E4=BD=99=E4=BB=A3=E7=A0=81=202.=20=E5=8D=87=E7=BA=A7Java=20JDK?= =?UTF-8?q?=E5=88=B017?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 7 ------- 1 file changed, 7 deletions(-) diff --git a/pom.xml b/pom.xml index 74fc8e0c..f2b12405 100644 --- a/pom.xml +++ b/pom.xml @@ -385,11 +385,4 @@ - - - maven_central - Maven Central - https://repo.maven.apache.org/maven2/ - - \ No newline at end of file From b609c729c3e358cb1414c4a943943cc185a523fa Mon Sep 17 00:00:00 2001 From: paderlol Date: Sat, 28 Sep 2024 13:26:07 +0800 Subject: [PATCH 4/4] =?UTF-8?q?1.=20=E5=AF=B9=E4=BB=A3=E7=A0=81=E4=B8=AD?= =?UTF-8?q?=E4=BE=9D=E8=B5=96=E6=B3=A8=E5=85=A5=E6=96=B9=E5=BC=8F=E5=85=A8?= =?UTF-8?q?=E9=83=A8=E4=BF=AE=E6=94=B9=E6=88=90=E6=9E=84=E9=80=A0=E5=87=BD?= =?UTF-8?q?=E6=95=B0=E6=B3=A8=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cache/SkyWalkerCacheServices.java | 24 +++++++------- .../nacossync/template/SkyWalkerTemplate.java | 3 +- .../ClusterDetailQueryProcessor.java | 31 +++++++++---------- .../processor/ClusterListQueryProcessor.java | 7 +++-- .../processor/TaskDeleteInBatchProcessor.java | 26 +++++----------- .../processor/TaskListQueryProcessor.java | 7 +++-- .../processor/TaskUpdateProcessor.java | 28 ++++++++--------- 7 files changed, 60 insertions(+), 66 deletions(-) diff --git a/nacossync-worker/src/main/java/com/alibaba/nacossync/cache/SkyWalkerCacheServices.java b/nacossync-worker/src/main/java/com/alibaba/nacossync/cache/SkyWalkerCacheServices.java index 100af683..d36179d4 100644 --- a/nacossync-worker/src/main/java/com/alibaba/nacossync/cache/SkyWalkerCacheServices.java +++ b/nacossync-worker/src/main/java/com/alibaba/nacossync/cache/SkyWalkerCacheServices.java @@ -26,7 +26,6 @@ import com.alibaba.nacossync.util.SkyWalkerUtil; import com.fasterxml.jackson.databind.ObjectMapper; import lombok.SneakyThrows; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.util.CollectionUtils; import org.springframework.util.StringUtils; @@ -43,14 +42,17 @@ @Service public class SkyWalkerCacheServices { - private static final Map finishedTaskMap = new ConcurrentHashMap<>(); + private static final Map FINISHED_TASK_MAP = new ConcurrentHashMap<>(); - @Autowired - private ClusterAccessService clusterAccessService; - - @Autowired - private ObjectMapper objectMapper; + private final ClusterAccessService clusterAccessService; + private final ObjectMapper objectMapper; + + public SkyWalkerCacheServices(ClusterAccessService clusterAccessService, ObjectMapper objectMapper) { + this.clusterAccessService = clusterAccessService; + this.objectMapper = objectMapper; + } + public String getClusterConnectKey(String clusterId) { List allClusterConnectKey = getAllClusterConnectKey(clusterId); return allClusterConnectKey.get(ThreadLocalRandom.current().nextInt(allClusterConnectKey.size())); @@ -83,7 +85,7 @@ public void addFinishedTask(TaskDO taskDO) { FinishedTask finishedTask = new FinishedTask(); finishedTask.setOperationId(operationId); - finishedTaskMap.put(operationId, finishedTask); + FINISHED_TASK_MAP.put(operationId, finishedTask); } public FinishedTask getFinishedTask(TaskDO taskDO) { @@ -94,7 +96,7 @@ public FinishedTask getFinishedTask(TaskDO taskDO) { return null; } - return finishedTaskMap.get(operationId); + return FINISHED_TASK_MAP.get(operationId); } @@ -102,12 +104,12 @@ public void removeFinishedTask(String operationId) { if (!StringUtils.hasLength(operationId)) { return; } - finishedTaskMap.remove(operationId); + FINISHED_TASK_MAP.remove(operationId); } public Map getFinishedTaskMap() { - return finishedTaskMap; + return FINISHED_TASK_MAP; } diff --git a/nacossync-worker/src/main/java/com/alibaba/nacossync/template/SkyWalkerTemplate.java b/nacossync-worker/src/main/java/com/alibaba/nacossync/template/SkyWalkerTemplate.java index d91223b6..ec0d62d2 100644 --- a/nacossync-worker/src/main/java/com/alibaba/nacossync/template/SkyWalkerTemplate.java +++ b/nacossync-worker/src/main/java/com/alibaba/nacossync/template/SkyWalkerTemplate.java @@ -45,8 +45,7 @@ public static T run(Processor processor, BaseRequest requ } private static void initExceptionResult(T result, Throwable e) { - if (e instanceof SkyWalkerException) { - SkyWalkerException skyWalkerException = (SkyWalkerException) e; + if (e instanceof SkyWalkerException skyWalkerException) { if (null != skyWalkerException.getResultCode()) { result.setResultCode(skyWalkerException.getResultCode().getCode()); } diff --git a/nacossync-worker/src/main/java/com/alibaba/nacossync/template/processor/ClusterDetailQueryProcessor.java b/nacossync-worker/src/main/java/com/alibaba/nacossync/template/processor/ClusterDetailQueryProcessor.java index 8b855730..eb318fd8 100644 --- a/nacossync-worker/src/main/java/com/alibaba/nacossync/template/processor/ClusterDetailQueryProcessor.java +++ b/nacossync-worker/src/main/java/com/alibaba/nacossync/template/processor/ClusterDetailQueryProcessor.java @@ -14,38 +14,37 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.alibaba.nacossync.template.processor; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; +package com.alibaba.nacossync.template.processor; import com.alibaba.nacossync.dao.ClusterAccessService; -import com.alibaba.nacossync.pojo.result.ClusterDetailQueryResult; import com.alibaba.nacossync.pojo.model.ClusterDO; import com.alibaba.nacossync.pojo.request.ClusterDetailQueryRequest; +import com.alibaba.nacossync.pojo.result.ClusterDetailQueryResult; import com.alibaba.nacossync.pojo.view.ClusterModel; import com.alibaba.nacossync.template.Processor; +import org.springframework.stereotype.Service; /** * @author NacosSync * @version $Id: ClusterDetailQueryProcessor.java, v 0.1 2018-09-30 PM2:39 NacosSync Exp $$ */ @Service -public class ClusterDetailQueryProcessor - implements - Processor { - @Autowired - private ClusterAccessService clusterAccessService; - +public class ClusterDetailQueryProcessor implements Processor { + + private final ClusterAccessService clusterAccessService; + + public ClusterDetailQueryProcessor(ClusterAccessService clusterAccessService) { + this.clusterAccessService = clusterAccessService; + } + @Override public void process(ClusterDetailQueryRequest clusterDetailQueryRequest, - ClusterDetailQueryResult clusterDetailQueryResult, Object... others) - throws Exception { - - ClusterDO clusterDO = clusterAccessService.findByClusterId(clusterDetailQueryRequest - .getClusterId()); + ClusterDetailQueryResult clusterDetailQueryResult, Object... others) throws Exception { + + ClusterDO clusterDO = clusterAccessService.findByClusterId(clusterDetailQueryRequest.getClusterId()); clusterDetailQueryResult.setClusterModel(ClusterModel.from(clusterDO)); - + } } diff --git a/nacossync-worker/src/main/java/com/alibaba/nacossync/template/processor/ClusterListQueryProcessor.java b/nacossync-worker/src/main/java/com/alibaba/nacossync/template/processor/ClusterListQueryProcessor.java index 247a2ddb..75eef4fc 100644 --- a/nacossync-worker/src/main/java/com/alibaba/nacossync/template/processor/ClusterListQueryProcessor.java +++ b/nacossync-worker/src/main/java/com/alibaba/nacossync/template/processor/ClusterListQueryProcessor.java @@ -38,8 +38,11 @@ @Service public class ClusterListQueryProcessor implements Processor { - @Autowired - private ClusterAccessService clusterAccessService; + private final ClusterAccessService clusterAccessService; + + public ClusterListQueryProcessor(ClusterAccessService clusterAccessService) { + this.clusterAccessService = clusterAccessService; + } @Override public void process(ClusterListQueryRequest clusterListQueryRequest, ClusterListQueryResult clusterListQueryResult, diff --git a/nacossync-worker/src/main/java/com/alibaba/nacossync/template/processor/TaskDeleteInBatchProcessor.java b/nacossync-worker/src/main/java/com/alibaba/nacossync/template/processor/TaskDeleteInBatchProcessor.java index f95ac3ce..c30a064c 100644 --- a/nacossync-worker/src/main/java/com/alibaba/nacossync/template/processor/TaskDeleteInBatchProcessor.java +++ b/nacossync-worker/src/main/java/com/alibaba/nacossync/template/processor/TaskDeleteInBatchProcessor.java @@ -16,19 +16,12 @@ */ package com.alibaba.nacossync.template.processor; -import java.util.ArrayList; -import java.util.List; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; - import com.alibaba.nacossync.dao.TaskAccessService; -import com.alibaba.nacossync.pojo.model.TaskDO; import com.alibaba.nacossync.pojo.request.TaskDeleteInBatchRequest; import com.alibaba.nacossync.pojo.result.BaseResult; import com.alibaba.nacossync.template.Processor; - import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; /** @@ -40,20 +33,15 @@ @Service public class TaskDeleteInBatchProcessor implements Processor { - @Autowired - private TaskAccessService taskAccessService; - + private final TaskAccessService taskAccessService; + + public TaskDeleteInBatchProcessor(TaskAccessService taskAccessService) { + this.taskAccessService = taskAccessService; + } + @Override public void process(TaskDeleteInBatchRequest taskBatchDeleteRequest, BaseResult baseResult, Object... others) { -// -// String[] taskIds= taskBatchDeleteRequest.getTaskIds(); -// List taskDOs = new ArrayList(); -// for (String taskId : taskIds) { -// TaskDO taskDO = new TaskDO(); -// taskDO.setTaskId(taskId); -// taskDOs.add(taskDO); -// } taskAccessService.deleteTaskInBatch(taskBatchDeleteRequest.getTaskIds()); } } diff --git a/nacossync-worker/src/main/java/com/alibaba/nacossync/template/processor/TaskListQueryProcessor.java b/nacossync-worker/src/main/java/com/alibaba/nacossync/template/processor/TaskListQueryProcessor.java index fb5063ed..e194d6e5 100644 --- a/nacossync-worker/src/main/java/com/alibaba/nacossync/template/processor/TaskListQueryProcessor.java +++ b/nacossync-worker/src/main/java/com/alibaba/nacossync/template/processor/TaskListQueryProcessor.java @@ -40,8 +40,11 @@ @Slf4j public class TaskListQueryProcessor implements Processor { - @Autowired - private TaskAccessService taskAccessService; + private final TaskAccessService taskAccessService; + + public TaskListQueryProcessor(TaskAccessService taskAccessService) { + this.taskAccessService = taskAccessService; + } @Override public void process(TaskListQueryRequest taskListQueryRequest, TaskListQueryResult taskListQueryResult, diff --git a/nacossync-worker/src/main/java/com/alibaba/nacossync/template/processor/TaskUpdateProcessor.java b/nacossync-worker/src/main/java/com/alibaba/nacossync/template/processor/TaskUpdateProcessor.java index 327c7dc2..ab041331 100644 --- a/nacossync-worker/src/main/java/com/alibaba/nacossync/template/processor/TaskUpdateProcessor.java +++ b/nacossync-worker/src/main/java/com/alibaba/nacossync/template/processor/TaskUpdateProcessor.java @@ -14,6 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.alibaba.nacossync.template.processor; import com.alibaba.nacossync.constant.TaskStatusEnum; @@ -25,7 +26,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; /** @@ -35,31 +35,31 @@ @Slf4j @Service public class TaskUpdateProcessor implements Processor { - @Autowired - private TaskAccessService taskAccessService; + + private final TaskAccessService taskAccessService; + + public TaskUpdateProcessor(TaskAccessService taskAccessService) { + this.taskAccessService = taskAccessService; + } @Override - public void process(TaskUpdateRequest taskUpdateRequest, BaseResult baseResult, - Object... others) throws Exception { - + public void process(TaskUpdateRequest taskUpdateRequest, BaseResult baseResult, Object... others) throws Exception { + TaskDO taskDO = taskAccessService.findByTaskId(taskUpdateRequest.getTaskId()); - + if (!TaskStatusEnum.contains(taskUpdateRequest.getTaskStatus())) { throw new SkyWalkerException( - "taskUpdateRequest.getTaskStatus() is not exist , value is :" - + taskUpdateRequest.getTaskStatus()); + "taskUpdateRequest.getTaskStatus() is not exist , value is :" + taskUpdateRequest.getTaskStatus()); } - + if (null == taskDO) { - throw new SkyWalkerException("taskDo is null ,taskId is :" - + taskUpdateRequest.getTaskId()); + throw new SkyWalkerException("taskDo is null ,taskId is :" + taskUpdateRequest.getTaskId()); } taskDO.setTaskStatus(taskUpdateRequest.getTaskStatus()); - taskDO.setOperationId(SkyWalkerUtil.generateOperationId()); - + taskAccessService.addTask(taskDO); }