Skip to content

Commit

Permalink
Merge pull request #176 from nacos-group/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
paderlol authored Oct 2, 2020
2 parents f1ac50c + 88832f6 commit d89e8be
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 21 deletions.
2 changes: 1 addition & 1 deletion nacossync-console/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<parent>
<artifactId>nacossync-parent</artifactId>
<groupId>com.alibaba.nacossync</groupId>
<version>0.4.0</version>
<version>0.4.1</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion nacossync-distribution/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>nacossync-parent</artifactId>
<groupId>com.alibaba.nacossync</groupId>
<version>0.4.0</version>
<version>0.4.1</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<packaging>pom</packaging>
Expand Down
4 changes: 2 additions & 2 deletions nacossync-test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<parent>
<artifactId>nacossync-parent</artifactId>
<groupId>com.alibaba.nacossync</groupId>
<version>0.4.0</version>
<version>0.4.1</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand All @@ -39,7 +39,7 @@
<dependency>
<groupId>com.alibaba.nacossync</groupId>
<artifactId>nacossync-worker</artifactId>
<version>0.4.0</version>
<version>0.4.1</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
Expand Down
4 changes: 2 additions & 2 deletions nacossync-worker/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
<parent>
<artifactId>nacossync-parent</artifactId>
<groupId>com.alibaba.nacossync</groupId>
<version>0.4.0</version>
<version>0.4.1</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>nacossync-worker</artifactId>
<version>0.4.0</version>
<version>0.4.1</version>
<properties>
<zookeeper.version>3.4.9</zookeeper.version>
<curator.version>4.1.0</curator.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,14 @@
import com.alibaba.nacossync.monitor.MetricsManager;
import com.alibaba.nacossync.pojo.model.TaskDO;
import com.netflix.appinfo.InstanceInfo;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
* eureka
*
Expand Down Expand Up @@ -70,9 +71,10 @@ public boolean delete(TaskDO taskDO) {

try {
specialSyncEventBus.unsubscribe(taskDO);
NamingService destNamingService = nacosServerHolder.get(taskDO.getDestClusterId(), taskDO.getNameSpace());
List<Instance> allInstances = destNamingService.getAllInstances(taskDO.getServiceName());
deleteAllInstance(taskDO, destNamingService, allInstances);
EurekaNamingService eurekaNamingService = eurekaServerHolder.get(taskDO.getSourceClusterId(), null);
NamingService destNamingService = nacosServerHolder.get(taskDO.getDestClusterId(), null);
List<InstanceInfo> eurekaInstances = eurekaNamingService.getApplications(taskDO.getServiceName());
deleteAllInstanceFromEureka(taskDO, destNamingService, eurekaInstances);

} catch (Exception e) {
log.error("delete a task from eureka to nacos was failed, taskId:{}", taskDO.getTaskId(), e);
Expand Down Expand Up @@ -119,6 +121,17 @@ private void addValidInstance(TaskDO taskDO, NamingService destNamingService, Li
}
}
}

private void deleteAllInstanceFromEureka(TaskDO taskDO, NamingService destNamingService, List<InstanceInfo> eurekaInstances)
throws NacosException {
for (InstanceInfo instance : eurekaInstances) {
if (needSync(instance.getMetadata())) {
log.info("Delete service instance from Eureka, serviceName={}, Ip={}, port={}",
instance.getAppName(), instance.getIPAddr(), instance.getPort());
destNamingService.deregisterInstance(taskDO.getServiceName(), buildSyncInstance(instance, taskDO));
}
}
}

private void removeInvalidInstance(TaskDO taskDO, NamingService destNamingService,
List<InstanceInfo> eurekaInstances, List<Instance> nacosInstances) throws NacosException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,16 @@
*/
package com.alibaba.nacossync.template.processor;

import lombok.extern.slf4j.Slf4j;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alibaba.nacossync.dao.TaskAccessService;
import com.alibaba.nacossync.pojo.result.BaseResult;
import com.alibaba.nacossync.event.DeleteTaskEvent;
import com.alibaba.nacossync.pojo.model.TaskDO;
import com.alibaba.nacossync.pojo.request.TaskDeleteRequest;
import com.alibaba.nacossync.pojo.result.BaseResult;
import com.alibaba.nacossync.template.Processor;
import com.google.common.eventbus.EventBus;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
* @author NacosSync
Expand All @@ -36,11 +37,15 @@ public class TaskDeleteProcessor implements Processor<TaskDeleteRequest, BaseRes

@Autowired
private TaskAccessService taskAccessService;
@Autowired
private EventBus eventBus;

@Override
public void process(TaskDeleteRequest taskDeleteRequest, BaseResult baseResult,
Object... others) {

TaskDO taskDO = taskAccessService.findByTaskId(taskDeleteRequest.getTaskId());
eventBus.post(new DeleteTaskEvent(taskDO));
log.info("删除同步任务数据之前,发出一个同步事件:" + taskDO);
taskAccessService.deleteTaskById(taskDeleteRequest.getTaskId());
}
}
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

<groupId>com.alibaba.nacossync</groupId>
<artifactId>nacossync-parent</artifactId>
<version>0.4.0</version>
<version>0.4.1</version>
<modules>
<module>nacossync-console</module>
<module>nacossync-worker</module>
Expand Down Expand Up @@ -73,7 +73,7 @@
<dependency>
<groupId>com.alibaba.nacossync</groupId>
<artifactId>nacossync-worker</artifactId>
<version>0.4.0</version>
<version>0.4.1</version>
</dependency>
</dependencies>
</dependencyManagement>
Expand Down

0 comments on commit d89e8be

Please sign in to comment.